Skip to content

Commit 86c45b7

Browse files
Dino-Licarlescufi
authored andcommitted
soc: it8xxx2: The "M" extension is disabled by default
There is a mul instruction bug. The bug may cause instructions of writing back CPU GPR (e.g mv a0,s2) which following the mul instruction to fail. This patch disables the 'M' extension and overwrite integer multiplication and division arithmetic library routines with using hardware multiplication and division and nop instructions. This will ensure that there is no write back GPR instruction to follow mul instruction to avoid the bug. Signed-off-by: Dino Li <[email protected]>
1 parent bf21e84 commit 86c45b7

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

soc/riscv/riscv-ite/it8xxx2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
zephyr_sources(
22
soc.c
33
)
4+
zephyr_library_sources_ifndef(CONFIG_RISCV_ISA_EXT_M __arithmetic.S)
45

56
# IMPORTANT:
67
# The h2ram section must be first added to RAM_SECTIONS to avoid gap.

soc/riscv/riscv-ite/it8xxx2/Kconfig.series

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
config SOC_SERIES_RISCV32_IT8XXX2
55
bool "ITE IT8XXX2 implementation"
66
#depends on RISCV
7-
select CPU_HAS_FPU
7+
# TODO:
8+
# Error of can't link soft-float modules with single-float modules.
9+
# No library built with -mabi=ilp32f -march=rv32iafc?
10+
select CPU_HAS_FPU if RISCV_ISA_EXT_M
811
select SOC_FAMILY_RISCV_ITE
912
help
1013
Enable support for ITE IT8XXX2

soc/riscv/riscv-ite/it8xxx2/Kconfig.soc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ config SOC_IT8XXX2
1010
select RISCV
1111
select ATOMIC_OPERATIONS_BUILTIN
1212
select RISCV_ISA_RV32I
13-
select RISCV_ISA_EXT_M
13+
# Workaround mul instruction bug, see:
14+
# https://www.ite.com.tw/uploads/product_download/it81202-bx-chip-errata.pdf
15+
#select RISCV_ISA_EXT_M
1416
select RISCV_ISA_EXT_A
1517
select RISCV_ISA_EXT_C
1618

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2022 ITE Corporation.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* When the 'M' extension is disabled, compiler can not recognize div/mul
6+
* instructions. So mul/div instructions in the below integer arithmetic
7+
* routines are hard coded by opcodes.
8+
*
9+
* IMPORTANT:
10+
* The workaround requires the nop instruction, please don't optimize it.
11+
*/
12+
13+
.macro __int_arithmetic func opcode
14+
.section .__ram_code
15+
.align 2
16+
.globl \func
17+
.type \func, @function
18+
\func:
19+
.word \opcode
20+
nop
21+
ret
22+
.size \func, .-\func
23+
.endm
24+
25+
/* signed 32 bit multiplication. opcode of mul a0,a0,a1 is 0x02b50533 */
26+
__int_arithmetic __mulsi3 0x02b50533
27+
28+
/* signed 32 bit division. opcode of div a0,a0,a1 is 0x02b54533 */
29+
__int_arithmetic __divsi3 0x02b54533
30+
31+
/* unsigned 32 bit division. opcode of divu a0,a0,a1 is 0x02b55533 */
32+
__int_arithmetic __udivsi3 0x02b55533
33+
34+
/*
35+
* This function return the remainder of the signed division.
36+
* opcode of rem a0,a0,a1 is 0x02b56533
37+
*/
38+
__int_arithmetic __modsi3 0x02b56533
39+
40+
/*
41+
* This function return the remainder of the unsigned division.
42+
* opcode of remu a0,a0,a1 is 0x02b57533
43+
*/
44+
__int_arithmetic __umodsi3 0x02b57533

0 commit comments

Comments
 (0)