bios/linker: Place .data in sram with initial copy in rom.

This commit is contained in:
Vegard Storheil Eriksen 2020-06-15 16:08:49 +02:00
parent 336896603f
commit 9c68d71503
10 changed files with 92 additions and 17 deletions

View File

@ -57,6 +57,19 @@ crt_init:
la a0, trap_entry la a0, trap_entry
csrw mtvec, a0 csrw mtvec, a0
data_init:
la a0, _fdata
la a1, _edata
la a2, _fdata_rom
data_loop:
beq a0,a1,data_done
ld a3,0(a2)
sd a3,0(a0)
add a0,a0,8
add a2,a2,8
j data_loop
data_done:
bss_init: bss_init:
la a0, _fbss la a0, _fbss
la a1, _ebss la a1, _ebss

View File

@ -94,6 +94,19 @@ crt_init:
la a0, vector_table la a0, vector_table
csrw mtvec, a0 csrw mtvec, a0
data_init:
la a0, _fdata
la a1, _edata
la a2, _fdata_rom
data_loop:
beq a0,a1,data_done
lw a3,0(a2)
sw a3,0(a0)
add a0,a0,4
add a2,a2,4
j data_loop
data_done:
bss_init: bss_init:
la a0, _fbss la a0, _fbss
la a1, _ebss la a1, _ebss

View File

@ -112,10 +112,9 @@ _crt0:
mvhi sp, hi(_fstack) mvhi sp, hi(_fstack)
ori sp, sp, lo(_fstack) ori sp, sp, lo(_fstack)
#ifdef EXECUTE_IN_PLACE
/* Load DATA */ /* Load DATA */
mvhi r1, hi(_erodata) mvhi r1, hi(_fdata_rom)
ori r1, r1, lo(_erodata) ori r1, r1, lo(_fdata_rom)
mvhi r2, hi(_fdata) mvhi r2, hi(_fdata)
ori r2, r2, lo(_fdata) ori r2, r2, lo(_fdata)
mvhi r3, hi(_edata) mvhi r3, hi(_edata)
@ -128,7 +127,6 @@ _crt0:
addi r1, r1, 4 addi r1, r1, 4
addi r2, r2, 4 addi r2, r2, 4
bi .moveDATA bi .moveDATA
#endif
.doBSS: .doBSS:
/* Clear BSS */ /* Clear BSS */

View File

@ -9,14 +9,26 @@ reset_vector:
la t0, trap_vector la t0, trap_vector
csrw mtvec, t0 csrw mtvec, t0
// initialize .data
la t0, _fdata
la t1, _edata
la t2, _fdata_rom
1: beq t0, t1, 2f
lw t3, 0(t0)
sw t3, 0(t2)
addi t0, t0, 4
addi t2, t2, 4
j 1b
2:
// initialize .bss // initialize .bss
la t0, _fbss la t0, _fbss
la t1, _ebss la t1, _ebss
1: beq t0, t1, 2f 1: beq t0, t1, 3f
sw zero, 0(t0) sw zero, 0(t0)
addi t0, t0, 4 addi t0, t0, 4
j 1b j 1b
2: 3:
// enable external interrupts // enable external interrupts
li t0, MIE_MEIE li t0, MIE_MEIE
csrs mie, t0 csrs mie, t0

View File

@ -194,9 +194,8 @@ _crt0:
la t1, _irq_mask la t1, _irq_mask
sw t0, 0(t1) sw t0, 0(t1)
#ifdef EXECUTE_IN_PLACE
/* Load DATA */ /* Load DATA */
la t0, _erodata la t0, _fdata_rom
la t1, _fdata la t1, _fdata
la t2, _edata la t2, _edata
3: 3:
@ -206,7 +205,6 @@ _crt0:
addi t0, t0, 4 addi t0, t0, 4
addi t1, t1, 4 addi t1, t1, 4
bltu t1, t2, 3b bltu t1, t2, 3b
#endif
/* Clear BSS */ /* Clear BSS */
la t0, _fbss la t0, _fbss

View File

@ -57,6 +57,19 @@ crt_init:
la a0, trap_entry la a0, trap_entry
csrw mtvec, a0 csrw mtvec, a0
data_init:
la a0, _fdata
la a1, _edata
la a2, _fdata_rom
data_loop:
beq a0,a1,data_done
ld a3,0(a2)
sd a3,0(a0)
add a0,a0,8
add a2,a2,8
j data_loop
data_done:
bss_init: bss_init:
la a0, _fbss la a0, _fbss
la a1, _ebss la a1, _ebss

View File

@ -9,14 +9,26 @@ reset_vector:
la t0, trap_vector la t0, trap_vector
csrw mtvec, t0 csrw mtvec, t0
// initialize .data
la t0, _fdata
la t1, _edata
la t2, _fdata_rom
1: beq t0, t1, 2f
lw t3, 0(t0)
sw t3, 0(t2)
addi t0, t0, 4
addi t2, t2, 4
j 1b
2:
// initialize .bss // initialize .bss
la t0, _fbss la t0, _fbss
la t1, _ebss la t1, _ebss
1: beq t0, t1, 2f 1: beq t0, t1, 3f
sw zero, 0(t0) sw zero, 0(t0)
addi t0, t0, 4 addi t0, t0, 4
j 1b j 1b
2: 3:
// enable external interrupts // enable external interrupts
li t0, MIE_MEIE li t0, MIE_MEIE
csrs mie, t0 csrs mie, t0

View File

@ -58,6 +58,19 @@ crt_init:
la a0, trap_entry la a0, trap_entry
csrw mtvec, a0 csrw mtvec, a0
data_init:
la a0, _fdata
la a1, _edata
la a2, _fdata_rom
data_loop:
beq a0,a1,data_done
lw a3,0(a2)
sw a3,0(a0)
add a0,a0,4
add a2,a2,4
j data_loop
data_done:
bss_init: bss_init:
la a0, _fbss la a0, _fbss
la a1, _ebss la a1, _ebss

View File

@ -11,7 +11,7 @@
#include "helpers.h" #include "helpers.h"
#include "command.h" #include "command.h"
extern unsigned int _ftext, _edata; extern unsigned int _ftext, _edata_rom;
#define NUMBER_OF_BYTES_ON_A_LINE 16 #define NUMBER_OF_BYTES_ON_A_LINE 16
void dump_bytes(unsigned int *ptr, int count, unsigned long addr) void dump_bytes(unsigned int *ptr, int count, unsigned long addr)
@ -59,14 +59,14 @@ void crcbios(void)
unsigned int actual_crc; unsigned int actual_crc;
/* /*
* _edata is located right after the end of the flat * _edata_rom is located right after the end of the flat
* binary image. The CRC tool writes the 32-bit CRC here. * binary image. The CRC tool writes the 32-bit CRC here.
* We also use the address of _edata to know the length * We also use the address of _edata_rom to know the length
* of our code. * of our code.
*/ */
offset_bios = (unsigned long)&_ftext; offset_bios = (unsigned long)&_ftext;
expected_crc = _edata; expected_crc = _edata_rom;
length = (unsigned long)&_edata - offset_bios; length = (unsigned long)&_edata_rom - offset_bios;
actual_crc = crc32((unsigned char *)offset_bios, length); actual_crc = crc32((unsigned char *)offset_bios, length);
if (expected_crc == actual_crc) if (expected_crc == actual_crc)
printf(" BIOS CRC passed (%08x)\n", actual_crc); printf(" BIOS CRC passed (%08x)\n", actual_crc);

View File

@ -53,7 +53,7 @@ SECTIONS
FILL(0); FILL(0);
. = ALIGN(8); . = ALIGN(8);
_edata = .; _edata = .;
} > rom } > sram AT > rom
.bss : .bss :
{ {
@ -78,3 +78,6 @@ SECTIONS
} }
PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 8); PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 8);
PROVIDE(_fdata_rom = LOADADDR(.data));
PROVIDE(_edata_rom = LOADADDR(.data) + SIZEOF(.data));