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.

688 lines
15 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. #if !defined(MIDL_PASS) || defined(_M_IX86)
  46. #if (_MSC_FULL_VER >= 13012035)
  47. //
  48. // Define bit scan intrinsics.
  49. //
  50. //#define BitScanForward _BitScanForward
  51. //#define BitScanReverse _BitScanReverse
  52. //BOOLEAN
  53. //_BitScanForward (
  54. // OUT ULONG *Index,
  55. // IN ULONG Mask
  56. // );
  57. //BOOLEAN
  58. //_BitScanReverse (
  59. // OUT ULONG *Index,
  60. // IN ULONG Mask
  61. // );
  62. //#pragma intrinsic(_BitScanForward)
  63. //#pragma intrinsic(_BitScanReverse)
  64. //
  65. // Define FS referencing intrinsics
  66. //
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. UCHAR
  71. __readfsbyte (
  72. IN ULONG Offset
  73. );
  74. USHORT
  75. __readfsword (
  76. IN ULONG Offset
  77. );
  78. ULONG
  79. __readfsdword (
  80. IN ULONG Offset
  81. );
  82. VOID
  83. __writefsbyte (
  84. IN ULONG Offset,
  85. IN UCHAR Data
  86. );
  87. VOID
  88. __writefsword (
  89. IN ULONG Offset,
  90. IN USHORT Data
  91. );
  92. VOID
  93. __writefsdword (
  94. IN ULONG Offset,
  95. IN ULONG Data
  96. );
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #pragma intrinsic(__readfsbyte)
  101. #pragma intrinsic(__readfsword)
  102. #pragma intrinsic(__readfsdword)
  103. #pragma intrinsic(__writefsbyte)
  104. #pragma intrinsic(__writefsword)
  105. #pragma intrinsic(__writefsdword)
  106. #endif
  107. #endif
  108. // end_ntddk end_wdm end_nthal end_winnt end_ntminiport end_wx86
  109. //
  110. // Values put in ExceptionRecord.ExceptionInformation[0]
  111. // First parameter is always in ExceptionInformation[1],
  112. // Second parameter is always in ExceptionInformation[2]
  113. //
  114. #define BREAKPOINT_BREAK 0
  115. #define BREAKPOINT_PRINT 1
  116. #define BREAKPOINT_PROMPT 2
  117. #define BREAKPOINT_LOAD_SYMBOLS 3
  118. #define BREAKPOINT_UNLOAD_SYMBOLS 4
  119. #define BREAKPOINT_COMMAND_STRING 5
  120. //
  121. // Define Address of User Shared Data
  122. //
  123. #define MM_SHARED_USER_DATA_VA 0x7FFE0000
  124. #define USER_SHARED_DATA ((KUSER_SHARED_DATA * const)MM_SHARED_USER_DATA_VA)
  125. // Add definitions for quick user mode test of i386 system architecture type
  126. #ifndef IsNEC_98
  127. #define IsNEC_98 (USER_SHARED_DATA->AlternativeArchitecture == NEC98x86)
  128. #endif
  129. #ifndef IsNotNEC_98
  130. #define IsNotNEC_98 (USER_SHARED_DATA->AlternativeArchitecture != NEC98x86)
  131. #endif
  132. #ifndef SetNEC_98
  133. #define SetNEC_98
  134. #endif
  135. #if defined(MIDL_PASS) || !defined(_M_IX86)
  136. struct _TEB *
  137. NTAPI
  138. NtCurrentTeb( void );
  139. #else
  140. #define PcTeb 0x18
  141. #if (_MSC_FULL_VER >= 13012035)
  142. _inline struct _TEB * NtCurrentTeb( void ) { return (struct _TEB *) (ULONG_PTR) __readfsdword (PcTeb); }
  143. #else
  144. #if _MSC_VER >= 1200
  145. #pragma warning(push)
  146. #endif
  147. #pragma warning (disable:4035) // disable 4035 (function must return something)
  148. _inline struct _TEB * NtCurrentTeb( void ) { __asm mov eax, fs:[PcTeb] }
  149. #if _MSC_VER >= 1200
  150. #pragma warning(pop)
  151. #else
  152. #pragma warning (default:4035) // reenable it
  153. #endif
  154. #endif
  155. #endif // defined(MIDL_PASS) || defined(__cplusplus) || !defined(_M_IX86)
  156. // begin_ntddk begin_nthal
  157. //
  158. // Size of kernel mode stack.
  159. //
  160. #define KERNEL_STACK_SIZE 12288
  161. //
  162. // Define size of large kernel mode stack for callbacks.
  163. //
  164. #define KERNEL_LARGE_STACK_SIZE 61440
  165. //
  166. // Define number of pages to initialize in a large kernel stack.
  167. //
  168. #define KERNEL_LARGE_STACK_COMMIT 12288
  169. // end_ntddk end_nthal
  170. #define DOUBLE_FAULT_STACK_SIZE KERNEL_STACK_SIZE
  171. //
  172. // Call frame record definition.
  173. //
  174. // There is no standard call frame for NT/386, but there is a linked
  175. // list structure used to register exception handlers, this is it.
  176. //
  177. // begin_nthal
  178. //
  179. // Exception Registration structure
  180. //
  181. typedef struct _EXCEPTION_REGISTRATION_RECORD {
  182. struct _EXCEPTION_REGISTRATION_RECORD *Next;
  183. PEXCEPTION_ROUTINE Handler;
  184. } EXCEPTION_REGISTRATION_RECORD;
  185. typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD;
  186. //
  187. // Define constants for system IDTs
  188. //
  189. #define MAXIMUM_IDTVECTOR 0xff
  190. #define MAXIMUM_PRIMARY_VECTOR 0xff
  191. #define PRIMARY_VECTOR_BASE 0x30 // 0-2f are x86 trap vectors
  192. // begin_ntddk
  193. #ifdef _X86_
  194. // end_ntddk
  195. // begin_ntddk begin_winnt
  196. #if !defined(MIDL_PASS) && defined(_M_IX86)
  197. FORCEINLINE
  198. VOID
  199. MemoryBarrier (
  200. VOID
  201. )
  202. {
  203. LONG Barrier;
  204. __asm {
  205. xchg Barrier, eax
  206. }
  207. }
  208. #define YieldProcessor() __asm { rep nop }
  209. //
  210. // Prefetch is not supported on all x86 procssors.
  211. //
  212. #define PreFetchCacheLine(l, a)
  213. //
  214. // PreFetchCacheLine level defines.
  215. //
  216. #define PF_TEMPORAL_LEVEL_1
  217. #define PF_NON_TEMPORAL_LEVEL_ALL
  218. // end_ntddk
  219. #if (_MSC_FULL_VER >= 13012035)
  220. _inline PVOID GetFiberData( void ) { return *(PVOID *) (ULONG_PTR) __readfsdword (0x10);}
  221. _inline PVOID GetCurrentFiber( void ) { return (PVOID) (ULONG_PTR) __readfsdword (0x10);}
  222. #else
  223. #if _MSC_VER >= 1200
  224. #pragma warning(push)
  225. #endif
  226. #pragma warning (disable:4035) // disable 4035 (function must return something)
  227. _inline PVOID GetFiberData( void ) { __asm {
  228. mov eax, fs:[0x10]
  229. mov eax,[eax]
  230. }
  231. }
  232. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  233. #if _MSC_VER >= 1200
  234. #pragma warning(pop)
  235. #else
  236. #pragma warning (default:4035) // Reenable it
  237. #endif
  238. #endif
  239. // begin_ntddk
  240. #endif
  241. // begin_wx86
  242. //
  243. // Define the size of the 80387 save area, which is in the context frame.
  244. //
  245. #define SIZE_OF_80387_REGISTERS 80
  246. //
  247. // The following flags control the contents of the CONTEXT structure.
  248. //
  249. #if !defined(RC_INVOKED)
  250. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  251. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  252. // end_wx86
  253. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  254. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  255. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  256. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  257. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  258. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  259. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  260. CONTEXT_SEGMENTS)
  261. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
  262. // begin_wx86
  263. #endif
  264. #define MAXIMUM_SUPPORTED_EXTENSION 512
  265. typedef struct _FLOATING_SAVE_AREA {
  266. ULONG ControlWord;
  267. ULONG StatusWord;
  268. ULONG TagWord;
  269. ULONG ErrorOffset;
  270. ULONG ErrorSelector;
  271. ULONG DataOffset;
  272. ULONG DataSelector;
  273. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  274. ULONG Cr0NpxState;
  275. } FLOATING_SAVE_AREA;
  276. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  277. //
  278. // Context Frame
  279. //
  280. // This frame has a several purposes: 1) it is used as an argument to
  281. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  282. // and 3) it is used in the user level thread creation routines.
  283. //
  284. // The layout of the record conforms to a standard call frame.
  285. //
  286. typedef struct _CONTEXT {
  287. //
  288. // The flags values within this flag control the contents of
  289. // a CONTEXT record.
  290. //
  291. // If the context record is used as an input parameter, then
  292. // for each portion of the context record controlled by a flag
  293. // whose value is set, it is assumed that that portion of the
  294. // context record contains valid context. If the context record
  295. // is being used to modify a threads context, then only that
  296. // portion of the threads context will be modified.
  297. //
  298. // If the context record is used as an IN OUT parameter to capture
  299. // the context of a thread, then only those portions of the thread's
  300. // context corresponding to set flags will be returned.
  301. //
  302. // The context record is never used as an OUT only parameter.
  303. //
  304. ULONG ContextFlags;
  305. //
  306. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  307. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  308. // included in CONTEXT_FULL.
  309. //
  310. ULONG Dr0;
  311. ULONG Dr1;
  312. ULONG Dr2;
  313. ULONG Dr3;
  314. ULONG Dr6;
  315. ULONG Dr7;
  316. //
  317. // This section is specified/returned if the
  318. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  319. //
  320. FLOATING_SAVE_AREA FloatSave;
  321. //
  322. // This section is specified/returned if the
  323. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  324. //
  325. ULONG SegGs;
  326. ULONG SegFs;
  327. ULONG SegEs;
  328. ULONG SegDs;
  329. //
  330. // This section is specified/returned if the
  331. // ContextFlags word contians the flag CONTEXT_INTEGER.
  332. //
  333. ULONG Edi;
  334. ULONG Esi;
  335. ULONG Ebx;
  336. ULONG Edx;
  337. ULONG Ecx;
  338. ULONG Eax;
  339. //
  340. // This section is specified/returned if the
  341. // ContextFlags word contians the flag CONTEXT_CONTROL.
  342. //
  343. ULONG Ebp;
  344. ULONG Eip;
  345. ULONG SegCs; // MUST BE SANITIZED
  346. ULONG EFlags; // MUST BE SANITIZED
  347. ULONG Esp;
  348. ULONG SegSs;
  349. //
  350. // This section is specified/returned if the ContextFlags word
  351. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  352. // The format and contexts are processor specific
  353. //
  354. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  355. } CONTEXT;
  356. typedef CONTEXT *PCONTEXT;
  357. // begin_ntminiport
  358. #endif //_X86_
  359. // end_ntddk end_nthal end_winnt end_ntminiport end_wx86
  360. //
  361. // Define the size of FP registers in the FXSAVE format
  362. //
  363. #define SIZE_OF_FX_REGISTERS 128
  364. //
  365. // Format of data for fnsave/frstor instruction
  366. //
  367. typedef struct _FNSAVE_FORMAT {
  368. ULONG ControlWord;
  369. ULONG StatusWord;
  370. ULONG TagWord;
  371. ULONG ErrorOffset;
  372. ULONG ErrorSelector;
  373. ULONG DataOffset;
  374. ULONG DataSelector;
  375. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  376. } FNSAVE_FORMAT, *PFNSAVE_FORMAT;
  377. //
  378. // Format of data for fxsave/fxrstor instruction
  379. //
  380. #include "pshpack1.h"
  381. typedef struct _FXSAVE_FORMAT {
  382. USHORT ControlWord;
  383. USHORT StatusWord;
  384. USHORT TagWord;
  385. USHORT ErrorOpcode;
  386. ULONG ErrorOffset;
  387. ULONG ErrorSelector;
  388. ULONG DataOffset;
  389. ULONG DataSelector;
  390. ULONG MXCsr;
  391. ULONG MXCsrMask;
  392. UCHAR RegisterArea[SIZE_OF_FX_REGISTERS];
  393. UCHAR Reserved3[SIZE_OF_FX_REGISTERS];
  394. UCHAR Reserved4[224];
  395. UCHAR Align16Byte[8];
  396. } FXSAVE_FORMAT, *PFXSAVE_FORMAT;
  397. #include "poppack.h"
  398. //
  399. // Union for FLOATING_SAVE_AREA and MMX_FLOATING_SAVE_AREA
  400. //
  401. typedef struct _FX_SAVE_AREA {
  402. union {
  403. FNSAVE_FORMAT FnArea;
  404. FXSAVE_FORMAT FxArea;
  405. } U;
  406. ULONG NpxSavedCpu; // Cpu that last did fxsave for this thread
  407. ULONG Cr0NpxState; // Has to be the last field because of the
  408. // Boot thread
  409. } FX_SAVE_AREA, *PFX_SAVE_AREA;
  410. #define CONTEXT_TO_PROGRAM_COUNTER(Context) ((Context)->Eip)
  411. #define PROGRAM_COUNTER_TO_CONTEXT(Context, ProgramCounter) ((Context)->Eip = (ProgramCounter))
  412. #define CONTEXT_LENGTH (sizeof(CONTEXT))
  413. #define CONTEXT_ALIGN (sizeof(ULONG))
  414. #define CONTEXT_ROUND (CONTEXT_ALIGN - 1)
  415. // begin_wx86
  416. //
  417. // GDT selectors - These defines are R0 selector numbers, which means
  418. // they happen to match the byte offset relative to
  419. // the base of the GDT.
  420. //
  421. #define KGDT_NULL 0
  422. #define KGDT_R0_CODE 8
  423. #define KGDT_R0_DATA 16
  424. #define KGDT_R3_CODE 24
  425. #define KGDT_R3_DATA 32
  426. #define KGDT_TSS 40
  427. #define KGDT_R0_PCR 48
  428. #define KGDT_R3_TEB 56
  429. #define KGDT_VDM_TILE 64
  430. #define KGDT_LDT 72
  431. #define KGDT_DF_TSS 80
  432. #define KGDT_NMI_TSS 88
  433. // end_wx86
  434. #ifdef ABIOS
  435. //
  436. // raid 72661 shielint Should be NEW os2ldr. The ABIOS ifdef will be
  437. // removed once we switch to new os2ldr.
  438. //
  439. #define KGDT_ALIAS 0x70
  440. #define KGDT_NUMBER 11
  441. #else
  442. #define KGDT_NUMBER 10
  443. #endif
  444. //
  445. // LDT descriptor entry
  446. //
  447. // begin_winnt begin_wx86
  448. #ifndef _LDT_ENTRY_DEFINED
  449. #define _LDT_ENTRY_DEFINED
  450. typedef struct _LDT_ENTRY {
  451. USHORT LimitLow;
  452. USHORT BaseLow;
  453. union {
  454. struct {
  455. UCHAR BaseMid;
  456. UCHAR Flags1; // Declare as bytes to avoid alignment
  457. UCHAR Flags2; // Problems.
  458. UCHAR BaseHi;
  459. } Bytes;
  460. struct {
  461. ULONG BaseMid : 8;
  462. ULONG Type : 5;
  463. ULONG Dpl : 2;
  464. ULONG Pres : 1;
  465. ULONG LimitHi : 4;
  466. ULONG Sys : 1;
  467. ULONG Reserved_0 : 1;
  468. ULONG Default_Big : 1;
  469. ULONG Granularity : 1;
  470. ULONG BaseHi : 8;
  471. } Bits;
  472. } HighWord;
  473. } LDT_ENTRY, *PLDT_ENTRY;
  474. #endif
  475. // end_winnt end_wx86
  476. //
  477. // Process Ldt Information
  478. // NtQueryInformationProcess using ProcessLdtInformation
  479. //
  480. typedef struct _LDT_INFORMATION {
  481. ULONG Start;
  482. ULONG Length;
  483. LDT_ENTRY LdtEntries[1];
  484. } PROCESS_LDT_INFORMATION, *PPROCESS_LDT_INFORMATION;
  485. //
  486. // Process Ldt Size
  487. // NtSetInformationProcess using ProcessLdtSize
  488. //
  489. typedef struct _LDT_SIZE {
  490. ULONG Length;
  491. } PROCESS_LDT_SIZE, *PPROCESS_LDT_SIZE;
  492. //
  493. // Thread Descriptor Table Entry
  494. // NtQueryInformationThread using ThreadDescriptorTableEntry
  495. //
  496. // begin_windbgkd
  497. #ifndef _DESCRIPTOR_TABLE_ENTRY_DEFINED
  498. #define _DESCRIPTOR_TABLE_ENTRY_DEFINED
  499. typedef struct _DESCRIPTOR_TABLE_ENTRY {
  500. ULONG Selector;
  501. LDT_ENTRY Descriptor;
  502. } DESCRIPTOR_TABLE_ENTRY, *PDESCRIPTOR_TABLE_ENTRY;
  503. #endif // _DESCRIPTOR_TABLE_ENTRY_DEFINED
  504. // end_windbgkd
  505. // begin_ntddk begin_wdm begin_nthal
  506. #endif // _X86_
  507. // end_ntddk end_wdm end_nthal
  508. PVOID
  509. RtlLookupFunctionTable (
  510. IN PVOID ControlPc,
  511. OUT PVOID *ImageBase,
  512. OUT PULONG SizeOfTable
  513. );
  514. //
  515. // Additional information supplied in QuerySectionInformation for images.
  516. //
  517. #define SECTION_ADDITIONAL_INFO_USED 0
  518. #ifdef __cplusplus
  519. }
  520. #endif
  521. #endif // _NTI386_