Commit | Line | Data |
---|---|---|
c877c8e6 | 1 | /* Target-dependent code for GDB, the GNU debugger. |
4e052eda | 2 | |
ecd75fc8 | 3 | Copyright (C) 1986-2014 Free Software Foundation, Inc. |
c877c8e6 KB |
4 | |
5 | This file is part of GDB. | |
6 | ||
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c877c8e6 KB |
10 | (at your option) any later version. |
11 | ||
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c877c8e6 KB |
19 | |
20 | #include "defs.h" | |
21 | #include "frame.h" | |
22 | #include "inferior.h" | |
23 | #include "symtab.h" | |
24 | #include "target.h" | |
25 | #include "gdbcore.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "symfile.h" | |
28 | #include "objfiles.h" | |
4e052eda | 29 | #include "regcache.h" |
fd0407d6 | 30 | #include "value.h" |
4be87837 | 31 | #include "osabi.h" |
f9be684a | 32 | #include "regset.h" |
6ded7999 | 33 | #include "solib-svr4.h" |
85e747d2 | 34 | #include "solib-spu.h" |
cc5f0d61 UW |
35 | #include "solib.h" |
36 | #include "solist.h" | |
9aa1e687 | 37 | #include "ppc-tdep.h" |
d78489bf | 38 | #include "ppc64-tdep.h" |
7284e1be | 39 | #include "ppc-linux-tdep.h" |
5d853008 | 40 | #include "glibc-tdep.h" |
61a65099 KB |
41 | #include "trad-frame.h" |
42 | #include "frame-unwind.h" | |
a8f60bfc | 43 | #include "tramp-frame.h" |
85e747d2 UW |
44 | #include "observer.h" |
45 | #include "auxv.h" | |
46 | #include "elf/common.h" | |
591a12a1 | 47 | #include "elf/ppc64.h" |
cc5f0d61 UW |
48 | #include "exceptions.h" |
49 | #include "arch-utils.h" | |
50 | #include "spu-tdep.h" | |
a96d9b2e | 51 | #include "xml-syscall.h" |
a5ee0f0c | 52 | #include "linux-tdep.h" |
9aa1e687 | 53 | |
55aa24fb SDJ |
54 | #include "stap-probe.h" |
55 | #include "ax.h" | |
56 | #include "ax-gdb.h" | |
57 | #include "cli/cli-utils.h" | |
58 | #include "parser-defs.h" | |
59 | #include "user-regs.h" | |
60 | #include <ctype.h> | |
b3ac9c77 | 61 | #include "elf-bfd.h" /* for elfcore_write_* */ |
55aa24fb | 62 | |
7284e1be UW |
63 | #include "features/rs6000/powerpc-32l.c" |
64 | #include "features/rs6000/powerpc-altivec32l.c" | |
f4d9bade | 65 | #include "features/rs6000/powerpc-cell32l.c" |
604c2f83 | 66 | #include "features/rs6000/powerpc-vsx32l.c" |
69abc51c TJB |
67 | #include "features/rs6000/powerpc-isa205-32l.c" |
68 | #include "features/rs6000/powerpc-isa205-altivec32l.c" | |
69 | #include "features/rs6000/powerpc-isa205-vsx32l.c" | |
7284e1be UW |
70 | #include "features/rs6000/powerpc-64l.c" |
71 | #include "features/rs6000/powerpc-altivec64l.c" | |
f4d9bade | 72 | #include "features/rs6000/powerpc-cell64l.c" |
604c2f83 | 73 | #include "features/rs6000/powerpc-vsx64l.c" |
69abc51c TJB |
74 | #include "features/rs6000/powerpc-isa205-64l.c" |
75 | #include "features/rs6000/powerpc-isa205-altivec64l.c" | |
76 | #include "features/rs6000/powerpc-isa205-vsx64l.c" | |
7284e1be UW |
77 | #include "features/rs6000/powerpc-e500l.c" |
78 | ||
5d853008 ME |
79 | /* Shared library operations for PowerPC-Linux. */ |
80 | static struct target_so_ops powerpc_so_ops; | |
81 | ||
a96d9b2e SDJ |
82 | /* The syscall's XML filename for PPC and PPC64. */ |
83 | #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml" | |
84 | #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml" | |
c877c8e6 | 85 | |
122a33de KB |
86 | /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint |
87 | in much the same fashion as memory_remove_breakpoint in mem-break.c, | |
88 | but is careful not to write back the previous contents if the code | |
89 | in question has changed in between inserting the breakpoint and | |
90 | removing it. | |
91 | ||
92 | Here is the problem that we're trying to solve... | |
93 | ||
94 | Once upon a time, before introducing this function to remove | |
95 | breakpoints from the inferior, setting a breakpoint on a shared | |
96 | library function prior to running the program would not work | |
97 | properly. In order to understand the problem, it is first | |
98 | necessary to understand a little bit about dynamic linking on | |
99 | this platform. | |
100 | ||
101 | A call to a shared library function is accomplished via a bl | |
102 | (branch-and-link) instruction whose branch target is an entry | |
103 | in the procedure linkage table (PLT). The PLT in the object | |
104 | file is uninitialized. To gdb, prior to running the program, the | |
105 | entries in the PLT are all zeros. | |
106 | ||
107 | Once the program starts running, the shared libraries are loaded | |
108 | and the procedure linkage table is initialized, but the entries in | |
109 | the table are not (necessarily) resolved. Once a function is | |
110 | actually called, the code in the PLT is hit and the function is | |
111 | resolved. In order to better illustrate this, an example is in | |
112 | order; the following example is from the gdb testsuite. | |
113 | ||
114 | We start the program shmain. | |
115 | ||
116 | [kev@arroyo testsuite]$ ../gdb gdb.base/shmain | |
117 | [...] | |
118 | ||
119 | We place two breakpoints, one on shr1 and the other on main. | |
120 | ||
121 | (gdb) b shr1 | |
122 | Breakpoint 1 at 0x100409d4 | |
123 | (gdb) b main | |
124 | Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44. | |
125 | ||
126 | Examine the instruction (and the immediatly following instruction) | |
127 | upon which the breakpoint was placed. Note that the PLT entry | |
128 | for shr1 contains zeros. | |
129 | ||
130 | (gdb) x/2i 0x100409d4 | |
131 | 0x100409d4 <shr1>: .long 0x0 | |
132 | 0x100409d8 <shr1+4>: .long 0x0 | |
133 | ||
134 | Now run 'til main. | |
135 | ||
136 | (gdb) r | |
137 | Starting program: gdb.base/shmain | |
138 | Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19. | |
139 | ||
140 | Breakpoint 2, main () | |
141 | at gdb.base/shmain.c:44 | |
142 | 44 g = 1; | |
143 | ||
144 | Examine the PLT again. Note that the loading of the shared | |
145 | library has initialized the PLT to code which loads a constant | |
146 | (which I think is an index into the GOT) into r11 and then | |
147 | branchs a short distance to the code which actually does the | |
148 | resolving. | |
149 | ||
150 | (gdb) x/2i 0x100409d4 | |
151 | 0x100409d4 <shr1>: li r11,4 | |
152 | 0x100409d8 <shr1+4>: b 0x10040984 <sg+4> | |
153 | (gdb) c | |
154 | Continuing. | |
155 | ||
156 | Breakpoint 1, shr1 (x=1) | |
157 | at gdb.base/shr1.c:19 | |
158 | 19 l = 1; | |
159 | ||
160 | Now we've hit the breakpoint at shr1. (The breakpoint was | |
161 | reset from the PLT entry to the actual shr1 function after the | |
162 | shared library was loaded.) Note that the PLT entry has been | |
0df8b418 | 163 | resolved to contain a branch that takes us directly to shr1. |
122a33de KB |
164 | (The real one, not the PLT entry.) |
165 | ||
166 | (gdb) x/2i 0x100409d4 | |
167 | 0x100409d4 <shr1>: b 0xffaf76c <shr1> | |
168 | 0x100409d8 <shr1+4>: b 0x10040984 <sg+4> | |
169 | ||
170 | The thing to note here is that the PLT entry for shr1 has been | |
171 | changed twice. | |
172 | ||
173 | Now the problem should be obvious. GDB places a breakpoint (a | |
0df8b418 | 174 | trap instruction) on the zero value of the PLT entry for shr1. |
122a33de KB |
175 | Later on, after the shared library had been loaded and the PLT |
176 | initialized, GDB gets a signal indicating this fact and attempts | |
177 | (as it always does when it stops) to remove all the breakpoints. | |
178 | ||
179 | The breakpoint removal was causing the former contents (a zero | |
180 | word) to be written back to the now initialized PLT entry thus | |
181 | destroying a portion of the initialization that had occurred only a | |
182 | short time ago. When execution continued, the zero word would be | |
766062f6 | 183 | executed as an instruction an illegal instruction trap was |
122a33de KB |
184 | generated instead. (0 is not a legal instruction.) |
185 | ||
186 | The fix for this problem was fairly straightforward. The function | |
187 | memory_remove_breakpoint from mem-break.c was copied to this file, | |
188 | modified slightly, and renamed to ppc_linux_memory_remove_breakpoint. | |
189 | In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new | |
190 | function. | |
191 | ||
192 | The differences between ppc_linux_memory_remove_breakpoint () and | |
193 | memory_remove_breakpoint () are minor. All that the former does | |
194 | that the latter does not is check to make sure that the breakpoint | |
195 | location actually contains a breakpoint (trap instruction) prior | |
196 | to attempting to write back the old contents. If it does contain | |
0df8b418 | 197 | a trap instruction, we allow the old contents to be written back. |
122a33de KB |
198 | Otherwise, we silently do nothing. |
199 | ||
200 | The big question is whether memory_remove_breakpoint () should be | |
201 | changed to have the same functionality. The downside is that more | |
202 | traffic is generated for remote targets since we'll have an extra | |
203 | fetch of a memory word each time a breakpoint is removed. | |
204 | ||
205 | For the time being, we'll leave this self-modifying-code-friendly | |
206 | version in ppc-linux-tdep.c, but it ought to be migrated somewhere | |
207 | else in the event that some other platform has similar needs with | |
208 | regard to removing breakpoints in some potentially self modifying | |
209 | code. */ | |
63807e1d | 210 | static int |
ae4b2284 MD |
211 | ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch, |
212 | struct bp_target_info *bp_tgt) | |
482ca3f5 | 213 | { |
8181d85f | 214 | CORE_ADDR addr = bp_tgt->placed_address; |
f4f9705a | 215 | const unsigned char *bp; |
482ca3f5 KB |
216 | int val; |
217 | int bplen; | |
50fd1280 | 218 | gdb_byte old_contents[BREAKPOINT_MAX]; |
8defab1a | 219 | struct cleanup *cleanup; |
482ca3f5 KB |
220 | |
221 | /* Determine appropriate breakpoint contents and size for this address. */ | |
ae4b2284 | 222 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen); |
482ca3f5 | 223 | if (bp == NULL) |
8a3fe4f8 | 224 | error (_("Software breakpoints not implemented for this target.")); |
482ca3f5 | 225 | |
8defab1a DJ |
226 | /* Make sure we see the memory breakpoints. */ |
227 | cleanup = make_show_memory_breakpoints_cleanup (1); | |
482ca3f5 KB |
228 | val = target_read_memory (addr, old_contents, bplen); |
229 | ||
230 | /* If our breakpoint is no longer at the address, this means that the | |
231 | program modified the code on us, so it is wrong to put back the | |
0df8b418 | 232 | old value. */ |
482ca3f5 | 233 | if (val == 0 && memcmp (bp, old_contents, bplen) == 0) |
dd110abf | 234 | val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen); |
482ca3f5 | 235 | |
8defab1a | 236 | do_cleanups (cleanup); |
482ca3f5 KB |
237 | return val; |
238 | } | |
6ded7999 | 239 | |
b9ff3018 AC |
240 | /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather |
241 | than the 32 bit SYSV R4 ABI structure return convention - all | |
242 | structures, no matter their size, are put in memory. Vectors, | |
243 | which were added later, do get returned in a register though. */ | |
244 | ||
05580c65 | 245 | static enum return_value_convention |
6a3a010b | 246 | ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 CV |
247 | struct type *valtype, struct regcache *regcache, |
248 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
b9ff3018 | 249 | { |
05580c65 AC |
250 | if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT |
251 | || TYPE_CODE (valtype) == TYPE_CODE_UNION) | |
252 | && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) | |
253 | && TYPE_VECTOR (valtype))) | |
254 | return RETURN_VALUE_STRUCT_CONVENTION; | |
255 | else | |
6a3a010b | 256 | return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache, |
c055b101 | 257 | readbuf, writebuf); |
b9ff3018 AC |
258 | } |
259 | ||
6207416c | 260 | static struct core_regset_section ppc_linux_vsx_regset_sections[] = |
17ea7499 | 261 | { |
2f2241f1 | 262 | { ".reg", 48 * 4, "general-purpose" }, |
1b1818e4 UW |
263 | { ".reg2", 264, "floating-point" }, |
264 | { ".reg-ppc-vmx", 544, "ppc Altivec" }, | |
265 | { ".reg-ppc-vsx", 256, "POWER7 VSX" }, | |
17ea7499 CES |
266 | { NULL, 0} |
267 | }; | |
268 | ||
6207416c LM |
269 | static struct core_regset_section ppc_linux_vmx_regset_sections[] = |
270 | { | |
2f2241f1 | 271 | { ".reg", 48 * 4, "general-purpose" }, |
1b1818e4 UW |
272 | { ".reg2", 264, "floating-point" }, |
273 | { ".reg-ppc-vmx", 544, "ppc Altivec" }, | |
6207416c LM |
274 | { NULL, 0} |
275 | }; | |
276 | ||
277 | static struct core_regset_section ppc_linux_fp_regset_sections[] = | |
278 | { | |
2f2241f1 UW |
279 | { ".reg", 48 * 4, "general-purpose" }, |
280 | { ".reg2", 264, "floating-point" }, | |
281 | { NULL, 0} | |
282 | }; | |
283 | ||
284 | static struct core_regset_section ppc64_linux_vsx_regset_sections[] = | |
285 | { | |
286 | { ".reg", 48 * 8, "general-purpose" }, | |
287 | { ".reg2", 264, "floating-point" }, | |
288 | { ".reg-ppc-vmx", 544, "ppc Altivec" }, | |
289 | { ".reg-ppc-vsx", 256, "POWER7 VSX" }, | |
290 | { NULL, 0} | |
291 | }; | |
292 | ||
293 | static struct core_regset_section ppc64_linux_vmx_regset_sections[] = | |
294 | { | |
295 | { ".reg", 48 * 8, "general-purpose" }, | |
296 | { ".reg2", 264, "floating-point" }, | |
297 | { ".reg-ppc-vmx", 544, "ppc Altivec" }, | |
298 | { NULL, 0} | |
299 | }; | |
300 | ||
301 | static struct core_regset_section ppc64_linux_fp_regset_sections[] = | |
302 | { | |
303 | { ".reg", 48 * 8, "general-purpose" }, | |
1b1818e4 | 304 | { ".reg2", 264, "floating-point" }, |
6207416c LM |
305 | { NULL, 0} |
306 | }; | |
307 | ||
5d853008 | 308 | /* PLT stub in executable. */ |
d78489bf | 309 | static struct ppc_insn_pattern powerpc32_plt_stub[] = |
5d853008 ME |
310 | { |
311 | { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */ | |
312 | { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ | |
313 | { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | |
314 | { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | |
315 | { 0, 0, 0 } | |
316 | }; | |
317 | ||
318 | /* PLT stub in shared library. */ | |
d78489bf | 319 | static struct ppc_insn_pattern powerpc32_plt_stub_so[] = |
5d853008 ME |
320 | { |
321 | { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */ | |
322 | { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | |
323 | { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | |
324 | { 0xffffffff, 0x60000000, 0 }, /* nop */ | |
325 | { 0, 0, 0 } | |
326 | }; | |
327 | #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub) | |
328 | ||
329 | /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt | |
330 | section. For secure PLT, stub is in .text and we need to check | |
331 | instruction patterns. */ | |
332 | ||
333 | static int | |
334 | powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc) | |
335 | { | |
7cbd4a93 | 336 | struct bound_minimal_symbol sym; |
5d853008 ME |
337 | |
338 | /* Check whether PC is in the dynamic linker. This also checks | |
339 | whether it is in the .plt section, used by non-PIC executables. */ | |
340 | if (svr4_in_dynsym_resolve_code (pc)) | |
341 | return 1; | |
342 | ||
343 | /* Check if we are in the resolver. */ | |
344 | sym = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 | 345 | if (sym.minsym != NULL |
efd66ac6 TT |
346 | && (strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0 |
347 | || strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), | |
7cbd4a93 | 348 | "__glink_PLTresolve") == 0)) |
5d853008 ME |
349 | return 1; |
350 | ||
351 | return 0; | |
352 | } | |
353 | ||
354 | /* Follow PLT stub to actual routine. */ | |
355 | ||
356 | static CORE_ADDR | |
357 | ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
358 | { | |
463920bf | 359 | unsigned int insnbuf[POWERPC32_PLT_STUB_LEN]; |
5d853008 ME |
360 | struct gdbarch *gdbarch = get_frame_arch (frame); |
361 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
362 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
363 | CORE_ADDR target = 0; | |
364 | ||
845d4708 | 365 | if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf)) |
5d853008 ME |
366 | { |
367 | /* Insn pattern is | |
368 | lis r11, xxxx | |
369 | lwz r11, xxxx(r11) | |
370 | Branch target is in r11. */ | |
371 | ||
d78489bf AT |
372 | target = (ppc_insn_d_field (insnbuf[0]) << 16) |
373 | | ppc_insn_d_field (insnbuf[1]); | |
5d853008 ME |
374 | target = read_memory_unsigned_integer (target, 4, byte_order); |
375 | } | |
376 | ||
845d4708 | 377 | if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf)) |
5d853008 ME |
378 | { |
379 | /* Insn pattern is | |
380 | lwz r11, xxxx(r30) | |
381 | Branch target is in r11. */ | |
382 | ||
383 | target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30) | |
d78489bf | 384 | + ppc_insn_d_field (insnbuf[0]); |
5d853008 ME |
385 | target = read_memory_unsigned_integer (target, 4, byte_order); |
386 | } | |
387 | ||
388 | return target; | |
389 | } | |
f470a70a | 390 | |
7284e1be UW |
391 | /* Wrappers to handle Linux-only registers. */ |
392 | ||
393 | static void | |
394 | ppc_linux_supply_gregset (const struct regset *regset, | |
395 | struct regcache *regcache, | |
396 | int regnum, const void *gregs, size_t len) | |
397 | { | |
7fefa8d7 | 398 | const struct ppc_reg_offsets *offsets = regset->regmap; |
7284e1be UW |
399 | |
400 | ppc_supply_gregset (regset, regcache, regnum, gregs, len); | |
401 | ||
402 | if (ppc_linux_trap_reg_p (get_regcache_arch (regcache))) | |
403 | { | |
404 | /* "orig_r3" is stored 2 slots after "pc". */ | |
405 | if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM) | |
406 | ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, gregs, | |
407 | offsets->pc_offset + 2 * offsets->gpr_size, | |
408 | offsets->gpr_size); | |
409 | ||
410 | /* "trap" is stored 8 slots after "pc". */ | |
411 | if (regnum == -1 || regnum == PPC_TRAP_REGNUM) | |
412 | ppc_supply_reg (regcache, PPC_TRAP_REGNUM, gregs, | |
413 | offsets->pc_offset + 8 * offsets->gpr_size, | |
414 | offsets->gpr_size); | |
415 | } | |
416 | } | |
f2db237a | 417 | |
f9be684a | 418 | static void |
f2db237a AM |
419 | ppc_linux_collect_gregset (const struct regset *regset, |
420 | const struct regcache *regcache, | |
421 | int regnum, void *gregs, size_t len) | |
f9be684a | 422 | { |
7fefa8d7 | 423 | const struct ppc_reg_offsets *offsets = regset->regmap; |
7284e1be UW |
424 | |
425 | /* Clear areas in the linux gregset not written elsewhere. */ | |
f2db237a AM |
426 | if (regnum == -1) |
427 | memset (gregs, 0, len); | |
7284e1be | 428 | |
f2db237a | 429 | ppc_collect_gregset (regset, regcache, regnum, gregs, len); |
7284e1be UW |
430 | |
431 | if (ppc_linux_trap_reg_p (get_regcache_arch (regcache))) | |
432 | { | |
433 | /* "orig_r3" is stored 2 slots after "pc". */ | |
434 | if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM) | |
435 | ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, gregs, | |
436 | offsets->pc_offset + 2 * offsets->gpr_size, | |
437 | offsets->gpr_size); | |
438 | ||
439 | /* "trap" is stored 8 slots after "pc". */ | |
440 | if (regnum == -1 || regnum == PPC_TRAP_REGNUM) | |
441 | ppc_collect_reg (regcache, PPC_TRAP_REGNUM, gregs, | |
442 | offsets->pc_offset + 8 * offsets->gpr_size, | |
443 | offsets->gpr_size); | |
444 | } | |
f9be684a AC |
445 | } |
446 | ||
f2db237a AM |
447 | /* Regset descriptions. */ |
448 | static const struct ppc_reg_offsets ppc32_linux_reg_offsets = | |
449 | { | |
450 | /* General-purpose registers. */ | |
451 | /* .r0_offset = */ 0, | |
452 | /* .gpr_size = */ 4, | |
453 | /* .xr_size = */ 4, | |
454 | /* .pc_offset = */ 128, | |
455 | /* .ps_offset = */ 132, | |
456 | /* .cr_offset = */ 152, | |
457 | /* .lr_offset = */ 144, | |
458 | /* .ctr_offset = */ 140, | |
459 | /* .xer_offset = */ 148, | |
460 | /* .mq_offset = */ 156, | |
461 | ||
462 | /* Floating-point registers. */ | |
463 | /* .f0_offset = */ 0, | |
464 | /* .fpscr_offset = */ 256, | |
465 | /* .fpscr_size = */ 8, | |
466 | ||
467 | /* AltiVec registers. */ | |
468 | /* .vr0_offset = */ 0, | |
06caf7d2 CES |
469 | /* .vscr_offset = */ 512 + 12, |
470 | /* .vrsave_offset = */ 528 | |
f2db237a | 471 | }; |
f9be684a | 472 | |
f2db237a AM |
473 | static const struct ppc_reg_offsets ppc64_linux_reg_offsets = |
474 | { | |
475 | /* General-purpose registers. */ | |
476 | /* .r0_offset = */ 0, | |
477 | /* .gpr_size = */ 8, | |
478 | /* .xr_size = */ 8, | |
479 | /* .pc_offset = */ 256, | |
480 | /* .ps_offset = */ 264, | |
481 | /* .cr_offset = */ 304, | |
482 | /* .lr_offset = */ 288, | |
483 | /* .ctr_offset = */ 280, | |
484 | /* .xer_offset = */ 296, | |
485 | /* .mq_offset = */ 312, | |
486 | ||
487 | /* Floating-point registers. */ | |
488 | /* .f0_offset = */ 0, | |
489 | /* .fpscr_offset = */ 256, | |
490 | /* .fpscr_size = */ 8, | |
491 | ||
492 | /* AltiVec registers. */ | |
493 | /* .vr0_offset = */ 0, | |
06caf7d2 CES |
494 | /* .vscr_offset = */ 512 + 12, |
495 | /* .vrsave_offset = */ 528 | |
f2db237a | 496 | }; |
2fda4977 | 497 | |
f2db237a AM |
498 | static const struct regset ppc32_linux_gregset = { |
499 | &ppc32_linux_reg_offsets, | |
7284e1be | 500 | ppc_linux_supply_gregset, |
09424cff | 501 | ppc_linux_collect_gregset |
f9be684a AC |
502 | }; |
503 | ||
f2db237a AM |
504 | static const struct regset ppc64_linux_gregset = { |
505 | &ppc64_linux_reg_offsets, | |
7284e1be | 506 | ppc_linux_supply_gregset, |
09424cff | 507 | ppc_linux_collect_gregset |
f2db237a | 508 | }; |
f9be684a | 509 | |
f2db237a AM |
510 | static const struct regset ppc32_linux_fpregset = { |
511 | &ppc32_linux_reg_offsets, | |
512 | ppc_supply_fpregset, | |
09424cff | 513 | ppc_collect_fpregset |
f9be684a AC |
514 | }; |
515 | ||
06caf7d2 CES |
516 | static const struct regset ppc32_linux_vrregset = { |
517 | &ppc32_linux_reg_offsets, | |
518 | ppc_supply_vrregset, | |
09424cff | 519 | ppc_collect_vrregset |
06caf7d2 CES |
520 | }; |
521 | ||
604c2f83 LM |
522 | static const struct regset ppc32_linux_vsxregset = { |
523 | &ppc32_linux_reg_offsets, | |
524 | ppc_supply_vsxregset, | |
09424cff | 525 | ppc_collect_vsxregset |
604c2f83 LM |
526 | }; |
527 | ||
f2db237a AM |
528 | const struct regset * |
529 | ppc_linux_gregset (int wordsize) | |
2fda4977 | 530 | { |
f2db237a | 531 | return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset; |
2fda4977 DJ |
532 | } |
533 | ||
f2db237a AM |
534 | const struct regset * |
535 | ppc_linux_fpregset (void) | |
536 | { | |
537 | return &ppc32_linux_fpregset; | |
538 | } | |
2fda4977 | 539 | |
f9be684a AC |
540 | static const struct regset * |
541 | ppc_linux_regset_from_core_section (struct gdbarch *core_arch, | |
542 | const char *sect_name, size_t sect_size) | |
2fda4977 | 543 | { |
f9be684a AC |
544 | struct gdbarch_tdep *tdep = gdbarch_tdep (core_arch); |
545 | if (strcmp (sect_name, ".reg") == 0) | |
2fda4977 | 546 | { |
f9be684a AC |
547 | if (tdep->wordsize == 4) |
548 | return &ppc32_linux_gregset; | |
2fda4977 | 549 | else |
f9be684a | 550 | return &ppc64_linux_gregset; |
2fda4977 | 551 | } |
f9be684a | 552 | if (strcmp (sect_name, ".reg2") == 0) |
f2db237a | 553 | return &ppc32_linux_fpregset; |
06caf7d2 CES |
554 | if (strcmp (sect_name, ".reg-ppc-vmx") == 0) |
555 | return &ppc32_linux_vrregset; | |
604c2f83 LM |
556 | if (strcmp (sect_name, ".reg-ppc-vsx") == 0) |
557 | return &ppc32_linux_vsxregset; | |
f9be684a | 558 | return NULL; |
2fda4977 DJ |
559 | } |
560 | ||
a8f60bfc | 561 | static void |
5366653e | 562 | ppc_linux_sigtramp_cache (struct frame_info *this_frame, |
a8f60bfc AC |
563 | struct trad_frame_cache *this_cache, |
564 | CORE_ADDR func, LONGEST offset, | |
565 | int bias) | |
566 | { | |
567 | CORE_ADDR base; | |
568 | CORE_ADDR regs; | |
569 | CORE_ADDR gpregs; | |
570 | CORE_ADDR fpregs; | |
571 | int i; | |
5366653e | 572 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
a8f60bfc | 573 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 574 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
a8f60bfc | 575 | |
5366653e DJ |
576 | base = get_frame_register_unsigned (this_frame, |
577 | gdbarch_sp_regnum (gdbarch)); | |
578 | if (bias > 0 && get_frame_pc (this_frame) != func) | |
a8f60bfc AC |
579 | /* See below, some signal trampolines increment the stack as their |
580 | first instruction, need to compensate for that. */ | |
581 | base -= bias; | |
582 | ||
583 | /* Find the address of the register buffer pointer. */ | |
584 | regs = base + offset; | |
585 | /* Use that to find the address of the corresponding register | |
586 | buffers. */ | |
e17a4113 | 587 | gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order); |
a8f60bfc AC |
588 | fpregs = gpregs + 48 * tdep->wordsize; |
589 | ||
590 | /* General purpose. */ | |
591 | for (i = 0; i < 32; i++) | |
592 | { | |
593 | int regnum = i + tdep->ppc_gp0_regnum; | |
0df8b418 MS |
594 | trad_frame_set_reg_addr (this_cache, |
595 | regnum, gpregs + i * tdep->wordsize); | |
a8f60bfc | 596 | } |
3e8c568d | 597 | trad_frame_set_reg_addr (this_cache, |
40a6adc1 | 598 | gdbarch_pc_regnum (gdbarch), |
3e8c568d | 599 | gpregs + 32 * tdep->wordsize); |
a8f60bfc AC |
600 | trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, |
601 | gpregs + 35 * tdep->wordsize); | |
602 | trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, | |
603 | gpregs + 36 * tdep->wordsize); | |
604 | trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, | |
605 | gpregs + 37 * tdep->wordsize); | |
606 | trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, | |
607 | gpregs + 38 * tdep->wordsize); | |
608 | ||
7284e1be UW |
609 | if (ppc_linux_trap_reg_p (gdbarch)) |
610 | { | |
611 | trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM, | |
612 | gpregs + 34 * tdep->wordsize); | |
613 | trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM, | |
614 | gpregs + 40 * tdep->wordsize); | |
615 | } | |
616 | ||
60f140f9 PG |
617 | if (ppc_floating_point_unit_p (gdbarch)) |
618 | { | |
619 | /* Floating point registers. */ | |
620 | for (i = 0; i < 32; i++) | |
621 | { | |
40a6adc1 | 622 | int regnum = i + gdbarch_fp0_regnum (gdbarch); |
60f140f9 PG |
623 | trad_frame_set_reg_addr (this_cache, regnum, |
624 | fpregs + i * tdep->wordsize); | |
625 | } | |
626 | trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum, | |
4019046a | 627 | fpregs + 32 * tdep->wordsize); |
60f140f9 | 628 | } |
a8f60bfc AC |
629 | trad_frame_set_id (this_cache, frame_id_build (base, func)); |
630 | } | |
631 | ||
632 | static void | |
633 | ppc32_linux_sigaction_cache_init (const struct tramp_frame *self, | |
5366653e | 634 | struct frame_info *this_frame, |
a8f60bfc AC |
635 | struct trad_frame_cache *this_cache, |
636 | CORE_ADDR func) | |
637 | { | |
5366653e | 638 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
639 | 0xd0 /* Offset to ucontext_t. */ |
640 | + 0x30 /* Offset to .reg. */, | |
641 | 0); | |
642 | } | |
643 | ||
644 | static void | |
645 | ppc64_linux_sigaction_cache_init (const struct tramp_frame *self, | |
5366653e | 646 | struct frame_info *this_frame, |
a8f60bfc AC |
647 | struct trad_frame_cache *this_cache, |
648 | CORE_ADDR func) | |
649 | { | |
5366653e | 650 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
651 | 0x80 /* Offset to ucontext_t. */ |
652 | + 0xe0 /* Offset to .reg. */, | |
653 | 128); | |
654 | } | |
655 | ||
656 | static void | |
657 | ppc32_linux_sighandler_cache_init (const struct tramp_frame *self, | |
5366653e | 658 | struct frame_info *this_frame, |
a8f60bfc AC |
659 | struct trad_frame_cache *this_cache, |
660 | CORE_ADDR func) | |
661 | { | |
5366653e | 662 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
663 | 0x40 /* Offset to ucontext_t. */ |
664 | + 0x1c /* Offset to .reg. */, | |
665 | 0); | |
666 | } | |
667 | ||
668 | static void | |
669 | ppc64_linux_sighandler_cache_init (const struct tramp_frame *self, | |
5366653e | 670 | struct frame_info *this_frame, |
a8f60bfc AC |
671 | struct trad_frame_cache *this_cache, |
672 | CORE_ADDR func) | |
673 | { | |
5366653e | 674 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
675 | 0x80 /* Offset to struct sigcontext. */ |
676 | + 0x38 /* Offset to .reg. */, | |
677 | 128); | |
678 | } | |
679 | ||
680 | static struct tramp_frame ppc32_linux_sigaction_tramp_frame = { | |
681 | SIGTRAMP_FRAME, | |
682 | 4, | |
683 | { | |
684 | { 0x380000ac, -1 }, /* li r0, 172 */ | |
685 | { 0x44000002, -1 }, /* sc */ | |
686 | { TRAMP_SENTINEL_INSN }, | |
687 | }, | |
688 | ppc32_linux_sigaction_cache_init | |
689 | }; | |
690 | static struct tramp_frame ppc64_linux_sigaction_tramp_frame = { | |
691 | SIGTRAMP_FRAME, | |
692 | 4, | |
693 | { | |
694 | { 0x38210080, -1 }, /* addi r1,r1,128 */ | |
695 | { 0x380000ac, -1 }, /* li r0, 172 */ | |
696 | { 0x44000002, -1 }, /* sc */ | |
697 | { TRAMP_SENTINEL_INSN }, | |
698 | }, | |
699 | ppc64_linux_sigaction_cache_init | |
700 | }; | |
701 | static struct tramp_frame ppc32_linux_sighandler_tramp_frame = { | |
702 | SIGTRAMP_FRAME, | |
703 | 4, | |
704 | { | |
705 | { 0x38000077, -1 }, /* li r0,119 */ | |
706 | { 0x44000002, -1 }, /* sc */ | |
707 | { TRAMP_SENTINEL_INSN }, | |
708 | }, | |
709 | ppc32_linux_sighandler_cache_init | |
710 | }; | |
711 | static struct tramp_frame ppc64_linux_sighandler_tramp_frame = { | |
712 | SIGTRAMP_FRAME, | |
713 | 4, | |
714 | { | |
715 | { 0x38210080, -1 }, /* addi r1,r1,128 */ | |
716 | { 0x38000077, -1 }, /* li r0,119 */ | |
717 | { 0x44000002, -1 }, /* sc */ | |
718 | { TRAMP_SENTINEL_INSN }, | |
719 | }, | |
720 | ppc64_linux_sighandler_cache_init | |
721 | }; | |
722 | ||
7284e1be | 723 | |
85e747d2 UW |
724 | /* Address to use for displaced stepping. When debugging a stand-alone |
725 | SPU executable, entry_point_address () will point to an SPU local-store | |
726 | address and is thus not usable as displaced stepping location. We use | |
727 | the auxiliary vector to determine the PowerPC-side entry point address | |
728 | instead. */ | |
729 | ||
730 | static CORE_ADDR ppc_linux_entry_point_addr = 0; | |
731 | ||
732 | static void | |
733 | ppc_linux_inferior_created (struct target_ops *target, int from_tty) | |
734 | { | |
735 | ppc_linux_entry_point_addr = 0; | |
736 | } | |
737 | ||
738 | static CORE_ADDR | |
739 | ppc_linux_displaced_step_location (struct gdbarch *gdbarch) | |
740 | { | |
741 | if (ppc_linux_entry_point_addr == 0) | |
742 | { | |
743 | CORE_ADDR addr; | |
744 | ||
745 | /* Determine entry point from target auxiliary vector. */ | |
746 | if (target_auxv_search (¤t_target, AT_ENTRY, &addr) <= 0) | |
747 | error (_("Cannot find AT_ENTRY auxiliary vector entry.")); | |
748 | ||
749 | /* Make certain that the address points at real code, and not a | |
750 | function descriptor. */ | |
751 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
752 | ¤t_target); | |
753 | ||
754 | /* Inferior calls also use the entry point as a breakpoint location. | |
755 | We don't want displaced stepping to interfere with those | |
756 | breakpoints, so leave space. */ | |
5931a2fa | 757 | ppc_linux_entry_point_addr = addr + 2 * PPC_INSN_SIZE; |
85e747d2 UW |
758 | } |
759 | ||
760 | return ppc_linux_entry_point_addr; | |
761 | } | |
762 | ||
763 | ||
7284e1be UW |
764 | /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */ |
765 | int | |
766 | ppc_linux_trap_reg_p (struct gdbarch *gdbarch) | |
767 | { | |
768 | /* If we do not have a target description with registers, then | |
769 | the special registers will not be included in the register set. */ | |
770 | if (!tdesc_has_registers (gdbarch_target_desc (gdbarch))) | |
771 | return 0; | |
772 | ||
773 | /* If we do, then it is safe to check the size. */ | |
774 | return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0 | |
775 | && register_size (gdbarch, PPC_TRAP_REGNUM) > 0; | |
776 | } | |
777 | ||
a96d9b2e SDJ |
778 | /* Return the current system call's number present in the |
779 | r0 register. When the function fails, it returns -1. */ | |
780 | static LONGEST | |
781 | ppc_linux_get_syscall_number (struct gdbarch *gdbarch, | |
782 | ptid_t ptid) | |
783 | { | |
784 | struct regcache *regcache = get_thread_regcache (ptid); | |
785 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
786 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
787 | struct cleanup *cleanbuf; | |
788 | /* The content of a register */ | |
789 | gdb_byte *buf; | |
790 | /* The result */ | |
791 | LONGEST ret; | |
792 | ||
793 | /* Make sure we're in a 32- or 64-bit machine */ | |
794 | gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8); | |
795 | ||
796 | buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte)); | |
797 | ||
798 | cleanbuf = make_cleanup (xfree, buf); | |
799 | ||
800 | /* Getting the system call number from the register. | |
801 | When dealing with PowerPC architecture, this information | |
802 | is stored at 0th register. */ | |
803 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf); | |
804 | ||
805 | ret = extract_signed_integer (buf, tdep->wordsize, byte_order); | |
806 | do_cleanups (cleanbuf); | |
807 | ||
808 | return ret; | |
809 | } | |
810 | ||
7284e1be UW |
811 | static void |
812 | ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) | |
813 | { | |
814 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
815 | ||
816 | regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc); | |
817 | ||
818 | /* Set special TRAP register to -1 to prevent the kernel from | |
819 | messing with the PC we just installed, if we happen to be | |
820 | within an interrupted system call that the kernel wants to | |
821 | restart. | |
822 | ||
823 | Note that after we return from the dummy call, the TRAP and | |
824 | ORIG_R3 registers will be automatically restored, and the | |
825 | kernel continues to restart the system call at this point. */ | |
826 | if (ppc_linux_trap_reg_p (gdbarch)) | |
827 | regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1); | |
828 | } | |
829 | ||
f4d9bade UW |
830 | static int |
831 | ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data) | |
832 | { | |
833 | return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0; | |
834 | } | |
835 | ||
7284e1be UW |
836 | static const struct target_desc * |
837 | ppc_linux_core_read_description (struct gdbarch *gdbarch, | |
838 | struct target_ops *target, | |
839 | bfd *abfd) | |
840 | { | |
f4d9bade | 841 | asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL); |
7284e1be | 842 | asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx"); |
604c2f83 | 843 | asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx"); |
7284e1be UW |
844 | asection *section = bfd_get_section_by_name (abfd, ".reg"); |
845 | if (! section) | |
846 | return NULL; | |
847 | ||
848 | switch (bfd_section_size (abfd, section)) | |
849 | { | |
850 | case 48 * 4: | |
f4d9bade UW |
851 | if (cell) |
852 | return tdesc_powerpc_cell32l; | |
853 | else if (vsx) | |
604c2f83 LM |
854 | return tdesc_powerpc_vsx32l; |
855 | else if (altivec) | |
856 | return tdesc_powerpc_altivec32l; | |
857 | else | |
858 | return tdesc_powerpc_32l; | |
7284e1be UW |
859 | |
860 | case 48 * 8: | |
f4d9bade UW |
861 | if (cell) |
862 | return tdesc_powerpc_cell64l; | |
863 | else if (vsx) | |
604c2f83 LM |
864 | return tdesc_powerpc_vsx64l; |
865 | else if (altivec) | |
866 | return tdesc_powerpc_altivec64l; | |
867 | else | |
868 | return tdesc_powerpc_64l; | |
7284e1be UW |
869 | |
870 | default: | |
871 | return NULL; | |
872 | } | |
873 | } | |
874 | ||
591a12a1 UW |
875 | |
876 | /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in | |
877 | gdbarch.h. This implementation is used for the ELFv2 ABI only. */ | |
878 | ||
879 | static void | |
880 | ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym) | |
881 | { | |
882 | elf_symbol_type *elf_sym = (elf_symbol_type *)sym; | |
883 | ||
884 | /* If the symbol is marked as having a local entry point, set a target | |
885 | flag in the msymbol. We currently only support local entry point | |
886 | offsets of 8 bytes, which is the only entry point offset ever used | |
887 | by current compilers. If/when other offsets are ever used, we will | |
888 | have to use additional target flag bits to store them. */ | |
889 | switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other)) | |
890 | { | |
891 | default: | |
892 | break; | |
893 | case 8: | |
894 | MSYMBOL_TARGET_FLAG_1 (msym) = 1; | |
895 | break; | |
896 | } | |
897 | } | |
898 | ||
899 | /* Implementation of `gdbarch_skip_entrypoint', as defined in | |
900 | gdbarch.h. This implementation is used for the ELFv2 ABI only. */ | |
901 | ||
902 | static CORE_ADDR | |
903 | ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc) | |
904 | { | |
905 | struct bound_minimal_symbol fun; | |
906 | int local_entry_offset = 0; | |
907 | ||
908 | fun = lookup_minimal_symbol_by_pc (pc); | |
909 | if (fun.minsym == NULL) | |
910 | return pc; | |
911 | ||
912 | /* See ppc_elfv2_elf_make_msymbol_special for how local entry point | |
913 | offset values are encoded. */ | |
914 | if (MSYMBOL_TARGET_FLAG_1 (fun.minsym)) | |
915 | local_entry_offset = 8; | |
916 | ||
77e371c0 TT |
917 | if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc |
918 | && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset) | |
919 | return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset; | |
591a12a1 UW |
920 | |
921 | return pc; | |
922 | } | |
923 | ||
55aa24fb SDJ |
924 | /* Implementation of `gdbarch_stap_is_single_operand', as defined in |
925 | gdbarch.h. */ | |
926 | ||
927 | static int | |
928 | ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s) | |
929 | { | |
930 | return (*s == 'i' /* Literal number. */ | |
931 | || (isdigit (*s) && s[1] == '(' | |
932 | && isdigit (s[2])) /* Displacement. */ | |
933 | || (*s == '(' && isdigit (s[1])) /* Register indirection. */ | |
934 | || isdigit (*s)); /* Register value. */ | |
935 | } | |
936 | ||
937 | /* Implementation of `gdbarch_stap_parse_special_token', as defined in | |
938 | gdbarch.h. */ | |
939 | ||
940 | static int | |
941 | ppc_stap_parse_special_token (struct gdbarch *gdbarch, | |
942 | struct stap_parse_info *p) | |
943 | { | |
944 | if (isdigit (*p->arg)) | |
945 | { | |
946 | /* This temporary pointer is needed because we have to do a lookahead. | |
947 | We could be dealing with a register displacement, and in such case | |
948 | we would not need to do anything. */ | |
949 | const char *s = p->arg; | |
950 | char *regname; | |
951 | int len; | |
952 | struct stoken str; | |
953 | ||
954 | while (isdigit (*s)) | |
955 | ++s; | |
956 | ||
957 | if (*s == '(') | |
958 | { | |
959 | /* It is a register displacement indeed. Returning 0 means we are | |
960 | deferring the treatment of this case to the generic parser. */ | |
961 | return 0; | |
962 | } | |
963 | ||
964 | len = s - p->arg; | |
965 | regname = alloca (len + 2); | |
966 | regname[0] = 'r'; | |
967 | ||
968 | strncpy (regname + 1, p->arg, len); | |
969 | ++len; | |
970 | regname[len] = '\0'; | |
971 | ||
972 | if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1) | |
973 | error (_("Invalid register name `%s' on expression `%s'."), | |
974 | regname, p->saved_arg); | |
975 | ||
410a0ff2 | 976 | write_exp_elt_opcode (&p->pstate, OP_REGISTER); |
55aa24fb SDJ |
977 | str.ptr = regname; |
978 | str.length = len; | |
410a0ff2 SDJ |
979 | write_exp_string (&p->pstate, str); |
980 | write_exp_elt_opcode (&p->pstate, OP_REGISTER); | |
55aa24fb SDJ |
981 | |
982 | p->arg = s; | |
983 | } | |
984 | else | |
985 | { | |
986 | /* All the other tokens should be handled correctly by the generic | |
987 | parser. */ | |
988 | return 0; | |
989 | } | |
990 | ||
991 | return 1; | |
992 | } | |
cc5f0d61 UW |
993 | |
994 | /* Cell/B.E. active SPE context tracking support. */ | |
995 | ||
996 | static struct objfile *spe_context_objfile = NULL; | |
997 | static CORE_ADDR spe_context_lm_addr = 0; | |
998 | static CORE_ADDR spe_context_offset = 0; | |
999 | ||
1000 | static ptid_t spe_context_cache_ptid; | |
1001 | static CORE_ADDR spe_context_cache_address; | |
1002 | ||
1003 | /* Hook into inferior_created, solib_loaded, and solib_unloaded observers | |
1004 | to track whether we've loaded a version of libspe2 (as static or dynamic | |
1005 | library) that provides the __spe_current_active_context variable. */ | |
1006 | static void | |
1007 | ppc_linux_spe_context_lookup (struct objfile *objfile) | |
1008 | { | |
3b7344d5 | 1009 | struct bound_minimal_symbol sym; |
cc5f0d61 UW |
1010 | |
1011 | if (!objfile) | |
1012 | { | |
1013 | spe_context_objfile = NULL; | |
1014 | spe_context_lm_addr = 0; | |
1015 | spe_context_offset = 0; | |
1016 | spe_context_cache_ptid = minus_one_ptid; | |
1017 | spe_context_cache_address = 0; | |
1018 | return; | |
1019 | } | |
1020 | ||
1021 | sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile); | |
3b7344d5 | 1022 | if (sym.minsym) |
cc5f0d61 UW |
1023 | { |
1024 | spe_context_objfile = objfile; | |
1025 | spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile); | |
77e371c0 | 1026 | spe_context_offset = BMSYMBOL_VALUE_ADDRESS (sym); |
cc5f0d61 UW |
1027 | spe_context_cache_ptid = minus_one_ptid; |
1028 | spe_context_cache_address = 0; | |
1029 | return; | |
1030 | } | |
1031 | } | |
1032 | ||
1033 | static void | |
1034 | ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty) | |
1035 | { | |
1036 | struct objfile *objfile; | |
1037 | ||
1038 | ppc_linux_spe_context_lookup (NULL); | |
1039 | ALL_OBJFILES (objfile) | |
1040 | ppc_linux_spe_context_lookup (objfile); | |
1041 | } | |
1042 | ||
1043 | static void | |
1044 | ppc_linux_spe_context_solib_loaded (struct so_list *so) | |
1045 | { | |
1046 | if (strstr (so->so_original_name, "/libspe") != NULL) | |
1047 | { | |
7e559477 | 1048 | solib_read_symbols (so, 0); |
cc5f0d61 UW |
1049 | ppc_linux_spe_context_lookup (so->objfile); |
1050 | } | |
1051 | } | |
1052 | ||
1053 | static void | |
1054 | ppc_linux_spe_context_solib_unloaded (struct so_list *so) | |
1055 | { | |
1056 | if (so->objfile == spe_context_objfile) | |
1057 | ppc_linux_spe_context_lookup (NULL); | |
1058 | } | |
1059 | ||
1060 | /* Retrieve contents of the N'th element in the current thread's | |
1061 | linked SPE context list into ID and NPC. Return the address of | |
1062 | said context element, or 0 if not found. */ | |
1063 | static CORE_ADDR | |
1064 | ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order, | |
1065 | int n, int *id, unsigned int *npc) | |
1066 | { | |
1067 | CORE_ADDR spe_context = 0; | |
1068 | gdb_byte buf[16]; | |
1069 | int i; | |
1070 | ||
1071 | /* Quick exit if we have not found __spe_current_active_context. */ | |
1072 | if (!spe_context_objfile) | |
1073 | return 0; | |
1074 | ||
1075 | /* Look up cached address of thread-local variable. */ | |
1076 | if (!ptid_equal (spe_context_cache_ptid, inferior_ptid)) | |
1077 | { | |
1078 | struct target_ops *target = ¤t_target; | |
1079 | volatile struct gdb_exception ex; | |
1080 | ||
cc5f0d61 UW |
1081 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
1082 | { | |
1083 | /* We do not call target_translate_tls_address here, because | |
1084 | svr4_fetch_objfile_link_map may invalidate the frame chain, | |
1085 | which must not do while inside a frame sniffer. | |
1086 | ||
1087 | Instead, we have cached the lm_addr value, and use that to | |
1088 | directly call the target's to_get_thread_local_address. */ | |
1089 | spe_context_cache_address | |
1090 | = target->to_get_thread_local_address (target, inferior_ptid, | |
1091 | spe_context_lm_addr, | |
1092 | spe_context_offset); | |
1093 | spe_context_cache_ptid = inferior_ptid; | |
1094 | } | |
1095 | ||
1096 | if (ex.reason < 0) | |
1097 | return 0; | |
1098 | } | |
1099 | ||
1100 | /* Read variable value. */ | |
1101 | if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0) | |
1102 | spe_context = extract_unsigned_integer (buf, wordsize, byte_order); | |
1103 | ||
1104 | /* Cyle through to N'th linked list element. */ | |
1105 | for (i = 0; i < n && spe_context; i++) | |
1106 | if (target_read_memory (spe_context + align_up (12, wordsize), | |
1107 | buf, wordsize) == 0) | |
1108 | spe_context = extract_unsigned_integer (buf, wordsize, byte_order); | |
1109 | else | |
1110 | spe_context = 0; | |
1111 | ||
1112 | /* Read current context. */ | |
1113 | if (spe_context | |
1114 | && target_read_memory (spe_context, buf, 12) != 0) | |
1115 | spe_context = 0; | |
1116 | ||
1117 | /* Extract data elements. */ | |
1118 | if (spe_context) | |
1119 | { | |
1120 | if (id) | |
1121 | *id = extract_signed_integer (buf, 4, byte_order); | |
1122 | if (npc) | |
1123 | *npc = extract_unsigned_integer (buf + 4, 4, byte_order); | |
1124 | } | |
1125 | ||
1126 | return spe_context; | |
1127 | } | |
1128 | ||
1129 | ||
1130 | /* Cell/B.E. cross-architecture unwinder support. */ | |
1131 | ||
1132 | struct ppu2spu_cache | |
1133 | { | |
1134 | struct frame_id frame_id; | |
1135 | struct regcache *regcache; | |
1136 | }; | |
1137 | ||
1138 | static struct gdbarch * | |
1139 | ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache) | |
1140 | { | |
1141 | struct ppu2spu_cache *cache = *this_cache; | |
1142 | return get_regcache_arch (cache->regcache); | |
1143 | } | |
1144 | ||
1145 | static void | |
1146 | ppu2spu_this_id (struct frame_info *this_frame, | |
1147 | void **this_cache, struct frame_id *this_id) | |
1148 | { | |
1149 | struct ppu2spu_cache *cache = *this_cache; | |
1150 | *this_id = cache->frame_id; | |
1151 | } | |
1152 | ||
1153 | static struct value * | |
1154 | ppu2spu_prev_register (struct frame_info *this_frame, | |
1155 | void **this_cache, int regnum) | |
1156 | { | |
1157 | struct ppu2spu_cache *cache = *this_cache; | |
1158 | struct gdbarch *gdbarch = get_regcache_arch (cache->regcache); | |
1159 | gdb_byte *buf; | |
1160 | ||
1161 | buf = alloca (register_size (gdbarch, regnum)); | |
a536c6d7 UW |
1162 | |
1163 | if (regnum < gdbarch_num_regs (gdbarch)) | |
1164 | regcache_raw_read (cache->regcache, regnum, buf); | |
1165 | else | |
1166 | gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf); | |
1167 | ||
cc5f0d61 UW |
1168 | return frame_unwind_got_bytes (this_frame, regnum, buf); |
1169 | } | |
1170 | ||
1171 | struct ppu2spu_data | |
1172 | { | |
1173 | struct gdbarch *gdbarch; | |
1174 | int id; | |
1175 | unsigned int npc; | |
1176 | gdb_byte gprs[128*16]; | |
1177 | }; | |
1178 | ||
1179 | static int | |
1180 | ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf) | |
1181 | { | |
1182 | struct ppu2spu_data *data = src; | |
1183 | enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch); | |
1184 | ||
1185 | if (regnum >= 0 && regnum < SPU_NUM_GPRS) | |
1186 | memcpy (buf, data->gprs + 16*regnum, 16); | |
1187 | else if (regnum == SPU_ID_REGNUM) | |
1188 | store_unsigned_integer (buf, 4, byte_order, data->id); | |
1189 | else if (regnum == SPU_PC_REGNUM) | |
1190 | store_unsigned_integer (buf, 4, byte_order, data->npc); | |
1191 | else | |
a536c6d7 | 1192 | return REG_UNAVAILABLE; |
cc5f0d61 | 1193 | |
a536c6d7 | 1194 | return REG_VALID; |
cc5f0d61 UW |
1195 | } |
1196 | ||
1197 | static int | |
1198 | ppu2spu_sniffer (const struct frame_unwind *self, | |
1199 | struct frame_info *this_frame, void **this_prologue_cache) | |
1200 | { | |
1201 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
1202 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1203 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
1204 | struct ppu2spu_data data; | |
1205 | struct frame_info *fi; | |
1206 | CORE_ADDR base, func, backchain, spe_context; | |
1207 | gdb_byte buf[8]; | |
1208 | int n = 0; | |
1209 | ||
1210 | /* Count the number of SPU contexts already in the frame chain. */ | |
1211 | for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi)) | |
1212 | if (get_frame_type (fi) == ARCH_FRAME | |
1213 | && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu) | |
1214 | n++; | |
1215 | ||
1216 | base = get_frame_sp (this_frame); | |
1217 | func = get_frame_pc (this_frame); | |
1218 | if (target_read_memory (base, buf, tdep->wordsize)) | |
1219 | return 0; | |
1220 | backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order); | |
1221 | ||
1222 | spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order, | |
1223 | n, &data.id, &data.npc); | |
1224 | if (spe_context && base <= spe_context && spe_context < backchain) | |
1225 | { | |
1226 | char annex[32]; | |
1227 | ||
1228 | /* Find gdbarch for SPU. */ | |
1229 | struct gdbarch_info info; | |
1230 | gdbarch_info_init (&info); | |
1231 | info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu); | |
1232 | info.byte_order = BFD_ENDIAN_BIG; | |
1233 | info.osabi = GDB_OSABI_LINUX; | |
1234 | info.tdep_info = (void *) &data.id; | |
1235 | data.gdbarch = gdbarch_find_by_info (info); | |
1236 | if (!data.gdbarch) | |
1237 | return 0; | |
1238 | ||
1239 | xsnprintf (annex, sizeof annex, "%d/regs", data.id); | |
1240 | if (target_read (¤t_target, TARGET_OBJECT_SPU, annex, | |
1241 | data.gprs, 0, sizeof data.gprs) | |
1242 | == sizeof data.gprs) | |
1243 | { | |
1244 | struct ppu2spu_cache *cache | |
1245 | = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache); | |
1246 | ||
d37346f0 DJ |
1247 | struct address_space *aspace = get_frame_address_space (this_frame); |
1248 | struct regcache *regcache = regcache_xmalloc (data.gdbarch, aspace); | |
cc5f0d61 UW |
1249 | struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache); |
1250 | regcache_save (regcache, ppu2spu_unwind_register, &data); | |
1251 | discard_cleanups (cleanups); | |
1252 | ||
1253 | cache->frame_id = frame_id_build (base, func); | |
1254 | cache->regcache = regcache; | |
1255 | *this_prologue_cache = cache; | |
1256 | return 1; | |
1257 | } | |
1258 | } | |
1259 | ||
1260 | return 0; | |
1261 | } | |
1262 | ||
1263 | static void | |
1264 | ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache) | |
1265 | { | |
1266 | struct ppu2spu_cache *cache = this_cache; | |
1267 | regcache_xfree (cache->regcache); | |
1268 | } | |
1269 | ||
1270 | static const struct frame_unwind ppu2spu_unwind = { | |
1271 | ARCH_FRAME, | |
8fbca658 | 1272 | default_frame_unwind_stop_reason, |
cc5f0d61 UW |
1273 | ppu2spu_this_id, |
1274 | ppu2spu_prev_register, | |
1275 | NULL, | |
1276 | ppu2spu_sniffer, | |
1277 | ppu2spu_dealloc_cache, | |
1278 | ppu2spu_prev_arch, | |
1279 | }; | |
1280 | ||
1281 | ||
7b112f9c JT |
1282 | static void |
1283 | ppc_linux_init_abi (struct gdbarch_info info, | |
1284 | struct gdbarch *gdbarch) | |
1285 | { | |
1286 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
7284e1be | 1287 | struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info; |
05c0465e SDJ |
1288 | static const char *const stap_integer_prefixes[] = { "i", NULL }; |
1289 | static const char *const stap_register_indirection_prefixes[] = { "(", | |
1290 | NULL }; | |
1291 | static const char *const stap_register_indirection_suffixes[] = { ")", | |
1292 | NULL }; | |
7b112f9c | 1293 | |
a5ee0f0c PA |
1294 | linux_init_abi (info, gdbarch); |
1295 | ||
b14d30e1 JM |
1296 | /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where |
1297 | 128-bit, they are IBM long double, not IEEE quad long double as | |
1298 | in the System V ABI PowerPC Processor Supplement. We can safely | |
1299 | let them default to 128-bit, since the debug info will give the | |
1300 | size of type actually used in each case. */ | |
1301 | set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT); | |
1302 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); | |
0598a43c | 1303 | |
7284e1be UW |
1304 | /* Handle inferior calls during interrupted system calls. */ |
1305 | set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc); | |
1306 | ||
a96d9b2e SDJ |
1307 | /* Get the syscall number from the arch's register. */ |
1308 | set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number); | |
1309 | ||
55aa24fb | 1310 | /* SystemTap functions. */ |
05c0465e SDJ |
1311 | set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes); |
1312 | set_gdbarch_stap_register_indirection_prefixes (gdbarch, | |
1313 | stap_register_indirection_prefixes); | |
1314 | set_gdbarch_stap_register_indirection_suffixes (gdbarch, | |
1315 | stap_register_indirection_suffixes); | |
55aa24fb SDJ |
1316 | set_gdbarch_stap_gdb_register_prefix (gdbarch, "r"); |
1317 | set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand); | |
1318 | set_gdbarch_stap_parse_special_token (gdbarch, | |
1319 | ppc_stap_parse_special_token); | |
1320 | ||
7b112f9c JT |
1321 | if (tdep->wordsize == 4) |
1322 | { | |
b9ff3018 AC |
1323 | /* Until November 2001, gcc did not comply with the 32 bit SysV |
1324 | R4 ABI requirement that structures less than or equal to 8 | |
1325 | bytes should be returned in registers. Instead GCC was using | |
b021a221 | 1326 | the AIX/PowerOpen ABI - everything returned in memory |
b9ff3018 AC |
1327 | (well ignoring vectors that is). When this was corrected, it |
1328 | wasn't fixed for GNU/Linux native platform. Use the | |
1329 | PowerOpen struct convention. */ | |
05580c65 | 1330 | set_gdbarch_return_value (gdbarch, ppc_linux_return_value); |
b9ff3018 | 1331 | |
7b112f9c JT |
1332 | set_gdbarch_memory_remove_breakpoint (gdbarch, |
1333 | ppc_linux_memory_remove_breakpoint); | |
61a65099 | 1334 | |
f470a70a | 1335 | /* Shared library handling. */ |
5d853008 | 1336 | set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code); |
7b112f9c | 1337 | set_solib_svr4_fetch_link_map_offsets |
76a9d10f | 1338 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); |
a8f60bfc | 1339 | |
a96d9b2e SDJ |
1340 | /* Setting the correct XML syscall filename. */ |
1341 | set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC); | |
1342 | ||
a8f60bfc | 1343 | /* Trampolines. */ |
0df8b418 MS |
1344 | tramp_frame_prepend_unwinder (gdbarch, |
1345 | &ppc32_linux_sigaction_tramp_frame); | |
1346 | tramp_frame_prepend_unwinder (gdbarch, | |
1347 | &ppc32_linux_sighandler_tramp_frame); | |
a78c2d62 UW |
1348 | |
1349 | /* BFD target for core files. */ | |
1350 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) | |
1351 | set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle"); | |
1352 | else | |
1353 | set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc"); | |
2f2241f1 UW |
1354 | |
1355 | /* Supported register sections. */ | |
1356 | if (tdesc_find_feature (info.target_desc, | |
1357 | "org.gnu.gdb.power.vsx")) | |
1358 | set_gdbarch_core_regset_sections (gdbarch, | |
1359 | ppc_linux_vsx_regset_sections); | |
1360 | else if (tdesc_find_feature (info.target_desc, | |
1361 | "org.gnu.gdb.power.altivec")) | |
1362 | set_gdbarch_core_regset_sections (gdbarch, | |
1363 | ppc_linux_vmx_regset_sections); | |
1364 | else | |
1365 | set_gdbarch_core_regset_sections (gdbarch, | |
1366 | ppc_linux_fp_regset_sections); | |
5d853008 ME |
1367 | |
1368 | if (powerpc_so_ops.in_dynsym_resolve_code == NULL) | |
1369 | { | |
1370 | powerpc_so_ops = svr4_so_ops; | |
1371 | /* Override dynamic resolve function. */ | |
1372 | powerpc_so_ops.in_dynsym_resolve_code = | |
1373 | powerpc_linux_in_dynsym_resolve_code; | |
1374 | } | |
1375 | set_solib_ops (gdbarch, &powerpc_so_ops); | |
1376 | ||
1377 | set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); | |
7b112f9c | 1378 | } |
f470a70a JB |
1379 | |
1380 | if (tdep->wordsize == 8) | |
1381 | { | |
d4094b6a UW |
1382 | if (tdep->elf_abi == POWERPC_ELF_V1) |
1383 | { | |
1384 | /* Handle PPC GNU/Linux 64-bit function pointers (which are really | |
1385 | function descriptors). */ | |
1386 | set_gdbarch_convert_from_func_ptr_addr | |
1387 | (gdbarch, ppc64_convert_from_func_ptr_addr); | |
00d5f93a | 1388 | |
d4094b6a UW |
1389 | set_gdbarch_elf_make_msymbol_special |
1390 | (gdbarch, ppc64_elf_make_msymbol_special); | |
1391 | } | |
591a12a1 UW |
1392 | else |
1393 | { | |
1394 | set_gdbarch_elf_make_msymbol_special | |
1395 | (gdbarch, ppc_elfv2_elf_make_msymbol_special); | |
1396 | ||
1397 | set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint); | |
1398 | } | |
24c274a1 | 1399 | |
fb318ff7 | 1400 | /* Shared library handling. */ |
2bbe3cc1 | 1401 | set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code); |
fb318ff7 DJ |
1402 | set_solib_svr4_fetch_link_map_offsets |
1403 | (gdbarch, svr4_lp64_fetch_link_map_offsets); | |
1404 | ||
a96d9b2e SDJ |
1405 | /* Setting the correct XML syscall filename. */ |
1406 | set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64); | |
1407 | ||
a8f60bfc | 1408 | /* Trampolines. */ |
0df8b418 MS |
1409 | tramp_frame_prepend_unwinder (gdbarch, |
1410 | &ppc64_linux_sigaction_tramp_frame); | |
1411 | tramp_frame_prepend_unwinder (gdbarch, | |
1412 | &ppc64_linux_sighandler_tramp_frame); | |
a78c2d62 UW |
1413 | |
1414 | /* BFD target for core files. */ | |
1415 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) | |
1416 | set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle"); | |
1417 | else | |
1418 | set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc"); | |
2f2241f1 UW |
1419 | |
1420 | /* Supported register sections. */ | |
1421 | if (tdesc_find_feature (info.target_desc, | |
1422 | "org.gnu.gdb.power.vsx")) | |
1423 | set_gdbarch_core_regset_sections (gdbarch, | |
1424 | ppc64_linux_vsx_regset_sections); | |
1425 | else if (tdesc_find_feature (info.target_desc, | |
1426 | "org.gnu.gdb.power.altivec")) | |
1427 | set_gdbarch_core_regset_sections (gdbarch, | |
1428 | ppc64_linux_vmx_regset_sections); | |
1429 | else | |
1430 | set_gdbarch_core_regset_sections (gdbarch, | |
1431 | ppc64_linux_fp_regset_sections); | |
f470a70a | 1432 | } |
b3ac9c77 SDJ |
1433 | |
1434 | /* PPC32 uses a different prpsinfo32 compared to most other Linux | |
1435 | archs. */ | |
1436 | if (tdep->wordsize == 4) | |
1437 | set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch, | |
1438 | elfcore_write_ppc_linux_prpsinfo32); | |
1439 | ||
0df8b418 MS |
1440 | set_gdbarch_regset_from_core_section (gdbarch, |
1441 | ppc_linux_regset_from_core_section); | |
7284e1be | 1442 | set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description); |
b2756930 KB |
1443 | |
1444 | /* Enable TLS support. */ | |
1445 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
1446 | svr4_fetch_objfile_link_map); | |
7284e1be UW |
1447 | |
1448 | if (tdesc_data) | |
1449 | { | |
1450 | const struct tdesc_feature *feature; | |
1451 | ||
1452 | /* If we have target-described registers, then we can safely | |
1453 | reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM | |
1454 | (whether they are described or not). */ | |
1455 | gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM); | |
1456 | set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1); | |
1457 | ||
1458 | /* If they are present, then assign them to the reserved number. */ | |
1459 | feature = tdesc_find_feature (info.target_desc, | |
1460 | "org.gnu.gdb.power.linux"); | |
1461 | if (feature != NULL) | |
1462 | { | |
1463 | tdesc_numbered_register (feature, tdesc_data, | |
1464 | PPC_ORIG_R3_REGNUM, "orig_r3"); | |
1465 | tdesc_numbered_register (feature, tdesc_data, | |
1466 | PPC_TRAP_REGNUM, "trap"); | |
1467 | } | |
1468 | } | |
85e747d2 UW |
1469 | |
1470 | /* Enable Cell/B.E. if supported by the target. */ | |
1471 | if (tdesc_compatible_p (info.target_desc, | |
1472 | bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu))) | |
1473 | { | |
1474 | /* Cell/B.E. multi-architecture support. */ | |
1475 | set_spu_solib_ops (gdbarch); | |
1476 | ||
cc5f0d61 UW |
1477 | /* Cell/B.E. cross-architecture unwinder support. */ |
1478 | frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind); | |
1479 | ||
85e747d2 UW |
1480 | /* The default displaced_step_at_entry_point doesn't work for |
1481 | SPU stand-alone executables. */ | |
1482 | set_gdbarch_displaced_step_location (gdbarch, | |
1483 | ppc_linux_displaced_step_location); | |
1484 | } | |
f782ad9b AS |
1485 | |
1486 | set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type); | |
7b112f9c JT |
1487 | } |
1488 | ||
63807e1d PA |
1489 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
1490 | extern initialize_file_ftype _initialize_ppc_linux_tdep; | |
1491 | ||
7b112f9c JT |
1492 | void |
1493 | _initialize_ppc_linux_tdep (void) | |
1494 | { | |
0a0a4ac3 AC |
1495 | /* Register for all sub-familes of the POWER/PowerPC: 32-bit and |
1496 | 64-bit PowerPC, and the older rs6k. */ | |
1497 | gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX, | |
1498 | ppc_linux_init_abi); | |
1499 | gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX, | |
1500 | ppc_linux_init_abi); | |
1501 | gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX, | |
1502 | ppc_linux_init_abi); | |
7284e1be | 1503 | |
85e747d2 UW |
1504 | /* Attach to inferior_created observer. */ |
1505 | observer_attach_inferior_created (ppc_linux_inferior_created); | |
1506 | ||
cc5f0d61 UW |
1507 | /* Attach to observers to track __spe_current_active_context. */ |
1508 | observer_attach_inferior_created (ppc_linux_spe_context_inferior_created); | |
1509 | observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded); | |
1510 | observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded); | |
1511 | ||
7284e1be UW |
1512 | /* Initialize the Linux target descriptions. */ |
1513 | initialize_tdesc_powerpc_32l (); | |
1514 | initialize_tdesc_powerpc_altivec32l (); | |
f4d9bade | 1515 | initialize_tdesc_powerpc_cell32l (); |
604c2f83 | 1516 | initialize_tdesc_powerpc_vsx32l (); |
69abc51c TJB |
1517 | initialize_tdesc_powerpc_isa205_32l (); |
1518 | initialize_tdesc_powerpc_isa205_altivec32l (); | |
1519 | initialize_tdesc_powerpc_isa205_vsx32l (); | |
7284e1be UW |
1520 | initialize_tdesc_powerpc_64l (); |
1521 | initialize_tdesc_powerpc_altivec64l (); | |
f4d9bade | 1522 | initialize_tdesc_powerpc_cell64l (); |
604c2f83 | 1523 | initialize_tdesc_powerpc_vsx64l (); |
69abc51c TJB |
1524 | initialize_tdesc_powerpc_isa205_64l (); |
1525 | initialize_tdesc_powerpc_isa205_altivec64l (); | |
1526 | initialize_tdesc_powerpc_isa205_vsx64l (); | |
7284e1be | 1527 | initialize_tdesc_powerpc_e500l (); |
7b112f9c | 1528 | } |