NTSTATUS DsppInitialize ( _In_ ULONG Flags ) { BL_LIBRARY_PARAMETERS LibraryParameters = BlpLibraryParameters; BOOLEAN NoGraphics, HighestMode; NTSTATUS Status; PBL_DISPLAY_MODE DisplayMode; ULONGLONG GraphicsResolution; PBL_GRAPHICS_CONSOLE GraphicsConsole; PBL_TEXT_CONSOLE TextConsole, RemoteConsole; /* Initialize font data */ BfiCachedStrikeData = 0; InitializeListHead(&BfiDeferredListHead); InitializeListHead(&BfiFontFileListHead); /* Allocate the font rectangle */ BfiGraphicsRectangle = BlMmAllocateHeap(90); if (!BfiGraphicsRectangle) { return STATUS_NO_MEMORY; } /* Display re-initialization not yet handled */ if (LibraryParameters.LibraryFlags & BL_LIBRARY_FLAG_REINITIALIZE_ALL) { EfiPrintf(L"Display path not handled\r\n"); return STATUS_NOT_SUPPORTED; } /* Check if no graphics console is needed */ if ((Flags & BL_LIBRARY_FLAG_NO_GRAPHICS_CONSOLE) || (DsppGraphicsDisabledByBcd())) { /* Remember this */ NoGraphics = TRUE; } else { /* No graphics -- remember this */ NoGraphics = FALSE; } /* On first load, we always initialize a graphics display */ GraphicsConsole = NULL; if (!(Flags & BL_LIBRARY_FLAG_REINITIALIZE_ALL) || !(NoGraphics)) { /* Default to mode 0 (1024x768) */ DisplayMode = &ConsoleGraphicalResolutionList[0]; /* Check what resolution to use*/ Status = BlGetBootOptionInteger(BlpApplicationEntry.BcdData, BcdLibraryInteger_GraphicsResolution, &GraphicsResolution); if (NT_SUCCESS(Status)) { ConsoleGraphicalResolutionListFlags |= BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG; EfiPrintf(L"Display selection not yet handled\r\n"); return STATUS_NOT_IMPLEMENTED; } /* Check if the highest mode should be forced */ Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData, BcdLibraryBoolean_GraphicsForceHighestMode, &HighestMode); if (NT_SUCCESS(Status)) { ConsoleGraphicalResolutionListFlags |= BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG; EfiPrintf(L"High res mode not yet handled\r\n"); return STATUS_NOT_IMPLEMENTED; } /* Do we need graphics mode after all? */ if (!NoGraphics) { /* Yep -- go allocate it */ GraphicsConsole = BlMmAllocateHeap(sizeof(*GraphicsConsole)); if (GraphicsConsole) { /* Construct it */ Status = ConsoleGraphicalConstruct(GraphicsConsole); if (!NT_SUCCESS(Status)) { EfiPrintf(L"GFX FAILED: %lx\r\n", Status); BlMmFreeHeap(GraphicsConsole); GraphicsConsole = NULL; } else { /* TEST */ RtlFillMemory(GraphicsConsole->FrameBuffer, GraphicsConsole->FrameBufferSize, 0x55); } } } /* Are we using something else than the default mode? */ if (DisplayMode != &ConsoleGraphicalResolutionList[0]) { EfiPrintf(L"Display path not handled\r\n"); return STATUS_NOT_SUPPORTED; } /* Mask out all the flags now */ ConsoleGraphicalResolutionListFlags &= ~(BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG | BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG); } /* Do we have a graphics console? */ TextConsole = NULL; if (!GraphicsConsole) { /* Nope -- go allocate a text console */ TextConsole = BlMmAllocateHeap(sizeof(*TextConsole)); if (TextConsole) { /* Construct it */ Status = ConsoleTextLocalConstruct(TextConsole, TRUE); if (!NT_SUCCESS(Status)) { BlMmFreeHeap(TextConsole); TextConsole = NULL; } } } /* Initialize all globals to NULL */ DspRemoteInputConsole = NULL; DspTextConsole = NULL; DspGraphicalConsole = NULL; /* If we don't have a text console, go get a remote console */ RemoteConsole = NULL; if (!TextConsole) { ConsoleCreateRemoteConsole(&RemoteConsole); } /* Do we have a remote console? */ if (!RemoteConsole) { /* Nope -- what about a graphical one? */ if (GraphicsConsole) { /* Yes, use it for both graphics and text */ DspGraphicalConsole = GraphicsConsole; DspTextConsole = GraphicsConsole; } else if (TextConsole) { /* Nope, but we have a text console */ DspTextConsole = TextConsole; } /* Console has been setup */ return STATUS_SUCCESS; } /* We have a remote console -- have to figure out how to use it*/ EfiPrintf(L"Display path not handled\r\n"); return STATUS_NOT_SUPPORTED; }
/*++ * @name InitializeLibrary * * The InitializeLibrary function initializes the Boot Library. * * @param BootParameters * Pointer to the Boot Application Parameter Block. * * @param LibraryParameters * Pointer to the Boot Library Parameters. * * @return NT_SUCCESS if the boot library was loaded correctly, relevant error * otherwise. * *--*/ NTSTATUS InitializeLibrary ( _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters, _In_ PBL_LIBRARY_PARAMETERS LibraryParameters ) { NTSTATUS Status; PBL_MEMORY_DATA MemoryData; PBL_APPLICATION_ENTRY AppEntry; PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor; ULONG_PTR ParamPointer = (ULONG_PTR)BootAppParameters; /* Validate correct Boot Application data */ if (!(BootAppParameters) || (BootAppParameters->Signature[0] != BOOT_APPLICATION_SIGNATURE_1) || (BootAppParameters->Signature[1] != BOOT_APPLICATION_SIGNATURE_2) || (BootAppParameters->Size < sizeof(*BootAppParameters))) { Status = STATUS_INVALID_PARAMETER; goto Quickie; } /* Get sub-structures */ MemoryData = (PBL_MEMORY_DATA)(ParamPointer + BootAppParameters->MemoryDataOffset); FirmwareDescriptor = (PBL_FIRMWARE_DESCRIPTOR)(ParamPointer + BootAppParameters->FirmwareParametersOffset); AppEntry = (PBL_APPLICATION_ENTRY)(ParamPointer + BootAppParameters->AppEntryOffset); BlpBootDevice = (PBL_DEVICE_DESCRIPTOR)(ParamPointer + BootAppParameters->BootDeviceOffset); BlpApplicationBaseDirectory = LibraryParameters->ApplicationBaseDirectory; /* Initialize the firmware table */ Status = BlpFwInitialize(0, FirmwareDescriptor); if (!NT_SUCCESS(Status)) { goto Quickie; } /* Find boot application entry */ if (strncmp(AppEntry->Signature, BL_APP_ENTRY_SIGNATURE, 7)) { Status = STATUS_INVALID_PARAMETER_9; goto Quickie; } /* Read parameters */ BlpApplicationParameters = BootAppParameters; BlpLibraryParameters = *LibraryParameters; /* Check if the caller sent us their internal BCD options */ if (AppEntry->Flags & BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL) { /* These are external to us now, as far as we are concerned */ AppEntry->Flags &= ~BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL; AppEntry->Flags |= BL_APPLICATION_ENTRY_BCD_OPTIONS_EXTERNAL; } /* Save the application entry flags */ BlpApplicationEntry.Flags = AppEntry->Flags; /* Copy the GUID and point to the options */ BlpApplicationEntry.Guid = AppEntry->Guid; BlpApplicationEntry.BcdData = &AppEntry->BcdData; /* Everything has been captured */ BlpLibraryParametersInitialized = TRUE; /* Initialize the architecture (PM or RM) switching */ Status = BlpArchInitialize(0); if (!NT_SUCCESS(Status)) { goto Quickie; } /* Initialize the memory manager */ Status = BlpMmInitialize(MemoryData, BootAppParameters->MemoryTranslationType, LibraryParameters); if (!NT_SUCCESS(Status)) { EfiPrintf(L"MM init failed!\r\n"); goto Quickie; } /* Initialize firmware now that the heap, etc works */ Status = BlpFwInitialize(1, FirmwareDescriptor); if (!NT_SUCCESS(Status)) { /* Destroy memory manager in phase 1 */ //BlpMmDestroy(1); EfiPrintf(L"Firmware2 init failed!\r\n"); return Status; } #if 0 /* Modern systems have an undocumented BCD system for the boot frequency */ Status = BlGetBootOptionInteger(BlpApplicationEntry.BcdData, 0x15000075, &BootFrequency); if (NT_SUCCESS(Status) && (BootFrequency)) { /* Use it if present */ BlpTimePerformanceFrequency = BootFrequency; } else #endif { /* Use the TSC for calibration */ Status = BlpTimeCalibratePerformanceCounter(); if (!NT_SUCCESS(Status)) { /* Destroy memory manager in phase 1 */ EfiPrintf(L"TSC calibration failed\r\n"); //BlpMmDestroy(1); return Status; } } /* Now setup the rest of the architecture (IDT, etc) */ Status = BlpArchInitialize(1); if (!NT_SUCCESS(Status)) { /* Destroy memory manager in phase 1 */ EfiPrintf(L"Arch2 init failed\r\n"); //BlpMmDestroy(1); return Status; } #ifdef BL_TPM_SUPPORT /* Initialize support for Trusted Platform Module v1.2 */ BlpTpmInitialize(); #endif #ifdef BL_TPM_SUPPORT /* Initialize the event manager */ EnSubsystemInitialized = 1; InitializeListHead(&EnEventNotificationList); #endif /* Initialize the I/O Manager */ Status = BlpIoInitialize(); if (!NT_SUCCESS(Status)) { /* Destroy memory manager in phase 1 and the event manager */ EfiPrintf(L"IO init failed\r\n"); #ifdef BL_TPM_SUPPORT if (EnSubsystemInitialized) { BlpEnDestroy(); } #endif //BlpMmDestroy(1); return Status; } #ifdef BL_NET_SUPPORT /* Initialize the network stack */ Status = BlNetInitialize(); if (!NT_SUCCESS(Status)) { /* Destroy the I/O, event, and memory managers in phase 1 */ BlpIoDestroy(); #ifdef BL_TPM_SUPPORT if (EnSubsystemInitialized) { BlpEnDestroy(); } #endif BlpMmDestroy(1); return Status; } #endif /* Initialize the utility library */ Status = BlUtlInitialize(); if (!NT_SUCCESS(Status)) { /* Destroy the network, I/O, event, and memory managers in phase 1 */ #ifdef BL_NET_SUPPORT BlNetDestroy(); #endif //BlpIoDestroy(); #ifdef BL_TPM_SUPPORT if (EnSubsystemInitialized) { BlpEnDestroy(); } #endif //BlpMmDestroy(1); EfiPrintf(L"Util init failed\r\n"); return Status; } #ifdef BL_KD_SUPPORT /* Initialize PCI Platform Support */ PltInitializePciConfiguration(); #endif #ifdef BL_SECURE_BOOT_SUPPORT /* Read the current SecureBoot Policy*/ Status = BlSecureBootSetActivePolicyFromPersistedData(); if (!NT_SUCCESS(Status)) { /* Destroy everything that we've currently set up */ #ifdef BL_KD_SUPPORT PltDestroyPciConfiguration(); #endif #ifdef BL_NET_SUPPORT BlNetDestroy(); #endif BlpIoDestroy(); #ifdef BL_TPM_SUPPORT if (EnSubsystemInitialized) { BlpEnDestroy(); } #endif BlpMmDestroy(1); return Status; } #endif #ifdef BL_TPM_SUPPORT /* Initialize phase 0 of the security subsystem */ SipInitializePhase0(); #endif #ifdef BL_KD_SUPPORT /* Bring up the boot debugger, now that SecureBoot has been processed */ BlBdInitialize(); #endif #ifdef BL_ETW_SUPPORT /* Initialize internal logging */ BlpLogInitialize(); #endif /* Are graphics enabled? */ if (!(LibraryParameters->LibraryFlags & BL_LIBRARY_FLAG_NO_DISPLAY)) { /* Initialize the graphics library */ BlpDisplayInitialize(LibraryParameters->LibraryFlags); } /* Initialize the boot application persistent data */ PdPersistAllocations = 0; InitializeListHead(&BlBadpListHead); #ifdef BL_TPM_SUPPORT /* Now setup the security subsystem in phase 1 */ BlpSiInitialize(1); #endif /* Setup the text, UI and font resources */ Status = BlpResourceInitialize(); if (!NT_SUCCESS(Status)) { /* Tear down everything if this failed */ if (!(LibraryParameters->LibraryFlags & BL_LIBRARY_FLAG_NO_DISPLAY)) { // BlpDisplayDestroy(); } #ifdef BL_KD_SUPPORT BlpBdDestroy(); PltDestroyPciConfiguration(); #endif #ifdef BL_NET_SUPPORT BlNetDestroy(); #endif //BlpIoDestroy(); #ifdef BL_TPM_SUPPORT if (EnSubsystemInitialized) { BlpEnDestroy(); } #endif //BlpMmDestroy(1); return Status; } #if BL_BITLOCKER_SUPPORT /* Setup the boot cryptography library */ g_pEnvironmentData = &SymCryptEnvironmentWindowsBootLibrary; if (SymCryptEnvWindowsBootLibInit) { SymCryptEnvWindowsBootLibInit(); } #endif /* We are fully initialized, remember this and exit with success */ BlpLibraryParameters.LibraryFlags |= BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED; Status = STATUS_SUCCESS; Quickie: return Status; }
NTSTATUS DsppReinitialize ( _In_ ULONG Flags ) { PBL_TEXT_CONSOLE TextConsole; PBL_GRAPHICS_CONSOLE GraphicsConsole; NTSTATUS Status; ULONGLONG GraphicsResolution; BOOLEAN HighestMode; BL_DISPLAY_MODE CurrentResolution; /* Do we have local input yet? */ if (!DspLocalInputConsole) { /* Create it now */ ConsoleCreateLocalInputConsole(); } /* If a graphics console is present without a remote console... */ TextConsole = NULL; if (!(DspRemoteInputConsole) && (DspGraphicalConsole)) { /* Try to create a remote console */ ConsoleCreateRemoteConsole(&TextConsole); } /* All good for now */ Status = STATUS_SUCCESS; /* Now check if we were able to create the remote console */ if (TextConsole) { EfiPrintf(L"EMS not supported\r\n"); return STATUS_NOT_IMPLEMENTED; } /* Set a local for the right cast */ GraphicsConsole = DspGraphicalConsole; /* Nothing to do without a graphics console being reinitialized */ if (!(Flags & BL_LIBRARY_FLAG_REINITIALIZE_ALL) || !(GraphicsConsole) || !(((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->IsEnabled(GraphicsConsole))) { return Status; } /* Check if graphics are disabled in the BCD */ if (DsppGraphicsDisabledByBcd()) { /* Turn off the graphics console, switching back to text mode */ Status = ((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->Enable(GraphicsConsole, FALSE); } /* Check if a custom graphics resolution is set */ if (MiscGetBootOption(BlpApplicationEntry.BcdData, BcdLibraryInteger_GraphicsResolution)) { /* Check what it's set to */ Status = BlGetBootOptionInteger(BlpApplicationEntry.BcdData, BcdLibraryInteger_GraphicsResolution, &GraphicsResolution); if (!NT_SUCCESS(Status)) { return Status; } /* Now check our current graphical resolution */ Status = ((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->GetGraphicalResolution(GraphicsConsole, &CurrentResolution); if (!NT_SUCCESS(Status)) { return Status; } /* Remember that we're forcing a video mode */ ConsoleGraphicalResolutionListFlags |= BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG; /* Check which resolution to set */ if (!GraphicsResolution) { /* 1024x768 */ EfiPrintf(L"Display selection not yet handled\r\n"); return STATUS_NOT_IMPLEMENTED; } else if (GraphicsResolution == 1) { /* 800x600 */ EfiPrintf(L"Display selection not yet handled\r\n"); return STATUS_NOT_IMPLEMENTED; } else if (GraphicsResolution == 2) { /* 1024x600 */ EfiPrintf(L"Display selection not yet handled\r\n"); return STATUS_NOT_IMPLEMENTED; } } /* Check if the force highest mode setting is present */ if (MiscGetBootOption(BlpApplicationEntry.BcdData, BcdLibraryBoolean_GraphicsForceHighestMode)) { /* Check what it's set to */ Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData, BcdLibraryBoolean_GraphicsForceHighestMode, &HighestMode); if ((NT_SUCCESS(Status)) && (HighestMode)) { /* Remember that high rest mode is being forced */ ConsoleGraphicalResolutionListFlags |= BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG; /* Turn it on */ //((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->SetGraphicalResolution(GraphicsConsole, 0, 0); /* All done now */ ConsoleGraphicalResolutionListFlags |= ~BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG; EfiPrintf(L"High res mode not yet handled\r\n"); Status = STATUS_NOT_IMPLEMENTED; } } /* Return back to the caller */ return Status; }