Skip to content

Commit

Permalink
Difftest: add more CSR into diff list
Browse files Browse the repository at this point in the history
* It will make snapshot more precise
  • Loading branch information
AugustusWillisWang committed Jul 14, 2021
1 parent 88575e9 commit 391c918
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib-include/difftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@

enum { DIFFTEST_TO_DUT, DIFFTEST_TO_REF };

#define RV64_FULL_DIFF

#if defined(__ISA_x86__)
# define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 9) // GPRs + PC
#elif defined(__ISA_mips32__)
# define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 38) // GRPs + status + lo + hi + badvaddr + cause + pc
#elif defined(__ISA_riscv32__)
# define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 33) // GRPs + pc
#elif defined(__ISA_riscv64__)
#ifdef RV64_FULL_DIFF
# define DIFFTEST_REG_SIZE (sizeof(uint64_t) * (32 + 32 + 1 + 6 + 7)) // GRPs + FPRs + pc + [m|s][status|cause|epc] + other necessary CSRs
#else
# define DIFFTEST_REG_SIZE (sizeof(uint64_t) * (32 + 1)) // GRPs + pc
#endif
#else
# error Unsupport ISA
#endif
Expand Down
16 changes: 16 additions & 0 deletions src/isa/riscv64/difftest/ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ static void csr_prepare() {
cpu.sstatus = csrid_read(0x100); // sstatus
cpu.scause = scause->val;
cpu.sepc = sepc->val;

cpu.satp = satp->val;
cpu.mip = mip->val;
cpu.mie = mie->val;
cpu.mscratch = mscratch->val;
cpu.sscratch = sscratch->val;
cpu.mideleg = mideleg->val;
cpu.medeleg = medeleg->val;
}

static void csr_writeback() {
Expand All @@ -22,6 +30,14 @@ static void csr_writeback() {
//sstatus->val = cpu.sstatus; // sstatus is a shadow of mstatus
scause ->val = cpu.scause ;
sepc ->val = cpu.sepc ;

satp->val = cpu.satp;
mip->val = cpu.mip;
mie->val = cpu.mie;
mscratch->val = cpu.mscratch;
sscratch->val = cpu.sscratch;
mideleg->val = cpu.mideleg;
medeleg->val = cpu.medeleg;
}

void isa_difftest_regcpy(void *dut, bool direction) {
Expand Down
9 changes: 5 additions & 4 deletions src/isa/riscv64/include/isa-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ typedef struct {
uint64_t _64;
} gpr[32];

uint64_t pc;
uint64_t mstatus, mcause, mepc;
uint64_t sstatus, scause, sepc;

union {
uint64_t _64;
} fpr[32];

uint64_t pc;
uint64_t mstatus, mcause, mepc;
uint64_t sstatus, scause, sepc;

uint64_t satp, mip, mie, mscratch, sscratch, mideleg, medeleg;

uint8_t mode;

Expand Down

0 comments on commit 391c918

Please sign in to comment.