Hacky debug output

This commit is contained in:
Mark Poliakov 2021-09-23 13:43:43 +03:00
parent d602398062
commit 98bf52ad06
10 changed files with 121 additions and 21 deletions

7
Cargo.lock generated
View File

@ -9,6 +9,12 @@ dependencies = [
"error",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cortex-a"
version = "6.1.0"
@ -26,6 +32,7 @@ version = "0.1.0"
name = "kernel"
version = "0.1.0"
dependencies = [
"cfg-if",
"cortex-a",
]

View File

@ -1,6 +1,6 @@
ENTRY(_entry);
KERNEL_OFFSET = 0xFFFFFF8000000000;
KERNEL_OFFSET = 0; /* 0xFFFFFF8000000000; */
SECTIONS {
. = 0x40080000 + KERNEL_OFFSET;
@ -8,7 +8,7 @@ SECTIONS {
PROVIDE(__kernel_start = .);
.text : AT(. - KERNEL_OFFSET) {
*(.text.boot)
*(.text._entry)
*(.text*)
}
@ -24,11 +24,11 @@ SECTIONS {
. = ALIGN(4K);
.bss : AT(. - KERNEL_OFFSET) {
PROVIDE(__bss_start_phys = . - KERNEL_OFFSET);
PROVIDE(__bss_start = .);
*(COMMON)
*(.bss*)
. = ALIGN(4K);
PROVIDE(__bss_end_phys = . - KERNEL_OFFSET);
PROVIDE(__bss_end = .);
}
PROVIDE(__kernel_end = .);

View File

@ -5,8 +5,16 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "kernel"
test = false
[dependencies]
cfg-if = "1.x.x"
[target.'cfg(target_arch = "aarch64")'.dependencies]
cortex-a = { version = "6.x.x" }
[features]
mach_qemu = []
default = ["mach_qemu"]

View File

@ -0,0 +1,37 @@
.macro ADR_REL reg, sym
adrp \reg, \sym
add \reg, \reg, #:lo12:\sym
.endm
.section .text._entry
.global _entry
_entry:
mrs x1, mpidr_el1
and x1, x1, #3
beq 2f
1:
wfe
b 1b
2:
// Zero .bss
ADR_REL x0, __bss_start
ADR_REL x1, __bss_end
1:
cmp x0, x1
beq 2f
stp xzr, xzr, [x0], #16
b 1b
2:
ADR_REL x0, bsp_stack_top
mov sp, x0
b __aa64_bsp_main
.section .bss
.p2align 4
bsp_stack_bottom:
.skip 16384
bsp_stack_top:

View File

@ -0,0 +1,11 @@
use cortex_a::asm;
#[no_mangle]
fn __aa64_bsp_main() {
debugln!("Test");
loop {
asm::wfe();
}
}
global_asm!(include_str!("entry.S"));

View File

@ -0,0 +1 @@
pub mod boot;

7
kernel/src/arch/mod.rs Normal file
View File

@ -0,0 +1,7 @@
cfg_if! {
if #[cfg(target_arch = "aarch64")] {
pub mod aarch64;
pub use aarch64 as platform;
}
}

30
kernel/src/debug.rs Normal file
View File

@ -0,0 +1,30 @@
use core::fmt;
struct Output;
impl fmt::Write for Output {
fn write_str(&mut self, s: &str) -> fmt::Result {
for &byte in s.as_bytes() {
// XXX
unsafe {
core::ptr::write_volatile(0x09000000 as *mut u32, byte as u32);
}
}
Ok(())
}
}
#[macro_export]
macro_rules! debug {
($($it:tt)+) => ($crate::debug::_debug(format_args!($($it)+)))
}
#[macro_export]
macro_rules! debugln {
($($it:tt)+) => (debug!("{}\n", format_args!($($it)+)))
}
pub fn _debug(args: fmt::Arguments) {
use fmt::Write;
drop(Output {}.write_fmt(args));
}

View File

@ -3,24 +3,15 @@
#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[macro_use]
extern crate cfg_if;
#[macro_use]
pub mod debug;
pub mod arch;
pub mod mem;
#[panic_handler]
fn panic_handler(_pi: &PanicInfo) -> ! {
fn panic_handler(_pi: &core::panic::PanicInfo) -> ! {
loop {}
}
global_asm!(r#"
.section .text._entry
.global _entry
_entry:
mrs x1, mpidr_el1
and x1, x1, #3
beq 2f
1:
wfe
b 1b
2:
b .
"#);

8
kernel/src/mem/mod.rs Normal file
View File

@ -0,0 +1,8 @@
#[no_mangle]
pub unsafe extern "C" fn memcpy(dst: *mut u8, src: *mut u8, mut len: usize) -> *mut u8 {
while len != 0 {
len -= 1;
*dst.add(len) = *src.add(len);
}
dst
}