set up debugging

This commit is contained in:
Michael Zhang 2024-02-22 22:59:57 -06:00
parent b4623a51a9
commit 3c7e7f59a6
7 changed files with 67 additions and 22 deletions

5
debug.sh Normal file
View file

@ -0,0 +1,5 @@
# Run run.sh before this!
set -euo pipefail
exec rust-lldb \
-s lldb-init \
target/aarch64-unknown-none/debug/kernel

View file

@ -1,14 +1,18 @@
use core::fmt::{self, Write}; use core::fmt::{self, Write};
use crate::uart::uart_init; use crate::{spinlock::SpinLock, uart::UART};
/// A wrapper around the console /// A wrapper around the console
pub struct Console {} pub struct Console {
lock: SpinLock,
uart: UART,
}
impl Console { impl Console {
pub fn init() -> Self { pub fn init() -> Self {
uart_init(); let lock = SpinLock::init("console");
Console {} let uart = UART::init();
Console { lock, uart }
} }
} }

View file

@ -14,13 +14,14 @@ mod console;
mod io; mod io;
mod memory_layout; mod memory_layout;
mod panic; mod panic;
mod spinlock;
mod uart; mod uart;
global_asm!(include_str!("start.s")); global_asm!(include_str!("start.s"));
#[no_mangle] #[no_mangle]
pub extern "C" fn main() { pub extern "C" fn main() {
// let mut console = Console::init(); let mut console = Console::init();
// let _ = writeln!(console, "eos0 is booting..."); // let _ = writeln!(console, "eos0 is booting...");
let out_str = b"AArch64 Bare Metal"; let out_str = b"AArch64 Bare Metal";

18
kernel/src/spinlock.rs Normal file
View file

@ -0,0 +1,18 @@
pub struct SpinLock {
locked: bool,
/// The name of the lock, for debugging
name: [u8; 32],
}
impl SpinLock {
pub fn init(name: &'static str) -> Self {
let mut this_name = [0; 32];
this_name.copy_from_slice(&name.as_bytes()[..32]);
SpinLock {
locked: false,
name: this_name,
}
}
}

View file

@ -2,28 +2,39 @@
use crate::memory_layout::UART0; use crate::memory_layout::UART0;
/// http://byterunner.com/16550.html /// The UART Interface
enum Register {} pub struct UART {}
impl Register { impl UART {
fn offset(&self) -> u64 { /// Most of this is just a port from xv6 right now, I have no idea why any of this works
todo!() pub fn init() -> Self {
unsafe {
UART::write_register(WriteRegister::IER, 0x00);
}
UART {}
} }
#[inline]
pub unsafe fn write_register(reg: WriteRegister, val: u8) {
*reg.as_mut_ptr() = val;
}
pub unsafe fn put_char(&self) {}
} }
/// the UART control registers are memory-mapped /// <http://byterunner.com/16550.html>
/// at address UART0. this macro returns the pub enum ReadRegister {}
/// address of one of the registers
#[inline] #[derive(Copy, Clone)]
fn register(reg: Register) -> *mut u8 { pub enum WriteRegister {
// (UART0 + reg.offset()) as *mut u8 IER = 1,
UART0 }
impl WriteRegister {
pub fn as_mut_ptr(&self) -> *mut u8 {
unsafe { UART0.offset(*self as isize) }
}
} }
#[inline] #[inline]
fn read_register() {} fn read_register() {}
#[inline]
fn write_register() {}
pub fn uart_init() {}

2
lldb-init Normal file
View file

@ -0,0 +1,2 @@
target create target/aarch64-unknown-none/debug/kernel
gdb-remote 1234

4
run.sh
View file

@ -1,7 +1,11 @@
set -euo pipefail set -euo pipefail
cargo xbuild --target=aarch64-unknown-none.json cargo xbuild --target=aarch64-unknown-none.json
printf "Running with qemu...\n"
set -x
exec qemu-system-aarch64 \ exec qemu-system-aarch64 \
-machine virt \ -machine virt \
-s -S \
-m 1024M \ -m 1024M \
-cpu cortex-a53 \ -cpu cortex-a53 \
-nographic \ -nographic \