Implement 32 bit MIPS16 instructions listed in m16.igen.
[deliverable/binutils-gdb.git] / sim / mips / gencode.c
index f45685de327d69468e3f0e6a9e12983723da45a8..44fac70846184ae1f6075dee127455a43d10f3a8 100644 (file)
@@ -480,6 +480,10 @@ typedef struct instruction {
 #define ARCH_R5900        ((unsigned)1 << 30) /* Toshiba r5900 extension instructions */
 /* end-sanitize-r5900 */
 #define ARCH_R3900        ((unsigned)1 << 29) /* Toshiba r3900 (tx39) */
+/* start-sanitize-tx49 */
+#define ARCH_R4900        ((unsigned)1 << 28) /* Toshiba r4900 (tx49) */
+/* end-sanitize-tx49 */   
+
 /* start-sanitize-tx19 */
 /* The r1900 (tx19) is a tx39 with a mips16 decoder.  For the purposes
    of implementing the simulator we treat them as the same. */
@@ -488,6 +492,9 @@ typedef struct instruction {
 /* A list (or'ed) of extension insn sets that can be requested independant of the ISA# */
 #define MASK_ISA_INDEP  (0                                             \
                          | ARCH_R3900                                  \
+                         /* start-sanitize-tx49 */                     \
+                         | ARCH_R4900                                  \
+                         /* end-sanitize-tx49 */                       \
                          /* start-sanitize-r5900 */                    \
                          | ARCH_R5900                                  \
                          /* end-sanitize-r5900 */                      \
@@ -516,6 +523,9 @@ typedef struct instruction {
 
 #define G5 (0                                         \
             | ARCH_R3900                              \
+            /* start-sanitize-tx49 */                 \
+            | ARCH_R4900                              \
+            /* end-sanitize-tx49 */                   \
             /* start-sanitize-r5900 */                \
             | ARCH_R5900                              \
             /* end-sanitize-r5900 */                  \
@@ -523,7 +533,27 @@ typedef struct instruction {
 
 #define G6 (3 | ARCH_R3900)
 
-#define T3 ARCH_R3900
+#define G7 (ARCH_R3900                                \
+            /* start-sanitize-tx49 */                 \
+            | ARCH_R4900                              \
+            /* end-sanitize-tx49 */                   \
+            )
+
+#define G8 (4                                         \
+            /* start-sanitize-tx49 */                 \
+            | ARCH_R4900                              \
+            /* end-sanitize-tx49 */                   \
+            /* start-sanitize-r5900 */                \
+            | ARCH_R5900                              \
+            /* end-sanitize-r5900 */                  \
+            )
+
+#define G9 (3                                         \
+            /* start-sanitize-tx49 */                 \
+            | ARCH_R4900                              \
+            /* end-sanitize-tx49 */                   \
+            )
+
 /* start-sanitize-r5900 */
 #define T5 ARCH_R5900       
 /* end-sanitize-r5900 */
@@ -588,8 +618,9 @@ struct instruction MIPS_DECODE[] = {
  {"DIVU1",  T5,"011100sssssggggg0000000000011011",MMINORM,DIV,      (WORD | WORD32 | UNSIGNED | SIGNEXTEND | HI | LO | PIPE1)},
  /* end-sanitize-r5900 */
  {"DMADD16",G1,"000000sssssggggg0000000000101001",SPECIAL,MADD16,   (DOUBLEWORD | HI | LO)},
- {"DMULT",   3,"000000sssssggggg0000000000011100",SPECIAL,MUL,      (DOUBLEWORD | HI | LO)},
- {"DMULTU",  3,"000000sssssggggg0000000000011101",SPECIAL,MUL,      (DOUBLEWORD | UNSIGNED | HI | LO)},
+ /* See note near MULT for explanation of 3op-ness. */
+ {"DMULT",  G9,"000000sssssgggggddddd00000011100",SPECIAL,MUL,      (OP3 | DOUBLEWORD | HI | LO)},
+ {"DMULTU", G9,"000000sssssgggggddddd00000011101",SPECIAL,MUL,      (OP3 | DOUBLEWORD | UNSIGNED | HI | LO)},
  {"DMxC1",   3,"01000100x01kkkkkvvvvv00000000000",COP1S,  FPMOVEC,  (FP | DOUBLEWORD)},
  {"DSLL",    3,"00000000000gggggdddddaaaaa111000",SPECIAL,SHIFT,    (DOUBLEWORD | LEFT | LOGICAL)},
  {"DSLLV",   3,"000000sssssgggggddddd00000010100",SPECIAL,SHIFT,    (DOUBLEWORD | LEFT | LOGICAL | REG)},
@@ -671,6 +702,10 @@ struct instruction MIPS_DECODE[] = {
  {"MSUB.D", G3,"010011bbbbbkkkkkvvvvvrrrrr101001",COP1X,  FPSUB,    (FP | MULTIPLY | DOUBLE)},
  {"MSUB.S", G3,"010011bbbbbkkkkkvvvvvrrrrr101000",COP1X,  FPSUB,    (FP | MULTIPLY | SINGLE)},
  {"MUL",     1,"01000110mmmkkkkkvvvvvrrrrr000010",COP1,   FPMUL,    (FP | HI | LO)},
+ /* The 3op version of MULT and MULTU are TX39 (and related chips) specific.
+    They should be removed from other chips sets, so that using the 3op opcode
+    causes a reserved instruction exception, but gencode can't deal with
+    that currently. */
  {"MULT",    1,"000000sssssgggggddddd00000011000",SPECIAL,MUL,      (OP3 | WORD | WORD32 | HI | LO)},
  /* start-sanitize-r5900 */
  {"MULT1",  T5,"011100sssssgggggddddd00000011000",MMINORM,MUL,      (OP3 | WORD | WORD32 | HI | LO | PIPE1)},
@@ -811,7 +846,7 @@ struct instruction MIPS_DECODE[] = {
  {"PXOR",   T5,"011100SSSSSTTTTTddddd10011001001",MMI2,   POP,      (POP_XOR)},
  /* end-sanitize-r5900 */
 
- {"PREF",   G2,"110011sssssnnnnnyyyyyyyyyyyyyyyy",NORMAL, PREFETCH, (NONE)},
+ {"PREF",   G8,"110011sssssnnnnnyyyyyyyyyyyyyyyy",NORMAL, PREFETCH, (NONE)},
  {"PREFX",   4,"010011sssssgggggvvvvv00000001111",COP1X,  FPPREFX,  (FP)},
 
  /* start-sanitize-r5900 */
@@ -827,7 +862,7 @@ struct instruction MIPS_DECODE[] = {
  {"SCD",     3,"111100sssssgggggeeeeeeeeeeeeeeee",NORMAL, STORE,    (DOUBLEWORD | ATOMIC)},
  {"SD",      3,"111111sssssgggggeeeeeeeeeeeeeeee",NORMAL, STORE,    (DOUBLEWORD)},
  {"SDC1",    2,"111101sssssttttteeeeeeeeeeeeeeee",NORMAL, STORE,    (DOUBLEWORD | COPROC)},
- {"SDBBP",  T3,"000000????????????????????001110",SPECIAL,SDBBP,    (NOARG)},
+ {"SDBBP",  G7,"000000????????????????????001110",SPECIAL,SDBBP,    (NOARG)},
  {"SDC2",    2,"111110sssssttttteeeeeeeeeeeeeeee",NORMAL, STORE,    (DOUBLEWORD | COPROC)},
  {"SDL",     3,"101100sssssgggggyyyyyyyyyyyyyyyy",NORMAL, STORE,    (DOUBLEWORD | LEFT)},
  {"SDR",     3,"101101sssssgggggyyyyyyyyyyyyyyyy",NORMAL, STORE,    (DOUBLEWORD | RIGHT)},
@@ -946,7 +981,7 @@ static const struct instruction MIPS16_DECODE[] = {
 {"NOT",     1, "11101dddyyy01111Z", RR,      OR,      NOT },
 {"OR",      1, "11101wwwyyy01101",  RR,      OR,      NONE },
 {"SB",      1, "11000xxxyyy55555",  RRI,     STORE,   BYTE },
-{"SDBBP",  T3, "11100??????00001",  RR,      SDBBP,   NOARG },
+{"SDBBP",  G7, "11100??????00001",  RR,      SDBBP,   NOARG },
 {"SD",      3, "01111xxxyyyDDDDD",  RRI,     STORE,   DOUBLEWORD },
 {"SDSP",    3, "11111001yyyDDDDDs", RI64,    STORE,   DOUBLEWORD },
 {"SDRASP",  3, "11111010CCCCCCCCsQ", I64,    STORE,   DOUBLEWORD },
@@ -1765,7 +1800,7 @@ build_mips16_operands (bitmap)
            {
              int j;
 
-             printf ("((INDELAYSLOT () ? (INJALDELAYSLOT () ? IPC - 4 : IPC - 2) : (have_extendval ? IPC - 2 : IPC)) & ~ (uword64) 1)");
+             printf ("((INDELAYSLOT () ? (INJALDELAYSLOT () ? cia - 4 : cia - 2) : (have_extendval ? cia - 2 : cia)) & ~ (uword64) 1)");
              for (j = 0; j < opindex; j++)
                if (ops[j]->shift != 0)
                  printf (" & ~ (uword64) 0x%x", (1 << ops[j]->shift) - 1);
@@ -1865,7 +1900,7 @@ build_mips16_operands (bitmap)
       if ((op->flags & MIPS16_JUMP_ADDR) != 0)
        {
          printf ("  {\n");
-         printf ("    uword64 paddr;\n");
+         printf ("    address_word paddr;\n");
          printf ("    int uncached;\n");
          printf ("    if (AddressTranslation (PC &~ (uword64) 1, isINSTRUCTION, isLOAD, &paddr, &uncached, isTARGET, isREAL))\n");
          printf ("      {\n");
@@ -2759,15 +2794,15 @@ build_instruction (doisa, features, mips16, insn)
      break ;
 
     case DECODE:
-     printf("   decode_coproc(instruction);\n");
+     printf("   DecodeCoproc(instruction);\n");
      break ;
 
     case CACHE:
      /* 16-bit offset is sign-extended and added to the base register to make a virtual address */
      /* The virtual address is translated to a physical address using the TLB */
      /* The hint specifies a cache operation for that address */
-     printf("    uword64 vaddr = (op1 + offset);\n");
-     printf("    uword64 paddr;\n");
+     printf("    address_word vaddr = (op1 + offset);\n");
+     printf("    address_word paddr;\n");
      printf("    int uncached;\n");
      /* NOTE: We are assuming that the AddressTranslation is a load: */
      printf("    if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))\n");
@@ -2928,10 +2963,10 @@ build_instruction (doisa, features, mips16, insn)
       }
 
       if (insn->flags & REG)
-       printf("   uword64 vaddr = ((uword64)op1 + op2);\n");
+       printf("   address_word vaddr = ((uword64)op1 + op2);\n");
       else
-       printf("   uword64 vaddr = ((uword64)op1 + offset);\n");
-      printf("   uword64 paddr;\n");
+       printf("   address_word vaddr = ((uword64)op1 + offset);\n");
+      printf("   address_word paddr;\n");
       printf("   int uncached;\n");
 
       /* The following check should only occur on normal (non-shifted) memory loads */
@@ -2980,7 +3015,7 @@ build_instruction (doisa, features, mips16, insn)
              printf("     int byte;\n");
              printf("     paddr = ((paddr & ~mask) | ((paddr & mask) ^ reverse));\n");
              printf("     byte = ((vaddr & mask) ^ bigend);\n");
-             printf("     if (%s!ByteSwapMem)\n",((insn->flags & LEFT) ? "!" : ""));
+             printf("     if (%sBigEndianMem)\n",((insn->flags & LEFT) ? "!" : ""));
              printf("      paddr &= ~mask;\n");
 
              if (isload) {
@@ -3265,8 +3300,8 @@ build_instruction (doisa, features, mips16, insn)
 
     case FPPREFX:
      /* This code could be merged with the PREFIX generation above: */
-     printf("   uword64 vaddr = ((uword64)op1 + (uword64)op2);\n");
-     printf("   uword64 paddr;\n");
+     printf("   address_word vaddr = ((uword64)op1 + (uword64)op2);\n");
+     printf("   address_word paddr;\n");
      printf("   int uncached;\n");
      printf("   if (AddressTranslation(vaddr,isDATA,isLOAD,&paddr,&uncached,isTARGET,isREAL))\n");
      printf("    Prefetch(uncached,paddr,vaddr,isDATA,fs);\n");
@@ -3323,7 +3358,7 @@ build_instruction (doisa, features, mips16, insn)
           printf("      FGR[fs] = (SET64HI(0xDEADC0DE) | WORD64LO(GPR[ft]));\n");
           printf("     else\n");
           printf("      FGR[fs] = WORD64LO(GPR[ft]);\n");
-          printf("     fpr_state[fs] = fmt_uninterpreted;\n");
+          printf("     FPR_STATE[fs] = fmt_uninterpreted;\n");
         }
        } else if (GETDATASIZEINSN(insn) == DOUBLEWORD) {
         if (doisa < 4) {
@@ -3342,14 +3377,14 @@ build_instruction (doisa, features, mips16, insn)
         } else {
           printf("     if (SizeFGR() == 64) {\n");
           printf("      FGR[fs] = GPR[ft];\n");
-          printf("      fpr_state[fs] = fmt_uninterpreted;\n");
+          printf("      FPR_STATE[fs] = fmt_uninterpreted;\n");
           printf("     } else\n");
           printf("      if ((fs & 0x1) == 0)\n");
           printf("       {\n");
           printf("        FGR[fs + 1] = WORD64HI(GPR[ft]);\n");
           printf("        FGR[fs] = WORD64LO(GPR[ft]);\n");
-          printf("        fpr_state[fs + 1] = fmt_uninterpreted;\n");
-          printf("        fpr_state[fs] = fmt_uninterpreted;\n");
+          printf("        FPR_STATE[fs + 1] = fmt_uninterpreted;\n");
+          printf("        FPR_STATE[fs] = fmt_uninterpreted;\n");
           printf("       }\n");
           if (features & FEATURE_WARN_RESULT) {
             printf("      else\n");
@@ -3457,8 +3492,8 @@ build_instruction (doisa, features, mips16, insn)
      printf("   SignalException(ReservedInstruction,instruction);\n");
      printf("  else\n");
      printf("   StoreFPR(destreg,format,%s(SquareRoot(ValueFPR(fs,format),format)%s));\n",
-          ((insn->flags & RECIP) ? "Recip" : ""),
-          ((insn->flags & RECIP) ? ",format" : ""));
+           ((insn->flags & RECIP) ? "Recip" : ""),
+           ((insn->flags & RECIP) ? ",format" : ""));
      break ;
 
     case FPCEIL:
@@ -3550,7 +3585,12 @@ build_instruction (doisa, features, mips16, insn)
          fprintf(stderr,"Error: Invalid data size %d for FPSUB operation\n",GETDATASIZEINSN(insn));
          exit(1);
        }
-       printf("   StoreFPR(destreg,%s,%s(Sub(Multiply(ValueFPR(fs,%s),ValueFPR(ft,%s),%s),ValueFPR(fr,%s),%s),%s));\n",type,((insn->flags & NOT) ? "Negate" : ""),type,type,type,type,type,type);
+       if (insn->flags & NOT)
+        printf ("   StoreFPR(destreg,%s,Negate(Sub(Multiply(ValueFPR(fs,%s),ValueFPR(ft,%s),%s),ValueFPR(fr,%s),%s),%s));\n",
+                type, type, type, type, type, type, type);
+       else
+        printf ("   StoreFPR(destreg,%s,Sub(Multiply(ValueFPR(fs,%s),ValueFPR(ft,%s),%s),ValueFPR(fr,%s),%s));\n",
+                type, type, type, type, type, type);
      } else {
        printf("  if ((format != fmt_single) && (format != fmt_double))\n");
        printf("   SignalException(ReservedInstruction,instruction);\n");
@@ -4429,6 +4469,9 @@ struct architectures {
 static const struct architectures available_architectures[] = {
   {"4100",ARCH_VR4100}, /* NEC MIPS VR4100 */
   {"3900",ARCH_R3900},   /* Toshiba R3900 (TX39) */
+  /* start-sanitize-tx49 */
+  {"4900",ARCH_R4900},   /* Toshiba R4900 (TX49) */
+  /* end-sanitize-tx49  */
   /* start-sanitize-tx19 */
   {"1900",ARCH_R3900},   /* Toshiba R1900 (TX19) */
   /* end-sanitize-tx19  */
This page took 0.027946 seconds and 4 git commands to generate.