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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [sim/] [verilator/] [soc/] [rtc/] [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 <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 "Vrtc.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
uint32 fdd_type       = 0x40;
29
uint32 hd_cylinders   = 1024;
30
uint32 hd_heads       = 16;
31
uint32 hd_spt         = 63;
32
bool boot_from_floppy = true;
33
 
34
uint32 translate_byte = 0;
35
 
36
//rtc contents 0-127
37
unsigned int cmos[128] = {
38
    0x00, //0x00: SEC BCD
39
    0x00, //0x01: ALARM SEC BCD
40
    0x00, //0x02: MIN BCD
41
    0x00, //0x03: ALARM MIN BCD
42
    0x12, //0x04: HOUR BCD 24h
43
    0x12, //0x05: ALARM HOUR BCD 24h
44
    0x01, //0x06: DAY OF WEEK Sunday=1
45
    0x03, //0x07: DAY OF MONTH BCD from 1
46
    0x11, //0x08: MONTH BCD from 1
47
    0x13, //0x09: YEAR BCD
48
    0x26, //0x0A: REG A
49
    0x02, //0x0B: REG B
50
    0x00, //0x0C: REG C
51
    0x80, //0x0D: REG D
52
    0x00, //0x0E: REG E - POST status
53
    0x00, //0x0F: REG F - shutdown status
54
 
55
    fdd_type, //0x10: floppy drive type; 0-none, 1-360K, 2-1.2M, 3-720K, 4-1.44M, 5-2.88M
56
    0x00, //0x11: configuration bits; not used
57
    0xF0, //0x12: hard disk types; 0-none, 1:E-type, F-type 16+
58
    0x00, //0x13: advanced configuration bits; not used
59
    0x0D, //0x14: equipment bits
60
    0x80, //0x15: base memory in 1k LSB
61
    0x02, //0x16: base memory in 1k MSB
62
    0x00, //0x17: memory size above 1m in 1k LSB
63
    0xFC, //0x18: memory size above 1m in 1k MSB
64
    0x2F, //0x19: extended hd types 1/2; type 47d
65
    0x00, //0x1A: extended hd types 2/2
66
 
67
    hd_cylinders & 0xFF,        //0x1B: hd 0 configuration 1/9; cylinders low
68
    (hd_cylinders >> 8) & 0xFF, //0x1C: hd 0 configuration 2/9; cylinders high
69
    hd_heads,                   //0x1D: hd 0 configuration 3/9; heads
70
    0xFF,                       //0x1E: hd 0 configuration 4/9; write pre-comp low
71
    0xFF,                       //0x1F: hd 0 configuration 5/9; write pre-comp high
72
    0xC8,                       //0x20: hd 0 configuration 6/9; retries/bad map/heads>8
73
    hd_cylinders & 0xFF,        //0x21: hd 0 configuration 7/9; landing zone low
74
    (hd_cylinders >> 8) & 0xFF, //0x22: hd 0 configuration 8/9; landing zone high
75
    hd_spt,                     //0x23: hd 0 configuration 9/9; sectors/track
76
 
77
    0x00, //0x24: hd 1 configuration 1/9
78
    0x00, //0x25: hd 1 configuration 2/9
79
    0x00, //0x26: hd 1 configuration 3/9
80
    0x00, //0x27: hd 1 configuration 4/9
81
    0x00, //0x28: hd 1 configuration 5/9
82
    0x00, //0x29: hd 1 configuration 6/9
83
    0x00, //0x2A: hd 1 configuration 7/9
84
    0x00, //0x2B: hd 1 configuration 8/9
85
    0x00, //0x2C: hd 1 configuration 9/9
86
 
87
    (boot_from_floppy)? 0x20u : 0x00u, //0x2D: boot sequence
88
 
89
    0x00, //0x2E: checksum MSB
90
    0x00, //0x2F: checksum LSB
91
 
92
    0x00, //0x30: memory size above 1m in 1k LSB
93
    0xFC, //0x31: memory size above 1m in 1k MSB
94
 
95
    0x20, //0x32: IBM century
96
    0x00, //0x33: ?
97
 
98
    0x00, //0x34: memory size above 16m in 64k LSB
99
    0x07, //0x35: memory size above 16m in 64k MSB; 128 MB
100
 
101
    0x00, //0x36: ?
102
    0x20, //0x37: IBM PS/2 century
103
 
104
    0x00,           //0x38: eltorito boot sequence; not used
105
    translate_byte, //0x39: ata translation policy 1/2
106
    0x00,           //0x3A: ata translation policy 2/2
107
 
108
    0x00, //0x3B: ?
109
    0x00, //0x3C: ?
110
 
111
    0x00, //0x3D: eltorito boot sequence; not used
112
 
113
    0x00, //0x3E: ?
114
    0x00, //0x3F: ?
115
 
116
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
120
};
121
 
122
//------------------------------------------------------------------------------
123
 
124
int main(int argc, char **argv) {
125
 
126
    //map shared memory
127
    int fd = open("./../../../sim_pc/shared_mem.dat", O_RDWR, S_IRUSR | S_IWUSR);
128
 
129
    if(fd == -1) {
130
        perror("open() failed for shared_mem.dat");
131
        return -1;
132
    }
133
 
134
    shared_ptr = (shared_mem_t *)mmap(NULL, sizeof(shared_mem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
135
 
136
    if(shared_ptr == MAP_FAILED) {
137
        perror("mmap() failed");
138
        close(fd);
139
        return -2;
140
    }
141
 
142
    Verilated::commandArgs(argc, argv);
143
 
144
    Verilated::traceEverOn(true);
145
    VerilatedVcdC* tracer = new VerilatedVcdC;
146
 
147
    Vrtc *top = new Vrtc();
148
    top->trace (tracer, 99);
149
    //tracer->rolloverMB(1000000);
150
    tracer->open("rtc.vcd");
151
 
152
    bool dump = false;
153
 
154
    //reset
155
    top->clk = 0; top->rst_n = 1; top->eval();
156
    top->clk = 1; top->rst_n = 1; top->eval();
157
    top->clk = 1; top->rst_n = 0; top->eval();
158
    top->clk = 0; top->rst_n = 0; top->eval();
159
    top->clk = 0; top->rst_n = 1; top->eval();
160
 
161
    uint64 cycle = 0;
162
    bool read_cycle = false;
163
 
164
    int CYCLES_IN_SECOND = 1000000;
165
    int CYCLES_IN_122_US = 100;
166
 
167
    //128.[26:0]: cycles in second
168
    //129.[12:0]: cycles in 122.07031 us
169
 
170
    for(uint32 i=0; i<130; i++) {
171
        top->mgmt_write = 1;
172
        top->mgmt_address = i;
173
        top->mgmt_writedata = (i==128)? CYCLES_IN_SECOND : (i==129)? CYCLES_IN_122_US : cmos[i];
174
 
175
        top->clk = 0;
176
        top->eval();
177
        if(dump) tracer->dump(cycle++);
178
 
179
        top->clk = 1;
180
        top->eval();
181
        if(dump) tracer->dump(cycle++);
182
 
183
        tracer->flush();
184
    }
185
    top->mgmt_write = 0;
186
 
187
    printf("rtc main_plugin.cpp\n");
188
 
189
    while(!Verilated::gotFinish()) {
190
 
191
        /*
192
        uint32 combined.io_address;
193
        uint32 combined.io_data;
194
        uint32 combined.io_byteenable;
195
        uint32 combined.io_is_write;
196
        step_t combined.io_step;
197
 
198
        //io slave 0x70-0x71
199
        input               io_address,
200
        input               io_read,
201
        output reg  [7:0]   io_readdata,
202
        input               io_write,
203
        input       [7:0]   io_writedata,
204
        */
205
 
206
        top->io_read      = 0;
207
        top->io_write     = 0;
208
 
209
        if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write && shared_ptr->combined.io_address == 0x0070 &&
210
            (shared_ptr->combined.io_byteenable == 1 || shared_ptr->combined.io_byteenable == 2))
211
        {
212
            top->io_address    = (shared_ptr->combined.io_byteenable == 1)?     0 :
213
                                                                                1;
214
            top->io_writedata  = (shared_ptr->combined.io_byteenable == 1)?     shared_ptr->combined.io_data & 0xFF :
215
                                                                                (shared_ptr->combined.io_data >> 8) & 0xFF;
216
            top->io_read  = 0;
217
            top->io_write = 1;
218
 
219
            shared_ptr->combined.io_step = STEP_ACK;
220
        }
221
 
222
        if(read_cycle == false) {
223
            if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 && shared_ptr->combined.io_address == 0x0070 &&
224
                (shared_ptr->combined.io_byteenable == 1 || shared_ptr->combined.io_byteenable == 2))
225
            {
226
                top->io_address = (shared_ptr->combined.io_byteenable == 1)?     0 :
227
                                                                                 1;
228
                top->io_writedata  = 0;
229
 
230
                top->io_read  = 1;
231
                top->io_write = 0;
232
 
233
                read_cycle = true;
234
            }
235
        }
236
        else {
237
            if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 && shared_ptr->combined.io_address == 0x0070 &&
238
                (shared_ptr->combined.io_byteenable == 1 || shared_ptr->combined.io_byteenable == 2))
239
            {
240
                uint32 val = top->io_readdata;
241
 
242
                if(shared_ptr->combined.io_byteenable & 1) val <<= 0;
243
                if(shared_ptr->combined.io_byteenable & 2) val <<= 8;
244
 
245
                shared_ptr->combined.io_data = val;
246
 
247
                read_cycle = false;
248
                shared_ptr->combined.io_step = STEP_ACK;
249
            }
250
        }
251
 
252
        //----------------------------------------------------------------------
253
 
254
        if(top->irq) {
255
            shared_ptr->rtc_irq_step = STEP_REQ;
256
        }
257
        else {
258
            shared_ptr->rtc_irq_step = STEP_IDLE;
259
        }
260
 
261
        //----------------------------------------------------------------------
262
 
263
        top->clk = 0;
264
        top->eval();
265
        if(dump) tracer->dump(cycle++);
266
 
267
        top->clk = 1;
268
        top->eval();
269
        if(dump) tracer->dump(cycle++);
270
 
271
        tracer->flush();
272
 
273
        usleep(1);
274
    }
275
    tracer->close();
276
    delete tracer;
277
    delete top;
278
 
279
    return 0;
280
}
281
 
282
//------------------------------------------------------------------------------
283
 
284
/*
285
    input               clk,
286
    input               rst_n,
287
 
288
    output reg          irq,
289
 
290
    //io slave 0x70-0x71
291
    input               io_address,
292
    input               io_read,
293
    output reg  [7:0]   io_readdata,
294
    input               io_write,
295
    input       [7:0]   io_writedata,
296
 
297
    //mgmt slave
298
    //128.[26:0]: cycles in second
299
    //129.[12:0]: cycles in 122.07031 us
300
 
301
    input       [7:0]   mgmt_address,
302
    input               mgmt_write,
303
    input       [31:0]  mgmt_writedata
304
*/

powered by: WebSVN 2.1.0

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