Home | History | Annotate | Line # | Download | only in arch
arm-get-next-pcs.c revision 1.1.1.5
      1      1.1  christos /* Common code for ARM software single stepping support.
      2      1.1  christos 
      3  1.1.1.5  christos    Copyright (C) 1988-2023 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    This file is part of GDB.
      6      1.1  christos 
      7      1.1  christos    This program is free software; you can redistribute it and/or modify
      8      1.1  christos    it under the terms of the GNU General Public License as published by
      9      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos    (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos    This program is distributed in the hope that it will be useful,
     13      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos    GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos    You should have received a copy of the GNU General Public License
     18      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19      1.1  christos 
     20  1.1.1.4  christos #include "gdbsupport/common-defs.h"
     21  1.1.1.4  christos #include "gdbsupport/gdb_vecs.h"
     22  1.1.1.4  christos #include "gdbsupport/common-regcache.h"
     23      1.1  christos #include "arm.h"
     24      1.1  christos #include "arm-get-next-pcs.h"
     25  1.1.1.4  christos #include "count-one-bits.h"
     26      1.1  christos 
     27      1.1  christos /* See arm-get-next-pcs.h.  */
     28      1.1  christos 
     29      1.1  christos void
     30      1.1  christos arm_get_next_pcs_ctor (struct arm_get_next_pcs *self,
     31      1.1  christos 		       struct arm_get_next_pcs_ops *ops,
     32      1.1  christos 		       int byte_order,
     33      1.1  christos 		       int byte_order_for_code,
     34      1.1  christos 		       int has_thumb2_breakpoint,
     35      1.1  christos 		       struct regcache *regcache)
     36      1.1  christos {
     37      1.1  christos   self->ops = ops;
     38      1.1  christos   self->byte_order = byte_order;
     39      1.1  christos   self->byte_order_for_code = byte_order_for_code;
     40      1.1  christos   self->has_thumb2_breakpoint = has_thumb2_breakpoint;
     41      1.1  christos   self->regcache = regcache;
     42      1.1  christos }
     43      1.1  christos 
     44      1.1  christos /* Checks for an atomic sequence of instructions beginning with a LDREX{,B,H,D}
     45      1.1  christos    instruction and ending with a STREX{,B,H,D} instruction.  If such a sequence
     46      1.1  christos    is found, attempt to step through it.  The end of the sequence address is
     47      1.1  christos    added to the next_pcs list.  */
     48      1.1  christos 
     49  1.1.1.3  christos static std::vector<CORE_ADDR>
     50      1.1  christos thumb_deal_with_atomic_sequence_raw (struct arm_get_next_pcs *self)
     51      1.1  christos {
     52      1.1  christos   int byte_order_for_code = self->byte_order_for_code;
     53  1.1.1.3  christos   CORE_ADDR breaks[2] = {CORE_ADDR_MAX, CORE_ADDR_MAX};
     54      1.1  christos   CORE_ADDR pc = regcache_read_pc (self->regcache);
     55      1.1  christos   CORE_ADDR loc = pc;
     56      1.1  christos   unsigned short insn1, insn2;
     57      1.1  christos   int insn_count;
     58      1.1  christos   int index;
     59      1.1  christos   int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed).  */
     60      1.1  christos   const int atomic_sequence_length = 16; /* Instruction sequence length.  */
     61      1.1  christos   ULONGEST status, itstate;
     62      1.1  christos 
     63      1.1  christos   /* We currently do not support atomic sequences within an IT block.  */
     64      1.1  christos   status = regcache_raw_get_unsigned (self->regcache, ARM_PS_REGNUM);
     65      1.1  christos   itstate = ((status >> 8) & 0xfc) | ((status >> 25) & 0x3);
     66      1.1  christos   if (itstate & 0x0f)
     67  1.1.1.3  christos     return {};
     68      1.1  christos 
     69      1.1  christos   /* Assume all atomic sequences start with a ldrex{,b,h,d} instruction.  */
     70      1.1  christos   insn1 = self->ops->read_mem_uint (loc, 2, byte_order_for_code);
     71      1.1  christos 
     72      1.1  christos   loc += 2;
     73      1.1  christos   if (thumb_insn_size (insn1) != 4)
     74  1.1.1.3  christos     return {};
     75      1.1  christos 
     76      1.1  christos   insn2 = self->ops->read_mem_uint (loc, 2, byte_order_for_code);
     77      1.1  christos 
     78      1.1  christos   loc += 2;
     79      1.1  christos   if (!((insn1 & 0xfff0) == 0xe850
     80  1.1.1.5  christos 	|| ((insn1 & 0xfff0) == 0xe8d0 && (insn2 & 0x00c0) == 0x0040)))
     81  1.1.1.3  christos     return {};
     82      1.1  christos 
     83      1.1  christos   /* Assume that no atomic sequence is longer than "atomic_sequence_length"
     84      1.1  christos      instructions.  */
     85      1.1  christos   for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
     86      1.1  christos     {
     87      1.1  christos       insn1 = self->ops->read_mem_uint (loc, 2,byte_order_for_code);
     88      1.1  christos       loc += 2;
     89      1.1  christos 
     90      1.1  christos       if (thumb_insn_size (insn1) != 4)
     91      1.1  christos 	{
     92      1.1  christos 	  /* Assume that there is at most one conditional branch in the
     93      1.1  christos 	     atomic sequence.  If a conditional branch is found, put a
     94      1.1  christos 	     breakpoint in its destination address.  */
     95      1.1  christos 	  if ((insn1 & 0xf000) == 0xd000 && bits (insn1, 8, 11) != 0x0f)
     96      1.1  christos 	    {
     97      1.1  christos 	      if (last_breakpoint > 0)
     98  1.1.1.3  christos 		return {}; /* More than one conditional branch found,
     99  1.1.1.3  christos 			      fallback to the standard code.  */
    100      1.1  christos 
    101      1.1  christos 	      breaks[1] = loc + 2 + (sbits (insn1, 0, 7) << 1);
    102      1.1  christos 	      last_breakpoint++;
    103      1.1  christos 	    }
    104      1.1  christos 
    105      1.1  christos 	  /* We do not support atomic sequences that use any *other*
    106      1.1  christos 	     instructions but conditional branches to change the PC.
    107      1.1  christos 	     Fall back to standard code to avoid losing control of
    108      1.1  christos 	     execution.  */
    109      1.1  christos 	  else if (thumb_instruction_changes_pc (insn1))
    110  1.1.1.3  christos 	    return {};
    111      1.1  christos 	}
    112      1.1  christos       else
    113      1.1  christos 	{
    114      1.1  christos 	  insn2 = self->ops->read_mem_uint (loc, 2, byte_order_for_code);
    115      1.1  christos 
    116      1.1  christos 	  loc += 2;
    117      1.1  christos 
    118      1.1  christos 	  /* Assume that there is at most one conditional branch in the
    119      1.1  christos 	     atomic sequence.  If a conditional branch is found, put a
    120      1.1  christos 	     breakpoint in its destination address.  */
    121      1.1  christos 	  if ((insn1 & 0xf800) == 0xf000
    122      1.1  christos 	      && (insn2 & 0xd000) == 0x8000
    123      1.1  christos 	      && (insn1 & 0x0380) != 0x0380)
    124      1.1  christos 	    {
    125      1.1  christos 	      int sign, j1, j2, imm1, imm2;
    126      1.1  christos 	      unsigned int offset;
    127      1.1  christos 
    128      1.1  christos 	      sign = sbits (insn1, 10, 10);
    129      1.1  christos 	      imm1 = bits (insn1, 0, 5);
    130      1.1  christos 	      imm2 = bits (insn2, 0, 10);
    131      1.1  christos 	      j1 = bit (insn2, 13);
    132      1.1  christos 	      j2 = bit (insn2, 11);
    133      1.1  christos 
    134      1.1  christos 	      offset = (sign << 20) + (j2 << 19) + (j1 << 18);
    135      1.1  christos 	      offset += (imm1 << 12) + (imm2 << 1);
    136      1.1  christos 
    137      1.1  christos 	      if (last_breakpoint > 0)
    138  1.1.1.3  christos 		return {}; /* More than one conditional branch found,
    139  1.1.1.3  christos 			      fallback to the standard code.  */
    140      1.1  christos 
    141      1.1  christos 	      breaks[1] = loc + offset;
    142      1.1  christos 	      last_breakpoint++;
    143      1.1  christos 	    }
    144      1.1  christos 
    145      1.1  christos 	  /* We do not support atomic sequences that use any *other*
    146      1.1  christos 	     instructions but conditional branches to change the PC.
    147      1.1  christos 	     Fall back to standard code to avoid losing control of
    148      1.1  christos 	     execution.  */
    149      1.1  christos 	  else if (thumb2_instruction_changes_pc (insn1, insn2))
    150  1.1.1.3  christos 	    return {};
    151      1.1  christos 
    152      1.1  christos 	  /* If we find a strex{,b,h,d}, we're done.  */
    153      1.1  christos 	  if ((insn1 & 0xfff0) == 0xe840
    154      1.1  christos 	      || ((insn1 & 0xfff0) == 0xe8c0 && (insn2 & 0x00c0) == 0x0040))
    155      1.1  christos 	    break;
    156      1.1  christos 	}
    157      1.1  christos     }
    158      1.1  christos 
    159      1.1  christos   /* If we didn't find the strex{,b,h,d}, we cannot handle the sequence.  */
    160      1.1  christos   if (insn_count == atomic_sequence_length)
    161  1.1.1.3  christos     return {};
    162      1.1  christos 
    163      1.1  christos   /* Insert a breakpoint right after the end of the atomic sequence.  */
    164      1.1  christos   breaks[0] = loc;
    165      1.1  christos 
    166      1.1  christos   /* Check for duplicated breakpoints.  Check also for a breakpoint
    167      1.1  christos      placed (branch instruction's destination) anywhere in sequence.  */
    168      1.1  christos   if (last_breakpoint
    169      1.1  christos       && (breaks[1] == breaks[0]
    170      1.1  christos 	  || (breaks[1] >= pc && breaks[1] < loc)))
    171      1.1  christos     last_breakpoint = 0;
    172      1.1  christos 
    173  1.1.1.3  christos   std::vector<CORE_ADDR> next_pcs;
    174  1.1.1.3  christos 
    175      1.1  christos   /* Adds the breakpoints to the list to be inserted.  */
    176      1.1  christos   for (index = 0; index <= last_breakpoint; index++)
    177  1.1.1.3  christos     next_pcs.push_back (MAKE_THUMB_ADDR (breaks[index]));
    178      1.1  christos 
    179      1.1  christos   return next_pcs;
    180      1.1  christos }
    181      1.1  christos 
    182      1.1  christos /* Checks for an atomic sequence of instructions beginning with a LDREX{,B,H,D}
    183      1.1  christos    instruction and ending with a STREX{,B,H,D} instruction.  If such a sequence
    184      1.1  christos    is found, attempt to step through it.  The end of the sequence address is
    185      1.1  christos    added to the next_pcs list.  */
    186      1.1  christos 
    187  1.1.1.3  christos static std::vector<CORE_ADDR>
    188      1.1  christos arm_deal_with_atomic_sequence_raw (struct arm_get_next_pcs *self)
    189      1.1  christos {
    190      1.1  christos   int byte_order_for_code = self->byte_order_for_code;
    191  1.1.1.3  christos   CORE_ADDR breaks[2] = {CORE_ADDR_MAX, CORE_ADDR_MAX};
    192      1.1  christos   CORE_ADDR pc = regcache_read_pc (self->regcache);
    193      1.1  christos   CORE_ADDR loc = pc;
    194      1.1  christos   unsigned int insn;
    195      1.1  christos   int insn_count;
    196      1.1  christos   int index;
    197      1.1  christos   int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed).  */
    198      1.1  christos   const int atomic_sequence_length = 16; /* Instruction sequence length.  */
    199      1.1  christos 
    200      1.1  christos   /* Assume all atomic sequences start with a ldrex{,b,h,d} instruction.
    201      1.1  christos      Note that we do not currently support conditionally executed atomic
    202      1.1  christos      instructions.  */
    203      1.1  christos   insn = self->ops->read_mem_uint (loc, 4, byte_order_for_code);
    204      1.1  christos 
    205      1.1  christos   loc += 4;
    206      1.1  christos   if ((insn & 0xff9000f0) != 0xe1900090)
    207  1.1.1.3  christos     return {};
    208      1.1  christos 
    209      1.1  christos   /* Assume that no atomic sequence is longer than "atomic_sequence_length"
    210      1.1  christos      instructions.  */
    211      1.1  christos   for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
    212      1.1  christos     {
    213      1.1  christos       insn = self->ops->read_mem_uint (loc, 4, byte_order_for_code);
    214      1.1  christos 
    215      1.1  christos       loc += 4;
    216      1.1  christos 
    217      1.1  christos       /* Assume that there is at most one conditional branch in the atomic
    218  1.1.1.5  christos 	 sequence.  If a conditional branch is found, put a breakpoint in
    219  1.1.1.5  christos 	 its destination address.  */
    220      1.1  christos       if (bits (insn, 24, 27) == 0xa)
    221      1.1  christos 	{
    222  1.1.1.5  christos 	  if (last_breakpoint > 0)
    223  1.1.1.5  christos 	    return {}; /* More than one conditional branch found, fallback
    224  1.1.1.3  christos 			  to the standard single-step code.  */
    225      1.1  christos 
    226      1.1  christos 	  breaks[1] = BranchDest (loc - 4, insn);
    227      1.1  christos 	  last_breakpoint++;
    228  1.1.1.5  christos 	}
    229      1.1  christos 
    230      1.1  christos       /* We do not support atomic sequences that use any *other* instructions
    231  1.1.1.5  christos 	 but conditional branches to change the PC.  Fall back to standard
    232      1.1  christos 	 code to avoid losing control of execution.  */
    233      1.1  christos       else if (arm_instruction_changes_pc (insn))
    234  1.1.1.3  christos 	return {};
    235      1.1  christos 
    236      1.1  christos       /* If we find a strex{,b,h,d}, we're done.  */
    237      1.1  christos       if ((insn & 0xff9000f0) == 0xe1800090)
    238      1.1  christos 	break;
    239      1.1  christos     }
    240      1.1  christos 
    241      1.1  christos   /* If we didn't find the strex{,b,h,d}, we cannot handle the sequence.  */
    242      1.1  christos   if (insn_count == atomic_sequence_length)
    243  1.1.1.3  christos     return {};
    244      1.1  christos 
    245      1.1  christos   /* Insert a breakpoint right after the end of the atomic sequence.  */
    246      1.1  christos   breaks[0] = loc;
    247      1.1  christos 
    248      1.1  christos   /* Check for duplicated breakpoints.  Check also for a breakpoint
    249      1.1  christos      placed (branch instruction's destination) anywhere in sequence.  */
    250      1.1  christos   if (last_breakpoint
    251      1.1  christos       && (breaks[1] == breaks[0]
    252      1.1  christos 	  || (breaks[1] >= pc && breaks[1] < loc)))
    253      1.1  christos     last_breakpoint = 0;
    254      1.1  christos 
    255  1.1.1.3  christos   std::vector<CORE_ADDR> next_pcs;
    256  1.1.1.3  christos 
    257      1.1  christos   /* Adds the breakpoints to the list to be inserted.  */
    258      1.1  christos   for (index = 0; index <= last_breakpoint; index++)
    259  1.1.1.3  christos     next_pcs.push_back (breaks[index]);
    260      1.1  christos 
    261      1.1  christos   return next_pcs;
    262      1.1  christos }
    263      1.1  christos 
    264      1.1  christos /* Find the next possible PCs for thumb mode.  */
    265      1.1  christos 
    266  1.1.1.3  christos static std::vector<CORE_ADDR>
    267      1.1  christos thumb_get_next_pcs_raw (struct arm_get_next_pcs *self)
    268      1.1  christos {
    269      1.1  christos   int byte_order = self->byte_order;
    270      1.1  christos   int byte_order_for_code = self->byte_order_for_code;
    271      1.1  christos   CORE_ADDR pc = regcache_read_pc (self->regcache);
    272      1.1  christos   unsigned long pc_val = ((unsigned long) pc) + 4;	/* PC after prefetch */
    273      1.1  christos   unsigned short inst1;
    274      1.1  christos   CORE_ADDR nextpc = pc + 2;		/* Default is next instruction.  */
    275      1.1  christos   ULONGEST status, itstate;
    276      1.1  christos   struct regcache *regcache = self->regcache;
    277  1.1.1.3  christos   std::vector<CORE_ADDR> next_pcs;
    278      1.1  christos 
    279      1.1  christos   nextpc = MAKE_THUMB_ADDR (nextpc);
    280      1.1  christos   pc_val = MAKE_THUMB_ADDR (pc_val);
    281      1.1  christos 
    282      1.1  christos   inst1 = self->ops->read_mem_uint (pc, 2, byte_order_for_code);
    283      1.1  christos 
    284      1.1  christos   /* Thumb-2 conditional execution support.  There are eight bits in
    285      1.1  christos      the CPSR which describe conditional execution state.  Once
    286      1.1  christos      reconstructed (they're in a funny order), the low five bits
    287      1.1  christos      describe the low bit of the condition for each instruction and
    288      1.1  christos      how many instructions remain.  The high three bits describe the
    289      1.1  christos      base condition.  One of the low four bits will be set if an IT
    290      1.1  christos      block is active.  These bits read as zero on earlier
    291      1.1  christos      processors.  */
    292      1.1  christos   status = regcache_raw_get_unsigned (regcache, ARM_PS_REGNUM);
    293      1.1  christos   itstate = ((status >> 8) & 0xfc) | ((status >> 25) & 0x3);
    294      1.1  christos 
    295      1.1  christos   /* If-Then handling.  On GNU/Linux, where this routine is used, we
    296      1.1  christos      use an undefined instruction as a breakpoint.  Unlike BKPT, IT
    297      1.1  christos      can disable execution of the undefined instruction.  So we might
    298      1.1  christos      miss the breakpoint if we set it on a skipped conditional
    299      1.1  christos      instruction.  Because conditional instructions can change the
    300      1.1  christos      flags, affecting the execution of further instructions, we may
    301      1.1  christos      need to set two breakpoints.  */
    302      1.1  christos 
    303      1.1  christos   if (self->has_thumb2_breakpoint)
    304      1.1  christos     {
    305      1.1  christos       if ((inst1 & 0xff00) == 0xbf00 && (inst1 & 0x000f) != 0)
    306      1.1  christos 	{
    307      1.1  christos 	  /* An IT instruction.  Because this instruction does not
    308      1.1  christos 	     modify the flags, we can accurately predict the next
    309      1.1  christos 	     executed instruction.  */
    310      1.1  christos 	  itstate = inst1 & 0x00ff;
    311      1.1  christos 	  pc += thumb_insn_size (inst1);
    312      1.1  christos 
    313      1.1  christos 	  while (itstate != 0 && ! condition_true (itstate >> 4, status))
    314      1.1  christos 	    {
    315      1.1  christos 	      inst1 = self->ops->read_mem_uint (pc, 2,byte_order_for_code);
    316      1.1  christos 	      pc += thumb_insn_size (inst1);
    317      1.1  christos 	      itstate = thumb_advance_itstate (itstate);
    318      1.1  christos 	    }
    319      1.1  christos 
    320  1.1.1.3  christos 	  next_pcs.push_back (MAKE_THUMB_ADDR (pc));
    321      1.1  christos 	  return next_pcs;
    322      1.1  christos 	}
    323      1.1  christos       else if (itstate != 0)
    324      1.1  christos 	{
    325      1.1  christos 	  /* We are in a conditional block.  Check the condition.  */
    326      1.1  christos 	  if (! condition_true (itstate >> 4, status))
    327      1.1  christos 	    {
    328      1.1  christos 	      /* Advance to the next executed instruction.  */
    329      1.1  christos 	      pc += thumb_insn_size (inst1);
    330      1.1  christos 	      itstate = thumb_advance_itstate (itstate);
    331      1.1  christos 
    332      1.1  christos 	      while (itstate != 0 && ! condition_true (itstate >> 4, status))
    333      1.1  christos 		{
    334      1.1  christos 		  inst1 = self->ops->read_mem_uint (pc, 2, byte_order_for_code);
    335      1.1  christos 
    336      1.1  christos 		  pc += thumb_insn_size (inst1);
    337      1.1  christos 		  itstate = thumb_advance_itstate (itstate);
    338      1.1  christos 		}
    339      1.1  christos 
    340  1.1.1.3  christos 	      next_pcs.push_back (MAKE_THUMB_ADDR (pc));
    341      1.1  christos 	      return next_pcs;
    342      1.1  christos 	    }
    343      1.1  christos 	  else if ((itstate & 0x0f) == 0x08)
    344      1.1  christos 	    {
    345      1.1  christos 	      /* This is the last instruction of the conditional
    346      1.1  christos 		 block, and it is executed.  We can handle it normally
    347      1.1  christos 		 because the following instruction is not conditional,
    348      1.1  christos 		 and we must handle it normally because it is
    349      1.1  christos 		 permitted to branch.  Fall through.  */
    350      1.1  christos 	    }
    351      1.1  christos 	  else
    352      1.1  christos 	    {
    353      1.1  christos 	      int cond_negated;
    354      1.1  christos 
    355      1.1  christos 	      /* There are conditional instructions after this one.
    356      1.1  christos 		 If this instruction modifies the flags, then we can
    357      1.1  christos 		 not predict what the next executed instruction will
    358      1.1  christos 		 be.  Fortunately, this instruction is architecturally
    359      1.1  christos 		 forbidden to branch; we know it will fall through.
    360      1.1  christos 		 Start by skipping past it.  */
    361      1.1  christos 	      pc += thumb_insn_size (inst1);
    362      1.1  christos 	      itstate = thumb_advance_itstate (itstate);
    363      1.1  christos 
    364      1.1  christos 	      /* Set a breakpoint on the following instruction.  */
    365      1.1  christos 	      gdb_assert ((itstate & 0x0f) != 0);
    366  1.1.1.3  christos 	      next_pcs.push_back (MAKE_THUMB_ADDR (pc));
    367      1.1  christos 
    368      1.1  christos 	      cond_negated = (itstate >> 4) & 1;
    369      1.1  christos 
    370      1.1  christos 	      /* Skip all following instructions with the same
    371      1.1  christos 		 condition.  If there is a later instruction in the IT
    372      1.1  christos 		 block with the opposite condition, set the other
    373      1.1  christos 		 breakpoint there.  If not, then set a breakpoint on
    374      1.1  christos 		 the instruction after the IT block.  */
    375      1.1  christos 	      do
    376      1.1  christos 		{
    377      1.1  christos 		  inst1 = self->ops->read_mem_uint (pc, 2, byte_order_for_code);
    378      1.1  christos 		  pc += thumb_insn_size (inst1);
    379      1.1  christos 		  itstate = thumb_advance_itstate (itstate);
    380      1.1  christos 		}
    381      1.1  christos 	      while (itstate != 0 && ((itstate >> 4) & 1) == cond_negated);
    382      1.1  christos 
    383  1.1.1.3  christos 	      next_pcs.push_back (MAKE_THUMB_ADDR (pc));
    384      1.1  christos 
    385      1.1  christos 	      return next_pcs;
    386      1.1  christos 	    }
    387      1.1  christos 	}
    388      1.1  christos     }
    389      1.1  christos   else if (itstate & 0x0f)
    390      1.1  christos     {
    391      1.1  christos       /* We are in a conditional block.  Check the condition.  */
    392      1.1  christos       int cond = itstate >> 4;
    393      1.1  christos 
    394      1.1  christos       if (! condition_true (cond, status))
    395      1.1  christos 	{
    396      1.1  christos 	  /* Advance to the next instruction.  All the 32-bit
    397      1.1  christos 	     instructions share a common prefix.  */
    398  1.1.1.3  christos 	  next_pcs.push_back (MAKE_THUMB_ADDR (pc + thumb_insn_size (inst1)));
    399      1.1  christos 	}
    400      1.1  christos 
    401      1.1  christos       return next_pcs;
    402      1.1  christos 
    403      1.1  christos       /* Otherwise, handle the instruction normally.  */
    404      1.1  christos     }
    405      1.1  christos 
    406      1.1  christos   if ((inst1 & 0xff00) == 0xbd00)	/* pop {rlist, pc} */
    407      1.1  christos     {
    408      1.1  christos       CORE_ADDR sp;
    409      1.1  christos 
    410      1.1  christos       /* Fetch the saved PC from the stack.  It's stored above
    411  1.1.1.5  christos 	 all of the other registers.  */
    412  1.1.1.4  christos       unsigned long offset
    413  1.1.1.4  christos 	= count_one_bits (bits (inst1, 0, 7)) * ARM_INT_REGISTER_SIZE;
    414      1.1  christos       sp = regcache_raw_get_unsigned (regcache, ARM_SP_REGNUM);
    415      1.1  christos       nextpc = self->ops->read_mem_uint (sp + offset, 4, byte_order);
    416      1.1  christos     }
    417      1.1  christos   else if ((inst1 & 0xf000) == 0xd000)	/* conditional branch */
    418      1.1  christos     {
    419      1.1  christos       unsigned long cond = bits (inst1, 8, 11);
    420      1.1  christos       if (cond == 0x0f)  /* 0x0f = SWI */
    421      1.1  christos 	{
    422      1.1  christos 	  nextpc = self->ops->syscall_next_pc (self);
    423      1.1  christos 	}
    424      1.1  christos       else if (cond != 0x0f && condition_true (cond, status))
    425      1.1  christos 	nextpc = pc_val + (sbits (inst1, 0, 7) << 1);
    426      1.1  christos     }
    427      1.1  christos   else if ((inst1 & 0xf800) == 0xe000)	/* unconditional branch */
    428      1.1  christos     {
    429      1.1  christos       nextpc = pc_val + (sbits (inst1, 0, 10) << 1);
    430      1.1  christos     }
    431      1.1  christos   else if (thumb_insn_size (inst1) == 4) /* 32-bit instruction */
    432      1.1  christos     {
    433      1.1  christos       unsigned short inst2;
    434      1.1  christos       inst2 = self->ops->read_mem_uint (pc + 2, 2, byte_order_for_code);
    435      1.1  christos 
    436      1.1  christos       /* Default to the next instruction.  */
    437      1.1  christos       nextpc = pc + 4;
    438      1.1  christos       nextpc = MAKE_THUMB_ADDR (nextpc);
    439      1.1  christos 
    440      1.1  christos       if ((inst1 & 0xf800) == 0xf000 && (inst2 & 0x8000) == 0x8000)
    441      1.1  christos 	{
    442      1.1  christos 	  /* Branches and miscellaneous control instructions.  */
    443      1.1  christos 
    444      1.1  christos 	  if ((inst2 & 0x1000) != 0 || (inst2 & 0xd001) == 0xc000)
    445      1.1  christos 	    {
    446      1.1  christos 	      /* B, BL, BLX.  */
    447      1.1  christos 	      int j1, j2, imm1, imm2;
    448      1.1  christos 
    449      1.1  christos 	      imm1 = sbits (inst1, 0, 10);
    450      1.1  christos 	      imm2 = bits (inst2, 0, 10);
    451      1.1  christos 	      j1 = bit (inst2, 13);
    452      1.1  christos 	      j2 = bit (inst2, 11);
    453      1.1  christos 
    454  1.1.1.3  christos 	      unsigned long offset = ((imm1 << 12) + (imm2 << 1));
    455      1.1  christos 	      offset ^= ((!j2) << 22) | ((!j1) << 23);
    456      1.1  christos 
    457      1.1  christos 	      nextpc = pc_val + offset;
    458      1.1  christos 	      /* For BLX make sure to clear the low bits.  */
    459      1.1  christos 	      if (bit (inst2, 12) == 0)
    460      1.1  christos 		nextpc = nextpc & 0xfffffffc;
    461      1.1  christos 	    }
    462      1.1  christos 	  else if (inst1 == 0xf3de && (inst2 & 0xff00) == 0x3f00)
    463      1.1  christos 	    {
    464      1.1  christos 	      /* SUBS PC, LR, #imm8.  */
    465      1.1  christos 	      nextpc = regcache_raw_get_unsigned (regcache, ARM_LR_REGNUM);
    466      1.1  christos 	      nextpc -= inst2 & 0x00ff;
    467      1.1  christos 	    }
    468      1.1  christos 	  else if ((inst2 & 0xd000) == 0x8000 && (inst1 & 0x0380) != 0x0380)
    469      1.1  christos 	    {
    470      1.1  christos 	      /* Conditional branch.  */
    471      1.1  christos 	      if (condition_true (bits (inst1, 6, 9), status))
    472      1.1  christos 		{
    473      1.1  christos 		  int sign, j1, j2, imm1, imm2;
    474      1.1  christos 
    475      1.1  christos 		  sign = sbits (inst1, 10, 10);
    476      1.1  christos 		  imm1 = bits (inst1, 0, 5);
    477      1.1  christos 		  imm2 = bits (inst2, 0, 10);
    478      1.1  christos 		  j1 = bit (inst2, 13);
    479      1.1  christos 		  j2 = bit (inst2, 11);
    480      1.1  christos 
    481  1.1.1.3  christos 		  unsigned long offset
    482  1.1.1.3  christos 		    = (sign << 20) + (j2 << 19) + (j1 << 18);
    483      1.1  christos 		  offset += (imm1 << 12) + (imm2 << 1);
    484      1.1  christos 
    485      1.1  christos 		  nextpc = pc_val + offset;
    486      1.1  christos 		}
    487      1.1  christos 	    }
    488      1.1  christos 	}
    489      1.1  christos       else if ((inst1 & 0xfe50) == 0xe810)
    490      1.1  christos 	{
    491      1.1  christos 	  /* Load multiple or RFE.  */
    492      1.1  christos 	  int rn, offset, load_pc = 1;
    493      1.1  christos 
    494      1.1  christos 	  rn = bits (inst1, 0, 3);
    495      1.1  christos 	  if (bit (inst1, 7) && !bit (inst1, 8))
    496      1.1  christos 	    {
    497      1.1  christos 	      /* LDMIA or POP */
    498      1.1  christos 	      if (!bit (inst2, 15))
    499      1.1  christos 		load_pc = 0;
    500  1.1.1.4  christos 	      offset = count_one_bits (inst2) * 4 - 4;
    501      1.1  christos 	    }
    502      1.1  christos 	  else if (!bit (inst1, 7) && bit (inst1, 8))
    503      1.1  christos 	    {
    504      1.1  christos 	      /* LDMDB */
    505      1.1  christos 	      if (!bit (inst2, 15))
    506      1.1  christos 		load_pc = 0;
    507      1.1  christos 	      offset = -4;
    508      1.1  christos 	    }
    509      1.1  christos 	  else if (bit (inst1, 7) && bit (inst1, 8))
    510      1.1  christos 	    {
    511      1.1  christos 	      /* RFEIA */
    512      1.1  christos 	      offset = 0;
    513      1.1  christos 	    }
    514      1.1  christos 	  else if (!bit (inst1, 7) && !bit (inst1, 8))
    515      1.1  christos 	    {
    516      1.1  christos 	      /* RFEDB */
    517      1.1  christos 	      offset = -8;
    518      1.1  christos 	    }
    519      1.1  christos 	  else
    520      1.1  christos 	    load_pc = 0;
    521      1.1  christos 
    522      1.1  christos 	  if (load_pc)
    523      1.1  christos 	    {
    524      1.1  christos 	      CORE_ADDR addr = regcache_raw_get_unsigned (regcache, rn);
    525      1.1  christos 	      nextpc = self->ops->read_mem_uint	(addr + offset, 4, byte_order);
    526      1.1  christos 	    }
    527      1.1  christos 	}
    528      1.1  christos       else if ((inst1 & 0xffef) == 0xea4f && (inst2 & 0xfff0) == 0x0f00)
    529      1.1  christos 	{
    530      1.1  christos 	  /* MOV PC or MOVS PC.  */
    531      1.1  christos 	  nextpc = regcache_raw_get_unsigned (regcache, bits (inst2, 0, 3));
    532      1.1  christos 	  nextpc = MAKE_THUMB_ADDR (nextpc);
    533      1.1  christos 	}
    534      1.1  christos       else if ((inst1 & 0xff70) == 0xf850 && (inst2 & 0xf000) == 0xf000)
    535      1.1  christos 	{
    536      1.1  christos 	  /* LDR PC.  */
    537      1.1  christos 	  CORE_ADDR base;
    538      1.1  christos 	  int rn, load_pc = 1;
    539      1.1  christos 
    540      1.1  christos 	  rn = bits (inst1, 0, 3);
    541      1.1  christos 	  base = regcache_raw_get_unsigned (regcache, rn);
    542      1.1  christos 	  if (rn == ARM_PC_REGNUM)
    543      1.1  christos 	    {
    544      1.1  christos 	      base = (base + 4) & ~(CORE_ADDR) 0x3;
    545      1.1  christos 	      if (bit (inst1, 7))
    546      1.1  christos 		base += bits (inst2, 0, 11);
    547      1.1  christos 	      else
    548      1.1  christos 		base -= bits (inst2, 0, 11);
    549      1.1  christos 	    }
    550      1.1  christos 	  else if (bit (inst1, 7))
    551      1.1  christos 	    base += bits (inst2, 0, 11);
    552      1.1  christos 	  else if (bit (inst2, 11))
    553      1.1  christos 	    {
    554      1.1  christos 	      if (bit (inst2, 10))
    555      1.1  christos 		{
    556      1.1  christos 		  if (bit (inst2, 9))
    557      1.1  christos 		    base += bits (inst2, 0, 7);
    558      1.1  christos 		  else
    559      1.1  christos 		    base -= bits (inst2, 0, 7);
    560      1.1  christos 		}
    561      1.1  christos 	    }
    562      1.1  christos 	  else if ((inst2 & 0x0fc0) == 0x0000)
    563      1.1  christos 	    {
    564      1.1  christos 	      int shift = bits (inst2, 4, 5), rm = bits (inst2, 0, 3);
    565      1.1  christos 	      base += regcache_raw_get_unsigned (regcache, rm) << shift;
    566      1.1  christos 	    }
    567      1.1  christos 	  else
    568      1.1  christos 	    /* Reserved.  */
    569      1.1  christos 	    load_pc = 0;
    570      1.1  christos 
    571      1.1  christos 	  if (load_pc)
    572      1.1  christos 	    nextpc
    573      1.1  christos 	      = self->ops->read_mem_uint (base, 4, byte_order);
    574      1.1  christos 	}
    575      1.1  christos       else if ((inst1 & 0xfff0) == 0xe8d0 && (inst2 & 0xfff0) == 0xf000)
    576      1.1  christos 	{
    577      1.1  christos 	  /* TBB.  */
    578      1.1  christos 	  CORE_ADDR tbl_reg, table, offset, length;
    579      1.1  christos 
    580      1.1  christos 	  tbl_reg = bits (inst1, 0, 3);
    581      1.1  christos 	  if (tbl_reg == 0x0f)
    582      1.1  christos 	    table = pc + 4;  /* Regcache copy of PC isn't right yet.  */
    583      1.1  christos 	  else
    584      1.1  christos 	    table = regcache_raw_get_unsigned (regcache, tbl_reg);
    585      1.1  christos 
    586      1.1  christos 	  offset = regcache_raw_get_unsigned (regcache, bits (inst2, 0, 3));
    587      1.1  christos 	  length = 2 * self->ops->read_mem_uint (table + offset, 1, byte_order);
    588      1.1  christos 	  nextpc = pc_val + length;
    589      1.1  christos 	}
    590      1.1  christos       else if ((inst1 & 0xfff0) == 0xe8d0 && (inst2 & 0xfff0) == 0xf010)
    591      1.1  christos 	{
    592      1.1  christos 	  /* TBH.  */
    593      1.1  christos 	  CORE_ADDR tbl_reg, table, offset, length;
    594      1.1  christos 
    595      1.1  christos 	  tbl_reg = bits (inst1, 0, 3);
    596      1.1  christos 	  if (tbl_reg == 0x0f)
    597      1.1  christos 	    table = pc + 4;  /* Regcache copy of PC isn't right yet.  */
    598      1.1  christos 	  else
    599      1.1  christos 	    table = regcache_raw_get_unsigned (regcache, tbl_reg);
    600      1.1  christos 
    601      1.1  christos 	  offset = 2 * regcache_raw_get_unsigned (regcache, bits (inst2, 0, 3));
    602      1.1  christos 	  length = 2 * self->ops->read_mem_uint (table + offset, 2, byte_order);
    603      1.1  christos 	  nextpc = pc_val + length;
    604      1.1  christos 	}
    605      1.1  christos     }
    606      1.1  christos   else if ((inst1 & 0xff00) == 0x4700)	/* bx REG, blx REG */
    607      1.1  christos     {
    608      1.1  christos       if (bits (inst1, 3, 6) == 0x0f)
    609      1.1  christos 	nextpc = UNMAKE_THUMB_ADDR (pc_val);
    610      1.1  christos       else
    611      1.1  christos 	nextpc = regcache_raw_get_unsigned (regcache, bits (inst1, 3, 6));
    612      1.1  christos     }
    613      1.1  christos   else if ((inst1 & 0xff87) == 0x4687)	/* mov pc, REG */
    614      1.1  christos     {
    615      1.1  christos       if (bits (inst1, 3, 6) == 0x0f)
    616      1.1  christos 	nextpc = pc_val;
    617      1.1  christos       else
    618      1.1  christos 	nextpc = regcache_raw_get_unsigned (regcache, bits (inst1, 3, 6));
    619      1.1  christos 
    620      1.1  christos       nextpc = MAKE_THUMB_ADDR (nextpc);
    621      1.1  christos     }
    622      1.1  christos   else if ((inst1 & 0xf500) == 0xb100)
    623      1.1  christos     {
    624      1.1  christos       /* CBNZ or CBZ.  */
    625      1.1  christos       int imm = (bit (inst1, 9) << 6) + (bits (inst1, 3, 7) << 1);
    626      1.1  christos       ULONGEST reg = regcache_raw_get_unsigned (regcache, bits (inst1, 0, 2));
    627      1.1  christos 
    628      1.1  christos       if (bit (inst1, 11) && reg != 0)
    629      1.1  christos 	nextpc = pc_val + imm;
    630      1.1  christos       else if (!bit (inst1, 11) && reg == 0)
    631      1.1  christos 	nextpc = pc_val + imm;
    632      1.1  christos     }
    633      1.1  christos 
    634  1.1.1.3  christos   next_pcs.push_back (nextpc);
    635      1.1  christos 
    636      1.1  christos   return next_pcs;
    637      1.1  christos }
    638      1.1  christos 
    639      1.1  christos /* Get the raw next possible addresses.  PC in next_pcs is the current program
    640      1.1  christos    counter, which is assumed to be executing in ARM mode.
    641      1.1  christos 
    642      1.1  christos    The values returned have the execution state of the next instruction
    643      1.1  christos    encoded in it.  Use IS_THUMB_ADDR () to see whether the instruction is
    644      1.1  christos    in Thumb-State, and gdbarch_addr_bits_remove () to get the plain memory
    645      1.1  christos    address in GDB and arm_addr_bits_remove in GDBServer.  */
    646      1.1  christos 
    647  1.1.1.3  christos static std::vector<CORE_ADDR>
    648      1.1  christos arm_get_next_pcs_raw (struct arm_get_next_pcs *self)
    649      1.1  christos {
    650      1.1  christos   int byte_order = self->byte_order;
    651      1.1  christos   int byte_order_for_code = self->byte_order_for_code;
    652      1.1  christos   unsigned long pc_val;
    653      1.1  christos   unsigned long this_instr = 0;
    654      1.1  christos   unsigned long status;
    655      1.1  christos   CORE_ADDR nextpc;
    656      1.1  christos   struct regcache *regcache = self->regcache;
    657      1.1  christos   CORE_ADDR pc = regcache_read_pc (self->regcache);
    658  1.1.1.3  christos   std::vector<CORE_ADDR> next_pcs;
    659      1.1  christos 
    660      1.1  christos   pc_val = (unsigned long) pc;
    661      1.1  christos   this_instr = self->ops->read_mem_uint (pc, 4, byte_order_for_code);
    662      1.1  christos 
    663      1.1  christos   status = regcache_raw_get_unsigned (regcache, ARM_PS_REGNUM);
    664      1.1  christos   nextpc = (CORE_ADDR) (pc_val + 4);	/* Default case */
    665      1.1  christos 
    666      1.1  christos   if (bits (this_instr, 28, 31) == INST_NV)
    667      1.1  christos     switch (bits (this_instr, 24, 27))
    668      1.1  christos       {
    669      1.1  christos       case 0xa:
    670      1.1  christos       case 0xb:
    671      1.1  christos 	{
    672      1.1  christos 	  /* Branch with Link and change to Thumb.  */
    673      1.1  christos 	  nextpc = BranchDest (pc, this_instr);
    674      1.1  christos 	  nextpc |= bit (this_instr, 24) << 1;
    675      1.1  christos 	  nextpc = MAKE_THUMB_ADDR (nextpc);
    676      1.1  christos 	  break;
    677      1.1  christos 	}
    678      1.1  christos       case 0xc:
    679      1.1  christos       case 0xd:
    680      1.1  christos       case 0xe:
    681      1.1  christos 	/* Coprocessor register transfer.  */
    682  1.1.1.5  christos 	if (bits (this_instr, 12, 15) == 15)
    683      1.1  christos 	  error (_("Invalid update to pc in instruction"));
    684      1.1  christos 	break;
    685      1.1  christos       }
    686      1.1  christos   else if (condition_true (bits (this_instr, 28, 31), status))
    687      1.1  christos     {
    688      1.1  christos       switch (bits (this_instr, 24, 27))
    689      1.1  christos 	{
    690      1.1  christos 	case 0x0:
    691      1.1  christos 	case 0x1:			/* data processing */
    692      1.1  christos 	case 0x2:
    693      1.1  christos 	case 0x3:
    694      1.1  christos 	  {
    695      1.1  christos 	    unsigned long operand1, operand2, result = 0;
    696      1.1  christos 	    unsigned long rn;
    697      1.1  christos 	    int c;
    698      1.1  christos 
    699      1.1  christos 	    if (bits (this_instr, 12, 15) != 15)
    700      1.1  christos 	      break;
    701      1.1  christos 
    702      1.1  christos 	    if (bits (this_instr, 22, 25) == 0
    703      1.1  christos 		&& bits (this_instr, 4, 7) == 9)	/* multiply */
    704      1.1  christos 	      error (_("Invalid update to pc in instruction"));
    705      1.1  christos 
    706      1.1  christos 	    /* BX <reg>, BLX <reg> */
    707      1.1  christos 	    if (bits (this_instr, 4, 27) == 0x12fff1
    708      1.1  christos 		|| bits (this_instr, 4, 27) == 0x12fff3)
    709      1.1  christos 	      {
    710      1.1  christos 		rn = bits (this_instr, 0, 3);
    711      1.1  christos 		nextpc = ((rn == ARM_PC_REGNUM)
    712      1.1  christos 			  ? (pc_val + 8)
    713      1.1  christos 			  : regcache_raw_get_unsigned (regcache, rn));
    714      1.1  christos 
    715  1.1.1.3  christos 		next_pcs.push_back (nextpc);
    716      1.1  christos 		return next_pcs;
    717      1.1  christos 	      }
    718      1.1  christos 
    719      1.1  christos 	    /* Multiply into PC.  */
    720      1.1  christos 	    c = (status & FLAG_C) ? 1 : 0;
    721      1.1  christos 	    rn = bits (this_instr, 16, 19);
    722      1.1  christos 	    operand1 = ((rn == ARM_PC_REGNUM)
    723      1.1  christos 			? (pc_val + 8)
    724      1.1  christos 			: regcache_raw_get_unsigned (regcache, rn));
    725      1.1  christos 
    726      1.1  christos 	    if (bit (this_instr, 25))
    727      1.1  christos 	      {
    728      1.1  christos 		unsigned long immval = bits (this_instr, 0, 7);
    729      1.1  christos 		unsigned long rotate = 2 * bits (this_instr, 8, 11);
    730      1.1  christos 		operand2 = ((immval >> rotate) | (immval << (32 - rotate)))
    731      1.1  christos 		  & 0xffffffff;
    732      1.1  christos 	      }
    733      1.1  christos 	    else		/* operand 2 is a shifted register.  */
    734      1.1  christos 	      operand2 = shifted_reg_val (regcache, this_instr, c,
    735      1.1  christos 					  pc_val, status);
    736      1.1  christos 
    737      1.1  christos 	    switch (bits (this_instr, 21, 24))
    738      1.1  christos 	      {
    739      1.1  christos 	      case 0x0:	/*and */
    740      1.1  christos 		result = operand1 & operand2;
    741      1.1  christos 		break;
    742      1.1  christos 
    743      1.1  christos 	      case 0x1:	/*eor */
    744      1.1  christos 		result = operand1 ^ operand2;
    745      1.1  christos 		break;
    746      1.1  christos 
    747      1.1  christos 	      case 0x2:	/*sub */
    748      1.1  christos 		result = operand1 - operand2;
    749      1.1  christos 		break;
    750      1.1  christos 
    751      1.1  christos 	      case 0x3:	/*rsb */
    752      1.1  christos 		result = operand2 - operand1;
    753      1.1  christos 		break;
    754      1.1  christos 
    755      1.1  christos 	      case 0x4:	/*add */
    756      1.1  christos 		result = operand1 + operand2;
    757      1.1  christos 		break;
    758      1.1  christos 
    759      1.1  christos 	      case 0x5:	/*adc */
    760      1.1  christos 		result = operand1 + operand2 + c;
    761      1.1  christos 		break;
    762      1.1  christos 
    763      1.1  christos 	      case 0x6:	/*sbc */
    764      1.1  christos 		result = operand1 - operand2 + c;
    765      1.1  christos 		break;
    766      1.1  christos 
    767      1.1  christos 	      case 0x7:	/*rsc */
    768      1.1  christos 		result = operand2 - operand1 + c;
    769      1.1  christos 		break;
    770      1.1  christos 
    771      1.1  christos 	      case 0x8:
    772      1.1  christos 	      case 0x9:
    773      1.1  christos 	      case 0xa:
    774      1.1  christos 	      case 0xb:	/* tst, teq, cmp, cmn */
    775      1.1  christos 		result = (unsigned long) nextpc;
    776      1.1  christos 		break;
    777      1.1  christos 
    778      1.1  christos 	      case 0xc:	/*orr */
    779      1.1  christos 		result = operand1 | operand2;
    780      1.1  christos 		break;
    781      1.1  christos 
    782      1.1  christos 	      case 0xd:	/*mov */
    783      1.1  christos 		/* Always step into a function.  */
    784      1.1  christos 		result = operand2;
    785      1.1  christos 		break;
    786      1.1  christos 
    787      1.1  christos 	      case 0xe:	/*bic */
    788      1.1  christos 		result = operand1 & ~operand2;
    789      1.1  christos 		break;
    790      1.1  christos 
    791      1.1  christos 	      case 0xf:	/*mvn */
    792      1.1  christos 		result = ~operand2;
    793      1.1  christos 		break;
    794      1.1  christos 	      }
    795      1.1  christos 	      nextpc = self->ops->addr_bits_remove (self, result);
    796      1.1  christos 	    break;
    797      1.1  christos 	  }
    798      1.1  christos 
    799      1.1  christos 	case 0x4:
    800      1.1  christos 	case 0x5:		/* data transfer */
    801      1.1  christos 	case 0x6:
    802      1.1  christos 	case 0x7:
    803      1.1  christos 	  if (bits (this_instr, 25, 27) == 0x3 && bit (this_instr, 4) == 1)
    804      1.1  christos 	    {
    805      1.1  christos 	      /* Media instructions and architecturally undefined
    806      1.1  christos 		 instructions.  */
    807      1.1  christos 	      break;
    808      1.1  christos 	    }
    809      1.1  christos 
    810      1.1  christos 	  if (bit (this_instr, 20))
    811      1.1  christos 	    {
    812      1.1  christos 	      /* load */
    813      1.1  christos 	      if (bits (this_instr, 12, 15) == 15)
    814      1.1  christos 		{
    815      1.1  christos 		  /* rd == pc */
    816      1.1  christos 		  unsigned long rn;
    817      1.1  christos 		  unsigned long base;
    818      1.1  christos 
    819      1.1  christos 		  if (bit (this_instr, 22))
    820      1.1  christos 		    error (_("Invalid update to pc in instruction"));
    821      1.1  christos 
    822      1.1  christos 		  /* byte write to PC */
    823      1.1  christos 		  rn = bits (this_instr, 16, 19);
    824      1.1  christos 		  base = ((rn == ARM_PC_REGNUM)
    825      1.1  christos 			  ? (pc_val + 8)
    826      1.1  christos 			  : regcache_raw_get_unsigned (regcache, rn));
    827      1.1  christos 
    828      1.1  christos 		  if (bit (this_instr, 24))
    829      1.1  christos 		    {
    830      1.1  christos 		      /* pre-indexed */
    831      1.1  christos 		      int c = (status & FLAG_C) ? 1 : 0;
    832      1.1  christos 		      unsigned long offset =
    833      1.1  christos 		      (bit (this_instr, 25)
    834      1.1  christos 		       ? shifted_reg_val (regcache, this_instr, c,
    835      1.1  christos 					  pc_val, status)
    836      1.1  christos 		       : bits (this_instr, 0, 11));
    837      1.1  christos 
    838      1.1  christos 		      if (bit (this_instr, 23))
    839      1.1  christos 			base += offset;
    840      1.1  christos 		      else
    841      1.1  christos 			base -= offset;
    842      1.1  christos 		    }
    843      1.1  christos 		  nextpc
    844      1.1  christos 		    = (CORE_ADDR) self->ops->read_mem_uint ((CORE_ADDR) base,
    845      1.1  christos 							    4, byte_order);
    846      1.1  christos 		}
    847      1.1  christos 	    }
    848      1.1  christos 	  break;
    849      1.1  christos 
    850      1.1  christos 	case 0x8:
    851      1.1  christos 	case 0x9:		/* block transfer */
    852      1.1  christos 	  if (bit (this_instr, 20))
    853      1.1  christos 	    {
    854      1.1  christos 	      /* LDM */
    855      1.1  christos 	      if (bit (this_instr, 15))
    856      1.1  christos 		{
    857      1.1  christos 		  /* loading pc */
    858      1.1  christos 		  int offset = 0;
    859      1.1  christos 		  CORE_ADDR rn_val_offset = 0;
    860      1.1  christos 		  unsigned long rn_val
    861      1.1  christos 		    = regcache_raw_get_unsigned (regcache,
    862      1.1  christos 						 bits (this_instr, 16, 19));
    863      1.1  christos 
    864      1.1  christos 		  if (bit (this_instr, 23))
    865      1.1  christos 		    {
    866      1.1  christos 		      /* up */
    867      1.1  christos 		      unsigned long reglist = bits (this_instr, 0, 14);
    868  1.1.1.4  christos 		      offset = count_one_bits_l (reglist) * 4;
    869      1.1  christos 		      if (bit (this_instr, 24))		/* pre */
    870      1.1  christos 			offset += 4;
    871      1.1  christos 		    }
    872      1.1  christos 		  else if (bit (this_instr, 24))
    873      1.1  christos 		    offset = -4;
    874      1.1  christos 
    875      1.1  christos 		  rn_val_offset = rn_val + offset;
    876      1.1  christos 		  nextpc = (CORE_ADDR) self->ops->read_mem_uint (rn_val_offset,
    877      1.1  christos 								 4, byte_order);
    878      1.1  christos 		}
    879      1.1  christos 	    }
    880      1.1  christos 	  break;
    881      1.1  christos 
    882      1.1  christos 	case 0xb:		/* branch & link */
    883      1.1  christos 	case 0xa:		/* branch */
    884      1.1  christos 	  {
    885      1.1  christos 	    nextpc = BranchDest (pc, this_instr);
    886      1.1  christos 	    break;
    887      1.1  christos 	  }
    888      1.1  christos 
    889      1.1  christos 	case 0xc:
    890      1.1  christos 	case 0xd:
    891      1.1  christos 	case 0xe:		/* coproc ops */
    892      1.1  christos 	  break;
    893      1.1  christos 	case 0xf:		/* SWI */
    894      1.1  christos 	  {
    895      1.1  christos 	    nextpc = self->ops->syscall_next_pc (self);
    896      1.1  christos 	  }
    897      1.1  christos 	  break;
    898      1.1  christos 
    899      1.1  christos 	default:
    900      1.1  christos 	  error (_("Bad bit-field extraction"));
    901      1.1  christos 	  return next_pcs;
    902      1.1  christos 	}
    903      1.1  christos     }
    904      1.1  christos 
    905  1.1.1.3  christos   next_pcs.push_back (nextpc);
    906  1.1.1.3  christos 
    907      1.1  christos   return next_pcs;
    908      1.1  christos }
    909      1.1  christos 
    910      1.1  christos /* See arm-get-next-pcs.h.  */
    911      1.1  christos 
    912  1.1.1.3  christos std::vector<CORE_ADDR>
    913      1.1  christos arm_get_next_pcs (struct arm_get_next_pcs *self)
    914      1.1  christos {
    915  1.1.1.3  christos   std::vector<CORE_ADDR> next_pcs;
    916      1.1  christos 
    917      1.1  christos   if (self->ops->is_thumb (self))
    918      1.1  christos     {
    919      1.1  christos       next_pcs = thumb_deal_with_atomic_sequence_raw (self);
    920  1.1.1.3  christos       if (next_pcs.empty ())
    921      1.1  christos 	next_pcs = thumb_get_next_pcs_raw (self);
    922      1.1  christos     }
    923      1.1  christos   else
    924      1.1  christos     {
    925      1.1  christos       next_pcs = arm_deal_with_atomic_sequence_raw (self);
    926  1.1.1.3  christos       if (next_pcs.empty ())
    927      1.1  christos 	next_pcs = arm_get_next_pcs_raw (self);
    928      1.1  christos     }
    929      1.1  christos 
    930      1.1  christos   if (self->ops->fixup != NULL)
    931      1.1  christos     {
    932  1.1.1.3  christos       for (CORE_ADDR &pc_ref : next_pcs)
    933  1.1.1.3  christos 	pc_ref = self->ops->fixup (self, pc_ref);
    934      1.1  christos     }
    935  1.1.1.3  christos 
    936      1.1  christos   return next_pcs;
    937      1.1  christos }
    938