diff --git a/sortix/Makefile b/sortix/Makefile index d2079ef6..0d857f91 100644 --- a/sortix/Makefile +++ b/sortix/Makefile @@ -102,17 +102,11 @@ sortix-x86-js.tmp: $(OBJS) # x64 compilation x64/boot.o: x64/boot.s - as -32 $< -o $@ + as -64 $< -o $@ sortix-x64.tmp: $(OBJS) x64/boot.o - ld -N -melf_x86_64 -Ttext 110000 -o sortix-x64-internal.out $(OBJS) - objcopy -O binary sortix-x64-internal.out sortix-x64-internal.tmp - objcopy --add-section kernel64=sortix-x64-internal.tmp \ - --set-section-flag kernel64=alloc,data,load,contents \ - $(CPU)/boot.o - ld -melf_i386 -Ttext 100000 $(CPU)/boot.o -o $@ - # move section to 0x11000 - objcopy --change-section-address kernel64=1114112 $@ + ld -N -melf_x86_64 -Ttext 100000 -o sortix-x64-internal.out x64/boot.o $(OBJS) + objcopy sortix-x64-internal.out -O elf32-i386 sortix-x64.tmp # x86 compilation diff --git a/sortix/kernel.cpp b/sortix/kernel.cpp index 4e332436..cf6bd253 100644 --- a/sortix/kernel.cpp +++ b/sortix/kernel.cpp @@ -56,8 +56,8 @@ using namespace Maxsi; void* RunApplication(void* Parameter); -extern "C" size_t stack[4096] = {0}; -extern "C" size_t stackend = 0; +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 b8af373d..18fe106e 100644 --- a/sortix/x64/base.s +++ b/sortix/x64/base.s @@ -28,12 +28,9 @@ .section .text -.text 0x110000 .type _beginkernel, @function beginkernel: _beginkernel: -start: -_start: movw $0x736, 0xB83E8 movw $0x734, 0xB83EA movw $0x753, 0xB83EE @@ -44,8 +41,7 @@ _start: movw $0x758, 0xB83F8 # Initialize the stack pointer. - # TODO: This is very hacky! - movq $0x110000, %rsp + movq $stackend, %rsp # Reset EFLAGS. # pushl $0 diff --git a/sortix/x64/boot.s b/sortix/x64/boot.s index 60fcd8e1..b7579ef5 100644 --- a/sortix/x64/boot.s +++ b/sortix/x64/boot.s @@ -77,14 +77,15 @@ multiboot_entry: movl $0x3207, (%edi) addl $0x1000, %edi - # Page-Directory - movl $0x4207, (%edi) + # Page-Directory (no user-space access here) + movl $0x4203, (%edi) # (First 2 MiB) + movl $0x5203, 8(%edi) # (Second 2 MiB) addl $0x1000, %edi # Page-Table - # Memory map the first 2 MiB. + # Memory map the first 4 MiB. movl $0x3, %ebx - movl $512, %ecx + movl $1024, %ecx SetEntry: mov %ebx, (%edi) @@ -177,6 +178,5 @@ Main: # Load the magic value. mov 0x100004, %eax - # The linker is kindly asked to put the real 64-bit kernel at 0x110000. - jmp 0x110000 + jmp beginkernel