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.

1273 lines
27 KiB

  1. ; Include file for kernel assembler source files.
  2. ?PLM = 1
  3. ?WIN = 1
  4. ?NODATA = 1
  5. ?DF = 1
  6. ?386regs = 1
  7. ifndef WINDEBUG
  8. KDEBUG = 0
  9. WDEBUG = 0
  10. DOS5 = 1 ; Do not mark far stack frames.
  11. else
  12. KDEBUG = 1
  13. WDEBUG = 1
  14. endif
  15. SHARE_AWARE = 0
  16. BUILDDLL equ 1
  17. PMODE equ 1
  18. include cmacros.inc
  19. include logerror.inc
  20. include vint.inc
  21. DEB_ERROR equ DBF_ERROR
  22. DEB_WARN equ DBF_WARNING
  23. DEB_TRACE equ DBF_TRACE
  24. DEB_FERROR equ DBF_FATAL
  25. DEB_krMemMan equ DBF_KRN_MEMMAN
  26. DEB_krLoadMod equ DBF_KRN_LOADMODULE
  27. DEB_krLoadSeg equ DBF_KRN_SEGMENTLOAD
  28. DEB_IERROR equ DBF_ERROR
  29. DEB_IWARN equ DBF_WARNING
  30. DEB_ITRACE equ DBF_TRACE
  31. DEB_IFERROR equ DBF_FATAL
  32. ;DEB_ERROR = 1
  33. ;DEB_WARN = 2
  34. ;DEB_TRACE = 4
  35. ;DEB_FERROR = 8 ;; fatal error - terminate app
  36. ;DEB_IERROR = 10h
  37. ;DEB_IWARN = 20h
  38. ;DEB_ITRACE = 40h
  39. ;DEB_IFERROR = 80h ;; fatal error - terminate app
  40. ;DEB_FERRORS = DEB_FERROR or DEB_IFERROR
  41. ;DEB_ERRORS = DEB_ERROR OR DEB_IERROR OR DEB_FERRORS
  42. ;DEB_WARNS = DEB_WARN OR DEB_IWARN
  43. ;DEB_TRACES = DEB_TRACE OR DEB_ITRACE
  44. ;DEB_NOCRLF = 8000h ;; No CR/LF in string
  45. DEB_BREAKLEVEL = 099h
  46. DEB_INFOLEVEL = 099h or 022h
  47. if KDEBUG
  48. ;include win3deb.inc
  49. ;declare_debug kr
  50. ;declare_areas Kernel, kr, <MemMan, LoadMod, LoadSeg>
  51. ifndef win3deb
  52. externFP _krDebugTest
  53. endif
  54. BegData macro
  55. _DATA SEGMENT PARA PUBLIC 'DATA'
  56. endm
  57. EndData macro
  58. _DATA ENDS
  59. endm
  60. krDebugOut macro flags,msg
  61. local a, b
  62. BegData
  63. a label byte
  64. ife ((flags and DBF_SEVMASK) - DBF_FATAL)
  65. db "fatl"
  66. elseife ((flags and DBF_SEVMASK) - DBF_ERROR)
  67. db "err"
  68. elseife ((flags and DBF_SEVMASK) - DBF_WARNING)
  69. db "wn"
  70. else
  71. db "t"
  72. endif
  73. ifdef WOW
  74. db " W16Kernel: "
  75. else
  76. db " Kernel: "
  77. endif
  78. db msg
  79. db 0ah
  80. db 0
  81. EndData
  82. push flags or DBF_KERNEL
  83. push offset a
  84. call _krDebugTest
  85. endm
  86. else
  87. krDebugOut macro flag, str, vals
  88. endm
  89. endif
  90. if1
  91. ifndef ?DFSTACK
  92. ?DFSTACK1 = 0
  93. else
  94. ?DFSTACK1 = 1
  95. endif
  96. endif
  97. ; Define IGROUP segments
  98. createSeg _TEXT,CODE,WORD,PUBLIC,CODE,IGROUP
  99. createSeg _INITTEXT,INITCODE,WORD,PUBLIC,CODE,IGROUP
  100. defGrp IGROUP,CODE
  101. ; Define Non-resident segments (after "defGrp IGROUP")
  102. createSeg _NRESTEXT,NRESCODE,WORD,PUBLIC,CODE
  103. createSeg _MISCTEXT,MISCCODE,WORD,PUBLIC,CODE
  104. ; Define DGROUP segments
  105. createSeg _DATA,DATA,PARA,PUBLIC,DATA,DGROUP
  106. createSeg _GPFIX0,GPFIX0,WORD,PUBLIC,DATA,DGROUP ; GP fault trapping
  107. createSeg _GPFIX,GPFIX,WORD,PUBLIC,DATA,DGROUP
  108. createSeg _GPFIX1,GPFIX1,WORD,PUBLIC,DATA,DGROUP
  109. createSeg _INITDATA,INITDATA,WORD,PUBLIC,DATA,DGROUP
  110. if ?DFSTACK1
  111. createSeg STACK,STACK,PARA,PUBLIC,DATA,DGROUP
  112. endif
  113. createSeg _PADDATA,PADDATA,BYTE,PUBLIC,DATA,DGROUP
  114. defGrp DGROUP,DATA
  115. if ?CHKSTK1
  116. externP <chkstk>
  117. endif
  118. DISCARD_HIGH = 1
  119. TONYS_EMS_STUFF = 0
  120. if KDEBUG
  121. RSHORT equ <>
  122. else
  123. RSHORT equ short
  124. endif
  125. .286
  126. .286p
  127. INTBASE = 90h
  128. RNTBASE = 45h
  129. ifndef PM386
  130. PMODE32 = 0
  131. else
  132. PMODE32 = 1
  133. endif
  134. ifndef ALIASTRACKING
  135. ALIASES = 0
  136. else
  137. ALIASES = 1
  138. endif
  139. if1
  140. ifdef FE_SB
  141. FFDBCS = 1
  142. else
  143. FFDBCS = 0
  144. endif
  145. KRNLDS EQU <DATA>
  146. ifdef ROMWIN
  147. ROM = 1
  148. if PMODE
  149. %OUT ROM Kernel requires Protect Mode
  150. .err
  151. endif
  152. else
  153. ROM = 0
  154. endif
  155. outif ROM,0,<ROM Windows kernel>
  156. outif KDEBUG,0,<Debug Kernel.>
  157. outif FFDBCS,0,<DBCS code enabled>
  158. ; The following three are obsolete, but they need to have the
  159. ; proper values so dead code doesn't get assembled, and live
  160. ; code does.
  161. SDEBUG equ 1
  162. LDCHKSUM equ 0
  163. SWAPPRO equ 0
  164. endif
  165. ERR_LMEM = 00100h ; Local memory errors
  166. ERR_LMEMCRIT = 00140h ; Local heap is busy
  167. ERR_LMEMHANDLE = 00180h ; Invalid local handle
  168. ERR_LMEMLOCK = 001C0h ; LocalLock count overflow
  169. ERR_LMEMUNLOCK = 001F0h ; LocalUnlock count underflow
  170. ERR_GMEM = 00200h ; global memory errors
  171. ;ERR_GMEMCRIT = 00240h ; Critical section problems
  172. ERR_GMEMHANDLE = 00280h ; Invalid global handle
  173. ERR_GMEMLOCK = 002C0h ; globalLock count overflow
  174. ERR_GMEMUNLOCK = 002F0h ; globalUnlock count underflow
  175. ;ERR_TASK = 00300h ; task schedule errors
  176. ;ERR_TASKID = 00301h ; Invalid task ID
  177. ;ERR_TASKEXIT = 00302h ; Invalid exit system call
  178. ;ERR_TASKFRAME = 00303h ; Invalid BP chain
  179. ;ERR_LD = 00400h ; dynamic loader/linker errors
  180. ;ERR_LDBOOT = 00401h ; Error during boot process
  181. ;ERR_LDLOAD = 00402h ; Error loading a module
  182. ;ERR_LDORD = 00403h ; Invalid ordinal reference
  183. ;ERR_LDNAME = 00404h ; Invalid entry name reference
  184. ;ERR_LDPROC = 00405h ; Invalid start proc
  185. ERR_LDMODULE = 00406h ; Invalid module handle
  186. ;ERR_LDRELOC = 00407h ; Invalid relocation record
  187. ;ERR_LDFWDREF = 00408h ; Error saving forward reference
  188. ;ERR_LDREADSEG = 00409h ; Error reading segment contents
  189. ;ERR_LDREADREL = 00410h ; Error reading segment contents
  190. ;ERR_LDDISK = 00411h ; Insert disk for specified file
  191. ERR_LDNRTABLE = 00412h ; Error reading non-resident table
  192. ;ERR_LDFILES = 00413h ; Out of files
  193. ;ERR_LDINT3F = 004FFh ; INT 3F handler unable to load segment
  194. ;ERR_RESMAN = 00500h ; resource manager/user profile errors
  195. ;ERR_MISSRES = 00501h ; Missing resource table
  196. ;ERR_BADRESTYPE = 00502h ; Bad resource type
  197. ;ERR_BADRESNAME = 00503h ; Bad resource name
  198. ERR_BADRESFILE = 00504h ; Bad resource file
  199. ERR_BADRESREAD = 00505h ; Error reading resource
  200. ERR_BADDEFAULT = 00506h ; Bad default pointer for profile routine
  201. ;ERR_ATOM = 00600h ; atom manager errors
  202. ;ERR_IO = 00700h ; I/O package errors
  203. ERR_PARAMETER = 00800h ; Internal KERNEL parameter validation
  204. ;** PTrace notification indexes. See 2lddebug and 3lddebug
  205. SDM_RIN = 9
  206. SDM_BANKLINE = 10
  207. SDM_NEWTASK = 11
  208. SDM_FLUSHTASK = 12
  209. SDM_SWITCHOUT = 13
  210. SDM_SWITCHIN = 14
  211. SDM_KEYBOARD = 15
  212. SDM_MAXFUNC = 15
  213. SDM_LOADSEG = 50h
  214. SDM_MOVESEG = 51h
  215. SDM_FREESEG = 52h
  216. SDM_RELEASESEG = 5Ch
  217. SDM_GLOBALHEAP = 3
  218. SDM_CONWRITE = 12h
  219. SDM_CONREAD = 1
  220. SDM_DGH = 56h
  221. SDM_DFL = 57h
  222. SDM_DLL = 58h
  223. SDM_LOADTASK = 59h
  224. SDM_POSTLOAD = 60h
  225. SDM_EXITCALL = 62h
  226. SDM_INT2 = 63h
  227. SDM_LOADDLL = 64h
  228. SDM_DELMODULE = 65h
  229. ; New notifications
  230. SDM_LOGERROR = 66h ; cx = error code, dx:bx = ptr to optional info
  231. SDM_LOGPARAMERROR = 67h ; es:bx = ptr to struct { err, lpfn, param };
  232. if1
  233. outif ?RIPAUX,0
  234. endif
  235. ; DataBegin/End macros are used to bracket data items. Examples:
  236. ;
  237. ; DataBegin ; in segment DATA
  238. ; globalD flarp,0
  239. ; DataEnd
  240. ;
  241. ; DataBegin INIT ; in segment INITDATA
  242. ; globalW who_cares,1022
  243. ; DataEnd INIT
  244. DataBegin macro type
  245. % sBegin &type&%KRNLDS
  246. assumes ds, %KRNLDS
  247. endm
  248. DataEnd macro type
  249. assumes ds,nothing
  250. sEnd &type&%KRNLDS
  251. endm
  252. ;-----------------------------------------------------------------------
  253. ; cProcVDO - cProc "Validate Debug Only"
  254. ;
  255. ; Same as cProc, except used for "Validate in Debug Only" entry points.
  256. ; Declares Iname if debug, name if retail.
  257. ;
  258. cProcVDO macro name,opts,savelist
  259. if KDEBUG
  260. cProc <I&name>,<opts>,<savelist>
  261. else
  262. LabelFP <PUBLIC, I&name>
  263. cProc <name>,<opts>,<savelist>
  264. endif
  265. endm
  266. ;-----------------------------------------------------------------------
  267. ; LabelVDO
  268. ;
  269. ; Similar to LabelFP, except used for "validate in debug only" entry points.
  270. ; Declares Iname if debug, name if
  271. ;
  272. LabelVDO macro name
  273. if KDEBUG
  274. LabelFP <PUBLIC, I&name>
  275. else
  276. LabelFP <PUBLIC, I&name>
  277. LabelFP <PUBLIC, name>
  278. endif
  279. endm
  280. if KDEBUG
  281. ife ?RIPAUX
  282. externFP FarKernelError
  283. ifndef WOW
  284. externNP NearKernelError
  285. endif
  286. externFP KOutDSStr
  287. endif
  288. ifdef WOW
  289. externFP <KernelError>
  290. else
  291. externNP <KernelError>
  292. endif
  293. DataBegin
  294. externB szFKE ; "**** Fatal Kernel Error ****" - Only define the string once
  295. DataEnd
  296. kerror macro errcode,msg,segarg,offarg
  297. local a
  298. ifnb <errcode> ;; Push either AX or errcode
  299. push errcode ;; Don't trash AX anymore!
  300. else
  301. push ax
  302. endif
  303. ifnb <msg> ;; Put strings in DGROUP so jcond
  304. _DATA SEGMENT PARA PUBLIC 'DATA' ;; can be short (not jump around)
  305. a label byte
  306. db '&msg',0
  307. _DATA ENDS
  308. push dataOffset a
  309. else
  310. push dataOffset szFKE
  311. endif
  312. ifnb <segarg> ;; Push seg:offset or NULLPTR
  313. push segarg
  314. push offarg
  315. else
  316. push 0
  317. push 0
  318. endif
  319. ifdef WOW
  320. call FarKernelError ;; Call Kernel Error
  321. else
  322. call NearKernelError ;; Call Kernel Error
  323. endif
  324. endm
  325. fkerror macro errcode,msg,segarg,offarg
  326. local a
  327. ifnb <errcode> ;; Push either AX or errcode
  328. push errcode ;; Don't trash AX anymore!
  329. else
  330. push ax
  331. endif
  332. ifnb <msg> ;; Put strings in DGROUP so jcond
  333. _DATA SEGMENT PARA PUBLIC 'DATA' ;; can be short (not jump around)
  334. a label byte
  335. db '&msg',0
  336. _DATA ENDS
  337. push dataOffset a
  338. else
  339. push dataOffset szFKE
  340. endif
  341. ifnb <segarg> ;; Push seg:offset or NULLPTR
  342. push segarg
  343. push offarg
  344. else
  345. push 0
  346. push 0
  347. endif
  348. call FarKernelError ;; Call Kernel Error
  349. endm
  350. mkerror macro errcode,msg,segarg,offarg
  351. local a
  352. ifnb <errcode> ;; Push either AX or errcode
  353. push errcode ;; Don't trash AX anymore!
  354. else
  355. push ax
  356. endif
  357. ifnb <msg> ;; Put strings in DGROUP so jcond
  358. _DATA SEGMENT PARA PUBLIC 'DATA' ;; can be short (not jump around)
  359. a label byte
  360. db '&msg',0
  361. _DATA ENDS
  362. push dataOffset a
  363. else
  364. push dataOffset szFKE
  365. endif
  366. ifnb <segarg> ;; Push seg:offset or NULLPTR
  367. push segarg
  368. push offarg
  369. else
  370. push 0
  371. push 0
  372. endif
  373. call FarKernelError ;; Call Kernel Error
  374. endm
  375. else ;; not KDEBUG
  376. ifdef WOW ; For WOW we call FatalExitC which thunks to WK32FatalExit.
  377. externFP <FatalExitC>
  378. kerror macro errcode,msg,segarg,offarg ;; Non-Debug version
  379. cCall FatalExitC,<errcode>
  380. endm
  381. fkerror macro errcode,msg,segarg,offarg ;; Non-Debug version
  382. cCall FatalExitC,<errcode>
  383. endm
  384. mkerror macro errcode,msg,segarg,offarg ;; Non-Debug version
  385. cCall FatalExitC,<errcode>
  386. endm
  387. else ;; not WOW
  388. ife ?RIPAUX ; Dont declare external in RIPAUX.ASM
  389. externFP <FatalExitDeath>
  390. endif
  391. kerror macro errcode,msg,segarg,offarg ;; Non-Debug version
  392. cCall FatalExitDeath,<errcode>
  393. endm
  394. fkerror macro errcode,msg,segarg,offarg ;; Non-Debug version
  395. cCall FatalExitDeath,<errcode>
  396. endm
  397. mkerror macro errcode,msg,segarg,offarg ;; Non-Debug version
  398. cCall FatalExitDeath,<errcode>
  399. endm
  400. endif ;; not WOW
  401. endif ;; not KDEBUG
  402. ; define misc. register pairs
  403. ;
  404. regptr esax,es,ax
  405. regptr esbx,es,bx
  406. regptr essi,es,si
  407. regptr esdi,es,di
  408. regptr dsax,ds,ax
  409. regptr dsbx,ds,bx
  410. regptr dsdx,ds,dx
  411. regptr dssi,ds,si
  412. regptr dsdi,ds,di
  413. regptr csbx,cs,bx
  414. regptr csdx,cs,dx
  415. regptr cssi,cs,si
  416. regptr csdi,cs,di
  417. regptr dxax,dx,ax
  418. regptr ssbx,ss,bx
  419. regptr ssdi,ss,di
  420. ; The jmpnext macro and associated symbols are used to generate
  421. ; the fall-through chain and generate the labels required for
  422. ; error checking.
  423. ??ji = 0 ;;Initial index value
  424. jmpnext macro e
  425. jn %??ji,%(??ji+1),e ;;Set next label
  426. endm
  427. jn macro i,j,e
  428. .sall
  429. ??ji&i:
  430. .xall
  431. ifb <e> ;;If not the end of the chain
  432. db 03Dh ;;cmp ax, next two bytes
  433. errn$ ??ji&j,+2 ;;next label must be two bytes away
  434. endif
  435. ??ji=j ;;increment counter
  436. endm
  437. smov macro segreg1,segreg2
  438. push segreg2
  439. pop segreg1
  440. endm
  441. jmps macro n
  442. jmp short n
  443. endm
  444. ret_far macro add_2_stack
  445. ifnb <add_2_stack>
  446. db 0CAh
  447. dw add_2_stack
  448. else
  449. db 0CBh
  450. endif
  451. endm
  452. entry macro routine
  453. extrn routine :near
  454. dw Offset IGROUP:routine
  455. endm
  456. STACK_SIGNATURE equ 'WD'
  457. MPIT_SIGNATURE equ 'TP'
  458. INT21 macro
  459. int 21h ; Force an actual int 21h
  460. endm
  461. DOSCALL macro
  462. pushf
  463. push cs
  464. call near ptr Int21Handler ; Call our handler directly!
  465. endm
  466. DOSFCALL macro
  467. pushf
  468. call far ptr Int21Handler ; Call our handler directly!
  469. endm
  470. SetKernelDSNRes macro segreg ; usable in kernel NRES segment
  471. ifndef KDataSeg
  472. externW KDataSeg
  473. endif
  474. ifnb <segreg>
  475. ifdifi <segreg>,<es>
  476. mov segreg, cs:KDataSeg
  477. else
  478. mov es, cs:KDataSeg
  479. endif
  480. assumes <segreg>, %KRNLDS
  481. else
  482. mov ds, cs:KDataSeg
  483. assumes ds, %KRNLDS
  484. endif
  485. endm
  486. SetKernelDSMisc macro segreg ; usable in kernel MISC segment
  487. ifndef MKDataSeg
  488. externW MKDataSeg
  489. endif
  490. ifnb <segreg>
  491. ifdifi <segreg>,<es>
  492. mov segreg, cs:MKDataSeg
  493. else
  494. mov es, cs:MKDataSeg
  495. endif
  496. assumes <segreg>, %KRNLDS
  497. else
  498. mov ds, cs:MKDataSeg
  499. assumes ds, %KRNLDS
  500. endif
  501. endm
  502. SetKernelDS macro segreg
  503. ifndef MyCSDS
  504. externW MyCSDS
  505. endif
  506. ifnb <segreg>
  507. ifdifi <segreg>,<es>
  508. mov segreg, cs:MyCSDS
  509. else
  510. mov es, cs:MyCSDS
  511. endif
  512. assumes <segreg>, %KRNLDS
  513. else
  514. mov ds, cs:MyCSDS
  515. assumes ds, %KRNLDS
  516. endif
  517. endm
  518. UnSetKernelDS macro segreg
  519. ifnb <segreg>
  520. assumes <segreg>, nothing
  521. else
  522. assumes ds, nothing
  523. endif
  524. endm
  525. ReSetKernelDS macro segreg
  526. ifnb <segreg>
  527. assumes <segreg>, %KRNLDS
  528. else
  529. assumes ds, %KRNLDS
  530. endif
  531. endm
  532. CheckKernelDS macro segreg
  533. local ok
  534. if KDEBUG
  535. ifndef MyCSDS
  536. externW MyCSDS
  537. endif
  538. push ax
  539. ifnb <segreg>
  540. mov ax, segreg
  541. else
  542. mov ax, ds
  543. endif
  544. cmp ax, cs:MyCSDS
  545. je short ok
  546. int 3
  547. ok:
  548. pop ax
  549. endif
  550. endm
  551. SetKernelCSDword macro pdw, dwseg, dwoff
  552. ifndef SetKernelCSDwordProc
  553. externNP SetKernelCSDwordProc
  554. endif
  555. cCall SetKernelCSDwordProc,<pdw,dwseg,dwoff>
  556. endm
  557. Critical_check macro
  558. local hey_dude
  559. if KDEBUG
  560. push ds
  561. mov ds,pGlobalHeap
  562. cmp ds:[gi_lrulock],0 ; Make sure we're critical!
  563. jnz short hey_dude
  564. int 3
  565. hey_dude:
  566. pop ds
  567. endif
  568. endm
  569. TDB_check_ES macro
  570. local hey_dude
  571. if KDEBUG
  572. cmp es:[TDB_sig],TDB_SIGNATURE
  573. jz short hey_dude
  574. int 3
  575. hey_dude:
  576. endif
  577. endm
  578. TDB_check_DS macro
  579. local hey_dude
  580. if KDEBUG
  581. cmp ds:[TDB_sig],TDB_SIGNATURE
  582. jz short hey_dude
  583. int 3
  584. hey_dude:
  585. endif
  586. endm
  587. NE_check_ES macro
  588. local hey_dude
  589. if KDEBUG
  590. cmp es:[ne_magic],NEMAGIC
  591. jz short hey_dude
  592. int 3
  593. hey_dude:
  594. endif
  595. endm
  596. NE_check_DS macro
  597. local hey_dude
  598. if KDEBUG
  599. cmp ds:[ne_magic],NEMAGIC
  600. jz short hey_dude
  601. int 3
  602. hey_dude:
  603. endif
  604. endm
  605. ife 3-3
  606. sel_check macro reg
  607. local hey_dude, aaarrrggghhh
  608. if KDEBUG
  609. or reg, reg
  610. jz short hey_dude
  611. test reg, 4h ; Must be LDT
  612. jz short aaarrrggghhh
  613. test reg,2h ; Must be ring 2 or 3
  614. jnz short hey_dude ; yes, fine
  615. aaarrrggghhh:
  616. int 3
  617. xor reg, reg ; HACK!! bug 5896
  618. hey_dude:
  619. endif
  620. and reg, not 7
  621. endm
  622. else
  623. sel_check macro reg
  624. local hey_dude, aaarrrggghhh
  625. if KDEBUG
  626. or reg, reg
  627. jz short hey_dude
  628. test reg, 4h ; Must be LDT
  629. jnz short hey_dude
  630. int 3
  631. hey_dude:
  632. endif
  633. and reg, not 7
  634. endm
  635. endif
  636. KBINFO STRUC
  637. kbRanges DB 4 dup (0) ; Far East ranges for KANJI
  638. kbStateSize DW 0 ; #bytes of state info maintained by TOASCII
  639. KBINFO ENDS
  640. EXECBLOCK struc
  641. envseg dw ? ; seg addr of environment
  642. lpcmdline dd ? ; pointer to asciz command line
  643. lpfcb1 dd ? ; default fcb at 5C
  644. lpfcb2 dd ? ; default fcb at 6C
  645. EXECBLOCK ends
  646. SYSINITVAR STRUC
  647. dpbhead DD ? ; Head of DPB-FAT list
  648. sfthead DD ? ; Head of SFT table list
  649. pclockdev DD ? ; pointer to clock device
  650. pcondev DD ? ; pointer to console device
  651. SYSI_MAXSEC DW ? ; maximum sector size
  652. SYSI_BUF DD ? ; points to Hashinitvar
  653. SYSI_CDS DD ? ; CDS list
  654. SYSI_FCB DD ? ; FCB chain
  655. SYSI_Keep DW ? ; keep count
  656. SYSI_NUMIO DB ? ; Number of block devices
  657. SYSI_NCDS DB ? ; number of CDS's
  658. SYSI_DEV DD ? ; device list
  659. SYSI_ATTR DW ? ; null device attribute word
  660. SYSI_STRAT DW ? ; null device strategy entry point
  661. SYSI_INTER DW ? ; null device interrupt entry point
  662. SYSI_NAME DB 8 DUP(?) ; null device name
  663. SYSI_SPLICE DB 0 ; TRUE -> splicees being done
  664. SYSI_IBMDOS_SIZE DW ? ; DOS size in paragraphs
  665. SYSI_IFS_DOSCALL@ DD ? ; IFS DOS service rountine entry
  666. SYSI_IFS DD ? ; IFS header chain
  667. SYSI_BUFFERS DW ?,0 ; BUFFERS= values (m,n)
  668. SYSI_BOOT_DRIVE DB ? ; boot drive A=1 B=2,..
  669. SYSI_DWMOVE DB 0 ; 1 if 386 machine
  670. SYSI_EXT_MEM DW 0 ; Extended memory size in KB.
  671. SYSINITVAR ENDS
  672. ;
  673. ; system file table
  674. ;
  675. SFT STRUC
  676. sftLink DD ?
  677. sftCount DW ? ; number of entries
  678. sftFile DB ?
  679. SFT ENDS
  680. SFT_ENTRY3 STRUC
  681. sf_ref_count3 DW ? ; number of processes sharing fcb
  682. sf_mode3 DW ? ; mode of access
  683. sf_attr3 DB ? ; attribute of file
  684. sf_flags DW ?
  685. sf_devptr DD ?
  686. DB 21 dup (?) ; this is 21 for DOS 3.1
  687. sf_name DB ?
  688. SFT_ENTRY3 ENDS
  689. DPB STRUC
  690. dpb_drive DB ? ; Logical drive # assoc with DPB (A=0,B=1,...)
  691. DPB ENDS
  692. devid_device EQU 0080H ; true if a device
  693. sf_isnet EQU 8000H ; true if network drive
  694. INTVECTOR = 00Bh
  695. INTSIZE = 8
  696. HILO STRUC
  697. lo DW ?
  698. hi DW ?
  699. HILO ENDS
  700. SEGOFF STRUC
  701. off DW ?
  702. sel DW ?
  703. SEGOFF ENDS
  704. ; CPU flags
  705. CPUF_CARRY = 0000000000000001b
  706. ; = 0000000000000010b
  707. CPUF_PARITY = 0000000000000100b
  708. ; = 0000000000001000b
  709. CPUF_AUXCARRY = 0000000000010000b
  710. ; = 0000000000100000b
  711. CPUF_ZERO = 0000000001000000b
  712. CPUF_SIGN = 0000000010000000b
  713. CPUF_TRAP = 0000000100000000b
  714. CPUF_INTERRUPT = 0000001000000000b
  715. CPUF_DIRECTION = 0000010000000000b
  716. CPUF_OVERFLOW = 0000100000000000b
  717. CPUF_IOPL = 0011000000000000b
  718. CPUF_NESTEDTASK = 0100000000000000b
  719. ; = 1000000000000000b
  720. ; WM_FILESYSCHANGE message wParam value
  721. WM_FILESYSCHANGE = 0034h
  722. FSC_CREATE = 0
  723. FSC_DELETE = 1
  724. FSC_RENAME = 2
  725. FSC_ATTRIBUTES = 3
  726. FSC_NETCONNECT = 4
  727. FSC_NETDISCONNECT = 5
  728. FSC_REFRESH = 6
  729. FSC_MKDIR = 7
  730. FSC_RMDIR = 8
  731. ; MessageBox type flags
  732. MB_OK = 0000H
  733. MB_OKCANCEL = 0001H
  734. MB_ABORTRETRYIGNORE = 0002H
  735. MB_YESNOCANCEL = 0003H
  736. MB_RETRYCANCEL = 0005H
  737. MB_ICONHAND = 0010H
  738. MB_ICONQUESTION = 0020H
  739. MB_ICONEXCLAMATION = 0030H
  740. MB_ICONASTERISK = 0040H
  741. MB_DEFBUTTON1 = 0000H
  742. MB_DEFBUTTON2 = 0100H
  743. MB_DEFBUTTON3 = 0200H
  744. MB_SYSTEMMODAL = 1000H
  745. MB_TASKMODAL = 2000H
  746. ; Conventional dialog box and message box command IDs
  747. IDOK = 1
  748. IDCANCEL = 2
  749. IDABORT = 3
  750. IDRETRY = 4
  751. IDIGNORE = 5
  752. IDYES = 6
  753. IDNO = 7
  754. ; SysErrorBox type flags
  755. SEB_OK = 0001h ; Button with "OK".
  756. SEB_CANCEL = 0002h ; Button with "Cancel"
  757. SEB_YES = 0003h ; Button with "&Yes"
  758. SEB_NO = 0004h ; Button with "&No"
  759. SEB_RETRY = 0005h ; Button with "&Retry"
  760. SEB_ABORT = 0006h ; Button with "&Abort"
  761. SEB_IGNORE = 0007h ; Button with "&Ignore"
  762. SEB_CLOSE = 0008h ; Button with "Close"
  763. SEB_DEFBUTTON = 8000h ; Mask to make this button default
  764. ; ExitKernel/ExitWindows flags
  765. EW_REBOOTSYSTEM = 43h
  766. ; Kernel Flags[0]
  767. kf_restore_CtrlC EQU 01h ; A task switch has occured.
  768. kf_restore_disk EQU 02h ; A task switch has occured.
  769. kf_mondrian EQU 04h ; Windows was started under Mondrian.
  770. kf_check_free EQU 08h ; Free memory checking requested.
  771. kf_pUID EQU 10h ; Time to call pUserInitDone.
  772. kf_EMS_debug EQU 20h ; Tell symdeb about pseudo discards.
  773. kf_search_inst_stacks EQU 40h ; In patchstack search module stacks.
  774. kf_useslim32 EQU 80h ; Uses LIM 3.2 API (Intel Above Board)
  775. ; Kernel Flags[1]
  776. kf1_WIN386 EQU 01h ; we are running under Windows/386
  777. kf1_WINOLDAP EQU 02h ; the app being loaded is WinOldAp
  778. kf1_ABORTION EQU 04h ; loading the automatic data segment?
  779. kf1_HAVEHMA EQU 08h ; High Memory Area is available
  780. kf1_GLOBALNOTIFY EQU 10h ; We're calling the app's notify proc.
  781. kf1_MEMORYMOVED EQU 20h ; global memory was moved by gmove
  782. ;
  783. kf1_A20ON EQU 80h ; We have A20 on
  784. ; Kernel Flags[2]
  785. KF2_GH_NORIP EQU 01h ; don't rip in gdref if invalid handle
  786. KF2_WIN_EXIT EQU 02h ; we're past ExitKernel
  787. KF2_APP_EXIT EQU 04h ; we're in DOS 4C quitting an app
  788. KF2_SYMDEB EQU 08h ; symdeb or somesuch in installed
  789. KF2_PTRACE EQU 10h ; ptrace.dll is installed
  790. KF2_DOSX EQU 20h ; running under 286 DOS extender
  791. KF2_WIN386CRAZINESS EQU 40h ; i hate async notification!
  792. KF2_TOOLHELP EQU 80h ; TOOLHELP.DLL callback installed
  793. ; WinFlags[0]
  794. WF_PMODE EQU 01h ; Windows is running in Protected Mode
  795. WF_CPU286 EQU 02h ; Windows is running on an 80286 cpu
  796. WF_CPU386 EQU 04h ; " " " " " 80386 cpu
  797. WF_CPU486 EQU 08h ; Windows is running on an 80486 cpu
  798. WF_STANDARD EQU 10h ; Running Windows/286
  799. WF_ENHANCED EQU 20h ; Running Windows/386
  800. WF_CPU086 EQU 40h ; Windows is running on an 8086 cpu
  801. WF_CPU186 EQU 80h ; Windows is running on an 80186 cpu
  802. ; WinFlags[1]
  803. WF1_LARGEFRAME EQU 01h ; Running in EMS small frame
  804. WF1_SMALLFRAME EQU 02h ; Running in EMS large frame
  805. WF1_80x87 EQU 04h ; There is a co-processor present
  806. WF1_PAGING EQU 08h ; Paging is enabled
  807. ifdef WOW
  808. WF1_WINNT EQU 40h ; Running on Windows NT WOW layer
  809. endif
  810. ifdef WOW
  811. ; DebugWOW
  812. DW_DEBUG EQU 0001h ; 32-bit Debugger debugging wow
  813. endif
  814. ; Note, WF_WIN286 + WF_PMODE indicates running under the 286 DOS extender
  815. ; Flags for OpenFile
  816. OF_READ = 0000H
  817. OF_WRITE = 0001H
  818. OF_READWRITE = 0002H
  819. OF_SHARE_COMPAT = 0000H
  820. OF_SHARE_EXCLUSIVE = 0010H
  821. OF_SHARE_DENY_WRITE = 0020H
  822. OF_SHARE_DENY_READ = 0030H
  823. OF_SHARE_DENY_NONE = 0040H
  824. OF_NO_INHERIT = 0080H
  825. OF_PARSE = 0100H
  826. OF_DELETE = 0200H
  827. OF_VERIFY = 0400H
  828. OF_CANCEL = 0800H
  829. OF_CREATE = 1000H
  830. OF_PROMPT = 2000H
  831. OF_EXIST = 4000H
  832. OF_REOPEN = 8000H
  833. TF_FORCEDRIVE = 80H
  834. MaxFileLen equ 128
  835. OPENSTRUC STRUC
  836. opLen db ?
  837. opDisk db ?
  838. opXtra dw ?
  839. opDate dw ?
  840. opTime dw ?
  841. opFile db ?
  842. OPENSTRUC ENDS
  843. ; GetAppCompatFlags/TDB_CompatFlags flag values
  844. GACF_IGNORENODISCARD EQU 0001h ; Ignore GA_NODISCARD on GlobalAlloc
  845. GACF_HACKWINFLAGS EQU 0400h ; mask out new win31 flags ie. WF_PAGING
  846. GACF_WINVER31 equ 00200000h ;Lie about windows version
  847. HIW_GACF_WINVER31 equ 0020h
  848. GACFE_INCREASESTACK EQU 0040h ; Increase the stack size for ALDUS
  849. GACF_31VALIDMASK EQU 0FFE484AFh ; valid bits for 3.1+ apps
  850. HIW_GACF_31VALIDMASK EQU 0FFE4h
  851. LOW_GACF_31VALIDMASK EQU 084AFh
  852. GACF_IGNOREFAULTS EQU 002000000h
  853. GACF_ALWAYSZEROINIT EQU 000400000h ;Always do GA_ZEROINIT on GlobalAlloc (overloads GACF_INCREASESTACK)
  854. GACF_MODULESPECIFIC equ 000040000h ;Module-specific hack
  855. ; Look for module in Module Compatibilty section of win.ini
  856. MCF_FIXEDSEGLOW = 00001h ; Win31 behaviour for FIXED segs
  857. MCF_MODPATCH = 00002h ; Look for module patches in the registry
  858. MCF_NODISCARD = 00004h ; Make all segments in the module not discardable
  859. MCF_MODPATCH_X86 = 08000h ; Apply this module patch on x86 only
  860. MCF_MODPATCH_RISC = 04000h ; Apply this module patch on RISC only
  861. ifdef JAPAN
  862. ;
  863. ; INT 41H SIGNATURE
  864. ; Some Japanese OEM want to use interrupt vector other than 41h for
  865. ; debugger hook since this vector already used by system hardware.
  866. ; We won't disclose sources for Kernel, OEM should change vector
  867. ; number by 'patch'ing. The following macro appears below the 'INT 41H'
  868. ; instruction so that OEM can find the patch position by searching this
  869. ; signature string.
  870. INT41SIGNATURE macro
  871. jmp short @F
  872. db 'DEB41PATCH'
  873. @@:
  874. endm
  875. endif ;JAPAN
  876. DebInt macro val
  877. ifnb <val>
  878. mov ax, val
  879. endif
  880. int 41h
  881. ifdef JAPAN
  882. jmp short @F
  883. db 'DEB41PATCH'
  884. @@:
  885. endif
  886. endm
  887. ;
  888. ; Structure passed between user profile routines
  889. ;
  890. PROINFO struc
  891. lpProFile dd ? ; Pointer to INI filename
  892. lpBuffer dd ? ; Pointer to buffer containing file
  893. hBuffer dw ? ; Handle of buffer
  894. BufferLen dw ? ; Length of buffer
  895. FileHandle dw ? ; File handle - -1 if not open
  896. ProFlags dw ? ; Open, writing etc
  897. wClusterSize dw ? ; Bytes/cluster on current disk
  898. ProBuf db (SIZE OPENSTRUC + MaxFileLen - 1) dup(?)
  899. PROINFO ends
  900. ; -------------------------------------------------------
  901. ; This macro displays a string if DEBUG
  902. ;
  903. Trace_Out MACRO String, nocrlf
  904. LOCAL a
  905. IF KDEBUG
  906. _DATA SEGMENT PARA PUBLIC 'DATA' ;; (not jump around)
  907. a label byte
  908. ifdef WOW
  909. db "W16KERNEL: "
  910. endif
  911. db String
  912. IFB <nocrlf>
  913. db 0dh, 0ah
  914. ENDIF
  915. db 0
  916. _DATA ENDS
  917. push dataOffset a
  918. call KOutDSStr
  919. ENDIF
  920. ENDM
  921. move MACRO reg,var
  922. mov reg,var
  923. endm
  924. WOWTrace MACRO String,args
  925. LOCAL String_Offset, Skip
  926. IFDEF WOWDEBUGTRACE
  927. irp arg,<args>
  928. move arg
  929. endm
  930. jmps Skip
  931. String_Offset db "W16KERNEL:",String,0Dh,0Ah,0
  932. Skip:
  933. push ds
  934. pushf
  935. pusha
  936. mov ax,cs ; make sure string is addressable
  937. mov ds,ax
  938. lea si, String_Offset ; LEA to stop link whining
  939. ifndef KOutDebugStr
  940. externFP KOutDebugStr
  941. endif
  942. call KOutDebugStr
  943. popa
  944. popf
  945. pop ds
  946. ENDIF
  947. ENDM
  948. ; -------------------------------------------------------
  949. ; This macro displays a string and breaks if DEBUG
  950. ;
  951. Debug_Out MACRO String
  952. IF KDEBUG
  953. Trace_Out <String>
  954. int 3
  955. ENDIF
  956. ENDM
  957. ;
  958. ; Error reporting constants (from windows.h)
  959. ;
  960. ; Error option flags (set by [kernel] ErrorOptions win.ini variable)
  961. ERO_PARAM_ERROR_BREAK equ 0001h
  962. ERO_BUFFER_FILL equ 0002h
  963. ; Debug fill constants
  964. DBGFILL_ALLOC equ 0fdh
  965. DBGFILL_FREE equ 0fbh
  966. DBGFILL_BUFFER equ 0f9h
  967. DBGFILL_STACK equ 0f7h
  968. include winkern.inc
  969. ifndef WINDEBUG
  970. include ikernel.inc
  971. endif
  972. ifdef WOW
  973. STIRET MACRO
  974. LOCAL Dont_Do_STI
  975. push ax
  976. pushf
  977. pop ax
  978. test ah, 2
  979. pop ax
  980. jnz SHORT Dont_Do_STI
  981. FSTI
  982. Dont_Do_STI:
  983. FIRET
  984. ENDM
  985. else
  986. STIRET MACRO
  987. LOCAL Dont_Do_STI
  988. if PMODE32
  989. push ax
  990. pushf
  991. pop ax
  992. test ah, 2
  993. pop ax
  994. jnz SHORT Dont_Do_STI
  995. FSTI
  996. Dont_Do_STI:
  997. endif
  998. FIRET
  999. ENDM
  1000. endif; WOW
  1001. ife ?RIPAUX
  1002. externFP LogError
  1003. endif
  1004. KernelLogError macro flags, errcode, msg
  1005. krDebugOut <flags>,<msg>
  1006. push errcode
  1007. push 0
  1008. push 0
  1009. call LogError
  1010. endm
  1011. ; Load Module error return codes
  1012. ; Used by LD.asm, LDHEADER.asm, etc.
  1013. LME_MEM = 0 ; Out of memory ;
  1014. LME_FNF = 2 ; File not found
  1015. LME_LINKTASK = 5 ; can't link to task ;
  1016. LME_LIBMDS = 6 ; lib can't have multiple data segments ;
  1017. LME_VERS = 10 ; Wrong windows version ;
  1018. LME_INVEXE = 11 ; Invalid exe ;
  1019. LME_OS2 = 12 ; OS/2 app ;
  1020. LME_DOS4 = 13 ; DOS 4 app ;
  1021. LME_EXETYPE = 14 ; unknown exe type ;
  1022. LME_RMODE = 15 ; not a pmode windows app ;
  1023. LME_APPMDS = 16 ; multiple data segments in app ;
  1024. LME_EMS = 17 ; scum app in l-frame EMS ;
  1025. LME_PMODE = 18 ; not an rmode windows app ;
  1026. LME_COMP = 19 ; compressed EXE file ;
  1027. LME_INVCOMP = 20 ; invalid DLL (component) caused EXE load fail ;
  1028. LME_PE = 21 ; Windows Portable EXE app - let them load it ;
  1029. LME_MAXERR = 32 ; for comparisons ;
  1030. LME_WOAWOW32 = 23 ; For wow special handling of WOA
  1031. PEMAGIC = 4550h ; 'PE'
  1032. ;
  1033. ; Use these macros instead of a raw "int 3" and maybe we can tell
  1034. ; later what is happening when we hit one!
  1035. ;
  1036. ; Put there by davidw or tonyg or even earlier. Nobody knows
  1037. ; what this is.
  1038. ;
  1039. INT3_ANCIENT macro
  1040. int 3
  1041. endm
  1042. ;
  1043. ; Used find out what happens when a code path is executed.
  1044. ; Should be ignoreable, but call a developer to make sure.
  1045. ;
  1046. INT3_TEST macro
  1047. int 3
  1048. endm
  1049. ;
  1050. ; This code path should "never" be executed.
  1051. ;
  1052. INT3_NEVER macro
  1053. int 3
  1054. endm
  1055. ;
  1056. ; Something strange, but not fatal. Should be changed to output
  1057. ; a message.
  1058. ;
  1059. INT3_WARN macro
  1060. int 3
  1061. endm
  1062. ;
  1063. ; This is bad, real bad.
  1064. ;
  1065. INT3_FATAL macro
  1066. int 3
  1067. endm
  1068. ;
  1069. ; Break in to debugger
  1070. ;
  1071. INT3_DEBUG macro
  1072. int 3
  1073. endm