home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / PEN / PENTKT / PENBASE / TRACE.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  16KB  |  545 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  4. ;
  5. ;    The following IBM OS/2 WARP source code is provided to you solely for
  6. ;    the purpose of assisting you in your development of OS/2 WARP device
  7. ;    drivers. You may use this code in accordance with the IBM License
  8. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  9. ;    Copyright statement may not be removed.;
  10. ;*****************************************************************************/
  11. ;      /*****************************************************************/
  12. ;      /*                                                               */
  13. ;      /*                                                               */
  14. ;      /*****************************************************************/
  15. ;      /******************* START OF SPECIFICATIONS *********************/
  16. ;      /*                                                               */
  17. ;      /*  SOURCE FILE NAME: TRACE.ASM                                  */
  18. ;      /*                                                               */
  19. ;      /*  DESCRIPTIVE NAME: Trace support                              */
  20. ;      /*                                                               */
  21. ;      /*                                                               */
  22. ;      /*  STATUS:  Version 1.0                                         */
  23. ;      /*                                                               */
  24. ;      /*  NOTES: This module provides tracing support which can be     */
  25. ;      /*         used for debugging. Macros are defined in PEN.INC     */
  26. ;      /*         to add trace data. The trace is extracted and         */
  27. ;      /*         formatted by the pen device driver tool (PENTL.EXE).  */
  28. ;      /*                                                               */
  29. ;      /*         The trace table must be allocated before tracing.     */
  30. ;      /*         This can be done throught the pen tool or can be      */
  31. ;      /*         allocated during driver initialization with by:       */
  32. ;      /*                                                               */
  33. ;      /*         device=c:\penpm\pendd.sys trace=1000                  */
  34. ;      /*                                                               */
  35. ;      /*         1000 can be any value trace table size.               */
  36. ;      /*                                                               */
  37. ;      /*  ENTRY POINTS:                                                */
  38. ;      /*      See public statements                                    */
  39. ;      /*  EXTERNAL REFERENCES:                                         */
  40. ;      /*      See extrn statements                                     */
  41. ;      /*                                                               */
  42. ;      /******************* END  OF  SPECIFICATIONS *********************/
  43. .xlist
  44.   include pensegs.inc
  45.   include pen.inc
  46.   include penei.inc
  47.   include penioctl.inc
  48.   include devsym.inc
  49.   include devhlp.inc
  50.   include struc.inc
  51. .list
  52.  
  53. .386p
  54. ;------------------------------------------------------------------------------
  55. ;declare external routines
  56. ;------------------------------------------------------------------------------
  57.  
  58. extrn skip_to_white : near
  59. extrn skip_white    : near
  60. extrn str_i_cmp     : near
  61. extrn get_dec_num   : near
  62.  
  63. ;------------------------------------------------------------------------------
  64. ;declare external variables
  65. ;------------------------------------------------------------------------------
  66.  
  67. extrn Device_Help : dword
  68.  
  69. ;------------------------------------------------------------------------------
  70. ; local equates
  71. ;------------------------------------------------------------------------------
  72.  
  73. fUSE_DEKKO  equ 0       ; 1= use dekko trace 0= don't
  74. CR equ 0Dh
  75. LF equ 0Ah
  76.  
  77. ;------------------------------------------------------------------------------
  78. ; local data that is device instance independent
  79. ;------------------------------------------------------------------------------
  80.  
  81. DSEG SEGMENT
  82.  
  83. ; share same trace buffer for all devcies
  84. public trcNext
  85. trcSize       dw  0  ; count of DWORD entries
  86. trcWrap       db  0
  87. trcDS         dw  0
  88. trcPhys_h     dw  0
  89. trcPhys_l     dw  0
  90.  
  91. trcNext       dw  0
  92. trcStart      dw  0
  93.  
  94. DSEG ends
  95.  
  96. DSEGI segment
  97.   opt_trace     db  'TRACE=',0
  98.   cnf_trace     dw  0             ; size of trace to allocate at init time
  99. DSEGI ends
  100.  
  101. CSEG SEGMENT
  102.      ASSUME    CS:CGROUP, SS:nothing, ES:nothing, DS:DGROUP
  103.  
  104. ;--- TRACE ROUTINES -----------------------------------------------------------
  105. ;
  106. ;------------------------------------------------------------------------------
  107.  
  108. ;------------------------------------------------------------------------------
  109. ; Trace ABSOLUTE packet
  110. ;  di = event packet
  111. ; returns
  112. ;  maintains all regs and indicators
  113. ;------------------------------------------------------------------------------
  114. Public   Trc_ABS
  115. Trc_ABS   Proc  Near
  116.   pushf
  117.   DISABLE
  118.   mov   ax,[di].cev_devicebits
  119.   mov   cx,TRACE_ABS_EH
  120.   call  doTrc
  121.  
  122.   mov   eax,[di].lev_dev_x
  123.   mov   cx,TRACE_ABS_XH
  124.   call  doTrc
  125.  
  126.   mov   eax,[di].lev_dev_y
  127.   mov   cx,TRACE_ABS_YH
  128.   call  doTrc
  129.  
  130.   mov   ax,[di].lev_dev_z
  131.   mov   cx,TRACE_ABS_ZH
  132.   call  doTrc
  133.   popf
  134.   ret
  135. Trc_ABS   EndP
  136.  
  137. ;------------------------------------------------------------------------------
  138. ; Trace a byte
  139. ;  al = byte to trace
  140. ; returns
  141. ;  maintains all regs and indicators
  142. ;------------------------------------------------------------------------------
  143. Public   Trc_Byte
  144. Trc_Byte  Proc  Near
  145.   pushf
  146.   DISABLE
  147.   push  ax
  148.   push  cx
  149.   mov   cx,TRACE_DATA_H
  150.   mov   ah,0
  151.   call  doTrc
  152.   pop   cx
  153.   pop   ax
  154.   popf
  155.   ret
  156. Trc_Byte  EndP
  157. ;------------------------------------------------------------------------------
  158. ; Trace a byte (first byte of packet)
  159. ;  al = byte to trace
  160. ; returns
  161. ;  maintains all regs and indicators
  162. ;------------------------------------------------------------------------------
  163. Public   Trc_Byte1
  164. Trc_Byte1 Proc  Near
  165.   pushf
  166.   DISABLE
  167.   push  ax
  168.   push  cx
  169.   mov   cx,TRACE_DATA_1H
  170.   mov   ah,0
  171.   call  doTrc
  172.   pop   cx
  173.   pop   ax
  174.   popf
  175.   ret
  176. Trc_Byte1 EndP
  177. ;------------------------------------------------------------------------------
  178. ; Trace a device dependent word
  179. ;  ax = word to trace
  180. ;  cl = index
  181. ; returns
  182. ;  maintains all regs and indicators
  183. ;------------------------------------------------------------------------------
  184. Public   Trc_DD
  185. Trc_DD    Proc  Near
  186.   pushf
  187.   DISABLE
  188.   push  ax
  189.   push  cx
  190.   xor   ch,ch
  191.   or    cx,TRACE_DD_H
  192.   call  doTrc
  193.   pop   cx
  194.   pop   ax
  195.   popf
  196.   ret
  197. Trc_DD    EndP
  198.  
  199. ;------------------------------------------------------------------------------
  200. ; Trace an interrupt (put a special mark in trace)
  201. ;
  202. ; returns
  203. ;  maintains all regs and indicators
  204. ;------------------------------------------------------------------------------
  205. Public   Trc_INT
  206. Trc_INT   Proc  Near
  207.   pushf
  208.   DISABLE
  209.   push  ax
  210.   push  cx
  211.   mov   cx, TRACE_INT_H
  212.   mov   ax,0
  213.   call  doTrc
  214.   pop   cx
  215.   pop   ax
  216.   popf
  217.   ret
  218. Trc_INT   EndP
  219.  
  220. ;------------------------------------------------------------------------------
  221. ; Trace a timer tick (put a special mark in trace)
  222. ;
  223. ; returns
  224. ;  maintains all regs and indicators
  225. ; note: Does not fill up trace with ticks, instead, increment trace entry
  226. ;       as the number of ticks since the last trace event.
  227. ;------------------------------------------------------------------------------
  228. Public   Trc_Tick
  229. Trc_Tick  Proc  Near
  230.   .if  <trcSize ne 0>         ; check for trace table
  231.      pushf
  232.      DISABLE
  233.      push  ax
  234.      push  cx
  235.      push  si
  236.  
  237.      mov   si, trcNext
  238.      push  ds
  239.      mov   ds, trcDS
  240.      .if  <<word ptr [si+6]> eq TRACE_TICK_H>
  241.         inc word ptr [si+4]
  242.         pop ds
  243.      .else
  244.         pop   ds
  245.         mov   cx, TRACE_TICK_H
  246.         mov   ax,1
  247.         call  doTrc
  248.      .endif
  249.  
  250.      pop   si
  251.      pop   cx
  252.      pop   ax
  253.      popf
  254.   .endif
  255.   ret
  256. Trc_Tick  EndP
  257.  
  258. ;------------------------------------------------------------------------------
  259. ; Actually do the trace entry
  260. ;  ax = low order
  261. ;  cx = high order
  262. ;------------------------------------------------------------------------------
  263. Public  doTrc
  264. doTrc   Proc
  265.   .if   <trcSize ne 0>
  266.  
  267.      push  di
  268.      mov   di,trcNext
  269.      push  ds
  270.      mov   ds, trcDS
  271.      mov   word ptr [di],ax
  272.      mov   word ptr [di+2],cx
  273.      pop   ds
  274.      sub   di,4
  275.      .if   c               ; do the wrap around
  276.        mov  trcWrap, 1
  277.        mov  di, trcStart
  278.      .endif
  279.      mov   trcNext,di
  280.      pop   di
  281.   .endif
  282.   xor ax,ax
  283.   ret
  284. doTrc     EndP
  285.  
  286. ;--- IOCTL   ROUTINES ---------------------------------------------------------
  287. ;
  288. ;------------------------------------------------------------------------------
  289.  
  290. ;------------------------------------------------------------------------------
  291. ; Return the size of the trace table
  292. ;
  293. ; The returned size includes one for the first entry which is used to return
  294. ; the number of valid entries on the query trace table command.
  295. ;
  296. ; We waste one entry to make tracing ticks easiler. Tick trace looks ahead one
  297. ; entry to see if its a tick trace. We would need a special check not to look
  298. ; past the end of the table, instead we just waste one entry at the end.
  299. ;
  300. ; So, if 10 entries are requested on the Set Trace Table Size IOCTL, we alloc
  301. ; storage for 10 entries, then waste one. We return 10 on Query Trace table
  302. ; to include the first LONG which contains the number of valid entries. If the
  303. ; table is full or has wrapped, a 9 would be in this first location.
  304. ;------------------------------------------------------------------------------
  305. public Gio_qtts
  306. Gio_qtts proc    ; query trace table size
  307.   mov   ax, trcSize
  308.   mov   word ptr gs:[si].dqtts_size,ax
  309.   mov   word ptr gs:[si].dqtts_size+2,0
  310.   xor   ax,ax
  311.   ret
  312. Gio_qtts endp
  313.  
  314. ;------------------------------------------------------------------------------
  315. ; Reset the trace back to start
  316. ;
  317. ; note: this is not really needed as the trace is a wrap trace, but the Trace
  318. ;       program dumps starting at trcStart as a simification.
  319. ;------------------------------------------------------------------------------
  320. public Gio_rtb
  321. Gio_rtb proc     ; reset trace buffer
  322.   push di
  323.   mov  di, trcStart
  324.   mov  trcNext, di
  325.   mov  trcWrap, 0
  326.   pop  di
  327.   xor  ax,ax
  328.   ret
  329. Gio_rtb endp
  330.  
  331. ;------------------------------------------------------------------------------
  332. ; Copy the trace table to the Trace application's buffer
  333. ;  gs:si = data packet
  334. ; note: handle generic IOCTL dump command
  335. ;------------------------------------------------------------------------------
  336. public Gio_qtt
  337. Gio_qtt proc     ; query trace table
  338.  
  339.   push  gs
  340.   pop   es
  341.   mov   di,si
  342.   .if  <trcSize eq 0>         ; check for trace table
  343.      mov  word ptr es:[di],0
  344.      mov  word ptr es:[di+2],0
  345.   .else
  346.      DISABLE
  347.      mov  cx, trcStart        ; ax = addr of last entry in trace table
  348.      sub  cx, trcNext         ; calculate trace byte count
  349.      shr  cx,2                ; convert to dword count
  350.      .if  <trcWrap ne 0>
  351.         mov  ax, trcSize
  352.         dec  ax               ; one is wasted
  353.         mov  dx, ax
  354.         sub  dx, cx
  355.      .else
  356.         mov  ax, cx
  357.      .endif
  358.      mov  word ptr es:[di],ax
  359.      add  di,2
  360.      mov  word ptr es:[di],0
  361.      add  di,2
  362.  
  363.      sal  cx, 1         ; convert to word count
  364.      mov  si, trcNext   ; calculate trace byte count
  365.      add  si,4          ; adv to first entry (not the next available)
  366.      push ds
  367.      mov  ds, trcDS
  368.      rep  movsw         ; move it
  369.      pop  ds
  370.  
  371.      .if  <trcWrap ne 0>
  372.         mov  cx, dx
  373.         sal  cx, 1
  374.         mov  si, 0
  375.         push ds
  376.         mov  ds, trcDS
  377.         rep  movsw     ; move it
  378.         pop  ds
  379.      .endif
  380.  
  381.      ENABLE
  382.   .endif
  383.   xor  ax,ax
  384.   ret
  385. Gio_qtt endp
  386.  
  387. ;------------------------------------------------------------------------------
  388. ; Allocate or re-size trace table
  389. ;  fs:di = PSTTS packet
  390. ;------------------------------------------------------------------------------
  391. public Gio_stts     ; Set Trace Table Size
  392. Gio_stts proc
  393. entryCount equ bp-4
  394. traceSize equ bp-2
  395.   mov  bx, word ptr fs:[di].pstts_size
  396.  
  397. ; free the old one
  398.  
  399. initentry:
  400.   enter 4,0
  401.   push bx
  402.   .if  <trcSize ne 0> ; free old buffer
  403.      mov  trcSize, 0  ; stop traceing
  404.      mov  ax, trcPhys_h
  405.      mov  bx, trcPhys_l
  406.      mov  dl, DevHlp_FreePhys
  407.      call Device_Help
  408.   .endif
  409.   pop  bx
  410.  
  411. ; allocate new size
  412. ; bx = size in dwords
  413.  
  414.   .if  <zero bx>
  415.      xor ax,ax         ; stop tracing
  416.   .else
  417.      .if  <bx a 4000>
  418.         mov  bx, 4000  ; limit how big
  419.      .endif
  420.      .if  <bx lt 10>
  421.         mov  bx, 10    ; limit how small
  422.      .endif
  423.      mov  [entryCount],bx
  424.      mov  ax, 0
  425.      sal  bx, 2        ; convert to byte count
  426.      mov  [traceSize],bx
  427.      mov  dh, 0        ; above 1 meg
  428.      mov  dl, DevHlp_AllocPhys
  429.      call Device_Help
  430.      .if  nc
  431.         mov  trcPhys_h,ax
  432.         mov  trcPhys_l,bx
  433.         mov  cx, [traceSize]
  434.         mov  si, trcDS
  435.         mov  dl, DevHlp_PhysToGDTSelector
  436.         call Device_Help
  437.         .if  nc
  438.            mov  ax, [traceSize]
  439.            sub  ax, 8        ; back up and waste one entry
  440.            mov  trcNext , ax
  441.            mov  trcStart, ax
  442.            mov  trcWrap, 0
  443.            mov  ax, [entryCount]
  444.            mov  trcSize, ax
  445.            xor  ax, ax
  446.         .endif
  447.      .endif
  448.      .if c
  449.         mov  ax,STERR+STECODE
  450.      .endif
  451.   .endif
  452.   leave
  453.   ret
  454. Gio_stts endp
  455.  
  456. CSEG ends
  457.  
  458. ;-- INITIALIZATION ROUTINE ----------------------------------------------------
  459. ;
  460. ;------------------------------------------------------------------------------
  461. CSEGI SEGMENT
  462.      ASSUME    CS:CGROUP, SS:nothing, ES:nothing, DS:DGROUP
  463. ;------------------------------------------------------------------------------
  464. ; prepare for trace
  465. ;------------------------------------------------------------------------------
  466. public Trc_Init
  467. Trc_Init Proc  Near
  468.   push  es     ; save parmline
  469.   push  di
  470.  
  471. ; allocate a selector to be used for the trace buffer
  472.  
  473.   push  ds
  474.   pop   es
  475.   mov   di, offset trcDS
  476.   mov   cx, 1
  477.   mov   dl, DevHlp_AllocGDTSelector
  478.   call  Device_Help
  479.  
  480.   pop   di     ; restore parmline
  481.   pop   es
  482.  
  483. ; see if trace= is specified
  484.  
  485.   call    skip_to_white             ; Skip driver name
  486.  
  487. pcl_loop:
  488.   call    skip_white                ; Skip any/all blanks til 1st char
  489.   mov     al, es:[di]               ; Get 1st parameter/keyword char
  490.   cmp     al, CR                    ; Scan remaining line chars for
  491.   jz      pcl_loop_exit             ; Keywords and parameters
  492.   cmp     al, LF                    ; until end of line condition
  493.   jz      pcl_loop_exit             ; reached
  494.   cmp     al, 0
  495.   jz      pcl_loop_exit
  496.  
  497.   cld
  498.   call    DParse
  499.   jmp     pcl_loop
  500. pcl_loop_exit:
  501.  
  502. ; allocate a trace table at init time if requested
  503.  
  504.   mov  bx, cnf_trace
  505.   .if  <nonzero bx>
  506.      call initentry
  507.   .endif
  508.  
  509.   ret
  510. Trc_Init  EndP
  511.  
  512. ;----------------------------------------------------------------------------
  513. ; Parses command line options given on CONFIG.SYS's DEVICE= line
  514. ; Look for trace parameter, ignore others.
  515. ;  es:[di] => possible command line option
  516. ;----------------------------------------------------------------------------
  517. temp_di equ     [bp]-2
  518. public Dparse
  519. Dparse  proc near
  520.   enter   2,0
  521.  
  522.   call    skip_white
  523.   mov     temp_di, di
  524.  
  525. ; look for TRACE= parm
  526.  
  527.   mov     si, offset opt_trace
  528.   call    str_i_cmp
  529.   .if     <zero ax> ; found TRACE=, get type number
  530.      mov  temp_di,di
  531.      call get_dec_num
  532.      .if <di ne temp_di>
  533.         mov  cnf_trace, ax
  534.      .endif
  535.   .endif
  536.  
  537. parse_exit:
  538.   call    skip_to_white
  539.   leave
  540.   ret
  541. Dparse endp
  542.  
  543. CSEGI    ENDS
  544. end
  545.