lang_items.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // NOTE: Adapted from cortex-m/src/lang_items.rs
  2. use riscv::asm;
  3. /// Default panic handler
  4. #[linkage = "weak"]
  5. #[lang = "panic_fmt"]
  6. unsafe extern "C" fn panic_fmt(
  7. _: ::core::fmt::Arguments, // fmt
  8. _: &'static str, // file
  9. _: u32, // line
  10. _: u32, // col
  11. ) -> ! {
  12. asm::ebreak();
  13. loop {}
  14. }
  15. /// Lang item required to make the normal `main` work in applications
  16. // This is how the `start` lang item works:
  17. // When `rustc` compiles a binary crate, it creates a `main` function that looks
  18. // like this:
  19. //
  20. // ```
  21. // #[export_name = "main"]
  22. // pub extern "C" fn rustc_main(argc: isize, argv: *const *const u8) -> isize {
  23. // start(main)
  24. // }
  25. // ```
  26. //
  27. // Where `start` is this function and `main` is the binary crate's `main`
  28. // function.
  29. //
  30. // The final piece is that the entry point of our program, the reset handler,
  31. // has to call `rustc_main`. That's covered by the `reset_handler` function in
  32. // root of this crate.
  33. #[lang = "start"]
  34. extern "C" fn start(
  35. main: fn(),
  36. _argc: isize,
  37. _argv: *const *const u8,
  38. ) -> isize {
  39. main();
  40. 0
  41. }