From 03e0510f546505e8a7bd631437db91355cdd583e Mon Sep 17 00:00:00 2001 From: davide schiavone Date: Fri, 9 Aug 2024 12:10:52 +0200 Subject: [PATCH 1/4] make linker folder a parameter --- Makefile | 10 ++++++---- sw/Makefile | 2 +- sw/device/lib/crt/vectors.S | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 905b2c6b3..e80cfd623 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,8 @@ endif # Project options are based on the app to be build (default - hello_world) PROJECT ?= hello_world +LINK_FOLDER ?= sw/linker + # Linker options are 'on_chip' (default),'flash_load','flash_exec','freertos' LINKER ?= on_chip @@ -111,7 +113,7 @@ mcu-gen: $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/core-v-mini-mcu/ --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --tpl-sv hw/core-v-mini-mcu/core_v_mini_mcu.sv.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/system/ --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --tpl-sv hw/system/x_heep_system.sv.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir sw/device/lib/runtime --cpu $(CPU) --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --external_domains $(EXTERNAL_DOMAINS) --header-c sw/device/lib/runtime/core_v_mini_mcu.h.tpl - $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir sw/linker --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --linker_script sw/linker/link.ld.tpl + $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir $(LINK_FOLDER) --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --linker_script $(LINK_FOLDER)/link.ld.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir . --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --pkg-sv ./core-v-mini-mcu.upf.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir . --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --pkg-sv ./core-v-mini-mcu.dc.upf.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/ip/power_manager/rtl --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --external_domains $(EXTERNAL_DOMAINS) --pkg-sv hw/ip/power_manager/data/power_manager.sv.tpl @@ -121,8 +123,8 @@ mcu-gen: $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/system/pad_control/data --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --external_pads $(EXT_PAD_CFG) --pkg-sv hw/system/pad_control/data/pad_control.hjson.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/system/pad_control/rtl --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --external_pads $(EXT_PAD_CFG) --pkg-sv hw/system/pad_control/rtl/pad_control.sv.tpl bash -c "cd hw/system/pad_control; source pad_control_gen.sh; cd ../../../" - $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir sw/linker --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --linker_script sw/linker/link_flash_exec.ld.tpl - $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir sw/linker --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --linker_script sw/linker/link_flash_load.ld.tpl + $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir $(LINK_FOLDER) --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --linker_script $(LINK_FOLDER)/link_flash_exec.ld.tpl + $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir $(LINK_FOLDER) --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --linker_script $(LINK_FOLDER)/link_flash_load.ld.tpl $(PYTHON) ./util/structs_periph_gen.py $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/fpga/ --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --tpl-sv hw/fpga/sram_wrapper.sv.tpl $(PYTHON) util/mcu_gen.py --config $(X_HEEP_CFG) --cfg_peripherals $(MCU_CFG_PERIPHERALS) --pads_cfg $(PAD_CFG) --outdir hw/fpga/scripts/ --bus $(BUS) --memorybanks $(MEMORY_BANKS) --memorybanks_il $(MEMORY_BANKS_IL) --tpl-sv hw/fpga/scripts/generate_sram.tcl.tpl @@ -147,7 +149,7 @@ verible: ## @param COMPILER_PREFIX=riscv32-unknown-(default) ## @param ARCH=rv32imc(default), app: clean-app - $(MAKE) -C sw PROJECT=$(PROJECT) TARGET=$(TARGET) LINKER=$(LINKER) COMPILER=$(COMPILER) COMPILER_PREFIX=$(COMPILER_PREFIX) ARCH=$(ARCH) SOURCE=$(SOURCE) \ + $(MAKE) -C sw PROJECT=$(PROJECT) TARGET=$(TARGET) LINKER=$(LINKER) LINK_FOLDER=$(LINK_FOLDER) COMPILER=$(COMPILER) COMPILER_PREFIX=$(COMPILER_PREFIX) ARCH=$(ARCH) SOURCE=$(SOURCE) \ || { \ echo "\033[0;31mHmmm... seems like the compilation failed...\033[0m"; \ echo "\033[0;31mIf you do not understand why, it is likely that you either:\033[0m"; \ diff --git a/sw/Makefile b/sw/Makefile index a36f5ead2..e327138b5 100644 --- a/sw/Makefile +++ b/sw/Makefile @@ -59,7 +59,7 @@ $(info $$You are fetching sources from $(source_path) ) SOURCE_PATH = $(source_path)/ ROOT_PROJECT = $(mkfile_path)/ INC_FOLDERS = $(mkfile_path)/device/target/$(TARGET)/ -LINK_FOLDER = $(mkfile_path)/linker +LINK_FOLDER ?= $(mkfile_path)/linker # CMake keyword CMAKE_DIR=cmake diff --git a/sw/device/lib/crt/vectors.S b/sw/device/lib/crt/vectors.S index f6a805c65..f4497af44 100644 --- a/sw/device/lib/crt/vectors.S +++ b/sw/device/lib/crt/vectors.S @@ -126,6 +126,7 @@ new vector table (which is at mtvec) */ .section .text.vecs /* exception handling */ +.globl __no_irq_handler __no_irq_handler: la a0, no_exception_handler_msg jal ra, puts @@ -144,21 +145,25 @@ sw_irq_handler: beq t0, t1, handle_ebreak j handle_unknown +.globl handle_ecall handle_ecall: la a0, ecall_msg jal ra, puts j end_handler +.globl handle_ebreak handle_ebreak: la a0, ebreak_msg jal ra, puts j end_handler +.globl handle_illegal_insn handle_illegal_insn: la a0, illegal_insn_msg jal ra, puts j end_handler +.globl handle_unknown handle_unknown: la a0, unknown_msg jal ra, puts From a551fe89437baa63485d0424b4ad2305089b5814 Mon Sep 17 00:00:00 2001 From: davide schiavone Date: Fri, 9 Aug 2024 12:39:44 +0200 Subject: [PATCH 2/4] removed unused routines --- sw/device/lib/crt/vectors.S | 12 ------------ sw/device/lib/crt/vectors_freertos.S | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/sw/device/lib/crt/vectors.S b/sw/device/lib/crt/vectors.S index f4497af44..81c14957f 100644 --- a/sw/device/lib/crt/vectors.S +++ b/sw/device/lib/crt/vectors.S @@ -133,18 +133,6 @@ __no_irq_handler: j __no_irq_handler -sw_irq_handler: - csrr t0, mcause - slli t0, t0, 1 /* shift off the high bit */ - srli t0, t0, 1 - li t1, 2 - beq t0, t1, handle_illegal_insn - li t1, 11 - beq t0, t1, handle_ecall - li t1, 3 - beq t0, t1, handle_ebreak - j handle_unknown - .globl handle_ecall handle_ecall: la a0, ecall_msg diff --git a/sw/device/lib/crt/vectors_freertos.S b/sw/device/lib/crt/vectors_freertos.S index 3596dc186..17654b935 100644 --- a/sw/device/lib/crt/vectors_freertos.S +++ b/sw/device/lib/crt/vectors_freertos.S @@ -132,18 +132,6 @@ __no_irq_handler: jal ra, puts j __no_irq_handler -sw_irq_handler: - csrr t0, mcause - slli t0, t0, 1 /* shift off the high bit */ - srli t0, t0, 1 - li t1, 2 - beq t0, t1, handle_illegal_insn - li t1, 11 - beq t0, t1, handle_ecall - li t1, 3 - beq t0, t1, handle_ebreak - j handle_unknown - handle_ecall: la a0, ecall_msg jal ra, puts From d4ea21db54f0ecd81c7070ac892cb890f7380728 Mon Sep 17 00:00:00 2001 From: davide schiavone Date: Fri, 9 Aug 2024 12:52:24 +0200 Subject: [PATCH 3/4] fix Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e80cfd623..c195242de 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ endif # Project options are based on the app to be build (default - hello_world) PROJECT ?= hello_world -LINK_FOLDER ?= sw/linker +LINK_FOLDER ?= $(mkfile_path)/sw/linker # Linker options are 'on_chip' (default),'flash_load','flash_exec','freertos' LINKER ?= on_chip From de66b36127cacc6b60dd2a3f098af6e79c186e25 Mon Sep 17 00:00:00 2001 From: davide schiavone Date: Fri, 9 Aug 2024 14:41:24 +0200 Subject: [PATCH 4/4] removed deadcode --- sw/device/lib/crt/vectors.S | 19 ------------------- sw/device/lib/crt/vectors_freertos.S | 15 --------------- 2 files changed, 34 deletions(-) diff --git a/sw/device/lib/crt/vectors.S b/sw/device/lib/crt/vectors.S index 81c14957f..8e573eefd 100644 --- a/sw/device/lib/crt/vectors.S +++ b/sw/device/lib/crt/vectors.S @@ -132,25 +132,6 @@ __no_irq_handler: jal ra, puts j __no_irq_handler - -.globl handle_ecall -handle_ecall: - la a0, ecall_msg - jal ra, puts - j end_handler - -.globl handle_ebreak -handle_ebreak: - la a0, ebreak_msg - jal ra, puts - j end_handler - -.globl handle_illegal_insn -handle_illegal_insn: - la a0, illegal_insn_msg - jal ra, puts - j end_handler - .globl handle_unknown handle_unknown: la a0, unknown_msg diff --git a/sw/device/lib/crt/vectors_freertos.S b/sw/device/lib/crt/vectors_freertos.S index 17654b935..c4586b300 100644 --- a/sw/device/lib/crt/vectors_freertos.S +++ b/sw/device/lib/crt/vectors_freertos.S @@ -132,21 +132,6 @@ __no_irq_handler: jal ra, puts j __no_irq_handler -handle_ecall: - la a0, ecall_msg - jal ra, puts - j end_handler - -handle_ebreak: - la a0, ebreak_msg - jal ra, puts - j end_handler - -handle_illegal_insn: - la a0, illegal_insn_msg - jal ra, puts - j end_handler - handle_unknown: la a0, unknown_msg jal ra, puts