Episode 01 only proved reset, UART TX and LED. Episode 02 brings the CVE2 trap and interrupt entries up for real: four CSR readbacks, three synchronous exceptions and three local interrupt sources, each printed as PASS on the UART.
The point is not another blinking LED. It is to prove that CVE2's mtvec, mepc, mcause, mstatus, mie and a minimal CLINT close the loop on one board: exceptions enter, record and return; interrupts pend, fire and clear.
After JTAG programming, /dev/ttyUSB0 prints the complete test result. The last line is RESULT: PASS with no FAIL item:
CASE csr mscratch=5a5a1234 PASS
CASE csr mie=00000888 PASS
CASE csr mstatus.MIE=00000001 PASS
CASE csr mtvec=00000101 PASS
EP02 CVE2 TRAP/IRQ TEST
mtvec=00000100
CASE ecall mcause=0000000b mepc=00000704 PASS
CASE ebreak mcause=00000003 mepc=00000728 PASS
CASE illegal mcause=00000002 mepc=0000074c PASS
CASE timer count=00000001 mcause=80000007 PASS
CASE software count=00000001 mcause=80000003 PASS
CASE external count=00000001 mcause=8000000b PASS
counts exc=00000001 timer=00000001 sw=00000001 ext=00000001
RESULT: PASS
The four CSR checks run before the exception tests, so the CSR lines appear first and the banner follows. That is the firmware's real order, not a re-ordered transcript.
| Group | Test | Expected | Observed | Result |
|---|---|---|---|---|
| CSR | mscratch write 0x5a5a1234, read back | 0x5a5a1234 | 0x5a5a1234 | PASS |
| CSR | mie write 0x888, read back | 0x888 | 0x00000888 | PASS |
| CSR | mstatus.MIE set, read back | 1 | 1 | PASS |
| CSR | mtvec readback | base 0x100, MODE=1 | 0x00000101 | PASS |
| Exception | ecall | mcause=11 | 0x0000000b | PASS |
| Exception | ebreak (32-bit) | mcause=3 | 0x00000003 | PASS |
| Exception | Illegal instruction 0x00000000 | mcause=2 | 0x00000002 | PASS |
| Interrupt | Timer IRQ 7 | mcause=0x80000007 | 0x80000007 | PASS |
| Interrupt | Software IRQ 3 | mcause=0x80000003 | 0x80000003 | PASS |
| Interrupt | External IRQ 11 (CLINT injected) | mcause=0x8000000b | 0x8000000b | PASS |
The timer interval is mtime + 50000, about 1 ms at 50 MHz. Each interrupt count is 1, so each source fires once, clears its pending bit and does not retrigger.
CVE2's mtvec is forced vectored (MODE=1). Exceptions enter at base; interrupts enter at base + irq_id*4. The firmware puts the table at 0x100:
| Entry | Address | Purpose |
|---|---|---|
| exception | 0x100 | ecall / ebreak / illegal |
| software IRQ 3 | 0x10c | msip injected |
| timer IRQ 7 | 0x11c | mtime >= mtimecmp |
| external IRQ 11 | 0x12c | ext_pending injected |
The CLINT implements only the registers needed for this test: mtime low/high, mtimecmp low/high, msip, an external pending bit and an IRQ status word. No full 64-bit timer rollover test and no real peripheral interrupt source.
| Item | Value | Utilization |
|---|---|---|
| Slice LUTs | 3,295 | 15.84% |
| Slice Registers | 2,554 | 6.14% |
| Block RAM Tile | 8 | 16.00% |
| DSPs | 11 | 12.22% |
| Bonded IOB | 4 | 1.60% |
| WNS / WHS | 2.340 ns / 0.132 ns | TNS / THS = 0, failing endpoints 0 |
Versus episode 01, LUTs rise from 3,170 to 3,295 (+125) and registers from 2,397 to 2,554; BRAM and DSP are unchanged. Bitstream: top_cve2_ep02.bit, 2,192,137 bytes.
Register as Latch (<0.01%). There is no explicit latch in the design, and timing and function both pass; the item is recorded for later clean-up.hello cve2. The INIT_FILE in top_cve2_ep02.sv still pointed at episode 01's firmware.hex, so the bitstream carried the old image. Pointing it at EP02's hex and rebuilding produced EP02 CVE2 TRAP/IRQ TEST. Always check the UART banner..align 8 is not 8 bytes: the RISC-V assembler treats .align 8 as 2^8 = 256-byte alignment, so .trap_vector overlapped .text. .balign 4 gives 4-byte alignment.mtimecmp only wrote its lowest byte: the first decode used 0x08/0x09/0x0a/0x0b, but a word store only hits 0x08, leaving the upper three bytes unwritten. The fix writes all four bytes from be[0..3] inside 0x08.c.ebreak derailed mepc: with -march=rv32imc, GCC emitted 2-byte c.ebreak; the handler blindly added 4 to mepc, resumed mid-instruction and took a second illegal trap. The test firmware now uses rv32im and an explicit 32-bit 0x00100073.rdata could change after the address and before rvalid; latch it on req.riscv-nuclei-elf-gcc (GCC 10.2).cd sw && make clean && make; confirm firmware.hex is updated.INIT_FILE in top_cve2_ep02.sv points at EP02's sw/firmware.hex.vivado -mode batch -source build_ep02.tcl.vivado -mode batch -source program_ep02.tcl.stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb raw -echo; timeout 20 cat /dev/ttyUSB0.cd sw && make clean && make
cd ..
/media/alinx/nvme4t/Xilinx/2025.2/Vivado/bin/vivado -mode batch -source build_ep02.tcl
/media/alinx/nvme4t/Xilinx/2025.2/Vivado/bin/vivado -mode batch -source program_ep02.tcl
stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb raw -echo
timeout 20 cat /dev/ttyUSB0
These files come directly from the verified project. The canonical CVE2 source remains the upstream repository.
Daily Briefing · Weekly Digest · Monthly Deep Dive