diff --git a/README.md b/README.md new file mode 100644 index 0000000..d5f8e05 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# NovaOS + +NovaOS is a expository project where I build a kernel from scratch for a Raspberry PI 3 B+. + +[Technical write-up](https://blog.leafnova.net/projects/pi3_kernel/) diff --git a/src/gpio.rs b/src/gpio.rs index d65c88e..354e85e 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -1,9 +1,9 @@ use core::ptr::{read_volatile, write_volatile}; +use core::result::Result; +use core::result::Result::Err; +use core::result::Result::Ok; -use crate::{ - timer::delay_nops, - uart::{self}, -}; +use crate::timer::delay_nops; const GPFSEL_BASE: u32 = 0x3F20_0000; const GPSET_BASE: u32 = 0x3F20_001C; diff --git a/src/interrupt.rs b/src/interrupt.rs index ef724e4..7d66b60 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs @@ -1,7 +1,4 @@ -use core::{ - arch::asm, - ptr::{read_volatile, write_volatile}, -}; +use core::ptr::{read_volatile, write_volatile}; use crate::uart::print; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a968802 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,6 @@ +#![no_std] + +pub mod gpio; +pub mod interrupt; +pub mod timer; +pub mod uart; diff --git a/src/main.rs b/src/main.rs index 10a60a7..ad9c235 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,17 +7,15 @@ use core::{ panic::PanicInfo, }; -use gpio::{ - gpio_enable_low_detect, gpio_get_state, gpio_high, gpio_low, gpio_pull_up, set_gpio_state, +use nova::{ + gpio::{ + gpio_enable_low_detect, gpio_get_state, gpio_high, gpio_low, gpio_pull_up, set_gpio_state, + GPIOState, + }, + interrupt::enable_iqr_source, + timer::{delay_nops, sleep}, + uart::{print, uart_init}, }; -use interrupt::enable_iqr_source; -use timer::{delay_nops, sleep}; -use uart::print; - -mod gpio; -mod interrupt; -mod timer; -mod uart; global_asm!(include_str!("vector.S")); @@ -28,7 +26,7 @@ extern "C" { #[panic_handler] fn panic(_panic: &PanicInfo) -> ! { loop { - uart::print("Panic\r\n"); + print("Panic\r\n"); } } @@ -46,19 +44,19 @@ pub unsafe extern "C" fn _start() { #[no_mangle] pub extern "C" fn main() -> ! { - uart::uart_init(); + uart_init(); // Set ACT Led to Outout - let _ = set_gpio_state(21, gpio::GPIOState::Output); + let _ = set_gpio_state(21, GPIOState::Output); // Set GPIO Pins to UART - let _ = set_gpio_state(14, gpio::GPIOState::Alternative0); - let _ = set_gpio_state(15, gpio::GPIOState::Alternative0); + let _ = set_gpio_state(14, GPIOState::Alternative0); + let _ = set_gpio_state(15, GPIOState::Alternative0); print_current_el_str(); // Delay so clock speed can stabilize delay_nops(50000); - uart::print("Hello World!\r\n"); + print("Hello World!\r\n"); unsafe { el2_to_el1(); @@ -69,14 +67,13 @@ pub extern "C" fn main() -> ! { #[no_mangle] pub extern "C" fn kernel_main() -> ! { - let el = get_current_el(); print_current_el_str(); sleep(500_000); // Set GPIO 21 to Input enable_iqr_source(49); //21 is on the first GPIO bank - let _ = set_gpio_state(21, gpio::GPIOState::Input); + let _ = set_gpio_state(21, GPIOState::Input); gpio_pull_up(21); gpio_enable_low_detect(21, true); diff --git a/src/vector.S b/src/vector.S index a2eb7a0..1e125a6 100644 --- a/src/vector.S +++ b/src/vector.S @@ -16,6 +16,8 @@ vector_table: ventry . ventry irq_handler // IRQ(Interrupt Request) 0x280 + ventry . + ventry . .align 4 @@ -25,26 +27,23 @@ el2_to_el1: mov x0, #(1 << 31) msr HCR_EL2, x0 - isb - // Set SPSR_EL2: return to EL1h (EL1, using SP_EL1) + // Set SPSR_EL2: return to EL1h mov x0, #(0b0101) msr SPSR_EL2, x0 - isb // Set return address to ELR_EL2 ldr x0, =kernel_main msr ELR_EL2, x0 - isb // Set SP_EL1 to stack base ldr x0, =__stack_end msr SP_EL1, x0 - isb // Set VBAR_EL1 to vector table adr x0, vector_table msr VBAR_EL1, x0 + isb // Return to EL1