From 067f633b42459a188afe739c1dfbf6857397a729 Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Wed, 31 May 2017 04:33:00 -0400 Subject: [PATCH 1/4] add mips32-minimal exception hanlding --- am/arch/mips32-minimal/img/boot/Makefile | 4 +++- am/arch/mips32-minimal/img/boot/start.S | 12 ++++++++++-- am/arch/mips32-minimal/include/npc.h | 9 +++++++-- am/arch/mips32-minimal/src/trap.S | 4 ++++ 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 am/arch/mips32-minimal/src/trap.S diff --git a/am/arch/mips32-minimal/img/boot/Makefile b/am/arch/mips32-minimal/img/boot/Makefile index 02ca299b..7452875a 100644 --- a/am/arch/mips32-minimal/img/boot/Makefile +++ b/am/arch/mips32-minimal/img/boot/Makefile @@ -1,2 +1,4 @@ start.o: start.S - mips-linux-gnu-gcc -EL -march=mips32 -fno-pic -MMD -mno-abicalls -fno-delayed-branch -c start.S -o start.o + mips-linux-gnu-gcc -I$(AM_HOME)/am/arch/mips32-minimal/include -EL -march=mips32 -fno-pic -MMD -mno-abicalls -fno-delayed-branch -c start.S -o start.o + +-include start.d diff --git a/am/arch/mips32-minimal/img/boot/start.S b/am/arch/mips32-minimal/img/boot/start.S index a11a5bbd..86081361 100644 --- a/am/arch/mips32-minimal/img/boot/start.S +++ b/am/arch/mips32-minimal/img/boot/start.S @@ -1,6 +1,14 @@ +#include + .globl _start -.type _start, @function - +.type _start, function +.globl _ex_entry +.type _ex_entry, function + _start: la $sp, _stack_pointer j _trm_init + +.org EX_ENTRY +_ex_entry: + j _trap diff --git a/am/arch/mips32-minimal/include/npc.h b/am/arch/mips32-minimal/include/npc.h index 3355c81b..ca47bf75 100644 --- a/am/arch/mips32-minimal/include/npc.h +++ b/am/arch/mips32-minimal/include/npc.h @@ -1,8 +1,7 @@ #ifndef __NPC_H__ #define __NPC_H__ -#include - +#define EX_ENTRY 0x20 #define SERIAL_PORT ((volatile char *)0x40001000) #define Rx 0x0 #define Tx 0x04 @@ -11,6 +10,10 @@ #define GPIO_TRAP ((volatile char *)0x40000000) #define HZ 50000000 +#ifndef __ASSEMBLER__ + +#include + struct TrapFrame{ u32 at, v0,v1, @@ -23,3 +26,5 @@ struct TrapFrame{ void serial_init(); #endif + +#endif diff --git a/am/arch/mips32-minimal/src/trap.S b/am/arch/mips32-minimal/src/trap.S new file mode 100644 index 00000000..e34dcb25 --- /dev/null +++ b/am/arch/mips32-minimal/src/trap.S @@ -0,0 +1,4 @@ +.globl _trap +.type _trap function +_trap: + j _trap From 059e534d0a66a1cf652c9b0019bd12a0d812255c Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Wed, 31 May 2017 05:16:45 -0400 Subject: [PATCH 2/4] mips32-npc loader scripts --- am/arch/mips32-npc/img/boot/Makefile | 4 +++- am/arch/mips32-npc/img/boot/start.S | 16 +++++++++------- am/arch/mips32-npc/img/build | 12 ++++-------- am/arch/mips32-npc/img/loader.ld | 28 +++++++++++++++------------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/am/arch/mips32-npc/img/boot/Makefile b/am/arch/mips32-npc/img/boot/Makefile index 02ca299b..481b2dae 100644 --- a/am/arch/mips32-npc/img/boot/Makefile +++ b/am/arch/mips32-npc/img/boot/Makefile @@ -1,2 +1,4 @@ start.o: start.S - mips-linux-gnu-gcc -EL -march=mips32 -fno-pic -MMD -mno-abicalls -fno-delayed-branch -c start.S -o start.o + mips-linux-gnu-gcc -I$(AM_HOME)/am/arch/mips32-npc/include -EL -march=mips32 -fno-pic -MMD -mno-abicalls -fno-delayed-branch -c start.S -o start.o + +-include start.d diff --git a/am/arch/mips32-npc/img/boot/start.S b/am/arch/mips32-npc/img/boot/start.S index 5d7aef9b..1fb2b2ff 100644 --- a/am/arch/mips32-npc/img/boot/start.S +++ b/am/arch/mips32-npc/img/boot/start.S @@ -1,13 +1,15 @@ +.section loader, "x" .globl _start .type _start, @function -.globl _qemu -.type _qemu, @function -.extern _trm_init +.globl _ex_entry +.type _ex_entry, @function _start: li $sp, 0x17fffffc - jal _trm_init + la $k0, _trm_init + jr $k0 -_qemu: - nop - jal _trm_init +.org 0x20 +_ex_entry: + la $k0, _trap + jr $k0 diff --git a/am/arch/mips32-npc/img/build b/am/arch/mips32-npc/img/build index 5e8f71ec..b34a102a 100755 --- a/am/arch/mips32-npc/img/build +++ b/am/arch/mips32-npc/img/build @@ -6,13 +6,9 @@ shift bash -c "cd $DIR/boot && make" -mips-linux-gnu-ld -EL -T $DIR/loader.ld -e _start -o ${DEST}.o $DIR/boot/start.o --start-group $@ --end-group - -# generate COE -mips-linux-gnu-objdump -d ${DEST}.o > ${DEST}.code.txt -mips-linux-gnu-objcopy -O binary ${DEST}.o ${DEST}.bin -python $DIR/scripts/gen_bram_coe.py ${DEST}.bin ${DEST}.coe - -# check instructions +mips-linux-gnu-ld -EL -T $DIR/loader.ld -e _start -o ${DEST}.o $DIR/boot/start.o --start-group $@ --end-group && \ +mips-linux-gnu-objdump -d ${DEST}.o > ${DEST}.code.txt && \ +mips-linux-gnu-objcopy -O binary ${DEST}.o ${DEST}.bin && \ +python $DIR/scripts/gen_bram_coe.py ${DEST}.bin ${DEST}.coe && \ mips-linux-gnu-objdump -d ${DEST}.o | python $DIR/scripts/instr_check.py diff --git a/am/arch/mips32-npc/img/loader.ld b/am/arch/mips32-npc/img/loader.ld index 57bb5a26..91bad528 100644 --- a/am/arch/mips32-npc/img/loader.ld +++ b/am/arch/mips32-npc/img/loader.ld @@ -1,13 +1,15 @@ -SECTIONS -{ - . = 0x10000000; - .text : { *(.text) } - .data : { *(.data) } - __bss_start = . ; - .bss : { - *(.bss) - *(.scommon) - *(.sbss) - } - _end = . ; -} +MEMORY { + bram : ORIGIN = 0x0, LENGTH = 8K + ddr : ORIGIN = 0x10000000, LENGTH = 128M +} + +SECTIONS { + loader : { *(loader) } > bram + .text : { *(.text) } > ddr + .data : { *(.data) } > ddr + .bss : { + __bss_start = .; + *(.bss) + _end = . ; + } > ddr +} From 188e186906fa4e50e6639119099616dd9f771c50 Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Wed, 31 May 2017 05:30:19 -0400 Subject: [PATCH 3/4] change ld scripts --- am/arch/mips32-minimal/img/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/am/arch/mips32-minimal/img/build b/am/arch/mips32-minimal/img/build index 82f54201..bd1dd7f7 100755 --- a/am/arch/mips32-minimal/img/build +++ b/am/arch/mips32-minimal/img/build @@ -6,4 +6,4 @@ shift bash -c "cd $DIR/boot && make" -mips-linux-gnu-ld -EL -T $DIR/loader.ld -e _start -o $DEST $DIR/boot/start.o --start-group $@ --end-group && python $DIR/gen_coe.py $DEST +mips-linux-gnu-ld -EL -T $DIR/loader.ld -e _start -o $DEST $DIR/boot/start.o $@ && python $DIR/gen_coe.py $DEST From 0730dd6610dffd7b3cafb9998fa5da0fbfd488aa Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Wed, 31 May 2017 05:40:06 -0400 Subject: [PATCH 4/4] reduce output file size --- Makefile.lib | 2 ++ am/arch/mips32-minimal/img/build | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile.lib b/Makefile.lib index cae428d4..683a26f0 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -10,6 +10,8 @@ ARCHIVE ?= $(LIB_DIR)/build/$(NAME)-$(ARCH).a INC_DIR += $(addsuffix /include/, $(addprefix $(AM_HOME)/libs/, $(LIBS))) +CFLAGS += -fdata-sections -ffunction-sections + $(shell mkdir -p $(DST_DIR)) include $(AM_HOME)/Makefile.compile diff --git a/am/arch/mips32-minimal/img/build b/am/arch/mips32-minimal/img/build index bd1dd7f7..2a632c5b 100755 --- a/am/arch/mips32-minimal/img/build +++ b/am/arch/mips32-minimal/img/build @@ -6,4 +6,4 @@ shift bash -c "cd $DIR/boot && make" -mips-linux-gnu-ld -EL -T $DIR/loader.ld -e _start -o $DEST $DIR/boot/start.o $@ && python $DIR/gen_coe.py $DEST +mips-linux-gnu-ld --gc-sections -EL -T $DIR/loader.ld -e _start -o $DEST $DIR/boot/start.o $@ && python $DIR/gen_coe.py $DEST