[BUG][RV32E] Reserved x16-x31 encodings produce LSU side effects while taking an illegal-instruction trap
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- backend
调研方向
Start by locating the RV32E illegal-register decode and LSU request handling in the Ibex RTL; the issue does not name source files or tests. Reproduce with the provided assembly using RV32E=1 and WritebackStage=0, then trace whether the illegal-instruction exception suppresses the store. Done means the store’s memory side effect is absent when the exception is taken, or the project clarifies that this behavior is permitted.
由索引模型根据 Issue 内容生成。
描述
Ibex is an exceptionally valuable contribution to the open-source hardware community, providing a high-quality and accessible implementation for learning, research, and verification.
I sincerely appreciate the considerable effort that the developers and maintainers have invested in designing, documenting, and continuously improving this project. Thank you for making this work openly available to the community.
Summary
With Ibex configured as RV32E=1 and WritebackStage=0, instruction encodings that reference the unavailable registers x16 through x31 raise an Illegal Instruction exception, but LSU operations decoded from the same instruction are not uniformly canceled.
Dynamic testing shows that a store referencing x18 modifies memory while raising the exception.
The RISC-V RV32E specification defines encodings that reference x16 through x31 as reserved, while the base specification defines the behavior of reserved instructions as UNSPECIFIED.
Given that illegal_reg_16 explicitly causes Ibex to raise an Illegal Instruction exception, should an instruction rejected in this way also be prevented from committing decoded LSU side effects, as other illegal instructions are?
Tested revision and configuration
- Ibex commit:
f4515520c0045bb8ef1e72d46ed82499a6ac5f18 - Configuration:
RV32E=1,WritebackStage=0,RegFile=ibex_pkg::RegFileFF - Simulation platform:
ibex_simple_systemwith Verilator - Toolchain:
riscv64-unknown-elf-gcc 14.2.0 - Reference model: Spike commit
4c6a9bc79dab80616932949707e7c0471d8e9e54 - fusesoc:
$ fusesoc --version
2.4.3
Command used to build the Ibex model:
# repo
cd ibex
fusesoc --cores-root=. run --target=sim --setup --build \
--build-root=build/configs/illegal_store_side_effect \
lowrisc:ibex:ibex_simple_system \
--RV32E=1 --WritebackStage=0 --RegFile=ibex_pkg::RegFileFF
Reproduction
The test first initializes target_word to 0x11223344, then executes the raw instruction encoding 0x0122a023, which corresponds to sw x18, 0(x5). The trap handler checks mcause and then reads target_word to determine whether the store produced a side effect.
test.s
.option norvc
.section .text.init
.globl _start
_start:
la t0, trap_handler
csrw mtvec, t0
# Initialize the destination with a sentinel and give x2 a distinct value.
la t0, target_word
li t1, 0x11223344
sw t1, 0(t0)
li sp, 0x55667788
faulting_instruction:
# sw x18, 0(x5). x18 is unavailable in RV32E, so this encoding is reserved and must trap without performing the store.
.word 0x0122a023
li a0, 2
j finish
.section .trap, "ax"
.balign 256
trap_handler:
csrr t1, mcause
li a0, 3
li t2, 2
bne t1, t2, finish
# A precise illegal-instruction trap must leave memory unchanged.
la t0, target_word
lw t1, 0(t0)
li t2, 0x11223344
li a0, 1
bne t1, t2, finish
li a0, 0
finish:
# 1 means pass. Odd values greater than 1 encode failures.
slli a0, a0, 1
ori a0, a0, 1
la t0, tohost
sw a0, 0(t0)
# Ibex simple_system terminates on this MMIO write.
li t0, 0x20008
sw a0, 0(t0)
1:
j 1b
.section .data
.balign 4
target_word:
.word 0
link.ld
OUTPUT_ARCH(riscv)
ENTRY(_start)
MEMORY {
ram (rwx) : ORIGIN = 0x100000, LENGTH = 0x30000
}
SECTIONS {
. = ORIGIN(ram);
.vectors : { . = . + 0x80; } > ram
.text : { *(.text.init) *(.text*) } > ram
.trap : { *(.trap) } > ram
.data : { *(.data*) } > ram
.bss : { *(.bss*) *(COMMON) } > ram
tohost = 0x12fff0;
fromhost = 0x12fff8;
}
tohost |
Meaning |
|---|---|
1 |
The handler is entered, mcause=2, and memory remains unchanged |
3 |
The handler is entered and mcause=2, but memory has been modified |
5 |
No exception occurs and execution continues past the faulting instruction |
7 |
The handler is entered, but mcause is not 2 |
Compile the test case:
riscv64-unknown-elf-gcc -march=rv32e_zicsr -mabi=ilp32e -nostdlib -nostartfiles -static -Wl,-T,link.ld -Wl,--build-id=none \
-o ./build/test.elf ./test.s
Run Spike:
spike -m0x100000:0x30000 --isa=rv32e_zicsr --priv=mu --log-commits ./build/test.elf 2> spike.log
Run Ibex:
model=/path/to/ibex/build/configs/illegal_store_side_effect/lowrisc_ibex_ibex_simple_system_0/sim-verilator/Vibex_simple_system
"${model}" --term-after-cycles=1000 --meminit=ram,"/path/to/build/test.elf" |& tee ibex.log
Compare the Spike and Ibex results:
#!/usr/bin/env bash
set -euo pipefail
spike_tohost=$(sed -n 's/.*mem 0x0012fff0 0x\([0-9a-fA-F]*\).*/\1/p' "./spike.log" | tail -n 1)
ibex_tohost=$(sed -n 's/.*PA:0x0012fff0 store:0x\([0-9a-fA-F]*\).*/\1/p' "./trace_core_00000000.log" | tail -n 1)
printf 'Spike tohost: 0x%s (expected 0x00000001: pass)\n' "${spike_tohost}"
printf 'Ibex tohost: 0x%s (expected 0x00000003: memory side effect detected)\n' "${ibex_tohost}"
Both Spike and Ibex produce mcause=2 for this encoding. However, Spike preserves target_word=0x11223344 and writes tohost=1, whereas Ibex overwrites that memory location with 0 and writes tohost=3.
ibex.log:
Simulation running, end by pressing CTRL-c.
TOP.ibex_simple_system.u_top.u_ibex_tracer.unnamedblk2.unnamedblk3: Writing execution trace to trace_core_00000000.log
41: Illegal instruction (hart 0) at PC 0x001000a8: 0x0122a023
Terminating simulation by software request.
The Ibex trace_core_00000000.log also records the store and its architecturally visible result:
44 18 001000a8 0122a023 -->sw x0,0(x0) x0:0x00000000 x0:0x00000000 PA:0x00100204 store:0x00000000
64 28 00100118 0002a303 lw x6,0(x5) x5:0x00100204 x6=0x00000000 PA:0x00100204 load:0x00000000
88 40 00100140 00a2a023 sw x10,0(x5) x5:0x0012fff0 x10:0x00000003 PA:0x0012fff0 store:0x00000003
| Model | mcause |
target_word read by the handler |
tohost |
|---|---|---|---|
| Spike | 2 | 0x11223344 |
1 |
| Ibex | 2 | 0x00000000 |
3 |
Expected behavior / questions
I would appreciate clarification on the following point:
- When Ibex raises an illegal-instruction exception, is the faulting instruction expected to produce no LSU side effects?
If the project explicitly permits these reserved encodings to produce side effects before entering the trap handler, then the current behavior is an allowed implementation choice and this report can instead serve as a confirmation and record of that behavior rather than as a bug report.
- 主要语言
- SystemVerilog
- 星标
- 2.2k
- 派生
- 836
- 平均合并
- 5 天 8 小时
- 30 天内合并 PR
- 22
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
lowRISC/ibex 的其他 Issue
-
[Bug Report] rvfi_intr is not set on the first instruction of an exception handler可能已有人在做 @h-filali 于 7 天前认领。 未关闭Type:Bug
难度 2/5 半天 新手友好度 68/100
维护者通常 2 天内回复
-
Type:Bug
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
Type:Bug
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 2 天内回复
-
[doc] Document basic commands for running/checking Ibex可能已有人在做 @shrutikbalwan 于 47 天前认领。 未关闭Component:Doc Good First Issue Type:Task
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 2 天内回复
相似的 Issue
-
parse: child keys like `007`, `1e3`, `0x1f`, `-1` make the parent an empty array and hide the value未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
OCA/account-invoicing#2529 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
jlcodes99/cockpit-tools#3125 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
deadfin-org/deadfin#35 ·