summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-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
-rw-r--r--kernel/src/lib.rs6
-rw-r--r--kernel/src/main.rs5
-rw-r--r--kernel/src/pm/panic.rs2
6 files changed, 44 insertions, 38 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();
-}
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index 614e8cb..7fe050e 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -1,5 +1,9 @@
#![no_std]
-#![feature(array_try_from_fn, abi_x86_interrupt)]
+#![feature(
+ array_try_from_fn,
+ abi_x86_interrupt,
+ decl_macro
+)]
pub mod init;
pub mod io;
diff --git a/kernel/src/main.rs b/kernel/src/main.rs
index 6a1cae3..dbf9926 100644
--- a/kernel/src/main.rs
+++ b/kernel/src/main.rs
@@ -4,7 +4,10 @@
// extern crate alloc;
use bootloader_api::{BootInfo, entry_point};
-use kernel::{init, pm::hcf, printlnk};
+use kernel::{
+ init::{self, earlyprintk::printlnk},
+ pm::hcf,
+};
// const CONFIG: BootloaderConfig = BootloaderConfig::new_default();
diff --git a/kernel/src/pm/panic.rs b/kernel/src/pm/panic.rs
index 5c24452..0c9e3e1 100644
--- a/kernel/src/pm/panic.rs
+++ b/kernel/src/pm/panic.rs
@@ -1,6 +1,6 @@
use core::panic::PanicInfo;
-use crate::{pm::hcf, printlnk};
+use crate::{init::earlyprintk::printlnk, pm::hcf};
#[allow(dead_code)]
#[cfg_attr(