set up debugging
This commit is contained in:
parent
b4623a51a9
commit
3c7e7f59a6
7 changed files with 67 additions and 22 deletions
5
debug.sh
Normal file
5
debug.sh
Normal 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
|
|
@ -1,14 +1,18 @@
|
|||
use core::fmt::{self, Write};
|
||||
|
||||
use crate::uart::uart_init;
|
||||
use crate::{spinlock::SpinLock, uart::UART};
|
||||
|
||||
/// A wrapper around the console
|
||||
pub struct Console {}
|
||||
pub struct Console {
|
||||
lock: SpinLock,
|
||||
uart: UART,
|
||||
}
|
||||
|
||||
impl Console {
|
||||
pub fn init() -> Self {
|
||||
uart_init();
|
||||
Console {}
|
||||
let lock = SpinLock::init("console");
|
||||
let uart = UART::init();
|
||||
Console { lock, uart }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,13 +14,14 @@ mod console;
|
|||
mod io;
|
||||
mod memory_layout;
|
||||
mod panic;
|
||||
mod spinlock;
|
||||
mod uart;
|
||||
|
||||
global_asm!(include_str!("start.s"));
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() {
|
||||
// let mut console = Console::init();
|
||||
let mut console = Console::init();
|
||||
// let _ = writeln!(console, "eos0 is booting...");
|
||||
|
||||
let out_str = b"AArch64 Bare Metal";
|
||||
|
|
18
kernel/src/spinlock.rs
Normal file
18
kernel/src/spinlock.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,28 +2,39 @@
|
|||
|
||||
use crate::memory_layout::UART0;
|
||||
|
||||
/// http://byterunner.com/16550.html
|
||||
enum Register {}
|
||||
/// The UART Interface
|
||||
pub struct UART {}
|
||||
|
||||
impl Register {
|
||||
fn offset(&self) -> u64 {
|
||||
todo!()
|
||||
impl UART {
|
||||
/// Most of this is just a port from xv6 right now, I have no idea why any of this works
|
||||
pub fn init() -> Self {
|
||||
unsafe {
|
||||
UART::write_register(WriteRegister::IER, 0x00);
|
||||
}
|
||||
UART {}
|
||||
}
|
||||
|
||||
/// the UART control registers are memory-mapped
|
||||
/// at address UART0. this macro returns the
|
||||
/// address of one of the registers
|
||||
#[inline]
|
||||
fn register(reg: Register) -> *mut u8 {
|
||||
// (UART0 + reg.offset()) as *mut u8
|
||||
UART0
|
||||
pub unsafe fn write_register(reg: WriteRegister, val: u8) {
|
||||
*reg.as_mut_ptr() = val;
|
||||
}
|
||||
|
||||
pub unsafe fn put_char(&self) {}
|
||||
}
|
||||
|
||||
/// <http://byterunner.com/16550.html>
|
||||
pub enum ReadRegister {}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum WriteRegister {
|
||||
IER = 1,
|
||||
}
|
||||
|
||||
impl WriteRegister {
|
||||
pub fn as_mut_ptr(&self) -> *mut u8 {
|
||||
unsafe { UART0.offset(*self as isize) }
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_register() {}
|
||||
|
||||
#[inline]
|
||||
fn write_register() {}
|
||||
|
||||
pub fn uart_init() {}
|
||||
|
|
2
lldb-init
Normal file
2
lldb-init
Normal file
|
@ -0,0 +1,2 @@
|
|||
target create target/aarch64-unknown-none/debug/kernel
|
||||
gdb-remote 1234
|
4
run.sh
4
run.sh
|
@ -1,7 +1,11 @@
|
|||
set -euo pipefail
|
||||
cargo xbuild --target=aarch64-unknown-none.json
|
||||
|
||||
printf "Running with qemu...\n"
|
||||
set -x
|
||||
exec qemu-system-aarch64 \
|
||||
-machine virt \
|
||||
-s -S \
|
||||
-m 1024M \
|
||||
-cpu cortex-a53 \
|
||||
-nographic \
|
||||
|
|
Loading…
Reference in a new issue