This commit is contained in:
Michael Zhang 2024-02-22 22:08:15 -06:00
parent ea550ccaa6
commit 4499d611e1
8 changed files with 42 additions and 15 deletions

View file

@ -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!()
}
}

1
kernel/src/io.rs Normal file
View file

@ -0,0 +1 @@

1
kernel/src/macros.rs Normal file
View file

@ -0,0 +1 @@

View file

@ -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);
}
}
}

View file

@ -2,5 +2,5 @@ use core::panic::PanicInfo;
#[panic_handler]
fn on_panic(_info: &PanicInfo) -> ! {
loop {}
loop {}
}

View file

@ -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]

5
run.sh
View file

@ -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 \

2
rustfmt.toml Normal file
View file

@ -0,0 +1,2 @@
tab_spaces = 2
max_width = 80