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.

1133 lines
22 KiB

  1. ;-----------------------------------------------------------------------;
  2. ; ;
  3. ; RIPAUX.ASM - ;
  4. ; ;
  5. ; Debugging Support Routines ;
  6. ; ;
  7. ;-----------------------------------------------------------------------;
  8. TITLE RIPAUX.ASM - Debugging Support Routines
  9. ;-----------------------------------------------------------------------;
  10. ; INCLUDES ;
  11. ;-----------------------------------------------------------------------;
  12. ?RIPAUX = 1
  13. .xlist
  14. win3deb = 1
  15. include kernel.inc
  16. include newexe.inc
  17. .list
  18. ;-----------------------------------------------------------------------;
  19. ; DATA SEGMENT DEFINITION ;
  20. ;-----------------------------------------------------------------------;
  21. DataBegin
  22. externD pDisableProc
  23. if KDEBUG
  24. externW fWinX
  25. externW hExeHead
  26. externB szDebugStr
  27. externW DebugOptions
  28. externW DebugFilter
  29. externB fKTraceOut ; Used by DebugWrite to ignore traces
  30. else
  31. externB szExitStr1
  32. externB szExitStr2
  33. externB szFatalExit
  34. endif
  35. DataEnd
  36. ifdef WOW
  37. externFP FatalExitC
  38. endif
  39. ;-----------------------------------------------------------------------;
  40. ; CODE SEGMENT DEFINITION ;
  41. ;-----------------------------------------------------------------------;
  42. sBegin CODE
  43. assumes CS,CODE
  44. assumes DS,NOTHING
  45. assumes ES,NOTHING
  46. ;-----------------------------------------------------------------------;
  47. ; EXTERNS ;
  48. ;-----------------------------------------------------------------------;
  49. externFP ExitKernel
  50. externFP FatalAppExit
  51. if KDEBUG
  52. externFP KOutDebugStr
  53. externNP DebugOutput2
  54. externNP LogParamError2
  55. else
  56. externD prevInt21Proc
  57. externFP InternalDisableDOS
  58. endif
  59. externNP DebugLogError
  60. externNP DebugLogParamError
  61. ; SAVEREGS - Preserve all registers
  62. ;
  63. SAVEREGS macro
  64. .386
  65. push ds ; preserve all registers
  66. push es
  67. push fs
  68. push gs
  69. pushad
  70. .286p
  71. endm
  72. ; RESTOREREGS - Restore registeres preserved with SAVEREGS
  73. ;
  74. RESTOREREGS macro
  75. .386
  76. popad
  77. pop gs
  78. pop fs
  79. pop es
  80. pop ds
  81. .286p
  82. endm
  83. ; In Win3.1, different code is used for FatalExit on retail
  84. ; and debug builds. WOW uses the code below derived from the
  85. ; debug wrapper for FatalExitC. FatalExitC is a thunk to
  86. ; WOW32's WK32FatalExit thunk.
  87. cProc FatalExit,<PUBLIC,FAR>
  88. parmW errCode
  89. cBegin nogen
  90. push bp
  91. mov bp, sp
  92. push ds
  93. pusha
  94. setkernelds
  95. push [bp+6]
  96. cCall FatalExitC
  97. popa
  98. pop ds
  99. INT3_DEBUG ; Stop here so WDEB386 can generate same stack trace.
  100. pop bp
  101. ret 2
  102. cEnd nogen
  103. if KDEBUG
  104. BegData
  105. szCRLF db 13,10,0
  106. EndData
  107. ; trashes ES - but caller saves it
  108. cProc KOutDSStr,<PUBLIC,FAR>,<ds>
  109. parmW string
  110. cBegin
  111. .386p
  112. pushad ; save upper 16 bits of EAX, etc
  113. push fs
  114. push gs
  115. .286p
  116. pushf
  117. push cs
  118. push ds
  119. push es
  120. push ss
  121. pusha
  122. SetKernelDS
  123. mov si,string
  124. call KOutDebugStr ; expects pusha right before call
  125. popa
  126. add sp, 8 ; don't need to restore seg regs
  127. popf
  128. .386p
  129. pop gs
  130. pop fs
  131. popad
  132. .286p
  133. cEnd
  134. cProc _krDebugTest,<PUBLIC, FAR, NONWIN>,<DS>
  135. ParmW flags
  136. ParmW psz
  137. LocalW axSave
  138. LocalW bxSave
  139. LocalW esSave
  140. LocalB fBreakPrint
  141. cBegin
  142. assumes ds,NOTHING
  143. mov axSave,ax ; save these regs before they're trashed
  144. mov bxSave,bx
  145. mov esSave,es
  146. ;
  147. ; If this .exe hasn't been relocated yet, just call FatalExit.
  148. ;
  149. mov ax,cs:MyCSDS
  150. cmp ax,1000h ;; DATA should be selector, not addr
  151. jc @F
  152. jmp kdtnobreak
  153. @@:
  154. mov es,ax
  155. assumes es,DATA
  156. ;
  157. ; First use DebugOptions to determine whether we should print anything
  158. ; and/or break with a fatalexit.
  159. ;
  160. errnz low(DBF_SEVMASK)
  161. errnz low(DBF_TRACE)
  162. errnz low(DBF_WARNING)
  163. errnz low(DBF_ERROR)
  164. errnz low(DBF_FATAL)
  165. mov bx,es:DebugOptions
  166. mov ax,flags
  167. and ah,high(DBF_SEVMASK)
  168. mov al,2 ; fBreak = FALSE, fPrint = TRUE
  169. cmp ah,high(DBF_TRACE)
  170. jnz notrace
  171. push ax
  172. mov es:fKTraceOut, 1 ; Set flag for DebugWrite
  173. mov ax,flags ; if (!((flags & DBF_FILTERMASK) & DebugFilter))
  174. and ax,DBF_FILTERMASK
  175. test ax,es:DebugFilter
  176. pop ax
  177. jnz @F
  178. and al,not 2 ; fPrint = FALSE
  179. jmp short kdtnobreak
  180. @@:
  181. test bx,DBO_TRACEBREAK ; else if (DebugOptions & DBO_TRACEBREAK)
  182. jnz kdtbreak ; fBreak = TRUE
  183. jmp short kdtnobreak
  184. notrace:
  185. cmp ah,high(DBF_WARNING)
  186. jnz nowarn
  187. test bx,DBO_WARNINGBREAK
  188. jnz kdtbreak
  189. jmp short kdtnobreak
  190. nowarn:
  191. cmp ah,high(DBF_ERROR)
  192. jnz dofatal
  193. test bx,DBO_NOERRORBREAK
  194. jnz kdtnobreak
  195. jmp short kdtbreak
  196. dofatal:
  197. test bx,DBO_NOFATALBREAK
  198. jnz kdtnobreak
  199. errn$ kdtbreak
  200. kdtbreak:
  201. or al,1 ; fBreak = TRUE
  202. kdtnobreak:
  203. ;
  204. ; If DBO_SILENT, then fPrint = FALSE
  205. ;
  206. test bx,DBO_SILENT
  207. jz @F
  208. and al,not 2
  209. @@:
  210. mov fBreakPrint,al
  211. ;
  212. ; if (fBreak || fPrint)
  213. ; print out the string
  214. ;
  215. or al,al ; if !(fBreak | fPrint)
  216. jz kdtnoprint
  217. assumes es,NOTHING
  218. mov es,esSave ; restore registers
  219. mov ax,axSave
  220. mov bx,bxSave
  221. push psz
  222. call KOutDSStr ; output the string
  223. ifndef WOW
  224. push offset szCRLF
  225. call KOutDSStr
  226. endif
  227. kdtnoprint:
  228. test fBreakPrint,1 ; if fBreak, then FatalExit
  229. jz kdtexit
  230. kdtdobreak:
  231. cCall FatalExit,<flags>
  232. kdtexit:
  233. SetKernelDS es
  234. mov es:fKTraceOut,0 ; Clear DebugWrite flag
  235. mov ax, axSave
  236. mov bx, bxSave
  237. mov es, esSave
  238. cEnd
  239. ifdef DISABLE
  240. flags equ word ptr [bp+6]
  241. msg equ word ptr [bp+8]
  242. appDS equ word ptr [bp-2]
  243. appAX equ word ptr [bp-4]
  244. ;myDS equ word ptr [bp-6]
  245. _krDebugTest proc far ;Per-component - check right flags
  246. public _krDebugTest
  247. push bp
  248. mov bp, sp
  249. push ds ; at BP-2
  250. push ax ; at BP-4
  251. mov ax, _DATA
  252. cmp ax, 1000h ;; DATA should be selector, not addr
  253. jnc skip
  254. mov ds, ax
  255. assume ds:_DATA
  256. mov ax, [flags] ; See if component enabled
  257. and ax, [_krInfoLevel]
  258. and al, byte ptr [_Win3InfoLevel] ; See if system enabled
  259. cmp ax, [flags]
  260. jnz skip
  261. push bx ; Print it, so format message
  262. test al, DEB_ERRORS
  263. mov bx, dataoffset STR_krError
  264. jnz @F
  265. test al, DEB_WARNS
  266. mov bx, dataoffset STR_krWarn
  267. jnz @F
  268. test al, DEB_TRACES
  269. mov bx, dataoffset STR_krTrace
  270. jz short deb_no_msg_type
  271. @@: push bx
  272. call KOutDSStr
  273. deb_no_msg_type:
  274. mov bx, dataoffset STR_krTable
  275. or ah, ah
  276. jz deb_show_it
  277. @@: add bx, 2 ; get next string table entry
  278. shr ah, 1 ; find which category
  279. jnz @B
  280. deb_show_it:
  281. push [bx] ;; push parameter
  282. call KOutDSStr
  283. pop bx ;; restore reg
  284. mov ax, [appAX] ; print message passed in
  285. push ds
  286. mov ds, appDS ; restore App ds for error strings
  287. push [msg]
  288. call KOutDSStr
  289. pop ds ; restore kernel DS
  290. mov ax, [flags] ; shall we have a breakpoint?
  291. and ax, [_krBreakLevel]
  292. and al, byte ptr _Win3BreakLevel
  293. cmp ax, [flags]
  294. jnz skip
  295. INT3_DEBUG
  296. skip:
  297. test byte ptr [flags], DEB_FERRORS
  298. jz @F
  299. push 0
  300. push cs:MyCSDS
  301. push word ptr [bp+8]
  302. cCall FatalAppExit ;,<0,DGROUP,[bp+8]>
  303. @@:
  304. pop ax
  305. pop ds
  306. pop bp
  307. retf
  308. _krDebugTest endp
  309. endif; DISABLE
  310. endif; KDEBUG
  311. ife KDEBUG ; RETAIL ONLY SECTION STARTS HERE!
  312. ifndef WOW ; WOW uses only the "debug" version
  313. ; of FatalExit which calls FatalExitC.
  314. ; FatalExitC is thunked in WOW, the
  315. ; version in rip.c is disabled.
  316. ;-----------------------------------------------------------------------;
  317. ; ;
  318. ; FatalExit() - ;
  319. ; ;
  320. ;-----------------------------------------------------------------------;
  321. ; Retail version. The Debug version is in RIP.C.
  322. assumes ds, nothing
  323. assumes es, nothing
  324. cProc FatalExit,<PUBLIC,FAR>
  325. parmW errCode
  326. cBegin
  327. SetKernelDS
  328. push 0
  329. push ds
  330. push dataOffset szFatalExit
  331. cCall IFatalAppExit ;,<0, ds, dataOffset szUndefDyn>
  332. cEnd
  333. cProc FatalExitDeath,<PUBLIC,FAR>
  334. parmW errCode
  335. localD pbuf
  336. localV buf,6
  337. cBegin
  338. if 0
  339. mov ax,4CFFh
  340. int 21h
  341. else
  342. SetKernelDS
  343. cCall TextMode ; Is USER started?
  344. ; cmp pDisableProc.sel,0
  345. ; je fex1
  346. ; cCall pDisableProc ; Yes, Call USER's DisableOEMLayer()
  347. ; ; to get to the text screen
  348. ; jmps fex1a
  349. ;fex1:
  350. ; mov ax, 6 ; set text mode
  351. ; int 10h
  352. ;fex1a:
  353. ; Is Int 21h hooked?
  354. cmp prevInt21Proc.sel,0
  355. je fex2
  356. cCall InternalDisableDOS ; Yes, disable Int 21h
  357. fex2:
  358. mov cx,errCode ; No output if error code is zero
  359. jcxz fe4
  360. ; Write "FatalExit = " message to STDOUT.
  361. mov bx,1
  362. mov dx,dataOffset szExitStr1
  363. mov cx,20
  364. mov ah,40h
  365. int 21h
  366. ; Error code of FFFF means Stack Overflow.
  367. mov dx,errCode
  368. inc dx
  369. jnz fe1
  370. mov dx,dataOffset szExitStr2 ; "Stack Overflow" message
  371. mov cx,17
  372. mov ah,40h
  373. int 21h
  374. jmps fe4
  375. UnSetKernelDS
  376. fe1:
  377. ; Write out error code in Hex.
  378. dec dx
  379. push ss
  380. pop es
  381. lea di,buf
  382. mov ax,'x' shl 8 OR '0'
  383. stosw
  384. mov cx,4
  385. rol dx,cl ; Rotate most significant into view
  386. fe2:
  387. mov ax,dx
  388. and ax,0Fh
  389. push cx
  390. mov cl,4
  391. rol dx,cl ; Rotate next byte into view
  392. pop cx
  393. add al,'0'
  394. cmp al,'9'
  395. jbe fe3
  396. add al,'A'-':'
  397. fe3:
  398. stosb
  399. loop fe2
  400. mov ax,10 shl 8 OR 13
  401. stosw
  402. xor ax,ax
  403. stosb
  404. lea dx,buf
  405. push ss
  406. pop ds
  407. mov cx,8
  408. mov bx,1
  409. mov ah,40h
  410. int 21h ; Write it out
  411. fe4:
  412. mov ax,errcode
  413. cCall ExitKernel,<ax>
  414. endif
  415. cEnd
  416. endif ; ifndef WOW
  417. else ; DEBUG ONLY SECTION STARTS HERE!
  418. ;-----------------------------------------------------------------------;
  419. ; ;
  420. ; GetSymFileName() - ;
  421. ; ;
  422. ;-----------------------------------------------------------------------;
  423. assumes ds, nothing
  424. assumes es, nothing
  425. ifdef WOW
  426. cProc GetSymFileName,<PUBLIC,FAR>,<ds,si,di>
  427. else
  428. cProc GetSymFileName,<PUBLIC,NEAR>,<ds,si,di>
  429. endif
  430. ParmW hExe
  431. ParmD lpName
  432. cBegin
  433. cld
  434. les di,lpName
  435. SetKernelDS
  436. ;; cmp fWinX,0
  437. ;; je slowboot
  438. ;; mov ax,hExe
  439. ;; cmp hExeHead,ax
  440. ;; mov ds,ax
  441. ;; UnSetKernelDS
  442. ;; je makename
  443. ;; mov si,ds:[ne_pfileinfo]
  444. ;; or si,si
  445. ;; jnz havename
  446. ;;makename:
  447. ;; mov si,ds:[ne_restab]
  448. ;; xor ax,ax
  449. ;; lodsb
  450. ;; mov cx,ax
  451. ;; rep movsb
  452. ;;appendext:
  453. ;; mov ax,'S.'
  454. ;; stosw
  455. ;; mov ax,'MY'
  456. ;; stosw
  457. ;; xor ax,ax
  458. ;; stosb
  459. ;; jmps namedone
  460. ;;
  461. ;;slowboot:
  462. mov ds,hExe
  463. mov si,ds:[ne_pfileinfo]
  464. havename:
  465. add si,opFile
  466. nameloop:
  467. lodsb
  468. cmp al,'.'
  469. je appendext
  470. stosb
  471. jmp nameloop
  472. appendext:
  473. mov ax,'S.'
  474. stosw
  475. mov ax,'MY'
  476. stosw
  477. xor ax,ax
  478. stosb
  479. les ax,lpName
  480. mov dx,es
  481. cEnd
  482. ;-----------------------------------------------------------------------;
  483. ; ;
  484. ; OpenSymFile() - ;
  485. ; ;
  486. ;-----------------------------------------------------------------------;
  487. assumes ds, nothing
  488. assumes es, nothing
  489. ifdef WOW
  490. cProc OpenSymFile,<PUBLIC,FAR>,<ds,si,di>
  491. else
  492. cProc OpenSymFile,<PUBLIC,NEAR>,<ds,si,di>
  493. endif
  494. ParmD path
  495. LocalV Buffer,MaxFileLen
  496. cBegin
  497. lds dx,path ; get pointer to pathname
  498. mov di,3D40h ; open file function code (SHARE_DENY_NONE)
  499. ; We don't use open test for existance, rather we use get
  500. ; file attributes. This is because if we are using Novell
  501. ; netware, opening a file causes Novell to execute its
  502. ; own path searching logic, but we want our code to do it.
  503. mov ax,4300h ; Get file attributes
  504. int 21h ; Does the file exist?
  505. jc opnnov ; No, then don't do the operation
  506. mov ax,di ; Yes, open the file then
  507. int 21h
  508. jnc opn2
  509. opnnov:
  510. mov ax, -1
  511. opn2: mov bx,ax
  512. cEnd
  513. ;-----------------------------------------------------------------------;
  514. ; ;
  515. ; GetDebugString() - ;
  516. ; ;
  517. ;-----------------------------------------------------------------------;
  518. ; Finds the 'strIndex'-th string in 'szDebugStr'. The strings are defined
  519. ; in STRINGS.ASM.
  520. assumes ds, nothing
  521. assumes es, nothing
  522. ifdef WOW
  523. cProc GetDebugString,<PUBLIC,FAR>,<di>
  524. else
  525. cProc GetDebugString,<PUBLIC,NEAR>,<di>
  526. endif
  527. parmW strIndex
  528. cBegin
  529. SetKernelDS es
  530. mov di,dataOffset szDebugStr
  531. mov bx,strIndex
  532. cld
  533. gds1:
  534. dec bx
  535. jl gdsx
  536. xor ax,ax
  537. mov cx,-1
  538. repne scasb
  539. cmp es:[di],al
  540. jne gds1
  541. xor di,di
  542. mov es,di
  543. gdsx:
  544. mov ax,di
  545. mov dx,es
  546. UnSetKernelDS es
  547. cEnd
  548. ;-----------------------------------------------------------------------;
  549. ; ;
  550. ; GetExeHead() - ;
  551. ; ;
  552. ;-----------------------------------------------------------------------;
  553. assumes ds, nothing
  554. assumes es, nothing
  555. ifdef WOW
  556. cProc GetExeHead,<PUBLIC,FAR>
  557. else
  558. cProc GetExeHead,<PUBLIC,NEAR>
  559. endif
  560. cBegin nogen
  561. push ds
  562. SetKernelDS
  563. mov ax,[hExeHead]
  564. pop ds
  565. UnSetKernelDS
  566. ret
  567. cEnd nogen
  568. ;-----------------------------------------------------------------------;
  569. ; ;
  570. ; LSHL() - ;
  571. ; ;
  572. ;-----------------------------------------------------------------------;
  573. ifdef WOW
  574. if KDEBUG
  575. sEnd CODE
  576. sBegin MISCCODE
  577. assumes cs, MISCCODE
  578. endif
  579. endif
  580. assumes ds, nothing
  581. assumes es, nothing
  582. cProc LSHL,<PUBLIC,NEAR>
  583. cBegin nogen
  584. pop bx
  585. pop cx
  586. pop ax
  587. xor dx,dx
  588. lshl1:
  589. shl ax,1
  590. rcl dx,1
  591. loop lshl1
  592. jmp bx
  593. cEnd nogen
  594. ifdef WOW
  595. if KDEBUG
  596. sEnd MISCCODE
  597. sBegin CODE
  598. assumes CS,CODE
  599. endif
  600. endif
  601. ;-----------------------------------------------------------------------;
  602. ; ;
  603. ; FarKernelError() - ;
  604. ; ;
  605. ; 05-09-91 EarleH modified to save and restore all registers. ;
  606. ; ;
  607. ;-----------------------------------------------------------------------;
  608. ; Far entry point for KernelError(). Allows the multitude of calls to
  609. ; KernelError() be made as near calls.
  610. assumes ds, nothing
  611. assumes es, nothing
  612. cProc FarKernelError,<PUBLIC,FAR,NODATA>
  613. cBegin nogen
  614. push bp
  615. mov bp,sp
  616. SAVEREGS
  617. mov ax, _DATA
  618. mov ds, ax
  619. ; push [bp+14]
  620. push [bp+12]
  621. push ds ; seg of string
  622. push [bp+10]
  623. push [bp+8]
  624. push [bp+6]
  625. mov bp,[bp]
  626. ifdef WOW
  627. cCall <far ptr Far_KernelError>
  628. else
  629. call KernelError
  630. endif
  631. or ax, ax
  632. RESTOREREGS
  633. pop bp
  634. jz @F
  635. INT3_DEBUG
  636. @@:
  637. ret 10
  638. cEnd nogen
  639. ;-----------------------------------------------------------------------;
  640. ; ;
  641. ; NearKernelError() - ;
  642. ; ;
  643. ; 05-09-91 EarleH modified to save and restore all registers. ;
  644. ; ;
  645. ;-----------------------------------------------------------------------;
  646. ifndef WOW
  647. cProc NearKernelError,<PUBLIC,NEAR,NODATA>
  648. cBegin nogen
  649. push bp
  650. mov bp,sp
  651. SAVEREGS
  652. mov ax, _DATA
  653. mov ds, ax
  654. ; push [bp+12] ; only pass 4 words now
  655. push [bp+10] ; err code
  656. push ds ; seg of string
  657. push [bp+8] ; offset of string
  658. push [bp+6]
  659. push [bp+4]
  660. mov bp,[bp] ; hide this stack frame
  661. call KernelError
  662. or ax, ax
  663. RESTOREREGS
  664. pop bp
  665. jz @F
  666. INT3_DEBUG
  667. @@:
  668. ret 8
  669. cEnd nogen
  670. endif ;; ! WOW
  671. ;-----------------------------------------------------------------------;
  672. ; ;
  673. ; IsCodeSelector() - ;
  674. ; ;
  675. ;-----------------------------------------------------------------------;
  676. ifdef WOW
  677. cProc IsCodeSelector,<PUBLIC,FAR>
  678. else
  679. cProc IsCodeSelector,<PUBLIC,NEAR>
  680. endif
  681. parmW Candidate
  682. cBegin
  683. mov ax,Candidate
  684. lar dx,ax
  685. jz lar_passed
  686. xor ax,ax
  687. jmp ics_ret
  688. lar_passed:
  689. xor ax,ax
  690. test dh,00001000b ; Executable segment descriptor?
  691. jz ics_ret ; No
  692. push cs ; Yes
  693. pop dx
  694. and dx,3
  695. and Candidate,3 ; RPL matches that of CS?
  696. cmp dx,Candidate
  697. jne ics_ret ; No
  698. inc ax ; Yes
  699. ics_ret:
  700. cEnd
  701. endif; DEBUG ; DEBUG ONLY SECTION ENDS HERE
  702. ;-----------------------------------------------------------------------;
  703. ; ;
  704. ; DebugBreak() - ;
  705. ; ;
  706. ;-----------------------------------------------------------------------;
  707. assumes ds, nothing
  708. assumes es, nothing
  709. if KDEBUG
  710. db_tab dw db_t, db_w, db_e, db_f, db_k, db_3
  711. db_len equ ($ - db_tab) / 2
  712. endif
  713. cProc DebugBreak,<PUBLIC,FAR>
  714. cBegin nogen
  715. if KDEBUG
  716. cmp ax, 0DACh
  717. jnz db_3
  718. cmp bx, db_len
  719. jae db_3
  720. shl bx, 1
  721. jmp db_tab[bx]
  722. db_t: krDebugOut DEB_TRACE, "Test trace"
  723. jmps db_end
  724. db_w: krDebugOut DEB_WARN, "Test warning"
  725. jmps db_end
  726. db_e: krDebugOut DEB_ERROR, "Test error"
  727. jmps db_end
  728. db_f: krDebugOut DEB_FERROR, "Test fatal error"
  729. jmps db_end
  730. db_k: kerror 0, "This is a kernel error"
  731. jmps db_end
  732. db_3:
  733. endif
  734. INT3_DEBUG ; Jump to debugger if installed
  735. db_end:
  736. ret
  737. cEnd nogen
  738. ;-----------------------------------------------------------------------;
  739. ; ;
  740. ; TextMode() - Enter text mode for debugging load failure ;
  741. ; ;
  742. ;-----------------------------------------------------------------------;
  743. assumes ds, nothing
  744. assumes es, nothing
  745. cProc TextMode,<PUBLIC,NEAR,NODATA>,<ds>
  746. cBegin
  747. SetKernelDS
  748. cmp word ptr [pDisableProc+2],0
  749. je tm1
  750. cCall [pDisableProc]
  751. jmps tm2
  752. tm1:
  753. mov ax, 3
  754. int 10h
  755. tm2:
  756. cEnd
  757. ;-----------------------------------------------------------------------;
  758. ; ;
  759. ; DoAbort() - ;
  760. ; ;
  761. ;-----------------------------------------------------------------------;
  762. assumes ds, nothing
  763. assumes es, nothing
  764. cProc DoAbort,<PUBLIC,NEAR>
  765. cBegin nogen
  766. SetKernelDS
  767. cCall TextMode
  768. ; cmp word ptr [pDisableProc+2],0
  769. ; je doa1
  770. ; cCall [pDisableProc]
  771. ;doa1:
  772. mov ax,1
  773. cCall ExitKernel,<ax>
  774. UnSetKernelDS
  775. cEnd nogen
  776. ;-----------------------------------------------------------------------;
  777. ;
  778. ; HandleParamError
  779. ;
  780. ; This entry point is jumped to by the parameter validation code of
  781. ; USER and GDI (and KERNEL). Its job is to parse the error code
  782. ; and, if necessary, RIP or jmp to the error handler routine
  783. ;
  784. ; Stack on entry: Far return addr to validation code
  785. ; Saved error handler offset
  786. ; Saved BP
  787. ; API far ret addr
  788. ;
  789. ;-----------------------------------------------------------------------;
  790. ERR_WARNING equ 08000h ; from error.h/windows.h/layer.inc
  791. LabelFP <PUBLIC, HandleParamError>
  792. push bp
  793. mov bp,sp
  794. push bx ; save err code
  795. push bx ; push err code
  796. push [bp+4] ; push err return addr as place where error occured
  797. push [bp+2]
  798. push cx ; push parameter
  799. push ax
  800. call far ptr LogParamError ; yell at the guy
  801. pop bx
  802. pop bp
  803. test bh,high(ERR_WARNING) ; warn or fail?
  804. errnz low(ERR_WARNING)
  805. jnz @F
  806. pop bx
  807. pop ax ; pop far return addr
  808. pop bx ; get error handler address
  809. pop bp ; restore BP
  810. and bp,not 1 ; Make even in case "inc bp" for ATM
  811. push ax
  812. push bx ; far return to handler
  813. xor ax,ax ; set dx:ax == 0 for default return value
  814. cwd
  815. xor cx,cx ; set cx == 0 too, for kernel error returns
  816. mov es,ax ; clear ES just in case it contains
  817. ; a Windows DLL's DS...
  818. @@:
  819. retf
  820. cProc DebugFillBuffer,<PUBLIC, FAR, PASCAL, NONWIN>,<DI>
  821. ParmD lpb
  822. ParmW cb
  823. cBegin
  824. if KDEBUG
  825. assumes ES,data
  826. mov ax,_DATA
  827. mov es,ax
  828. test es:DebugOptions,DBO_BUFFERFILL
  829. assumes ES,nothing
  830. jz dfbexit
  831. les di,lpb
  832. mov cx,cb
  833. mov ax,(DBGFILL_BUFFER or (DBGFILL_BUFFER shl 8))
  834. cld
  835. shr cx,1
  836. rep stosw
  837. rcl cx,1
  838. rep stosb
  839. dfbexit:
  840. endif; KDEBUG
  841. cEnd
  842. ;========================================================================
  843. ;
  844. ; void FAR _cdecl DebugOutput(UINT flags, LPCSTR lpszFmt, ...);
  845. ;
  846. ; NOTE: there is a CMACROS bug with C that causes the parameter offsets
  847. ; to be calculated incorrectly. Offsets calculated by hand here.
  848. ;
  849. cProc DebugOutput,<PUBLIC, FAR, C, NONWIN>
  850. flags equ <[bp+2+4]> ; parmW flags point past ret addr & saved bp
  851. lpszFmt equ <[bp+2+4+2]> ; parmD lpszFmt
  852. cBegin
  853. if KDEBUG
  854. push bp ; generate a stack frame
  855. mov bp,sp
  856. SAVEREGS ; save all registers
  857. push ds
  858. SetKernelDS
  859. lea ax,flags ; point at flags, lpszFmt, and rest of arguments
  860. push ss
  861. push ax
  862. call DebugOutput2
  863. UnsetKernelDS
  864. pop ds
  865. or ax,ax ; test break flag
  866. RESTOREREGS
  867. pop bp
  868. jz @F ; break if needed
  869. INT3_DEBUG
  870. @@:
  871. endif
  872. cEnd
  873. ;========================================================================
  874. ;
  875. ; void WINAPI LogError(UINT err, void FAR* lpInfo);
  876. ;
  877. cProc LogError,<PUBLIC, FAR, PASCAL, NONWIN>
  878. ParmD err
  879. ParmW lpInfo
  880. cBegin
  881. SAVEREGS
  882. assumes ds,NOTHING
  883. cCall DebugLogError,<err, lpInfo>
  884. RESTOREREGS
  885. cEnd
  886. ;========================================================================
  887. ;
  888. ; void WINAPI LogParamError(UINT err, FARPROC lpfn, void FAR* param);
  889. ;
  890. cProc LogParamError,<PUBLIC, FAR, PASCAL, NONWIN>
  891. ParmW err
  892. ParmD lpfn
  893. ParmD param
  894. cBegin
  895. assumes ds,NOTHING
  896. SAVEREGS
  897. ; Call debugger hook (note the reversed parameter order)
  898. ;
  899. cCall DebugLogParamError,<param, lpfn, err>
  900. if KDEBUG
  901. push ds
  902. SetKernelDS
  903. assumes ds,DATA
  904. mov bx, [bp+0] ; address of faulting code
  905. mov bx, ss:[bx+0]
  906. ; mov bx, ss:[bx+0]
  907. mov bx, ss:[bx+4]
  908. cCall LogParamError2,<err, lpfn, param, bx>
  909. UnsetKernelDS
  910. pop ds
  911. assumes ds,NOTHING
  912. or ax,ax ; test break flag
  913. endif
  914. RESTOREREGS
  915. if KDEBUG
  916. jz @F ; break if needed
  917. INT3_DEBUG
  918. @@:
  919. endif
  920. cEnd
  921. ;-----------------------------------------------------------------------
  922. sEnd CODE
  923. if KDEBUG
  924. ifdef WOW
  925. sBegin MISCCODE
  926. assumes cs, MISCCODE
  927. assumes ds, nothing
  928. assumes es, nothing
  929. externFP KernelError
  930. ;-----------------------------------------------------------------------;
  931. ; allows KernelError to be called from _TEXT code segment
  932. cProc Far_KernelError,<PUBLIC,FAR>
  933. parmW errcode
  934. parmD lpmsg1
  935. parmD lpmsg2
  936. cBegin
  937. push [bp+14]
  938. push [bp+12]
  939. push [bp+10]
  940. push [bp+8]
  941. push [bp+6]
  942. call far ptr KernelError
  943. cEnd
  944. sEnd MISCCODE
  945. endif ;; WOW
  946. endif ;; KDEBUG
  947. end