use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::write_volatile;
use core::ptr::{addr_of, addr_of_mut};
use kernel::debug;
use kernel::debug::IoWrite;
use crate::CHIP;
use crate::PROCESSES;
use crate::PROCESS_PRINTER;
struct Writer {}
static mut WRITER: Writer = Writer {};
impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}
impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
for b in buf {
unsafe {
write_volatile(0xd0580000 as *mut u32, (*b) as u32);
}
}
buf.len()
}
}
#[cfg(not(test))]
#[no_mangle]
#[panic_handler]
pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
let writer = &mut *addr_of_mut!(WRITER);
debug::panic_print(
writer,
pi,
&rv32i::support::nop,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
);
write_volatile(0xd0580000 as *mut u8, 0xff);
unreachable!()
}