veer_el2_sim/
io.rs
1use core::fmt::Write;
6use core::panic::PanicInfo;
7use core::ptr::write_volatile;
8use core::ptr::{addr_of, addr_of_mut};
9use kernel::debug;
10use kernel::debug::IoWrite;
11
12use crate::CHIP;
13use crate::PROCESSES;
14use crate::PROCESS_PRINTER;
15
16struct Writer {}
17
18static mut WRITER: Writer = Writer {};
19
20impl Write for Writer {
21 fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
22 self.write(s.as_bytes());
23 Ok(())
24 }
25}
26
27impl IoWrite for Writer {
28 fn write(&mut self, buf: &[u8]) -> usize {
29 for b in buf {
30 unsafe {
32 write_volatile(0xd0580000 as *mut u32, (*b) as u32);
33 }
34 }
35 buf.len()
36 }
37}
38
39#[cfg(not(test))]
44#[no_mangle]
45#[panic_handler]
46pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
47 let writer = &mut *addr_of_mut!(WRITER);
48
49 debug::panic_print(
50 writer,
51 pi,
52 &rv32i::support::nop,
53 &*addr_of!(PROCESSES),
54 &*addr_of!(CHIP),
55 &*addr_of!(PROCESS_PRINTER),
56 );
57
58 write_volatile(0xd0580000 as *mut u8, 0xff);
61
62 unreachable!()
63}