From 02773ed2f47e8300917317860dd20cc94d2fd7c3 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 13 Apr 2018 14:21:09 +0800 Subject: [PATCH] Move kernel virtual address to high zone. Change asm. --- src/arch/x86_64/boot/boot.asm | 9 +++--- src/arch/x86_64/boot/linker.ld | 41 +++++++++++++++++++------ src/arch/x86_64/boot/long_mode_init.asm | 5 +-- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/arch/x86_64/boot/boot.asm b/src/arch/x86_64/boot/boot.asm index c82b6df..cc5dca3 100644 --- a/src/arch/x86_64/boot/boot.asm +++ b/src/arch/x86_64/boot/boot.asm @@ -1,7 +1,7 @@ global start extern long_mode_start -section .text +section .text32 bits 32 start: mov esp, stack_top @@ -90,10 +90,11 @@ set_up_page_tables: or eax, 0b11 ; present + writable mov [p4_table + 511 * 8], eax - ; map first P4 entry to P3 table + ; map first & 510th P4 entry to P3 table mov eax, p3_table or eax, 0b11 ; present + writable mov [p4_table], eax + mov [p4_table + 510 * 8], eax ; map first P3 entry to P2 table mov eax, p2_table @@ -148,7 +149,7 @@ error: mov byte [0xb800a], al hlt -section .bss +section .bss32 align 4096 p4_table: resb 4096 @@ -160,7 +161,7 @@ stack_bottom: resb 4096 * 4 stack_top: -section .rodata +section .rodata32 gdt64: dq 0 ; zero entry .code: equ $ - gdt64 ; new diff --git a/src/arch/x86_64/boot/linker.ld b/src/arch/x86_64/boot/linker.ld index 5b58518..86d17ec 100644 --- a/src/arch/x86_64/boot/linker.ld +++ b/src/arch/x86_64/boot/linker.ld @@ -1,52 +1,75 @@ ENTRY(start) +BOOT_OFFSET = 0x100000; +KERNEL_OFFSET = 0xffffff0000000000; + SECTIONS { - . = 1M; + . = BOOT_OFFSET; - .rodata : + .rodata32 : { /* ensure that the multiboot header is at the beginning */ KEEP(*(.multiboot_header)) + *(.rodata32 .rodata32.*) + . = ALIGN(4K); + } + .text32 : + { + *(.text32 .text32.*) + . = ALIGN(4K); + } + .bss32 : + { + *(.bss32 .bss32.*) + . = ALIGN(4K); + } + + . += KERNEL_OFFSET; + + .rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) + { *(.rodata .rodata.*) . = ALIGN(4K); } - .text : + .text : AT(ADDR(.text) - KERNEL_OFFSET) { *(.text .text.*) . = ALIGN(4K); } - .data : + .data : AT(ADDR(.data) - KERNEL_OFFSET) { *(.data .data.*) . = ALIGN(4K); } - .bss : + .bss : AT(ADDR(.bss) - KERNEL_OFFSET) { *(.bss .bss.*) . = ALIGN(4K); } - .got : + .got : AT(ADDR(.got) - KERNEL_OFFSET) { *(.got) . = ALIGN(4K); } - .got.plt : + .got.plt : AT(ADDR(.got.plt) - KERNEL_OFFSET) { *(.got.plt) . = ALIGN(4K); } - .data.rel.ro : ALIGN(4K) { + .data.rel.ro : AT(ADDR(.data.rel.ro) - KERNEL_OFFSET) + { *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*) . = ALIGN(4K); } - .gcc_except_table : ALIGN(4K) { + .gcc_except_table : AT(ADDR(.gcc_except_table) - KERNEL_OFFSET) + { *(.gcc_except_table) . = ALIGN(4K); } diff --git a/src/arch/x86_64/boot/long_mode_init.asm b/src/arch/x86_64/boot/long_mode_init.asm index 00b6b22..61b96d9 100644 --- a/src/arch/x86_64/boot/long_mode_init.asm +++ b/src/arch/x86_64/boot/long_mode_init.asm @@ -1,7 +1,7 @@ global long_mode_start extern rust_main -section .text +section .text32 bits 64 long_mode_start: ; load 0 into all data segment registers @@ -14,7 +14,8 @@ long_mode_start: ; call the rust main extern rust_main - call rust_main + mov rax, rust_main + call rax ; print `OKAY` to screen mov rax, 0x2f592f412f4b2f4f