Do not create new bootloader stack as it is not needed any longer and kernel will use its own stack
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Rafal Kupiec 2023-01-03 23:04:11 +01:00
parent b22303003c
commit f19afbddb7
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
5 changed files with 7 additions and 179 deletions

View File

@ -9,50 +9,6 @@
#include <xtbl.h>
/**
* Creates and switches to a new stack.
*
* @param StackPtr
* Supplies a pointer to memory area, where the stack will be created.
*
* @param StackSize
* Specifies a size (in bytes) of the new stack.
*
* @param Callback
* Supplies a pointer to a callback function that will be executed on top of new stack.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
BlCreateStack(IN PVOID *StackPtr,
IN ULONG StackSize,
IN PVOID Callback)
{
EFI_PHYSICAL_ADDRESS Address;
PVOID StackEnd;
/* Allocate pages for new stack and calculate its end */
BlEfiMemoryAllocatePages(EFI_SIZE_TO_PAGES(StackSize), &Address);
*StackPtr = (PVOID)(UINT_PTR)Address;
StackEnd = (PUINT8)*StackPtr + (StackSize - EFI_PAGE_SIZE);
/* Create new stack and switch to it immediatelly by calling callback function */
asm volatile("mov %1, %%rax\n"
"mov %%rsp, %%rbx\n"
"mov %0, %%rsp\n"
"push %%rbp\n"
"mov %%rsp, %%rbp\n"
"push %%rbx\n"
"sub $32, %%rsp\n"
"call *%%rax\n"
:
: "m" (StackEnd), "m" (Callback)
: "rax", "rbx");
}
/**
* Builds the actual memory mapping page table and enables paging. This routine exits EFI boot services as well.
*
@ -84,7 +40,6 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
PEFI_MEMORY_MAP MemoryMap;
PLIST_ENTRY ListEntry;
EFI_STATUS Status;
PVOID Stack;
/* Allocate and zero-fill buffer for EFI memory map */
BlEfiMemoryAllocatePool(sizeof(EFI_MEMORY_MAP), (PVOID*)&MemoryMap);
@ -110,16 +65,6 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
*PtePointer = (PVOID)(UINT_PTR)Address;
RtlZeroMemory(*PtePointer, EFI_PAGE_SIZE);
/* Map the stack */
BlGetStackPointer(&Stack);
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, EFI_SIZE_TO_PAGES(KERNEL_STACK_SIZE),
LoaderOsloaderStack);
if(Status != STATUS_EFI_SUCCESS)
{
/* Mapping the stack failed */
return Status;
}
/* Map XTLDR code */
Status = BlAddVirtualMemoryMapping(MemoryMappings, ImageProtocol->ImageBase, ImageProtocol->ImageBase,
EFI_SIZE_TO_PAGES(ImageProtocol->ImageSize), LoaderFirmwareTemporary);

View File

@ -9,50 +9,6 @@
#include <xtbl.h>
/**
* Creates and switches to a new stack.
*
* @param StackPtr
* Supplies a pointer to memory area, where the stack will be created.
*
* @param StackSize
* Specifies a size (in bytes) of the new stack.
*
* @param Callback
* Supplies a pointer to a callback function that will be executed on top of new stack.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
BlCreateStack(IN PVOID *StackPtr,
IN ULONG StackSize,
IN PVOID Callback)
{
EFI_PHYSICAL_ADDRESS Address;
PVOID StackEnd;
/* Allocate pages for new stack and calculate its end */
BlEfiMemoryAllocatePages(EFI_SIZE_TO_PAGES(StackSize), &Address);
*StackPtr = (PVOID)(UINT_PTR)Address;
StackEnd = (PUINT8)*StackPtr + (StackSize - EFI_PAGE_SIZE);
/* Create new stack and switch to it immediatelly by calling callback function */
asm volatile("mov %1, %%eax\n"
"mov %%esp, %%ebx\n"
"mov %0, %%esp\n"
"push %%ebp\n"
"mov %%esp, %%ebp\n"
"push %%ebx\n"
"sub $32, %%esp\n"
"call *%%eax\n"
:
: "m" (StackEnd), "m" (Callback)
: "eax", "ebx");
}
/**
* Builds the actual memory mapping page table and enables paging. This routine exits EFI boot services as well.
*
@ -87,7 +43,6 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
PEFI_MEMORY_MAP MemoryMap;
PLIST_ENTRY ListEntry;
EFI_STATUS Status;
PVOID Stack;
UINT Index;
/* Prepare CPUID registers */
@ -196,16 +151,6 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
Address += EFI_PAGE_SIZE;
}
/* Map the stack */
BlGetStackPointer(&Stack);
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, EFI_SIZE_TO_PAGES(KERNEL_STACK_SIZE),
LoaderOsloaderStack);
if(Status != STATUS_EFI_SUCCESS)
{
/* Mapping the stack failed */
return Status;
}
/* Map XTLDR code */
Status = BlAddVirtualMemoryMapping(MemoryMappings, ImageProtocol->ImageBase, ImageProtocol->ImageBase,
EFI_SIZE_TO_PAGES(ImageProtocol->ImageSize), LoaderFirmwareTemporary);

View File

@ -43,7 +43,6 @@ typedef struct _XT_BOOT_LOADER_PROTOCOL
PBL_GET_VIRTUAL_ADDRESS GetVirtualAddress;
PBL_INIT_VIRTUAL_MEMORY InitializeVirtualMemory;
PBL_MAP_VIRTUAL_MEMORY MapVirtualMemory;
PBL_GET_STACK GetStack;
PBL_DBG_PRINT DbgPrint;
PBL_EFI_PRINT EfiPrint;
PBL_CLOSE_VOLUME CloseVolume;

View File

@ -72,12 +72,6 @@ XTCDECL
LOADER_MEMORY_TYPE
BlConvertEfiMemoryType(IN EFI_MEMORY_TYPE EfiMemoryType);
XTCDECL
VOID
BlCreateStack(IN PVOID *StackPtr,
IN ULONG StackSize,
IN PVOID Callback);
XTCDECL
VOID
BlDbgPrint(IN PUINT16 Format,
@ -137,10 +131,6 @@ XTCDECL
EFI_STATUS
BlGetMemoryMap(OUT PEFI_MEMORY_MAP MemoryMap);
XTCDECL
VOID
BlGetStackPointer(OUT PVOID *Stack);
XTCDECL
EFI_STATUS
BlGetVirtualAddress(IN PLIST_ENTRY MemoryMappings,
@ -185,10 +175,6 @@ XTCDECL
EFI_STATUS
BlRegisterXtLoaderProtocol();
XTCDECL
EFI_STATUS
BlStartNewStack();
XTCDECL
EFI_STATUS
BlStartXtLoader(IN EFI_HANDLE ImageHandle,

View File

@ -28,23 +28,6 @@ PVOID EfiLoaderStack;
CPPORT EfiSerialPort;
/**
* Gets a pointer to the stack address.
*
* @param Stack
* Supplies a pointer to the memory area where address to the current stack will be stored.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
BlGetStackPointer(OUT PVOID *Stack)
{
*Stack = EfiLoaderStack;
}
/**
* This routine loads XTLDR EFI modules.
*
@ -351,7 +334,6 @@ BlRegisterXtLoaderProtocol()
EfiLdrProtocol.GetVirtualAddress = BlGetVirtualAddress;
EfiLdrProtocol.InitializeVirtualMemory = BlInitializeVirtualMemory;
EfiLdrProtocol.MapVirtualMemory = BlMapVirtualMemory;
EfiLdrProtocol.GetStack = BlGetStackPointer;
EfiLdrProtocol.DbgPrint = BlDbgPrint;
EfiLdrProtocol.EfiPrint = BlEfiPrint;
EfiLdrProtocol.CloseVolume = BlCloseVolume;
@ -363,39 +345,6 @@ BlRegisterXtLoaderProtocol()
&EfiLdrProtocol);
}
/**
* Callback routine called right after new stack is created.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlStartNewStack()
{
EFI_STATUS Status;
/* Boot XTOS */
Status = BlLoadXtSystem();
if(Status != STATUS_EFI_SUCCESS)
{
/* Boot process failed */
BlEfiPrint(L"Failed to start XT OS (Status code: %lx)!\n", Status);
}
/* Infinite bootloader loop */
BlEfiPrint(L"System halted!");
for(;;)
{
HlClearInterruptFlag();
HlHalt();
}
/* Return success */
return STATUS_EFI_SUCCESS;
}
/**
* This routine is the entry point of the XT EFI boot loader.
*
@ -469,11 +418,15 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
/* Discover and enumerate EFI block devices */
BlEnumerateEfiBlockDevices();
/* Create new bootloader stack */
BlCreateStack(&EfiLoaderStack, KERNEL_STACK_SIZE, &BlStartNewStack);
/* Boot XTOS */
Status = BlLoadXtSystem();
if(Status != STATUS_EFI_SUCCESS)
{
/* Boot process failed */
BlEfiPrint(L"Failed to start XT OS (Status code: %lx)!\n", Status);
}
/* Infinite bootloader loop */
BlDbgPrint(L"ERROR: Unexpected exception occurred, probably did not create a new stack\n");
BlEfiPrint(L"System halted!");
for(;;)
{