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.

397 lines
17 KiB

  1. ; Copyright (c) Microsoft Corporation 1988-1991. All Rights Reserved.
  2. ;****************************************************************
  3. ;* *
  4. ;* PMDEFS.INC -- 80286 Protected Mode Definitions *
  5. ;* *
  6. ;****************************************************************
  7. ;* Revision History: *
  8. ;* *
  9. ;* 7/28/89 jimmat Changes selectors for Wdeb386 (it now *
  10. ;* needs 4, not 2) *
  11. ;* 3/11/89 jimmat Added selector for TSS *
  12. ;* 3/09/89 jimmat Added selectors for DynaLink call gates *
  13. ;* 02/10/89 (GeneA): reorganized selector definitions for *
  14. ;* change from small model to medium model *
  15. ;* 12/01/88 (GeneA): added definitions for SEL_BIOSCODE and *
  16. ;* SEL_USERSCR *
  17. ;* *
  18. ;****************************************************************
  19. ;
  20. ; -------------------------------------------------------
  21. ; SELECTOR FIELDS
  22. ; -------------------------------------------------------
  23. SELECTOR_RPL = 00000011b ;Requested Privilege Level mask
  24. SELECTOR_TI = 00000100b ;Table Indicator mask
  25. SELECTOR_INDEX = 0fff8h ;Index mask
  26. SELECTOR_PL0 = 00000000b ;Ring 0 privilege level
  27. SELECTOR_PL1 = 00000001b ;Ring 1 privilege level
  28. SELECTOR_PL2 = 00000010b ;Ring 2 privilege level
  29. SELECTOR_PL3 = 00000011b ;Ring 3 privilege level
  30. SELECTOR_PL_DX = SELECTOR_PL3 ;Privilege level used by DOSX
  31. ; -------------------------------------------------------
  32. ; ACCESS RIGHTS BIT DEFINITIONS
  33. ; -------------------------------------------------------
  34. ;
  35. ; These are the access rights byte bit position definitions.
  36. ; These fields are common to all descriptors
  37. AB_PRESENT = 10000000b ;segment present bit
  38. AB_DPL0 = 00000000b ;ring 0 DPL
  39. AB_DPL1 = 00100000b ;ring 1 DPL
  40. AB_DPL2 = 01000000b ;ring 2 DPL
  41. AB_DPL3 = 01100000b ;ring 3 DPL
  42. AB_DPL = 01100000b ;mask for DPL field
  43. ;AB_DPL_DX = AB_DPL3 ;DPL used by DOSX
  44. AB_DPL_DX = (SELECTOR_PL_DX shl 5) ;DPL used by DOSX
  45. ; These fields are relevant to code and data segment descriptors
  46. ; (non-system descriptors)
  47. AB_DATA = 00010000b ;data segment
  48. AB_CODE = 00011000b ;code segment
  49. AB_STACK = 00010100b ;expand down (stack) segment
  50. AB_WRITE = 00000010b ;writable data
  51. AB_READ = 00000010b ;readable code
  52. AB_CONFORM = 00000100b ;conforming code
  53. AB_ACCESSED = 00000001b ;segment has been accessed
  54. AB_BIG = 0100000000000000b ; 32 bit segment
  55. ; These fields are relevant to system descriptors
  56. AB_INVALID = 00000000b ;invalid descriptor
  57. AB_TSS = 00000001b ;task state segment descriptor
  58. AB_TSS386 = 00001001b ;task state segment descriptor 386
  59. AB_BUSY = 00000010b ;busy bit for task state descriptor
  60. AB_LDT = 00000010b ;local descriptor table descriptor
  61. AB_CALLGATE = 00000100b ;call gate descriptor
  62. AB_TASKGATE = 00000101b ;task gate descriptor
  63. AB_INTRGATE = 00000110b ;interrupt gate descriptor
  64. AB_TRAPGATE = 00000111b ;trap gate descriptor
  65. AB_IGATE386 = 00001110b ;80386 interrupt gate descriptor
  66. ; These are some common combinations of the above fields making up
  67. ; useful access rights bytes.
  68. ARB_CODE0 = AB_PRESENT+AB_DPL0+AB_CODE+AB_READ ;ring 0 code segment
  69. ARB_CODE1 = AB_PRESENT+AB_DPL1+AB_CODE+AB_READ ;ring 1 code segment
  70. ARB_CODE3 = AB_PRESENT+AB_DPL3+AB_CODE+AB_READ ;ring 3 code segment
  71. ARB_CODE_DX = AB_PRESENT+AB_DPL_DX+AB_CODE+AB_READ ;DOSX ring code segment
  72. ARB_DATA0NP = AB_DPL0+AB_DATA+AB_WRITE ;illegal segment
  73. ARB_DATA0 = AB_PRESENT+AB_DPL0+AB_DATA+AB_WRITE ;ring 0 read/write data
  74. ARB_DATA1 = AB_PRESENT+AB_DPL1+AB_DATA+AB_WRITE ;ring 1 read/write data
  75. ARB_DATA3 = AB_PRESENT+AB_DPL3+AB_DATA+AB_WRITE ;ring 3 read/write data
  76. ARB_DATA_DX = AB_PRESENT+AB_DPL_DX+AB_DATA+AB_WRITE ;DOSX ring read/write data
  77. ARB_STACK0 = AB_PRESENT+AB_DPL0+AB_STACK+AB_WRITE ;ring 0 stack
  78. ARB_STACK1 = AB_PRESENT+AB_DPL1+AB_STACK+AB_WRITE ;ring 1 stack
  79. ARB_STACK3 = AB_PRESENT+AB_DPL3+AB_STACK+AB_WRITE ;ring 3 stack
  80. ARB_STACK_DX = AB_PRESENT+AB_DPL_DX+AB_STACK+AB_WRITE ;DOSX ring stack
  81. ARB_TRAP0 = AB_PRESENT+AB_DPL0+AB_TRAPGATE ;ring 0 trap gate
  82. ARB_TRAP1 = AB_PRESENT+AB_DPL1+AB_TRAPGATE ;ring 1 trap gate
  83. ARB_TRAP3 = AB_PRESENT+AB_DPL3+AB_TRAPGATE ;ring 3 trap gate
  84. ARB_TRAP_DX = AB_PRESENT+AB_DPL_DX+AB_TRAPGATE ;DOSX ring trap gate
  85. ARB_INTR0 = AB_PRESENT+AB_DPL0+AB_INTRGATE ;ring 0 interrupt gate
  86. ARB_INTR1 = AB_PRESENT+AB_DPL1+AB_INTRGATE ;ring 1 interrupt gate
  87. ARB_INTR3 = AB_PRESENT+AB_DPL3+AB_INTRGATE ;ring 3 interrupt gate
  88. ARB_INTR_DX = AB_PRESENT+AB_DPL_DX+AB_INTRGATE ;DOSX ring interrupt gate
  89. ARB_INTR0386= AB_PRESENT+AB_DPL0+AB_IGATE386 ;ring 0 386 int gate
  90. ARB_INTR1386= AB_PRESENT+AB_DPL1+AB_IGATE386 ;ring 1 386 int gate
  91. ARB_INTR3386= AB_PRESENT+AB_DPL3+AB_IGATE386 ;ring 3 386 int gate
  92. ARB_INTR_DX386= AB_PRESENT+AB_DPL_DX+AB_IGATE386 ;DOSX ring 386 int gate
  93. ARB_CALL0 = AB_PRESENT+AB_DPL0+AB_CALLGATE ;ring 0 call gate
  94. ARB_CALL1 = AB_PRESENT+AB_DPL1+AB_CALLGATE ;ring 1 call gate
  95. ARB_CALL3 = AB_PRESENT+AB_DPL3+AB_CALLGATE ;ring 3 call gate
  96. ARB_CALL_DX = AB_PRESENT+AB_DPL_DX+AB_CALLGATE ;DOSX ring call gate
  97. ARB_TSS1 = AB_PRESENT+AB_DPL1+AB_TSS ;ring 1 task state seg
  98. ARB_TSS3 = AB_PRESENT+AB_DPL3+AB_TSS ;ring 3 task state seg
  99. ARB_TSS_DX = AB_PRESENT+AB_DPL_DX+AB_TSS ;DOSX ring task state seg
  100. ARB_TSS1386 = AB_PRESENT+AB_DPL1+AB_TSS386 ;ring 1 386 TSS
  101. ARB_TSS3386 = AB_PRESENT+AB_DPL3+AB_TSS386 ;ring 3 386 TSS
  102. ARB_TSS_DX386 = AB_PRESENT+AB_DPL_DX+AB_TSS386 ;DOSX ring 386 TSS
  103. ARB_LDT1 = AB_PRESENT+AB_DPL1+AB_LDT ;ring 1 local dscr tbl
  104. ARB_LDT3 = AB_PRESENT+AB_DPL3+AB_LDT ;ring 3 local dscr tbl
  105. ARB_LDT_DX = AB_PRESENT+AB_DPL_DX+AB_LDT ;DOSX ring local dscr tbl
  106. ;--------------------------------------------------------
  107. ; STANDARD DESCRIPTOR TABLE/RING EQUATES
  108. ;--------------------------------------------------------
  109. ; Currently DOSX is setup to run most of itself and the child app in
  110. ; ring 1. However this may be changed by changing the following equates.
  111. STD_DPL = AB_DPL_DX
  112. STD_DATA = ARB_DATA_DX
  113. STD_CODE = ARB_CODE_DX
  114. STD_STACK = ARB_STACK_DX
  115. STD_TRAP = ARB_TRAP_DX
  116. STD_INTR = ARB_INTR_DX
  117. STD_INTR386 = ARB_INTR_DX386
  118. STD_CALL = ARB_CALL_DX
  119. STD_TSS = ARB_TSS_DX
  120. STD_TSS386 = ARB_TSS_DX386
  121. STD_LDT = ARB_LDT_DX
  122. STD_TBL = SELECTOR_TI
  123. STD_RING = SELECTOR_PL_DX OR SELECTOR_TI
  124. STD_TBL_RING = (STD_TBL or STD_RING)
  125. ;
  126. ; Code descriptor type for handling processor exceptions.
  127. ;
  128. EH_CODE = ARB_CODE0
  129. EH_RING = SELECTOR_PL0
  130. EH_RING_MASK = NOT 3
  131. EH_DATA = ARB_DATA0
  132. ; -------------------------------------------------------
  133. ; DESCRIPTOR STRUCTURE DEFINITIONS
  134. ; -------------------------------------------------------
  135. ; This structure defines the layout of a segment descriptor on the '286
  136. ; These can appear in either the local descriptor table or the global
  137. ; descriptor table. The local descriptor table descriptors also fit into
  138. ; this format, but they can only appear in the global descriptor table.
  139. SEGDSCR struc
  140. cbLimit dw 0 ;segment size limit
  141. adrBaseLow dw 0 ;low word of segment base address
  142. adrBaseHigh db 0 ;high byte of segment base address
  143. arbSegAccess db 0 ;access rights byte
  144. rsvdSeg dw 0 ;Intel reserved, must be 0
  145. SEGDSCR ends
  146. SEGDSCR386 struc
  147. cbLimit386 dw 0 ;segment size limit
  148. adrwBaseLow386 dw 0 ;low word of segment base address
  149. adrbBaseMid386 db 0 ;mid byte of segment base address
  150. arbSegAccess386 db 0 ;access rights byte
  151. cbLimitHi386 db 0 ;hi nybble of size limit
  152. adrbBaseHi386 db 0 ;high byte of segment base address
  153. SEGDSCR386 ends
  154. ; This structure defines the layout of gate descriptors. These can appear
  155. ; in any of the descriptor tables. Only Interrupt Gate, Trap Gate, and
  156. ; Task Gate descriptors can appear in the interrupt descriptor table.
  157. GATEDSCR struc
  158. offDest dw 0 ;destination function offset (not used in
  159. ; task gates)
  160. selDest dw 0 ;destination function segment selector
  161. cwParam db 0 ;count of parameter words to transfer
  162. arbGate db 0 ;access rights byte
  163. rsvdGate dw 0 ;Intel reserved, must be 0
  164. GATEDSCR ends
  165. ; This is the structure defines the layout of a Task State Segment
  166. ; descriptor. This can only appear in the Global Descriptor Table
  167. TSSDSCR struc
  168. cbTssLimit dw 0 ;segment size limit
  169. adrTssBaseLow dw 0 ;low word of segment base address
  170. adrTssBaseHigh db 0 ;high byte of segment base address
  171. arbTssAccess db 0 ;access rights byte
  172. rsvdTss dw 0 ;Intel reserved, must be 0
  173. TSSDSCR ends
  174. ; -------------------------------------------------------
  175. ; 80286 TASK STATE SEGMENT
  176. ; -------------------------------------------------------
  177. ;
  178. ; This structure describes the layout of an 80286 task state
  179. ; segment.
  180. TSS286 struc
  181. tss_backlink dw ? ;backlink to previous task
  182. tss_sp0 dw ? ;privelege level 0 stack pointer
  183. tss_ss0 dw ? ;privelege level 0 stack segment
  184. tss_sp1 dw ? ;privelege level 1 stack pointer
  185. tss_ss1 dw ? ;privelege level 1 stack segment
  186. tss_sp2 dw ? ;privelege level 2 stack pointer
  187. tss_ss2 dw ? ;privelege level 2 stack segment
  188. tss_ip dw ? ;initial instruction pointer
  189. tss_flags dw ?
  190. tss_ax dw ?
  191. tss_cx dw ?
  192. tss_dx dw ?
  193. tss_bx dw ?
  194. tss_sp dw ?
  195. tss_bp dw ?
  196. tss_si dw ?
  197. tss_di dw ?
  198. tss_es dw ?
  199. tss_cs dw ?
  200. tss_ss dw ?
  201. tss_ds dw ?
  202. tss_ldt dw ? ;local descriptor table for this task
  203. TSS286 ends
  204. ; -------------------------------------------------------
  205. ; 80386 TASK STATE SEGMENT
  206. ; -------------------------------------------------------
  207. ;
  208. ; This structure describes the layout of an 80386 task state
  209. ; segment.
  210. TSS386 struc
  211. ts3_backlink dw 0 ;backlink to previous task
  212. dw 0
  213. ts3_esp0 dd 0 ;privelege level 0 stack pointer
  214. ts3_ss0 dw 0 ;privelege level 0 stack segment
  215. dw 0
  216. ts3_esp1 dd 0 ;privelege level 1 stack pointer
  217. ts3_ss1 dw 0 ;privelege level 1 stack segment
  218. dw 0
  219. ts3_esp2 dd 0 ;privelege level 2 stack pointer
  220. ts3_ss2 dw 0 ;privelege level 2 stack segment
  221. dw 0
  222. ts3_eip dd 0 ;initial instruction pointer
  223. ts3_cr3 dd 0
  224. ts3_eflags dd 0
  225. ts3_eax dd 0
  226. ts3_ecx dd 0
  227. ts3_edx dd 0
  228. ts3_ebx dd 0
  229. ts3_esp dd 0
  230. ts3_ebp dd 0
  231. ts3_esi dd 0
  232. ts3_edi dd 0
  233. ts3_es dw 0
  234. dw 0
  235. ts3_cs dw 0
  236. dw 0
  237. ts3_ss dw 0
  238. dw 0
  239. ts3_ds dw 0
  240. dw 0
  241. ts3_fs dw 0
  242. dw 0
  243. ts3_gs dw 0
  244. dw 0
  245. ts3_ldt dw 0 ;local descriptor table for this task
  246. dw 0
  247. ts3_iomap dw 0
  248. dw 0
  249. TSS386 ends
  250. ; -------------------------------------------------------
  251. ; EXCEPTION VECTORS
  252. ; -------------------------------------------------------
  253. ; These are the interrupt vector numbers for the exception
  254. ; interrupts reserved by the 80286/80386.
  255. EXC_DIV0 = 0 ;divide error
  256. EXC_SINGLESTEP = 1 ;single step
  257. EXC_NMI = 2 ;NMI interrupt
  258. EXC_BREAKPOINT = 3 ;breakpoint interrupt
  259. EXC_INTO = 4 ;overflow interrupt
  260. EXC_BOUND = 5 ;bounds overflow exception
  261. EXC_OPCODE = 6 ;invalid opcode exception
  262. EXC_COPROCESSOR = 7 ;processor extension not available
  263. EXC_DOUBLE = 8 ;double fault
  264. EXC_XOVERRUN = 9 ;coprocessor segment overrun
  265. EXC_TSS = 10 ;invalid task state segment exception
  266. EXC_NOTPRESENT = 11 ;segment not present exception
  267. EXC_STACK = 12 ;stack overrun, or stack segment not present
  268. EXC_GP = 13 ;general protection exception
  269. EXC_PF = 14 ;page fault
  270. ; -------------------------------------------------------
  271. ; GLOBAL DESCRIPTOR DECLARATIONS
  272. ; -------------------------------------------------------
  273. ;
  274. ; The following symbols define the segment descriptors that
  275. ; are statically defined in the Dos Extender.
  276. ;
  277. ; NOTE:
  278. ; These selector definitions assume that codeview is running
  279. ; at privelege level 0. If codeview is running at another
  280. ; privelege level, the RPL fields must be adjusted.
  281. ;
  282. ; Global Descriptor Table Conventions used in the Dos Extender
  283. SEL_NULL = 00h ;null selector
  284. SEL_GDT = 80h ;read/write data segment pointing to the
  285. ; global descriptor table
  286. SEL_IDT = 88h ;read/write data segment pointing to the
  287. ; protected mode interrupt descriptor table
  288. SEL_RMIVT = 90h ;read/write data segment pointing to the
  289. ; real mode interrupt vector table
  290. SEL_PSP = 98h ;Dos Extender PSP
  291. SEL_ENVIRON = 0A0h ;Dos Extender Environment
  292. SEL_BIOSCODE = 0A8h ;points at segment F000
  293. SEL_DXDATA = 0B0h ;Dos Extender data segment
  294. SEL_BIOSDATA = 0B8h ;PC BIOS data segment
  295. SEL_DXPMCODE = 0C0h ;Dos Extender extended memory code segment
  296. SEL_DXCODE = 0C8h ;Dos Extender low memory code segment
  297. SEL_LDT_ALIAS = 0D0h ;read/write alias to LDT
  298. ;SEL_VDMTIB = 0D8h ;used by DOSX to access TIB
  299. SEL_EH = 0E0h ;Ring 0 segment code for handling processor
  300. ;exceptions in PMODE
  301. SEL_DOSSCR = 0E8h
  302. SEL_DXDATA0 = 0f0h
  303. SEL_DXCODE0 = 0f8h
  304. ;SEL_RZIRET = 0100h
  305. SEL_LDT = 0108h
  306. ;SEL_RESET = 0110h
  307. SEL_TSS = 0118h
  308. SEL_TSS_ALIAS = 0120h
  309. SEL_NBSCRATCH = 0128h
  310. SEL_WOW_LDT = 0130h ; readonly LDT selector for WOW kernel
  311. SEL_NPXHDLR = 0138h ; selector for NpxExceptionHandler
  312. SEL_IRETHOOK = 0140h
  313. SEL_NBPMCODE = 0148H ; net bios anr handler cs
  314. ;
  315. ; Size of the GDT.
  316. ;
  317. GDT_SIZE = (SEL_NBPMCODE + 8)
  318. GDT_SELECTORS = (GDT_SIZE shr 3)
  319. ;
  320. ; Special LDT selectors.
  321. ;
  322. SEL_DPMI_FIRST = 0 ; first reserved DPMI LDT selector
  323. C_DPMI_RESERVED = 10h ; count of reserved DPMI LDT selectors
  324. SEL_DPMI_LAST = (C_DPMI_RESERVED - 1) * 8
  325. ; last reserved DPMI LDT selector
  326. SEL_SCR0 = SEL_NBPMCODE + 8
  327. ;scratch selector 0
  328. SEL_SCR1 = SEL_SCR0 + 8 ;scratch selector 1
  329. SEL_USERSCR = SEL_SCR1 + 8 ;user scratch selector. This is used for
  330. ; temporary return values to user from
  331. ; system and bios calls
  332. SEL_USER_STACK = SEL_USERSCR + 8
  333. SEL_USER = SEL_USER_STACK + 8
  334. ; -------------------------------------------------------
  335. ; -------------------------------------------------------
  336. ; -------------------------------------------------------
  337. ;****************************************************************