XTLDR Rewrite #7

Merged
belliash merged 184 commits from xtldr_rewrite into master 2024-01-09 18:51:04 +01:00
8 changed files with 162 additions and 88 deletions
Showing only changes of commit 2b2efd0dd3 - Show all commits

View File

@ -10,14 +10,15 @@
#define __XTDK_BMTYPES_H
#include <xttypes.h>
#include <xtuefi.h>
/* Debug port type definitions */
/* XTLDR Debug port type definitions */
#define XTBL_DEBUGPORT_SCREEN 1
#define XTBL_DEBUGPORT_SERIAL 2
/* XTLDR configuration data */
typedef struct _XTBM_CONFIGURATION
typedef struct _XTBL_CONFIGURATION
{
PWCHAR Default;
PWCHAR Debug;
@ -26,6 +27,14 @@ typedef struct _XTBM_CONFIGURATION
PWCHAR Theme;
ULONG Timeout;
PWCHAR Tune;
} XTBM_CONFIGURATION, *PXTBM_CONFIGURATION;
} XTBL_CONFIGURATION, *PXTBL_CONFIGURATION;
/* XTLDR status data */
typedef struct _XTBL_STATUS
{
BOOLEAN BootServices;
EFI_HANDLE ImageHandle;
PEFI_SYSTEM_TABLE SystemTable;
} XTBL_STATUS, *PXTBL_STATUS;
#endif /* __XTDK_BMTYPES_H */

View File

@ -16,7 +16,7 @@
#include <xtstruct.h>
/* Architecture-specific XT forward references */
#include ARCH_HEADER(xtstruct.h)
// #include ARCH_HEADER(xtstruct.h)
/* Architecture-independent XT API */
#include <xtbase.h>
@ -32,16 +32,16 @@
#include <rtltypes.h>
/* Architecture dependent XT kernel data types */
#include ARCH_HEADER(artypes.h)
#include ARCH_HEADER(hltypes.h)
// #include ARCH_HEADER(artypes.h)
// #include ARCH_HEADER(hltypes.h)
/* XT Kernel runtime routines */
#include <hlfuncs.h>
#include <rtlfuncs.h>
/* Architecture specific XT kernel routines */
#include ARCH_HEADER(arfuncs.h)
#include ARCH_HEADER(hlfuncs.h)
// #include ARCH_HEADER(arfuncs.h)
// #include ARCH_HEADER(hlfuncs.h)
/* Boot Manager specific structures */
#include <bltypes.h>

View File

@ -43,7 +43,7 @@ BlDebugPrint(IN PUINT16 Format,
}
/* Check if screen debug port is enabled and Boot Services are still available */
if((BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SCREEN) && (EfiSystemTable->BootServices != 0))
if((BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SCREEN) && (BlpStatus.BootServices == TRUE))
{
/* Format and print the string to the screen */
BlpStringPrint(BlpConsolePrintChar, Format, Arguments);
@ -54,68 +54,6 @@ BlDebugPrint(IN PUINT16 Format,
}
}
/**
* This routine initializes the serial debug console.
*
* @param PortNumber
* Supplies a port number.
*
* @param PortAddress
* Supplies an address of the COM port.
*
* @param BaudRate
* Supplies an optional port baud rate.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlpDebugInitializeComPort(IN ULONG PortNumber,
IN ULONG PortAddress,
IN ULONG BaudRate)
{
EFI_STATUS EfiStatus;
XTSTATUS Status;
/* Print debug message depending on port settings */
if(PortAddress)
{
BlConsolePrint(L"Initializing serial console at COM port address: 0x%lx\n", PortAddress);
}
else
{
BlConsolePrint(L"Initializing serial console at port COM%d\n", PortNumber);
}
/* Initialize COM port */
Status = HlInitializeComPort(&BlpSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
/* Port not found under supplied address */
if(Status == STATUS_NOT_FOUND && PortAddress)
{
/* This might be PCI(E) serial controller, try to activate I/O space access first */
EfiStatus = BlpActivateSerialIOController();
if(EfiStatus == STATUS_EFI_SUCCESS)
{
/* Try to reinitialize COM port */
BlConsolePrint(L"Enabled I/O space access for all PCI(E) serial controllers found\n");
Status = HlInitializeComPort(&BlpSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
}
}
/* Check COM port initialization status code */
if(Status != STATUS_SUCCESS)
{
/* Serial port initialization failed, mark as not ready */
return STATUS_EFI_NOT_READY;
}
/* Return success */
return STATUS_EFI_SUCCESS;
}
/**
* This routine initializes the XTLDR debug console.
*
@ -125,7 +63,7 @@ BlpDebugInitializeComPort(IN ULONG PortNumber,
*/
XTCDECL
EFI_STATUS
BlpDebugInitializeConsole()
BlpInitializeDebugConsole()
{
ULONG PortAddress, PortNumber, BaudRate;
PWCHAR DebugPort, LastPort;
@ -223,7 +161,7 @@ BlpDebugInitializeConsole()
if(BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SERIAL)
{
/* Try to initialize COM port */
Status = BlpDebugInitializeComPort(PortNumber, PortAddress, BaudRate);
Status = BlpInitializeSerialPort(PortNumber, PortAddress, BaudRate);
if(Status != STATUS_EFI_SUCCESS)
{
/* Remove serial debug port, as COM port initialization failed and return */
@ -236,6 +174,68 @@ BlpDebugInitializeConsole()
return STATUS_EFI_SUCCESS;
}
/**
* This routine initializes the serial debug console.
*
* @param PortNumber
* Supplies a port number.
*
* @param PortAddress
* Supplies an address of the COM port.
*
* @param BaudRate
* Supplies an optional port baud rate.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlpInitializeSerialPort(IN ULONG PortNumber,
IN ULONG PortAddress,
IN ULONG BaudRate)
{
EFI_STATUS EfiStatus;
XTSTATUS Status;
/* Print debug message depending on port settings */
if(PortAddress)
{
BlConsolePrint(L"Initializing serial console at COM port address: 0x%lx\n", PortAddress);
}
else
{
BlConsolePrint(L"Initializing serial console at port COM%d\n", PortNumber);
}
/* Initialize COM port */
Status = HlInitializeComPort(&BlpSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
/* Port not found under supplied address */
if(Status == STATUS_NOT_FOUND && PortAddress)
{
/* This might be PCI(E) serial controller, try to activate I/O space access first */
EfiStatus = BlpActivateSerialIOController();
if(EfiStatus == STATUS_EFI_SUCCESS)
{
/* Try to reinitialize COM port */
BlConsolePrint(L"Enabled I/O space access for all PCI(E) serial controllers found\n");
Status = HlInitializeComPort(&BlpSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
}
}
/* Check COM port initialization status code */
if(Status != STATUS_SUCCESS)
{
/* Serial port initialization failed, mark as not ready */
return STATUS_EFI_NOT_READY;
}
/* Return success */
return STATUS_EFI_SUCCESS;
}
/**
* Writes a character to the serial console.
*

View File

@ -9,6 +9,41 @@
#include <xtldr.h>
/**
* Exits EFI boot services.
*
* @param MapKey
* Identifies the current memory map of the system.
*
* @return This routine returns status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlExitBootServices(IN UINT_PTR MapKey)
{
EFI_STATUS Status;
/* Attempt to exit boot services */
Status = EfiSystemTable->BootServices->ExitBootServices(BlpStatus.ImageHandle, MapKey);
if(Status != STATUS_EFI_SUCCESS)
{
/* Retry as UEFI spec says to do it twice */
Status = EfiSystemTable->BootServices->ExitBootServices(BlpStatus.ImageHandle, MapKey);
}
/* Make sure boot services were successfully exited */
if(Status == STATUS_EFI_SUCCESS)
{
/* Mark EFI Boot Services as no longer available */
BlpStatus.BootServices = FALSE;
}
/* Return EFI status code */
return Status;
}
/**
* Puts the system to sleep for the specified number of milliseconds.
*
@ -25,3 +60,23 @@ BlSleepExecution(IN ULONG_PTR Milliseconds)
{
EfiSystemTable->BootServices->Stall(Milliseconds * 1000);
}
/**
* Initializes EFI Boot Loader (XTLDR).
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
BlpInitializeEfiBootLoader()
{
/* Set current XTLDR status */
BlpStatus.BootServices = TRUE;
BlpStatus.ImageHandle = EfiImageHandle;
BlpStatus.SystemTable = EfiSystemTable;
/* Initialize console */
BlpConsoleInitialize();
}

View File

@ -10,7 +10,7 @@
/* XT Boot Loader configuration data */
XTBM_CONFIGURATION BlpConfiguration = {0};
XTBL_CONFIGURATION BlpConfiguration = {0};
/* XT Boot Loader hex table */
STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
@ -18,6 +18,9 @@ STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
/* Serial port configuration */
CPPORT BlpSerialPort;
/* XT Boot Loader status data */
XTBL_STATUS BlpStatus = {0};
/* EFI Image Handle */
EFI_HANDLE EfiImageHandle;

View File

@ -16,6 +16,10 @@
typedef VOID (BMPRINTCHAR)(IN USHORT Character);
/* XTLDR routines forward references */
XTCDECL
EFI_STATUS
BlExitBootServices(IN UINT_PTR MapKey);
XTCDECL
EFI_STATUS
BlMemoryAllocatePages(IN UINT64 Pages,
@ -87,18 +91,22 @@ VOID
BlpConsolePrintChar(IN USHORT Character);
XTCDECL
EFI_STATUS
BlpDebugInitializeComPort(IN ULONG PortNumber,
IN ULONG PortAddress,
IN ULONG BaudRate);
VOID
BlpDebugPutChar(IN USHORT Character);
XTCDECL
EFI_STATUS
BlpDebugInitializeConsole();
BlpInitializeDebugConsole();
XTCDECL
VOID
BlpDebugPutChar(IN USHORT Character);
BlpInitializeEfiBootLoader();
XTCDECL
EFI_STATUS
BlpInitializeSerialPort(IN ULONG PortNumber,
IN ULONG PortAddress,
IN ULONG BaudRate);
XTCDECL
VOID

View File

@ -13,7 +13,7 @@
/* XT Boot Loader configuration data */
EXTERN XTBM_CONFIGURATION BlpConfiguration;
EXTERN XTBL_CONFIGURATION BlpConfiguration;
/* XT Boot Loader hex table */
EXTERN PUINT16 BlpHexTable;
@ -21,6 +21,9 @@ EXTERN PUINT16 BlpHexTable;
/* Serial port configuration */
EXTERN CPPORT BlpSerialPort;
/* XT Boot Loader status data */
EXTERN XTBL_STATUS BlpStatus;
/* EFI Image Handle */
EXTERN EFI_HANDLE EfiImageHandle;

View File

@ -29,12 +29,8 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
{
EFI_STATUS Status;
/* Set the system table and image handle */
EfiImageHandle = ImageHandle;
EfiSystemTable = SystemTable;
/* Initialize UEFI console and early print XTLDR version */
BlpConsoleInitialize();
/* Initialize XTLDR and early print XTLDR version */
BlpInitializeEfiBootLoader();
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
/* Parse configuration options passed from UEFI shell */
@ -43,7 +39,7 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
/* Attempt to early initialize debug console */
if(DEBUG)
{
Status = BlpDebugInitializeConsole();
Status = BlpInitializeDebugConsole();
if(Status != STATUS_EFI_SUCCESS)
{
/* Initialization failed, notify user on stdout */