mips_rt/lib.rs
1//! Startup code and minimal runtime for MIPS microcontrollers
2//! targets a MIPS microcontroller.
3
4#![no_std]
5
6/// Attribute to declare a `pre_init` hook function
7pub use mips_rt_macros::pre_init;
8
9/// Attribute to declare the entry point of the program
10///
11/// The specified function will be called by the reset handler after RAM has
12/// been initialized.
13///
14/// The type of the specified function must be `[unsafe] fn() -> !` (never
15/// ending function)
16///
17/// The entry point will be called by the reset handler. The program can't
18/// reference to the entry point, much less invoke it.
19///
20/// `static mut` variables declared within the entry function are safe to access
21/// and can be used to preserve state across invocations of the handler. The
22/// compiler can't prove this is safe so the attribute will help by making a
23/// transformation to the source code: for this reason a variable like `static
24/// mut FOO: u32` will be accessible from within the entry function as `let FOO:
25/// &mut u32;`.
26///
27/// ## Example
28///
29/// ```ignore
30/// # #![no_main]
31/// # use mips_rt_macros::entry;
32/// #[entry]
33/// fn main() -> ! {
34/// loop {
35/// /* .. */
36/// }
37/// }
38/// ```
39pub use mips_rt_macros::entry;
40
41/// Attribute to declare an Interrupt Service Routine (ISR)
42///
43/// The name of the ISRs must correspond to the interrupts names defined in the
44/// Peripheral Access Crate of the respective device.
45///
46/// `static mut` variables declared within an ISR are safe to access and can be
47/// used to preserve state across invocations of the handler. The compiler can't
48/// prove this is safe so the attribute will help by making a transformation to
49/// the source code: for this reason a variable like `static mut FOO: u32` will
50/// be accessible from within the ISR as `let FOO: &mut u32;`.
51///
52/// ## Example
53///
54/// ```ignore
55/// #[interrupt]
56/// fn CORE_TIMER() {
57/// static mut COUNTER: u32 = 0;
58///
59/// *COUNTER += 1; // access of a static mut variable as described above
60///
61/// // clear interrupt flag
62/// unsafe {
63/// (*INT::ptr()).ifs0clr.write(|w| w.ctif().bit(true));
64/// }
65/// }
66/// ```
67///
68pub use mips_rt_macros::interrupt;
69
70/// Attribute to declare an exception handler and setting up respective symbols
71/// for linking
72///
73/// The exception handlers must have the name `nmi` or `general_exception` to
74/// create an NMI or an General Exception handler, respectively. The handlers
75/// take two u32 arguments for the CP0 Cause and CP0 Status registers.
76///
77/// ## Example (General Exception)
78///
79/// ```ignore
80/// #[exception]
81/// fn general_exception(cp0_cause: u32, cp0_status: u32) {
82///
83/// // ...
84/// }
85/// ```
86///
87/// ## Example (NMI)
88///
89/// ```ignore
90/// #[exception]
91/// fn nmi(cp0_cause: u32, cp0_status: u32) {
92///
93/// // ...
94/// }
95/// ```
96pub use mips_rt_macros::exception;
97
98#[doc(hidden)]
99#[no_mangle]
100pub unsafe extern "C" fn DefaultPreInit() {}
101
102/// Returns a pointer to the start of the heap
103///
104/// The returned pointer is guaranteed to be 4-byte aligned.
105#[inline]
106pub fn heap_start() -> *mut u32 {
107 extern "C" {
108 static mut __sheap: u32;
109 }
110
111 unsafe { &mut __sheap }
112}