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.

349 lines
8.9 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. CHAR 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. ULONGLONG BootFlags = 0;
  65. #if DBG
  66. extern EFI_SYSTEM_TABLE *EfiST;
  67. #define DBG_TRACE(_X) EfiPrint(_X)
  68. #else
  69. #define DBG_TRACE(_X)
  70. #endif // for FORCE_CD_BOOT
  71. VOID
  72. NtProcessStartup(
  73. IN PBOOT_CONTEXT BootContextRecord
  74. )
  75. /*++
  76. Routine Description:
  77. Main entry point for setup loader. Control is transferred here by the
  78. start-up (SU) module.
  79. Arguments:
  80. BootContextRecord - Supplies the boot context, particularly the
  81. ExternalServicesTable.
  82. Returns:
  83. Does not return. Control eventually passed to the kernel.
  84. --*/
  85. {
  86. PBOOT_DEVICE_ATAPI BootDeviceAtapi;
  87. PBOOT_DEVICE_SCSI BootDeviceScsi;
  88. PBOOT_DEVICE_FLOPPY BootDeviceFloppy;
  89. PBOOT_DEVICE_UNKNOWN BootDeviceUnknown;
  90. ARC_STATUS Status;
  91. DBG_TRACE(L"NtProcessStart: Entry\r\n");
  92. //
  93. // Initialize the boot loader's video
  94. //
  95. DoGlobalInitialization(BootContextRecord);
  96. BlFillInSystemParameters(BootContextRecord);
  97. //
  98. // Set the global bootflags
  99. //
  100. BootFlags = BootContextRecord->BootFlags;
  101. //
  102. // Initialize the memory descriptor list, the OS loader heap, and the
  103. // OS loader parameter block.
  104. //
  105. DBG_TRACE( L"NtProcessStartup:about to BlMemoryInitialize\r\n");
  106. Status = BlMemoryInitialize();
  107. if (Status != ESUCCESS) {
  108. DBG_TRACE(TEXT("Couldn't initialize memory\r\n"));
  109. FlipToPhysical();
  110. EfiBS->Exit(EfiImageHandle, Status, 0, 0);
  111. }
  112. #ifdef FORCE_CD_BOOT
  113. DBG_TRACE(L"Forcing BootMediaCdrom\r\n");
  114. BootContextRecord->MediaType = BootMediaCdrom;
  115. #endif // for FORCE_CD_BOOT
  116. if (BootContextRecord->MediaType == BootMediaFloppyDisk) {
  117. //
  118. // Boot was from A:
  119. //
  120. BootDeviceFloppy = (PBOOT_DEVICE_FLOPPY) &(BootContextRecord->BootDevice);
  121. sprintf(BootPartitionName,
  122. "multi(0)disk(0)fdisk(%u)",
  123. BootDeviceFloppy->DriveNumber);
  124. } else if (BootContextRecord->MediaType == BootMediaTcpip) {
  125. //
  126. // Boot was from the net
  127. //
  128. strcpy(BootPartitionName,"net(0)");
  129. BlBootingFromNet = TRUE;
  130. #if defined(ELTORITO)
  131. } else if (BootContextRecord->MediaType == BootMediaCdrom) {
  132. #ifdef FORCE_CD_BOOT
  133. sprintf(BootPartitionName,
  134. "multi(0)disk(0)cdrom(%u)",
  135. 0
  136. );
  137. ElToritoCDBoot = TRUE;
  138. #else
  139. //
  140. // Boot was from El Torito CD
  141. //
  142. if( BootContextRecord->BusType == BootBusAtapi ) {
  143. BootDeviceAtapi = (PBOOT_DEVICE_ATAPI) &(BootContextRecord->BootDevice);
  144. sprintf(BootPartitionName,
  145. "multi(0)disk(0)cdrom(%u)",
  146. BootDeviceAtapi->Lun);
  147. } else if( BootContextRecord->BusType == BootBusScsi ) {
  148. BootDeviceScsi = (PBOOT_DEVICE_SCSI) &(BootContextRecord->BootDevice);
  149. sprintf(BootPartitionName,
  150. "multi(0)disk(0)cdrom(%u)",
  151. BootDeviceScsi->Lun);
  152. } else if( BootContextRecord->BusType == BootBusVendor ) {
  153. BootDeviceUnknown = (PBOOT_DEVICE_UNKNOWN) &(BootContextRecord->BootDevice);
  154. sprintf(BootPartitionName,
  155. "multi(0)disk(0)cdrom(%u)",
  156. 0
  157. );
  158. }
  159. ElToritoCDBoot = TRUE;
  160. #endif // for FORCE_CD_BOOT
  161. #endif // for ELTORITO
  162. } else {
  163. //
  164. // Find the partition we have been booted from. Note that this
  165. // is *NOT* necessarily the active partition. If the system has
  166. // Boot Mangler installed, it will be the active partition, and
  167. // we have to go figure out what partition we are actually on.
  168. //
  169. if (BootContextRecord->BusType == BootBusAtapi) {
  170. BootDeviceAtapi = (PBOOT_DEVICE_ATAPI) &(BootContextRecord->BootDevice);
  171. sprintf(BootPartitionName,
  172. "multi(0)disk(0)rdisk(%u)partition(%u)",
  173. BlGetDriveId(BL_DISKTYPE_ATAPI, (PBOOT_DEVICE)BootDeviceAtapi), // BootDeviceAtapi->Lun,
  174. BootContextRecord->PartitionNumber);
  175. } else if (BootContextRecord->BusType == BootBusScsi) {
  176. BootDeviceScsi = (PBOOT_DEVICE_SCSI) &(BootContextRecord->BootDevice);
  177. sprintf(BootPartitionName,
  178. "scsi(0)disk(0)rdisk(%u)partition(%u)",
  179. BlGetDriveId(BL_DISKTYPE_SCSI, (PBOOT_DEVICE)BootDeviceScsi), //BootDeviceScsi->Pun,
  180. BootContextRecord->PartitionNumber);
  181. } else if (BootContextRecord->BusType == BootBusVendor) {
  182. BootDeviceUnknown = (PBOOT_DEVICE_UNKNOWN) &(BootContextRecord->BootDevice);
  183. sprintf(BootPartitionName,
  184. "multi(0)disk(0)rdisk(%u)partition(%u)",
  185. BlGetDriveId(BL_DISKTYPE_UNKNOWN, (PBOOT_DEVICE)BootDeviceUnknown), //BootDeviceUnknown->LegacyDriveLetter & 0x7F,
  186. BootContextRecord->PartitionNumber);
  187. }
  188. }
  189. //
  190. // Initialize the OS loader I/O system.
  191. //
  192. AEInitializeStall();
  193. FlipToPhysical();
  194. DBG_TRACE( L"NtProcessStartup:about to Init I/O\r\n");
  195. FlipToVirtual();
  196. Status = BlIoInitialize();
  197. if (Status != ESUCCESS) {
  198. #if DBG
  199. BlPrint(TEXT("Couldn't initialize I/O\r\n"));
  200. #endif
  201. FlipToPhysical();
  202. EfiBS->Exit(EfiImageHandle, Status, 0, 0);
  203. }
  204. //
  205. // Call off to regular startup code
  206. //
  207. FlipToPhysical();
  208. DBG_TRACE( L"NtProcessStartup:about to call BlStartup\r\n");
  209. FlipToVirtual();
  210. BlStartup(BootPartitionName);
  211. //
  212. // we should never get here!
  213. //
  214. if (BootFlags & BOOTFLAG_REBOOT_ON_FAILURE) {
  215. ULONG StartTime = ArcGetRelativeTime();
  216. BlPrint(TEXT("\nRebooting in 5 seconds...\n"));
  217. while ( ArcGetRelativeTime() - StartTime < 5) {}
  218. ArcRestart();
  219. }
  220. do {
  221. GET_KEY();
  222. } while ( 1 );
  223. }
  224. VOID
  225. DoGlobalInitialization(
  226. IN PBOOT_CONTEXT BootContextRecord
  227. )
  228. /*++
  229. Routine Description
  230. This routine calls all of the subsytem initialization routines.
  231. Arguments:
  232. None
  233. Returns:
  234. Nothing
  235. --*/
  236. {
  237. ARC_STATUS Status;
  238. //
  239. // Set base address of OS Loader image for the debugger.
  240. //
  241. OsLoaderBase = BootContextRecord->OsLoaderBase;
  242. OsLoaderExports = BootContextRecord->OsLoaderExports;
  243. //
  244. // Initialize memory.
  245. //
  246. Status = InitializeMemorySubsystem(BootContextRecord);
  247. if (Status != ESUCCESS) {
  248. #if DBG
  249. BlPrint(TEXT("InitializeMemory failed %lx\r\n"),Status);
  250. #endif
  251. FlipToPhysical();
  252. EfiBS->Exit(EfiImageHandle, Status, 0, 0);
  253. }
  254. ExternalServicesTable=BootContextRecord->ExternalServicesTable;
  255. MachineType = (ULONG) BootContextRecord->MachineType;
  256. //
  257. // Turn the cursor off
  258. //
  259. // bugbug EFI
  260. //HW_CURSOR(0,127);
  261. FlipToPhysical();
  262. DBG_TRACE( L"DoGlobalInitialization: cursor off\r\n");
  263. EfiST->ConOut->EnableCursor(EfiST->ConOut, FALSE);
  264. FlipToVirtual();
  265. BlpResourceDirectory = (PUCHAR)(BootContextRecord->ResourceDirectory);
  266. BlpResourceFileOffset = (PUCHAR)(BootContextRecord->ResourceOffset);
  267. OsLoaderBase = BootContextRecord->OsLoaderBase;
  268. OsLoaderExports = BootContextRecord->OsLoaderExports;
  269. }