-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilated_cpu.cpp
executable file
·62 lines (49 loc) · 1.39 KB
/
verilated_cpu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "./vsrc/obj_dir/Vcpu.h"
#include <cstdio>
#include <assert.h>
#include <fstream>
#include <iostream>
using namespace std;
#define CREATE_DPI(type, name) \
type read##name(uint64_t addr) {return vaddr_read(addr, sizeof(type)); } \
void write##name(uint64_t addr, type value) {vaddr_write(addr, sizeof(type), value); }
extern "C" {
#include <memory/vaddr.h>
CREATE_DPI(uint8_t, byte)
CREATE_DPI(uint16_t, half)
CREATE_DPI(uint32_t, word)
CREATE_DPI(uint64_t, dword)
#include <cpu/cpu.h>
void debug_inv(uint64_t addr) {INV(addr); }
void ebreak(uint64_t addr, uint64_t gpr10) {NEMUTRAP(addr, gpr10); }
}
Vcpu* vcpu = NULL;
VerilatedContext* vcontext = NULL;
extern "C" {
void vcpu_init() {
if (vcpu) delete vcpu;
if (vcontext) delete vcontext;
vcontext = new VerilatedContext();
vcpu = new Vcpu{vcontext};
vcpu->clk = 0;
vcpu->rst_clk = 1;
vcpu->eval();
vcpu->rst_clk = 0;
vcpu->eval();
vcpu->rst_clk = 1;
vcpu->eval();
}
void vcpu_do_cycle() {
vcpu->clk = 1;
vcpu->eval();
vcpu->clk = 0;
vcpu->eval();
}
uint64_t vcpu_get_pc() {
return vcpu->pc;
}
void vcpu_get_regs(uint64_t* writeout) {
for (int i = 0; i < 32; i++)
writeout[i] = 0;
}
}