1.1 --- a/lib/payload.c Sat Oct 27 17:16:55 2018 +0200
1.2 +++ b/lib/payload.c Sat Oct 27 21:51:40 2018 +0200
1.3 @@ -19,12 +19,14 @@
1.4
1.5 #include <stdint.h>
1.6
1.7 -extern uint8_t _data_original, _data;
1.8 +
1.9 +
1.10 +extern uint8_t _data_original, _data, _bss;
1.11
1.12 -/* This is defined using SIZEOF and its table entry contains the actual value.
1.13 - Its "address" provided by the table is therefore the value! */
1.14 +/* These are defined using SIZEOF and their table entries contain actual values.
1.15 + The "address" provided by each entry is therefore the value! */
1.16
1.17 -extern uint32_t _data_size;
1.18 +extern uint32_t _data_size, _bss_size;
1.19
1.20 /* Relocate the .data section's contents to initialise mutable structures. */
1.21
1.22 @@ -38,3 +40,13 @@
1.23 while (original < limit)
1.24 *current++ = *original++;
1.25 }
1.26 +
1.27 +/* Clear the .bss section. */
1.28 +
1.29 +void init_bss(void)
1.30 +{
1.31 + uint8_t *current = &_bss, *limit = current + (uint32_t) &_bss_size;
1.32 +
1.33 + while (current < limit)
1.34 + *current++ = 0;
1.35 +}
2.1 --- a/lib/payload.ld Sat Oct 27 17:16:55 2018 +0200
2.2 +++ b/lib/payload.ld Sat Oct 27 21:51:40 2018 +0200
2.3 @@ -37,6 +37,12 @@
2.4 /* Exception/interrupt vectors and general program code. */
2.5
2.6 .vectors : { *(.vectors*) } > kseg0_program_mem AT > physical_program_mem
2.7 +
2.8 + .got : {
2.9 + _gp = ALIGN(16);
2.10 + *(.got*)
2.11 + } > kseg0_program_mem AT > physical_program_mem
2.12 +
2.13 .text : { *(.text*) } > kseg0_program_mem AT > physical_program_mem
2.14
2.15 /* Reserve space at the bottom of RAM for the IRQ stack. */
2.16 @@ -47,15 +53,16 @@
2.17
2.18 /* Add other data after the IRQ stack. */
2.19
2.20 - .bss : { *(.bss*) } > kseg0_data_mem AT > physical_data_mem
2.21 + .bss : {
2.22 + _bss = .;
2.23 + *(.bss*)
2.24 + } > kseg0_data_mem AT > physical_data_mem
2.25 +
2.26 + _bss_size = SIZEOF(.bss);
2.27
2.28 /* Store constant data in program memory. */
2.29
2.30 .rodata : { *(.rodata*) } > kseg0_program_mem AT > physical_program_mem
2.31 - .got : {
2.32 - _gp = ALIGN(16);
2.33 - *(.got*)
2.34 - } > kseg0_program_mem AT > physical_program_mem
2.35
2.36 /* Store initialised non-constant data in program memory for relocation.
2.37 Employ data memory addresses for generated content. */
2.38 @@ -63,7 +70,6 @@
2.39 .data : {
2.40 _data = .;
2.41 *(.data*)
2.42 - _data_end = .;
2.43 } > kseg0_data_mem AT > physical_program_mem
2.44
2.45 _data_original = LOADADDR(.data) - ORIGIN(physical_program_mem) + ORIGIN(kseg0_program_mem);
3.1 --- a/lib/start.S Sat Oct 27 17:16:55 2018 +0200
3.2 +++ b/lib/start.S Sat Oct 27 21:51:40 2018 +0200
3.3 @@ -45,6 +45,7 @@
3.4
3.5 .globl _start
3.6 .extern relocate_data
3.7 +.extern init_bss
3.8 .extern main
3.9
3.10 _start:
3.11 @@ -72,10 +73,14 @@
3.12 lui $gp, %hi(_GLOBAL_OFFSET_TABLE_)
3.13 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_)
3.14
3.15 - /* Relocate mutable data and then jump to the main program. */
3.16 + /* Clear or relocate mutable data and then jump to the main program. */
3.17 +
3.18 + la $t9, init_bss
3.19 + jalr $t9
3.20 + nop
3.21
3.22 la $t9, relocate_data
3.23 - jal $t9
3.24 + jalr $t9
3.25 nop
3.26
3.27 la $t9, main