diff --git a/xtldr/amd64/memory.c b/xtldr/amd64/memory.c index b9d946f..094e90b 100644 --- a/xtldr/amd64/memory.c +++ b/xtldr/amd64/memory.c @@ -9,50 +9,6 @@ #include -/** - * 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); diff --git a/xtldr/i686/memory.c b/xtldr/i686/memory.c index 742822b..102bf43 100644 --- a/xtldr/i686/memory.c +++ b/xtldr/i686/memory.c @@ -9,50 +9,6 @@ #include -/** - * 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); diff --git a/xtldr/includes/blproto.h b/xtldr/includes/blproto.h index 0566de2..8b82e8c 100644 --- a/xtldr/includes/blproto.h +++ b/xtldr/includes/blproto.h @@ -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; diff --git a/xtldr/includes/xtbl.h b/xtldr/includes/xtbl.h index 20c7f62..0889d35 100644 --- a/xtldr/includes/xtbl.h +++ b/xtldr/includes/xtbl.h @@ -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, diff --git a/xtldr/xtldr.c b/xtldr/xtldr.c index 11cdbcf..30bdc8e 100644 --- a/xtldr/xtldr.c +++ b/xtldr/xtldr.c @@ -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(;;) {