Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

540 lines
13 KiB

  1. /*++ BUILD Version: 0002 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. nti386.h
  5. Abstract:
  6. User-mode visible i386 specific i386 structures and constants
  7. Author:
  8. Mark Lucovsky (markl) 30-Nov-1989
  9. Revision History:
  10. Bryan Willman (bryanwi) 8-Jan-90
  11. port to the 386
  12. --*/
  13. #ifndef _NTI386_
  14. #define _NTI386_
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. // begin_ntddk begin_wdm begin_nthal begin_winnt begin_ntminiport begin_wx86
  22. #ifdef _X86_
  23. //
  24. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  25. // writers to not leave them inadvertantly in their code.
  26. //
  27. #if !defined(MIDL_PASS)
  28. #if !defined(RC_INVOKED)
  29. #if _MSC_VER >= 1200
  30. #pragma warning(push)
  31. #endif
  32. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  33. // build with /Od don't get weird errors !
  34. #ifdef _M_IX86
  35. #pragma function(_enable)
  36. #pragma function(_disable)
  37. #endif
  38. #if _MSC_VER >= 1200
  39. #pragma warning(pop)
  40. #else
  41. #pragma warning(default:4164) // reenable C4164 warning
  42. #endif
  43. #endif
  44. #endif
  45. // end_ntddk end_wdm end_nthal end_winnt end_ntminiport end_wx86
  46. //
  47. // Values put in ExceptionRecord.ExceptionInformation[0]
  48. // First parameter is always in ExceptionInformation[1],
  49. // Second parameter is always in ExceptionInformation[2]
  50. //
  51. #define BREAKPOINT_BREAK 0
  52. #define BREAKPOINT_PRINT 1
  53. #define BREAKPOINT_PROMPT 2
  54. #define BREAKPOINT_LOAD_SYMBOLS 3
  55. #define BREAKPOINT_UNLOAD_SYMBOLS 4
  56. #define BREAKPOINT_COMMAND_STRING 5
  57. //
  58. // Define Address of User Shared Data
  59. //
  60. #define MM_SHARED_USER_DATA_VA 0x7FFE0000
  61. #define USER_SHARED_DATA ((KUSER_SHARED_DATA * const)MM_SHARED_USER_DATA_VA)
  62. // Add definitions for quick user mode test of i386 system architecture type
  63. #ifndef IsNEC_98
  64. #define IsNEC_98 (USER_SHARED_DATA->AlternativeArchitecture == NEC98x86)
  65. #endif
  66. #ifndef IsNotNEC_98
  67. #define IsNotNEC_98 (USER_SHARED_DATA->AlternativeArchitecture != NEC98x86)
  68. #endif
  69. #ifndef SetNEC_98
  70. #define SetNEC_98
  71. #endif
  72. #if defined(MIDL_PASS) || !defined(_M_IX86)
  73. struct _TEB *
  74. NTAPI
  75. NtCurrentTeb( void );
  76. #else
  77. #if _MSC_VER >= 1200
  78. #pragma warning(push)
  79. #endif
  80. #pragma warning (disable:4035) // disable 4035 (function must return something)
  81. #define PcTeb 0x18
  82. _inline struct _TEB * NtCurrentTeb( void ) { __asm mov eax, fs:[PcTeb] }
  83. #if _MSC_VER >= 1200
  84. #pragma warning(pop)
  85. #else
  86. #pragma warning (default:4035) // reenable it
  87. #endif
  88. #endif // defined(MIDL_PASS) || defined(__cplusplus) || !defined(_M_IX86)
  89. // begin_ntddk begin_nthal
  90. //
  91. // Size of kernel mode stack.
  92. //
  93. #define KERNEL_STACK_SIZE 12288
  94. //
  95. // Define size of large kernel mode stack for callbacks.
  96. //
  97. #define KERNEL_LARGE_STACK_SIZE 61440
  98. //
  99. // Define number of pages to initialize in a large kernel stack.
  100. //
  101. #define KERNEL_LARGE_STACK_COMMIT 12288
  102. // end_ntddk end_nthal
  103. #define DOUBLE_FAULT_STACK_SIZE 4096
  104. //
  105. // Call frame record definition.
  106. //
  107. // There is no standard call frame for NT/386, but there is a linked
  108. // list structure used to register exception handlers, this is it.
  109. //
  110. // begin_nthal
  111. //
  112. // Exception Registration structure
  113. //
  114. typedef struct _EXCEPTION_REGISTRATION_RECORD {
  115. struct _EXCEPTION_REGISTRATION_RECORD *Next;
  116. PEXCEPTION_ROUTINE Handler;
  117. } EXCEPTION_REGISTRATION_RECORD;
  118. typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD;
  119. //
  120. // Define constants for system IDTs
  121. //
  122. #define MAXIMUM_IDTVECTOR 0xff
  123. #define MAXIMUM_PRIMARY_VECTOR 0xff
  124. #define PRIMARY_VECTOR_BASE 0x30 // 0-2f are x86 trap vectors
  125. // begin_ntddk
  126. #ifdef _X86_
  127. // end_ntddk
  128. // begin_winnt
  129. #if !defined(MIDL_PASS) && defined(_M_IX86)
  130. #if _MSC_VER >= 1200
  131. #pragma warning(push)
  132. #endif
  133. #pragma warning (disable:4035) // disable 4035 (function must return something)
  134. _inline PVOID GetFiberData( void ) { __asm {
  135. mov eax, fs:[0x10]
  136. mov eax,[eax]
  137. }
  138. }
  139. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  140. #if _MSC_VER >= 1200
  141. #pragma warning(pop)
  142. #else
  143. #pragma warning (default:4035) // Reenable it
  144. #endif
  145. #endif
  146. // begin_ntddk begin_wx86
  147. //
  148. // Define the size of the 80387 save area, which is in the context frame.
  149. //
  150. #define SIZE_OF_80387_REGISTERS 80
  151. //
  152. // The following flags control the contents of the CONTEXT structure.
  153. //
  154. #if !defined(RC_INVOKED)
  155. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  156. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  157. // end_wx86
  158. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  159. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  160. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  161. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  162. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  163. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  164. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  165. CONTEXT_SEGMENTS)
  166. // begin_wx86
  167. #endif
  168. #define MAXIMUM_SUPPORTED_EXTENSION 512
  169. typedef struct _FLOATING_SAVE_AREA {
  170. ULONG ControlWord;
  171. ULONG StatusWord;
  172. ULONG TagWord;
  173. ULONG ErrorOffset;
  174. ULONG ErrorSelector;
  175. ULONG DataOffset;
  176. ULONG DataSelector;
  177. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  178. ULONG Cr0NpxState;
  179. } FLOATING_SAVE_AREA;
  180. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  181. //
  182. // Context Frame
  183. //
  184. // This frame has a several purposes: 1) it is used as an argument to
  185. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  186. // and 3) it is used in the user level thread creation routines.
  187. //
  188. // The layout of the record conforms to a standard call frame.
  189. //
  190. typedef struct _CONTEXT {
  191. //
  192. // The flags values within this flag control the contents of
  193. // a CONTEXT record.
  194. //
  195. // If the context record is used as an input parameter, then
  196. // for each portion of the context record controlled by a flag
  197. // whose value is set, it is assumed that that portion of the
  198. // context record contains valid context. If the context record
  199. // is being used to modify a threads context, then only that
  200. // portion of the threads context will be modified.
  201. //
  202. // If the context record is used as an IN OUT parameter to capture
  203. // the context of a thread, then only those portions of the thread's
  204. // context corresponding to set flags will be returned.
  205. //
  206. // The context record is never used as an OUT only parameter.
  207. //
  208. ULONG ContextFlags;
  209. //
  210. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  211. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  212. // included in CONTEXT_FULL.
  213. //
  214. ULONG Dr0;
  215. ULONG Dr1;
  216. ULONG Dr2;
  217. ULONG Dr3;
  218. ULONG Dr6;
  219. ULONG Dr7;
  220. //
  221. // This section is specified/returned if the
  222. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  223. //
  224. FLOATING_SAVE_AREA FloatSave;
  225. //
  226. // This section is specified/returned if the
  227. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  228. //
  229. ULONG SegGs;
  230. ULONG SegFs;
  231. ULONG SegEs;
  232. ULONG SegDs;
  233. //
  234. // This section is specified/returned if the
  235. // ContextFlags word contians the flag CONTEXT_INTEGER.
  236. //
  237. ULONG Edi;
  238. ULONG Esi;
  239. ULONG Ebx;
  240. ULONG Edx;
  241. ULONG Ecx;
  242. ULONG Eax;
  243. //
  244. // This section is specified/returned if the
  245. // ContextFlags word contians the flag CONTEXT_CONTROL.
  246. //
  247. ULONG Ebp;
  248. ULONG Eip;
  249. ULONG SegCs; // MUST BE SANITIZED
  250. ULONG EFlags; // MUST BE SANITIZED
  251. ULONG Esp;
  252. ULONG SegSs;
  253. //
  254. // This section is specified/returned if the ContextFlags word
  255. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  256. // The format and contexts are processor specific
  257. //
  258. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  259. } CONTEXT;
  260. typedef CONTEXT *PCONTEXT;
  261. // begin_ntminiport
  262. #endif //_X86_
  263. // end_ntddk end_nthal end_winnt end_ntminiport end_wx86
  264. //
  265. // Define the size of FP registers in the FXSAVE format
  266. //
  267. #define SIZE_OF_FX_REGISTERS 128
  268. //
  269. // Format of data for fnsave/frstor instruction
  270. //
  271. typedef struct _FNSAVE_FORMAT {
  272. ULONG ControlWord;
  273. ULONG StatusWord;
  274. ULONG TagWord;
  275. ULONG ErrorOffset;
  276. ULONG ErrorSelector;
  277. ULONG DataOffset;
  278. ULONG DataSelector;
  279. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  280. } FNSAVE_FORMAT, *PFNSAVE_FORMAT;
  281. //
  282. // Format of data for fxsave/fxrstor instruction
  283. //
  284. #include "pshpack1.h"
  285. typedef struct _FXSAVE_FORMAT {
  286. USHORT ControlWord;
  287. USHORT StatusWord;
  288. USHORT TagWord;
  289. USHORT ErrorOpcode;
  290. ULONG ErrorOffset;
  291. ULONG ErrorSelector;
  292. ULONG DataOffset;
  293. ULONG DataSelector;
  294. ULONG MXCsr;
  295. ULONG MXCsrMask;
  296. UCHAR RegisterArea[SIZE_OF_FX_REGISTERS];
  297. UCHAR Reserved3[SIZE_OF_FX_REGISTERS];
  298. UCHAR Reserved4[224];
  299. UCHAR Align16Byte[8];
  300. } FXSAVE_FORMAT, *PFXSAVE_FORMAT;
  301. #include "poppack.h"
  302. //
  303. // Union for FLOATING_SAVE_AREA and MMX_FLOATING_SAVE_AREA
  304. //
  305. typedef struct _FX_SAVE_AREA {
  306. union {
  307. FNSAVE_FORMAT FnArea;
  308. FXSAVE_FORMAT FxArea;
  309. } U;
  310. ULONG NpxSavedCpu; // Cpu that last did fxsave for this thread
  311. ULONG Cr0NpxState; // Has to be the last field because of the
  312. // Boot thread
  313. } FX_SAVE_AREA, *PFX_SAVE_AREA;
  314. #define CONTEXT_TO_PROGRAM_COUNTER(Context) ((Context)->Eip)
  315. #define PROGRAM_COUNTER_TO_CONTEXT(Context, ProgramCounter) ((Context)->Eip = (ProgramCounter))
  316. #define CONTEXT_LENGTH (sizeof(CONTEXT))
  317. #define CONTEXT_ALIGN (sizeof(ULONG))
  318. #define CONTEXT_ROUND (CONTEXT_ALIGN - 1)
  319. // begin_wx86
  320. //
  321. // GDT selectors - These defines are R0 selector numbers, which means
  322. // they happen to match the byte offset relative to
  323. // the base of the GDT.
  324. //
  325. #define KGDT_NULL 0
  326. #define KGDT_R0_CODE 8
  327. #define KGDT_R0_DATA 16
  328. #define KGDT_R3_CODE 24
  329. #define KGDT_R3_DATA 32
  330. #define KGDT_TSS 40
  331. #define KGDT_R0_PCR 48
  332. #define KGDT_R3_TEB 56
  333. #define KGDT_VDM_TILE 64
  334. #define KGDT_LDT 72
  335. #define KGDT_DF_TSS 80
  336. #define KGDT_NMI_TSS 88
  337. // end_wx86
  338. #ifdef ABIOS
  339. //
  340. // raid 72661 shielint Should be NEW os2ldr. The ABIOS ifdef will be
  341. // removed once we switch to new os2ldr.
  342. //
  343. #define KGDT_ALIAS 0x70
  344. #define KGDT_NUMBER 11
  345. #else
  346. #define KGDT_NUMBER 10
  347. #endif
  348. //
  349. // LDT descriptor entry
  350. //
  351. // begin_winnt begin_wx86
  352. #ifndef _LDT_ENTRY_DEFINED
  353. #define _LDT_ENTRY_DEFINED
  354. typedef struct _LDT_ENTRY {
  355. USHORT LimitLow;
  356. USHORT BaseLow;
  357. union {
  358. struct {
  359. UCHAR BaseMid;
  360. UCHAR Flags1; // Declare as bytes to avoid alignment
  361. UCHAR Flags2; // Problems.
  362. UCHAR BaseHi;
  363. } Bytes;
  364. struct {
  365. ULONG BaseMid : 8;
  366. ULONG Type : 5;
  367. ULONG Dpl : 2;
  368. ULONG Pres : 1;
  369. ULONG LimitHi : 4;
  370. ULONG Sys : 1;
  371. ULONG Reserved_0 : 1;
  372. ULONG Default_Big : 1;
  373. ULONG Granularity : 1;
  374. ULONG BaseHi : 8;
  375. } Bits;
  376. } HighWord;
  377. } LDT_ENTRY, *PLDT_ENTRY;
  378. #endif
  379. // end_winnt end_wx86
  380. //
  381. // Process Ldt Information
  382. // NtQueryInformationProcess using ProcessLdtInformation
  383. //
  384. typedef struct _LDT_INFORMATION {
  385. ULONG Start;
  386. ULONG Length;
  387. LDT_ENTRY LdtEntries[1];
  388. } PROCESS_LDT_INFORMATION, *PPROCESS_LDT_INFORMATION;
  389. //
  390. // Process Ldt Size
  391. // NtSetInformationProcess using ProcessLdtSize
  392. //
  393. typedef struct _LDT_SIZE {
  394. ULONG Length;
  395. } PROCESS_LDT_SIZE, *PPROCESS_LDT_SIZE;
  396. //
  397. // Thread Descriptor Table Entry
  398. // NtQueryInformationThread using ThreadDescriptorTableEntry
  399. //
  400. // begin_windbgkd
  401. #ifndef _DESCRIPTOR_TABLE_ENTRY_DEFINED
  402. #define _DESCRIPTOR_TABLE_ENTRY_DEFINED
  403. typedef struct _DESCRIPTOR_TABLE_ENTRY {
  404. ULONG Selector;
  405. LDT_ENTRY Descriptor;
  406. } DESCRIPTOR_TABLE_ENTRY, *PDESCRIPTOR_TABLE_ENTRY;
  407. #endif // _DESCRIPTOR_TABLE_ENTRY_DEFINED
  408. // end_windbgkd
  409. // begin_ntddk begin_wdm begin_nthal
  410. #endif // _X86_
  411. // end_ntddk end_wdm end_nthal
  412. //
  413. // Additional information supplied in QuerySectionInformation for images.
  414. //
  415. #define SECTION_ADDITIONAL_INFO_USED 0
  416. #ifdef __cplusplus
  417. }
  418. #endif
  419. #endif // _NTI386_