--- BasiliskII/src/uae_cpu/gencpu.c 2002/01/06 08:21:09 1.16 +++ BasiliskII/src/uae_cpu/gencpu.c 2002/09/01 15:17:13 1.17 @@ -725,7 +725,6 @@ static void genflags (flagtypes type, wo start_brace (); printf ("\tuae_u32 %s;\n", value); break; - default: break; } @@ -746,6 +745,7 @@ static void genflags (flagtypes type, wo } printf ("\t}\n"); return; + case flag_logical: if (strcmp (value, "0") == 0) { printf ("\tSET_CZNV (FLAGVAL_Z);\n"); @@ -786,7 +786,6 @@ static void genflags (flagtypes type, wo break; } #endif - genflags_normal (type, size, value, src, dst); } @@ -824,6 +823,25 @@ static int source_is_imm1_8 (struct inst return i->stype == 3; } +static const char * cflow_string_of(uae_u32 opcode) +{ + const char * cflow_type_str; + + int cflow_type = table68k[opcode].cflow & ~fl_trap; + switch (cflow_type) { + case fl_branch: cflow_type_str = "CFLOW_BRANCH"; break; + case fl_jump: cflow_type_str = "CFLOW_JUMP"; break; + case fl_return: cflow_type_str = "CFLOW_RETURN"; break; + default: cflow_type_str = "CFLOW_NORMAL"; + } + + /* Patch M68K_EXEC_RETURN instruction */ + if (table68k[opcode].mnemo == i_EMULOP_RETURN) + cflow_type_str = "CFLOW_EXEC_RETURN"; + + return cflow_type_str; +} + static void gen_opcode (unsigned long int opcode) { struct instr *curi = table68k + opcode; @@ -957,7 +975,7 @@ static void gen_opcode (unsigned long in printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n"); printf ("\tuae_u16 newv, tmp_newv;\n"); printf ("\tint cflg;\n"); - printf ("\tnewv = tmp_newv = newv_hi + newv_lo;"); + printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n"); printf ("\tif (newv_lo > 9) { newv += 6; }\n"); printf ("\tcflg = (newv & 0x3F0) > 0x90;\n"); printf ("\tif (cflg) newv += 0x60;\n"); @@ -989,7 +1007,7 @@ static void gen_opcode (unsigned long in printf ("\tuae_u16 newv;\n"); printf ("\tint cflg;\n"); printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n"); - printf ("\tnewv = newv_hi + newv_lo;"); + printf ("\tnewv = newv_hi + newv_lo;\n"); printf ("\tcflg = (newv & 0x1F0) > 0x90;\n"); printf ("\tif (cflg) newv -= 0x60;\n"); printf ("\tSET_CFLG (cflg);\n"); @@ -1201,6 +1219,7 @@ static void gen_opcode (unsigned long in printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n"); printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n"); printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n"); + /* gb-- the next two lines are deleted in Bernie's gencpu.c */ printf ("\telse if ((format & 0xF000) == 0x3000) { m68k_areg(regs, 7) += 4; break; }\n"); printf ("\telse if ((format & 0xF000) == 0x7000) { m68k_areg(regs, 7) += 52; break; }\n"); printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n"); @@ -1289,6 +1308,18 @@ static void gen_opcode (unsigned long in m68k_pc_offset = 0; break; case i_Bcc: + if (0 && !using_prefetch && !using_exception_3 && (cpu_level >= 2)) { + /* gb-- variant probably more favorable to compiler optimizations + also assumes no prefetch buffer is used + Hmm, that would make sense with processors capable of conditional moves */ + if (curi->size == sz_long && next_cpu_level < 1) + next_cpu_level = 1; + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); + printf ("\tm68k_incpc (cctrue(%d) ? ((uae_s32)src + 2) : %d);\n", curi->cc, m68k_pc_offset); + m68k_pc_offset = 0; + } + else { + /* original code for branch instructions */ if (curi->size == sz_long) { if (cpu_level < 2) { printf ("\tm68k_incpc(2);\n"); @@ -1312,15 +1343,12 @@ static void gen_opcode (unsigned long in printf ("\t}\n"); need_endlabel = 1; } -#ifdef USE_COMPILER - printf ("\tm68k_setpc_bcc(m68k_getpc() + 2 + (uae_s32)src);\n"); -#else printf ("\tm68k_incpc ((uae_s32)src + 2);\n"); -#endif fill_prefetch_0 (); - printf ("\tgoto %s;\n", endlabelstr); + printf ("cpuop_return(%s);\n", cflow_string_of(opcode)); printf ("didnt_jump:;\n"); need_endlabel = 1; + } break; case i_LEA: genamode (curi->smode, "srcreg", curi->size, "src", 0, 0); @@ -1348,13 +1376,9 @@ static void gen_opcode (unsigned long in printf ("\t\t}\n"); need_endlabel = 1; } -#ifdef USE_COMPILER - printf ("\t\t\tm68k_setpc_bcc(m68k_getpc() + (uae_s32)offs + 2);\n"); -#else printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n"); -#endif fill_prefetch_0 (); - printf ("\t\tgoto %s;\n", endlabelstr); + printf ("cpuop_return(%s);\n", cflow_string_of(opcode)); printf ("\t\t}\n"); printf ("\t}\n"); need_endlabel = 1; @@ -1452,7 +1476,7 @@ static void gen_opcode (unsigned long in abort (); } printf ("\tSET_ZFLG (upper == reg || lower == reg);\n"); - printf ("\tSET_CFLG (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n"); + printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n"); printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr); need_endlabel = 1; break; @@ -1989,7 +2013,7 @@ static void gen_opcode (unsigned long in printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n"); } printf ("\ttmp >>= (32 - width);\n"); - printf ("\tSET_NFLG (tmp & (1 << (width-1)) ? 1 : 0);\n"); + printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width-1)) ? 1 : 0);\n"); printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n"); switch (curi->mnemo) { case i_BFTST: @@ -2017,7 +2041,7 @@ static void gen_opcode (unsigned long in break; case i_BFINS: printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n"); - printf ("\tSET_NFLG (tmp & (1 << (width - 1)) ? 1 : 0);\n"); + printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width - 1)) ? 1 : 0);\n"); printf ("\tSET_ZFLG (tmp == 0);\n"); break; default: @@ -2175,6 +2199,18 @@ static void gen_opcode (unsigned long in swap_opcode (); printf ("\tmmu_op(opcode,extra);\n"); break; + + case i_EMULOP_RETURN: + printf ("\tm68k_emulop_return();\n"); + m68k_pc_offset = 0; + break; + + case i_EMULOP: + printf ("\n"); + swap_opcode (); + printf ("\tm68k_emulop(opcode);\n"); + break; + default: abort (); break; @@ -2186,11 +2222,22 @@ static void gen_opcode (unsigned long in static void generate_includes (FILE * f) { fprintf (f, "#include \"sysdeps.h\"\n"); + fprintf (f, "#include \"m68k.h\"\n"); fprintf (f, "#include \"memory.h\"\n"); fprintf (f, "#include \"readcpu.h\"\n"); fprintf (f, "#include \"newcpu.h\"\n"); fprintf (f, "#include \"cputbl.h\"\n"); + + fprintf (f, "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n"); + fprintf (f, "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n"); + fprintf (f, "#define CPUFUNC_FF(x) x##_ff\n"); + fprintf (f, "#define CPUFUNC_NF(x) x##_nf\n"); + fprintf (f, "#define CPUFUNC(x) CPUFUNC_FF(x)\n"); + + fprintf (f, "#ifdef NOFLAGS\n"); + fprintf (f, "# include \"noflags.h\"\n"); + fprintf (f, "#endif\n"); } static int postfix; @@ -2214,13 +2261,28 @@ static void generate_one_opcode (int rp) return; if (opcode_next_clev[rp] != cpu_level) { - fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp], + fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp], opcode, lookuptab[i].name); return; } - fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name); - fprintf (headerfile, "extern cpuop_func op_%lx_%d;\n", opcode, postfix); - printf ("void REGPARAM2 op_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name); + + if (table68k[opcode].flagdead == 0) + /* force to the "ff" variant since the instruction doesn't set at all the condition codes */ + fprintf (stblfile, "{ CPUFUNC_FF(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name); + else + fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name); + + fprintf (headerfile, "extern cpuop_func op_%lx_%d_nf;\n", opcode, postfix); + fprintf (headerfile, "extern cpuop_func op_%lx_%d_ff;\n", opcode, postfix); + printf ("cpuop_rettype REGPARAM2 CPUFUNC(op_%lx_%d)(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name); + printf ("\tcpuop_begin();\n"); + + /* gb-- The "nf" variant for an instruction that doesn't set the condition + codes at all is the same as the "ff" variant, so we don't need the "nf" + variant to be compiled since it is mapped to the "ff" variant in the + smalltbl. */ + if (table68k[opcode].flagdead == 0) + printf ("#ifndef NOFLAGS\n"); switch (table68k[opcode].stype) { case 0: smsk = 7; break; @@ -2229,6 +2291,7 @@ static void generate_one_opcode (int rp) case 3: smsk = 7; break; case 4: smsk = 7; break; case 5: smsk = 63; break; + case 6: smsk = 255; break; case 7: smsk = 3; break; default: abort (); } @@ -2239,7 +2302,12 @@ static void generate_one_opcode (int rp) && table68k[opcode].smode != imm && table68k[opcode].smode != imm0 && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2 && table68k[opcode].smode != absw && table68k[opcode].smode != absl - && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16) + && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16 + /* gb-- We don't want to fetch the EmulOp code since the EmulOp() + routine uses the whole opcode value. Maybe all the EmulOps + could be expanded out but I don't think it is an improvement */ + && table68k[opcode].stype != 6 + ) { if (table68k[opcode].spos == -1) { if (((int) table68k[opcode].sreg) >= 128) @@ -2335,6 +2403,9 @@ static void generate_one_opcode (int rp) gen_opcode (opcode); if (need_endlabel) printf ("%s: ;\n", endlabelstr); + if (table68k[opcode].flagdead == 0) + printf ("\n#endif\n"); + printf ("\tcpuop_end(%s);\n", cflow_string_of(opcode)); printf ("}\n"); opcode_next_clev[rp] = next_cpu_level; opcode_last_postfix[rp] = postfix; @@ -2362,7 +2433,7 @@ static void generate_func (void) opcode_next_clev[rp] = 0; } postfix = i; - fprintf (stblfile, "struct cputbl op_smalltbl_%d[] = {\n", postfix); + fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix); /* sam: this is for people with low memory (eg. me :)) */ printf ("\n"