Skip to content

Commit

Permalink
add multi-processor control in main
Browse files Browse the repository at this point in the history
  • Loading branch information
yodalee committed May 30, 2022
1 parent 5406745 commit 6acce74
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ use crate::trap::init_harttrap;

use linked_list_allocator::LockedHeap;
use alloc::alloc::Layout;
use core::sync::atomic::{AtomicBool, Ordering};
use rv64::asm::sync_synchronize;

#[no_mangle]
pub fn main() -> ! {
static KERNEL_STARTED: AtomicBool = AtomicBool::new(false);
if get_cpuid() == 0 {
init_scheduler(); // initialize scheduler for schedule
init_cpu(); // initialize cpu struct
Expand All @@ -61,7 +64,17 @@ pub fn main() -> ! {

init_userproc(); // create first user process

println!("OS started");
sync_synchronize();
KERNEL_STARTED.swap(true, Ordering::Relaxed);
} else {
while !KERNEL_STARTED.load(Ordering::Relaxed) {
}
sync_synchronize();
println!("hart {} starting", get_cpuid());
init_page(); // initialize virtual memory
init_harttrap(); // install kernel trap vector
init_plic(); // initialize PLIC interrupt controller
init_hartplic(); // ask PLIC for device interrupt
}

let scheduler = get_scheduler();
Expand Down

0 comments on commit 6acce74

Please sign in to comment.