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.1 by cebix, 1999-10-03T14:16:26Z vs.
Revision 1.15 by gbeauche, 2001-08-19T16:21:01Z

# Line 24 | Line 24
24   #include "sysdeps.h"
25   #include "readcpu.h"
26  
27 + #if defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY)
28 + #define SPARC_ASSEMBLY 0
29 + #endif
30 +
31   #define BOOL_TYPE "int"
32  
33   static FILE *headerfile;
# Line 55 | Line 59 | static void read_counts (void)
59      if (file) {
60          fscanf (file, "Total: %lu\n", &total);
61          while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) {
62 <            opcode_next_clev[nr] = 3;
62 >            opcode_next_clev[nr] = 4;
63              opcode_last_postfix[nr] = -1;
64              opcode_map[nr++] = opcode;
65              counts[opcode] = count;
# Line 68 | Line 72 | static void read_counts (void)
72          if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
73              && counts[opcode] == 0)
74          {
75 <            opcode_next_clev[nr] = 3;
75 >            opcode_next_clev[nr] = 4;
76              opcode_last_postfix[nr] = -1;
77              opcode_map[nr++] = opcode;
78              counts[opcode] = count;
# Line 217 | Line 221 | static void sync_m68k_pc (void)
221   }
222  
223   /* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
224 < * the calling routine handles Apdi and Aipi modes. */
224 > * the calling routine handles Apdi and Aipi modes.
225 > * gb-- movem == 2 means the same thing but for a MOVE16 instruction */
226   static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem)
227   {
228      start_brace ();
# Line 228 | Line 233 | static void genamode (amodes mode, char
233          if (getv == 1)
234              switch (size) {
235               case sz_byte:
236 < #ifdef AMIGA
236 > #if defined(AMIGA) && !defined(WARPUP)
237                  /* sam: I don't know why gcc.2.7.2.1 produces a code worse */
238                  /* if it is not done like that: */
239                  printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg(regs, %s))[3];\n", name, reg);
# Line 237 | Line 242 | static void genamode (amodes mode, char
242   #endif
243                  break;
244               case sz_word:
245 < #ifdef AMIGA
245 > #if defined(AMIGA) && !defined(WARPUP)
246                  printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg(regs, %s))[1];\n", name, reg);
247   #else
248                  printf ("\tuae_s16 %s = m68k_dreg(regs, %s);\n", name, reg);
# Line 710 | Line 715 | static void genflags_normal (flagtypes t
715  
716   static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst)
717   {
718 < #ifdef X86_ASSEMBLY
718 >    /* Temporarily deleted 68k/ARM flag optimizations.  I'd prefer to have
719 >       them in the appropriate m68k.h files and use just one copy of this
720 >       code here.  The API can be changed if necessary.  */
721 > #ifdef OPTIMIZED_FLAGS
722      switch (type) {
723       case flag_add:
724       case flag_sub:
# Line 725 | Line 733 | static void genflags (flagtypes type, wo
733      /* At least some of those casts are fairly important! */
734      switch (type) {
735       case flag_logical_noclobber:
736 <        printf ("\t{uae_u32 oldcznv = regflags.cznv & ~0xC0;\n");
736 >        printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n");
737          if (strcmp (value, "0") == 0) {
738 <            printf ("\tregflags.cznv = olcznv | 64;\n");
738 >            printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n");
739          } else {
740              switch (size) {
741 <             case sz_byte: printf ("\tx86_flag_testb ((uae_s8)(%s));\n", value); break;
742 <             case sz_word: printf ("\tx86_flag_testw ((uae_s16)(%s));\n", value); break;
743 <             case sz_long: printf ("\tx86_flag_testl ((uae_s32)(%s));\n", value); break;
741 >             case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
742 >             case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
743 >             case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
744              }
745 <            printf ("\tregflags.cznv |= oldcznv;\n");
745 >            printf ("\tIOR_CZNV (oldcznv);\n");
746          }
747          printf ("\t}\n");
748          return;
749       case flag_logical:
750          if (strcmp (value, "0") == 0) {
751 <            printf ("\tregflags.cznv = 64;\n");
751 >            printf ("\tSET_CZNV (FLAGVAL_Z);\n");
752          } else {
753              switch (size) {
754 <             case sz_byte: printf ("\tx86_flag_testb ((uae_s8)(%s));\n", value); break;
755 <             case sz_word: printf ("\tx86_flag_testw ((uae_s16)(%s));\n", value); break;
756 <             case sz_long: printf ("\tx86_flag_testl ((uae_s32)(%s));\n", value); break;
754 >             case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
755 >             case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
756 >             case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
757              }
758          }
759          return;
760  
761       case flag_add:
762          switch (size) {
763 <         case sz_byte: printf ("\tx86_flag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
764 <         case sz_word: printf ("\tx86_flag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
765 <         case sz_long: printf ("\tx86_flag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
763 >         case sz_byte: printf ("\toptflag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
764 >         case sz_word: printf ("\toptflag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
765 >         case sz_long: printf ("\toptflag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
766          }
767          return;
768  
769       case flag_sub:
770          switch (size) {
771 <         case sz_byte: printf ("\tx86_flag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
772 <         case sz_word: printf ("\tx86_flag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
773 <         case sz_long: printf ("\tx86_flag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
771 >         case sz_byte: printf ("\toptflag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
772 >         case sz_word: printf ("\toptflag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
773 >         case sz_long: printf ("\toptflag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
774          }
775          return;
776  
777       case flag_cmp:
778          switch (size) {
779 <         case sz_byte: printf ("\tx86_flag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
780 <         case sz_word: printf ("\tx86_flag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
781 <         case sz_long: printf ("\tx86_flag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
779 >         case sz_byte: printf ("\toptflag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
780 >         case sz_word: printf ("\toptflag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
781 >         case sz_long: printf ("\toptflag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
782          }
783          return;
784          
785       default:
786          break;
787      }
780 #elif defined(M68K_FLAG_OPT)
781    /* sam: here I'm cloning what X86_ASSEMBLY does */
782 #define EXT(size)  (size==sz_byte?"b":(size==sz_word?"w":"l"))
783 #define CAST(size) (size==sz_byte?"uae_s8":(size==sz_word?"uae_s16":"uae_s32"))
784    switch (type) {
785     case flag_add:
786     case flag_sub:
787        start_brace ();
788        printf ("\tuae_u32 %s;\n", value);
789        break;
790
791     default:
792        break;
793    }
794
795    switch (type) {
796     case flag_logical:
797        if (strcmp (value, "0") == 0) {
798            printf ("\t*(uae_u16 *)&regflags = 4;\n");  /* Z = 1 */
799        } else {
800            printf ("\tm68k_flag_tst (%s, (%s)(%s));\n",
801                    EXT (size), CAST (size), value);
802        }
803        return;
804
805     case flag_add:
806        printf ("\t{uae_u16 ccr;\n");
807        printf ("\tm68k_flag_add (%s, (%s)%s, (%s)(%s), (%s)(%s));\n",
808                EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst);
809        printf ("\t((uae_u16*)&regflags)[1]=((uae_u16*)&regflags)[0]=ccr;}\n");
810        return;
811
812     case flag_sub:
813        printf ("\t{uae_u16 ccr;\n");
814        printf ("\tm68k_flag_sub (%s, (%s)%s, (%s)(%s), (%s)(%s));\n",
815                EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst);
816        printf ("\t((uae_u16*)&regflags)[1]=((uae_u16*)&regflags)[0]=ccr;}\n");
817        return;
818
819     case flag_cmp:
820        printf ("\tm68k_flag_cmp (%s, (%s)(%s), (%s)(%s));\n",
821                EXT (size), CAST (size), src, CAST (size), dst);
822        return;
823
824     default:
825        break;
826    }
827 #elif defined(ACORN_FLAG_OPT) && defined(__GNUC_MINOR__)
828 /*
829 * This is new. Might be quite buggy.
830 */
831    switch (type) {
832     case flag_av:
833     case flag_sv:
834     case flag_zn:
835     case flag_addx:
836     case flag_subx:
837        break;
838
839     case flag_logical:
840        if (strcmp (value, "0") == 0) {
841            /* v=c=n=0 z=1 */
842            printf ("\t*(ULONG*)&regflags = 0x40000000;\n");
843            return;
844        } else {
845            start_brace ();
846            switch (size) {
847             case sz_byte:
848                printf ("\tUBYTE ccr;\n");
849                printf ("\tULONG shift;\n");
850                printf ("\t__asm__(\"mov %%2,%%1,lsl#24\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
851                        "\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value);
852                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
853                return;
854             case sz_word:
855                printf ("\tUBYTE ccr;\n");
856                printf ("\tULONG shift;\n");
857                printf ("\t__asm__(\"mov %%2,%%1,lsl#16\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
858                        "\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value);
859                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
860                return;
861             case sz_long:
862                printf ("\tUBYTE ccr;\n");
863                printf ("\t__asm__(\"tst %%1,%%1\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
864                        "\t: \"=r\" (ccr) : \"r\" ((LONG)%s) : \"cc\" );\n", value);
865                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
866                return;
867            }
868        }
869        break;
870     case flag_add:
871        if (strcmp (dst, "0") == 0) {
872            printf ("/* Error! Hier muss Peter noch was machen !!! (ADD-Flags) */");
873        } else {
874            start_brace ();
875            switch (size) {
876             case sz_byte:
877                printf ("\tULONG ccr, shift, %s;\n", value);
878                printf ("\t__asm__(\"mov %%4,%%3,lsl#24\n\tadds %%0,%%4,%%2,lsl#24\n\tmov %%0,%%0,asr#24\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
879                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
880                printf ("\t*(ULONG*)&regflags = ccr;\n");
881                return;
882             case sz_word:
883                printf ("\tULONG ccr, shift, %s;\n", value);
884                printf ("\t__asm__(\"mov %%4,%%3,lsl#16\n\tadds %%0,%%4,%%2,lsl#16\n\tmov %%0,%%0,asr#16\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
885                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
886                printf ("\t*(ULONG*)&regflags = ccr;\n");
887                return;
888             case sz_long:
889                printf ("\tULONG ccr, %s;\n", value);
890                printf ("\t__asm__(\"adds %%0,%%3,%%2\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
891                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst);
892                printf ("\t*(ULONG*)&regflags = ccr;\n");
893                return;
894            }
895        }
896        break;
897     case flag_sub:
898        if (strcmp (dst, "0") == 0) {
899            printf ("/* Error! Hier muss Peter noch was machen !!! (SUB-Flags) */");
900        } else {
901            start_brace ();
902            switch (size) {
903             case sz_byte:
904                printf ("\tULONG ccr, shift, %s;\n", value);
905                printf ("\t__asm__(\"mov %%4,%%3,lsl#24\n\tsubs %%0,%%4,%%2,lsl#24\n\tmov %%0,%%0,asr#24\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
906                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
907                printf ("\t*(ULONG*)&regflags = ccr;\n");
908                return;
909             case sz_word:
910                printf ("\tULONG ccr, shift, %s;\n", value);
911                printf ("\t__asm__(\"mov %%4,%%3,lsl#16\n\tsubs %%0,%%4,%%2,lsl#16\n\tmov %%0,%%0,asr#16\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
912                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
913                printf ("\t*(ULONG*)&regflags = ccr;\n");
914                return;
915             case sz_long:
916                printf ("\tULONG ccr, %s;\n", value);
917                printf ("\t__asm__(\"subs %%0,%%3,%%2\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
918                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst);
919                printf ("\t*(ULONG*)&regflags = ccr;\n");
920                return;
921            }
922        }
923        break;
924     case flag_cmp:
925        if (strcmp (dst, "0") == 0) {
926            printf ("/*Error! Hier muss Peter noch was machen !!! (CMP-Flags)*/");
927        } else {
928            start_brace ();
929            switch (size) {
930             case sz_byte:
931                printf ("\tULONG shift, ccr;\n");
932                printf ("\t__asm__(\"mov %%3,%%2,lsl#24\n\tcmp %%3,%%1,lsl#24\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
933                        "\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", src, dst);
934                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
935                return;
936             case sz_word:
937                printf ("\tULONG shift, ccr;\n");
938                printf ("\t__asm__(\"mov %%3,%%2,lsl#16\n\tcmp %%3,%%1,lsl#16\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
939                        "\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", src, dst);
940                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
941                return;
942             case sz_long:
943                printf ("\tULONG ccr;\n");
944                printf ("\t__asm__(\"cmp %%2,%%1\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
945                        "\t: \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", src, dst);
946                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
947                /*printf ("\tprintf (\"%%08x %%08x %%08x\\n\", %s, %s, *((ULONG*)&regflags));\n", src, dst); */
948                return;
949            }
950        }
951        break;
952    }
788   #endif
789 +
790      genflags_normal (type, size, value, src, dst);
791   }
792  
# Line 1074 | Line 910 | static void gen_opcode (unsigned long in
910          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
911          break;
912       case i_SBCD:
1077        /* Let's hope this works... */
913          genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
914          genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
915          start_brace ();
916          printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
917          printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n");
918 <        printf ("\tuae_u16 newv;\n");
919 <        printf ("\tint cflg;\n");
920 <        printf ("\tif (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }\n");
921 <        printf ("\tnewv = newv_hi + (newv_lo & 0xF);");
922 <        printf ("\tSET_CFLG (cflg = (newv_hi & 0x1F0) > 0x90);\n");
918 >        printf ("\tuae_u16 newv, tmp_newv;\n");
919 >        printf ("\tint bcd = 0;\n");
920 >        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
921 >        printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n");
922 >        printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
923 >        printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG ? 1 : 0)) & 0x300) > 0xFF);\n");
924          duplicate_carry ();
1089        printf ("\tif (cflg) newv -= 0x60;\n");
925          genflags (flag_zn, curi->size, "newv", "", "");
926 <        genflags (flag_sv, curi->size, "newv", "src", "dst");
926 >        printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
927          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
928          break;
929       case i_ADD:
# Line 1120 | Line 955 | static void gen_opcode (unsigned long in
955          start_brace ();
956          printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG ? 1 : 0);\n");
957          printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
958 <        printf ("\tuae_u16 newv;\n");
958 >        printf ("\tuae_u16 newv, tmp_newv;\n");
959          printf ("\tint cflg;\n");
960 <        printf ("\tif (newv_lo > 9) { newv_lo +=6; }\n");
961 <        printf ("\tnewv = newv_hi + newv_lo;");
962 <        printf ("\tSET_CFLG (cflg = (newv & 0x1F0) > 0x90);\n");
1128 <        duplicate_carry ();
960 >        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;");
961 >        printf ("\tif (newv_lo > 9) { newv += 6; }\n");
962 >        printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
963          printf ("\tif (cflg) newv += 0x60;\n");
964 +        printf ("\tSET_CFLG (cflg);\n");
965 +        duplicate_carry ();
966          genflags (flag_zn, curi->size, "newv", "", "");
967 <        genflags (flag_sv, curi->size, "newv", "src", "dst");
967 >        printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
968          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
969          break;
970       case i_NEG:
# Line 1152 | Line 988 | static void gen_opcode (unsigned long in
988          printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n");
989          printf ("\tuae_u16 newv;\n");
990          printf ("\tint cflg;\n");
991 <        printf ("\tif (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }\n");
992 <        printf ("\tnewv = newv_hi + (newv_lo & 0xF);");
993 <        printf ("\tSET_CFLG (cflg = (newv_hi & 0x1F0) > 0x90);\n");
1158 <        duplicate_carry();
991 >        printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n");
992 >        printf ("\tnewv = newv_hi + newv_lo;");
993 >        printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
994          printf ("\tif (cflg) newv -= 0x60;\n");
995 +        printf ("\tSET_CFLG (cflg);\n");
996 +        duplicate_carry();
997          genflags (flag_zn, curi->size, "newv", "", "");
998          genastore ("newv", curi->smode, "srcreg", curi->size, "src");
999          break;
# Line 1193 | Line 1030 | static void gen_opcode (unsigned long in
1030          else
1031              printf ("\tsrc &= 31;\n");
1032          printf ("\tdst ^= (1 << src);\n");
1033 <        printf ("\tSET_ZFLG ((dst & (1 << src)) >> src);\n");
1033 >        printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n");
1034          genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1035          break;
1036       case i_BCLR:
# Line 1364 | Line 1201 | static void gen_opcode (unsigned long in
1201              printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n");
1202              printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n");
1203              printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n");
1204 +            printf ("\telse if ((format & 0xF000) == 0x3000) { m68k_areg(regs, 7) += 4; break; }\n");
1205 +            printf ("\telse if ((format & 0xF000) == 0x7000) { m68k_areg(regs, 7) += 52; break; }\n");
1206              printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n");
1207              printf ("\telse if ((format & 0xF000) == 0x9000) { m68k_areg(regs, 7) += 12; break; }\n");
1208              printf ("\telse if ((format & 0xF000) == 0xa000) { m68k_areg(regs, 7) += 24; break; }\n");
# Line 1380 | Line 1219 | static void gen_opcode (unsigned long in
1219          m68k_pc_offset = 0;
1220          break;
1221       case i_RTD:
1383        printf ("\tcompiler_flush_jsr_stack();\n");
1222          genamode (Aipi, "7", sz_long, "pc", 1, 0);
1223          genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0);
1224          printf ("\tm68k_areg(regs, 7) += offs;\n");
# Line 1414 | Line 1252 | static void gen_opcode (unsigned long in
1252          need_endlabel = 1;
1253          break;
1254       case i_RTR:
1417        printf ("\tcompiler_flush_jsr_stack();\n");
1255          printf ("\tMakeSR();\n");
1256          genamode (Aipi, "7", sz_word, "sr", 1, 0);
1257          genamode (Aipi, "7", sz_long, "pc", 1, 0);
# Line 1532 | Line 1369 | static void gen_opcode (unsigned long in
1369          printf ("\tuaecptr oldpc = m68k_getpc();\n");
1370          genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1371          genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1372 <        printf ("\tif(src == 0) { Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1372 >        sync_m68k_pc ();
1373 >        /* Clear V flag when dividing by zero - Alcatraz Odyssey demo depends
1374 >         * on this (actually, it's doing a DIVS).  */
1375 >        printf ("\tif (src == 0) { SET_VFLG (0); Exception (5, oldpc); goto %s; } else {\n", endlabelstr);
1376          printf ("\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n");
1377          printf ("\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n");
1378          /* The N flag appears to be set each time there is an overflow.
# Line 1550 | Line 1390 | static void gen_opcode (unsigned long in
1390          printf ("\tuaecptr oldpc = m68k_getpc();\n");
1391          genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1392          genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1393 <        printf ("\tif(src == 0) { Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1393 >        sync_m68k_pc ();
1394 >        printf ("\tif (src == 0) { SET_VFLG (0); Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1395          printf ("\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n");
1396          printf ("\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n");
1397          printf ("\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n");
# Line 1810 | Line 1651 | static void gen_opcode (unsigned long in
1651          }
1652          printf ("\tcnt &= 63;\n");
1653          printf ("\tCLEAR_CZNV;\n");
1813        if (! source_is_imm1_8 (curi))
1814            force_range_for_rox ("cnt", curi->size);
1654          if (source_is_imm1_8 (curi))
1655              printf ("{");
1656 <        else
1656 >        else {
1657 >            force_range_for_rox ("cnt", curi->size);
1658              printf ("\tif (cnt > 0) {\n");
1659 +        }
1660          printf ("\tcnt--;\n");
1661          printf ("\t{\n\tuae_u32 carry;\n");
1662          printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1);
# Line 1840 | Line 1681 | static void gen_opcode (unsigned long in
1681          }
1682          printf ("\tcnt &= 63;\n");
1683          printf ("\tCLEAR_CZNV;\n");
1843        if (! source_is_imm1_8 (curi))
1844            force_range_for_rox ("cnt", curi->size);
1684          if (source_is_imm1_8 (curi))
1685              printf ("{");
1686 <        else
1686 >        else {
1687 >            force_range_for_rox ("cnt", curi->size);
1688              printf ("\tif (cnt > 0) {\n");
1689 +        }
1690          printf ("\tcnt--;\n");
1691          printf ("\t{\n\tuae_u32 carry;\n");
1692          printf ("\tuae_u32 hival = (val << 1) | GET_XFLG;\n");
# Line 2001 | Line 1842 | static void gen_opcode (unsigned long in
1842          start_brace ();
1843          printf ("\tint regno = (src >> 12) & 15;\n");
1844          printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1845 <        printf ("\tm68k_movec2(src & 0xFFF, regp);\n");
1845 >        printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1846          break;
1847       case i_MOVE2C:
1848          genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1849          start_brace ();
1850          printf ("\tint regno = (src >> 12) & 15;\n");
1851          printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1852 <        printf ("\tm68k_move2c(src & 0xFFF, regp);\n");
1852 >        printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1853          break;
1854       case i_CAS:
1855          {
# Line 2289 | Line 2130 | static void gen_opcode (unsigned long in
2130          swap_opcode ();
2131          printf ("\tfrestore_opp(opcode);\n");
2132          break;
2133 +     case i_CINVL:
2134 +     case i_CINVP:
2135 +     case i_CINVA:
2136 +     case i_CPUSHL:
2137 +     case i_CPUSHP:
2138 +     case i_CPUSHA:
2139 +        break;
2140 +     case i_MOVE16:
2141 +        if ((opcode & 0xfff8) == 0xf620) {
2142 +                /* MOVE16 (Ax)+,(Ay)+ */
2143 +                printf ("\tuaecptr mems = m68k_areg(regs, srcreg) & ~15, memd;\n");
2144 +                printf ("\tdstreg = (%s >> 12) & 7;\n", gen_nextiword());
2145 +                printf ("\tmemd = m68k_areg(regs, dstreg) & ~15;\n");
2146 +                printf ("\tput_long(memd, get_long(mems));\n");
2147 +                printf ("\tput_long(memd+4, get_long(mems+4));\n");
2148 +                printf ("\tput_long(memd+8, get_long(mems+8));\n");
2149 +                printf ("\tput_long(memd+12, get_long(mems+12));\n");
2150 +                printf ("\tif (srcreg != dstreg)\n");
2151 +                printf ("\tm68k_areg(regs, srcreg) += 16;\n");
2152 +                printf ("\tm68k_areg(regs, dstreg) += 16;\n");
2153 +        }
2154 +        else {
2155 +                /* Other variants */
2156 +                genamode (curi->smode, "srcreg", curi->size, "mems", 0, 2);
2157 +                genamode (curi->dmode, "dstreg", curi->size, "memd", 0, 2);
2158 +                printf ("\tmemsa &= ~15;\n");
2159 +                printf ("\tmemda &= ~15;\n");
2160 +                printf ("\tput_long(memda, get_long(memsa));\n");
2161 +                printf ("\tput_long(memda+4, get_long(memsa+4));\n");
2162 +                printf ("\tput_long(memda+8, get_long(memsa+8));\n");
2163 +                printf ("\tput_long(memda+12, get_long(memsa+12));\n");
2164 +                if ((opcode & 0xfff8) == 0xf600)
2165 +                printf ("\tm68k_areg(regs, srcreg) += 16;\n");
2166 +                else if ((opcode & 0xfff8) == 0xf608)
2167 +                printf ("\tm68k_areg(regs, dstreg) += 16;\n");
2168 +        }
2169 +        break;
2170       case i_MMUOP:
2171          genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2172          sync_m68k_pc ();
# Line 2310 | Line 2188 | static void generate_includes (FILE * f)
2188      fprintf (f, "#include \"memory.h\"\n");
2189      fprintf (f, "#include \"readcpu.h\"\n");
2190      fprintf (f, "#include \"newcpu.h\"\n");
2313    fprintf (f, "#include \"compiler.h\"\n");
2191      fprintf (f, "#include \"cputbl.h\"\n");
2192   }
2193  
# Line 2341 | Line 2218 | static void generate_one_opcode (int rp)
2218      }
2219      fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
2220      fprintf (headerfile, "extern cpuop_func op_%lx_%d;\n", opcode, postfix);
2221 <    printf ("unsigned long REGPARAM2 op_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2221 >    printf ("void REGPARAM2 op_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2222  
2223      switch (table68k[opcode].stype) {
2224       case 0: smsk = 7; break;
# Line 2350 | Line 2227 | static void generate_one_opcode (int rp)
2227       case 3: smsk = 7; break;
2228       case 4: smsk = 7; break;
2229       case 5: smsk = 63; break;
2230 +         case 7: smsk = 3; break;
2231       default: abort ();
2232      }
2233      dmsk = 7;
# Line 2455 | Line 2333 | static void generate_one_opcode (int rp)
2333      gen_opcode (opcode);
2334      if (need_endlabel)
2335          printf ("%s: ;\n", endlabelstr);
2458    printf ("return %d;\n", insn_n_cycles);
2336      printf ("}\n");
2337      opcode_next_clev[rp] = next_cpu_level;
2338      opcode_last_postfix[rp] = postfix;
# Line 2467 | Line 2344 | static void generate_func (void)
2344  
2345      using_prefetch = 0;
2346      using_exception_3 = 0;
2347 <    for (i = 0; i < 5; i++) {
2348 <        cpu_level = 3 - i;
2349 <        if (i == 4) {
2347 > #if !USE_PREFETCH_BUFFER
2348 >        /* gb-- No need for a prefetch buffer, nor exception 3 handling */
2349 >        /* Anyway, Basilisk2 does not use the op_smalltbl_5 table... */
2350 >    for (i = 0; i <= 4; i++) {
2351 > #else
2352 >    for (i = 0; i < 6; i++) {
2353 > #endif
2354 >        cpu_level = 4 - i;
2355 >        if (i == 5) {
2356              cpu_level = 0;
2357              using_prefetch = 1;
2358              using_exception_3 = 1;
# Line 2507 | Line 2390 | static void generate_func (void)
2390  
2391          fprintf (stblfile, "{ 0, 0, 0 }};\n");
2392      }
2510
2393   }
2394  
2395   int main (int argc, char **argv)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines