[PATCH RFC 0/8] RISC-V: Experimental fetch support for 48-bit and 64-bit instructions

TANG Tiancheng posted 8 patches 4 days, 19 hours ago
disas/riscv.c                               |  49 ++++++---
disas/riscv.h                               |   4 +-
target/riscv/cpu.c                          |   6 +
target/riscv/cpu.h                          |  10 +-
target/riscv/cpu_cfg_fields.h.inc           |   1 +
target/riscv/insn_length.h                  |  29 +++++
target/riscv/internals.h                    |  17 +--
target/riscv/tcg/cpu_helper.c               |   7 +-
target/riscv/tcg/csr.c                      |   7 +-
target/riscv/tcg/insn_trans/trans_rvi.c.inc |   8 +-
target/riscv/tcg/op_helper.c                |  10 +-
target/riscv/tcg/translate.c                | 101 ++++++++++++-----
tests/tcg/riscv/zl/zl.S                     | 165 ++++++++++++++++++++++++++++
tests/tcg/riscv32/system/meson.build        |   9 ++
tests/tcg/riscv64/system/meson.build        |   9 ++
15 files changed, 359 insertions(+), 73 deletions(-)
[PATCH RFC 0/8] RISC-V: Experimental fetch support for 48-bit and 64-bit instructions
Posted by TANG Tiancheng 4 days, 19 hours ago
QEMU's RISC-V TCG implementation currently supports only 16-bit
compressed instructions and 32-bit instructions. This series adds
experimental support for fetching 48-bit and 64-bit instructions and
for halfword alignment, following Zl draft 65c377a [1].

This work is motivated in part by an AME proposal that encodes operand
datatypes in instructions and is still under evaluation [3]. Larger
immediates and longer-range direct calls are other uses under discussion
[1,2]. This series provides instruction-fetch, alignment and trap-reporting
support for long instructions, without implementing individual instruction
semantics.

The x-zl CPU property is disabled by default and supported only under
TCG. When enabled, the translator and built-in disassembler share the
length rules, and halfword alignment does not require C/Zca. Compressed
decoding remains disabled if C/Zca are disabled. Complete 48/64-bit
encodings still raise illegal-instruction exceptions, and the
disassembler prints "unknown".

For an undefined length, fetching stops after the third 16-bit parcel
and no instruction bits are reported. This avoids additional fetches
solely for trap reporting. Feedback on this choice would be useful.

Patch 1 fixes incomplete instruction reads in the disassembler and can
be taken independently of Zl support.

The code was built for RV32/RV64 user and system emulation. RV32/RV64
bare-metal tests check RAM-boundary fetches and trap values, halfword
jumps and returns, and rejection of compressed instructions with C/Zca
disabled. The Zl tests and existing MEPC regression passed with Capstone
enabled and disabled.

[1] https://github.com/riscv/riscv-long-instruction/blob/65c377a665feb29a4848384ad566a9873c5fd423/src/unpriv/zl.adoc
[2] https://github.com/riscv/riscv-isa-manual/pull/3269#issuecomment-5328426143
[3] https://riscv.atlassian.net/wiki/spaces/AMEX/pages/2445836308/2026-11-09+AME+Meeting+Notes

---
TANG Tiancheng (8):
      disas/riscv: Reject incomplete instruction reads
      target/riscv: Share instruction length helper
      target/riscv: Prepare Zl instruction alignment
      disas/riscv: Decode Zl instruction lengths
      target/riscv: Limit instruction bits to the trap CSR width
      target/riscv: Fetch 48-bit and 64-bit instructions
      target/riscv: Enable experimental Zl fetch support
      tests/tcg/riscv: Check Zl fetching and halfword alignment

 disas/riscv.c                               |  49 ++++++---
 disas/riscv.h                               |   4 +-
 target/riscv/cpu.c                          |   6 +
 target/riscv/cpu.h                          |  10 +-
 target/riscv/cpu_cfg_fields.h.inc           |   1 +
 target/riscv/insn_length.h                  |  29 +++++
 target/riscv/internals.h                    |  17 +--
 target/riscv/tcg/cpu_helper.c               |   7 +-
 target/riscv/tcg/csr.c                      |   7 +-
 target/riscv/tcg/insn_trans/trans_rvi.c.inc |   8 +-
 target/riscv/tcg/op_helper.c                |  10 +-
 target/riscv/tcg/translate.c                | 101 ++++++++++++-----
 tests/tcg/riscv/zl/zl.S                     | 165 ++++++++++++++++++++++++++++
 tests/tcg/riscv32/system/meson.build        |   9 ++
 tests/tcg/riscv64/system/meson.build        |   9 ++
 15 files changed, 359 insertions(+), 73 deletions(-)
---
base-commit: f29ccc287a6cfdd51d3a4fd17fbe9af3310a0ac5
change-id: 20261117-zl-master-8ebcaae0953f

Best regards,
-- 
TANG Tiancheng <lyndra@linux.alibaba.com>