EP02 — CVE2 trap / interrupt / CSR test on ALINX PI-AR035-F1-1 ================================================================ Verified: 2026-11-20 Build host: Ubuntu 20.04, Vivado 2025.2, RISC-V GCC 10.2.0 FPGA: AMD XC7A35T-2FGG484 Board: ALINX PI-AR035-F1-1 (engineering board) Clock: 50 MHz UART: /dev/ttyUSB0, 115200 8N1 1. Design --------- - CVE2/CV32E20, RV32IM (firmware built without compressed instructions). - 16 KiB instruction RAM + 16 KiB data RAM at 0x0000_0000. - UART TX at 0x1000_0000. - Minimal CLINT at 0x2000_0000: 0x00 mtime low 0x04 mtime high 0x08 mtimecmp low 0x0c mtimecmp high 0x10 msip 0x14 external pending 0x18 IRQ status {ext, timer, software} - CVE2 mtvec is forced vectored (MODE=1). Vector table base 0x100: 0x100 exception 0x10c software IRQ (IRQ 3) 0x11c timer IRQ (IRQ 7) 0x12c external IRQ (IRQ 11) 2. Firmware ----------- - sw/start.S: boot, BSS clear, vector table, exception/IRQ handlers. - sw/main.c: CSR readback tests and six trap/IRQ cases. - sw/link.ld: .text.start=0x0, .trap_vector=0x100, .text=0x140, stack top 0x4000. - sw/Makefile: -march=rv32im -mabi=ilp32. 3. Build -------- cd sw && make clean && make cd .. /media/alinx/nvme4t/Xilinx/2025.2/Vivado/bin/vivado \ -mode batch -source build_ep02.tcl The RAM INIT_FILE in rtl/top_cve2_ep02.sv must point to this project's sw/firmware.hex. If it still points at the EP01 project, the bitstream will boot the old "hello cve2" firmware even though programming reports success. 4. Program and capture ---------------------- stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb -echo raw timeout 25 cat /dev/ttyUSB0 > /tmp/uart.log & /media/alinx/nvme4t/Xilinx/2025.2/Vivado/bin/vivado \ -mode batch -source program_ep02.tcl cat /tmp/uart.log program_ep02.tcl connects to the Vivado 2025.2 hw_server on TCP 127.0.0.1:3122 (Digilent FT232H, target 127.0.0.1:3122/xilinx_tcf/Digilent/210512180081). The older 2023.2.1 hw_server on 3121 is still running and may hold the board. 5. Expected UART log -------------------- 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 6. Build result --------------- WNS 2.340 ns, TNS 0.000, failing endpoints 0 WHS 0.132 ns, THS 0.000, failing endpoints 0 Slice LUTs 3,295 / 20,800 (15.84%) Slice Registers 2,554 / 41,600 (6.14%) Block RAM Tile 8 / 50 (16.00%) DSPs 11 / 90 (12.22%) Bonded IOB 4 / 250 (1.60%) Bitstream 2,192,137 bytes SHA-256: top_cve2_ep02.bit 4661ae399727ae54b3a2b762e0bfd805d94bc39a63a950c3e8bf5bea2b254473 firmware.elf 27c2813fcf46b44c4b9c13533ba6c354544f841340376c3498f25d2326b934ab firmware.hex 39b2e2c2e17940195eb8524fb061c44fb787e673f0afd8b3c19e4b0543f6c36b 7. Pitfalls found in EP02 ------------------------- - RISC-V assembler treats .align 8 as 256-byte alignment. The first vector table used .align 8 and overlapped .text. Use .balign 4 for 4-byte alignment. - mtimecmp low was initially decoded per byte at 0x08/0x09/0x0a/0x0b. A word store only hits offset 0x08, so only the lowest byte was written. Write all four bytes from be[0..3] inside offset 0x08. - CLINT read data was combinational; address could change before rvalid. Latch rdata on req. - With -march=rv32imc, GCC emitted c.ebreak (2 bytes). The handler blindly added 4 to mepc, resumed mid-instruction, and took a second illegal trap. Build the test firmware as rv32im and use a 32-bit EBREAK (0x00100073). - Programming can report PROGRAM_DONE while the board still runs old firmware if INIT_FILE points at the EP01 firmware.hex. Always check the UART banner. 8. Not verified in EP02 ----------------------- - Nested interrupts and priority arbitration. - Multiple simultaneous IRQ sources. - mtime high-word rollover (64-bit timer overflow). - External interrupt from a real peripheral; only the CLINT pending bit was injected. - Debug mode / dcsr.ebreakm behavior. - UART RX.