Commit | Line | Data |
---|---|---|
c877c8e6 | 1 | /* Target-dependent code for GDB, the GNU debugger. |
4e052eda | 2 | |
e2882c85 | 3 | Copyright (C) 1986-2018 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" |
76727919 | 44 | #include "observable.h" |
85e747d2 UW |
45 | #include "auxv.h" |
46 | #include "elf/common.h" | |
591a12a1 | 47 | #include "elf/ppc64.h" |
cc5f0d61 UW |
48 | #include "arch-utils.h" |
49 | #include "spu-tdep.h" | |
a96d9b2e | 50 | #include "xml-syscall.h" |
a5ee0f0c | 51 | #include "linux-tdep.h" |
b4cdae6f WW |
52 | #include "linux-record.h" |
53 | #include "record-full.h" | |
cf90fd9a | 54 | #include "infrun.h" |
9aa1e687 | 55 | |
55aa24fb SDJ |
56 | #include "stap-probe.h" |
57 | #include "ax.h" | |
58 | #include "ax-gdb.h" | |
59 | #include "cli/cli-utils.h" | |
60 | #include "parser-defs.h" | |
61 | #include "user-regs.h" | |
62 | #include <ctype.h> | |
a2f63b2e | 63 | #include "elf-bfd.h" |
55aa24fb | 64 | |
7284e1be UW |
65 | #include "features/rs6000/powerpc-32l.c" |
66 | #include "features/rs6000/powerpc-altivec32l.c" | |
f4d9bade | 67 | #include "features/rs6000/powerpc-cell32l.c" |
604c2f83 | 68 | #include "features/rs6000/powerpc-vsx32l.c" |
69abc51c TJB |
69 | #include "features/rs6000/powerpc-isa205-32l.c" |
70 | #include "features/rs6000/powerpc-isa205-altivec32l.c" | |
71 | #include "features/rs6000/powerpc-isa205-vsx32l.c" | |
7284e1be UW |
72 | #include "features/rs6000/powerpc-64l.c" |
73 | #include "features/rs6000/powerpc-altivec64l.c" | |
f4d9bade | 74 | #include "features/rs6000/powerpc-cell64l.c" |
604c2f83 | 75 | #include "features/rs6000/powerpc-vsx64l.c" |
69abc51c TJB |
76 | #include "features/rs6000/powerpc-isa205-64l.c" |
77 | #include "features/rs6000/powerpc-isa205-altivec64l.c" | |
78 | #include "features/rs6000/powerpc-isa205-vsx64l.c" | |
7284e1be UW |
79 | #include "features/rs6000/powerpc-e500l.c" |
80 | ||
5d853008 ME |
81 | /* Shared library operations for PowerPC-Linux. */ |
82 | static struct target_so_ops powerpc_so_ops; | |
83 | ||
a96d9b2e SDJ |
84 | /* The syscall's XML filename for PPC and PPC64. */ |
85 | #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml" | |
86 | #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml" | |
c877c8e6 | 87 | |
122a33de KB |
88 | /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint |
89 | in much the same fashion as memory_remove_breakpoint in mem-break.c, | |
90 | but is careful not to write back the previous contents if the code | |
91 | in question has changed in between inserting the breakpoint and | |
92 | removing it. | |
93 | ||
94 | Here is the problem that we're trying to solve... | |
95 | ||
96 | Once upon a time, before introducing this function to remove | |
97 | breakpoints from the inferior, setting a breakpoint on a shared | |
98 | library function prior to running the program would not work | |
99 | properly. In order to understand the problem, it is first | |
100 | necessary to understand a little bit about dynamic linking on | |
101 | this platform. | |
102 | ||
103 | A call to a shared library function is accomplished via a bl | |
104 | (branch-and-link) instruction whose branch target is an entry | |
105 | in the procedure linkage table (PLT). The PLT in the object | |
106 | file is uninitialized. To gdb, prior to running the program, the | |
107 | entries in the PLT are all zeros. | |
108 | ||
109 | Once the program starts running, the shared libraries are loaded | |
110 | and the procedure linkage table is initialized, but the entries in | |
111 | the table are not (necessarily) resolved. Once a function is | |
112 | actually called, the code in the PLT is hit and the function is | |
113 | resolved. In order to better illustrate this, an example is in | |
114 | order; the following example is from the gdb testsuite. | |
115 | ||
116 | We start the program shmain. | |
117 | ||
118 | [kev@arroyo testsuite]$ ../gdb gdb.base/shmain | |
119 | [...] | |
120 | ||
121 | We place two breakpoints, one on shr1 and the other on main. | |
122 | ||
123 | (gdb) b shr1 | |
124 | Breakpoint 1 at 0x100409d4 | |
125 | (gdb) b main | |
126 | Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44. | |
127 | ||
128 | Examine the instruction (and the immediatly following instruction) | |
129 | upon which the breakpoint was placed. Note that the PLT entry | |
130 | for shr1 contains zeros. | |
131 | ||
132 | (gdb) x/2i 0x100409d4 | |
133 | 0x100409d4 <shr1>: .long 0x0 | |
134 | 0x100409d8 <shr1+4>: .long 0x0 | |
135 | ||
136 | Now run 'til main. | |
137 | ||
138 | (gdb) r | |
139 | Starting program: gdb.base/shmain | |
140 | Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19. | |
141 | ||
142 | Breakpoint 2, main () | |
143 | at gdb.base/shmain.c:44 | |
144 | 44 g = 1; | |
145 | ||
146 | Examine the PLT again. Note that the loading of the shared | |
147 | library has initialized the PLT to code which loads a constant | |
148 | (which I think is an index into the GOT) into r11 and then | |
149 | branchs a short distance to the code which actually does the | |
150 | resolving. | |
151 | ||
152 | (gdb) x/2i 0x100409d4 | |
153 | 0x100409d4 <shr1>: li r11,4 | |
154 | 0x100409d8 <shr1+4>: b 0x10040984 <sg+4> | |
155 | (gdb) c | |
156 | Continuing. | |
157 | ||
158 | Breakpoint 1, shr1 (x=1) | |
159 | at gdb.base/shr1.c:19 | |
160 | 19 l = 1; | |
161 | ||
162 | Now we've hit the breakpoint at shr1. (The breakpoint was | |
163 | reset from the PLT entry to the actual shr1 function after the | |
164 | shared library was loaded.) Note that the PLT entry has been | |
0df8b418 | 165 | resolved to contain a branch that takes us directly to shr1. |
122a33de KB |
166 | (The real one, not the PLT entry.) |
167 | ||
168 | (gdb) x/2i 0x100409d4 | |
169 | 0x100409d4 <shr1>: b 0xffaf76c <shr1> | |
170 | 0x100409d8 <shr1+4>: b 0x10040984 <sg+4> | |
171 | ||
172 | The thing to note here is that the PLT entry for shr1 has been | |
173 | changed twice. | |
174 | ||
175 | Now the problem should be obvious. GDB places a breakpoint (a | |
0df8b418 | 176 | trap instruction) on the zero value of the PLT entry for shr1. |
122a33de KB |
177 | Later on, after the shared library had been loaded and the PLT |
178 | initialized, GDB gets a signal indicating this fact and attempts | |
179 | (as it always does when it stops) to remove all the breakpoints. | |
180 | ||
181 | The breakpoint removal was causing the former contents (a zero | |
182 | word) to be written back to the now initialized PLT entry thus | |
183 | destroying a portion of the initialization that had occurred only a | |
184 | short time ago. When execution continued, the zero word would be | |
766062f6 | 185 | executed as an instruction an illegal instruction trap was |
122a33de KB |
186 | generated instead. (0 is not a legal instruction.) |
187 | ||
188 | The fix for this problem was fairly straightforward. The function | |
189 | memory_remove_breakpoint from mem-break.c was copied to this file, | |
190 | modified slightly, and renamed to ppc_linux_memory_remove_breakpoint. | |
191 | In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new | |
192 | function. | |
193 | ||
194 | The differences between ppc_linux_memory_remove_breakpoint () and | |
195 | memory_remove_breakpoint () are minor. All that the former does | |
196 | that the latter does not is check to make sure that the breakpoint | |
197 | location actually contains a breakpoint (trap instruction) prior | |
198 | to attempting to write back the old contents. If it does contain | |
0df8b418 | 199 | a trap instruction, we allow the old contents to be written back. |
122a33de KB |
200 | Otherwise, we silently do nothing. |
201 | ||
202 | The big question is whether memory_remove_breakpoint () should be | |
203 | changed to have the same functionality. The downside is that more | |
204 | traffic is generated for remote targets since we'll have an extra | |
205 | fetch of a memory word each time a breakpoint is removed. | |
206 | ||
207 | For the time being, we'll leave this self-modifying-code-friendly | |
208 | version in ppc-linux-tdep.c, but it ought to be migrated somewhere | |
209 | else in the event that some other platform has similar needs with | |
210 | regard to removing breakpoints in some potentially self modifying | |
211 | code. */ | |
63807e1d | 212 | static int |
ae4b2284 MD |
213 | ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch, |
214 | struct bp_target_info *bp_tgt) | |
482ca3f5 | 215 | { |
0d5ed153 | 216 | CORE_ADDR addr = bp_tgt->reqstd_address; |
f4f9705a | 217 | const unsigned char *bp; |
482ca3f5 KB |
218 | int val; |
219 | int bplen; | |
50fd1280 | 220 | gdb_byte old_contents[BREAKPOINT_MAX]; |
482ca3f5 KB |
221 | |
222 | /* Determine appropriate breakpoint contents and size for this address. */ | |
ae4b2284 | 223 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen); |
482ca3f5 | 224 | |
8defab1a | 225 | /* Make sure we see the memory breakpoints. */ |
cb85b21b TT |
226 | scoped_restore restore_memory |
227 | = make_scoped_restore_show_memory_breakpoints (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 KB |
235 | |
236 | return val; | |
237 | } | |
6ded7999 | 238 | |
b9ff3018 AC |
239 | /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather |
240 | than the 32 bit SYSV R4 ABI structure return convention - all | |
241 | structures, no matter their size, are put in memory. Vectors, | |
242 | which were added later, do get returned in a register though. */ | |
243 | ||
05580c65 | 244 | static enum return_value_convention |
6a3a010b | 245 | ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 CV |
246 | struct type *valtype, struct regcache *regcache, |
247 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
b9ff3018 | 248 | { |
05580c65 AC |
249 | if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT |
250 | || TYPE_CODE (valtype) == TYPE_CODE_UNION) | |
251 | && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) | |
252 | && TYPE_VECTOR (valtype))) | |
253 | return RETURN_VALUE_STRUCT_CONVENTION; | |
254 | else | |
6a3a010b | 255 | return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache, |
c055b101 | 256 | readbuf, writebuf); |
b9ff3018 AC |
257 | } |
258 | ||
7433498b AM |
259 | /* PLT stub in an executable. */ |
260 | static const struct ppc_insn_pattern powerpc32_plt_stub[] = | |
5d853008 ME |
261 | { |
262 | { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */ | |
263 | { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ | |
264 | { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | |
265 | { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | |
266 | { 0, 0, 0 } | |
267 | }; | |
268 | ||
7433498b AM |
269 | /* PLT stubs in a shared library or PIE. |
270 | The first variant is used when the PLT entry is within +/-32k of | |
271 | the GOT pointer (r30). */ | |
272 | static const struct ppc_insn_pattern powerpc32_plt_stub_so_1[] = | |
5d853008 ME |
273 | { |
274 | { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */ | |
275 | { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | |
276 | { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | |
5d853008 ME |
277 | { 0, 0, 0 } |
278 | }; | |
7433498b AM |
279 | |
280 | /* The second variant is used when the PLT entry is more than +/-32k | |
281 | from the GOT pointer (r30). */ | |
282 | static const struct ppc_insn_pattern powerpc32_plt_stub_so_2[] = | |
283 | { | |
284 | { 0xffff0000, 0x3d7e0000, 0 }, /* addis r11, r30, xxxx */ | |
285 | { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ | |
286 | { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | |
287 | { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | |
288 | { 0, 0, 0 } | |
289 | }; | |
290 | ||
291 | /* The max number of insns we check using ppc_insns_match_pattern. */ | |
292 | #define POWERPC32_PLT_CHECK_LEN (ARRAY_SIZE (powerpc32_plt_stub) - 1) | |
5d853008 ME |
293 | |
294 | /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt | |
295 | section. For secure PLT, stub is in .text and we need to check | |
296 | instruction patterns. */ | |
297 | ||
298 | static int | |
299 | powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc) | |
300 | { | |
7cbd4a93 | 301 | struct bound_minimal_symbol sym; |
5d853008 ME |
302 | |
303 | /* Check whether PC is in the dynamic linker. This also checks | |
304 | whether it is in the .plt section, used by non-PIC executables. */ | |
305 | if (svr4_in_dynsym_resolve_code (pc)) | |
306 | return 1; | |
307 | ||
308 | /* Check if we are in the resolver. */ | |
309 | sym = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 | 310 | if (sym.minsym != NULL |
efd66ac6 TT |
311 | && (strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0 |
312 | || strcmp (MSYMBOL_LINKAGE_NAME (sym.minsym), | |
7cbd4a93 | 313 | "__glink_PLTresolve") == 0)) |
5d853008 ME |
314 | return 1; |
315 | ||
316 | return 0; | |
317 | } | |
318 | ||
ddeca1df WW |
319 | /* Follow PLT stub to actual routine. |
320 | ||
321 | When the execution direction is EXEC_REVERSE, scan backward to | |
322 | check whether we are in the middle of a PLT stub. Currently, | |
7433498b | 323 | we only look-behind at most 4 instructions (the max length of a PLT |
ddeca1df | 324 | stub sequence. */ |
5d853008 ME |
325 | |
326 | static CORE_ADDR | |
327 | ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
328 | { | |
7433498b | 329 | unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN]; |
5d853008 ME |
330 | struct gdbarch *gdbarch = get_frame_arch (frame); |
331 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
332 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
333 | CORE_ADDR target = 0; | |
cf90fd9a | 334 | int scan_limit, i; |
5d853008 | 335 | |
cf90fd9a WW |
336 | scan_limit = 1; |
337 | /* When reverse-debugging, scan backward to check whether we are | |
338 | in the middle of trampoline code. */ | |
339 | if (execution_direction == EXEC_REVERSE) | |
7433498b | 340 | scan_limit = 4; /* At most 4 instructions. */ |
5d853008 | 341 | |
cf90fd9a | 342 | for (i = 0; i < scan_limit; i++) |
5d853008 | 343 | { |
cf90fd9a WW |
344 | if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf)) |
345 | { | |
7433498b | 346 | /* Calculate PLT entry address from |
cf90fd9a | 347 | lis r11, xxxx |
7433498b AM |
348 | lwz r11, xxxx(r11). */ |
349 | target = ((ppc_insn_d_field (insnbuf[0]) << 16) | |
350 | + ppc_insn_d_field (insnbuf[1])); | |
351 | } | |
352 | else if (i < ARRAY_SIZE (powerpc32_plt_stub_so_1) - 1 | |
353 | && ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_1, | |
354 | insnbuf)) | |
355 | { | |
356 | /* Calculate PLT entry address from | |
357 | lwz r11, xxxx(r30). */ | |
358 | target = (ppc_insn_d_field (insnbuf[0]) | |
359 | + get_frame_register_unsigned (frame, | |
360 | tdep->ppc_gp0_regnum + 30)); | |
cf90fd9a | 361 | } |
7433498b | 362 | else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_2, |
cf90fd9a WW |
363 | insnbuf)) |
364 | { | |
7433498b AM |
365 | /* Calculate PLT entry address from |
366 | addis r11, r30, xxxx | |
367 | lwz r11, xxxx(r11). */ | |
368 | target = ((ppc_insn_d_field (insnbuf[0]) << 16) | |
369 | + ppc_insn_d_field (insnbuf[1]) | |
370 | + get_frame_register_unsigned (frame, | |
371 | tdep->ppc_gp0_regnum + 30)); | |
cf90fd9a WW |
372 | } |
373 | else | |
374 | { | |
7433498b | 375 | /* Scan backward one more instruction if it doesn't match. */ |
cf90fd9a WW |
376 | pc -= 4; |
377 | continue; | |
378 | } | |
379 | ||
7433498b | 380 | target = read_memory_unsigned_integer (target, 4, byte_order); |
cf90fd9a | 381 | return target; |
5d853008 ME |
382 | } |
383 | ||
cf90fd9a | 384 | return 0; |
5d853008 | 385 | } |
f470a70a | 386 | |
7284e1be UW |
387 | /* Wrappers to handle Linux-only registers. */ |
388 | ||
389 | static void | |
390 | ppc_linux_supply_gregset (const struct regset *regset, | |
391 | struct regcache *regcache, | |
392 | int regnum, const void *gregs, size_t len) | |
393 | { | |
19ba03f4 SM |
394 | const struct ppc_reg_offsets *offsets |
395 | = (const struct ppc_reg_offsets *) regset->regmap; | |
7284e1be UW |
396 | |
397 | ppc_supply_gregset (regset, regcache, regnum, gregs, len); | |
398 | ||
ac7936df | 399 | if (ppc_linux_trap_reg_p (regcache->arch ())) |
7284e1be UW |
400 | { |
401 | /* "orig_r3" is stored 2 slots after "pc". */ | |
402 | if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM) | |
19ba03f4 | 403 | ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, (const gdb_byte *) gregs, |
7284e1be UW |
404 | offsets->pc_offset + 2 * offsets->gpr_size, |
405 | offsets->gpr_size); | |
406 | ||
407 | /* "trap" is stored 8 slots after "pc". */ | |
408 | if (regnum == -1 || regnum == PPC_TRAP_REGNUM) | |
19ba03f4 | 409 | ppc_supply_reg (regcache, PPC_TRAP_REGNUM, (const gdb_byte *) gregs, |
7284e1be UW |
410 | offsets->pc_offset + 8 * offsets->gpr_size, |
411 | offsets->gpr_size); | |
412 | } | |
413 | } | |
f2db237a | 414 | |
f9be684a | 415 | static void |
f2db237a AM |
416 | ppc_linux_collect_gregset (const struct regset *regset, |
417 | const struct regcache *regcache, | |
418 | int regnum, void *gregs, size_t len) | |
f9be684a | 419 | { |
19ba03f4 SM |
420 | const struct ppc_reg_offsets *offsets |
421 | = (const struct ppc_reg_offsets *) regset->regmap; | |
7284e1be UW |
422 | |
423 | /* Clear areas in the linux gregset not written elsewhere. */ | |
f2db237a AM |
424 | if (regnum == -1) |
425 | memset (gregs, 0, len); | |
7284e1be | 426 | |
f2db237a | 427 | ppc_collect_gregset (regset, regcache, regnum, gregs, len); |
7284e1be | 428 | |
ac7936df | 429 | if (ppc_linux_trap_reg_p (regcache->arch ())) |
7284e1be UW |
430 | { |
431 | /* "orig_r3" is stored 2 slots after "pc". */ | |
432 | if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM) | |
19ba03f4 | 433 | ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, (gdb_byte *) gregs, |
7284e1be UW |
434 | offsets->pc_offset + 2 * offsets->gpr_size, |
435 | offsets->gpr_size); | |
436 | ||
437 | /* "trap" is stored 8 slots after "pc". */ | |
438 | if (regnum == -1 || regnum == PPC_TRAP_REGNUM) | |
19ba03f4 | 439 | ppc_collect_reg (regcache, PPC_TRAP_REGNUM, (gdb_byte *) gregs, |
7284e1be UW |
440 | offsets->pc_offset + 8 * offsets->gpr_size, |
441 | offsets->gpr_size); | |
442 | } | |
f9be684a AC |
443 | } |
444 | ||
f2db237a AM |
445 | /* Regset descriptions. */ |
446 | static const struct ppc_reg_offsets ppc32_linux_reg_offsets = | |
447 | { | |
448 | /* General-purpose registers. */ | |
449 | /* .r0_offset = */ 0, | |
450 | /* .gpr_size = */ 4, | |
451 | /* .xr_size = */ 4, | |
452 | /* .pc_offset = */ 128, | |
453 | /* .ps_offset = */ 132, | |
454 | /* .cr_offset = */ 152, | |
455 | /* .lr_offset = */ 144, | |
456 | /* .ctr_offset = */ 140, | |
457 | /* .xer_offset = */ 148, | |
458 | /* .mq_offset = */ 156, | |
459 | ||
460 | /* Floating-point registers. */ | |
461 | /* .f0_offset = */ 0, | |
462 | /* .fpscr_offset = */ 256, | |
463 | /* .fpscr_size = */ 8, | |
464 | ||
465 | /* AltiVec registers. */ | |
466 | /* .vr0_offset = */ 0, | |
06caf7d2 CES |
467 | /* .vscr_offset = */ 512 + 12, |
468 | /* .vrsave_offset = */ 528 | |
f2db237a | 469 | }; |
f9be684a | 470 | |
f2db237a AM |
471 | static const struct ppc_reg_offsets ppc64_linux_reg_offsets = |
472 | { | |
473 | /* General-purpose registers. */ | |
474 | /* .r0_offset = */ 0, | |
475 | /* .gpr_size = */ 8, | |
476 | /* .xr_size = */ 8, | |
477 | /* .pc_offset = */ 256, | |
478 | /* .ps_offset = */ 264, | |
479 | /* .cr_offset = */ 304, | |
480 | /* .lr_offset = */ 288, | |
481 | /* .ctr_offset = */ 280, | |
482 | /* .xer_offset = */ 296, | |
483 | /* .mq_offset = */ 312, | |
484 | ||
485 | /* Floating-point registers. */ | |
486 | /* .f0_offset = */ 0, | |
487 | /* .fpscr_offset = */ 256, | |
488 | /* .fpscr_size = */ 8, | |
489 | ||
490 | /* AltiVec registers. */ | |
491 | /* .vr0_offset = */ 0, | |
06caf7d2 CES |
492 | /* .vscr_offset = */ 512 + 12, |
493 | /* .vrsave_offset = */ 528 | |
f2db237a | 494 | }; |
2fda4977 | 495 | |
f2db237a AM |
496 | static const struct regset ppc32_linux_gregset = { |
497 | &ppc32_linux_reg_offsets, | |
7284e1be | 498 | ppc_linux_supply_gregset, |
09424cff | 499 | ppc_linux_collect_gregset |
f9be684a AC |
500 | }; |
501 | ||
f2db237a AM |
502 | static const struct regset ppc64_linux_gregset = { |
503 | &ppc64_linux_reg_offsets, | |
7284e1be | 504 | ppc_linux_supply_gregset, |
09424cff | 505 | ppc_linux_collect_gregset |
f2db237a | 506 | }; |
f9be684a | 507 | |
f2db237a AM |
508 | static const struct regset ppc32_linux_fpregset = { |
509 | &ppc32_linux_reg_offsets, | |
510 | ppc_supply_fpregset, | |
09424cff | 511 | ppc_collect_fpregset |
f9be684a AC |
512 | }; |
513 | ||
06caf7d2 CES |
514 | static const struct regset ppc32_linux_vrregset = { |
515 | &ppc32_linux_reg_offsets, | |
516 | ppc_supply_vrregset, | |
09424cff | 517 | ppc_collect_vrregset |
06caf7d2 CES |
518 | }; |
519 | ||
604c2f83 LM |
520 | static const struct regset ppc32_linux_vsxregset = { |
521 | &ppc32_linux_reg_offsets, | |
522 | ppc_supply_vsxregset, | |
09424cff | 523 | ppc_collect_vsxregset |
604c2f83 LM |
524 | }; |
525 | ||
f2db237a AM |
526 | const struct regset * |
527 | ppc_linux_gregset (int wordsize) | |
2fda4977 | 528 | { |
f2db237a | 529 | return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset; |
2fda4977 DJ |
530 | } |
531 | ||
f2db237a AM |
532 | const struct regset * |
533 | ppc_linux_fpregset (void) | |
534 | { | |
535 | return &ppc32_linux_fpregset; | |
536 | } | |
2fda4977 | 537 | |
5aa82d05 AA |
538 | /* Iterate over supported core file register note sections. */ |
539 | ||
540 | static void | |
541 | ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
542 | iterate_over_regset_sections_cb *cb, | |
543 | void *cb_data, | |
544 | const struct regcache *regcache) | |
545 | { | |
546 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
547 | int have_altivec = tdep->ppc_vr0_regnum != -1; | |
548 | int have_vsx = tdep->ppc_vsr0_upper_regnum != -1; | |
549 | ||
8f0435f7 AA |
550 | if (tdep->wordsize == 4) |
551 | cb (".reg", 48 * 4, &ppc32_linux_gregset, NULL, cb_data); | |
552 | else | |
553 | cb (".reg", 48 * 8, &ppc64_linux_gregset, NULL, cb_data); | |
554 | ||
555 | cb (".reg2", 264, &ppc32_linux_fpregset, NULL, cb_data); | |
5aa82d05 AA |
556 | |
557 | if (have_altivec) | |
8f0435f7 | 558 | cb (".reg-ppc-vmx", 544, &ppc32_linux_vrregset, "ppc Altivec", cb_data); |
5aa82d05 AA |
559 | |
560 | if (have_vsx) | |
8f0435f7 | 561 | cb (".reg-ppc-vsx", 256, &ppc32_linux_vsxregset, "POWER7 VSX", cb_data); |
5aa82d05 AA |
562 | } |
563 | ||
a8f60bfc | 564 | static void |
5366653e | 565 | ppc_linux_sigtramp_cache (struct frame_info *this_frame, |
a8f60bfc AC |
566 | struct trad_frame_cache *this_cache, |
567 | CORE_ADDR func, LONGEST offset, | |
568 | int bias) | |
569 | { | |
570 | CORE_ADDR base; | |
571 | CORE_ADDR regs; | |
572 | CORE_ADDR gpregs; | |
573 | CORE_ADDR fpregs; | |
574 | int i; | |
5366653e | 575 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
a8f60bfc | 576 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 577 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
a8f60bfc | 578 | |
5366653e DJ |
579 | base = get_frame_register_unsigned (this_frame, |
580 | gdbarch_sp_regnum (gdbarch)); | |
581 | if (bias > 0 && get_frame_pc (this_frame) != func) | |
a8f60bfc AC |
582 | /* See below, some signal trampolines increment the stack as their |
583 | first instruction, need to compensate for that. */ | |
584 | base -= bias; | |
585 | ||
586 | /* Find the address of the register buffer pointer. */ | |
587 | regs = base + offset; | |
588 | /* Use that to find the address of the corresponding register | |
589 | buffers. */ | |
e17a4113 | 590 | gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order); |
a8f60bfc AC |
591 | fpregs = gpregs + 48 * tdep->wordsize; |
592 | ||
593 | /* General purpose. */ | |
594 | for (i = 0; i < 32; i++) | |
595 | { | |
596 | int regnum = i + tdep->ppc_gp0_regnum; | |
0df8b418 MS |
597 | trad_frame_set_reg_addr (this_cache, |
598 | regnum, gpregs + i * tdep->wordsize); | |
a8f60bfc | 599 | } |
3e8c568d | 600 | trad_frame_set_reg_addr (this_cache, |
40a6adc1 | 601 | gdbarch_pc_regnum (gdbarch), |
3e8c568d | 602 | gpregs + 32 * tdep->wordsize); |
a8f60bfc AC |
603 | trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, |
604 | gpregs + 35 * tdep->wordsize); | |
605 | trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, | |
606 | gpregs + 36 * tdep->wordsize); | |
607 | trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, | |
608 | gpregs + 37 * tdep->wordsize); | |
609 | trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, | |
610 | gpregs + 38 * tdep->wordsize); | |
611 | ||
7284e1be UW |
612 | if (ppc_linux_trap_reg_p (gdbarch)) |
613 | { | |
614 | trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM, | |
615 | gpregs + 34 * tdep->wordsize); | |
616 | trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM, | |
617 | gpregs + 40 * tdep->wordsize); | |
618 | } | |
619 | ||
60f140f9 PG |
620 | if (ppc_floating_point_unit_p (gdbarch)) |
621 | { | |
622 | /* Floating point registers. */ | |
623 | for (i = 0; i < 32; i++) | |
624 | { | |
40a6adc1 | 625 | int regnum = i + gdbarch_fp0_regnum (gdbarch); |
60f140f9 PG |
626 | trad_frame_set_reg_addr (this_cache, regnum, |
627 | fpregs + i * tdep->wordsize); | |
628 | } | |
629 | trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum, | |
4019046a | 630 | fpregs + 32 * tdep->wordsize); |
60f140f9 | 631 | } |
a8f60bfc AC |
632 | trad_frame_set_id (this_cache, frame_id_build (base, func)); |
633 | } | |
634 | ||
635 | static void | |
636 | ppc32_linux_sigaction_cache_init (const struct tramp_frame *self, | |
5366653e | 637 | struct frame_info *this_frame, |
a8f60bfc AC |
638 | struct trad_frame_cache *this_cache, |
639 | CORE_ADDR func) | |
640 | { | |
5366653e | 641 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
642 | 0xd0 /* Offset to ucontext_t. */ |
643 | + 0x30 /* Offset to .reg. */, | |
644 | 0); | |
645 | } | |
646 | ||
647 | static void | |
648 | ppc64_linux_sigaction_cache_init (const struct tramp_frame *self, | |
5366653e | 649 | struct frame_info *this_frame, |
a8f60bfc AC |
650 | struct trad_frame_cache *this_cache, |
651 | CORE_ADDR func) | |
652 | { | |
5366653e | 653 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
654 | 0x80 /* Offset to ucontext_t. */ |
655 | + 0xe0 /* Offset to .reg. */, | |
656 | 128); | |
657 | } | |
658 | ||
659 | static void | |
660 | ppc32_linux_sighandler_cache_init (const struct tramp_frame *self, | |
5366653e | 661 | struct frame_info *this_frame, |
a8f60bfc AC |
662 | struct trad_frame_cache *this_cache, |
663 | CORE_ADDR func) | |
664 | { | |
5366653e | 665 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
666 | 0x40 /* Offset to ucontext_t. */ |
667 | + 0x1c /* Offset to .reg. */, | |
668 | 0); | |
669 | } | |
670 | ||
671 | static void | |
672 | ppc64_linux_sighandler_cache_init (const struct tramp_frame *self, | |
5366653e | 673 | struct frame_info *this_frame, |
a8f60bfc AC |
674 | struct trad_frame_cache *this_cache, |
675 | CORE_ADDR func) | |
676 | { | |
5366653e | 677 | ppc_linux_sigtramp_cache (this_frame, this_cache, func, |
a8f60bfc AC |
678 | 0x80 /* Offset to struct sigcontext. */ |
679 | + 0x38 /* Offset to .reg. */, | |
680 | 128); | |
681 | } | |
682 | ||
683 | static struct tramp_frame ppc32_linux_sigaction_tramp_frame = { | |
684 | SIGTRAMP_FRAME, | |
685 | 4, | |
686 | { | |
687 | { 0x380000ac, -1 }, /* li r0, 172 */ | |
688 | { 0x44000002, -1 }, /* sc */ | |
689 | { TRAMP_SENTINEL_INSN }, | |
690 | }, | |
691 | ppc32_linux_sigaction_cache_init | |
692 | }; | |
693 | static struct tramp_frame ppc64_linux_sigaction_tramp_frame = { | |
694 | SIGTRAMP_FRAME, | |
695 | 4, | |
696 | { | |
697 | { 0x38210080, -1 }, /* addi r1,r1,128 */ | |
698 | { 0x380000ac, -1 }, /* li r0, 172 */ | |
699 | { 0x44000002, -1 }, /* sc */ | |
700 | { TRAMP_SENTINEL_INSN }, | |
701 | }, | |
702 | ppc64_linux_sigaction_cache_init | |
703 | }; | |
704 | static struct tramp_frame ppc32_linux_sighandler_tramp_frame = { | |
705 | SIGTRAMP_FRAME, | |
706 | 4, | |
707 | { | |
708 | { 0x38000077, -1 }, /* li r0,119 */ | |
709 | { 0x44000002, -1 }, /* sc */ | |
710 | { TRAMP_SENTINEL_INSN }, | |
711 | }, | |
712 | ppc32_linux_sighandler_cache_init | |
713 | }; | |
714 | static struct tramp_frame ppc64_linux_sighandler_tramp_frame = { | |
715 | SIGTRAMP_FRAME, | |
716 | 4, | |
717 | { | |
718 | { 0x38210080, -1 }, /* addi r1,r1,128 */ | |
719 | { 0x38000077, -1 }, /* li r0,119 */ | |
720 | { 0x44000002, -1 }, /* sc */ | |
721 | { TRAMP_SENTINEL_INSN }, | |
722 | }, | |
723 | ppc64_linux_sighandler_cache_init | |
724 | }; | |
725 | ||
7284e1be UW |
726 | /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */ |
727 | int | |
728 | ppc_linux_trap_reg_p (struct gdbarch *gdbarch) | |
729 | { | |
730 | /* If we do not have a target description with registers, then | |
731 | the special registers will not be included in the register set. */ | |
732 | if (!tdesc_has_registers (gdbarch_target_desc (gdbarch))) | |
733 | return 0; | |
734 | ||
735 | /* If we do, then it is safe to check the size. */ | |
736 | return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0 | |
737 | && register_size (gdbarch, PPC_TRAP_REGNUM) > 0; | |
738 | } | |
739 | ||
a96d9b2e SDJ |
740 | /* Return the current system call's number present in the |
741 | r0 register. When the function fails, it returns -1. */ | |
742 | static LONGEST | |
743 | ppc_linux_get_syscall_number (struct gdbarch *gdbarch, | |
744 | ptid_t ptid) | |
745 | { | |
746 | struct regcache *regcache = get_thread_regcache (ptid); | |
747 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
748 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
a96d9b2e SDJ |
749 | |
750 | /* Make sure we're in a 32- or 64-bit machine */ | |
751 | gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8); | |
752 | ||
779bc38e TT |
753 | /* The content of a register */ |
754 | gdb::byte_vector buf (tdep->wordsize); | |
a96d9b2e SDJ |
755 | |
756 | /* Getting the system call number from the register. | |
757 | When dealing with PowerPC architecture, this information | |
758 | is stored at 0th register. */ | |
779bc38e | 759 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf.data ()); |
a96d9b2e | 760 | |
779bc38e | 761 | return extract_signed_integer (buf.data (), tdep->wordsize, byte_order); |
a96d9b2e SDJ |
762 | } |
763 | ||
b4cdae6f WW |
764 | /* PPC process record-replay */ |
765 | ||
766 | static struct linux_record_tdep ppc_linux_record_tdep; | |
767 | static struct linux_record_tdep ppc64_linux_record_tdep; | |
768 | ||
ddeca1df WW |
769 | /* ppc_canonicalize_syscall maps from the native PowerPC Linux set of |
770 | syscall ids into a canonical set of syscall ids used by process | |
771 | record. (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.) | |
772 | Return -1 if this system call is not supported by process record. | |
773 | Otherwise, return the syscall number for preocess reocrd of given | |
774 | SYSCALL. */ | |
775 | ||
b4cdae6f WW |
776 | static enum gdb_syscall |
777 | ppc_canonicalize_syscall (int syscall) | |
778 | { | |
aead7601 SM |
779 | int result = -1; |
780 | ||
b4cdae6f | 781 | if (syscall <= 165) |
aead7601 | 782 | result = syscall; |
b4cdae6f | 783 | else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */ |
aead7601 | 784 | result = syscall + 1; |
b4cdae6f | 785 | else if (syscall >= 192 && syscall <= 197) /* mmap2 */ |
aead7601 | 786 | result = syscall; |
b4cdae6f | 787 | else if (syscall == 208) /* tkill */ |
aead7601 | 788 | result = gdb_sys_tkill; |
b4cdae6f | 789 | else if (syscall >= 207 && syscall <= 220) /* gettid */ |
aead7601 | 790 | result = syscall + 224 - 207; |
b4cdae6f | 791 | else if (syscall >= 234 && syscall <= 239) /* exit_group */ |
aead7601 SM |
792 | result = syscall + 252 - 234; |
793 | else if (syscall >= 240 && syscall <= 248) /* timer_create */ | |
794 | result = syscall += 259 - 240; | |
795 | else if (syscall >= 250 && syscall <= 251) /* tgkill */ | |
796 | result = syscall + 270 - 250; | |
b4cdae6f | 797 | else if (syscall == 336) |
aead7601 | 798 | result = gdb_sys_recv; |
b4cdae6f | 799 | else if (syscall == 337) |
aead7601 | 800 | result = gdb_sys_recvfrom; |
b4cdae6f | 801 | else if (syscall == 342) |
aead7601 SM |
802 | result = gdb_sys_recvmsg; |
803 | ||
804 | return (enum gdb_syscall) result; | |
b4cdae6f WW |
805 | } |
806 | ||
ddeca1df WW |
807 | /* Record registers which might be clobbered during system call. |
808 | Return 0 if successful. */ | |
809 | ||
b4cdae6f WW |
810 | static int |
811 | ppc_linux_syscall_record (struct regcache *regcache) | |
812 | { | |
ac7936df | 813 | struct gdbarch *gdbarch = regcache->arch (); |
b4cdae6f WW |
814 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
815 | ULONGEST scnum; | |
816 | enum gdb_syscall syscall_gdb; | |
817 | int ret; | |
818 | int i; | |
819 | ||
820 | regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum); | |
821 | syscall_gdb = ppc_canonicalize_syscall (scnum); | |
822 | ||
823 | if (syscall_gdb < 0) | |
824 | { | |
825 | printf_unfiltered (_("Process record and replay target doesn't " | |
826 | "support syscall number %d\n"), (int) scnum); | |
827 | return 0; | |
828 | } | |
829 | ||
830 | if (syscall_gdb == gdb_sys_sigreturn | |
831 | || syscall_gdb == gdb_sys_rt_sigreturn) | |
832 | { | |
833 | int i, j; | |
834 | int regsets[] = { tdep->ppc_gp0_regnum, | |
835 | tdep->ppc_fp0_regnum, | |
836 | tdep->ppc_vr0_regnum, | |
837 | tdep->ppc_vsr0_upper_regnum }; | |
838 | ||
839 | for (j = 0; j < 4; j++) | |
840 | { | |
841 | if (regsets[j] == -1) | |
842 | continue; | |
843 | for (i = 0; i < 32; i++) | |
844 | { | |
845 | if (record_full_arch_list_add_reg (regcache, regsets[j] + i)) | |
846 | return -1; | |
847 | } | |
848 | } | |
849 | ||
850 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum)) | |
851 | return -1; | |
852 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum)) | |
853 | return -1; | |
854 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum)) | |
855 | return -1; | |
856 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum)) | |
857 | return -1; | |
858 | ||
859 | return 0; | |
860 | } | |
861 | ||
862 | if (tdep->wordsize == 8) | |
863 | ret = record_linux_system_call (syscall_gdb, regcache, | |
864 | &ppc64_linux_record_tdep); | |
865 | else | |
866 | ret = record_linux_system_call (syscall_gdb, regcache, | |
867 | &ppc_linux_record_tdep); | |
868 | ||
869 | if (ret != 0) | |
870 | return ret; | |
871 | ||
872 | /* Record registers clobbered during syscall. */ | |
873 | for (i = 3; i <= 12; i++) | |
874 | { | |
875 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i)) | |
876 | return -1; | |
877 | } | |
878 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0)) | |
879 | return -1; | |
880 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum)) | |
881 | return -1; | |
882 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum)) | |
883 | return -1; | |
884 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum)) | |
885 | return -1; | |
886 | ||
887 | return 0; | |
888 | } | |
889 | ||
ddeca1df WW |
890 | /* Record registers which might be clobbered during signal handling. |
891 | Return 0 if successful. */ | |
892 | ||
b4cdae6f WW |
893 | static int |
894 | ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache, | |
895 | enum gdb_signal signal) | |
896 | { | |
897 | /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c | |
898 | handle_rt_signal32 in arch/powerpc/kernel/signal_32.c | |
899 | arch/powerpc/include/asm/ptrace.h | |
900 | for details. */ | |
901 | const int SIGNAL_FRAMESIZE = 128; | |
902 | const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512; | |
903 | ULONGEST sp; | |
904 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
905 | int i; | |
906 | ||
907 | for (i = 3; i <= 12; i++) | |
908 | { | |
909 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i)) | |
910 | return -1; | |
911 | } | |
912 | ||
913 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum)) | |
914 | return -1; | |
915 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum)) | |
916 | return -1; | |
917 | if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum)) | |
918 | return -1; | |
919 | if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch))) | |
920 | return -1; | |
921 | if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch))) | |
922 | return -1; | |
923 | ||
924 | /* Record the change in the stack. | |
925 | frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */ | |
926 | regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp); | |
927 | sp -= SIGNAL_FRAMESIZE; | |
928 | sp -= sizeof_rt_sigframe; | |
929 | ||
930 | if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe)) | |
931 | return -1; | |
932 | ||
933 | if (record_full_arch_list_add_end ()) | |
934 | return -1; | |
935 | ||
936 | return 0; | |
937 | } | |
938 | ||
7284e1be UW |
939 | static void |
940 | ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) | |
941 | { | |
ac7936df | 942 | struct gdbarch *gdbarch = regcache->arch (); |
7284e1be UW |
943 | |
944 | regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc); | |
945 | ||
946 | /* Set special TRAP register to -1 to prevent the kernel from | |
947 | messing with the PC we just installed, if we happen to be | |
948 | within an interrupted system call that the kernel wants to | |
949 | restart. | |
950 | ||
951 | Note that after we return from the dummy call, the TRAP and | |
952 | ORIG_R3 registers will be automatically restored, and the | |
953 | kernel continues to restart the system call at this point. */ | |
954 | if (ppc_linux_trap_reg_p (gdbarch)) | |
955 | regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1); | |
956 | } | |
957 | ||
f4d9bade UW |
958 | static int |
959 | ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data) | |
960 | { | |
61012eef | 961 | return startswith (bfd_section_name (abfd, asect), "SPU/"); |
f4d9bade UW |
962 | } |
963 | ||
7284e1be UW |
964 | static const struct target_desc * |
965 | ppc_linux_core_read_description (struct gdbarch *gdbarch, | |
966 | struct target_ops *target, | |
967 | bfd *abfd) | |
968 | { | |
f4d9bade | 969 | asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL); |
7284e1be | 970 | asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx"); |
604c2f83 | 971 | asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx"); |
7284e1be UW |
972 | asection *section = bfd_get_section_by_name (abfd, ".reg"); |
973 | if (! section) | |
974 | return NULL; | |
975 | ||
976 | switch (bfd_section_size (abfd, section)) | |
977 | { | |
978 | case 48 * 4: | |
f4d9bade UW |
979 | if (cell) |
980 | return tdesc_powerpc_cell32l; | |
981 | else if (vsx) | |
604c2f83 LM |
982 | return tdesc_powerpc_vsx32l; |
983 | else if (altivec) | |
984 | return tdesc_powerpc_altivec32l; | |
985 | else | |
986 | return tdesc_powerpc_32l; | |
7284e1be UW |
987 | |
988 | case 48 * 8: | |
f4d9bade UW |
989 | if (cell) |
990 | return tdesc_powerpc_cell64l; | |
991 | else if (vsx) | |
604c2f83 LM |
992 | return tdesc_powerpc_vsx64l; |
993 | else if (altivec) | |
994 | return tdesc_powerpc_altivec64l; | |
995 | else | |
996 | return tdesc_powerpc_64l; | |
7284e1be UW |
997 | |
998 | default: | |
999 | return NULL; | |
1000 | } | |
1001 | } | |
1002 | ||
591a12a1 UW |
1003 | |
1004 | /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in | |
1005 | gdbarch.h. This implementation is used for the ELFv2 ABI only. */ | |
1006 | ||
1007 | static void | |
1008 | ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym) | |
1009 | { | |
1010 | elf_symbol_type *elf_sym = (elf_symbol_type *)sym; | |
1011 | ||
1012 | /* If the symbol is marked as having a local entry point, set a target | |
1013 | flag in the msymbol. We currently only support local entry point | |
1014 | offsets of 8 bytes, which is the only entry point offset ever used | |
1015 | by current compilers. If/when other offsets are ever used, we will | |
1016 | have to use additional target flag bits to store them. */ | |
1017 | switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other)) | |
1018 | { | |
1019 | default: | |
1020 | break; | |
1021 | case 8: | |
1022 | MSYMBOL_TARGET_FLAG_1 (msym) = 1; | |
1023 | break; | |
1024 | } | |
1025 | } | |
1026 | ||
1027 | /* Implementation of `gdbarch_skip_entrypoint', as defined in | |
1028 | gdbarch.h. This implementation is used for the ELFv2 ABI only. */ | |
1029 | ||
1030 | static CORE_ADDR | |
1031 | ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1032 | { | |
1033 | struct bound_minimal_symbol fun; | |
1034 | int local_entry_offset = 0; | |
1035 | ||
1036 | fun = lookup_minimal_symbol_by_pc (pc); | |
1037 | if (fun.minsym == NULL) | |
1038 | return pc; | |
1039 | ||
1040 | /* See ppc_elfv2_elf_make_msymbol_special for how local entry point | |
1041 | offset values are encoded. */ | |
1042 | if (MSYMBOL_TARGET_FLAG_1 (fun.minsym)) | |
1043 | local_entry_offset = 8; | |
1044 | ||
77e371c0 TT |
1045 | if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc |
1046 | && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset) | |
1047 | return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset; | |
591a12a1 UW |
1048 | |
1049 | return pc; | |
1050 | } | |
1051 | ||
55aa24fb SDJ |
1052 | /* Implementation of `gdbarch_stap_is_single_operand', as defined in |
1053 | gdbarch.h. */ | |
1054 | ||
1055 | static int | |
1056 | ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s) | |
1057 | { | |
1058 | return (*s == 'i' /* Literal number. */ | |
1059 | || (isdigit (*s) && s[1] == '(' | |
1060 | && isdigit (s[2])) /* Displacement. */ | |
1061 | || (*s == '(' && isdigit (s[1])) /* Register indirection. */ | |
1062 | || isdigit (*s)); /* Register value. */ | |
1063 | } | |
1064 | ||
1065 | /* Implementation of `gdbarch_stap_parse_special_token', as defined in | |
1066 | gdbarch.h. */ | |
1067 | ||
1068 | static int | |
1069 | ppc_stap_parse_special_token (struct gdbarch *gdbarch, | |
1070 | struct stap_parse_info *p) | |
1071 | { | |
1072 | if (isdigit (*p->arg)) | |
1073 | { | |
1074 | /* This temporary pointer is needed because we have to do a lookahead. | |
1075 | We could be dealing with a register displacement, and in such case | |
1076 | we would not need to do anything. */ | |
1077 | const char *s = p->arg; | |
1078 | char *regname; | |
1079 | int len; | |
1080 | struct stoken str; | |
1081 | ||
1082 | while (isdigit (*s)) | |
1083 | ++s; | |
1084 | ||
1085 | if (*s == '(') | |
1086 | { | |
1087 | /* It is a register displacement indeed. Returning 0 means we are | |
1088 | deferring the treatment of this case to the generic parser. */ | |
1089 | return 0; | |
1090 | } | |
1091 | ||
1092 | len = s - p->arg; | |
224c3ddb | 1093 | regname = (char *) alloca (len + 2); |
55aa24fb SDJ |
1094 | regname[0] = 'r'; |
1095 | ||
1096 | strncpy (regname + 1, p->arg, len); | |
1097 | ++len; | |
1098 | regname[len] = '\0'; | |
1099 | ||
1100 | if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1) | |
1101 | error (_("Invalid register name `%s' on expression `%s'."), | |
1102 | regname, p->saved_arg); | |
1103 | ||
410a0ff2 | 1104 | write_exp_elt_opcode (&p->pstate, OP_REGISTER); |
55aa24fb SDJ |
1105 | str.ptr = regname; |
1106 | str.length = len; | |
410a0ff2 SDJ |
1107 | write_exp_string (&p->pstate, str); |
1108 | write_exp_elt_opcode (&p->pstate, OP_REGISTER); | |
55aa24fb SDJ |
1109 | |
1110 | p->arg = s; | |
1111 | } | |
1112 | else | |
1113 | { | |
1114 | /* All the other tokens should be handled correctly by the generic | |
1115 | parser. */ | |
1116 | return 0; | |
1117 | } | |
1118 | ||
1119 | return 1; | |
1120 | } | |
cc5f0d61 UW |
1121 | |
1122 | /* Cell/B.E. active SPE context tracking support. */ | |
1123 | ||
1124 | static struct objfile *spe_context_objfile = NULL; | |
1125 | static CORE_ADDR spe_context_lm_addr = 0; | |
1126 | static CORE_ADDR spe_context_offset = 0; | |
1127 | ||
1128 | static ptid_t spe_context_cache_ptid; | |
1129 | static CORE_ADDR spe_context_cache_address; | |
1130 | ||
1131 | /* Hook into inferior_created, solib_loaded, and solib_unloaded observers | |
1132 | to track whether we've loaded a version of libspe2 (as static or dynamic | |
1133 | library) that provides the __spe_current_active_context variable. */ | |
1134 | static void | |
1135 | ppc_linux_spe_context_lookup (struct objfile *objfile) | |
1136 | { | |
3b7344d5 | 1137 | struct bound_minimal_symbol sym; |
cc5f0d61 UW |
1138 | |
1139 | if (!objfile) | |
1140 | { | |
1141 | spe_context_objfile = NULL; | |
1142 | spe_context_lm_addr = 0; | |
1143 | spe_context_offset = 0; | |
1144 | spe_context_cache_ptid = minus_one_ptid; | |
1145 | spe_context_cache_address = 0; | |
1146 | return; | |
1147 | } | |
1148 | ||
1149 | sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile); | |
3b7344d5 | 1150 | if (sym.minsym) |
cc5f0d61 UW |
1151 | { |
1152 | spe_context_objfile = objfile; | |
1153 | spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile); | |
ef36892e | 1154 | spe_context_offset = MSYMBOL_VALUE_RAW_ADDRESS (sym.minsym); |
cc5f0d61 UW |
1155 | spe_context_cache_ptid = minus_one_ptid; |
1156 | spe_context_cache_address = 0; | |
1157 | return; | |
1158 | } | |
1159 | } | |
1160 | ||
1161 | static void | |
1162 | ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty) | |
1163 | { | |
1164 | struct objfile *objfile; | |
1165 | ||
1166 | ppc_linux_spe_context_lookup (NULL); | |
1167 | ALL_OBJFILES (objfile) | |
1168 | ppc_linux_spe_context_lookup (objfile); | |
1169 | } | |
1170 | ||
1171 | static void | |
1172 | ppc_linux_spe_context_solib_loaded (struct so_list *so) | |
1173 | { | |
1174 | if (strstr (so->so_original_name, "/libspe") != NULL) | |
1175 | { | |
7e559477 | 1176 | solib_read_symbols (so, 0); |
cc5f0d61 UW |
1177 | ppc_linux_spe_context_lookup (so->objfile); |
1178 | } | |
1179 | } | |
1180 | ||
1181 | static void | |
1182 | ppc_linux_spe_context_solib_unloaded (struct so_list *so) | |
1183 | { | |
1184 | if (so->objfile == spe_context_objfile) | |
1185 | ppc_linux_spe_context_lookup (NULL); | |
1186 | } | |
1187 | ||
1188 | /* Retrieve contents of the N'th element in the current thread's | |
1189 | linked SPE context list into ID and NPC. Return the address of | |
1190 | said context element, or 0 if not found. */ | |
1191 | static CORE_ADDR | |
1192 | ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order, | |
1193 | int n, int *id, unsigned int *npc) | |
1194 | { | |
1195 | CORE_ADDR spe_context = 0; | |
1196 | gdb_byte buf[16]; | |
1197 | int i; | |
1198 | ||
1199 | /* Quick exit if we have not found __spe_current_active_context. */ | |
1200 | if (!spe_context_objfile) | |
1201 | return 0; | |
1202 | ||
1203 | /* Look up cached address of thread-local variable. */ | |
1204 | if (!ptid_equal (spe_context_cache_ptid, inferior_ptid)) | |
1205 | { | |
1206 | struct target_ops *target = ¤t_target; | |
cc5f0d61 | 1207 | |
492d29ea | 1208 | TRY |
cc5f0d61 UW |
1209 | { |
1210 | /* We do not call target_translate_tls_address here, because | |
1211 | svr4_fetch_objfile_link_map may invalidate the frame chain, | |
1212 | which must not do while inside a frame sniffer. | |
1213 | ||
1214 | Instead, we have cached the lm_addr value, and use that to | |
1215 | directly call the target's to_get_thread_local_address. */ | |
1216 | spe_context_cache_address | |
1217 | = target->to_get_thread_local_address (target, inferior_ptid, | |
1218 | spe_context_lm_addr, | |
1219 | spe_context_offset); | |
1220 | spe_context_cache_ptid = inferior_ptid; | |
1221 | } | |
1222 | ||
492d29ea PA |
1223 | CATCH (ex, RETURN_MASK_ERROR) |
1224 | { | |
1225 | return 0; | |
1226 | } | |
1227 | END_CATCH | |
cc5f0d61 UW |
1228 | } |
1229 | ||
1230 | /* Read variable value. */ | |
1231 | if (target_read_memory (spe_context_cache_address, buf, wordsize) == 0) | |
1232 | spe_context = extract_unsigned_integer (buf, wordsize, byte_order); | |
1233 | ||
1234 | /* Cyle through to N'th linked list element. */ | |
1235 | for (i = 0; i < n && spe_context; i++) | |
1236 | if (target_read_memory (spe_context + align_up (12, wordsize), | |
1237 | buf, wordsize) == 0) | |
1238 | spe_context = extract_unsigned_integer (buf, wordsize, byte_order); | |
1239 | else | |
1240 | spe_context = 0; | |
1241 | ||
1242 | /* Read current context. */ | |
1243 | if (spe_context | |
1244 | && target_read_memory (spe_context, buf, 12) != 0) | |
1245 | spe_context = 0; | |
1246 | ||
1247 | /* Extract data elements. */ | |
1248 | if (spe_context) | |
1249 | { | |
1250 | if (id) | |
1251 | *id = extract_signed_integer (buf, 4, byte_order); | |
1252 | if (npc) | |
1253 | *npc = extract_unsigned_integer (buf + 4, 4, byte_order); | |
1254 | } | |
1255 | ||
1256 | return spe_context; | |
1257 | } | |
1258 | ||
1259 | ||
1260 | /* Cell/B.E. cross-architecture unwinder support. */ | |
1261 | ||
1262 | struct ppu2spu_cache | |
1263 | { | |
1264 | struct frame_id frame_id; | |
daf6667d | 1265 | readonly_detached_regcache *regcache; |
cc5f0d61 UW |
1266 | }; |
1267 | ||
1268 | static struct gdbarch * | |
1269 | ppu2spu_prev_arch (struct frame_info *this_frame, void **this_cache) | |
1270 | { | |
19ba03f4 | 1271 | struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache; |
ac7936df | 1272 | return cache->regcache->arch (); |
cc5f0d61 UW |
1273 | } |
1274 | ||
1275 | static void | |
1276 | ppu2spu_this_id (struct frame_info *this_frame, | |
1277 | void **this_cache, struct frame_id *this_id) | |
1278 | { | |
19ba03f4 | 1279 | struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache; |
cc5f0d61 UW |
1280 | *this_id = cache->frame_id; |
1281 | } | |
1282 | ||
1283 | static struct value * | |
1284 | ppu2spu_prev_register (struct frame_info *this_frame, | |
1285 | void **this_cache, int regnum) | |
1286 | { | |
19ba03f4 | 1287 | struct ppu2spu_cache *cache = (struct ppu2spu_cache *) *this_cache; |
ac7936df | 1288 | struct gdbarch *gdbarch = cache->regcache->arch (); |
cc5f0d61 UW |
1289 | gdb_byte *buf; |
1290 | ||
224c3ddb | 1291 | buf = (gdb_byte *) alloca (register_size (gdbarch, regnum)); |
a536c6d7 | 1292 | |
d679c21a | 1293 | cache->regcache->cooked_read (regnum, buf); |
cc5f0d61 UW |
1294 | return frame_unwind_got_bytes (this_frame, regnum, buf); |
1295 | } | |
1296 | ||
1297 | struct ppu2spu_data | |
1298 | { | |
1299 | struct gdbarch *gdbarch; | |
1300 | int id; | |
1301 | unsigned int npc; | |
1302 | gdb_byte gprs[128*16]; | |
1303 | }; | |
1304 | ||
f486487f | 1305 | static enum register_status |
cc5f0d61 UW |
1306 | ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf) |
1307 | { | |
19ba03f4 | 1308 | struct ppu2spu_data *data = (struct ppu2spu_data *) src; |
cc5f0d61 UW |
1309 | enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch); |
1310 | ||
1311 | if (regnum >= 0 && regnum < SPU_NUM_GPRS) | |
1312 | memcpy (buf, data->gprs + 16*regnum, 16); | |
1313 | else if (regnum == SPU_ID_REGNUM) | |
1314 | store_unsigned_integer (buf, 4, byte_order, data->id); | |
1315 | else if (regnum == SPU_PC_REGNUM) | |
1316 | store_unsigned_integer (buf, 4, byte_order, data->npc); | |
1317 | else | |
a536c6d7 | 1318 | return REG_UNAVAILABLE; |
cc5f0d61 | 1319 | |
a536c6d7 | 1320 | return REG_VALID; |
cc5f0d61 UW |
1321 | } |
1322 | ||
1323 | static int | |
1324 | ppu2spu_sniffer (const struct frame_unwind *self, | |
1325 | struct frame_info *this_frame, void **this_prologue_cache) | |
1326 | { | |
1327 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
1328 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1329 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
1330 | struct ppu2spu_data data; | |
1331 | struct frame_info *fi; | |
1332 | CORE_ADDR base, func, backchain, spe_context; | |
1333 | gdb_byte buf[8]; | |
1334 | int n = 0; | |
1335 | ||
1336 | /* Count the number of SPU contexts already in the frame chain. */ | |
1337 | for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi)) | |
1338 | if (get_frame_type (fi) == ARCH_FRAME | |
1339 | && gdbarch_bfd_arch_info (get_frame_arch (fi))->arch == bfd_arch_spu) | |
1340 | n++; | |
1341 | ||
1342 | base = get_frame_sp (this_frame); | |
1343 | func = get_frame_pc (this_frame); | |
1344 | if (target_read_memory (base, buf, tdep->wordsize)) | |
1345 | return 0; | |
1346 | backchain = extract_unsigned_integer (buf, tdep->wordsize, byte_order); | |
1347 | ||
1348 | spe_context = ppc_linux_spe_context (tdep->wordsize, byte_order, | |
1349 | n, &data.id, &data.npc); | |
1350 | if (spe_context && base <= spe_context && spe_context < backchain) | |
1351 | { | |
1352 | char annex[32]; | |
1353 | ||
1354 | /* Find gdbarch for SPU. */ | |
1355 | struct gdbarch_info info; | |
1356 | gdbarch_info_init (&info); | |
1357 | info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu); | |
1358 | info.byte_order = BFD_ENDIAN_BIG; | |
1359 | info.osabi = GDB_OSABI_LINUX; | |
0dba2a6c | 1360 | info.id = &data.id; |
cc5f0d61 UW |
1361 | data.gdbarch = gdbarch_find_by_info (info); |
1362 | if (!data.gdbarch) | |
1363 | return 0; | |
1364 | ||
1365 | xsnprintf (annex, sizeof annex, "%d/regs", data.id); | |
1366 | if (target_read (¤t_target, TARGET_OBJECT_SPU, annex, | |
1367 | data.gprs, 0, sizeof data.gprs) | |
1368 | == sizeof data.gprs) | |
1369 | { | |
1370 | struct ppu2spu_cache *cache | |
1371 | = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache); | |
daf6667d YQ |
1372 | std::unique_ptr<readonly_detached_regcache> regcache |
1373 | (new readonly_detached_regcache (data.gdbarch, | |
1374 | ppu2spu_unwind_register, | |
1375 | &data)); | |
cc5f0d61 UW |
1376 | |
1377 | cache->frame_id = frame_id_build (base, func); | |
9ac86b52 | 1378 | cache->regcache = regcache.release (); |
cc5f0d61 UW |
1379 | *this_prologue_cache = cache; |
1380 | return 1; | |
1381 | } | |
1382 | } | |
1383 | ||
1384 | return 0; | |
1385 | } | |
1386 | ||
1387 | static void | |
1388 | ppu2spu_dealloc_cache (struct frame_info *self, void *this_cache) | |
1389 | { | |
19ba03f4 | 1390 | struct ppu2spu_cache *cache = (struct ppu2spu_cache *) this_cache; |
c0e383c6 | 1391 | delete cache->regcache; |
cc5f0d61 UW |
1392 | } |
1393 | ||
1394 | static const struct frame_unwind ppu2spu_unwind = { | |
1395 | ARCH_FRAME, | |
8fbca658 | 1396 | default_frame_unwind_stop_reason, |
cc5f0d61 UW |
1397 | ppu2spu_this_id, |
1398 | ppu2spu_prev_register, | |
1399 | NULL, | |
1400 | ppu2spu_sniffer, | |
1401 | ppu2spu_dealloc_cache, | |
1402 | ppu2spu_prev_arch, | |
1403 | }; | |
1404 | ||
ddeca1df WW |
1405 | /* Initialize linux_record_tdep if not initialized yet. |
1406 | WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively. | |
1407 | Sizes of data structures are initialized accordingly. */ | |
b4cdae6f WW |
1408 | |
1409 | static void | |
1410 | ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep, | |
1411 | int wordsize) | |
1412 | { | |
1413 | /* Simply return if it had been initialized. */ | |
1414 | if (record_tdep->size_pointer != 0) | |
1415 | return; | |
1416 | ||
1417 | /* These values are the size of the type that will be used in a system | |
1418 | call. They are obtained from Linux Kernel source. */ | |
1419 | ||
1420 | if (wordsize == 8) | |
1421 | { | |
1422 | record_tdep->size_pointer = 8; | |
1423 | record_tdep->size__old_kernel_stat = 32; | |
1424 | record_tdep->size_tms = 32; | |
1425 | record_tdep->size_loff_t = 8; | |
1426 | record_tdep->size_flock = 32; | |
1427 | record_tdep->size_oldold_utsname = 45; | |
1428 | record_tdep->size_ustat = 32; | |
7571f7f2 MK |
1429 | record_tdep->size_old_sigaction = 32; |
1430 | record_tdep->size_old_sigset_t = 8; | |
b4cdae6f WW |
1431 | record_tdep->size_rlimit = 16; |
1432 | record_tdep->size_rusage = 144; | |
1433 | record_tdep->size_timeval = 16; | |
1434 | record_tdep->size_timezone = 8; | |
1435 | record_tdep->size_old_gid_t = 4; | |
1436 | record_tdep->size_old_uid_t = 4; | |
1437 | record_tdep->size_fd_set = 128; | |
72aded86 | 1438 | record_tdep->size_old_dirent = 280; |
b4cdae6f WW |
1439 | record_tdep->size_statfs = 120; |
1440 | record_tdep->size_statfs64 = 120; | |
1441 | record_tdep->size_sockaddr = 16; | |
1442 | record_tdep->size_int = 4; | |
1443 | record_tdep->size_long = 8; | |
1444 | record_tdep->size_ulong = 8; | |
1445 | record_tdep->size_msghdr = 56; | |
1446 | record_tdep->size_itimerval = 32; | |
1447 | record_tdep->size_stat = 144; | |
1448 | record_tdep->size_old_utsname = 325; | |
1449 | record_tdep->size_sysinfo = 112; | |
1450 | record_tdep->size_msqid_ds = 120; | |
1451 | record_tdep->size_shmid_ds = 112; | |
1452 | record_tdep->size_new_utsname = 390; | |
1453 | record_tdep->size_timex = 208; | |
1454 | record_tdep->size_mem_dqinfo = 24; | |
1455 | record_tdep->size_if_dqblk = 72; | |
1456 | record_tdep->size_fs_quota_stat = 80; | |
1457 | record_tdep->size_timespec = 16; | |
1458 | record_tdep->size_pollfd = 8; | |
1459 | record_tdep->size_NFS_FHSIZE = 32; | |
1460 | record_tdep->size_knfsd_fh = 132; | |
c28ebe25 | 1461 | record_tdep->size_TASK_COMM_LEN = 16; |
7571f7f2 MK |
1462 | record_tdep->size_sigaction = 32; |
1463 | record_tdep->size_sigset_t = 8; | |
b4cdae6f WW |
1464 | record_tdep->size_siginfo_t = 128; |
1465 | record_tdep->size_cap_user_data_t = 8; | |
1466 | record_tdep->size_stack_t = 24; | |
1467 | record_tdep->size_off_t = 8; | |
1468 | record_tdep->size_stat64 = 104; | |
1469 | record_tdep->size_gid_t = 4; | |
1470 | record_tdep->size_uid_t = 4; | |
1471 | record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */ | |
1472 | record_tdep->size_flock64 = 32; | |
1473 | record_tdep->size_io_event = 32; | |
1474 | record_tdep->size_iocb = 64; | |
1475 | record_tdep->size_epoll_event = 16; | |
1476 | record_tdep->size_itimerspec = 32; | |
1477 | record_tdep->size_mq_attr = 64; | |
b4cdae6f WW |
1478 | record_tdep->size_termios = 44; |
1479 | record_tdep->size_pid_t = 4; | |
1480 | record_tdep->size_winsize = 8; | |
1481 | record_tdep->size_serial_struct = 72; | |
1482 | record_tdep->size_serial_icounter_struct = 80; | |
1483 | record_tdep->size_size_t = 8; | |
1484 | record_tdep->size_iovec = 16; | |
b80d067f | 1485 | record_tdep->size_time_t = 8; |
b4cdae6f WW |
1486 | } |
1487 | else if (wordsize == 4) | |
1488 | { | |
1489 | record_tdep->size_pointer = 4; | |
1490 | record_tdep->size__old_kernel_stat = 32; | |
1491 | record_tdep->size_tms = 16; | |
1492 | record_tdep->size_loff_t = 8; | |
1493 | record_tdep->size_flock = 16; | |
1494 | record_tdep->size_oldold_utsname = 45; | |
1495 | record_tdep->size_ustat = 20; | |
7571f7f2 MK |
1496 | record_tdep->size_old_sigaction = 16; |
1497 | record_tdep->size_old_sigset_t = 4; | |
b4cdae6f WW |
1498 | record_tdep->size_rlimit = 8; |
1499 | record_tdep->size_rusage = 72; | |
1500 | record_tdep->size_timeval = 8; | |
1501 | record_tdep->size_timezone = 8; | |
1502 | record_tdep->size_old_gid_t = 4; | |
1503 | record_tdep->size_old_uid_t = 4; | |
1504 | record_tdep->size_fd_set = 128; | |
72aded86 | 1505 | record_tdep->size_old_dirent = 268; |
b4cdae6f WW |
1506 | record_tdep->size_statfs = 64; |
1507 | record_tdep->size_statfs64 = 88; | |
1508 | record_tdep->size_sockaddr = 16; | |
1509 | record_tdep->size_int = 4; | |
1510 | record_tdep->size_long = 4; | |
1511 | record_tdep->size_ulong = 4; | |
1512 | record_tdep->size_msghdr = 28; | |
1513 | record_tdep->size_itimerval = 16; | |
1514 | record_tdep->size_stat = 88; | |
1515 | record_tdep->size_old_utsname = 325; | |
1516 | record_tdep->size_sysinfo = 64; | |
1517 | record_tdep->size_msqid_ds = 68; | |
1518 | record_tdep->size_shmid_ds = 60; | |
1519 | record_tdep->size_new_utsname = 390; | |
1520 | record_tdep->size_timex = 128; | |
1521 | record_tdep->size_mem_dqinfo = 24; | |
1522 | record_tdep->size_if_dqblk = 72; | |
1523 | record_tdep->size_fs_quota_stat = 80; | |
1524 | record_tdep->size_timespec = 8; | |
1525 | record_tdep->size_pollfd = 8; | |
1526 | record_tdep->size_NFS_FHSIZE = 32; | |
1527 | record_tdep->size_knfsd_fh = 132; | |
c28ebe25 | 1528 | record_tdep->size_TASK_COMM_LEN = 16; |
7571f7f2 MK |
1529 | record_tdep->size_sigaction = 20; |
1530 | record_tdep->size_sigset_t = 8; | |
b4cdae6f WW |
1531 | record_tdep->size_siginfo_t = 128; |
1532 | record_tdep->size_cap_user_data_t = 4; | |
1533 | record_tdep->size_stack_t = 12; | |
1534 | record_tdep->size_off_t = 4; | |
1535 | record_tdep->size_stat64 = 104; | |
1536 | record_tdep->size_gid_t = 4; | |
1537 | record_tdep->size_uid_t = 4; | |
1538 | record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */ | |
1539 | record_tdep->size_flock64 = 32; | |
1540 | record_tdep->size_io_event = 32; | |
1541 | record_tdep->size_iocb = 64; | |
1542 | record_tdep->size_epoll_event = 16; | |
1543 | record_tdep->size_itimerspec = 16; | |
1544 | record_tdep->size_mq_attr = 32; | |
b4cdae6f WW |
1545 | record_tdep->size_termios = 44; |
1546 | record_tdep->size_pid_t = 4; | |
1547 | record_tdep->size_winsize = 8; | |
1548 | record_tdep->size_serial_struct = 60; | |
1549 | record_tdep->size_serial_icounter_struct = 80; | |
1550 | record_tdep->size_size_t = 4; | |
1551 | record_tdep->size_iovec = 8; | |
b80d067f | 1552 | record_tdep->size_time_t = 4; |
b4cdae6f WW |
1553 | } |
1554 | else | |
1555 | internal_error (__FILE__, __LINE__, _("unexpected wordsize")); | |
1556 | ||
1557 | /* These values are the second argument of system call "sys_fcntl" | |
1558 | and "sys_fcntl64". They are obtained from Linux Kernel source. */ | |
1559 | record_tdep->fcntl_F_GETLK = 5; | |
1560 | record_tdep->fcntl_F_GETLK64 = 12; | |
1561 | record_tdep->fcntl_F_SETLK64 = 13; | |
1562 | record_tdep->fcntl_F_SETLKW64 = 14; | |
1563 | ||
1564 | record_tdep->arg1 = PPC_R0_REGNUM + 3; | |
1565 | record_tdep->arg2 = PPC_R0_REGNUM + 4; | |
1566 | record_tdep->arg3 = PPC_R0_REGNUM + 5; | |
1567 | record_tdep->arg4 = PPC_R0_REGNUM + 6; | |
1568 | record_tdep->arg5 = PPC_R0_REGNUM + 7; | |
1569 | record_tdep->arg6 = PPC_R0_REGNUM + 8; | |
1570 | ||
1571 | /* These values are the second argument of system call "sys_ioctl". | |
1572 | They are obtained from Linux Kernel source. | |
1573 | See arch/powerpc/include/uapi/asm/ioctls.h. */ | |
1574 | record_tdep->ioctl_TCGETS = 0x403c7413; | |
1575 | record_tdep->ioctl_TCSETS = 0x803c7414; | |
1576 | record_tdep->ioctl_TCSETSW = 0x803c7415; | |
1577 | record_tdep->ioctl_TCSETSF = 0x803c7416; | |
1578 | record_tdep->ioctl_TCGETA = 0x40147417; | |
1579 | record_tdep->ioctl_TCSETA = 0x80147418; | |
1580 | record_tdep->ioctl_TCSETAW = 0x80147419; | |
1581 | record_tdep->ioctl_TCSETAF = 0x8014741c; | |
1582 | record_tdep->ioctl_TCSBRK = 0x2000741d; | |
1583 | record_tdep->ioctl_TCXONC = 0x2000741e; | |
1584 | record_tdep->ioctl_TCFLSH = 0x2000741f; | |
1585 | record_tdep->ioctl_TIOCEXCL = 0x540c; | |
1586 | record_tdep->ioctl_TIOCNXCL = 0x540d; | |
1587 | record_tdep->ioctl_TIOCSCTTY = 0x540e; | |
1588 | record_tdep->ioctl_TIOCGPGRP = 0x40047477; | |
1589 | record_tdep->ioctl_TIOCSPGRP = 0x80047476; | |
1590 | record_tdep->ioctl_TIOCOUTQ = 0x40047473; | |
1591 | record_tdep->ioctl_TIOCSTI = 0x5412; | |
1592 | record_tdep->ioctl_TIOCGWINSZ = 0x40087468; | |
1593 | record_tdep->ioctl_TIOCSWINSZ = 0x80087467; | |
1594 | record_tdep->ioctl_TIOCMGET = 0x5415; | |
1595 | record_tdep->ioctl_TIOCMBIS = 0x5416; | |
1596 | record_tdep->ioctl_TIOCMBIC = 0x5417; | |
1597 | record_tdep->ioctl_TIOCMSET = 0x5418; | |
1598 | record_tdep->ioctl_TIOCGSOFTCAR = 0x5419; | |
1599 | record_tdep->ioctl_TIOCSSOFTCAR = 0x541a; | |
1600 | record_tdep->ioctl_FIONREAD = 0x4004667f; | |
1601 | record_tdep->ioctl_TIOCINQ = 0x4004667f; | |
1602 | record_tdep->ioctl_TIOCLINUX = 0x541c; | |
1603 | record_tdep->ioctl_TIOCCONS = 0x541d; | |
1604 | record_tdep->ioctl_TIOCGSERIAL = 0x541e; | |
1605 | record_tdep->ioctl_TIOCSSERIAL = 0x541f; | |
1606 | record_tdep->ioctl_TIOCPKT = 0x5420; | |
1607 | record_tdep->ioctl_FIONBIO = 0x8004667e; | |
1608 | record_tdep->ioctl_TIOCNOTTY = 0x5422; | |
1609 | record_tdep->ioctl_TIOCSETD = 0x5423; | |
1610 | record_tdep->ioctl_TIOCGETD = 0x5424; | |
1611 | record_tdep->ioctl_TCSBRKP = 0x5425; | |
1612 | record_tdep->ioctl_TIOCSBRK = 0x5427; | |
1613 | record_tdep->ioctl_TIOCCBRK = 0x5428; | |
1614 | record_tdep->ioctl_TIOCGSID = 0x5429; | |
1615 | record_tdep->ioctl_TIOCGPTN = 0x40045430; | |
1616 | record_tdep->ioctl_TIOCSPTLCK = 0x80045431; | |
1617 | record_tdep->ioctl_FIONCLEX = 0x20006602; | |
1618 | record_tdep->ioctl_FIOCLEX = 0x20006601; | |
1619 | record_tdep->ioctl_FIOASYNC = 0x8004667d; | |
1620 | record_tdep->ioctl_TIOCSERCONFIG = 0x5453; | |
1621 | record_tdep->ioctl_TIOCSERGWILD = 0x5454; | |
1622 | record_tdep->ioctl_TIOCSERSWILD = 0x5455; | |
1623 | record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456; | |
1624 | record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457; | |
1625 | record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458; | |
1626 | record_tdep->ioctl_TIOCSERGETLSR = 0x5459; | |
1627 | record_tdep->ioctl_TIOCSERGETMULTI = 0x545a; | |
1628 | record_tdep->ioctl_TIOCSERSETMULTI = 0x545b; | |
1629 | record_tdep->ioctl_TIOCMIWAIT = 0x545c; | |
1630 | record_tdep->ioctl_TIOCGICOUNT = 0x545d; | |
1631 | record_tdep->ioctl_FIOQSIZE = 0x40086680; | |
1632 | } | |
cc5f0d61 | 1633 | |
00d5215e UW |
1634 | /* Return a floating-point format for a floating-point variable of |
1635 | length LEN in bits. If non-NULL, NAME is the name of its type. | |
1636 | If no suitable type is found, return NULL. */ | |
1637 | ||
1638 | const struct floatformat ** | |
1639 | ppc_floatformat_for_type (struct gdbarch *gdbarch, | |
1640 | const char *name, int len) | |
1641 | { | |
1642 | if (len == 128 && name) | |
ed0f4273 UW |
1643 | { |
1644 | if (strcmp (name, "__float128") == 0 | |
1645 | || strcmp (name, "_Float128") == 0 | |
1646 | || strcmp (name, "_Float64x") == 0 | |
1647 | || strcmp (name, "complex _Float128") == 0 | |
1648 | || strcmp (name, "complex _Float64x") == 0) | |
1649 | return floatformats_ia64_quad; | |
1650 | ||
1651 | if (strcmp (name, "__ibm128") == 0) | |
1652 | return floatformats_ibm_long_double; | |
1653 | } | |
00d5215e UW |
1654 | |
1655 | return default_floatformat_for_type (gdbarch, name, len); | |
1656 | } | |
1657 | ||
7b112f9c JT |
1658 | static void |
1659 | ppc_linux_init_abi (struct gdbarch_info info, | |
1660 | struct gdbarch *gdbarch) | |
1661 | { | |
1662 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
0dba2a6c | 1663 | struct tdesc_arch_data *tdesc_data = info.tdesc_data; |
05c0465e SDJ |
1664 | static const char *const stap_integer_prefixes[] = { "i", NULL }; |
1665 | static const char *const stap_register_indirection_prefixes[] = { "(", | |
1666 | NULL }; | |
1667 | static const char *const stap_register_indirection_suffixes[] = { ")", | |
1668 | NULL }; | |
7b112f9c | 1669 | |
a5ee0f0c PA |
1670 | linux_init_abi (info, gdbarch); |
1671 | ||
b14d30e1 | 1672 | /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where |
ed0f4273 UW |
1673 | 128-bit, they can be either IBM long double or IEEE quad long double. |
1674 | The 64-bit long double case will be detected automatically using | |
1675 | the size specified in debug info. We use a .gnu.attribute flag | |
1676 | to distinguish between the IBM long double and IEEE quad cases. */ | |
b14d30e1 | 1677 | set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT); |
ed0f4273 UW |
1678 | if (tdep->long_double_abi == POWERPC_LONG_DOUBLE_IEEE128) |
1679 | set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); | |
1680 | else | |
1681 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); | |
0598a43c | 1682 | |
00d5215e UW |
1683 | /* Support for floating-point data type variants. */ |
1684 | set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type); | |
1685 | ||
7284e1be UW |
1686 | /* Handle inferior calls during interrupted system calls. */ |
1687 | set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc); | |
1688 | ||
a96d9b2e SDJ |
1689 | /* Get the syscall number from the arch's register. */ |
1690 | set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number); | |
1691 | ||
55aa24fb | 1692 | /* SystemTap functions. */ |
05c0465e SDJ |
1693 | set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes); |
1694 | set_gdbarch_stap_register_indirection_prefixes (gdbarch, | |
1695 | stap_register_indirection_prefixes); | |
1696 | set_gdbarch_stap_register_indirection_suffixes (gdbarch, | |
1697 | stap_register_indirection_suffixes); | |
55aa24fb SDJ |
1698 | set_gdbarch_stap_gdb_register_prefix (gdbarch, "r"); |
1699 | set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand); | |
1700 | set_gdbarch_stap_parse_special_token (gdbarch, | |
1701 | ppc_stap_parse_special_token); | |
1702 | ||
7b112f9c JT |
1703 | if (tdep->wordsize == 4) |
1704 | { | |
b9ff3018 AC |
1705 | /* Until November 2001, gcc did not comply with the 32 bit SysV |
1706 | R4 ABI requirement that structures less than or equal to 8 | |
1707 | bytes should be returned in registers. Instead GCC was using | |
b021a221 | 1708 | the AIX/PowerOpen ABI - everything returned in memory |
b9ff3018 AC |
1709 | (well ignoring vectors that is). When this was corrected, it |
1710 | wasn't fixed for GNU/Linux native platform. Use the | |
1711 | PowerOpen struct convention. */ | |
05580c65 | 1712 | set_gdbarch_return_value (gdbarch, ppc_linux_return_value); |
b9ff3018 | 1713 | |
7b112f9c JT |
1714 | set_gdbarch_memory_remove_breakpoint (gdbarch, |
1715 | ppc_linux_memory_remove_breakpoint); | |
61a65099 | 1716 | |
f470a70a | 1717 | /* Shared library handling. */ |
5d853008 | 1718 | set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code); |
7b112f9c | 1719 | set_solib_svr4_fetch_link_map_offsets |
76a9d10f | 1720 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); |
a8f60bfc | 1721 | |
a96d9b2e | 1722 | /* Setting the correct XML syscall filename. */ |
458c8db8 | 1723 | set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC); |
a96d9b2e | 1724 | |
a8f60bfc | 1725 | /* Trampolines. */ |
0df8b418 MS |
1726 | tramp_frame_prepend_unwinder (gdbarch, |
1727 | &ppc32_linux_sigaction_tramp_frame); | |
1728 | tramp_frame_prepend_unwinder (gdbarch, | |
1729 | &ppc32_linux_sighandler_tramp_frame); | |
a78c2d62 UW |
1730 | |
1731 | /* BFD target for core files. */ | |
1732 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) | |
1733 | set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle"); | |
1734 | else | |
1735 | set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc"); | |
2f2241f1 | 1736 | |
5d853008 ME |
1737 | if (powerpc_so_ops.in_dynsym_resolve_code == NULL) |
1738 | { | |
1739 | powerpc_so_ops = svr4_so_ops; | |
1740 | /* Override dynamic resolve function. */ | |
1741 | powerpc_so_ops.in_dynsym_resolve_code = | |
1742 | powerpc_linux_in_dynsym_resolve_code; | |
1743 | } | |
1744 | set_solib_ops (gdbarch, &powerpc_so_ops); | |
1745 | ||
1746 | set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); | |
7b112f9c | 1747 | } |
f470a70a JB |
1748 | |
1749 | if (tdep->wordsize == 8) | |
1750 | { | |
d4094b6a UW |
1751 | if (tdep->elf_abi == POWERPC_ELF_V1) |
1752 | { | |
1753 | /* Handle PPC GNU/Linux 64-bit function pointers (which are really | |
1754 | function descriptors). */ | |
1755 | set_gdbarch_convert_from_func_ptr_addr | |
1756 | (gdbarch, ppc64_convert_from_func_ptr_addr); | |
00d5f93a | 1757 | |
d4094b6a UW |
1758 | set_gdbarch_elf_make_msymbol_special |
1759 | (gdbarch, ppc64_elf_make_msymbol_special); | |
1760 | } | |
591a12a1 UW |
1761 | else |
1762 | { | |
1763 | set_gdbarch_elf_make_msymbol_special | |
1764 | (gdbarch, ppc_elfv2_elf_make_msymbol_special); | |
1765 | ||
1766 | set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint); | |
1767 | } | |
24c274a1 | 1768 | |
fb318ff7 | 1769 | /* Shared library handling. */ |
2bbe3cc1 | 1770 | set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code); |
fb318ff7 DJ |
1771 | set_solib_svr4_fetch_link_map_offsets |
1772 | (gdbarch, svr4_lp64_fetch_link_map_offsets); | |
1773 | ||
a96d9b2e | 1774 | /* Setting the correct XML syscall filename. */ |
458c8db8 | 1775 | set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64); |
a96d9b2e | 1776 | |
a8f60bfc | 1777 | /* Trampolines. */ |
0df8b418 MS |
1778 | tramp_frame_prepend_unwinder (gdbarch, |
1779 | &ppc64_linux_sigaction_tramp_frame); | |
1780 | tramp_frame_prepend_unwinder (gdbarch, | |
1781 | &ppc64_linux_sighandler_tramp_frame); | |
a78c2d62 UW |
1782 | |
1783 | /* BFD target for core files. */ | |
1784 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) | |
1785 | set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle"); | |
1786 | else | |
1787 | set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc"); | |
f470a70a | 1788 | } |
b3ac9c77 | 1789 | |
7284e1be | 1790 | set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description); |
5aa82d05 AA |
1791 | set_gdbarch_iterate_over_regset_sections (gdbarch, |
1792 | ppc_linux_iterate_over_regset_sections); | |
b2756930 KB |
1793 | |
1794 | /* Enable TLS support. */ | |
1795 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
1796 | svr4_fetch_objfile_link_map); | |
7284e1be UW |
1797 | |
1798 | if (tdesc_data) | |
1799 | { | |
1800 | const struct tdesc_feature *feature; | |
1801 | ||
1802 | /* If we have target-described registers, then we can safely | |
1803 | reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM | |
1804 | (whether they are described or not). */ | |
1805 | gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM); | |
1806 | set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1); | |
1807 | ||
1808 | /* If they are present, then assign them to the reserved number. */ | |
1809 | feature = tdesc_find_feature (info.target_desc, | |
1810 | "org.gnu.gdb.power.linux"); | |
1811 | if (feature != NULL) | |
1812 | { | |
1813 | tdesc_numbered_register (feature, tdesc_data, | |
1814 | PPC_ORIG_R3_REGNUM, "orig_r3"); | |
1815 | tdesc_numbered_register (feature, tdesc_data, | |
1816 | PPC_TRAP_REGNUM, "trap"); | |
1817 | } | |
1818 | } | |
85e747d2 UW |
1819 | |
1820 | /* Enable Cell/B.E. if supported by the target. */ | |
1821 | if (tdesc_compatible_p (info.target_desc, | |
1822 | bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu))) | |
1823 | { | |
1824 | /* Cell/B.E. multi-architecture support. */ | |
1825 | set_spu_solib_ops (gdbarch); | |
1826 | ||
cc5f0d61 UW |
1827 | /* Cell/B.E. cross-architecture unwinder support. */ |
1828 | frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind); | |
396d3980 UW |
1829 | |
1830 | /* We need to support more than "addr_bit" significant address bits | |
1831 | in order to support SPUADDR_ADDR encoded values. */ | |
1832 | set_gdbarch_significant_addr_bit (gdbarch, 64); | |
85e747d2 | 1833 | } |
f782ad9b | 1834 | |
906d60cf PA |
1835 | set_gdbarch_displaced_step_location (gdbarch, |
1836 | linux_displaced_step_location); | |
1837 | ||
b4cdae6f WW |
1838 | /* Support reverse debugging. */ |
1839 | set_gdbarch_process_record (gdbarch, ppc_process_record); | |
1840 | set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal); | |
1841 | tdep->ppc_syscall_record = ppc_linux_syscall_record; | |
1842 | ||
1843 | ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4); | |
1844 | ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8); | |
7b112f9c JT |
1845 | } |
1846 | ||
1847 | void | |
1848 | _initialize_ppc_linux_tdep (void) | |
1849 | { | |
0a0a4ac3 AC |
1850 | /* Register for all sub-familes of the POWER/PowerPC: 32-bit and |
1851 | 64-bit PowerPC, and the older rs6k. */ | |
1852 | gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX, | |
1853 | ppc_linux_init_abi); | |
1854 | gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX, | |
1855 | ppc_linux_init_abi); | |
1856 | gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX, | |
1857 | ppc_linux_init_abi); | |
7284e1be | 1858 | |
cc5f0d61 | 1859 | /* Attach to observers to track __spe_current_active_context. */ |
76727919 TT |
1860 | gdb::observers::inferior_created.attach (ppc_linux_spe_context_inferior_created); |
1861 | gdb::observers::solib_loaded.attach (ppc_linux_spe_context_solib_loaded); | |
1862 | gdb::observers::solib_unloaded.attach (ppc_linux_spe_context_solib_unloaded); | |
cc5f0d61 | 1863 | |
7284e1be UW |
1864 | /* Initialize the Linux target descriptions. */ |
1865 | initialize_tdesc_powerpc_32l (); | |
1866 | initialize_tdesc_powerpc_altivec32l (); | |
f4d9bade | 1867 | initialize_tdesc_powerpc_cell32l (); |
604c2f83 | 1868 | initialize_tdesc_powerpc_vsx32l (); |
69abc51c TJB |
1869 | initialize_tdesc_powerpc_isa205_32l (); |
1870 | initialize_tdesc_powerpc_isa205_altivec32l (); | |
1871 | initialize_tdesc_powerpc_isa205_vsx32l (); | |
7284e1be UW |
1872 | initialize_tdesc_powerpc_64l (); |
1873 | initialize_tdesc_powerpc_altivec64l (); | |
f4d9bade | 1874 | initialize_tdesc_powerpc_cell64l (); |
604c2f83 | 1875 | initialize_tdesc_powerpc_vsx64l (); |
69abc51c TJB |
1876 | initialize_tdesc_powerpc_isa205_64l (); |
1877 | initialize_tdesc_powerpc_isa205_altivec64l (); | |
1878 | initialize_tdesc_powerpc_isa205_vsx64l (); | |
7284e1be | 1879 | initialize_tdesc_powerpc_e500l (); |
7b112f9c | 1880 | } |