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.

536 lines
11 KiB

  1. /**
  2. *** Copyright (C) 1996-97 Intel Corporation. All rights reserved.
  3. ***
  4. *** The information and source code contained herein is the exclusive
  5. *** property of Intel Corporation and may not be disclosed, examined
  6. *** or reproduced in whole or in part without explicit written authorization
  7. *** from the company.
  8. **/
  9. /*++
  10. Copyright (c) 1992 Microsoft Corporation
  11. Module Name:
  12. bootia64.h
  13. Abstract:
  14. Header file for the Ia64 portions of the common boot library
  15. Author:
  16. John Vert (jvert) 14-Oct-1993
  17. Revision History:
  18. Allen Kay (akay) 26-Jan-1996 Ported to IA-64
  19. --*/
  20. #include "bldria64.h"
  21. #include "..\bootlib.h"
  22. #include "efi.h"
  23. //
  24. // Macro definition
  25. //
  26. //
  27. // Macro for translation memory size in bytes to page size in TR format
  28. //
  29. #define MEM_SIZE_TO_PS(MemSize, TrPageSize) \
  30. if (MemSize <= MEM_4K) { \
  31. TrPageSize = PS_4K; \
  32. } else if (MemSize <= MEM_8K) { \
  33. TrPageSize = PS_8K; \
  34. } else if (MemSize <= MEM_16K) { \
  35. TrPageSize = PS_16K; \
  36. } else if (MemSize <= MEM_64K) { \
  37. TrPageSize = PS_64K; \
  38. } else if (MemSize <= MEM_256K) { \
  39. TrPageSize = PS_256K; \
  40. } else if (MemSize <= MEM_1M) { \
  41. TrPageSize = PS_1M; \
  42. } else if (MemSize <= MEM_4M) { \
  43. TrPageSize = PS_4M; \
  44. } else if (MemSize <= MEM_16M) { \
  45. TrPageSize = PS_16M; \
  46. } else if (MemSize <= MEM_64M) { \
  47. TrPageSize = PS_64M; \
  48. } else if (MemSize <= MEM_256M) { \
  49. TrPageSize = PS_256M; \
  50. }
  51. extern PMEMORY_DESCRIPTOR MDArray;
  52. extern ULONG MaxDescriptors;
  53. extern ULONG NumberDescriptors;
  54. VOID
  55. InitializeMemoryDescriptors (
  56. VOID
  57. );
  58. VOID
  59. InsertDescriptor (
  60. ULONG BasePage,
  61. ULONG NumberOfPages,
  62. MEMORY_TYPE MemoryType
  63. );
  64. // B O O T C O N T E X T R E C O R D
  65. //
  66. // Passed to the OS loader by the SU module or bootstrap
  67. // code, whatever the case. Constains all the basic machine
  68. // and environment information the OS loaders needs to get
  69. // itself going.
  70. //
  71. typedef enum {
  72. BootBusAtapi,
  73. BootBusScsi,
  74. BootBusVendor,
  75. BootBusMax
  76. } BUS_TYPE;
  77. typedef enum {
  78. BootMediaHardDisk,
  79. BootMediaCdrom,
  80. BootMediaFloppyDisk,
  81. BootMediaTcpip,
  82. BootMediaMax
  83. } MEDIA_TYPE;
  84. typedef struct _BOOT_DEVICE_ATAPI {
  85. UCHAR PrimarySecondary;
  86. UCHAR SlaveMaster;
  87. USHORT Lun;
  88. } BOOT_DEVICE_ATAPI, *PBOOT_DEVICE_ATAPI;
  89. typedef struct _BOOT_DEVICE_SCSI {
  90. USHORT Pun;
  91. USHORT Lun;
  92. } BOOT_DEVICE_SCSI, *PBOOT_DEVICE_SCSI;
  93. typedef struct _BOOT_DEVICE_FLOPPY {
  94. ULONG DriveNumber;
  95. } BOOT_DEVICE_FLOPPY, *PBOOT_DEVICE_FLOPPY;
  96. typedef struct _BOOT_DEVICE_IPv4 {
  97. USHORT RemotePort;
  98. USHORT LocalPort;
  99. EFI_IPv4_ADDRESS Ip;
  100. } BOOT_DEVICE_IPv4, *PBOOT_DEVICE_IPv4;
  101. typedef struct {
  102. UINT64 Ip[2];
  103. } IPv6_ADDRESS;
  104. typedef struct _BOOT_DEVICE_IPv6 {
  105. USHORT RemotePort;
  106. USHORT LocalPort;
  107. IPv6_ADDRESS Ip;
  108. } BOOT_DEVICE_IPv6, *PBOOT_DEVICE_IPv6;
  109. typedef struct {
  110. ULONG Data1;
  111. USHORT Data2;
  112. USHORT Data3;
  113. UCHAR Data4[8];
  114. } BOOT_EFI_GUID;
  115. typedef struct _BOOT_DEVICE_UNKNOWN {
  116. BOOT_EFI_GUID Guid;
  117. UCHAR LegacyDriveLetter;
  118. } BOOT_DEVICE_UNKNOWN, *PBOOT_DEVICE_UNKNOWN;
  119. typedef union _BOOT_DEVICE {
  120. BOOT_DEVICE_ATAPI BootDeviceAtapi;
  121. BOOT_DEVICE_SCSI BootDeviceScsi;
  122. BOOT_DEVICE_FLOPPY BootDeviceFloppy;
  123. BOOT_DEVICE_IPv4 BootDeviceIpv4;
  124. BOOT_DEVICE_IPv6 BootDeviceIpv6;
  125. BOOT_DEVICE_UNKNOWN BootDeviceUnknown;
  126. } BOOT_DEVICE, *PBOOT_DEVICE;
  127. typedef struct _BOOT_CONTEXT {
  128. ULONG BusType;
  129. ULONG MediaType;
  130. ULONG PartitionNumber;
  131. BOOT_DEVICE BootDevice;
  132. PEXTERNAL_SERVICES_TABLE ExternalServicesTable;
  133. ULONGLONG MachineType;
  134. ULONGLONG OsLoaderStart;
  135. ULONGLONG OsLoaderEnd;
  136. ULONGLONG ResourceDirectory;
  137. ULONGLONG ResourceOffset;
  138. ULONGLONG OsLoaderBase;
  139. ULONGLONG OsLoaderExports;
  140. } BOOT_CONTEXT, *PBOOT_CONTEXT;
  141. //
  142. // Common function prototypes
  143. //
  144. VOID
  145. InitializeDisplaySubsystem(
  146. VOID
  147. );
  148. ARC_STATUS
  149. InitializeMemorySubsystem(
  150. PBOOT_CONTEXT
  151. );
  152. ARC_STATUS
  153. XferPhysicalDiskSectors(
  154. IN UCHAR Int13UnitNumber,
  155. IN ULONGLONG StartSector,
  156. IN UCHAR SectorCount,
  157. OUT PUCHAR Buffer,
  158. IN UCHAR SectorsPerTrack,
  159. IN USHORT Heads,
  160. IN USHORT Cylinders,
  161. IN BOOLEAN AllowExtendedInt13,
  162. IN BOOLEAN Write
  163. );
  164. #define ReadPhysicalSectors(d,a,n,p,s,h,c,f) \
  165. \
  166. XferPhysicalDiskSectors((d),(a),(n),(p),(s),(h),(c),(f),FALSE)
  167. #define WritePhysicalSectors(d,a,n,p,s,h,c,f) \
  168. \
  169. XferPhysicalDiskSectors((d),(a),(n),(p),(s),(h),(c),(f),TRUE)
  170. ARC_STATUS
  171. XferExtendedPhysicalDiskSectors(
  172. IN ULONGLONG DeviceHandle,
  173. IN ULONGLONG StartSector,
  174. IN USHORT SectorCount,
  175. OUT PUCHAR Buffer,
  176. IN BOOLEAN Write
  177. );
  178. #define ReadExtendedPhysicalSectors(d,a,c,p) \
  179. \
  180. XferExtendedPhysicalDiskSectors((d),(a),(c),(p),FALSE)
  181. #define WriteExtendedPhysicalSectors(d,a,c,p) \
  182. \
  183. XferExtendedPhysicalDiskSectors((d),(a),(c),(p),TRUE)
  184. VOID
  185. ResetDiskSystem(
  186. UCHAR Int13UnitNumber
  187. );
  188. VOID
  189. MdShutoffFloppy(
  190. VOID
  191. );
  192. BOOLEAN
  193. FwGetPathMnemonicKey(
  194. IN PCHAR OpenPath,
  195. IN PCHAR Mnemonic,
  196. IN PULONG Key
  197. );
  198. PVOID
  199. FwAllocateHeapAligned(
  200. IN ULONG Size
  201. );
  202. PVOID
  203. FwAllocatePool(
  204. IN ULONG Size
  205. );
  206. PVOID
  207. FwAllocateHeapPermanent(
  208. IN ULONG NumberPages
  209. );
  210. VOID
  211. FwStallExecution(
  212. IN ULONG Microseconds
  213. );
  214. VOID
  215. BlGetActivePartition(
  216. OUT PUCHAR PartitionName
  217. );
  218. VOID
  219. BlFillInSystemParameters(
  220. IN PBOOT_CONTEXT BootContextRecord
  221. );
  222. //
  223. // PS/2 ABIOS module (in abiosc.c)
  224. //
  225. VOID
  226. RemapAbiosSelectors(
  227. VOID
  228. );
  229. //
  230. // global data definitions
  231. //
  232. extern ULONG MachineType;
  233. extern PCONFIGURATION_COMPONENT_DATA FwConfigurationTree;
  234. extern ULONG HeapUsed;
  235. ULONG PalFreeBase;
  236. //
  237. // page Table definition
  238. //
  239. #define HYPER_SPACE_BEGIN 0xC0000000
  240. #define HYPER_PAGE_DIR 0xC0300000
  241. #define GetPteOffset(va) \
  242. ( (((ULONG)(va)) << (32-PDI_SHIFT)) >> ((32-PDI_SHIFT) + PTI_SHIFT) )
  243. //
  244. // X86 Detection definitions
  245. // The size is *ALWAYS* assumed to be 64K.
  246. // N.B. The definition *MUST* be the same as the ones defined in
  247. // startup\su.inc
  248. //
  249. #define DETECTION_LOADED_ADDRESS 0x10000
  250. //
  251. // We need to allocate permanent and temporary memory for the page directory,
  252. // assorted page tables, and the memory descriptors before the blmemory
  253. // routines ever get control. So we have two private heaps, one for permanent
  254. // data and one for temporary data. There are two descriptors for this. The
  255. // permanent heap descriptor starts out as zero-length at P.A. 0x30000. The
  256. // temporary heap descriptor immediately follows the permanent heap in memory
  257. // and starts out as 128k long. As we allocate permanent pages, we increase
  258. // the size of the permanent heap descriptor and increase the base (thereby
  259. // decreasing the size) of the temporary heap descriptor)
  260. //
  261. // So the permanent heap starts at P.A. 0x30000 and grows upwards. The
  262. // temporary heap starts at P.A. 0x5C000 and grows downwards. This gives us
  263. // a total of 128k of combined permanent and temporary data.
  264. //
  265. //
  266. // Heap starting locations (in pages)
  267. //
  268. #define PERMANENT_HEAP_START (0x1010000 >> PAGE_SHIFT)
  269. #define TEMPORARY_HEAP_START (0x1040000 >> PAGE_SHIFT)
  270. //
  271. // Useful Macro Definitions
  272. //
  273. #define ROUND_UP(Num,Size) (((Num) + Size - 1) & ~(Size -1))
  274. typedef union _UCHAR1 {
  275. UCHAR Uchar[1];
  276. UCHAR ForceAlignment;
  277. } UCHAR1, *PUCHAR1;
  278. typedef union _UCHAR2 {
  279. UCHAR Uchar[2];
  280. USHORT ForceAlignment;
  281. } UCHAR2, *PUCHAR2;
  282. typedef union _UCHAR4 {
  283. UCHAR Uchar[4];
  284. ULONG ForceAlignment;
  285. } UCHAR4, *PUCHAR4;
  286. //
  287. // This macro copies an unaligned src byte to an aligned dst byte
  288. //
  289. #define CopyUchar1(Dst,Src) { \
  290. *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
  291. }
  292. //
  293. // This macro copies an unaligned src word to an aligned dst word
  294. //
  295. #define CopyUchar2(Dst,Src) { \
  296. *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
  297. }
  298. //
  299. // This macro copies an unaligned src longword to an aligned dsr longword
  300. //
  301. #define CopyUchar4(Dst,Src) { \
  302. *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
  303. }
  304. //
  305. // Global definitions for the BIOS ARC Emulation
  306. //
  307. //
  308. // Defines for the ARC name of console input and output
  309. //
  310. #define CONSOLE_INPUT_NAME "multi(0)key(0)keyboard(0)"
  311. #define CONSOLE_OUTPUT_NAME "multi(0)video(0)monitor(0)"
  312. //
  313. // Define special character values.
  314. //
  315. #define ASCI_NUL 0x00
  316. #define ASCI_BEL 0x07
  317. #define ASCI_BS 0x08
  318. #define ASCI_HT 0x09
  319. #define ASCI_LF 0x0A
  320. #define ASCI_VT 0x0B
  321. #define ASCI_FF 0x0C
  322. #define ASCI_CR 0x0D
  323. #define ASCI_CSI 0x9B
  324. #define ASCI_ESC 0x1B
  325. #define ASCI_SYSRQ 0x80
  326. //
  327. // Device I/O prototypes
  328. //
  329. ARC_STATUS
  330. BiosPartitionClose(
  331. IN ULONG FileId
  332. );
  333. ARC_STATUS
  334. BiosPartitionOpen(
  335. IN PCHAR OpenPath,
  336. IN OPEN_MODE OpenMode,
  337. OUT PULONG FileId
  338. );
  339. ARC_STATUS
  340. BiosPartitionRead (
  341. IN ULONG FileId,
  342. OUT PVOID Buffer,
  343. IN ULONG Length,
  344. OUT PULONG Count
  345. );
  346. ARC_STATUS
  347. BiosPartitionWrite(
  348. IN ULONG FileId,
  349. OUT PVOID Buffer,
  350. IN ULONG Length,
  351. OUT PULONG Count
  352. );
  353. ARC_STATUS
  354. BiosPartitionSeek (
  355. IN ULONG FileId,
  356. IN PLARGE_INTEGER Offset,
  357. IN SEEK_MODE SeekMode
  358. );
  359. ARC_STATUS
  360. BiosDiskGetFileInfo(
  361. IN ULONG FileId,
  362. OUT PFILE_INFORMATION FileInfo
  363. );
  364. ARC_STATUS
  365. BiosPartitionGetFileInfo(
  366. IN ULONG FileId,
  367. OUT PFILE_INFORMATION FileInfo
  368. );
  369. ARC_STATUS
  370. BlArcNotYetImplemented(
  371. IN ULONG FileId
  372. );
  373. ARC_STATUS
  374. BiosConsoleOpen(
  375. IN PCHAR OpenPath,
  376. IN OPEN_MODE OpenMode,
  377. OUT PULONG FileId
  378. );
  379. ARC_STATUS
  380. BiosConsoleReadStatus(
  381. IN ULONG FileId
  382. );
  383. ARC_STATUS
  384. BiosConsoleRead (
  385. IN ULONG FileId,
  386. OUT PUCHAR Buffer,
  387. IN ULONG Length,
  388. OUT PULONG Count
  389. );
  390. ARC_STATUS
  391. BiosConsoleWrite (
  392. IN ULONG FileId,
  393. OUT PWCHAR Buffer,
  394. IN ULONG Length,
  395. OUT PULONG Count
  396. );
  397. ARC_STATUS
  398. BiosDiskOpen(
  399. IN ULONG DriveId,
  400. IN OPEN_MODE OpenMode,
  401. OUT PULONG FileId
  402. );
  403. ARC_STATUS
  404. BiosDiskRead (
  405. IN ULONG FileId,
  406. OUT PVOID Buffer,
  407. IN ULONG Length,
  408. OUT PULONG Count
  409. );
  410. ARC_STATUS
  411. BiosElToritoDiskRead(
  412. IN ULONG FileId,
  413. OUT PVOID Buffer,
  414. IN ULONG Length,
  415. OUT PULONG Count
  416. );
  417. BOOLEAN
  418. BlIsElToritoCDBoot(
  419. UCHAR DriveNum
  420. );
  421. ARC_STATUS
  422. BiosDiskWrite(
  423. IN ULONG FileId,
  424. OUT PVOID Buffer,
  425. IN ULONG Length,
  426. OUT PULONG Count
  427. );
  428. ARC_STATUS
  429. HardDiskPartitionOpen(
  430. IN ULONG FileId,
  431. IN ULONG DiskId,
  432. IN UCHAR PartitionNumber
  433. );