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 "Vps2.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 |
|
|
#define SEND_BUF_LIMIT 5
|
29 |
|
|
|
30 |
|
|
int kb_send[SEND_BUF_LIMIT];
|
31 |
|
|
int kb_send_count = 0;
|
32 |
|
|
|
33 |
|
|
int mouse_send[SEND_BUF_LIMIT];
|
34 |
|
|
int mouse_send_count = 0;
|
35 |
|
|
|
36 |
|
|
void send_byte(uint8 byte, int *table, int &count) {
|
37 |
|
|
if(count >= SEND_BUF_LIMIT) {
|
38 |
|
|
printf("ERROR: send buffer overflow.\n");
|
39 |
|
|
exit(-1);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
int parity = 1;
|
43 |
|
|
for(int i=0; i<8; i++) parity ^= ((byte >> i) & 1);
|
44 |
|
|
int new_byte = byte;
|
45 |
|
|
new_byte |= (parity & 1) << 8;
|
46 |
|
|
|
47 |
|
|
table[count] = new_byte;
|
48 |
|
|
count++;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
void kb_send_byte(uint8 byte) { send_byte(byte, kb_send, kb_send_count); }
|
52 |
|
|
void mouse_send_byte(uint8 byte) { send_byte(byte, mouse_send, mouse_send_count); }
|
53 |
|
|
|
54 |
|
|
//------------------------------------------------------------------------------
|
55 |
|
|
|
56 |
|
|
void keyboard_controller(uint32 got) {
|
57 |
|
|
if(got == 0xFF) {
|
58 |
|
|
printf("resp: 0xFA, 0xAA\n");
|
59 |
|
|
kb_send_byte(0xFA);
|
60 |
|
|
kb_send_byte(0xAA);
|
61 |
|
|
}
|
62 |
|
|
else {
|
63 |
|
|
printf("resp: 0xFA\n");
|
64 |
|
|
kb_send_byte(0xFA);
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
void mouse_controller(uint32 got) {
|
69 |
|
|
if(got == 0xFF) {
|
70 |
|
|
printf("resp: 0xFA, 0xAA, 0x00\n");
|
71 |
|
|
mouse_send_byte(0xFA);
|
72 |
|
|
mouse_send_byte(0xAA);
|
73 |
|
|
mouse_send_byte(0x00);
|
74 |
|
|
}
|
75 |
|
|
else if(got == 0xF2) {
|
76 |
|
|
printf("resp: 0xFA, 0x00\n");
|
77 |
|
|
mouse_send_byte(0xFA);
|
78 |
|
|
mouse_send_byte(0x00);
|
79 |
|
|
}
|
80 |
|
|
else {
|
81 |
|
|
printf("resp: 0xFA\n");
|
82 |
|
|
mouse_send_byte(0xFA);
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
//------------------------------------------------------------------------------
|
88 |
|
|
|
89 |
|
|
//0 - wait for ena + 0
|
90 |
|
|
//r - wait for !ena
|
91 |
|
|
//z - set zero
|
92 |
|
|
//o - set one
|
93 |
|
|
//c - capture
|
94 |
|
|
const char *clk_recv_string = "0 rzo zo zo zo zo zo zo zo zo zo zo zo";
|
95 |
|
|
const char *dat_recv_string = " 0 c c c c c c c c c c czo";
|
96 |
|
|
|
97 |
|
|
const char *clk_send_string = "zozozozozozozozozozozo";
|
98 |
|
|
const char *dat_send_string = "z i i i i i i i i i oo";
|
99 |
|
|
|
100 |
|
|
void proceed_ps2(int &index, int &waiting, int &wait_limit, int &recv_byte, bool &is_recv, bool &clk_hold, int &clk_hold_value, bool &dat_hold, int &dat_hold_value, int &send_count, bool recv_start,
|
101 |
|
|
bool recv_start_zero, bool recv_release, bool recv_dat_start_zero, int &sending_byte, int receiving_byte, bool is_mouse)
|
102 |
|
|
{
|
103 |
|
|
waiting++;
|
104 |
|
|
if(waiting == wait_limit) {
|
105 |
|
|
waiting = 0;
|
106 |
|
|
wait_limit = 50;
|
107 |
|
|
|
108 |
|
|
if(recv_start) {
|
109 |
|
|
is_recv = true;
|
110 |
|
|
index = 0;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
clk_hold = false;
|
114 |
|
|
dat_hold = false;
|
115 |
|
|
|
116 |
|
|
if(is_recv || send_count > 0) {
|
117 |
|
|
|
118 |
|
|
bool clk_continue = false;
|
119 |
|
|
switch(is_recv? clk_recv_string[index] : clk_send_string[index]) {
|
120 |
|
|
case ' ':
|
121 |
|
|
clk_continue = true;
|
122 |
|
|
break;
|
123 |
|
|
case '0':
|
124 |
|
|
if(recv_start_zero) clk_continue = true;
|
125 |
|
|
break;
|
126 |
|
|
case 'r':
|
127 |
|
|
if(recv_release) clk_continue = true;
|
128 |
|
|
break;
|
129 |
|
|
case 'z':
|
130 |
|
|
clk_continue = true;
|
131 |
|
|
clk_hold_value = 0;
|
132 |
|
|
clk_hold = true;
|
133 |
|
|
break;
|
134 |
|
|
case 'o':
|
135 |
|
|
clk_continue = true;
|
136 |
|
|
clk_hold_value = 1;
|
137 |
|
|
clk_hold = true;
|
138 |
|
|
break;
|
139 |
|
|
default:
|
140 |
|
|
printf("ERROR: unknown val.\n");
|
141 |
|
|
exit(-1);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
bool dat_continue = false;
|
145 |
|
|
switch(is_recv? dat_recv_string[index] : dat_send_string[index]) {
|
146 |
|
|
case ' ':
|
147 |
|
|
dat_continue = true;
|
148 |
|
|
break;
|
149 |
|
|
case '0':
|
150 |
|
|
if(recv_dat_start_zero) dat_continue = true;
|
151 |
|
|
break;
|
152 |
|
|
case 'z':
|
153 |
|
|
dat_continue = true;
|
154 |
|
|
dat_hold_value = 0;
|
155 |
|
|
dat_hold = true;
|
156 |
|
|
break;
|
157 |
|
|
case 'o':
|
158 |
|
|
dat_continue = true;
|
159 |
|
|
dat_hold_value = 1;
|
160 |
|
|
dat_hold = true;
|
161 |
|
|
break;
|
162 |
|
|
case 'i':
|
163 |
|
|
dat_continue = true;
|
164 |
|
|
dat_hold_value = sending_byte & 1;
|
165 |
|
|
dat_hold = true;
|
166 |
|
|
sending_byte >>= 1;
|
167 |
|
|
break;
|
168 |
|
|
case 'c':
|
169 |
|
|
dat_continue = true;
|
170 |
|
|
recv_byte <<= 1;
|
171 |
|
|
recv_byte |= receiving_byte & 1;
|
172 |
|
|
break;
|
173 |
|
|
default:
|
174 |
|
|
printf("ERROR: unknown val.\n");
|
175 |
|
|
exit(-1);
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
if(clk_continue && dat_continue) index++;
|
179 |
|
|
|
180 |
|
|
if(is_recv && index == strlen(clk_recv_string)) {
|
181 |
|
|
index = 0;
|
182 |
|
|
is_recv = false;
|
183 |
|
|
|
184 |
|
|
int byte = 0;
|
185 |
|
|
for(int i=0; i<8; i++) byte |= ((recv_byte >> (9-i)) & 1) << i;
|
186 |
|
|
int parity = 0;
|
187 |
|
|
for(int i=0; i<9; i++) parity ^= ((recv_byte >> (9-i)) & 1);
|
188 |
|
|
int stop = recv_byte & 1;
|
189 |
|
|
int start = (recv_byte >> 10) & 1;
|
190 |
|
|
printf("Recv: is_mouse %d, start: %x, byte: %02x, parity: %x, stop: %x\n", is_mouse, start, byte, parity, stop);
|
191 |
|
|
|
192 |
|
|
wait_limit = 50000;
|
193 |
|
|
|
194 |
|
|
if(is_mouse) mouse_controller(byte);
|
195 |
|
|
else keyboard_controller(byte);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
if(is_recv == false && index == strlen(clk_send_string)) {
|
199 |
|
|
index = 0;
|
200 |
|
|
is_recv = false;
|
201 |
|
|
|
202 |
|
|
if(is_mouse) {
|
203 |
|
|
for(int i=0; i<SEND_BUF_LIMIT-1; i++) mouse_send[i] = mouse_send[i+1];
|
204 |
|
|
mouse_send_count--;
|
205 |
|
|
}
|
206 |
|
|
else {
|
207 |
|
|
for(int i=0; i<SEND_BUF_LIMIT-1; i++) kb_send[i] = kb_send[i+1];
|
208 |
|
|
kb_send_count--;
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
if(index == 0) {
|
215 |
|
|
clk_hold = true;
|
216 |
|
|
clk_hold_value = 1;
|
217 |
|
|
|
218 |
|
|
dat_hold = true;
|
219 |
|
|
dat_hold_value = 1;
|
220 |
|
|
}
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
//------------------------------------------------------------------------------
|
225 |
|
|
|
226 |
|
|
int main(int argc, char **argv) {
|
227 |
|
|
|
228 |
|
|
//map shared memory
|
229 |
|
|
int fd = open("./../../../sim_pc/shared_mem.dat", O_RDWR, S_IRUSR | S_IWUSR);
|
230 |
|
|
|
231 |
|
|
if(fd == -1) {
|
232 |
|
|
perror("open() failed for shared_mem.dat");
|
233 |
|
|
return -1;
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
shared_ptr = (shared_mem_t *)mmap(NULL, sizeof(shared_mem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
237 |
|
|
|
238 |
|
|
if(shared_ptr == MAP_FAILED) {
|
239 |
|
|
perror("mmap() failed");
|
240 |
|
|
close(fd);
|
241 |
|
|
return -2;
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
Verilated::commandArgs(argc, argv);
|
245 |
|
|
|
246 |
|
|
Verilated::traceEverOn(true);
|
247 |
|
|
VerilatedVcdC* tracer = new VerilatedVcdC;
|
248 |
|
|
|
249 |
|
|
Vps2 *top = new Vps2();
|
250 |
|
|
top->trace (tracer, 99);
|
251 |
|
|
//tracer->rolloverMB(1000000);
|
252 |
|
|
tracer->open("ps2.vcd");
|
253 |
|
|
|
254 |
|
|
//reset
|
255 |
|
|
top->clk = 0; top->rst_n = 1; top->eval();
|
256 |
|
|
top->clk = 1; top->rst_n = 1; top->eval();
|
257 |
|
|
top->clk = 1; top->rst_n = 0; top->eval();
|
258 |
|
|
top->clk = 0; top->rst_n = 0; top->eval();
|
259 |
|
|
top->clk = 0; top->rst_n = 1; top->eval();
|
260 |
|
|
|
261 |
|
|
bool dump = false;
|
262 |
|
|
uint64 cycle = 0;
|
263 |
|
|
bool read_cycle = false;
|
264 |
|
|
|
265 |
|
|
printf("ps2 main_plugin.cpp\n");
|
266 |
|
|
|
267 |
|
|
//keyboard
|
268 |
|
|
int kb_index = 0;
|
269 |
|
|
int kb_waiting = 0;
|
270 |
|
|
int kb_wait_limit = 50;
|
271 |
|
|
int kb_recv_byte = 0;
|
272 |
|
|
bool kb_is_recv = false;
|
273 |
|
|
|
274 |
|
|
bool kb_clk_hold = false;
|
275 |
|
|
int kb_clk_hold_value = 0;
|
276 |
|
|
bool kb_dat_hold = false;
|
277 |
|
|
int kb_dat_hold_value = 0;
|
278 |
|
|
|
279 |
|
|
//mouse
|
280 |
|
|
int ms_index = 0;
|
281 |
|
|
int ms_waiting = 0;
|
282 |
|
|
int ms_wait_limit = 50;
|
283 |
|
|
int ms_recv_byte = 0;
|
284 |
|
|
bool ms_is_recv = false;
|
285 |
|
|
|
286 |
|
|
bool ms_clk_hold = false;
|
287 |
|
|
int ms_clk_hold_value = 0;
|
288 |
|
|
bool ms_dat_hold = false;
|
289 |
|
|
int ms_dat_hold_value = 0;
|
290 |
|
|
|
291 |
|
|
int a20_last = 1;
|
292 |
|
|
|
293 |
|
|
while(!Verilated::gotFinish()) {
|
294 |
|
|
|
295 |
|
|
//test
|
296 |
|
|
/*
|
297 |
|
|
top->io_address = 0;
|
298 |
|
|
top->io_write = 0;
|
299 |
|
|
if(first_run == 0) {
|
300 |
|
|
top->io_write = 1;
|
301 |
|
|
top->io_writedata = 0xFA;
|
302 |
|
|
|
303 |
|
|
first_run = 1;
|
304 |
|
|
}
|
305 |
|
|
*/
|
306 |
|
|
|
307 |
|
|
proceed_ps2(kb_index, kb_waiting, kb_wait_limit, kb_recv_byte, kb_is_recv, kb_clk_hold, kb_clk_hold_value, kb_dat_hold, kb_dat_hold_value, kb_send_count,
|
308 |
|
|
top->v__DOT__ps2_kbclk_ena && top->v__DOT__ps2_kbclk_out == 0 && kb_is_recv == false,
|
309 |
|
|
top->v__DOT__ps2_kbclk_ena && top->v__DOT__ps2_kbclk_out == 0,
|
310 |
|
|
top->v__DOT__ps2_kbclk_ena == 0,
|
311 |
|
|
top->v__DOT__ps2_kbdat_ena && top->v__DOT__ps2_kbdat_out == 0,
|
312 |
|
|
kb_send[0],
|
313 |
|
|
top->v__DOT__ps2_kbdat_out,
|
314 |
|
|
false);
|
315 |
|
|
|
316 |
|
|
proceed_ps2(ms_index, ms_waiting, ms_wait_limit, ms_recv_byte, ms_is_recv, ms_clk_hold, ms_clk_hold_value, ms_dat_hold, ms_dat_hold_value, mouse_send_count,
|
317 |
|
|
top->v__DOT__ps2_mouseclk_ena && top->v__DOT__ps2_mouseclk_out == 0 && ms_is_recv == false,
|
318 |
|
|
top->v__DOT__ps2_mouseclk_ena && top->v__DOT__ps2_mouseclk_out == 0,
|
319 |
|
|
top->v__DOT__ps2_mouseclk_ena == 0,
|
320 |
|
|
top->v__DOT__ps2_mousedat_ena && top->v__DOT__ps2_mousedat_out == 0,
|
321 |
|
|
mouse_send[0],
|
322 |
|
|
top->v__DOT__ps2_mousedat_out,
|
323 |
|
|
true);
|
324 |
|
|
|
325 |
|
|
/*
|
326 |
|
|
uint32 combined.io_address;
|
327 |
|
|
uint32 combined.io_data;
|
328 |
|
|
uint32 combined.io_byteenable;
|
329 |
|
|
uint32 combined.io_is_write;
|
330 |
|
|
step_t combined.io_step;
|
331 |
|
|
|
332 |
|
|
//io slave 0x60-0x67
|
333 |
|
|
input [2:0] io_address,
|
334 |
|
|
input io_read,
|
335 |
|
|
output reg [7:0] io_readdata,
|
336 |
|
|
input io_write,
|
337 |
|
|
input [7:0] io_writedata,
|
338 |
|
|
|
339 |
|
|
//io slave 0x90-0x9F
|
340 |
|
|
input [3:0] sysctl_address,
|
341 |
|
|
input sysctl_read,
|
342 |
|
|
output reg [7:0] sysctl_readdata,
|
343 |
|
|
input sysctl_write,
|
344 |
|
|
input [7:0] sysctl_writedata,
|
345 |
|
|
*/
|
346 |
|
|
|
347 |
|
|
top->io_read = 0;
|
348 |
|
|
top->io_write = 0;
|
349 |
|
|
|
350 |
|
|
top->sysctl_read = 0;
|
351 |
|
|
top->sysctl_write = 0;
|
352 |
|
|
|
353 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write &&
|
354 |
|
|
((shared_ptr->combined.io_address == 0x0060 && ((shared_ptr->combined.io_byteenable >> 1) & 1) == 0) || shared_ptr->combined.io_address == 0x0064))
|
355 |
|
|
{
|
356 |
|
|
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) {
|
357 |
|
|
printf("Vps2 0x60: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
|
358 |
|
|
exit(-1);
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
top->io_address = (shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
362 |
|
|
(shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
363 |
|
|
(shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
364 |
|
|
(shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
365 |
|
|
(shared_ptr->combined.io_address == 0x0064 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
366 |
|
|
(shared_ptr->combined.io_address == 0x0064 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
367 |
|
|
(shared_ptr->combined.io_address == 0x0064 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
368 |
|
|
7;
|
369 |
|
|
|
370 |
|
|
top->io_writedata = (shared_ptr->combined.io_byteenable == 1)? shared_ptr->combined.io_data & 0xFF :
|
371 |
|
|
(shared_ptr->combined.io_byteenable == 2)? (shared_ptr->combined.io_data >> 8) & 0xFF :
|
372 |
|
|
(shared_ptr->combined.io_byteenable == 4)? (shared_ptr->combined.io_data >> 16) & 0xFF :
|
373 |
|
|
(shared_ptr->combined.io_data >> 24) & 0xFF;
|
374 |
|
|
top->io_read = 0;
|
375 |
|
|
top->io_write = 1;
|
376 |
|
|
|
377 |
|
|
shared_ptr->combined.io_step = STEP_ACK;
|
378 |
|
|
}
|
379 |
|
|
|
380 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write &&
|
381 |
|
|
(shared_ptr->combined.io_address == 0x0090 || shared_ptr->combined.io_address == 0x0094 || shared_ptr->combined.io_address == 0x0098 || shared_ptr->combined.io_address == 0x009C))
|
382 |
|
|
{
|
383 |
|
|
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) {
|
384 |
|
|
printf("Vps2 0x90: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
|
385 |
|
|
exit(-1);
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
top->sysctl_address= (shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
389 |
|
|
(shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
390 |
|
|
(shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
391 |
|
|
(shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
392 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
393 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
394 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
395 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 8)? 7 :
|
396 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 1)? 8 :
|
397 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 2)? 9 :
|
398 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 4)? 10 :
|
399 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 8)? 11 :
|
400 |
|
|
(shared_ptr->combined.io_address == 0x009C && shared_ptr->combined.io_byteenable == 1)? 12 :
|
401 |
|
|
(shared_ptr->combined.io_address == 0x009C && shared_ptr->combined.io_byteenable == 2)? 13 :
|
402 |
|
|
(shared_ptr->combined.io_address == 0x009C && shared_ptr->combined.io_byteenable == 4)? 14 :
|
403 |
|
|
15;
|
404 |
|
|
|
405 |
|
|
top->sysctl_writedata = (shared_ptr->combined.io_byteenable == 1)? shared_ptr->combined.io_data & 0xFF :
|
406 |
|
|
(shared_ptr->combined.io_byteenable == 2)? (shared_ptr->combined.io_data >> 8) & 0xFF :
|
407 |
|
|
(shared_ptr->combined.io_byteenable == 4)? (shared_ptr->combined.io_data >> 16) & 0xFF :
|
408 |
|
|
(shared_ptr->combined.io_data >> 24) & 0xFF;
|
409 |
|
|
top->sysctl_read = 0;
|
410 |
|
|
top->sysctl_write = 1;
|
411 |
|
|
|
412 |
|
|
shared_ptr->combined.io_step = STEP_ACK;
|
413 |
|
|
}
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
if(read_cycle == false) {
|
417 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 &&
|
418 |
|
|
((shared_ptr->combined.io_address == 0x0060 && ((shared_ptr->combined.io_byteenable >> 1) & 1) == 0) || shared_ptr->combined.io_address == 0x0064))
|
419 |
|
|
{
|
420 |
|
|
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) {
|
421 |
|
|
printf("Vps2 0x60: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
|
422 |
|
|
exit(-1);
|
423 |
|
|
}
|
424 |
|
|
|
425 |
|
|
top->io_address= (shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
426 |
|
|
(shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
427 |
|
|
(shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
428 |
|
|
(shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
429 |
|
|
(shared_ptr->combined.io_address == 0x0064 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
430 |
|
|
(shared_ptr->combined.io_address == 0x0064 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
431 |
|
|
(shared_ptr->combined.io_address == 0x0064 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
432 |
|
|
7;
|
433 |
|
|
top->io_writedata = 0;
|
434 |
|
|
|
435 |
|
|
top->io_read = 1;
|
436 |
|
|
top->io_write = 0;
|
437 |
|
|
|
438 |
|
|
read_cycle = true;
|
439 |
|
|
}
|
440 |
|
|
|
441 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 &&
|
442 |
|
|
(shared_ptr->combined.io_address == 0x0090 || shared_ptr->combined.io_address == 0x0094 || shared_ptr->combined.io_address == 0x0098 || shared_ptr->combined.io_address == 0x009C))
|
443 |
|
|
{
|
444 |
|
|
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) {
|
445 |
|
|
printf("Vps2 0x90: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
|
446 |
|
|
exit(-1);
|
447 |
|
|
}
|
448 |
|
|
|
449 |
|
|
top->sysctl_address= (shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 1)? 0 :
|
450 |
|
|
(shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 2)? 1 :
|
451 |
|
|
(shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 4)? 2 :
|
452 |
|
|
(shared_ptr->combined.io_address == 0x0090 && shared_ptr->combined.io_byteenable == 8)? 3 :
|
453 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 1)? 4 :
|
454 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 2)? 5 :
|
455 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 4)? 6 :
|
456 |
|
|
(shared_ptr->combined.io_address == 0x0094 && shared_ptr->combined.io_byteenable == 8)? 7 :
|
457 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 1)? 8 :
|
458 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 2)? 9 :
|
459 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 4)? 10 :
|
460 |
|
|
(shared_ptr->combined.io_address == 0x0098 && shared_ptr->combined.io_byteenable == 8)? 11 :
|
461 |
|
|
(shared_ptr->combined.io_address == 0x009C && shared_ptr->combined.io_byteenable == 1)? 12 :
|
462 |
|
|
(shared_ptr->combined.io_address == 0x009C && shared_ptr->combined.io_byteenable == 2)? 13 :
|
463 |
|
|
(shared_ptr->combined.io_address == 0x009C && shared_ptr->combined.io_byteenable == 4)? 14 :
|
464 |
|
|
15;
|
465 |
|
|
top->sysctl_writedata = 0;
|
466 |
|
|
|
467 |
|
|
top->sysctl_read = 1;
|
468 |
|
|
top->sysctl_write = 0;
|
469 |
|
|
|
470 |
|
|
read_cycle = true;
|
471 |
|
|
}
|
472 |
|
|
}
|
473 |
|
|
else {
|
474 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 &&
|
475 |
|
|
((shared_ptr->combined.io_address == 0x0060 && ((shared_ptr->combined.io_byteenable >> 1) & 1) == 0) || shared_ptr->combined.io_address == 0x0064))
|
476 |
|
|
{
|
477 |
|
|
uint32 val = top->io_readdata;
|
478 |
|
|
|
479 |
|
|
if(shared_ptr->combined.io_byteenable & 1) val <<= 0;
|
480 |
|
|
if(shared_ptr->combined.io_byteenable & 2) val <<= 8;
|
481 |
|
|
if(shared_ptr->combined.io_byteenable & 4) val <<= 16;
|
482 |
|
|
if(shared_ptr->combined.io_byteenable & 8) val <<= 24;
|
483 |
|
|
|
484 |
|
|
shared_ptr->combined.io_data = val;
|
485 |
|
|
|
486 |
|
|
read_cycle = false;
|
487 |
|
|
shared_ptr->combined.io_step = STEP_ACK;
|
488 |
|
|
}
|
489 |
|
|
|
490 |
|
|
if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 &&
|
491 |
|
|
(shared_ptr->combined.io_address == 0x0090 || shared_ptr->combined.io_address == 0x0094 || shared_ptr->combined.io_address == 0x0098 || shared_ptr->combined.io_address == 0x009C))
|
492 |
|
|
{
|
493 |
|
|
uint32 val = top->sysctl_readdata;
|
494 |
|
|
|
495 |
|
|
if(shared_ptr->combined.io_byteenable & 1) val <<= 0;
|
496 |
|
|
if(shared_ptr->combined.io_byteenable & 2) val <<= 8;
|
497 |
|
|
if(shared_ptr->combined.io_byteenable & 4) val <<= 16;
|
498 |
|
|
if(shared_ptr->combined.io_byteenable & 8) val <<= 24;
|
499 |
|
|
|
500 |
|
|
shared_ptr->combined.io_data = val;
|
501 |
|
|
|
502 |
|
|
read_cycle = false;
|
503 |
|
|
shared_ptr->combined.io_step = STEP_ACK;
|
504 |
|
|
}
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
|
508 |
|
|
//----------------------------------------------------------------------
|
509 |
|
|
|
510 |
|
|
shared_ptr->keyboard_irq_step = (top->irq_keyb)? STEP_REQ : STEP_IDLE;
|
511 |
|
|
shared_ptr->mouse_irq_step = (top->irq_mouse)? STEP_REQ : STEP_IDLE;
|
512 |
|
|
|
513 |
|
|
//----------------------------------------------------------------------
|
514 |
|
|
|
515 |
|
|
if(top->speaker_61h_read) {
|
516 |
|
|
printf("ERROR: speaker_61h_read not zero !\n");
|
517 |
|
|
exit(-1);
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
if(top->speaker_61h_write) {
|
521 |
|
|
printf("ERROR: speaker_61h_write not zero !\n");
|
522 |
|
|
exit(-1);
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
if(top->output_a20_enable != a20_last) {
|
526 |
|
|
printf("WARNING: output_a20_enable: %d\n", top->output_a20_enable);
|
527 |
|
|
a20_last = top->output_a20_enable;
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
if(top->output_reset_n == 0) {
|
531 |
|
|
printf("ERROR: output_a20_enable not one !\n");
|
532 |
|
|
exit(-1);
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
//----------------------------------------------------------------------
|
536 |
|
|
|
537 |
|
|
if(kb_clk_hold) top->ps2_kbclk = kb_clk_hold_value;
|
538 |
|
|
if(kb_dat_hold) top->ps2_kbdat = kb_dat_hold_value;
|
539 |
|
|
if(ms_clk_hold) top->ps2_mouseclk = ms_clk_hold_value;
|
540 |
|
|
if(ms_dat_hold) top->ps2_mousedat = ms_dat_hold_value;
|
541 |
|
|
|
542 |
|
|
top->clk = 0;
|
543 |
|
|
top->eval();
|
544 |
|
|
|
545 |
|
|
if(kb_clk_hold) top->ps2_kbclk = kb_clk_hold_value;
|
546 |
|
|
if(kb_dat_hold) top->ps2_kbdat = kb_dat_hold_value;
|
547 |
|
|
if(ms_clk_hold) top->ps2_mouseclk = ms_clk_hold_value;
|
548 |
|
|
if(ms_dat_hold) top->ps2_mousedat = ms_dat_hold_value;
|
549 |
|
|
|
550 |
|
|
cycle++; if(dump) tracer->dump(cycle);
|
551 |
|
|
|
552 |
|
|
|
553 |
|
|
top->clk = 1;
|
554 |
|
|
top->eval();
|
555 |
|
|
|
556 |
|
|
if(kb_clk_hold) top->ps2_kbclk = kb_clk_hold_value;
|
557 |
|
|
if(kb_dat_hold) top->ps2_kbdat = kb_dat_hold_value;
|
558 |
|
|
if(ms_clk_hold) top->ps2_mouseclk = ms_clk_hold_value;
|
559 |
|
|
if(ms_dat_hold) top->ps2_mousedat = ms_dat_hold_value;
|
560 |
|
|
|
561 |
|
|
cycle++; if(dump) tracer->dump(cycle);
|
562 |
|
|
|
563 |
|
|
tracer->flush();
|
564 |
|
|
|
565 |
|
|
usleep(1);
|
566 |
|
|
}
|
567 |
|
|
tracer->close();
|
568 |
|
|
delete tracer;
|
569 |
|
|
delete top;
|
570 |
|
|
|
571 |
|
|
return 0;
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
//------------------------------------------------------------------------------
|
575 |
|
|
|
576 |
|
|
/*
|
577 |
|
|
module ps2(
|
578 |
|
|
input clk,
|
579 |
|
|
input rst_n,
|
580 |
|
|
|
581 |
|
|
output reg irq_keyb,
|
582 |
|
|
output reg irq_mouse,
|
583 |
|
|
|
584 |
|
|
//io slave 0x60-0x67
|
585 |
|
|
input [2:0] io_address,
|
586 |
|
|
input io_read,
|
587 |
|
|
output reg [7:0] io_readdata,
|
588 |
|
|
input io_write,
|
589 |
|
|
input [7:0] io_writedata,
|
590 |
|
|
|
591 |
|
|
//io slave 0x90-0x9F
|
592 |
|
|
input [3:0] sysctl_address,
|
593 |
|
|
input sysctl_read,
|
594 |
|
|
output reg [7:0] sysctl_readdata,
|
595 |
|
|
input sysctl_write,
|
596 |
|
|
input [7:0] sysctl_writedata,
|
597 |
|
|
|
598 |
|
|
//speaker port 61h
|
599 |
|
|
output speaker_61h_read,
|
600 |
|
|
input [7:0] speaker_61h_readdata,
|
601 |
|
|
output speaker_61h_write,
|
602 |
|
|
output [7:0] speaker_61h_writedata,
|
603 |
|
|
|
604 |
|
|
//output port
|
605 |
|
|
output reg output_a20_enable,
|
606 |
|
|
output reg output_reset_n,
|
607 |
|
|
|
608 |
|
|
//ps2 keyboard
|
609 |
|
|
inout ps2_kbclk,
|
610 |
|
|
inout ps2_kbdat,
|
611 |
|
|
|
612 |
|
|
//ps2 mouse
|
613 |
|
|
inout ps2_mouseclk,
|
614 |
|
|
inout ps2_mousedat
|
615 |
|
|
);
|
616 |
|
|
*/
|