ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/gencpu.c
(Generate patch)

Comparing BasiliskII/src/uae_cpu/gencpu.c (file contents):
Revision 1.15 by gbeauche, 2001-08-19T16:21:01Z vs.
Revision 1.17 by gbeauche, 2002-09-01T15:17:13Z

# Line 725 | Line 725 | static void genflags (flagtypes type, wo
725          start_brace ();
726          printf ("\tuae_u32 %s;\n", value);
727          break;
728
728       default:
729          break;
730      }
# Line 746 | Line 745 | static void genflags (flagtypes type, wo
745          }
746          printf ("\t}\n");
747          return;
748 +        
749       case flag_logical:
750          if (strcmp (value, "0") == 0) {
751              printf ("\tSET_CZNV (FLAGVAL_Z);\n");
# Line 786 | Line 786 | static void genflags (flagtypes type, wo
786          break;
787      }
788   #endif
789
789      genflags_normal (type, size, value, src, dst);
790   }
791  
# Line 824 | Line 823 | static int source_is_imm1_8 (struct inst
823      return i->stype == 3;
824   }
825  
826 + static const char * cflow_string_of(uae_u32 opcode)
827 + {
828 +        const char * cflow_type_str;
829 +        
830 +        int cflow_type = table68k[opcode].cflow & ~fl_trap;
831 +        switch (cflow_type) {
832 +                case fl_branch:         cflow_type_str = "CFLOW_BRANCH";                break;
833 +                case fl_jump:           cflow_type_str = "CFLOW_JUMP";                  break;
834 +                case fl_return:         cflow_type_str = "CFLOW_RETURN";                break;
835 +                default:                        cflow_type_str = "CFLOW_NORMAL";
836 +        }
837 +        
838 +        /* Patch M68K_EXEC_RETURN instruction */
839 +        if (table68k[opcode].mnemo == i_EMULOP_RETURN)
840 +                cflow_type_str = "CFLOW_EXEC_RETURN";
841 +        
842 +        return cflow_type_str;
843 + }
844 +
845   static void gen_opcode (unsigned long int opcode)
846   {
847      struct instr *curi = table68k + opcode;
# Line 957 | Line 975 | static void gen_opcode (unsigned long in
975          printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
976          printf ("\tuae_u16 newv, tmp_newv;\n");
977          printf ("\tint cflg;\n");
978 <        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;");
978 >        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
979          printf ("\tif (newv_lo > 9) { newv += 6; }\n");
980          printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
981          printf ("\tif (cflg) newv += 0x60;\n");
# Line 989 | Line 1007 | static void gen_opcode (unsigned long in
1007          printf ("\tuae_u16 newv;\n");
1008          printf ("\tint cflg;\n");
1009          printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n");
1010 <        printf ("\tnewv = newv_hi + newv_lo;");
1010 >        printf ("\tnewv = newv_hi + newv_lo;\n");
1011          printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
1012          printf ("\tif (cflg) newv -= 0x60;\n");
1013          printf ("\tSET_CFLG (cflg);\n");
# Line 1201 | Line 1219 | static void gen_opcode (unsigned long in
1219              printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n");
1220              printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n");
1221              printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n");
1222 +            /* gb-- the next two lines are deleted in Bernie's gencpu.c */
1223              printf ("\telse if ((format & 0xF000) == 0x3000) { m68k_areg(regs, 7) += 4; break; }\n");
1224              printf ("\telse if ((format & 0xF000) == 0x7000) { m68k_areg(regs, 7) += 52; break; }\n");
1225              printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n");
# Line 1289 | Line 1308 | static void gen_opcode (unsigned long in
1308          m68k_pc_offset = 0;
1309          break;
1310       case i_Bcc:
1311 +        if (0 && !using_prefetch && !using_exception_3 && (cpu_level >= 2)) {
1312 +        /* gb-- variant probably more favorable to compiler optimizations
1313 +                    also assumes no prefetch buffer is used
1314 +        Hmm, that would make sense with processors capable of conditional moves */
1315 +        if (curi->size == sz_long && next_cpu_level < 1)
1316 +                next_cpu_level = 1;
1317 +        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1318 +        printf ("\tm68k_incpc (cctrue(%d) ? ((uae_s32)src + 2) : %d);\n", curi->cc, m68k_pc_offset);
1319 +        m68k_pc_offset = 0;
1320 +        }
1321 +        else {
1322 +        /* original code for branch instructions */
1323          if (curi->size == sz_long) {
1324              if (cpu_level < 2) {
1325                  printf ("\tm68k_incpc(2);\n");
# Line 1312 | Line 1343 | static void gen_opcode (unsigned long in
1343              printf ("\t}\n");
1344              need_endlabel = 1;
1345          }
1315 #ifdef USE_COMPILER
1316        printf ("\tm68k_setpc_bcc(m68k_getpc() + 2 + (uae_s32)src);\n");
1317 #else
1346          printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
1319 #endif
1347          fill_prefetch_0 ();
1348 <        printf ("\tgoto %s;\n", endlabelstr);
1348 >        printf ("cpuop_return(%s);\n", cflow_string_of(opcode));
1349          printf ("didnt_jump:;\n");
1350          need_endlabel = 1;
1351 +        }
1352          break;
1353       case i_LEA:
1354          genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
# Line 1348 | Line 1376 | static void gen_opcode (unsigned long in
1376              printf ("\t\t}\n");
1377              need_endlabel = 1;
1378          }
1351 #ifdef USE_COMPILER
1352        printf ("\t\t\tm68k_setpc_bcc(m68k_getpc() + (uae_s32)offs + 2);\n");
1353 #else
1379          printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n");
1355 #endif
1380          fill_prefetch_0 ();
1381 <        printf ("\t\tgoto %s;\n", endlabelstr);
1381 >        printf ("cpuop_return(%s);\n", cflow_string_of(opcode));
1382          printf ("\t\t}\n");
1383          printf ("\t}\n");
1384          need_endlabel = 1;
# Line 1452 | Line 1476 | static void gen_opcode (unsigned long in
1476              abort ();
1477          }
1478          printf ("\tSET_ZFLG (upper == reg || lower == reg);\n");
1479 <        printf ("\tSET_CFLG (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
1479 >        printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
1480          printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr);
1481          need_endlabel = 1;
1482          break;
# Line 1989 | Line 2013 | static void gen_opcode (unsigned long in
2013              printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n");
2014          }
2015          printf ("\ttmp >>= (32 - width);\n");
2016 <        printf ("\tSET_NFLG (tmp & (1 << (width-1)) ? 1 : 0);\n");
2016 >        printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width-1)) ? 1 : 0);\n");
2017          printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n");
2018          switch (curi->mnemo) {
2019           case i_BFTST:
# Line 2017 | Line 2041 | static void gen_opcode (unsigned long in
2041              break;
2042           case i_BFINS:
2043              printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n");
2044 +            printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width - 1)) ? 1 : 0);\n");
2045 +            printf ("\tSET_ZFLG (tmp == 0);\n");
2046              break;
2047           default:
2048              break;
# Line 2173 | Line 2199 | static void gen_opcode (unsigned long in
2199          swap_opcode ();
2200          printf ("\tmmu_op(opcode,extra);\n");
2201          break;
2202 +        
2203 +        case i_EMULOP_RETURN:
2204 +        printf ("\tm68k_emulop_return();\n");
2205 +        m68k_pc_offset = 0;
2206 +        break;
2207 +        
2208 +        case i_EMULOP:
2209 +        printf ("\n");
2210 +        swap_opcode ();
2211 +        printf ("\tm68k_emulop(opcode);\n");
2212 +        break;
2213 +        
2214       default:
2215          abort ();
2216          break;
# Line 2184 | Line 2222 | static void gen_opcode (unsigned long in
2222   static void generate_includes (FILE * f)
2223   {
2224      fprintf (f, "#include \"sysdeps.h\"\n");
2225 +        
2226      fprintf (f, "#include \"m68k.h\"\n");
2227      fprintf (f, "#include \"memory.h\"\n");
2228      fprintf (f, "#include \"readcpu.h\"\n");
2229      fprintf (f, "#include \"newcpu.h\"\n");
2230      fprintf (f, "#include \"cputbl.h\"\n");
2231 +        
2232 +        fprintf (f, "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n");
2233 +        fprintf (f, "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n");
2234 +        fprintf (f, "#define CPUFUNC_FF(x) x##_ff\n");
2235 +        fprintf (f, "#define CPUFUNC_NF(x) x##_nf\n");
2236 +        fprintf (f, "#define CPUFUNC(x) CPUFUNC_FF(x)\n");
2237 +        
2238 +        fprintf (f, "#ifdef NOFLAGS\n");
2239 +        fprintf (f, "# include \"noflags.h\"\n");
2240 +        fprintf (f, "#endif\n");
2241   }
2242  
2243   static int postfix;
# Line 2212 | Line 2261 | static void generate_one_opcode (int rp)
2261          return;
2262  
2263      if (opcode_next_clev[rp] != cpu_level) {
2264 <        fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2264 >        fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2265                   opcode, lookuptab[i].name);
2266          return;
2267      }
2268 <    fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
2269 <    fprintf (headerfile, "extern cpuop_func op_%lx_%d;\n", opcode, postfix);
2270 <    printf ("void REGPARAM2 op_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2268 >        
2269 >        if (table68k[opcode].flagdead == 0)
2270 >        /* force to the "ff" variant since the instruction doesn't set at all the condition codes */
2271 >    fprintf (stblfile, "{ CPUFUNC_FF(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
2272 >        else
2273 >    fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
2274 >
2275 >    fprintf (headerfile, "extern cpuop_func op_%lx_%d_nf;\n", opcode, postfix);
2276 >    fprintf (headerfile, "extern cpuop_func op_%lx_%d_ff;\n", opcode, postfix);
2277 >    printf ("cpuop_rettype REGPARAM2 CPUFUNC(op_%lx_%d)(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2278 >        printf ("\tcpuop_begin();\n");
2279 >        
2280 >        /* gb-- The "nf" variant for an instruction that doesn't set the condition
2281 >           codes at all is the same as the "ff" variant, so we don't need the "nf"
2282 >           variant to be compiled since it is mapped to the "ff" variant in the
2283 >           smalltbl. */
2284 >        if (table68k[opcode].flagdead == 0)
2285 >        printf ("#ifndef NOFLAGS\n");
2286  
2287      switch (table68k[opcode].stype) {
2288       case 0: smsk = 7; break;
# Line 2227 | Line 2291 | static void generate_one_opcode (int rp)
2291       case 3: smsk = 7; break;
2292       case 4: smsk = 7; break;
2293       case 5: smsk = 63; break;
2294 +         case 6: smsk = 255; break;
2295           case 7: smsk = 3; break;
2296       default: abort ();
2297      }
# Line 2237 | Line 2302 | static void generate_one_opcode (int rp)
2302          && table68k[opcode].smode != imm && table68k[opcode].smode != imm0
2303          && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2
2304          && table68k[opcode].smode != absw && table68k[opcode].smode != absl
2305 <        && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16)
2305 >        && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16
2306 >        /* gb-- We don't want to fetch the EmulOp code since the EmulOp()
2307 >           routine uses the whole opcode value. Maybe all the EmulOps
2308 >           could be expanded out but I don't think it is an improvement */
2309 >        && table68k[opcode].stype != 6
2310 >        )
2311      {
2312          if (table68k[opcode].spos == -1) {
2313              if (((int) table68k[opcode].sreg) >= 128)
# Line 2333 | Line 2403 | static void generate_one_opcode (int rp)
2403      gen_opcode (opcode);
2404      if (need_endlabel)
2405          printf ("%s: ;\n", endlabelstr);
2406 +        if (table68k[opcode].flagdead == 0)
2407 +        printf ("\n#endif\n");
2408 +        printf ("\tcpuop_end(%s);\n", cflow_string_of(opcode));
2409      printf ("}\n");
2410      opcode_next_clev[rp] = next_cpu_level;
2411      opcode_last_postfix[rp] = postfix;
# Line 2360 | Line 2433 | static void generate_func (void)
2433                  opcode_next_clev[rp] = 0;
2434          }
2435          postfix = i;
2436 <        fprintf (stblfile, "struct cputbl op_smalltbl_%d[] = {\n", postfix);
2436 >        fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix);
2437  
2438          /* sam: this is for people with low memory (eg. me :)) */
2439          printf ("\n"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines