KERNEL_STACK_SIZE should be expressed in bytes as the name suggests, calculate number of pages where needed

This commit is contained in:
Rafal Kupiec 2022-12-21 22:24:16 +01:00
parent dc2570ca8e
commit 6c4496f839
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
4 changed files with 15 additions and 18 deletions

View File

@ -17,6 +17,6 @@
#define KSEG0_KERNEL_BASE 0x0000000800000000 #define KSEG0_KERNEL_BASE 0x0000000800000000
/* XTOS Kernel stack size */ /* XTOS Kernel stack size */
#define KERNEL_STACK_SIZE 8 #define KERNEL_STACK_SIZE 0x8000
#endif /* __XTDK_AMD64_KETYPES_H */ #endif /* __XTDK_AMD64_KETYPES_H */

View File

@ -17,6 +17,6 @@
#define KSEG0_KERNEL_BASE 0x01800000 #define KSEG0_KERNEL_BASE 0x01800000
/* XTOS Kernel stack size */ /* XTOS Kernel stack size */
#define KERNEL_STACK_SIZE 8 #define KERNEL_STACK_SIZE 0x4000
#endif /* __XTDK_I686_KETYPES_H */ #endif /* __XTDK_I686_KETYPES_H */

View File

@ -18,9 +18,9 @@ BlCreateStack(IN PVOID *StackPtr,
PVOID StackEnd; PVOID StackEnd;
/* Allocate pages for new stack and calculate its end */ /* Allocate pages for new stack and calculate its end */
BlEfiMemoryAllocatePages(StackSize, &Address); BlEfiMemoryAllocatePages(EFI_SIZE_TO_PAGES(StackSize), &Address);
*StackPtr = (PVOID)(UINT_PTR)Address; *StackPtr = (PVOID)(UINT_PTR)Address;
StackEnd = (PUINT8)*StackPtr + (StackSize * EFI_PAGE_SIZE) - EFI_PAGE_SIZE; StackEnd = (PUINT8)*StackPtr + (StackSize - EFI_PAGE_SIZE);
/* Create new stack and switch to it immediatelly by calling callback function */ /* Create new stack and switch to it immediatelly by calling callback function */
asm volatile("mov %1, %%rax\n" asm volatile("mov %1, %%rax\n"
@ -94,8 +94,8 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
/* Map the stack */ /* Map the stack */
BlGetStackPointer(&Stack); BlGetStackPointer(&Stack);
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, KERNEL_STACK_SIZE, Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, EFI_SIZE_TO_PAGES(KERNEL_STACK_SIZE),
LoaderOsloaderStack); LoaderOsloaderStack);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Mapping the stack failed */ /* Mapping the stack failed */
@ -104,8 +104,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
/* Map XTLDR code */ /* Map XTLDR code */
Status = BlAddVirtualMemoryMapping(MemoryMappings, ImageProtocol->ImageBase, ImageProtocol->ImageBase, Status = BlAddVirtualMemoryMapping(MemoryMappings, ImageProtocol->ImageBase, ImageProtocol->ImageBase,
EFI_SIZE_TO_PAGES(ImageProtocol->ImageSize), EFI_SIZE_TO_PAGES(ImageProtocol->ImageSize), LoaderFirmwareTemporary);
LoaderFirmwareTemporary);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Mapping the boot loader code failed */ /* Mapping the boot loader code failed */
@ -132,8 +131,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
{ {
/* Map memory */ /* Map memory */
Status = BlMapVirtualMemory(MemoryMappings, (UINT_PTR)Mapping->VirtualAddress, Status = BlMapVirtualMemory(MemoryMappings, (UINT_PTR)Mapping->VirtualAddress,
(UINT_PTR)Mapping->PhysicalAddress, Mapping->NumberOfPages, (UINT_PTR)Mapping->PhysicalAddress, Mapping->NumberOfPages, FALSE, PtePointer);
FALSE, PtePointer);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Memory mapping failed */ /* Memory mapping failed */

View File

@ -18,9 +18,9 @@ BlCreateStack(IN PVOID *StackPtr,
PVOID StackEnd; PVOID StackEnd;
/* Allocate pages for new stack and calculate its end */ /* Allocate pages for new stack and calculate its end */
BlEfiMemoryAllocatePages(StackSize, &Address); BlEfiMemoryAllocatePages(EFI_SIZE_TO_PAGES(StackSize), &Address);
*StackPtr = (PVOID)(UINT_PTR)Address; *StackPtr = (PVOID)(UINT_PTR)Address;
StackEnd = (PUINT8)*StackPtr + (StackSize * EFI_PAGE_SIZE) - EFI_PAGE_SIZE; StackEnd = (PUINT8)*StackPtr + (StackSize - EFI_PAGE_SIZE);
/* Create new stack and switch to it immediatelly by calling callback function */ /* Create new stack and switch to it immediatelly by calling callback function */
asm volatile("mov %1, %%eax\n" asm volatile("mov %1, %%eax\n"
@ -200,8 +200,8 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
/* Map the stack */ /* Map the stack */
BlGetStackPointer(&Stack); BlGetStackPointer(&Stack);
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, KERNEL_STACK_SIZE, Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, EFI_SIZE_TO_PAGES(KERNEL_STACK_SIZE),
LoaderOsloaderStack); LoaderOsloaderStack);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Mapping the stack failed */ /* Mapping the stack failed */
@ -210,8 +210,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
/* Map XTLDR code */ /* Map XTLDR code */
Status = BlAddVirtualMemoryMapping(MemoryMappings, ImageProtocol->ImageBase, ImageProtocol->ImageBase, Status = BlAddVirtualMemoryMapping(MemoryMappings, ImageProtocol->ImageBase, ImageProtocol->ImageBase,
EFI_SIZE_TO_PAGES(ImageProtocol->ImageSize), EFI_SIZE_TO_PAGES(ImageProtocol->ImageSize), LoaderFirmwareTemporary);
LoaderFirmwareTemporary);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Mapping the boot loader code failed */ /* Mapping the boot loader code failed */
@ -238,8 +237,8 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
{ {
/* Map memory */ /* Map memory */
Status = BlMapVirtualMemory(MemoryMappings, (UINT_PTR)Mapping->VirtualAddress, Status = BlMapVirtualMemory(MemoryMappings, (UINT_PTR)Mapping->VirtualAddress,
(UINT_PTR)Mapping->PhysicalAddress, Mapping->NumberOfPages, (UINT_PTR)Mapping->PhysicalAddress, Mapping->NumberOfPages,
PaeExtension, PtePointer); PaeExtension, PtePointer);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Memory mapping failed */ /* Memory mapping failed */