Critical section macro

This commit is contained in:
River 2025-05-26 00:07:44 -04:00
parent f569497776
commit 1bd0c60b93
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
4 changed files with 21 additions and 20 deletions

View File

@ -2,10 +2,8 @@ use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable};
use lazy_static::lazy_static;
use super::asm::*;
use crate::log::{LOGGER, LogLevel};
use crate::{format, log_trace};
use crate::{critical_section, format, log_trace};
lazy_static! {
pub static ref GDT: GlobalDescriptorTable = {
@ -15,16 +13,13 @@ lazy_static! {
};
}
#[allow(dead_code)]
pub fn setup_gdt() {
unsafe {
interrupt_disable();
}
GDT.load();
log_trace!(
"GDT: Setting up global descriptor table at 0x{:x}",
core::ptr::addr_of!(GDT) as usize
);
unsafe {
interrupt_enable();
}
critical_section!({
GDT.load();
log_trace!(
"GDT: Setting up global descriptor table at 0x{:x}",
core::ptr::addr_of!(GDT) as usize
);
});
}

View File

@ -4,8 +4,6 @@
use lazy_static::lazy_static;
use x86_64::structures::idt::*;
use crate::log_error;
use crate::log::*;
use crate::format;
lazy_static! {
@ -17,5 +15,5 @@ lazy_static! {
}
extern "x86-interrupt" fn double_fault(info: InterruptStackFrame, _: u64) -> ! {
crate::interrupt::double_fault(&format!("{:#?}", info));
crate::interrupt::double_fault(&format!("{info:#?}"));
}

View File

@ -16,10 +16,9 @@ mod log;
mod memory;
mod panic;
mod process;
#[macro_use]
mod util;
#[cfg(target_arch = "x86_64")]
use arch::x86_64::gdt;
use arch::x86_64::interrupts::IDT;
#[cfg(target_arch = "x86_64")]
use arch::x86_64::serial::Serialport;

View File

@ -0,0 +1,9 @@
#[macro_export]
macro_rules! critical_section {
($b:block) => {
unsafe { $crate::arch::asm::interrupt_disable(); }
$b
unsafe { $crate::arch::asm::interrupt_enable(); }
};
}