forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gencpu.cpp
9349 lines (8928 loc) · 258 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.
* 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
*/
#define CPU_TESTER 0
#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_N_FLAG 4
#define xBCD_KEEPS_V_FLAG 2
// if set: 68030 MMU and instruction's last memory access is write and it causes fault:
// instruction is considered completed, generate short bus error stack frame.
#define MMU68030_LAST_WRITE 1
static FILE *headerfile;
static FILE *stblfile;
// optional settings
static int using_always_dynamic_cycles = 1;
static int using_bus_error = 1;
static int using_prefetch, using_indirect, using_mmu;
static int using_prefetch_020, using_ce020;
static int using_exception_3;
static int using_ce;
static int using_tracer;
static int using_waitstates;
static int using_simple_cycles;
static int using_debugmem;
static int using_test;
static int need_special_fixup;
static int cpu_level, cpu_generic;
static int count_readp;
static int count_readw, count_readl;
static int count_writew, count_writel;
static int 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, *xfc_postfix;
static int memory_cycle_cnt;
static int did_prefetch;
static int ipl_fetched;
static int opcode_nextcopy;
static int do_always_dynamic_cycles;
static int optimized_flags;
#define GF_APDI 0x00001
#define GF_AD8R 0x00002
#define GF_PC8R 0x00004
#define GF_AA 0x00007
#define GF_NOREFILL 0x00008
#define GF_PREFETCH 0x00010
#define GF_FC 0x00020
#define GF_MOVE 0x00040
#define GF_IR2IRC 0x00080
#define GF_LRMW 0x00100
#define GF_NOFAULTPC 0x00200
#define GF_RMW 0x00400
#define GF_OPCE020 0x00800
#define GF_REVERSE 0x01000
#define GF_REVERSE2 0x02000
#define GF_SECONDWORDSETFLAGS 0x04000
#define GF_SECONDEA 0x08000
#define GF_NOFETCH 0x10000 // 68010
#define GF_CLR68010 0x20000 // 68010
#define GF_NOEXC3 0x40000
#define GF_EXC3 0x80000
typedef enum
{
flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_z, flag_zn,
flag_av, flag_sv
}
flagtypes;
/* 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];
static struct instr *g_instr;
static char g_srcname[100];
static int loopmode;
static int loopmodeextra;
static int loopmode_set;
#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, *prefetch_opcode;
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
static int brace_level;
static char outbuffer[30000];
static int last_access_offset;
static void out(const char *format, ...)
{
char outbuf[1000];
va_list parms;
va_start(parms, format);
_vsnprintf(outbuf, sizeof(outbuf) - 1, format, parms);
outbuf[sizeof(outbuf) - 1] = 0;
va_end(parms);
char *p = outbuf;
while (*p) {
char v = *p;
if (v == '\t') {
memmove(p, p + 1, strlen(p + 1) + 1);
} else {
p++;
}
}
p = outbuf;
for (;;) {
char *pe = p;
int islf = 0;
while (*pe != 0 && *pe != '\n') {
pe++;
}
if (*pe == '\n') {
islf = 1;
*pe = 0;
}
char outbuf2[1000];
strcpy(outbuf2, p);
outbuf2[pe - p] = 0;
if (outbuf2[0]) {
char *ps = outbuf2;
while (*ps) {
char v = *ps;
if (v == '}') {
brace_level--;
}
ps++;
}
for (int i = 0; i < brace_level; i++) {
strcat(outbuffer, "\t");
}
strcat(outbuffer, outbuf2);
ps = outbuf2;
while (*ps) {
char v = *ps;
if (v == '{') {
brace_level++;
}
ps++;
}
}
if (islf) {
strcat(outbuffer, "\n");
pe++;
}
if (*pe == 0)
break;
p = pe;
}
}
static void insertstring(const char *s, int offset)
{
int len = strlen(s);
memmove(outbuffer + offset + len + brace_level, outbuffer + offset, strlen(outbuffer + offset) + 1);
for (int i = 0; i < brace_level; i++) {
outbuffer[offset + i] = '\t';
}
memcpy(outbuffer + offset + brace_level, s, len);
}
static void set_last_access(void)
{
last_access_offset = strlen(outbuffer);
}
NORETURN static void term (void)
{
out("Abort!\n");
abort();
}
NORETURN static void term (const char *err)
{
out("%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 int genamode_cnt, genamode8r_offset[2];
static int set_fpulimit;
static int m68k_pc_offset, m68k_pc_offset_old;
static int m68k_pc_total;
static int exception_pc_offset;
static int branch_inst;
static int ir2irc;
static int insn_n_cycles;
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;
// 68010-40 needs different implementation than 68060
static bool next_level_060_to_040(void)
{
if (cpu_level >= 5) {
if (next_cpu_level < 5) {
next_cpu_level = 5 - 1;
return true;
}
}
return false;
}
// 68010-30 needs different implementation than 68040/060
static bool next_level_040_to_030(void)
{
if (cpu_level >= 4) {
if (next_cpu_level < 4) {
next_cpu_level = 4 - 1;
return true;
}
}
return false;
}
// 68000-010 needs different implementation than 68020+
static bool next_level_020_to_010(void)
{
if (cpu_level >= 2) {
if (next_cpu_level < 2) {
next_cpu_level = 2 - 1;
return true;
}
}
return false;
}
// 68000 <> 68010
static bool next_level_000(void)
{
if (next_cpu_level < 0) {
next_cpu_level = 0;
}
return false;
}
static void fpulimit (void)
{
out("\n#ifdef FPUEMU\n");
set_fpulimit = 1;
}
static int s_count_readw, s_count_readl;
static int s_count_writew, s_count_writel;
static int s_count_readp;
static int s_count_cycles, s_count_ncycles, s_insn_cycles;
static void push_ins_cnt(void)
{
s_count_readw = count_readw;
s_count_readl = count_readl;
s_count_writew = count_writew;
s_count_writel = count_writel;
s_count_readp = count_readp;
s_count_cycles = count_cycles;
s_count_ncycles = count_ncycles;
s_insn_cycles = insn_n_cycles;
}
static void pop_ins_cnt(void)
{
count_readw = s_count_readw;
count_readl = s_count_readl;
count_writew = s_count_writew;
count_writel = s_count_writel;
count_readp = s_count_readp;
count_cycles = s_count_cycles;
count_ncycles = s_count_ncycles;
insn_n_cycles = s_insn_cycles;
}
static bool needmmufixup(void)
{
if (need_special_fixup) {
// need to restore -(an)/(an)+ if unimplemented
switch (g_instr->mnemo)
{
case i_MULL:
case i_DIVL:
case i_CAS:
return true;
}
}
if (!using_mmu)
return false;
if (using_mmu == 68040 && (mmufixupstate || mmufixupcnt > 0))
return false;
return true;
}
static void addmmufixup(const char *reg, int size, int mode)
{
if (!needmmufixup())
return;
int flags = 0;
if (cpu_level == 3 && size >= 0 && mode >= 0) {
if (mode == Aipi) {
flags |= 0x100;
} else if (mode == Apdi) {
flags |= 0x200;
}
if (size == sz_long) {
flags |= 0x800;
} else if (size == sz_word) {
flags |= 0x400;
}
}
out("mmufixup[%d].reg = %s | 0x%x;\n", mmufixupcnt, reg, flags);
out("mmufixup[%d].value = m68k_areg(regs, %s);\n", mmufixupcnt, reg);
mmufixupstate |= 1 << mmufixupcnt;
mmufixupcnt++;
}
static void clearmmufixup(int cnt, int noclear)
{
if (mmufixupstate & (1 << cnt)) {
out("mmufixup[%d].reg = -1;\n", cnt);
if (!noclear)
mmufixupstate &= ~(1 << cnt);
}
}
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 0
if (cycles > 0) {
if (s == NULL)
out("%s(%d);\n", do_cycles, cycles);
else
out("%s(%d); /* %s */\n", do_cycles, cycles, s);
}
#endif
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;
out("regs.irc = %s(%d);\n", prefetch_opcode, m68k_pc_offset);
}
static void get_prefetch_020_continue(void)
{
if (!isprefetch020())
return;
if (using_ce020) {
if (using_ce020 > 1)
out("continue_ce030_prefetch();\n");
else
out("continue_ce020_prefetch();\n");
} else {
if (using_prefetch_020 > 1)
out("continue_030_prefetch();\n");
else
out("continue_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) {
out("/* C - %d = %d */\n", memory_cycle_cnt, total_ce020 - memory_cycle_cnt);
total_ce020 -= memory_cycle_cnt;
} else {
out("/* C = %d */\n", total_ce020);
}
#endif
if (0 && total_ce020 <= 0) {
out("/* C was zero */\n");
total_ce020 = 1;
}
if (!did_prefetch)
get_prefetch_020();
if (total_ce020 > 0)
addcycles_ce020 (total_ce020);
//out("regs.irc = %s;\n", prefetch_opcode);
if (0 && total_ce020 >= 2) {
out("op_cycles = get_cycles() - op_cycles;\n");
out("op_cycles /= cpucycleunit;\n");
out("if (op_cycles < %d) {\n", total_ce020);
out("do_cycles_ce020((%d) - op_cycles);\n", total_ce020);
out("}\n");
}
#if 0
if (tail_ce020 > 0) {
out("regs.ce020_tail = %d * cpucycleunit;\n", tail_ce020);
out("regs.ce020_tail_cycles = get_cycles() + regs.ce020_tail;\n");
} else {
out("regs.ce020_tail = 0;\n");
}
#endif
tail_ce020_done = true;
}
}
static void returncycles(int cycles)
{
if (using_ce || using_ce020) {
#if 0
if (tail_ce020 == 0)
out("regs.ce020memcycles -= 2 * cpucycleunit; /* T=0 */ \n");
else if (tail_ce020 == 1)
out("regs.ce020memcycles -= 1 * cpucycleunit; /* T=1 */ \n");
else if (tail_ce020 == 2)
out("regs.ce020memcycles -= 0 * cpucycleunit; /* T=2 */\n");
#endif
out("return;\n");
return;
}
if (do_always_dynamic_cycles) {
int total = count_readl + count_readw + count_writel + count_writew - count_readp;
if (!total)
total++;
out("return (%d * CYCLE_UNIT / 2 + count_cycles) | (((%d * 4 * CYCLE_UNIT / 2 + count_cycles) * 3) << 16);\n",
cycles, total);
} else if (using_simple_cycles) {
out("return %d * CYCLE_UNIT / 2 + count_cycles;\n", cycles);
} else {
out("return %d * CYCLE_UNIT / 2;\n", cycles);
}
}
static void write_return_cycles_none(void)
{
if (using_ce || using_ce020) {
out("return;\n");
} else {
out("return 0;\n");
}
}
static void write_return_cycles2(int end, int no4)
{
if (end <= 0) {
clearmmufixup(0, 1);
clearmmufixup(1, 1);
}
if (using_ce || using_prefetch) {
if (end < 0) {
if (using_ce) {
out("return;\n");
} else {
out("return 0;\n");
}
} else {
int cc = count_cycles;
if (count_readw + count_writew + count_readl + count_writel + cc == 0 && !no4)
cc = 4;
returncycles((count_readw + count_writew) * 4 + (count_readl + count_writel) * 8 + cc);
if (end) {
out("}\n");
out("/* %d%s (%d/%d)",
(count_readw + count_writew) * 4 + (count_readl + count_writel) * 8 + cc, count_ncycles ? "+" : "",
count_readw + count_readl * 2, count_writew + count_writel * 2);
out(" */\n");
}
}
} else {
if (end < 0) {
if (using_ce020) {
out("return;\n");
} else {
out("return 0;\n");
}
} else {
if (!using_prefetch && !using_prefetch_020) {
returncycles((count_readw + count_writew) * 4 + (count_readl + count_writel) * 8 + insn_n_cycles);
} else {
returncycles((count_readw + count_writew) * 4 + (count_readl + count_writel) * 8 + count_cycles);
}
if (end) {
out("}\n");
}
}
}
}
static void write_return_cycles(int end)
{
write_return_cycles2(end, 0);
}
static void write_return_cycles_noadd(int end)
{
write_return_cycles2(end, 1);
}
static void addcycles_ce020 (const char *name, int head, int tail, int cycles)
{
if (!isce020())
return;
if (!head && !tail && !cycles)
return;
out("/* %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) {
out("/* OP zero */\n");
return;
}
count_cycles += cycles;
if (!ophead) {
addcycles_ce020 (name, head, tail, cycles);
} else if (ophead > 0) {
out("/* %s H:%d-,T:%d,C:%d */\n", name, head, tail, cycles);
} else {
out("/* %s H:%d+,T:%d,C:%d */\n", name, head, tail, cycles);
}
}
static void addcycles000_nonces(const char *sc)
{
if (using_simple_cycles || do_always_dynamic_cycles) {
out("count_cycles += (%s) * CYCLE_UNIT / 2;\n", sc);
count_ncycles++;
}
}
static void addcycles000_nonce(int c)
{
if (using_simple_cycles || do_always_dynamic_cycles) {
out("count_cycles += %d * CYCLE_UNIT / 2;\n", c);
count_ncycles++;
}
}
static void addcycles000_onlyce (int cycles)
{
if (using_ce) {
out("%s(%d);\n", do_cycles, cycles);
}
}
static void addcycles000(int cycles)
{
if (using_ce) {
out("%s(%d);\n", do_cycles, cycles);
}
count_cycles += cycles;
insn_n_cycles += cycles;
}
static void addcycles000_2(int cycles)
{
if (using_ce) {
out("%s(%d);\n", do_cycles, cycles);
}
count_cycles += cycles;
insn_n_cycles += cycles;
}
static void addcycles000_3(void)
{
if (using_ce) {
out("if (cycles > 0) %s(cycles);\n", do_cycles);
}
count_ncycles++;
}
static int isreg (amodes mode)
{
if (mode == Dreg || mode == Areg)
return 1;
return 0;
}
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 int mmu040_movem;
static void start_mmu040_movem(int movem)
{
if (abs(movem) != 3)
return;
out("if (mmu040_movem) {\n");
out("srca = mmu040_movem_ea;\n");
out("} else {\n");
mmu040_movem = 1;
}
static void end_mmu040_movem(void)
{
if (!mmu040_movem)
return;
out("}\n");
mmu040_movem = 0;
}
static char bus_error_text[200];
static int bus_error_specials;
static int bus_error_cycles;
// 1 = first access, 2 = long second access only
static char bus_error_code[1000], bus_error_code2[1000];
static void do_instruction_buserror(void)
{
if (!using_bus_error || using_mmu)
return;
if (bus_error_text[0]) {
out("if(hardware_bus_error) {\n");
if (bus_error_code[0])
out("%s", bus_error_code);
out("%s", bus_error_text);
write_return_cycles(0);
out("}\n");
}
bus_error_code[0] = 0;
bus_error_specials = 0;
}
static void check_bus_error_ins(int offset)
{
const char *opcode;
if (bus_error_specials) {
opcode = "0";
} else {
opcode = "opcode";
}
sprintf(bus_error_text, "exception2_fetch(%s, %d);\n", opcode, offset);
}
static void check_bus_error_ins_opcode(int offset)
{
const char *opcode;
if (bus_error_specials) {
opcode = "0";
} else {
opcode = "opcode";
}
sprintf(bus_error_text, "exception2_fetch_opcode(%s, %d);\n", opcode, offset);
}
static void check_prefetch_bus_error(int offset, int secondprefetchmode)
{
if (!using_bus_error || using_mmu)
return;
if (offset < 0) {
if (offset == -1)
offset = 0;
else
offset = 2;
// full prefetch: opcode field is zero
if ((offset == 2 && !secondprefetchmode) || secondprefetchmode > 0) {
bus_error_specials = 1;
}
}
check_bus_error_ins_opcode(offset);
do_instruction_buserror();
}
static void check_prefetch_buserror(int offset)
{
check_bus_error_ins(offset);
do_instruction_buserror();
}
static void gen_nextilong2 (const char *type, const char *name, int flags, int movem)
{
int r = m68k_pc_offset;
m68k_pc_offset += 4;
out("%s %s;\n", type, name);
start_mmu040_movem(movem);
if (using_ce020) {
if (flags & GF_NOREFILL)
out("%s = %s(%d);\n", name, prefetch_long, r);
else
out("%s = %s(%d);\n", name, prefetch_long, r);
count_readl++;
} else if (using_ce) {
/* we must do this because execution order of (something | something2) is not defined */
if (flags & GF_NOREFILL) {
set_last_access();
out("%s = %s(%d) << 16;\n", name, prefetch_word, r + 2);
count_readw++;
out("%s |= regs.irc;\n", name);
check_bus_error_ins(r + 2);
do_instruction_buserror();
strcpy(bus_error_code, bus_error_code2);
bus_error_code2[0] = 0;
bus_error_text[0] = 0;
} else {
out("%s = %s(%d) << 16;\n", name, prefetch_word, r + 2);
count_readw++;
check_bus_error_ins(r + 2);
do_instruction_buserror();
strcpy(bus_error_code, bus_error_code2);
bus_error_code2[0] = 0;
set_last_access();
out("%s |= %s(%d);\n", name, prefetch_word, r + 4);
count_readw++;
check_bus_error_ins(r + 4);
}
} else if (using_prefetch) {
if (flags & GF_NOREFILL) {
set_last_access();
out("%s = %s(%d) << 16;\n", name, prefetch_word, r + 2);
count_readw++;
out("%s |= regs.irc;\n", name);
check_bus_error_ins(r + 2);
do_instruction_buserror();
strcpy(bus_error_code, bus_error_code2);
bus_error_code2[0] = 0;
bus_error_text[0] = 0;
} else {
out("%s = %s(%d) << 16;\n", name, prefetch_word, r + 2);
count_readw++;
check_bus_error_ins(r + 2);
do_instruction_buserror();
strcpy(bus_error_code, bus_error_code2);
bus_error_code2[0] = 0;
set_last_access();
out("%s |= %s(%d);\n", name, prefetch_word, r + 4);
count_readw++;
check_bus_error_ins(r + 4);
}
} else {
if (flags & GF_NOREFILL) {
count_readw++;
count_readp++;
} else {
count_readl++;
count_readp++;
}
out("%s = %s(%d);\n", name, prefetch_long, r);
}
}
static void gen_nextilong (const char *type, const char *name, int flags)
{
bus_error_text[0] = 0;
bus_error_specials = 0;
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;
bus_error_text[0] = 0;
bus_error_specials = 0;
if (using_ce020) {
if (flags & GF_NOREFILL)
sprintf(buffer, "%s(%d)", prefetch_word, r);
else
sprintf(buffer, "%s(%d)", prefetch_word, r);
count_readw++;
} else if (using_ce) {
if (flags & GF_NOREFILL) {
strcpy(buffer, "regs.irc");
} else {
set_last_access();
sprintf(buffer, "%s(%d)", prefetch_word, r + 2);
count_readw++;
check_bus_error_ins(r + 2);
}
} else if (using_prefetch) {
if (flags & GF_NOREFILL) {
strcpy(buffer, "regs.irc");
} else {
set_last_access();
sprintf(buffer, "%s(%d)", prefetch_word, r + 2);
count_readw++;
check_bus_error_ins(r + 2);
}
} else {
sprintf(buffer, "%s(%d)", prefetch_word, r);
if (!(flags & GF_NOREFILL)) {
count_readw++;
count_readp++;
check_bus_error_ins(r);
}
}
return buffer;
}
static const char *gen_nextibyte (int flags)
{
static char buffer[80];
int r = m68k_pc_offset;
m68k_pc_offset += 2;
bus_error_text[0] = 0;
bus_error_specials = 0;
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_readw++;
} else if (using_ce) {
if (flags & GF_NOREFILL) {
strcpy(buffer, "(uae_u8)regs.irc");
} else {
set_last_access();
sprintf(buffer, "(uae_u8)%s(%d)", prefetch_word, r + 2);
count_readw++;
check_bus_error_ins(r + 2);
}
} else if (using_prefetch) {
if (flags & GF_NOREFILL) {
strcpy(buffer, "(uae_u8)regs.irc");
} else {
set_last_access();
sprintf(buffer, "(uae_u8)%s(%d)", prefetch_word, r + 2);
count_readw++;
check_bus_error_ins(r + 2);
}
} else {
sprintf(buffer, "%s(%d)", srcbi, r);
if (!(flags & GF_NOREFILL)) {
count_readw++;
count_readp++;
check_bus_error_ins(r);
}
}
return buffer;
}
static void makefromsr(void)
{
out("MakeFromSR();\n");
if (using_ce || isce020())
out("regs.ipl_pin = intlev();\n");
}
static void makefromsr_t0(void)
{
if (using_prefetch || using_ce) {
out("MakeFromSR();\n");