Improvements for context switching

This commit is contained in:
Jeremy Soller 2016-08-30 16:23:51 -06:00
parent 3a232cc60f
commit d3dfff8d51
6 changed files with 68 additions and 27 deletions

View file

@ -3,6 +3,7 @@
use core::intrinsics::{atomic_load, atomic_store};
use interrupt;
use memory::{allocate_frame, Frame};
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
use start::kstart_ap;
@ -87,7 +88,7 @@ pub fn init_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) {
// Wait for trampoline ready
println!(" Waiting for AP {}", asp_local_apic.id);
while unsafe { atomic_load(ap_ready) } == 0 {
unsafe { asm!("pause" : : : : "intel", "volatile") };
interrupt::pause();
}
println!(" AP {} is ready!", asp_local_apic.id);
} else {

View file

@ -93,6 +93,7 @@ impl Context {
asm!("mov cr3, $0" : : "r"(self.cr3) : "memory" : "intel", "volatile");
*/
//CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
// Unset global lock, set inside of kernel
CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
}
}

View file

@ -26,6 +26,13 @@ pub unsafe fn halt() {
asm!("hlt" : : : : "intel", "volatile");
}
/// Pause instruction
/// Safe because it is similar to a NOP, and has no memory effects
#[inline(always)]
pub fn pause() {
unsafe { asm!("pause" : : : : "intel", "volatile"); }
}
/// Get a stack trace
//TODO: Check for stack being mapped before dereferencing
#[inline(never)]

View file

@ -11,6 +11,7 @@ use display;
use externs::memset;
use gdt;
use idt;
use interrupt;
use memory::{self, Frame};
use paging::{self, entry, Page, PhysicalAddress, VirtualAddress};
@ -92,7 +93,7 @@ pub unsafe extern fn kstart() -> ! {
}
// Initialize display
//display::init(&mut active_table);
display::init(&mut active_table);
// Reset AP variables
AP_COUNT.store(0, Ordering::SeqCst);
@ -100,7 +101,7 @@ pub unsafe extern fn kstart() -> ! {
HEAP_FRAME.store(0, Ordering::SeqCst);
// Read ACPI tables, starts APs
//acpi::init(&mut active_table);
acpi::init(&mut active_table);
// Map heap
{
@ -173,7 +174,7 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
assert_eq!(heap_start_page.p4_index(), heap_end_page.p4_index());
while HEAP_FRAME.load(Ordering::SeqCst) == 0 {
asm!("pause" : : : : "intel", "volatile");
interrupt::pause();
}
let frame = Frame::containing_address(PhysicalAddress::new(HEAP_FRAME.load(Ordering::SeqCst)));
@ -188,7 +189,7 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
let ap_number = AP_COUNT.fetch_add(1, Ordering::SeqCst);
while ! BSP_READY.load(Ordering::SeqCst) {
asm!("pause" : : : : "intel", "volatile");
interrupt::pause();
}
kmain_ap(ap_number);