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.

375 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. amd64prv.h
  5. Abstract:
  6. This header file defines private interfaces shared between the following
  7. modules:
  8. amd64.c
  9. amd64s.asm
  10. amd64x86.c
  11. Author:
  12. Forrest Foltz (forrestf) 20-Apr-00
  13. Revision History:
  14. --*/
  15. #if !defined(_AMD64PRV_H_)
  16. #define _AMD64PRV_H_
  17. //
  18. // 64-bit pointer and LONG_PTR fields are changed to this
  19. //
  20. typedef LONGLONG POINTER64;
  21. //
  22. // KSEG0 definitions for both the AMD64 and X86 platforms. Note that
  23. // these are duplicated from amd64.h and i386.h, respectively.
  24. //
  25. #define KSEG0_BASE_AMD64 0xFFFFF80000000000UI64
  26. #define KSEG0_SIZE_AMD64 0x0000000040000000UI64
  27. #define KSEG0_LIMIT_AMD64 (KSEG0_BASE_AMD64 + KSEG0_SIZE_AMD64)
  28. #define KSEG0_BASE_X86 0x80000000
  29. #define KSEG0_SIZE_X86 0x40000000
  30. #define KSEG0_LIMIT_X86 (KSEG0_BASE_X86 + KSEG0_SIZE_X86)
  31. #define IS_KSEG0_PTR_X86(x) (((x) >= KSEG0_BASE_X86) && ((x) < KSEG0_LIMIT_X86))
  32. #define IS_KSEG0_PTR_AMD64(x) (((x) >= KSEG0_BASE_AMD64) && ((x) < KSEG0_LIMIT_AMD64))
  33. __inline
  34. POINTER64
  35. PTR_64(
  36. IN PVOID Pointer32
  37. )
  38. /*++
  39. Routine Description:
  40. This function is used by the loader to convert a 32-bit X86 KSEG0 pointer
  41. to a 64-bit AMD64 KSEG0 pointer.
  42. Arguments:
  43. Pointer32 - Supplies the 32-bit KSEG0 pointer to convert.
  44. Return value:
  45. Returns the equivalent 64-bit KSEG0 pointer.
  46. --*/
  47. {
  48. ULONG pointer32;
  49. ULONGLONG pointer64;
  50. if (Pointer32 == NULL) {
  51. return 0;
  52. }
  53. ASSERT( IS_KSEG0_PTR_X86((ULONG)Pointer32) != FALSE );
  54. pointer32 = (ULONG)Pointer32 - KSEG0_BASE_X86;
  55. pointer64 = KSEG0_BASE_AMD64 + pointer32;
  56. return (POINTER64)pointer64;
  57. }
  58. __inline
  59. PVOID
  60. PTR_32(
  61. IN POINTER64 Pointer64
  62. )
  63. /*++
  64. Routine Description:
  65. This function is used by the loader to convert a 64-bit AMD64 KSEG0
  66. pointer to a 32-bit X86 KSEG0 pointer.
  67. Arguments:
  68. Pointer64 - Supplies the 64-bit KSEG0 pointer to convert.
  69. Return value:
  70. Returns the equivalent 32-bit KSEG0 pointer.
  71. --*/
  72. {
  73. ULONG pointer32;
  74. if (Pointer64 == 0) {
  75. return NULL;
  76. }
  77. ASSERT( IS_KSEG0_PTR_AMD64(Pointer64) != FALSE );
  78. pointer32 = (ULONG)(Pointer64 - KSEG0_BASE_AMD64 + KSEG0_BASE_X86);
  79. return (PVOID)pointer32;
  80. }
  81. //
  82. // Macros
  83. //
  84. #define PAGE_MASK ((1 << PAGE_SHIFT) - 1)
  85. #define ROUNDUP_X(x,m) (((x)+(m)-1) & ~((m)-1))
  86. //
  87. // Size round up
  88. //
  89. #define ROUNDUP16(x) ROUNDUP_X(x,16)
  90. #define ROUNDUP_PAGE(x) ROUNDUP_X(x,PAGE_SIZE)
  91. //
  92. // Shared PTE, PFN types
  93. //
  94. typedef ULONG PFN_NUMBER32, *PPFN_NUMBER32;
  95. typedef ULONGLONG PFN_NUMBER64, *PPFN_NUMBER64;
  96. #if defined(_AMD64_)
  97. typedef ULONG PTE_X86, *PPTE_X86;
  98. typedef HARDWARE_PTE PTE_AMD64, *PPTE_AMD64;
  99. #elif defined(_X86_)
  100. typedef ULONGLONG PTE_AMD64, *PPTE_AMD64;
  101. typedef HARDWARE_PTE PTE_X86, *PPTE_X86;
  102. #else
  103. #error "Target architecture not defined"
  104. #endif
  105. //
  106. // Descriptor table descriptor
  107. //
  108. #pragma pack(push,1)
  109. typedef struct DESCRIPTOR_TABLE_DESCRIPTOR {
  110. USHORT Limit;
  111. POINTER64 Base;
  112. } DESCRIPTOR_TABLE_DESCRIPTOR, *PDESCRIPTOR_TABLE_DESCRIPTOR;
  113. #pragma pack(pop)
  114. //
  115. // Structures found within the CM_PARTIAL_RESOURCE_DESCRIPTOR union
  116. //
  117. typedef struct _CM_PRD_GENERIC {
  118. PHYSICAL_ADDRESS Start;
  119. ULONG Length;
  120. } CM_PRD_GENERIC, *PCM_PRD_GENERIC;
  121. typedef struct _CM_PRD_PORT {
  122. PHYSICAL_ADDRESS Start;
  123. ULONG Length;
  124. } CM_PRD_PORT, *PCM_PRD_PORT;
  125. typedef struct _CM_PRD_INTERRUPT {
  126. ULONG Level;
  127. ULONG Vector;
  128. KAFFINITY Affinity;
  129. } CM_PRD_INTERRUPT, *PCM_PRD_INTERRUPT;
  130. typedef struct _CM_PRD_MEMORY {
  131. PHYSICAL_ADDRESS Start;
  132. ULONG Length;
  133. } CM_PRD_MEMORY, *PCM_PRD_MEMORY;
  134. typedef struct _CM_PRD_DMA {
  135. ULONG Channel;
  136. ULONG Port;
  137. ULONG Reserved1;
  138. } CM_PRD_DMA, *PCM_PRD_DMA;
  139. typedef struct _CM_PRD_DEVICEPRIVATE {
  140. ULONG Data[3];
  141. } CM_PRD_DEVICEPRIVATE, *PCM_PRD_DEVICEPRIVATE;
  142. typedef struct _CM_PRD_BUSNUMBER {
  143. ULONG Start;
  144. ULONG Length;
  145. ULONG Reserved;
  146. } CM_PRD_BUSNUMBER, *PCM_PRD_BUSNUMBER;
  147. typedef struct _CM_PRD_DEVICESPECIFICDATA {
  148. ULONG DataSize;
  149. ULONG Reserved1;
  150. ULONG Reserved2;
  151. } CM_PRD_DEVICESPECIFICDATA, *PCM_PRD_DEVICESPECIFICDATA;
  152. //
  153. // Define page table structure.
  154. //
  155. #define PTES_PER_PAGE (PAGE_SIZE / sizeof(HARDWARE_PTE))
  156. typedef HARDWARE_PTE PAGE_TABLE[ PTES_PER_PAGE ];
  157. typedef HARDWARE_PTE *PPAGE_TABLE;
  158. typedef struct _AMD64_PAGE_TABLE {
  159. PTE_AMD64 PteArray[ PTES_PER_PAGE ];
  160. } AMD64_PAGE_TABLE, *PAMD64_PAGE_TABLE;
  161. //
  162. // Constants that are already defined in other header files but are not
  163. // (yet) included here
  164. //
  165. #define LU_BASE_ADDRESS (ULONG)0xFEE00000
  166. //
  167. // Inclusion of this header file by both amd64.c and amd64x86.c ensures that
  168. // a PAGE_TABLE is the same size for both platforms.
  169. //
  170. C_ASSERT( sizeof(PAGE_TABLE) == PAGE_SIZE );
  171. //
  172. // 64-bit GDT entry
  173. //
  174. typedef struct _GDT_64 *PGDT_64;
  175. //
  176. // We keep some information for each AMD64 mapping level
  177. //
  178. typedef struct _AMD64_MAPPING_LEVEL {
  179. ULONGLONG RecursiveMappingBase;
  180. ULONG AddressMask;
  181. ULONG AddressShift;
  182. } CONST AMD64_MAPPING_INFO, *PAMD64_MAPPING_INFO;
  183. //
  184. // Routines and data found in amd64.c and referenced in amd64x86.c
  185. //
  186. #define AMD64_MAPPING_LEVELS 4
  187. extern AMD64_MAPPING_INFO BlAmd64MappingLevels[ AMD64_MAPPING_LEVELS ];
  188. extern const ULONG BlAmd64DoubleFaultStackSize;
  189. #define DOUBLE_FAULT_STACK_SIZE_64 BlAmd64DoubleFaultStackSize
  190. extern const ULONG BlAmd64KernelStackSize;
  191. #define KERNEL_STACK_SIZE_64 BlAmd64KernelStackSize
  192. extern const ULONG BlAmd64McaExceptionStackSize;
  193. #define MCA_EXCEPTION_STACK_SIZE_64 BlAmd64McaExceptionStackSize
  194. extern const ULONG BlAmd64GdtSize;
  195. #define GDT_64_SIZE BlAmd64GdtSize
  196. extern const ULONG BlAmd64IdtSize;
  197. #define IDT_64_SIZE BlAmd64IdtSize
  198. extern const ULONG BlAmd64_TSS_IST_PANIC;
  199. #define TSS64_IST_PANIC BlAmd64_TSS_IST_PANIC
  200. extern const ULONG BlAmd64_TSS_IST_MCA;
  201. #define TSS64_IST_MCA BlAmd64_TSS_IST_MCA
  202. extern const ULONG64 BlAmd64UserSharedData;
  203. #define KI_USER_SHARED_DATA_64 BlAmd64UserSharedData
  204. VOID
  205. BlAmd64ClearTopLevelPte(
  206. VOID
  207. );
  208. VOID
  209. BlAmd64BuildAmd64GDT(
  210. IN PVOID SysTss,
  211. OUT PVOID Gdt
  212. );
  213. VOID
  214. BlAmd64BuildGdtEntry(
  215. IN PGDT_64 Gdt,
  216. IN USHORT Selector,
  217. IN POINTER64 Base,
  218. IN ULONGLONG Limit,
  219. IN ULONG Type,
  220. IN ULONG Dpl,
  221. IN BOOLEAN LongMode,
  222. IN BOOLEAN DefaultBig
  223. );
  224. ARC_STATUS
  225. BlAmd64CreateMapping(
  226. IN ULONGLONG Va,
  227. IN ULONGLONG Pfn
  228. );
  229. ARC_STATUS
  230. BlAmd64MapHalVaSpace(
  231. VOID
  232. );
  233. //
  234. // Routines and data found in amd64x86.c and referenced in amd64.c
  235. //
  236. PAMD64_PAGE_TABLE
  237. BlAmd64AllocatePageTable(
  238. VOID
  239. );
  240. VOID
  241. BlAmd64InitializePageTable(
  242. IN PPAGE_TABLE PageTable
  243. );
  244. ARC_STATUS
  245. BlAmd64PrepForTransferToKernelPhase1(
  246. IN PLOADER_PARAMETER_BLOCK BlLoaderBlock
  247. );
  248. VOID
  249. BlAmd64PrepForTransferToKernelPhase2(
  250. IN PLOADER_PARAMETER_BLOCK BlLoaderBlock
  251. );
  252. ARC_STATUS
  253. BlAmd64TransferToKernel(
  254. IN PTRANSFER_ROUTINE SystemEntry,
  255. IN PLOADER_PARAMETER_BLOCK BlLoaderBlock
  256. );
  257. //
  258. // Routines and data found in amd64s.asm and referenced elsewhere
  259. //
  260. BOOLEAN
  261. BlIsAmd64Supported (
  262. VOID
  263. );
  264. //
  265. // Shared data
  266. //
  267. #endif // _AMD64PRV_H_