Skip to content

[ot] Merge core QEMU and RISC-V improvements for OpenTitan - #338

Closed
siemen11 wants to merge 9 commits into
lowRISC:ot-10.2.0from
siemen11:merge-qemu-core
Closed

siemen11 wants to merge 9 commits into
lowRISC:ot-10.2.0from
siemen11:merge-qemu-core

Conversation

@siemen11

Copy link
Copy Markdown

Merge the remaining 8 commits from sasdf/qemu-ot:qemu-prototype that touch upstream QEMU core/TCG/RISC-V/PLIC/meson files (companion to #337):

  • 795241b2 [ot] build: meson: add qemu-system-riscv32-cov and gcno packaging
  • a48dffd2 [ot] accel/tcg: icount: add exact freq, warp clamp, and idle check
  • 39e8a477 [ot] accel/tcg: cputlb: support sub-page offsets and empty-TLB hit
  • 71f7a46a [ot] system: memory: align sub-word accesses to access_size_min
  • e47fa82a [ot] target/riscv: pmp: flush TB on CSR write and enforce sub-page TLB
  • c9b54cc7 [ot] target/riscv: ibex: add NMI delivery and mstack CSR save/restore
  • 7522dbcc [ot] target/riscv: ibex: add double-fault alert, crash dump, and WFI
  • bb7adc9b [ot] hw/intc: sifive_plic: align claim, level IRQ, and TL-UL with RTL

sasdf and others added 9 commits October 30, 2026 14:39
Build a gcov-instrumented QEMU binary (qemu-system-riscv32-cov) linked
against --coverage static libraries (libsystem-ot-cov.a and
libqemu-riscv32-softmmu-ot-cov.a) for the riscv32-softmmu target, and
package qemu-system-riscv32-cov together with its .gcno note files in
scripts/opentitan/make_release.sh so Bazel test runs can collect host
hardware model line/branch coverage.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I6af52fbd3d1537704e491b047b41ac1d6a6a6964
Support exact non-power-of-two CPU clock frequencies and deterministic
sleep/idle virtual clock warping in TCG icount mode for OpenTitan
Earlgrey:

- Add icount_set_freq_hz() and update icount_to_ns() / icount_round()
  to use muldiv64() against icount_freq_hz when set, avoiding
  power-of-two icount_time_shift rounding drift relative to 24 MHz /
  500 kHz peripheral clocks.
- Add icount_get_cycles() and icount_advance_bias_ns() to track total
  elapsed CPU cycles (executed instructions plus idle warp and host I/O
  poll bias).
- Clamp warp_delta in icount_warp_rt() to the nearest non-external
  QEMU_CLOCK_VIRTUAL timer deadline so idle time warps never overshoot
  scheduled virtual timer expirations.
- Treat cpu->disabled as idle in cpu_thread_is_idle() so QEMU_CLOCK_VIRTUAL
  warps forward to AON wakeup timer deadlines while the Ibex core is
  powered down in deep sleep.
- Configure icount_set_freq_hz(24 MHz / 500 kHz) in Earlgrey AST
  initialization (ot_eg_soc_ast_configure).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I4ceb2556ebaa94e832a702d3331617426a6a6964
Support sub-page (< 4 KiB) address translation offsets and instruction
fetches required by OpenTitan's Ibex address translation (ot_vmapper)
and sub-page ePMP regions:

- Check tlb_entry_is_empty() in tlb_hit_page_mask_anyprot() and mask
  with TARGET_PAGE_MASK so empty TLB entries (-1) do not falsely match
  sub-page masked TLB invalidations.
- Preserve the intra-page offset delta
  ((full->phys_addr & ~TARGET_PAGE_MASK) - (addr & ~TARGET_PAGE_MASK))
  in tlb_set_page_full() and use addition in io_failed() so sub-page
  NAPOT windows remapped to different intra-page offsets translate
  accurately.
- Allow get_page_addr_code_hostp() to resolve host code pointers when
  full->lg_page_size < TARGET_PAGE_BITS so instruction fetches inside
  sub-page ePMP and vmapper regions execute without faulting.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Iefd28c41c65b315d9a80f6c8199fe0bb6a6a6964
In access_with_adjusted_size(), when a sub-word access (size < access_size,
such as an 8-bit or 16-bit access to a MemoryRegion with
valid.min_access_size = 1 and impl.min_access_size = 4) targets a
little-endian device, align the dispatch address to the containing word
(addr - byte_off), shift by -(byte_off * 8), and pass the byte-lane
mask MAKE_64BIT_MASK(byte_off * 8, size * 8).

Without this alignment and shift, sub-word reads/writes at non-zero
intra-word offsets (+1, +2, +3) pass unaligned offsets with shift = 0
and a full 32-bit access_mask to the 32-bit MMIO handler, returning
wrong byte lanes on sub-word reads and mis-evaluating TL-UL sub-word
write permit masks.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ie88da62f10dbe52772e2078c828304cc6a6a6964
When software updates pmpcfg, pmpaddr, or mseccfg CSRs, tlb_flush() alone
does not invalidate already-translated TCG blocks in the current page, and
multi-instruction TBs can cross 4-byte sub-page ePMP boundaries.

- Call queue_tb_flush(env_cpu(env)) alongside tlb_flush() in
  pmpcfg_csr_write(), pmpaddr_csr_write(), and mseccfg_csr_write().
- Limit DisasContext max_insns to 1 in riscv_tr_init_disas_context() when
  pmp_get_tlb_size(env, ctx->base.pc_first) == 1.
- Add env->tlb_subpage and enforce tlb_size = 1 in riscv_cpu_tlb_fill()
  when tlb_subpage or sub-page address translation is active.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ie467ca9827763118aa7e8c7b2eeb4a0d6a6a6964
Earlgrey's Ibex core (ibex_controller.sv and ibex_cs_registers.sv)
implements custom Non-Maskable Interrupt (NMI) handling rather than the
ratified Smrnmi extension:
- External NMI (irq 31, mcause 0x8000001f) and internal NMI causes
  (cause 0..30, mcause 0xffffffe0 | cause) both vector to mtvec + 31 * 4.
- Entering an NMI saves mstatus.{mpie,mpp}, mepc, and mcause into internal
  mstack shadow CSRs and asserts nmi_mode, masking all further interrupts
  and nested NMIs until MRET.
- Executing MRET while in nmi_mode restores mstatus.{mpie,mpp}, mepc, and
  mcause from mstack, exits nmi_mode, and re-evaluates pending interrupts.

Add riscv_cpu_set_rnmi_int(), mstack/nmi_mode state tracking in
riscv_cpu_do_interrupt() and helper_mret(), and WFI wake on rnmip.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I4a014d5e33ac0f5804e4a58c5fb75b5d6a6a6964
Model Earlgrey Ibex core crash dump and pipeline stall state
(ibex_core.sv and ibex_controller.sv):
- Track synchronous exception nesting (sync_exc_seen) across traps and
  MRET; when a second synchronous fault occurs before MRET, latch
  double_fault_seen, preserve prev_exception_pc/prev_exception_addr, and
  halt the CPU.
- Track WFI instruction PC (wfi_pc) and the preceding store address
  (last_data_addr) in helper_wfi() so resets triggered during WFI report
  accurate current_pc, next_pc, and mdaa in rstmgr's CPU_INFO dump.
- Implement riscv_cpu_get_crash_dump() (8-word crash dump state) and
  riscv_cpu_stall_on_unclocked_mmio() for bus accesses to clock-gated
  peripherals.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I9fe781b5536cb36ad107efbd25b973f66a6a6964
Align `hw/intc/sifive_plic.c` with OpenTitan Earlgrey `rv_plic` RTL
(`rv_plic_target.sv` and `rv_plic_reg_top.sv`):
- Allow `CC0` claim reads (`sifive_plic_claimed(..., ignore_threshold =
  true)`) to claim the highest-priority enabled and pending interrupt
  even when `prio <= THRESHOLD0`, while keeping `THRESHOLD0` gating on
  the external `MEIP` line (`ignore_threshold = false`).
- Track claimed state (`sifive_plic_is_claimed()`) so level-triggered
  IRQs are not re-marked pending while claimed, and re-set `IP` upon
  `CC0` completion write (masked to `src_bits`) when the input level
  remains high.
- Allow 2-bit WARL writes to `PRIO0`, mask unimplemented upper bits in
  the last `IE` word (`(1u << (num_sources & 31)) - 1u`), and check
  `pending_base` against `bitfield_words << 2`.
- Implement `sifive_plic_accepts()` to enforce `RV_PLIC_PERMIT` sub-word
  byte-enable rules and raise TL-UL access faults on unmapped offsets.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I59b5a09073e5466cdaa19fe09d00edb36a6a6964
Remove the removed flash_storage_ ML-DSA test target aliases and replace
print_flash_storage_mldsa_certs_overlapped_test_sim_qemu_rom_ext with
print_mldsa_certs_overlapped_test_sim_qemu_rom_ext following OpenTitan
commit c21599172c.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
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.

2 participants