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.

325 lines
5.4 KiB

  1. ; Watson.asm - Helper routines for Sherlock
  2. memS = 1
  3. ?PLM = 0
  4. ?WIN = 0
  5. ?QUIET = 1
  6. include cmacros.inc
  7. include toolhelp.inc
  8. .286p
  9. .model small
  10. .data?
  11. ;newStack db 4096 dup (?)
  12. externW newsp
  13. externW cpu32
  14. externW retflag
  15. ;newsp = (newStack+4096)
  16. externW regs
  17. val = 0
  18. irp reg, <ax,cx,dx,bx,sp,bp,si,di,ip,flag,es,cs,ss,ds,fs,gs,int>
  19. r&reg = val
  20. val = val+2
  21. endm
  22. externD regs32
  23. val = 0
  24. irp reg, <ax, cx, dx, bx, sp, bp, si, di, ip, flags>
  25. re&reg = val
  26. val = val+4
  27. endm
  28. .code
  29. externP Sherlock
  30. cProc SegLimit, <PUBLIC>,
  31. parmW segVal
  32. cBegin
  33. cmp [cpu32], 0
  34. jnz SegLimit32
  35. xor ax, ax
  36. xor dx, dx
  37. lsl ax, [segVal]
  38. jmp short done
  39. SegLimit32:
  40. .386p
  41. push edx ; save EDX.hi
  42. pop dx
  43. push eax ; save EAX.hi
  44. pop ax
  45. xor edx, edx ; return 0 if failure
  46. movzx eax, [segVal]
  47. lsl edx, eax ; EDX = return result
  48. push dx ; push ans.lo
  49. pop eax ; EAX.lo = ans.lo, EAX.hi restored
  50. push edx ; stack is ans.lo, ans.hi, EDX.hi
  51. pop dx ; discard ans.lo (already in EAX.lo)
  52. pop edx ; DX has ans.hi, EDX.hi restored
  53. .286p
  54. done:
  55. cEnd
  56. cProc SegBase, <PUBLIC>
  57. parmW segVal
  58. cBegin
  59. mov ax, 6
  60. mov bx, [segVal]
  61. or bx, bx ; DPMI whines on a 0 selector
  62. jz baseBad
  63. int 31h ; call DPMI
  64. jnc baseOK
  65. baseBad:
  66. xor dx, dx
  67. xor cx, cx
  68. baseOK:
  69. mov ax, dx
  70. mov dx, cx
  71. cEnd
  72. cProc SegRights, <PUBLIC>
  73. parmW segVal
  74. cBegin
  75. lar ax, [segVal]
  76. jz rightOK
  77. xor ax, ax
  78. rightOK:
  79. cEnd
  80. externNP CallMeToo
  81. cProc CallMe,<PUBLIC,FAR> ; I was a big Blondie fan
  82. ; parmD foo ; BP+6, BP+8
  83. ; parmW id ; BP+10
  84. cBegin nogen
  85. push bp
  86. mov bp, sp
  87. id equ word ptr [bp+10]
  88. seg_foo equ word ptr [bp+8]
  89. off_foo equ word ptr [bp+6]
  90. xor ax, ax
  91. cmp id, NFY_LOGERROR
  92. jz cm_stay
  93. cmp id, NFY_LOGPARAMERROR
  94. ; jz cm_stay
  95. ; cmp id, NFY_OUTSTR
  96. jnz cm_go ; "if I go there will be trouble"
  97. cm_stay: ; "if I stay it will be double"
  98. mov ax, DGROUP
  99. mov bx, ss
  100. cmp ax, bx
  101. jz cm_go
  102. push ds ; I like The Clash too
  103. mov ds, ax
  104. mov dx, SEG_foo
  105. mov cx, OFF_foo
  106. mov bx, id
  107. mov [regs+rss], ss ; for stack trace, and to continue
  108. mov [regs+rsp], sp
  109. mov [regs+rbp], bp
  110. mov [regs+rcs], cs
  111. mov [regs+rip], offset cm_stay
  112. mov ss, ax
  113. mov sp, [newsp]
  114. mov bp, 0
  115. push dx
  116. push cx
  117. push bx
  118. cCall CallMeToo
  119. mov bp, [regs+rbp]
  120. mov ss, [regs+rss]
  121. mov sp, [regs+rsp]
  122. pop ds
  123. cm_go:
  124. pop bp
  125. retf 6
  126. cEnd nogen
  127. ; GPFault - called as part of gpfault chain by ToolHelp
  128. ; Ret IP Far ret back to ToolHelp fault handler
  129. ; Ret CS
  130. ; AX Saved in case prolog trashes AX
  131. ;6 IntNum Number of interrupt that occurred
  132. ; Resv Magic value, don't trash
  133. ;10 Fault IP IRET back to faulting instruction
  134. ;12 Fault CS
  135. ;14 Fault Flags
  136. fint = 6
  137. fip = 10
  138. fcs = 12
  139. fflag = 14
  140. GPFAULT proc far ; pascal
  141. public GPFAULT
  142. push ds ; save ds
  143. push ax
  144. push bp
  145. mov bp, sp
  146. mov ax, [bp+12]
  147. cmp ax, 0 ; only save regs if int Div0,
  148. jz keeper
  149. cmp ax, 6 ; invalid opcode
  150. jz keeper
  151. cmp ax, 13 ; GP fault
  152. jz keeper
  153. nokeep: pop bp ; don't like this fault, chain on
  154. pop ax
  155. pop ds
  156. ret
  157. keeper: push bx
  158. mov bx, ss
  159. mov ax, DGROUP ; and address our group
  160. cmp ax, bx
  161. pop bx
  162. je nokeep ; don't go re-entrant
  163. mov ds, ax
  164. pop [regs+rbp]
  165. pop [regs+rax] ;save AX
  166. pop [regs+rds] ; and DS in regs[]
  167. irp reg, <cx,dx,bx, sp, si,di, es,ss>
  168. mov [regs+r&reg], reg ; all but ip, flag, intNum,
  169. endm ; cs, fs, gs, int
  170. mov bp, sp ; nothing local on stack
  171. irp reg, <cs, ip, flag, int>
  172. mov bx, [bp+f&reg]
  173. mov [regs+r&reg], bx
  174. endm
  175. ; Save away 32 bit registers if required
  176. cmp [cpu32], 0
  177. jz NoSave32
  178. .386p
  179. mov ax, [regs+rax]
  180. irp reg, <eax, ecx, edx, esi, edi>
  181. mov [regs32+r&reg], reg
  182. endm
  183. irp reg, <bx, sp, bp>
  184. mov eax, e&reg
  185. mov ax, [regs+r&reg]
  186. mov [regs32+re&reg], eax
  187. endm
  188. pushfd
  189. pop [regs32+reflags]
  190. mov [regs+rfs], fs
  191. mov [regs+rgs], gs
  192. .286p
  193. NoSave32:
  194. mov ax, ds
  195. mov ss, ax
  196. mov sp, [newsp]
  197. mov bp, 0
  198. cmp ax, [regs+rss] ; can't debug ourselves
  199. jz oh_no
  200. ; Save high halves of registers if required
  201. cmp [cpu32], 0
  202. jz CallSherlock286
  203. .386p
  204. pushad
  205. call Sherlock ; Display the info
  206. mov retflag, ax
  207. popad
  208. mov eax, [regs32+reax]
  209. .286p
  210. jmp short DoneWithSherlock
  211. CallSherlock286:
  212. pusha
  213. call Sherlock ; Display the info
  214. mov retflag, ax
  215. popa
  216. DoneWithSherlock:
  217. mov ax, retflag
  218. or ax, ax ; 0 - fault, 1 = continue
  219. jz oh_no
  220. mov es, [regs+rss]
  221. mov bx, [regs+rsp]
  222. mov ax, [regs+rip]
  223. mov es:[bx+10], ax
  224. oh_no: ; restore all regs, then test again
  225. irp reg, <ax,cx,dx,bx, ss,sp, bp,si,di, es,ds>
  226. mov reg, [regs+r&reg]
  227. endm
  228. jz oh_no_2
  229. add sp, 10
  230. iret
  231. oh_no_2:
  232. ret
  233. GPFAULT endp
  234. .386p
  235. cProc GetRegs32, <PUBLIC>
  236. cBegin
  237. cEnd
  238. irp reg, <sp, bp, si, di>
  239. mov eax, [regs32+re&reg]
  240. mov ax, reg
  241. mov e&reg, eax
  242. endm
  243. irp reg, <ebx, edx, ecx, eax>
  244. mov reg, [regs32+r&reg]
  245. endm
  246. cEnd
  247. .286p
  248. cProc GetTimeDate, <PUBLIC>
  249. parmW buf
  250. cBegin
  251. mov ah, 2ah
  252. int 21h
  253. mov bx, [buf]
  254. mov [bx], ax
  255. mov [bx+2], cx
  256. mov [bx+4], dx
  257. mov ah, 2ch
  258. int 21h
  259. mov bx, [buf]
  260. mov [bx+6], cx
  261. mov [bx+8], dx
  262. cEnd
  263. cProc FindFile, <PUBLIC>
  264. parmW buf
  265. parmW _name
  266. localW dtaSeg
  267. localW dtaOff
  268. cBegin
  269. mov ah, 2fh ;get DTA
  270. int 21h
  271. mov [dtaSeg], es
  272. mov [dtaOff], bx
  273. mov ah, 1ah
  274. mov dx, buf
  275. int 21h ; set DTA to caller's buffer
  276. mov ah, 4eh ; find first matching file
  277. mov cx, 0
  278. mov dx, _name
  279. int 21h
  280. sbb ax, ax
  281. push ax
  282. push ds ; restore DTA
  283. mov ds, [dtaSeg]
  284. mov dx, [dtaOff]
  285. mov ah, 1ah
  286. int 21h
  287. pop ds
  288. pop ax ; return value, 0 == OK
  289. cEnd
  290. end