summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: a3e807189981fe617a0a7fc580b9f125768904f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![no_main]
#![no_std]

use core::panic::PanicInfo;

#[link_section = ".on_reset"]
#[no_mangle]
pub static __RESET_VECTOR: fn() -> ! = on_reset;

#[no_mangle]
pub static mut DEADBEEF: u32 = 0xdeadbeef;
pub static mut OTHER: u32 = 0;

/** Load into the data segments */
pub fn load_data_segments() -> () {
    extern "C" {
        static mut __data_load: u32;
        static mut __data_store_start: u32;
        static mut __data_store_end: u32;
        static mut __bss_start: u32;
        static mut __bss_end: u32;
    }

    unsafe {
        let mut data_load_addr: *mut u32 = &mut __data_load;
        let mut store_cursor: *mut u32 = &mut __data_store_start;
        let data_store_end_addr: *mut u32 = &mut __data_store_end;

        while store_cursor < data_store_end_addr {
            store_cursor.write_volatile(*data_load_addr);
            data_load_addr = data_load_addr.offset(1);
            store_cursor = store_cursor.offset(1);
        }

        let bss_end: *mut u32 = &mut __bss_end;
        let mut bss_cursor: *mut u32 = &mut __bss_start;

        while bss_cursor < bss_end {
            bss_cursor.write_volatile(0);
            bss_cursor = bss_cursor.offset(1);
        }
    }

    return;
}

pub fn on_reset() -> ! {
    load_data_segments();

    unsafe {
        DEADBEEF += 100;
        OTHER = DEADBEEF;
    }

    loop {}
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}