From f0b1bd057c7ba2f316f5a4750d5a5cf6b0e18c10 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 26 Sep 2017 14:54:16 +1000 Subject: [PATCH 1/4] bios: Print location jumping too. Makes it easier to understand what is happening (and that the BIOS is jumping to the right place). --- misoc/software/bios/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misoc/software/bios/boot.c b/misoc/software/bios/boot.c index f476a42de..a73e568be 100644 --- a/misoc/software/bios/boot.c +++ b/misoc/software/bios/boot.c @@ -18,7 +18,7 @@ extern void boot_helper(unsigned int r1, unsigned int r2, unsigned int r3, unsig static void __attribute__((noreturn)) boot(unsigned int r1, unsigned int r2, unsigned int r3, unsigned int addr) { - printf("Executing booted program.\n"); + printf("Executing booted program at 0x%08x\n", addr); uart_sync(); irq_setmask(0); irq_setie(0); From 6686c8d4c4f0c161329d1307e1709877d4ea43a6 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 26 Sep 2017 05:33:58 +1000 Subject: [PATCH 2/4] common: Compile with debugging symbols on. Debugging symbols are useful when using GDB :-) --- misoc/software/common.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misoc/software/common.mak b/misoc/software/common.mak index 9ba59ccdc..7d09363df 100644 --- a/misoc/software/common.mak +++ b/misoc/software/common.mak @@ -44,7 +44,7 @@ endif # Toolchain options # INCLUDES = -I$(MISOC_DIRECTORY)/software/include/base -I$(MISOC_DIRECTORY)/software/include -I$(MISOC_DIRECTORY)/common -I$(BUILDINC_DIRECTORY) -COMMONFLAGS = -Os $(CPUFLAGS) -fomit-frame-pointer -ffunction-sections -Wall -fno-builtin -nostdinc $(INCLUDES) +COMMONFLAGS = -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -ffunction-sections -Wall -fno-builtin -nostdinc $(INCLUDES) CFLAGS = $(COMMONFLAGS) -fexceptions -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Werror=incompatible-pointer-types CXXFLAGS = $(COMMONFLAGS) -std=c++11 -I$(MISOC_DIRECTORY)/software/include/basec++ -fexceptions -fno-rtti -ffreestanding LDFLAGS = --gc-sections -nostdlib -nodefaultlibs -L$(BUILDINC_DIRECTORY) From 98dd745548319242399e8ff1e7137dbb73e3cb21 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 26 Sep 2017 05:28:27 +1000 Subject: [PATCH 3/4] or1k: Use EXCEPTION_STACK_SIZE of 256bytes. or1k defines a 128 byte "red zone" after the stack that can not be touched by the exception handler. We also need 128 bytes to store the 32 registers. --- misoc/software/libbase/crt0-or1k.S | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/misoc/software/libbase/crt0-or1k.S b/misoc/software/libbase/crt0-or1k.S index 5db4142af..ff77910dc 100644 --- a/misoc/software/libbase/crt0-or1k.S +++ b/misoc/software/libbase/crt0-or1k.S @@ -19,7 +19,18 @@ #include -#define EXCEPTION_STACK_SIZE (4*32) +/* + * OR1K Architecture has a 128 byte "red zone" after the stack that can not be + * touched by exception handlers. GCC uses this red zone for locals and + * temps without needing to change the stack pointer. + */ +#define OR1K_RED_ZONE_SIZE 128 + +/* + * We need 4 bytes (32 bits) * 32 registers space on the stack to save all the + * registers. + */ +#define EXCEPTION_STACK_SIZE ((4*32) + OR1K_RED_ZONE_SIZE) #define HANDLE_EXCEPTION ; \ l.addi r1, r1, -EXCEPTION_STACK_SIZE ; \ From 8a13566c02ad92a46f9c0eff98c670f8c3899980 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 25 Sep 2017 19:32:55 +1000 Subject: [PATCH 4/4] bios: Declare dependency on linked in .a files. This means if the libraries are modified for any reason, the bios will be correctly relinked. --- misoc/software/bios/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misoc/software/bios/Makefile b/misoc/software/bios/Makefile index 2da8a8d25..8c57907dd 100644 --- a/misoc/software/bios/Makefile +++ b/misoc/software/bios/Makefile @@ -12,8 +12,8 @@ all: bios.bin bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS) -%.elf: - $(LD) $(LDFLAGS) -T $< -N -o $@ \ +%.elf: ../libbase/crt0-$(CPU).o ../libnet/libnet.a ../libbase/libbase-nofloat.a ../libcompiler_rt/libcompiler_rt.a + $(LD) $(LDFLAGS) -T $(BIOS_DIRECTORY)/linker.ld -N -o $@ \ ../libbase/crt0-$(CPU).o \ $(OBJECTS) \ -L../libnet \