|
23 | 23 | //! - Before main initialization of the `.bss` and `.data` sections.
|
24 | 24 | //!
|
25 | 25 | //! - [`#[entry]`][attr-entry] to declare the entry point of the program
|
26 |
| -//! - [`#[pre_init]`][attr-pre-init]to run code *before* `static` variables are initialized |
27 | 26 | //! - [`#[exception]`][attr-exception] to override an exception handler.
|
28 | 27 | //! - [`#[core_interrupt]`][attr-core-interrupt] to override a core interrupt handler.
|
29 | 28 | //! - [`#[external_interrupt]`][attr-external-interrupt] to override an external interrupt handler.
|
|
476 | 475 | //!
|
477 | 476 | //! # Cargo Features
|
478 | 477 | //!
|
| 478 | +//! ## `pre-init` |
| 479 | +//! |
| 480 | +//! The pre-init feature (`pre-init`) can be activated via [Cargo features](https://doc.rust-lang.org/cargo/reference/features.html). |
| 481 | +//! When enabled, the runtime will execute the `__pre_init` function to be run **before RAM is initialized**. |
| 482 | +//! If the feature is enabled, the `__pre_init` function must be defined in the user code (i.e., no default implementation is |
| 483 | +//! provided by this crate). If the feature is disabled, the `__pre_init` function is not required. |
| 484 | +//! |
| 485 | +//! As `__pre_init` runs before RAM is initialised, it is not sound to use a Rust function for `__pre_init`, and |
| 486 | +//! instead it should typically be written in assembly using `global_asm` or an external assembly file. |
| 487 | +//! |
| 488 | +//! Alternatively, you can use the [`#[pre_init]`][attr-pre-init] attribute to define a pre-init function with Rust. |
| 489 | +//! Note that using this macro is discouraged, as it may lead to undefined behavior. |
| 490 | +//! We left this option for backwards compatibility, but it is subject to removal in the future. |
| 491 | +//! |
479 | 492 | //! ## `single-hart`
|
480 | 493 | //!
|
481 | 494 | //! The single hart feature (`single-hart) can be activated via [Cargo features](https://doc.rust-lang.org/cargo/reference/features.html).
|
@@ -570,7 +583,10 @@ use riscv::register::scause as xcause;
|
570 | 583 | use riscv::register::mcause as xcause;
|
571 | 584 |
|
572 | 585 | pub use riscv_pac::*;
|
573 |
| -pub use riscv_rt_macros::{core_interrupt, entry, exception, external_interrupt, pre_init}; |
| 586 | +pub use riscv_rt_macros::{core_interrupt, entry, exception, external_interrupt}; |
| 587 | + |
| 588 | +#[cfg(feature = "pre-init")] |
| 589 | +pub use riscv_rt_macros::pre_init; |
574 | 590 |
|
575 | 591 | /// We export this static with an informative name so that if an application attempts to link
|
576 | 592 | /// two copies of riscv-rt together, linking will fail. We also declare a links key in
|
|
0 commit comments