Annotation of uae/src/gencpu.c, revision 1.1.1.15

1.1.1.3   root        1: /*
1.1       root        2:  * UAE - The Un*x Amiga Emulator
                      3:  *
                      4:  * MC68000 emulation generator
                      5:  *
1.1.1.3   root        6:  * This is a fairly stupid program that generates a lot of case labels that
1.1       root        7:  * can be #included in a switch statement.
                      8:  * As an alternative, it can generate functions that handle specific
                      9:  * MC68000 instructions, plus a prototype header file and a function pointer
                     10:  * array to look up the function for an opcode.
                     11:  * Error checking is bad, an illegal table68k file will cause the program to
                     12:  * call abort().
1.1.1.3   root       13:  * The generated code is sometimes sub-optimal, an optimizing compiler should
1.1       root       14:  * take care of this.
1.1.1.3   root       15:  *
1.1.1.11  root       16:  * The source for the insn timings is Markt & Technik's Amiga Magazin 8/1992.
                     17:  *
                     18:  * Copyright 1995, 1996, 1997, 1998, 1999, 2000 Bernd Schmidt
1.1       root       19:  */
                     20: 
                     21: #include "sysconfig.h"
                     22: #include "sysdeps.h"
                     23: #include <ctype.h>
                     24: 
                     25: #include "readcpu.h"
                     26: 
                     27: #define BOOL_TYPE "int"
                     28: 
1.1.1.3   root       29: static FILE *headerfile;
                     30: static FILE *stblfile;
                     31: 
                     32: static int using_prefetch;
                     33: static int using_exception_3;
                     34: static int cpu_level;
                     35: 
                     36: /* For the current opcode, the next lower level that will have different code.
                     37:  * Initialized to -1 for each opcode. If it remains unchanged, indicates we
                     38:  * are done with that opcode.  */
                     39: static int next_cpu_level;
1.1       root       40: 
1.1.1.3   root       41: static int *opcode_map;
                     42: static int *opcode_next_clev;
                     43: static int *opcode_last_postfix;
                     44: static unsigned long *counts;
                     45: 
1.1.1.5   root       46: static void read_counts (void)
1.1       root       47: {
                     48:     FILE *file;
1.1.1.5   root       49:     unsigned long opcode, count, total;
1.1       root       50:     char name[20];
1.1.1.5   root       51:     int nr = 0;
1.1.1.3   root       52:     memset (counts, 0, 65536 * sizeof *counts);
1.1       root       53: 
1.1.1.3   root       54:     file = fopen ("frequent.68k", "r");
                     55:     if (file) {
                     56:        fscanf (file, "Total: %lu\n", &total);
1.1.1.5   root       57:        while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) {
1.1.1.12  root       58:            opcode_next_clev[nr] = 4;
1.1.1.3   root       59:            opcode_last_postfix[nr] = -1;
                     60:            opcode_map[nr++] = opcode;
                     61:            counts[opcode] = count;
                     62:        }
                     63:        fclose (file);
                     64:     }
                     65:     if (nr == nr_cpuop_funcs)
                     66:        return;
                     67:     for (opcode = 0; opcode < 0x10000; opcode++) {
                     68:        if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
                     69:            && counts[opcode] == 0)
1.1       root       70:        {
1.1.1.12  root       71:            opcode_next_clev[nr] = 4;
1.1.1.3   root       72:            opcode_last_postfix[nr] = -1;
                     73:            opcode_map[nr++] = opcode;
                     74:            counts[opcode] = count;
1.1       root       75:        }
                     76:     }
1.1.1.3   root       77:     if (nr != nr_cpuop_funcs)
                     78:        abort ();
1.1       root       79: }
                     80: 
1.1.1.3   root       81: static char endlabelstr[80];
                     82: static int endlabelno = 0;
1.1.1.5   root       83: static int need_endlabel;
1.1       root       84: 
                     85: static int n_braces = 0;
1.1.1.3   root       86: static int m68k_pc_offset = 0;
1.1.1.5   root       87: static int insn_n_cycles;
1.1       root       88: 
1.1.1.5   root       89: static void start_brace (void)
1.1       root       90: {
                     91:     n_braces++;
1.1.1.3   root       92:     printf ("{");
1.1       root       93: }
                     94: 
1.1.1.5   root       95: static void close_brace (void)
1.1       root       96: {
                     97:     assert (n_braces > 0);
                     98:     n_braces--;
1.1.1.3   root       99:     printf ("}");
1.1       root      100: }
                    101: 
1.1.1.5   root      102: static void finish_braces (void)
1.1       root      103: {
                    104:     while (n_braces > 0)
1.1.1.5   root      105:        close_brace ();
1.1       root      106: }
                    107: 
1.1.1.5   root      108: static void pop_braces (int to)
1.1       root      109: {
                    110:     while (n_braces > to)
1.1.1.5   root      111:        close_brace ();
1.1       root      112: }
                    113: 
1.1.1.5   root      114: static int bit_size (int size)
1.1       root      115: {
1.1.1.5   root      116:     switch (size) {
                    117:      case sz_byte: return 8;
                    118:      case sz_word: return 16;
                    119:      case sz_long: return 32;
                    120:      default: abort ();
1.1       root      121:     }
                    122:     return 0;
                    123: }
                    124: 
1.1.1.5   root      125: static const char *bit_mask (int size)
1.1       root      126: {
1.1.1.5   root      127:     switch (size) {
1.1.1.3   root      128:      case sz_byte: return "0xff";
                    129:      case sz_word: return "0xffff";
                    130:      case sz_long: return "0xffffffff";
1.1.1.5   root      131:      default: abort ();
1.1       root      132:     }
                    133:     return 0;
                    134: }
                    135: 
1.1.1.3   root      136: static const char *gen_nextilong (void)
                    137: {
                    138:     static char buffer[80];
                    139:     int r = m68k_pc_offset;
                    140:     m68k_pc_offset += 4;
1.1.1.5   root      141: 
1.1.1.11  root      142:     insn_n_cycles += 8;
1.1.1.5   root      143: 
                    144:     if (using_prefetch)
                    145:        sprintf (buffer, "get_ilong_prefetch(%d)", r);
                    146:     else
                    147:        sprintf (buffer, "get_ilong(%d)", r);
1.1.1.3   root      148:     return buffer;
                    149: }
                    150: 
                    151: static const char *gen_nextiword (void)
                    152: {
                    153:     static char buffer[80];
                    154:     int r = m68k_pc_offset;
                    155:     m68k_pc_offset += 2;
1.1.1.5   root      156: 
1.1.1.11  root      157:     insn_n_cycles += 4;
1.1.1.5   root      158: 
                    159:     if (using_prefetch)
                    160:        sprintf (buffer, "get_iword_prefetch(%d)", r);
                    161:     else
                    162:        sprintf (buffer, "get_iword(%d)", r);
1.1.1.3   root      163:     return buffer;
                    164: }
                    165: 
                    166: static const char *gen_nextibyte (void)
                    167: {
                    168:     static char buffer[80];
                    169:     int r = m68k_pc_offset;
                    170:     m68k_pc_offset += 2;
1.1.1.5   root      171: 
1.1.1.11  root      172:     insn_n_cycles += 4;
1.1.1.5   root      173: 
                    174:     if (using_prefetch)
                    175:        sprintf (buffer, "get_ibyte_prefetch(%d)", r);
                    176:     else
                    177:        sprintf (buffer, "get_ibyte(%d)", r);
1.1.1.3   root      178:     return buffer;
                    179: }
                    180: 
                    181: static void fill_prefetch_0 (void)
                    182: {
                    183:     if (using_prefetch)
                    184:        printf ("fill_prefetch_0 ();\n");
                    185: }
                    186: 
                    187: static void fill_prefetch_2 (void)
                    188: {
                    189:     if (using_prefetch)
                    190:        printf ("fill_prefetch_2 ();\n");
                    191: }
                    192: 
                    193: static void sync_m68k_pc (void)
                    194: {
                    195:     if (m68k_pc_offset == 0)
                    196:        return;
                    197:     printf ("m68k_incpc(%d);\n", m68k_pc_offset);
                    198:     switch (m68k_pc_offset) {
                    199:      case 0:
1.1.1.5   root      200:        /*fprintf (stderr, "refilling prefetch at 0\n"); */
1.1.1.3   root      201:        break;
                    202:      case 2:
1.1.1.5   root      203:        fill_prefetch_2 ();
1.1.1.3   root      204:        break;
                    205:      default:
1.1.1.5   root      206:        fill_prefetch_0 ();
1.1.1.3   root      207:        break;
                    208:     }
                    209:     m68k_pc_offset = 0;
                    210: }
                    211: 
                    212: /* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
1.1.1.14  root      213:  * the calling routine handles Apdi and Aipi modes.
                    214:  * gb-- movem == 2 means the same thing but for a MOVE16 instruction */
1.1.1.3   root      215: static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem)
1.1       root      216: {
1.1.1.6   root      217:     start_brace ();
1.1.1.5   root      218:     switch (mode) {
1.1.1.11  root      219:     case Dreg:
1.1       root      220:        if (movem)
1.1.1.5   root      221:            abort ();
1.1.1.3   root      222:        if (getv == 1)
1.1.1.5   root      223:            switch (size) {
1.1.1.11  root      224:            case sz_byte:
1.1.1.8   root      225: #if defined(AMIGA) && !defined(WARPUP)
1.1.1.2   root      226:                /* sam: I don't know why gcc.2.7.2.1 produces a code worse */
                    227:                /* if it is not done like that: */
1.1.1.3   root      228:                printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg(regs, %s))[3];\n", name, reg);
1.1.1.2   root      229: #else
1.1.1.3   root      230:                printf ("\tuae_s8 %s = m68k_dreg(regs, %s);\n", name, reg);
1.1.1.2   root      231: #endif
1.1       root      232:                break;
1.1.1.11  root      233:            case sz_word:
1.1.1.8   root      234: #if defined(AMIGA) && !defined(WARPUP)
1.1.1.3   root      235:                printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg(regs, %s))[1];\n", name, reg);
1.1.1.2   root      236: #else
1.1.1.3   root      237:                printf ("\tuae_s16 %s = m68k_dreg(regs, %s);\n", name, reg);
1.1.1.2   root      238: #endif
1.1       root      239:                break;
1.1.1.11  root      240:            case sz_long:
1.1.1.3   root      241:                printf ("\tuae_s32 %s = m68k_dreg(regs, %s);\n", name, reg);
1.1       root      242:                break;
1.1.1.11  root      243:            default:
1.1.1.5   root      244:                abort ();
1.1       root      245:            }
1.1.1.3   root      246:        return;
1.1.1.11  root      247:     case Areg:
1.1       root      248:        if (movem)
1.1.1.5   root      249:            abort ();
1.1.1.3   root      250:        if (getv == 1)
1.1.1.5   root      251:            switch (size) {
1.1.1.11  root      252:            case sz_word:
1.1.1.3   root      253:                printf ("\tuae_s16 %s = m68k_areg(regs, %s);\n", name, reg);
1.1       root      254:                break;
1.1.1.11  root      255:            case sz_long:
1.1.1.3   root      256:                printf ("\tuae_s32 %s = m68k_areg(regs, %s);\n", name, reg);
1.1       root      257:                break;
1.1.1.11  root      258:            default:
1.1.1.5   root      259:                abort ();
1.1       root      260:            }
1.1.1.3   root      261:        return;
1.1.1.11  root      262:     case Aind:
1.1.1.3   root      263:        printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg);
1.1       root      264:        break;
1.1.1.11  root      265:     case Aipi:
1.1.1.3   root      266:        printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg);
1.1       root      267:        break;
1.1.1.11  root      268:     case Apdi:
                    269:        insn_n_cycles += 2;
1.1.1.5   root      270:        switch (size) {
1.1.1.11  root      271:        case sz_byte:
1.1.1.3   root      272:            if (movem)
                    273:                printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg);
                    274:            else
                    275:                printf ("\tuaecptr %sa = m68k_areg(regs, %s) - areg_byteinc[%s];\n", name, reg, reg);
1.1       root      276:            break;
1.1.1.11  root      277:        case sz_word:
1.1.1.3   root      278:            printf ("\tuaecptr %sa = m68k_areg(regs, %s) - %d;\n", name, reg, movem ? 0 : 2);
1.1       root      279:            break;
1.1.1.11  root      280:        case sz_long:
1.1.1.3   root      281:            printf ("\tuaecptr %sa = m68k_areg(regs, %s) - %d;\n", name, reg, movem ? 0 : 4);
1.1       root      282:            break;
1.1.1.11  root      283:        default:
1.1.1.5   root      284:            abort ();
1.1       root      285:        }
                    286:        break;
1.1.1.11  root      287:     case Ad16:
1.1.1.5   root      288:        printf ("\tuaecptr %sa = m68k_areg(regs, %s) + (uae_s32)(uae_s16)%s;\n", name, reg, gen_nextiword ());
1.1       root      289:        break;
1.1.1.11  root      290:     case Ad8r:
                    291:        insn_n_cycles += 2;
1.1.1.3   root      292:        if (cpu_level > 1) {
                    293:            if (next_cpu_level < 1)
                    294:                next_cpu_level = 1;
1.1.1.5   root      295:            sync_m68k_pc ();
                    296:            start_brace ();
1.1.1.11  root      297:            /* This would ordinarily be done in gen_nextiword, which we bypass.  */
                    298:            insn_n_cycles += 4;
1.1.1.3   root      299:            printf ("\tuaecptr %sa = get_disp_ea_020(m68k_areg(regs, %s), next_iword());\n", name, reg);
1.1.1.6   root      300:        } else
1.1.1.5   root      301:            printf ("\tuaecptr %sa = get_disp_ea_000(m68k_areg(regs, %s), %s);\n", name, reg, gen_nextiword ());
1.1.1.6   root      302: 
1.1       root      303:        break;
1.1.1.11  root      304:     case PC16:
1.1.1.6   root      305:        printf ("\tuaecptr %sa = m68k_getpc () + %d;\n", name, m68k_pc_offset);
                    306:        printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ());
1.1       root      307:        break;
1.1.1.11  root      308:     case PC8r:
                    309:        insn_n_cycles += 2;
1.1.1.3   root      310:        if (cpu_level > 1) {
                    311:            if (next_cpu_level < 1)
                    312:                next_cpu_level = 1;
1.1.1.5   root      313:            sync_m68k_pc ();
                    314:            start_brace ();
1.1.1.11  root      315:            /* This would ordinarily be done in gen_nextiword, which we bypass.  */
                    316:            insn_n_cycles += 4;
1.1.1.3   root      317:            printf ("\tuaecptr tmppc = m68k_getpc();\n");
                    318:            printf ("\tuaecptr %sa = get_disp_ea_020(tmppc, next_iword());\n", name);
                    319:        } else {
1.1.1.6   root      320:            printf ("\tuaecptr tmppc = m68k_getpc() + %d;\n", m68k_pc_offset);
                    321:            printf ("\tuaecptr %sa = get_disp_ea_000(tmppc, %s);\n", name, gen_nextiword ());
1.1       root      322:        }
1.1.1.3   root      323: 
1.1       root      324:        break;
1.1.1.11  root      325:     case absw:
1.1.1.6   root      326:        printf ("\tuaecptr %sa = (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ());
1.1       root      327:        break;
1.1.1.11  root      328:     case absl:
1.1.1.6   root      329:        printf ("\tuaecptr %sa = %s;\n", name, gen_nextilong ());
1.1       root      330:        break;
1.1.1.11  root      331:     case imm:
1.1.1.3   root      332:        if (getv != 1)
                    333:            abort ();
1.1.1.5   root      334:        switch (size) {
1.1.1.11  root      335:        case sz_byte:
1.1.1.6   root      336:            printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ());
1.1.1.3   root      337:            break;
1.1.1.11  root      338:        case sz_word:
1.1.1.6   root      339:            printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ());
1.1.1.3   root      340:            break;
1.1.1.11  root      341:        case sz_long:
1.1.1.6   root      342:            printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ());
1.1.1.3   root      343:            break;
1.1.1.11  root      344:        default:
1.1.1.5   root      345:            abort ();
1.1.1.3   root      346:        }
                    347:        return;
1.1.1.11  root      348:     case imm0:
1.1.1.5   root      349:        if (getv != 1)
                    350:            abort ();
1.1.1.6   root      351:        printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ());
1.1.1.3   root      352:        return;
1.1.1.11  root      353:     case imm1:
1.1.1.5   root      354:        if (getv != 1)
                    355:            abort ();
1.1.1.6   root      356:        printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ());
1.1.1.3   root      357:        return;
1.1.1.11  root      358:     case imm2:
1.1.1.5   root      359:        if (getv != 1)
                    360:            abort ();
1.1.1.6   root      361:        printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ());
1.1.1.3   root      362:        return;
1.1.1.11  root      363:     case immi:
1.1.1.5   root      364:        if (getv != 1)
                    365:            abort ();
1.1.1.3   root      366:        printf ("\tuae_u32 %s = %s;\n", name, reg);
                    367:        return;
1.1.1.11  root      368:     default:
1.1.1.5   root      369:        abort ();
1.1.1.3   root      370:     }
                    371: 
                    372:     /* We get here for all non-reg non-immediate addressing modes to
                    373:      * actually fetch the value. */
                    374: 
1.1.1.6   root      375:     if (using_exception_3 && getv != 0 && size != sz_byte) {       
1.1.1.3   root      376:        printf ("\tif ((%sa & 1) != 0) {\n", name);
                    377:        printf ("\t\tlast_fault_for_exception_3 = %sa;\n", name);
1.1.1.5   root      378:        printf ("\t\tlast_op_for_exception_3 = opcode;\n");
1.1.1.3   root      379:        printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + %d;\n", m68k_pc_offset);
                    380:        printf ("\t\tException(3, 0);\n");
                    381:        printf ("\t\tgoto %s;\n", endlabelstr);
                    382:        printf ("\t}\n");
1.1.1.5   root      383:        need_endlabel = 1;
1.1.1.3   root      384:        start_brace ();
                    385:     }
1.1.1.6   root      386: 
                    387:     if (getv == 1) {
                    388:        switch (size) {
1.1.1.11  root      389:        case sz_byte: insn_n_cycles += 4; break;
                    390:        case sz_word: insn_n_cycles += 4; break;
                    391:        case sz_long: insn_n_cycles += 8; break;
                    392:        default: abort ();
1.1.1.6   root      393:        }
                    394:        start_brace ();
                    395:        switch (size) {
1.1.1.11  root      396:        case sz_byte: printf ("\tuae_s8 %s = get_byte(%sa);\n", name, name); break;
                    397:        case sz_word: printf ("\tuae_s16 %s = get_word(%sa);\n", name, name); break;
                    398:        case sz_long: printf ("\tuae_s32 %s = get_long(%sa);\n", name, name); break;
                    399:        default: abort ();
1.1.1.6   root      400:        }
                    401:     }
                    402: 
1.1.1.3   root      403:     /* We now might have to fix up the register for pre-dec or post-inc
                    404:      * addressing modes. */
                    405:     if (!movem)
                    406:        switch (mode) {
1.1.1.11  root      407:        case Aipi:
1.1.1.5   root      408:            switch (size) {
1.1.1.11  root      409:            case sz_byte:
1.1.1.3   root      410:                printf ("\tm68k_areg(regs, %s) += areg_byteinc[%s];\n", reg, reg);
1.1       root      411:                break;
1.1.1.11  root      412:            case sz_word:
1.1.1.3   root      413:                printf ("\tm68k_areg(regs, %s) += 2;\n", reg);
1.1       root      414:                break;
1.1.1.11  root      415:            case sz_long:
1.1.1.3   root      416:                printf ("\tm68k_areg(regs, %s) += 4;\n", reg);
1.1       root      417:                break;
1.1.1.11  root      418:            default:
1.1.1.5   root      419:                abort ();
1.1       root      420:            }
1.1.1.3   root      421:            break;
1.1.1.11  root      422:        case Apdi:
1.1.1.3   root      423:            printf ("\tm68k_areg (regs, %s) = %sa;\n", reg, name);
                    424:            break;
1.1.1.11  root      425:        default:
1.1.1.3   root      426:            break;
                    427:        }
1.1       root      428: }
                    429: 
1.1.1.3   root      430: static void genastore (char *from, amodes mode, char *reg, wordsizes size, char *to)
1.1       root      431: {
1.1.1.5   root      432:     switch (mode) {
1.1       root      433:      case Dreg:
1.1.1.5   root      434:        switch (size) {
1.1       root      435:         case sz_byte:
1.1.1.3   root      436:            printf ("\tm68k_dreg(regs, %s) = (m68k_dreg(regs, %s) & ~0xff) | ((%s) & 0xff);\n", reg, reg, from);
1.1       root      437:            break;
                    438:         case sz_word:
1.1.1.3   root      439:            printf ("\tm68k_dreg(regs, %s) = (m68k_dreg(regs, %s) & ~0xffff) | ((%s) & 0xffff);\n", reg, reg, from);
1.1       root      440:            break;
                    441:         case sz_long:
1.1.1.3   root      442:            printf ("\tm68k_dreg(regs, %s) = (%s);\n", reg, from);
1.1       root      443:            break;
1.1.1.5   root      444:         default:
                    445:            abort ();
1.1       root      446:        }
                    447:        break;
                    448:      case Areg:
1.1.1.5   root      449:        switch (size) {
1.1       root      450:         case sz_word:
1.1.1.3   root      451:            fprintf (stderr, "Foo\n");
                    452:            printf ("\tm68k_areg(regs, %s) = (uae_s32)(uae_s16)(%s);\n", reg, from);
1.1       root      453:            break;
                    454:         case sz_long:
1.1.1.3   root      455:            printf ("\tm68k_areg(regs, %s) = (%s);\n", reg, from);
1.1       root      456:            break;
1.1.1.5   root      457:         default:
                    458:            abort ();
1.1       root      459:        }
                    460:        break;
                    461:      case Aind:
                    462:      case Aipi:
                    463:      case Apdi:
                    464:      case Ad16:
                    465:      case Ad8r:
                    466:      case absw:
                    467:      case absl:
                    468:      case PC16:
                    469:      case PC8r:
1.1.1.3   root      470:        if (using_prefetch)
1.1.1.5   root      471:            sync_m68k_pc ();
                    472:        switch (size) {
1.1       root      473:         case sz_byte:
1.1.1.11  root      474:            insn_n_cycles += 4;
1.1.1.3   root      475:            printf ("\tput_byte(%sa,%s);\n", to, from);
1.1       root      476:            break;
                    477:         case sz_word:
1.1.1.11  root      478:            insn_n_cycles += 4;
1.1.1.5   root      479:            if (cpu_level < 2 && (mode == PC16 || mode == PC8r))
                    480:                abort ();
1.1.1.3   root      481:            printf ("\tput_word(%sa,%s);\n", to, from);
1.1       root      482:            break;
                    483:         case sz_long:
1.1.1.11  root      484:            insn_n_cycles += 8;
1.1.1.5   root      485:            if (cpu_level < 2 && (mode == PC16 || mode == PC8r))
                    486:                abort ();
1.1.1.3   root      487:            printf ("\tput_long(%sa,%s);\n", to, from);
1.1       root      488:            break;
1.1.1.5   root      489:         default:
                    490:            abort ();
1.1       root      491:        }
                    492:        break;
                    493:      case imm:
                    494:      case imm0:
                    495:      case imm1:
                    496:      case imm2:
                    497:      case immi:
1.1.1.5   root      498:        abort ();
1.1       root      499:        break;
1.1.1.3   root      500:      default:
1.1.1.5   root      501:        abort ();
1.1       root      502:     }
                    503: }
                    504: 
1.1.1.5   root      505: static void genmovemel (uae_u16 opcode)
1.1       root      506: {
                    507:     char getcode[100];
                    508:     int size = table68k[opcode].size == sz_long ? 4 : 2;
1.1.1.3   root      509: 
                    510:     if (table68k[opcode].size == sz_long) {
1.1.1.5   root      511:        strcpy (getcode, "get_long(srca)");
1.1.1.3   root      512:     } else {
1.1.1.5   root      513:        strcpy (getcode, "(uae_s32)(uae_s16)get_word(srca)");
1.1       root      514:     }
1.1.1.3   root      515: 
1.1.1.5   root      516:     printf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
1.1.1.3   root      517:     printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n");
                    518:     genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
1.1.1.5   root      519:     start_brace ();
1.1.1.3   root      520:     printf ("\twhile (dmask) { m68k_dreg(regs, movem_index1[dmask]) = %s; srca += %d; dmask = movem_next[dmask]; }\n",
1.1.1.5   root      521:            getcode, size);
1.1.1.3   root      522:     printf ("\twhile (amask) { m68k_areg(regs, movem_index1[amask]) = %s; srca += %d; amask = movem_next[amask]; }\n",
1.1.1.5   root      523:            getcode, size);
1.1       root      524: 
                    525:     if (table68k[opcode].dmode == Aipi)
1.1.1.3   root      526:        printf ("\tm68k_areg(regs, dstreg) = srca;\n");
1.1       root      527: }
                    528: 
1.1.1.5   root      529: static void genmovemle (uae_u16 opcode)
1.1       root      530: {
                    531:     char putcode[100];
                    532:     int size = table68k[opcode].size == sz_long ? 4 : 2;
                    533:     if (table68k[opcode].size == sz_long) {
1.1.1.5   root      534:        strcpy (putcode, "put_long(srca,");
1.1.1.3   root      535:     } else {
1.1.1.5   root      536:        strcpy (putcode, "put_word(srca,");
1.1       root      537:     }
1.1.1.3   root      538: 
1.1.1.5   root      539:     printf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
1.1.1.3   root      540:     genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
                    541:     if (using_prefetch)
1.1.1.5   root      542:        sync_m68k_pc ();
1.1.1.3   root      543: 
1.1.1.5   root      544:     start_brace ();
1.1       root      545:     if (table68k[opcode].dmode == Apdi) {
1.1.1.3   root      546:        printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n");
                    547:        printf ("\twhile (amask) { srca -= %d; %s m68k_areg(regs, movem_index2[amask])); amask = movem_next[amask]; }\n",
1.1.1.5   root      548:                size, putcode);
1.1.1.3   root      549:        printf ("\twhile (dmask) { srca -= %d; %s m68k_dreg(regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n",
1.1.1.5   root      550:                size, putcode);
1.1.1.3   root      551:        printf ("\tm68k_areg(regs, dstreg) = srca;\n");
1.1.1.2   root      552:     } else {
1.1.1.3   root      553:        printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n");
                    554:        printf ("\twhile (dmask) { %s m68k_dreg(regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n",
1.1.1.5   root      555:                putcode, size);
1.1.1.3   root      556:        printf ("\twhile (amask) { %s m68k_areg(regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n",
1.1.1.5   root      557:                putcode, size);
1.1       root      558:     }
                    559: }
                    560: 
1.1.1.7   root      561: static void duplicate_carry (void)
                    562: {
                    563:     printf ("\tCOPY_CARRY;\n");
                    564: }
                    565: 
1.1.1.12  root      566: typedef enum
                    567: {
                    568:   flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_zn,
                    569:   flag_av, flag_sv
                    570: }
                    571: flagtypes;
1.1       root      572: 
1.1.1.5   root      573: static void genflags_normal (flagtypes type, wordsizes size, char *value, char *src, char *dst)
1.1       root      574: {
1.1.1.5   root      575:     char vstr[100], sstr[100], dstr[100];
                    576:     char usstr[100], udstr[100];
                    577:     char unsstr[100], undstr[100];
1.1       root      578: 
1.1.1.5   root      579:     switch (size) {
1.1       root      580:      case sz_byte:
1.1.1.5   root      581:        strcpy (vstr, "((uae_s8)(");
                    582:        strcpy (usstr, "((uae_u8)(");
1.1       root      583:        break;
                    584:      case sz_word:
1.1.1.5   root      585:        strcpy (vstr, "((uae_s16)(");
                    586:        strcpy (usstr, "((uae_u16)(");
1.1       root      587:        break;
                    588:      case sz_long:
1.1.1.5   root      589:        strcpy (vstr, "((uae_s32)(");
                    590:        strcpy (usstr, "((uae_u32)(");
1.1       root      591:        break;
                    592:      default:
1.1.1.5   root      593:        abort ();
1.1       root      594:     }
1.1.1.5   root      595:     strcpy (unsstr, usstr);
1.1       root      596: 
1.1.1.5   root      597:     strcpy (sstr, vstr);
                    598:     strcpy (dstr, vstr);
                    599:     strcat (vstr, value);
                    600:     strcat (vstr, "))");
                    601:     strcat (dstr, dst);
                    602:     strcat (dstr, "))");
                    603:     strcat (sstr, src);
                    604:     strcat (sstr, "))");
                    605: 
                    606:     strcpy (udstr, usstr);
                    607:     strcat (udstr, dst);
                    608:     strcat (udstr, "))");
                    609:     strcat (usstr, src);
                    610:     strcat (usstr, "))");
                    611: 
                    612:     strcpy (undstr, unsstr);
                    613:     strcat (unsstr, "-");
                    614:     strcat (undstr, "~");
                    615:     strcat (undstr, dst);
                    616:     strcat (undstr, "))");
                    617:     strcat (unsstr, src);
                    618:     strcat (unsstr, "))");
1.1       root      619: 
                    620:     switch (type) {
1.1.1.7   root      621:      case flag_logical_noclobber:
1.1       root      622:      case flag_logical:
                    623:      case flag_zn:
                    624:      case flag_av:
                    625:      case flag_sv:
                    626:      case flag_addx:
                    627:      case flag_subx:
                    628:        break;
1.1.1.3   root      629: 
1.1       root      630:      case flag_add:
1.1.1.5   root      631:        start_brace ();
1.1.1.3   root      632:        printf ("uae_u32 %s = %s + %s;\n", value, dstr, sstr);
1.1       root      633:        break;
                    634:      case flag_sub:
                    635:      case flag_cmp:
1.1.1.5   root      636:        start_brace ();
1.1.1.3   root      637:        printf ("uae_u32 %s = %s - %s;\n", value, dstr, sstr);
1.1       root      638:        break;
                    639:     }
                    640: 
                    641:     switch (type) {
1.1.1.7   root      642:      case flag_logical_noclobber:
1.1       root      643:      case flag_logical:
                    644:      case flag_zn:
                    645:        break;
1.1.1.3   root      646: 
1.1       root      647:      case flag_add:
                    648:      case flag_sub:
                    649:      case flag_addx:
                    650:      case flag_subx:
                    651:      case flag_cmp:
                    652:      case flag_av:
                    653:      case flag_sv:
1.1.1.5   root      654:        start_brace ();
                    655:        printf ("\t" BOOL_TYPE " flgs = %s < 0;\n", sstr);
                    656:        printf ("\t" BOOL_TYPE " flgo = %s < 0;\n", dstr);
                    657:        printf ("\t" BOOL_TYPE " flgn = %s < 0;\n", vstr);
1.1       root      658:        break;
                    659:     }
1.1.1.3   root      660: 
1.1.1.5   root      661:     switch (type) {
1.1       root      662:      case flag_logical:
1.1.1.7   root      663:        printf ("\tCLEAR_CZNV;\n");
                    664:        printf ("\tSET_ZFLG (%s == 0);\n", vstr);
                    665:        printf ("\tSET_NFLG (%s < 0);\n", vstr);
                    666:        break;
                    667:      case flag_logical_noclobber:
                    668:        printf ("\tSET_ZFLG (%s == 0);\n", vstr);
                    669:        printf ("\tSET_NFLG (%s < 0);\n", vstr);
1.1       root      670:        break;
                    671:      case flag_av:
1.1.1.7   root      672:        printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
1.1       root      673:        break;
                    674:      case flag_sv:
1.1.1.7   root      675:        printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
1.1       root      676:        break;
                    677:      case flag_zn:
1.1.1.7   root      678:        printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr);
                    679:        printf ("\tSET_NFLG (%s < 0);\n", vstr);
1.1       root      680:        break;
                    681:      case flag_add:
1.1.1.7   root      682:        printf ("\tSET_ZFLG (%s == 0);\n", vstr);
1.1.1.8   root      683:        printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
1.1.1.7   root      684:        printf ("\tSET_CFLG (%s < %s);\n", undstr, usstr);
                    685:        duplicate_carry ();
                    686:        printf ("\tSET_NFLG (flgn != 0);\n");
1.1       root      687:        break;
                    688:      case flag_sub:
1.1.1.7   root      689:        printf ("\tSET_ZFLG (%s == 0);\n", vstr);
                    690:        printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
                    691:        printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr);
1.1.1.8   root      692:        duplicate_carry ();
1.1.1.7   root      693:        printf ("\tSET_NFLG (flgn != 0);\n");
1.1       root      694:        break;
                    695:      case flag_addx:
1.1.1.7   root      696:        printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */
                    697:        printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */
                    698:        duplicate_carry ();
1.1       root      699:        break;
                    700:      case flag_subx:
1.1.1.7   root      701:        printf ("\tSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */
                    702:        printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */
                    703:        duplicate_carry ();
1.1       root      704:        break;
                    705:      case flag_cmp:
1.1.1.7   root      706:        printf ("\tSET_ZFLG (%s == 0);\n", vstr);
                    707:        printf ("\tSET_VFLG ((flgs != flgo) && (flgn != flgo));\n");
                    708:        printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr);
                    709:        printf ("\tSET_NFLG (flgn != 0);\n");
1.1       root      710:        break;
                    711:     }
                    712: }
                    713: 
1.1.1.5   root      714: static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst)
1.1       root      715: {
1.1.1.11  root      716:     /* Temporarily deleted 68k/ARM flag optimizations.  I'd prefer to have
                    717:        them in the appropriate m68k.h files and use just one copy of this
                    718:        code here.  The API can be changed if necessary.  */
                    719: #ifdef OPTIMIZED_FLAGS
1.1       root      720:     switch (type) {
1.1.1.5   root      721:      case flag_add:
                    722:      case flag_sub:
                    723:        start_brace ();
1.1.1.3   root      724:        printf ("\tuae_u32 %s;\n", value);
1.1       root      725:        break;
                    726: 
1.1.1.3   root      727:      default:
1.1       root      728:        break;
                    729:     }
                    730: 
1.1.1.3   root      731:     /* At least some of those casts are fairly important! */
1.1.1.5   root      732:     switch (type) {
1.1.1.7   root      733:      case flag_logical_noclobber:
1.1.1.11  root      734:        printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n");
1.1.1.7   root      735:        if (strcmp (value, "0") == 0) {
1.1.1.11  root      736:            printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n");
1.1.1.7   root      737:        } else {
                    738:            switch (size) {
1.1.1.11  root      739:             case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
                    740:             case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
                    741:             case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
1.1.1.7   root      742:            }
1.1.1.11  root      743:            printf ("\tIOR_CZNV (oldcznv);\n");
1.1.1.7   root      744:        }
                    745:        printf ("\t}\n");
                    746:        return;
1.1       root      747:      case flag_logical:
1.1.1.5   root      748:        if (strcmp (value, "0") == 0) {
1.1.1.11  root      749:            printf ("\tSET_CZNV (FLAGVAL_Z);\n");
1.1       root      750:        } else {
1.1.1.5   root      751:            switch (size) {
1.1.1.11  root      752:             case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
                    753:             case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
                    754:             case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
1.1       root      755:            }
                    756:        }
                    757:        return;
                    758: 
                    759:      case flag_add:
1.1.1.5   root      760:        switch (size) {
1.1.1.11  root      761:         case sz_byte: printf ("\toptflag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
                    762:         case sz_word: printf ("\toptflag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
                    763:         case sz_long: printf ("\toptflag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
1.1       root      764:        }
                    765:        return;
                    766: 
                    767:      case flag_sub:
1.1.1.5   root      768:        switch (size) {
1.1.1.11  root      769:         case sz_byte: printf ("\toptflag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
                    770:         case sz_word: printf ("\toptflag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
                    771:         case sz_long: printf ("\toptflag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
1.1       root      772:        }
                    773:        return;
                    774: 
                    775:      case flag_cmp:
1.1.1.5   root      776:        switch (size) {
1.1.1.11  root      777:         case sz_byte: printf ("\toptflag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
                    778:         case sz_word: printf ("\toptflag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
                    779:         case sz_long: printf ("\toptflag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
1.1       root      780:        }
                    781:        return;
1.1.1.5   root      782:        
1.1.1.3   root      783:      default:
                    784:        break;
1.1       root      785:     }
                    786: #endif
1.1.1.11  root      787: 
1.1.1.5   root      788:     genflags_normal (type, size, value, src, dst);
1.1       root      789: }
1.1.1.3   root      790: 
1.1.1.7   root      791: static void force_range_for_rox (const char *var, wordsizes size)
                    792: {
                    793:     /* Could do a modulo operation here... which one is faster? */
                    794:     switch (size) {
                    795:      case sz_long:
                    796:        printf ("\tif (%s >= 33) %s -= 33;\n", var, var);
                    797:        break;
                    798:      case sz_word:
                    799:        printf ("\tif (%s >= 34) %s -= 34;\n", var, var);
                    800:        printf ("\tif (%s >= 17) %s -= 17;\n", var, var);
                    801:        break;
                    802:      case sz_byte:
                    803:        printf ("\tif (%s >= 36) %s -= 36;\n", var, var);
                    804:        printf ("\tif (%s >= 18) %s -= 18;\n", var, var);
                    805:        printf ("\tif (%s >= 9) %s -= 9;\n", var, var);
                    806:        break;
                    807:     }
                    808: }
                    809: 
                    810: static const char *cmask (wordsizes size)
                    811: {
                    812:     switch (size) {
                    813:      case sz_byte: return "0x80";
                    814:      case sz_word: return "0x8000";
                    815:      case sz_long: return "0x80000000";
                    816:      default: abort ();
                    817:     }
                    818: }
                    819: 
                    820: static int source_is_imm1_8 (struct instr *i)
                    821: {
                    822:     return i->stype == 3;
                    823: }
                    824: 
1.1.1.5   root      825: static void gen_opcode (unsigned long int opcode)
1.1       root      826: {
1.1.1.7   root      827:     struct instr *curi = table68k + opcode;
1.1.1.11  root      828:     insn_n_cycles = 4;
1.1.1.5   root      829: 
1.1       root      830:     start_brace ();
1.1.1.3   root      831: #if 0
                    832:     printf ("uae_u8 *m68k_pc = regs.pc_p;\n");
                    833: #endif
                    834:     m68k_pc_offset = 2;
1.1.1.7   root      835:     switch (curi->plev) {
1.1.1.11  root      836:     case 0: /* not privileged */
1.1       root      837:        break;
1.1.1.11  root      838:     case 1: /* unprivileged only on 68000 */
1.1.1.3   root      839:        if (cpu_level == 0)
1.1       root      840:            break;
1.1.1.3   root      841:        if (next_cpu_level < 0)
                    842:            next_cpu_level = 0;
                    843: 
1.1.1.5   root      844:        /* fall through */
1.1.1.11  root      845:     case 2: /* priviledged */
1.1.1.3   root      846:        printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr);
1.1.1.5   root      847:        need_endlabel = 1;
                    848:        start_brace ();
1.1       root      849:        break;
1.1.1.11  root      850:     case 3: /* privileged if size == word */
1.1.1.7   root      851:        if (curi->size == sz_byte)
1.1       root      852:            break;
1.1.1.3   root      853:        printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr);
1.1.1.5   root      854:        need_endlabel = 1;
                    855:        start_brace ();
1.1       root      856:        break;
                    857:     }
1.1.1.7   root      858:     switch (curi->mnemo) {
1.1.1.11  root      859:     case i_OR:
                    860:     case i_AND:
                    861:     case i_EOR:
1.1.1.7   root      862:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    863:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                    864:        printf ("\tsrc %c= dst;\n", curi->mnemo == i_OR ? '|' : curi->mnemo == i_AND ? '&' : '^');
                    865:        genflags (flag_logical, curi->size, "src", "", "");
                    866:        genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      867:        break;
1.1.1.11  root      868:     case i_ORSR:
                    869:     case i_EORSR:
1.1.1.3   root      870:        printf ("\tMakeSR();\n");
1.1.1.7   root      871:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    872:        if (curi->size == sz_byte) {
1.1.1.3   root      873:            printf ("\tsrc &= 0xFF;\n");
1.1       root      874:        }
1.1.1.7   root      875:        printf ("\tregs.sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|');
1.1.1.3   root      876:        printf ("\tMakeFromSR();\n");
1.1       root      877:        break;
1.1.1.11  root      878:     case i_ANDSR:
1.1.1.3   root      879:        printf ("\tMakeSR();\n");
1.1.1.7   root      880:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    881:        if (curi->size == sz_byte) {
1.1.1.3   root      882:            printf ("\tsrc |= 0xFF00;\n");
1.1       root      883:        }
1.1.1.3   root      884:        printf ("\tregs.sr &= src;\n");
                    885:        printf ("\tMakeFromSR();\n");
1.1       root      886:        break;
1.1.1.11  root      887:     case i_SUB:
1.1.1.7   root      888:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    889:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root      890:        start_brace ();
1.1.1.7   root      891:        genflags (flag_sub, curi->size, "newv", "src", "dst");
                    892:        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      893:        break;
1.1.1.11  root      894:     case i_SUBA:
1.1.1.7   root      895:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    896:        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1.1       root      897:        start_brace ();
1.1.1.3   root      898:        printf ("\tuae_u32 newv = dst - src;\n");
1.1.1.7   root      899:        genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1.1       root      900:        break;
1.1.1.11  root      901:     case i_SUBX:
1.1.1.7   root      902:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    903:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root      904:        start_brace ();
1.1.1.7   root      905:        printf ("\tuae_u32 newv = dst - src - (GET_XFLG ? 1 : 0);\n");
                    906:        genflags (flag_subx, curi->size, "newv", "src", "dst");
                    907:        genflags (flag_zn, curi->size, "newv", "", "");
                    908:        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      909:        break;
1.1.1.11  root      910:     case i_SBCD:
1.1.1.7   root      911:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    912:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root      913:        start_brace ();
1.1.1.7   root      914:        printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
1.1.1.3   root      915:        printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n");
1.1.1.14  root      916:        printf ("\tuae_u16 newv, tmp_newv;\n");
                    917:        printf ("\tint bcd = 0;\n");
                    918:        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
                    919:        printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n");
                    920:        printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
                    921:        printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG ? 1 : 0)) & 0x300) > 0xFF);\n");
1.1.1.7   root      922:        duplicate_carry ();
                    923:        genflags (flag_zn, curi->size, "newv", "", "");
1.1.1.14  root      924:        printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
1.1.1.7   root      925:        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      926:        break;
1.1.1.11  root      927:     case i_ADD:
1.1.1.7   root      928:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    929:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root      930:        start_brace ();
1.1.1.7   root      931:        genflags (flag_add, curi->size, "newv", "src", "dst");
                    932:        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      933:        break;
1.1.1.11  root      934:     case i_ADDA:
1.1.1.7   root      935:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    936:        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1.1       root      937:        start_brace ();
1.1.1.3   root      938:        printf ("\tuae_u32 newv = dst + src;\n");
1.1.1.7   root      939:        genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1.1       root      940:        break;
1.1.1.11  root      941:     case i_ADDX:
1.1.1.7   root      942:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    943:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root      944:        start_brace ();
1.1.1.7   root      945:        printf ("\tuae_u32 newv = dst + src + (GET_XFLG ? 1 : 0);\n");
                    946:        genflags (flag_addx, curi->size, "newv", "src", "dst");
                    947:        genflags (flag_zn, curi->size, "newv", "", "");
                    948:        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      949:        break;
1.1.1.11  root      950:     case i_ABCD:
1.1.1.7   root      951:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                    952:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root      953:        start_brace ();
1.1.1.7   root      954:        printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG ? 1 : 0);\n");
1.1.1.3   root      955:        printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
1.1.1.14  root      956:        printf ("\tuae_u16 newv, tmp_newv;\n");
1.1.1.7   root      957:        printf ("\tint cflg;\n");
1.1.1.14  root      958:        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;");
                    959:        printf ("\tif (newv_lo > 9) { newv += 6; }\n");
                    960:        printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
                    961:        printf ("\tif (cflg) newv += 0x60;\n");
1.1.1.12  root      962:        printf ("\tSET_CFLG (cflg);\n");
1.1.1.7   root      963:        duplicate_carry ();
                    964:        genflags (flag_zn, curi->size, "newv", "", "");
1.1.1.14  root      965:        printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
1.1.1.7   root      966:        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1.1       root      967:        break;
1.1.1.11  root      968:     case i_NEG:
1.1.1.7   root      969:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1       root      970:        start_brace ();
1.1.1.7   root      971:        genflags (flag_sub, curi->size, "dst", "src", "0");
                    972:        genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1.1       root      973:        break;
1.1.1.11  root      974:     case i_NEGX:
1.1.1.7   root      975:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1       root      976:        start_brace ();
1.1.1.7   root      977:        printf ("\tuae_u32 newv = 0 - src - (GET_XFLG ? 1 : 0);\n");
                    978:        genflags (flag_subx, curi->size, "newv", "src", "0");
                    979:        genflags (flag_zn, curi->size, "newv", "", "");
                    980:        genastore ("newv", curi->smode, "srcreg", curi->size, "src");
1.1       root      981:        break;
1.1.1.11  root      982:     case i_NBCD:
1.1.1.7   root      983:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1       root      984:        start_brace ();
1.1.1.7   root      985:        printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
1.1.1.3   root      986:        printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n");
                    987:        printf ("\tuae_u16 newv;\n");
1.1.1.7   root      988:        printf ("\tint cflg;\n");
1.1.1.14  root      989:        printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n");
                    990:        printf ("\tnewv = newv_hi + newv_lo;");
                    991:        printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
                    992:        printf ("\tif (cflg) newv -= 0x60;\n");
1.1.1.12  root      993:        printf ("\tSET_CFLG (cflg);\n");
1.1.1.8   root      994:        duplicate_carry();
1.1.1.7   root      995:        genflags (flag_zn, curi->size, "newv", "", "");
                    996:        genastore ("newv", curi->smode, "srcreg", curi->size, "src");
1.1       root      997:        break;
1.1.1.11  root      998:     case i_CLR:
1.1.1.7   root      999:        genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
                   1000:        genflags (flag_logical, curi->size, "0", "", "");
                   1001:        genastore ("0", curi->smode, "srcreg", curi->size, "src");
1.1       root     1002:        break;
1.1.1.11  root     1003:     case i_NOT:
1.1.1.7   root     1004:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1       root     1005:        start_brace ();
1.1.1.3   root     1006:        printf ("\tuae_u32 dst = ~src;\n");
1.1.1.7   root     1007:        genflags (flag_logical, curi->size, "dst", "", "");
                   1008:        genastore ("dst", curi->smode, "srcreg", curi->size, "src");
1.1       root     1009:        break;
1.1.1.11  root     1010:     case i_TST:
1.1.1.7   root     1011:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1012:        genflags (flag_logical, curi->size, "src", "", "");
1.1       root     1013:        break;
1.1.1.11  root     1014:     case i_BTST:
1.1.1.7   root     1015:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1016:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1017:        if (curi->size == sz_byte)
1.1.1.3   root     1018:            printf ("\tsrc &= 7;\n");
1.1       root     1019:        else
1.1.1.3   root     1020:            printf ("\tsrc &= 31;\n");
1.1.1.7   root     1021:        printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
1.1       root     1022:        break;
1.1.1.11  root     1023:     case i_BCHG:
1.1.1.7   root     1024:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1025:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1026:        if (curi->size == sz_byte)
1.1.1.3   root     1027:            printf ("\tsrc &= 7;\n");
1.1       root     1028:        else
1.1.1.3   root     1029:            printf ("\tsrc &= 31;\n");
                   1030:        printf ("\tdst ^= (1 << src);\n");
1.1.1.9   root     1031:        printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n");
1.1.1.7   root     1032:        genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1033:        break;
1.1.1.11  root     1034:     case i_BCLR:
1.1.1.7   root     1035:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1036:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1037:        if (curi->size == sz_byte)
1.1.1.3   root     1038:            printf ("\tsrc &= 7;\n");
1.1       root     1039:        else
1.1.1.3   root     1040:            printf ("\tsrc &= 31;\n");
1.1.1.7   root     1041:        printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
1.1.1.3   root     1042:        printf ("\tdst &= ~(1 << src);\n");
1.1.1.7   root     1043:        genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1044:        break;
1.1.1.11  root     1045:     case i_BSET:
1.1.1.7   root     1046:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1047:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1048:        if (curi->size == sz_byte)
1.1.1.3   root     1049:            printf ("\tsrc &= 7;\n");
1.1       root     1050:        else
1.1.1.3   root     1051:            printf ("\tsrc &= 31;\n");
1.1.1.7   root     1052:        printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
1.1.1.3   root     1053:        printf ("\tdst |= (1 << src);\n");
1.1.1.7   root     1054:        genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1055:        break;
1.1.1.11  root     1056:     case i_CMPM:
                   1057:     case i_CMP:
1.1.1.7   root     1058:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1059:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1       root     1060:        start_brace ();
1.1.1.7   root     1061:        genflags (flag_cmp, curi->size, "newv", "src", "dst");
1.1       root     1062:        break;
1.1.1.11  root     1063:     case i_CMPA:
1.1.1.7   root     1064:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1065:        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1.1       root     1066:        start_brace ();
1.1.1.5   root     1067:        genflags (flag_cmp, sz_long, "newv", "src", "dst");
1.1       root     1068:        break;
                   1069:        /* The next two are coded a little unconventional, but they are doing
                   1070:         * weird things... */
1.1.1.11  root     1071:     case i_MVPRM:
1.1.1.7   root     1072:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.5   root     1073: 
                   1074:        printf ("\tuaecptr memp = m68k_areg(regs, dstreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
1.1.1.7   root     1075:        if (curi->size == sz_word) {
1.1.1.3   root     1076:            printf ("\tput_byte(memp, src >> 8); put_byte(memp + 2, src);\n");
1.1       root     1077:        } else {
1.1.1.3   root     1078:            printf ("\tput_byte(memp, src >> 24); put_byte(memp + 2, src >> 16);\n");
                   1079:            printf ("\tput_byte(memp + 4, src >> 8); put_byte(memp + 6, src);\n");
1.1       root     1080:        }
                   1081:        break;
1.1.1.11  root     1082:     case i_MVPMR:
1.1.1.5   root     1083:        printf ("\tuaecptr memp = m68k_areg(regs, srcreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
1.1.1.7   root     1084:        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
                   1085:        if (curi->size == sz_word) {
1.1.1.3   root     1086:            printf ("\tuae_u16 val = (get_byte(memp) << 8) + get_byte(memp + 2);\n");
1.1       root     1087:        } else {
1.1.1.3   root     1088:            printf ("\tuae_u32 val = (get_byte(memp) << 24) + (get_byte(memp + 2) << 16)\n");
                   1089:            printf ("              + (get_byte(memp + 4) << 8) + get_byte(memp + 6);\n");
1.1       root     1090:        }
1.1.1.7   root     1091:        genastore ("val", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1092:        break;
1.1.1.11  root     1093:     case i_MOVE:
1.1.1.7   root     1094:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1095:        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
                   1096:        genflags (flag_logical, curi->size, "src", "", "");
                   1097:        genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1098:        break;
1.1.1.11  root     1099:     case i_MOVEA:
1.1.1.7   root     1100:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1101:        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
                   1102:        if (curi->size == sz_word) {
1.1.1.3   root     1103:            printf ("\tuae_u32 val = (uae_s32)(uae_s16)src;\n");
1.1       root     1104:        } else {
1.1.1.3   root     1105:            printf ("\tuae_u32 val = src;\n");
1.1       root     1106:        }
1.1.1.7   root     1107:        genastore ("val", curi->dmode, "dstreg", sz_long, "dst");
1.1       root     1108:        break;
1.1.1.11  root     1109:     case i_MVSR2:
1.1.1.7   root     1110:        genamode (curi->smode, "srcreg", sz_word, "src", 2, 0);
1.1.1.3   root     1111:        printf ("\tMakeSR();\n");
1.1.1.7   root     1112:        if (curi->size == sz_byte)
                   1113:            genastore ("regs.sr & 0xff", curi->smode, "srcreg", sz_word, "src");
1.1       root     1114:        else
1.1.1.7   root     1115:            genastore ("regs.sr", curi->smode, "srcreg", sz_word, "src");
1.1       root     1116:        break;
1.1.1.11  root     1117:     case i_MV2SR:
1.1.1.7   root     1118:        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
                   1119:        if (curi->size == sz_byte)
1.1.1.3   root     1120:            printf ("\tMakeSR();\n\tregs.sr &= 0xFF00;\n\tregs.sr |= src & 0xFF;\n");
                   1121:        else {
                   1122:            printf ("\tregs.sr = src;\n");
1.1       root     1123:        }
1.1.1.3   root     1124:        printf ("\tMakeFromSR();\n");
1.1       root     1125:        break;
1.1.1.11  root     1126:     case i_SWAP:
1.1.1.7   root     1127:        genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1.1       root     1128:        start_brace ();
1.1.1.3   root     1129:        printf ("\tuae_u32 dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);\n");
1.1.1.5   root     1130:        genflags (flag_logical, sz_long, "dst", "", "");
1.1.1.7   root     1131:        genastore ("dst", curi->smode, "srcreg", sz_long, "src");
1.1       root     1132:        break;
1.1.1.11  root     1133:     case i_EXG:
1.1.1.7   root     1134:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1135:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1136:        genastore ("dst", curi->smode, "srcreg", curi->size, "src");
                   1137:        genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1138:        break;
1.1.1.11  root     1139:     case i_EXT:
1.1.1.7   root     1140:        genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1.1       root     1141:        start_brace ();
1.1.1.7   root     1142:        switch (curi->size) {
1.1.1.11  root     1143:        case sz_byte: printf ("\tuae_u32 dst = (uae_s32)(uae_s8)src;\n"); break;
                   1144:        case sz_word: printf ("\tuae_u16 dst = (uae_s16)(uae_s8)src;\n"); break;
                   1145:        case sz_long: printf ("\tuae_u32 dst = (uae_s32)(uae_s16)src;\n"); break;
                   1146:        default: abort ();
1.1       root     1147:        }
1.1.1.5   root     1148:        genflags (flag_logical,
1.1.1.7   root     1149:                  curi->size == sz_word ? sz_word : sz_long, "dst", "", "");
                   1150:        genastore ("dst", curi->smode, "srcreg",
                   1151:                   curi->size == sz_word ? sz_word : sz_long, "src");
1.1       root     1152:        break;
1.1.1.11  root     1153:     case i_MVMEL:
1.1.1.5   root     1154:        genmovemel (opcode);
1.1       root     1155:        break;
1.1.1.11  root     1156:     case i_MVMLE:
1.1.1.5   root     1157:        genmovemle (opcode);
1.1       root     1158:        break;
1.1.1.11  root     1159:     case i_TRAP:
1.1.1.7   root     1160:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.5   root     1161:        sync_m68k_pc ();
1.1.1.3   root     1162:        printf ("\tException(src+32,0);\n");
                   1163:        m68k_pc_offset = 0;
1.1       root     1164:        break;
1.1.1.11  root     1165:     case i_MVR2USP:
1.1.1.7   root     1166:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.3   root     1167:        printf ("\tregs.usp = src;\n");
1.1       root     1168:        break;
1.1.1.11  root     1169:     case i_MVUSP2R:
1.1.1.7   root     1170:        genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
                   1171:        genastore ("regs.usp", curi->smode, "srcreg", curi->size, "src");
1.1       root     1172:        break;
1.1.1.11  root     1173:     case i_RESET:
1.1.1.3   root     1174:        printf ("\tcustomreset();\n");
1.1       root     1175:        break;
1.1.1.11  root     1176:     case i_NOP:
1.1       root     1177:        break;
1.1.1.11  root     1178:     case i_STOP:
1.1.1.7   root     1179:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.3   root     1180:        printf ("\tregs.sr = src;\n");
                   1181:        printf ("\tMakeFromSR();\n");
                   1182:        printf ("\tm68k_setstopped(1);\n");
1.1       root     1183:        break;
1.1.1.11  root     1184:     case i_RTE:
1.1.1.3   root     1185:        if (cpu_level == 0) {
                   1186:            genamode (Aipi, "7", sz_word, "sr", 1, 0);
                   1187:            genamode (Aipi, "7", sz_long, "pc", 1, 0);
                   1188:            printf ("\tregs.sr = sr; m68k_setpc_rte(pc);\n");
                   1189:            fill_prefetch_0 ();
                   1190:            printf ("\tMakeFromSR();\n");
                   1191:        } else {
1.1       root     1192:            int old_brace_level = n_braces;
1.1.1.3   root     1193:            if (next_cpu_level < 0)
                   1194:                next_cpu_level = 0;
                   1195:            printf ("\tuae_u16 newsr; uae_u32 newpc; for (;;) {\n");
                   1196:            genamode (Aipi, "7", sz_word, "sr", 1, 0);
                   1197:            genamode (Aipi, "7", sz_long, "pc", 1, 0);
                   1198:            genamode (Aipi, "7", sz_word, "format", 1, 0);
                   1199:            printf ("\tnewsr = sr; newpc = pc;\n");
                   1200:            printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n");
                   1201:            printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n");
                   1202:            printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n");
                   1203:            printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n");
                   1204:            printf ("\telse if ((format & 0xF000) == 0x9000) { m68k_areg(regs, 7) += 12; break; }\n");
                   1205:            printf ("\telse if ((format & 0xF000) == 0xa000) { m68k_areg(regs, 7) += 24; break; }\n");
                   1206:            printf ("\telse if ((format & 0xF000) == 0xb000) { m68k_areg(regs, 7) += 84; break; }\n");
                   1207:            printf ("\telse { Exception(14,0); goto %s; }\n", endlabelstr);
                   1208:            printf ("\tregs.sr = newsr; MakeFromSR();\n}\n");
1.1       root     1209:            pop_braces (old_brace_level);
1.1.1.3   root     1210:            printf ("\tregs.sr = newsr; MakeFromSR();\n");
                   1211:            printf ("\tm68k_setpc_rte(newpc);\n");
                   1212:            fill_prefetch_0 ();
1.1.1.5   root     1213:            need_endlabel = 1;
1.1       root     1214:        }
1.1.1.3   root     1215:        /* PC is set and prefetch filled. */
                   1216:        m68k_pc_offset = 0;
1.1       root     1217:        break;
1.1.1.11  root     1218:     case i_RTD:
1.1.1.3   root     1219:        printf ("\tcompiler_flush_jsr_stack();\n");
                   1220:        genamode (Aipi, "7", sz_long, "pc", 1, 0);
1.1.1.7   root     1221:        genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0);
1.1.1.3   root     1222:        printf ("\tm68k_areg(regs, 7) += offs;\n");
                   1223:        printf ("\tm68k_setpc_rte(pc);\n");
                   1224:        fill_prefetch_0 ();
                   1225:        /* PC is set and prefetch filled. */
                   1226:        m68k_pc_offset = 0;
1.1       root     1227:        break;
1.1.1.11  root     1228:     case i_LINK:
1.1.1.3   root     1229:        genamode (Apdi, "7", sz_long, "old", 2, 0);
1.1.1.7   root     1230:        genamode (curi->smode, "srcreg", sz_long, "src", 1, 0);
1.1.1.3   root     1231:        genastore ("src", Apdi, "7", sz_long, "old");
1.1.1.7   root     1232:        genastore ("m68k_areg(regs, 7)", curi->smode, "srcreg", sz_long, "src");
                   1233:        genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
1.1.1.3   root     1234:        printf ("\tm68k_areg(regs, 7) += offs;\n");
1.1       root     1235:        break;
1.1.1.11  root     1236:     case i_UNLK:
1.1.1.7   root     1237:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.3   root     1238:        printf ("\tm68k_areg(regs, 7) = src;\n");
                   1239:        genamode (Aipi, "7", sz_long, "old", 1, 0);
1.1.1.7   root     1240:        genastore ("old", curi->smode, "srcreg", curi->size, "src");
1.1       root     1241:        break;
1.1.1.11  root     1242:     case i_RTS:
1.1.1.3   root     1243:        printf ("\tm68k_do_rts();\n");
                   1244:        fill_prefetch_0 ();
                   1245:        m68k_pc_offset = 0;
1.1       root     1246:        break;
1.1.1.11  root     1247:     case i_TRAPV:
1.1.1.3   root     1248:        sync_m68k_pc ();
1.1.1.7   root     1249:        printf ("\tif (GET_VFLG) { Exception(7,m68k_getpc()); goto %s; }\n", endlabelstr);
1.1.1.5   root     1250:        need_endlabel = 1;
1.1       root     1251:        break;
1.1.1.11  root     1252:     case i_RTR:
1.1.1.3   root     1253:        printf ("\tcompiler_flush_jsr_stack();\n");
                   1254:        printf ("\tMakeSR();\n");
                   1255:        genamode (Aipi, "7", sz_word, "sr", 1, 0);
                   1256:        genamode (Aipi, "7", sz_long, "pc", 1, 0);
                   1257:        printf ("\tregs.sr &= 0xFF00; sr &= 0xFF;\n");
                   1258:        printf ("\tregs.sr |= sr; m68k_setpc(pc);\n");
                   1259:        fill_prefetch_0 ();
                   1260:        printf ("\tMakeFromSR();\n");
                   1261:        m68k_pc_offset = 0;
1.1       root     1262:        break;
1.1.1.11  root     1263:     case i_JSR:
1.1.1.7   root     1264:        genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1.1.1.3   root     1265:        printf ("\tm68k_do_jsr(m68k_getpc() + %d, srca);\n", m68k_pc_offset);
                   1266:        fill_prefetch_0 ();
                   1267:        m68k_pc_offset = 0;
                   1268:        break;
1.1.1.11  root     1269:     case i_JMP:
1.1.1.7   root     1270:        genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1.1.1.3   root     1271:        printf ("\tm68k_setpc(srca);\n");
                   1272:        fill_prefetch_0 ();
                   1273:        m68k_pc_offset = 0;
1.1       root     1274:        break;
1.1.1.11  root     1275:     case i_BSR:
1.1.1.7   root     1276:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.3   root     1277:        printf ("\tuae_s32 s = (uae_s32)src + 2;\n");
                   1278:        if (using_exception_3) {
                   1279:            printf ("\tif (src & 1) {\n");
                   1280:            printf ("\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
                   1281:            printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + s;\n");
                   1282:            printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
                   1283:            printf ("\t}\n");
1.1.1.5   root     1284:            need_endlabel = 1;
1.1.1.3   root     1285:        }
                   1286:        printf ("\tm68k_do_bsr(m68k_getpc() + %d, s);\n", m68k_pc_offset);
                   1287:        fill_prefetch_0 ();
                   1288:        m68k_pc_offset = 0;
1.1       root     1289:        break;
1.1.1.11  root     1290:     case i_Bcc:
1.1.1.7   root     1291:        if (curi->size == sz_long) {
1.1.1.3   root     1292:            if (cpu_level < 2) {
                   1293:                printf ("\tm68k_incpc(2);\n");
1.1.1.7   root     1294:                printf ("\tif (!cctrue(%d)) goto %s;\n", curi->cc, endlabelstr);
1.1.1.3   root     1295:                printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
                   1296:                printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + 1;\n");
                   1297:                printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
1.1.1.5   root     1298:                need_endlabel = 1;
1.1.1.3   root     1299:            } else {
                   1300:                if (next_cpu_level < 1)
                   1301:                    next_cpu_level = 1;
                   1302:            }
                   1303:        }
1.1.1.7   root     1304:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1305:        printf ("\tif (!cctrue(%d)) goto didnt_jump;\n", curi->cc);
1.1.1.3   root     1306:        if (using_exception_3) {
                   1307:            printf ("\tif (src & 1) {\n");
                   1308:            printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
                   1309:            printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + 2 + (uae_s32)src;\n");
                   1310:            printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
                   1311:            printf ("\t}\n");
1.1.1.5   root     1312:            need_endlabel = 1;
1.1.1.3   root     1313:        }
1.1       root     1314: #ifdef USE_COMPILER
1.1.1.3   root     1315:        printf ("\tm68k_setpc_bcc(m68k_getpc() + 2 + (uae_s32)src);\n");
1.1       root     1316: #else
1.1.1.3   root     1317:        printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
1.1       root     1318: #endif
1.1.1.3   root     1319:        fill_prefetch_0 ();
1.1.1.14  root     1320:        printf ("\treturn 5 * CYCLE_UNIT;\n");
1.1.1.3   root     1321:        printf ("didnt_jump:;\n");
1.1.1.5   root     1322:        need_endlabel = 1;
1.1.1.11  root     1323:        insn_n_cycles = curi->size == sz_byte ? 8 : 12;
1.1       root     1324:        break;
1.1.1.11  root     1325:     case i_LEA:
1.1.1.7   root     1326:        genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
                   1327:        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
                   1328:        genastore ("srca", curi->dmode, "dstreg", curi->size, "dst");
1.1       root     1329:        break;
1.1.1.11  root     1330:     case i_PEA:
1.1.1.7   root     1331:        genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
1.1.1.3   root     1332:        genamode (Apdi, "7", sz_long, "dst", 2, 0);
                   1333:        genastore ("srca", Apdi, "7", sz_long, "dst");
1.1       root     1334:        break;
1.1.1.11  root     1335:     case i_DBcc:
1.1.1.7   root     1336:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1337:        genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0);
1.1.1.3   root     1338: 
1.1.1.7   root     1339:        printf ("\tif (!cctrue(%d)) {\n", curi->cc);
                   1340:        genastore ("(src-1)", curi->smode, "srcreg", curi->size, "src");
1.1.1.3   root     1341: 
                   1342:        printf ("\t\tif (src) {\n");
                   1343:        if (using_exception_3) {
                   1344:            printf ("\t\t\tif (offs & 1) {\n");
                   1345:            printf ("\t\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n");
                   1346:            printf ("\t\t\tlast_fault_for_exception_3 = m68k_getpc() + 2 + (uae_s32)offs + 2;\n");
                   1347:            printf ("\t\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr);
                   1348:            printf ("\t\t}\n");
1.1.1.5   root     1349:            need_endlabel = 1;
1.1.1.3   root     1350:        }
1.1       root     1351: #ifdef USE_COMPILER
1.1.1.3   root     1352:        printf ("\t\t\tm68k_setpc_bcc(m68k_getpc() + (uae_s32)offs + 2);\n");
1.1       root     1353: #else
1.1.1.3   root     1354:        printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n");
1.1       root     1355: #endif
1.1.1.3   root     1356:        fill_prefetch_0 ();
1.1.1.11  root     1357:        /* ??? Cycle count is a guess.  */
1.1.1.14  root     1358:        printf ("\t\treturn 6 * CYCLE_UNIT;\n");
1.1.1.3   root     1359:        printf ("\t\t}\n");
                   1360:        printf ("\t}\n");
1.1.1.11  root     1361:        insn_n_cycles = 12;
1.1.1.5   root     1362:        need_endlabel = 1;
1.1       root     1363:        break;
1.1.1.11  root     1364:     case i_Scc:
1.1.1.7   root     1365:        genamode (curi->smode, "srcreg", curi->size, "src", 2, 0);
1.1       root     1366:        start_brace ();
1.1.1.7   root     1367:        printf ("\tint val = cctrue(%d) ? 0xff : 0;\n", curi->cc);
                   1368:        genastore ("val", curi->smode, "srcreg", curi->size, "src");
1.1       root     1369:        break;
1.1.1.11  root     1370:     case i_DIVU:
1.1.1.3   root     1371:        printf ("\tuaecptr oldpc = m68k_getpc();\n");
1.1.1.7   root     1372:        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
                   1373:        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1.1.1.10  root     1374:        sync_m68k_pc ();
1.1.1.9   root     1375:        /* Clear V flag when dividing by zero - Alcatraz Odyssey demo depends
                   1376:         * on this (actually, it's doing a DIVS).  */
                   1377:        printf ("\tif (src == 0) { SET_VFLG (0); Exception (5, oldpc); goto %s; } else {\n", endlabelstr);
1.1.1.3   root     1378:        printf ("\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n");
                   1379:        printf ("\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n");
1.1       root     1380:        /* The N flag appears to be set each time there is an overflow.
                   1381:         * Weird. */
1.1.1.7   root     1382:        printf ("\tif (newv > 0xffff) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n");
1.1.1.5   root     1383:        genflags (flag_logical, sz_word, "newv", "", "");
1.1.1.3   root     1384:        printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
1.1.1.7   root     1385:        genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1.1.1.3   root     1386:        printf ("\t}\n");
                   1387:        printf ("\t}\n");
1.1.1.11  root     1388:        insn_n_cycles += 136;
1.1.1.5   root     1389:        need_endlabel = 1;
1.1.1.3   root     1390:        break;
1.1.1.11  root     1391:     case i_DIVS:
1.1.1.3   root     1392:        printf ("\tuaecptr oldpc = m68k_getpc();\n");
1.1.1.7   root     1393:        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
                   1394:        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1.1.1.10  root     1395:        sync_m68k_pc ();
1.1.1.9   root     1396:        printf ("\tif (src == 0) { SET_VFLG (0); Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1.1.1.3   root     1397:        printf ("\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n");
                   1398:        printf ("\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n");
1.1.1.7   root     1399:        printf ("\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n");
1.1.1.3   root     1400:        printf ("\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n");
1.1.1.5   root     1401:        genflags (flag_logical, sz_word, "newv", "", "");
1.1.1.3   root     1402:        printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
1.1.1.7   root     1403:        genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1.1.1.3   root     1404:        printf ("\t}\n");
                   1405:        printf ("\t}\n");
1.1.1.11  root     1406:        insn_n_cycles += 154;
1.1.1.5   root     1407:        need_endlabel = 1;
1.1.1.3   root     1408:        break;
1.1.1.11  root     1409:     case i_MULU:
1.1.1.7   root     1410:        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
                   1411:        genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
1.1       root     1412:        start_brace ();
1.1.1.3   root     1413:        printf ("\tuae_u32 newv = (uae_u32)(uae_u16)dst * (uae_u32)(uae_u16)src;\n");
1.1.1.5   root     1414:        genflags (flag_logical, sz_long, "newv", "", "");
1.1.1.7   root     1415:        genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1.1.1.11  root     1416:        insn_n_cycles += 66;
1.1       root     1417:        break;
1.1.1.11  root     1418:     case i_MULS:
1.1.1.7   root     1419:        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
                   1420:        genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0);
1.1       root     1421:        start_brace ();
1.1.1.3   root     1422:        printf ("\tuae_u32 newv = (uae_s32)(uae_s16)dst * (uae_s32)(uae_s16)src;\n");
1.1.1.5   root     1423:        genflags (flag_logical, sz_long, "newv", "", "");
1.1.1.7   root     1424:        genastore ("newv", curi->dmode, "dstreg", sz_long, "dst");
1.1.1.11  root     1425:        insn_n_cycles += 66;
1.1       root     1426:        break;
1.1.1.11  root     1427:     case i_CHK:
1.1.1.3   root     1428:        printf ("\tuaecptr oldpc = m68k_getpc();\n");
1.1.1.7   root     1429:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1430:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1431:        printf ("\tif ((uae_s32)dst < 0) { SET_NFLG (1); Exception(6,oldpc); goto %s; }\n", endlabelstr);
                   1432:        printf ("\telse if (dst > src) { SET_NFLG (0); Exception(6,oldpc); goto %s; }\n", endlabelstr);
1.1.1.5   root     1433:        need_endlabel = 1;
1.1       root     1434:        break;
1.1.1.3   root     1435: 
1.1.1.11  root     1436:     case i_CHK2:
1.1.1.3   root     1437:        printf ("\tuaecptr oldpc = m68k_getpc();\n");
1.1.1.7   root     1438:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
                   1439:        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
1.1.1.3   root     1440:        printf ("\t{uae_s32 upper,lower,reg = regs.regs[(extra >> 12) & 15];\n");
1.1.1.7   root     1441:        switch (curi->size) {
1.1.1.11  root     1442:        case sz_byte:
1.1.1.3   root     1443:            printf ("\tlower=(uae_s32)(uae_s8)get_byte(dsta); upper = (uae_s32)(uae_s8)get_byte(dsta+1);\n");
                   1444:            printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s8)reg;\n");
                   1445:            break;
1.1.1.11  root     1446:        case sz_word:
1.1.1.3   root     1447:            printf ("\tlower=(uae_s32)(uae_s16)get_word(dsta); upper = (uae_s32)(uae_s16)get_word(dsta+2);\n");
                   1448:            printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s16)reg;\n");
                   1449:            break;
1.1.1.11  root     1450:        case sz_long:
1.1.1.3   root     1451:            printf ("\tlower=get_long(dsta); upper = get_long(dsta+4);\n");
                   1452:            break;
1.1.1.11  root     1453:        default:
1.1.1.5   root     1454:            abort ();
1.1.1.3   root     1455:        }
1.1.1.7   root     1456:        printf ("\tSET_ZFLG (upper == reg || lower == reg);\n");
                   1457:        printf ("\tSET_CFLG (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
                   1458:        printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr);
1.1.1.5   root     1459:        need_endlabel = 1;
1.1.1.3   root     1460:        break;
                   1461: 
1.1.1.11  root     1462:     case i_ASR:
1.1.1.7   root     1463:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1464:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1.1.3   root     1465:        start_brace ();
1.1.1.7   root     1466:        switch (curi->size) {
1.1.1.11  root     1467:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1468:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1469:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1470:        default: abort ();
1.1       root     1471:        }
1.1.1.7   root     1472:        printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1);
1.1.1.3   root     1473:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1474:        printf ("\tCLEAR_CZNV;\n");
                   1475:        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
                   1476:        printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size));
                   1477:        printf ("\t\tSET_CFLG (sign);\n");
                   1478:        duplicate_carry ();
                   1479:        if (source_is_imm1_8 (curi))
                   1480:            printf ("\t} else {\n");
                   1481:        else
                   1482:            printf ("\t} else if (cnt > 0) {\n");
                   1483:        printf ("\t\tval >>= cnt - 1;\n");
                   1484:        printf ("\t\tSET_CFLG (val & 1);\n");
                   1485:        duplicate_carry ();
                   1486:        printf ("\t\tval >>= 1;\n");
                   1487:        printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n",
                   1488:                bit_mask (curi->size),
                   1489:                bit_size (curi->size));
                   1490:        printf ("\t\tval &= %s;\n", bit_mask (curi->size));
                   1491:        printf ("\t}\n");
                   1492:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1493:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1494:        break;
1.1.1.11  root     1495:     case i_ASL:
1.1.1.7   root     1496:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1497:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1498:        start_brace ();
1.1.1.7   root     1499:        switch (curi->size) {
1.1.1.11  root     1500:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1501:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1502:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1503:        default: abort ();
1.1       root     1504:        }
1.1.1.3   root     1505:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1506:        printf ("\tCLEAR_CZNV;\n");
                   1507:        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
                   1508:        printf ("\t\tSET_VFLG (val != 0);\n");
                   1509:        printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n",
                   1510:                bit_size (curi->size));
                   1511:        duplicate_carry ();
1.1.1.3   root     1512:        printf ("\t\tval = 0;\n");
1.1.1.7   root     1513:        if (source_is_imm1_8 (curi))
                   1514:            printf ("\t} else {\n");
                   1515:        else
                   1516:            printf ("\t} else if (cnt > 0) {\n");
1.1.1.3   root     1517:        printf ("\t\tuae_u32 mask = (%s << (%d - cnt)) & %s;\n",
1.1.1.7   root     1518:                bit_mask (curi->size),
                   1519:                bit_size (curi->size) - 1,
                   1520:                bit_mask (curi->size));
                   1521:        printf ("\t\tSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n");
                   1522:        printf ("\t\tval <<= cnt - 1;\n");
                   1523:        printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
                   1524:        duplicate_carry ();
                   1525:        printf ("\t\tval <<= 1;\n");
                   1526:        printf ("\t\tval &= %s;\n", bit_mask (curi->size));
                   1527:        printf ("\t}\n");
                   1528:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1529:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1530:        break;
1.1.1.11  root     1531:     case i_LSR:
1.1.1.7   root     1532:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1533:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1534:        start_brace ();
1.1.1.7   root     1535:        switch (curi->size) {
1.1.1.11  root     1536:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1537:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1538:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1539:        default: abort ();
1.1       root     1540:        }
1.1.1.3   root     1541:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1542:        printf ("\tCLEAR_CZNV;\n");
                   1543:        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
                   1544:        printf ("\t\tSET_CFLG ((cnt == %d) & (val >> %d));\n",
                   1545:                bit_size (curi->size), bit_size (curi->size) - 1);
                   1546:        duplicate_carry ();
1.1.1.3   root     1547:        printf ("\t\tval = 0;\n");
1.1.1.7   root     1548:        if (source_is_imm1_8 (curi))
                   1549:            printf ("\t} else {\n");
                   1550:        else
                   1551:            printf ("\t} else if (cnt > 0) {\n");
                   1552:        printf ("\t\tval >>= cnt - 1;\n");
                   1553:        printf ("\t\tSET_CFLG (val & 1);\n");
                   1554:        duplicate_carry ();
                   1555:        printf ("\t\tval >>= 1;\n");
                   1556:        printf ("\t}\n");
                   1557:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1558:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1559:        break;
1.1.1.11  root     1560:     case i_LSL:
1.1.1.7   root     1561:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1562:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1563:        start_brace ();
1.1.1.7   root     1564:        switch (curi->size) {
1.1.1.11  root     1565:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1566:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1567:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1568:        default: abort ();
1.1       root     1569:        }
1.1.1.3   root     1570:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1571:        printf ("\tCLEAR_CZNV;\n");
                   1572:        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
                   1573:        printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n",
                   1574:                bit_size (curi->size));
                   1575:        duplicate_carry ();
1.1.1.3   root     1576:        printf ("\t\tval = 0;\n");
1.1.1.7   root     1577:        if (source_is_imm1_8 (curi))
                   1578:            printf ("\t} else {\n");
                   1579:        else
                   1580:            printf ("\t} else if (cnt > 0) {\n");
                   1581:        printf ("\t\tval <<= (cnt - 1);\n");
                   1582:        printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
                   1583:        duplicate_carry ();
                   1584:        printf ("\t\tval <<= 1;\n");
                   1585:        printf ("\tval &= %s;\n", bit_mask (curi->size));
                   1586:        printf ("\t}\n");
                   1587:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1588:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1589:        break;
1.1.1.11  root     1590:     case i_ROL:
1.1.1.7   root     1591:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1592:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1593:        start_brace ();
1.1.1.7   root     1594:        switch (curi->size) {
1.1.1.11  root     1595:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1596:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1597:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1598:        default: abort ();
1.1       root     1599:        }
1.1.1.3   root     1600:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1601:        printf ("\tCLEAR_CZNV;\n");
                   1602:        if (source_is_imm1_8 (curi))
                   1603:            printf ("{");
                   1604:        else
                   1605:            printf ("\tif (cnt > 0) {\n");
                   1606:        printf ("\tuae_u32 loval;\n");
                   1607:        printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1);
                   1608:        printf ("\tloval = val >> (%d - cnt);\n", bit_size (curi->size));
                   1609:        printf ("\tval <<= cnt;\n");
                   1610:        printf ("\tval |= loval;\n");
                   1611:        printf ("\tval &= %s;\n", bit_mask (curi->size));
                   1612:        printf ("\tSET_CFLG (val & 1);\n");
                   1613:        printf ("}\n");
                   1614:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1615:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1616:        break;
1.1.1.11  root     1617:     case i_ROR:
1.1.1.7   root     1618:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1619:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1620:        start_brace ();
1.1.1.7   root     1621:        switch (curi->size) {
1.1.1.11  root     1622:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1623:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1624:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1625:        default: abort ();
1.1       root     1626:        }
1.1.1.3   root     1627:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1628:        printf ("\tCLEAR_CZNV;\n");
                   1629:        if (source_is_imm1_8 (curi))
                   1630:            printf ("{");
                   1631:        else
                   1632:            printf ("\tif (cnt > 0) {");
                   1633:        printf ("\tuae_u32 hival;\n");
                   1634:        printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1);
                   1635:        printf ("\thival = val << (%d - cnt);\n", bit_size (curi->size));
                   1636:        printf ("\tval >>= cnt;\n");
                   1637:        printf ("\tval |= hival;\n");
                   1638:        printf ("\tval &= %s;\n", bit_mask (curi->size));
                   1639:        printf ("\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
1.1.1.3   root     1640:        printf ("\t}\n");
1.1.1.7   root     1641:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1642:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1643:        break;
1.1.1.11  root     1644:     case i_ROXL:
1.1.1.7   root     1645:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1646:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1647:        start_brace ();
1.1.1.7   root     1648:        switch (curi->size) {
1.1.1.11  root     1649:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1650:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1651:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1652:        default: abort ();
1.1       root     1653:        }
1.1.1.3   root     1654:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1655:        printf ("\tCLEAR_CZNV;\n");
                   1656:        if (source_is_imm1_8 (curi))
                   1657:            printf ("{");
1.1.1.12  root     1658:        else {
                   1659:            force_range_for_rox ("cnt", curi->size);
1.1.1.7   root     1660:            printf ("\tif (cnt > 0) {\n");
1.1.1.12  root     1661:        }
1.1.1.7   root     1662:        printf ("\tcnt--;\n");
                   1663:        printf ("\t{\n\tuae_u32 carry;\n");
                   1664:        printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1);
                   1665:        printf ("\tcarry = loval & 1;\n");
                   1666:        printf ("\tval = (((val << 1) | GET_XFLG) << cnt) | (loval >> 1);\n");
                   1667:        printf ("\tSET_XFLG (carry);\n");
                   1668:        printf ("\tval &= %s;\n", bit_mask (curi->size));
                   1669:        printf ("\t} }\n");
                   1670:        printf ("\tSET_CFLG (GET_XFLG);\n");
                   1671:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1672:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1673:        break;
1.1.1.11  root     1674:     case i_ROXR:
1.1.1.7   root     1675:        genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0);
                   1676:        genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0);
1.1       root     1677:        start_brace ();
1.1.1.7   root     1678:        switch (curi->size) {
1.1.1.11  root     1679:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1680:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1681:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1682:        default: abort ();
1.1       root     1683:        }
1.1.1.3   root     1684:        printf ("\tcnt &= 63;\n");
1.1.1.7   root     1685:        printf ("\tCLEAR_CZNV;\n");
                   1686:        if (source_is_imm1_8 (curi))
                   1687:            printf ("{");
1.1.1.12  root     1688:        else {
                   1689:            force_range_for_rox ("cnt", curi->size);
1.1.1.7   root     1690:            printf ("\tif (cnt > 0) {\n");
1.1.1.12  root     1691:        }
1.1.1.7   root     1692:        printf ("\tcnt--;\n");
                   1693:        printf ("\t{\n\tuae_u32 carry;\n");
                   1694:        printf ("\tuae_u32 hival = (val << 1) | GET_XFLG;\n");
                   1695:        printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1);
                   1696:        printf ("\tval >>= cnt;\n");
                   1697:        printf ("\tcarry = val & 1;\n");
                   1698:        printf ("\tval >>= 1;\n");
                   1699:        printf ("\tval |= hival;\n");
                   1700:        printf ("\tSET_XFLG (carry);\n");
                   1701:        printf ("\tval &= %s;\n", bit_mask (curi->size));
                   1702:        printf ("\t} }\n");
                   1703:        printf ("\tSET_CFLG (GET_XFLG);\n");
                   1704:        genflags (flag_logical_noclobber, curi->size, "val", "", "");
                   1705:        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
1.1       root     1706:        break;
1.1.1.11  root     1707:     case i_ASRW:
1.1.1.7   root     1708:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1709:        start_brace ();
1.1.1.7   root     1710:        switch (curi->size) {
1.1.1.11  root     1711:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1712:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1713:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1714:        default: abort ();
1.1       root     1715:        }
1.1.1.7   root     1716:        printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size));
                   1717:        printf ("\tuae_u32 cflg = val & 1;\n");
                   1718:        printf ("\tval = (val >> 1) | sign;\n");
                   1719:        genflags (flag_logical, curi->size, "val", "", "");
                   1720:        printf ("\tSET_CFLG (cflg);\n");
                   1721:        duplicate_carry ();
                   1722:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1723:        break;
1.1.1.11  root     1724:     case i_ASLW:
1.1.1.7   root     1725:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1726:        start_brace ();
1.1.1.7   root     1727:        switch (curi->size) {
1.1.1.11  root     1728:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1729:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1730:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1731:        default: abort ();
1.1       root     1732:        }
1.1.1.7   root     1733:        printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size));
                   1734:        printf ("\tuae_u32 sign2;\n");
                   1735:        printf ("\tval <<= 1;\n");
                   1736:        genflags (flag_logical, curi->size, "val", "", "");
                   1737:        printf ("\tsign2 = %s & val;\n", cmask (curi->size));
                   1738:        printf ("\tSET_CFLG (sign != 0);\n");
                   1739:        duplicate_carry ();
                   1740: 
                   1741:        printf ("\tSET_VFLG (GET_VFLG | (sign2 != sign));\n");
                   1742:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1743:        break;
1.1.1.11  root     1744:     case i_LSRW:
1.1.1.7   root     1745:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1746:        start_brace ();
1.1.1.7   root     1747:        switch (curi->size) {
1.1.1.11  root     1748:        case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break;
                   1749:        case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break;
                   1750:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1751:        default: abort ();
1.1       root     1752:        }
1.1.1.7   root     1753:        printf ("\tuae_u32 carry = val & 1;\n");
1.1.1.3   root     1754:        printf ("\tval >>= 1;\n");
1.1.1.7   root     1755:        genflags (flag_logical, curi->size, "val", "", "");
                   1756:        printf ("SET_CFLG (carry);\n");
                   1757:        duplicate_carry ();
                   1758:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1759:        break;
1.1.1.11  root     1760:     case i_LSLW:
1.1.1.7   root     1761:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1762:        start_brace ();
1.1.1.7   root     1763:        switch (curi->size) {
1.1.1.11  root     1764:        case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
                   1765:        case sz_word: printf ("\tuae_u16 val = data;\n"); break;
                   1766:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1767:        default: abort ();
1.1       root     1768:        }
1.1.1.7   root     1769:        printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
1.1.1.3   root     1770:        printf ("\tval <<= 1;\n");
1.1.1.7   root     1771:        genflags (flag_logical, curi->size, "val", "", "");
                   1772:        printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
                   1773:        duplicate_carry ();
                   1774:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1775:        break;
1.1.1.11  root     1776:     case i_ROLW:
1.1.1.7   root     1777:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1778:        start_brace ();
1.1.1.7   root     1779:        switch (curi->size) {
1.1.1.11  root     1780:        case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
                   1781:        case sz_word: printf ("\tuae_u16 val = data;\n"); break;
                   1782:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1783:        default: abort ();
1.1       root     1784:        }
1.1.1.7   root     1785:        printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
1.1.1.3   root     1786:        printf ("\tval <<= 1;\n");
1.1.1.7   root     1787:        printf ("\tif (carry)  val |= 1;\n");
                   1788:        genflags (flag_logical, curi->size, "val", "", "");
                   1789:        printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
                   1790:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1791:        break;
1.1.1.11  root     1792:     case i_RORW:
1.1.1.7   root     1793:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1794:        start_brace ();
1.1.1.7   root     1795:        switch (curi->size) {
1.1.1.11  root     1796:        case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
                   1797:        case sz_word: printf ("\tuae_u16 val = data;\n"); break;
                   1798:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1799:        default: abort ();
1.1       root     1800:        }
1.1.1.7   root     1801:        printf ("\tuae_u32 carry = val & 1;\n");
1.1.1.3   root     1802:        printf ("\tval >>= 1;\n");
1.1.1.7   root     1803:        printf ("\tif (carry) val |= %s;\n", cmask (curi->size));
                   1804:        genflags (flag_logical, curi->size, "val", "", "");
                   1805:        printf ("SET_CFLG (carry);\n");
                   1806:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1807:        break;
1.1.1.11  root     1808:     case i_ROXLW:
1.1.1.7   root     1809:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1810:        start_brace ();
1.1.1.7   root     1811:        switch (curi->size) {
1.1.1.11  root     1812:        case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
                   1813:        case sz_word: printf ("\tuae_u16 val = data;\n"); break;
                   1814:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1815:        default: abort ();
1.1       root     1816:        }
1.1.1.7   root     1817:        printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
1.1.1.3   root     1818:        printf ("\tval <<= 1;\n");
1.1.1.7   root     1819:        printf ("\tif (GET_XFLG) val |= 1;\n");
                   1820:        genflags (flag_logical, curi->size, "val", "", "");
                   1821:        printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
                   1822:        duplicate_carry ();
                   1823:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1824:        break;
1.1.1.11  root     1825:     case i_ROXRW:
1.1.1.7   root     1826:        genamode (curi->smode, "srcreg", curi->size, "data", 1, 0);
1.1       root     1827:        start_brace ();
1.1.1.7   root     1828:        switch (curi->size) {
1.1.1.11  root     1829:        case sz_byte: printf ("\tuae_u8 val = data;\n"); break;
                   1830:        case sz_word: printf ("\tuae_u16 val = data;\n"); break;
                   1831:        case sz_long: printf ("\tuae_u32 val = data;\n"); break;
                   1832:        default: abort ();
1.1       root     1833:        }
1.1.1.7   root     1834:        printf ("\tuae_u32 carry = val & 1;\n");
1.1.1.3   root     1835:        printf ("\tval >>= 1;\n");
1.1.1.7   root     1836:        printf ("\tif (GET_XFLG) val |= %s;\n", cmask (curi->size));
                   1837:        genflags (flag_logical, curi->size, "val", "", "");
                   1838:        printf ("SET_CFLG (carry);\n");
                   1839:        duplicate_carry ();
                   1840:        genastore ("val", curi->smode, "srcreg", curi->size, "data");
1.1       root     1841:        break;
1.1.1.11  root     1842:     case i_MOVEC2:
1.1.1.7   root     1843:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.5   root     1844:        start_brace ();
1.1.1.3   root     1845:        printf ("\tint regno = (src >> 12) & 15;\n");
                   1846:        printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1.1.1.9   root     1847:        printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1.1       root     1848:        break;
1.1.1.11  root     1849:     case i_MOVE2C:
1.1.1.7   root     1850:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1.1.1.5   root     1851:        start_brace ();
1.1.1.3   root     1852:        printf ("\tint regno = (src >> 12) & 15;\n");
                   1853:        printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1.1.1.9   root     1854:        printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1.1       root     1855:        break;
1.1.1.11  root     1856:     case i_CAS:
                   1857:     {
                   1858:        int old_brace_level;
                   1859:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   1860:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
                   1861:        start_brace ();
                   1862:        printf ("\tint ru = (src >> 6) & 7;\n");
                   1863:        printf ("\tint rc = src & 7;\n");
                   1864:        genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, rc)", "dst");
                   1865:        printf ("\tif (GET_ZFLG)");
                   1866:        old_brace_level = n_braces;
                   1867:        start_brace ();
                   1868:        genastore ("(m68k_dreg(regs, ru))", curi->dmode, "dstreg", curi->size, "dst");
                   1869:        pop_braces (old_brace_level);
                   1870:        printf ("else");
                   1871:        start_brace ();
                   1872:        printf ("m68k_dreg(regs, rc) = dst;\n");
                   1873:        pop_braces (old_brace_level);
                   1874:     }
                   1875:     break;
                   1876:     case i_CAS2:
1.1.1.7   root     1877:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1.1.1.8   root     1878:        printf ("\tuae_u32 rn1 = regs.regs[(extra >> 28) & 15];\n");
                   1879:        printf ("\tuae_u32 rn2 = regs.regs[(extra >> 12) & 15];\n");
1.1.1.7   root     1880:        if (curi->size == sz_word) {
1.1.1.5   root     1881:            int old_brace_level = n_braces;
                   1882:            printf ("\tuae_u16 dst1 = get_word(rn1), dst2 = get_word(rn2);\n");
1.1.1.7   root     1883:            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1");
                   1884:            printf ("\tif (GET_ZFLG) {\n");
                   1885:            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2");
                   1886:            printf ("\tif (GET_ZFLG) {\n");
1.1.1.5   root     1887:            printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n");
                   1888:            printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n");
                   1889:            printf ("\t}}\n");
                   1890:            pop_braces (old_brace_level);
1.1.1.7   root     1891:            printf ("\tif (! GET_ZFLG) {\n");
1.1.1.5   root     1892:            printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = (m68k_dreg(regs, (extra >> 22) & 7) & ~0xffff) | (dst1 & 0xffff);\n");
                   1893:            printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = (m68k_dreg(regs, (extra >> 6) & 7) & ~0xffff) | (dst2 & 0xffff);\n");
                   1894:            printf ("\t}\n");
1.1       root     1895:        } else {
1.1.1.5   root     1896:            int old_brace_level = n_braces;
                   1897:            printf ("\tuae_u32 dst1 = get_long(rn1), dst2 = get_long(rn2);\n");
1.1.1.7   root     1898:            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1");
                   1899:            printf ("\tif (GET_ZFLG) {\n");
                   1900:            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2");
                   1901:            printf ("\tif (GET_ZFLG) {\n");
1.1.1.5   root     1902:            printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n");
                   1903:            printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n");
                   1904:            printf ("\t}}\n");
                   1905:            pop_braces (old_brace_level);
1.1.1.7   root     1906:            printf ("\tif (! GET_ZFLG) {\n");
1.1.1.5   root     1907:            printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = dst1;\n");
                   1908:            printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = dst2;\n");
                   1909:            printf ("\t}\n");
1.1       root     1910:        }
                   1911:        break;
1.1.1.11  root     1912:     case i_MOVES:              /* ignore DFC and SFC because we have no MMU */
                   1913:     {
                   1914:        int old_brace_level;
                   1915:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
                   1916:        printf ("\tif (extra & 0x800)\n");
                   1917:        old_brace_level = n_braces;
                   1918:        start_brace ();
                   1919:        printf ("\tuae_u32 src = regs.regs[(extra >> 12) & 15];\n");
                   1920:        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0);
                   1921:        genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
                   1922:        pop_braces (old_brace_level);
                   1923:        printf ("else");
                   1924:        start_brace ();
                   1925:        genamode (curi->dmode, "dstreg", curi->size, "src", 1, 0);
                   1926:        printf ("\tif (extra & 0x8000) {\n");
                   1927:        switch (curi->size) {
                   1928:        case sz_byte: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = (uae_s32)(uae_s8)src;\n"); break;
                   1929:        case sz_word: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = (uae_s32)(uae_s16)src;\n"); break;
                   1930:        case sz_long: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = src;\n"); break;
                   1931:        default: abort ();
1.1       root     1932:        }
1.1.1.11  root     1933:        printf ("\t} else {\n");
                   1934:        genastore ("src", Dreg, "(extra >> 12) & 7", curi->size, "");
                   1935:        printf ("\t}\n");
                   1936:        pop_braces (old_brace_level);
                   1937:     }
                   1938:     break;
                   1939:     case i_BKPT:               /* only needed for hardware emulators */
1.1.1.5   root     1940:        sync_m68k_pc ();
1.1.1.3   root     1941:        printf ("\top_illg(opcode);\n");
1.1       root     1942:        break;
1.1.1.11  root     1943:     case i_CALLM:              /* not present in 68030 */
1.1.1.5   root     1944:        sync_m68k_pc ();
1.1.1.3   root     1945:        printf ("\top_illg(opcode);\n");
1.1       root     1946:        break;
1.1.1.11  root     1947:     case i_RTM:                /* not present in 68030 */
1.1.1.5   root     1948:        sync_m68k_pc ();
1.1.1.3   root     1949:        printf ("\top_illg(opcode);\n");
1.1       root     1950:        break;
1.1.1.11  root     1951:     case i_TRAPcc:
1.1.1.7   root     1952:        if (curi->smode != am_unknown && curi->smode != am_illg)
                   1953:            genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0);
                   1954:        printf ("\tif (cctrue(%d)) { Exception(7,m68k_getpc()); goto %s; }\n", curi->cc, endlabelstr);
1.1.1.5   root     1955:        need_endlabel = 1;
1.1       root     1956:        break;
1.1.1.11  root     1957:     case i_DIVL:
1.1.1.3   root     1958:        sync_m68k_pc ();
                   1959:        start_brace ();
                   1960:        printf ("\tuaecptr oldpc = m68k_getpc();\n");
1.1.1.7   root     1961:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
                   1962:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1.1.5   root     1963:        sync_m68k_pc ();
1.1.1.3   root     1964:        printf ("\tm68k_divl(opcode, dst, extra, oldpc);\n");
1.1       root     1965:        break;
1.1.1.11  root     1966:     case i_MULL:
1.1.1.7   root     1967:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
                   1968:        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
1.1.1.5   root     1969:        sync_m68k_pc ();
1.1.1.3   root     1970:        printf ("\tm68k_mull(opcode, dst, extra);\n");
1.1       root     1971:        break;
1.1.1.11  root     1972:     case i_BFTST:
                   1973:     case i_BFEXTU:
                   1974:     case i_BFCHG:
                   1975:     case i_BFEXTS:
                   1976:     case i_BFCLR:
                   1977:     case i_BFFFO:
                   1978:     case i_BFSET:
                   1979:     case i_BFINS:
1.1.1.7   root     1980:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
                   1981:        genamode (curi->dmode, "dstreg", sz_long, "dst", 2, 0);
1.1.1.5   root     1982:        start_brace ();
1.1.1.3   root     1983:        printf ("\tuae_s32 offset = extra & 0x800 ? m68k_dreg(regs, (extra >> 6) & 7) : (extra >> 6) & 0x1f;\n");
                   1984:        printf ("\tint width = (((extra & 0x20 ? m68k_dreg(regs, extra & 7) : extra) -1) & 0x1f) +1;\n");
1.1.1.7   root     1985:        if (curi->dmode == Dreg) {
1.1.1.3   root     1986:            printf ("\tuae_u32 tmp = m68k_dreg(regs, dstreg) << (offset & 0x1f);\n");
                   1987:        } else {
                   1988:            printf ("\tuae_u32 tmp,bf0,bf1;\n");
                   1989:            printf ("\tdsta += (offset >> 3) | (offset & 0x80000000 ? ~0x1fffffff : 0);\n");
                   1990:            printf ("\tbf0 = get_long(dsta);bf1 = get_byte(dsta+4) & 0xff;\n");
                   1991:            printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n");
                   1992:        }
                   1993:        printf ("\ttmp >>= (32 - width);\n");
1.1.1.7   root     1994:        printf ("\tSET_NFLG (tmp & (1 << (width-1)) ? 1 : 0);\n");
                   1995:        printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n");
                   1996:        switch (curi->mnemo) {
1.1.1.11  root     1997:        case i_BFTST:
1.1.1.3   root     1998:            break;
1.1.1.11  root     1999:        case i_BFEXTU:
1.1.1.3   root     2000:            printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n");
                   2001:            break;
1.1.1.11  root     2002:        case i_BFCHG:
1.1.1.3   root     2003:            printf ("\ttmp = ~tmp;\n");
                   2004:            break;
1.1.1.11  root     2005:        case i_BFEXTS:
1.1.1.7   root     2006:            printf ("\tif (GET_NFLG) tmp |= width == 32 ? 0 : (-1 << width);\n");
1.1.1.3   root     2007:            printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n");
                   2008:            break;
1.1.1.11  root     2009:        case i_BFCLR:
1.1.1.3   root     2010:            printf ("\ttmp = 0;\n");
                   2011:            break;
1.1.1.11  root     2012:        case i_BFFFO:
1.1.1.3   root     2013:            printf ("\t{ uae_u32 mask = 1 << (width-1);\n");
                   2014:            printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset++; }}\n");
                   2015:            printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = offset;\n");
                   2016:            break;
1.1.1.11  root     2017:        case i_BFSET:
1.1.1.3   root     2018:            printf ("\ttmp = 0xffffffff;\n");
                   2019:            break;
1.1.1.11  root     2020:        case i_BFINS:
1.1.1.3   root     2021:            printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n");
1.1.1.15! root     2022:            printf ("\tSET_NFLG (tmp & (1 << (width - 1)) ? 1 : 0);\n");
        !          2023:            printf ("\tSET_ZFLG (tmp == 0);\n");
1.1.1.3   root     2024:            break;
1.1.1.11  root     2025:        default:
1.1.1.3   root     2026:            break;
1.1       root     2027:        }
1.1.1.7   root     2028:        if (curi->mnemo == i_BFCHG
                   2029:            || curi->mnemo == i_BFCLR
                   2030:            || curi->mnemo == i_BFSET
                   2031:            || curi->mnemo == i_BFINS)
1.1.1.11  root     2032:            {
                   2033:                printf ("\ttmp <<= (32 - width);\n");
                   2034:                if (curi->dmode == Dreg) {
                   2035:                    printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & ((offset & 0x1f) == 0 ? 0 :\n");
                   2036:                    printf ("\t\t(0xffffffff << (32 - (offset & 0x1f))))) |\n");
                   2037:                    printf ("\t\t(tmp >> (offset & 0x1f)) |\n");
                   2038:                    printf ("\t\t(((offset & 0x1f) + width) >= 32 ? 0 :\n");
                   2039:                    printf (" (m68k_dreg(regs, dstreg) & ((uae_u32)0xffffffff >> ((offset & 0x1f) + width))));\n");
                   2040:                } else {
                   2041:                    printf ("\tbf0 = (bf0 & (0xff000000 << (8 - (offset & 7)))) |\n");
                   2042:                    printf ("\t\t(tmp >> (offset & 7)) |\n");
                   2043:                    printf ("\t\t(((offset & 7) + width) >= 32 ? 0 :\n");
                   2044:                    printf ("\t\t (bf0 & ((uae_u32)0xffffffff >> ((offset & 7) + width))));\n");
                   2045:                    printf ("\tput_long(dsta,bf0 );\n");
                   2046:                    printf ("\tif (((offset & 7) + width) > 32) {\n");
                   2047:                    printf ("\t\tbf1 = (bf1 & (0xff >> (width - 32 + (offset & 7)))) |\n");
                   2048:                    printf ("\t\t\t(tmp << (8 - (offset & 7)));\n");
                   2049:                    printf ("\t\tput_byte(dsta+4,bf1);\n");
                   2050:                    printf ("\t}\n");
                   2051:                }
1.1.1.5   root     2052:            }
1.1       root     2053:        break;
1.1.1.11  root     2054:     case i_PACK:
1.1.1.7   root     2055:        if (curi->smode == Dreg) {
1.1.1.5   root     2056:            printf ("\tuae_u16 val = m68k_dreg(regs, srcreg) + %s;\n", gen_nextiword ());
1.1.1.3   root     2057:            printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & 0xffffff00) | ((val >> 4) & 0xf0) | (val & 0xf);\n");
                   2058:        } else {
                   2059:            printf ("\tuae_u16 val;\n");
                   2060:            printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n");
                   2061:            printf ("\tval = (uae_u16)get_byte(m68k_areg(regs, srcreg));\n");
                   2062:            printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n");
1.1.1.5   root     2063:            printf ("\tval = (val | ((uae_u16)get_byte(m68k_areg(regs, srcreg)) << 8)) + %s;\n", gen_nextiword ());
1.1.1.3   root     2064:            printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n");
                   2065:            printf ("\tput_byte(m68k_areg(regs, dstreg),((val >> 4) & 0xf0) | (val & 0xf));\n");
1.1       root     2066:        }
                   2067:        break;
1.1.1.11  root     2068:     case i_UNPK:
1.1.1.7   root     2069:        if (curi->smode == Dreg) {
1.1.1.3   root     2070:            printf ("\tuae_u16 val = m68k_dreg(regs, srcreg);\n");
1.1.1.5   root     2071:            printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword ());
1.1.1.3   root     2072:            printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & 0xffff0000) | (val & 0xffff);\n");
                   2073:        } else {
                   2074:            printf ("\tuae_u16 val;\n");
                   2075:            printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n");
                   2076:            printf ("\tval = (uae_u16)get_byte(m68k_areg(regs, srcreg));\n");
1.1.1.5   root     2077:            printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword ());
1.1.1.3   root     2078:            printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n");
                   2079:            printf ("\tput_byte(m68k_areg(regs, dstreg),val);\n");
                   2080:            printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n");
                   2081:            printf ("\tput_byte(m68k_areg(regs, dstreg),val >> 8);\n");
1.1       root     2082:        }
                   2083:        break;
1.1.1.11  root     2084:     case i_TAS:
1.1.1.7   root     2085:        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
                   2086:        genflags (flag_logical, curi->size, "src", "", "");
1.1.1.3   root     2087:        printf ("\tsrc |= 0x80;\n");
1.1.1.7   root     2088:        genastore ("src", curi->smode, "srcreg", curi->size, "src");
1.1       root     2089:        break;
1.1.1.11  root     2090:     case i_FPP:
1.1.1.7   root     2091:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1.1.1.5   root     2092:        sync_m68k_pc ();
1.1.1.3   root     2093:        printf ("\tfpp_opp(opcode,extra);\n");
1.1       root     2094:        break;
1.1.1.11  root     2095:     case i_FDBcc:
1.1.1.7   root     2096:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1.1.1.5   root     2097:        sync_m68k_pc ();
1.1.1.3   root     2098:        printf ("\tfdbcc_opp(opcode,extra);\n");
1.1       root     2099:        break;
1.1.1.11  root     2100:     case i_FScc:
1.1.1.7   root     2101:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1.1.1.5   root     2102:        sync_m68k_pc ();
1.1.1.3   root     2103:        printf ("\tfscc_opp(opcode,extra);\n");
1.1       root     2104:        break;
1.1.1.11  root     2105:     case i_FTRAPcc:
1.1.1.5   root     2106:        sync_m68k_pc ();
                   2107:        start_brace ();
1.1.1.3   root     2108:        printf ("\tuaecptr oldpc = m68k_getpc();\n");
1.1.1.7   root     2109:        if (curi->smode != am_unknown && curi->smode != am_illg)
                   2110:            genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0);
1.1.1.5   root     2111:        sync_m68k_pc ();
1.1.1.3   root     2112:        printf ("\tftrapcc_opp(opcode,oldpc);\n");
1.1       root     2113:        break;
1.1.1.11  root     2114:     case i_FBcc:
1.1.1.5   root     2115:        sync_m68k_pc ();
                   2116:        start_brace ();
1.1.1.3   root     2117:        printf ("\tuaecptr pc = m68k_getpc();\n");
1.1.1.7   root     2118:        genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0);
1.1.1.5   root     2119:        sync_m68k_pc ();
1.1.1.3   root     2120:        printf ("\tfbcc_opp(opcode,pc,extra);\n");
1.1       root     2121:        break;
1.1.1.11  root     2122:     case i_FSAVE:
1.1.1.5   root     2123:        sync_m68k_pc ();
1.1.1.3   root     2124:        printf ("\tfsave_opp(opcode);\n");
1.1       root     2125:        break;
1.1.1.11  root     2126:     case i_FRESTORE:
1.1.1.5   root     2127:        sync_m68k_pc ();
1.1.1.3   root     2128:        printf ("\tfrestore_opp(opcode);\n");
1.1       root     2129:        break;
1.1.1.12  root     2130: 
                   2131:      case i_CINVL:
                   2132:      case i_CINVP:
                   2133:      case i_CINVA:
                   2134:      case i_CPUSHL:
                   2135:      case i_CPUSHP:
                   2136:      case i_CPUSHA:
                   2137:        break;
                   2138:      case i_MOVE16:
1.1.1.14  root     2139:         if ((opcode & 0xfff8) == 0xf620) {
                   2140:             /* MOVE16 (Ax)+,(Ay)+ */
                   2141:             printf ("\tuaecptr mems = m68k_areg(regs, srcreg) & ~15, memd;\n");
                   2142:             printf ("\tdstreg = (%s >> 12) & 7;\n", gen_nextiword());
                   2143:             printf ("\tmemd = m68k_areg(regs, dstreg) & ~15;\n");
                   2144:             printf ("\tput_long(memd, get_long(mems));\n");
                   2145:             printf ("\tput_long(memd+4, get_long(mems+4));\n");
                   2146:             printf ("\tput_long(memd+8, get_long(mems+8));\n");
                   2147:             printf ("\tput_long(memd+12, get_long(mems+12));\n");
                   2148:             printf ("\tif (srcreg != dstreg)\n");
                   2149:             printf ("\tm68k_areg(regs, srcreg) += 16;\n");
                   2150:             printf ("\tm68k_areg(regs, dstreg) += 16;\n");
                   2151:         } else {
                   2152:             /* Other variants */
                   2153:             genamode (curi->smode, "srcreg", curi->size, "mems", 0, 2);
                   2154:             genamode (curi->dmode, "dstreg", curi->size, "memd", 0, 2);
                   2155:             printf ("\tmemsa &= ~15;\n");
                   2156:             printf ("\tmemda &= ~15;\n");
                   2157:             printf ("\tput_long(memda, get_long(memsa));\n");
                   2158:             printf ("\tput_long(memda+4, get_long(memsa+4));\n");
                   2159:             printf ("\tput_long(memda+8, get_long(memsa+8));\n");
                   2160:             printf ("\tput_long(memda+12, get_long(memsa+12));\n");
                   2161:             if ((opcode & 0xfff8) == 0xf600)
                   2162:                  printf ("\tm68k_areg(regs, srcreg) += 16;\n");
                   2163:             else if ((opcode & 0xfff8) == 0xf608)
                   2164:                 printf ("\tm68k_areg(regs, dstreg) += 16;\n");
                   2165:         }
                   2166:         break;
1.1.1.12  root     2167: 
1.1.1.11  root     2168:     case i_MMUOP:
1.1.1.7   root     2169:        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
1.1.1.5   root     2170:        sync_m68k_pc ();
1.1.1.3   root     2171:        printf ("\tmmu_op(opcode,extra);\n");
1.1       root     2172:        break;
1.1.1.11  root     2173:     default:
1.1.1.5   root     2174:        abort ();
1.1       root     2175:        break;
1.1.1.5   root     2176:     }
1.1       root     2177:     finish_braces ();
1.1.1.3   root     2178:     sync_m68k_pc ();
1.1       root     2179: }
                   2180: 
1.1.1.5   root     2181: static void generate_includes (FILE * f)
1.1.1.3   root     2182: {
                   2183:     fprintf (f, "#include \"sysconfig.h\"\n");
                   2184:     fprintf (f, "#include \"sysdeps.h\"\n");
                   2185:     fprintf (f, "#include \"config.h\"\n");
                   2186:     fprintf (f, "#include \"options.h\"\n");
                   2187:     fprintf (f, "#include \"memory.h\"\n");
                   2188:     fprintf (f, "#include \"custom.h\"\n");
                   2189:     fprintf (f, "#include \"newcpu.h\"\n");
                   2190:     fprintf (f, "#include \"compiler.h\"\n");
                   2191:     fprintf (f, "#include \"cputbl.h\"\n");
1.1.1.12  root     2192:     
                   2193:     fprintf (f, "#define CPUFUNC(x) x##_ff\n"
                   2194:             "#ifdef NOFLAGS\n"
                   2195:             "#include \"noflags.h\"\n"
                   2196:             "#endif\n");
1.1.1.3   root     2197: }
                   2198: 
                   2199: static int postfix;
                   2200: 
                   2201: static void generate_one_opcode (int rp)
1.1       root     2202: {
                   2203:     int i;
1.1.1.3   root     2204:     uae_u16 smsk, dmsk;
                   2205:     long int opcode = opcode_map[rp];
1.1       root     2206: 
1.1.1.3   root     2207:     if (table68k[opcode].mnemo == i_ILLG
                   2208:        || table68k[opcode].clev > cpu_level)
                   2209:        return;
1.1       root     2210: 
1.1.1.5   root     2211:     for (i = 0; lookuptab[i].name[0]; i++) {
1.1.1.3   root     2212:        if (table68k[opcode].mnemo == lookuptab[i].mnemo)
                   2213:            break;
                   2214:     }
1.1       root     2215: 
1.1.1.3   root     2216:     if (table68k[opcode].handler != -1)
                   2217:        return;
1.1       root     2218: 
1.1.1.3   root     2219:     if (opcode_next_clev[rp] != cpu_level) {
1.1.1.12  root     2220:        fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
1.1.1.3   root     2221:                 opcode, lookuptab[i].name);
                   2222:        return;
                   2223:     }
1.1.1.12  root     2224:     fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
                   2225:     fprintf (headerfile, "extern cpuop_func op_%lx_%d_nf;\n", opcode, postfix);
                   2226:     fprintf (headerfile, "extern cpuop_func op_%lx_%d_ff;\n", opcode, postfix);
                   2227:     printf ("unsigned long REGPARAM2 CPUFUNC(op_%lx_%d)(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
1.1.1.3   root     2228: 
                   2229:     switch (table68k[opcode].stype) {
1.1.1.14  root     2230:     case 0: smsk = 7; break;
                   2231:     case 1: smsk = 255; break;
                   2232:     case 2: smsk = 15; break;
                   2233:     case 3: smsk = 7; break;
                   2234:     case 4: smsk = 7; break;
                   2235:     case 5: smsk = 63; break;
                   2236:     case 7: smsk = 3; break;
                   2237:     default: abort ();
1.1.1.3   root     2238:     }
                   2239:     dmsk = 7;
                   2240: 
                   2241:     next_cpu_level = -1;
                   2242:     if (table68k[opcode].suse
1.1.1.5   root     2243:        && table68k[opcode].smode != imm && table68k[opcode].smode != imm0
1.1.1.3   root     2244:        && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2
                   2245:        && table68k[opcode].smode != absw && table68k[opcode].smode != absl
                   2246:        && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16)
                   2247:     {
                   2248:        if (table68k[opcode].spos == -1) {
1.1.1.5   root     2249:            if (((int) table68k[opcode].sreg) >= 128)
                   2250:                printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg);
1.1.1.3   root     2251:            else
1.1.1.5   root     2252:                printf ("\tuae_u32 srcreg = %d;\n", (int) table68k[opcode].sreg);
1.1.1.3   root     2253:        } else {
                   2254:            char source[100];
1.1.1.6   root     2255:            int pos = table68k[opcode].spos;
1.1.1.5   root     2256: 
1.1.1.6   root     2257:            if (pos)
                   2258:                sprintf (source, "((opcode >> %d) & %d)", pos, smsk);
1.1.1.3   root     2259:            else
1.1.1.5   root     2260:                sprintf (source, "(opcode & %d)", smsk);
                   2261: 
1.1.1.3   root     2262:            if (table68k[opcode].stype == 3)
                   2263:                printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source);
                   2264:            else if (table68k[opcode].stype == 1)
                   2265:                printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source);
                   2266:            else
                   2267:                printf ("\tuae_u32 srcreg = %s;\n", source);
1.1       root     2268:        }
1.1.1.3   root     2269:     }
                   2270:     if (table68k[opcode].duse
                   2271:        /* Yes, the dmode can be imm, in case of LINK or DBcc */
1.1.1.5   root     2272:        && table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0
1.1.1.3   root     2273:        && table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2
1.1.1.5   root     2274:        && table68k[opcode].dmode != absw && table68k[opcode].dmode != absl)
                   2275:     {
1.1.1.3   root     2276:        if (table68k[opcode].dpos == -1) {
1.1.1.5   root     2277:            if (((int) table68k[opcode].dreg) >= 128)
                   2278:                printf ("\tuae_u32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg);
1.1.1.3   root     2279:            else
1.1.1.5   root     2280:                printf ("\tuae_u32 dstreg = %d;\n", (int) table68k[opcode].dreg);
1.1.1.3   root     2281:        } else {
1.1.1.5   root     2282:            int pos = table68k[opcode].dpos;
1.1.1.6   root     2283: #if 0
1.1.1.5   root     2284:            /* Check that we can do the little endian optimization safely.  */
1.1.1.6   root     2285:            if (pos < 8 && (dmsk >> (8 - pos)) != 0)
1.1.1.5   root     2286:                abort ();
1.1.1.6   root     2287: #endif     
1.1.1.5   root     2288:            if (pos)
1.1.1.3   root     2289:                printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n",
1.1.1.5   root     2290:                        pos, dmsk);
1.1.1.3   root     2291:            else
                   2292:                printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk);
1.1       root     2293:        }
                   2294:     }
1.1.1.5   root     2295:     need_endlabel = 0;
1.1.1.3   root     2296:     endlabelno++;
                   2297:     sprintf (endlabelstr, "endlabel%d", endlabelno);
                   2298:     gen_opcode (opcode);
1.1.1.5   root     2299:     if (need_endlabel)
1.1.1.6   root     2300:        printf ("%s: ;\n", endlabelstr);
1.1.1.13  root     2301:     printf ("return %d;\n", insn_n_cycles * CYCLE_UNIT / 2);
1.1.1.3   root     2302:     printf ("}\n");
                   2303:     opcode_next_clev[rp] = next_cpu_level;
                   2304:     opcode_last_postfix[rp] = postfix;
1.1       root     2305: }
                   2306: 
1.1.1.3   root     2307: static void generate_func (void)
1.1       root     2308: {
1.1.1.5   root     2309:     int i, j, rp;
1.1       root     2310: 
1.1.1.3   root     2311:     using_prefetch = 0;
                   2312:     using_exception_3 = 0;
1.1.1.12  root     2313:     for (i = 0; i < 6; i++) {
                   2314:        cpu_level = 4 - i;
                   2315:        if (i == 5) {
1.1.1.3   root     2316:            cpu_level = 0;
                   2317:            using_prefetch = 1;
                   2318:            using_exception_3 = 1;
                   2319:            for (rp = 0; rp < nr_cpuop_funcs; rp++)
                   2320:                opcode_next_clev[rp] = 0;
                   2321:        }
1.1.1.12  root     2322: 
1.1.1.3   root     2323:        postfix = i;
1.1.1.12  root     2324:        fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix);
1.1.1.3   root     2325: 
1.1.1.5   root     2326:        /* sam: this is for people with low memory (eg. me :)) */
                   2327:        printf ("\n"
                   2328:                 "#if !defined(PART_1) && !defined(PART_2) && "
                   2329:                    "!defined(PART_3) && !defined(PART_4) && "
                   2330:                    "!defined(PART_5) && !defined(PART_6) && "
                   2331:                    "!defined(PART_7) && !defined(PART_8)"
                   2332:                "\n"
                   2333:                "#define PART_1 1\n"
                   2334:                "#define PART_2 1\n"
                   2335:                "#define PART_3 1\n"
                   2336:                "#define PART_4 1\n"
                   2337:                "#define PART_5 1\n"
                   2338:                "#define PART_6 1\n"
                   2339:                "#define PART_7 1\n"
                   2340:                "#define PART_8 1\n"
                   2341:                "#endif\n\n");
                   2342:        
                   2343:        rp = 0;
                   2344:        for(j=1;j<=8;++j) {
                   2345:                int k = (j*nr_cpuop_funcs)/8;
                   2346:                printf ("#ifdef PART_%d\n",j);
                   2347:                for (; rp < k; rp++)
                   2348:                   generate_one_opcode (rp);
                   2349:                printf ("#endif\n\n");
                   2350:        }
                   2351: 
1.1.1.3   root     2352:        fprintf (stblfile, "{ 0, 0, 0 }};\n");
1.1       root     2353:     }
                   2354: 
                   2355: }
                   2356: 
1.1.1.3   root     2357: int main (int argc, char **argv)
1.1.1.5   root     2358: {
1.1       root     2359:     read_table68k ();
                   2360:     do_merges ();
1.1.1.3   root     2361: 
1.1.1.5   root     2362:     opcode_map = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs);
                   2363:     opcode_last_postfix = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs);
                   2364:     opcode_next_clev = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs);
                   2365:     counts = (unsigned long *) xmalloc (65536 * sizeof (unsigned long));
                   2366:     read_counts ();
1.1.1.3   root     2367: 
                   2368:     /* It would be a lot nicer to put all in one file (we'd also get rid of
                   2369:      * cputbl.h that way), but cpuopti can't cope.  That could be fixed, but
                   2370:      * I don't dare to touch the 68k version.  */
1.1.1.5   root     2371: 
1.1.1.3   root     2372:     headerfile = fopen ("cputbl.h", "wb");
                   2373:     stblfile = fopen ("cpustbl.c", "wb");
                   2374:     freopen ("cpuemu.c", "wb", stdout);
                   2375: 
                   2376:     generate_includes (stdout);
                   2377:     generate_includes (stblfile);
                   2378: 
                   2379:     generate_func ();
                   2380: 
                   2381:     free (table68k);
1.1       root     2382:     return 0;
                   2383: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.