Move free_all_objfiles to program_space
[deliverable/binutils-gdb.git] / opcodes / s12z-opc.c
index 36509b58dcd8bb52278d3d5755c6ef47c41c79ec..044c72a21cad948b7630e71d0d29fd91ebab1d20 100644 (file)
@@ -36,8 +36,8 @@ typedef int (* insn_bytes_f) (struct mem_read_abstraction_base *);
 typedef void (*operands_f) (struct mem_read_abstraction_base *,
                            int *n_operands, struct operand **operand);
 
-typedef enum operator (*discriminator_f) (struct mem_read_abstraction_base *,
-                                         enum operator hint);
+typedef enum optr (*discriminator_f) (struct mem_read_abstraction_base *,
+                                         enum optr hint);
 
 enum OPR_MODE
   {
@@ -256,7 +256,8 @@ xysp_reg_from_postbyte (uint8_t postbyte)
   return reg;
 }
 
-static struct operand * create_immediate_operand (int value)
+static struct operand *
+create_immediate_operand (int value)
 {
   struct immediate_operand *op = malloc (sizeof (*op));
 
@@ -267,7 +268,8 @@ static struct operand * create_immediate_operand (int value)
   return (struct operand *) op;
 }
 
-static struct operand * create_bitfield_operand (int width, int offset)
+static struct operand *
+create_bitfield_operand (int width, int offset)
 {
   struct bitfield_operand *op = malloc (sizeof (*op));
 
@@ -297,7 +299,8 @@ create_register_operand (int reg)
   return create_register_operand_with_size (reg, -1);
 }
 
-static struct operand * create_register_all_operand (void)
+static struct operand *
+create_register_all_operand (void)
 {
   struct register_operand *op = malloc (sizeof (*op));
 
@@ -307,7 +310,8 @@ static struct operand * create_register_all_operand (void)
   return (struct operand *) op;
 }
 
-static struct operand * create_register_all16_operand (void)
+static struct operand *
+create_register_all16_operand (void)
 {
   struct register_operand *op = malloc (sizeof (*op));
 
@@ -371,7 +375,8 @@ create_memory_auto_operand (enum op_reg_mutation mutation, int reg)
 \f
 
 static void
-z_ext24_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand)
+z_ext24_decode (struct mem_read_abstraction_base *mra, int *n_operands,
+               struct operand **operand)
 {
   uint8_t buffer[3];
   int status = mra->read (mra, 0, 3, buffer);
@@ -391,7 +396,8 @@ z_ext24_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct o
 
 
 static uint32_t
-z_decode_signed_value (struct mem_read_abstraction_base *mra, int offset, short size)
+z_decode_signed_value (struct mem_read_abstraction_base *mra, int offset,
+                      short size)
 {
   assert (size >0);
   assert (size <= 4);
@@ -404,9 +410,7 @@ z_decode_signed_value (struct mem_read_abstraction_base *mra, int offset, short
   int i;
   uint32_t value = 0;
   for (i = 0; i < size; ++i)
-    {
-      value |= buffer[i] << (8 * (size - i - 1));
-    }
+    value = (value << 8) | buffer[i];
 
   if (buffer[0] & 0x80)
     {
@@ -438,7 +442,7 @@ x_imm1 (struct mem_read_abstraction_base *mra,
 /* An eight bit immediate operand.  */
 static void
 imm1_decode (struct mem_read_abstraction_base *mra,
-       int *n_operands, struct operand **operand)
+            int *n_operands, struct operand **operand)
 {
   x_imm1 (mra, 0, n_operands, operand);
 }
@@ -485,30 +489,30 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
        else
          n = x;
 
-        operand = create_immediate_operand (n);
+       operand = create_immediate_operand (n);
        break;
       }
     case OPR_REG:
       {
        uint8_t x = (postbyte & 0x07);
-        operand = create_register_operand (x);
+       operand = create_register_operand (x);
        break;
       }
     case OPR_OFXYS:
       {
-        operand = create_memory_operand (false, postbyte & 0x0F, 1,
+       operand = create_memory_operand (false, postbyte & 0x0F, 1,
                                         xysp_reg_from_postbyte (postbyte), -1);
        break;
       }
     case OPR_REG_DIRECT:
       {
-        operand = create_memory_operand (false, 0, 2, postbyte & 0x07,
+       operand = create_memory_operand (false, 0, 2, postbyte & 0x07,
                                         xysp_reg_from_postbyte (postbyte));
        break;
       }
     case OPR_REG_INDIRECT:
       {
-        operand = create_memory_operand (true, 0, 2, postbyte & 0x07,
+       operand = create_memory_operand (true, 0, 2, postbyte & 0x07,
                                         (postbyte & 0x10) ? REG_Y : REG_X);
        break;
       }
@@ -525,7 +529,7 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
            idx -= 0x1UL << 8;
          }
 
-        operand = create_memory_operand (true, idx, 1,
+       operand = create_memory_operand (true, idx, 1,
                                         xysp_reg_from_postbyte (postbyte), -1);
        break;
       }
@@ -542,7 +546,7 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
            idx -= 0x1UL << 24;
          }
 
-        operand = create_memory_operand (false, idx, 1,
+       operand = create_memory_operand (false, idx, 1,
                                         xysp_reg_from_postbyte (postbyte), -1);
        break;
       }
@@ -559,7 +563,7 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
            idx -= 0x1UL << 24;
          }
 
-        operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
+       operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
        break;
       }
 
@@ -592,7 +596,7 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
            idx -= 0x1UL << 8;
          }
 
-        operand = create_memory_operand (false, idx, 1,
+       operand = create_memory_operand (false, idx, 1,
                                         xysp_reg_from_postbyte (postbyte), -1);
        break;
       }
@@ -604,7 +608,7 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
        uint32_t idx = x[1] | x[0] << 8 ;
        idx |= (postbyte & 0x30) << 12;
 
-        operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
+       operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
        break;
       }
 
@@ -709,7 +713,7 @@ x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
            ext24 |= buffer[i] << (8 * (size - i - 1));
          }
 
-        operand = create_memory_operand (true, ext24, 0, -1, -1);
+       operand = create_memory_operand (true, ext24, 0, -1, -1);
        break;
       }
 
@@ -969,12 +973,12 @@ static void bit_field_decode (struct mem_read_abstraction_base *mra, int *n_oper
 static void exg_sex_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
 
 
-static enum operator shift_discrim (struct mem_read_abstraction_base *mra, enum operator hint);
-static enum operator psh_pul_discrim (struct mem_read_abstraction_base *mra, enum operator hint);
-static enum operator mul_discrim (struct mem_read_abstraction_base *mra, enum operator hint);
-static enum operator loop_primitive_discrim (struct mem_read_abstraction_base *mra, enum operator hint);
-static enum operator bit_field_discrim (struct mem_read_abstraction_base *mra, enum operator hint);
-static enum operator exg_sex_discrim (struct mem_read_abstraction_base *mra, enum operator hint);
+static enum optr shift_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
+static enum optr psh_pul_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
+static enum optr mul_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
+static enum optr loop_primitive_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
+static enum optr bit_field_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
+static enum optr exg_sex_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
 
 
 static void
@@ -1003,10 +1007,12 @@ sub_d6_y_x (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
   operand[(*n_operands)++] = create_register_operand (REG_X);
 }
 
-static void ld_18bit_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
+static void
+ld_18bit_decode (struct mem_read_abstraction_base *mra, int *n_operands,
+                struct operand **operand);
 
-static enum operator
-mul_discrim (struct mem_read_abstraction_base *mra, enum operator hint)
+static enum optr
+mul_discrim (struct mem_read_abstraction_base *mra, enum optr hint)
 {
   uint8_t mb;
   int status = mra->read (mra, 0, 1, &mb);
@@ -1042,7 +1048,7 @@ mul_discrim (struct mem_read_abstraction_base *mra, enum operator hint)
 struct opcode
 {
   /* The operation that this opcode performs.  */
-  enum operator operator;
+  enum optr operator;
 
   /* The size of this operation.  May be -1 if it is implied
      in the operands or if size is not applicable.  */
@@ -1821,6 +1827,7 @@ bm_decode (struct mem_read_abstraction_base *mra,
   switch (mode)
     {
     case BM_REG_IMM:
+    case BM_RESERVED0:
       imm = (bm & 0x38) >> 3;
       operand[(*n_operands)++] = create_immediate_operand (imm);
       break;
@@ -1838,9 +1845,6 @@ bm_decode (struct mem_read_abstraction_base *mra,
     case BM_RESERVED1:
       operand[(*n_operands)++] = create_register_operand ((bm & 0x70) >> 4);
       break;
-    case BM_RESERVED0:
-      assert (0);
-      break;
     }
 }
 
@@ -2196,25 +2200,33 @@ loop_prim_n_bytes (struct mem_read_abstraction_base *mra)
 
 \f
 
-static enum operator
-exg_sex_discrim (struct mem_read_abstraction_base *mra, enum operator hint ATTRIBUTE_UNUSED)
+static enum optr
+exg_sex_discrim (struct mem_read_abstraction_base *mra,
+                enum optr hint ATTRIBUTE_UNUSED)
 {
   uint8_t eb;
   int status = mra->read (mra, 0, 1, &eb);
+  enum optr operator = OP_INVALID;
   if (status < 0)
-    return OP_INVALID;
+    return operator;
 
   struct operand *op0 = create_register_operand ((eb & 0xf0) >> 4);
   struct operand *op1 = create_register_operand (eb & 0xf);
 
-  const struct reg *r0 = registers + ((struct register_operand *) op0)->reg;
-  const struct reg *r1 = registers + ((struct register_operand *) op1)->reg;
+  int reg0 = ((struct register_operand *) op0)->reg;
+  int reg1 = ((struct register_operand *) op1)->reg;
+  if (reg0 >= 0 && reg0 < S12Z_N_REGISTERS
+      && reg1 >= 0 && reg1 < S12Z_N_REGISTERS)
+    {
+      const struct reg *r0 = registers + reg0;
+      const struct reg *r1 = registers + reg1;
 
-  enum operator operator = (r0->bytes < r1->bytes) ? OP_sex : OP_exg;
+      operator = r0->bytes < r1->bytes ? OP_sex : OP_exg;
+    }
 
   free (op0);
   free (op1);
-  
+
   return operator;
 }
 
@@ -2233,22 +2245,22 @@ exg_sex_decode (struct mem_read_abstraction_base *mra,
   operands[(*n_operands)++] =  create_register_operand (eb & 0xf);
 }
 
-static enum operator
+static enum optr
 loop_primitive_discrim (struct mem_read_abstraction_base *mra,
-                       enum operator hint ATTRIBUTE_UNUSED)
+                       enum optr hint ATTRIBUTE_UNUSED)
 {
   uint8_t lb;
   int status = mra->read (mra, 0, 1, &lb);
   if (status < 0)
     return OP_INVALID;
 
-  enum operator opbase = (lb & 0x80) ? OP_dbNE : OP_tbNE;
+  enum optr opbase = (lb & 0x80) ? OP_dbNE : OP_tbNE;
   return opbase + ((lb & 0x70) >> 4);
 }
 
 static void
 loop_primitive_decode (struct mem_read_abstraction_base *mra,
-                 int *n_operands, struct operand **operands)
+                      int *n_operands, struct operand **operands)
 {
   int offs = 1;
   uint8_t lb;
@@ -2287,14 +2299,15 @@ loop_primitive_decode (struct mem_read_abstraction_base *mra,
 }
 
 
-static enum operator
-shift_discrim (struct mem_read_abstraction_base *mra,  enum operator hint ATTRIBUTE_UNUSED)
+static enum optr
+shift_discrim (struct mem_read_abstraction_base *mra,
+              enum optr hint ATTRIBUTE_UNUSED)
 {
   size_t i;
   uint8_t sb;
   int status = mra->read (mra, 0, 1, &sb);
   if (status < 0)
-    return status;
+    return OP_INVALID;
 
   enum SB_DIR  dir = (sb & 0x40) ? SB_LEFT : SB_RIGHT;
   enum SB_TYPE type = (sb & 0x80) ? SB_ARITHMETIC : SB_LOGICAL;
@@ -2317,7 +2330,8 @@ shift_discrim (struct mem_read_abstraction_base *mra,  enum operator hint ATTRIB
 
 
 static void
-shift_decode (struct mem_read_abstraction_base *mra,  int *n_operands, struct operand **operands)
+shift_decode (struct mem_read_abstraction_base *mra, int *n_operands,
+             struct operand **operands)
 {
   size_t i;
 
@@ -2409,30 +2423,30 @@ shift_decode (struct mem_read_abstraction_base *mra,  int *n_operands, struct op
 
     case SB_REG_REG_N:
       {
-        uint8_t xb;
-        mra->read (mra, 1, 1, &xb);
-
-        /* This case is slightly unusual.
-           If XB matches the binary pattern 0111XXXX, then instead of
-           interpreting this as a general OPR postbyte in the IMMe4 mode,
-           the XB byte is interpreted in s special way.  */
-        if ((xb & 0xF0) == 0x70)
-          {
-            if (byte & 0x10)
-              {
-                int shift = ((sb & 0x08) >> 3) | ((xb & 0x0f) << 1);
-                operands[(*n_operands)++] = create_immediate_operand (shift);
-              }
-            else
-              {
-                /* This should not happen.  */
-                abort ();
-              }
-          }
-        else
-          {
-            operands[(*n_operands)++] = x_opr_decode (mra, 1);
-          }
+       uint8_t xb;
+       mra->read (mra, 1, 1, &xb);
+
+       /* This case is slightly unusual.
+          If XB matches the binary pattern 0111XXXX, then instead of
+          interpreting this as a general OPR postbyte in the IMMe4 mode,
+          the XB byte is interpreted in s special way.  */
+       if ((xb & 0xF0) == 0x70)
+         {
+           if (byte & 0x10)
+             {
+               int shift = ((sb & 0x08) >> 3) | ((xb & 0x0f) << 1);
+               operands[(*n_operands)++] = create_immediate_operand (shift);
+             }
+           else
+             {
+               /* This should not happen.  */
+               abort ();
+             }
+         }
+       else
+         {
+           operands[(*n_operands)++] = x_opr_decode (mra, 1);
+         }
       }
       break;
     case SB_REG_OPR_OPR:
@@ -2464,8 +2478,8 @@ shift_decode (struct mem_read_abstraction_base *mra,  int *n_operands, struct op
     case SB_REG_OPR_EFF:
     case SB_OPR_N:
       {
-        int imm = (sb & 0x08) ? 2 : 1;
-        operands[(*n_operands)++] = create_immediate_operand (imm);
+       int imm = (sb & 0x08) ? 2 : 1;
+       operands[(*n_operands)++] = create_immediate_operand (imm);
       }
       break;
 
@@ -2474,9 +2488,9 @@ shift_decode (struct mem_read_abstraction_base *mra,  int *n_operands, struct op
     }
 }
 
-static enum operator
+static enum optr
 psh_pul_discrim (struct mem_read_abstraction_base *mra,
-                enum operator hint ATTRIBUTE_UNUSED)
+                enum optr hint ATTRIBUTE_UNUSED)
 {
   uint8_t byte;
   int status = mra->read (mra, 0, 1, &byte);
@@ -2499,9 +2513,7 @@ psh_pul_decode (struct mem_read_abstraction_base *mra,
   if (byte & 0x40)
     {
       if ((byte & 0x3F) == 0)
-        {
-         operand[(*n_operands)++] = create_register_all16_operand ();
-        }
+       operand[(*n_operands)++] = create_register_all16_operand ();
       else
        for (bit = 5; bit >= 0; --bit)
          {
@@ -2514,9 +2526,7 @@ psh_pul_decode (struct mem_read_abstraction_base *mra,
   else
     {
       if ((byte & 0x3F) == 0)
-        {
-         operand[(*n_operands)++] = create_register_all_operand ();
-        }
+       operand[(*n_operands)++] = create_register_all_operand ();
       else
        for (bit = 5; bit >= 0; --bit)
          {
@@ -2528,8 +2538,9 @@ psh_pul_decode (struct mem_read_abstraction_base *mra,
     }
 }
 
-static enum operator
-bit_field_discrim (struct mem_read_abstraction_base *mra, enum operator hint ATTRIBUTE_UNUSED)
+static enum optr
+bit_field_discrim (struct mem_read_abstraction_base *mra,
+                  enum optr hint ATTRIBUTE_UNUSED)
 {
   int status;
   bfd_byte bb;
@@ -2563,10 +2574,10 @@ bit_field_decode (struct mem_read_abstraction_base *mra,
     {
       bbs = bb_modes + i;
       if ((bb & bbs->mask) == bbs->value)
-        {
-          mode = bbs->mode;
-          break;
-        }
+       {
+         mode = bbs->mode;
+         break;
+       }
     }
   int reg1 = byte2 & 0x07;
   /* First operand */
@@ -2594,15 +2605,15 @@ bit_field_decode (struct mem_read_abstraction_base *mra,
     case BB_REG_REG_REG:
     case BB_REG_REG_IMM:
       {
-        int reg_src = (bb >> 2) & 0x07;
-        operands[(*n_operands)++] = create_register_operand (reg_src);
+       int reg_src = (bb >> 2) & 0x07;
+       operands[(*n_operands)++] = create_register_operand (reg_src);
       }
       break;
     case BB_OPR_REG_REG:
     case BB_OPR_REG_IMM:
       {
-        int reg_src = (byte2 & 0x07);
-        operands[(*n_operands)++] = create_register_operand (reg_src);
+       int reg_src = (byte2 & 0x07);
+       operands[(*n_operands)++] = create_register_operand (reg_src);
       }
       break;
     case BB_REG_OPR_REG:
@@ -2622,7 +2633,7 @@ bit_field_decode (struct mem_read_abstraction_base *mra,
     case BB_OPR_REG_REG:
     case BB_REG_OPR_REG:
       {
-        int reg_parm = bb & 0x03;
+       int reg_parm = bb & 0x03;
        operands[(*n_operands)++] = create_register_operand (reg_parm);
       }
       break;
@@ -2630,13 +2641,13 @@ bit_field_decode (struct mem_read_abstraction_base *mra,
     case BB_OPR_REG_IMM:
     case BB_REG_OPR_IMM:
       {
-        bfd_byte i1;
-        mra->read (mra, 1, 1, &i1);
-        int offset = i1 & 0x1f;
-        int width = bb & 0x03;
-        width <<= 3;
-        width |= i1 >> 5;
-        operands[(*n_operands)++] = create_bitfield_operand (width, offset);
+       bfd_byte i1;
+       mra->read (mra, 1, 1, &i1);
+       int offset = i1 & 0x1f;
+       int width = bb & 0x03;
+       width <<= 3;
+       width |= i1 >> 5;
+       operands[(*n_operands)++] = create_bitfield_operand (width, offset);
       }
       break;
     }
@@ -2647,12 +2658,12 @@ bit_field_decode (struct mem_read_abstraction_base *mra,
    The operation to be performed is returned.
    The number of operands, will be placed in N_OPERANDS.
    The operands themselved into OPERANDS.  */
-static enum operator
+static enum optr
 decode_operation (const struct opcode *opc,
                  struct mem_read_abstraction_base *mra,
                  int *n_operands, struct operand **operands)
 {
-  enum operator op = opc->operator;
+  enum optr op = opc->operator;
   if (opc->discriminator)
     op = opc->discriminator (mra, opc->operator);
 
@@ -2666,7 +2677,7 @@ decode_operation (const struct opcode *opc,
 }
 
 int
-decode_s12z (enum operator *myoperator, short *osize,
+decode_s12z (enum optr *myoperator, short *osize,
             int *n_operands, struct operand **operands,
             struct mem_read_abstraction_base *mra)
 {
This page took 0.034246 seconds and 4 git commands to generate.