r0 0.2.0

Initialization code ('crt0') written in Rust

Initialization code ("crt0") written in Rust

This is for bare metal systems where there is no ELF loader or OS to take care of initializing RAM for the program.

Example

On the linker script side, we must assign names (symbols) to the boundaries of the .bss and .data sections.

.bss : ALIGN(4)
{
    _sbss = .;
    *(.bss.*);
    _ebss = ALIGN(4);
} > RAM

.data : ALIGN(4)
{
    _sdata = .;
    *(.data.*);
    _edata = ALIGN(4);
} > RAM AT > FLASH

_sidata = LOADADDR(.data);

On the Rust side, we must bind to those symbols using an extern block.

unsafe fn before_main() {
    // The type, `u32`, indicates that the memory is 4-byte aligned
    extern "C" {
        static mut _sbss: u32;
        static mut _ebss: u32;

        static mut _sdata: u32;
        static mut _edata: u32;

        static _sidata: u32;
    }

    zero_bss(&mut _sbss, &mut _ebss);
    init_data(&mut _sdata, &mut _edata, &_sidata);
}