arm: add SDIV/UDIV emulation for ARMv7 processors
PATCH 1/1 arm: add SDIV/UDIV emulation for ARMv7 processors
The Virtualization Extensions introduce the requirement for an ARMv7-A implementation to include SDIV and UDIV. Any implementation of the Virtualization Extensions must include the SDIV and UDIV instructions in the Thumb and ARM instruction sets.
In an ARMv7-A implementation that does not include the Virtualization Extensions, it is IMPLEMENTATION DEFINED whether:
* SDIV and UDIV are not implemented * SDIV and UDIV are implemented only in the Thumb instruction set * SDIV and UDIV are implemented in the Thumb and ARM instruction sets.
This patch adds a handler to trap and emulate unimplemented SDIV and UDIV instructions in ARM and Thumb modes. Also some basic statistic is exported via /proc/cpu/idiv_emulation
--- arch/arm/kernel/Makefile | 1 + arch/arm/kernel/idiv_emulate.c | 194 ++++++++++++++++++++++++++++++++++++++++ arch/arm/mm/Kconfig | 26 ++++++ 3 files changed, 221 insertions(+), 0 deletions(-) create mode 100644 arch/arm/kernel/idiv_emulate.c
arch/arm/kernel/Makefile +1 -0
@@ -62,6 +62,7 @@ obj-$(CONFIG_OF) += devtree.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_SWP_EMULATE) += swp_emulate.o CFLAGS_swp_emulate.o := -Wa,-march=armv7-a +obj-$(CONFIG_IDIV_EMULATE) += idiv_emulate.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_CPU_XSCALE) += xscale-cp0.o
arch/arm/kernel/idiv_emulate.c new file +195 -0
195 lines not on this page · raw message
arch/arm/mm/Kconfig +26 -0
@@ -651,6 +651,32 @@ config SWP_EMULATE If unsure, say Y. +config IDIV_EMULATE + bool "Emulate SDIV/UDIV instructions" + depends on !CPU_USE_DOMAINS && CPU_V7 + select HAVE_PROC_CPU if PROC_FS + default y if SMP + help + + The Virtualization Extensions introduce the requirement for an + ARMv7-A implementation to include SDIV and UDIV. Any + implementation of the Virtualization Extensions must include + the SDIV and UDIV instructions in the Thumb and ARM + instruction sets. + + In an ARMv7-A implementation that does not include the + Virtualization Extensions, it is IMPLEMENTATION DEFINED whether: + * SDIV and UDIV are not implemented + * SDIV and UDIV are implemented only in the Thumb instruction set + * SDIV and UDIV are implemented in the Thumb and ARM + instruction sets. + + This option allows to handle exeptions due to unimplemented + SDIV and UDIV instructions in ARM and Thumb modes. + + If unsure, say Y. + + config CPU_BIG_ENDIAN bool "Build big-endian kernel" depends on ARCH_SUPPORTS_BIG_ENDIAN
--
1.7.8.6
PATCH 1/1 arm: add SDIV/UDIV emulation for ARMv7 processors
Quoted 10 lines · Vladimir Murzin
The Virtualization Extensions introduce the requirement for an ARMv7-A implementation to include SDIV and UDIV. Any implementation of the Virtualization Extensions must include the SDIV and UDIV instructions in the Thumb and ARM instruction sets.
In an ARMv7-A implementation that does not include the Virtualization Extensions, it is IMPLEMENTATION DEFINED whether:
* SDIV and UDIV are not implemented * SDIV and UDIV are implemented only in the Thumb instruction set * SDIV and UDIV are implemented in the Thumb and ARM instruction sets.
We don't want to do emulation of instructions in the kernel because it's slow. It's far better for userspace to figure this stuff out itself and select appropriate libraries and instructions to use than to have the CPU take an exception, have to save a lot of state, and then emulate the instruction.
We learnt that with the old FPA emulation code. We're not making the same mistake again.
If there's a problem with that, the folk to complain to are at ARM Ltd for this "implementation defined" madness when it comes to instructions.
PATCH 1/1 arm: add SDIV/UDIV emulation for ARMv7 processors
Quoted 12 lines · Russell King - ARM Linux
Quoted 10 lines · Vladimir Murzin
The Virtualization Extensions introduce the requirement for an ARMv7-A implementation to include SDIV and UDIV. Any implementation of the Virtualization Extensions must include the SDIV and UDIV instructions in the Thumb and ARM instruction sets.
In an ARMv7-A implementation that does not include the Virtualization Extensions, it is IMPLEMENTATION DEFINED whether:
* SDIV and UDIV are not implemented * SDIV and UDIV are implemented only in the Thumb instruction set * SDIV and UDIV are implemented in the Thumb and ARM instruction sets.
Quoted 5 lines
We don't want to do emulation of instructions in the kernel because it's slow. It's far better for userspace to figure this stuff out itself and select appropriate libraries and instructions to use than to have the CPU take an exception, have to save a lot of state, and then emulate the instruction.
I added some hwcaps for precisely this purpose. Please see idiva and idivt.
Will