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.

334 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. entry.c
  5. Abstract:
  6. EFI specific startup for os loaders
  7. Author:
  8. John Vert (jvert) 14-Oct-1993
  9. Revision History:
  10. --*/
  11. #if defined(_IA64_)
  12. #include "bootia64.h"
  13. #endif
  14. #include "biosdrv.h"
  15. #include "efi.h"
  16. #include "stdio.h"
  17. #include "flop.h"
  18. #if 0
  19. #define DBGOUT(x) BlPrint x
  20. #define DBGPAUSE while(!GET_KEY());
  21. #else
  22. #define DBGOUT(x)
  23. #define DBGPAUSE
  24. #endif
  25. extern VOID AEInitializeStall();
  26. //
  27. // Externals
  28. //
  29. extern EFI_HANDLE EfiImageHandle;
  30. extern EFI_SYSTEM_TABLE *EfiST;
  31. extern EFI_BOOT_SERVICES *EfiBS;
  32. extern EFI_RUNTIME_SERVICES *EfiRS;
  33. BOOLEAN GoneVirtual = FALSE;
  34. //
  35. // Prototypes for Internal Routines
  36. //
  37. VOID
  38. DoGlobalInitialization(
  39. PBOOT_CONTEXT
  40. );
  41. #if defined(ELTORITO)
  42. BOOLEAN ElToritoCDBoot = FALSE;
  43. #endif
  44. extern CHAR NetBootPath[];
  45. //
  46. // Global context pointers. These are passed to us by the SU module or
  47. // the bootstrap code.
  48. //
  49. PCONFIGURATION_COMPONENT_DATA FwConfigurationTree = NULL;
  50. PEXTERNAL_SERVICES_TABLE ExternalServicesTable;
  51. UCHAR BootPartitionName[129];
  52. ULONG FwHeapUsed = 0;
  53. #if defined(NEC_98)
  54. ULONG Key;
  55. int ArrayDiskStartOrdinal = -1;
  56. BOOLEAN BootedFromArrayDisk = FALSE;
  57. BOOLEAN HyperScsiAvalable = FALSE;
  58. #endif //NEC_98
  59. ULONG MachineType = 0;
  60. LONG_PTR OsLoaderBase;
  61. LONG_PTR OsLoaderExports;
  62. extern PUCHAR BlpResourceDirectory;
  63. extern PUCHAR BlpResourceFileOffset;
  64. #if DBG
  65. extern EFI_SYSTEM_TABLE *EfiST;
  66. #define DBG_TRACE(_X) EfiST->ConOut->OutputString(EfiST->ConOut, (_X))
  67. #else
  68. #define DBG_TRACE(_X)
  69. #endif // for FORCE_CD_BOOT
  70. VOID
  71. NtProcessStartup(
  72. IN PBOOT_CONTEXT BootContextRecord
  73. )
  74. /*++
  75. Routine Description:
  76. Main entry point for setup loader. Control is transferred here by the
  77. start-up (SU) module.
  78. Arguments:
  79. BootContextRecord - Supplies the boot context, particularly the
  80. ExternalServicesTable.
  81. Returns:
  82. Does not return. Control eventually passed to the kernel.
  83. --*/
  84. {
  85. PBOOT_DEVICE_ATAPI BootDeviceAtapi;
  86. PBOOT_DEVICE_SCSI BootDeviceScsi;
  87. PBOOT_DEVICE_FLOPPY BootDeviceFloppy;
  88. PBOOT_DEVICE_UNKNOWN BootDeviceUnknown;
  89. ARC_STATUS Status;
  90. DBG_TRACE(L"NtProcessStart: Entry\r\n");
  91. //
  92. // Initialize the boot loader's video
  93. //
  94. DoGlobalInitialization(BootContextRecord);
  95. BlFillInSystemParameters(BootContextRecord);
  96. //
  97. // Initialize the memory descriptor list, the OS loader heap, and the
  98. // OS loader parameter block.
  99. //
  100. DBG_TRACE( L"NtProcessStartup:about to BlMemoryInitialize\r\n");
  101. Status = BlMemoryInitialize();
  102. if (Status != ESUCCESS) {
  103. DBG_TRACE(TEXT("Couldn't initialize memory\r\n"));
  104. EfiBS->Exit(EfiImageHandle, Status, 0, 0);
  105. }
  106. #ifdef FORCE_CD_BOOT
  107. DBG_TRACE(L"Forcing BootMediaCdrom\r\n");
  108. BootContextRecord->MediaType = BootMediaCdrom;
  109. #endif // for FORCE_CD_BOOT
  110. if (BootContextRecord->MediaType == BootMediaFloppyDisk) {
  111. //
  112. // Boot was from A:
  113. //
  114. BootDeviceFloppy = (PBOOT_DEVICE_FLOPPY) &(BootContextRecord->BootDevice);
  115. sprintf(BootPartitionName,
  116. "multi(0)disk(0)fdisk(%u)",
  117. BootDeviceFloppy->DriveNumber);
  118. } else if (BootContextRecord->MediaType == BootMediaTcpip) {
  119. //
  120. // Boot was from the net
  121. //
  122. strcpy(BootPartitionName,"net(0)");
  123. BlBootingFromNet = TRUE;
  124. #if defined(ELTORITO)
  125. } else if (BootContextRecord->MediaType == BootMediaCdrom) {
  126. #ifdef FORCE_CD_BOOT
  127. sprintf(BootPartitionName,
  128. "multi(0)disk(0)cdrom(%u)",
  129. 0
  130. );
  131. ElToritoCDBoot = TRUE;
  132. #else
  133. //
  134. // Boot was from El Torito CD
  135. //
  136. if( BootContextRecord->BusType == BootBusAtapi ) {
  137. BootDeviceAtapi = (PBOOT_DEVICE_ATAPI) &(BootContextRecord->BootDevice);
  138. sprintf(BootPartitionName,
  139. "multi(0)disk(0)cdrom(%u)",
  140. BootDeviceAtapi->Lun);
  141. } else if( BootContextRecord->BusType == BootBusScsi ) {
  142. BootDeviceScsi = (PBOOT_DEVICE_SCSI) &(BootContextRecord->BootDevice);
  143. sprintf(BootPartitionName,
  144. "multi(0)disk(0)cdrom(%u)",
  145. BootDeviceScsi->Lun);
  146. } else if( BootContextRecord->BusType == BootBusVendor ) {
  147. BootDeviceUnknown = (PBOOT_DEVICE_UNKNOWN) &(BootContextRecord->BootDevice);
  148. sprintf(BootPartitionName,
  149. "multi(0)disk(0)cdrom(%u)",
  150. 0
  151. );
  152. }
  153. ElToritoCDBoot = TRUE;
  154. #endif // for FORCE_CD_BOOT
  155. #endif // for ELTORITO
  156. } else {
  157. //
  158. // Find the partition we have been booted from. Note that this
  159. // is *NOT* necessarily the active partition. If the system has
  160. // Boot Mangler installed, it will be the active partition, and
  161. // we have to go figure out what partition we are actually on.
  162. //
  163. if (BootContextRecord->BusType == BootBusAtapi) {
  164. BootDeviceAtapi = (PBOOT_DEVICE_ATAPI) &(BootContextRecord->BootDevice);
  165. sprintf(BootPartitionName,
  166. "multi(0)disk(0)rdisk(%u)partition(%u)",
  167. BlGetDriveId(BL_DISKTYPE_ATAPI, (PBOOT_DEVICE)BootDeviceAtapi), // BootDeviceAtapi->Lun,
  168. BootContextRecord->PartitionNumber);
  169. } else if (BootContextRecord->BusType == BootBusScsi) {
  170. BootDeviceScsi = (PBOOT_DEVICE_SCSI) &(BootContextRecord->BootDevice);
  171. sprintf(BootPartitionName,
  172. "scsi(0)disk(0)rdisk(%u)partition(%u)",
  173. BlGetDriveId(BL_DISKTYPE_SCSI, (PBOOT_DEVICE)BootDeviceScsi), //BootDeviceScsi->Pun,
  174. BootContextRecord->PartitionNumber);
  175. } else if (BootContextRecord->BusType == BootBusVendor) {
  176. BootDeviceUnknown = (PBOOT_DEVICE_UNKNOWN) &(BootContextRecord->BootDevice);
  177. sprintf(BootPartitionName,
  178. "multi(0)disk(0)rdisk(%u)partition(%u)",
  179. BlGetDriveId(BL_DISKTYPE_UNKNOWN, (PBOOT_DEVICE)BootDeviceUnknown), //BootDeviceUnknown->LegacyDriveLetter & 0x7F,
  180. BootContextRecord->PartitionNumber);
  181. }
  182. }
  183. //
  184. // Initialize the OS loader I/O system.
  185. //
  186. AEInitializeStall();
  187. FlipToPhysical();
  188. DBG_TRACE( L"NtProcessStartup:about to Init I/O\r\n");
  189. FlipToVirtual();
  190. Status = BlIoInitialize();
  191. if (Status != ESUCCESS) {
  192. #if DBG
  193. BlPrint(TEXT("Couldn't initialize I/O\r\n"));
  194. #endif
  195. EfiBS->Exit(EfiImageHandle, Status, 0, 0);
  196. }
  197. //
  198. // Call off to regular startup code
  199. //
  200. FlipToPhysical();
  201. DBG_TRACE( L"NtProcessStartup:about to call BlStartup\r\n");
  202. FlipToVirtual();
  203. BlStartup(BootPartitionName);
  204. //
  205. // we should never get here!
  206. //
  207. do {
  208. GET_KEY();
  209. } while ( 1 );
  210. }
  211. VOID
  212. DoGlobalInitialization(
  213. IN PBOOT_CONTEXT BootContextRecord
  214. )
  215. /*++
  216. Routine Description
  217. This routine calls all of the subsytem initialization routines.
  218. Arguments:
  219. None
  220. Returns:
  221. Nothing
  222. --*/
  223. {
  224. ARC_STATUS Status;
  225. //
  226. // Set base address of OS Loader image for the debugger.
  227. //
  228. OsLoaderBase = BootContextRecord->OsLoaderBase;
  229. OsLoaderExports = BootContextRecord->OsLoaderExports;
  230. //
  231. // Initialize memory.
  232. //
  233. Status = InitializeMemorySubsystem(BootContextRecord);
  234. if (Status != ESUCCESS) {
  235. #if DBG
  236. BlPrint(TEXT("InitializeMemory failed %lx\r\n"),Status);
  237. #endif
  238. EfiBS->Exit(EfiImageHandle, Status, 0, 0);
  239. }
  240. ExternalServicesTable=BootContextRecord->ExternalServicesTable;
  241. MachineType = (ULONG) BootContextRecord->MachineType;
  242. //
  243. // Turn the cursor off
  244. //
  245. // bugbug EFI
  246. //HW_CURSOR(0,127);
  247. FlipToPhysical();
  248. DBG_TRACE( L"DoGlobalInitialization: cursor off\r\n");
  249. EfiST->ConOut->EnableCursor(EfiST->ConOut, FALSE);
  250. FlipToVirtual();
  251. BlpResourceDirectory = (PUCHAR)(BootContextRecord->ResourceDirectory);
  252. BlpResourceFileOffset = (PUCHAR)(BootContextRecord->ResourceOffset);
  253. OsLoaderBase = BootContextRecord->OsLoaderBase;
  254. OsLoaderExports = BootContextRecord->OsLoaderExports;
  255. }