home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP7 / WINDBG.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-07-01  |  4.5 KB  |  249 lines

  1.     page    78,132
  2.     title    Windows debugging monitor
  3.  
  4.     .sall
  5. ?PLM    =    0
  6. ?WIN    =    0
  7.     .xlist
  8.     include    cmacros.inc
  9.     .list
  10.  
  11.     .model    small
  12.     .code
  13.     .data
  14. InitSeg segment byte public
  15. InitSeg ends
  16.  
  17. DGroup    group    _TEXT,_DATA,InitSeg
  18.  
  19.     .code
  20.     assume    cs:DGroup,ds:DGroup,es:DGroup,ss:DGroup
  21.  
  22.     extrn    Monitor:near,PrintMes:near,OutCh:near,Out16:near,Hex:near
  23.     extrn    CrLf:near
  24.  
  25. WinMsg        db    "WinMsg"," "+80H
  26. LoadMsg        db    " Load"," "+80H
  27. LoadLabs    db    " Ordinal", " "+80H
  28.         db     " Segment", " "+80H
  29.         db     " Instance", " "+80H
  30. MoveLabs    db    " Segment moving from", " "+80H
  31.         db    " to", " "+80H
  32. DiscardMsg    db    " Discard segment", " "+80H
  33. InitHeapMsg    db    " Heap initialized to", " "+80H
  34. PrintMsg    db    " String:", " "+80H
  35. StartProgMsg    db    " Start program Id", " "+80H
  36. EndProgMsg    db    " End program Id", " "+80H
  37. EndFocusMsg    db    " End", " "+80H
  38. StartFocusMsg    db    " Start", " "+80H
  39. FocusMsg    db    "focus DGroup", " "+80H
  40.         db    " Id", " "+80H
  41. UnknownMsg    db    " Use unknown", " "+80H
  42.  
  43. WinSig    label    byte
  44.     db    0E9H            ;near JMP
  45.     dw    WinMessage - (100H - 2)
  46.     org    WinSig + 5
  47.     db    "SEGDEBUG",0
  48. cbWinSig    =    $ - WinSig
  49.  
  50. tWinDisp    label    word
  51.     dw    WinMsg0
  52.     dw    WinMsg1
  53.     dw    WinMsg2
  54.     dw    WinMsg3
  55.     dw    WinMsg4
  56.     dw    WinMsg5
  57.     dw    WinMsg6
  58.     dw    WinMsg7
  59.     dw    WinMsg8
  60.     dw    WinMsg9
  61.     dw    WinMsg10
  62.     dw    WinMsg11
  63.     dw    WinMsg12
  64.     dw    WinMsg13
  65.     dw    WinMsg14
  66. LastMsg    =    ($ - tWinDisp)/2
  67.     dw    WinMsg15        ;Unused
  68.  
  69. cProc    WinMessage    <FAR>,<ds,si,di>
  70. ParmW    Action
  71. ParmW    p1
  72. ParmW    p2
  73. ParmW    Ordinal
  74. ParmW    SegVal
  75. ParmW    Instance
  76. cBegin
  77.     mov    ax,[Action]
  78.     push    cs
  79.     pop    ds
  80.     push    cs
  81.     pop    es
  82.     mov    si,offset DGroup:WinMsg
  83.     call    PrintMes
  84.     mov    ax,[Action]
  85.     mov    bx,ax
  86.     cmp    ax,10            ;Two digit number?
  87.     jb    OneDigit
  88.     aam                ;Convert to unpacked BCD
  89.     xchg    al,ah
  90.     or    al,"0"
  91.     call    OutCh
  92.     xchg    al,ah
  93. OneDigit:
  94.     or    al,"0"
  95.     call    OutCh
  96.     cmp    bx,LastMsg        ;Bigger than our table?
  97.     jbe    MsgOk
  98.     mov    bx,LastMsg+1        ;Limit to end of table
  99. MsgOk:
  100.     shl    bx,1            ;Index into table
  101.     jmp    [bx].tWinDisp
  102.  
  103. WinMsg0:
  104. ;Load new segment
  105.     mov    si,offset DGroup:LoadMsg
  106.     call    PrintMes
  107.     lds    si,dword ptr [p1]        ;First arg is pointer to name
  108. PrintName:
  109.     lodsb
  110.     or    al,al
  111.     jz    NameDone
  112.     call    OutCh
  113.     jmp    PrintName
  114.  
  115. ;SymDeb handles messages 0 - 9.  Here's labels for the rest in case we figure
  116. ;out what they're for.
  117.  
  118. WinMsg5:
  119. WinMsg6:
  120. WinMsg7:
  121. WinMsg8:
  122. WinMsg9:
  123. WinMsg10:
  124. WinMsg15:
  125. ;A message we don't understand
  126.     mov    si,offset DGroup:UnknownMsg
  127.     call    PrintMes
  128. ;Print two word arguments
  129.     mov    dx,[p1]
  130.     call    Out16
  131.     mov    al,","
  132.     call    OutCh
  133.     mov    dx,[p2]
  134.     call    Out16
  135. WinMessageExit:
  136.     call    CrLf
  137. NoMessage:
  138. cEnd    WinMessage
  139.  
  140. NameDone:
  141.     push    cs
  142.     pop    ds
  143.     mov    si,offset DGroup:LoadLabs
  144.     call    PrintMes        ;Print label
  145.     mov    ax,[Ordinal]
  146.     call    Hex            ;Print 2 hex digits
  147.     call    PrintMes
  148.     mov    dx,[SegVal]
  149.     call    Out16
  150.     call    PrintMes
  151.     mov    ax,[Instance]
  152.     call    Hex
  153.     jmp    WinMessageExit
  154.  
  155. WinMsg1:
  156. ;Memory movement
  157.     cmp    [p2],0            ;Is destination zero?
  158.     jz    WinMsg2            ;Same as Msg 2, Discard
  159.     mov    si,offset DGroup:MoveLabs
  160.     call    PrintMes
  161.     mov    dx,[p1]            ;First arg is old location
  162.     call    Out16
  163.     call    PrintMes
  164.     mov    dx,[p2]
  165.     call    Out16
  166.     jmp    WinMessageExit
  167.  
  168. WinMsg2:
  169. ;Discard segment
  170.     mov    si,offset DGroup:DiscardMsg
  171.     call    PrintMes
  172.     mov    dx,[p1]            ;First arg is segment
  173.     call    Out16
  174.     jmp    WinMessageExit
  175.  
  176. WinMsg3:
  177. ;Heap initialization
  178.     mov    si,offset DGroup:InitHeapMsg
  179.     call    PrintMes
  180.     mov    dx,[p1]            ;First arg is pGlobalHeap
  181.     call    Out16
  182.     jmp    WinMessageExit
  183.  
  184. WinMsg4:
  185. ;Print message
  186.     mov    si,offset DGroup:PrintMsg
  187.     call    PrintMes
  188.     lds    si,dword ptr [p1]
  189.     mov    cx,[Ordinal]
  190.     jcxz    WinMessageExit
  191. PrintLoop:
  192.     lodsb
  193.     call    OutCh
  194.     loop    PrintLoop
  195.     push    cs
  196.     pop    ds
  197.     jmp    WinMessageExit
  198.  
  199. WinMsg11:
  200. ;Start program
  201.     mov    si,offset DGroup:StartProgMsg
  202.     jmp    short ProgMsg
  203.  
  204. WinMsg12:
  205. ;End program
  206.     mov    si,offset DGroup:EndProgMsg
  207. ProgMsg:
  208.     call    PrintMes
  209.     mov    ax,[p1]            ;First arg is ordinal
  210.     call    Hex
  211.     jmp    WinMessageExit
  212.  
  213. WinMsg13:
  214. ;End focus
  215.     mov    si,offset DGroup:EndFocusMsg
  216.     call    PrintMes
  217.     mov    si,offset DGroup:FocusMsg
  218.     jmp    short NewFocus
  219.  
  220. WinMsg14:
  221. ;Start focus
  222.     mov    si,offset DGroup:StartFocusMsg
  223.     call    PrintMes
  224. NewFocus:
  225.     call    PrintMes
  226.     mov    dx,[p1]            ;First arg is DGroup
  227.     call    Out16
  228.     call    PrintMes
  229.     mov    ax,[p2]            ;Second arg is ID
  230.     call    Hex
  231.     jmp    WinMessageExit
  232.  
  233.  
  234. ;************************************************************
  235.  
  236. InitSeg    segment
  237.     assume    cs:DGroup,ds:Dgroup
  238.  
  239.     push    cs
  240.     pop    es
  241.     mov    di,offset DGroup:Monitor - 5    ;Start of signature area
  242.     mov    si,offset DGroup:WinSig
  243.     mov    cx,cbWinSig
  244. rep    movsb
  245. ;Will now fall into next module's init code
  246. InitSeg    ends
  247.  
  248.     end
  249.