Move kernel virtual address to high zone. Change asm.

master
WangRunji 7 years ago
parent 96258c6a0b
commit 02773ed2f4

@ -1,7 +1,7 @@
global start global start
extern long_mode_start extern long_mode_start
section .text section .text32
bits 32 bits 32
start: start:
mov esp, stack_top mov esp, stack_top
@ -90,10 +90,11 @@ set_up_page_tables:
or eax, 0b11 ; present + writable or eax, 0b11 ; present + writable
mov [p4_table + 511 * 8], eax 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 mov eax, p3_table
or eax, 0b11 ; present + writable or eax, 0b11 ; present + writable
mov [p4_table], eax mov [p4_table], eax
mov [p4_table + 510 * 8], eax
; map first P3 entry to P2 table ; map first P3 entry to P2 table
mov eax, p2_table mov eax, p2_table
@ -148,7 +149,7 @@ error:
mov byte [0xb800a], al mov byte [0xb800a], al
hlt hlt
section .bss section .bss32
align 4096 align 4096
p4_table: p4_table:
resb 4096 resb 4096
@ -160,7 +161,7 @@ stack_bottom:
resb 4096 * 4 resb 4096 * 4
stack_top: stack_top:
section .rodata section .rodata32
gdt64: gdt64:
dq 0 ; zero entry dq 0 ; zero entry
.code: equ $ - gdt64 ; new .code: equ $ - gdt64 ; new

@ -1,52 +1,75 @@
ENTRY(start) ENTRY(start)
BOOT_OFFSET = 0x100000;
KERNEL_OFFSET = 0xffffff0000000000;
SECTIONS { SECTIONS {
. = 1M; . = BOOT_OFFSET;
.rodata : .rodata32 :
{ {
/* ensure that the multiboot header is at the beginning */ /* ensure that the multiboot header is at the beginning */
KEEP(*(.multiboot_header)) 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.*) *(.rodata .rodata.*)
. = ALIGN(4K); . = ALIGN(4K);
} }
.text : .text : AT(ADDR(.text) - KERNEL_OFFSET)
{ {
*(.text .text.*) *(.text .text.*)
. = ALIGN(4K); . = ALIGN(4K);
} }
.data : .data : AT(ADDR(.data) - KERNEL_OFFSET)
{ {
*(.data .data.*) *(.data .data.*)
. = ALIGN(4K); . = ALIGN(4K);
} }
.bss : .bss : AT(ADDR(.bss) - KERNEL_OFFSET)
{ {
*(.bss .bss.*) *(.bss .bss.*)
. = ALIGN(4K); . = ALIGN(4K);
} }
.got : .got : AT(ADDR(.got) - KERNEL_OFFSET)
{ {
*(.got) *(.got)
. = ALIGN(4K); . = ALIGN(4K);
} }
.got.plt : .got.plt : AT(ADDR(.got.plt) - KERNEL_OFFSET)
{ {
*(.got.plt) *(.got.plt)
. = ALIGN(4K); . = 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.*) *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*)
. = ALIGN(4K); . = ALIGN(4K);
} }
.gcc_except_table : ALIGN(4K) { .gcc_except_table : AT(ADDR(.gcc_except_table) - KERNEL_OFFSET)
{
*(.gcc_except_table) *(.gcc_except_table)
. = ALIGN(4K); . = ALIGN(4K);
} }

@ -1,7 +1,7 @@
global long_mode_start global long_mode_start
extern rust_main extern rust_main
section .text section .text32
bits 64 bits 64
long_mode_start: long_mode_start:
; load 0 into all data segment registers ; load 0 into all data segment registers
@ -14,7 +14,8 @@ long_mode_start:
; call the rust main ; call the rust main
extern rust_main extern rust_main
call rust_main mov rax, rust_main
call rax
; print `OKAY` to screen ; print `OKAY` to screen
mov rax, 0x2f592f412f4b2f4f mov rax, 0x2f592f412f4b2f4f

Loading…
Cancel
Save