From a7b54980bd409e708a8388452ccf3166759ca7ee Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Fri, 24 Jun 2016 11:27:39 -0700 Subject: [PATCH] nios2: set appropriate compiler flags for math support Nios II CPUs vary in configuration on whether they support 'mul', 'mulx', and 'div' family of instructions. The compiler can be told to use GCC integer library routines instead if needed. Ideally we would just pull the configuration out of system.h, but pulling include file #defines into the Make environment will involve some build system work that is best left to a later improvement. We've decided to take this build-time approach rather than handle unimplemented instruction exceptions, so remove the hook in exception.S Change-Id: I05be0d5ed4c1a49b23dca1550ee66fd5891044d2 Signed-off-by: Andrew Boie --- arch/nios2/Kconfig | 12 ++++++++++++ arch/nios2/Makefile | 18 ++++++++++++++++++ arch/nios2/core/exception.S | 10 ---------- arch/nios2/soc/nios2-qemu/Kconfig.soc | 3 +++ arch/nios2/soc/nios2f-zephyr/Kconfig.soc | 2 ++ 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig index 092926f952d..e036d7bd5f5 100644 --- a/arch/nios2/Kconfig +++ b/arch/nios2/Kconfig @@ -55,6 +55,18 @@ config IRQ_OFFLOAD Enable irq_offload() API which allows functions to be synchronously run in interrupt context. Mainly useful for test cases. +config HAS_MUL_INSTRUCTION + bool + default n + +config HAS_DIV_INSTRUCTION + bool + default n + +config HAS_MULX_INSTRUCTION + bool + default n + endmenu source "arch/nios2/soc/*/Kconfig" diff --git a/arch/nios2/Makefile b/arch/nios2/Makefile index 57b732f4fd3..9a95e18689c 100644 --- a/arch/nios2/Makefile +++ b/arch/nios2/Makefile @@ -9,6 +9,24 @@ arch_cflags := $(call cc-option,-G0) arch_cflags += $(call cc-option,-ffunction-sections) \ $(call cc-option,-fdata-sections) +# TODO Find a way to pull this out of system.h somehow +# instead of having Kconfig for it +ifdef CONFIG_HAS_MUL_INSTRUCTION +arch_cflags += -mhw-mul +else +arch_cflags += -mno-hw-mul +endif +ifdef CONFIG_HAS_MULX_INSTRUCTION +arch_cflags += -mhw-mulx +else +arch_cflags += -mno-hw-mulx +endif +ifdef CONFIG_HAS_DIV_INSTRUCTION +arch_cflags += -mhw-div +else +arch_cflags += -mno-hw-div +endif + # Nios II CPUs are configurable and we need to pull in the generated # headers system.h and linker.h which specify what is enabled and where # everything is. diff --git a/arch/nios2/core/exception.S b/arch/nios2/core/exception.S index a8ccdacff99..95968115f3e 100644 --- a/arch/nios2/core/exception.S +++ b/arch/nios2/core/exception.S @@ -26,7 +26,6 @@ GTEXT(_exception_enter_fault) /* import */ GTEXT(_Fault) GTEXT(_Swap) -GTEXT(_exception_try_muldiv) #ifdef CONFIG_IRQ_OFFLOAD GTEXT(_irq_do_offload) GTEXT(_offload_routine) @@ -189,15 +188,6 @@ BRANCH_LABEL(not_interrupt) bne r11, zero, is_interrupt #endif -#if 0 /* TODO: implement multiply/divide handling */ - /* Could be an unimplemented instruction we have to emulate. - * Smaller Nios II cores don't have multiply or divide instructions. - * This code comes back to either _exception_enter_fault or - * _exception_exit - */ - jmpi _exception_try_muldiv -#endif - SECTION_FUNC(exception.entry, _exception_enter_fault) /* If we get here, the exception wasn't in interrupt or an * unimplemented math instruction. Let _Fault() handle it in diff --git a/arch/nios2/soc/nios2-qemu/Kconfig.soc b/arch/nios2/soc/nios2-qemu/Kconfig.soc index 35e14fae9a3..3a80d01c00b 100644 --- a/arch/nios2/soc/nios2-qemu/Kconfig.soc +++ b/arch/nios2/soc/nios2-qemu/Kconfig.soc @@ -1,3 +1,6 @@ config SOC_NIOS2_QEMU bool "Nios II - Experimental QEMU emulation" + select HAS_MUL_INSTRUCTION + select HAS_DIV_INSTRUCTION + select HAS_MULX_INSTRUCTION diff --git a/arch/nios2/soc/nios2f-zephyr/Kconfig.soc b/arch/nios2/soc/nios2f-zephyr/Kconfig.soc index e10a79c767a..8cd5d7cb07b 100644 --- a/arch/nios2/soc/nios2f-zephyr/Kconfig.soc +++ b/arch/nios2/soc/nios2f-zephyr/Kconfig.soc @@ -1,3 +1,5 @@ config SOC_NIOS2F_ZEPHYR bool "Nios IIf - Zephyr Golden Configuration" + select HAS_MUL_INSTRUCTION + select HAS_DIV_INSTRUCTION