Prepare for higher half - map entire lower 4 GB
This commit is contained in:
parent
8ddddcec9f
commit
0693540a5b
2
Makefile
2
Makefile
|
@ -38,7 +38,7 @@ build/libkernel.a: build/libcore.rlib build/liballoc.rlib build/libcollections.r
|
|||
RUSTC="./rustc.sh" cargo rustc --target $(ARCH)-unknown-none.json -- -C soft-float -o $@
|
||||
|
||||
build/kernel.bin: build/libkernel.a
|
||||
ld -m elf_$(ARCH) --gc-sections -z max-page-size=0x1000 -T bootloader/x86/kernel.ld -o $@ $<
|
||||
ld --gc-sections -z max-page-size=0x1000 -T bootloader/x86/kernel.ld -o $@ $<
|
||||
|
||||
build/kernel.list: build/kernel.bin
|
||||
objdump -C -M intel -D $< > $@
|
||||
|
|
|
@ -43,7 +43,7 @@ pub unsafe fn init(stack_start: usize, stack_end: usize) -> ActivePageTable {
|
|||
|
||||
let mut active_table = ActivePageTable::new();
|
||||
|
||||
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(0x80000000)));
|
||||
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(0x8_0000_0000)));
|
||||
|
||||
let mut new_table = {
|
||||
let frame = allocate_frame().expect("no more frames");
|
||||
|
@ -85,7 +85,7 @@ pub unsafe fn init(stack_start: usize, stack_end: usize) -> ActivePageTable {
|
|||
pub unsafe fn init_ap(stack_start: usize, stack_end: usize, bsp_page_table: usize) -> ActivePageTable {
|
||||
let mut active_table = ActivePageTable::new();
|
||||
|
||||
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(0x80000000)));
|
||||
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(0x8_0000_0000)));
|
||||
|
||||
let mut new_table = {
|
||||
let frame = Frame::containing_address(PhysicalAddress::new(bsp_page_table));
|
||||
|
|
|
@ -1,31 +1,38 @@
|
|||
ENTRY(kstart)
|
||||
OUTPUT_FORMAT(elf64-x86-64)
|
||||
|
||||
KERNEL_OFFSET = 0;
|
||||
|
||||
SECTIONS {
|
||||
kernel_base = 0x101000;
|
||||
. = kernel_base;
|
||||
. = 0x100000;
|
||||
|
||||
.text : AT(ADDR(.text) - kernel_base) {
|
||||
. += SIZEOF_HEADERS;
|
||||
. = ALIGN(4096);
|
||||
|
||||
. += KERNEL_OFFSET;
|
||||
|
||||
.text : AT(ADDR(.text) - KERNEL_OFFSET) {
|
||||
__text_start = .;
|
||||
*(.text*)
|
||||
. = ALIGN(4096);
|
||||
__text_end = .;
|
||||
}
|
||||
|
||||
.rodata : AT(ADDR(.rodata) - kernel_base) {
|
||||
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) {
|
||||
__rodata_start = .;
|
||||
*(.rodata*)
|
||||
. = ALIGN(4096);
|
||||
__rodata_end = .;
|
||||
}
|
||||
|
||||
.data : AT(ADDR(.data) - kernel_base) {
|
||||
.data : AT(ADDR(.data) - KERNEL_OFFSET) {
|
||||
__data_start = .;
|
||||
*(.data*)
|
||||
. = ALIGN(4096);
|
||||
__data_end = .;
|
||||
}
|
||||
|
||||
.bss : AT(ADDR(.bss) - kernel_base) {
|
||||
.bss : AT(ADDR(.bss) - KERNEL_OFFSET) {
|
||||
__bss_start = .;
|
||||
*(.bss*)
|
||||
. = ALIGN(4096);
|
||||
|
@ -33,8 +40,9 @@ SECTIONS {
|
|||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.comment)
|
||||
*(.eh_frame)
|
||||
*(.rel.eh_frame)
|
||||
*(.comment*)
|
||||
*(.eh_frame*)
|
||||
*(.note*)
|
||||
*(.rel.eh_frame*)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ startup_arch:
|
|||
|
||||
xor edi, edi
|
||||
xor eax, eax
|
||||
mov ecx, 3 * 4096 / 4 ;PML4, PDP, PD / moves 4 Bytes at once
|
||||
mov ecx, 6 * 4096 / 4 ;PML4, PDP, 4 PD / moves 4 Bytes at once
|
||||
cld
|
||||
rep stosd
|
||||
|
||||
|
@ -63,12 +63,15 @@ startup_arch:
|
|||
add edi, 0x1000
|
||||
;Link last PML4 to PML4
|
||||
mov DWORD [es:edi - 8], 0x70000 | 1 << 1 | 1
|
||||
;Link first PDP to PD
|
||||
;Link first four PDP to PD
|
||||
mov DWORD [es:edi], 0x72000 | 1 << 1 | 1
|
||||
mov DWORD [es:edi + 8], 0x73000 | 1 << 1 | 1
|
||||
mov DWORD [es:edi + 16], 0x74000 | 1 << 1 | 1
|
||||
mov DWORD [es:edi + 24], 0x75000 | 1 << 1 | 1
|
||||
add edi, 0x1000
|
||||
;Link all PD's (512 per PDP, 2MB each)y
|
||||
mov ebx, 1 << 7 | 1 << 1 | 1
|
||||
mov ecx, 512
|
||||
mov ecx, 4*512
|
||||
.setpd:
|
||||
mov [es:edi], ebx
|
||||
add ebx, 0x200000
|
||||
|
@ -100,6 +103,8 @@ startup_arch:
|
|||
or ebx, 1 << 31 | 1 << 16 | 1 ;Bit 31: Paging, Bit 16: write protect kernel, Bit 0: Protected Mode
|
||||
mov cr0, ebx
|
||||
|
||||
xchg bx, bx
|
||||
|
||||
; far jump to enable Long Mode and load CS with 64 bit segment
|
||||
jmp gdt.kernel_code:long_mode
|
||||
|
||||
|
|
Loading…
Reference in a new issue