1use core::fmt::Write;
6use core::panic::PanicInfo;
7use core::str;
8use kernel::debug;
9use kernel::debug::IoWrite;
10
11struct Writer {
12 uart: litex_vexriscv::uart::LiteXUart<'static, crate::socc::SoCRegisterFmt>,
13}
14
15impl Write for Writer {
16 fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
17 self.write(s.as_bytes());
18 Ok(())
19 }
20}
21
22impl IoWrite for Writer {
23 fn write(&mut self, buf: &[u8]) -> usize {
24 self.uart.transmit_sync(buf);
25 buf.len()
26 }
27}
28
29#[cfg(not(test))]
31#[panic_handler]
32pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
33 let mut writer = Writer {
39 uart: litex_vexriscv::uart::LiteXUart::new(
40 kernel::utilities::StaticRef::new(
41 crate::socc::CSR_UART_BASE
42 as *const litex_vexriscv::uart::LiteXUartRegisters<crate::socc::SoCRegisterFmt>,
43 ),
44 None, ),
46 };
47
48 debug::panic_print(
49 &mut writer,
50 pi,
51 &rv32i::support::nop,
52 crate::PANIC_RESOURCES.get(),
53 );
54
55 loop {}
57}