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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Verilated -*- C++ -*-
// DESCRIPTION: Verilator output: main() simulation loop, created with --main
#include "Veater_computer.h"
#include "Veater_computer_eater_computer.h"
#include "Veater_computer_my_mem__DB10.h"
#include "verilated.h"
#include "verilatedos.h"
#include "verilated_fst_c.h"
#include "simpc_ui.h"
#include <algorithm>
#include <vector>
//======================
void load_program(const std::unique_ptr<Veater_computer> &topp) {
std::vector<uint8_t> instructions
//
{// LDA 14
0x1e,
// ADD 15
0x2f,
// STA 12
0x4c,
// SUB 13
0x3d,
// OUT_op
0xe0,
// ADD 11
0x2b,
// LDI 4
0x54,
// NOP
0x00,
// JMP -> @0
0x60,
// HALT
0xf0};
std::copy(instructions.begin(), instructions.end(),
&topp->eater_computer->RAM->r_datastore[0]);
// Data @ 11 - provoke overflow
topp->eater_computer->RAM->r_datastore[11] = 0xfe;
// Data @ 13
topp->eater_computer->RAM->r_datastore[13] = 1;
// Data @ 14
topp->eater_computer->RAM->r_datastore[14] = 14;
// Data @ 15
topp->eater_computer->RAM->r_datastore[15] = 28;
}
void load_program_countdown(const std::unique_ptr<Veater_computer> &topp) {
std::vector<uint8_t> instructions
//
{// LDI 2
0x52,
// SUB 15
0x3f,
// JZ 4
0x84,
// JMP -> @0
0x61,
// HALT
0xf0};
std::copy(instructions.begin(), instructions.end(),
&topp->eater_computer->RAM->r_datastore[0]);
// Data @ 15
topp->eater_computer->RAM->r_datastore[15] = 1;
}
int main(int argc, char **argv, char **) {
// Setup context, defaults, and parse command line
Verilated::debug(0);
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
contextp->traceEverOn(true);
contextp->threads(1);
contextp->commandArgs(argc, argv);
// Construct the Verilated model, from Vtop.h generated from Verilating
const std::unique_ptr<Veater_computer> topp{
new Veater_computer{contextp.get(), ""}};
// waveforms!!!
VerilatedFstC *tfp = new VerilatedFstC;
topp->trace(tfp, 100);
tfp->open("eater.vvp");
topp->clk_in = 0;
topp->auto_run_in = 1;
// Load program
load_program_countdown(topp);
simpc_ui_init();
// Simulate until $finish
while (VL_LIKELY(!contextp->gotFinish()) &&
VL_LIKELY(contextp->time() < 100) &&
VL_LIKELY(!(topp->eater_computer->flags.__PVT__halt))) {
// Evaluate model
topp->eval();
tfp->dump(contextp->time());
simpc_ui_write(topp, contextp->time());
// Advance time
contextp->timeInc(1);
topp->clk_in = !topp->clk_in;
}
contextp->timeInc(10);
tfp->dump(contextp->time());
tfp->close();
simpc_ui_finish_message(contextp, topp);
// if (VL_LIKELY(!contextp->gotFinish())) {
// VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););
// }
// Execute 'final' processes
topp->final();
// Print statistical summary report
// contextp->statsPrintSummary();
simpc_ui_confirm_finish();
simpc_ui_cleanup();
return 0;
}
|