diff --git a/sortix/kernel.cpp b/sortix/kernel.cpp index ecee8f6f..95914283 100644 --- a/sortix/kernel.cpp +++ b/sortix/kernel.cpp @@ -56,8 +56,8 @@ using namespace Maxsi; void* RunApplication(void* Parameter); +// Keep the stack size aligned with $CPU/base.s extern "C" { size_t stack[64*1024] = {0}; } -extern "C" { size_t stackend = 0; } namespace Sortix { diff --git a/sortix/x64/base.s b/sortix/x64/base.s index 18fe106e..ab401ac3 100644 --- a/sortix/x64/base.s +++ b/sortix/x64/base.s @@ -41,7 +41,8 @@ _beginkernel: movw $0x758, 0xB83F8 # Initialize the stack pointer. - movq $stackend, %rsp + movq $stack, %rsp + addq $65536, %rsp # 64 KiB, see kernel.cpp # Reset EFLAGS. # pushl $0 diff --git a/sortix/x86-family/memorymanagement.cpp b/sortix/x86-family/memorymanagement.cpp index 07140deb..414c5d0b 100644 --- a/sortix/x86-family/memorymanagement.cpp +++ b/sortix/x86-family/memorymanagement.cpp @@ -291,6 +291,12 @@ namespace Sortix addr_t SwitchAddressSpace(addr_t addrspace) { + if ( currentdir != Page::AlignDown(currentdir) ) + { + PanicF("Attempted to switch to address space 0x%zx, but it " + "wasn't page aligned!", currentdir); + } + // Don't switch if we are already there. if ( addrspace == currentdir ) { return currentdir; } diff --git a/sortix/x86/base.s b/sortix/x86/base.s index 509cfa71..c02c11b3 100644 --- a/sortix/x86/base.s +++ b/sortix/x86/base.s @@ -31,8 +31,9 @@ .type _beginkernel, @function beginkernel: _beginkernel: - # Initialize the stack pointer. - mov $stackend, %esp + # Initialize the stack pointer. The magic value is from kernel.cpp. + movl $stack, %esp + addl $65536, %esp # 64 KiB, see kernel.cpp # Reset EFLAGS. # pushl $0