Implement BlDbgPrint() for printing debug messages to the serial console and rename loader entry point

This commit is contained in:
Rafal Kupiec 2022-08-09 22:27:15 +02:00
parent fa8fa99d6f
commit a961ac1e69
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
4 changed files with 85 additions and 8 deletions

View File

@ -4,6 +4,7 @@ PROJECT(XTLDR)
# Specify include directories # Specify include directories
include_directories( include_directories(
${EXECTOS_SOURCE_DIR}/sdk/xtdk ${EXECTOS_SOURCE_DIR}/sdk/xtdk
${EXECTOS_SOURCE_DIR}/sdk/xtklib/includes
${XTLDR_SOURCE_DIR}/includes) ${XTLDR_SOURCE_DIR}/includes)
# Specify list of source code files # Specify list of source code files
@ -16,6 +17,9 @@ list(APPEND XTLDR_SOURCE
# Add executable # Add executable
add_executable(xtldr ${XTLDR_SOURCE}) add_executable(xtldr ${XTLDR_SOURCE})
# Add linker libraries
target_link_libraries(xtldr xtklib)
# Set proper binary name and install target # Set proper binary name and install target
if(ARCH STREQUAL "i686") if(ARCH STREQUAL "i686")
set(BINARY_NAME "bootia32") set(BINARY_NAME "bootia32")
@ -26,5 +30,5 @@ set_target_properties(xtldr PROPERTIES OUTPUT_NAME ${BINARY_NAME} SUFFIX .efi)
set_install_target(xtldr efi/boot) set_install_target(xtldr efi/boot)
# Set loader entrypoint, imagebase address, ordinals and subsystem # Set loader entrypoint, imagebase address, ordinals and subsystem
set_entrypoint(xtldr "XtLoaderStartup") set_entrypoint(xtldr "BlStartXtLoader")
set_subsystem(xtldr efi_application) set_subsystem(xtldr efi_application)

View File

@ -9,6 +9,35 @@
#include <xtbl.h> #include <xtbl.h>
/**
* This routine formats the input string and prints it out to the serial console.
*
* @param Format
* The formatted string that is to be written to the output.
*
* @param ...
* Depending on the format string, this routine might expect a sequence of additional arguments.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
VOID
BlDbgPrint(IN PUINT16 Format,
IN ...)
{
VA_LIST Arguments;
/* Initialise the va_list */
VA_START(Arguments, Format);
/* Format and print the string to the serial console */
BlStringPrint(BlComPortPutChar, Format, Arguments);
/* Clean up the va_list */
VA_END(Arguments);
}
/** /**
* This routine formats the input string and prints it out to the stdout and serial console. * This routine formats the input string and prints it out to the stdout and serial console.
* *
@ -22,7 +51,7 @@
* *
* @since XT 1.0 * @since XT 1.0
* *
* @todo Check if GOP is active and use it instead of default conout protocol; duplicate output to serial console. * @todo Check if GOP is active and use it instead of default conout protocol
*/ */
VOID VOID
BlEfiPrint(IN PUINT16 Format, BlEfiPrint(IN PUINT16 Format,
@ -36,6 +65,9 @@ BlEfiPrint(IN PUINT16 Format,
/* Format and print the string to the stdout */ /* Format and print the string to the stdout */
BlStringPrint(BlConsolePutChar, Format, Arguments); BlStringPrint(BlConsolePutChar, Format, Arguments);
/* Format and print the string to the serial console */
BlStringPrint(BlComPortPutChar, Format, Arguments);
/* Clean up the va_list */ /* Clean up the va_list */
VA_END(Arguments); VA_END(Arguments);
} }

View File

@ -10,6 +10,7 @@
#define __XTLDR_XTBL_H #define __XTLDR_XTBL_H
#include <xtkmapi.h> #include <xtkmapi.h>
#include <xtklib.h>
/* EFI Image Handle */ /* EFI Image Handle */
@ -18,6 +19,12 @@ EXTERN EFI_HANDLE EfiImageHandle;
/* EFI System Table */ /* EFI System Table */
EXTERN EFI_SYSTEM_TABLE *EfiSystemTable; EXTERN EFI_SYSTEM_TABLE *EfiSystemTable;
/* Serial port configuration */
EXTERN CPPORT EfiSerialPort;
VOID
BlComPortPutChar(IN USHORT Character);
VOID VOID
BlConsoleClearScreen(); BlConsoleClearScreen();
@ -27,10 +34,18 @@ BlConsoleInitialize();
VOID VOID
BlConsolePutChar(IN USHORT Character); BlConsolePutChar(IN USHORT Character);
VOID
BlDbgPrint(IN PUINT16 Format,
IN ...);
VOID VOID
BlEfiPrint(IN PUINT16 Format, BlEfiPrint(IN PUINT16 Format,
IN ...); IN ...);
EFI_STATUS
BlStartXtLoader(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable);
VOID VOID
BlStringPrint(IN VOID PutChar(IN USHORT Character), BlStringPrint(IN VOID PutChar(IN USHORT Character),
IN PUINT16 Format, IN PUINT16 Format,
@ -66,8 +81,4 @@ BlpStringPrintUnsigned64(IN VOID PutChar(IN USHORT Character),
UINT64 UINT64
BlpStringReadPadding(IN PUINT16 *Format); BlpStringReadPadding(IN PUINT16 *Format);
EFI_STATUS
XtLoaderStartup(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable);
#endif /* __XTLDR_XTBL_H */ #endif /* __XTLDR_XTBL_H */

View File

@ -15,6 +15,31 @@ EFI_HANDLE EfiImageHandle;
/* EFI System Table */ /* EFI System Table */
PEFI_SYSTEM_TABLE EfiSystemTable; PEFI_SYSTEM_TABLE EfiSystemTable;
/* Serial port configuration */
CPPORT EfiSerialPort;
/**
* Writes a character to the serial console.
*
* @param Character
* The integer promotion of the character to be written.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
VOID
BlComPortPutChar(IN USHORT Character)
{
USHORT Buffer[2];
/* Write character to the serial console */
Buffer[0] = Character;
Buffer[1] = 0;
HlComPortPutByte(&EfiSerialPort, Buffer[0]);
}
/** /**
* This routine is the entry point of the XT EFI boot loader. * This routine is the entry point of the XT EFI boot loader.
* *
@ -27,10 +52,9 @@ PEFI_SYSTEM_TABLE EfiSystemTable;
* @return This routine returns status code. * @return This routine returns status code.
* *
* @since XT 1.0 * @since XT 1.0
*
*/ */
EFI_STATUS EFI_STATUS
XtLoaderStartup(IN EFI_HANDLE ImageHandle, BlStartXtLoader(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable) IN PEFI_SYSTEM_TABLE SystemTable)
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -39,6 +63,12 @@ XtLoaderStartup(IN EFI_HANDLE ImageHandle,
EfiImageHandle = ImageHandle; EfiImageHandle = ImageHandle;
EfiSystemTable = SystemTable; EfiSystemTable = SystemTable;
Status = HlInitializeComPort(&EfiSerialPort, 1, 0);
if(Status != STATUS_SUCCESS)
{
BlEfiPrint(L"Failed to initialize serial console");
}
/* Initialize EFI console */ /* Initialize EFI console */
Status = BlConsoleInitialize(); Status = BlConsoleInitialize();
if(Status != STATUS_EFI_SUCCESS) { if(Status != STATUS_EFI_SUCCESS) {