1 |
2 |
alfik |
#include <cstdio>
|
2 |
|
|
#include <cstdlib>
|
3 |
|
|
|
4 |
|
|
#include <dlfcn.h>
|
5 |
|
|
|
6 |
|
|
#include <sys/mman.h>
|
7 |
|
|
#include <sys/types.h>
|
8 |
|
|
#include <sys/stat.h>
|
9 |
|
|
#include <fcntl.h>
|
10 |
|
|
#include <unistd.h>
|
11 |
|
|
|
12 |
|
|
#include "Vvga.h"
|
13 |
|
|
#include "verilated.h"
|
14 |
|
|
#include "verilated_vcd_c.h"
|
15 |
|
|
|
16 |
|
|
#include "shared_mem.h"
|
17 |
|
|
|
18 |
|
|
//------------------------------------------------------------------------------
|
19 |
|
|
//------------------------------------------------------------------------------
|
20 |
|
|
//------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
volatile shared_mem_t *shared_ptr = NULL;
|
23 |
|
|
|
24 |
|
|
//------------------------------------------------------------------------------
|
25 |
|
|
//------------------------------------------------------------------------------
|
26 |
|
|
//------------------------------------------------------------------------------
|
27 |
|
|
|
28 |
|
|
//------------------------------------------------------------------------------
|
29 |
|
|
|
30 |
|
|
int main(int argc, char **argv) {
|
31 |
|
|
//map shared memory
|
32 |
|
|
int fd = open("./../../../sim_pc/shared_mem.dat", O_RDWR, S_IRUSR | S_IWUSR);
|
33 |
|
|
|
34 |
|
|
if(fd == -1) {
|
35 |
|
|
perror("open() failed for shared_mem.dat");
|
36 |
|
|
return -1;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
shared_ptr = (shared_mem_t *)mmap(NULL, sizeof(shared_mem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
40 |
|
|
|
41 |
|
|
if(shared_ptr == MAP_FAILED) {
|
42 |
|
|
perror("mmap() failed");
|
43 |
|
|
close(fd);
|
44 |
|
|
return -2;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
Verilated::commandArgs(argc, argv);
|
48 |
|
|
|
49 |
|
|
Verilated::traceEverOn(true);
|
50 |
|
|
VerilatedVcdC* tracer = new VerilatedVcdC;
|
51 |
|
|
|
52 |
|
|
Vvga *top = new Vvga();
|
53 |
|
|
top->trace (tracer, 99);
|
54 |
|
|
//tracer->rolloverMB(1000000);
|
55 |
|
|
tracer->open("vga.vcd");
|
56 |
|
|
|
57 |
|
|
bool dump = false;
|
58 |
|
|
|
59 |
|
|
//reset
|
60 |
|
|
top->clk_26 = 0; top->rst_n = 1; top->eval();
|
61 |
|
|
top->clk_26 = 1; top->rst_n = 1; top->eval();
|
62 |
|
|
top->clk_26 = 1; top->rst_n = 0; top->eval();
|
63 |
|
|
top->clk_26 = 0; top->rst_n = 0; top->eval();
|
64 |
|
|
top->clk_26 = 0; top->rst_n = 1; top->eval();
|
65 |
|
|
|
66 |
|
|
uint64 cycle = 0;
|
67 |
|
|
bool read_cycle = false;
|
68 |
|
|
bool read_mem_cycle = false;
|
69 |
|
|
|
70 |
|
|
uint32 curr_io_byteenable = 0;
|
71 |
|
|
uint32 curr_io_byteena_modif = 0;
|
72 |
|
|
step_t curr_io_step = STEP_IDLE;
|
73 |
|
|
|
74 |
|
|
uint32 curr_mem_byteenable = 0;
|
75 |
|
|
uint32 curr_mem_byteena_modif = 0;
|
76 |
|
|
step_t curr_mem_step = STEP_IDLE;
|
77 |
|
|
|
78 |
|
|
uint32 curr_mrd_byteenable = 0;
|
79 |
|
|
uint32 curr_mrd_byteena_modif = 0;
|
80 |
|
|
step_t curr_mrd_step = STEP_IDLE;
|
81 |
|
|
|
82 |
|
|
printf("vga main_plugin.cpp\n");
|
83 |
|
|
while(!Verilated::gotFinish()) {
|
84 |
|
|
|
85 |
|
|
//----------------------------------------------------------------------
|
86 |
|
|
|
87 |
|
|
/*
|
88 |
|
|
uint32 combined.io_address;
|
89 |
|
|
uint32 combined.io_data;
|
90 |
|
|
uint32 combined.io_byteenable;
|
91 |
|
|
uint32 combined.io_is_write;
|
92 |
|
|
step_t combined.io_step;
|
93 |
|
|
|
94 |
|
|
//avalon slave vga io 0x3B0 - 0x3BF
|
95 |
|
|
input [3:0] io_b_address,
|
96 |
|
|
input io_b_read,
|
97 |
|
|
output [7:0] io_b_readdata,
|
98 |
|
|
input io_b_write,
|
99 |
|
|
input [7:0] io_b_writedata,
|
100 |
|
|
|
101 |
|
|
//avalon slave vga io 0x3C0 - 0xCF
|
102 |
|
|
input [3:0] io_c_address,
|
103 |
|
|
input io_c_read,
|
104 |
|
|
output [7:0] io_c_readdata,
|
105 |
|
|
input io_c_write,
|
106 |
|
|
input [7:0] io_c_writedata,
|
107 |
|
|
|
108 |
|
|
//avalon slave vga io 0x3D0 - 0x3DF
|
109 |
|
|
input [3:0] io_d_address,
|
110 |
|
|
input io_d_read,
|
111 |
|
|
output [7:0] io_d_readdata,
|
112 |
|
|
input io_d_write,
|
113 |
|
|
input [7:0] io_d_writedata,
|
114 |
|
|
*/
|
115 |
|
|
|
116 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write &&
|
117 |
|
|
(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC ||
|
118 |
|
|
shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC ||
|
119 |
|
|
shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC))
|
120 |
|
|
{
|
121 |
|
|
if(curr_io_step == STEP_IDLE) {
|
122 |
|
|
curr_io_byteena_modif = shared_ptr->combined.io_byteenable;
|
123 |
|
|
curr_io_step = STEP_REQ;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
if(curr_io_step == STEP_REQ) {
|
127 |
|
|
if((curr_io_byteena_modif >> 0) & 1) {
|
128 |
|
|
curr_io_byteenable = 1;
|
129 |
|
|
curr_io_byteena_modif &= 0xE;
|
130 |
|
|
}
|
131 |
|
|
else if((curr_io_byteena_modif >> 1) & 1) {
|
132 |
|
|
curr_io_byteenable = 2;
|
133 |
|
|
curr_io_byteena_modif &= 0xC;
|
134 |
|
|
}
|
135 |
|
|
else if((curr_io_byteena_modif >> 2) & 1) {
|
136 |
|
|
curr_io_byteenable = 4;
|
137 |
|
|
curr_io_byteena_modif &= 0x8;
|
138 |
|
|
}
|
139 |
|
|
else if((curr_io_byteena_modif >> 3) & 1) {
|
140 |
|
|
curr_io_byteenable = 8;
|
141 |
|
|
curr_io_byteena_modif &= 0x0;
|
142 |
|
|
}
|
143 |
|
|
else {
|
144 |
|
|
shared_ptr->combined.io_step = STEP_ACK;
|
145 |
|
|
curr_io_step = STEP_IDLE;
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
top->io_b_read = 0;
|
151 |
|
|
top->io_b_write = 0;
|
152 |
|
|
|
153 |
|
|
top->io_c_read = 0;
|
154 |
|
|
top->io_c_write = 0;
|
155 |
|
|
|
156 |
|
|
top->io_d_read = 0;
|
157 |
|
|
top->io_d_write = 0;
|
158 |
|
|
|
159 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write && curr_io_step == STEP_REQ &&
|
160 |
|
|
(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC ||
|
161 |
|
|
shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC ||
|
162 |
|
|
shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC))
|
163 |
|
|
{
|
164 |
|
|
if(curr_io_byteenable != 1 && curr_io_byteenable != 2 && curr_io_byteenable != 4 && curr_io_byteenable != 8) {
|
165 |
|
|
printf("Vvga: curr_io_byteenable invalid: %04x %x\n", shared_ptr->combined.io_address, curr_io_byteenable);
|
166 |
|
|
exit(-1);
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
top->io_b_address = (shared_ptr->combined.io_address == 0x03B0 && curr_io_byteenable == 1)? 0 :
|
170 |
|
|
(shared_ptr->combined.io_address == 0x03B0 && curr_io_byteenable == 2)? 1 :
|
171 |
|
|
(shared_ptr->combined.io_address == 0x03B0 && curr_io_byteenable == 4)? 2 :
|
172 |
|
|
(shared_ptr->combined.io_address == 0x03B0 && curr_io_byteenable == 8)? 3 :
|
173 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && curr_io_byteenable == 1)? 4 :
|
174 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && curr_io_byteenable == 2)? 5 :
|
175 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && curr_io_byteenable == 4)? 6 :
|
176 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && curr_io_byteenable == 8)? 7 :
|
177 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && curr_io_byteenable == 1)? 8 :
|
178 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && curr_io_byteenable == 2)? 9 :
|
179 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && curr_io_byteenable == 4)? 10 :
|
180 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && curr_io_byteenable == 8)? 11 :
|
181 |
|
|
(shared_ptr->combined.io_address == 0x03BC && curr_io_byteenable == 1)? 12 :
|
182 |
|
|
(shared_ptr->combined.io_address == 0x03BC && curr_io_byteenable == 2)? 13 :
|
183 |
|
|
(shared_ptr->combined.io_address == 0x03BC && curr_io_byteenable == 4)? 14 :
|
184 |
|
|
15;
|
185 |
|
|
|
186 |
|
|
top->io_c_address = (shared_ptr->combined.io_address == 0x03C0 && curr_io_byteenable == 1)? 0 :
|
187 |
|
|
(shared_ptr->combined.io_address == 0x03C0 && curr_io_byteenable == 2)? 1 :
|
188 |
|
|
(shared_ptr->combined.io_address == 0x03C0 && curr_io_byteenable == 4)? 2 :
|
189 |
|
|
(shared_ptr->combined.io_address == 0x03C0 && curr_io_byteenable == 8)? 3 :
|
190 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && curr_io_byteenable == 1)? 4 :
|
191 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && curr_io_byteenable == 2)? 5 :
|
192 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && curr_io_byteenable == 4)? 6 :
|
193 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && curr_io_byteenable == 8)? 7 :
|
194 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && curr_io_byteenable == 1)? 8 :
|
195 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && curr_io_byteenable == 2)? 9 :
|
196 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && curr_io_byteenable == 4)? 10 :
|
197 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && curr_io_byteenable == 8)? 11 :
|
198 |
|
|
(shared_ptr->combined.io_address == 0x03CC && curr_io_byteenable == 1)? 12 :
|
199 |
|
|
(shared_ptr->combined.io_address == 0x03CC && curr_io_byteenable == 2)? 13 :
|
200 |
|
|
(shared_ptr->combined.io_address == 0x03CC && curr_io_byteenable == 4)? 14 :
|
201 |
|
|
15;
|
202 |
|
|
|
203 |
|
|
top->io_d_address = (shared_ptr->combined.io_address == 0x03D0 && curr_io_byteenable == 1)? 0 :
|
204 |
|
|
(shared_ptr->combined.io_address == 0x03D0 && curr_io_byteenable == 2)? 1 :
|
205 |
|
|
(shared_ptr->combined.io_address == 0x03D0 && curr_io_byteenable == 4)? 2 :
|
206 |
|
|
(shared_ptr->combined.io_address == 0x03D0 && curr_io_byteenable == 8)? 3 :
|
207 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && curr_io_byteenable == 1)? 4 :
|
208 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && curr_io_byteenable == 2)? 5 :
|
209 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && curr_io_byteenable == 4)? 6 :
|
210 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && curr_io_byteenable == 8)? 7 :
|
211 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && curr_io_byteenable == 1)? 8 :
|
212 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && curr_io_byteenable == 2)? 9 :
|
213 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && curr_io_byteenable == 4)? 10 :
|
214 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && curr_io_byteenable == 8)? 11 :
|
215 |
|
|
(shared_ptr->combined.io_address == 0x03DC && curr_io_byteenable == 1)? 12 :
|
216 |
|
|
(shared_ptr->combined.io_address == 0x03DC && curr_io_byteenable == 2)? 13 :
|
217 |
|
|
(shared_ptr->combined.io_address == 0x03DC && curr_io_byteenable == 4)? 14 :
|
218 |
|
|
15;
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
top->io_b_writedata = (curr_io_byteenable == 1)? shared_ptr->combined.io_data & 0xFF :
|
222 |
|
|
(curr_io_byteenable == 2)? (shared_ptr->combined.io_data >> 8) & 0xFF :
|
223 |
|
|
(curr_io_byteenable == 4)? (shared_ptr->combined.io_data >> 16) & 0xFF :
|
224 |
|
|
(shared_ptr->combined.io_data >> 24) & 0xFF;
|
225 |
|
|
|
226 |
|
|
top->io_c_writedata = (curr_io_byteenable == 1)? shared_ptr->combined.io_data & 0xFF :
|
227 |
|
|
(curr_io_byteenable == 2)? (shared_ptr->combined.io_data >> 8) & 0xFF :
|
228 |
|
|
(curr_io_byteenable == 4)? (shared_ptr->combined.io_data >> 16) & 0xFF :
|
229 |
|
|
(shared_ptr->combined.io_data >> 24) & 0xFF;
|
230 |
|
|
|
231 |
|
|
top->io_d_writedata = (curr_io_byteenable == 1)? shared_ptr->combined.io_data & 0xFF :
|
232 |
|
|
(curr_io_byteenable == 2)? (shared_ptr->combined.io_data >> 8) & 0xFF :
|
233 |
|
|
(curr_io_byteenable == 4)? (shared_ptr->combined.io_data >> 16) & 0xFF :
|
234 |
|
|
(shared_ptr->combined.io_data >> 24) & 0xFF;
|
235 |
|
|
|
236 |
|
|
if(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC) {
|
237 |
|
|
top->io_b_read = 0;
|
238 |
|
|
top->io_b_write = 1;
|
239 |
|
|
}
|
240 |
|
|
if(shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC) {
|
241 |
|
|
top->io_c_read = 0;
|
242 |
|
|
top->io_c_write = 1;
|
243 |
|
|
}
|
244 |
|
|
if(shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC) {
|
245 |
|
|
top->io_d_read = 0;
|
246 |
|
|
top->io_d_write = 1;
|
247 |
|
|
}
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
if(read_cycle == false) {
|
251 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 &&
|
252 |
|
|
(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC ||
|
253 |
|
|
shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC ||
|
254 |
|
|
shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC))
|
255 |
|
|
{
|
256 |
|
|
if(shared_ptr->combined.io_byteenable != 1 && shared_ptr->combined.io_byteenable != 2 && shared_ptr->combined.io_byteenable != 4 && shared_ptr->combined.io_byteenable != 8) {
|
257 |
|
|
printf("Vvga: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
|
258 |
|
|
exit(-1);
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
top->io_b_address = (shared_ptr->combined.io_address == 0x03B0 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
262 |
|
|
(shared_ptr->combined.io_address == 0x03B0 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
263 |
|
|
(shared_ptr->combined.io_address == 0x03B0 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
264 |
|
|
(shared_ptr->combined.io_address == 0x03B0 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
265 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
266 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
267 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
268 |
|
|
(shared_ptr->combined.io_address == 0x03B4 && shared_ptr->combined.io_byteenable == 8)? 7 :
|
269 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && shared_ptr->combined.io_byteenable == 1)? 8 :
|
270 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && shared_ptr->combined.io_byteenable == 2)? 9 :
|
271 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && shared_ptr->combined.io_byteenable == 4)? 10 :
|
272 |
|
|
(shared_ptr->combined.io_address == 0x03B8 && shared_ptr->combined.io_byteenable == 8)? 11 :
|
273 |
|
|
(shared_ptr->combined.io_address == 0x03BC && shared_ptr->combined.io_byteenable == 1)? 12 :
|
274 |
|
|
(shared_ptr->combined.io_address == 0x03BC && shared_ptr->combined.io_byteenable == 2)? 13 :
|
275 |
|
|
(shared_ptr->combined.io_address == 0x03BC && shared_ptr->combined.io_byteenable == 4)? 14 :
|
276 |
|
|
15;
|
277 |
|
|
|
278 |
|
|
top->io_c_address = (shared_ptr->combined.io_address == 0x03C0 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
279 |
|
|
(shared_ptr->combined.io_address == 0x03C0 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
280 |
|
|
(shared_ptr->combined.io_address == 0x03C0 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
281 |
|
|
(shared_ptr->combined.io_address == 0x03C0 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
282 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
283 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
284 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
285 |
|
|
(shared_ptr->combined.io_address == 0x03C4 && shared_ptr->combined.io_byteenable == 8)? 7 :
|
286 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && shared_ptr->combined.io_byteenable == 1)? 8 :
|
287 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && shared_ptr->combined.io_byteenable == 2)? 9 :
|
288 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && shared_ptr->combined.io_byteenable == 4)? 10 :
|
289 |
|
|
(shared_ptr->combined.io_address == 0x03C8 && shared_ptr->combined.io_byteenable == 8)? 11 :
|
290 |
|
|
(shared_ptr->combined.io_address == 0x03CC && shared_ptr->combined.io_byteenable == 1)? 12 :
|
291 |
|
|
(shared_ptr->combined.io_address == 0x03CC && shared_ptr->combined.io_byteenable == 2)? 13 :
|
292 |
|
|
(shared_ptr->combined.io_address == 0x03CC && shared_ptr->combined.io_byteenable == 4)? 14 :
|
293 |
|
|
15;
|
294 |
|
|
|
295 |
|
|
top->io_d_address = (shared_ptr->combined.io_address == 0x03D0 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
296 |
|
|
(shared_ptr->combined.io_address == 0x03D0 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
297 |
|
|
(shared_ptr->combined.io_address == 0x03D0 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
298 |
|
|
(shared_ptr->combined.io_address == 0x03D0 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
299 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
300 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
301 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
302 |
|
|
(shared_ptr->combined.io_address == 0x03D4 && shared_ptr->combined.io_byteenable == 8)? 7 :
|
303 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && shared_ptr->combined.io_byteenable == 1)? 8 :
|
304 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && shared_ptr->combined.io_byteenable == 2)? 9 :
|
305 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && shared_ptr->combined.io_byteenable == 4)? 10 :
|
306 |
|
|
(shared_ptr->combined.io_address == 0x03D8 && shared_ptr->combined.io_byteenable == 8)? 11 :
|
307 |
|
|
(shared_ptr->combined.io_address == 0x03DC && shared_ptr->combined.io_byteenable == 1)? 12 :
|
308 |
|
|
(shared_ptr->combined.io_address == 0x03DC && shared_ptr->combined.io_byteenable == 2)? 13 :
|
309 |
|
|
(shared_ptr->combined.io_address == 0x03DC && shared_ptr->combined.io_byteenable == 4)? 14 :
|
310 |
|
|
15;
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
top->io_b_writedata = 0;
|
314 |
|
|
top->io_c_writedata = 0;
|
315 |
|
|
top->io_d_writedata = 0;
|
316 |
|
|
|
317 |
|
|
if(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC) {
|
318 |
|
|
top->io_b_read = 1;
|
319 |
|
|
top->io_b_write = 0;
|
320 |
|
|
}
|
321 |
|
|
if(shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC) {
|
322 |
|
|
top->io_c_read = 1;
|
323 |
|
|
top->io_c_write = 0;
|
324 |
|
|
}
|
325 |
|
|
if(shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC) {
|
326 |
|
|
top->io_d_read = 1;
|
327 |
|
|
top->io_d_write = 0;
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
read_cycle = true;
|
331 |
|
|
}
|
332 |
|
|
}
|
333 |
|
|
else {
|
334 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 &&
|
335 |
|
|
(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC ||
|
336 |
|
|
shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC ||
|
337 |
|
|
shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC))
|
338 |
|
|
{
|
339 |
|
|
uint32 val = 0;
|
340 |
|
|
|
341 |
|
|
if(shared_ptr->combined.io_address == 0x03B0 || shared_ptr->combined.io_address == 0x03B4 || shared_ptr->combined.io_address == 0x03B8 || shared_ptr->combined.io_address == 0x03BC) {
|
342 |
|
|
val = top->io_b_readdata;
|
343 |
|
|
}
|
344 |
|
|
if(shared_ptr->combined.io_address == 0x03C0 || shared_ptr->combined.io_address == 0x03C4 || shared_ptr->combined.io_address == 0x03C8 || shared_ptr->combined.io_address == 0x03CC) {
|
345 |
|
|
val = top->io_c_readdata;
|
346 |
|
|
}
|
347 |
|
|
if(shared_ptr->combined.io_address == 0x03D0 || shared_ptr->combined.io_address == 0x03D4 || shared_ptr->combined.io_address == 0x03D8 || shared_ptr->combined.io_address == 0x03DC) {
|
348 |
|
|
val = top->io_d_readdata;
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
if(shared_ptr->combined.io_byteenable & 1) val <<= 0;
|
352 |
|
|
if(shared_ptr->combined.io_byteenable & 2) val <<= 8;
|
353 |
|
|
if(shared_ptr->combined.io_byteenable & 4) val <<= 16;
|
354 |
|
|
if(shared_ptr->combined.io_byteenable & 8) val <<= 24;
|
355 |
|
|
|
356 |
|
|
shared_ptr->combined.io_data = val;
|
357 |
|
|
|
358 |
|
|
read_cycle = false;
|
359 |
|
|
shared_ptr->combined.io_step = STEP_ACK;
|
360 |
|
|
}
|
361 |
|
|
}
|
362 |
|
|
|
363 |
|
|
//----------------------------------------------------------------------
|
364 |
|
|
/*
|
365 |
|
|
uint32 combined.mem_address;
|
366 |
|
|
uint32 combined.mem_data;
|
367 |
|
|
uint32 combined.mem_byteenable;
|
368 |
|
|
uint32 combined.mem_is_write;
|
369 |
|
|
step_t combined.mem_step;
|
370 |
|
|
|
371 |
|
|
//avalon slave vga memory 0xA0000 - 0xBFFFF
|
372 |
|
|
input [16:0] mem_address,
|
373 |
|
|
input mem_read,
|
374 |
|
|
output [7:0] mem_readdata,
|
375 |
|
|
input mem_write,
|
376 |
|
|
input [7:0] mem_writedata,
|
377 |
|
|
*/
|
378 |
|
|
|
379 |
|
|
if(shared_ptr->combined.mem_step == STEP_REQ && shared_ptr->combined.mem_is_write && shared_ptr->combined.mem_address >= 0x000A0000 && shared_ptr->combined.mem_address < 0x000C0000)
|
380 |
|
|
{
|
381 |
|
|
if(curr_mem_step == STEP_IDLE) {
|
382 |
|
|
curr_mem_byteena_modif = shared_ptr->combined.mem_byteenable;
|
383 |
|
|
curr_mem_step = STEP_REQ;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
if(curr_mem_step == STEP_REQ) {
|
387 |
|
|
if((curr_mem_byteena_modif >> 0) & 1) {
|
388 |
|
|
curr_mem_byteenable = 1;
|
389 |
|
|
curr_mem_byteena_modif &= 0xE;
|
390 |
|
|
}
|
391 |
|
|
else if((curr_mem_byteena_modif >> 1) & 1) {
|
392 |
|
|
curr_mem_byteenable = 2;
|
393 |
|
|
curr_mem_byteena_modif &= 0xC;
|
394 |
|
|
}
|
395 |
|
|
else if((curr_mem_byteena_modif >> 2) & 1) {
|
396 |
|
|
curr_mem_byteenable = 4;
|
397 |
|
|
curr_mem_byteena_modif &= 0x8;
|
398 |
|
|
}
|
399 |
|
|
else if((curr_mem_byteena_modif >> 3) & 1) {
|
400 |
|
|
curr_mem_byteenable = 8;
|
401 |
|
|
curr_mem_byteena_modif &= 0x0;
|
402 |
|
|
}
|
403 |
|
|
else {
|
404 |
|
|
shared_ptr->combined.mem_step = STEP_ACK;
|
405 |
|
|
curr_mem_step = STEP_IDLE;
|
406 |
|
|
}
|
407 |
|
|
}
|
408 |
|
|
}
|
409 |
|
|
|
410 |
|
|
top->mem_read = 0;
|
411 |
|
|
top->mem_write = 0;
|
412 |
|
|
|
413 |
|
|
if(shared_ptr->combined.mem_step == STEP_REQ && shared_ptr->combined.mem_is_write && shared_ptr->combined.mem_address >= 0x000A0000 && shared_ptr->combined.mem_address < 0x000C0000 &&
|
414 |
|
|
curr_mem_step == STEP_REQ)
|
415 |
|
|
{
|
416 |
|
|
if(curr_mem_byteenable != 1 && curr_mem_byteenable != 2 && curr_mem_byteenable != 4 && curr_mem_byteenable != 8) {
|
417 |
|
|
printf("Vvga: combined.curr_mem_byteenable invalid wr: %x\n", curr_mem_byteenable);
|
418 |
|
|
exit(-1);
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
top->mem_address = (shared_ptr->combined.mem_address >> 2) & 0x1FFFF;
|
422 |
|
|
|
423 |
|
|
top->mem_writedata = (curr_mem_byteenable == 1)? shared_ptr->combined.mem_data & 0xFF :
|
424 |
|
|
(curr_mem_byteenable == 2)? (shared_ptr->combined.mem_data >> 8) & 0xFF :
|
425 |
|
|
(curr_mem_byteenable == 4)? (shared_ptr->combined.mem_data >> 16) & 0xFF :
|
426 |
|
|
(shared_ptr->combined.mem_data >> 24) & 0xFF;
|
427 |
|
|
top->mem_read = 0;
|
428 |
|
|
top->mem_write = 1;
|
429 |
|
|
}
|
430 |
|
|
|
431 |
|
|
if(read_mem_cycle == false) {
|
432 |
|
|
|
433 |
|
|
if(shared_ptr->combined.mem_step == STEP_REQ && shared_ptr->combined.mem_is_write == 0 && shared_ptr->combined.mem_address >= 0x000A0000 && shared_ptr->combined.mem_address < 0x000C0000)
|
434 |
|
|
{
|
435 |
|
|
if(curr_mrd_step == STEP_IDLE) {
|
436 |
|
|
curr_mrd_byteena_modif = shared_ptr->combined.mem_byteenable;
|
437 |
|
|
curr_mrd_step = STEP_REQ;
|
438 |
|
|
|
439 |
|
|
shared_ptr->combined.mem_data = 0;
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
if(curr_mrd_step == STEP_REQ) {
|
443 |
|
|
if((curr_mrd_byteena_modif >> 0) & 1) {
|
444 |
|
|
curr_mrd_byteenable = 1;
|
445 |
|
|
curr_mrd_byteena_modif &= 0xE;
|
446 |
|
|
}
|
447 |
|
|
else if((curr_mrd_byteena_modif >> 1) & 1) {
|
448 |
|
|
curr_mrd_byteenable = 2;
|
449 |
|
|
curr_mrd_byteena_modif &= 0xC;
|
450 |
|
|
}
|
451 |
|
|
else if((curr_mrd_byteena_modif >> 2) & 1) {
|
452 |
|
|
curr_mrd_byteenable = 4;
|
453 |
|
|
curr_mrd_byteena_modif &= 0x8;
|
454 |
|
|
}
|
455 |
|
|
else if((curr_mrd_byteena_modif >> 3) & 1) {
|
456 |
|
|
curr_mrd_byteenable = 8;
|
457 |
|
|
curr_mrd_byteena_modif &= 0x0;
|
458 |
|
|
}
|
459 |
|
|
else {
|
460 |
|
|
shared_ptr->combined.mem_step = STEP_ACK;
|
461 |
|
|
curr_mrd_step = STEP_IDLE;
|
462 |
|
|
}
|
463 |
|
|
}
|
464 |
|
|
}
|
465 |
|
|
|
466 |
|
|
if(shared_ptr->combined.mem_step == STEP_REQ && shared_ptr->combined.mem_is_write == 0 && shared_ptr->combined.mem_address >= 0x000A0000 && shared_ptr->combined.mem_address < 0x000C0000 &&
|
467 |
|
|
curr_mrd_step == STEP_REQ)
|
468 |
|
|
{
|
469 |
|
|
if(curr_mrd_byteenable != 1 && curr_mrd_byteenable != 2 && curr_mrd_byteenable != 4 && curr_mrd_byteenable != 8) {
|
470 |
|
|
printf("Vvga: curr_mrd_byteenable invalid rd: %x\n", curr_mrd_byteenable);
|
471 |
|
|
exit(-1);
|
472 |
|
|
}
|
473 |
|
|
|
474 |
|
|
top->mem_address = (shared_ptr->combined.mem_address >> 2) & 0x1FFFF;
|
475 |
|
|
|
476 |
|
|
top->mem_writedata = 0;
|
477 |
|
|
|
478 |
|
|
top->mem_read = 1;
|
479 |
|
|
top->mem_write= 0;
|
480 |
|
|
|
481 |
|
|
read_mem_cycle = true;
|
482 |
|
|
}
|
483 |
|
|
}
|
484 |
|
|
else {
|
485 |
|
|
if(shared_ptr->combined.mem_step == STEP_REQ && shared_ptr->combined.mem_is_write == 0 && shared_ptr->combined.mem_address >= 0x000A0000 && shared_ptr->combined.mem_address < 0x000C0000 &&
|
486 |
|
|
curr_mrd_step == STEP_REQ)
|
487 |
|
|
{
|
488 |
|
|
uint32 val = top->mem_readdata;
|
489 |
|
|
|
490 |
|
|
if(curr_mrd_byteenable & 1) val <<= 0;
|
491 |
|
|
if(curr_mrd_byteenable & 2) val <<= 8;
|
492 |
|
|
if(curr_mrd_byteenable & 4) val <<= 16;
|
493 |
|
|
if(curr_mrd_byteenable & 8) val <<= 24;
|
494 |
|
|
|
495 |
|
|
shared_ptr->combined.mem_data |= val;
|
496 |
|
|
|
497 |
|
|
read_mem_cycle = false;
|
498 |
|
|
}
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
//----------------------------------------------------------------------
|
502 |
|
|
|
503 |
|
|
//----------------------------------------------------------------------
|
504 |
|
|
|
505 |
|
|
top->clk_26 = 0;
|
506 |
|
|
top->eval();
|
507 |
|
|
if(dump) tracer->dump(cycle++);
|
508 |
|
|
|
509 |
|
|
top->clk_26 = 1;
|
510 |
|
|
top->eval();
|
511 |
|
|
if(dump) tracer->dump(cycle++);
|
512 |
|
|
|
513 |
|
|
tracer->flush();
|
514 |
|
|
|
515 |
|
|
usleep(1);
|
516 |
|
|
}
|
517 |
|
|
tracer->close();
|
518 |
|
|
delete tracer;
|
519 |
|
|
delete top;
|
520 |
|
|
|
521 |
|
|
return 0;
|
522 |
|
|
}
|
523 |
|
|
|
524 |
|
|
//------------------------------------------------------------------------------
|
525 |
|
|
|
526 |
|
|
/*
|
527 |
|
|
input clk_26,
|
528 |
|
|
input rst_n,
|
529 |
|
|
|
530 |
|
|
//avalon slave for system overlay
|
531 |
|
|
input [7:0] sys_address,
|
532 |
|
|
input sys_read,
|
533 |
|
|
output [31:0] sys_readdata,
|
534 |
|
|
input sys_write,
|
535 |
|
|
input [31:0] sys_writedata,
|
536 |
|
|
|
537 |
|
|
//avalon slave vga io 0x3B0 - 0x3BF
|
538 |
|
|
input [3:0] io_b_address,
|
539 |
|
|
input io_b_read,
|
540 |
|
|
output [7:0] io_b_readdata,
|
541 |
|
|
input io_b_write,
|
542 |
|
|
input [7:0] io_b_writedata,
|
543 |
|
|
|
544 |
|
|
//avalon slave vga io 0x3C0 - 0xCF
|
545 |
|
|
input [3:0] io_c_address,
|
546 |
|
|
input io_c_read,
|
547 |
|
|
output [7:0] io_c_readdata,
|
548 |
|
|
input io_c_write,
|
549 |
|
|
input [7:0] io_c_writedata,
|
550 |
|
|
|
551 |
|
|
//avalon slave vga io 0x3D0 - 0x3DF
|
552 |
|
|
input [3:0] io_d_address,
|
553 |
|
|
input io_d_read,
|
554 |
|
|
output [7:0] io_d_readdata,
|
555 |
|
|
input io_d_write,
|
556 |
|
|
input [7:0] io_d_writedata,
|
557 |
|
|
|
558 |
|
|
//avalon slave vga memory 0xA0000 - 0xBFFFF
|
559 |
|
|
input [16:0] mem_address,
|
560 |
|
|
input mem_read,
|
561 |
|
|
output [7:0] mem_readdata,
|
562 |
|
|
input mem_write,
|
563 |
|
|
input [7:0] mem_writedata,
|
564 |
|
|
*/
|