Prepare for higher half

This commit is contained in:
Jeremy Soller 2016-09-09 18:31:48 -06:00
parent 59327eb1b2
commit 729c7fd004
3 changed files with 10 additions and 2 deletions

View file

@ -1,6 +1,7 @@
ENTRY(kstart) ENTRY(kstart)
OUTPUT_FORMAT(elf64-x86-64) OUTPUT_FORMAT(elf64-x86-64)
/* KERNEL_OFFSET = 0xfffffe8000100000; */
KERNEL_OFFSET = 0x100000; KERNEL_OFFSET = 0x100000;
SECTIONS { SECTIONS {

View file

@ -21,6 +21,9 @@ pub const ENTRY_COUNT: usize = 512;
/// Size of pages /// Size of pages
pub const PAGE_SIZE: usize = 4096; pub const PAGE_SIZE: usize = 4096;
/// Offset of kernel from physical
pub const KERNEL_OFFSET: usize = 0xfffffe8000000000;
/// Initialize paging /// Initialize paging
pub unsafe fn init(stack_start: usize, stack_end: usize) -> ActivePageTable { pub unsafe fn init(stack_start: usize, stack_end: usize) -> ActivePageTable {
extern { extern {
@ -66,7 +69,10 @@ pub unsafe fn init(stack_start: usize, stack_end: usize) -> ActivePageTable {
let start_frame = Frame::containing_address(PhysicalAddress::new(start)); let start_frame = Frame::containing_address(PhysicalAddress::new(start));
let end_frame = Frame::containing_address(PhysicalAddress::new(end - 1)); let end_frame = Frame::containing_address(PhysicalAddress::new(end - 1));
for frame in Frame::range_inclusive(start_frame, end_frame) { for frame in Frame::range_inclusive(start_frame, end_frame) {
mapper.identity_map(frame, flags); mapper.identity_map(frame.clone(), flags);
let page = Page::containing_address(VirtualAddress::new(frame.start_address().get() + KERNEL_OFFSET));
mapper.map_to(page, frame, flags);
} }
} }
}; };

View file

@ -58,8 +58,9 @@ startup_arch:
rep stosd rep stosd
xor edi, edi xor edi, edi
;Link first PML4 to PDP ;Link first PML4 and third to last PML4 to PDP
mov DWORD [es:edi], 0x71000 | 1 << 1 | 1 mov DWORD [es:edi], 0x71000 | 1 << 1 | 1
mov DWORD [es:edi + 509*8], 0x71000 | 1 << 1 | 1
add edi, 0x1000 add edi, 0x1000
;Link last PML4 to PML4 ;Link last PML4 to PML4
mov DWORD [es:edi - 8], 0x70000 | 1 << 1 | 1 mov DWORD [es:edi - 8], 0x70000 | 1 << 1 | 1