OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [sim/] [verilator/] [ao486/] [main_plugin.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
#include "shared_mem.h"
15
 
16
//------------------------------------------------------------------------------
17
 
18
volatile shared_mem_t *shared_ptr = NULL;
19
 
20
//------------------------------------------------------------------------------
21
 
22
int main(int argc, char **argv) {
23
    //map shared memory
24
    int fd = open("./../../../sim/sim_pc/shared_mem.dat", O_RDWR, S_IRUSR | S_IWUSR);
25
 
26
    if(fd == -1) {
27
        perror("open() failed for shared_mem.dat");
28
        return -1;
29
    }
30
 
31
    shared_ptr = (shared_mem_t *)mmap(NULL, sizeof(shared_mem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
32
 
33
    if(shared_ptr == MAP_FAILED) {
34
        perror("mmap() failed");
35
        close(fd);
36
        return -2;
37
    }
38
 
39
    //wait for ack
40
    shared_ptr->ao486.starting = STEP_REQ;
41
    printf("Waiting for startup ack...");
42
    fflush(stdout);
43
    while(shared_ptr->ao486.starting != STEP_ACK) {
44
        usleep(100000);
45
    }
46
    printf("done.\n");
47
 
48
    //--------------------------------------------------------------------------
49
 
50
 
51
    Verilated::commandArgs(argc, argv);
52
 
53
    Verilated::traceEverOn(true);
54
    VerilatedVcdC* tracer = new VerilatedVcdC;
55
 
56
    Vmain *top = new Vmain();
57
    top->trace (tracer, 99);
58
//    tracer->rolloverMB(1000000);
59
    tracer->open("ao486.vcd");
60
//tracer->flush();
61
//return 0;
62
    //reset
63
    top->clk = 0; top->rst_n = 1; top->eval();
64
    top->clk = 1; top->rst_n = 1; top->eval();
65
    top->clk = 1; top->rst_n = 0; top->eval();
66
    top->clk = 0; top->rst_n = 0; top->eval();
67
    top->clk = 0; top->rst_n = 1; top->eval();
68
 
69
    //--------------------------------------------------------------------------
70
 
71
    uint32 sdram_read_count = 0;
72
    uint32 sdram_read_data[4];
73
 
74
    uint32 sdram_write_count = 0;
75
    uint32 sdram_write_address = 0;
76
 
77
    uint32 vga_read_count = 0;
78
    uint32 vga_read_address = 0;
79
    uint32 vga_read_byteenable = 0;
80
 
81
    uint32 vga_write_count = 0;
82
    uint32 vga_write_address = 0;
83
 
84
    uint32 io_read_count = 0;
85
    uint32 io_read_address = 0;
86
    uint32 io_read_byteenable = 0;
87
 
88
    uint32 ignored_intr_counter = 0;
89
 
90
    //--------------------------------------------------------------------------
91
 
92
    uint64 cycle = 0;
93
 
94
    char irq_txt[256];
95
    int  irq_delay = 0;
96
 
97
    while(!Verilated::gotFinish()) {
98
 
99
        //----------------------------------------------------------------------
100
        if(top->tb_finish_instr) {
101
            shared_ptr->ao486.instr_counter++;
102
 
103
            if(shared_ptr->ao486.stop == STEP_REQ) {
104
                shared_ptr->ao486.stop = STEP_ACK;
105
                while(shared_ptr->ao486.stop != STEP_IDLE) {
106
                    usleep(500);
107
                }
108
            }
109
        }
110
 
111
        //---------------------------------------------------------------------- sdram
112
 
113
        top->sdram_readdatavalid = 0;
114
 
115
        if(top->sdram_read) {
116
            uint32 address = top->sdram_address & 0x07FFFFFC;
117
 
118
            for(uint32 i=0; i<4; i++) {
119
                sdram_read_data[i] = shared_ptr->mem.ints[(address + i*4)/4];
120
 
121
                if(((top->sdram_byteenable >> 0) & 1) == 0) sdram_read_data[i] &= 0xFFFFFF00;
122
                if(((top->sdram_byteenable >> 1) & 1) == 0) sdram_read_data[i] &= 0xFFFF00FF;
123
                if(((top->sdram_byteenable >> 2) & 1) == 0) sdram_read_data[i] &= 0xFF00FFFF;
124
                if(((top->sdram_byteenable >> 3) & 1) == 0) sdram_read_data[i] &= 0x00FFFFFF;
125
            }
126
            sdram_read_count = top->sdram_burstcount;
127
 
128
//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]);
129
        }
130
        else if(sdram_read_count > 0) {
131
            top->sdram_readdatavalid = 1;
132
            top->sdram_readdata = sdram_read_data[0];
133
//printf("r: %08x\n", top->sdram_readdata);
134
            memmove(sdram_read_data, &sdram_read_data[1], sizeof(sdram_read_data)-sizeof(uint32));
135
            sdram_read_count--;
136
        }
137
 
138
        if(top->sdram_write) {
139
            uint32 address = (sdram_write_count > 0)? sdram_write_address : top->sdram_address & 0x07FFFFFC;
140
            uint32 data = top->sdram_writedata;
141
 
142
            if((top->sdram_byteenable & 0x1) == 0) data &= 0xFFFFFF00;
143
            if((top->sdram_byteenable & 0x2) == 0) data &= 0xFFFF00FF;
144
            if((top->sdram_byteenable & 0x4) == 0) data &= 0xFF00FFFF;
145
            if((top->sdram_byteenable & 0x8) == 0) data &= 0x00FFFFFF;
146
 
147
printf("sdram write: %08x %x %08x %d", address, top->sdram_byteenable, data, sdram_write_count);
148
 
149
            FILE *fp = fopen("track.txt", "a");
150
            fprintf(fp, "mem wr %08x %x %08x\n", address, top->sdram_byteenable, data);
151
            fclose(fp);
152
 
153
            shared_ptr->ao486.mem_address    = address;
154
            shared_ptr->ao486.mem_byteenable = top->sdram_byteenable;
155
            shared_ptr->ao486.mem_is_write   = 1;
156
            shared_ptr->ao486.mem_data       = data;
157
            shared_ptr->ao486.mem_step       = STEP_REQ;
158
            while(shared_ptr->ao486.mem_step != STEP_ACK) {
159
                fflush(stdout);
160
                usleep(10);
161
            }
162
            shared_ptr->ao486.mem_step = STEP_IDLE;
163
 
164
            if(sdram_write_count == 0) {
165
                sdram_write_address = (address + 4) & 0x07FFFFFC;
166
                sdram_write_count = top->sdram_burstcount;
167
            }
168
 
169
            if(sdram_write_count > 0) sdram_write_count--;
170
printf("\n");
171
        }
172
 
173
        //---------------------------------------------------------------------- vga
174
 
175
        top->vga_readdatavalid = 0;
176
 
177
        if(top->vga_read) {
178
            vga_read_address = top->vga_address & 0x000FFFFC;
179
 
180
            vga_read_count = top->vga_burstcount;
181
            vga_read_byteenable = top->vga_byteenable;
182
printf("vga read: %08x %x %d\n", vga_read_address, vga_read_byteenable, vga_read_count);
183
        }
184
        else if(vga_read_count > 0) {
185
            shared_ptr->ao486.mem_address    = vga_read_address;
186
            shared_ptr->ao486.mem_byteenable = vga_read_byteenable;
187
            shared_ptr->ao486.mem_is_write   = 0;
188
            shared_ptr->ao486.mem_step       = STEP_REQ;
189
            while(shared_ptr->ao486.mem_step != STEP_ACK) {
190
                fflush(stdout);
191
                usleep(10);
192
            }
193
            uint32 value = shared_ptr->ao486.mem_data;
194
            shared_ptr->ao486.mem_step = STEP_IDLE;
195
 
196
            top->vga_readdatavalid = 1;
197
            top->vga_readdata = value;
198
 
199
            FILE *fp = fopen("track.txt", "a");
200
            fprintf(fp, "mem rd %08x %x %08x\n", vga_read_address, vga_read_byteenable, value);
201
            fclose(fp);
202
 
203
            vga_read_address = (vga_read_address + 4) & 0x000FFFFC;
204
            vga_read_count--;
205
printf("\n");
206
        }
207
 
208
        if(top->vga_write) {
209
            uint32 address = (vga_write_count > 0)? vga_write_address : top->vga_address & 0x000FFFFC;
210
            uint32 data = top->vga_writedata;
211
 
212
            if((top->vga_byteenable & 0x1) == 0) data &= 0xFFFFFF00;
213
            if((top->vga_byteenable & 0x2) == 0) data &= 0xFFFF00FF;
214
            if((top->vga_byteenable & 0x4) == 0) data &= 0xFF00FFFF;
215
            if((top->vga_byteenable & 0x8) == 0) data &= 0x00FFFFFF;
216
 
217
            FILE *fp = fopen("track.txt", "a");
218
            fprintf(fp, "mem wr %08x %x %08x\n", address, top->sdram_byteenable, data);
219
            fclose(fp);
220
 
221
printf("vga write: %08x %x %08x %d", address, top->sdram_byteenable, data, vga_write_count);
222
            shared_ptr->ao486.mem_address    = address;
223
            shared_ptr->ao486.mem_byteenable = top->vga_byteenable;
224
            shared_ptr->ao486.mem_is_write   = 1;
225
            shared_ptr->ao486.mem_data       = data;
226
            shared_ptr->ao486.mem_step       = STEP_REQ;
227
            while(shared_ptr->ao486.mem_step != STEP_ACK) {
228
                fflush(stdout);
229
                usleep(10);
230
            }
231
            shared_ptr->ao486.mem_step = STEP_IDLE;
232
 
233
            if(vga_write_count == 0) {
234
                vga_write_address = (address + 4) & 0x07FFFFFC;
235
                vga_write_count = top->vga_burstcount;
236
            }
237
 
238
            if(vga_write_count > 0) vga_write_count--;
239
printf("\n", vga_write_count);
240
        }
241
 
242
        //---------------------------------------------------------------------- io
243
 
244
        top->avalon_io_readdatavalid = 0;
245
 
246
        if(top->avalon_io_read) {
247
            io_read_address = top->avalon_io_address & 0x0000FFFC;
248
 
249
            io_read_count = 1;
250
            io_read_byteenable = top->avalon_io_byteenable;
251
printf("io read: %08x %x %d", io_read_address, io_read_byteenable, io_read_count);
252
        }
253
        else if(io_read_count > 0) {
254
            shared_ptr->ao486.io_address    = io_read_address;
255
            shared_ptr->ao486.io_byteenable = io_read_byteenable;
256
            shared_ptr->ao486.io_is_write   = 0;
257
            shared_ptr->ao486.io_step       = STEP_REQ;
258
            while(shared_ptr->ao486.io_step != STEP_ACK) {
259
                fflush(stdout);
260
                usleep(10);
261
            }
262
            uint32 value = shared_ptr->ao486.io_data;
263
            shared_ptr->ao486.io_step = STEP_IDLE;
264
 
265
            FILE *fp = fopen("track.txt", "a");
266
            fprintf(fp, "io rd %04x %x %08x\n", io_read_address, io_read_byteenable, value);
267
            fclose(fp);
268
 
269
//if(io_read_address == 0x01F0 && io_read_byteenable == 0xF && value == 0x655301c6) shared_ptr->dump_enabled = 1;
270
 
271
            top->avalon_io_readdatavalid = 1;
272
            top->avalon_io_readdata = value;
273
 
274
            io_read_count--;
275
printf("\n");
276
        }
277
 
278
        if(top->avalon_io_write) {
279
            uint32 data = top->avalon_io_writedata;
280
 
281
            if((top->avalon_io_byteenable & 0x1) == 0) data &= 0xFFFFFF00;
282
            if((top->avalon_io_byteenable & 0x2) == 0) data &= 0xFFFF00FF;
283
            if((top->avalon_io_byteenable & 0x4) == 0) data &= 0xFF00FFFF;
284
            if((top->avalon_io_byteenable & 0x8) == 0) data &= 0x00FFFFFF;
285
 
286
            FILE *fp = fopen("track.txt", "a");
287
            fprintf(fp, "io wr %04x %x %08x\n", top->avalon_io_address & 0x0000FFFC, top->avalon_io_byteenable, data);
288
            fclose(fp);
289
 
290
printf("io write: %08x %x %08x", (top->avalon_io_address & 0x0000FFFC), top->avalon_io_byteenable, data);
291
            shared_ptr->ao486.io_address    = top->avalon_io_address & 0x0000FFFC;
292
            shared_ptr->ao486.io_byteenable = top->avalon_io_byteenable;
293
            shared_ptr->ao486.io_is_write   = 1;
294
            shared_ptr->ao486.io_data       = data;
295
            shared_ptr->ao486.io_step       = STEP_REQ;
296
            while(shared_ptr->ao486.io_step != STEP_ACK) {
297
                fflush(stdout);
298
                usleep(10);
299
            }
300
            shared_ptr->ao486.io_step = STEP_IDLE;
301
printf("\n");
302
        }
303
 
304
        //---------------------------------------------------------------------- interrupt
305
 
306
        uint32 vec = shared_ptr->irq_do_vector;
307
        top->interrupt_vector = vec;
308
        top->interrupt_do     = (shared_ptr->irq_do == STEP_REQ)? 1 : 0;
309
 
310
        if(top->interrupt_done && shared_ptr->irq_done == STEP_IDLE) {
311
            shared_ptr->irq_done_vector = vec;
312
            shared_ptr->irq_done = STEP_REQ;
313
 
314
            const char *txt = "";
315
 
316
            if(shared_ptr->irq_do == STEP_IDLE)     txt = "-spurIDLE";
317
            else if(shared_ptr->irq_do == STEP_ACK) txt = "-spurACK";
318
 
319
            sprintf(irq_txt, "IAC%s 0x%02x at %d\n", txt, vec, shared_ptr->ao486.instr_counter);
320
            irq_delay = 3;
321
 
322
            shared_ptr->irq_do = STEP_ACK;
323
        }
324
        else if(irq_delay > 0) {
325
            if(irq_delay == 1) {
326
                FILE *fp = fopen("track.txt", "a");
327
                fprintf(fp, irq_txt);
328
                fclose(fp);
329
 
330
                fp = fopen("interrupt.txt", "a");
331
                fprintf(fp, irq_txt);
332
                fclose(fp);
333
            }
334
 
335
            irq_delay--;
336
        }
337
 
338
        //---------------------------------------------------------------------- exception
339
 
340
        if(top->dbg_exc) {
341
            FILE *fp = fopen("track.txt", "a");
342
            fprintf(fp, "Exception 0x%02x at %d\n", top->dbg_exc_vector, shared_ptr->ao486.instr_counter);
343
            fclose(fp);
344
        }
345
 
346
        //----------------------------------------------------------------------
347
 
348
        if(shared_ptr->dump_enabled == 0 && fopen("start", "rb") != NULL) shared_ptr->dump_enabled = 1;
349
        //else if(cycle > 142400000 || shared_ptr->ao486.instr_counter > 7720000) shared_ptr->dump_enabled = 1;
350
        //else if(shared_ptr->ao486.instr_counter > 712000) shared_ptr->dump_enabled = 1;
351
 
352
        //if(shared_ptr->ao486.instr_counter >= 11000000 && shared_ptr->ao486.instr_counter <= 13000000) shared_ptr->dump_enabled = 1;
353
        //else shared_ptr->dump_enabled = 0;
354
 
355
        //12032233
356
 
357
        //shared_ptr->dump_enabled = 1;
358
 
359
        top->clk = 0;
360
        top->eval();
361
 
362
        if(shared_ptr->dump_enabled) tracer->dump(cycle++);
363
 
364
        top->clk = 1;
365
        top->eval();
366
 
367
        if(shared_ptr->dump_enabled) tracer->dump(cycle++);
368
 
369
        if((cycle % 10000) == 0) printf("half-cycle: %lld\n", cycle);
370
 
371
        //12320000
372
 
373
        tracer->flush();
374
        //usleep(1);
375
    }
376
    delete top;
377
    return 0;
378
}
379
 
380
/*
381
    uint32 interrupt_vector;
382
    uint64 interrupt_timestamp;
383
    uint32 interrupt_valid;
384
 
385
    ----
386
 
387
    VL_IN8(clk,0,0);
388
    VL_IN8(rst_n,0,0);
389
 
390
    VL_IN8(interrupt_do,0,0);
391
    VL_IN8(interrupt_vector,7,0);
392
    VL_OUT8(interrupt_done,0,0);
393
 
394
    VL_OUT8(avalon_io_byteenable,3,0);
395
    VL_OUT8(avalon_io_read,0,0);
396
    VL_IN8(avalon_io_readdatavalid,0,0);
397
    VL_OUT8(avalon_io_write,0,0);
398
    VL_IN8(avalon_io_waitrequest,0,0);
399
    VL_OUT16(avalon_io_address,15,0);
400
    VL_IN(avalon_io_readdata,31,0);
401
    VL_OUT(avalon_io_writedata,31,0);
402
 
403
    VL_OUT8(sdram_byteenable,3,0);
404
    VL_OUT8(sdram_read,0,0);
405
    VL_OUT8(sdram_write,0,0);
406
    VL_OUT8(sdram_burstcount,2,0);
407
    VL_OUT(sdram_address,31,0);
408
    VL_OUT(sdram_writedata,31,0);
409
    VL_IN8(sdram_waitrequest,0,0);
410
    VL_IN8(sdram_readdatavalid,0,0);
411
    VL_IN(sdram_readdata,31,0);
412
 
413
    VL_OUT8(vga_byteenable,3,0);
414
    VL_OUT8(vga_read,0,0);
415
    VL_OUT8(vga_write,0,0);
416
    VL_IN8(vga_waitrequest,0,0);
417
    VL_IN8(vga_readdatavalid,0,0);
418
    VL_OUT8(vga_burstcount,2,0);
419
    VL_OUT(vga_address,31,0);
420
    VL_IN(vga_readdata,31,0);
421
    VL_OUT(vga_writedata,31,0);
422
*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.