Using it

We need to initialise the logger before we use it.

  1. #![no_main]
  2. #![no_std]
  3. mod exceptions;
  4. mod logger;
  5. mod pl011;
  6. use crate::pl011::Uart;
  7. use core::panic::PanicInfo;
  8. use log::{error, info, LevelFilter};
  9. use smccc::psci::system_off;
  10. use smccc::Hvc;
  11. /// Base address of the primary PL011 UART.
  12. const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _;
  13. // SAFETY: There is no other global function of this name.
  14. #[unsafe(no_mangle)]
  15. extern "C" fn main(x0: u64, x1: u64, x2: u64, x3: u64) {
  16.     // SAFETY: `PL011_BASE_ADDRESS` is the base address of a PL011 device, and
  17.     // nothing else accesses that address range.
  18.     let uart = unsafe { Uart::new(PL011_BASE_ADDRESS) };
  19.     logger::init(uart, LevelFilter::Trace).unwrap();
  20.     info!("main({x0:#x}, {x1:#x}, {x2:#x}, {x3:#x})");
  21.     assert_eq!(x1, 42);
  22.     system_off::<Hvc>().unwrap();
  23. }
  24. #[panic_handler]
  25. fn panic(info: &PanicInfo) -> ! {
  26.     error!("{info}");
  27.     system_off::<Hvc>().unwrap();
  28.     loop {}
  29. }
  • Note that our panic handler can now log details of panics.
  • Run the example in QEMU with make qemu_logger under src/bare-metal/aps/examples.