summaryrefslogtreecommitdiff
path: root/kernel/src/init
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/init')
-rw-r--r--kernel/src/init/earlyprintk.rs46
-rw-r--r--kernel/src/init/int.rs9
-rw-r--r--kernel/src/init/int/idt.rs14
3 files changed, 34 insertions, 35 deletions
diff --git a/kernel/src/init/earlyprintk.rs b/kernel/src/init/earlyprintk.rs
index 088a4db..ae26a2f 100644
--- a/kernel/src/init/earlyprintk.rs
+++ b/kernel/src/init/earlyprintk.rs
@@ -3,35 +3,29 @@ use spin::{lazylock::LazyLock, mutex::Mutex};
use crate::io::output::serial::uart_16550::Uart16550;
// TODO: use linkme instead
-pub static EARLY_PRINTK_SERIAL: LazyLock<Option<Mutex<Uart16550>>> = LazyLock::new(|| {
- match unsafe { Uart16550::init([Some(Default::default()), None, None, None]) } {
+pub static EARLY_PRINTK_SERIAL: LazyLock<Option<Mutex<Uart16550>>> = LazyLock::new(
+ || match unsafe { Uart16550::init([Some(Default::default()), None, None, None]) } {
Ok(o) => Some(Mutex::new(o)),
Err(_) => None,
- }
-});
+ },
+);
-#[macro_export]
// TODO: configurable via option or arguments
// or use a system similar to the drivers(`linkme`)
-macro_rules! printk {
- ($($arg:tt)*) => ({
- use ::core::fmt::Write;
- match &*$crate::init::earlyprintk::EARLY_PRINTK_SERIAL {
- // TODO: elim the unwrap
- Some(m) => write!(m.lock().coms[0].as_mut().unwrap(), $($arg)*),
- // TODO: if needed find a way to return an error here, but for now just ignore it
- None => Ok(()),
- }
- });
-}
+pub macro printk($($arg:tt)*) {{
+ use ::core::fmt::Write;
+ match &*$crate::init::earlyprintk::EARLY_PRINTK_SERIAL {
+ // TODO: elim the unwrap
+ Some(m) => write!(m.lock().coms[0].as_mut().unwrap(), $($arg)*),
+ // TODO: if needed find a way to return an error here, but for now just ignore it
+ None => Ok(()),
+ }
+}}
-#[macro_export]
-macro_rules! printlnk {
- ($($arg:tt)*) => ({
- use ::core::fmt::Write;
- match &*$crate::init::earlyprintk::EARLY_PRINTK_SERIAL {
- Some(m) => writeln!(m.lock().coms[0].as_mut().unwrap(), $($arg)*),
- None => Ok(()),
- }
- });
-}
+pub macro printlnk($($arg:tt)*) {{
+ use ::core::fmt::Write;
+ match &*$crate::init::earlyprintk::EARLY_PRINTK_SERIAL {
+ Some(m) => writeln!(m.lock().coms[0].as_mut().unwrap(), $($arg)*),
+ None => Ok(()),
+ }
+}}
diff --git a/kernel/src/init/int.rs b/kernel/src/init/int.rs
index 59f1e20..97a96a7 100644
--- a/kernel/src/init/int.rs
+++ b/kernel/src/init/int.rs
@@ -1,6 +1,7 @@
-use spin::LazyLock;
-use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
-
-use crate::printlnk;
+use crate::init::int::idt::IDT;
pub mod idt;
+
+pub fn init() {
+ IDT.load();
+}
diff --git a/kernel/src/init/int/idt.rs b/kernel/src/init/int/idt.rs
index 89228cf..80d42f8 100644
--- a/kernel/src/init/int/idt.rs
+++ b/kernel/src/init/int/idt.rs
@@ -1,3 +1,8 @@
+use spin::LazyLock;
+use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
+
+use crate::init::earlyprintk::printlnk;
+
pub static IDT: LazyLock<InterruptDescriptorTable> = LazyLock::new(
|| {
let mut idt = InterruptDescriptorTable::new();
@@ -7,14 +12,13 @@ pub static IDT: LazyLock<InterruptDescriptorTable> = LazyLock::new(
},
);
-extern "x86-interrupt" fn double_fault_handler(stack_frame: InterruptStackFrame, error_code: u64) -> ! {
+extern "x86-interrupt" fn double_fault_handler(
+ stack_frame: InterruptStackFrame,
+ error_code: u64,
+) -> ! {
panic!("EXCEPTION: DOUBLE FAULT\n{stack_frame:#?}\nERROR CODE:{error_code}");
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
_ = printlnk!("EXCEPTION: BREAKPOINT\n{stack_frame:#?}");
}
-
-pub fn init() {
- IDT.load();
-}