Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

492 lines
13 KiB

  1. PAGE ,132
  2. TITLE DXBUG.ASM -- Dos Extender Debug Services
  3. ; Copyright (c) Microsoft Corporation 1989-1991. All Rights Reserved.
  4. ;****************************************************************
  5. ;* *
  6. ;* DXBUG.ASM - Dos Extender Debug Services *
  7. ;* *
  8. ;****************************************************************
  9. ;* *
  10. ;* Module Description: *
  11. ;* *
  12. ;* This module contains protect mode debug services for the *
  13. ;* DOS extender. *
  14. ;* *
  15. ;****************************************************************
  16. ;* Revision History: *
  17. ;* *
  18. ;* 11/17/89 Jimmat Added TraceBug stuff for debugging on *
  19. ;* 286 machines. *
  20. ;* 03/09/89 JimMat Initial version. *
  21. ;* *
  22. ;****************************************************************
  23. .286p
  24. .287
  25. ifndef DEBUG
  26. DEBUG = 0
  27. endif
  28. ; -------------------------------------------------------
  29. ; INCLUDE FILE DEFINITIONS
  30. ; -------------------------------------------------------
  31. include segdefs.inc
  32. include gendefs.inc
  33. include pmdefs.inc
  34. if DEBUG ;********** ENTIRE FILE IS DEBUG CODE ***********
  35. ; -------------------------------------------------------
  36. ; DATA SEGMENT DEFINITIONS
  37. ; -------------------------------------------------------
  38. DXDATA segment
  39. extrn fDebug:BYTE
  40. extrn fTraceBug:WORD
  41. ;******************************************************************************
  42. ;
  43. ; DXOutputDebugStr
  44. ;
  45. ; Basically stolen from Windows/386 code by Ralph Lipe -- hacked up for
  46. ; 286 instead of 386. Here in RalphL's own words is the description:
  47. ;
  48. ; DESCRIPTION:
  49. ; The following code is not pretty but it does what it needs to. It will
  50. ; only be included in DEBUG versions of Win386. It accepts an ASCIIZ
  51. ; string which it will output to the COM1 serial port. If the string
  52. ; contains #(Register) (for example #AX) then the value of that register
  53. ; will be output. It will not work for segment registers.
  54. ;
  55. ; If the string contains ?(Register)[:(Register)] (for example ?AX or
  56. ; ?AX:BX) then the value of the register(s) is passed to the debugger
  57. ; to display the label nearest to the given address. (It, also, will
  58. ; not work with segment registers. If ?AX is given, then the segment is
  59. ; assumed to be the DX code segment.
  60. ;
  61. ; ENTRY:
  62. ; DS:SI -> ASCIIZ string
  63. ;
  64. ; EXIT:
  65. ; All registers and flags trashed
  66. ;
  67. ; ASSUMES:
  68. ; This procedure was called by the Trace_Out macro. It assumes that
  69. ; the stack is a pushad followed by a FAR call to this procedure.
  70. ;
  71. ;------------------------------------------------------------------------------
  72. Reg_Offset_Table LABEL WORD ; Order of PUSHA
  73. dw "DI"
  74. dw "SI"
  75. dw "BP"
  76. dw "SP"
  77. dw "BX"
  78. dw "DX"
  79. dw "CX"
  80. dw "AX"
  81. DXDATA ends
  82. DXCODE segment
  83. assume cs:DXCODE
  84. public DXOutDebugStr
  85. DXOutDebugStr proc far
  86. push bp
  87. mov bp, sp ; Assumes BP+6 = Pusha
  88. pushf
  89. push es
  90. push SEL_DXDATA ; Address our own data seg
  91. pop es
  92. assume ds:NOTHING,es:DGROUP
  93. cld
  94. cli
  95. OSC1_Loop:
  96. lodsb ; Get the next character
  97. test al, al ; Q: End of string?
  98. jz short OSC1_Done ; Y: Return
  99. cmp al, "#" ; N: Q: Special register out?
  100. je SHORT OSC1_Hex ; Y: Find out which one
  101. cmp al, "?" ; Q: special lable out?
  102. je short OSC1_Label ; Y: find out which one
  103. cmp al, "@" ; Q: special string out?
  104. je short OSC1_Str
  105. OSC1_out:
  106. xor ah, ah ; N: Send char to COM
  107. call Out_Debug_Chr
  108. jmp OSC1_Loop ; Loop until done
  109. OSC1_Hex:
  110. call Get_Register
  111. jnc short OSC1_not_special
  112. cmp bl, 2 ; Q: Word output?
  113. jb SHORT OSC1_Out_Byte ; N: display byte
  114. OSC1_Out_Word:
  115. call Out_Hex_Word ; Display AX in hex
  116. jmp OSC1_Loop ; Output next char
  117. OSC1_Out_Byte:
  118. xchg al, ah ; swap bytes to print just
  119. call Out_Hex_Byte ; the low one!
  120. jmp OSC1_Loop ; Output next char
  121. OSC1_Label:
  122. call Get_Register
  123. jc short show_label
  124. OSC1_not_special:
  125. lodsb ; Get special char again
  126. jmp OSC1_out ; display it, and continue
  127. show_label:
  128. mov cx, ax ; save first value
  129. cmp byte ptr [si], ':' ;Q: selector separator?
  130. jne short flat_offset ; N:
  131. lodsb ; Y: eat the ':'
  132. call Get_Register ; and attempt to get the selector
  133. jc short sel_offset
  134. flat_offset:
  135. mov ax, cs ; default selector value
  136. sel_offset:
  137. call Show_Near_Label
  138. jmp OSC1_Loop
  139. OSC1_Str:
  140. call Get_Register
  141. jnc short OSC1_not_special
  142. mov cx,ax
  143. cmp byte ptr [si],':'
  144. jne short no_selector
  145. lodsb
  146. push cx
  147. call Get_Register
  148. pop cx
  149. xchg ax,cx
  150. jc short got_sel_off
  151. mov cx,ax
  152. no_selector:
  153. mov ax,ds ; default selector for strings
  154. got_sel_off:
  155. call Show_String
  156. jmp OSC1_Loop
  157. OSC1_Done: ; The end
  158. pop es
  159. npopf
  160. pop bp
  161. ret 10h
  162. DXOutDebugStr endp
  163. ;******************************************************************************
  164. ;
  165. ; Get_Register
  166. ;
  167. ; DESCRIPTION:
  168. ;
  169. ; ENTRY:
  170. ;
  171. ; EXIT: Carry set if register value found
  172. ; AX = register value
  173. ; BL = value size (1, 2, 4)
  174. ;
  175. ; USES:
  176. ;
  177. ;==============================================================================
  178. Get_Register proc near
  179. push si ; Save string pointer
  180. xor ax, ax ; Zero AX
  181. mov bl, 2 ; BL = 2 (assume word output)
  182. call Load_Up_Char ; Get 1st char
  183. mov ah, al ; Move 1st char to AH
  184. call Load_Up_Char ; Get second char
  185. cmp al, 'L' ; Q: "L" (ie AL, BL, etc)?
  186. jne short OSC1_WORD ; N: word reg
  187. mov al, 'X' ; Y: change to X for pos match
  188. mov bl, 1 ; BL = 1 -- byte output
  189. OSC1_WORD:
  190. xor di, di ; DI = 0
  191. mov cx, 8 ; Size of a pusha
  192. OSC1_Special_Loop:
  193. push di
  194. shl di,1
  195. cmp ax, Reg_Offset_Table[di] ; Q: Is this the register?
  196. pop di
  197. je SHORT OSC1_Out_Reg ; Y: Output it
  198. inc di ; N: Try the next one
  199. loop OSC1_Special_Loop ; until CX = 0
  200. OSC1_Ignore_Special: ; OOPS! backup and ignore special
  201. pop si ; Restore original string ptr
  202. dec si ; back up to special char
  203. clc
  204. jmp short gr_exit
  205. OSC1_Out_Reg:
  206. push di
  207. shl di,1
  208. mov ax, SS:[bp.6][di] ; AX = Value to output
  209. pop di
  210. add sp, 2 ; Trash pushed SI
  211. cmp bl, 2 ;Q: byte or word value?
  212. je short value_fnd ; jump if word value
  213. xor ah, ah ; clear ah, if byte value
  214. value_fnd:
  215. stc
  216. gr_exit:
  217. ret
  218. Get_Register endp
  219. ;******************************************************************************
  220. ;
  221. ; Load_Up_Char
  222. ;
  223. ; Moves the character at DS:SI into AL and converts it to an upper case
  224. ; character. SI is incremented.
  225. ;
  226. ;------------------------------------------------------------------------------
  227. Load_Up_Char proc near
  228. lodsb
  229. cmp al, "Z"
  230. jb SHORT LUC_Done
  231. sub al, "a" - "A"
  232. LUC_Done:
  233. ret
  234. Load_Up_Char endp
  235. ;******************************************************************************
  236. ;
  237. ; Out_Hex_Word
  238. ;
  239. ; Outputs the value in AX to the COM port in hexadecimal.
  240. ;
  241. ;------------------------------------------------------------------------------
  242. Out_Hex_Word proc near
  243. rol ax, 4
  244. call Out_Hex_Char
  245. rol ax, 4
  246. call Out_Hex_Char
  247. Out_Hex_Byte:
  248. rol ax, 4
  249. call Out_Hex_Char
  250. rol ax, 4
  251. call Out_Hex_Char
  252. ret
  253. Out_Hex_Word endp
  254. ;******************************************************************************
  255. ;
  256. ; Out_Hex_Char
  257. ;
  258. ; Outputs the low nibble in AL to the COM port.
  259. ;
  260. ;------------------------------------------------------------------------------
  261. DXDATA segment
  262. Hex_Char_Tab LABEL BYTE
  263. db "0123456789ABCDEF"
  264. DXDATA ends
  265. Out_Hex_Char proc near
  266. push ax
  267. push bx
  268. mov bx, ax
  269. and bx, 1111b
  270. mov al, Hex_Char_Tab[bx]
  271. call Out_Debug_Chr
  272. pop bx
  273. pop ax
  274. ret
  275. Out_Hex_Char endp
  276. ;******************************************************************************
  277. ;
  278. ; Out_Debug_Chr
  279. ;
  280. ; DESCRIPTION:
  281. ;
  282. ; ENTRY:
  283. ; AL contains character to output
  284. ;
  285. ; EXIT:
  286. ;
  287. ; USES:
  288. ; Nothing
  289. ;
  290. ;==============================================================================
  291. Out_Debug_Chr proc near
  292. assume ds:nothing,es:DGROUP
  293. if 0
  294. push ax
  295. mov ax,cs
  296. cmp ax,SEL_DXCODE0 ; Are we in real mode?
  297. pop ax
  298. jne out_com
  299. cmp fDebug,0 ; debugger installed?
  300. je out_com ; N: go output it ourselves
  301. push ax
  302. push dx
  303. mov dl, al
  304. mov ax, DS_Out_Char
  305. int Debug_Serv_Int
  306. pop dx
  307. pop ax
  308. endif
  309. ret
  310. Out_Debug_Chr endp
  311. ;******************************************************************************
  312. ;
  313. ; Show_Near_Label
  314. ;
  315. ; DESCRIPTION: call the debugger to display a label less than or equal
  316. ; to the given address
  317. ;
  318. ; ENTRY: AX is selector, CX is offset of address to try to find
  319. ; a symbol for
  320. ; ES selector to DOSX data segment
  321. ; EXIT:
  322. ;
  323. ; USES:
  324. ;
  325. ;==============================================================================
  326. Show_Near_Label proc near
  327. if 0
  328. push ax
  329. mov ax,cs
  330. cmp ax,SEL_DXCODE0 ; Are we in real mode?
  331. pop ax
  332. jne Show_Near_Label_ret
  333. cmp es:idCpuType,3 ;use 32 bit regs?
  334. jae debug_386
  335. push ax ;on a 286, use 16 bit regs
  336. push bx
  337. push cx
  338. mov bx,cx
  339. mov cx,ax
  340. mov ax,DS_Out_Symbol
  341. int Debug_Serv_Int
  342. pop cx
  343. pop bx
  344. pop ax
  345. endif
  346. ret
  347. if 0
  348. debug_386:
  349. .386p
  350. push eax
  351. push ebx
  352. push ecx
  353. mov bx, cx
  354. movzx ecx, ax ;WDEB386 wants a 32 bit offset
  355. mov ax, DS_Out_Symbol
  356. int Debug_Serv_Int
  357. pop ecx
  358. pop ebx
  359. pop eax
  360. ret
  361. .286p
  362. Show_Near_Label_ret:
  363. endif
  364. Show_Near_Label endp
  365. ;******************************************************************************
  366. ;
  367. ; Show_String
  368. ;
  369. ; DESCRIPTION: Display an asciiz string
  370. ;
  371. ; ENTRY: AX is selector, CX is offset of address to find string
  372. ;
  373. ; EXIT:
  374. ;
  375. ; USES:
  376. ;
  377. ;==============================================================================
  378. Show_String proc near
  379. if 0
  380. push ax
  381. push ds
  382. push si
  383. mov ds,ax
  384. mov si,cx
  385. xor ax,ax
  386. @@:
  387. lodsb
  388. or al,al
  389. jz @f
  390. call Out_Debug_Chr
  391. jmp short @b
  392. @@:
  393. pop si
  394. pop ds
  395. pop ax
  396. endif
  397. ret
  398. Show_String endp
  399. DXCODE ends
  400. endif ; DEBUG
  401. end