1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
|
// license:BSD-3-Clause
// copyright-holders:Farfetch'd, R. Belmont
uint32_t v60_device::opINCB() /* TRUSTED */
{
uint8_t appb;
m_modadd = PC + 1;
m_moddim = 0;
m_amlength1 = ReadAMAddress();
if (m_amflag)
appb = (uint8_t)m_reg[m_amout];
else
appb = m_program->read_byte(m_amout);
ADDB(appb, 1);
if (m_amflag)
SETREG8(m_reg[m_amout], appb);
else
m_program->write_byte(m_amout, appb);
return m_amlength1 + 1;
}
uint32_t v60_device::opINCH() /* TRUSTED */
{
uint16_t apph;
m_modadd = PC + 1;
m_moddim = 1;
m_amlength1 = ReadAMAddress();
if (m_amflag)
apph = (uint16_t)m_reg[m_amout];
else
apph = m_program->read_word_unaligned(m_amout);
ADDW(apph, 1);
if (m_amflag)
SETREG16(m_reg[m_amout], apph);
else
m_program->write_word_unaligned(m_amout, apph);
return m_amlength1 + 1;
}
uint32_t v60_device::opINCW() /* TRUSTED */
{
uint32_t appw;
m_modadd = PC + 1;
m_moddim = 2;
m_amlength1 = ReadAMAddress();
if (m_amflag)
appw = m_reg[m_amout];
else
appw = m_program->read_dword_unaligned(m_amout);
ADDL(appw, 1);
if (m_amflag)
m_reg[m_amout] = appw;
else
m_program->write_dword_unaligned(m_amout, appw);
return m_amlength1 + 1;
}
uint32_t v60_device::opDECB() /* TRUSTED */
{
uint8_t appb;
m_modadd = PC + 1;
m_moddim = 0;
m_amlength1 = ReadAMAddress();
if (m_amflag)
appb = (uint8_t)m_reg[m_amout];
else
appb = m_program->read_byte(m_amout);
SUBB(appb, 1);
if (m_amflag)
SETREG8(m_reg[m_amout], appb);
else
m_program->write_byte(m_amout, appb);
return m_amlength1 + 1;
}
uint32_t v60_device::opDECH() /* TRUSTED */
{
uint16_t apph;
m_modadd = PC + 1;
m_moddim = 1;
m_amlength1 = ReadAMAddress();
if (m_amflag)
apph = (uint16_t)m_reg[m_amout];
else
apph = m_program->read_word_unaligned(m_amout);
SUBW(apph, 1);
if (m_amflag)
SETREG16(m_reg[m_amout], apph);
else
m_program->write_word_unaligned(m_amout, apph);
return m_amlength1 + 1;
}
uint32_t v60_device::opDECW() /* TRUSTED */
{
uint32_t appw;
m_modadd = PC + 1;
m_moddim = 2;
m_amlength1 = ReadAMAddress();
if (m_amflag)
appw = m_reg[m_amout];
else
appw = m_program->read_dword_unaligned(m_amout);
SUBL(appw, 1);
if (m_amflag)
m_reg[m_amout] = appw;
else
m_program->write_dword_unaligned(m_amout, appw);
return m_amlength1 + 1;
}
uint32_t v60_device::opJMP() /* TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 0;
// Read the address of the operand
ReadAMAddress();
// It cannot be a register!!
assert(m_amflag == 0);
// Jump there
PC = m_amout;
return 0;
}
uint32_t v60_device::opJSR() /* TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 0;
// Read the address of the operand
m_amlength1 = ReadAMAddress();
// It cannot be a register!!
assert(m_amflag == 0);
// Save NextPC into the stack
SP -= 4;
m_program->write_dword_unaligned(SP, PC + m_amlength1 + 1);
// Jump there
PC = m_amout;
return 0;
}
uint32_t v60_device::opPREPARE() /* somewhat TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 2;
// Read the operand
m_amlength1 = ReadAM();
// step 1: save frame pointer on the stack
SP -= 4;
m_program->write_dword_unaligned(SP, FP);
// step 2: FP = new SP
FP = SP;
// step 3: SP -= operand
SP -= m_amout;
return m_amlength1 + 1;
}
uint32_t v60_device::opRET() /* TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 2;
// Read the operand
ReadAM();
// Read return address from stack
PC = m_program->read_dword_unaligned(SP);
SP +=4;
// Restore AP from stack
AP = m_program->read_dword_unaligned(SP);
SP +=4;
// Skip stack frame
SP += m_amout;
return 0;
}
uint32_t v60_device::opTRAP()
{
uint32_t oldPSW;
m_modadd = PC + 1;
m_moddim = 0;
// Read the operand
m_amlength1 = ReadAM();
// Normalize the flags
NORMALIZEFLAGS();
switch ((m_amout >> 4) & 0xF)
{
case 0:
if (!_OV) return m_amlength1 + 1;
else break;
case 1:
if (_OV) return m_amlength1 + 1;
else break;
case 2:
if (!_CY) return m_amlength1 + 1;
else break;
case 3:
if (_CY) return m_amlength1 + 1;
else break;
case 4:
if (!_Z) return m_amlength1 + 1;
else break;
case 5:
if (_Z) return m_amlength1 + 1;
else break;
case 6:
if (!(_CY | _Z)) return m_amlength1 + 1;
else break;
case 7:
if ((_CY | _Z)) return m_amlength1 + 1;
else break;
case 8:
if (!_S) return m_amlength1 + 1;
else break;
case 9:
if (_S) return m_amlength1 + 1;
else break;
case 10:
break;
case 11:
return m_amlength1 + 1;
case 12:
if (!(_S^_OV)) return m_amlength1 + 1;
else break;
case 13:
if ((_S^_OV)) return m_amlength1 + 1;
else break;
case 14:
if (!((_S^_OV)|_Z)) return m_amlength1 + 1;
else break;
case 15:
if (((_S^_OV)|_Z)) return m_amlength1 + 1;
else break;
}
oldPSW = v60_update_psw_for_exception(0, 0);
// Issue the software trap with interrupts
SP -= 4;
m_program->write_dword_unaligned(SP, EXCEPTION_CODE_AND_SIZE(0x3000 + 0x100 * (m_amout & 0xF), 4));
SP -= 4;
m_program->write_dword_unaligned(SP, oldPSW);
SP -= 4;
m_program->write_dword_unaligned(SP, PC + m_amlength1 + 1);
PC = GETINTVECT(48 + (m_amout & 0xF));
return 0;
}
uint32_t v60_device::opRETIU() /* TRUSTED */
{
uint32_t newPSW;
m_modadd = PC + 1;
m_moddim = 1;
// Read the operand
ReadAM();
// Restore PC and PSW from stack
PC = m_program->read_dword_unaligned(SP);
SP += 4;
newPSW = m_program->read_dword_unaligned(SP);
SP += 4;
// Destroy stack frame
SP += m_amout;
v60WritePSW(newPSW);
return 0;
}
uint32_t v60_device::opRETIS()
{
uint32_t newPSW;
m_modadd = PC + 1;
m_moddim = 1;
// Read the operand
ReadAM();
// Restore PC and PSW from stack
PC = m_program->read_dword_unaligned(SP);
SP += 4;
newPSW = m_program->read_dword_unaligned(SP);
SP += 4;
// Destroy stack frame
SP += m_amout;
v60WritePSW(newPSW);
return 0;
}
uint32_t v60_device::opSTTASK()
{
int i;
uint32_t adr;
m_modadd = PC + 1;
m_moddim = 2;
m_amlength1 = ReadAM();
adr = TR;
v60WritePSW(v60ReadPSW() | 0x10000000);
v60SaveStack();
m_program->write_dword_unaligned(adr, TKCW);
adr += 4;
if(SYCW & 0x100) {
m_program->write_dword_unaligned(adr, L0SP);
adr += 4;
}
if(SYCW & 0x200) {
m_program->write_dword_unaligned(adr, L1SP);
adr += 4;
}
if(SYCW & 0x400) {
m_program->write_dword_unaligned(adr, L2SP);
adr += 4;
}
if(SYCW & 0x800) {
m_program->write_dword_unaligned(adr, L3SP);
adr += 4;
}
// 31 registers supported, _not_ 32
for(i = 0; i < 31; i++)
if(m_amout & (1 << i)) {
m_program->write_dword_unaligned(adr, m_reg[i]);
adr += 4;
}
// #### Ignore the virtual addressing crap.
return m_amlength1 + 1;
}
uint32_t v60_device::opGETPSW()
{
m_modadd = PC + 1;
m_moddim = 2;
m_modwritevalw = v60ReadPSW();
// Write PSW to the operand
m_amlength1 = WriteAM();
return m_amlength1 + 1;
}
uint32_t v60_device::opTASI()
{
uint8_t appb;
m_modadd = PC + 1;
m_moddim = 0;
// Load the address of the operand
m_amlength1 = ReadAMAddress();
// Load uint8_t from the address
if (m_amflag)
appb = (uint8_t)m_reg[m_amout & 0x1F];
else
appb = m_program->read_byte(m_amout);
// Set the flags for SUB appb, FF
SUBB(appb, 0xff);
// Write FF in the operand
if (m_amflag)
SETREG8(m_reg[m_amout & 0x1F], 0xFF);
else
m_program->write_byte(m_amout, 0xFF);
return m_amlength1 + 1;
}
uint32_t v60_device::opCLRTLB()
{
m_modadd = PC + 1;
m_moddim = 2;
// Read the operand
m_amlength1 = ReadAM();
// @@@ TLB not yet emulated
return m_amlength1 + 1;
}
uint32_t v60_device::opPOPM()
{
int i;
m_modadd = PC + 1;
m_moddim = 2;
// Read the bit register list
m_amlength1 = ReadAM();
for (i = 0;i < 31;i++)
if (m_amout & (1 << i))
{
m_reg[i] = m_program->read_dword_unaligned(SP);
SP += 4;
}
if (m_amout & (1 << 31))
{
v60WritePSW((v60ReadPSW() & 0xffff0000) | m_program->read_word_unaligned(SP));
SP += 4;
}
return m_amlength1 + 1;
}
uint32_t v60_device::opPUSHM()
{
int i;
m_modadd = PC + 1;
m_moddim = 2;
// Read the bit register list
m_amlength1 = ReadAM();
if (m_amout & (1 << 31))
{
SP -= 4;
m_program->write_dword_unaligned(SP, v60ReadPSW());
}
for (i = 0;i < 31;i++)
if (m_amout & (1 << (30 - i)))
{
SP -= 4;
m_program->write_dword_unaligned(SP, m_reg[(30 - i)]);
}
return m_amlength1 + 1;
}
uint32_t v60_device::opTESTB() /* TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 0;
// Read the operand
m_amlength1 = ReadAM();
_Z = (m_amout == 0);
_S = ((m_amout & 0x80) != 0);
_CY = 0;
_OV = 0;
return m_amlength1 + 1;
}
uint32_t v60_device::opTESTH() /* TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 1;
// Read the operand
m_amlength1 = ReadAM();
_Z = (m_amout == 0);
_S = ((m_amout & 0x8000) != 0);
_CY = 0;
_OV = 0;
return m_amlength1 + 1;
}
uint32_t v60_device::opTESTW() /* TRUSTED */
{
m_modadd = PC + 1;
m_moddim = 2;
// Read the operand
m_amlength1 = ReadAM();
_Z = (m_amout == 0);
_S = ((m_amout & 0x80000000) != 0);
_CY = 0;
_OV = 0;
return m_amlength1 + 1;
}
uint32_t v60_device::opPUSH()
{
m_modadd = PC + 1;
m_moddim = 2;
m_amlength1 = ReadAM();
SP-=4;
m_program->write_dword_unaligned(SP, m_amout);
return m_amlength1 + 1;
}
uint32_t v60_device::opPOP()
{
m_modadd = PC + 1;
m_moddim = 2;
m_modwritevalw = m_program->read_dword_unaligned(SP);
SP +=4;
m_amlength1 = WriteAM();
return m_amlength1 + 1;
}
uint32_t v60_device::opINCB_0() { m_modm = 0; return opINCB(); }
uint32_t v60_device::opINCB_1() { m_modm = 1; return opINCB(); }
uint32_t v60_device::opINCH_0() { m_modm = 0; return opINCH(); }
uint32_t v60_device::opINCH_1() { m_modm = 1; return opINCH(); }
uint32_t v60_device::opINCW_0() { m_modm = 0; return opINCW(); }
uint32_t v60_device::opINCW_1() { m_modm = 1; return opINCW(); }
uint32_t v60_device::opDECB_0() { m_modm = 0; return opDECB(); }
uint32_t v60_device::opDECB_1() { m_modm = 1; return opDECB(); }
uint32_t v60_device::opDECH_0() { m_modm = 0; return opDECH(); }
uint32_t v60_device::opDECH_1() { m_modm = 1; return opDECH(); }
uint32_t v60_device::opDECW_0() { m_modm = 0; return opDECW(); }
uint32_t v60_device::opDECW_1() { m_modm = 1; return opDECW(); }
uint32_t v60_device::opJMP_0() { m_modm = 0; return opJMP(); }
uint32_t v60_device::opJMP_1() { m_modm = 1; return opJMP(); }
uint32_t v60_device::opJSR_0() { m_modm = 0; return opJSR(); }
uint32_t v60_device::opJSR_1() { m_modm = 1; return opJSR(); }
uint32_t v60_device::opPREPARE_0() { m_modm = 0; return opPREPARE(); }
uint32_t v60_device::opPREPARE_1() { m_modm = 1; return opPREPARE(); }
uint32_t v60_device::opRET_0() { m_modm = 0; return opRET(); }
uint32_t v60_device::opRET_1() { m_modm = 1; return opRET(); }
uint32_t v60_device::opTRAP_0() { m_modm = 0; return opTRAP(); }
uint32_t v60_device::opTRAP_1() { m_modm = 1; return opTRAP(); }
uint32_t v60_device::opRETIU_0() { m_modm = 0; return opRETIU(); }
uint32_t v60_device::opRETIU_1() { m_modm = 1; return opRETIU(); }
uint32_t v60_device::opRETIS_0() { m_modm = 0; return opRETIS(); }
uint32_t v60_device::opRETIS_1() { m_modm = 1; return opRETIS(); }
uint32_t v60_device::opGETPSW_0() { m_modm = 0; return opGETPSW(); }
uint32_t v60_device::opGETPSW_1() { m_modm = 1; return opGETPSW(); }
uint32_t v60_device::opTASI_0() { m_modm = 0; return opTASI(); }
uint32_t v60_device::opTASI_1() { m_modm = 1; return opTASI(); }
uint32_t v60_device::opCLRTLB_0() { m_modm = 0; return opCLRTLB(); }
uint32_t v60_device::opCLRTLB_1() { m_modm = 1; return opCLRTLB(); }
uint32_t v60_device::opPOPM_0() { m_modm = 0; return opPOPM(); }
uint32_t v60_device::opPOPM_1() { m_modm = 1; return opPOPM(); }
uint32_t v60_device::opPUSHM_0() { m_modm = 0; return opPUSHM(); }
uint32_t v60_device::opPUSHM_1() { m_modm = 1; return opPUSHM(); }
uint32_t v60_device::opTESTB_0() { m_modm = 0; return opTESTB(); }
uint32_t v60_device::opTESTB_1() { m_modm = 1; return opTESTB(); }
uint32_t v60_device::opTESTH_0() { m_modm = 0; return opTESTH(); }
uint32_t v60_device::opTESTH_1() { m_modm = 1; return opTESTH(); }
uint32_t v60_device::opTESTW_0() { m_modm = 0; return opTESTW(); }
uint32_t v60_device::opTESTW_1() { m_modm = 1; return opTESTW(); }
uint32_t v60_device::opPUSH_0() { m_modm = 0; return opPUSH(); }
uint32_t v60_device::opPUSH_1() { m_modm = 1; return opPUSH(); }
uint32_t v60_device::opPOP_0() { m_modm = 0; return opPOP(); }
uint32_t v60_device::opPOP_1() { m_modm = 1; return opPOP(); }
uint32_t v60_device::opSTTASK_0() { m_modm = 0; return opSTTASK(); }
uint32_t v60_device::opSTTASK_1() { m_modm = 1; return opSTTASK(); }
|