daily update
[external/binutils.git] / sim / h8300 / compile.c
index 3e8992c..7b4a5fa 100644 (file)
@@ -599,7 +599,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst)
   /* Find the exact opcode/arg combo.  */
   for (q = h8_opcodes; q->name; q++)
     {
-      op_type *nib = q->data.nib;
+      const op_type *nib = q->data.nib;
       unsigned int len = 0;
 
       if ((q->available == AV_H8SX && !h8300sxmode) ||
@@ -924,7 +924,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst)
 #endif
                  /* Fill in the args.  */
                  {
-                   op_type *args = q->args.nib;
+                   const op_type *args = q->args.nib;
                    int hadone = 0;
                    int nargs;
 
@@ -1018,7 +1018,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst)
                            p->literal = 0;
                            if (OP_KIND (q->how) == O_JSR ||
                                OP_KIND (q->how) == O_JMP)
-                             if (lvalue (sd, p->type, p->reg, &p->type))
+                             if (lvalue (sd, p->type, p->reg, (unsigned int *)&p->type))
                                goto end;
                          }
                        else if ((x & MODE) == ABS)
@@ -1050,7 +1050,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst)
                            p->literal = cst[opnum];
                            if (OP_KIND (q->how) == O_JSR ||
                                OP_KIND (q->how) == O_JMP)
-                             if (lvalue (sd, p->type, p->reg, &p->type))
+                             if (lvalue (sd, p->type, p->reg, (unsigned int *)&p->type))
                                goto end;
                          }
                        else if ((x & MODE) == PCREL)
@@ -1386,105 +1386,93 @@ fetch_1 (SIM_DESC sd, ea_type *arg, int *val, int twice)
       break;
     case X (OP_POSTINC, SB):   /* Register indirect w/post-incr: byte.  */
       t = GET_L_REG (rn);
-      t &= h8_get_mask (sd);
-      r = GET_MEMORY_B (t);
+      r = GET_MEMORY_B (t & h8_get_mask (sd));
       if (!twice)
        t += 1;
-      t = t & h8_get_mask (sd);
       SET_L_REG (rn, t);
       *val = r;
       break;
     case X (OP_POSTINC, SW):   /* Register indirect w/post-incr: word.  */
       t = GET_L_REG (rn);
-      t &= h8_get_mask (sd);
-      r = GET_MEMORY_W (t);
+      r = GET_MEMORY_W (t & h8_get_mask (sd));
       if (!twice)
        t += 2;
-      t = t & h8_get_mask (sd);
       SET_L_REG (rn, t);
       *val = r;
       break;
     case X (OP_POSTINC, SL):   /* Register indirect w/post-incr: long.  */
       t = GET_L_REG (rn);
-      t &= h8_get_mask (sd);
-      r = GET_MEMORY_L (t);
+      r = GET_MEMORY_L (t & h8_get_mask (sd));
       if (!twice)
        t += 4;
-      t = t & h8_get_mask (sd);
       SET_L_REG (rn, t);
       *val = r;
       break;
 
     case X (OP_POSTDEC, SB):   /* Register indirect w/post-decr: byte.  */
       t = GET_L_REG (rn);
-      t &= h8_get_mask (sd);
-      r = GET_MEMORY_B (t);
+      r = GET_MEMORY_B (t & h8_get_mask (sd));
       if (!twice)
        t -= 1;
-      t = t & h8_get_mask (sd);
       SET_L_REG (rn, t);
       *val = r;
       break;
     case X (OP_POSTDEC, SW):   /* Register indirect w/post-decr: word.  */
       t = GET_L_REG (rn);
-      t &= h8_get_mask (sd);
-      r = GET_MEMORY_W (t);
+      r = GET_MEMORY_W (t & h8_get_mask (sd));
       if (!twice)
        t -= 2;
-      t = t & h8_get_mask (sd);
       SET_L_REG (rn, t);
       *val = r;
       break;
     case X (OP_POSTDEC, SL):   /* Register indirect w/post-decr: long.  */
       t = GET_L_REG (rn);
-      t &= h8_get_mask (sd);
-      r = GET_MEMORY_L (t);
+      r = GET_MEMORY_L (t & h8_get_mask (sd));
       if (!twice)
        t -= 4;
-      t = t & h8_get_mask (sd);
       SET_L_REG (rn, t);
       *val = r;
       break;
 
     case X (OP_PREDEC, SB):    /* Register indirect w/pre-decr: byte.  */
       t = GET_L_REG (rn) - 1;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       *val = GET_MEMORY_B (t);
       break;
       
     case X (OP_PREDEC, SW):    /* Register indirect w/pre-decr: word.  */
       t = GET_L_REG (rn) - 2;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       *val = GET_MEMORY_W (t);
       break;
       
     case X (OP_PREDEC, SL):    /* Register indirect w/pre-decr: long.  */
       t = GET_L_REG (rn) - 4;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       *val = GET_MEMORY_L (t);
       break;
       
     case X (OP_PREINC, SB):    /* Register indirect w/pre-incr: byte.  */
       t = GET_L_REG (rn) + 1;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       *val = GET_MEMORY_B (t);
       break;
 
     case X (OP_PREINC, SW):    /* Register indirect w/pre-incr: long.  */
       t = GET_L_REG (rn) + 2;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       *val = GET_MEMORY_W (t);
       break;
 
     case X (OP_PREINC, SL):    /* Register indirect w/pre-incr: long.  */
       t = GET_L_REG (rn) + 4;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       *val = GET_MEMORY_L (t);
       break;
 
@@ -1621,8 +1609,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
       t = GET_L_REG (rn);
       if (!twice)
        t -= 1;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       SET_MEMORY_B (t, n);
 
       break;
@@ -1630,8 +1618,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
       t = GET_L_REG (rn);
       if (!twice)
        t -= 2;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       SET_MEMORY_W (t, n);
       break;
 
@@ -1639,8 +1627,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
       t = GET_L_REG (rn);
       if (!twice)
        t -= 4;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       SET_MEMORY_L (t, n);
       break;
 
@@ -1648,8 +1636,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
       t = GET_L_REG (rn);
       if (!twice)
        t += 1;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       SET_MEMORY_B (t, n);
 
       break;
@@ -1657,8 +1645,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
       t = GET_L_REG (rn);
       if (!twice)
        t += 2;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       SET_MEMORY_W (t, n);
       break;
 
@@ -1666,45 +1654,51 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
       t = GET_L_REG (rn);
       if (!twice)
        t += 4;
-      t &= h8_get_mask (sd);
       SET_L_REG (rn, t);
+      t &= h8_get_mask (sd);
       SET_MEMORY_L (t, n);
       break;
 
     case X (OP_POSTDEC, SB):   /* Register indirect w/post-decr, byte.  */
-      t = GET_L_REG (rn) & h8_get_mask (sd);
-      SET_MEMORY_B (t, n);
+      t = GET_L_REG (rn);
       SET_L_REG (rn, t - 1);
+      t &= h8_get_mask (sd);
+      SET_MEMORY_B (t, n);
       break;
 
     case X (OP_POSTDEC, SW):   /* Register indirect w/post-decr, word.  */
-      t = GET_L_REG (rn) & h8_get_mask (sd);
-      SET_MEMORY_W (t, n);
+      t = GET_L_REG (rn);
       SET_L_REG (rn, t - 2);
+      t &= h8_get_mask (sd);
+      SET_MEMORY_W (t, n);
       break;
 
     case X (OP_POSTDEC, SL):   /* Register indirect w/post-decr, long.  */
-      t = GET_L_REG (rn) & h8_get_mask (sd);
-      SET_MEMORY_L (t, n);
+      t = GET_L_REG (rn);
       SET_L_REG (rn, t - 4);
+      t &= h8_get_mask (sd);
+      SET_MEMORY_L (t, n);
       break;
 
     case X (OP_POSTINC, SB):   /* Register indirect w/post-incr, byte.  */
-      t = GET_L_REG (rn) & h8_get_mask (sd);
-      SET_MEMORY_B (t, n);
+      t = GET_L_REG (rn);
       SET_L_REG (rn, t + 1);
+      t &= h8_get_mask (sd);
+      SET_MEMORY_B (t, n);
       break;
 
     case X (OP_POSTINC, SW):   /* Register indirect w/post-incr, word.  */
-      t = GET_L_REG (rn) & h8_get_mask (sd);
-      SET_MEMORY_W (t, n);
+      t = GET_L_REG (rn);
       SET_L_REG (rn, t + 2);
+      t &= h8_get_mask (sd);
+      SET_MEMORY_W (t, n);
       break;
 
     case X (OP_POSTINC, SL):   /* Register indirect w/post-incr, long.  */
-      t = GET_L_REG (rn) & h8_get_mask (sd);
-      SET_MEMORY_L (t, n);
+      t = GET_L_REG (rn);
       SET_L_REG (rn, t + 4);
+      t &= h8_get_mask (sd);
+      SET_MEMORY_L (t, n);
       break;
 
     case X (OP_DISP, SB):      /* Register indirect w/displacement, byte.  */
@@ -1891,7 +1885,7 @@ case O (name, SB):                                \
       goto end;                                        \
   if (fetch (sd, &code->src, &tmp))            \
     goto end;                                  \
-  m = 1 << tmp;                                        \
+  m = 1 << (tmp & 7);                          \
   op;                                          \
   if (s)                                       \
     if (store (sd, &code->dst,ea))             \
@@ -2037,7 +2031,10 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              code->op3.literal = 0;
 
              if (OP_KIND (code->src.type) == OP_INDEXB)
-               code->dst.type = X (OP_REG, SB);
+               {
+                 code->dst.type = X (OP_REG, SB);
+                 code->dst.reg = code->op3.reg + 8;
+               }
              else
                code->dst.type = X (OP_REG, SW);
            }
@@ -2807,7 +2804,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
                ind_arg_len = 0;
 
                /* The size of the commandline argument.  */
-               ind_arg_len = strlen (h8_get_cmdline_arg (sd, i) + 1);
+               ind_arg_len = strlen (h8_get_cmdline_arg (sd, i)) + 1;
 
                /* The total size of the command line string.  */
                size_cmdline += ind_arg_len;
@@ -3886,13 +3883,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfff0;
-         else
-           ea = SEXTSHORT (ea);
-
+         ea = SEXTSHORT (ea);
          res = SEXTSHORT (ea * SEXTSHORT (rd));
 
          n  = res & 0x8000;
@@ -3907,11 +3898,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-
          res = ea * rd;
 
          n  = res & 0x80000000;
@@ -3925,11 +3911,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-
          /* Compute upper 32 bits of the 64-bit result.  */
          res = (((long long) ea) * ((long long) rd)) >> 32;
 
@@ -3985,13 +3966,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-         else
-           ea = SEXTCHAR (ea);
-
+         ea = SEXTCHAR (ea);
          res = ea * SEXTCHAR (rd);
 
          n  = res & 0x8000;
@@ -4006,13 +3981,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfff0;
-         else
-           ea = SEXTSHORT (ea);
-
+         ea = SEXTSHORT (ea);
          res = ea * SEXTSHORT (rd & 0xffff);
 
          n  = res & 0x80000000;
@@ -4103,11 +4072,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-
          if (ea)
            {
              res = SEXTSHORT (rd) / SEXTSHORT (ea);
@@ -4129,11 +4093,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-
          if (ea)
            {
              res = rd / ea;
@@ -4205,13 +4164,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
            goto end;
 
          rd = SEXTSHORT (rd);
-
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-         else
-           ea = SEXTCHAR (ea);
+         ea = SEXTCHAR (ea);
 
          if (ea)
            {
@@ -4236,12 +4189,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
              fetch (sd, &code->dst, &rd))
            goto end;
 
-         /* FIXME: is this the right place to be doing sign extend?  */
-         if (OP_KIND (code->src.type) == OP_IMM &&
-             (ea & 8) != 0)
-           ea |= 0xfffffff0;
-         else
-           ea = SEXTSHORT (ea);
+         ea = SEXTSHORT (ea);
 
          if (ea)
            {
@@ -4668,7 +4616,7 @@ sim_trace (SIM_DESC sd)
 }
 
 int
-sim_write (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
+sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size)
 {
   int i;
 
@@ -4767,7 +4715,7 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *value, int length)
       h8_set_ticks (sd, longval);
       break;
     }
-  return -1;
+  return length;
 }
 
 int
@@ -5160,13 +5108,6 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
 }
 
 void
-sim_do_command (SIM_DESC sd, char *cmd)
-{
-  (*sim_callback->printf_filtered) (sim_callback,
-                                   "This simulator does not accept any commands.\n");
-}
-
-void
 sim_set_callbacks (struct host_callback_struct *ptr)
 {
   sim_callback = ptr;