Basys 3 RISC-V computer
The Basys 3 Z-80 computer with the Z-80 replaced by an RV32IM processor written from scratch (rtl/rv32_cpu.v): multi-cycle, 90 MHz, CSRs and traps, interrupts, two hardware triggers and a resumable NMI for the monitor. Passes riscv-tests rv32ui/um/mi. rv32_system.v keeps all the Z-80 machine's peripherals, with I/O port N at FFFFFF00h + N, 80 KB of RAM with BASIC preloaded, and a 32 KB monitor ROM. BASIC, the five games and the monitor (with an RV32 disassembler, assembler, breakpoints and single step) are ported to RISC-V GCC. Python emulator and tests in tools/; full-system simulation in sim/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
5930b958b4
103 files changed
+55677
No files matched your search
+89
@@ -0,0 +1,89 @@
|
||||
# Resumable NMI: one from the nmi line, then single steps from nmi_step.
|
||||
# The handler is at 8000h (tb_cpu.v's NMI_VEC); the test device is FFFFFF00.
|
||||
|
||||
#include "riscv_test.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
#define DEV -256
|
||||
#define NMI 16
|
||||
#define STEP 32
|
||||
#define RAISE(lines, delay) li t0, ((delay) << 8) | (lines); sw t0, DEV(zero)
|
||||
|
||||
RVTEST_RV32M
|
||||
RVTEST_CODE_BEGIN
|
||||
|
||||
li s2, 0
|
||||
# NMIE starts set
|
||||
li TESTNUM, 2
|
||||
csrr t0, CSR_MNSTATUS; andi t0, t0, MNSTATUS_NMIE; beqz t0, fail
|
||||
|
||||
# an NMI from the line: handler runs once, mnret comes back here
|
||||
li TESTNUM, 3
|
||||
li s4, 0 # handler mode: drop the line
|
||||
RAISE(NMI, 10)
|
||||
li t1, 1000
|
||||
1: bnez s2, 2f; addi t1, t1, -1; bnez t1, 1b; j fail
|
||||
2: li t0, 1; bne s2, t0, fail
|
||||
csrr t0, CSR_MNSTATUS; andi t0, t0, MNSTATUS_NMIE; beqz t0, fail
|
||||
andi t0, s5, MNSTATUS_NMIE; bnez t0, fail # clear inside the handler
|
||||
|
||||
# NMIs are masked while NMIE is clear
|
||||
li TESTNUM, 4
|
||||
csrci CSR_MNSTATUS, MNSTATUS_NMIE
|
||||
RAISE(NMI, 0)
|
||||
li t1, 50
|
||||
1: addi t1, t1, -1; bnez t1, 1b
|
||||
li t0, 1; bne s2, t0, fail
|
||||
csrsi CSR_MNSTATUS, MNSTATUS_NMIE
|
||||
li t1, 50
|
||||
1: addi t1, t1, -1; bnez t1, 1b
|
||||
li t0, 2; bne s2, t0, fail
|
||||
|
||||
# single steps: the handler logs mnepc and stops after four
|
||||
li TESTNUM, 5
|
||||
li s2, 0
|
||||
li s4, 1 # handler mode: log, stop after 4
|
||||
la s6, log
|
||||
RAISE(STEP, 0)
|
||||
step0:
|
||||
addi a0, x0, 1
|
||||
step1:
|
||||
addi a0, a0, 1
|
||||
step2:
|
||||
addi a0, a0, 1
|
||||
step3:
|
||||
addi a0, a0, 1
|
||||
addi a0, a0, 1
|
||||
li t0, 4; bne s2, t0, fail
|
||||
li t0, 5; bne a0, t0, fail # every instruction ran once
|
||||
# the stops were after the RAISE's store, then after each instruction
|
||||
la s6, log
|
||||
la t0, step0; lw t1, 0(s6); bne t0, t1, fail
|
||||
la t0, step1; lw t1, 4(s6); bne t0, t1, fail
|
||||
la t0, step2; lw t1, 8(s6); bne t0, t1, fail
|
||||
la t0, step3; lw t1, 12(s6); bne t0, t1, fail
|
||||
|
||||
TEST_PASSFAIL
|
||||
|
||||
.section .nmi, "ax"
|
||||
nmi_handler:
|
||||
csrr s5, CSR_MNSTATUS
|
||||
addi s2, s2, 1
|
||||
bnez s4, 1f
|
||||
sw zero, DEV(zero) # drop the line
|
||||
.word 0x70200073 # mnret
|
||||
1:
|
||||
csrr t5, CSR_MNEPC
|
||||
sw t5, 0(s6)
|
||||
addi s6, s6, 4
|
||||
li t5, 4
|
||||
bne s2, t5, 2f
|
||||
sw zero, DEV(zero) # stop stepping
|
||||
2:
|
||||
.word 0x70200073 # mnret
|
||||
|
||||
.data
|
||||
RVTEST_DATA_BEGIN
|
||||
TEST_DATA
|
||||
log: .fill 8, 4, 0
|
||||
RVTEST_DATA_END
|
||||
Reference in new issue
Block a user