Refactor part 6
This commit is contained in:
parent
9a3e0f69fa
commit
2b2efd0dd3
@ -10,14 +10,15 @@
|
|||||||
#define __XTDK_BMTYPES_H
|
#define __XTDK_BMTYPES_H
|
||||||
|
|
||||||
#include <xttypes.h>
|
#include <xttypes.h>
|
||||||
|
#include <xtuefi.h>
|
||||||
|
|
||||||
|
|
||||||
/* Debug port type definitions */
|
/* XTLDR Debug port type definitions */
|
||||||
#define XTBL_DEBUGPORT_SCREEN 1
|
#define XTBL_DEBUGPORT_SCREEN 1
|
||||||
#define XTBL_DEBUGPORT_SERIAL 2
|
#define XTBL_DEBUGPORT_SERIAL 2
|
||||||
|
|
||||||
/* XTLDR configuration data */
|
/* XTLDR configuration data */
|
||||||
typedef struct _XTBM_CONFIGURATION
|
typedef struct _XTBL_CONFIGURATION
|
||||||
{
|
{
|
||||||
PWCHAR Default;
|
PWCHAR Default;
|
||||||
PWCHAR Debug;
|
PWCHAR Debug;
|
||||||
@ -26,6 +27,14 @@ typedef struct _XTBM_CONFIGURATION
|
|||||||
PWCHAR Theme;
|
PWCHAR Theme;
|
||||||
ULONG Timeout;
|
ULONG Timeout;
|
||||||
PWCHAR Tune;
|
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 */
|
#endif /* __XTDK_BMTYPES_H */
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include <xtstruct.h>
|
#include <xtstruct.h>
|
||||||
|
|
||||||
/* Architecture-specific XT forward references */
|
/* Architecture-specific XT forward references */
|
||||||
#include ARCH_HEADER(xtstruct.h)
|
// #include ARCH_HEADER(xtstruct.h)
|
||||||
|
|
||||||
/* Architecture-independent XT API */
|
/* Architecture-independent XT API */
|
||||||
#include <xtbase.h>
|
#include <xtbase.h>
|
||||||
@ -32,16 +32,16 @@
|
|||||||
#include <rtltypes.h>
|
#include <rtltypes.h>
|
||||||
|
|
||||||
/* Architecture dependent XT kernel data types */
|
/* Architecture dependent XT kernel data types */
|
||||||
#include ARCH_HEADER(artypes.h)
|
// #include ARCH_HEADER(artypes.h)
|
||||||
#include ARCH_HEADER(hltypes.h)
|
// #include ARCH_HEADER(hltypes.h)
|
||||||
|
|
||||||
/* XT Kernel runtime routines */
|
/* XT Kernel runtime routines */
|
||||||
#include <hlfuncs.h>
|
#include <hlfuncs.h>
|
||||||
#include <rtlfuncs.h>
|
#include <rtlfuncs.h>
|
||||||
|
|
||||||
/* Architecture specific XT kernel routines */
|
/* Architecture specific XT kernel routines */
|
||||||
#include ARCH_HEADER(arfuncs.h)
|
// #include ARCH_HEADER(arfuncs.h)
|
||||||
#include ARCH_HEADER(hlfuncs.h)
|
// #include ARCH_HEADER(hlfuncs.h)
|
||||||
|
|
||||||
/* Boot Manager specific structures */
|
/* Boot Manager specific structures */
|
||||||
#include <bltypes.h>
|
#include <bltypes.h>
|
||||||
|
130
xtldr2/debug.c
130
xtldr2/debug.c
@ -43,7 +43,7 @@ BlDebugPrint(IN PUINT16 Format,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if screen debug port is enabled and Boot Services are still available */
|
/* 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 */
|
/* Format and print the string to the screen */
|
||||||
BlpStringPrint(BlpConsolePrintChar, Format, Arguments);
|
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.
|
* This routine initializes the XTLDR debug console.
|
||||||
*
|
*
|
||||||
@ -125,7 +63,7 @@ BlpDebugInitializeComPort(IN ULONG PortNumber,
|
|||||||
*/
|
*/
|
||||||
XTCDECL
|
XTCDECL
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BlpDebugInitializeConsole()
|
BlpInitializeDebugConsole()
|
||||||
{
|
{
|
||||||
ULONG PortAddress, PortNumber, BaudRate;
|
ULONG PortAddress, PortNumber, BaudRate;
|
||||||
PWCHAR DebugPort, LastPort;
|
PWCHAR DebugPort, LastPort;
|
||||||
@ -223,7 +161,7 @@ BlpDebugInitializeConsole()
|
|||||||
if(BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SERIAL)
|
if(BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SERIAL)
|
||||||
{
|
{
|
||||||
/* Try to initialize COM port */
|
/* Try to initialize COM port */
|
||||||
Status = BlpDebugInitializeComPort(PortNumber, PortAddress, BaudRate);
|
Status = BlpInitializeSerialPort(PortNumber, PortAddress, BaudRate);
|
||||||
if(Status != STATUS_EFI_SUCCESS)
|
if(Status != STATUS_EFI_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Remove serial debug port, as COM port initialization failed and return */
|
/* Remove serial debug port, as COM port initialization failed and return */
|
||||||
@ -236,6 +174,68 @@ BlpDebugInitializeConsole()
|
|||||||
return STATUS_EFI_SUCCESS;
|
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.
|
* Writes a character to the serial console.
|
||||||
*
|
*
|
||||||
|
@ -9,6 +9,41 @@
|
|||||||
#include <xtldr.h>
|
#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.
|
* 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);
|
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();
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* XT Boot Loader configuration data */
|
/* XT Boot Loader configuration data */
|
||||||
XTBM_CONFIGURATION BlpConfiguration = {0};
|
XTBL_CONFIGURATION BlpConfiguration = {0};
|
||||||
|
|
||||||
/* XT Boot Loader hex table */
|
/* XT Boot Loader hex table */
|
||||||
STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
|
STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
|
||||||
@ -18,6 +18,9 @@ STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
|
|||||||
/* Serial port configuration */
|
/* Serial port configuration */
|
||||||
CPPORT BlpSerialPort;
|
CPPORT BlpSerialPort;
|
||||||
|
|
||||||
|
/* XT Boot Loader status data */
|
||||||
|
XTBL_STATUS BlpStatus = {0};
|
||||||
|
|
||||||
/* EFI Image Handle */
|
/* EFI Image Handle */
|
||||||
EFI_HANDLE EfiImageHandle;
|
EFI_HANDLE EfiImageHandle;
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
typedef VOID (BMPRINTCHAR)(IN USHORT Character);
|
typedef VOID (BMPRINTCHAR)(IN USHORT Character);
|
||||||
|
|
||||||
/* XTLDR routines forward references */
|
/* XTLDR routines forward references */
|
||||||
|
XTCDECL
|
||||||
|
EFI_STATUS
|
||||||
|
BlExitBootServices(IN UINT_PTR MapKey);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BlMemoryAllocatePages(IN UINT64 Pages,
|
BlMemoryAllocatePages(IN UINT64 Pages,
|
||||||
@ -87,18 +91,22 @@ VOID
|
|||||||
BlpConsolePrintChar(IN USHORT Character);
|
BlpConsolePrintChar(IN USHORT Character);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
EFI_STATUS
|
VOID
|
||||||
BlpDebugInitializeComPort(IN ULONG PortNumber,
|
BlpDebugPutChar(IN USHORT Character);
|
||||||
IN ULONG PortAddress,
|
|
||||||
IN ULONG BaudRate);
|
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BlpDebugInitializeConsole();
|
BlpInitializeDebugConsole();
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
VOID
|
VOID
|
||||||
BlpDebugPutChar(IN USHORT Character);
|
BlpInitializeEfiBootLoader();
|
||||||
|
|
||||||
|
XTCDECL
|
||||||
|
EFI_STATUS
|
||||||
|
BlpInitializeSerialPort(IN ULONG PortNumber,
|
||||||
|
IN ULONG PortAddress,
|
||||||
|
IN ULONG BaudRate);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
VOID
|
VOID
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* XT Boot Loader configuration data */
|
/* XT Boot Loader configuration data */
|
||||||
EXTERN XTBM_CONFIGURATION BlpConfiguration;
|
EXTERN XTBL_CONFIGURATION BlpConfiguration;
|
||||||
|
|
||||||
/* XT Boot Loader hex table */
|
/* XT Boot Loader hex table */
|
||||||
EXTERN PUINT16 BlpHexTable;
|
EXTERN PUINT16 BlpHexTable;
|
||||||
@ -21,6 +21,9 @@ EXTERN PUINT16 BlpHexTable;
|
|||||||
/* Serial port configuration */
|
/* Serial port configuration */
|
||||||
EXTERN CPPORT BlpSerialPort;
|
EXTERN CPPORT BlpSerialPort;
|
||||||
|
|
||||||
|
/* XT Boot Loader status data */
|
||||||
|
EXTERN XTBL_STATUS BlpStatus;
|
||||||
|
|
||||||
/* EFI Image Handle */
|
/* EFI Image Handle */
|
||||||
EXTERN EFI_HANDLE EfiImageHandle;
|
EXTERN EFI_HANDLE EfiImageHandle;
|
||||||
|
|
||||||
|
@ -29,12 +29,8 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
|
|||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
/* Set the system table and image handle */
|
/* Initialize XTLDR and early print XTLDR version */
|
||||||
EfiImageHandle = ImageHandle;
|
BlpInitializeEfiBootLoader();
|
||||||
EfiSystemTable = SystemTable;
|
|
||||||
|
|
||||||
/* Initialize UEFI console and early print XTLDR version */
|
|
||||||
BlpConsoleInitialize();
|
|
||||||
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
|
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
|
||||||
|
|
||||||
/* Parse configuration options passed from UEFI shell */
|
/* Parse configuration options passed from UEFI shell */
|
||||||
@ -43,7 +39,7 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
|
|||||||
/* Attempt to early initialize debug console */
|
/* Attempt to early initialize debug console */
|
||||||
if(DEBUG)
|
if(DEBUG)
|
||||||
{
|
{
|
||||||
Status = BlpDebugInitializeConsole();
|
Status = BlpInitializeDebugConsole();
|
||||||
if(Status != STATUS_EFI_SUCCESS)
|
if(Status != STATUS_EFI_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Initialization failed, notify user on stdout */
|
/* Initialization failed, notify user on stdout */
|
||||||
|
Loading…
Reference in New Issue
Block a user