Leaked source code of windows server 2003
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.

2208 lines
48 KiB

  1. TITLE LDDEBUG - Debugger interface procedures
  2. include kernel.inc
  3. include newexe.inc
  4. include tdb.inc
  5. include protect.inc
  6. include wow.inc
  7. include dbgsvc.inc
  8. include bop.inc
  9. ifdef WOW
  10. include vint.inc
  11. endif
  12. ;.386p
  13. HEAPDUMP = 0
  14. DEBUGOFFSET equ 000FBH
  15. INTOFFSET equ 4*3+2
  16. DEBUGCALL MACRO
  17. call MyDebugCall
  18. ENDM
  19. DataBegin
  20. externW winVer
  21. externW wDefRip
  22. externB Kernel_Flags
  23. externB Kernel_InDOS
  24. externB fDW_Int21h
  25. externW pGlobalHeap
  26. externW hGlobalHeap
  27. externD ptrace_dll_entry
  28. externD lpfnToolHelpProc
  29. externD pKeyboardSysReq
  30. externW curTDB
  31. externW wExitingTDB
  32. externW <Win_PDB, topPDB>
  33. ifdef WOW
  34. externD FastBop
  35. externW DebugWOW
  36. externW hExeHead
  37. externW gdtdsc
  38. endif; WOW
  39. debugseg dw 0
  40. IF KDEBUG
  41. externB fKTraceOut
  42. ENDIF
  43. DataEnd
  44. ifdef WOW
  45. externFP GetModuleFileName
  46. externFP GetModuleHandle
  47. externFP WOWOutputDebugString
  48. externFP WOWNotifyTHHOOK
  49. endif
  50. ifdef FE_SB
  51. ; _TEXT code segment is over flow with debug 386 version
  52. ; GetOwnerName moves to _MISCTEXT from _TEXT segment with DBCS flag
  53. externFP FarGetOwner
  54. endif ; FE_SB
  55. sBegin CODE
  56. assumes CS,CODE
  57. externNP get_arena_pointer32
  58. externNP GetOwner
  59. externNP genter
  60. externNP get_physical_address
  61. externNP ValidatePointer
  62. sEnd CODE
  63. sBegin INITCODE
  64. assumes CS,CODE
  65. assumes DS,NOTHING
  66. assumes ES,NOTHING
  67. ;-----------------------------------------------------------------------;
  68. ; debuginit ;
  69. ; ;
  70. ; Returns a non zero value in AX if debugger is resident. ;
  71. ; If the debugger is present a distinquished string of "SEGDEBUG",0 ;
  72. ; will be found at 100H off of the interrupt vector segment (int 3). ;
  73. ; ;
  74. ; Arguments: ;
  75. ; None. ;
  76. ; ;
  77. ; Returns: ;
  78. ; AX =! 0 if debugger resident. ;
  79. ; ;
  80. ; Error Returns: ;
  81. ; ;
  82. ; Registers Preserved: ;
  83. ; ;
  84. ; Registers Destroyed: ;
  85. ; ;
  86. ; Calls: ;
  87. ; ;
  88. ; History: ;
  89. ; ;
  90. ; Thu Nov 13, 1986 02:03:51p -by- David N. Weise [davidw] ;
  91. ; Added this nifty comment block. ;
  92. ;-----------------------------------------------------------------------;
  93. assumes ds,nothing
  94. assumes es,nothing
  95. cProc DebugInit,<PUBLIC,NEAR>,<es,si,di>
  96. cBegin
  97. CheckKernelDS
  98. ReSetKernelDS
  99. DebInt 4fh
  100. cmp ax, 0F386h
  101. jne short no_debugger
  102. inc debugseg
  103. or Kernel_flags[2],KF2_SYMDEB
  104. no_debugger:
  105. cEnd
  106. ;-----------------------------------------------------------------------;
  107. ; DebugDebug
  108. ;
  109. ;
  110. ; Entry:
  111. ;
  112. ; Returns:
  113. ;
  114. ; Registers Destroyed:
  115. ;
  116. ; History:
  117. ; Tue 21-Jun-1988 13:10:41 -by- David N. Weise [davidw]
  118. ;
  119. ;-----------------------------------------------------------------------;
  120. assumes ds,nothing
  121. assumes es,nothing
  122. cProc DebugDebug,<PUBLIC,NEAR>
  123. cBegin nogen
  124. push ds
  125. SetKernelDS
  126. ifdef WOW
  127. call WOWNotifyTHHOOK
  128. ; Tell the debugger where it can poke around for kernel data structure info
  129. mov cx, hGlobalHeap
  130. mov dx, hExeHead
  131. push DBG_WOWINIT
  132. FBOP BOP_DEBUGGER,,FastBop
  133. add sp,+2
  134. else
  135. test Kernel_Flags[2],KF2_SYMDEB or KF2_PTRACE
  136. jz short dd_done
  137. ; Tell the debugger where it can poke around for kernel data structure info
  138. push ax
  139. push bx
  140. push cx
  141. push dx
  142. mov bx,winVer
  143. mov cx,dataOffset hGlobalHeap
  144. mov dx,ds
  145. DebInt 5ah
  146. pop dx
  147. pop cx
  148. pop bx
  149. pop ax
  150. UnSetKernelDS
  151. dd_done:
  152. endif
  153. pop ds
  154. ret
  155. cEnd nogen
  156. ;-----------------------------------------------------------------------;
  157. ; DebugSysReq
  158. ;
  159. ; tell the keyboard driver to pass sys req through
  160. ;
  161. ; Entry:
  162. ;
  163. ; Returns:
  164. ;
  165. ; Registers Destroyed:
  166. ;
  167. ; History:
  168. ; Tue 19-Sep-1989 21:42:02 -by- David N. Weise [davidw]
  169. ; Wrote it!
  170. ;-----------------------------------------------------------------------;
  171. assumes ds,nothing
  172. assumes es,nothing
  173. cProc DebugSysReq,<PUBLIC,NEAR>
  174. cBegin nogen
  175. CheckKernelDS
  176. ReSetKernelDS
  177. mov ax,debugseg
  178. or ax,ax
  179. jz short dwr_ret
  180. cmp pKeyboardSysReq.sel,0 ; is there a keyboard driver?
  181. jz short dwr_ret
  182. mov ax,1 ; use int 2
  183. cCall pKeyboardSysReq,<ax>
  184. dwr_ret:
  185. ret
  186. cEnd nogen
  187. sEnd INITCODE
  188. ifdef FE_SB
  189. sBegin MISCCODE
  190. assumes CS,MISCCODE
  191. else ; !FE_SB
  192. sBegin CODE
  193. assumes CS,CODE
  194. endif ; !FE_SB
  195. assumes DS,NOTHING
  196. assumes ES,NOTHING
  197. ; Copyright (c) Microsoft Coropration 1989-1990. All Rights Reserved.
  198. ;
  199. ; Stolen from DOSX\DXBUG.ASM
  200. ;
  201. ; -------------------------------------------------------
  202. ; GENERAL SYMBOL DEFINITIONS
  203. ; -------------------------------------------------------
  204. Debug_Serv_Int equ 41h ;WDEB386 service codes
  205. DS_Out_Char equ 0
  206. DS_Out_Symbol equ 0fh
  207. ; Find owner of 'sel', copy name to buffer, zero terminate name
  208. ; return count of chars copied, or 0.
  209. cProc GetOwnerName,<PUBLIC,FAR>,<ds, si, di>
  210. parmW obj
  211. parmD buf
  212. parmW buflen
  213. cBegin
  214. push [obj]
  215. ifdef FE_SB
  216. call FarGetOwner
  217. else ; !FE_SB
  218. call GetOwner
  219. endif ; !FE_SB
  220. or ax, ax
  221. jz gon_exit
  222. mov ds, ax ; DS:SI points to name
  223. xor ax, ax
  224. cmp word ptr ds:[0], NEMAGIC
  225. jnz gon_exit
  226. mov si, ds:[ne_restab]
  227. lodsb ; get length
  228. cmp ax, [buflen] ; name must be smaller than buf
  229. jb @F
  230. mov ax, [buflen]
  231. dec ax
  232. @@: mov cx, ax
  233. cld
  234. les di, [buf]
  235. rep movsb
  236. mov byte ptr es:[di], 0
  237. gon_exit:
  238. cEnd
  239. ifdef FE_SB
  240. sEnd MISCCODE
  241. sBegin CODE
  242. assumes CS,CODE
  243. assumes DS,NOTHING
  244. assumes ES,NOTHING
  245. endif ; FE_SB
  246. ;******************************************************************************
  247. ;
  248. ; KOutputDebugStr
  249. ;
  250. ; Basically stolen from Windows/386 code by Ralph Lipe -- hacked up for
  251. ; 286 instead of 386. Here in RalphL's own words is the description:
  252. ;
  253. ; DESCRIPTION:
  254. ; The following code is not pretty but it does what it needs to. It will
  255. ; only be included in DEBUG versions of Kernel. It accepts an ASCIIZ
  256. ; string which it will output to the COM1 serial port. If the string
  257. ; contains #(Register) (for example #AX) then the value of that register
  258. ; will be output. It will not work for segment registers.
  259. ;
  260. ; If the string contains ?(Register)[:(Register)] (for example ?AX or
  261. ; ?AX:BX) then the value of the register(s) is passed to the debugger
  262. ; to display the label nearest to the given address. (It, also, will
  263. ; not work with segment registers. If ?AX is given, then the segment is
  264. ; assumed to be the DS data segment.
  265. ;
  266. ; Lower case register forces skip leading zeros.
  267. ;
  268. ; ENTRY:
  269. ; DS:SI -> ASCIIZ string
  270. ;
  271. ; EXIT:
  272. ; All registers and flags trashed
  273. ;
  274. ; ASSUMES:
  275. ; This procedure was called by the Trace_Out macro. It assumes that
  276. ; the stack is a pusha followed by a FAR call to this procedure.
  277. ;
  278. ;------------------------------------------------------------------------------
  279. Reg_Offset_Table LABEL WORD ; Order of PUSHA
  280. dw "DI"
  281. dw "SI"
  282. dw "BP"
  283. dw "SP"
  284. dw "BX"
  285. dw "DX"
  286. dw "CX"
  287. dw "AX"
  288. dw "SS"
  289. dw "ES"
  290. dw "DS"
  291. dw "CS"
  292. OSC1_ModName:
  293. pop ax
  294. OSC1_ModName1:
  295. push es
  296. mov es, ax
  297. cmp word ptr es:[0], NEMAGIC
  298. jz @F
  299. pop es
  300. jmps is_pdb
  301. @@: mov cx, es:[ne_restab]
  302. inc cx ; skip length byte
  303. pop es
  304. jmp Show_String ; AX:CX -> string to print
  305. OSC1_FileName:
  306. pop ax
  307. push es
  308. mov es, ax
  309. mov cx, word ptr es:[ne_crc+2]
  310. add cx, 8
  311. pop es
  312. jmp Show_String
  313. szUnk db 'Unknown',0
  314. OSC1_OwnerName:
  315. pop ax
  316. push ds
  317. push ax
  318. cCall GetOwner ; seg value already on stack
  319. pop ds
  320. or ax, ax
  321. jnz OSC1_ModName1
  322. is_pdb: mov ax, cs
  323. mov cx, CodeOffset szUnk
  324. jmp Show_String
  325. OSC1_Custom:
  326. call Get_Register
  327. jnc short OSC1_not_special
  328. or ax, ax
  329. jz short OSC1_not_special
  330. push ax
  331. lodsb
  332. cmp al, '0'
  333. jz short OSC1_ModName
  334. cmp al, '1'
  335. jz short OSC1_FileName
  336. cmp al, '2'
  337. jz short OSC1_OwnerName
  338. pop ax
  339. jmps OSC1_not_special
  340. public KOutDebugStr
  341. KOutDebugStr proc far
  342. push bp
  343. mov bp, sp ; Assumes BP+6 = Pusha
  344. sub sp, 84 ; local 80 char line + count
  345. odslen equ word ptr [bp-2]
  346. odsbuf equ byte ptr [bp-82]
  347. odszero equ word ptr [bp-84] ; flag - true if skip leading zero
  348. odsflag equ word ptr [bp-86] ; last local var - from pushf
  349. mov odslen, 0
  350. pushf
  351. push es
  352. push cs ; Address our own data seg
  353. pop es
  354. assumes ds,NOTHING
  355. assumes es,code
  356. cld
  357. FCLI
  358. OSC1_Loop:
  359. lodsb ; Get the next character
  360. test al, al ; Q: End of string?
  361. jz short OSC1_Done ; Y: Return
  362. push codeoffset OSC1_Loop
  363. cmp al, "#" ; N: Q: Special register out?
  364. je SHORT OSC1_Hex ; Y: Find out which one
  365. cmp al, "?" ; Q: special label out?
  366. je short OSC1_Label ; Y: find out which one
  367. cmp al, "@" ; Q: special string out?
  368. je short OSC1_Str
  369. cmp al, "%" ; Custom value?
  370. je short OSC1_Custom
  371. OSC1_out:
  372. xor ah, ah ; N: Send char to COM
  373. jmp Out_Debug_Chr
  374. OSC1_Hex:
  375. call Get_Register
  376. jnc short OSC1_not_special
  377. or bh, bh ; Q: Word output?
  378. jz SHORT OSC1_Out_Byte ; N: display byte
  379. OSC1_Out_Word:
  380. jmp Out_Hex_4_test ; Display AX in hex
  381. OSC1_Out_Byte:
  382. xchg al, ah ; swap bytes to print just
  383. jmp Out_Hex_2_test ; the low one!
  384. OSC1_Label:
  385. call Get_Register
  386. jc short show_label
  387. OSC1_not_special:
  388. lodsb ; Get special char again
  389. jmp OSC1_out ; display it, and continue
  390. show_label:
  391. mov cx, ax ; save first value
  392. cmp byte ptr [si], ':' ;Q: selector separator?
  393. jne short flat_offset ; N:
  394. lodsb ; Y: eat the ':'
  395. call Get_Register ; and attempt to get the selector
  396. jc short sel_offset
  397. flat_offset:
  398. mov ax, cs ; default selector value
  399. sel_offset:
  400. jmp Show_Near_Label
  401. OSC1_Str:
  402. call Get_Register
  403. jnc short OSC1_not_special
  404. mov cx,ax
  405. cmp byte ptr [si],':'
  406. jne short no_selector
  407. lodsb
  408. push cx
  409. call Get_Register
  410. pop cx
  411. xchg ax,cx
  412. jc short got_sel_off
  413. mov cx,ax
  414. no_selector:
  415. mov ax,ds ; default selector for strings
  416. got_sel_off:
  417. jmp Show_String
  418. OSC1_Done: ; The end
  419. xor ax, ax ; flush buffer
  420. call Out_Debug_Chr
  421. pop es
  422. test odsflag, 200h
  423. jz short @F
  424. FSTI
  425. @@:
  426. popf
  427. leave
  428. ret
  429. KOutDebugStr endp
  430. ;******************************************************************************
  431. ;
  432. ; Get_Register
  433. ;
  434. ; DESCRIPTION:
  435. ;
  436. ; ENTRY:
  437. ;
  438. ; EXIT: Carry set if register value found
  439. ; AX = register value
  440. ; BL = value size (1, 2, 4) (no longer true - donc)
  441. ;
  442. ; USES:
  443. ;
  444. ;==============================================================================
  445. Get_Register proc near
  446. lodsw ; get next pair of letters
  447. mov bx, ax
  448. and bx, 2020h
  449. mov [odszero], bx
  450. and ax, 0dfdfh ; to upper case
  451. xchg ah, al ; normal order (or change table?)
  452. or bx, -1 ; BH = -1
  453. cmp al, 'L' ; Q: "L" (ie AL, BL, etc)?
  454. jne short @F ; N: word reg
  455. mov al, 'X' ; Y: change to X for pos match
  456. inc bh ; BH now 0 - will clear AH below
  457. @@:
  458. xor di, di ; DI = 0
  459. mov cx, 12 ; Size of a pusha + 4 seg regs
  460. OSC1_Special_Loop:
  461. cmp ax, Reg_Offset_Table[di] ; Q: Is this the register?
  462. je SHORT OSC1_Out_Reg ; Y: Output it
  463. add di, 2 ; N: Try the next one
  464. loop OSC1_Special_Loop ; until CX = 0
  465. sub si, 3 ; restore pointer, clear carry
  466. ret
  467. OSC1_Out_Reg:
  468. mov ax, SS:[bp.6][di] ; AX = Value to output
  469. and ah, bh ; if xL, zero out high byte
  470. stc
  471. ret
  472. Get_Register endp
  473. ;******************************************************************************
  474. ;
  475. ; Out_Hex_Word
  476. ;
  477. ; Outputs the value in AX to the COM port in hexadecimal.
  478. ;
  479. ;------------------------------------------------------------------------------
  480. Out_Hex_2_test: ; Write two chars
  481. xor ah, ah
  482. cmp [odszero], 0 ; skip leading 0's?
  483. je Out_Hex_2 ; no, show 2 chars
  484. ; yes, fall through
  485. Out_Hex_4_test:
  486. cmp [odszero], 0
  487. je Out_Hex_4
  488. test ax, 0fff0h
  489. jz Out_Hex_1
  490. test ah, 0f0h
  491. jnz Out_Hex_4
  492. test ah, 0fh
  493. jz Out_Hex_2
  494. Out_Hex_3:
  495. xchg al, ah
  496. call Out_Hex_1
  497. xchg al, ah
  498. jmps Out_Hex_2
  499. Out_Hex_4:
  500. xchg al, ah
  501. call Out_Hex_2
  502. xchg al, ah
  503. Out_Hex_2:
  504. push ax
  505. shr ax, 4
  506. call Out_Hex_1
  507. pop ax
  508. Out_Hex_1:
  509. push ax
  510. and al, 0fh
  511. cmp al, 10
  512. jb @F
  513. add al, '@'-'9'
  514. @@: add al, '0'
  515. call Out_Debug_Chr
  516. pop ax
  517. ret
  518. ;******************************************************************************
  519. ;
  520. ; Out_Debug_Chr
  521. ;
  522. ; DESCRIPTION:
  523. ;
  524. ; ENTRY:
  525. ; AL contains character to output
  526. ;
  527. ; EXIT:
  528. ;
  529. ; USES:
  530. ; Nothing
  531. ;
  532. ;==============================================================================
  533. Out_Debug_Chr proc near
  534. push di
  535. mov di, odslen
  536. mov odsbuf[di], al ; store in buffer (in stack)
  537. or al, al
  538. jz short odc_flushit ; if null, flush buffer
  539. inc odslen
  540. cmp di, 79 ; if full, flush buffer
  541. jnz short odc_ret
  542. odc_flushit:
  543. mov odsbuf[di], 0 ; null terminate string
  544. lea di, odsbuf
  545. ifdef WOW
  546. cCall <far ptr DebugWrite>,<ssdi,odslen>
  547. else
  548. cCall DebugWrite,<ssdi,odslen>
  549. endif
  550. mov odslen, 0
  551. odc_ret:
  552. pop di
  553. ret
  554. Out_Debug_Chr endp
  555. ;******************************************************************************
  556. ;
  557. ; Show_Near_Label
  558. ;
  559. ; DESCRIPTION: call the debugger to display a label less than or equal
  560. ; to the given address
  561. ;
  562. ; ENTRY: AX is selector, CX is offset of address to try to find
  563. ; a symbol for
  564. ; ES selector to DOSX data segment
  565. ; EXIT:
  566. ;
  567. ; USES:
  568. ;
  569. ;==============================================================================
  570. Show_Near_Label proc near
  571. push ax ;on a 286, use 16 bit regs
  572. push bx
  573. push cx
  574. mov bx,cx
  575. mov cx,ax
  576. mov ax,DS_Out_Symbol
  577. int Debug_Serv_Int
  578. pop cx
  579. pop bx
  580. pop ax
  581. ret
  582. Show_Near_Label endp
  583. ;******************************************************************************
  584. ;
  585. ; Show_String
  586. ;
  587. ; DESCRIPTION: Display an asciiz string
  588. ;
  589. ; ENTRY: AX is selector, CX is offset of address to find string
  590. ;
  591. ; EXIT:
  592. ;
  593. ; USES:
  594. ;
  595. ;==============================================================================
  596. Show_String proc near
  597. push ax
  598. push ds
  599. push si
  600. mov ds,ax
  601. mov si,cx
  602. xor ax,ax
  603. cmp byte ptr ds:[si], ' '
  604. jbe pascal_show_string
  605. @@:
  606. lodsb
  607. or al,al
  608. jz short @f
  609. call Out_Debug_Chr
  610. jmp short @b
  611. @@:
  612. pop si
  613. pop ds
  614. pop ax
  615. ret
  616. pascal_show_string:
  617. push cx
  618. lodsb
  619. mov cl, al
  620. xor ch, ch
  621. pss_1: lodsb
  622. call Out_Debug_Chr
  623. loop pss_1
  624. pop cx
  625. jmps @B
  626. Show_String endp
  627. ; END OF DXBUG STUFF
  628. ;-----------------------------------------------------------------------;
  629. ; CVWBreak
  630. ;
  631. ; This is part of the tortuous path from a Ctrl-Alt-SysReq to
  632. ; CVW. In RegisterPtrace we tell the keyboard driver to jump
  633. ; here if Ctrl-Alt_SysReq is done.
  634. ;
  635. ; Entry:
  636. ; none
  637. ;
  638. ; Returns:
  639. ;
  640. ; Registers Destroyed:
  641. ; none
  642. ;
  643. ; History:
  644. ; Mon 17-Jul-1989 14:34:21 -by- David N. Weise [davidw]
  645. ; Wrote it!
  646. ;-----------------------------------------------------------------------;
  647. assumes ds,nothing
  648. assumes es,nothing
  649. cProc CVWBreak,<PUBLIC,FAR>
  650. cBegin nogen
  651. push ax
  652. push di
  653. push ds
  654. SetKernelDS
  655. test Kernel_flags[2],KF2_PTRACE
  656. jz short call_WDEB
  657. cmp Kernel_InDOS,0 ; not in DOS we don't
  658. jnz short TVC15_exit
  659. .386p
  660. push fs ; save current FS for debuggers
  661. .286p
  662. call genter ; sets FS to kernel data seg
  663. UnSetKernelDS
  664. .386p
  665. pop fs
  666. .286p
  667. dec [di].gi_lrulock
  668. jz short call_PTrace
  669. or [di].gi_flags,GIF_INT2
  670. jmps TVC15_exit
  671. call_PTrace:
  672. SetKernelDS
  673. cmp ptrace_DLL_entry.sel,0
  674. jnz short yes_CVW
  675. ;** This is the only case where WINDEBUG gets first dibs something.
  676. ;* Since we have no way of knowing if TOOLHELP wants the
  677. ;** CtlAltSysRq, we always give it to CVW if it's there.
  678. test Kernel_Flags[2],KF2_TOOLHELP
  679. jz SHORT call_WDEB
  680. mov ax,SDM_INT2 ;Notification number
  681. call lpfnToolHelpProc ;Give it to TOOLHELP
  682. jmp SHORT TVC15_exit
  683. ;** Give it to the kernel debugger
  684. call_WDEB:
  685. pop ds
  686. UnSetKernelDS
  687. pop di
  688. pop ax
  689. int 1
  690. iret
  691. ;** Give it to CVW
  692. yes_CVW:
  693. ReSetKernelDS
  694. mov ax,SDM_INT2
  695. call ptrace_DLL_entry
  696. TVC15_exit:
  697. pop ds
  698. UnSetKernelDS
  699. pop di
  700. pop ax
  701. iret
  702. cEnd nogen
  703. ;-----------------------------------------------------------------------;
  704. ; DebugDefineSegment ;
  705. ; ;
  706. ; Informs debugger of physical address and type of a segment for the ;
  707. ; named module, that is informed of segment index and corresponding ;
  708. ; name and physical segment. ;
  709. ; ;
  710. ; Arguments: ;
  711. ; ModName - Long pointer to module name. ;
  712. ; SegNumber - zero based segment index ;
  713. ; LoadedSeg - Physical seg address assigned by user to index. ;
  714. ; InstanceNumber - Windows instance number bound to physical seg.;
  715. ; DataOrCodeFlag - Whether segment is code or data. ;
  716. ; ;
  717. ; Returns: ;
  718. ; None. ;
  719. ; ;
  720. ; Error Returns: ;
  721. ; ;
  722. ; Registers Preserved: ;
  723. ; ;
  724. ; Registers Destroyed: ;
  725. ; ;
  726. ; Calls: ;
  727. ; ;
  728. ; History: ;
  729. ; ;
  730. ; Thu Nov 13, 1986 02:20:52p -by- David N. Weise [davidw] ;
  731. ; Added this nifty comment block. ;
  732. ;-----------------------------------------------------------------------;
  733. assumes ds,nothing
  734. assumes es,nothing
  735. default_buf_size equ 130
  736. cProc DebugDefineSegment,<PUBLIC,NEAR>,<es>
  737. Parmd ModName
  738. Parmw SegNumber
  739. Parmw LoadedSeg
  740. Parmw InstanceNumber
  741. Parmw DataOrCodeFlag
  742. localV modBuf,default_buf_size
  743. localV nameBuf,default_buf_size
  744. cBegin
  745. SetKernelDS es
  746. test Kernel_Flags[2],KF2_SYMDEB or KF2_PTRACE
  747. jz short setdone
  748. push bx
  749. push cx
  750. push dx
  751. push si
  752. push di
  753. les di, ModName
  754. UnSetKernelDS es
  755. mov bx, SegNumber
  756. mov cx, LoadedSeg
  757. mov dx, InstanceNumber
  758. mov si, DataOrCodeFlag
  759. mov ax,SDM_LOADSEG
  760. DEBUGCALL
  761. pop di
  762. pop si
  763. pop dx
  764. pop cx
  765. pop bx
  766. setdone:
  767. ifdef WOW
  768. SetKernelDS es
  769. test es:DebugWOW,DW_DEBUG
  770. jnz @f
  771. jmp dd_no_wdebug
  772. UnSetKernelDS es
  773. @@:
  774. push ds
  775. push bx
  776. push cx
  777. push dx
  778. push si
  779. push di
  780. lds si, ModName
  781. mov cx,ds:[ne_magic]
  782. cmp cx,NEMAGIC
  783. jz @f
  784. jmp not_yet
  785. @@: mov cx,ss
  786. mov es,cx
  787. lea di,modBuf
  788. xor cx,cx
  789. mov cl,byte ptr [si-1] ; Get length byte
  790. cmp cx,default_buf_size
  791. jl @f
  792. mov cx,default_buf_size-1
  793. @@:
  794. rep movsb ; Copy the string
  795. xor ax,ax
  796. stosb
  797. mov si,ds:[ne_pfileinfo]
  798. mov cl,ds:[si].opLen
  799. sub cx,opFile
  800. lea si,[si].opFile
  801. lea di,nameBuf
  802. cmp cx,default_buf_size
  803. jl @f
  804. mov cx,default_buf_size-1
  805. @@:
  806. rep movsb ; Copy the string
  807. stosb
  808. SetKernelDS es
  809. push DataOrCodeFlag
  810. lea si,nameBuf
  811. push ss
  812. push si
  813. lea si,modBuf
  814. push ss
  815. push si
  816. push SegNumber
  817. push LoadedSeg
  818. push DBG_SEGLOAD
  819. FBOP BOP_DEBUGGER,,FastBop
  820. add sp,+16
  821. not_yet:
  822. pop di
  823. pop si
  824. pop dx
  825. pop cx
  826. pop bx
  827. pop ds
  828. UnSetKernelDS
  829. dd_no_wdebug:
  830. endif
  831. cEnd
  832. ;-----------------------------------------------------------------------;
  833. ; DebugMovedSegment ;
  834. ; ;
  835. ; Informs debugger of the old and new values for a physical segment. ;
  836. ; ;
  837. ; Arguments: ;
  838. ; SourceSeg - Original segment value. ;
  839. ; DestSeg - New segment value. ;
  840. ; ;
  841. ; Returns: ;
  842. ; None. ;
  843. ; ;
  844. ; Error Returns: ;
  845. ; ;
  846. ; Registers Preserved: ;
  847. ; ;
  848. ; Registers Destroyed: ;
  849. ; ;
  850. ; Calls: ;
  851. ; ;
  852. ; History: ;
  853. ; ;
  854. ; Thu Nov 13, 1986 02:29:15p -by- David N. Weise [davidw] ;
  855. ; Wrote it. ;
  856. ;-----------------------------------------------------------------------;
  857. cProc DebugMovedSegment,<PUBLIC,NEAR>
  858. ParmW SourceSeg
  859. ParmW DestSeg
  860. cBegin
  861. cEnd
  862. ;-----------------------------------------------------------------------;
  863. ; DebugFreeSegment ;
  864. ; ;
  865. ; Informs debugger that a segment is being returned to the global ;
  866. ; memory pool and is no longer code or data. ;
  867. ; ;
  868. ; Arguments: ;
  869. ; SegAddr - segment being freed ;
  870. ; fRelBP - flag indicating if breakpoints should be released, ;
  871. ; -1 means yes ;
  872. ; ;
  873. ; Returns: ;
  874. ; None. ;
  875. ; ;
  876. ; Error Returns: ;
  877. ; ;
  878. ; Registers Preserved: ;
  879. ; ;
  880. ; Registers Destroyed: ;
  881. ; ;
  882. ; Calls: ;
  883. ; ;
  884. ; History: ;
  885. ; ;
  886. ; Thu Nov 13, 1986 02:34:13p -by- David N. Weise [davidw] ;
  887. ; Added this nifty comment block. ;
  888. ;-----------------------------------------------------------------------;
  889. cProc DebugFreeSegment,<PUBLIC,NEAR>,<es>
  890. Parmw SegAddr
  891. parmW fRelBP
  892. cBegin
  893. push ds
  894. SetKernelDS
  895. ifdef WOW
  896. test DebugWOW,DW_DEBUG
  897. jz df_no_wdebug
  898. push SegAddr ; Notify the Win32 debugger that
  899. push fRelBP
  900. mov ax,DBG_SEGFREE ; the selector number needs to be freed
  901. push ax
  902. FBOP BOP_DEBUGGER,,FastBop
  903. add sp,+6
  904. df_no_wdebug:
  905. endif
  906. test Kernel_Flags[2],KF2_SYMDEB or KF2_PTRACE
  907. pop ds
  908. UnSetKernelDS
  909. jz short killdone
  910. mov bx, SegAddr
  911. mov ax, SDM_FREESEG
  912. inc fRelBP
  913. jnz short @f
  914. mov ax, SDM_RELEASESEG ;free but pulls out breakpoints 1st
  915. @@:
  916. DEBUGCALL
  917. killdone:
  918. cEnd
  919. ;-----------------------------------------------------------------------;
  920. ; DebugWrite ;
  921. ; ;
  922. ; Prints the given string of the given length. If a debugger is ;
  923. ; present tells the debugger to print the message. Otherwise uses ;
  924. ; DOS Function 40h to the con device. ;
  925. ; ;
  926. ; Arguments: ;
  927. ; lpBuf long pointer to string to write ;
  928. ; nBytes # of bytes in string ;
  929. ; ;
  930. ; Returns: ;
  931. ; None. ;
  932. ; ;
  933. ; Error Returns: ;
  934. ; ;
  935. ; Registers Preserved: ;
  936. ; ;
  937. ; Registers Destroyed: ;
  938. ; ;
  939. ; Calls: ;
  940. ; ;
  941. ; History: ;
  942. ; ;
  943. ; Thu Nov 13, 1986 02:53:08p -by- David N. Weise [davidw] ;
  944. ; Added this nifty comment block. ;
  945. ;-----------------------------------------------------------------------;
  946. ifdef WOW
  947. cProc DebugWrite,<PUBLIC,FAR>,<ds,si>
  948. else
  949. cProc DebugWrite,<PUBLIC,NEAR>,<ds,si>
  950. endif
  951. parmD lpBuf
  952. parmW nBytes
  953. localW wHandled
  954. localW SavePDB
  955. cBegin
  956. ;** Validate the pointer and number of bytes
  957. mov ax,WORD PTR lpBuf[0]
  958. add ax,nBytes
  959. jnc SHORT @F
  960. jmp DW_End ;Overflow: error
  961. @@:
  962. .386
  963. push eax ; 32 bit ValidatePointer destroys top half
  964. push ecx ; of eax, ecx which isn't nice in debug outs
  965. .286
  966. push WORD PTR lpBuf[2]
  967. push ax
  968. call ValidatePointer ;Make sure pointer is OK
  969. or ax,ax
  970. .386
  971. pop ecx
  972. pop eax
  973. .286
  974. jnz SHORT @F
  975. jmp DW_End ;Bogus pointer: just return.
  976. @@: mov cx,nBytes
  977. lds dx,lpBuf ;DS:DX points to string
  978. or cx,cx ;Zero length requires computing
  979. jnz SHORT DW_GoodLen
  980. ;** Compute string length if a valid length not passed in
  981. mov si,dx
  982. cld
  983. DW_LenLoop:
  984. lodsb
  985. or al,al
  986. jnz short DW_LenLoop
  987. mov cx,si
  988. sub cx,dx
  989. dec cx
  990. DW_GoodLen:
  991. ;** Set up for the Int 41h, PTrace, and TOOLHELP interfaces
  992. mov wHandled,0 ;Flag that we haven't handled yet
  993. mov si,dx ;Point to string with DS:SI
  994. push ds ; and ES:SI
  995. pop es
  996. ;** Decide which debugger (if any) to send string to
  997. push ds
  998. SetKernelDS
  999. test Kernel_Flags[2],KF2_SYMDEB ;WDEB386 loaded?
  1000. pop ds
  1001. UnSetKernelDS
  1002. jz SHORT DW_TryToolHelp ;No, now try TOOLHELP
  1003. ;** Send to WDEB386
  1004. push si
  1005. DebInt SDM_CONWRITE
  1006. pop si
  1007. mov wHandled,1 ;Assume that WDEB386 handled it
  1008. ;** Send it to TOOLHELP if it is there
  1009. DW_TryToolHelp:
  1010. push ds
  1011. SetKernelDS
  1012. test Kernel_Flags[2],KF2_TOOLHELP ;ToolHelp around?
  1013. pop ds
  1014. UnSetKernelDS
  1015. jz SHORT DW_TryPTrace ;Nope, now try PTrace
  1016. push ds
  1017. SetKernelDS
  1018. push Win_PDB ;Save current PDB
  1019. cmp curTDB,0
  1020. jz @F
  1021. push es ; and set to current task's PDB
  1022. mov es,curTDB ; for toolhelp call.
  1023. push es:[TDB_PDB]
  1024. pop ds:Win_PDB
  1025. pop es
  1026. @@:
  1027. mov ax,SDM_CONWRITE ;Notification ID
  1028. call lpfnToolHelpProc ;String in ES:SI for TOOLHELP
  1029. pop Win_PDB ;Restore current PDB
  1030. or ax,ax ;TOOLHELP client say to pass it on?
  1031. pop ds
  1032. UnSetKernelDS
  1033. jnz SHORT DW_End ;No, we're done
  1034. ;** Handle PTrace
  1035. DW_TryPTrace:
  1036. SetKernelDS es
  1037. cmp WORD PTR es:ptrace_dll_entry[2],0 ;WINDEBUG.DLL lurking around?
  1038. jz SHORT DW_WriteToCOM ;No, try COM port
  1039. ;** If we're exiting a task, don't send the debug write to PTrace.
  1040. ;** This is a gross hack for QCWin who chokes on these. These
  1041. ;** were being sent because of parameter validation errors.
  1042. push ax ;Temp reg
  1043. mov ax,es:curTDB
  1044. cmp ax,es:wExitingTDB
  1045. pop ax
  1046. je DW_WriteToCOM ;Write out directly
  1047. IF KDEBUG
  1048. ;** If we're sending a KERNEL trace out, we don't want to send this
  1049. ;** to PTrace, either
  1050. cmp fKTraceOut, 0 ;Are we doing a KERNEL trace out?
  1051. jne DW_WriteToCOM ;Yes, don't call PTrace
  1052. ENDIF
  1053. ;** Now send to PTrace
  1054. mov wHandled,1 ;Assume WINDEBUG handles if present
  1055. push ax ;Save regs PTrace might trash
  1056. push si
  1057. push dx
  1058. push ds
  1059. push es
  1060. mov ax,SDM_CONWRITE ;Notification ID
  1061. call es:ptrace_DLL_entry ;Do the PTrace thing
  1062. pop es
  1063. pop ds
  1064. pop dx
  1065. pop si
  1066. pop ax
  1067. ;** Write string to debug terminal
  1068. DW_WriteToCOM:
  1069. cmp wHandled,0 ;Handled?
  1070. jnz SHORT DW_End ;Yes
  1071. inc es:fDW_Int21h ; Skip it if user has canceled
  1072. jnz SHORT DW_Skip_Write ; a crit error on this before
  1073. mov ax, es:topPDB
  1074. xchg es:Win_PDB, ax ; Switch to Kernel's PDB,
  1075. mov SavePDB, ax ; saving current PDB
  1076. ifdef WOW
  1077. cCall WOWOutputDebugString,<lpBuf>
  1078. else
  1079. mov bx,3 ;Send to DOS AUX port
  1080. mov ah,40h
  1081. int 21h
  1082. endif; WOW
  1083. mov ax, SavePDB
  1084. mov es:Win_PDB, ax ; restore app pdb
  1085. DW_Skip_Write:
  1086. dec es:fDW_Int21h
  1087. DW_End:
  1088. UnSetKernelDS
  1089. UnSetKernelDS es
  1090. cEnd
  1091. ;-----------------------------------------------------------------------;
  1092. ; OutputDebugString ;
  1093. ; ;
  1094. ; A routine callable from anywhere since it is exported. It calls ;
  1095. ; DebugWrite to do its dirty work. ;
  1096. ; ;
  1097. ; Arguments: ;
  1098. ; lpStr long pointer to null terminated string ;
  1099. ; ;
  1100. ; Returns: ;
  1101. ; none ;
  1102. ; ;
  1103. ; Error Returns: ;
  1104. ; ;
  1105. ; Registers Preserved: ;
  1106. ; all ;
  1107. ; ;
  1108. ; Registers Destroyed: ;
  1109. ; ;
  1110. ; Calls: ;
  1111. ; ;
  1112. ; History: ;
  1113. ; ;
  1114. ; Tue June 28, 1988 -by- Ken Shirriff [t-kens] ;
  1115. ; Made it save all the registers. ;
  1116. ; ;
  1117. ; Thu Nov 13, 1986 02:54:36p -by- David N. Weise [davidw] ;
  1118. ; Added this nifty comment block. ;
  1119. ;-----------------------------------------------------------------------;
  1120. cProc OutputDebugString,<PUBLIC,FAR,NODATA>,<es>
  1121. parmD lpStr
  1122. cBegin
  1123. pusha
  1124. ifdef WOW
  1125. cCall <far ptr DebugWrite>,<lpStr, 0>
  1126. else
  1127. cCall DebugWrite,<lpStr, 0>
  1128. endif
  1129. popa
  1130. cEnd
  1131. ;-----------------------------------------------------------------------;
  1132. ; DebugRead ;
  1133. ; ;
  1134. ; Gets a character from either the debugger (if one is present) or ;
  1135. ; from the AUX. ;
  1136. ; ;
  1137. ; Arguments: ;
  1138. ; none ;
  1139. ; ;
  1140. ; Returns: ;
  1141. ; AL = character ;
  1142. ; ;
  1143. ; Error Returns: ;
  1144. ; ;
  1145. ; Registers Preserved: ;
  1146. ; ;
  1147. ; Registers Destroyed: ;
  1148. ; ;
  1149. ; Calls: ;
  1150. ; ;
  1151. ; History: ;
  1152. ; ;
  1153. ; Thu Nov 13, 1986 02:55:09p -by- David N. Weise [davidw] ;
  1154. ; Added this nifty comment block. ;
  1155. ;-----------------------------------------------------------------------;
  1156. cProc DebugRead,<PUBLIC,NEAR>
  1157. cBegin nogen
  1158. push ds
  1159. SetKernelDS
  1160. ;** Send it to the debugger(s) FIRST
  1161. mov ax,SDM_CONREAD ;Get the notification ID
  1162. ; This sure is weird! Goal is to ask if WDEB386 has a char
  1163. ; available. If so, return.
  1164. ; We do the check here because MyDebugCall assumes INT41
  1165. ; doesn't modify registers, but the CONREAD call does.
  1166. ; This was hosing TOOLHELP, since we were passing a different
  1167. ; function to TOOLHELP based on what char a user was pressing.
  1168. test Kernel_Flags[2],KF2_SYMDEB ; WDEB386 loaded?
  1169. jz short dr_symdeb ; no - MyDebugCall
  1170. DebInt ; Yes - read CON
  1171. cmp ax, SDM_CONREAD
  1172. jnz @F ; got a response - continue.
  1173. dr_symdeb:
  1174. DEBUGCALL
  1175. @@:
  1176. ;** See if we should still hand it to the AUX port
  1177. cmp al,SDM_CONREAD ;If not changed, we didn't get a character
  1178. jne SHORT DR_End
  1179. mov ax, wDefRIP ;Do we have a default value to use?
  1180. or ax, ax
  1181. jnz DR_End
  1182. xor cx,cx ;Allocate WORD to read into
  1183. push cx
  1184. mov dx,sp ;Point with DS:DX
  1185. push ss
  1186. pop ds
  1187. inc cx ;Get one byte
  1188. DR_ConLoop:
  1189. ifdef WOW
  1190. int 3 ; BUGBUG mattfe 29-mar-92, should be thunked to 32 bit side.
  1191. endif
  1192. mov bx,3 ;Use AUX
  1193. mov ah,3fh ;Read device
  1194. int 21h ;Call DOS
  1195. cmp ax,cx ;Did we get a byte?
  1196. jne SHORT DR_ConLoop ;No, try again
  1197. pop ax ;Get the byte read
  1198. DR_End:
  1199. pop ds
  1200. ret
  1201. cEnd nogen
  1202. ;-----------------------------------------------------------------------;
  1203. ; DebugDefineLine ;
  1204. ; ;
  1205. ; Notifies debugger of the location of The Line. ;
  1206. ; ;
  1207. ; Arguments: ;
  1208. ; None ;
  1209. ; ;
  1210. ; Returns: ;
  1211. ; None ;
  1212. ; ;
  1213. ; Registers Destroyed: ;
  1214. ; ;
  1215. ; History: ;
  1216. ; Mon 20-Jun-1988 13:17:41 -by- David N. Weise [davidw] ;
  1217. ; Moved it here. ;
  1218. ;-----------------------------------------------------------------------;
  1219. ;
  1220. ; assumes ds,nothing
  1221. ; assumes es,nothing
  1222. ;
  1223. ;cProc DebugDefineLine,<PUBLIC,NEAR>
  1224. ;
  1225. ;cBegin nogen
  1226. ; ret
  1227. ;cEnd nogen
  1228. ;
  1229. ;cProc FarDebugNewTask,<PUBLIC,FAR>
  1230. ;
  1231. ;cBegin nogen
  1232. ; call DebugNewTask
  1233. ; ret
  1234. ;cEnd nogen
  1235. ;
  1236. ;
  1237. ;-----------------------------------------------------------------------;
  1238. ; DebugNewTask ;
  1239. ; ;
  1240. ; ;
  1241. ; Arguments: ;
  1242. ; AX = EMS PID ;
  1243. ; ;
  1244. ; Returns: ;
  1245. ; None ;
  1246. ; ;
  1247. ; Error Returns: ;
  1248. ; ;
  1249. ; Registers Preserved: ;
  1250. ; ;
  1251. ; Registers Destroyed: ;
  1252. ; ;
  1253. ; Calls: ;
  1254. ; ;
  1255. ; History: ;
  1256. ; ;
  1257. ;-----------------------------------------------------------------------;
  1258. ;
  1259. ;cProc DebugNewTask,<PUBLIC,NEAR>
  1260. ;
  1261. ;cBegin nogen
  1262. ; ret
  1263. ;cEnd nogen
  1264. ;
  1265. ;cProc FarDebugFlushTask,<PUBLIC,FAR>
  1266. ;
  1267. ;cBegin nogen
  1268. ; call DebugFlushTask
  1269. ; ret
  1270. ;cEnd nogen
  1271. ;
  1272. ;-----------------------------------------------------------------------;
  1273. ; DebugFlushTask ;
  1274. ; ;
  1275. ; ;
  1276. ; Arguments: ;
  1277. ; AX = EMS PID ;
  1278. ; ;
  1279. ; Returns: ;
  1280. ; None ;
  1281. ; ;
  1282. ; Error Returns: ;
  1283. ; ;
  1284. ; Registers Preserved: ;
  1285. ; ;
  1286. ; Registers Destroyed: ;
  1287. ; ;
  1288. ; Calls: ;
  1289. ; ;
  1290. ; History: ;
  1291. ; ;
  1292. ;-----------------------------------------------------------------------;
  1293. ;
  1294. ;cProc DebugFlushTask,<PUBLIC,NEAR>
  1295. ;
  1296. ;cBegin nogen
  1297. ; ret
  1298. ;cEnd nogen
  1299. ;-----------------------------------------------------------------------;
  1300. ; DebugSwitchOut ;
  1301. ; ;
  1302. ; ;
  1303. ; Arguments: ;
  1304. ; DS = TDB ;
  1305. ; ;
  1306. ; Returns: ;
  1307. ; None ;
  1308. ; ;
  1309. ; Error Returns: ;
  1310. ; ;
  1311. ; Registers Preserved: ;
  1312. ; All ;
  1313. ; ;
  1314. ; Registers Destroyed: ;
  1315. ; ;
  1316. ; Calls: ;
  1317. ; ;
  1318. ; History: ;
  1319. ; ;
  1320. ;-----------------------------------------------------------------------;
  1321. cProc DebugSwitchOut,<PUBLIC,NEAR>
  1322. cBegin nogen
  1323. push ds
  1324. SetKernelDS
  1325. test Kernel_Flags[2],KF2_PTRACE
  1326. pop ds
  1327. UnSetKernelDS
  1328. jz short dso_done
  1329. push ax
  1330. mov ax,SDM_SWITCHOUT
  1331. DEBUGCALL
  1332. pop ax
  1333. dso_done:
  1334. ret
  1335. cEnd nogen
  1336. ;-----------------------------------------------------------------------;
  1337. ; DebugSwitchIn ;
  1338. ; ;
  1339. ; ;
  1340. ; Arguments: ;
  1341. ; DS = TDB ;
  1342. ; ;
  1343. ; Returns: ;
  1344. ; None ;
  1345. ; ;
  1346. ; Error Returns: ;
  1347. ; ;
  1348. ; Registers Preserved: ;
  1349. ; All ;
  1350. ; ;
  1351. ; Registers Destroyed: ;
  1352. ; ;
  1353. ; Calls: ;
  1354. ; ;
  1355. ; History: ;
  1356. ; ;
  1357. ;-----------------------------------------------------------------------;
  1358. cProc DebugSwitchIn,<PUBLIC,NEAR>
  1359. cBegin nogen
  1360. push ds
  1361. SetKernelDS
  1362. test Kernel_Flags[2],KF2_PTRACE
  1363. pop ds
  1364. UnSetKernelDS
  1365. jz short dsi_done
  1366. push ax
  1367. mov ax,SDM_SWITCHIN
  1368. DEBUGCALL
  1369. pop ax
  1370. dsi_done:
  1371. ret
  1372. cEnd nogen
  1373. ;-----------------------------------------------------------------------;
  1374. ; DebugExitCall
  1375. ;
  1376. ; Notifies the debugger than an app is quitting. This gets
  1377. ; called at the top of ExitCall.
  1378. ;
  1379. ; Entry:
  1380. ;
  1381. ; Returns:
  1382. ;
  1383. ; Registers Preserved:
  1384. ; all
  1385. ;
  1386. ; History:
  1387. ; Thu 11-May-1989 08:58:40 -by- David N. Weise [davidw]
  1388. ; Wrote it!
  1389. ;-----------------------------------------------------------------------;
  1390. assumes ds,nothing
  1391. assumes es,nothing
  1392. cProc DebugExitCall,<PUBLIC,NEAR>
  1393. cBegin nogen
  1394. ;
  1395. ; Windebug knows where this is. See MyDebugCall() comment.
  1396. ;
  1397. ifdef WOW
  1398. push ds
  1399. SetKernelDS
  1400. test DebugWOW,DW_DEBUG
  1401. jz de_no_wdebug
  1402. push ax
  1403. push es
  1404. mov es,bx ; Get the current TDB
  1405. push es ; hTask
  1406. mov ax,es:[TDB_pModule] ; Get the module handle
  1407. mov es,ax
  1408. push es ; hModule
  1409. push es ; Pointer to module name
  1410. push es:ne_restab
  1411. push es ; Pointer to module path
  1412. push word ptr es:ne_crc+2
  1413. mov ax,DBG_TASKSTOP ; the selector number needs to be freed
  1414. push ax
  1415. FBOP BOP_DEBUGGER,,FastBop
  1416. add sp,+14
  1417. pop es ; Restore original ES
  1418. pop ax
  1419. de_no_wdebug:
  1420. pop ds
  1421. UnSetKernelDS
  1422. endif
  1423. push ax
  1424. mov bl,al ;Exit code in BL
  1425. mov ax,SDM_EXITCALL
  1426. DEBUGCALL
  1427. pop ax
  1428. ret
  1429. cEnd nogen
  1430. ;-----------------------------------------------------------------------;
  1431. ; FarDebugDelModule
  1432. ;
  1433. ; Notifies the debugger than a module is being deleted. This gets
  1434. ; called at the top of ExitCall.
  1435. ;
  1436. ; Entry:
  1437. ; ES = module handle
  1438. ;
  1439. ; Returns:
  1440. ;
  1441. ; Registers Reserved:
  1442. ; all
  1443. ;
  1444. ; History:
  1445. ; Mon 11-Sep-1989 18:34:06 -by- David N. Weise [davidw]
  1446. ; Wrote it!
  1447. ;-----------------------------------------------------------------------;
  1448. assumes ds,nothing
  1449. assumes es,nothing
  1450. cProc FarDebugDelModule,<PUBLIC,FAR>
  1451. ifdef WOW
  1452. localV nameBuf,130
  1453. localV ModName,64
  1454. endif
  1455. cBegin nogen
  1456. push es
  1457. ifdef WOW
  1458. push ds
  1459. push es
  1460. SetKernelDS
  1461. test DebugWOW,DW_DEBUG
  1462. jnz @f
  1463. jmp fdd_no_wdebug
  1464. @@: push di
  1465. push si
  1466. push cx
  1467. xor cx,cx
  1468. mov ax,es
  1469. mov ds,ax
  1470. mov si,es:[ne_restab]
  1471. mov cl,[si]
  1472. inc si
  1473. cmp cl,64
  1474. jb @f
  1475. mov cl,63
  1476. @@:
  1477. mov ax,ss
  1478. mov es,ax
  1479. lea di,ModName
  1480. rep movsb ; Copy module name from resource
  1481. mov byte ptr es:[di],0 ; table and null terminate it
  1482. mov ax,ds
  1483. mov es,ax
  1484. lea di,nameBuf
  1485. push ax
  1486. push ss
  1487. push di
  1488. mov ax, 130
  1489. push ax
  1490. call GetModuleFileName
  1491. SetKernelDS
  1492. lea di,nameBuf
  1493. push ss
  1494. push di
  1495. lea di,ModName
  1496. push ss
  1497. push di
  1498. push DBG_MODFREE
  1499. FBOP BOP_DEBUGGER,,FastBop
  1500. add sp,+10
  1501. pop cx
  1502. pop si
  1503. pop di
  1504. fdd_no_wdebug:
  1505. pop es
  1506. pop ds
  1507. UnSetKernelDS
  1508. endif; WOW
  1509. mov ax,SDM_DELMODULE
  1510. DEBUGCALL
  1511. add sp,2
  1512. ret
  1513. cEnd nogen
  1514. ;-----------------------------------------------------------------------;
  1515. ; void DebugLogError(WORD err, VOID FAR* lpInfo);
  1516. ;
  1517. ; Notifies debugger of a LogError() call.
  1518. ;
  1519. ;-----------------------------------------------------------------------;
  1520. assumes ds,nothing
  1521. assumes es,nothing
  1522. cProc DebugLogError,<PUBLIC,NEAR>
  1523. ;ParmW err
  1524. cBegin nogen
  1525. pop ax
  1526. pop bx ; dx:bx = lpInfo
  1527. pop dx
  1528. pop cx ; cx = error code
  1529. push ax
  1530. mov ax,SDM_LOGERROR
  1531. jmp short MyDebugCall
  1532. cEnd nogen
  1533. ;-----------------------------------------------------------------------;
  1534. ; void DebugLogParamError(VOID FAR* param, FARPROC lpfn, WORD err);
  1535. ;
  1536. ; Notifies debugger of a LogParamError() call.
  1537. ;
  1538. ; NOTE: the parameters are passed in the REVERSE order than expected,
  1539. ; so that the stack layout is natural when we do the DebugCall.
  1540. ;
  1541. ;-----------------------------------------------------------------------;
  1542. assumes ds,nothing
  1543. assumes es,nothing
  1544. cProc DebugLogParamError,<PUBLIC,NEAR>
  1545. ;ParmD param
  1546. ;ParmD lpfn
  1547. ;ParmW err
  1548. cBegin nogen
  1549. ;
  1550. ; es:bx = pointer to struct containing args
  1551. ;
  1552. mov bx,sp
  1553. add bx,2 ; point past return addr.
  1554. push ss
  1555. pop es
  1556. mov ax,SDM_LOGPARAMERROR
  1557. call MyDebugCall
  1558. ret 2+4+4
  1559. cEnd nogen
  1560. ;------------------------------------------------------------------------
  1561. ;
  1562. ; MyDebugCall
  1563. ;
  1564. ; Call the debugger interface. Created to reduce references to kernel
  1565. ; data segment.
  1566. ;
  1567. ;------------------------------------------------------------------------
  1568. assumes ds,nothing
  1569. assumes es,nothing
  1570. cProc MyFarDebugCall, <FAR,PUBLIC>
  1571. cBegin nogen
  1572. cCall MyDebugCall
  1573. retf
  1574. cEnd nogen
  1575. cProc MyDebugCall,<NEAR,PUBLIC>
  1576. cBegin nogen
  1577. push ds
  1578. SetKernelDS
  1579. test Kernel_Flags[2],KF2_SYMDEB
  1580. jz short no_symdeb
  1581. cmp ax,SDM_SWITCHOUT ; Don't give these to WDEB.
  1582. je no_symdeb
  1583. cmp ax,SDM_SWITCHIN
  1584. je no_symdeb
  1585. pop ds ; Too bad some Int 41h services
  1586. UnSetKernelDS ; require segment reg params
  1587. DebInt
  1588. push ds
  1589. SetKernelDS
  1590. no_symdeb:
  1591. ;** Check for TOOLHELP's hook. We always send it here first
  1592. ;** This callback does NOT depend on what's on the stack.
  1593. test Kernel_Flags[2],KF2_TOOLHELP ;TOOLHELP hook?
  1594. jz SHORT MDC_NoToolHelp ;No
  1595. push ax
  1596. push Win_PDB ; Preserve Win_TDB across ToolHelp call
  1597. cmp curTDB,0
  1598. jz @F
  1599. push es
  1600. mov es,curTDB
  1601. push es:[TDB_PDB]
  1602. pop ds:Win_PDB
  1603. pop es
  1604. @@:
  1605. ;** Just call the TOOLHELP callback. It preserves all registers
  1606. ;** except AX where it returns nonzero if the notification
  1607. ;** was handled.
  1608. call lpfnToolHelpProc ;Do it
  1609. pop Win_PDB ; Restore Win_TDB
  1610. or ax,ax ;Did the TOOLHELP client say to
  1611. ; pass it on?
  1612. jz SHORT @F ;Yes
  1613. add sp,2 ;No, so return TOOLHELP's return value
  1614. jmp SHORT no_ptrace
  1615. @@: pop ax ;Restore notification ID
  1616. MDC_NoToolHelp:
  1617. ;** Make sure we don't have a new notification. If it's newer than
  1618. ;* CVW, CVW chokes on it so we can't send new notifications
  1619. ;** through PTrace.
  1620. cmp ax,SDM_DELMODULE ;Last old notification
  1621. ja short no_ptrace ;Don't send new notification
  1622. MDC_PTraceOk:
  1623. cmp WORD PTR ptrace_dll_entry[2],0 ;WINDEBUG.DLL lurking around?
  1624. jz SHORT no_ptrace
  1625. ; !!!!!!!!!!!!!! HACK ALERT !!!!!!!!!!!!!!
  1626. ;
  1627. ; Windebug.DLL for Windows 3.0 knows exactly what is on the stack
  1628. ; when Kernel makes a PTrace callout. For this reason, we cannot
  1629. ; change what is on the stack when we make one of these calls.
  1630. ; This stuff below fakes a FAR return to our NEAR caller, and jumps
  1631. ; to the PTrace DLL entry with all registers intact.
  1632. ;
  1633. ; SP -> DS RET
  1634. sub sp,8
  1635. push bp
  1636. mov bp,sp
  1637. ; BP -> BP xx xx xx xx DS KERNEL_RET
  1638. mov [bp+2],ax ; save AX
  1639. mov ax,[bp+10] ; move saved DS
  1640. mov [bp+4],ax
  1641. mov ax,[bp+12] ; convert near RET to far
  1642. mov [bp+10],ax
  1643. mov [bp+12],cs
  1644. mov ax,word ptr ptrace_dll_entry[2] ; CS of Routine to invoke
  1645. mov [bp+8],ax
  1646. mov ax,word ptr ptrace_dll_entry ; IP of Routine to invoke
  1647. mov [bp+6],ax
  1648. ; SP -> BP AX DS PTRACE_IP PTRACE_CS KERNEL_RET KERNEL_CS
  1649. pop bp
  1650. pop ax
  1651. pop ds
  1652. UnSetKernelDS
  1653. retf
  1654. no_ptrace:
  1655. pop ds
  1656. UnSetKernelDS
  1657. ret
  1658. cEnd nogen
  1659. if KDEBUG
  1660. dout macro var
  1661. mov byte ptr ss:[si],var
  1662. inc si
  1663. endm
  1664. ;-----------------------------------------------------------------------;
  1665. ; hex ;
  1666. ; ;
  1667. ; Outputs byte in AL as two hex digits. ;
  1668. ; ;
  1669. ; Arguments: ;
  1670. ; AL = 8-bit value to be output ;
  1671. ; SS:SI = where it's to be put ;
  1672. ; ;
  1673. ; Returns: ;
  1674. ; ;
  1675. ; Error Returns: ;
  1676. ; ;
  1677. ; Registers Preserved: ;
  1678. ; ;
  1679. ; Registers Destroyed: ;
  1680. ; ;
  1681. ; Calls: ;
  1682. ; ;
  1683. ; History: ;
  1684. ; ;
  1685. ; Fri Nov 14, 1986 02:32:15p -by- David N. Weise [davidw] ;
  1686. ; Modified it from symdeb\debug.asm. ;
  1687. ;-----------------------------------------------------------------------;
  1688. ifndef WOW
  1689. cProc hex,<NEAR>
  1690. cBegin nogen
  1691. mov ah,al ; save for second digit
  1692. ; shift high digit into low 4 bits
  1693. mov cl,4
  1694. shr al,cl
  1695. and al,0Fh ; mask to 4 bits
  1696. add al,90h
  1697. daa
  1698. adc al,40h
  1699. daa
  1700. dout al
  1701. mov al,ah ; now do digit saved in ah
  1702. and al,0Fh ; mask to 4 bits
  1703. add al,90h
  1704. daa
  1705. adc al,40h
  1706. daa
  1707. dout al
  1708. ret
  1709. cEnd nogen
  1710. ;-----------------------------------------------------------------------;
  1711. ; pdref_norip ;
  1712. ; ;
  1713. ; Dereferences the given global handle, i.e. gives back abs. address. ;
  1714. ; ;
  1715. ; Arguments: ;
  1716. ; DX = selector ;
  1717. ; DS:DI = BURGERMASTER ;
  1718. ; ;
  1719. ; Returns: ;
  1720. ; FS:ESI = address of arena header ;
  1721. ; AX = address of client data ;
  1722. ; CH = lock count or 0 for fixed objects ;
  1723. ; CL = flags ;
  1724. ; DX = handle, 0 for fixed objects ;
  1725. ; ;
  1726. ; Error Returns: ;
  1727. ; ZF = 1 if invalid or discarded ;
  1728. ; AX = 0 ;
  1729. ; BX = owner of discarded object ;
  1730. ; SI = handle of discarded object ;
  1731. ; ;
  1732. ; Registers Preserved: ;
  1733. ; ;
  1734. ; Registers Destroyed: ;
  1735. ; ;
  1736. ; Calls: ;
  1737. ; ghdref ;
  1738. ; ;
  1739. ; History: ;
  1740. ; ;
  1741. ;-----------------------------------------------------------------------;
  1742. .386p
  1743. assumes ds,nothing
  1744. assumes es,nothing
  1745. cProc pdref_norip,<PUBLIC,NEAR>
  1746. cBegin nogen
  1747. ; DPMI - no LDT access
  1748. mov si, dx
  1749. sel_check si
  1750. or si, si ; Null handle?
  1751. jnz short OK1
  1752. mov ax, si ; yes, return 0
  1753. jmps pd_exit
  1754. OK1:
  1755. lar eax, edx
  1756. jnz short pd_totally_bogus
  1757. shr eax, 8
  1758. ; We should beef up the check for a valid discarded sel.
  1759. xor cx,cx
  1760. test ah, DSC_DISCARDABLE
  1761. jz short pd_not_discardable
  1762. or cl, GA_DISCARDABLE
  1763. ; Discardable, is it code?
  1764. test al, DSC_CODE_BIT
  1765. jz short pd_not_code
  1766. or cl,GA_DISCCODE
  1767. pd_not_code:
  1768. pd_not_discardable:
  1769. test al, DSC_PRESENT
  1770. jnz short pd_not_discarded
  1771. ; object discarded
  1772. or cl,HE_DISCARDED
  1773. ifdef WOW
  1774. ; On WOW we don't copy the owner to the real LDT since it is slow to call
  1775. ; the NT Kernel, so we read our copy of it directly.
  1776. ; see set_discarded_sel_owner mattfe mar 23 93
  1777. mov ax,es ; save es
  1778. mov bx,dx
  1779. mov es,cs:gdtdsc
  1780. and bl, not 7
  1781. mov bx,es:[bx].dsc_owner
  1782. mov es,ax ; restore
  1783. else
  1784. lsl bx, dx ; get the owner
  1785. endif
  1786. or si, SEG_RING-1 ; Handles are RING 2
  1787. xor ax,ax
  1788. jmps pd_exit
  1789. pd_not_discarded:
  1790. cCall get_arena_pointer32,<dx>
  1791. mov esi, eax
  1792. mov ax, dx
  1793. or esi, esi ; Unknown selector
  1794. jz short pd_maybe_alias
  1795. mov dx, ds:[esi].pga_handle
  1796. cmp dx, ax ; Quick check - handle in header
  1797. je short pd_match ; matches what we were given?
  1798. test al, 1 ; NOW, we MUST have been given
  1799. jz short pd_totally_bogus ; a selector address.
  1800. push ax
  1801. StoH ax ; Turn into handle
  1802. cmp dx, ax
  1803. pop ax
  1804. jne short pd_nomatch
  1805. pd_match:
  1806. or cl, ds:[esi].pga_flags
  1807. and cl, NOT HE_DISCARDED ; same as GA_NOTIFY!!
  1808. mov ax, dx ; Get address in AX
  1809. test dl, GA_FIXED ; DX contains handle
  1810. jnz short pd_fixed ; Does handle need derefencing?
  1811. mov ch, ds:[esi].pga_count
  1812. HtoS ax ; Dereference moveable handle
  1813. jmps pd_exit
  1814. pd_totally_bogus:
  1815. xor ax,ax
  1816. pd_maybe_alias:
  1817. pd_nomatch: ; Handle did not match...
  1818. xor dx, dx
  1819. pd_fixed:
  1820. pd_exit:
  1821. or ax,ax
  1822. ret
  1823. cEnd nogen
  1824. .286p
  1825. ;-----------------------------------------------------------------------;
  1826. ; xhandle_norip ;
  1827. ; ;
  1828. ; Returns the handle for a global segment. ;
  1829. ; ;
  1830. ; Arguments: ;
  1831. ; Stack = sp -> near return return address ;
  1832. ; sp+2 -> far return return address of caller ;
  1833. ; sp+6 -> segment address parameter ;
  1834. ; ;
  1835. ; Returns: ;
  1836. ; Old DS,DI have been pushed on the stack ;
  1837. ; ;
  1838. ; ZF= 1 if fixed segment. ;
  1839. ; AX = handle ;
  1840. ; ;
  1841. ; ZF = 0 ;
  1842. ; AX = handle ;
  1843. ; BX = pointer to handle table entry ;
  1844. ; CX = flags and count word from handle table ;
  1845. ; DX = segment address ;
  1846. ; ES:DI = arena header of object ;
  1847. ; DS:DI = master object segment address ;
  1848. ; ;
  1849. ; Error Returns: ;
  1850. ; AX = 0 if invalid segment address ;
  1851. ; ZF = 1 ;
  1852. ; ;
  1853. ; Registers Preserved: ;
  1854. ; ;
  1855. ; Registers Destroyed: ;
  1856. ; ;
  1857. ; Calls: ;
  1858. ; ;
  1859. ; History: ;
  1860. ; ;
  1861. ; Thu Oct 16, 1986 02:40:08p -by- David N. Weise [davidw] ;
  1862. ; Added this nifty comment block. ;
  1863. ;-----------------------------------------------------------------------;
  1864. .386p
  1865. cProc xhandle_norip,<PUBLIC,NEAR>
  1866. cBegin nogen
  1867. pop dx ; Get near return address
  1868. mov bx,sp ; Get seg parameter from stack
  1869. mov ax,ss:[bx+4]
  1870. cmp ax,-1 ; Is it -1?
  1871. jnz short xh1
  1872. mov ax,ds ; Yes, use callers DS
  1873. xh1: inc bp
  1874. push bp
  1875. mov bp,sp
  1876. push ds ; Save DS:DI
  1877. push edi
  1878. push esi
  1879. SetKernelDS
  1880. mov ds, pGlobalHeap ; Point to master object
  1881. UnSetKernelDS
  1882. xor edi,edi
  1883. inc [di].gi_lrulock
  1884. push dx
  1885. mov dx,ax
  1886. call pdref_norip
  1887. xchg dx,ax ; get seg address in DX
  1888. jz short xhandle_ret ; invalid or discarded handle
  1889. test al, GA_FIXED
  1890. jnz short xhandle_fixed
  1891. or ax, ax
  1892. jmps xhandle_ret
  1893. xhandle_fixed:
  1894. xor bx, bx ; Set ZF
  1895. xhandle_ret:
  1896. ret
  1897. cEnd nogen
  1898. .286p
  1899. endif ;ifndef WOW
  1900. endif ;KDEBUG
  1901. cProc ReplaceInst,<PUBLIC,FAR>
  1902. ;; parmD bpaddress
  1903. ;; parmW instruct
  1904. cBegin nogen
  1905. ret 6
  1906. cEnd nogen
  1907. sEnd CODE
  1908. end