mirror of
https://github.com/iceHtwoO/novaOS.git
synced 2026-04-16 20:22:26 +00:00
Readme and cleanup
This commit is contained in:
5
README.md
Normal file
5
README.md
Normal file
@@ -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/)
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
use core::ptr::{read_volatile, write_volatile};
|
use core::ptr::{read_volatile, write_volatile};
|
||||||
|
use core::result::Result;
|
||||||
|
use core::result::Result::Err;
|
||||||
|
use core::result::Result::Ok;
|
||||||
|
|
||||||
use crate::{
|
use crate::timer::delay_nops;
|
||||||
timer::delay_nops,
|
|
||||||
uart::{self},
|
|
||||||
};
|
|
||||||
|
|
||||||
const GPFSEL_BASE: u32 = 0x3F20_0000;
|
const GPFSEL_BASE: u32 = 0x3F20_0000;
|
||||||
const GPSET_BASE: u32 = 0x3F20_001C;
|
const GPSET_BASE: u32 = 0x3F20_001C;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use core::{
|
use core::ptr::{read_volatile, write_volatile};
|
||||||
arch::asm,
|
|
||||||
ptr::{read_volatile, write_volatile},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::uart::print;
|
use crate::uart::print;
|
||||||
|
|
||||||
|
|||||||
6
src/lib.rs
Normal file
6
src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#![no_std]
|
||||||
|
|
||||||
|
pub mod gpio;
|
||||||
|
pub mod interrupt;
|
||||||
|
pub mod timer;
|
||||||
|
pub mod uart;
|
||||||
33
src/main.rs
33
src/main.rs
@@ -7,17 +7,15 @@ use core::{
|
|||||||
panic::PanicInfo,
|
panic::PanicInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
use gpio::{
|
use nova::{
|
||||||
gpio_enable_low_detect, gpio_get_state, gpio_high, gpio_low, gpio_pull_up, set_gpio_state,
|
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"));
|
global_asm!(include_str!("vector.S"));
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ extern "C" {
|
|||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(_panic: &PanicInfo) -> ! {
|
fn panic(_panic: &PanicInfo) -> ! {
|
||||||
loop {
|
loop {
|
||||||
uart::print("Panic\r\n");
|
print("Panic\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,19 +44,19 @@ pub unsafe extern "C" fn _start() {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn main() -> ! {
|
pub extern "C" fn main() -> ! {
|
||||||
uart::uart_init();
|
uart_init();
|
||||||
// Set ACT Led to Outout
|
// 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
|
// Set GPIO Pins to UART
|
||||||
let _ = set_gpio_state(14, gpio::GPIOState::Alternative0);
|
let _ = set_gpio_state(14, GPIOState::Alternative0);
|
||||||
let _ = set_gpio_state(15, gpio::GPIOState::Alternative0);
|
let _ = set_gpio_state(15, GPIOState::Alternative0);
|
||||||
|
|
||||||
print_current_el_str();
|
print_current_el_str();
|
||||||
|
|
||||||
// Delay so clock speed can stabilize
|
// Delay so clock speed can stabilize
|
||||||
delay_nops(50000);
|
delay_nops(50000);
|
||||||
uart::print("Hello World!\r\n");
|
print("Hello World!\r\n");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
el2_to_el1();
|
el2_to_el1();
|
||||||
@@ -69,14 +67,13 @@ pub extern "C" fn main() -> ! {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn kernel_main() -> ! {
|
pub extern "C" fn kernel_main() -> ! {
|
||||||
let el = get_current_el();
|
|
||||||
print_current_el_str();
|
print_current_el_str();
|
||||||
|
|
||||||
sleep(500_000);
|
sleep(500_000);
|
||||||
|
|
||||||
// Set GPIO 21 to Input
|
// Set GPIO 21 to Input
|
||||||
enable_iqr_source(49); //21 is on the first GPIO bank
|
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_pull_up(21);
|
||||||
gpio_enable_low_detect(21, true);
|
gpio_enable_low_detect(21, true);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ vector_table:
|
|||||||
|
|
||||||
ventry .
|
ventry .
|
||||||
ventry irq_handler // IRQ(Interrupt Request) 0x280
|
ventry irq_handler // IRQ(Interrupt Request) 0x280
|
||||||
|
ventry .
|
||||||
|
ventry .
|
||||||
|
|
||||||
|
|
||||||
.align 4
|
.align 4
|
||||||
@@ -25,26 +27,23 @@ el2_to_el1:
|
|||||||
|
|
||||||
mov x0, #(1 << 31)
|
mov x0, #(1 << 31)
|
||||||
msr HCR_EL2, x0
|
msr HCR_EL2, x0
|
||||||
isb
|
|
||||||
|
|
||||||
// Set SPSR_EL2: return to EL1h (EL1, using SP_EL1)
|
// Set SPSR_EL2: return to EL1h
|
||||||
mov x0, #(0b0101)
|
mov x0, #(0b0101)
|
||||||
msr SPSR_EL2, x0
|
msr SPSR_EL2, x0
|
||||||
isb
|
|
||||||
|
|
||||||
// Set return address to ELR_EL2
|
// Set return address to ELR_EL2
|
||||||
ldr x0, =kernel_main
|
ldr x0, =kernel_main
|
||||||
msr ELR_EL2, x0
|
msr ELR_EL2, x0
|
||||||
isb
|
|
||||||
|
|
||||||
// Set SP_EL1 to stack base
|
// Set SP_EL1 to stack base
|
||||||
ldr x0, =__stack_end
|
ldr x0, =__stack_end
|
||||||
msr SP_EL1, x0
|
msr SP_EL1, x0
|
||||||
isb
|
|
||||||
|
|
||||||
// Set VBAR_EL1 to vector table
|
// Set VBAR_EL1 to vector table
|
||||||
adr x0, vector_table
|
adr x0, vector_table
|
||||||
msr VBAR_EL1, x0
|
msr VBAR_EL1, x0
|
||||||
|
|
||||||
isb
|
isb
|
||||||
|
|
||||||
// Return to EL1
|
// Return to EL1
|
||||||
|
|||||||
Reference in New Issue
Block a user