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.

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