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.

508 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. bootx86.h
  5. Abstract:
  6. Header file for the x86-specific portions of the common boot library
  7. Author:
  8. John Vert (jvert) 14-Oct-1993
  9. Revision History:
  10. --*/
  11. #ifndef _BOOTX86_
  12. #define _BOOTX86_
  13. #include "bldrx86.h"
  14. #include "..\bootlib.h"
  15. //
  16. // common typedefs
  17. //
  18. //
  19. // This must match the structure with the same name in startup\i386\types.h,
  20. // and the FsContextRecord struct in startup\i386\su.inc.
  21. //
  22. typedef struct _FSCONTEXT_RECORD {
  23. UCHAR BootDrive;
  24. } FSCONTEXT_RECORD, *PFSCONTEXT_RECORD;
  25. // M E M O R Y D E S C R I P T O R
  26. //
  27. // Memory Descriptor - each contiguous block of physical memory is
  28. // described by a Memory Descriptor. The descriptors are a table, with
  29. // the last entry having a BlockBase and BlockSize of zero. A pointer
  30. // to the beginning of this table is passed as part of the BootContext
  31. // Record to the OS Loader.
  32. //
  33. typedef struct _SU_MEMORY_DESCRIPTOR {
  34. ULONG BlockBase;
  35. ULONG BlockSize;
  36. } SU_MEMORY_DESCRIPTOR , *PSU_MEMORY_DESCRIPTOR;
  37. VOID
  38. InitializeMemoryDescriptors (
  39. VOID
  40. );
  41. // B O O T C O N T E X T R E C O R D
  42. //
  43. // Passed to the OS loader by the SU module or bootstrap
  44. // code, whatever the case. Constains all the basic machine
  45. // and environment information the OS loaders needs to get
  46. // itself going.
  47. //
  48. typedef struct _BOOT_CONTEXT {
  49. PFSCONTEXT_RECORD FSContextPointer;
  50. PEXTERNAL_SERVICES_TABLE ExternalServicesTable;
  51. PSU_MEMORY_DESCRIPTOR MemoryDescriptorList;
  52. ULONG MachineType;
  53. ULONG OsLoaderStart;
  54. ULONG OsLoaderEnd;
  55. ULONG ResourceDirectory;
  56. ULONG ResourceOffset;
  57. ULONG OsLoaderBase;
  58. ULONG OsLoaderExports;
  59. ULONG BootFlags;
  60. ULONG NtDetectStart;
  61. ULONG NtDetectEnd;
  62. ULONG SdiAddress;
  63. } BOOT_CONTEXT, *PBOOT_CONTEXT;
  64. //
  65. // Common function prototypes
  66. //
  67. VOID
  68. InitializeDisplaySubsystem(
  69. VOID
  70. );
  71. ARC_STATUS
  72. InitializeMemorySubsystem(
  73. PBOOT_CONTEXT
  74. );
  75. ARC_STATUS
  76. XferPhysicalDiskSectors(
  77. IN UCHAR Int13UnitNumber,
  78. IN ULONGLONG StartSector,
  79. IN UCHAR SectorCount,
  80. OUT PUCHAR Buffer,
  81. IN UCHAR SectorsPerTrack,
  82. IN USHORT Heads,
  83. IN USHORT Cylinders,
  84. IN BOOLEAN AllowExtendedInt13,
  85. IN BOOLEAN Write
  86. );
  87. #define ReadPhysicalSectors(d,a,n,p,s,h,c,f) \
  88. \
  89. XferPhysicalDiskSectors((d),(a),(n),(p),(s),(h),(c),(f),FALSE)
  90. #define WritePhysicalSectors(d,a,n,p,s,h,c,f) \
  91. \
  92. XferPhysicalDiskSectors((d),(a),(n),(p),(s),(h),(c),(f),TRUE)
  93. ARC_STATUS
  94. XferExtendedPhysicalDiskSectors(
  95. IN UCHAR Int13UnitNumber,
  96. IN ULONGLONG StartSector,
  97. IN USHORT SectorCount,
  98. OUT PUCHAR Buffer,
  99. IN BOOLEAN Write
  100. );
  101. #define ReadExtendedPhysicalSectors(d,a,c,p) \
  102. \
  103. XferExtendedPhysicalDiskSectors((d),(a),(c),(p),FALSE)
  104. #define WriteExtendedPhysicalSectors(d,a,c,p) \
  105. \
  106. XferExtendedPhysicalDiskSectors((d),(a),(c),(p),TRUE)
  107. VOID
  108. ResetDiskSystem(
  109. UCHAR Int13UnitNumber
  110. );
  111. VOID
  112. MdShutoffFloppy(
  113. VOID
  114. );
  115. BOOLEAN
  116. FwGetPathMnemonicKey(
  117. IN PCHAR OpenPath,
  118. IN PCHAR Mnemonic,
  119. IN PULONG Key
  120. );
  121. PVOID
  122. FwAllocateHeapAligned(
  123. IN ULONG Size
  124. );
  125. PVOID
  126. FwAllocatePool(
  127. IN ULONG Size
  128. );
  129. PVOID
  130. FwAllocateHeapPermanent(
  131. IN ULONG NumberPages
  132. );
  133. VOID
  134. FwStallExecution(
  135. IN ULONG Microseconds
  136. );
  137. VOID
  138. BlGetActivePartition(
  139. OUT PCHAR PartitionName
  140. );
  141. VOID
  142. BlFillInSystemParameters(
  143. IN PBOOT_CONTEXT BootContextRecord
  144. );
  145. VOID
  146. BlpRemapReserve (
  147. VOID
  148. );
  149. ARC_STATUS
  150. BlpMarkExtendedVideoRegionOffLimits(
  151. VOID
  152. );
  153. //
  154. // global data definitions
  155. //
  156. extern ULONG MachineType;
  157. extern PCONFIGURATION_COMPONENT_DATA FwConfigurationTree;
  158. extern ULONG HeapUsed;
  159. extern ULONG BlHighestPage;
  160. extern ULONG BlLowestPage;
  161. #define HYPER_SPACE_ENTRY 768
  162. #define HYPER_SPACE_BEGIN 0xC0000000
  163. #define HYPER_PAGE_DIR 0xC0300000
  164. //
  165. // X86 Detection definitions
  166. // The size is *ALWAYS* assumed to be 64K.
  167. // N.B. The definition *MUST* be the same as the ones defined in
  168. // startup\su.inc
  169. //
  170. #define DETECTION_LOADED_ADDRESS 0x10000
  171. //
  172. // We need to allocate permanent and temporary memory for the page directory,
  173. // assorted page tables, and the memory descriptors before the blmemory
  174. // routines ever get control. So we have two private heaps, one for permanent
  175. // data and one for temporary data. There are two descriptors for this. The
  176. // permanent heap descriptor starts out as zero-length at P.A. 0x30000. The
  177. // temporary heap descriptor immediately follows the permanent heap in memory
  178. // and starts out as 128k long. As we allocate permanent pages, we increase
  179. // the size of the permanent heap descriptor and increase the base (thereby
  180. // decreasing the size) of the temporary heap descriptor)
  181. //
  182. // So the permanent heap starts at P.A. 0x30000 and grows upwards. The
  183. // temporary heap starts at P.A. 0x5C000 and grows downwards. This gives us
  184. // a total of 128k of combined permanent and temporary data.
  185. //
  186. //
  187. // Heap starting locations (in pages)
  188. //
  189. //
  190. // Scratch buffer for disk cache is 36K and begins before the permanent heap
  191. //
  192. #define SCRATCH_BUFFER_SIZE (36*1024)
  193. extern PUCHAR FwDiskCache;
  194. #define BIOS_DISK_CACHE_START 0x30
  195. #define PERMANENT_HEAP_START (0x30+(SCRATCH_BUFFER_SIZE/PAGE_SIZE))
  196. #define TEMPORARY_HEAP_START 0x60
  197. //
  198. // The base "window" for the loader and loaded images == 16MB
  199. // See the comments in memory.c for the implications of changing these.
  200. //
  201. #define BASE_LOADER_IMAGE (16*1024*1024)
  202. //
  203. // Useful Macro Definitions
  204. //
  205. #define ROUND_UP(Num,Size) (((Num) + Size - 1) & ~(Size -1))
  206. typedef union _UCHAR1 {
  207. UCHAR Uchar[1];
  208. UCHAR ForceAlignment;
  209. } UCHAR1, *PUCHAR1;
  210. typedef union _UCHAR2 {
  211. UCHAR Uchar[2];
  212. USHORT ForceAlignment;
  213. } UCHAR2, *PUCHAR2;
  214. typedef union _UCHAR4 {
  215. UCHAR Uchar[4];
  216. ULONG ForceAlignment;
  217. } UCHAR4, *PUCHAR4;
  218. //
  219. // This macro copies an unaligned src byte to an aligned dst byte
  220. //
  221. #define CopyUchar1(Dst,Src) { \
  222. *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
  223. }
  224. //
  225. // This macro copies an unaligned src word to an aligned dst word
  226. //
  227. #define CopyUchar2(Dst,Src) { \
  228. *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
  229. }
  230. //
  231. // This macro copies an unaligned src longword to an aligned dsr longword
  232. //
  233. #define CopyUchar4(Dst,Src) { \
  234. *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
  235. }
  236. //
  237. // Global definitions for the BIOS ARC Emulation
  238. //
  239. // Defines for the ARC name of console input and output
  240. //
  241. #define CONSOLE_INPUT_NAME "multi(0)key(0)keyboard(0)"
  242. #define CONSOLE_OUTPUT_NAME "multi(0)video(0)monitor(0)"
  243. //
  244. // Define special character values.
  245. //
  246. #define ASCI_NUL 0x00
  247. #define ASCI_BEL 0x07
  248. #define ASCI_BS 0x08
  249. #define ASCI_HT 0x09
  250. #define ASCI_LF 0x0A
  251. #define ASCI_VT 0x0B
  252. #define ASCI_FF 0x0C
  253. #define ASCI_CR 0x0D
  254. #define ASCI_ESC 0x1B
  255. #define ASCI_SYSRQ 0x80
  256. //
  257. // Device I/O prototypes
  258. //
  259. ARC_STATUS
  260. BiosPartitionClose(
  261. IN ULONG FileId
  262. );
  263. ARC_STATUS
  264. BiosPartitionOpen(
  265. IN PCHAR OpenPath,
  266. IN OPEN_MODE OpenMode,
  267. OUT PULONG FileId
  268. );
  269. ARC_STATUS
  270. BiosPartitionRead (
  271. IN ULONG FileId,
  272. OUT PVOID Buffer,
  273. IN ULONG Length,
  274. OUT PULONG Count
  275. );
  276. ARC_STATUS
  277. BiosPartitionWrite(
  278. IN ULONG FileId,
  279. OUT PVOID Buffer,
  280. IN ULONG Length,
  281. OUT PULONG Count
  282. );
  283. ARC_STATUS
  284. BiosPartitionSeek (
  285. IN ULONG FileId,
  286. IN PLARGE_INTEGER Offset,
  287. IN SEEK_MODE SeekMode
  288. );
  289. ARC_STATUS
  290. BiosPartitionGetFileInfo(
  291. IN ULONG FileId,
  292. OUT PFILE_INFORMATION FileInfo
  293. );
  294. ARC_STATUS
  295. BiosDiskGetFileInfo(
  296. IN ULONG FileId,
  297. OUT PFILE_INFORMATION FileInfo
  298. );
  299. ARC_STATUS
  300. BlArcNotYetImplemented(
  301. IN ULONG FileId
  302. );
  303. ARC_STATUS
  304. BiosConsoleOpen(
  305. IN PCHAR OpenPath,
  306. IN OPEN_MODE OpenMode,
  307. OUT PULONG FileId
  308. );
  309. ARC_STATUS
  310. BiosConsoleReadStatus(
  311. IN ULONG FileId
  312. );
  313. ARC_STATUS
  314. BiosConsoleRead (
  315. IN ULONG FileId,
  316. OUT PUCHAR Buffer,
  317. IN ULONG Length,
  318. OUT PULONG Count
  319. );
  320. ARC_STATUS
  321. BiosConsoleWrite (
  322. IN ULONG FileId,
  323. OUT PUCHAR Buffer,
  324. IN ULONG Length,
  325. OUT PULONG Count
  326. );
  327. ARC_STATUS
  328. BiosDiskOpen(
  329. IN ULONG DriveId,
  330. IN OPEN_MODE OpenMode,
  331. OUT PULONG FileId
  332. );
  333. ARC_STATUS
  334. BiosDiskRead (
  335. IN ULONG FileId,
  336. OUT PVOID Buffer,
  337. IN ULONG Length,
  338. OUT PULONG Count
  339. );
  340. ARC_STATUS
  341. BiosElToritoDiskRead(
  342. IN ULONG FileId,
  343. OUT PVOID Buffer,
  344. IN ULONG Length,
  345. OUT PULONG Count
  346. );
  347. BOOLEAN
  348. BlIsElToritoCDBoot(
  349. UCHAR DriveNum
  350. );
  351. ARC_STATUS
  352. BiosDiskWrite(
  353. IN ULONG FileId,
  354. OUT PVOID Buffer,
  355. IN ULONG Length,
  356. OUT PULONG Count
  357. );
  358. ARC_STATUS
  359. HardDiskPartitionOpen(
  360. IN ULONG FileId,
  361. IN ULONG DiskId,
  362. IN UCHAR PartitionNumber
  363. );
  364. //
  365. // Boot debugger prototypes required to initialize the appropriate IDT entries.
  366. //
  367. VOID
  368. BdTrap01 (
  369. VOID
  370. );
  371. VOID
  372. BdTrap03 (
  373. VOID
  374. );
  375. VOID
  376. BdTrap0d (
  377. VOID
  378. );
  379. VOID
  380. BdTrap0e (
  381. VOID
  382. );
  383. VOID
  384. BdTrap2d (
  385. VOID
  386. );
  387. //
  388. // Helper functions and macros
  389. //
  390. #define PTE_PER_PAGE_X86 (PAGE_SIZE / sizeof(HARDWARE_PTE_X86))
  391. #define PTE_PER_PAGE_X86PAE (PAGE_SIZE / sizeof(HARDWARE_PTE_X86PAE))
  392. //
  393. // todo: this is a bug. this can be used in the translation
  394. // from a PTE frame number to the physical address.
  395. // by returning a pointer to the address, we limit ourselves
  396. // and will die if there are more than 32 bits of address.
  397. // jamschw: 2/26/02
  398. //
  399. #define PAGE_FRAME_FROM_PTE( _pte ) \
  400. ((PVOID)(((ULONG) _pte->PageFrameNumber) << PAGE_SHIFT))
  401. #define PPI_SHIFT_X86PAE 30
  402. #define PT_INDEX_PAE( va ) (((ULONG_PTR)(va) >> PTI_SHIFT) & \
  403. ((1 << (PDI_SHIFT_X86PAE - PTI_SHIFT)) - 1))
  404. #define PD_INDEX_PAE( va ) (((ULONG_PTR)(va) >> PDI_SHIFT_X86PAE) & \
  405. ((1 << (PPI_SHIFT_X86PAE - PDI_SHIFT_X86PAE)) - 1));
  406. #define PP_INDEX_PAE( va ) ((ULONG_PTR)(va) >> PPI_SHIFT_X86PAE)
  407. #define PAGE_TO_VIRTUAL( page ) ((PVOID)((page << PAGE_SHIFT)))
  408. #endif // _BOOTX86_