-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlphaCPU.cpp
More file actions
1816 lines (1696 loc) · 58 KB
/
AlphaCPU.cpp
File metadata and controls
1816 lines (1696 loc) · 58 KB
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ES40 emulator.
* Copyright (C) 2007-2008 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : camiel@camicom.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*/
/**
* \file
* Contains the code for the emulated DecChip 21264CB EV68 Alpha processor.
*
* $Id: AlphaCPU.cpp,v 1.71 2008/03/04 19:05:21 iamcamiel Exp $
*
* X-1.71 Camiel Vanderhoeven 04-MAR-2008
* Support some basic MP features. (CPUID read from C-Chip MISC
* register, inter-processor interrupts)
*
* X-1.70 Camiel Vanderhoeven 29-FEB-2008
* Comments.
*
* X-1.69 Brian Wheeler 29-FEB-2008
* Add BREAKPOINT INSTRUCTION command to IDB.
*
* X-1.68 Brian Wheeler 27-FEB-2008
* Avoid compiler warnings.
*
* X-1.67 Camiel Vanderhoeven 08-FEB-2008
* Show originating device name on memory errors.
*
* X-1.66 Camiel Vanderhoeven 05-FEB-2008
* Only use new floating-point code when HAVE_NEW_FP has been defined.
*
* X-1.65 Camiel Vanderhoeven 01-FEB-2008
* Avoid unnecessary shift-operations to calculate constant values.
*
* X-1.64 Camiel Vanderhoeven 30-JAN-2008
* Always use set_pc or add_pc to change the program counter.
*
* X-1.63 Camiel Vanderhoeven 30-JAN-2008
* Remember number of instructions left in current memory page, so
* that the translation-buffer doens't need to be consulted on every
* instruction fetch when the Icache is disabled.
*
* X-1.62 Camiel Vanderhoeven 29-JAN-2008
* Comments.
*
* X-1.61 Camiel Vanderhoeven 29-JAN-2008
* Undid last change, remember separate last found translation-buffer
* entries for read and wrote operations. This should help with memory
* copy operations.
*
* X-1.60 Camiel Vanderhoeven 27-JAN-2008
* Have GO_PAL throw an exception, so we don't continue doing what we
* were doing before the exception was taken.
*
* X-1.59 Camiel Vanderhoeven 26-JAN-2008
* Made IDB compile again.
*
* X-1.58 Camiel Vanderhoeven 25-JAN-2008
* Added option to disable the icache.
*
* X-1.57 Camiel Vanderhoeven 22-JAN-2008
* Nicer initialization of "state" structure.
*
* X-1.56 Camiel Vanderhoeven 22-JAN-2008
* Implemented missing /V integer instructions.
*
* X-1.55 Camiel Vanderhoeven 21-JAN-2008
* Moved some macro's to cpu_defs.h; implement new floating-point code.
*
* X-1.54 Camiel Vanderhoeven 19-JAN-2008
* Run CPU in a separate thread if CPU_THREADS is defined.
* NOTA BENE: This is very experimental, and has several problems.
*
* X-1.53 Camiel Vanderhoeven 18-JAN-2008
* Replaced sext_64 inlines with sext_u64_<bits> inlines for
* performance reasons (thanks to David Hittner for spotting this!);
* Process device interrupts after a 100-cpu-cycle delay.
*
* X-1.52 David Hittner 16-JAN-2008
* Added ADDL/V instruction, added MIPS estimate (define MIPS_ESTIMATE)
*
* X-1.51 Camiel Vanderhoeven 08-JAN-2008
* Removed last references to IDE disk read SRM replacement.
*
* X-1.50 Camiel Vanderhoeven 30-DEC-2007
* Print file id on initialization.
*
* X-1.49 Camiel Vanderhoeven 28-DEC-2007
* Keep the compiler happy.
*
* X-1.48 Camiel Vanderhoeven 17-DEC-2007
* SaveState file format 2.1
*
* X-1.47 Camiel Vanderhoeven 10-DEC-2007
* Use configurator.
*
* X-1.46 Camiel Vanderhoeven 2-DEC-2007
* Changed the way translation buffers work, the way interrupts work.
*
* X-1.45 Brian Wheeler 1-DEC-2007
* Added support for instruction counting, underlined lines in
* listings, corrected some unsigned/signed issues.
*
* X-1.44 Camiel Vanderhoeven 16-NOV-2007
* Avoid more compiler warnings.
*
* X-1.43 Camiel Vanderhoeven 16-NOV-2007
* Avoid compiler warning about default without any cases.
*
* X-1.42 Camiel Vanderhoeven 08-NOV-2007
* Instruction set complete now.
*
* X-1.41 Camiel Vanderhoeven 06-NOV-2007
* Performance improvements to ICACHE: last result is kept; cache
* lines are larger (512 DWORDS in stead of 16 DWORDS), cache size is
* configurable (both number of cache lines and size of each cache
* line), memcpy is used to move memory into the ICACHE.
* CAVEAT: ICACHE can only be filled from memory (not from I/O).
*
* X-1.40 Camiel Vanderhoeven 02-NOV-2007
* Added integer /V instructions.
*
* X-1.39 Camiel Vanderhoeven 02-NOV-2007
* Added missing floating point instructions.
*
* X-1.38 Eduardo Marcelo Ferrat 31-OCT-2007
* EXC_SUM contained the wrong register (3 in stead of 1) on a DTBM
* exception. Added instructions for CVTDG, CVTGD, MULG, CVTGF.
*
* X-1.37 Camiel Vanderhoeven 18-APR-2007
* Faster lockstep mechanism (send info 50 cpu cycles at a time)
*
* X-1.36 Camiel Vanderhoeven 11-APR-2007
* Moved all data that should be saved to a state file to a structure
* "state".
*
* X-1.35 Camiel Vanderhoeven 10-APR-2007
* New mechanism for SRM replacements. Where these need to be executed,
* CSystem::LoadROM() puts a special opcode (a CALL_PAL instruction
* with an otherwise illegal operand of 0x01234xx) in memory.
* CAlphaCPU::DoClock() recognizes these opcodes and performs the SRM
* action.
*
* X-1.34 Camiel Vanderhoeven 10-APR-2007
* Unintentional version number increase.
*
* X-1.33 Camiel Vanderhoeven 30-MAR-2007
* Formatting.
*
* X-1.32 Camiel Vanderhoeven 29-MAR-2007
* Added AST to the list of conditions that cause the processor to go to
* the interrupt PAL vector (680).
*
* X-1.31 Brian Wheeler 28-MAR-2007
* Fixed missing ) after #if !defined(SRM_NO_SPEEDUPS
*
* X-1.30 Camiel Vanderhoeven 26-MAR-2007
* a) Possibility to disable SRM-code replacements with the defines
* SRM_NO_IDE, SRM_NO_SRL, and SRM_NO_SPEEDUPS
* b) Possibility to send SRM-code replacement debugging messages to the
* console, with the defines DEBUG_SRM_IDE and DEBUG_SRM_SRL
* c) Added software-interrupts to the list of conditions that can cause
* the processot to go to the interrupt PAL vector (680)
*
* X-1.29 Camiel Vanderhoeven 14-MAR-2007
* Formatting.
*
* X-1.28 Camiel Vanderhoeven 14-MAR-2007
* Fixed typo in "case 0x22: OP(CPYSE,F12_f3);"
*
* X-1.27 Camiel Vanderhoeven 13-MAR-2007
* Added some floating-point opcodes, added es_float.h inclusion
*
* X-1.26 Camiel Vanderhoeven 12-MAR-2007
* a) Changed call to CTranslationBuffer::convert_address (arguments list
* changed)
* b) Set values for EXC_SUM and MM_STAT on various exceptions
*
* X-1.25 Camiel Vanderhoeven 9-MAR-2007
* In the listing-process, addresses were executed twice
*
* X-1.24 Camiel Vanderhoeven 8-MAR-2007
* a) Changed call to CTranslationBuffer::write_pte (arguments list
* changed)
* b) Backed-out X-1.23 as real problem was solved. (X-1.3 in cpu_bwx.h)
*
* X-1.23 Camiel Vanderhoeven 7-MAR-2007
* HACK to stop APB.EXE from crashing when passing bootflags
*
* X-1.22 Camiel Vanderhoeven 3-MAR-2007
* Wrote code to be executed in stead of SRM console code for writing
* to the serial port, and reading from IDE disks. Mechanism is based
* on recognition of the PC value. Should be replaced with a better
* mechanism in the future.
*
* X-1.21 Camiel Vanderhoeven 2-MAR-2007
* Initialize debug_string to "".
*
* X-1.20 Camiel Vanderhoeven 2-MAR-2007
* Fixed problem in Save and RestoreState; argument f conflicted with
* class member f.
*
* X-1.19 Camiel Vanderhoeven 28-FEB-2007
* Added support for the lockstep-mechanism.
*
* X-1.18 Camiel Vanderhoeven 27-FEB-2007
* Removed an unreachable "return 0;" line from DoClock
*
* X-1.17 Camiel Vanderhoeven 22-FEB-2007
* E_FAULT returned from translation buffer now causes DFAULT exception
*
* X-1.16 Camiel Vanderhoven 22-FEB-2007
* a) Changed call to CTranslationBuffer::convert_address (arguments list
* changed)
* b) Fixed HW_MTPR and HW_MFPR opcodes
*
* X-1.15 Camiel Vanderhoeven 19-FEB-2007
* Fixed preprocessor macro concatenation bug (used ## both before and
* after the literal; changed this to only before).
*
* X-1.14 Camiel Vanderhoeven 18-FEB-2007
* Put all actual code behind the processor opcodes in cpu_xxx.h include
* files, and replaced them with OP(...,...) macro's in this file.
*
* X-1.13 Camiel Vanderhoeven 16-FEB-2007
* a) Added CAlphaCPU::listing.
* b) Clocking changes (due to changes in CSystem): CAlphaCPU::DoClock now
* returns a value, and the CPU is registered as a fast clocked device.
*
* X-1.12 Brian Wheeler 13-FEB-2007
* Different algorithm used for UMULH (previous algorithm suffered from
* portability issues).
*
* X-1.11 Camiel Vanderhoeven 13-FEB-2007
* a) Bugfix in the UMULH instruction.
* b) Bugfix in the HW_MTPR VA_CTL instruction. Now updates va_ctl_va_mode
* instead of i_ctl_va_mode.
*
* X-1.10 Camiel Vanderhoeven 12-FEB-2007
* a) Moved debugging macro's to cpu_debug.h
* b) Cleaned up SEXT and REG macro's (a lot neater now)
* c) Moved CAlphaCPU::get_r and CAlphaCPU::get_prbr to AlphaCPU.h as
* inline functions
* d) Use SEXT macro in a some places where exotic constructions were used
* previously
*
* X-1.9 Camiel Vanderhoeven 12-FEB-2007
* a) Added X64_BYTE, X64_WORD, X64_LONG and X64_QUAD, and used these
* instead of the corresponding values.
* b) Added ier to the variables that are saved to the state file.
*
* X-1.8 Camiel Vanderhoeven 9-FEB-2007
* a) Moved debugging flags (booleans) to CSystem.cpp.
* b) Removed loggin of last_write_loc and last_write_val
*
* X-1.7 Camiel Vanderhoeven 7-FEB-2007
* Made various dubugging-related statements dependent on the
* definition of IDB (interactive debugger)
*
* X-1.6 Camiel Vanderhoeven 3-FEB-2007
* Inline function printable moved to StdAfx.h
*
* X-1.5 Brian Wheeler 3-FEB-2007
* Formatting.
*
* X-1.4 Brian Wheeler 3-FEB-2007
* More scanf and printf statements made compatible with Linux/GCC/glibc.
*
* X-1.3 Brian Wheeler 3-FEB-2007
* Scanf and printf statements made compatible with Linux/GCC/glibc.
*
* X-1.2 Brian Wheeler 3-FEB-2007
* Includes are now case-correct (necessary on Linux)
*
* X-1.1 Camiel Vanderhoeven 19-JAN-2007
* Initial version in CVS.
**/
#include "StdAfx.h"
#include "AlphaCPU.h"
#include "TraceEngine.h"
#include "lockstep.h"
#include "cpu_memory.h"
#include "cpu_control.h"
#include "cpu_arith.h"
#include "cpu_logical.h"
#include "cpu_bwx.h"
#include "cpu_fp_memory.h"
#include "cpu_fp_branch.h"
#include "cpu_fp_operate.h"
#include "cpu_misc.h"
#include "cpu_vax.h"
#include "cpu_mvi.h"
#include "cpu_pal.h"
#include "cpu_debug.h"
#if !defined(HAVE_NEW_FP)
#include "es40_float.h"
#endif
/**
* Constructor.
**/
CAlphaCPU::CAlphaCPU(CConfigurator * cfg, CSystem * system) : CSystemComponent (cfg,system)
{
cSystem = system;
#if !defined(CPU_THREADS)
// if the CPU doesn't have it's own thread, register it as a fast clocked device.
cSystem->RegisterClock(this, false);
#else
thread_shouldrun = false;
thread_doesrun = false;
#endif
memset(&state,0,sizeof(state));
state.iProcNum = cSystem->RegisterCPU(this);
icache_enabled = true;
flush_icache();
icache_enabled = myCfg->get_bool_value("icache",false);
tbia(ACCESS_READ);
tbia(ACCESS_EXEC);
// state.fpcr = X64(8ff0000000000000);
state.fpen = true;
state.i_ctl_other = X64(502086);
state.smc = 1;
// SROM imitation...
add_tb(0, 0, X64(ff61),ACCESS_READ);
#if defined(IDB)
bListing = false;
#endif
printf("%s: $Id: AlphaCPU.cpp,v 1.71 2008/03/04 19:05:21 iamcamiel Exp $\n",devid_string);
}
/**
* Destructor.
**/
CAlphaCPU::~CAlphaCPU()
{
}
#if defined(IDB)
char dbg_string[1000];
#if !defined(LS_MASTER) && !defined(LS_SLAVE)
char * dbg_strptr;
#endif
/**
* \brief Do whatever needs to be done to a debug-string.
*
* Used in IDB-mode to handle the disassembly- string. In es40_idb, it is
* written to the standard output.
*
* \param s Pointer to the debug string.
**/
void handle_debug_string(char * s)
{
#if defined(LS_SLAVE) || defined(LS_MASTER)
// lockstep_compare(s);
*dbg_strptr++ = '\n';
*dbg_strptr='\0';
#else
if (*s)
printf("%s\n",s);
#endif
}
#endif
#if defined(MIPS_ESTIMATE)
// MIPS_INTERVAL must take longer than 1 second to execute
// or estimate will generate a divide-by-zero error
#define MIPS_INTERVAL 0xfffffff
static time_t saved = 0;
static u64 count;
static double min_mips = 999999999999999.0;
static double max_mips = 0.0;
#endif
/**
* \brief Called each clock-cycle.
*
* This is where the actual CPU emulation takes place. Each clocktick, one instruction
* is processed by the processor. The instruction pipeline is not emulated, things are
* complicated enough as it is. The one exception is the instruction cache, which is
* implemented, to accomodate self-modifying code. The instruction cache can be disabled
* if self-modifying code is not expected.
*
* \return 0 (succes)
**/
int CAlphaCPU::DoClock()
{
u32 ins;
int i;
u64 phys_address;
u64 temp_64;
u64 temp_64_1;
u64 temp_64_2;
UFP ufp1, ufp2;
int opcode;
int function;
#if defined(MIPS_ESTIMATE)
// Calculate simulated performance statistics
if (++count >= MIPS_INTERVAL) {
time_t current;
time(¤t);
if (saved > 0) {
double secs = difftime(current, saved);
double ips = MIPS_INTERVAL / secs;
double mips = ips / 1000000.0;
if (max_mips < mips) max_mips = mips;
if (min_mips > mips) min_mips = mips;
printf("ES40 MIPS (%3.1f sec):: current: %5.3f, min: %5.3f, max: %5.3f\n", secs, mips, min_mips, max_mips);
}
saved = current;
count = 0;
}
#endif
#if defined(IDB)
char * funcname = 0;
dbg_string[0] = '\0';
#if !defined(LS_MASTER) && !defined(LS_SLAVE)
dbg_strptr = dbg_string;
#endif
#endif
state.current_pc = state.pc;
#ifdef IDB
state.instruction_count++;
#endif
// Service interrupts
if (DO_ACTION) {
// We're actually executing code. Cycle counter should be updated, interrupt and interrupt
// timer status needs to be checked, and the next instruction should be fetched from the
// instruction cache.
// Increase the cycle counter if it is currently enabled.
if (state.cc_ena) {
#if defined(CPU_THREADS)
state.cc+=20;
#else
state.cc+=83;
#endif
}
if (state.check_timers) {
// There are one or more active delayed irq_h interrupts. Go through the 6
// irq_h timers, decrease them as needed, and set the interrupt if the timer
// reaches 0.
state.check_timers = false;
for (int i=0;i<6;i++) {
if (state.irq_h_timer[i]) {
// This timer is active. Decrease it, and check if it reached 0.
state.irq_h_timer[i]--;
if (state.irq_h_timer[i]) {
// The timer hasn't reached 0 yet; check on the timers again next clock tick.
state.check_timers = true;
} else {
// The timer has reached 0. Set the interrupt status, and set the flag that we
// need to check the interrupt status
state.eir |= (X64(1)<<i);
state.check_int = true;
}
}
}
}
if (state.check_int && !(state.pc&1)) {
// One or more of the variables that affect interrupt status have changed, and we are not
// currently inside PALmode. It is not certain that this means we hava an interrupt to
// service, but we might have. This needs to be checked.
if (state.pal_vms) {
// PALcode base is set to 0x8000; meaning OpenVMS PALcode is currently active. In this
// case, our VMS PALcode replacement routines are valid, and should be used as it is
// faster than using the original PALcode.
if (state.eir & state.eien & 6)
if (vmspal_ent_ext_int(state.eir&state.eien & 6))
return 0;
if (state.sir & state.sien & 0xfffc)
if (vmspal_ent_sw_int(state.sir&state.sien))
return 0;
if (state.asten && (state.aster & state.astrr & ((1<<(state.cm+1))-1) ))
if (vmspal_ent_ast_int(state.aster & state.astrr & ((1<<(state.cm+1))-1) ))
return 0;
if (state.sir & state.sien)
if (vmspal_ent_sw_int(state.sir&state.sien))
return 0;
} else {
// PALcode base is set to an unsupported value. We have no choice but to transfer control
// to PALmode at the PALcode interrupt entry point.
if ((state.eien & state.eir) ||
(state.sien & state.sir) ||
(state.asten && (state.aster & state.astrr & ((1<<(state.cm+1))-1) )))
{
GO_PAL(INTERRUPT);
return 0;
}
}
// This point is reached only if there are no more active interrupts. We can safely set
// check_int to false now to save time on the next CPU clock ticks.
state.check_int = false;
}
// If profiling is enabled, increase the profiling counter for the current block of addresses.
#if defined(PROFILE)
PROFILE_DO(state.pc);
#endif
// Get the next instruction from the instruction cache.
if (get_icache(state.pc, &ins))
return 0;
} // if (DO_ACTION)
else
{
// We're not really executing any code (DO_ACTION is false); that means that we're
// in a debugging session, and just listing instructions at a particular address.
// In this case, we treat the program counter as a physical address.
ins = (u32)(cSystem->ReadMem(state.pc,32,this));
}
// Increase the program counter. The current value is retained in state.current_pc.
next_pc();
// Clear "always zero" registers. The last instruction might have written something to
// one of these registers.
state.r[31] = 0;
state.f[31] = 0;
// Decode and dispatch opcode. This is kept very compact using the OP-macro defined in
// cpu_debug.h. For the normal emulator, this simply calls the DO_<mnemonic> macro defined
// in one of the other cpu_*.h files; but for the interactive debugger, it will also do
// disassembly, where the second parameter to the macro (e.g. R12_R3) determines the
// formatting applied to the operands. The macro ends with "return 0;".
#if defined(IDB)
last_instruction = ins;
#endif
opcode = ins >> 26;
switch (opcode)
{
case 0x00: // CALL_PAL
function = ins & 0x1fffffff;
OP(CALL_PAL,PAL);
// switch (function)
// {
// case 0x123401: OP_FNC(vmspal_int_read_ide, NOP);
// default: OP(CALL_PAL,PAL);
// }
case 0x08: OP(LDA,MEM);
case 0x09: OP(LDAH,MEM);
case 0x0a: OP(LDBU,MEM);
case 0x0b: OP(LDQ_U,MEM);
case 0x0c: OP(LDWU,MEM);
case 0x0d: OP(STW,MEM);
case 0x0e: OP(STB,MEM);
case 0x0f: OP(STQ_U,MEM);
case 0x10: // INTA* instructions
function = (ins >> 5) & 0x7f;
switch (function)
{
case 0x40: OP(ADDL_V,R12_R3);
case 0x00: OP(ADDL,R12_R3);
case 0x02: OP(S4ADDL,R12_R3);
case 0x49: OP(SUBL_V,R12_R3);
case 0x09: OP(SUBL,R12_R3);
case 0x0b: OP(S4SUBL,R12_R3);
case 0x0f: OP(CMPBGE,R12_R3);
case 0x12: OP(S8ADDL,R12_R3);
case 0x1b: OP(S8SUBL,R12_R3);
case 0x1d: OP(CMPULT,R12_R3);
case 0x60: OP(ADDQ_V,R12_R3);
case 0x20: OP(ADDQ,R12_R3);
case 0x22: OP(S4ADDQ,R12_R3);
case 0x69: OP(SUBQ_V,R12_R3);
case 0x29: OP(SUBQ,R12_R3);
case 0x2b: OP(S4SUBQ,R12_R3);
case 0x2d: OP(CMPEQ,R12_R3);
case 0x32: OP(S8ADDQ,R12_R3);
case 0x3b: OP(S8SUBQ,R12_R3);
case 0x3d: OP(CMPULE,R12_R3);
case 0x4d: OP(CMPLT,R12_R3);
case 0x6d: OP(CMPLE,R12_R3);
default: UNKNOWN2;
}
break;
case 0x11: // INTL* instructions
function = (ins >> 5) & 0x7f;
switch (function)
{
case 0x00: OP(AND,R12_R3);
case 0x08: OP(BIC,R12_R3);
case 0x14: OP(CMOVLBS,R12_R3);
case 0x16: OP(CMOVLBC,R12_R3);
case 0x20: OP(BIS,R12_R3);
case 0x24: OP(CMOVEQ,R12_R3);
case 0x26: OP(CMOVNE,R12_R3);
case 0x28: OP(ORNOT,R12_R3);
case 0x40: OP(XOR,R12_R3);
case 0x44: OP(CMOVLT,R12_R3);
case 0x46: OP(CMOVGE,R12_R3);
case 0x48: OP(EQV,R12_R3);
case 0x61: OP(AMASK,R2_R3);
case 0x64: OP(CMOVLE,R12_R3);
case 0x66: OP(CMOVGT,R12_R3);
case 0x6c: OP(IMPLVER,X_R3);
default: UNKNOWN2;
}
break;
case 0x12: // INTS* instructions
function = (ins>>5) & 0x7f;
switch (function)
{
case 0x02: OP(MSKBL,R12_R3);
case 0x06: OP(EXTBL,R12_R3);
case 0x0b: OP(INSBL,R12_R3);
case 0x12: OP(MSKWL,R12_R3);
case 0x16: OP(EXTWL,R12_R3);
case 0x1b: OP(INSWL,R12_R3);
case 0x22: OP(MSKLL,R12_R3);
case 0x26: OP(EXTLL,R12_R3);
case 0x2b: OP(INSLL,R12_R3);
case 0x30: OP(ZAP,R12_R3);
case 0x31: OP(ZAPNOT,R12_R3);
case 0x32: OP(MSKQL,R12_R3);
case 0x34: OP(SRL,R12_R3);
case 0x36: OP(EXTQL,R12_R3);
case 0x39: OP(SLL,R12_R3);
case 0x3b: OP(INSQL,R12_R3);
case 0x3c: OP(SRA,R12_R3);
case 0x52: OP(MSKWH,R12_R3);
case 0x57: OP(INSWH,R12_R3);
case 0x5a: OP(EXTWH,R12_R3);
case 0x62: OP(MSKLH,R12_R3);
case 0x67: OP(INSLH,R12_R3);
case 0x6a: OP(EXTLH,R12_R3);
case 0x72: OP(MSKQH,R12_R3);
case 0x77: OP(INSQH,R12_R3);
case 0x7a: OP(EXTQH,R12_R3);
default: UNKNOWN2;
}
break;
case 0x13: // INTM* instructions
function = (ins>>5) & 0x7f;
switch (function) // ignore /V for now
{
case 0x40: OP(MULL_V,R12_R3);
case 0x00: OP(MULL,R12_R3);
case 0x60: OP(MULQ_V,R12_R3);
case 0x20: OP(MULQ,R12_R3);
case 0x30: OP(UMULH,R12_R3);
default: UNKNOWN2;
}
break;
case 0x14: // ITFP* instructions
function = (ins>>5) & 0x7ff;
switch(function)
{
case 0x004: OP(ITOFS,R1_F3);
case 0x00a:
case 0x08a:
case 0x10a:
case 0x18a:
case 0x40a:
case 0x48a:
case 0x50a:
case 0x58a: OP(SQRTF,F2_F3);
case 0x00b:
case 0x04b:
case 0x08b:
case 0x0cb:
case 0x10b:
case 0x14b:
case 0x18b:
case 0x1cb:
case 0x50b:
case 0x54b:
case 0x58b:
case 0x5cb:
case 0x70b:
case 0x74b:
case 0x78b:
case 0x7cb: OP(SQRTS,F2_F3);
case 0x014: OP(ITOFF,R1_F3);
case 0x024: OP(ITOFT,R1_F3);
case 0x02a:
case 0x0aa:
case 0x12a:
case 0x1aa:
case 0x42a:
case 0x4aa:
case 0x52a:
case 0x5aa: OP(SQRTG,F2_F3);
case 0x02b:
case 0x06b:
case 0x0ab:
case 0x0eb:
case 0x12b:
case 0x16b:
case 0x1ab:
case 0x1eb:
case 0x52b:
case 0x56b:
case 0x5ab:
case 0x5eb:
case 0x72b:
case 0x76b:
case 0x7ab:
case 0x7eb: OP(SQRTT,F2_F3);
default: UNKNOWN2;
}
break;
case 0x15: // FLTV* instructions
function = (ins>>5) & 0x7ff;
switch(function)
{
case 0x0a5:
case 0x4a5: OP(CMPGEQ,F12_F3);
case 0x0a6:
case 0x4a6: OP(CMPGLT,F12_F3);
case 0x0a7:
case 0x4a7: OP(CMPGLE,F12_F3);
case 0x03c:
case 0x0bc: OP(CVTQF,F2_F3);
case 0x03e:
case 0x0be: OP(CVTQG,F2_F3);
default:
if (function & 0x200) {
UNKNOWN2;
}
switch(function & 0x7f)
{
case 0x000: OP(ADDF,F12_F3);
case 0x001: OP(SUBF,F12_F3);
case 0x002: OP(MULF,F12_F3);
case 0x003: OP(DIVF,F12_F3);
case 0x01e: OP(CVTDG,F2_F3);
case 0x020: OP(ADDG,F12_F3);
case 0x021: OP(SUBG,F12_F3);
case 0x022: OP(MULG,F12_F3);
case 0x023: OP(DIVG,F12_F3);
case 0x02c: OP(CVTGF,F12_F3);
case 0x02d: OP(CVTGD,F2_F3);
case 0x02f: OP(CVTGQ,F2_F3);
default: UNKNOWN2;
}
break;
}
break;
case 0x16: // FLTI* instructions
function = (ins>>5) & 0x7ff;
switch(function)
{
case 0x0a4:
case 0x5a4: OP(CMPTUN,F12_F3);
case 0x0a5:
case 0x5a5: OP(CMPTEQ,F12_F3);
case 0x0a6:
case 0x5a6: OP(CMPTLT,F12_F3);
case 0x0a7:
case 0x5a7: OP(CMPTLE,F12_F3);
case 0x2ac:
case 0x6ac: OP(CVTST,F2_F3);
default:
if (((function & 0x600) == 0x200) || ((function & 0x500) == 0x400)) {
UNKNOWN2;
}
switch (function & 0x3f)
{
case 0x00: OP(ADDS,F12_F3);
case 0x01: OP(SUBS,F12_F3);
case 0x02: OP(MULS,F12_F3);
case 0x03: OP(DIVS,F12_F3);
case 0x20: OP(ADDT,F12_F3);
case 0x21: OP(SUBT,F12_F3);
case 0x22: OP(MULT,F12_F3);
case 0x23: OP(DIVT,F12_F3);
case 0x2c: OP(CVTTS,F2_F3);
case 0x2f: OP(CVTTQ,F2_F3);
case 0x3c:
if ((function &0x300) == 0x100) {
UNKNOWN2;
}
OP(CVTQS,F2_F3);
case 0x3e:
if ((function &0x300) == 0x100) {
UNKNOWN2;
}
OP(CVTQT,F2_F3);
default: UNKNOWN2;
}
break;
}
break;
case 0x17: // FLTL* instructions
function = (ins>>5) & 0x7ff;
switch (function)
{
case 0x010: OP(CVTLQ,F2_F3);
case 0x020: OP(CPYS,F12_F3);
case 0x021: OP(CPYSN,F12_F3);
case 0x022: OP(CPYSE,F12_F3);
case 0x024: OP(MT_FPCR,X_F1);
case 0x025: OP(MF_FPCR,X_F1);
case 0x02a: OP(FCMOVEQ,F12_F3);
case 0x02b: OP(FCMOVNE,F12_F3);
case 0x02c: OP(FCMOVLT,F12_F3);
case 0x02d: OP(FCMOVGE,F12_F3);
case 0x02e: OP(FCMOVLE,F12_F3);
case 0x02f: OP(FCMOVGT,F12_F3);
case 0x030:
case 0x130:
case 0x530: OP(CVTQL,F12_F3);
default: UNKNOWN2;
}
break;
case 0x18: // MISC* instructions
function = (ins & 0xffff);
switch (function)
{
case 0x0000: OP(TRAPB,NOP);
case 0x0400: OP(EXCB,NOP);
case 0x4000: OP(MB,NOP);
case 0x4400: OP(WMB,NOP);
case 0x8000: OP(FETCH,NOP);
case 0xA000: OP(FETCH_M,NOP);
case 0xC000: OP(RPCC,X_R1);
case 0xE000: OP(RC,X_R1);
case 0xE800: OP(ECB,NOP);
case 0xF000: OP(RS,X_R1);
case 0xF800: OP(WH64,NOP);
case 0xFC00: OP(WH64EN,NOP);
default: UNKNOWN2;
}
break;
case 0x19: // HW_MFPR
function = (ins>>8) & 0xff;
OP(HW_MFPR,MFPR);
case 0x1a: // JSR* instructions
OP(JMP,JMP);
case 0x1b: // PAL reserved - HW_LD
function = (ins>>12) & 0xf;
if (function&1) {
OP(HW_LDQ,HW_LD);
} else {
OP(HW_LDL,HW_LD);
}
case 0x1c: // FPTI* instructions
function = (ins>>5) & 0x7f;
switch (function)
{
case 0x00: OP(SEXTB,R2_R3);
case 0x01: OP(SEXTW,R2_R3);
case 0x30: OP(CTPOP,R2_R3);
case 0x31: OP(PERR,R2_R3);
case 0x32: OP(CTLZ,R2_R3);
case 0x33: OP(CTTZ,R2_R3);
case 0x34: OP(UNPKBW,R2_R3);
case 0x35: OP(UNPKBL,R2_R3);
case 0x36: OP(PKWB,R2_R3);
case 0x37: OP(PKLB,R2_R3);
case 0x38: OP(MINSB8,R12_R3);
case 0x39: OP(MINSW4,R12_R3);
case 0x3a: OP(MINUB8,R12_R3);
case 0x3b: OP(MINUW4,R12_R3);
case 0x3c: OP(MAXUB8,R12_R3);
case 0x3d: OP(MAXUW4,R12_R3);
case 0x3e: OP(MAXSB8,R12_R3);
case 0x3f: OP(MAXSW4,R12_R3);
case 0x70: OP(FTOIT,F1_R3);
case 0x78: OP(FTOIS,F1_R3);
default: UNKNOWN2;
}
break;
case 0x1d: // HW_MTPR
function = (ins>>8) & 0xff;
OP(HW_MTPR,MTPR);
case 0x1e: OP(HW_RET,RET);
case 0x1f: // HW_ST
function = (ins>>12) & 0xf;
if (function&1) {
OP(HW_STQ,HW_ST);
} else {
OP(HW_STL,HW_ST);
}
case 0x20: OP(LDF, FMEM);
case 0x21: OP(LDG, FMEM);
case 0x22: OP(LDS, FMEM);
case 0x23: OP(LDT,FMEM);
case 0x24: OP(STF,FMEM);
case 0x25: OP(STG,FMEM);
case 0x26: OP(STS,FMEM);
case 0x27: OP(STT,FMEM);
case 0x28: OP(LDL,MEM);
case 0x29: OP(LDQ,MEM);
case 0x2a: OP(LDL_L,MEM);
case 0x2b: OP(LDQ_L,MEM);
case 0x2c: OP(STL,MEM);
case 0x2d: OP(STQ,MEM);
case 0x2e: OP(STL_C,MEM);
case 0x2f: OP(STQ_C,MEM);
case 0x30: OP(BR,BR);
case 0x31: OP(FBEQ,FCOND);
case 0x32: OP(FBLT,FCOND);
case 0x33: OP(FBLE,FCOND);
case 0x34: OP(BSR,BSR);
case 0x35: OP(FBNE,FCOND);
case 0x36: OP(FBGE,FCOND);
case 0x37: OP(FBGT,FCOND);
case 0x38: OP(BLBC,COND);
case 0x39: OP(BEQ,COND);
case 0x3a: OP(BLT,COND);
case 0x3b: OP(BLE,COND);
case 0x3c: OP(BLBS,COND);
case 0x3d: OP(BNE,COND);
case 0x3e: OP(BGE,COND);
case 0x3f: OP(BGT,COND);
default: UNKNOWN1;
}
return 0;
}
#if defined(IDB)
/**
* \brief Produce disassembly-listing without marker
*
* \param from Address of first instruction to be disassembled.
* \param to Address of instruction following the last instruction to
* be disassembled.
**/
void CAlphaCPU::listing(u64 from, u64 to)
{
listing(from,to,0);
}
/**
* \brief Produce disassembly-listing with marker
*
* \param from Address of first instruction to be disassembled.
* \param to Address of instruction following the last instruction to
* be disassembled.
* \param mark Address of instruction to be underlined with a marker line.