@@ -9,6 +9,8 @@ extern unsigned _data_end;
9
9
extern unsigned _bss_start;
10
10
extern unsigned _bss_end;
11
11
12
+ extern unsigned _heap_start;
13
+
12
14
extern unsigned _init_array_start;
13
15
extern unsigned _init_array_end;
14
16
@@ -18,48 +20,54 @@ extern unsigned _fini_array_end;
18
20
// main application
19
21
extern void main_app ();
20
22
21
- // reset handler
22
- void RESET_handler () {
23
- unsigned *src, *dst;
24
-
25
- // copy data
26
- src = &_data_load;
27
- dst = &_data_start;
23
+ void copy_data () {
24
+ unsigned *src = &_data_load;
25
+ unsigned *dst = &_data_start;
28
26
while (dst < &_data_end) {
29
27
*dst++ = *src++;
30
28
}
29
+ }
31
30
32
- // zero bss
33
- dst = &_bss_start;
31
+ void zero_bss () {
32
+ unsigned * dst = &_bss_start;
34
33
while (dst < &_bss_end) {
35
34
*dst++ = 0 ;
36
35
}
36
+ }
37
37
38
- // get current stack pointer
38
+ void fill_heap (unsigned fill=0x55555555 ) {
39
+ unsigned *dst = &_heap_start;
39
40
register unsigned *msp_reg;
40
41
__asm__ (" mrs %0, msp\n " : " =r" (msp_reg) );
41
-
42
- // fill unused SRAM
43
- dst = &_bss_end;
44
42
while (dst < msp_reg) {
45
- *dst++ = 0x55555555 ;
43
+ *dst++ = fill ;
46
44
}
45
+ }
47
46
48
- // call constructors for static instances
49
- dst = &_init_array_start;
50
- while (dst < &_init_array_end) {
51
- ((void (*)())*dst ++)();
47
+ void call_ctors () {
48
+ unsigned *tbl = &_init_array_start;
49
+ while (tbl < &_init_array_end) {
50
+ ((void (*)())*tbl ++)();
52
51
}
52
+ }
53
53
54
+ void call_dtors () {
55
+ unsigned *tbl = &_fini_array_start;
56
+ while (tbl < &_fini_array_end) {
57
+ ((void (*)())*tbl++)();
58
+ }
59
+ }
60
+
61
+ // reset handler
62
+ void RESET_handler () {
63
+ copy_data ();
64
+ zero_bss ();
65
+ fill_heap ();
66
+ call_ctors ();
54
67
// run application
55
68
main_app ();
56
-
57
69
// call destructors for static instances
58
- dst = &_fini_array_start;
59
- while (dst < &_fini_array_end) {
60
- ((void (*)())*dst++)();
61
- }
62
-
70
+ call_dtors ();
63
71
// stop
64
72
while (true );
65
73
}
0 commit comments