Skip to content

riscv: reject odd instruction addresses at fetch time - #2394

Open
carlosqwqqwq wants to merge 1 commit into
unicorn-engine:masterfrom
carlosqwqqwq:fix/riscv-odd-pc-reject
Open

riscv: reject odd instruction addresses at fetch time#2394
carlosqwqqwq wants to merge 1 commit into
unicorn-engine:masterfrom
carlosqwqqwq:fix/riscv-odd-pc-reject

Conversation

@carlosqwqqwq

@carlosqwqqwq carlosqwqqwq commented Aug 12, 2026

Copy link
Copy Markdown

riscv: reject odd instruction addresses at fetch time

Fixes #2390

Problem

IALIGN=16 forbids instruction addresses with bit 0 set (even with the C extension). Unicorn accepts an externally supplied odd PC at the emulator entry and fetches at that address; branch-target checks in trans_rvi.inc.c do not cover the entry path.

Change

qemu/target/riscv/translate.c riscv_tr_translate_insn: when ctx->base.pc_next & 1, raise RISCV_EXCP_INST_ADDR_MIS (through gen_exception_inst_addr_mis, which also records the address in mtval) before any fetch. The proposed change is source-only and contains no test-framework or repository-local changes.

Regression scope

Verify that starting at an odd PC raises the instruction-address-misaligned exception on both C and non-C models, that even-PC starts and all legal compressed/32-bit streams are unaffected, and that existing tests remain unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RISC-V: execution starts from an odd PC (IALIGN=16 violation)

1 participant