lang_items.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // NOTE: Adapted from cortex-m/src/lang_items.rs
  2. use riscv::asm;
  3. /// Default panic handler
  4. #[panic_handler]
  5. fn panic(_info: &core::panic::PanicInfo) -> ! {
  6. asm::ebreak();
  7. loop {}
  8. }
  9. /// Lang item required to make the normal `main` work in applications
  10. // This is how the `start` lang item works:
  11. // When `rustc` compiles a binary crate, it creates a `main` function that looks
  12. // like this:
  13. //
  14. // ```
  15. // #[export_name = "main"]
  16. // pub extern "C" fn rustc_main(argc: isize, argv: *const *const u8) -> isize {
  17. // start(main)
  18. // }
  19. // ```
  20. //
  21. // Where `start` is this function and `main` is the binary crate's `main`
  22. // function.
  23. //
  24. // The final piece is that the entry point of our program, the reset handler,
  25. // has to call `rustc_main`. That's covered by the `reset_handler` function in
  26. // root of this crate.
  27. #[lang = "start"]
  28. extern "C" fn lang_start<T>(
  29. main: fn(),
  30. _argc: isize,
  31. _argv: *const *const u8,
  32. ) -> isize
  33. where
  34. T: Termination,
  35. {
  36. main();
  37. 0
  38. }
  39. #[lang = "termination"]
  40. pub trait Termination {
  41. fn report(self) -> i32;
  42. }
  43. impl Termination for () {
  44. fn report(self) -> i32 {
  45. 0
  46. }
  47. }