1 /* Common code for ARM software single stepping support.
3 Copyright (C) 1988-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "common-defs.h"
22 #include "common-regcache.h"
24 #include "arm-get-next-pcs.h"
26 /* See arm-get-next-pcs.h. */
29 arm_get_next_pcs_ctor (struct arm_get_next_pcs *self,
30 struct arm_get_next_pcs_ops *ops,
32 int byte_order_for_code,
33 const gdb_byte *arm_thumb2_breakpoint,
34 struct regcache *regcache)
37 self->byte_order = byte_order;
38 self->byte_order_for_code = byte_order_for_code;
39 self->arm_thumb2_breakpoint = arm_thumb2_breakpoint;
40 self->regcache = regcache;
43 /* Checks for an atomic sequence of instructions beginning with a LDREX{,B,H,D}
44 instruction and ending with a STREX{,B,H,D} instruction. If such a sequence
45 is found, attempt to step through it. The end of the sequence address is
46 added to the next_pcs list. */
48 static VEC (CORE_ADDR) *
49 thumb_deal_with_atomic_sequence_raw (struct arm_get_next_pcs *self,
52 int byte_order_for_code = self->byte_order_for_code;
53 CORE_ADDR breaks[2] = {-1, -1};
55 unsigned short insn1, insn2;
58 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
59 const int atomic_sequence_length = 16; /* Instruction sequence length. */
60 ULONGEST status, itstate;
61 VEC (CORE_ADDR) *next_pcs = NULL;
63 /* We currently do not support atomic sequences within an IT block. */
64 status = regcache_raw_get_unsigned (self->regcache, ARM_PS_REGNUM);
65 itstate = ((status >> 8) & 0xfc) | ((status >> 25) & 0x3);
69 /* Assume all atomic sequences start with a ldrex{,b,h,d} instruction. */
70 insn1 = self->ops->read_mem_uint (loc, 2, byte_order_for_code);
73 if (thumb_insn_size (insn1) != 4)
76 insn2 = self->ops->read_mem_uint (loc, 2, byte_order_for_code);
79 if (!((insn1 & 0xfff0) == 0xe850
80 || ((insn1 & 0xfff0) == 0xe8d0 && (insn2 & 0x00c0) == 0x0040)))
83 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
85 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
87 insn1 = self->ops->read_mem_uint (loc, 2,byte_order_for_code);
90 if (thumb_insn_size (insn1) != 4)
92 /* Assume that there is at most one conditional branch in the
93 atomic sequence. If a conditional branch is found, put a
94 breakpoint in its destination address. */
95 if ((insn1 & 0xf000) == 0xd000 && bits (insn1, 8, 11) != 0x0f)
97 if (last_breakpoint > 0)
98 return NULL; /* More than one conditional branch found,
99 fallback to the standard code. */
101 breaks[1] = loc + 2 + (sbits (insn1, 0, 7) << 1);
105 /* We do not support atomic sequences that use any *other*
106 instructions but conditional branches to change the PC.
107 Fall back to standard code to avoid losing control of
109 else if (thumb_instruction_changes_pc (insn1))
114 insn2 = self->ops->read_mem_uint (loc, 2, byte_order_for_code);
118 /* Assume that there is at most one conditional branch in the
119 atomic sequence. If a conditional branch is found, put a
120 breakpoint in its destination address. */
121 if ((insn1 & 0xf800) == 0xf000
122 && (insn2 & 0xd000) == 0x8000
123 && (insn1 & 0x0380) != 0x0380)
125 int sign, j1, j2, imm1, imm2;
128 sign = sbits (insn1, 10, 10);
129 imm1 = bits (insn1, 0, 5);
130 imm2 = bits (insn2, 0, 10);
131 j1 = bit (insn2, 13);
132 j2 = bit (insn2, 11);
134 offset = (sign << 20) + (j2 << 19) + (j1 << 18);
135 offset += (imm1 << 12) + (imm2 << 1);
137 if (last_breakpoint > 0)
138 return 0; /* More than one conditional branch found,
139 fallback to the standard code. */
141 breaks[1] = loc + offset;
145 /* We do not support atomic sequences that use any *other*
146 instructions but conditional branches to change the PC.
147 Fall back to standard code to avoid losing control of
149 else if (thumb2_instruction_changes_pc (insn1, insn2))
152 /* If we find a strex{,b,h,d}, we're done. */
153 if ((insn1 & 0xfff0) == 0xe840
154 || ((insn1 & 0xfff0) == 0xe8c0 && (insn2 & 0x00c0) == 0x0040))
159 /* If we didn't find the strex{,b,h,d}, we cannot handle the sequence. */
160 if (insn_count == atomic_sequence_length)
163 /* Insert a breakpoint right after the end of the atomic sequence. */
166 /* Check for duplicated breakpoints. Check also for a breakpoint
167 placed (branch instruction's destination) anywhere in sequence. */
169 && (breaks[1] == breaks[0]
170 || (breaks[1] >= pc && breaks[1] < loc)))
173 /* Adds the breakpoints to the list to be inserted. */
174 for (index = 0; index <= last_breakpoint; index++)
175 VEC_safe_push (CORE_ADDR, next_pcs, MAKE_THUMB_ADDR (breaks[index]));
180 /* Checks for an atomic sequence of instructions beginning with a LDREX{,B,H,D}
181 instruction and ending with a STREX{,B,H,D} instruction. If such a sequence
182 is found, attempt to step through it. The end of the sequence address is
183 added to the next_pcs list. */
185 static VEC (CORE_ADDR) *
186 arm_deal_with_atomic_sequence_raw (struct arm_get_next_pcs *self,
189 int byte_order_for_code = self->byte_order_for_code;
190 CORE_ADDR breaks[2] = {-1, -1};
195 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
196 const int atomic_sequence_length = 16; /* Instruction sequence length. */
197 VEC (CORE_ADDR) *next_pcs = NULL;
199 /* Assume all atomic sequences start with a ldrex{,b,h,d} instruction.
200 Note that we do not currently support conditionally executed atomic
202 insn = self->ops->read_mem_uint (loc, 4, byte_order_for_code);
205 if ((insn & 0xff9000f0) != 0xe1900090)
208 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
210 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
212 insn = self->ops->read_mem_uint (loc, 4, byte_order_for_code);
216 /* Assume that there is at most one conditional branch in the atomic
217 sequence. If a conditional branch is found, put a breakpoint in
218 its destination address. */
219 if (bits (insn, 24, 27) == 0xa)
221 if (last_breakpoint > 0)
222 return NULL; /* More than one conditional branch found, fallback
223 to the standard single-step code. */
225 breaks[1] = BranchDest (loc - 4, insn);
229 /* We do not support atomic sequences that use any *other* instructions
230 but conditional branches to change the PC. Fall back to standard
231 code to avoid losing control of execution. */
232 else if (arm_instruction_changes_pc (insn))
235 /* If we find a strex{,b,h,d}, we're done. */
236 if ((insn & 0xff9000f0) == 0xe1800090)
240 /* If we didn't find the strex{,b,h,d}, we cannot handle the sequence. */
241 if (insn_count == atomic_sequence_length)
244 /* Insert a breakpoint right after the end of the atomic sequence. */
247 /* Check for duplicated breakpoints. Check also for a breakpoint
248 placed (branch instruction's destination) anywhere in sequence. */
250 && (breaks[1] == breaks[0]
251 || (breaks[1] >= pc && breaks[1] < loc)))
254 /* Adds the breakpoints to the list to be inserted. */
255 for (index = 0; index <= last_breakpoint; index++)
256 VEC_safe_push (CORE_ADDR, next_pcs, breaks[index]);
261 /* See arm-get-next-pcs.h. */
264 arm_get_next_pcs (struct arm_get_next_pcs *self, CORE_ADDR pc)
266 VEC (CORE_ADDR) *next_pcs = NULL;
268 if (self->ops->is_thumb (self))
270 next_pcs = thumb_deal_with_atomic_sequence_raw (self, pc);
271 if (next_pcs == NULL)
272 next_pcs = thumb_get_next_pcs_raw (self, pc);
276 next_pcs = arm_deal_with_atomic_sequence_raw (self, pc);
277 if (next_pcs == NULL)
278 next_pcs = arm_get_next_pcs_raw (self, pc);
284 /* See arm-get-next-pcs.h. */
287 thumb_get_next_pcs_raw (struct arm_get_next_pcs *self,
290 int byte_order = self->byte_order;
291 int byte_order_for_code = self->byte_order_for_code;
292 unsigned long pc_val = ((unsigned long) pc) + 4; /* PC after prefetch */
293 unsigned short inst1;
294 CORE_ADDR nextpc = pc + 2; /* Default is next instruction. */
295 unsigned long offset;
296 ULONGEST status, itstate;
297 struct regcache *regcache = self->regcache;
298 VEC (CORE_ADDR) * next_pcs = NULL;
300 nextpc = MAKE_THUMB_ADDR (nextpc);
301 pc_val = MAKE_THUMB_ADDR (pc_val);
303 inst1 = self->ops->read_mem_uint (pc, 2, byte_order_for_code);
305 /* Thumb-2 conditional execution support. There are eight bits in
306 the CPSR which describe conditional execution state. Once
307 reconstructed (they're in a funny order), the low five bits
308 describe the low bit of the condition for each instruction and
309 how many instructions remain. The high three bits describe the
310 base condition. One of the low four bits will be set if an IT
311 block is active. These bits read as zero on earlier
313 status = regcache_raw_get_unsigned (regcache, ARM_PS_REGNUM);
314 itstate = ((status >> 8) & 0xfc) | ((status >> 25) & 0x3);
316 /* If-Then handling. On GNU/Linux, where this routine is used, we
317 use an undefined instruction as a breakpoint. Unlike BKPT, IT
318 can disable execution of the undefined instruction. So we might
319 miss the breakpoint if we set it on a skipped conditional
320 instruction. Because conditional instructions can change the
321 flags, affecting the execution of further instructions, we may
322 need to set two breakpoints. */
324 if (self->arm_thumb2_breakpoint != NULL)
326 if ((inst1 & 0xff00) == 0xbf00 && (inst1 & 0x000f) != 0)
328 /* An IT instruction. Because this instruction does not
329 modify the flags, we can accurately predict the next
330 executed instruction. */
331 itstate = inst1 & 0x00ff;
332 pc += thumb_insn_size (inst1);
334 while (itstate != 0 && ! condition_true (itstate >> 4, status))
336 inst1 = self->ops->read_mem_uint (pc, 2,byte_order_for_code);
337 pc += thumb_insn_size (inst1);
338 itstate = thumb_advance_itstate (itstate);
341 VEC_safe_push (CORE_ADDR, next_pcs, MAKE_THUMB_ADDR (pc));
344 else if (itstate != 0)
346 /* We are in a conditional block. Check the condition. */
347 if (! condition_true (itstate >> 4, status))
349 /* Advance to the next executed instruction. */
350 pc += thumb_insn_size (inst1);
351 itstate = thumb_advance_itstate (itstate);
353 while (itstate != 0 && ! condition_true (itstate >> 4, status))
355 inst1 = self->ops->read_mem_uint (pc, 2, byte_order_for_code);
357 pc += thumb_insn_size (inst1);
358 itstate = thumb_advance_itstate (itstate);
361 VEC_safe_push (CORE_ADDR, next_pcs, MAKE_THUMB_ADDR (pc));
364 else if ((itstate & 0x0f) == 0x08)
366 /* This is the last instruction of the conditional
367 block, and it is executed. We can handle it normally
368 because the following instruction is not conditional,
369 and we must handle it normally because it is
370 permitted to branch. Fall through. */
376 /* There are conditional instructions after this one.
377 If this instruction modifies the flags, then we can
378 not predict what the next executed instruction will
379 be. Fortunately, this instruction is architecturally
380 forbidden to branch; we know it will fall through.
381 Start by skipping past it. */
382 pc += thumb_insn_size (inst1);
383 itstate = thumb_advance_itstate (itstate);
385 /* Set a breakpoint on the following instruction. */
386 gdb_assert ((itstate & 0x0f) != 0);
387 VEC_safe_push (CORE_ADDR, next_pcs, MAKE_THUMB_ADDR (pc));
389 cond_negated = (itstate >> 4) & 1;
391 /* Skip all following instructions with the same
392 condition. If there is a later instruction in the IT
393 block with the opposite condition, set the other
394 breakpoint there. If not, then set a breakpoint on
395 the instruction after the IT block. */
398 inst1 = self->ops->read_mem_uint (pc, 2, byte_order_for_code);
399 pc += thumb_insn_size (inst1);
400 itstate = thumb_advance_itstate (itstate);
402 while (itstate != 0 && ((itstate >> 4) & 1) == cond_negated);
404 VEC_safe_push (CORE_ADDR, next_pcs, MAKE_THUMB_ADDR (pc));
410 else if (itstate & 0x0f)
412 /* We are in a conditional block. Check the condition. */
413 int cond = itstate >> 4;
415 if (! condition_true (cond, status))
417 /* Advance to the next instruction. All the 32-bit
418 instructions share a common prefix. */
419 VEC_safe_push (CORE_ADDR, next_pcs,
420 MAKE_THUMB_ADDR (pc + thumb_insn_size (inst1)));
425 /* Otherwise, handle the instruction normally. */
428 if ((inst1 & 0xff00) == 0xbd00) /* pop {rlist, pc} */
432 /* Fetch the saved PC from the stack. It's stored above
433 all of the other registers. */
434 offset = bitcount (bits (inst1, 0, 7)) * INT_REGISTER_SIZE;
435 sp = regcache_raw_get_unsigned (regcache, ARM_SP_REGNUM);
436 nextpc = self->ops->read_mem_uint (sp + offset, 4, byte_order);
438 else if ((inst1 & 0xf000) == 0xd000) /* conditional branch */
440 unsigned long cond = bits (inst1, 8, 11);
441 if (cond == 0x0f) /* 0x0f = SWI */
443 nextpc = self->ops->syscall_next_pc (self, pc);
445 else if (cond != 0x0f && condition_true (cond, status))
446 nextpc = pc_val + (sbits (inst1, 0, 7) << 1);
448 else if ((inst1 & 0xf800) == 0xe000) /* unconditional branch */
450 nextpc = pc_val + (sbits (inst1, 0, 10) << 1);
452 else if (thumb_insn_size (inst1) == 4) /* 32-bit instruction */
454 unsigned short inst2;
455 inst2 = self->ops->read_mem_uint (pc + 2, 2, byte_order_for_code);
457 /* Default to the next instruction. */
459 nextpc = MAKE_THUMB_ADDR (nextpc);
461 if ((inst1 & 0xf800) == 0xf000 && (inst2 & 0x8000) == 0x8000)
463 /* Branches and miscellaneous control instructions. */
465 if ((inst2 & 0x1000) != 0 || (inst2 & 0xd001) == 0xc000)
468 int j1, j2, imm1, imm2;
470 imm1 = sbits (inst1, 0, 10);
471 imm2 = bits (inst2, 0, 10);
472 j1 = bit (inst2, 13);
473 j2 = bit (inst2, 11);
475 offset = ((imm1 << 12) + (imm2 << 1));
476 offset ^= ((!j2) << 22) | ((!j1) << 23);
478 nextpc = pc_val + offset;
479 /* For BLX make sure to clear the low bits. */
480 if (bit (inst2, 12) == 0)
481 nextpc = nextpc & 0xfffffffc;
483 else if (inst1 == 0xf3de && (inst2 & 0xff00) == 0x3f00)
485 /* SUBS PC, LR, #imm8. */
486 nextpc = regcache_raw_get_unsigned (regcache, ARM_LR_REGNUM);
487 nextpc -= inst2 & 0x00ff;
489 else if ((inst2 & 0xd000) == 0x8000 && (inst1 & 0x0380) != 0x0380)
491 /* Conditional branch. */
492 if (condition_true (bits (inst1, 6, 9), status))
494 int sign, j1, j2, imm1, imm2;
496 sign = sbits (inst1, 10, 10);
497 imm1 = bits (inst1, 0, 5);
498 imm2 = bits (inst2, 0, 10);
499 j1 = bit (inst2, 13);
500 j2 = bit (inst2, 11);
502 offset = (sign << 20) + (j2 << 19) + (j1 << 18);
503 offset += (imm1 << 12) + (imm2 << 1);
505 nextpc = pc_val + offset;
509 else if ((inst1 & 0xfe50) == 0xe810)
511 /* Load multiple or RFE. */
512 int rn, offset, load_pc = 1;
514 rn = bits (inst1, 0, 3);
515 if (bit (inst1, 7) && !bit (inst1, 8))
518 if (!bit (inst2, 15))
520 offset = bitcount (inst2) * 4 - 4;
522 else if (!bit (inst1, 7) && bit (inst1, 8))
525 if (!bit (inst2, 15))
529 else if (bit (inst1, 7) && bit (inst1, 8))
534 else if (!bit (inst1, 7) && !bit (inst1, 8))
544 CORE_ADDR addr = regcache_raw_get_unsigned (regcache, rn);
545 nextpc = self->ops->read_mem_uint (addr + offset, 4, byte_order);
548 else if ((inst1 & 0xffef) == 0xea4f && (inst2 & 0xfff0) == 0x0f00)
550 /* MOV PC or MOVS PC. */
551 nextpc = regcache_raw_get_unsigned (regcache, bits (inst2, 0, 3));
552 nextpc = MAKE_THUMB_ADDR (nextpc);
554 else if ((inst1 & 0xff70) == 0xf850 && (inst2 & 0xf000) == 0xf000)
560 rn = bits (inst1, 0, 3);
561 base = regcache_raw_get_unsigned (regcache, rn);
562 if (rn == ARM_PC_REGNUM)
564 base = (base + 4) & ~(CORE_ADDR) 0x3;
566 base += bits (inst2, 0, 11);
568 base -= bits (inst2, 0, 11);
570 else if (bit (inst1, 7))
571 base += bits (inst2, 0, 11);
572 else if (bit (inst2, 11))
577 base += bits (inst2, 0, 7);
579 base -= bits (inst2, 0, 7);
582 else if ((inst2 & 0x0fc0) == 0x0000)
584 int shift = bits (inst2, 4, 5), rm = bits (inst2, 0, 3);
585 base += regcache_raw_get_unsigned (regcache, rm) << shift;
593 = self->ops->read_mem_uint (base, 4, byte_order);
595 else if ((inst1 & 0xfff0) == 0xe8d0 && (inst2 & 0xfff0) == 0xf000)
598 CORE_ADDR tbl_reg, table, offset, length;
600 tbl_reg = bits (inst1, 0, 3);
602 table = pc + 4; /* Regcache copy of PC isn't right yet. */
604 table = regcache_raw_get_unsigned (regcache, tbl_reg);
606 offset = regcache_raw_get_unsigned (regcache, bits (inst2, 0, 3));
607 length = 2 * self->ops->read_mem_uint (table + offset, 1, byte_order);
608 nextpc = pc_val + length;
610 else if ((inst1 & 0xfff0) == 0xe8d0 && (inst2 & 0xfff0) == 0xf010)
613 CORE_ADDR tbl_reg, table, offset, length;
615 tbl_reg = bits (inst1, 0, 3);
617 table = pc + 4; /* Regcache copy of PC isn't right yet. */
619 table = regcache_raw_get_unsigned (regcache, tbl_reg);
621 offset = 2 * regcache_raw_get_unsigned (regcache, bits (inst2, 0, 3));
622 length = 2 * self->ops->read_mem_uint (table + offset, 2, byte_order);
623 nextpc = pc_val + length;
626 else if ((inst1 & 0xff00) == 0x4700) /* bx REG, blx REG */
628 if (bits (inst1, 3, 6) == 0x0f)
629 nextpc = UNMAKE_THUMB_ADDR (pc_val);
631 nextpc = regcache_raw_get_unsigned (regcache, bits (inst1, 3, 6));
633 else if ((inst1 & 0xff87) == 0x4687) /* mov pc, REG */
635 if (bits (inst1, 3, 6) == 0x0f)
638 nextpc = regcache_raw_get_unsigned (regcache, bits (inst1, 3, 6));
640 nextpc = MAKE_THUMB_ADDR (nextpc);
642 else if ((inst1 & 0xf500) == 0xb100)
645 int imm = (bit (inst1, 9) << 6) + (bits (inst1, 3, 7) << 1);
646 ULONGEST reg = regcache_raw_get_unsigned (regcache, bits (inst1, 0, 2));
648 if (bit (inst1, 11) && reg != 0)
649 nextpc = pc_val + imm;
650 else if (!bit (inst1, 11) && reg == 0)
651 nextpc = pc_val + imm;
654 VEC_safe_push (CORE_ADDR, next_pcs, nextpc);
659 /* Get the raw next possible addresses. PC in next_pcs is the current program
660 counter, which is assumed to be executing in ARM mode.
662 The values returned have the execution state of the next instruction
663 encoded in it. Use IS_THUMB_ADDR () to see whether the instruction is
664 in Thumb-State, and gdbarch_addr_bits_remove () to get the plain memory
665 address in GDB and arm_addr_bits_remove in GDBServer. */
668 arm_get_next_pcs_raw (struct arm_get_next_pcs *self,
671 int byte_order = self->byte_order;
672 unsigned long pc_val;
673 unsigned long this_instr = 0;
674 unsigned long status;
676 struct regcache *regcache = self->regcache;
677 VEC (CORE_ADDR) *next_pcs = NULL;
679 pc_val = (unsigned long) pc;
680 this_instr = self->ops->read_mem_uint (pc, 4, byte_order);
682 status = regcache_raw_get_unsigned (regcache, ARM_PS_REGNUM);
683 nextpc = (CORE_ADDR) (pc_val + 4); /* Default case */
685 if (bits (this_instr, 28, 31) == INST_NV)
686 switch (bits (this_instr, 24, 27))
691 /* Branch with Link and change to Thumb. */
692 nextpc = BranchDest (pc, this_instr);
693 nextpc |= bit (this_instr, 24) << 1;
694 nextpc = MAKE_THUMB_ADDR (nextpc);
700 /* Coprocessor register transfer. */
701 if (bits (this_instr, 12, 15) == 15)
702 error (_("Invalid update to pc in instruction"));
705 else if (condition_true (bits (this_instr, 28, 31), status))
707 switch (bits (this_instr, 24, 27))
710 case 0x1: /* data processing */
714 unsigned long operand1, operand2, result = 0;
718 if (bits (this_instr, 12, 15) != 15)
721 if (bits (this_instr, 22, 25) == 0
722 && bits (this_instr, 4, 7) == 9) /* multiply */
723 error (_("Invalid update to pc in instruction"));
725 /* BX <reg>, BLX <reg> */
726 if (bits (this_instr, 4, 27) == 0x12fff1
727 || bits (this_instr, 4, 27) == 0x12fff3)
729 rn = bits (this_instr, 0, 3);
730 nextpc = ((rn == ARM_PC_REGNUM)
732 : regcache_raw_get_unsigned (regcache, rn));
734 VEC_safe_push (CORE_ADDR, next_pcs, nextpc);
738 /* Multiply into PC. */
739 c = (status & FLAG_C) ? 1 : 0;
740 rn = bits (this_instr, 16, 19);
741 operand1 = ((rn == ARM_PC_REGNUM)
743 : regcache_raw_get_unsigned (regcache, rn));
745 if (bit (this_instr, 25))
747 unsigned long immval = bits (this_instr, 0, 7);
748 unsigned long rotate = 2 * bits (this_instr, 8, 11);
749 operand2 = ((immval >> rotate) | (immval << (32 - rotate)))
752 else /* operand 2 is a shifted register. */
753 operand2 = shifted_reg_val (regcache, this_instr, c,
756 switch (bits (this_instr, 21, 24))
759 result = operand1 & operand2;
763 result = operand1 ^ operand2;
767 result = operand1 - operand2;
771 result = operand2 - operand1;
775 result = operand1 + operand2;
779 result = operand1 + operand2 + c;
783 result = operand1 - operand2 + c;
787 result = operand2 - operand1 + c;
793 case 0xb: /* tst, teq, cmp, cmn */
794 result = (unsigned long) nextpc;
798 result = operand1 | operand2;
802 /* Always step into a function. */
807 result = operand1 & ~operand2;
814 nextpc = self->ops->addr_bits_remove (self, result);
819 case 0x5: /* data transfer */
822 if (bits (this_instr, 25, 27) == 0x3 && bit (this_instr, 4) == 1)
824 /* Media instructions and architecturally undefined
829 if (bit (this_instr, 20))
832 if (bits (this_instr, 12, 15) == 15)
838 if (bit (this_instr, 22))
839 error (_("Invalid update to pc in instruction"));
841 /* byte write to PC */
842 rn = bits (this_instr, 16, 19);
843 base = ((rn == ARM_PC_REGNUM)
845 : regcache_raw_get_unsigned (regcache, rn));
847 if (bit (this_instr, 24))
850 int c = (status & FLAG_C) ? 1 : 0;
851 unsigned long offset =
852 (bit (this_instr, 25)
853 ? shifted_reg_val (regcache, this_instr, c,
855 : bits (this_instr, 0, 11));
857 if (bit (this_instr, 23))
863 = (CORE_ADDR) self->ops->read_mem_uint ((CORE_ADDR) base,
870 case 0x9: /* block transfer */
871 if (bit (this_instr, 20))
874 if (bit (this_instr, 15))
878 CORE_ADDR rn_val_offset = 0;
880 = regcache_raw_get_unsigned (regcache,
881 bits (this_instr, 16, 19));
883 if (bit (this_instr, 23))
886 unsigned long reglist = bits (this_instr, 0, 14);
887 offset = bitcount (reglist) * 4;
888 if (bit (this_instr, 24)) /* pre */
891 else if (bit (this_instr, 24))
894 rn_val_offset = rn_val + offset;
895 nextpc = (CORE_ADDR) self->ops->read_mem_uint (rn_val_offset,
901 case 0xb: /* branch & link */
902 case 0xa: /* branch */
904 nextpc = BranchDest (pc, this_instr);
910 case 0xe: /* coproc ops */
914 nextpc = self->ops->syscall_next_pc (self, pc);
919 error (_("Bad bit-field extraction\n"));
924 VEC_safe_push (CORE_ADDR, next_pcs, nextpc);