1 |
2 |
alfik |
#include <cstdio>
|
2 |
|
|
#include <cstdlib>
|
3 |
|
|
|
4 |
|
|
#include <sys/mman.h>
|
5 |
|
|
#include <sys/types.h>
|
6 |
|
|
#include <sys/stat.h>
|
7 |
|
|
#include <fcntl.h>
|
8 |
|
|
#include <unistd.h>
|
9 |
|
|
|
10 |
|
|
#include "Vmain.h"
|
11 |
|
|
#include "verilated.h"
|
12 |
|
|
#include "verilated_vcd_c.h"
|
13 |
|
|
|
14 |
|
|
typedef unsigned char uint8;
|
15 |
|
|
typedef unsigned short uint16;
|
16 |
|
|
typedef unsigned int uint32;
|
17 |
|
|
typedef unsigned long uint64;
|
18 |
|
|
|
19 |
|
|
//------------------------------------------------------------------------------
|
20 |
|
|
|
21 |
|
|
FILE *check_fp = NULL;
|
22 |
|
|
|
23 |
|
|
char check_line[256];
|
24 |
|
|
char check_next[256];
|
25 |
|
|
int check_state = 0;
|
26 |
|
|
/*
|
27 |
|
|
|
28 |
|
|
1 - EOF is next
|
29 |
|
|
2 - both full; line will be used
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
|
|
uint32 check_next_irq_at = 0;
|
33 |
|
|
uint32 check_next_irq_vector = 0;
|
34 |
|
|
|
35 |
|
|
union memory_t {
|
36 |
|
|
uint8 bytes [134217728];
|
37 |
|
|
uint16 shorts[67108864];
|
38 |
|
|
uint32 ints [33554432];
|
39 |
|
|
};
|
40 |
|
|
memory_t check_memory;
|
41 |
|
|
|
42 |
|
|
uint32 instr_counter = 0;
|
43 |
|
|
|
44 |
|
|
void load_file(const char *name, int byte_location) {
|
45 |
|
|
FILE *fp = fopen(name, "rb");
|
46 |
|
|
if(fp == NULL) {
|
47 |
|
|
fprintf(stderr, "#ao486_reader: error opening file: %s\n", name);
|
48 |
|
|
exit(-1);
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
int int_ret = fseek(fp, 0, SEEK_END);
|
52 |
|
|
if(int_ret != 0) {
|
53 |
|
|
fclose(fp);
|
54 |
|
|
fprintf(stderr, "#ao486_reader: error stat file: %s\n", name);
|
55 |
|
|
exit(-1);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
long size = ftell(fp);
|
59 |
|
|
rewind(fp);
|
60 |
|
|
|
61 |
|
|
int_ret = fread((void *)&check_memory.bytes[byte_location], size, 1, fp);
|
62 |
|
|
if(int_ret != 1) {
|
63 |
|
|
fclose(fp);
|
64 |
|
|
fprintf(stderr, "#ao486_reader: error loading file: %s\n", name);
|
65 |
|
|
exit(-1);
|
66 |
|
|
}
|
67 |
|
|
fclose(fp);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
bool check_read_fp(char *line) {
|
71 |
|
|
while(true) {
|
72 |
|
|
char *endoffile = fgets(line, 256, check_fp);
|
73 |
|
|
if(endoffile == NULL) return false;
|
74 |
|
|
printf("line: %s\n", line);
|
75 |
|
|
uint32 val1 = 0, val2 = 0;
|
76 |
|
|
int scan_ret = sscanf(line, "Exception 0x%x at %x", &val1, &val2);
|
77 |
|
|
if(scan_ret == 2) {
|
78 |
|
|
//ignore
|
79 |
|
|
continue;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
val1 = val2 = 0;
|
83 |
|
|
scan_ret = sscanf(line, "IAC 0x%x at %d", &val1, &val2);
|
84 |
|
|
if(scan_ret == 2) {
|
85 |
|
|
check_next_irq_vector = val1;
|
86 |
|
|
check_next_irq_at = val2;
|
87 |
|
|
|
88 |
|
|
continue;
|
89 |
|
|
}
|
90 |
|
|
break;
|
91 |
|
|
}
|
92 |
|
|
return true;
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
void check_look_ahead_fp() {
|
96 |
|
|
uint64 curr_pos = ftell(check_fp);
|
97 |
|
|
|
98 |
|
|
char line[256];
|
99 |
|
|
check_read_fp(line);
|
100 |
|
|
check_read_fp(line);
|
101 |
|
|
check_read_fp(line);
|
102 |
|
|
|
103 |
|
|
int ret = fseek(check_fp, curr_pos, SEEK_SET);
|
104 |
|
|
if(ret != 0) {
|
105 |
|
|
fprintf(stderr, "#ao486_reader: can not seek reader file.\n");
|
106 |
|
|
exit(-1);
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
uint64 total_size = 0;
|
111 |
|
|
uint64 last_percent = 0;
|
112 |
|
|
|
113 |
|
|
void check_init() {
|
114 |
|
|
if(check_fp == NULL) {
|
115 |
|
|
//const char *filename = "./../backup/run-10/track.txt";
|
116 |
|
|
const char *filename = "./../../../ao486/io_win95pipeline_1.txt";
|
117 |
|
|
|
118 |
|
|
check_fp = fopen(filename, "rb");
|
119 |
|
|
if(check_fp == NULL) {
|
120 |
|
|
fprintf(stderr, "#ao486_reader: can not open reader file.\n");
|
121 |
|
|
exit(-1);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
struct stat st;
|
125 |
|
|
memset(&st, 0, sizeof(struct stat));
|
126 |
|
|
stat(filename, &st);
|
127 |
|
|
total_size = st.st_size;
|
128 |
|
|
fprintf(stderr, "#ao486_reader: total file size: %d\n", total_size);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
uint64 curr_pos = ftell(check_fp);
|
132 |
|
|
uint64 curr_percent = curr_pos * 100 / total_size;
|
133 |
|
|
if(curr_percent != last_percent) {
|
134 |
|
|
last_percent = curr_percent;
|
135 |
|
|
fprintf(stderr, "#ao486_reader: %d percent\n", (uint32)last_percent);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
if(check_state == 0) {
|
139 |
|
|
if(check_read_fp(check_line) == false) {
|
140 |
|
|
fprintf(stderr, "#ao486_reader: EOF\n");
|
141 |
|
|
exit(0);
|
142 |
|
|
}
|
143 |
|
|
if(check_read_fp(check_next) == false) {
|
144 |
|
|
check_state = 1;
|
145 |
|
|
return;
|
146 |
|
|
}
|
147 |
|
|
check_state = 2;
|
148 |
|
|
}
|
149 |
|
|
else if(check_state == 1) {
|
150 |
|
|
fprintf(stderr, "#ao486_reader: EOF\n");
|
151 |
|
|
exit(0);
|
152 |
|
|
}
|
153 |
|
|
else if(check_state == 2) {
|
154 |
|
|
memcpy(check_line, check_next, 256);
|
155 |
|
|
|
156 |
|
|
if(check_read_fp(check_next) == false) {
|
157 |
|
|
check_state = 1;
|
158 |
|
|
return;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
check_look_ahead_fp();
|
162 |
|
|
check_state = 2;
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
uint32 check_io_rd(uint32 address, uint32 byteenable) {
|
167 |
|
|
check_init();
|
168 |
|
|
|
169 |
|
|
uint32 io_addr = 0, io_byteena = 0, io_data = 0;
|
170 |
|
|
int scan_ret = sscanf(check_line, "io rd %x %x %x", &io_addr, &io_byteena, &io_data);
|
171 |
|
|
|
172 |
|
|
if(scan_ret == 3) {
|
173 |
|
|
if(address != io_addr) {
|
174 |
|
|
fprintf(stderr, "#check_io_rd MISMATCH:%s != l:%04x %x\n", check_line, address, byteenable);
|
175 |
|
|
exit(-1);
|
176 |
|
|
}
|
177 |
|
|
if(byteenable != io_byteena) {
|
178 |
|
|
fprintf(stderr, "#check_io_rd MISMATCH:%s != l:%04x %x\n", check_line, address, byteenable);
|
179 |
|
|
exit(-1);
|
180 |
|
|
}
|
181 |
|
|
}
|
182 |
|
|
else {
|
183 |
|
|
fprintf(stderr, "#check_io_rd MISMATCH: f:%s != l:%04x %x\n", check_line, address, byteenable);
|
184 |
|
|
exit(-1);
|
185 |
|
|
}
|
186 |
|
|
return io_data;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
void check_io_wr(uint32 address, uint32 byteenable, uint32 data) {
|
190 |
|
|
check_init();
|
191 |
|
|
|
192 |
|
|
uint32 io_addr = 0, io_byteena = 0, io_data = 0;
|
193 |
|
|
int scan_ret = sscanf(check_line, "io wr %x %x %x", &io_addr, &io_byteena, &io_data);
|
194 |
|
|
|
195 |
|
|
if(scan_ret == 3) {
|
196 |
|
|
if(((byteenable>>0) & 1) == 0) { data &= 0xFFFFFF00; io_data &= 0xFFFFFF00; }
|
197 |
|
|
if(((byteenable>>1) & 1) == 0) { data &= 0xFFFF00FF; io_data &= 0xFFFF00FF; }
|
198 |
|
|
if(((byteenable>>2) & 1) == 0) { data &= 0xFF00FFFF; io_data &= 0xFF00FFFF; }
|
199 |
|
|
if(((byteenable>>3) & 1) == 0) { data &= 0x00FFFFFF; io_data &= 0x00FFFFFF; }
|
200 |
|
|
|
201 |
|
|
if(address != io_addr) {
|
202 |
|
|
fprintf(stderr, "#check_io_wr MISMATCH:%s | %04x %x %08x\n", check_line, address, byteenable, data);
|
203 |
|
|
exit(-1);
|
204 |
|
|
}
|
205 |
|
|
if(byteenable != io_byteena) {
|
206 |
|
|
fprintf(stderr, "#check_io_wr MISMATCH:%s | %04x %x %08x\n", check_line, address, byteenable, data);
|
207 |
|
|
exit(-1);
|
208 |
|
|
}
|
209 |
|
|
if(data != io_data) {
|
210 |
|
|
fprintf(stderr, "#check_io_wr MISMATCH:%s | %04x %x %08x\n", check_line, address, byteenable, data);
|
211 |
|
|
exit(-1);
|
212 |
|
|
}
|
213 |
|
|
}
|
214 |
|
|
else {
|
215 |
|
|
fprintf(stderr, "#check_io_wr MISMATCH:%s | %04x %x %08x\n", check_line, address, byteenable, data);
|
216 |
|
|
exit(-1);
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
void check_mem_wr(uint32 address, uint32 byteenable, uint32 data) {
|
221 |
|
|
check_init();
|
222 |
|
|
|
223 |
|
|
uint32 mem_addr = 0, mem_byteena = 0, mem_data = 0;
|
224 |
|
|
int scan_ret = sscanf(check_line, "mem wr %x %x %x", &mem_addr, &mem_byteena, &mem_data);
|
225 |
|
|
|
226 |
|
|
if(scan_ret == 3) {
|
227 |
|
|
if(((byteenable>>0) & 1) == 0) { data &= 0xFFFFFF00; mem_data &= 0xFFFFFF00; }
|
228 |
|
|
if(((byteenable>>1) & 1) == 0) { data &= 0xFFFF00FF; mem_data &= 0xFFFF00FF; }
|
229 |
|
|
if(((byteenable>>2) & 1) == 0) { data &= 0xFF00FFFF; mem_data &= 0xFF00FFFF; }
|
230 |
|
|
if(((byteenable>>3) & 1) == 0) { data &= 0x00FFFFFF; mem_data &= 0x00FFFFFF; }
|
231 |
|
|
|
232 |
|
|
if(address != mem_addr) {
|
233 |
|
|
fprintf(stderr, "#check_mem_wr MISMATCH:%s != l:%08x %x %08x\n", check_line, address, byteenable, data);
|
234 |
|
|
exit(-1);
|
235 |
|
|
}
|
236 |
|
|
if(byteenable != mem_byteena) {
|
237 |
|
|
fprintf(stderr, "#check_mem_wr MISMATCH:%s != l:%08x %x %08x\n", check_line, address, byteenable, data);
|
238 |
|
|
exit(-1);
|
239 |
|
|
}
|
240 |
|
|
if(data != mem_data) {
|
241 |
|
|
fprintf(stderr, "#check_mem_wr MISMATCH:%s != l:%08x %x %08x\n", check_line, address, byteenable, data);
|
242 |
|
|
exit(-1);
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
for(uint32 i=0; i<4; i++) {
|
246 |
|
|
if(byteenable & 1) {
|
247 |
|
|
check_memory.bytes[address + i] = data & 0xFF;
|
248 |
|
|
}
|
249 |
|
|
byteenable >>= 1;
|
250 |
|
|
data >>= 8;
|
251 |
|
|
}
|
252 |
|
|
}
|
253 |
|
|
else {
|
254 |
|
|
fprintf(stderr, "#check_io_wr MISMATCH:%s != l:%08x %x %08x\n", check_line, address, byteenable, data);
|
255 |
|
|
exit(-1);
|
256 |
|
|
}
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
uint32 check_mem_rd(uint32 address, uint32 byteenable) {
|
260 |
|
|
check_init();
|
261 |
|
|
|
262 |
|
|
uint32 mem_addr = 0, mem_byteena = 0, mem_data = 0;
|
263 |
|
|
int scan_ret = sscanf(check_line, "mem rd %x %x %x", &mem_addr, &mem_byteena, &mem_data);
|
264 |
|
|
|
265 |
|
|
if(scan_ret == 3) {
|
266 |
|
|
if(address != mem_addr) {
|
267 |
|
|
fprintf(stderr, "#check_mem_rd MISMATCH:%s != l:%08x %x\n", check_line, address, byteenable);
|
268 |
|
|
exit(-1);
|
269 |
|
|
}
|
270 |
|
|
if(byteenable != mem_byteena) {
|
271 |
|
|
fprintf(stderr, "#check_mem_rd MISMATCH:%s != l:%08x %x\n", check_line, address, byteenable);
|
272 |
|
|
exit(-1);
|
273 |
|
|
}
|
274 |
|
|
}
|
275 |
|
|
else {
|
276 |
|
|
fprintf(stderr, "#check_mem_rd MISMATCH:%s != l:%04x %x\n", check_line, address, byteenable);
|
277 |
|
|
exit(-1);
|
278 |
|
|
}
|
279 |
|
|
return mem_data;
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
//------------------------------------------------------------------------------
|
283 |
|
|
|
284 |
|
|
int main(int argc, char **argv) {
|
285 |
|
|
|
286 |
|
|
load_file("./../../../sd/bios/bochs_legacy", 0xF0000);
|
287 |
|
|
load_file("./../../../sd/vgabios/vgabios_lgpl", 0xC0000);
|
288 |
|
|
|
289 |
|
|
{
|
290 |
|
|
FILE *fp = fopen("track.txt", "w");
|
291 |
|
|
fclose(fp);
|
292 |
|
|
|
293 |
|
|
fp = fopen("interrupt.txt", "w");
|
294 |
|
|
fclose(fp);
|
295 |
|
|
}
|
296 |
|
|
//--------------------------------------------------------------------------
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
Verilated::commandArgs(argc, argv);
|
300 |
|
|
|
301 |
|
|
Verilated::traceEverOn(true);
|
302 |
|
|
VerilatedVcdC* tracer = new VerilatedVcdC;
|
303 |
|
|
|
304 |
|
|
Vmain *top = new Vmain();
|
305 |
|
|
top->trace (tracer, 99);
|
306 |
|
|
// tracer->rolloverMB(1000000);
|
307 |
|
|
tracer->open("ao486.vcd");
|
308 |
|
|
//tracer->flush();
|
309 |
|
|
//return 0;
|
310 |
|
|
//reset
|
311 |
|
|
top->clk = 0; top->rst_n = 1; top->eval();
|
312 |
|
|
top->clk = 1; top->rst_n = 1; top->eval();
|
313 |
|
|
top->clk = 1; top->rst_n = 0; top->eval();
|
314 |
|
|
top->clk = 0; top->rst_n = 0; top->eval();
|
315 |
|
|
top->clk = 0; top->rst_n = 1; top->eval();
|
316 |
|
|
|
317 |
|
|
//--------------------------------------------------------------------------
|
318 |
|
|
|
319 |
|
|
uint32 sdram_read_count = 0;
|
320 |
|
|
uint32 sdram_read_data[4];
|
321 |
|
|
|
322 |
|
|
uint32 sdram_write_count = 0;
|
323 |
|
|
uint32 sdram_write_address = 0;
|
324 |
|
|
|
325 |
|
|
uint32 vga_read_count = 0;
|
326 |
|
|
uint32 vga_read_address = 0;
|
327 |
|
|
uint32 vga_read_byteenable = 0;
|
328 |
|
|
|
329 |
|
|
uint32 vga_write_count = 0;
|
330 |
|
|
uint32 vga_write_address = 0;
|
331 |
|
|
|
332 |
|
|
uint32 io_read_count = 0;
|
333 |
|
|
uint32 io_read_address = 0;
|
334 |
|
|
uint32 io_read_byteenable = 0;
|
335 |
|
|
|
336 |
|
|
uint32 dump_enabled = 0;
|
337 |
|
|
|
338 |
|
|
//--------------------------------------------------------------------------
|
339 |
|
|
|
340 |
|
|
uint64 cycle = 0;
|
341 |
|
|
|
342 |
|
|
char irq_txt[256];
|
343 |
|
|
int irq_delay = 0;
|
344 |
|
|
|
345 |
|
|
while(!Verilated::gotFinish()) {
|
346 |
|
|
|
347 |
|
|
//---------------------------------------------------------------------- sdram
|
348 |
|
|
|
349 |
|
|
top->sdram_readdatavalid = 0;
|
350 |
|
|
|
351 |
|
|
if(top->sdram_read) {
|
352 |
|
|
uint32 address = top->sdram_address & 0x07FFFFFC;
|
353 |
|
|
|
354 |
|
|
for(uint32 i=0; i<4; i++) {
|
355 |
|
|
sdram_read_data[i] = check_memory.ints[(address + i*4)/4];
|
356 |
|
|
|
357 |
|
|
if(((top->sdram_byteenable >> 0) & 1) == 0) sdram_read_data[i] &= 0xFFFFFF00;
|
358 |
|
|
if(((top->sdram_byteenable >> 1) & 1) == 0) sdram_read_data[i] &= 0xFFFF00FF;
|
359 |
|
|
if(((top->sdram_byteenable >> 2) & 1) == 0) sdram_read_data[i] &= 0xFF00FFFF;
|
360 |
|
|
if(((top->sdram_byteenable >> 3) & 1) == 0) sdram_read_data[i] &= 0x00FFFFFF;
|
361 |
|
|
}
|
362 |
|
|
sdram_read_count = top->sdram_burstcount;
|
363 |
|
|
|
364 |
|
|
//printf("sdram read: %08x %x [%08x %08x %08x %08x]\n", address, top->sdram_byteenable, sdram_read_data[0], sdram_read_data[1], sdram_read_data[2], sdram_read_data[3]);
|
365 |
|
|
}
|
366 |
|
|
else if(sdram_read_count > 0) {
|
367 |
|
|
top->sdram_readdatavalid = 1;
|
368 |
|
|
top->sdram_readdata = sdram_read_data[0];
|
369 |
|
|
//printf("r: %08x\n", top->sdram_readdata);
|
370 |
|
|
memmove(sdram_read_data, &sdram_read_data[1], sizeof(sdram_read_data)-sizeof(uint32));
|
371 |
|
|
sdram_read_count--;
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
if(top->sdram_write) {
|
375 |
|
|
uint32 address = (sdram_write_count > 0)? sdram_write_address : top->sdram_address & 0x07FFFFFC;
|
376 |
|
|
uint32 data = top->sdram_writedata;
|
377 |
|
|
|
378 |
|
|
if((top->sdram_byteenable & 0x1) == 0) data &= 0xFFFFFF00;
|
379 |
|
|
if((top->sdram_byteenable & 0x2) == 0) data &= 0xFFFF00FF;
|
380 |
|
|
if((top->sdram_byteenable & 0x4) == 0) data &= 0xFF00FFFF;
|
381 |
|
|
if((top->sdram_byteenable & 0x8) == 0) data &= 0x00FFFFFF;
|
382 |
|
|
|
383 |
|
|
printf("mem wr: %08x %x %08x %d\n", address, top->sdram_byteenable, data, sdram_write_count);
|
384 |
|
|
|
385 |
|
|
FILE *fp = fopen("track.txt", "a");
|
386 |
|
|
fprintf(fp, "mem wr %08x %x %08x\n", address, top->sdram_byteenable, data);
|
387 |
|
|
fclose(fp);
|
388 |
|
|
|
389 |
|
|
check_mem_wr(address, top->sdram_byteenable, data);
|
390 |
|
|
|
391 |
|
|
if(sdram_write_count == 0) {
|
392 |
|
|
sdram_write_address = (address + 4) & 0x07FFFFFC;
|
393 |
|
|
sdram_write_count = top->sdram_burstcount;
|
394 |
|
|
}
|
395 |
|
|
|
396 |
|
|
if(sdram_write_count > 0) sdram_write_count--;
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
//---------------------------------------------------------------------- vga
|
400 |
|
|
|
401 |
|
|
top->vga_readdatavalid = 0;
|
402 |
|
|
|
403 |
|
|
if(top->vga_read) {
|
404 |
|
|
vga_read_address = top->vga_address & 0x000FFFFC;
|
405 |
|
|
|
406 |
|
|
vga_read_count = top->vga_burstcount;
|
407 |
|
|
vga_read_byteenable = top->vga_byteenable;
|
408 |
|
|
printf("mem rd: %08x %x %d\n", vga_read_address, vga_read_byteenable, vga_read_count);
|
409 |
|
|
}
|
410 |
|
|
else if(vga_read_count > 0) {
|
411 |
|
|
|
412 |
|
|
uint32 value = check_mem_rd(vga_read_address, vga_read_byteenable);
|
413 |
|
|
|
414 |
|
|
top->vga_readdatavalid = 1;
|
415 |
|
|
top->vga_readdata = value;
|
416 |
|
|
|
417 |
|
|
FILE *fp = fopen("track.txt", "a");
|
418 |
|
|
fprintf(fp, "mem rd %08x %x %08x\n", vga_read_address, vga_read_byteenable, value);
|
419 |
|
|
fclose(fp);
|
420 |
|
|
|
421 |
|
|
vga_read_address = (vga_read_address + 4) & 0x000FFFFC;
|
422 |
|
|
vga_read_count--;
|
423 |
|
|
}
|
424 |
|
|
|
425 |
|
|
if(top->vga_write) {
|
426 |
|
|
uint32 address = (vga_write_count > 0)? vga_write_address : top->vga_address & 0x000FFFFC;
|
427 |
|
|
uint32 data = top->vga_writedata;
|
428 |
|
|
|
429 |
|
|
if((top->vga_byteenable & 0x1) == 0) data &= 0xFFFFFF00;
|
430 |
|
|
if((top->vga_byteenable & 0x2) == 0) data &= 0xFFFF00FF;
|
431 |
|
|
if((top->vga_byteenable & 0x4) == 0) data &= 0xFF00FFFF;
|
432 |
|
|
if((top->vga_byteenable & 0x8) == 0) data &= 0x00FFFFFF;
|
433 |
|
|
|
434 |
|
|
FILE *fp = fopen("track.txt", "a");
|
435 |
|
|
fprintf(fp, "mem wr %08x %x %08x\n", address, top->sdram_byteenable, data);
|
436 |
|
|
fclose(fp);
|
437 |
|
|
|
438 |
|
|
printf("mem wr: %08x %x %08x %d\n", address, top->sdram_byteenable, data, vga_write_count);
|
439 |
|
|
|
440 |
|
|
check_mem_wr(address, top->vga_byteenable, data);
|
441 |
|
|
|
442 |
|
|
if(vga_write_count == 0) {
|
443 |
|
|
vga_write_address = (address + 4) & 0x07FFFFFC;
|
444 |
|
|
vga_write_count = top->vga_burstcount;
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
if(vga_write_count > 0) vga_write_count--;
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
//---------------------------------------------------------------------- io
|
451 |
|
|
|
452 |
|
|
top->avalon_io_readdatavalid = 0;
|
453 |
|
|
|
454 |
|
|
if(top->avalon_io_read) {
|
455 |
|
|
io_read_address = top->avalon_io_address & 0x0000FFFC;
|
456 |
|
|
|
457 |
|
|
io_read_count = 1;
|
458 |
|
|
io_read_byteenable = top->avalon_io_byteenable;
|
459 |
|
|
printf("io rd: %08x %x %d\n", io_read_address, io_read_byteenable, io_read_count);
|
460 |
|
|
}
|
461 |
|
|
else if(io_read_count > 0) {
|
462 |
|
|
|
463 |
|
|
uint32 value = check_io_rd(io_read_address, io_read_byteenable);
|
464 |
|
|
|
465 |
|
|
FILE *fp = fopen("track.txt", "a");
|
466 |
|
|
fprintf(fp, "io rd %04x %x %08x\n", io_read_address, io_read_byteenable, value);
|
467 |
|
|
fclose(fp);
|
468 |
|
|
|
469 |
|
|
//if(io_read_address == 0x01F0 && io_read_byteenable == 0xF && value == 0x655301c6) shared_ptr->dump_enabled = 1;
|
470 |
|
|
|
471 |
|
|
top->avalon_io_readdatavalid = 1;
|
472 |
|
|
top->avalon_io_readdata = value;
|
473 |
|
|
|
474 |
|
|
io_read_count--;
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
if(top->avalon_io_write) {
|
478 |
|
|
uint32 data = top->avalon_io_writedata;
|
479 |
|
|
|
480 |
|
|
if((top->avalon_io_byteenable & 0x1) == 0) data &= 0xFFFFFF00;
|
481 |
|
|
if((top->avalon_io_byteenable & 0x2) == 0) data &= 0xFFFF00FF;
|
482 |
|
|
if((top->avalon_io_byteenable & 0x4) == 0) data &= 0xFF00FFFF;
|
483 |
|
|
if((top->avalon_io_byteenable & 0x8) == 0) data &= 0x00FFFFFF;
|
484 |
|
|
|
485 |
|
|
FILE *fp = fopen("track.txt", "a");
|
486 |
|
|
fprintf(fp, "io wr %04x %x %08x\n", top->avalon_io_address & 0x0000FFFC, top->avalon_io_byteenable, data);
|
487 |
|
|
fclose(fp);
|
488 |
|
|
|
489 |
|
|
printf("io wr: %08x %x %08x\n", (top->avalon_io_address & 0x0000FFFC), top->avalon_io_byteenable, data);
|
490 |
|
|
|
491 |
|
|
check_io_wr(top->avalon_io_address & 0x0000FFFC, top->avalon_io_byteenable, data);
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
//----------------------------------------------------------------------
|
495 |
|
|
if(top->tb_finish_instr) instr_counter++;
|
496 |
|
|
|
497 |
|
|
if(instr_counter >= 77020000) dump_enabled = 1;
|
498 |
|
|
//11490000
|
499 |
|
|
//---------------------------------------------------------------------- interrupt
|
500 |
|
|
|
501 |
|
|
top->interrupt_vector = check_next_irq_vector;
|
502 |
|
|
top->interrupt_do = (instr_counter == check_next_irq_at)? 1 : 0;
|
503 |
|
|
|
504 |
|
|
if(top->interrupt_done) {
|
505 |
|
|
sprintf(irq_txt, "IAC 0x%02x at %d\n", check_next_irq_vector, instr_counter);
|
506 |
|
|
irq_delay = 3;
|
507 |
|
|
}
|
508 |
|
|
else if(irq_delay > 0) {
|
509 |
|
|
if(irq_delay == 1) {
|
510 |
|
|
FILE *fp = fopen("track.txt", "a");
|
511 |
|
|
fprintf(fp, irq_txt);
|
512 |
|
|
fclose(fp);
|
513 |
|
|
|
514 |
|
|
fp = fopen("interrupt.txt", "a");
|
515 |
|
|
fprintf(fp, irq_txt);
|
516 |
|
|
fclose(fp);
|
517 |
|
|
}
|
518 |
|
|
|
519 |
|
|
irq_delay--;
|
520 |
|
|
}
|
521 |
|
|
|
522 |
|
|
//---------------------------------------------------------------------- exception
|
523 |
|
|
|
524 |
|
|
if(top->dbg_exc) {
|
525 |
|
|
FILE *fp = fopen("track.txt", "a");
|
526 |
|
|
fprintf(fp, "Exception 0x%02x at %d\n", top->dbg_exc_vector, instr_counter);
|
527 |
|
|
fclose(fp);
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
//----------------------------------------------------------------------
|
531 |
|
|
|
532 |
|
|
if(dump_enabled == 0 && fopen("start", "rb") != NULL) dump_enabled = 1;
|
533 |
|
|
|
534 |
|
|
top->clk = 0;
|
535 |
|
|
top->eval();
|
536 |
|
|
|
537 |
|
|
if(dump_enabled) tracer->dump(cycle++);
|
538 |
|
|
|
539 |
|
|
top->clk = 1;
|
540 |
|
|
top->eval();
|
541 |
|
|
|
542 |
|
|
if(dump_enabled) tracer->dump(cycle++);
|
543 |
|
|
|
544 |
|
|
tracer->flush();
|
545 |
|
|
|
546 |
|
|
if(instr_counter >= 77026000) { fprintf(stderr, "#ao486_reader: test finished.\n"); exit(0); }
|
547 |
|
|
//11491275
|
548 |
|
|
//usleep(1);
|
549 |
|
|
}
|
550 |
|
|
delete top;
|
551 |
|
|
return 0;
|
552 |
|
|
}
|