diff --git a/framework/jinux-frame/src/arch/x86/timer/apic.rs b/framework/jinux-frame/src/arch/x86/timer/apic.rs index e5d7e04a..cf152081 100644 --- a/framework/jinux-frame/src/arch/x86/timer/apic.rs +++ b/framework/jinux-frame/src/arch/x86/timer/apic.rs @@ -1,3 +1,4 @@ +use core::sync::atomic::{AtomicBool, Ordering}; use log::info; use trapframe::TrapFrame; @@ -20,13 +21,11 @@ pub fn init() { pic::enable_temp(); super::pit::init(); - static mut IS_FINISH: bool = false; // wait until it is finish x86_64::instructions::interrupts::enable(); - unsafe { - while !IS_FINISH { - x86_64::instructions::hlt(); - } + static IS_FINISH: AtomicBool = AtomicBool::new(false); + while !IS_FINISH.load(Ordering::Acquire) { + x86_64::instructions::hlt(); } x86_64::instructions::interrupts::disable(); drop(a); @@ -36,7 +35,7 @@ pub fn init() { static mut IN_TIME: u8 = 0; static mut FIRST_TIME_COUNT: u64 = 0; unsafe { - if IS_FINISH || IN_TIME == 0 { + if IS_FINISH.load(Ordering::Acquire) || IN_TIME == 0 { // drop the first entry, since it may not be the time we want IN_TIME += 1; let apic_lock = APIC_INSTANCE.get().unwrap().lock(); @@ -63,8 +62,6 @@ pub fn init() { remain_ticks, config::TIMER_FREQ ); - unsafe { - IS_FINISH = true; - } + IS_FINISH.store(true, Ordering::Release); } } diff --git a/framework/jinux-frame/src/vm/frame_allocator.rs b/framework/jinux-frame/src/vm/frame_allocator.rs index c16cae0e..e631a09f 100644 --- a/framework/jinux-frame/src/vm/frame_allocator.rs +++ b/framework/jinux-frame/src/vm/frame_allocator.rs @@ -63,7 +63,7 @@ pub(crate) fn init(regions: &Vec) { if region.typ() == MemoryRegionType::Usable { // Make the memory region page-aligned let start = region.base().align_up(PAGE_SIZE) / PAGE_SIZE; - let end = (start + region.len()).align_down(PAGE_SIZE) / PAGE_SIZE; + let end = (region.base() + region.len()).align_down(PAGE_SIZE) / PAGE_SIZE; allocator.add_frame(start, end); info!( "Found usable region, start:{:x}, end:{:x}",