forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gencpu.cpp
5950 lines (5707 loc) · 174 KB
/
gencpu.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
/*
* UAE - The Un*x Amiga Emulator
*
* MC68000 emulation generator
*
* This is a fairly stupid program that generates a lot of case labels that
* can be #included in a switch statement.
* As an alternative, it can generate functions that handle specific
* MC68000 instructions, plus a prototype header file and a function pointer
* array to look up the function for an opcode.
* Error checking is bad, an illegal table68k file will cause the program to
* call abort().
* The generated code is sometimes sub-optimal, an optimizing compiler should
* take care of this.
*
* The source for the insn timings is Markt & Technik's Amiga Magazin 8/1992.
*
* Copyright 1995, 1996, 1997, 1998, 1999, 2000 Bernd Schmidt
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <ctype.h>
#include "readcpu.h"
#define BOOL_TYPE "int"
/* Define the minimal 680x0 where NV flags are not affected by xBCD instructions. */
#define xBCD_KEEPS_NV_FLAGS 4
static FILE *headerfile;
static FILE *stblfile;
static int using_prefetch, using_indirect, using_mmu;
static int using_prefetch_020, using_ce020;
static int using_exception_3;
static int using_bus_error;
static int using_ce;
static int using_tracer;
static int using_waitstates;
static int using_simple_cycles;
static int cpu_level;
static int count_read, count_write, count_cycles, count_ncycles;
static int count_cycles_ce020;
static int count_read_ea, count_write_ea, count_cycles_ea;
static const char *mmu_postfix;
static int memory_cycle_cnt;
static int did_prefetch;
static int ipl_fetched;
static int optimized_flags;
#define GF_APDI 1
#define GF_AD8R 2
#define GF_PC8R 4
#define GF_AA 7
#define GF_NOREFILL 8
#define GF_PREFETCH 16
#define GF_FC 32
#define GF_MOVE 64
#define GF_IR2IRC 128
#define GF_LRMW 256
#define GF_NOFAULTPC 512
#define GF_RMW 1024
#define GF_OPCE020 2048
/* For the current opcode, the next lower level that will have different code.
* Initialized to -1 for each opcode. If it remains unchanged, indicates we
* are done with that opcode. */
static int next_cpu_level;
static int *opcode_map;
static int *opcode_next_clev;
static int *opcode_last_postfix;
static unsigned long *counts;
static int generate_stbl;
static int mmufixupcnt;
static int mmufixupstate;
static int disp020cnt;
static bool candormw;
static bool genastore_done;
static char rmw_varname[100];
#define GENA_GETV_NO_FETCH 0
#define GENA_GETV_FETCH 1
#define GENA_GETV_FETCH_ALIGN 2
#define GENA_MOVEM_DO_INC 0
#define GENA_MOVEM_NO_INC 1
#define GENA_MOVEM_MOVE16 2
static const char *srcl, *dstl;
static const char *srcw, *dstw;
static const char *srcb, *dstb;
static const char *srcblrmw, *srcwlrmw, *srcllrmw;
static const char *dstblrmw, *dstwlrmw, *dstllrmw;
static const char *srcbrmw, *srcwrmw, *srclrmw;
static const char *dstbrmw, *dstwrmw, *dstlrmw;
static const char *prefetch_long, *prefetch_word;
static const char *srcli, *srcwi, *srcbi, *nextl, *nextw;
static const char *srcld, *dstld;
static const char *srcwd, *dstwd;
static const char *do_cycles, *disp000, *disp020, *getpc;
#define fetchmode_fea 1
#define fetchmode_cea 2
#define fetchmode_fiea 3
#define fetchmode_ciea 4
#define fetchmode_jea 5
NORETURN static void term (void)
{
printf("Abort!\n");
abort ();
}
NORETURN static void term (const char *err)
{
printf ("%s\n", err);
term ();
}
static void read_counts (void)
{
FILE *file;
unsigned int opcode, count, total;
char name[20];
int nr = 0;
memset (counts, 0, 65536 * sizeof *counts);
count = 0;
file = fopen ("frequent.68k", "r");
if (file) {
if (fscanf (file, "Total: %u\n", &total) == 0) {
abort ();
}
while (fscanf (file, "%x: %u %s\n", &opcode, &count, name) == 3) {
opcode_next_clev[nr] = 5;
opcode_last_postfix[nr] = -1;
opcode_map[nr++] = opcode;
counts[opcode] = count;
}
fclose (file);
}
if (nr == nr_cpuop_funcs)
return;
for (opcode = 0; opcode < 0x10000; opcode++) {
if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
&& counts[opcode] == 0)
{
opcode_next_clev[nr] = 5;
opcode_last_postfix[nr] = -1;
opcode_map[nr++] = opcode;
counts[opcode] = count;
}
}
if (nr != nr_cpuop_funcs)
term ();
}
static char endlabelstr[80];
static int endlabelno = 0;
static int need_endlabel;
static int genamode_cnt, genamode8r_offset[2];
static int n_braces, limit_braces;
static int m68k_pc_offset, m68k_pc_offset_old;
static int m68k_pc_total;
static int branch_inst;
static int insn_n_cycles, insn_n_cycles020;
static int ir2irc;
static int tail_ce020, total_ce020, head_in_ea_ce020;
static bool head_ce020_cycs_done, tail_ce020_done;
static int subhead_ce020;
static instr *curi_ce020;
static bool no_prefetch_ce020;
static bool got_ea_ce020;
static void fpulimit (void)
{
if (limit_braces)
return;
printf ("\n#ifdef FPUEMU\n");
limit_braces = n_braces;
n_braces = 0;
}
static void cpulimit (void)
{
printf ("#ifndef CPUEMU_68000_ONLY\n");
}
static int s_count_read, s_count_write, s_count_cycles, s_count_ncycles;
static void push_ins_cnt(void)
{
s_count_read = count_read;
s_count_write = count_write;
s_count_cycles = count_cycles;
s_count_ncycles = count_ncycles;
}
static void pop_ins_cnt(void)
{
count_read = s_count_read;
count_write = s_count_write;
count_cycles = s_count_cycles;
count_ncycles = s_count_ncycles;
}
static bool isce020(void)
{
if (!using_ce020)
return false;
if (using_ce020 >= 3)
return false;
return true;
}
static bool isprefetch020(void)
{
if (!using_prefetch_020)
return false;
if (using_prefetch_020 >= 3)
return false;
return true;
}
static void addcycles_ce020 (int cycles, const char *s)
{
if (!isce020())
return;
if (cycles > 0) {
if (s == NULL)
printf ("\t%s (%d);\n", do_cycles, cycles);
else
printf ("\t%s (%d); /* %s */\n", do_cycles, cycles, s);
}
count_cycles += cycles;
count_cycles_ce020 += cycles;
}
static void addcycles_ce020 (int cycles)
{
addcycles_ce020 (cycles, NULL);
}
static void get_prefetch_020 (void)
{
if (!isprefetch020() || no_prefetch_ce020)
return;
printf ("\tregs.irc = %s (%d);\n", prefetch_word, m68k_pc_offset);
}
static void get_prefetch_020_0 (void)
{
if (!isprefetch020() || no_prefetch_ce020)
return;
printf ("\tregs.irc = %s (0);\n", prefetch_word);
}
static void get_prefetch_020_continue(void)
{
if (!isprefetch020())
return;
if (using_ce020)
printf("\tcontinue_ce020_prefetch();\n");
else
printf ("\tcontinue_020_prefetch();\n");
}
static void returntail (bool iswrite)
{
if (!isce020()) {
if (isprefetch020()) {
if (!tail_ce020_done) {
if (!did_prefetch)
get_prefetch_020 ();
did_prefetch = 1;
tail_ce020_done = true;
}
}
return;
}
if (!tail_ce020_done) {
total_ce020 -= 2;
#if 0
if (iswrite) {
printf("\t/* C - %d = %d */\n", memory_cycle_cnt, total_ce020 - memory_cycle_cnt);
total_ce020 -= memory_cycle_cnt;
} else {
printf("\t/* C = %d */\n", total_ce020);
}
#endif
if (0 && total_ce020 <= 0) {
printf ("\t/* C was zero */\n");
total_ce020 = 1;
}
if (!did_prefetch)
get_prefetch_020 ();
if (total_ce020 > 0)
addcycles_ce020 (total_ce020);
//printf ("\tregs.irc = %s;\n", prefetch_word);
if (0 && total_ce020 >= 2) {
printf ("\top_cycles = get_cycles () - op_cycles;\n");
printf ("\top_cycles /= cpucycleunit;\n");
printf ("\tif (op_cycles < %d) {\n", total_ce020);
printf ("\t\tdo_cycles_ce020 ((%d) - op_cycles);\n", total_ce020);
printf ("\t}\n");
}
#if 0
if (tail_ce020 > 0) {
printf ("\tregs.ce020_tail = %d * cpucycleunit;\n", tail_ce020);
printf ("\tregs.ce020_tail_cycles = get_cycles () + regs.ce020_tail;\n");
} else {
printf ("\tregs.ce020_tail = 0;\n");
}
#endif
tail_ce020_done = true;
}
}
static void returncycles (const char *s, int cycles)
{
if (using_ce || using_ce020) {
#if 0
if (tail_ce020 == 0)
printf ("\tregs.ce020memcycles -= 2 * cpucycleunit; /* T=0 */ \n");
else if (tail_ce020 == 1)
printf ("\tregs.ce020memcycles -= 1 * cpucycleunit; /* T=1 */ \n");
else if (tail_ce020 == 2)
printf ("\tregs.ce020memcycles -= 0 * cpucycleunit; /* T=2 */\n");
#endif
printf ("%sreturn;\n", s);
return;
}
if (using_simple_cycles)
printf ("%sreturn %d * CYCLE_UNIT / 2 + count_cycles;\n", s, cycles);
else
printf ("%sreturn %d * CYCLE_UNIT / 2;\n", s, cycles);
}
static void addcycles_ce020 (const char *name, int head, int tail, int cycles)
{
if (!isce020())
return;
if (!head && !tail && !cycles)
return;
printf ("\t/* %s H:%d,T:%d,C:%d */\n", name, head, tail, cycles);
}
static void addcycles_ce020 (const char *name, int head, int tail, int cycles, int ophead)
{
if (!isce020())
return;
if (!head && !tail && !cycles && !ophead) {
printf ("\t/* OP zero */\n");
return;
}
count_cycles += cycles;
if (!ophead) {
addcycles_ce020 (name, head, tail, cycles);
} else if (ophead > 0) {
printf ("\t/* %s H:%d-,T:%d,C:%d */\n", name, head, tail, cycles);
} else {
printf ("\t/* %s H:%d+,T:%d,C:%d */\n", name, head, tail, cycles);
}
}
static void addcycles000_nonces(const char *s, const char *sc)
{
if (using_simple_cycles) {
printf("%scount_cycles += (%s) * CYCLE_UNIT / 2;\n", s, sc);
count_ncycles++;
}
}
static void addcycles000_nonce(const char *s, int c)
{
if (using_simple_cycles) {
printf("%scount_cycles += %d * CYCLE_UNIT / 2;\n", s, c);
count_ncycles++;
}
}
static void addcycles000_onlyce (int cycles)
{
if (using_ce) {
printf ("\t%s (%d);\n", do_cycles, cycles);
}
}
static void addcycles000 (int cycles)
{
if (using_ce) {
printf ("\t%s (%d);\n", do_cycles, cycles);
}
count_cycles += cycles;
}
static void addcycles000_2 (const char *s, int cycles)
{
if (using_ce) {
printf ("%s%s (%d);\n", s, do_cycles, cycles);
}
count_cycles += cycles;
}
static void addcycles000_3 (const char *s)
{
if (using_ce) {
printf ("%sif (cycles > 0) %s (cycles);\n", s, do_cycles);
}
count_ncycles++;
}
static int isreg (amodes mode)
{
if (mode == Dreg || mode == Areg)
return 1;
return 0;
}
static void start_brace (void)
{
n_braces++;
printf ("{");
}
static void close_brace (void)
{
assert (n_braces > 0);
n_braces--;
printf ("}");
}
static void finish_braces (void)
{
while (n_braces > 0)
close_brace ();
}
static void pop_braces (int to)
{
while (n_braces > to)
close_brace ();
}
static int bit_size (int size)
{
switch (size) {
case sz_byte: return 8;
case sz_word: return 16;
case sz_long: return 32;
default: term ();
}
return 0;
}
static const char *bit_mask (int size)
{
switch (size) {
case sz_byte: return "0xff";
case sz_word: return "0xffff";
case sz_long: return "0xffffffff";
default: term ();
}
return 0;
}
static void add_mmu040_movem (int movem)
{
if (movem != 3)
return;
printf ("\tif (mmu040_movem) {\n");
printf ("\t\tsrca = mmu040_movem_ea;\n");
printf ("\t} else\n");
start_brace ();
}
static void gen_nextilong2 (const char *type, const char *name, int flags, int movem)
{
int r = m68k_pc_offset;
m68k_pc_offset += 4;
printf ("\t%s %s;\n", type, name);
add_mmu040_movem (movem);
if (using_ce020) {
if (flags & GF_NOREFILL)
printf("\t%s = %s (%d);\n", name, prefetch_long, r);
else
printf("\t%s = %s (%d);\n", name, prefetch_long, r);
count_read += 2;
} else if (using_ce) {
/* we must do this because execution order of (something | something2) is not defined */
if (flags & GF_NOREFILL) {
printf ("\t%s = %s (%d) << 16;\n", name, prefetch_word, r + 2);
count_read++;
printf ("\t%s |= regs.irc;\n", name);
} else {
printf ("\t%s = %s (%d) << 16;\n", name, prefetch_word, r + 2);
count_read++;
printf ("\t%s |= %s (%d);\n", name, prefetch_word, r + 4);
count_read++;
}
} else {
if (using_prefetch) {
if (flags & GF_NOREFILL) {
printf ("\t%s = %s (%d) << 16;\n", name, prefetch_word, r + 2);
count_read++;
printf ("\t%s |= regs.irc;\n", name);
insn_n_cycles += 4;
} else {
printf ("\t%s = %s (%d) << 16;\n", name, prefetch_word, r + 2);
count_read += 2;
printf ("\t%s |= %s (%d);\n", name, prefetch_word, r + 4);
insn_n_cycles += 8;
}
} else {
insn_n_cycles += 8;
printf ("\t%s = %s (%d);\n", name, prefetch_long, r);
}
}
}
static void gen_nextilong (const char *type, const char *name, int flags)
{
gen_nextilong2 (type, name, flags, 0);
}
static const char *gen_nextiword (int flags)
{
static char buffer[80];
int r = m68k_pc_offset;
m68k_pc_offset += 2;
if (using_ce020) {
if (flags & GF_NOREFILL)
sprintf(buffer, "%s (%d)", prefetch_word, r);
else
sprintf(buffer, "%s (%d)", prefetch_word, r);
count_read++;
} else if (using_ce) {
if (flags & GF_NOREFILL) {
strcpy (buffer, "regs.irc");
} else {
sprintf (buffer, "%s (%d)", prefetch_word, r + 2);
count_read++;
}
} else {
if (using_prefetch) {
if (flags & GF_NOREFILL) {
strcpy (buffer, "regs.irc");
} else {
sprintf (buffer, "%s (%d)", prefetch_word, r + 2);
count_read++;
insn_n_cycles += 4;
}
} else {
sprintf (buffer, "%s (%d)", prefetch_word, r);
insn_n_cycles += 4;
}
}
return buffer;
}
static const char *gen_nextibyte (int flags)
{
static char buffer[80];
int r = m68k_pc_offset;
m68k_pc_offset += 2;
if (using_ce020 || using_prefetch_020) {
if (flags & GF_NOREFILL)
sprintf(buffer, "(uae_u8)%s (%d)", prefetch_word, r);
else
sprintf(buffer, "(uae_u8)%s (%d)", prefetch_word, r);
count_read++;
} else if (using_ce) {
if (flags & GF_NOREFILL) {
strcpy (buffer, "(uae_u8)regs.irc");
} else {
sprintf (buffer, "(uae_u8)%s (%d)", prefetch_word, r + 2);
count_read++;
}
} else {
insn_n_cycles += 4;
if (using_prefetch) {
if (flags & GF_NOREFILL) {
strcpy (buffer, "(uae_u8)regs.irc");
} else {
sprintf (buffer, "(uae_u8)%s (%d)", prefetch_word, r + 2);
insn_n_cycles += 4;
count_read++;
}
} else {
sprintf (buffer, "%s (%d)", srcbi, r);
insn_n_cycles += 4;
}
}
return buffer;
}
static void makefromsr (void)
{
printf ("\tMakeFromSR();\n");
if (using_ce || isce020())
printf ("\tregs.ipl_pin = intlev ();\n");
}
static void check_ipl (void)
{
if (ipl_fetched)
return;
if (using_ce || isce020())
printf ("\tipl_fetch ();\n");
ipl_fetched = 1;
}
static void single_check_ipl(void)
{
check_ipl();
ipl_fetched = 2;
}
/* this is not true, it seems to be microcode controller */
/* Apparently interrupt state is sampled
* during any memory access. Because we don't
* know if there are future memory accesses,
* we'll check each memory access after prefetch
* and recheck interrupt state again.
*/
static void check_ipl_again (void)
{
if (ipl_fetched != 1)
return;
if (using_ce)
printf ("\tipl_fetch ();\n");
}
static void irc2ir (bool dozero)
{
if (!using_prefetch)
return;
if (ir2irc)
return;
ir2irc = 1;
printf ("\tregs.ir = regs.irc;\n");
if (dozero)
printf ("\tregs.irc = 0;\n");
check_ipl ();
}
static void irc2ir (void)
{
irc2ir (false);
}
static void fill_prefetch_2 (void)
{
if (!using_prefetch)
return;
printf ("\t%s (%d);\n", prefetch_word, m68k_pc_offset + 2);
did_prefetch = 1;
ir2irc = 0;
count_read++;
insn_n_cycles += 4;
}
static void fill_prefetch_1 (int o)
{
if (using_prefetch) {
printf ("\t%s (%d);\n", prefetch_word, o);
did_prefetch = 1;
ir2irc = 0;
count_read++;
insn_n_cycles += 4;
}
}
static void fill_prefetch_full (void)
{
if (using_prefetch) {
fill_prefetch_1 (0);
irc2ir ();
fill_prefetch_1 (2);
} else if (isprefetch020()) {
did_prefetch = 2;
total_ce020 -= 4;
returntail (false);
if (cpu_level >= 3)
printf ("\tfill_prefetch_030 ();\n");
else if (cpu_level == 2)
printf ("\tfill_prefetch_020 ();\n");
}
}
// 68000 and 68010 only
static void fill_prefetch_full_000 (void)
{
if (!using_prefetch)
return;
fill_prefetch_full ();
}
// 68020+
static void fill_prefetch_full_020 (void)
{
if (!using_prefetch_020)
return;
fill_prefetch_full ();
}
static void fill_prefetch_0 (void)
{
if (!using_prefetch)
return;
printf ("\t%s (0);\n", prefetch_word);
did_prefetch = 1;
ir2irc = 0;
count_read++;
insn_n_cycles += 4;
}
static void dummy_prefetch (void)
{
int o = m68k_pc_offset + 2;
if (!using_prefetch)
return;
printf ("\t%s (%d);\n", srcwi, o);
count_read++;
insn_n_cycles += 4;
}
static void fill_prefetch_next_1 (void)
{
irc2ir ();
fill_prefetch_1 (m68k_pc_offset + 2);
}
static void fill_prefetch_next (void)
{
if (using_prefetch) {
fill_prefetch_next_1 ();
}
// if (using_prefetch_020) {
// printf ("\t%s (%d);\n", prefetch_word, m68k_pc_offset);
// did_prefetch = 1;
// }
}
static void fill_prefetch_finish (void)
{
if (did_prefetch)
return;
if (using_prefetch) {
fill_prefetch_1 (m68k_pc_offset);
}
if (using_prefetch_020) {
did_prefetch = 1;
}
}
static void setpc (const char *format, ...)
{
va_list parms;
char buffer[1000];
va_start (parms, format);
_vsnprintf (buffer, 1000 - 1, format, parms);
va_end (parms);
if (using_mmu || using_prefetch || using_prefetch_020)
printf ("\tm68k_setpci (%s);\n", buffer);
else
printf ("\tm68k_setpc (%s);\n", buffer);
}
static void incpc (const char *format, ...)
{
va_list parms;
char buffer[1000];
va_start (parms, format);
_vsnprintf (buffer, 1000 - 1, format, parms);
va_end (parms);
if (using_mmu || using_prefetch || using_prefetch_020)
printf ("\tm68k_incpci (%s);\n", buffer);
else
printf ("\tm68k_incpc (%s);\n", buffer);
}
static void sync_m68k_pc (void)
{
m68k_pc_offset_old = m68k_pc_offset;
if (m68k_pc_offset == 0)
return;
incpc ("%d", m68k_pc_offset);
m68k_pc_total += m68k_pc_offset;
m68k_pc_offset = 0;
}
static void clear_m68k_offset(void)
{
m68k_pc_total += m68k_pc_offset;
m68k_pc_offset = 0;
}
static void sync_m68k_pc_noreset (void)
{
sync_m68k_pc ();
m68k_pc_offset = m68k_pc_offset_old;
}
static void addmmufixup (const char *reg)
{
if (!using_mmu)
return;
if (using_mmu == 68040 && (mmufixupstate || mmufixupcnt > 0))
return;
printf ("\tmmufixup[%d].reg = %s;\n", mmufixupcnt, reg);
printf ("\tmmufixup[%d].value = m68k_areg (regs, %s);\n", mmufixupcnt, reg);
mmufixupstate |= 1 << mmufixupcnt;
mmufixupcnt++;
}
static void clearmmufixup (int cnt)
{
if (mmufixupstate & (1 << cnt)) {
printf ("\tmmufixup[%d].reg = -1;\n", cnt);
mmufixupstate &= ~(1 << cnt);
}
}
static void gen_set_fault_pc (void)
{
if (using_mmu != 68040)
return;
sync_m68k_pc ();
printf ("\tregs.instruction_pc = %s;\n", getpc);
printf ("\tmmu_restart = false;\n");
m68k_pc_offset = 0;
clearmmufixup (0);
}
static void syncmovepc (int getv, int flags)
{
#if 0
if (!(flags & GF_MOVE))
return;
if (getv == 1) {
sync_m68k_pc ();
//fill_prefetch_next ();
}
#endif
}
static void head_cycs (int h)
{
if (head_ce020_cycs_done)
return;
if (h < 0)
return;
//printf ("\tdo_sync_tail (%d);\n", h);
//printf ("\tdo_head_cycles_ce020 (%d);\n", h);
head_ce020_cycs_done = true;
tail_ce020 = -1;
}
static void add_head_cycs (int h)
{
if (!isce020())
return;
head_ce020_cycs_done = false;
head_cycs (h);
}
static void addopcycles_ce20 (int h, int t, int c, int subhead)
{
head_cycs (h);
//c = 0;
#if 0
if (tail_ce020 == 1)
printf ("\tregs.ce020memcycles -= 1 * cpucycleunit; /* T=1 */ \n");
else if (tail_ce020 == 2)
printf ("\tregs.ce020memcycles -= 2 * cpucycleunit; /* T=2 */\n");
#endif
if (1 && !subhead && (h > 0 || t > 0 || c > 0) && got_ea_ce020) {
if (!did_prefetch) {
get_prefetch_020 ();
did_prefetch = 1;
}
if (1) {
if (h > 0) {
printf ("\tif (regs.ce020memcycles > %d * cpucycleunit)\n", h);
printf ("\t\tregs.ce020memcycles = %d * cpucycleunit;\n", h);
} else {
printf ("\tregs.ce020memcycles = 0;\n");
}
}
}
#if 0
if (tail_ce020 >= 0 && h >= 0 && head_in_ea_ce020 == 0) {
int largest = tail_ce020 > h ? tail_ce020: h;
if (tail_ce020 != h) {
//printf ("\tdo_cycles_ce020 (%d - %d);\n", tail_ce020 > h ? tail_ce020 : h, tail_ce020 > h ? h : tail_ce020);
//printf ("\tdo_cycles_ce020 (%d - %d);\n", tail_ce020 > h ? tail_ce020 : h, tail_ce020 > h ? h : tail_ce020);
if (h) {
printf ("\tregs.ce020memcycles -= %d * cpucycleunit;\n", h);
printf ("\tif (regs.ce020memcycles < 0) {\n");
//printf ("\t\tx_do_cycles (-regs.ce020memcycles);\n");
printf ("\t\tregs.ce020memcycles = 0;\n");
printf ("\t}\n");
} else {
printf ("\tregs.ce020memcycles = 0;\n");
}
//printf ("\tregs.ce020memcycles = 0;\n");
#if 0
if (tail_ce020)
printf ("\tregs.ce020_tail = get_cycles () - regs.ce020_tail;\n");
else
printf ("\tregs.ce020_tail = 0;\n");
printf ("\tif (regs.ce020_tail < %d * cpucycleunit)\n", largest);
printf ("\t\tx_do_cycles (%d * cpucycleunit - regs.ce020_tail);\n", largest);
#endif
} else if (h) {
printf ("\t/* ea tail == op head (%d) */\n", h);
printf ("\tregs.ce020memcycles -= %d * cpucycleunit;\n", h);
printf ("\tif (regs.ce020memcycles < 0) {\n");
//printf ("\t\tx_do_cycles (-regs.ce020memcycles);\n");
printf ("\t\tregs.ce020memcycles = 0;\n");
printf ("\t}\n");
}
}
#endif
if (h < 0)
h = 0;
//c = 0;
// c = internal cycles needed after head cycles and before tail cycles. Not total cycles.
addcycles_ce020 ("op", h, t, c - h - t, -subhead);
//printf ("\tregs.irc = get_word_ce020_prefetch (%d);\n", m68k_pc_offset);
#if 0
if (c - h - t > 0) {
printf ("\t%s (%d);\n", do_cycles, c - h - t);
count_cycles_ce020 += c;
count_cycles += c;
}
#endif
//printf ("\tregs.ce020_tail = 0;\n");
total_ce020 = c;
tail_ce020 = t;
// if (total_ce020 >= 2)
// printf ("\tint op_cycles = get_cycles ();\n");
}
static void addop_ce020 (instr *curi, int subhead)
{
if (!isce020())
return;
int h = curi->head;
int t = curi->tail;
int c = curi->clocks;
#if 0
if ((((curi->sduse & 2) && !isreg (curi->smode)) || (((curi->sduse >> 4) & 2) && !isreg (curi->dmode))) && using_waitstates) {
t += using_waitstates;
c += using_waitstates;
}
#endif
addopcycles_ce20 (h, t, c, -subhead);
}
static void addcycles_ea_ce020 (const char *ea, int h, int t, int c, int oph)
{
head_cycs (h + oph);
// if (!h && !h && !c && !oph)
// return;
c = c - h - t;
//c = 0;
if (!oph) {
printf ("\t/* ea H:%d,T:%d,C:%d %s */\n", h, t, c, ea);
} else {
if (oph && t)
term ("Both op head and tail can't be non-zero");
if (oph > 0) {
printf ("\t/* ea H:%d+%d=%d,T:%d,C:%d %s */\n", h, oph, h + oph, t, c, ea);
h += oph;
} else {
printf ("\t/* ea H:%d-%d=%d,T:%d,C:%d %s */\n", h, -oph, h + oph, t, c, ea);
h += oph;
}
}
if (h) {
printf ("\tif (regs.ce020memcycles > %d * cpucycleunit)\n", h);
printf ("\t\tregs.ce020memcycles = %d * cpucycleunit;\n", h);
} else {