1use core::fmt::Write;
6use core::panic::PanicInfo;
7use core::str;
8use kernel::debug;
9use kernel::debug::IoWrite;
10use kernel::hil::led;
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 let uart = sifive::uart::Uart::new(e310_g003::uart::UART0_BASE, 16_000_000);
30 uart.transmit_sync(buf);
31 buf.len()
32 }
33}
34
35#[cfg(not(test))]
37#[no_mangle]
38#[panic_handler]
39pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
40 use core::ptr::{addr_of, addr_of_mut};
41
42 let led = sifive::gpio::GpioPin::new(
43 e310_g003::gpio::GPIO0_BASE,
44 sifive::gpio::pins::pin22,
45 sifive::gpio::pins::pin22::SET,
46 sifive::gpio::pins::pin22::CLEAR,
47 );
48 let led = &mut led::LedLow::new(&led);
49 let writer = &mut *addr_of_mut!(WRITER);
50
51 debug::panic(
52 &mut [led],
53 writer,
54 pi,
55 &rv32i::support::nop,
56 &*addr_of!(PROCESSES),
57 &*addr_of!(CHIP),
58 &*addr_of!(PROCESS_PRINTER),
59 )
60}