1.1 --- a/examples/demo/main.c Thu Oct 25 21:19:01 2018 +0200
1.2 +++ b/examples/demo/main.c Fri Oct 26 18:22:04 2018 +0200
1.3 @@ -43,7 +43,7 @@
1.4 #define CELLSIZE 4
1.5 #endif
1.6
1.7 -static int uart_echo;
1.8 +static int uart_echo = 1;
1.9
1.10
1.11
1.12 @@ -75,8 +75,6 @@
1.13
1.14 void main(void)
1.15 {
1.16 - uart_echo = 0;
1.17 -
1.18 init_memory();
1.19 init_pins();
1.20 init_outputs();
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/lib/payload.c Fri Oct 26 18:22:04 2018 +0200
2.3 @@ -0,0 +1,36 @@
2.4 +/*
2.5 + * Payload initialisation functions.
2.6 + *
2.7 + * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
2.8 + *
2.9 + * This program is free software: you can redistribute it and/or modify
2.10 + * it under the terms of the GNU General Public License as published by
2.11 + * the Free Software Foundation, either version 3 of the License, or
2.12 + * (at your option) any later version.
2.13 + *
2.14 + * This program is distributed in the hope that it will be useful,
2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 + * GNU General Public License for more details.
2.18 + *
2.19 + * You should have received a copy of the GNU General Public License
2.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.21 + */
2.22 +
2.23 +#include <stdint.h>
2.24 +
2.25 +/* Relocate the .data section's contents to initialise mutable structures. */
2.26 +
2.27 +void relocate_data(uint32_t *original, uint32_t *current, uint32_t size)
2.28 +{
2.29 + /* Reference stored content as values. */
2.30 +
2.31 + uint32_t *source, *target;
2.32 +
2.33 + /* Copy data from program memory to the relocated data area in RAM. */
2.34 +
2.35 + for (source = original, target = current; source < original + size;
2.36 + source++, target++)
2.37 +
2.38 + *target = *source;
2.39 +}
3.1 --- a/lib/payload.ld Thu Oct 25 21:19:01 2018 +0200
3.2 +++ b/lib/payload.ld Fri Oct 26 18:22:04 2018 +0200
3.3 @@ -43,7 +43,7 @@
3.4
3.5 .irqstack : {
3.6 . += IRQ_STACK_SIZE;
3.7 - } > kseg0_data_mem AT > physical_data_mem
3.8 + } > kseg0_data_mem AT > physical_data_mem
3.9
3.10 /* Add other data after the IRQ stack. */
3.11
3.12 @@ -51,13 +51,24 @@
3.13
3.14 /* Store constant data in program memory. */
3.15
3.16 - .data : { *(.data*) } > kseg0_program_mem AT > physical_program_mem
3.17 .rodata : { *(.rodata*) } > kseg0_program_mem AT > physical_program_mem
3.18 .got : {
3.19 _gp = ALIGN(16);
3.20 *(.got*)
3.21 } > kseg0_program_mem AT > physical_program_mem
3.22
3.23 + /* Store initialised non-constant data in program memory for relocation.
3.24 + Employ data memory addresses for generated content. */
3.25 +
3.26 + .data : {
3.27 + _data = .;
3.28 + *(.data*)
3.29 + _data_end = .;
3.30 + } > kseg0_data_mem AT > physical_program_mem
3.31 +
3.32 + _data_original = LOADADDR(.data) - ORIGIN(physical_program_mem) + ORIGIN(kseg0_program_mem);
3.33 + _data_size = SIZEOF(.data);
3.34 +
3.35 /* Device configuration registers to be flashed. */
3.36
3.37 .devcfg0 : { *(.devcfg0) } > config0 AT > physical_config0
4.1 --- a/lib/start.S Thu Oct 25 21:19:01 2018 +0200
4.2 +++ b/lib/start.S Fri Oct 26 18:22:04 2018 +0200
4.3 @@ -44,6 +44,10 @@
4.4 .section .boot, "a"
4.5
4.6 .globl _start
4.7 +.extern relocate_data
4.8 +.extern _data_original
4.9 +.extern _data
4.10 +.extern _data_size
4.11 .extern main
4.12
4.13 _start:
4.14 @@ -72,11 +76,29 @@
4.15 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_)
4.16
4.17 /*
4.18 - Jump to the main program. Since the boot code is separate from the
4.19 - other code, the address cannot be obtained via the GOT.
4.20 - ("relocation truncated to fit: R_MIPS_PC16 against `main'")
4.21 + Relocate mutable data and then jump to the main program.
4.22 +
4.23 + Since the boot code is separate from the other code, addresses cannot be
4.24 + obtained via the GOT:
4.25 +
4.26 + "relocation truncated to fit: R_MIPS_PC16 against `main'"
4.27 */
4.28
4.29 + lui $a0, %hi(_data_original)
4.30 + ori $a0, $a0, %lo(_data_original)
4.31 +
4.32 + lui $a1, %hi(_data)
4.33 + ori $a1, $a1, %lo(_data)
4.34 +
4.35 + lui $a2, %hi(_data_size)
4.36 + ori $a2, $a2, %lo(_data_size)
4.37 + lw $a2, 0($a2)
4.38 +
4.39 + lui $t9, %hi(relocate_data)
4.40 + ori $t9, $t9, %lo(relocate_data)
4.41 + jal $t9
4.42 + nop
4.43 +
4.44 lui $t9, %hi(main)
4.45 ori $t9, $t9, %lo(main)
4.46 jr $t9
5.1 --- a/mk/common.mk Thu Oct 25 21:19:01 2018 +0200
5.2 +++ b/mk/common.mk Fri Oct 26 18:22:04 2018 +0200
5.3 @@ -48,8 +48,8 @@
5.4 # Application-specific files appear after the above but before those below in
5.5 # the application Makefiles.
5.6
5.7 -COMMON_SRC = $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/cpu.S
5.8 -COMMON_OBJ = $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/cpu.o
5.9 +COMMON_SRC = $(LIBDIR)/payload.c $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/cpu.S
5.10 +COMMON_OBJ = $(LIBDIR)/payload.o $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/cpu.o
5.11
5.12 DISPLAY_SRC = $(LIBDIR)/display.c $(LIBDIR)/vga_display.c
5.13 DISPLAY_OBJ = $(LIBDIR)/display.o $(LIBDIR)/vga_display.o