forked from IsaacWoods/poplar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seed_riscv: get the thing actually working
We were getting really weird behaviour before with the tracing stuff, that was leading me to think code was being corrupted somehow. We seem to have fixed that by stripping everything right back to basics and making sure we're loading everything right, but I haven't convincingly found the problem. Oh well - let's start adding stuff back and see what breaks.
- Loading branch information
1 parent
f61ed38
commit 7b94d81
Showing
7 changed files
with
85 additions
and
137 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,50 @@ | ||
OUTPUT_ARCH("riscv") | ||
OUTPUT_FORMAT("elf64-littleriscv") | ||
ENTRY(_start) | ||
|
||
SECTIONS { | ||
. = 0x80200000; | ||
_kernel_start = .; | ||
|
||
.text : { | ||
*(.text.entry) | ||
.text : ALIGN(16) { | ||
*(.text.start) | ||
*(.text .text.*) | ||
. = ALIGN(4K); | ||
} | ||
|
||
.rodata : { | ||
*(.rodata .rodata.*) | ||
. = ALIGN(4K); | ||
} | ||
|
||
.data : { | ||
*(.data .data.*) | ||
.srodata : ALIGN(16) { | ||
*(.srodata .srodata.*) | ||
} | ||
|
||
. = ALIGN(8); | ||
|
||
.sdata : { | ||
.sdata : ALIGN(16) { | ||
*(.sdata .sdata.*) | ||
. = ALIGN(4K); | ||
} | ||
|
||
.sbss : { | ||
PROVIDE(__global_pointer$ = .); | ||
PROVIDE(__bss_start = .); | ||
|
||
.sbss : ALIGN(16) { | ||
*(.sbss .sbss.*) | ||
} | ||
|
||
.bss : { | ||
.bss : ALIGN(16) { | ||
*(.bss .bss.*) | ||
. = ALIGN(4K); | ||
|
||
_stack_bottom = .; | ||
. += 4K; | ||
_stack_top = .; | ||
PROVIDE(_stack_bottom = .); | ||
. += 64K; | ||
PROVIDE(_stack_top = .); | ||
} | ||
|
||
_kernel_end = .; | ||
PROVIDE(__bss_end = .); | ||
|
||
.data : ALIGN(16) { | ||
*(.data .data.*) | ||
} | ||
|
||
.rodata : ALIGN(16) { | ||
*(.rodata .rodata.*) | ||
} | ||
|
||
.eh_frame : ALIGN(16) { | ||
*(.eh_frame) | ||
} | ||
|
||
/DISCARD/ : { *(.eh_frame_hdr .eh_frame) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,46 @@ | ||
use core::sync::atomic::{AtomicU64, Ordering}; | ||
use hal_riscv::hw::uart16550::Uart16550; | ||
use poplar_util::InitGuard; | ||
use tracing::{span, Collect, Event, Metadata}; | ||
use tracing_core::span::Current as CurrentSpan; | ||
use core::{fmt, fmt::Write}; | ||
use log::{Level, LevelFilter, Metadata, Record}; | ||
|
||
static LOGGER: Logger = Logger::new(); | ||
pub struct Logger; | ||
|
||
pub struct Logger { | ||
next_id: AtomicU64, | ||
serial_port: InitGuard<&'static mut Uart16550>, | ||
} | ||
static LOGGER: Logger = Logger; | ||
|
||
impl Logger { | ||
const fn new() -> Logger { | ||
Logger { next_id: AtomicU64::new(0), serial_port: InitGuard::uninit() } | ||
} | ||
|
||
pub fn init() { | ||
let serial_port = unsafe { &mut *(0x10000000 as *mut hal_riscv::hw::uart16550::Uart16550) }; | ||
LOGGER.serial_port.initialize(serial_port); | ||
tracing::dispatch::set_global_default(tracing::dispatch::Dispatch::from_static(&LOGGER)) | ||
.expect("Failed to set default tracing dispatch"); | ||
log::set_logger(&LOGGER).map(|_| log::set_max_level(LevelFilter::Trace)).unwrap(); | ||
} | ||
} | ||
|
||
impl Collect for Logger { | ||
fn current_span(&self) -> CurrentSpan { | ||
todo!() | ||
} | ||
|
||
fn enabled(&self, _: &Metadata) -> bool { | ||
true | ||
} | ||
|
||
fn enter(&self, span: &span::Id) { | ||
todo!() | ||
} | ||
|
||
fn event(&self, event: &Event) { | ||
todo!() | ||
} | ||
impl fmt::Write for Logger { | ||
fn write_str(&mut self, s: &str) -> fmt::Result { | ||
for byte in s.bytes() { | ||
unsafe { | ||
(0x1000_0000 as *mut u8).write_volatile(byte); | ||
} | ||
} | ||
|
||
fn exit(&self, span: &span::Id) { | ||
todo!() | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn new_span(&self, span: &span::Attributes) -> span::Id { | ||
let mut id = self.next_id.fetch_add(1, Ordering::Acquire); | ||
span::Id::from_u64(id) | ||
impl log::Log for Logger { | ||
fn enabled(&self, _metadata: &Metadata) -> bool { | ||
true | ||
} | ||
|
||
fn record(&self, _span: &span::Id, _values: &span::Record) { | ||
todo!() | ||
fn log(&self, record: &Record) { | ||
if self.enabled(record.metadata()) { | ||
let color = match record.metadata().level() { | ||
Level::Trace => "\x1b[36m", | ||
Level::Debug => "\x1b[34m", | ||
Level::Info => "\x1b[32m", | ||
Level::Warn => "\x1b[33m", | ||
Level::Error => "\x1b[31m", | ||
}; | ||
writeln!(Logger, "[{}{:5}\x1b[0m] {}: {}", color, record.level(), record.target(), record.args()) | ||
.unwrap(); | ||
} | ||
} | ||
|
||
fn record_follows_from(&self, _span: &span::Id, _follows: &span::Id) { | ||
todo!() | ||
} | ||
fn flush(&self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters