Set page table of AP to BSP, to allow mapping of heap to be shared

This commit is contained in:
Jeremy Soller 2016-08-17 19:06:33 -06:00
parent 48741e3b99
commit 26c86f8242
2 changed files with 39 additions and 6 deletions

View file

@ -81,6 +81,37 @@ pub unsafe fn init(stack_start: usize, stack_end: usize) -> ActivePageTable {
active_table
}
/// Initialize paging for AP
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 new_table = {
let frame = Frame::containing_address(PhysicalAddress::new(bsp_page_table));
InactivePageTable {
p4_frame: frame
}
};
active_table.with(&mut new_table, &mut temporary_page, |mapper| {
let mut remap = |start: usize, end: usize, flags: EntryFlags| {
let start_frame = Frame::containing_address(PhysicalAddress::new(start));
let end_frame = Frame::containing_address(PhysicalAddress::new(end - 1));
for frame in Frame::range_inclusive(start_frame, end_frame) {
mapper.identity_map(frame, flags);
}
};
// Remap stack writable, no execute
remap(stack_start, stack_end, PRESENT | WRITABLE | NO_EXECUTE);
});
active_table.switch(new_table);
active_table
}
pub struct ActivePageTable {
mapper: Mapper,
}

View file

@ -3,7 +3,8 @@
/// It must create the IDT with the correct entries, those entries are
/// defined in other files inside of the `arch` module
use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use x86::controlregs;
use acpi;
use allocator::{HEAP_START, HEAP_SIZE};
@ -19,6 +20,7 @@ static BSS_TEST_ZERO: usize = 0;
static BSS_TEST_NONZERO: usize = 0xFFFFFFFFFFFFFFFF;
static BSP_READY: AtomicBool = ATOMIC_BOOL_INIT;
static BSP_PAGE_TABLE: AtomicUsize = ATOMIC_USIZE_INIT;
extern {
/// Kernel main function
@ -68,7 +70,9 @@ pub unsafe extern fn kstart() -> ! {
// Initialize paging
let mut active_table = paging::init(stack_start, stack_end);
// Read ACPI tables
BSP_PAGE_TABLE.store(controlregs::cr3() as usize, Ordering::SeqCst);
// Read ACPI tables, starts APs
acpi::init(&mut active_table);
// Map heap
@ -96,9 +100,7 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
// Initialize paging
//let mut active_table =
paging::init(stack_start, stack_end);
// TODO: Use heap from master, ensuring consistency
paging::init_ap(stack_start, stack_end, BSP_PAGE_TABLE.load(Ordering::SeqCst));
}
while ! BSP_READY.load(Ordering::SeqCst) {