From 4499d611e1c1e1506b6ddece4f1354ee5561a8ff Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 22 Feb 2024 22:08:15 -0600 Subject: [PATCH] wtf lol --- kernel/src/console.rs | 16 +++++++++++++++- kernel/src/io.rs | 1 + kernel/src/macros.rs | 1 + kernel/src/main.rs | 22 ++++++++++++++-------- kernel/src/panic.rs | 2 +- kernel/src/uart.rs | 8 ++++---- run.sh | 5 ++++- rustfmt.toml | 2 ++ 8 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 kernel/src/io.rs create mode 100644 kernel/src/macros.rs create mode 100644 rustfmt.toml diff --git a/kernel/src/console.rs b/kernel/src/console.rs index 5ae8740..64912a1 100644 --- a/kernel/src/console.rs +++ b/kernel/src/console.rs @@ -1,5 +1,19 @@ +use core::fmt::{self, Write}; + use crate::uart::uart_init; -pub fn console_init() { +/// A wrapper around the console +pub struct Console {} + +impl Console { + pub fn init() -> Self { uart_init(); + Console {} + } +} + +impl Write for Console { + fn write_str(&mut self, s: &str) -> fmt::Result { + todo!() + } } diff --git a/kernel/src/io.rs b/kernel/src/io.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/kernel/src/io.rs @@ -0,0 +1 @@ + diff --git a/kernel/src/macros.rs b/kernel/src/macros.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/kernel/src/macros.rs @@ -0,0 +1 @@ + diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 3ed6d7b..aca4640 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -1,11 +1,16 @@ #![no_std] #![no_main] +use core::fmt::Write; use core::{arch::global_asm, ptr}; -use crate::console::console_init; +use crate::console::Console; + +#[macro_use] +mod macros; mod console; +mod io; mod memory_layout; mod panic; mod uart; @@ -14,13 +19,14 @@ global_asm!(include_str!("start.s")); #[no_mangle] pub extern "C" fn not_main() { - console_init(); + let mut console = Console::init(); + let _ = writeln!(console, "eos0 is booting..."); - const UART0: *mut u8 = 0x0900_0000 as *mut u8; - let out_str = b"AArch64 Bare Metal"; - for byte in out_str { - unsafe { - ptr::write_volatile(UART0, *byte); - } + const UART0: *mut u8 = 0x0900_0000 as *mut u8; + let out_str = b"AArch64 Bare Metal"; + for byte in out_str { + unsafe { + ptr::write_volatile(UART0, *byte); } + } } diff --git a/kernel/src/panic.rs b/kernel/src/panic.rs index 739f039..9d2cceb 100644 --- a/kernel/src/panic.rs +++ b/kernel/src/panic.rs @@ -2,5 +2,5 @@ use core::panic::PanicInfo; #[panic_handler] fn on_panic(_info: &PanicInfo) -> ! { - loop {} + loop {} } diff --git a/kernel/src/uart.rs b/kernel/src/uart.rs index 67a8de7..6f756fe 100644 --- a/kernel/src/uart.rs +++ b/kernel/src/uart.rs @@ -4,9 +4,9 @@ use crate::memory_layout::UART0; enum Register {} impl Register { - fn offset(&self) -> u64 { - todo!() - } + fn offset(&self) -> u64 { + todo!() + } } /// the UART control registers are memory-mapped @@ -14,7 +14,7 @@ impl Register { /// address of one of the registers #[inline] fn register(reg: Register) -> *mut u8 { - (UART0 + reg.offset()) as *mut u8 + (UART0 + reg.offset()) as *mut u8 } #[inline] diff --git a/run.sh b/run.sh index 4191a50..26df59f 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,7 @@ -exec qemu-system-aarch64 -machine virt \ +set -euo pipefail +cargo build +exec qemu-system-aarch64 \ + -machine virt \ -m 1024M \ -cpu cortex-a53 \ -nographic \ diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..205c72c --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +tab_spaces = 2 +max_width = 80