-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMipsOpcode.h
2103 lines (1781 loc) · 45.4 KB
/
MipsOpcode.h
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
/*
Copyright (C) 2012-2030
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MIPSOPCODE_H_
#define _MIPSOPCODE_H_
// this gives you what you need to know about a Mips Instruction
struct MipsInstructionInfo
{
char* InstName;
// char InstAttributes;
};
// Mips registers
enum { R0 = 0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, R26,
R27, R28, R29, R30, R31 };
// **** Here are the InstAtributes, these can be ORed ****
// set if it is a 64-bit instruction
#define IS64BIT 1
// set if the instruction uses Rs
#define USESRS 2
// set if the instuction uses Rt
#define USESRT 4
// set if the instruction uses Rd
#define USESRD 8
#define USESRALL ( USESRS | USESRT | USESRD )
#define USESFT 16
#define USESFS 32
#define USESFD 64
#define USESFALL ( USESFT | USESFS | USESFD )
// **** This might help with the opcodes ****
#define OPCOP0 16
#define OPCOP1 17
#define OPCOP2 18
#define OPCOP1X 19
#define OPSPECIAL 0
#define OPSPECIAL2 28
#define OPREGIMM 1
#define RSBC 8
// for fmt
// .w = fmt=20,fmt3=4
// .s fmt=16,fmt3=0
// .d fmt=17,fmt3=1
//.L fmt=21,fmt3=5
//.ps fmt=22,fmt=6
// **** These will help with fmt and fmt3 fields ****
#define FMTS 16
#define FMTD 17
#define FMTW 20
#define FMTL 21
#define FMTPS 22
#define FMT3S 0
#define FMT3D 1
#define FMT3W 4
#define FMT3L 5
#define FMT3PS 6
// **** This should help with encoding instructions to test them **** //
#define SET_SPECIAL(inst) ( ( inst ) & 0x3f )
#define SET_SHIFT(inst) ( ( ( inst ) & 0x1f ) << 6 )
#define SET_RD(inst) ( ( ( inst ) & 0x1f ) << 11 )
#define SET_RT(inst) ( ( ( inst ) & 0x1f ) << 16 )
#define SET_RS(inst) ( ( ( inst ) & 0x1f ) << 21 )
#define SET_OPCODE(inst) ( ( ( inst ) & 0x3f ) << 26 )
#define SET_IMMED(inst) ( ( inst ) & 0xffff )
#define SET_ADDRESS(inst) ( ( inst ) & 0x3ffffff )
#define SET_BASE(inst) ( ( ( inst ) & 0x1f ) << 21 )
#define SET_HINT(inst) ( ( ( inst ) & 0x1f ) << 16 )
#define SET_REG(inst) ( ( ( inst ) & 0x1f ) << 1 )
#define SET_FD(inst) ( ( ( inst ) & 0x1f ) << 6 )
#define SET_FS(inst) ( ( ( inst ) & 0x1f ) << 11 )
#define SET_FT(inst) ( ( ( inst ) & 0x1f ) << 16 )
#define SET_FMT(inst) ( ( ( inst ) & 0x1f ) << 21 )
// This is the same as FMT
#define SET_RS(inst) ( ( ( inst ) & 0x1f ) << 21 )
// I'll define this as the next 5 bits after the opcode and "FMT/RS" on branch instructions
#define SET_RT(inst) ( ( ( inst ) & 0x1f ) << 16 )
// this will be the 5 bits like where the shift amount goes in shift instructions
#define SET_SF(inst) ( ( ( inst ) & 0x1f ) << 6 )
// this stuff is for vu
#define SET_DEST(inst) ( ( ( inst ) & 0xf ) << 21 )
#define SET_DESTX(inst) ( ( ( inst ) & 0x1 ) << 24 )
#define SET_DESTY(inst) ( ( ( inst ) & 0x1 ) << 23 )
#define SET_DESTZ(inst) ( ( ( inst ) & 0x1 ) << 22 )
#define SET_DESTW(inst) ( ( ( inst ) & 0x1 ) << 21 )
#define SET_IMM11(inst) ( ( ( inst ) & 0x7ff ) )
#define SET_IMM12(inst) ( ( ( ( inst ) & 0x800 ) << 10 ) | ( ( inst ) & 0x7ff ) )
#define SET_IMM15(inst) ( ( ( ( inst ) & 0x7800 ) << 10 ) | ( ( inst ) & 0x7ff ) )
#define SET_IMM24(inst) ( ( inst ) & 0xffffff )
#define SET_FSF(inst) ( ( ( inst ) & 0x3 ) << 21 )
#define SET_FTF(inst) ( ( ( inst ) & 0x3 ) << 23 )
#define SET_IT(inst) ( ( ( inst ) & 0x1f ) << 16 )
#define SET_IS(inst) ( ( ( inst ) & 0x1f ) << 11 )
#define SET_ID(inst) ( ( ( inst ) & 0x1f ) << 6 )
#define SET_IMM5(inst) ( ( ( inst ) & 0x1f ) << 6 )
// **** This should help with decoding instructions ****
#define GET_SPECIAL(inst) ( ( inst ) & 0x3f )
#define GET_SHIFT(inst) ( ( ( inst ) >> 6 ) & 0x1f )
#define GET_RD(inst) ( ( ( inst ) >> 11 ) & 0x1f )
#define GET_RT(inst) ( ( ( inst ) >> 16 ) & 0x1f )
#define GET_RS(inst) ( ( ( inst ) >> 21 ) & 0x1f )
#define GET_OPCODE(inst) ( ( ( inst ) >> 26 ) & 0x3f )
#define GET_IMMED(inst) ( ( inst ) & 0xffff )
#define GET_ADDRESS(inst) ( ( inst ) & 0x3ffffff )
#define GET_BASE(inst) ( ( ( inst ) >> 21 ) & 0x1f )
#define GET_HINT(inst) ( ( ( inst ) >> 16 ) & 0x1f )
#define GET_REG(inst) ( ( ( inst ) >> 1 ) & 0x1f )
#define GET_FD(inst) ( ( ( inst ) >> 6 ) & 0x1f )
#define GET_FS(inst) ( ( ( inst ) >> 11 ) & 0x1f )
#define GET_FT(inst) ( ( ( inst ) >> 16 ) & 0x1f )
#define GET_FMT(inst) ( ( ( inst ) >> 21 ) & 0x1f )
// This is the same as FMT
#define GET_RS(inst) ( ( ( inst ) >> 21 ) & 0x1f )
// I'll define this as the next 5 bits after the opcode and "FMT/RS" on branch instructions
#define GET_RT(inst) ( ( ( inst ) >> 16 ) & 0x1f )
// this will be the 5 bits like where the shift amount goes in shift instructions
#define GET_SF(inst) ( ( ( inst ) >> 6 ) & 0x1f )
// this stuff is for vu
#define GET_UPPER(inst) ( ( ( inst ) >> 32 ) & 0xffffffff )
#define GET_LOWER(inst) ( ( inst ) & 0xffffffff )
#define GET_DEST(inst) ( ( ( inst ) >> 21 ) & 0xf )
#define GET_DESTX(inst) ( ( ( inst ) >> 24 ) & 0x1 )
#define GET_DESTY(inst) ( ( ( inst ) >> 23 ) & 0x1 )
#define GET_DESTZ(inst) ( ( ( inst ) >> 22 ) & 0x1 )
#define GET_DESTW(inst) ( ( ( inst ) >> 21 ) & 0x1 )
#define GET_IMM11(inst) ( ( inst ) & 0x7ff )
#define GET_IMM12(inst) ( ( ( ( inst ) >> 10 ) & 0x800 ) | ( ( inst ) & 0x7ff ) )
#define GET_IMM15(inst) ( ( ( ( inst ) >> 10 ) & 0x7800 ) | ( ( inst ) & 0x7ff ) )
#define GET_IMM24(inst) ( ( inst ) & 0xffffff )
#define GET_FSF(inst) ( ( ( inst ) >> 21 ) & 0x3 )
#define GET_FTF(inst) ( ( ( inst ) >> 23 ) & 0x3 )
#define GET_IT(inst) ( ( ( inst >> 16 ) ) & 0x1f )
#define GET_IS(inst) ( ( ( inst >> 11 ) ) & 0x1f )
#define GET_ID(inst) ( ( ( inst >> 6 ) ) & 0x1f )
#define GET_IMM5(inst) ( ( ( inst >> 6 ) ) & 0x1f )
// **** This should helps with the opcodes ****
// "OP" means it is an opcode
// "SP" means it goes in the "Special" field
// **** "Special" opcodes **** (Mostly R-Type Instructions)
#define SPSLL 0
#define SPMOVCI 1
#define SPSRL 2
#define SPSRA 3
#define SPSLLV 4
#define SPSRLV 6
#define SPSRAV 7
#define SPJR 8
#define SPJALR 9
#define SPMOVZ 10
#define SPMOVN 11
#define SPSYSCALL 12
#define SPBREAK 13
#define SPSYNC 15
#define SPMFHI 16
#define SPMTHI 17
#define SPMFLO 18
#define SPMTLO 19
#define SPDSLLV 20
#define SPDSRLV 22
#define SPDSRAV 23
#define SPMULT 24
#define SPMULTU 25
#define SPDIV 26
#define SPDIVU 27
#define SPDMULT 28
#define SPDMULTU 29
#define SPDDIV 30
#define SPDDIVU 31
#define SPADD 32
#define SPADDU 33
#define SPSUB 34
#define SPSUBU 35
#define SPAND 36
#define SPOR 37
#define SPXOR 38
#define SPNOR 39
#define SPSLT 42
#define SPSLTU 43
#define SPDADD 44
#define SPDADDU 45
#define SPDSUB 46
#define SPDSUBU 47
#define SPTGE 48
#define SPTGEU 49
#define SPTLT 50
#define SPTLTU 51
#define SPTEQ 52
#define SPTNE 54
#define SPDSLL 56
#define SPDSRL 58
#define SPDSRA 59
#define SPDSLL32 60
#define SPDSRL32 62
#define SPDSRA32 63
// **** "Special2" opcodes ****
#define SPMADD 0
#define SPMADDU 1
#define SPMUL 2
#define SPMSUB 4
#define SPMSUBU 5
#define SPCLZ 32
#define SPCLO 33
#define SPDCLZ 36
#define SPDCLO 37
#define SPSDBBP 63
// **** COP1 codes **** (it's just a floating point co-processor)
// Note: For these instructions check the opcode then check fmt to determine what type of instruction it is
// it looks like you have to use the fmt value to determine what's going on
// these are the defines for Playstation 2
#define SPADDFMTS 0
#define SPSUBFMTS 1
#define SPMULFMTS 2
#define SPDIVFMTS 3
#define SPSQRTFMTS 4
#define SPABSFMTS 5
#define SPMOVFMTS 6
#define SPNEGFMTS 7
#define SPRSQRTFMTS 22
#define SPADDAFMTS 24
#define SPSUBAFMTS 25
#define SPMULAFMTS 26
#define SPMADDFMTS 28
#define SPMSUBFMTS 29
#define SPMADDAFMTS 30
#define SPMSUBAFMTS 31
#define SPCVTSFMTW 32
#define SPCVTWFMTS 36
#define SPMAXFMTS 40
#define SPMINFMTS 41
#define SPCFFMTS 48
#define SPCEQFMTS 50
#define SPCLTFMTS 52
#define SPCLEFMTS 54
// COP1 codes not used by PS2 //
#define SPROUNDLFMT 8
#define SPTRUNCLFMT 9
#define SPCEILLFMT 10
#define SPFLOORLFMT 11
#define SPROUNDWFMT 12
#define SPTRUNCWFMT 13
#define SPCEILWFMT 14
#define SPFLOORWFMT 15
#define SPMOVCF 17
#define SPMOVZFMT 18
#define SPMOVNFMT 19
#define SPRECIPFMT 21
#define SPRSQRTFMT 22
#define SPCVTSFMTW 32
#define SPCVTSPU 32
#define SPCVTDFMT 33
#define SPCVTWFMTS 36
#define SPCVTLFMT 37
#define SPCVTPSS 38
#define SPCVTSPL 40
#define SPPLLPS 44
#define SPPLUPS 45
#define SPPULPS 46
#define SPPUUPS 47
#define RSMFC1 0
#define RSDMFC1 1
#define RSCFC1 2
#define RSMTC1 4
#define RSDMTC1 5
#define RSCTC1 6
#define RSBC0F 8
#define RSBC0FL 8
#define RSBC0T 8
#define RSBC0TL 8
#define RSBC1F 8
#define RSBC1FL 8
#define RSBC1T 8
#define RSBC1TL 8
#define RSBC2F 8
#define RSBC2FL 8
#define RSBC2T 8
#define RSBC2TL 8
#define RSS 16
#define RSW 20
#define RTBC0F 0
#define RTBC0FL 2
#define RTBC0T 1
#define RTBC0TL 3
#define RTBC1F 0
#define RTBC1FL 2
#define RTBC1T 1
#define RTBC1TL 3
#define RTBC2F 0
#define RTBC2FL 2
#define RTBC2T 1
#define RTBC2TL 3
// **** Immediate opcodes **** (Mostly I-Type instructions)
#define OPADDI 8
#define OPADDIU 9
#define OPSLTI 10
#define OPSLTIU 11
#define OPANDI 12
#define OPORI 13
#define OPXORI 14
#define OPLUI 15
#define OPDADDI 24
#define OPDADDIU 25
// **** COP1X codes ****
/*
#define SPLWXC1 0
#define SPLDXC1 1
#define SPLUXC1 5
#define SPSWXC1 8
#define SPSDXC1 9
#define SPSUXC1 13
#define SPPREFX 15
#define SPALNVPS 30
#define SPMADDFMTS 32
#define SPMADDFMTD 33
#define SPMADDFMTPS 38
#define SPMSUBFMTS 40
#define SPMSUBFMTD 41
#define SPMSUBFMTPS 46
*/
// **** REGIMM codes ****
#define RTBLTZ 0
#define RTBGEZ 1
#define RTBLTZL 2
#define RTBGEZL 3
#define RTTGEI 8
#define RTTGEIU 9
#define RTTLTI 10
#define RTTLTIU 11
#define RTTEQI 12
#define RTTNEI 14
#define RTBLTZAL 16
#define RTBGEZAL 17
#define RTBLTZALL 18
#define RTBGEZALL 19
// **** REGIMM instructions ****
#define OPBGEZ OPREGIMM
#define OPBGEZAL OPREGIMM
#define OPBGEZALL OPREGIMM
#define OPBGEZL OPREGIMM
#define OPBLTZ OPREGIMM
#define OPBLTZAL OPREGIMM
#define OPBLTZALL OPREGIMM
#define OPBLTZL OPREGIMM
#define OPTEQI OPREGIMM
#define OPTGEI OPREGIMM
#define OPTGEIU OPREGIMM
#define OPTLTI OPREGIMM
#define OPTLTIU OPREGIMM
#define OPTNEI OPREGIMM
// **** "Special" Instructions ****
#define OPADD OPSPECIAL
#define OPADDU OPSPECIAL
#define OPAND OPSPECIAL
#define OPBREAK OPSPECIAL
#define OPDADD OPSPECIAL
#define OPDADDU OPSPECIAL
#define OPDDIV OPSPECIAL
#define OPDDIVU OPSPECIAL
#define OPDIV OPSPECIAL
#define OPDIVU OPSPECIAL
#define OPDMULT OPSPECIAL
#define OPDMULTU OPSPECIAL
#define OPDSLL OPSPECIAL
#define OPDSLL32 OPSPECIAL
#define OPDSLLV OPSPECIAL
#define OPDSRA OPSPECIAL
#define OPDSRA32 OPSPECIAL
#define OPDSRAV OPSPECIAL
#define OPDSRL OPSPECIAL
#define OPDSRL32 OPSPECIAL
#define OPDSRLV OPSPECIAL
#define OPDSUB OPSPECIAL
#define OPDSUBU OPSPECIAL
#define OPJALR OPSPECIAL
#define OPJR OPSPECIAL
#define OPMFHI OPSPECIAL
#define OPMFLO OPSPECIAL
#define OPMOVF OPSPECIAL
#define OPMOVN OPSPECIAL
#define OPMOVT OPSPECIAL
#define OPMOVZ OPSPECIAL
#define OPMTHI OPSPECIAL
#define OPMTLO OPSPECIAL
#define OPMULT OPSPECIAL
#define OPMULTU OPSPECIAL
#define OPNOP OPSPECIAL
#define OPNOR OPSPECIAL
#define OPOR OPSPECIAL
#define OPSLL OPSPECIAL
#define OPSLLV OPSPECIAL
#define OPSLT OPSPECIAL
#define OPSLTU OPSPECIAL
#define OPSRA OPSPECIAL
#define OPSRAV OPSPECIAL
#define OPSRL OPSPECIAL
#define OPSRLV OPSPECIAL
#define OPSSNOP OPSPECIAL
#define OPSUB OPSPECIAL
#define OPSUBU OPSPECIAL
#define OPSYNC OPSPECIAL
#define OPSYSCALL OPSPECIAL
#define OPTEQ OPSPECIAL
#define OPTGE OPSPECIAL
#define OPTGEU OPSPECIAL
#define OPTLT OPSPECIAL
#define OPTLTU OPSPECIAL
#define OPTNE OPSPECIAL
#define OPXOR OPSPECIAL
// **** "Special2" Instructions ****
/*
#define OPCLO OPSPECIAL2
#define OPCLZ OPSPECIAL2
#define OPDCLO OPSPECIAL2
#define OPDCLZ OPSPECIAL2
#define OPMADD OPSPECIAL2
#define OPMADDU OPSPECIAL2
#define OPMSUB OPSPECIAL2
#define OPMSUBU OPSPECIAL2
#define OPMUL OPSPECIAL2
#define OPSDBBP OPSPECIAL2
*/
// **** COP1 Instructions ****
// these include the ones for Playstation 2
#define OPABSFMTS OPCOP1
#define OPADDFMTS OPCOP1
#define OPBC1F OPCOP1
#define OPBC1FL OPCOP1
#define OPBC1T OPCOP1
#define OPBC1TL OPCOP1
#define OPCCONDFMT OPCOP1
#define OPCFS OPCOP1
#define OPCEQS OPCOP1
#define OPCLTS OPCOP1
#define OPCLES OPCOP1
#define OPCEILLFMT OPCOP1
#define OPCEILWFMT OPCOP1
#define OPCFC1 OPCOP1
#define OPCTC1 OPCOP1
#define OPCVTDFMT OPCOP1
#define OPCVTLFMT OPCOP1
#define OPCVTPSS OPCOP1
#define OPCVTSFMTW OPCOP1
#define OPCVTSPL OPCOP1
#define OPCVTSPU OPCOP1
#define OPCVTWFMTS OPCOP1
#define OPDIVFMTS OPCOP1
#define OPDMFC1 OPCOP1
#define OPDMTC1 OPCOP1
#define OPFLOORLFMT OPCOP1
#define OPFLOORWFMT OPCOP1
#define OPMFC1 OPCOP1
#define OPMOVFMTS OPCOP1
#define OPMOVFFMT OPCOP1
#define OPMOVNFMT OPCOP1
#define OPMOVTFMT OPCOP1
#define OPMOVZFMT OPCOP1
#define OPMTC1 OPCOP1
#define OPMULFMTS OPCOP1
#define OPNEGFMTS OPCOP1
#define OPPLLPS OPCOP1
#define OPPLUPS OPCOP1
#define OPPULPS OPCOP1
#define OPPUUPS OPCOP1
#define OPRECIPFMT OPCOP1
#define OPROUNDLFMT OPCOP1
#define OPROUNDWFMT OPCOP1
#define OPRSQRTFMTS OPCOP1
#define OPSQRTFMTS OPCOP1
#define OPSUBFMTS OPCOP1
#define OPTRUNCLFMT OPCOP1
#define OPTRUNCWFMT OPCOP1
// * Playstation 2 specific Cop1 opcodes * //
#define OPADDAFMTS OPCOP1
#define OPSUBFMTS OPCOP1
#define OPMADDFMTS OPCOP1
#define OPMSUBFMTS OPCOP1
#define OPCVTWFMTS OPCOP1
#define OPMAXFMTS OPCOP1
#define OPMINFMTS OPCOP1
#define OPCFFMTS OPCOP1
#define OPCEQFMTS OPCOP1
#define OPCLTFMTS OPCOP1
#define OPCLEFMTS OPCOP1
// **** COP1X Instructions ****
/*
#define OPALNVPS OPCOP1X
#define OPLDXC1 OPCOP1X
#define OPLUXC1 OPCOP1X
#define OPLWXC1 OPCOP1X
#define OPMADDFMT OPCOP1X
#define OPMSUBFMT OPCOP1X
#define OPNMADDFMT OPCOP1X
#define OPNSUBFMT OPCOP1X
#define OPPREFX OPCOP1X
#define OPSDXC1 OPCOP1X
#define OPSUXC1 OPCOP1X
#define OPSWXC1 OPCOP1X
*/
// **** Load Instructions ****
#define OPLB 32
#define OPLBU 36
#define OPLD 55
#define OPLDC1 53
#define OPLDC2 54
#define OPLDL 26
#define OPLDR 27
#define OPLH 33
#define OPLHU 37
#define OPLL 48
#define OPLLD 52
#define OPLW 35
#define OPLWC1 49
#define OPLWC2 50
#define OPLWL 34
#define OPLWR 38
#define OPLWU 39
// **** Store Instructions ****
#define OPSB 40
#define OPSC 56
#define OPSCD 60
#define OPSD 63
#define OPSDC1 61
#define OPSDC2 62
#define OPSDL 44
#define OPSDR 45
#define OPSH 41
#define OPSW 43
#define OPSWC1 57
#define OPSWC2 58
#define OPSWL 42
#define OPSWR 46
// **** COP0 codes ****
#define SPUSERSCODE 0
#define SPTLBR 1
#define SPTLBWI 2
#define SPTLBWR 6
#define SPTLBP 8
#define SPERET 24
#define SPDERET 31
#define SPWAIT 32
#define SPDI 57
#define SPEI 56
// * R3000A *
#define SPRFE 16
#define RSMFC0 0
#define RSDMFC0 1
#define RSMTC0 4
#define RSDMTC0 5
#define RSCFC0 0
#define RSCTC0 4
#define RSCO 16
// * R3000A *
#define RSRFE 16
// **** COP0 Opcodes ****
#define OPBC0F OPCOP0
#define OPBC0FL OPCOP0
#define OPBC0T OPCOP0
#define OPBC0TL OPCOP0
#define OPDERET OPCOP0
#define OPDMFC0 OPCOP0
#define OPDMTC0 OPCOP0
#define OPERET OPCOP0
#define OPMFC0 OPCOP0
#define OPMTC0 OPCOP0
#define OPTLBP OPCOP0
#define OPTLBR OPCOP0
#define OPTLBWI OPCOP0
#define OPTLBWR OPCOP0
#define OPWAIT OPCOP0
#define OPEI OPCOP0
#define OPDI OPCOP0
#define OPCFC0 OPCOP0
#define OPCTC0 OPCOP0
// * R3000A *
#define OPRFE OPCOP0
// **** COP2 codes ****
#define RSMFC2 0
#define RSDMFC2 1
#define RSCFC2 2
#define RSMTC2 4
#define RSDMTC2 5
#define RSCTC2 6
#define RSBC2F 8
#define RSBC2FL 8
#define RSBC2T 8
#define RSBC2TL 8
#define RSCOP2 16
// **** COP2 Opcodes ****
#define OPBC2F OPCOP2
#define OPBC2FL OPCOP2
#define OPBC2T OPCOP2
#define OPBC2TL OPCOP2
#define OPCFC2 OPCOP2
#define OPCTC2 OPCOP2
#define OPDMFC2 OPCOP2
#define OPDMTC2 OPCOP2
#define OPMFC2 OPCOP2
#define OPMTC2 OPCOP2
// **** Branch codes ****
#define RTBGTZ 0
#define RTBGTZL 0
#define RTBLEZ 0
#define RTBLEZL 0
// **** Branch Instruction Opcodes ****
#define OPBEQ 4
#define OPBNE 5
#define OPBLEZ 6
#define OPBGTZ 7
#define OPBEQL 20
#define OPBNEL 21
#define OPBLEZL 22
#define OPBGTZL 23
// **** Jump Instruction Opcodes ****
#define OPJ 2
#define OPJAL 3
// **** Other Opcodes ****
#define OPCACHE 47
#define OPPREF 51
//#define OPB OPBEQ // commented out since this is really BEQ R0, R0, offset
//#define OPBAL OPREGIMM // commented out since this is really BGEZAL r0, offset
//#define RSBAL 0
//#define RTBAL RTBGEZAL
//#define OPBEQ OPBEQ // commenting out since this was already defined
//#define OPCOP2 OPCOP2
#define SPMOVF SPMOVCI
#define SPMOVFFMT SPMOVCF
#define SPMOVT SPMOVCI
#define SPMOVTFMT SPMOVCF
#define SPNOP SPSLL
#define SPSSNOP SPSLL
// **** MMI Opcodes **** //
// this seems to be the same as Special2
#define OPMMI 28
#define OPDIV1 OPMMI
#define OPDIVU1 OPMMI
#define OPMADD OPMMI
#define OPMADD1 OPMMI
#define OPMADDU OPMMI
#define OPMADDU1 OPMMI
#define OPMFHI1 OPMMI
#define OPMFLO1 OPMMI
#define OPMTHI1 OPMMI
#define OPMTLO1 OPMMI
#define OPMULT1 OPMMI
#define OPMULTU1 OPMMI
#define OPPABSH OPMMI
#define OPPLZCW OPMMI
#define OPPMFHLFMT OPMMI
#define OPPMTHL OPMMI
#define OPPSLLH OPMMI
#define OPPSRLH OPMMI
#define OPPSRAH OPMMI
#define OPPSLLW OPMMI
#define OPPSRLW OPMMI
#define OPPSRAW OPMMI
// **** Opcode MMI "Special" (actually "Special2") codes **** //
#define SPMADD 0
#define SPMADDU 1
#define SPPLZCW 4
#define SPMMI0 8
#define SPMMI2 9
#define SPMFHI1 16
#define SPMTHI1 17 /* This might be wrong, will find out during "testing" */
#define SPMTLO1 17 /* This might be wrong, will find out during "testing" */
#define SPMULT1 24
#define SPMULTU1 25
#define SPDIV1 26
#define SPDIVU1 27
#define SPMFLO1 28
#define SPMADD1 32
#define SPMADDU1 33
#define SPMMI1 40
#define SPMMI3 41
#define SPPMFHLFMT 48
#define SPPMTHL 49
#define SPPSLLH 52
#define SPPSRLH 54
#define SPPSRAH 55
#define SPPSLLW 60
#define SPPSRLW 62
#define SPPSRAW 63
// **** MMI0 Opcodes **** //
#define OPPADDB OPMMI
#define OPPADDH OPMMI
#define OPPADDSB OPMMI
#define OPPADDSH OPMMI
#define OPPADDSW OPMMI
#define OPPADDW OPMMI
#define OPPCGTB OPMMI
#define OPPCGTH OPMMI
#define OPPCGTW OPMMI
#define OPPEXT5 OPMMI
#define OPPEXTLB OPMMI
#define OPPEXTLH OPMMI
#define OPPEXTLW OPMMI
#define OPPMAXH OPMMI
#define OPPMAXW OPMMI
#define OPPPAC5 OPMMI
#define OPPPACB OPMMI
#define OPPPACH OPMMI
#define OPPPACW OPMMI
#define OPPSUBB OPMMI
#define OPPSUBH OPMMI
#define OPPSUBSB OPMMI
#define OPPSUBSH OPMMI
#define OPPSUBSW OPMMI
#define OPPSUBW OPMMI
// **** MMI1 Opcodes **** //
#define OPPABSH OPMMI
#define OPPABSW OPMMI
#define OPPADDUB OPMMI
#define OPPADDUH OPMMI
#define OPPADDUW OPMMI
#define OPPADSBH OPMMI
#define OPPCEQB OPMMI
#define OPPCEQH OPMMI
#define OPPCEQW OPMMI
#define OPPEXTUB OPMMI
#define OPPEXTUH OPMMI
#define OPPEXTUW OPMMI
#define OPPMINH OPMMI
#define OPPMINW OPMMI
#define OPPSUBUB OPMMI
#define OPPSUBUH OPMMI
#define OPPSUBUW OPMMI
#define OPQFSRV OPMMI
// **** MMI2 Opcodes **** //
#define OPPAND OPMMI
#define OPPCPYLD OPMMI
#define OPPDIVBW OPMMI
#define OPPDIVW OPMMI
#define OPPEXEH OPMMI
#define OPPEXEW OPMMI
#define OPPHMADH OPMMI
#define OPPHMSBH OPMMI
#define OPPINTH OPMMI
#define OPPMADDH OPMMI
#define OPPMADDW OPMMI
#define OPPMFHI OPMMI
#define OPPMFLO OPMMI
#define OPPMSUBH OPMMI
#define OPPMSUBW OPMMI
#define OPPMULTH OPMMI
#define OPPMULTW OPMMI
#define OPPREVH OPMMI
#define OPPROT3W OPMMI
#define OPPSLLVW OPMMI
#define OPPSRLVW OPMMI
#define OPPXOR OPMMI
// **** MMI3 Opcodes **** //
#define OPPCPYH OPMMI
#define OPPCPYUD OPMMI
#define OPPDIVUW OPMMI
#define OPPEXCH OPMMI
#define OPPEXCW OPMMI
#define OPPINTEH OPMMI
#define OPPMADDUW OPMMI
#define OPPMTHI OPMMI
#define OPPMTLO OPMMI
#define OPPMULTUW OPMMI
#define OPPNOR OPMMI
#define OPPOR OPMMI
#define OPPSRAVW OPMMI
// **** MMI0 "Special" codes ****
#define SPPADDB SPMMI0
#define SPPADDH SPMMI0
#define SPPADDSB SPMMI0
#define SPPADDSH SPMMI0
#define SPPADDSW SPMMI0
#define SPPADDW SPMMI0
#define SPPCGTB SPMMI0
#define SPPCGTH SPMMI0
#define SPPCGTW SPMMI0
#define SPPEXT5 SPMMI0
#define SPPEXTLB SPMMI0
#define SPPEXTLH SPMMI0
#define SPPEXTLW SPMMI0
#define SPPMAXH SPMMI0
#define SPPMAXW SPMMI0
#define SPPPAC5 SPMMI0
#define SPPPACB SPMMI0
#define SPPPACH SPMMI0
#define SPPPACW SPMMI0
#define SPPSUBB SPMMI0
#define SPPSUBH SPMMI0
#define SPPSUBSB SPMMI0
#define SPPSUBSH SPMMI0
#define SPPSUBSW SPMMI0
#define SPPSUBW SPMMI0
// **** MMI1 "Special" codes ****
#define SPPABSH SPMMI1
#define SPPABSW SPMMI1
#define SPPADDUB SPMMI1
#define SPPADDUH SPMMI1
#define SPPADDUW SPMMI1
#define SPPADSBH SPMMI1
#define SPPCEQB SPMMI1
#define SPPCEQH SPMMI1
#define SPPCEQW SPMMI1
#define SPPEXTUB SPMMI1
#define SPPEXTUH SPMMI1
#define SPPEXTUW SPMMI1
#define SPPMINH SPMMI1
#define SPPMINW SPMMI1
#define SPPSUBUB SPMMI1
#define SPPSUBUH SPMMI1
#define SPPSUBUW SPMMI1
#define SPQFSRV SPMMI1
// **** MMI2 "Special" codes ****
#define SPPAND SPMMI2
#define SPPCPYLD SPMMI2
#define SPPDIVBW SPMMI2
#define SPPDIVW SPMMI2
#define SPPEXEH SPMMI2
#define SPPEXEW SPMMI2