2 * This file is part of ltrace.
3 * Copyright (C) 2012 Petr Machata, Red Hat Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 /* Instruction masks used during single-stepping of atomic
22 * sequences. This was lifted from GDB. */
23 #define LWARX_MASK 0xfc0007fe
24 #define LWARX_INSTRUCTION 0x7c000028
25 #define LDARX_INSTRUCTION 0x7c0000A8
26 #define STWCX_MASK 0xfc0007ff
27 #define STWCX_INSTRUCTION 0x7c00012d
28 #define STDCX_INSTRUCTION 0x7c0001ad
29 #define BRANCH_MASK 0xfc000000
30 #define BC_MASK 0xfc000000
31 #define BC_INSN 0x40000000
32 #define B_INSN 0x48000000
34 static inline arch_addr_t
35 ppc_branch_dest(arch_addr_t addr, uint32_t insn)
37 int immediate = ((insn & 0xfffc) ^ 0x8000) - 0x8000;
38 int absolute = insn & 2;
40 /* XXX drop the following double casts. */
42 return (arch_addr_t)(uintptr_t)immediate;
44 return addr + (uintptr_t)immediate;