Fix the bug caused by opt-level=1

This commit is contained in:
Chen Chengjun 2023-08-08 19:01:50 +08:00 committed by Tate, Hongliang Tian
parent 84155289cf
commit c321e411f6
2 changed files with 7 additions and 10 deletions

View File

@ -1,3 +1,4 @@
use core::sync::atomic::{AtomicBool, Ordering};
use log::info; use log::info;
use trapframe::TrapFrame; use trapframe::TrapFrame;
@ -20,14 +21,12 @@ pub fn init() {
pic::enable_temp(); pic::enable_temp();
super::pit::init(); super::pit::init();
static mut IS_FINISH: bool = false;
// wait until it is finish // wait until it is finish
x86_64::instructions::interrupts::enable(); x86_64::instructions::interrupts::enable();
unsafe { static IS_FINISH: AtomicBool = AtomicBool::new(false);
while !IS_FINISH { while !IS_FINISH.load(Ordering::Acquire) {
x86_64::instructions::hlt(); x86_64::instructions::hlt();
} }
}
x86_64::instructions::interrupts::disable(); x86_64::instructions::interrupts::disable();
drop(a); drop(a);
drop(handle); drop(handle);
@ -36,7 +35,7 @@ pub fn init() {
static mut IN_TIME: u8 = 0; static mut IN_TIME: u8 = 0;
static mut FIRST_TIME_COUNT: u64 = 0; static mut FIRST_TIME_COUNT: u64 = 0;
unsafe { 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 // drop the first entry, since it may not be the time we want
IN_TIME += 1; IN_TIME += 1;
let apic_lock = APIC_INSTANCE.get().unwrap().lock(); let apic_lock = APIC_INSTANCE.get().unwrap().lock();
@ -63,8 +62,6 @@ pub fn init() {
remain_ticks, remain_ticks,
config::TIMER_FREQ config::TIMER_FREQ
); );
unsafe { IS_FINISH.store(true, Ordering::Release);
IS_FINISH = true;
}
} }
} }

View File

@ -63,7 +63,7 @@ pub(crate) fn init(regions: &Vec<MemoryRegion>) {
if region.typ() == MemoryRegionType::Usable { if region.typ() == MemoryRegionType::Usable {
// Make the memory region page-aligned // Make the memory region page-aligned
let start = region.base().align_up(PAGE_SIZE) / PAGE_SIZE; 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); allocator.add_frame(start, end);
info!( info!(
"Found usable region, start:{:x}, end:{:x}", "Found usable region, start:{:x}, end:{:x}",