ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/compiler/gencomp.c
Revision: 1.1
Committed: 2002-09-17T16:04:06Z (22 years, 2 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Log Message:
Import JIT compiler

File Contents

# Content
1 /*
2 * UAE - The Un*x Amiga Emulator
3 *
4 * MC68000 compilation generator
5 *
6 * Based on work Copyright 1995, 1996 Bernd Schmidt. Changes Copyright 2000
7 * Bernd Meyer
8 */
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include "sysdeps.h"
17 #include "readcpu.h"
18
19 #define BOOL_TYPE "int"
20 #define failure global_failure=1
21 #define FAILURE global_failure=1
22 #define isjump global_isjump=1
23 #define is_const_jump global_iscjump=1;
24 #define isaddx global_isaddx=1
25 #define uses_cmov global_cmov=1
26 #define mayfail global_mayfail=1
27 #define uses_fpu global_fpu=1
28
29 int hack_opcode;
30
31 static int global_failure;
32 static int global_isjump;
33 static int global_iscjump;
34 static int global_isaddx;
35 static int global_cmov;
36 static int long_opcode;
37 static int global_mayfail;
38 static int global_fpu;
39
40 static char endstr[1000];
41 static char lines[100000];
42 static int comp_index=0;
43
44 static int cond_codes_x86[]={-1,-1,7,6,3,2,5,4,-1,-1,9,8,13,12,15,14};
45
46 static void comprintf(const char* format, ...)
47 {
48 va_list args;
49
50 va_start(args,format);
51 comp_index+=vsprintf(lines+comp_index,format,args);
52 }
53
54 static void com_discard(void)
55 {
56 comp_index=0;
57 }
58
59 static void com_flush(void)
60 {
61 int i;
62 for (i=0;i<comp_index;i++)
63 putchar(lines[i]);
64 com_discard();
65 }
66
67
68 static FILE *headerfile;
69 static FILE *stblfile;
70
71 static int using_prefetch;
72 static int using_exception_3;
73 static int cpu_level;
74 static int noflags;
75
76 /* For the current opcode, the next lower level that will have different code.
77 * Initialized to -1 for each opcode. If it remains unchanged, indicates we
78 * are done with that opcode. */
79 static int next_cpu_level;
80
81 static int *opcode_map;
82 static int *opcode_next_clev;
83 static int *opcode_last_postfix;
84 static unsigned long *counts;
85
86 static void
87 read_counts (void)
88 {
89 FILE *file;
90 unsigned long opcode, count, total;
91 char name[20];
92 int nr = 0;
93 memset (counts, 0, 65536 * sizeof *counts);
94
95 file = fopen ("frequent.68k", "r");
96 if (file)
97 {
98 fscanf (file, "Total: %lu\n", &total);
99 while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3)
100 {
101 opcode_next_clev[nr] = 4;
102 opcode_last_postfix[nr] = -1;
103 opcode_map[nr++] = opcode;
104 counts[opcode] = count;
105 }
106 fclose (file);
107 }
108 if (nr == nr_cpuop_funcs)
109 return;
110 for (opcode = 0; opcode < 0x10000; opcode++)
111 {
112 if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
113 && counts[opcode] == 0)
114 {
115 opcode_next_clev[nr] = 4;
116 opcode_last_postfix[nr] = -1;
117 opcode_map[nr++] = opcode;
118 counts[opcode] = count;
119 }
120 }
121 if (nr != nr_cpuop_funcs)
122 abort ();
123 }
124
125 static int n_braces = 0;
126 static int insn_n_cycles;
127
128 static void
129 start_brace (void)
130 {
131 n_braces++;
132 comprintf ("{");
133 }
134
135 static void
136 close_brace (void)
137 {
138 assert (n_braces > 0);
139 n_braces--;
140 comprintf ("}");
141 }
142
143 static void
144 finish_braces (void)
145 {
146 while (n_braces > 0)
147 close_brace ();
148 }
149
150 static void
151 pop_braces (int to)
152 {
153 while (n_braces > to)
154 close_brace ();
155 }
156
157 static int
158 bit_size (int size)
159 {
160 switch (size)
161 {
162 case sz_byte:
163 return 8;
164 case sz_word:
165 return 16;
166 case sz_long:
167 return 32;
168 default:
169 abort ();
170 }
171 return 0;
172 }
173
174 static const char *
175 bit_mask (int size)
176 {
177 switch (size)
178 {
179 case sz_byte:
180 return "0xff";
181 case sz_word:
182 return "0xffff";
183 case sz_long:
184 return "0xffffffff";
185 default:
186 abort ();
187 }
188 return 0;
189 }
190
191 static __inline__ void gen_update_next_handler(void)
192 {
193 return; /* Can anything clever be done here? */
194 }
195
196 static void gen_writebyte(char* address, char* source)
197 {
198 comprintf("\twritebyte(%s,%s,scratchie);\n",address,source);
199 }
200
201 static void gen_writeword(char* address, char* source)
202 {
203 comprintf("\twriteword(%s,%s,scratchie);\n",address,source);
204 }
205
206 static void gen_writelong(char* address, char* source)
207 {
208 comprintf("\twritelong(%s,%s,scratchie);\n",address,source);
209 }
210
211 static void gen_readbyte(char* address, char* dest)
212 {
213 comprintf("\treadbyte(%s,%s,scratchie);\n",address,dest);
214 }
215
216 static void gen_readword(char* address, char* dest)
217 {
218 comprintf("\treadword(%s,%s,scratchie);\n",address,dest);
219 }
220
221 static void gen_readlong(char* address, char* dest)
222 {
223 comprintf("\treadlong(%s,%s,scratchie);\n",address,dest);
224 }
225
226
227
228 static const char *
229 gen_nextilong (void)
230 {
231 static char buffer[80];
232
233 sprintf (buffer, "comp_get_ilong((m68k_pc_offset+=4)-4)");
234 insn_n_cycles += 4;
235
236 long_opcode=1;
237 return buffer;
238 }
239
240 static const char *
241 gen_nextiword (void)
242 {
243 static char buffer[80];
244
245 sprintf (buffer, "comp_get_iword((m68k_pc_offset+=2)-2)");
246 insn_n_cycles+=2;
247
248 long_opcode=1;
249 return buffer;
250 }
251
252 static const char *
253 gen_nextibyte (void)
254 {
255 static char buffer[80];
256
257 sprintf (buffer, "comp_get_ibyte((m68k_pc_offset+=2)-2)");
258 insn_n_cycles += 2;
259
260 long_opcode=1;
261 return buffer;
262 }
263
264 static void
265 swap_opcode (void)
266 {
267 comprintf("#ifdef HAVE_GET_WORD_UNSWAPPED\n");
268 comprintf("\topcode = do_byteswap_16(opcode);\n");
269 comprintf("#endif\n");
270 }
271
272 static void
273 sync_m68k_pc (void)
274 {
275 comprintf("\t if (m68k_pc_offset>100) sync_m68k_pc();\n");
276 }
277
278
279 /* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
280 * the calling routine handles Apdi and Aipi modes.
281 * gb-- movem == 2 means the same thing but for a MOVE16 instruction */
282 static void
283 genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem)
284 {
285 start_brace ();
286 switch (mode)
287 {
288 case Dreg: /* Do we need to check dodgy here? */
289 if (movem)
290 abort ();
291 if (getv == 1 || getv==2) {
292 /* We generate the variable even for getv==2, so we can use
293 it as a destination for MOVE */
294 comprintf ("\tint %s=%s;\n",name,reg);
295 }
296 return;
297
298 case Areg:
299 if (movem)
300 abort ();
301 if (getv == 1 || getv==2) {
302 /* see above */
303 comprintf ("\tint %s=dodgy?scratchie++:%s+8;\n",name,reg);
304 if (getv==1) {
305 comprintf ("\tif (dodgy) \n");
306 comprintf ("\t\tmov_l_rr(%s,%s+8);\n",name, reg);
307 }
308 }
309 return;
310
311 case Aind:
312 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
313 comprintf ("\tif (dodgy) \n");
314 comprintf ("\t\tmov_l_rr(%sa,%s+8);\n",name, reg);
315 break;
316 case Aipi:
317 comprintf ("\tint %sa=scratchie++;\n",name,reg);
318 comprintf ("\tmov_l_rr(%sa,%s+8);\n",name, reg);
319 break;
320 case Apdi:
321 switch (size)
322 {
323 case sz_byte:
324 if (movem) {
325 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
326 comprintf ("\tif (dodgy) \n");
327 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
328 }
329 else {
330 start_brace();
331 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
332 comprintf("\tlea_l_brr(%s+8,%s+8,(uae_s32)-areg_byteinc[%s]);\n",reg,reg,reg);
333 comprintf ("\tif (dodgy) \n");
334 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
335 }
336 break;
337 case sz_word:
338 if (movem) {
339 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
340 comprintf ("\tif (dodgy) \n");
341 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
342 }
343 else {
344 start_brace();
345 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
346 comprintf("\tlea_l_brr(%s+8,%s+8,-2);\n",reg,reg);
347 comprintf ("\tif (dodgy) \n");
348 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
349 }
350 break;
351 case sz_long:
352 if (movem) {
353 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
354 comprintf ("\tif (dodgy) \n");
355 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
356 }
357 else {
358 start_brace();
359 comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
360 comprintf("\tlea_l_brr(%s+8,%s+8,-4);\n",reg,reg);
361 comprintf ("\tif (dodgy) \n");
362 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
363 }
364 break;
365 default:
366 abort ();
367 }
368 break;
369 case Ad16:
370 comprintf("\tint %sa=scratchie++;\n",name);
371 comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
372 comprintf("\tlea_l_brr(%sa,%sa,(uae_s32)(uae_s16)%s);\n",name,name,gen_nextiword());
373 break;
374 case Ad8r:
375 comprintf("\tint %sa=scratchie++;\n",name);
376 comprintf("\tcalc_disp_ea_020(%s+8,%s,%sa,scratchie);\n",
377 reg,gen_nextiword(),name);
378 break;
379
380 case PC16:
381 comprintf("\tint %sa=scratchie++;\n",name);
382 comprintf("\tuae_u32 address=start_pc+((char *)comp_pc_p-(char *)start_pc_p)+m68k_pc_offset;\n");
383 comprintf ("\tuae_s32 PC16off = (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
384 comprintf("\tmov_l_ri(%sa,address+PC16off);\n",name);
385 break;
386
387 case PC8r:
388 comprintf("\tint pctmp=scratchie++;\n");
389 comprintf("\tint %sa=scratchie++;\n",name);
390 comprintf("\tuae_u32 address=start_pc+((char *)comp_pc_p-(char *)start_pc_p)+m68k_pc_offset;\n");
391 start_brace();
392 comprintf("\tmov_l_ri(pctmp,address);\n");
393
394 comprintf("\tcalc_disp_ea_020(pctmp,%s,%sa,scratchie);\n",
395 gen_nextiword(),name);
396 break;
397 case absw:
398 comprintf ("\tint %sa = scratchie++;\n",name);
399 comprintf ("\tmov_l_ri(%sa,(uae_s32)(uae_s16)%s);\n", name, gen_nextiword ());
400 break;
401 case absl:
402 comprintf ("\tint %sa = scratchie++;\n",name);
403 comprintf ("\tmov_l_ri(%sa,%s); /* absl */\n", name, gen_nextilong ());
404 break;
405 case imm:
406 if (getv != 1)
407 abort ();
408 switch (size)
409 {
410 case sz_byte:
411 comprintf ("\tint %s = scratchie++;\n",name);
412 comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s8)%s);\n", name, gen_nextibyte ());
413 break;
414 case sz_word:
415 comprintf ("\tint %s = scratchie++;\n",name);
416 comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s16)%s);\n", name, gen_nextiword ());
417 break;
418 case sz_long:
419 comprintf ("\tint %s = scratchie++;\n",name);
420 comprintf ("\tmov_l_ri(%s,%s);\n", name, gen_nextilong ());
421 break;
422 default:
423 abort ();
424 }
425 return;
426 case imm0:
427 if (getv != 1)
428 abort ();
429 comprintf ("\tint %s = scratchie++;\n",name);
430 comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s8)%s);\n", name, gen_nextibyte ());
431 return;
432 case imm1:
433 if (getv != 1)
434 abort ();
435 comprintf ("\tint %s = scratchie++;\n",name);
436 comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s16)%s);\n", name, gen_nextiword ());
437 return;
438 case imm2:
439 if (getv != 1)
440 abort ();
441 comprintf ("\tint %s = scratchie++;\n",name);
442 comprintf ("\tmov_l_ri(%s,%s);\n", name, gen_nextilong ());
443 return;
444 case immi:
445 if (getv != 1)
446 abort ();
447 comprintf ("\tint %s = scratchie++;\n",name);
448 comprintf ("\tmov_l_ri(%s,%s);\n", name, reg);
449 return;
450 default:
451 abort ();
452 }
453
454 /* We get here for all non-reg non-immediate addressing modes to
455 * actually fetch the value. */
456 if (getv == 1)
457 {
458 char astring[80];
459 sprintf(astring,"%sa",name);
460 switch (size)
461 {
462 case sz_byte:
463 insn_n_cycles += 2;
464 break;
465 case sz_word:
466 insn_n_cycles += 2;
467 break;
468 case sz_long:
469 insn_n_cycles += 4;
470 break;
471 default:
472 abort ();
473 }
474 start_brace ();
475 comprintf("\tint %s=scratchie++;\n",name);
476 switch (size)
477 {
478 case sz_byte:
479 gen_readbyte(astring,name);
480 break;
481 case sz_word:
482 gen_readword(astring,name);
483 break;
484 case sz_long:
485 gen_readlong(astring,name);
486 break;
487 default:
488 abort ();
489 }
490 }
491
492 /* We now might have to fix up the register for pre-dec or post-inc
493 * addressing modes. */
494 if (!movem) {
495 char x[160];
496 switch (mode)
497 {
498 case Aipi:
499 switch (size)
500 {
501 case sz_byte:
502 comprintf("\tlea_l_brr(%s+8,%s+8,areg_byteinc[%s]);\n",reg,reg,reg);
503 break;
504 case sz_word:
505 comprintf("\tlea_l_brr(%s+8,%s+8,2);\n",reg,reg,reg);
506 break;
507 case sz_long:
508 comprintf("\tlea_l_brr(%s+8,%s+8,4);\n",reg,reg);
509 break;
510 default:
511 abort ();
512 }
513 break;
514 case Apdi:
515 break;
516 default:
517 break;
518 }
519 }
520 }
521
522 static void
523 genastore (char *from, amodes mode, char *reg, wordsizes size, char *to)
524 {
525 switch (mode)
526 {
527 case Dreg:
528 switch (size)
529 {
530 case sz_byte:
531 comprintf("\tif(%s!=%s)\n",reg,from);
532 comprintf ("\t\tmov_b_rr(%s,%s);\n", reg, from);
533 break;
534 case sz_word:
535 comprintf("\tif(%s!=%s)\n",reg,from);
536 comprintf ("\t\tmov_w_rr(%s,%s);\n", reg, from);
537 break;
538 case sz_long:
539 comprintf("\tif(%s!=%s)\n",reg,from);
540 comprintf ("\t\tmov_l_rr(%s,%s);\n", reg, from);
541 break;
542 default:
543 abort ();
544 }
545 break;
546 case Areg:
547 switch (size)
548 {
549 case sz_word:
550 comprintf("\tif(%s+8!=%s)\n",reg,from);
551 comprintf ("\t\tmov_w_rr(%s+8,%s);\n", reg, from);
552 break;
553 case sz_long:
554 comprintf("\tif(%s+8!=%s)\n",reg,from);
555 comprintf ("\t\tmov_l_rr(%s+8,%s);\n", reg, from);
556 break;
557 default:
558 abort ();
559 }
560 break;
561
562 case Apdi:
563 case absw:
564 case PC16:
565 case PC8r:
566 case Ad16:
567 case Ad8r:
568 case Aipi:
569 case Aind:
570 case absl:
571 {
572 char astring[80];
573 sprintf(astring,"%sa",to);
574
575 switch (size)
576 {
577 case sz_byte:
578 insn_n_cycles += 2;
579 gen_writebyte(astring,from);
580 break;
581 case sz_word:
582 insn_n_cycles += 2;
583 gen_writeword(astring,from);
584 break;
585 case sz_long:
586 insn_n_cycles += 4;
587 gen_writelong(astring,from);
588 break;
589 default:
590 abort ();
591 }
592 }
593 break;
594 case imm:
595 case imm0:
596 case imm1:
597 case imm2:
598 case immi:
599 abort ();
600 break;
601 default:
602 abort ();
603 }
604 }
605
606 static void genmov16(uae_u32 opcode, struct instr *curi)
607 {
608 comprintf("\tint src=scratchie++;\n");
609 comprintf("\tint dst=scratchie++;\n");
610
611 if ((opcode & 0xfff8) == 0xf620) {
612 /* MOVE16 (Ax)+,(Ay)+ */
613 comprintf("\tuae_u16 dstreg=((%s)>>12)&0x07;\n", gen_nextiword());
614 comprintf("\tmov_l_rr(src,8+srcreg);\n");
615 comprintf("\tmov_l_rr(dst,8+dstreg);\n");
616 }
617 else {
618 /* Other variants */
619 genamode (curi->smode, "srcreg", curi->size, "src", 0, 2);
620 genamode (curi->dmode, "dstreg", curi->size, "dst", 0, 2);
621 comprintf("\tmov_l_rr(src,srca);\n");
622 comprintf("\tmov_l_rr(dst,dsta);\n");
623 }
624
625 /* Align on 16-byte boundaries */
626 comprintf("\tand_l_ri(src,~15);\n");
627 comprintf("\tand_l_ri(dst,~15);\n");
628
629 if ((opcode & 0xfff8) == 0xf620) {
630 comprintf("\tif (srcreg != dstreg)\n");
631 comprintf("\tadd_l_ri(srcreg+8,16);\n");
632 comprintf("\tadd_l_ri(dstreg+8,16);\n");
633 }
634 else if ((opcode & 0xfff8) == 0xf600)
635 comprintf("\tadd_l_ri(srcreg+8,16);\n");
636 else if ((opcode & 0xfff8) == 0xf608)
637 comprintf("\tadd_l_ri(dstreg+8,16);\n");
638
639 comprintf("\tint tmp=scratchie;\n");
640 comprintf("\tscratchie+=4;\n");
641
642 comprintf("\tget_n_addr(src,src,scratchie);\n"
643 "\tget_n_addr(dst,dst,scratchie);\n"
644 "\tmov_l_rR(tmp+0,src,0);\n"
645 "\tmov_l_rR(tmp+1,src,4);\n"
646 "\tmov_l_rR(tmp+2,src,8);\n"
647 "\tmov_l_rR(tmp+3,src,12);\n"
648 "\tmov_l_Rr(dst,tmp+0,0);\n"
649 "\tforget_about(tmp+0);\n"
650 "\tmov_l_Rr(dst,tmp+1,4);\n"
651 "\tforget_about(tmp+1);\n"
652 "\tmov_l_Rr(dst,tmp+2,8);\n"
653 "\tforget_about(tmp+2);\n"
654 "\tmov_l_Rr(dst,tmp+3,12);\n");
655 }
656
657 static void
658 genmovemel (uae_u16 opcode)
659 {
660 comprintf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
661 comprintf ("\tint native=scratchie++;\n");
662 comprintf ("\tint i;\n");
663 comprintf ("\tsigned char offset=0;\n");
664 genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
665 comprintf("\tget_n_addr(srca,native,scratchie);\n");
666
667 comprintf("\tfor (i=0;i<16;i++) {\n"
668 "\t\tif ((mask>>i)&1) {\n");
669 switch(table68k[opcode].size) {
670 case sz_long:
671 comprintf("\t\t\tmov_l_rR(i,native,offset);\n"
672 "\t\t\tbswap_32(i);\n"
673 "\t\t\toffset+=4;\n");
674 break;
675 case sz_word:
676 comprintf("\t\t\tmov_w_rR(i,native,offset);\n"
677 "\t\t\tbswap_16(i);\n"
678 "\t\t\tsign_extend_16_rr(i,i);\n"
679 "\t\t\toffset+=2;\n");
680 break;
681 default: abort();
682 }
683 comprintf("\t\t}\n"
684 "\t}");
685 if (table68k[opcode].dmode == Aipi) {
686 comprintf("\t\t\tlea_l_brr(8+dstreg,srca,offset);\n");
687 }
688 }
689
690
691 static void
692 genmovemle (uae_u16 opcode)
693 {
694 comprintf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
695 comprintf ("\tint native=scratchie++;\n");
696 comprintf ("\tint i;\n");
697 comprintf ("\tint tmp=scratchie++;\n");
698 comprintf ("\tsigned char offset=0;\n");
699 genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
700
701 comprintf("\tget_n_addr(srca,native,scratchie);\n");
702
703 if (table68k[opcode].dmode!=Apdi) {
704 comprintf("\tfor (i=0;i<16;i++) {\n"
705 "\t\tif ((mask>>i)&1) {\n");
706 switch(table68k[opcode].size) {
707 case sz_long:
708 comprintf("\t\t\tmov_l_rr(tmp,i);\n"
709 "\t\t\tbswap_32(tmp);\n"
710 "\t\t\tmov_l_Rr(native,tmp,offset);\n"
711 "\t\t\toffset+=4;\n");
712 break;
713 case sz_word:
714 comprintf("\t\t\tmov_l_rr(tmp,i);\n"
715 "\t\t\tbswap_16(tmp);\n"
716 "\t\t\tmov_w_Rr(native,tmp,offset);\n"
717 "\t\t\toffset+=2;\n");
718 break;
719 default: abort();
720 }
721 }
722 else { /* Pre-decrement */
723 comprintf("\tfor (i=0;i<16;i++) {\n"
724 "\t\tif ((mask>>i)&1) {\n");
725 switch(table68k[opcode].size) {
726 case sz_long:
727 comprintf("\t\t\toffset-=4;\n"
728 "\t\t\tmov_l_rr(tmp,15-i);\n"
729 "\t\t\tbswap_32(tmp);\n"
730 "\t\t\tmov_l_Rr(native,tmp,offset);\n"
731 );
732 break;
733 case sz_word:
734 comprintf("\t\t\toffset-=2;\n"
735 "\t\t\tmov_l_rr(tmp,15-i);\n"
736 "\t\t\tbswap_16(tmp);\n"
737 "\t\t\tmov_w_Rr(native,tmp,offset);\n"
738 );
739 break;
740 default: abort();
741 }
742 }
743
744
745 comprintf("\t\t}\n"
746 "\t}");
747 if (table68k[opcode].dmode == Apdi) {
748 comprintf("\t\t\tlea_l_brr(8+dstreg,srca,(uae_s32)offset);\n");
749 }
750 }
751
752
753 static void
754 duplicate_carry (void)
755 {
756 comprintf ("\tif (needed_flags&FLAG_X) duplicate_carry();\n");
757 }
758
759 typedef enum
760 {
761 flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp,
762 flag_addx, flag_subx, flag_zn, flag_av, flag_sv, flag_and, flag_or,
763 flag_eor, flag_mov
764 }
765 flagtypes;
766
767
768 static void
769 genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst)
770 {
771 if (noflags) {
772 switch(type) {
773 case flag_cmp:
774 comprintf("\tdont_care_flags();\n");
775 comprintf("/* Weird --- CMP with noflags ;-) */\n");
776 return;
777 case flag_add:
778 case flag_sub:
779 comprintf("\tdont_care_flags();\n");
780 {
781 char* op;
782 switch(type) {
783 case flag_add: op="add"; break;
784 case flag_sub: op="sub"; break;
785 default: abort();
786 }
787 switch (size)
788 {
789 case sz_byte:
790 comprintf("\t%s_b(%s,%s);\n",op,dst,src);
791 break;
792 case sz_word:
793 comprintf("\t%s_w(%s,%s);\n",op,dst,src);
794 break;
795 case sz_long:
796 comprintf("\t%s_l(%s,%s);\n",op,dst,src);
797 break;
798 }
799 return;
800 }
801 break;
802
803 case flag_and:
804 comprintf("\tdont_care_flags();\n");
805 switch (size)
806 {
807 case sz_byte:
808 comprintf("if (kill_rodent(dst)) {\n");
809 comprintf("\tzero_extend_8_rr(scratchie,%s);\n",src);
810 comprintf("\tor_l_ri(scratchie,0xffffff00);\n");
811 comprintf("\tand_l(%s,scratchie);\n",dst);
812 comprintf("\tforget_about(scratchie);\n");
813 comprintf("\t} else \n"
814 "\tand_b(%s,%s);\n",dst,src);
815 break;
816 case sz_word:
817 comprintf("if (kill_rodent(dst)) {\n");
818 comprintf("\tzero_extend_16_rr(scratchie,%s);\n",src);
819 comprintf("\tor_l_ri(scratchie,0xffff0000);\n");
820 comprintf("\tand_l(%s,scratchie);\n",dst);
821 comprintf("\tforget_about(scratchie);\n");
822 comprintf("\t} else \n"
823 "\tand_w(%s,%s);\n",dst,src);
824 break;
825 case sz_long:
826 comprintf("\tand_l(%s,%s);\n",dst,src);
827 break;
828 }
829 return;
830
831 case flag_mov:
832 comprintf("\tdont_care_flags();\n");
833 switch (size)
834 {
835 case sz_byte:
836 comprintf("if (kill_rodent(dst)) {\n");
837 comprintf("\tzero_extend_8_rr(scratchie,%s);\n",src);
838 comprintf("\tand_l_ri(%s,0xffffff00);\n",dst);
839 comprintf("\tor_l(%s,scratchie);\n",dst);
840 comprintf("\tforget_about(scratchie);\n");
841 comprintf("\t} else \n"
842 "\tmov_b_rr(%s,%s);\n",dst,src);
843 break;
844 case sz_word:
845 comprintf("if (kill_rodent(dst)) {\n");
846 comprintf("\tzero_extend_16_rr(scratchie,%s);\n",src);
847 comprintf("\tand_l_ri(%s,0xffff0000);\n",dst);
848 comprintf("\tor_l(%s,scratchie);\n",dst);
849 comprintf("\tforget_about(scratchie);\n");
850 comprintf("\t} else \n"
851 "\tmov_w_rr(%s,%s);\n",dst,src);
852 break;
853 case sz_long:
854 comprintf("\tmov_l_rr(%s,%s);\n",dst,src);
855 break;
856 }
857 return;
858
859 case flag_or:
860 case flag_eor:
861 comprintf("\tdont_care_flags();\n");
862 start_brace();
863 {
864 char* op;
865 switch(type) {
866 case flag_or: op="or"; break;
867 case flag_eor: op="xor"; break;
868 default: abort();
869 }
870 switch (size)
871 {
872 case sz_byte:
873 comprintf("if (kill_rodent(dst)) {\n");
874 comprintf("\tzero_extend_8_rr(scratchie,%s);\n",src);
875 comprintf("\t%s_l(%s,scratchie);\n",op,dst);
876 comprintf("\tforget_about(scratchie);\n");
877 comprintf("\t} else \n"
878 "\t%s_b(%s,%s);\n",op,dst,src);
879 break;
880 case sz_word:
881 comprintf("if (kill_rodent(dst)) {\n");
882 comprintf("\tzero_extend_16_rr(scratchie,%s);\n",src);
883 comprintf("\t%s_l(%s,scratchie);\n",op,dst);
884 comprintf("\tforget_about(scratchie);\n");
885 comprintf("\t} else \n"
886 "\t%s_w(%s,%s);\n",op,dst,src);
887 break;
888 case sz_long:
889 comprintf("\t%s_l(%s,%s);\n",op,dst,src);
890 break;
891 }
892 close_brace();
893 return;
894 }
895
896
897 case flag_addx:
898 case flag_subx:
899 comprintf("\tdont_care_flags();\n");
900 {
901 char* op;
902 switch(type) {
903 case flag_addx: op="adc"; break;
904 case flag_subx: op="sbb"; break;
905 default: abort();
906 }
907 comprintf("\trestore_carry();\n"); /* Reload the X flag into C */
908 switch (size)
909 {
910 case sz_byte:
911 comprintf("\t%s_b(%s,%s);\n",op,dst,src);
912 break;
913 case sz_word:
914 comprintf("\t%s_w(%s,%s);\n",op,dst,src);
915 break;
916 case sz_long:
917 comprintf("\t%s_l(%s,%s);\n",op,dst,src);
918 break;
919 }
920 return;
921 }
922 break;
923 default: return;
924 }
925 }
926
927 /* Need the flags, but possibly not all of them */
928 switch (type)
929 {
930 case flag_logical_noclobber:
931 failure;
932
933 case flag_and:
934 case flag_or:
935 case flag_eor:
936 comprintf("\tdont_care_flags();\n");
937 start_brace();
938 {
939 char* op;
940 switch(type) {
941 case flag_and: op="and"; break;
942 case flag_or: op="or"; break;
943 case flag_eor: op="xor"; break;
944 default: abort();
945 }
946 switch (size)
947 {
948 case sz_byte:
949 comprintf("\tstart_needflags();\n"
950 "\t%s_b(%s,%s);\n",op,dst,src);
951 break;
952 case sz_word:
953 comprintf("\tstart_needflags();\n"
954 "\t%s_w(%s,%s);\n",op,dst,src);
955 break;
956 case sz_long:
957 comprintf("\tstart_needflags();\n"
958 "\t%s_l(%s,%s);\n",op,dst,src);
959 break;
960 }
961 comprintf("\tlive_flags();\n");
962 comprintf("\tend_needflags();\n");
963 close_brace();
964 return;
965 }
966
967 case flag_mov:
968 comprintf("\tdont_care_flags();\n");
969 start_brace();
970 {
971 switch (size)
972 {
973 case sz_byte:
974 comprintf("\tif (%s!=%s) {\n",src,dst);
975 comprintf("\tmov_b_ri(%s,0);\n"
976 "\tstart_needflags();\n",dst);
977 comprintf("\tor_b(%s,%s);\n",dst,src);
978 comprintf("\t} else {\n");
979 comprintf("\tmov_b_rr(%s,%s);\n",dst,src);
980 comprintf("\ttest_b_rr(%s,%s);\n",dst,dst);
981 comprintf("\t}\n");
982 break;
983 case sz_word:
984 comprintf("\tif (%s!=%s) {\n",src,dst);
985 comprintf("\tmov_w_ri(%s,0);\n"
986 "\tstart_needflags();\n",dst);
987 comprintf("\tor_w(%s,%s);\n",dst,src);
988 comprintf("\t} else {\n");
989 comprintf("\tmov_w_rr(%s,%s);\n",dst,src);
990 comprintf("\ttest_w_rr(%s,%s);\n",dst,dst);
991 comprintf("\t}\n");
992 break;
993 case sz_long:
994 comprintf("\tif (%s!=%s) {\n",src,dst);
995 comprintf("\tmov_l_ri(%s,0);\n"
996 "\tstart_needflags();\n",dst);
997 comprintf("\tor_l(%s,%s);\n",dst,src);
998 comprintf("\t} else {\n");
999 comprintf("\tmov_l_rr(%s,%s);\n",dst,src);
1000 comprintf("\ttest_l_rr(%s,%s);\n",dst,dst);
1001 comprintf("\t}\n");
1002 break;
1003 }
1004 comprintf("\tlive_flags();\n");
1005 comprintf("\tend_needflags();\n");
1006 close_brace();
1007 return;
1008 }
1009
1010 case flag_logical:
1011 comprintf("\tdont_care_flags();\n");
1012 start_brace();
1013 switch (size)
1014 {
1015 case sz_byte:
1016 comprintf("\tstart_needflags();\n"
1017 "\ttest_b_rr(%s,%s);\n",value,value);
1018 break;
1019 case sz_word:
1020 comprintf("\tstart_needflags();\n"
1021 "\ttest_w_rr(%s,%s);\n",value,value);
1022 break;
1023 case sz_long:
1024 comprintf("\tstart_needflags();\n"
1025 "\ttest_l_rr(%s,%s);\n",value,value);
1026 break;
1027 }
1028 comprintf("\tlive_flags();\n");
1029 comprintf("\tend_needflags();\n");
1030 close_brace();
1031 return;
1032
1033
1034 case flag_add:
1035 case flag_sub:
1036 case flag_cmp:
1037 comprintf("\tdont_care_flags();\n");
1038 {
1039 char* op;
1040 switch(type) {
1041 case flag_add: op="add"; break;
1042 case flag_sub: op="sub"; break;
1043 case flag_cmp: op="cmp"; break;
1044 default: abort();
1045 }
1046 switch (size)
1047 {
1048 case sz_byte:
1049 comprintf("\tstart_needflags();\n"
1050 "\t%s_b(%s,%s);\n",op,dst,src);
1051 break;
1052 case sz_word:
1053 comprintf("\tstart_needflags();\n"
1054 "\t%s_w(%s,%s);\n",op,dst,src);
1055 break;
1056 case sz_long:
1057 comprintf("\tstart_needflags();\n"
1058 "\t%s_l(%s,%s);\n",op,dst,src);
1059 break;
1060 }
1061 comprintf("\tlive_flags();\n");
1062 comprintf("\tend_needflags();\n");
1063 if (type!=flag_cmp) {
1064 duplicate_carry();
1065 }
1066 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
1067
1068 return;
1069 }
1070
1071 case flag_addx:
1072 case flag_subx:
1073 uses_cmov;
1074 comprintf("\tdont_care_flags();\n");
1075 {
1076 char* op;
1077 switch(type) {
1078 case flag_addx: op="adc"; break;
1079 case flag_subx: op="sbb"; break;
1080 default: abort();
1081 }
1082 start_brace();
1083 comprintf("\tint zero=scratchie++;\n"
1084 "\tint one=scratchie++;\n"
1085 "\tif (needed_flags&FLAG_Z) {\n"
1086 "\tmov_l_ri(zero,0);\n"
1087 "\tmov_l_ri(one,1);\n"
1088 "\tmake_flags_live();\n"
1089 "\tcmov_l_rr(zero,one,5);\n"
1090 "\t}\n");
1091 comprintf("\trestore_carry();\n"); /* Reload the X flag into C */
1092 switch (size)
1093 {
1094 case sz_byte:
1095 comprintf("\tstart_needflags();\n"
1096 "\t%s_b(%s,%s);\n",op,dst,src);
1097 break;
1098 case sz_word:
1099 comprintf("\tstart_needflags();\n"
1100 "\t%s_w(%s,%s);\n",op,dst,src);
1101 break;
1102 case sz_long:
1103 comprintf("\tstart_needflags();\n"
1104 "\t%s_l(%s,%s);\n",op,dst,src);
1105 break;
1106 }
1107 comprintf("\tif (needed_flags&FLAG_Z) {\n"
1108 "\tcmov_l_rr(zero,one,5);\n"
1109 "\tbsf_l_rr(zero,zero);\n"
1110 "\t}\n");
1111 comprintf("\tlive_flags();\n");
1112 comprintf("\tend_needflags();\n");
1113 duplicate_carry();
1114 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
1115 return;
1116 }
1117 default:
1118 failure;
1119 break;
1120 }
1121 }
1122
1123 static void
1124 force_range_for_rox (const char *var, wordsizes size)
1125 {
1126 /* Could do a modulo operation here... which one is faster? */
1127 switch (size)
1128 {
1129 case sz_long:
1130 comprintf ("\tif (%s >= 33) %s -= 33;\n", var, var);
1131 break;
1132 case sz_word:
1133 comprintf ("\tif (%s >= 34) %s -= 34;\n", var, var);
1134 comprintf ("\tif (%s >= 17) %s -= 17;\n", var, var);
1135 break;
1136 case sz_byte:
1137 comprintf ("\tif (%s >= 36) %s -= 36;\n", var, var);
1138 comprintf ("\tif (%s >= 18) %s -= 18;\n", var, var);
1139 comprintf ("\tif (%s >= 9) %s -= 9;\n", var, var);
1140 break;
1141 }
1142 }
1143
1144 static const char *
1145 cmask (wordsizes size)
1146 {
1147 switch (size)
1148 {
1149 case sz_byte:
1150 return "0x80";
1151 case sz_word:
1152 return "0x8000";
1153 case sz_long:
1154 return "0x80000000";
1155 default:
1156 abort ();
1157 }
1158 }
1159
1160 static int
1161 source_is_imm1_8 (struct instr *i)
1162 {
1163 return i->stype == 3;
1164 }
1165
1166 static int /* returns zero for success, non-zero for failure */
1167 gen_opcode (unsigned long int opcode)
1168 {
1169 struct instr *curi = table68k + opcode;
1170 char* ssize=NULL;
1171
1172 insn_n_cycles = 2;
1173 global_failure=0;
1174 long_opcode=0;
1175 global_isjump=0;
1176 global_iscjump=0;
1177 global_isaddx=0;
1178 global_cmov=0;
1179 global_fpu=0;
1180 global_mayfail=0;
1181 hack_opcode=opcode;
1182 endstr[0]=0;
1183
1184 start_brace ();
1185 comprintf("\tuae_u8 scratchie=S1;\n");
1186 switch (curi->plev)
1187 {
1188 case 0: /* not privileged */
1189 break;
1190 case 1: /* unprivileged only on 68000 */
1191 if (cpu_level == 0)
1192 break;
1193 if (next_cpu_level < 0)
1194 next_cpu_level = 0;
1195
1196 /* fall through */
1197 case 2: /* priviledged */
1198 failure; /* Easy ones first */
1199 break;
1200 case 3: /* privileged if size == word */
1201 if (curi->size == sz_byte)
1202 break;
1203 failure;
1204 break;
1205 }
1206 switch (curi->size) {
1207 case sz_byte: ssize="b"; break;
1208 case sz_word: ssize="w"; break;
1209 case sz_long: ssize="l"; break;
1210 default: abort();
1211 }
1212
1213 switch (curi->mnemo)
1214 {
1215 case i_OR:
1216 case i_AND:
1217 case i_EOR:
1218 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1219 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1220 switch(curi->mnemo) {
1221 case i_OR: genflags (flag_or, curi->size, "", "src", "dst"); break;
1222 case i_AND: genflags (flag_and, curi->size, "", "src", "dst"); break;
1223 case i_EOR: genflags (flag_eor, curi->size, "", "src", "dst"); break;
1224 }
1225 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1226 break;
1227
1228 case i_ORSR:
1229 case i_EORSR:
1230 failure;
1231 isjump;
1232 break;
1233 case i_ANDSR:
1234 failure;
1235 isjump;
1236 break;
1237 case i_SUB:
1238 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1239 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1240 genflags (flag_sub, curi->size, "", "src", "dst");
1241 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1242 break;
1243 case i_SUBA:
1244 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1245 genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1246 start_brace();
1247 comprintf("\tint tmp=scratchie++;\n");
1248 switch(curi->size) {
1249 case sz_byte: comprintf("\tsign_extend_8_rr(tmp,src);\n"); break;
1250 case sz_word: comprintf("\tsign_extend_16_rr(tmp,src);\n"); break;
1251 case sz_long: comprintf("\ttmp=src;\n"); break;
1252 default: abort();
1253 }
1254 comprintf("\tsub_l(dst,tmp);\n");
1255 genastore ("dst", curi->dmode, "dstreg", sz_long, "dst");
1256 break;
1257 case i_SUBX:
1258 isaddx;
1259 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1260 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1261 genflags (flag_subx, curi->size, "", "src", "dst");
1262 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1263 break;
1264 case i_SBCD:
1265 failure;
1266 /* I don't think so! */
1267 break;
1268 case i_ADD:
1269 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1270 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1271 genflags (flag_add, curi->size, "", "src", "dst");
1272 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1273 break;
1274 case i_ADDA:
1275 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1276 genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1277 start_brace();
1278 comprintf("\tint tmp=scratchie++;\n");
1279 switch(curi->size) {
1280 case sz_byte: comprintf("\tsign_extend_8_rr(tmp,src);\n"); break;
1281 case sz_word: comprintf("\tsign_extend_16_rr(tmp,src);\n"); break;
1282 case sz_long: comprintf("\ttmp=src;\n"); break;
1283 default: abort();
1284 }
1285 comprintf("\tadd_l(dst,tmp);\n");
1286 genastore ("dst", curi->dmode, "dstreg", sz_long, "dst");
1287 break;
1288 case i_ADDX:
1289 isaddx;
1290 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1291 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1292 start_brace();
1293 genflags (flag_addx, curi->size, "", "src", "dst");
1294 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1295 break;
1296 case i_ABCD:
1297 failure;
1298 /* No BCD maths for me.... */
1299 break;
1300 case i_NEG:
1301 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1302 start_brace ();
1303 comprintf("\tint dst=scratchie++;\n");
1304 comprintf("\tmov_l_ri(dst,0);\n");
1305 genflags (flag_sub, curi->size, "", "src", "dst");
1306 genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1307 break;
1308 case i_NEGX:
1309 isaddx;
1310 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1311 start_brace ();
1312 comprintf("\tint dst=scratchie++;\n");
1313 comprintf("\tmov_l_ri(dst,0);\n");
1314 genflags (flag_subx, curi->size, "", "src", "dst");
1315 genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1316 break;
1317
1318 case i_NBCD:
1319 failure;
1320 /* Nope! */
1321 break;
1322 case i_CLR:
1323 genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
1324 start_brace();
1325 comprintf("\tint dst=scratchie++;\n");
1326 comprintf("\tmov_l_ri(dst,0);\n");
1327 genflags (flag_logical, curi->size, "dst", "", "");
1328 genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1329 break;
1330 case i_NOT:
1331 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1332 start_brace ();
1333 comprintf("\tint dst=scratchie++;\n");
1334 comprintf("\tmov_l_ri(dst,0xffffffff);\n");
1335 genflags (flag_eor, curi->size, "", "src", "dst");
1336 genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1337 break;
1338 case i_TST:
1339 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1340 genflags (flag_logical, curi->size, "src", "", "");
1341 break;
1342 case i_BCHG:
1343 case i_BCLR:
1344 case i_BSET:
1345 case i_BTST:
1346 /* failure; /* NEW: from "Ipswitch Town" release */
1347 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1348 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1349 start_brace();
1350 comprintf("\tint s=scratchie++;\n"
1351 "\tmov_l_rr(s,src);\n");
1352 if (curi->size == sz_byte)
1353 comprintf("\tand_l_ri(s,7);\n");
1354 else
1355 comprintf("\tand_l_ri(s,31);\n");
1356
1357 {
1358 char* op;
1359 int need_write=1;
1360
1361 switch(curi->mnemo) {
1362 case i_BCHG: op="btc"; break;
1363 case i_BCLR: op="btr"; break;
1364 case i_BSET: op="bts"; break;
1365 case i_BTST: op="bt"; need_write=0; break;
1366 }
1367 comprintf("\t%s_l_rr(dst,s);\n" /* Answer now in C */
1368 "\tsbb_l(s,s);\n" /* s is 0 if bit was 0,
1369 -1 otherwise */
1370 "\tmake_flags_live();\n" /* Get the flags back */
1371 "\tdont_care_flags();\n"
1372 "\tstart_needflags();\n"
1373 "\tbsf_l_rr(s,s);\n"
1374 "\tlive_flags();\n"
1375 "\tend_needflags();\n",op);
1376 if (need_write)
1377 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1378 }
1379 break;
1380
1381 case i_CMPM:
1382 case i_CMP:
1383 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1384 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1385 start_brace ();
1386 genflags (flag_cmp, curi->size, "", "src", "dst");
1387 break;
1388 case i_CMPA:
1389 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1390 genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1391 start_brace();
1392 comprintf("\tint tmps=scratchie++;\n");
1393 switch(curi->size) {
1394 case sz_byte: comprintf("\tsign_extend_8_rr(tmps,src);\n"); break;
1395 case sz_word: comprintf("\tsign_extend_16_rr(tmps,src);\n"); break;
1396 case sz_long: comprintf("tmps=src;\n"); break;
1397 default: abort();
1398 }
1399 genflags (flag_cmp, sz_long, "", "tmps", "dst");
1400 break;
1401 /* The next two are coded a little unconventional, but they are doing
1402 * weird things... */
1403 case i_MVPRM:
1404 isjump;
1405 failure;
1406 break;
1407 case i_MVPMR:
1408 isjump;
1409 failure;
1410 break;
1411 case i_MOVE:
1412 switch(curi->dmode) {
1413 case Dreg:
1414 case Areg:
1415 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1416 genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1417 genflags (flag_mov, curi->size, "", "src", "dst");
1418 genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1419 break;
1420 default: /* It goes to memory, not a register */
1421 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1422 genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1423 genflags (flag_logical, curi->size, "src", "", "");
1424 genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1425 break;
1426 }
1427 break;
1428 case i_MOVEA:
1429 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1430 genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1431
1432 start_brace();
1433 comprintf("\tint tmps=scratchie++;\n");
1434 switch(curi->size) {
1435 case sz_word: comprintf("\tsign_extend_16_rr(dst,src);\n"); break;
1436 case sz_long: comprintf("\tmov_l_rr(dst,src);\n"); break;
1437 default: abort();
1438 }
1439 genastore ("dst", curi->dmode, "dstreg", sz_long, "dst");
1440 break;
1441
1442 case i_MVSR2:
1443 isjump;
1444 failure;
1445 break;
1446 case i_MV2SR:
1447 isjump;
1448 failure;
1449 break;
1450 case i_SWAP:
1451 genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1452 comprintf("\tdont_care_flags();\n");
1453 comprintf("\trol_l_ri(src,16);\n");
1454 genflags (flag_logical, sz_long, "src", "", "");
1455 genastore ("src", curi->smode, "srcreg", sz_long, "src");
1456 break;
1457 case i_EXG:
1458 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1459 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1460 start_brace();
1461 comprintf("\tint tmp=scratchie++;\n"
1462 "\tmov_l_rr(tmp,src);\n");
1463 genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1464 genastore ("tmp", curi->dmode, "dstreg", curi->size, "dst");
1465 break;
1466 case i_EXT:
1467 genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1468 comprintf("\tdont_care_flags();\n");
1469 start_brace ();
1470 switch (curi->size)
1471 {
1472 case sz_byte:
1473 comprintf ("\tint dst = src;\n"
1474 "\tsign_extend_8_rr(src,src);\n");
1475 break;
1476 case sz_word:
1477 comprintf ("\tint dst = scratchie++;\n"
1478 "\tsign_extend_8_rr(dst,src);\n");
1479 break;
1480 case sz_long:
1481 comprintf ("\tint dst = src;\n"
1482 "\tsign_extend_16_rr(src,src);\n");
1483 break;
1484 default:
1485 abort ();
1486 }
1487 genflags (flag_logical,
1488 curi->size == sz_word ? sz_word : sz_long, "dst", "", "");
1489 genastore ("dst", curi->smode, "srcreg",
1490 curi->size == sz_word ? sz_word : sz_long, "src");
1491 break;
1492 case i_MVMEL:
1493 genmovemel (opcode);
1494 break;
1495 case i_MVMLE:
1496 genmovemle (opcode);
1497 break;
1498 case i_TRAP:
1499 isjump;
1500 failure;
1501 break;
1502 case i_MVR2USP:
1503 isjump;
1504 failure;
1505 break;
1506 case i_MVUSP2R:
1507 isjump;
1508 failure;
1509 break;
1510 case i_RESET:
1511 isjump;
1512 failure;
1513 break;
1514 case i_NOP:
1515 break;
1516 case i_STOP:
1517 isjump;
1518 failure;
1519 break;
1520 case i_RTE:
1521 isjump;
1522 failure;
1523 break;
1524 case i_RTD:
1525 /* failure; /* NEW: from "Ipswitch Town" release */
1526 genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0);
1527 /* offs is constant */
1528 comprintf("\tadd_l_ri(offs,4);\n");
1529 start_brace();
1530 comprintf("\tint newad=scratchie++;\n"
1531 "\treadlong(15,newad,scratchie);\n"
1532 "\tmov_l_mr((uae_u32)&regs.pc,newad);\n"
1533 "\tget_n_addr_jmp(newad,PC_P,scratchie);\n"
1534 "\tmov_l_mr((uae_u32)&regs.pc_oldp,PC_P);\n"
1535 "\tm68k_pc_offset=0;\n"
1536 "\tadd_l(15,offs);\n");
1537 gen_update_next_handler();
1538 isjump;
1539 break;
1540 case i_LINK:
1541 /* failure; /* NEW: from "Ipswitch Town" release */
1542 genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1543 genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
1544 comprintf("\tsub_l_ri(15,4);\n"
1545 "\twritelong_clobber(15,src,scratchie);\n"
1546 "\tmov_l_rr(src,15);\n");
1547 if (curi->size==sz_word)
1548 comprintf("\tsign_extend_16_rr(offs,offs);\n");
1549 comprintf("\tadd_l(15,offs);\n");
1550 genastore ("src", curi->smode, "srcreg", sz_long, "src");
1551 break;
1552 case i_UNLK:
1553 /* failure; /* NEW: from "Ipswitch Town" release */
1554 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1555 comprintf("\tmov_l_rr(15,src);\n"
1556 "\treadlong(15,src,scratchie);\n"
1557 "\tadd_l_ri(15,4);\n");
1558 genastore ("src", curi->smode, "srcreg", curi->size, "src");
1559 break;
1560 case i_RTS:
1561 comprintf("\tint newad=scratchie++;\n"
1562 "\treadlong(15,newad,scratchie);\n"
1563 "\tmov_l_mr((uae_u32)&regs.pc,newad);\n"
1564 "\tget_n_addr_jmp(newad,PC_P,scratchie);\n"
1565 "\tmov_l_mr((uae_u32)&regs.pc_oldp,PC_P);\n"
1566 "\tm68k_pc_offset=0;\n"
1567 "\tlea_l_brr(15,15,4);\n");
1568 gen_update_next_handler();
1569 isjump;
1570 break;
1571 case i_TRAPV:
1572 isjump;
1573 failure;
1574 break;
1575 case i_RTR:
1576 isjump;
1577 failure;
1578 break;
1579 case i_JSR:
1580 isjump;
1581 genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1582 start_brace();
1583 comprintf("\tuae_u32 retadd=start_pc+((char *)comp_pc_p-(char *)start_pc_p)+m68k_pc_offset;\n");
1584 comprintf("\tint ret=scratchie++;\n"
1585 "\tmov_l_ri(ret,retadd);\n"
1586 "\tsub_l_ri(15,4);\n"
1587 "\twritelong_clobber(15,ret,scratchie);\n");
1588 comprintf("\tmov_l_mr((uae_u32)&regs.pc,srca);\n"
1589 "\tget_n_addr_jmp(srca,PC_P,scratchie);\n"
1590 "\tmov_l_mr((uae_u32)&regs.pc_oldp,PC_P);\n"
1591 "\tm68k_pc_offset=0;\n");
1592 gen_update_next_handler();
1593 break;
1594 case i_JMP:
1595 isjump;
1596 genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1597 comprintf("\tmov_l_mr((uae_u32)&regs.pc,srca);\n"
1598 "\tget_n_addr_jmp(srca,PC_P,scratchie);\n"
1599 "\tmov_l_mr((uae_u32)&regs.pc_oldp,PC_P);\n"
1600 "\tm68k_pc_offset=0;\n");
1601 gen_update_next_handler();
1602 break;
1603 case i_BSR:
1604 if (curi->size==sz_long)
1605 failure;
1606 is_const_jump;
1607 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1608 start_brace();
1609 comprintf("\tuae_u32 retadd=start_pc+((char *)comp_pc_p-(char *)start_pc_p)+m68k_pc_offset;\n");
1610 comprintf("\tint ret=scratchie++;\n"
1611 "\tmov_l_ri(ret,retadd);\n"
1612 "\tsub_l_ri(15,4);\n"
1613 "\twritelong_clobber(15,ret,scratchie);\n");
1614 comprintf("\tadd_l_ri(src,m68k_pc_offset_thisinst+2);\n");
1615 comprintf("\tm68k_pc_offset=0;\n");
1616 comprintf("\tadd_l(PC_P,src);\n");
1617
1618 comprintf("\tcomp_pc_p=(uae_u8*)get_const(PC_P);\n");
1619 break;
1620 case i_Bcc:
1621 comprintf("\tuae_u32 v,v1,v2;\n");
1622 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1623 /* That source is an immediate, so we can clobber it with abandon */
1624 switch(curi->size) {
1625 case sz_byte: comprintf("\tsign_extend_8_rr(src,src);\n"); break;
1626 case sz_word: comprintf("\tsign_extend_16_rr(src,src);\n"); break;
1627 case sz_long: break;
1628 }
1629 comprintf("\tsub_l_ri(src,m68k_pc_offset-m68k_pc_offset_thisinst-2);\n");
1630 /* Leave the following as "add" --- it will allow it to be optimized
1631 away due to src being a constant ;-) */
1632 comprintf("\tadd_l_ri(src,(uae_u32)comp_pc_p);\n");
1633 comprintf("\tmov_l_ri(PC_P,(uae_u32)comp_pc_p);\n");
1634 /* Now they are both constant. Might as well fold in m68k_pc_offset */
1635 comprintf("\tadd_l_ri(src,m68k_pc_offset);\n");
1636 comprintf("\tadd_l_ri(PC_P,m68k_pc_offset);\n");
1637 comprintf("\tm68k_pc_offset=0;\n");
1638
1639 if (curi->cc>=2) {
1640 comprintf("\tv1=get_const(PC_P);\n"
1641 "\tv2=get_const(src);\n"
1642 "\tregister_branch(v1,v2,%d);\n",
1643 cond_codes_x86[curi->cc]);
1644 comprintf("\tmake_flags_live();\n"); /* Load the flags */
1645 isjump;
1646 }
1647 else {
1648 is_const_jump;
1649 }
1650
1651 switch(curi->cc) {
1652 case 0: /* Unconditional jump */
1653 comprintf("\tmov_l_rr(PC_P,src);\n");
1654 comprintf("\tcomp_pc_p=(uae_u8*)get_const(PC_P);\n");
1655 break;
1656 case 1: break; /* This is silly! */
1657 case 8: failure; break; /* Work out details! FIXME */
1658 case 9: failure; break; /* Not critical, though! */
1659
1660 case 2:
1661 case 3:
1662 case 4:
1663 case 5:
1664 case 6:
1665 case 7:
1666 case 10:
1667 case 11:
1668 case 12:
1669 case 13:
1670 case 14:
1671 case 15:
1672 break;
1673 default: abort();
1674 }
1675 break;
1676 case i_LEA:
1677 genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1678 genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1679 genastore ("srca", curi->dmode, "dstreg", curi->size, "dst");
1680 break;
1681 case i_PEA:
1682 if (table68k[opcode].smode==Areg ||
1683 table68k[opcode].smode==Aind ||
1684 table68k[opcode].smode==Aipi ||
1685 table68k[opcode].smode==Apdi ||
1686 table68k[opcode].smode==Ad16 ||
1687 table68k[opcode].smode==Ad8r)
1688 comprintf("if (srcreg==7) dodgy=1;\n");
1689
1690 genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1691 genamode (Apdi, "7", sz_long, "dst", 2, 0);
1692 genastore ("srca", Apdi, "7", sz_long, "dst");
1693 break;
1694 case i_DBcc:
1695 isjump;
1696 uses_cmov;
1697 genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1698 genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
1699
1700 /* That offs is an immediate, so we can clobber it with abandon */
1701 switch(curi->size) {
1702 case sz_word: comprintf("\tsign_extend_16_rr(offs,offs);\n"); break;
1703 default: abort(); /* Seems this only comes in word flavour */
1704 }
1705 comprintf("\tsub_l_ri(offs,m68k_pc_offset-m68k_pc_offset_thisinst-2);\n");
1706 comprintf("\tadd_l_ri(offs,(uae_u32)comp_pc_p);\n"); /* New PC,
1707 once the
1708 offset_68k is
1709 * also added */
1710 /* Let's fold in the m68k_pc_offset at this point */
1711 comprintf("\tadd_l_ri(offs,m68k_pc_offset);\n");
1712 comprintf("\tadd_l_ri(PC_P,m68k_pc_offset);\n");
1713 comprintf("\tm68k_pc_offset=0;\n");
1714
1715 start_brace();
1716 comprintf("\tint nsrc=scratchie++;\n");
1717
1718 if (curi->cc>=2) {
1719 comprintf("\tmake_flags_live();\n"); /* Load the flags */
1720 }
1721
1722 if (curi->size!=sz_word)
1723 abort();
1724
1725
1726 switch(curi->cc) {
1727 case 0: /* This is an elaborate nop? */
1728 break;
1729 case 1:
1730 comprintf("\tstart_needflags();\n");
1731 comprintf("\tsub_w_ri(src,1);\n");
1732 comprintf("\t end_needflags();\n");
1733 start_brace();
1734 comprintf("\tuae_u32 v2,v;\n"
1735 "\tuae_u32 v1=get_const(PC_P);\n");
1736 comprintf("\tv2=get_const(offs);\n"
1737 "\tregister_branch(v1,v2,3);\n");
1738 break;
1739
1740 case 8: failure; break; /* Work out details! FIXME */
1741 case 9: failure; break; /* Not critical, though! */
1742
1743 case 2:
1744 case 3:
1745 case 4:
1746 case 5:
1747 case 6:
1748 case 7:
1749 case 10:
1750 case 11:
1751 case 12:
1752 case 13:
1753 case 14:
1754 case 15:
1755 comprintf("\tmov_l_rr(nsrc,src);\n");
1756 comprintf("\tlea_l_brr(scratchie,src,(uae_s32)-1);\n"
1757 "\tmov_w_rr(src,scratchie);\n");
1758 comprintf("\tcmov_l_rr(offs,PC_P,%d);\n",
1759 cond_codes_x86[curi->cc]);
1760 comprintf("\tcmov_l_rr(src,nsrc,%d);\n",
1761 cond_codes_x86[curi->cc]);
1762 /* OK, now for cc=true, we have src==nsrc and offs==PC_P,
1763 so whether we move them around doesn't matter. However,
1764 if cc=false, we have offs==jump_pc, and src==nsrc-1 */
1765
1766 comprintf("\t start_needflags();\n");
1767 comprintf("\ttest_w_rr(nsrc,nsrc);\n");
1768 comprintf("\t end_needflags();\n");
1769 comprintf("\tcmov_l_rr(PC_P,offs,5);\n");
1770 break;
1771 default: abort();
1772 }
1773 genastore ("src", curi->smode, "srcreg", curi->size, "src");
1774 gen_update_next_handler();
1775 break;
1776
1777 case i_Scc:
1778 /* failure; /* NEW: from "Ipswitch Town" release */
1779 genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
1780 start_brace ();
1781 comprintf ("\tint val = scratchie++;\n");
1782
1783 /* We set val to 0 if we really should use 255, and to 1 for real 0 */
1784 switch(curi->cc) {
1785 case 0: /* Unconditional set */
1786 comprintf("\tmov_l_ri(val,0);\n");
1787 break;
1788 case 1:
1789 /* Unconditional not-set */
1790 comprintf("\tmov_l_ri(val,1);\n");
1791 break;
1792 case 8: failure; break; /* Work out details! FIXME */
1793 case 9: failure; break; /* Not critical, though! */
1794
1795 case 2:
1796 case 3:
1797 case 4:
1798 case 5:
1799 case 6:
1800 case 7:
1801 case 10:
1802 case 11:
1803 case 12:
1804 case 13:
1805 case 14:
1806 case 15:
1807 comprintf("\tmake_flags_live();\n"); /* Load the flags */
1808 /* All condition codes can be inverted by changing the LSB */
1809 comprintf("\tsetcc(val,%d);\n",
1810 cond_codes_x86[curi->cc]^1); break;
1811 default: abort();
1812 }
1813 comprintf("\tsub_b_ri(val,1);\n");
1814 genastore ("val", curi->smode, "srcreg", curi->size, "src");
1815 break;
1816 case i_DIVU:
1817 isjump;
1818 failure;
1819 break;
1820 case i_DIVS:
1821 isjump;
1822 failure;
1823 break;
1824 case i_MULU:
1825 /* failure; /* NEW: from "Ipswitch Town" release */
1826 comprintf("\tdont_care_flags();\n");
1827 genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1828 genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
1829 /* To do 16x16 unsigned multiplication, we actually use
1830 32x32 signed, and zero-extend the registers first.
1831 That solves the problem of MUL needing dedicated registers
1832 on the x86 */
1833 comprintf("\tzero_extend_16_rr(scratchie,src);\n"
1834 "\tzero_extend_16_rr(dst,dst);\n"
1835 "\timul_32_32(dst,scratchie);\n");
1836 genflags (flag_logical, sz_long, "dst", "", "");
1837 genastore ("dst", curi->dmode, "dstreg", sz_long, "dst");
1838 break;
1839 case i_MULS:
1840 /* failure; /* NEW: from "Ipswitch Town" release */
1841 comprintf("\tdont_care_flags();\n");
1842 genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1843 genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
1844 comprintf("\tsign_extend_16_rr(scratchie,src);\n"
1845 "\tsign_extend_16_rr(dst,dst);\n"
1846 "\timul_32_32(dst,scratchie);\n");
1847 genflags (flag_logical, sz_long, "dst", "", "");
1848 genastore ("dst", curi->dmode, "dstreg", sz_long, "dst");
1849 break;
1850 case i_CHK:
1851 isjump;
1852 failure;
1853 break;
1854
1855 case i_CHK2:
1856 isjump;
1857 failure;
1858 break;
1859
1860 case i_ASR:
1861 mayfail;
1862 if (curi->smode==Dreg) {
1863 comprintf("if ((uae_u32)srcreg==(uae_u32)dstreg) {\n"
1864 " FAIL(1);\n"
1865 " return;\n"
1866 "} \n");
1867 start_brace();
1868 }
1869 comprintf("\tdont_care_flags();\n");
1870
1871 genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
1872 genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1873 if (curi->smode!=immi) {
1874 /* failure; /* UNTESTED: NEW: from "Ipswitch Town" release */
1875 if (!noflags) {
1876 uses_cmov;
1877 start_brace();
1878 comprintf("\tint highmask;\n"
1879 "\tint width;\n"
1880 "\tint cdata=scratchie++;\n"
1881 "\tint tmpcnt=scratchie++;\n"
1882 "\tint highshift=scratchie++;\n");
1883 comprintf("\tmov_l_rr(tmpcnt,cnt);\n"
1884 "\tand_l_ri(tmpcnt,63);\n"
1885 "\tmov_l_ri(cdata,0);\n"
1886 "\tcmov_l_rr(cdata,data,5);\n");
1887 /* cdata is now either data (for shift count!=0) or
1888 0 (for shift count==0) */
1889 switch(curi->size) {
1890 case sz_byte: comprintf("\tshra_b_rr(data,cnt);\n"
1891 "\thighmask=0x38;\n"
1892 "\twidth=8;\n");
1893 break;
1894 case sz_word: comprintf("\tshra_w_rr(data,cnt);\n"
1895 "\thighmask=0x30;\n"
1896 "\twidth=16;\n");
1897 break;
1898 case sz_long: comprintf("\tshra_l_rr(data,cnt);\n"
1899 "\thighmask=0x20;\n"
1900 "\twidth=32;\n");
1901 break;
1902 default: abort();
1903 }
1904 comprintf("test_l_ri(cnt,highmask);\n"
1905 "mov_l_ri(highshift,0);\n"
1906 "mov_l_ri(scratchie,width/2);\n"
1907 "cmov_l_rr(highshift,scratchie,5);\n");
1908 /* The x86 masks out bits, so we now make sure that things
1909 really get shifted as much as planned */
1910 switch(curi->size) {
1911 case sz_byte: comprintf("\tshra_b_rr(data,highshift);\n");break;
1912 case sz_word: comprintf("\tshra_w_rr(data,highshift);\n");break;
1913 case sz_long: comprintf("\tshra_l_rr(data,highshift);\n");break;
1914 default: abort();
1915 }
1916 /* And again */
1917 switch(curi->size) {
1918 case sz_byte: comprintf("\tshra_b_rr(data,highshift);\n");break;
1919 case sz_word: comprintf("\tshra_w_rr(data,highshift);\n");break;
1920 case sz_long: comprintf("\tshra_l_rr(data,highshift);\n");break;
1921 default: abort();
1922 }
1923
1924 /* Result of shift is now in data. Now we need to determine
1925 the carry by shifting cdata one less */
1926 comprintf("\tsub_l_ri(tmpcnt,1);\n");
1927 switch(curi->size) {
1928 case sz_byte: comprintf("\tshra_b_rr(cdata,tmpcnt);\n");break;
1929 case sz_word: comprintf("\tshra_w_rr(cdata,tmpcnt);\n");break;
1930 case sz_long: comprintf("\tshra_l_rr(cdata,tmpcnt);\n");break;
1931 default: abort();
1932 }
1933 /* If the shift count was higher than the width, we need
1934 to pick up the sign from data */
1935 comprintf("test_l_ri(tmpcnt,highmask);\n"
1936 "cmov_l_rr(cdata,data,5);\n");
1937 /* And create the flags */
1938 comprintf("\tstart_needflags();\n");
1939 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
1940 switch(curi->size) {
1941 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
1942 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
1943 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
1944 }
1945 comprintf("\t bt_l_ri(cdata,0);\n"); /* Set C */
1946 comprintf("\t live_flags();\n");
1947 comprintf("\t end_needflags();\n");
1948 comprintf("\t duplicate_carry();\n");
1949 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
1950 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
1951 }
1952 else {
1953 uses_cmov;
1954 start_brace();
1955 comprintf("\tint highmask;\n"
1956 "\tint width;\n"
1957 "\tint highshift=scratchie++;\n");
1958 switch(curi->size) {
1959 case sz_byte: comprintf("\tshra_b_rr(data,cnt);\n"
1960 "\thighmask=0x38;\n"
1961 "\twidth=8;\n");
1962 break;
1963 case sz_word: comprintf("\tshra_w_rr(data,cnt);\n"
1964 "\thighmask=0x30;\n"
1965 "\twidth=16;\n");
1966 break;
1967 case sz_long: comprintf("\tshra_l_rr(data,cnt);\n"
1968 "\thighmask=0x20;\n"
1969 "\twidth=32;\n");
1970 break;
1971 default: abort();
1972 }
1973 comprintf("test_l_ri(cnt,highmask);\n"
1974 "mov_l_ri(highshift,0);\n"
1975 "mov_l_ri(scratchie,width/2);\n"
1976 "cmov_l_rr(highshift,scratchie,5);\n");
1977 /* The x86 masks out bits, so we now make sure that things
1978 really get shifted as much as planned */
1979 switch(curi->size) {
1980 case sz_byte: comprintf("\tshra_b_rr(data,highshift);\n");break;
1981 case sz_word: comprintf("\tshra_w_rr(data,highshift);\n");break;
1982 case sz_long: comprintf("\tshra_l_rr(data,highshift);\n");break;
1983 default: abort();
1984 }
1985 /* And again */
1986 switch(curi->size) {
1987 case sz_byte: comprintf("\tshra_b_rr(data,highshift);\n");break;
1988 case sz_word: comprintf("\tshra_w_rr(data,highshift);\n");break;
1989 case sz_long: comprintf("\tshra_l_rr(data,highshift);\n");break;
1990 default: abort();
1991 }
1992 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
1993 }
1994 }
1995 else {
1996 start_brace();
1997 comprintf("\tint tmp=scratchie++;\n"
1998 "\tint bp;\n"
1999 "\tmov_l_rr(tmp,data);\n");
2000 switch(curi->size) {
2001 case sz_byte: comprintf("\tshra_b_ri(data,srcreg);\n"
2002 "\tbp=srcreg-1;\n"); break;
2003 case sz_word: comprintf("\tshra_w_ri(data,srcreg);\n"
2004 "\tbp=srcreg-1;\n"); break;
2005 case sz_long: comprintf("\tshra_l_ri(data,srcreg);\n"
2006 "\tbp=srcreg-1;\n"); break;
2007 default: abort();
2008 }
2009
2010 if (!noflags) {
2011 comprintf("\tstart_needflags();\n");
2012 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2013 switch(curi->size) {
2014 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2015 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2016 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2017 }
2018 comprintf("\t bt_l_ri(tmp,bp);\n"); /* Set C */
2019 comprintf("\t live_flags();\n");
2020 comprintf("\t end_needflags();\n");
2021 comprintf("\t duplicate_carry();\n");
2022 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2023 }
2024 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2025 }
2026 break;
2027
2028 case i_ASL:
2029 /* failure; /* NEW: from "Ipswitch Town" release */
2030 mayfail;
2031 if (curi->smode==Dreg) {
2032 comprintf("if ((uae_u32)srcreg==(uae_u32)dstreg) {\n"
2033 " FAIL(1);\n"
2034 " return;\n"
2035 "} \n");
2036 start_brace();
2037 }
2038 comprintf("\tdont_care_flags();\n");
2039 /* Except for the handling of the V flag, this is identical to
2040 LSL. The handling of V is, uhm, unpleasant, so if it's needed,
2041 let the normal emulation handle it. Shoulders of giants kinda
2042 thing ;-) */
2043 comprintf("if (needed_flags & FLAG_V) {\n"
2044 " FAIL(1);\n"
2045 " return;\n"
2046 "} \n");
2047
2048 genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
2049 genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
2050 if (curi->smode!=immi) {
2051 if (!noflags) {
2052 uses_cmov;
2053 start_brace();
2054 comprintf("\tint highmask;\n"
2055 "\tint cdata=scratchie++;\n"
2056 "\tint tmpcnt=scratchie++;\n");
2057 comprintf("\tmov_l_rr(tmpcnt,cnt);\n"
2058 "\tand_l_ri(tmpcnt,63);\n"
2059 "\tmov_l_ri(cdata,0);\n"
2060 "\tcmov_l_rr(cdata,data,5);\n");
2061 /* cdata is now either data (for shift count!=0) or
2062 0 (for shift count==0) */
2063 switch(curi->size) {
2064 case sz_byte: comprintf("\tshll_b_rr(data,cnt);\n"
2065 "\thighmask=0x38;\n");
2066 break;
2067 case sz_word: comprintf("\tshll_w_rr(data,cnt);\n"
2068 "\thighmask=0x30;\n");
2069 break;
2070 case sz_long: comprintf("\tshll_l_rr(data,cnt);\n"
2071 "\thighmask=0x20;\n");
2072 break;
2073 default: abort();
2074 }
2075 comprintf("test_l_ri(cnt,highmask);\n"
2076 "mov_l_ri(scratchie,0);\n"
2077 "cmov_l_rr(scratchie,data,4);\n");
2078 switch(curi->size) {
2079 case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break;
2080 case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break;
2081 case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break;
2082 default: abort();
2083 }
2084 /* Result of shift is now in data. Now we need to determine
2085 the carry by shifting cdata one less */
2086 comprintf("\tsub_l_ri(tmpcnt,1);\n");
2087 switch(curi->size) {
2088 case sz_byte: comprintf("\tshll_b_rr(cdata,tmpcnt);\n");break;
2089 case sz_word: comprintf("\tshll_w_rr(cdata,tmpcnt);\n");break;
2090 case sz_long: comprintf("\tshll_l_rr(cdata,tmpcnt);\n");break;
2091 default: abort();
2092 }
2093 comprintf("test_l_ri(tmpcnt,highmask);\n"
2094 "mov_l_ri(scratchie,0);\n"
2095 "cmov_l_rr(cdata,scratchie,5);\n");
2096 /* And create the flags */
2097 comprintf("\tstart_needflags();\n");
2098
2099 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2100 switch(curi->size) {
2101 case sz_byte: comprintf("\t test_b_rr(data,data);\n");
2102 comprintf("\t bt_l_ri(cdata,7);\n"); break;
2103 case sz_word: comprintf("\t test_w_rr(data,data);\n");
2104 comprintf("\t bt_l_ri(cdata,15);\n"); break;
2105 case sz_long: comprintf("\t test_l_rr(data,data);\n");
2106 comprintf("\t bt_l_ri(cdata,31);\n"); break;
2107 }
2108 comprintf("\t live_flags();\n");
2109 comprintf("\t end_needflags();\n");
2110 comprintf("\t duplicate_carry();\n");
2111 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2112 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2113 }
2114 else {
2115 uses_cmov;
2116 start_brace();
2117 comprintf("\tint highmask;\n");
2118 switch(curi->size) {
2119 case sz_byte: comprintf("\tshll_b_rr(data,cnt);\n"
2120 "\thighmask=0x38;\n");
2121 break;
2122 case sz_word: comprintf("\tshll_w_rr(data,cnt);\n"
2123 "\thighmask=0x30;\n");
2124 break;
2125 case sz_long: comprintf("\tshll_l_rr(data,cnt);\n"
2126 "\thighmask=0x20;\n");
2127 break;
2128 default: abort();
2129 }
2130 comprintf("test_l_ri(cnt,highmask);\n"
2131 "mov_l_ri(scratchie,0);\n"
2132 "cmov_l_rr(scratchie,data,4);\n");
2133 switch(curi->size) {
2134 case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break;
2135 case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break;
2136 case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break;
2137 default: abort();
2138 }
2139 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2140 }
2141 }
2142 else {
2143 start_brace();
2144 comprintf("\tint tmp=scratchie++;\n"
2145 "\tint bp;\n"
2146 "\tmov_l_rr(tmp,data);\n");
2147 switch(curi->size) {
2148 case sz_byte: comprintf("\tshll_b_ri(data,srcreg);\n"
2149 "\tbp=8-srcreg;\n"); break;
2150 case sz_word: comprintf("\tshll_w_ri(data,srcreg);\n"
2151 "\tbp=16-srcreg;\n"); break;
2152 case sz_long: comprintf("\tshll_l_ri(data,srcreg);\n"
2153 "\tbp=32-srcreg;\n"); break;
2154 default: abort();
2155 }
2156
2157 if (!noflags) {
2158 comprintf("\tstart_needflags();\n");
2159 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2160 switch(curi->size) {
2161 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2162 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2163 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2164 }
2165 comprintf("\t bt_l_ri(tmp,bp);\n"); /* Set C */
2166 comprintf("\t live_flags();\n");
2167 comprintf("\t end_needflags();\n");
2168 comprintf("\t duplicate_carry();\n");
2169 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2170 }
2171 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2172 }
2173 break;
2174
2175 case i_LSR:
2176 /* failure; /* NEW: from "Ipswitch Town" release */
2177 mayfail;
2178 if (curi->smode==Dreg) {
2179 comprintf("if ((uae_u32)srcreg==(uae_u32)dstreg) {\n"
2180 " FAIL(1);\n"
2181 " return;\n"
2182 "} \n");
2183 start_brace();
2184 }
2185 comprintf("\tdont_care_flags();\n");
2186
2187 genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
2188 genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
2189 if (curi->smode!=immi) {
2190 if (!noflags) {
2191 uses_cmov;
2192 start_brace();
2193 comprintf("\tint highmask;\n"
2194 "\tint cdata=scratchie++;\n"
2195 "\tint tmpcnt=scratchie++;\n");
2196 comprintf("\tmov_l_rr(tmpcnt,cnt);\n"
2197 "\tand_l_ri(tmpcnt,63);\n"
2198 "\tmov_l_ri(cdata,0);\n"
2199 "\tcmov_l_rr(cdata,data,5);\n");
2200 /* cdata is now either data (for shift count!=0) or
2201 0 (for shift count==0) */
2202 switch(curi->size) {
2203 case sz_byte: comprintf("\tshrl_b_rr(data,cnt);\n"
2204 "\thighmask=0x38;\n");
2205 break;
2206 case sz_word: comprintf("\tshrl_w_rr(data,cnt);\n"
2207 "\thighmask=0x30;\n");
2208 break;
2209 case sz_long: comprintf("\tshrl_l_rr(data,cnt);\n"
2210 "\thighmask=0x20;\n");
2211 break;
2212 default: abort();
2213 }
2214 comprintf("test_l_ri(cnt,highmask);\n"
2215 "mov_l_ri(scratchie,0);\n"
2216 "cmov_l_rr(scratchie,data,4);\n");
2217 switch(curi->size) {
2218 case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break;
2219 case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break;
2220 case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break;
2221 default: abort();
2222 }
2223 /* Result of shift is now in data. Now we need to determine
2224 the carry by shifting cdata one less */
2225 comprintf("\tsub_l_ri(tmpcnt,1);\n");
2226 switch(curi->size) {
2227 case sz_byte: comprintf("\tshrl_b_rr(cdata,tmpcnt);\n");break;
2228 case sz_word: comprintf("\tshrl_w_rr(cdata,tmpcnt);\n");break;
2229 case sz_long: comprintf("\tshrl_l_rr(cdata,tmpcnt);\n");break;
2230 default: abort();
2231 }
2232 comprintf("test_l_ri(tmpcnt,highmask);\n"
2233 "mov_l_ri(scratchie,0);\n"
2234 "cmov_l_rr(cdata,scratchie,5);\n");
2235 /* And create the flags */
2236 comprintf("\tstart_needflags();\n");
2237 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2238 switch(curi->size) {
2239 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2240 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2241 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2242 }
2243 comprintf("\t bt_l_ri(cdata,0);\n"); /* Set C */
2244 comprintf("\t live_flags();\n");
2245 comprintf("\t end_needflags();\n");
2246 comprintf("\t duplicate_carry();\n");
2247 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2248 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2249 }
2250 else {
2251 uses_cmov;
2252 start_brace();
2253 comprintf("\tint highmask;\n");
2254 switch(curi->size) {
2255 case sz_byte: comprintf("\tshrl_b_rr(data,cnt);\n"
2256 "\thighmask=0x38;\n");
2257 break;
2258 case sz_word: comprintf("\tshrl_w_rr(data,cnt);\n"
2259 "\thighmask=0x30;\n");
2260 break;
2261 case sz_long: comprintf("\tshrl_l_rr(data,cnt);\n"
2262 "\thighmask=0x20;\n");
2263 break;
2264 default: abort();
2265 }
2266 comprintf("test_l_ri(cnt,highmask);\n"
2267 "mov_l_ri(scratchie,0);\n"
2268 "cmov_l_rr(scratchie,data,4);\n");
2269 switch(curi->size) {
2270 case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break;
2271 case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break;
2272 case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break;
2273 default: abort();
2274 }
2275 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2276 }
2277 }
2278 else {
2279 start_brace();
2280 comprintf("\tint tmp=scratchie++;\n"
2281 "\tint bp;\n"
2282 "\tmov_l_rr(tmp,data);\n");
2283 switch(curi->size) {
2284 case sz_byte: comprintf("\tshrl_b_ri(data,srcreg);\n"
2285 "\tbp=srcreg-1;\n"); break;
2286 case sz_word: comprintf("\tshrl_w_ri(data,srcreg);\n"
2287 "\tbp=srcreg-1;\n"); break;
2288 case sz_long: comprintf("\tshrl_l_ri(data,srcreg);\n"
2289 "\tbp=srcreg-1;\n"); break;
2290 default: abort();
2291 }
2292
2293 if (!noflags) {
2294 comprintf("\tstart_needflags();\n");
2295 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2296 switch(curi->size) {
2297 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2298 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2299 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2300 }
2301 comprintf("\t bt_l_ri(tmp,bp);\n"); /* Set C */
2302 comprintf("\t live_flags();\n");
2303 comprintf("\t end_needflags();\n");
2304 comprintf("\t duplicate_carry();\n");
2305 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2306 }
2307 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2308 }
2309 break;
2310
2311 case i_LSL:
2312 mayfail;
2313 if (curi->smode==Dreg) {
2314 comprintf("if ((uae_u32)srcreg==(uae_u32)dstreg) {\n"
2315 " FAIL(1);\n"
2316 " return;\n"
2317 "} \n");
2318 start_brace();
2319 }
2320 comprintf("\tdont_care_flags();\n");
2321
2322 genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
2323 genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
2324 if (curi->smode!=immi) {
2325 /* failure; /* UNTESTED: NEW: from "Ipswitch Town" release */
2326 if (!noflags) {
2327 uses_cmov;
2328 start_brace();
2329 comprintf("\tint highmask;\n"
2330 "\tint cdata=scratchie++;\n"
2331 "\tint tmpcnt=scratchie++;\n");
2332 comprintf("\tmov_l_rr(tmpcnt,cnt);\n"
2333 "\tand_l_ri(tmpcnt,63);\n"
2334 "\tmov_l_ri(cdata,0);\n"
2335 "\tcmov_l_rr(cdata,data,5);\n");
2336 /* cdata is now either data (for shift count!=0) or
2337 0 (for shift count==0) */
2338 switch(curi->size) {
2339 case sz_byte: comprintf("\tshll_b_rr(data,cnt);\n"
2340 "\thighmask=0x38;\n");
2341 break;
2342 case sz_word: comprintf("\tshll_w_rr(data,cnt);\n"
2343 "\thighmask=0x30;\n");
2344 break;
2345 case sz_long: comprintf("\tshll_l_rr(data,cnt);\n"
2346 "\thighmask=0x20;\n");
2347 break;
2348 default: abort();
2349 }
2350 comprintf("test_l_ri(cnt,highmask);\n"
2351 "mov_l_ri(scratchie,0);\n"
2352 "cmov_l_rr(scratchie,data,4);\n");
2353 switch(curi->size) {
2354 case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break;
2355 case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break;
2356 case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break;
2357 default: abort();
2358 }
2359 /* Result of shift is now in data. Now we need to determine
2360 the carry by shifting cdata one less */
2361 comprintf("\tsub_l_ri(tmpcnt,1);\n");
2362 switch(curi->size) {
2363 case sz_byte: comprintf("\tshll_b_rr(cdata,tmpcnt);\n");break;
2364 case sz_word: comprintf("\tshll_w_rr(cdata,tmpcnt);\n");break;
2365 case sz_long: comprintf("\tshll_l_rr(cdata,tmpcnt);\n");break;
2366 default: abort();
2367 }
2368 comprintf("test_l_ri(tmpcnt,highmask);\n"
2369 "mov_l_ri(scratchie,0);\n"
2370 "cmov_l_rr(cdata,scratchie,5);\n");
2371 /* And create the flags */
2372 comprintf("\tstart_needflags();\n");
2373 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2374 switch(curi->size) {
2375 case sz_byte: comprintf("\t test_b_rr(data,data);\n");
2376 comprintf("\t bt_l_ri(cdata,7);\n"); break;
2377 case sz_word: comprintf("\t test_w_rr(data,data);\n");
2378 comprintf("\t bt_l_ri(cdata,15);\n"); break;
2379 case sz_long: comprintf("\t test_l_rr(data,data);\n");
2380 comprintf("\t bt_l_ri(cdata,31);\n"); break;
2381 }
2382 comprintf("\t live_flags();\n");
2383 comprintf("\t end_needflags();\n");
2384 comprintf("\t duplicate_carry();\n");
2385 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2386 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2387 }
2388 else {
2389 uses_cmov;
2390 start_brace();
2391 comprintf("\tint highmask;\n");
2392 switch(curi->size) {
2393 case sz_byte: comprintf("\tshll_b_rr(data,cnt);\n"
2394 "\thighmask=0x38;\n");
2395 break;
2396 case sz_word: comprintf("\tshll_w_rr(data,cnt);\n"
2397 "\thighmask=0x30;\n");
2398 break;
2399 case sz_long: comprintf("\tshll_l_rr(data,cnt);\n"
2400 "\thighmask=0x20;\n");
2401 break;
2402 default: abort();
2403 }
2404 comprintf("test_l_ri(cnt,highmask);\n"
2405 "mov_l_ri(scratchie,0);\n"
2406 "cmov_l_rr(scratchie,data,4);\n");
2407 switch(curi->size) {
2408 case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break;
2409 case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break;
2410 case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break;
2411 default: abort();
2412 }
2413 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2414 }
2415 }
2416 else {
2417 start_brace();
2418 comprintf("\tint tmp=scratchie++;\n"
2419 "\tint bp;\n"
2420 "\tmov_l_rr(tmp,data);\n");
2421 switch(curi->size) {
2422 case sz_byte: comprintf("\tshll_b_ri(data,srcreg);\n"
2423 "\tbp=8-srcreg;\n"); break;
2424 case sz_word: comprintf("\tshll_w_ri(data,srcreg);\n"
2425 "\tbp=16-srcreg;\n"); break;
2426 case sz_long: comprintf("\tshll_l_ri(data,srcreg);\n"
2427 "\tbp=32-srcreg;\n"); break;
2428 default: abort();
2429 }
2430
2431 if (!noflags) {
2432 comprintf("\tstart_needflags();\n");
2433 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2434 switch(curi->size) {
2435 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2436 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2437 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2438 }
2439 comprintf("\t bt_l_ri(tmp,bp);\n"); /* Set C */
2440 comprintf("\t live_flags();\n");
2441 comprintf("\t end_needflags();\n");
2442 comprintf("\t duplicate_carry();\n");
2443 comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n");
2444 }
2445 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2446 }
2447 break;
2448
2449 case i_ROL:
2450 mayfail;
2451 if (curi->smode==Dreg) {
2452 comprintf("if ((uae_u32)srcreg==(uae_u32)dstreg) {\n"
2453 " FAIL(1);\n"
2454 " return;\n"
2455 "} \n");
2456 start_brace();
2457 }
2458 comprintf("\tdont_care_flags();\n");
2459 genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
2460 genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
2461 start_brace ();
2462
2463 switch(curi->size) {
2464 case sz_long: comprintf("\t rol_l_rr(data,cnt);\n"); break;
2465 case sz_word: comprintf("\t rol_w_rr(data,cnt);\n"); break;
2466 case sz_byte: comprintf("\t rol_b_rr(data,cnt);\n"); break;
2467 }
2468
2469 if (!noflags) {
2470 comprintf("\tstart_needflags();\n");
2471 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2472 switch(curi->size) {
2473 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2474 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2475 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2476 }
2477 comprintf("\t bt_l_ri(data,0x00);\n"); /* Set C */
2478 comprintf("\t live_flags();\n");
2479 comprintf("\t end_needflags();\n");
2480 }
2481 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2482 break;
2483
2484 case i_ROR:
2485 mayfail;
2486 if (curi->smode==Dreg) {
2487 comprintf("if ((uae_u32)srcreg==(uae_u32)dstreg) {\n"
2488 " FAIL(1);\n"
2489 " return;\n"
2490 "} \n");
2491 start_brace();
2492 }
2493 comprintf("\tdont_care_flags();\n");
2494 genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
2495 genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
2496 start_brace ();
2497
2498 switch(curi->size) {
2499 case sz_long: comprintf("\t ror_l_rr(data,cnt);\n"); break;
2500 case sz_word: comprintf("\t ror_w_rr(data,cnt);\n"); break;
2501 case sz_byte: comprintf("\t ror_b_rr(data,cnt);\n"); break;
2502 }
2503
2504 if (!noflags) {
2505 comprintf("\tstart_needflags();\n");
2506 comprintf("\tif (needed_flags & FLAG_ZNV)\n");
2507 switch(curi->size) {
2508 case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break;
2509 case sz_word: comprintf("\t test_w_rr(data,data);\n"); break;
2510 case sz_long: comprintf("\t test_l_rr(data,data);\n"); break;
2511 }
2512 switch(curi->size) {
2513 case sz_byte: comprintf("\t bt_l_ri(data,0x07);\n"); break;
2514 case sz_word: comprintf("\t bt_l_ri(data,0x0f);\n"); break;
2515 case sz_long: comprintf("\t bt_l_ri(data,0x1f);\n"); break;
2516 }
2517 comprintf("\t live_flags();\n");
2518 comprintf("\t end_needflags();\n");
2519 }
2520 genastore ("data", curi->dmode, "dstreg", curi->size, "data");
2521 break;
2522
2523 case i_ROXL:
2524 failure;
2525 break;
2526 case i_ROXR:
2527 failure;
2528 break;
2529 case i_ASRW:
2530 failure;
2531 break;
2532 case i_ASLW:
2533 failure;
2534 break;
2535 case i_LSRW:
2536 failure;
2537 break;
2538 case i_LSLW:
2539 failure;
2540 break;
2541 case i_ROLW:
2542 failure;
2543 break;
2544 case i_RORW:
2545 failure;
2546 break;
2547 case i_ROXLW:
2548 failure;
2549 break;
2550 case i_ROXRW:
2551 failure;
2552 break;
2553 case i_MOVEC2:
2554 isjump;
2555 failure;
2556 break;
2557 case i_MOVE2C:
2558 isjump;
2559 failure;
2560 break;
2561 case i_CAS:
2562 failure;
2563 break;
2564 case i_CAS2:
2565 failure;
2566 break;
2567 case i_MOVES: /* ignore DFC and SFC because we have no MMU */
2568 isjump;
2569 failure;
2570 break;
2571 case i_BKPT: /* only needed for hardware emulators */
2572 isjump;
2573 failure;
2574 break;
2575 case i_CALLM: /* not present in 68030 */
2576 isjump;
2577 failure;
2578 break;
2579 case i_RTM: /* not present in 68030 */
2580 isjump;
2581 failure;
2582 break;
2583 case i_TRAPcc:
2584 isjump;
2585 failure;
2586 break;
2587 case i_DIVL:
2588 isjump;
2589 failure;
2590 break;
2591 case i_MULL:
2592 /* failure; /* NEW: from "Ipswitch Town" release */
2593 if (!noflags) {
2594 failure;
2595 break;
2596 }
2597 comprintf("\tuae_u16 extra=%s;\n",gen_nextiword());
2598 comprintf("\tint r2=(extra>>12)&7;\n"
2599 "\tint tmp=scratchie++;\n");
2600
2601 genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
2602 /* The two operands are in dst and r2 */
2603 comprintf("\tif (extra&0x0400) {\n" /* Need full 64 bit result */
2604 "\tint r3=(extra&7);\n"
2605 "\tmov_l_rr(r3,dst);\n"); /* operands now in r3 and r2 */
2606 comprintf("\tif (extra&0x0800) { \n" /* signed */
2607 "\t\timul_64_32(r2,r3);\n"
2608 "\t} else { \n"
2609 "\t\tmul_64_32(r2,r3);\n"
2610 "\t} \n");
2611 /* The result is in r2/tmp, with r2 holding the lower 32 bits */
2612 comprintf("\t} else {\n"); /* Only want 32 bit result */
2613 /* operands in dst and r2, result foes into r2 */
2614 /* shouldn't matter whether it's signed or unsigned?!? */
2615 comprintf("\timul_32_32(r2,dst);\n"
2616 "\t}\n");
2617 break;
2618
2619 case i_BFTST:
2620 case i_BFEXTU:
2621 case i_BFCHG:
2622 case i_BFEXTS:
2623 case i_BFCLR:
2624 case i_BFFFO:
2625 case i_BFSET:
2626 case i_BFINS:
2627 failure;
2628 break;
2629 case i_PACK:
2630 failure;
2631 break;
2632 case i_UNPK:
2633 failure;
2634 break;
2635 case i_TAS:
2636 failure;
2637 break;
2638 case i_FPP:
2639 uses_fpu;
2640 #ifdef USE_JIT_FPU
2641 mayfail;
2642 comprintf("\tuae_u16 extra=%s;\n",gen_nextiword());
2643 swap_opcode();
2644 comprintf("\tcomp_fpp_opp(opcode,extra);\n");
2645 #else
2646 failure;
2647 #endif
2648 break;
2649 case i_FBcc:
2650 uses_fpu;
2651 #ifdef USE_JIT_FPU
2652 isjump;
2653 uses_cmov;
2654 mayfail;
2655 swap_opcode();
2656 comprintf("\tcomp_fbcc_opp(opcode);\n");
2657 #else
2658 isjump;
2659 failure;
2660 #endif
2661 break;
2662 case i_FDBcc:
2663 uses_fpu;
2664 isjump;
2665 failure;
2666 break;
2667 case i_FScc:
2668 uses_fpu;
2669 #ifdef USE_JIT_FPU
2670 mayfail;
2671 uses_cmov;
2672 comprintf("\tuae_u16 extra=%s;\n",gen_nextiword());
2673 swap_opcode();
2674 comprintf("\tcomp_fscc_opp(opcode,extra);\n");
2675 #else
2676 failure;
2677 #endif
2678 break;
2679 case i_FTRAPcc:
2680 uses_fpu;
2681 isjump;
2682 failure;
2683 break;
2684 case i_FSAVE:
2685 uses_fpu;
2686 failure;
2687 break;
2688 case i_FRESTORE:
2689 uses_fpu;
2690 failure;
2691 break;
2692
2693 case i_CINVL:
2694 case i_CINVP:
2695 case i_CINVA:
2696 isjump; /* Not really, but it's probably a good idea to stop
2697 translating at this point */
2698 failure;
2699 comprintf ("\tflush_icache();\n"); /* Differentiate a bit more? */
2700 break;
2701 case i_CPUSHL:
2702 case i_CPUSHP:
2703 case i_CPUSHA:
2704 isjump; /* Not really, but it's probably a good idea to stop
2705 translating at this point */
2706 failure;
2707 break;
2708 case i_MOVE16:
2709 genmov16(opcode, curi);
2710 break;
2711
2712 case i_EMULOP_RETURN:
2713 isjump;
2714 failure;
2715 break;
2716
2717 case i_EMULOP:
2718 failure;
2719 break;
2720
2721 case i_MMUOP:
2722 isjump;
2723 failure;
2724 break;
2725 default:
2726 abort ();
2727 break;
2728 }
2729 comprintf("%s",endstr);
2730 finish_braces ();
2731 sync_m68k_pc ();
2732 if (global_mayfail)
2733 comprintf("\tif (failure) m68k_pc_offset=m68k_pc_offset_thisinst;\n");
2734 return global_failure;
2735 }
2736
2737 static void
2738 generate_includes (FILE * f)
2739 {
2740 fprintf (f, "#include \"sysdeps.h\"\n");
2741 fprintf (f, "#include \"m68k.h\"\n");
2742 fprintf (f, "#include \"memory.h\"\n");
2743 fprintf (f, "#include \"readcpu.h\"\n");
2744 fprintf (f, "#include \"newcpu.h\"\n");
2745 fprintf (f, "#include \"comptbl.h\"\n");
2746 }
2747
2748 static int postfix;
2749
2750 static void
2751 generate_one_opcode (int rp, int noflags)
2752 {
2753 int i;
2754 uae_u16 smsk, dmsk;
2755 long int opcode = opcode_map[rp];
2756 int aborted=0;
2757 int have_srcreg=0;
2758 int have_dstreg=0;
2759
2760 if (table68k[opcode].mnemo == i_ILLG
2761 || table68k[opcode].clev > cpu_level)
2762 return;
2763
2764 for (i = 0; lookuptab[i].name[0]; i++)
2765 {
2766 if (table68k[opcode].mnemo == lookuptab[i].mnemo)
2767 break;
2768 }
2769
2770 if (table68k[opcode].handler != -1)
2771 return;
2772
2773 switch (table68k[opcode].stype)
2774 {
2775 case 0:
2776 smsk = 7;
2777 break;
2778 case 1:
2779 smsk = 255;
2780 break;
2781 case 2:
2782 smsk = 15;
2783 break;
2784 case 3:
2785 smsk = 7;
2786 break;
2787 case 4:
2788 smsk = 7;
2789 break;
2790 case 5:
2791 smsk = 63;
2792 break;
2793 case 6:
2794 smsk = 255;
2795 break;
2796 case 7:
2797 smsk = 3;
2798 break;
2799 default:
2800 abort ();
2801 }
2802 dmsk = 7;
2803
2804 next_cpu_level = -1;
2805 if (table68k[opcode].suse
2806 && table68k[opcode].smode != imm && table68k[opcode].smode != imm0
2807 && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2
2808 && table68k[opcode].smode != absw && table68k[opcode].smode != absl
2809 && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16)
2810 {
2811 have_srcreg=1;
2812 if (table68k[opcode].spos == -1)
2813 {
2814 if (((int) table68k[opcode].sreg) >= 128)
2815 comprintf ("\tuae_s32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg);
2816 else
2817 comprintf ("\tuae_s32 srcreg = %d;\n", (int) table68k[opcode].sreg);
2818 }
2819 else
2820 {
2821 char source[100];
2822 int pos = table68k[opcode].spos;
2823
2824 comprintf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n");
2825
2826 if (pos < 8 && (smsk >> (8 - pos)) != 0)
2827 sprintf (source, "(((opcode >> %d) | (opcode << %d)) & %d)",
2828 pos ^ 8, 8 - pos, dmsk);
2829 else if (pos != 8)
2830 sprintf (source, "((opcode >> %d) & %d)", pos ^ 8, smsk);
2831 else
2832 sprintf (source, "(opcode & %d)", smsk);
2833
2834 if (table68k[opcode].stype == 3)
2835 comprintf ("\tuae_u32 srcreg = imm8_table[%s];\n", source);
2836 else if (table68k[opcode].stype == 1)
2837 comprintf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source);
2838 else
2839 comprintf ("\tuae_u32 srcreg = %s;\n", source);
2840
2841 comprintf ("#else\n");
2842
2843 if (pos)
2844 sprintf (source, "((opcode >> %d) & %d)", pos, smsk);
2845 else
2846 sprintf (source, "(opcode & %d)", smsk);
2847
2848 if (table68k[opcode].stype == 3)
2849 comprintf ("\tuae_s32 srcreg = imm8_table[%s];\n", source);
2850 else if (table68k[opcode].stype == 1)
2851 comprintf ("\tuae_s32 srcreg = (uae_s32)(uae_s8)%s;\n", source);
2852 else
2853 comprintf ("\tuae_s32 srcreg = %s;\n", source);
2854
2855 comprintf ("#endif\n");
2856 }
2857 }
2858 if (table68k[opcode].duse
2859 /* Yes, the dmode can be imm, in case of LINK or DBcc */
2860 && table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0
2861 && table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2
2862 && table68k[opcode].dmode != absw && table68k[opcode].dmode != absl)
2863 {
2864 have_dstreg=1;
2865 if (table68k[opcode].dpos == -1)
2866 {
2867 if (((int) table68k[opcode].dreg) >= 128)
2868 comprintf ("\tuae_s32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg);
2869 else
2870 comprintf ("\tuae_s32 dstreg = %d;\n", (int) table68k[opcode].dreg);
2871 }
2872 else
2873 {
2874 int pos = table68k[opcode].dpos;
2875
2876 comprintf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n");
2877
2878 if (pos < 8 && (dmsk >> (8 - pos)) != 0)
2879 comprintf ("\tuae_u32 dstreg = ((opcode >> %d) | (opcode << %d)) & %d;\n",
2880 pos ^ 8, 8 - pos, dmsk);
2881 else if (pos != 8)
2882 comprintf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n",
2883 pos ^ 8, dmsk);
2884 else
2885 comprintf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk);
2886
2887 comprintf ("#else\n");
2888
2889 if (pos)
2890 comprintf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n",
2891 pos, dmsk);
2892 else
2893 comprintf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk);
2894
2895 comprintf ("#endif\n");
2896 }
2897 }
2898
2899 if (have_srcreg && have_dstreg &&
2900 (table68k[opcode].dmode==Areg ||
2901 table68k[opcode].dmode==Aind ||
2902 table68k[opcode].dmode==Aipi ||
2903 table68k[opcode].dmode==Apdi ||
2904 table68k[opcode].dmode==Ad16 ||
2905 table68k[opcode].dmode==Ad8r) &&
2906 (table68k[opcode].smode==Areg ||
2907 table68k[opcode].smode==Aind ||
2908 table68k[opcode].smode==Aipi ||
2909 table68k[opcode].smode==Apdi ||
2910 table68k[opcode].smode==Ad16 ||
2911 table68k[opcode].smode==Ad8r)
2912 ) {
2913 comprintf("\tuae_u32 dodgy=(srcreg==(uae_s32)dstreg);\n");
2914 }
2915 else {
2916 comprintf("\tuae_u32 dodgy=0;\n");
2917 }
2918 comprintf("\tuae_u32 m68k_pc_offset_thisinst=m68k_pc_offset;\n");
2919 comprintf("\tm68k_pc_offset+=2;\n");
2920
2921 aborted=gen_opcode (opcode);
2922 {
2923 int flags=0;
2924 if (global_isjump) flags|=1;
2925 if (long_opcode) flags|=2;
2926 if (global_cmov) flags|=4;
2927 if (global_isaddx) flags|=8;
2928 if (global_iscjump) flags|=16;
2929 if (global_fpu) flags|=32;
2930
2931 comprintf ("}\n");
2932
2933 if (aborted) {
2934 fprintf (stblfile, "{ NULL, 0x%08x, %ld }, /* %s */\n", flags, opcode, lookuptab[i].name);
2935 com_discard();
2936 }
2937 else {
2938 if (noflags) {
2939 fprintf (stblfile, "{ op_%lx_%d_comp_nf, 0x%08x, %ld }, /* %s */\n", opcode, postfix, flags, opcode, lookuptab[i].name);
2940 fprintf (headerfile, "extern compop_func op_%lx_%d_comp_nf;\n", opcode, postfix);
2941 printf ("void REGPARAM2 op_%lx_%d_comp_nf(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2942 }
2943 else {
2944 fprintf (stblfile, "{ op_%lx_%d_comp_ff, 0x%08x, %ld }, /* %s */\n", opcode, postfix, flags, opcode, lookuptab[i].name);
2945 fprintf (headerfile, "extern compop_func op_%lx_%d_comp_ff;\n", opcode, postfix);
2946 printf ("void REGPARAM2 op_%lx_%d_comp_ff(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2947 }
2948 com_flush();
2949 }
2950 }
2951 opcode_next_clev[rp] = next_cpu_level;
2952 opcode_last_postfix[rp] = postfix;
2953 }
2954
2955 static void
2956 generate_func (int noflags)
2957 {
2958 int i, j, rp;
2959
2960 using_prefetch = 0;
2961 using_exception_3 = 0;
2962 for (i = 0; i < 1; i++) /* We only do one level! */
2963 {
2964 cpu_level = 4 - i;
2965 postfix = i;
2966
2967 if (noflags)
2968 fprintf (stblfile, "struct comptbl op_smalltbl_%d_comp_nf[] = {\n", postfix);
2969 else
2970 fprintf (stblfile, "struct comptbl op_smalltbl_%d_comp_ff[] = {\n", postfix);
2971
2972
2973 /* sam: this is for people with low memory (eg. me :)) */
2974 !printf ("\n"
2975 "#if !defined(PART_1) && !defined(PART_2) && "
2976 "!defined(PART_3) && !defined(PART_4) && "
2977 "!defined(PART_5) && !defined(PART_6) && "
2978 "!defined(PART_7) && !defined(PART_8)"
2979 "\n"
2980 "#define PART_1 1\n"
2981 "#define PART_2 1\n"
2982 "#define PART_3 1\n"
2983 "#define PART_4 1\n"
2984 "#define PART_5 1\n"
2985 "#define PART_6 1\n"
2986 "#define PART_7 1\n"
2987 "#define PART_8 1\n"
2988 "#endif\n\n");
2989
2990 rp = 0;
2991 for (j = 1; j <= 8; ++j)
2992 {
2993 int k = (j * nr_cpuop_funcs) / 8;
2994 printf ("#ifdef PART_%d\n", j);
2995 for (; rp < k; rp++)
2996 generate_one_opcode (rp,noflags);
2997 printf ("#endif\n\n");
2998 }
2999
3000 fprintf (stblfile, "{ 0, 0,65536 }};\n");
3001 }
3002
3003 }
3004
3005 int
3006 main (int argc, char **argv)
3007 {
3008 read_table68k ();
3009 do_merges ();
3010
3011 opcode_map = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
3012 opcode_last_postfix = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
3013 opcode_next_clev = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
3014 counts = (unsigned long *) malloc (65536 * sizeof (unsigned long));
3015 read_counts ();
3016
3017 /* It would be a lot nicer to put all in one file (we'd also get rid of
3018 * cputbl.h that way), but cpuopti can't cope. That could be fixed, but
3019 * I don't dare to touch the 68k version. */
3020
3021 headerfile = fopen ("comptbl.h", "wb");
3022 stblfile = fopen ("compstbl.cpp", "wb");
3023 freopen ("compemu.cpp", "wb", stdout);
3024
3025 generate_includes (stdout);
3026 generate_includes (stblfile);
3027
3028 printf("#include \"compiler/compemu.h\"\n");
3029
3030 noflags=0;
3031 generate_func (noflags);
3032
3033 free(opcode_map);
3034 free(opcode_last_postfix);
3035 free(opcode_next_clev);
3036 free(counts);
3037
3038 opcode_map = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
3039 opcode_last_postfix = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
3040 opcode_next_clev = (int *) malloc (sizeof (int) * nr_cpuop_funcs);
3041 counts = (unsigned long *) malloc (65536 * sizeof (unsigned long));
3042 read_counts ();
3043 noflags=1;
3044 generate_func (noflags);
3045
3046 free(opcode_map);
3047 free(opcode_last_postfix);
3048 free(opcode_next_clev);
3049 free(counts);
3050
3051 free (table68k);
3052 fclose (stblfile);
3053 fclose (headerfile);
3054 return 0;
3055 }