-
Notifications
You must be signed in to change notification settings - Fork 10
/
RecompilerCPU.cpp
3398 lines (3210 loc) · 124 KB
/
RecompilerCPU.cpp
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
/*
* Project 64 - A Nintendo 64 emulator.
*
* (c) Copyright 2001 zilmar ([email protected]) and
* Jabo ([email protected]).
*
* pj64 homepage: www.pj64.net
*
* Permission to use, copy, modify and distribute Project64 in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Project64 is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Project64 or software derived from Project64.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so if they want them.
*
*/
#include <Windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "main.h"
#include "cpu.h"
#include "x86.h"
#include "debugger.h"
#include "plugin.h"
void _fastcall CreateSectionLinkage (BLOCK_SECTION * Section);
void _fastcall DetermineLoop(BLOCK_SECTION * Section, DWORD Test, DWORD Test2, DWORD TestID);
BOOL DisplaySectionInformation (BLOCK_SECTION * Section, DWORD ID, DWORD Test);
BLOCK_SECTION * ExistingSection(BLOCK_SECTION * StartSection, DWORD Addr, DWORD Test);
void _fastcall FillSectionInfo(BLOCK_SECTION * Section);
void _fastcall FixConstants ( BLOCK_SECTION * Section, DWORD Test,int * Changed );
BOOL GenerateX86Code (BLOCK_SECTION * Section, DWORD Test );
DWORD GetNewTestValue( void );
void _fastcall InheritConstants(BLOCK_SECTION * Section);
BOOL InheritParentInfo (BLOCK_SECTION * Section);
void _fastcall InitilzeSection(BLOCK_SECTION * Section, BLOCK_SECTION * Parent, DWORD StartAddr, DWORD ID);
void InitilizeRegSet(REG_INFO * RegSet);
BOOL IsAllParentLoops(BLOCK_SECTION * Section, BLOCK_SECTION * Parent, BOOL IgnoreIfCompiled, DWORD Test);
void MarkCodeBlock (DWORD PAddr);
void SyncRegState (BLOCK_SECTION * Section, REG_INFO * SyncTo);
DWORD TLBLoadAddress, TargetIndex;
TARGET_INFO * TargetInfo = NULL;
BLOCK_INFO BlockInfo;
ORIGINAL_MEMMARKER * OrigMem = NULL;
void InitilizeInitialCompilerVariable ( void)
{
memset(&BlockInfo,0,sizeof(BlockInfo));
}
void _fastcall AddParent(BLOCK_SECTION * Section, BLOCK_SECTION * Parent){
int NoOfParents, count;
if (Section == NULL) { return; }
if (Parent == NULL) {
InitilizeRegSet(&Section->RegStart);
memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO));
return;
}
if (Section->ParentSection != NULL) {
for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++) {
if (Section->ParentSection[NoOfParents] == Parent) {
return;
}
}
for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++);
NoOfParents += 1;
} else {
NoOfParents = 1;
}
if (NoOfParents == 1) {
Section->ParentSection = malloc((NoOfParents + 1)*sizeof(void *));
} else {
Section->ParentSection = realloc(Section->ParentSection,(NoOfParents + 1)*sizeof(void *));
}
Section->ParentSection[NoOfParents - 1] = Parent;
Section->ParentSection[NoOfParents] = NULL;
if (NoOfParents == 1) {
if (Parent->ContinueSection == Section) {
memcpy(&Section->RegStart,&Parent->Cont.RegSet,sizeof(REG_INFO));
} else if (Parent->JumpSection == Section) {
memcpy(&Section->RegStart,&Parent->Jump.RegSet,sizeof(REG_INFO));
} else {
#ifndef EXTERNAL_RELEASE
DisplayError("How are these sections joined?????");
#endif
}
memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO));
} else {
if (Parent->ContinueSection == Section) {
for (count = 0; count < 32; count++) {
if (Section->RegStart.MIPS_RegState[count] != Parent->Cont.RegSet.MIPS_RegState[count]) {
Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN;
}
}
}
if (Parent->JumpSection == Section) {
for (count = 0; count < 32; count++) {
if (Section->RegStart.MIPS_RegState[count] != Parent->Jump.RegSet.MIPS_RegState[count]) {
Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN;
}
}
}
memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO));
}
}
void AnalyseBlock (void) {
int Changed;
BLOCK_SECTION * Section = &BlockInfo.BlockInfo;
BlockInfo.NoOfSections = 1;
InitilzeSection (Section, NULL, BlockInfo.StartVAddr, BlockInfo.NoOfSections);
if (UseLinking) {
CreateSectionLinkage (Section);
DetermineLoop(Section,GetNewTestValue(),GetNewTestValue(), Section->SectionID);
do {
Changed = FALSE;
FixConstants(Section,GetNewTestValue(),&Changed);
} while (Changed == TRUE);
}
}
int ConstantsType (__int64 Value) {
if (((Value >> 32) == -1) && ((Value & 0x80000000) != 0)) { return STATE_CONST_32; }
if (((Value >> 32) == 0) && ((Value & 0x80000000) == 0)) { return STATE_CONST_32; }
return STATE_CONST_64;
}
BYTE * Compiler4300iBlock(void) {
DWORD StartAddress;
int count;
//reset BlockInfo
if (BlockInfo.ExitInfo)
{
for (count = 0; count < BlockInfo.ExitCount; count ++) {
free(BlockInfo.ExitInfo[count]);
}
if (BlockInfo.ExitInfo) { free(BlockInfo.ExitInfo); }
BlockInfo.ExitInfo = NULL;
}
memset(&BlockInfo,0,sizeof(BlockInfo));
BlockInfo.CompiledLocation = RecompPos;
BlockInfo.StartVAddr = PROGRAM_COUNTER;
AnalyseBlock();
StartAddress = BlockInfo.StartVAddr;
TranslateVaddr(&StartAddress);
MarkCodeBlock(StartAddress);
if (StartAddress < RdramSize) {
CPU_Message("====== RDRAM: block (%X:%d) ======", StartAddress>>12,N64_Blocks.NoOfRDRamBlocks[StartAddress>>12]);
} else if (StartAddress >= 0x04000000 && StartAddress <= 0x04000FFC) {
CPU_Message("====== DMEM: block (%d) ======", N64_Blocks.NoOfDMEMBlocks);
} else if (StartAddress >= 0x04001000 && StartAddress <= 0x04001FFC) {
CPU_Message("====== IMEM: block (%d) ======", N64_Blocks.NoOfIMEMBlocks);
} else if (StartAddress >= 0x1FC00000 && StartAddress <= 0x1FC00800) {
CPU_Message("====== PIF ROM: block ======");
} else {
#ifndef ROM_IN_MAPSPACE
#ifndef EXTERNAL_RELEASE
DisplayError("Ummm... Where does this block go");
#endif
ExitThread(0);
#endif
}
CPU_Message("x86 code at: %X",BlockInfo.CompiledLocation);
CPU_Message("Start of Block: %X",BlockInfo.StartVAddr );
CPU_Message("No of Sections: %d",BlockInfo.NoOfSections );
CPU_Message("====== recompiled code ======");
if (UseLinking) {
/*for (count = 0; count < BlockInfo.NoOfSections; count ++) {
DisplaySectionInformation(&BlockInfo.BlockInfo,count + 1,BlockInfo.BlockInfo.Test + 1);
}*/
}
if (CPU_Type == CPU_SyncCores) {
//if ((DWORD)BlockInfo.CompiledLocation == 0x60A7B73B) { BreakPoint(); }
MoveConstToVariable((DWORD)BlockInfo.CompiledLocation,&CurrentBlock,"CurrentBlock");
}
if (UseLinking) {
while (GenerateX86Code(&BlockInfo.BlockInfo,GetNewTestValue()));
} else {
GenerateX86Code(&BlockInfo.BlockInfo,GetNewTestValue());
}
for (count = 0; count < BlockInfo.ExitCount; count ++) {
CPU_Message("");
CPU_Message(" $Exit_%d",count);
SetJump32(BlockInfo.ExitInfo[count]->JumpLoc,RecompPos);
NextInstruction = BlockInfo.ExitInfo[count]->NextInstruction;
CompileExit(BlockInfo.ExitInfo[count]->TargetPC,BlockInfo.ExitInfo[count]->ExitRegSet,
BlockInfo.ExitInfo[count]->reason,TRUE,NULL);
}
CPU_Message("====== End of recompiled code ======");
FreeSection (BlockInfo.BlockInfo.ContinueSection,&BlockInfo.BlockInfo);
FreeSection (BlockInfo.BlockInfo.JumpSection,&BlockInfo.BlockInfo);
for (count = 0; count < BlockInfo.ExitCount; count ++) {
free(BlockInfo.ExitInfo[count]);
}
if (BlockInfo.ExitInfo) { free(BlockInfo.ExitInfo); }
BlockInfo.ExitInfo = NULL;
BlockInfo.ExitCount = 0;
if (ShowCompMem) {
char StatusString[256];
DWORD Size, MB, KB;
Size = RecompPos - RecompCode;
MB = Size / 0x100000;
Size -= MB * 0x100000;
KB = Size / 1024;
Size -= KB * 1024;
sprintf(StatusString,"Memory used: %d mb %d kb %d bytes ",MB,KB,Size);
SendMessage( hStatusWnd, SB_SETTEXT, 0, (LPARAM)StatusString );
}
return BlockInfo.CompiledLocation;
}
BYTE * CompileDelaySlot(void) {
DWORD StartAddress = PROGRAM_COUNTER;
BLOCK_SECTION *Section, DelaySection;
BYTE * Block = RecompPos;
int count, x86Reg;
Section = &DelaySection;
if ((StartAddress & 0xFFC) != 0) {
#ifndef EXTERNAL_RELEASE
DisplayError("Why are you compiling the Delay Slot at %X",StartAddress);
#endif
ExitThread(0);
}
if (!r4300i_LW_VAddr(StartAddress, &Opcode.Hex)) {
#ifndef EXTERNAL_RELEASE
DisplayError("TLB Miss in delay slot\nEmulation will know stop");
#endif
ExitThread(0);
}
TranslateVaddr(&StartAddress);
if (StartAddress < RdramSize) {
CPU_Message("====== RDRAM: Delay Slot ======", 1);
} else if (StartAddress >= 0x04000000 && StartAddress <= 0x04000FFC) {
CPU_Message("====== DMEM: Delay Slot ======");
} else if (StartAddress >= 0x04001000 && StartAddress <= 0x04001FFC) {
CPU_Message("====== IMEM: Delay Slot ======");
} else if (StartAddress >= 0x1FC00000 && StartAddress <= 0x1FC00800) {
CPU_Message("====== PIF ROM: Delay Slot ======");
} else {
#ifndef ROM_IN_MAPSPACE
#ifndef EXTERNAL_RELEASE
DisplayError("Ummm... Where does this block go");
#endif
ExitThread(0);
#endif
}
MarkCodeBlock(StartAddress);
CPU_Message("x86 code at: %X",Block);
CPU_Message("Delay Slot location: %X",PROGRAM_COUNTER );
CPU_Message("====== recompiled code ======");
InitilzeSection (Section, NULL, PROGRAM_COUNTER, 0);
InitilizeRegSet(&Section->RegStart);
memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO));
if (CPU_Type == CPU_SyncCores) {
MoveConstToVariable((DWORD)Block,&CurrentBlock,"CurrentBlock");
}
BlockCycleCount += CountPerOp;
//CPU_Message("BlockCycleCount = %d",BlockCycleCount);
BlockRandomModifier += 1;
//CPU_Message("BlockRandomModifier = %d",BlockRandomModifier);
switch (Opcode.op) {
case R4300i_SPECIAL:
switch (Opcode.funct) {
case R4300i_SPECIAL_SLL: Compile_R4300i_SPECIAL_SLL(Section); break;
case R4300i_SPECIAL_SRL: Compile_R4300i_SPECIAL_SRL(Section); break;
case R4300i_SPECIAL_SRA: Compile_R4300i_SPECIAL_SRA(Section); break;
case R4300i_SPECIAL_SLLV: Compile_R4300i_SPECIAL_SLLV(Section); break;
case R4300i_SPECIAL_SRLV: Compile_R4300i_SPECIAL_SRLV(Section); break;
case R4300i_SPECIAL_SRAV: Compile_R4300i_SPECIAL_SRAV(Section); break;
case R4300i_SPECIAL_MFLO: Compile_R4300i_SPECIAL_MFLO(Section); break;
case R4300i_SPECIAL_MTLO: Compile_R4300i_SPECIAL_MTLO(Section); break;
case R4300i_SPECIAL_MFHI: Compile_R4300i_SPECIAL_MFHI(Section); break;
case R4300i_SPECIAL_MTHI: Compile_R4300i_SPECIAL_MTHI(Section); break;
case R4300i_SPECIAL_MULT: Compile_R4300i_SPECIAL_MULT(Section); break;
case R4300i_SPECIAL_DIV: Compile_R4300i_SPECIAL_DIV(Section); break;
case R4300i_SPECIAL_DIVU: Compile_R4300i_SPECIAL_DIVU(Section); break;
case R4300i_SPECIAL_MULTU: Compile_R4300i_SPECIAL_MULTU(Section); break;
case R4300i_SPECIAL_DMULTU: Compile_R4300i_SPECIAL_DMULTU(Section); break;
case R4300i_SPECIAL_DDIVU: Compile_R4300i_SPECIAL_DDIVU(Section); break;
case R4300i_SPECIAL_ADD: Compile_R4300i_SPECIAL_ADD(Section); break;
case R4300i_SPECIAL_ADDU: Compile_R4300i_SPECIAL_ADDU(Section); break;
case R4300i_SPECIAL_SUB: Compile_R4300i_SPECIAL_SUB(Section); break;
case R4300i_SPECIAL_SUBU: Compile_R4300i_SPECIAL_SUBU(Section); break;
case R4300i_SPECIAL_AND: Compile_R4300i_SPECIAL_AND(Section); break;
case R4300i_SPECIAL_OR: Compile_R4300i_SPECIAL_OR(Section); break;
case R4300i_SPECIAL_XOR: Compile_R4300i_SPECIAL_XOR(Section); break;
case R4300i_SPECIAL_SLT: Compile_R4300i_SPECIAL_SLT(Section); break;
case R4300i_SPECIAL_SLTU: Compile_R4300i_SPECIAL_SLTU(Section); break;
case R4300i_SPECIAL_DADD: Compile_R4300i_SPECIAL_DADD(Section); break;
case R4300i_SPECIAL_DADDU: Compile_R4300i_SPECIAL_DADDU(Section); break;
case R4300i_SPECIAL_DSLL32: Compile_R4300i_SPECIAL_DSLL32(Section); break;
case R4300i_SPECIAL_DSRA32: Compile_R4300i_SPECIAL_DSRA32(Section); break;
default:
Compile_R4300i_UnknownOpcode(Section); break;
}
break;
case R4300i_ADDI: Compile_R4300i_ADDI(Section); break;
case R4300i_ADDIU: Compile_R4300i_ADDIU(Section); break;
case R4300i_SLTI: Compile_R4300i_SLTI(Section); break;
case R4300i_SLTIU: Compile_R4300i_SLTIU(Section); break;
case R4300i_ANDI: Compile_R4300i_ANDI(Section); break;
case R4300i_ORI: Compile_R4300i_ORI(Section); break;
case R4300i_XORI: Compile_R4300i_XORI(Section); break;
case R4300i_LUI: Compile_R4300i_LUI(Section); break;
case R4300i_CP1:
switch (Opcode.rs) {
case R4300i_COP1_CF: Compile_R4300i_COP1_CF(Section); break;
case R4300i_COP1_MT: Compile_R4300i_COP1_MT(Section); break;
case R4300i_COP1_CT: Compile_R4300i_COP1_CT(Section); break;
case R4300i_COP1_MF: Compile_R4300i_COP1_MF(Section); break;
case R4300i_COP1_S:
switch (Opcode.funct) {
case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_S_ADD(Section); break;
case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_S_SUB(Section); break;
case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_S_MUL(Section); break;
case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_S_DIV(Section); break;
case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_S_ABS(Section); break;
case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_S_NEG(Section); break;
case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_S_SQRT(Section); break;
case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_S_MOV(Section); break;
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_S_CVT_D(Section); break;
case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_S_ROUND_W(Section); break;
case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_S_TRUNC_W(Section); break;
case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_S_FLOOR_W(Section); break;
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
Compile_R4300i_COP1_S_CMP(Section); break;
default:
Compile_R4300i_UnknownOpcode(Section); break;
}
break;
case R4300i_COP1_D:
switch (Opcode.funct) {
case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_D_ADD(Section); break;
case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_D_SUB(Section); break;
case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_D_MUL(Section); break;
case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_D_DIV(Section); break;
case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_D_ABS(Section); break;
case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_D_NEG(Section); break;
case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_D_SQRT(Section); break;
case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_D_MOV(Section); break;
case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_D_TRUNC_W(Section); break;
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_D_CVT_S(Section); break;
case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_D_CVT_W(Section); break;
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
Compile_R4300i_COP1_D_CMP(Section); break;
default:
Compile_R4300i_UnknownOpcode(Section); break;
}
break;
case R4300i_COP1_W:
switch (Opcode.funct) {
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_W_CVT_S(Section); break;
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_W_CVT_D(Section); break;
default:
Compile_R4300i_UnknownOpcode(Section); break;
}
break;
default:
Compile_R4300i_UnknownOpcode(Section); break;
}
break;
case R4300i_LB: Compile_R4300i_LB(Section); break;
case R4300i_LH: Compile_R4300i_LH(Section); break;
case R4300i_LW: Compile_R4300i_LW(Section); break;
case R4300i_LBU: Compile_R4300i_LBU(Section); break;
case R4300i_LHU: Compile_R4300i_LHU(Section); break;
case R4300i_SB: Compile_R4300i_SB(Section); break;
case R4300i_SH: Compile_R4300i_SH(Section); break;
case R4300i_SW: Compile_R4300i_SW(Section); break;
case R4300i_SWR: Compile_R4300i_SWR(Section); break;
case R4300i_CACHE: Compile_R4300i_CACHE(Section); break;
case R4300i_LWC1: Compile_R4300i_LWC1(Section); break;
case R4300i_LDC1: Compile_R4300i_LDC1(Section); break;
case R4300i_LD: Compile_R4300i_LD(Section); break;
case R4300i_SWC1: Compile_R4300i_SWC1(Section); break;
case R4300i_SDC1: Compile_R4300i_SDC1(Section); break;
case R4300i_SD: Compile_R4300i_SD(Section); break;
default:
Compile_R4300i_UnknownOpcode(Section); break;
}
for (count = 1; count < 10; count ++) { x86Protected(count) = FALSE; }
WriteBackRegisters(Section);
if (BlockCycleCount != 0) {
AddConstToVariable(BlockCycleCount,&CP0[9],Cop0_Name[9]);
SubConstFromVariable(BlockCycleCount,&Timers.Timer,"Timer");
}
if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1],Cop0_Name[1]); }
x86Reg = Map_TempReg(Section,x86_Any,-1,FALSE);
MoveVariableToX86reg(&JumpToLocation,"JumpToLocation",x86Reg);
MoveX86regToVariable(x86Reg,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
MoveConstToVariable(NORMAL,&NextInstruction,"NextInstruction");
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Ret();
CPU_Message("====== End of recompiled code ======");
return Block;
}
void CompileExit (DWORD TargetPC, REG_INFO ExitRegSet, int reason, int CompileNow, void (*x86Jmp)(char * Label, DWORD Value)) {
BLOCK_SECTION Section;
if (!CompileNow) {
char String[100];
if (BlockInfo.ExitCount == 0) {
BlockInfo.ExitInfo = malloc(sizeof(void *));
} else {
BlockInfo.ExitInfo = realloc(BlockInfo.ExitInfo,(BlockInfo.ExitCount + 1) * sizeof(void *));
}
sprintf(String,"Exit_%d",BlockInfo.ExitCount);
if (x86Jmp == NULL) {
#ifndef EXTERNAL_RELEASE
DisplayError("CompileExit error");
#endif
ExitThread(0);
}
x86Jmp(String,0);
BlockInfo.ExitInfo[BlockInfo.ExitCount] = malloc(sizeof(EXIT_INFO));
BlockInfo.ExitInfo[BlockInfo.ExitCount]->TargetPC = TargetPC;
BlockInfo.ExitInfo[BlockInfo.ExitCount]->ExitRegSet = ExitRegSet;
BlockInfo.ExitInfo[BlockInfo.ExitCount]->reason = reason;
BlockInfo.ExitInfo[BlockInfo.ExitCount]->NextInstruction = NextInstruction;
BlockInfo.ExitInfo[BlockInfo.ExitCount]->JumpLoc = RecompPos - 4;
BlockInfo.ExitCount += 1;
return;
}
//CPU_Message("CompileExit: %d",reason);
InitilzeSection (&Section, NULL, (DWORD)-1, 0);
memcpy(&Section.RegWorking, &ExitRegSet, sizeof(REG_INFO));
if (TargetPC != (DWORD)-1) { MoveConstToVariable(TargetPC,&PROGRAM_COUNTER,"PROGRAM_COUNTER"); }
if (ExitRegSet.CycleCount != 0) {
AddConstToVariable(ExitRegSet.CycleCount,&CP0[9],Cop0_Name[9]);
SubConstFromVariable(ExitRegSet.CycleCount,&Timers.Timer,"Timer");
}
if (ExitRegSet.RandomModifier != 0) { SubConstFromVariable(ExitRegSet.RandomModifier,&CP0[1],Cop0_Name[1]); }
WriteBackRegisters(&Section);
switch (reason) {
case Normal: case Normal_NoSysCheck:
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Section.RegWorking.RandomModifier = 0;
Section.RegWorking.CycleCount = 0;
if (reason == Normal) { CompileSystemCheck(0,(DWORD)-1,Section.RegWorking); }
#ifdef LinkBlocks
if (SelfModCheck == ModCode_ChangeMemory) {
BYTE * Jump, * Jump2;
if (TargetPC >= 0x80000000 && TargetPC < 0xC0000000) {
DWORD pAddr = TargetPC & 0x1FFFFFFF;
MoveVariableToX86reg((BYTE *)N64MEM + pAddr,"N64MEM + pAddr",x86_EAX);
Jump2 = NULL;
} else {
MoveConstToX86reg((TargetPC >> 12),x86_ECX);
MoveConstToX86reg(TargetPC,x86_EBX);
MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4);
TestX86RegToX86Reg(x86_ECX,x86_ECX);
JeLabel8("NoTlbEntry",0);
Jump2 = RecompPos - 1;
MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_EAX);
}
MoveX86RegToX86Reg(x86_EAX,x86_ECX);
AndConstToX86Reg(x86_ECX,0xFFFF0000);
CompConstToX86reg(x86_ECX,0x7C7C0000);
JneLabel8("NoCode",0);
Jump = RecompPos - 1;
AndConstToX86Reg(x86_EAX,0xFFFF);
ShiftLeftSignImmed(x86_EAX,4);
AddConstToX86Reg(x86_EAX,0xC);
MoveVariableDispToX86Reg(OrigMem,"OrigMem",x86_ECX,x86_EAX,1);
JmpDirectReg(x86_ECX);
CPU_Message(" NoCode:");
*((BYTE *)(Jump))=(BYTE)(RecompPos - Jump - 1);
if (Jump2 != NULL) {
CPU_Message(" NoTlbEntry:");
*((BYTE *)(Jump2))=(BYTE)(RecompPos - Jump2 - 1);
}
} else if (SelfModCheck == ModCode_CheckMemoryCache) {
} else if (SelfModCheck == ModCode_CheckMemory2) { // *** Add in Build 53
} else {
BYTE * Jump, * Jump2;
if (TargetPC >= 0x80000000 && TargetPC < 0x90000000) {
DWORD pAddr = TargetPC & 0x1FFFFFFF;
MoveVariableToX86reg((BYTE *)JumpTable + pAddr,"JumpTable + pAddr",x86_ECX);
Jump2 = NULL;
} else if (TargetPC >= 0x90000000 && TargetPC < 0xC0000000) {
} else {
MoveConstToX86reg((TargetPC >> 12),x86_ECX);
MoveConstToX86reg(TargetPC,x86_EBX);
MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4);
TestX86RegToX86Reg(x86_ECX,x86_ECX);
JeLabel8("NoTlbEntry",0);
Jump2 = RecompPos - 1;
AddConstToX86Reg(x86_ECX,(DWORD)JumpTable - (DWORD)N64MEM);
MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_ECX);
}
if (TargetPC < 0x90000000 || TargetPC >= 0xC0000000)
{
JecxzLabel8("NullPointer",0);
Jump = RecompPos - 1;
JmpDirectReg(x86_ECX);
CPU_Message(" NullPointer:");
*((BYTE *)(Jump))=(BYTE)(RecompPos - Jump - 1);
if (Jump2 != NULL) {
CPU_Message(" NoTlbEntry:");
*((BYTE *)(Jump2))=(BYTE)(RecompPos - Jump2 - 1);
}
}
}
Ret();
#else
Ret();
#endif
break;
case DoCPU_Action:
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Call_Direct(DoSomething,"DoSomething");
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Ret();
break;
case DoSysCall:
MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_ECX);
Call_Direct(DoSysCallException,"DoSysCallException");
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Ret();
break;
case COP1_Unuseable:
MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_ECX);
MoveConstToX86reg(1,x86_EDX);
Call_Direct(DoCopUnusableException,"DoCopUnusableException");
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Ret();
break;
case ExitResetRecompCode:
if (NextInstruction == JUMP || NextInstruction == DELAY_SLOT) {
BreakPoint();
}
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Call_Direct(ResetRecompCode, "ResetRecompCode");
Ret();
break;
case TLBReadMiss:
MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_ECX);
MoveVariableToX86reg(&TLBLoadAddress,"TLBLoadAddress",x86_EDX);
Call_Direct(DoTLBMiss,"DoTLBMiss");
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Ret();
break;
#ifndef EXTERNAL_RELEASE
default:
DisplayError("how did you want to exit on reason (%d) ???",reason);
#endif
}
}
void CompileSystemCheck (DWORD TimerModifier, DWORD TargetPC, REG_INFO RegSet) {
BLOCK_SECTION Section;
BYTE *Jump, *Jump2;
// Timer
if (TimerModifier != 0) {
SubConstFromVariable(TimerModifier,&Timers.Timer,"Timer");
} else {
CompConstToVariable(0,&Timers.Timer,"Timer");
}
JnsLabel32("Continue_From_Timer_Test",0);
Jump = RecompPos - 4;
Pushad();
if (TargetPC != (DWORD)-1) { MoveConstToVariable(TargetPC,&PROGRAM_COUNTER,"PROGRAM_COUNTER"); }
InitilzeSection (&Section, NULL, (DWORD)-1, 0);
memcpy(&Section.RegWorking, &RegSet, sizeof(REG_INFO));
WriteBackRegisters(&Section);
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Call_Direct(TimerDone,"TimerDone");
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
Popad();
//Interrupt
CompConstToVariable(0,&CPU_Action.DoSomething,"CPU_Action.DoSomething");
JeLabel32("Continue_From_Interrupt_Test",0);
Jump2 = RecompPos - 4;
CompileExit(-1,Section.RegWorking,DoCPU_Action,TRUE,NULL);
CPU_Message("");
CPU_Message(" $Continue_From_Interrupt_Test:");
SetJump32(Jump2,RecompPos);
Ret();
CPU_Message("");
CPU_Message(" $Continue_From_Timer_Test:");
SetJump32(Jump,RecompPos);
//Interrupt 2
CompConstToVariable(0,&CPU_Action.DoSomething,"CPU_Action.DoSomething");
JeLabel32("Continue_From_Interrupt_Test",0);
Jump = RecompPos - 4;
if (TargetPC != (DWORD)-1) { MoveConstToVariable(TargetPC,&PROGRAM_COUNTER,"PROGRAM_COUNTER"); }
InitilzeSection (&Section, NULL, (DWORD)-1, 0);
memcpy(&Section.RegWorking, &RegSet, sizeof(REG_INFO));
WriteBackRegisters(&Section);
CompileExit(-1,Section.RegWorking,DoCPU_Action,TRUE,NULL);
CPU_Message("");
CPU_Message(" $Continue_From_Interrupt_Test:");
SetJump32(Jump,RecompPos);
return;
}
void _fastcall CreateSectionLinkage (BLOCK_SECTION * Section) {
BLOCK_SECTION ** TargetSection[2];
DWORD * TargetPC[2], count;
InheritConstants(Section);
__try {
FillSectionInfo(Section);
} __except( r4300i_CPU_MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) {
DisplayError(GS(MSG_UNKNOWN_MEM_ACTION));
ExitThread(0);
}
if (Section->Jump.TargetPC < Section->Cont.TargetPC) {
TargetSection[0] = (BLOCK_SECTION **)&Section->JumpSection;
TargetSection[1] = (BLOCK_SECTION **)&Section->ContinueSection;
TargetPC[0] = &Section->Jump.TargetPC;
TargetPC[1] = &Section->Cont.TargetPC;
} else {
TargetSection[0] = (BLOCK_SECTION **)&Section->ContinueSection;
TargetSection[1] = (BLOCK_SECTION **)&Section->JumpSection;
TargetPC[0] = &Section->Cont.TargetPC;
TargetPC[1] = &Section->Jump.TargetPC;
}
for (count = 0; count < 2; count ++) {
if (*TargetPC[count] != (DWORD)-1 && *TargetSection[count] == NULL) {
*TargetSection[count] = ExistingSection(BlockInfo.BlockInfo.ContinueSection,*TargetPC[count],GetNewTestValue());
if (*TargetSection[count] == NULL) {
*TargetSection[count] = ExistingSection(BlockInfo.BlockInfo.JumpSection,*TargetPC[count],GetNewTestValue());
}
if (*TargetSection[count] == NULL) {
BlockInfo.NoOfSections += 1;
*TargetSection[count] = malloc(sizeof(BLOCK_SECTION));
InitilzeSection (*TargetSection[count], Section, *TargetPC[count], BlockInfo.NoOfSections);
CreateSectionLinkage(*TargetSection[count]);
} else {
AddParent(*TargetSection[count],Section);
}
}
}
}
void _fastcall DetermineLoop(BLOCK_SECTION * Section, DWORD Test, DWORD Test2, DWORD TestID) {
if (Section == NULL) { return; }
if (Section->SectionID != TestID) {
if (Section->Test2 == Test2) {
return;
}
Section->Test2 = Test2;
DetermineLoop(Section->ContinueSection,Test,Test2,TestID);
DetermineLoop(Section->JumpSection,Test,Test2,TestID);
return;
}
if (Section->Test2 == Test2) {
Section->InLoop = TRUE;
return;
}
Section->Test2 = Test2;
DetermineLoop(Section->ContinueSection,Test,Test2,TestID);
DetermineLoop(Section->JumpSection,Test,Test2,TestID);
if (Section->Test == Test) { return; }
Section->Test = Test;
if (Section->ContinueSection != NULL) {
DetermineLoop(Section->ContinueSection,Test,GetNewTestValue(),((BLOCK_SECTION *)Section->ContinueSection)->SectionID);
}
if (Section->JumpSection != NULL) {
DetermineLoop(Section->JumpSection,Test,GetNewTestValue(),((BLOCK_SECTION *)Section->JumpSection)->SectionID);
}
}
BOOL DisplaySectionInformation (BLOCK_SECTION * Section, DWORD ID, DWORD Test) {
int NoOfParents;
if (Section == NULL) { return FALSE; }
if (Section->Test == Test) { return FALSE; }
Section->Test = Test;
if (Section->SectionID != ID) {
if (DisplaySectionInformation(Section->ContinueSection,ID,Test)) { return TRUE; }
if (DisplaySectionInformation(Section->JumpSection,ID,Test)) { return TRUE; }
return FALSE;
}
CPU_Message("====== Section %d ======",Section->SectionID);
CPU_Message("Start PC: %X",Section->StartPC);
if (Section->ParentSection != NULL) {
for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++);
CPU_Message("Number of parents: %d",NoOfParents);
}
if (Section->JumpSection != NULL) {
CPU_Message("Jump Section: %d",((BLOCK_SECTION *)Section->JumpSection)->SectionID);
} else {
CPU_Message("Jump Section: None");
}
if (Section->ContinueSection != NULL) {
CPU_Message("Continue Section: %d",((BLOCK_SECTION *)Section->ContinueSection)->SectionID);
} else {
CPU_Message("Continue Section: None");
}
CPU_Message("=======================",Section->SectionID);
return TRUE;
}
BLOCK_SECTION * ExistingSection(BLOCK_SECTION * StartSection, DWORD Addr, DWORD Test) {
BLOCK_SECTION * Section;
if (StartSection == NULL) { return NULL; }
if (StartSection->StartPC == Addr) { return StartSection; }
if (StartSection->Test == Test) { return NULL; }
StartSection->Test = Test;
Section = ExistingSection(StartSection->JumpSection,Addr,Test);
if (Section != NULL) { return Section; }
Section = ExistingSection(StartSection->ContinueSection,Addr,Test);
if (Section != NULL) { return Section; }
return NULL;
}
void _fastcall FillSectionInfo(BLOCK_SECTION * Section) {
OPCODE Command;
if (Section->CompiledLocation != NULL) { return; }
Section->CompilePC = Section->StartPC;
memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO));
NextInstruction = NORMAL;
do {
if (!r4300i_LW_VAddr(Section->CompilePC, &Command.Hex)) {
DisplayError(GS(MSG_FAIL_LOAD_WORD));
ExitThread(0);
}
if (SelfModCheck == ModCode_ChangeMemory) {
if ( (Command.Hex >> 16) == 0x7C7C) {
Command.Hex = OrigMem[(Command.Hex & 0xFFFF)].OriginalValue;
}
}
switch (Command.op) {
case R4300i_SPECIAL:
switch (Command.funct) {
case R4300i_SPECIAL_SLL:
if (Command.rd == 0) { break; }
if (Section->InLoop && Command.rt == Command.rd) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt)) {
MipsRegState(Command.rd) = STATE_CONST_32;
MipsRegLo(Command.rd) = MipsRegLo(Command.rt) << Command.sa;
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_SRL:
if (Command.rd == 0) { break; }
if (Section->InLoop && Command.rt == Command.rd) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt)) {
MipsRegState(Command.rd) = STATE_CONST_32;
MipsRegLo(Command.rd) = MipsRegLo(Command.rt) >> Command.sa;
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_SRA:
if (Command.rd == 0) { break; }
if (Section->InLoop && Command.rt == Command.rd) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt)) {
MipsRegState(Command.rd) = STATE_CONST_32;
MipsRegLo(Command.rd) = MipsRegLo_S(Command.rt) >> Command.sa;
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_SLLV:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegState(Command.rd) = STATE_CONST_32;
MipsRegLo(Command.rd) = MipsRegLo(Command.rt) << (MipsRegLo(Command.rs) & 0x1F);
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_SRLV:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegState(Command.rd) = STATE_CONST_32;
MipsRegLo(Command.rd) = MipsRegLo(Command.rt) >> (MipsRegLo(Command.rs) & 0x1F);
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_SRAV:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegState(Command.rd) = STATE_CONST_32;
MipsRegLo(Command.rd) = MipsRegLo_S(Command.rt) >> (MipsRegLo(Command.rs) & 0x1F);
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_JR:
if (IsConst(Command.rs)) {
Section->Jump.TargetPC = MipsRegLo(Command.rs);
} else {
Section->Jump.TargetPC = (DWORD)-1;
}
NextInstruction = DELAY_SLOT;
break;
case R4300i_SPECIAL_JALR:
MipsRegLo(Opcode.rd) = Section->CompilePC + 8;
MipsRegState(Opcode.rd) = STATE_CONST_32;
if (IsConst(Command.rs)) {
Section->Jump.TargetPC = MipsRegLo(Command.rs);
} else {
Section->Jump.TargetPC = (DWORD)-1;
}
NextInstruction = DELAY_SLOT;
break;
case R4300i_SPECIAL_SYSCALL:
case R4300i_SPECIAL_BREAK:
NextInstruction = END_BLOCK;
Section->CompilePC -= 4;
break;
case R4300i_SPECIAL_MFHI: MipsRegState(Command.rd) = STATE_UNKNOWN; break;
case R4300i_SPECIAL_MTHI: break;
case R4300i_SPECIAL_MFLO: MipsRegState(Command.rd) = STATE_UNKNOWN; break;
case R4300i_SPECIAL_MTLO: break;
case R4300i_SPECIAL_DSLLV:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegState(Command.rd) = STATE_CONST_64;
MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg(Command.rt):(QWORD)MipsRegLo_S(Command.rt) << (MipsRegLo(Command.rs) & 0x3F);
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_DSRLV:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegState(Command.rd) = STATE_CONST_64;
MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg(Command.rt):(QWORD)MipsRegLo_S(Command.rt) >> (MipsRegLo(Command.rs) & 0x3F);
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_DSRAV:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegState(Command.rd) = STATE_CONST_64;
MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg_S(Command.rt):(_int64)MipsRegLo_S(Command.rt) >> (MipsRegLo(Command.rs) & 0x3F);
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_MULT: break;
case R4300i_SPECIAL_MULTU: break;
case R4300i_SPECIAL_DIV: break;
case R4300i_SPECIAL_DIVU: break;
case R4300i_SPECIAL_DMULT: break;
case R4300i_SPECIAL_DMULTU: break;
case R4300i_SPECIAL_DDIV: break;
case R4300i_SPECIAL_DDIVU: break;
case R4300i_SPECIAL_ADD:
case R4300i_SPECIAL_ADDU:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegLo(Command.rd) = MipsRegLo(Command.rs) + MipsRegLo(Command.rt);
MipsRegState(Command.rd) = STATE_CONST_32;
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_SUB:
case R4300i_SPECIAL_SUBU:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
MipsRegLo(Command.rd) = MipsRegLo(Command.rs) - MipsRegLo(Command.rt);
MipsRegState(Command.rd) = STATE_CONST_32;
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_AND:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
if (Is64Bit(Command.rt) && Is64Bit(Command.rs)) {
MipsReg(Command.rd) = MipsReg(Command.rt) & MipsReg(Command.rs);
MipsRegState(Command.rd) = STATE_CONST_64;
} else if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) {
if (Is64Bit(Command.rt)) {
MipsReg(Command.rd) = MipsReg(Command.rt) & MipsRegLo(Command.rs);
} else {
MipsReg(Command.rd) = MipsRegLo(Command.rt) & MipsReg(Command.rs);
}
MipsRegState(Command.rd) = ConstantsType(MipsReg(Command.rd));
} else {
MipsRegLo(Command.rd) = MipsRegLo(Command.rt) & MipsRegLo(Command.rs);
MipsRegState(Command.rd) = STATE_CONST_32;
}
} else {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
break;
case R4300i_SPECIAL_OR:
if (Command.rd == 0) { break; }
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
MipsRegState(Command.rd) = STATE_UNKNOWN;
}
if (IsConst(Command.rt) && IsConst(Command.rs)) {
if (Is64Bit(Command.rt) && Is64Bit(Command.rs)) {
MipsReg(Command.rd) = MipsReg(Command.rt) | MipsReg(Command.rs);
MipsRegState(Command.rd) = STATE_CONST_64;
} else if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) {
if (Is64Bit(Command.rt)) {
MipsReg(Command.rd) = MipsReg(Command.rt) | MipsRegLo(Command.rs);
} else {
MipsReg(Command.rd) = MipsRegLo(Command.rt) | MipsReg(Command.rs);