Commit | Line | Data |
---|---|---|
1f82754b JB |
1 | /* Native support code for PPC AIX, for GDB the GNU debugger. |
2 | ||
3666a048 | 3 | Copyright (C) 2006-2021 Free Software Foundation, Inc. |
1f82754b JB |
4 | |
5 | Free Software Foundation, Inc. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
1f82754b JB |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
1f82754b JB |
21 | |
22 | #include "defs.h" | |
23 | #include "osabi.h" | |
7a61a01c UW |
24 | #include "regcache.h" |
25 | #include "regset.h" | |
4a7622d1 UW |
26 | #include "gdbtypes.h" |
27 | #include "gdbcore.h" | |
28 | #include "target.h" | |
29 | #include "value.h" | |
30 | #include "infcall.h" | |
31 | #include "objfiles.h" | |
32 | #include "breakpoint.h" | |
1f82754b | 33 | #include "rs6000-tdep.h" |
6f7f3f0d | 34 | #include "ppc-tdep.h" |
356a5233 | 35 | #include "rs6000-aix-tdep.h" |
d5367fe1 | 36 | #include "xcoffread.h" |
4d1eb6b4 JB |
37 | #include "solib.h" |
38 | #include "solib-aix.h" | |
3b2ca824 | 39 | #include "target-float.h" |
268a13a5 | 40 | #include "gdbsupport/xml-utils.h" |
cdcda965 SM |
41 | #include "trad-frame.h" |
42 | #include "frame-unwind.h" | |
4a7622d1 UW |
43 | |
44 | /* If the kernel has to deliver a signal, it pushes a sigcontext | |
45 | structure on the stack and then calls the signal handler, passing | |
0df8b418 | 46 | the address of the sigcontext in an argument register. Usually |
4a7622d1 UW |
47 | the signal handler doesn't save this register, so we have to |
48 | access the sigcontext structure via an offset from the signal handler | |
49 | frame. | |
cdcda965 SM |
50 | The following constants were determined by experimentation on AIX 3.2. |
51 | ||
52 | sigcontext structure have the mstsave saved under the | |
53 | sc_jmpbuf.jmp_context. STKMIN(minimum stack size) is 56 for 32-bit | |
54 | processes, and iar offset under sc_jmpbuf.jmp_context is 40. | |
55 | ie offsetof(struct sigcontext, sc_jmpbuf.jmp_context.iar). | |
56 | so PC offset in this case is STKMIN+iar offset, which is 96. */ | |
57 | ||
4a7622d1 UW |
58 | #define SIG_FRAME_PC_OFFSET 96 |
59 | #define SIG_FRAME_LR_OFFSET 108 | |
cdcda965 | 60 | /* STKMIN+grp1 offset, which is 56+228=284 */ |
4a7622d1 UW |
61 | #define SIG_FRAME_FP_OFFSET 284 |
62 | ||
cdcda965 SM |
63 | /* 64 bit process. |
64 | STKMIN64 is 112 and iar offset is 312. So 112+312=424 */ | |
65 | #define SIG_FRAME_LR_OFFSET64 424 | |
66 | /* STKMIN64+grp1 offset. 112+56=168 */ | |
67 | #define SIG_FRAME_FP_OFFSET64 168 | |
68 | ||
69 | static struct trad_frame_cache * | |
70 | aix_sighandle_frame_cache (struct frame_info *this_frame, | |
71 | void **this_cache) | |
72 | { | |
73 | LONGEST backchain; | |
74 | CORE_ADDR base, base_orig, func; | |
75 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
76 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
77 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
78 | struct trad_frame_cache *this_trad_cache; | |
79 | ||
80 | if ((*this_cache) != NULL) | |
81 | return (struct trad_frame_cache *) (*this_cache); | |
82 | ||
83 | this_trad_cache = trad_frame_cache_zalloc (this_frame); | |
84 | (*this_cache) = this_trad_cache; | |
85 | ||
86 | base = get_frame_register_unsigned (this_frame, | |
dda83cd7 | 87 | gdbarch_sp_regnum (gdbarch)); |
cdcda965 SM |
88 | base_orig = base; |
89 | ||
90 | if (tdep->wordsize == 4) | |
91 | { | |
92 | func = read_memory_unsigned_integer (base_orig + | |
93 | SIG_FRAME_PC_OFFSET + 8, | |
94 | tdep->wordsize, byte_order); | |
95 | safe_read_memory_integer (base_orig + SIG_FRAME_FP_OFFSET + 8, | |
96 | tdep->wordsize, byte_order, &backchain); | |
97 | base = (CORE_ADDR)backchain; | |
98 | } | |
99 | else | |
100 | { | |
101 | func = read_memory_unsigned_integer (base_orig + | |
102 | SIG_FRAME_LR_OFFSET64, | |
103 | tdep->wordsize, byte_order); | |
104 | safe_read_memory_integer (base_orig + SIG_FRAME_FP_OFFSET64, | |
105 | tdep->wordsize, byte_order, &backchain); | |
106 | base = (CORE_ADDR)backchain; | |
107 | } | |
108 | ||
109 | trad_frame_set_reg_value (this_trad_cache, gdbarch_pc_regnum (gdbarch), func); | |
110 | trad_frame_set_reg_value (this_trad_cache, gdbarch_sp_regnum (gdbarch), base); | |
111 | ||
112 | if (tdep->wordsize == 4) | |
113 | trad_frame_set_reg_addr (this_trad_cache, tdep->ppc_lr_regnum, | |
dda83cd7 | 114 | base_orig + 0x38 + 52 + 8); |
cdcda965 SM |
115 | else |
116 | trad_frame_set_reg_addr (this_trad_cache, tdep->ppc_lr_regnum, | |
dda83cd7 | 117 | base_orig + 0x70 + 320); |
cdcda965 SM |
118 | |
119 | trad_frame_set_id (this_trad_cache, frame_id_build (base, func)); | |
120 | trad_frame_set_this_base (this_trad_cache, base); | |
121 | ||
122 | return this_trad_cache; | |
123 | } | |
124 | ||
125 | static void | |
126 | aix_sighandle_frame_this_id (struct frame_info *this_frame, | |
127 | void **this_prologue_cache, | |
128 | struct frame_id *this_id) | |
129 | { | |
130 | struct trad_frame_cache *this_trad_cache | |
131 | = aix_sighandle_frame_cache (this_frame, this_prologue_cache); | |
132 | trad_frame_get_id (this_trad_cache, this_id); | |
133 | } | |
134 | ||
135 | static struct value * | |
136 | aix_sighandle_frame_prev_register (struct frame_info *this_frame, | |
137 | void **this_prologue_cache, int regnum) | |
138 | { | |
139 | struct trad_frame_cache *this_trad_cache | |
140 | = aix_sighandle_frame_cache (this_frame, this_prologue_cache); | |
141 | return trad_frame_get_register (this_trad_cache, this_frame, regnum); | |
142 | } | |
143 | ||
cb8c24b6 | 144 | static int |
cdcda965 SM |
145 | aix_sighandle_frame_sniffer (const struct frame_unwind *self, |
146 | struct frame_info *this_frame, | |
147 | void **this_prologue_cache) | |
148 | { | |
149 | CORE_ADDR pc = get_frame_pc (this_frame); | |
150 | if (pc && pc < AIX_TEXT_SEGMENT_BASE) | |
151 | return 1; | |
152 | ||
153 | return 0; | |
154 | } | |
155 | ||
156 | /* AIX signal handler frame unwinder */ | |
157 | ||
158 | static const struct frame_unwind aix_sighandle_frame_unwind = { | |
a154d838 | 159 | "rs6000 aix sighandle", |
cdcda965 SM |
160 | SIGTRAMP_FRAME, |
161 | default_frame_unwind_stop_reason, | |
162 | aix_sighandle_frame_this_id, | |
163 | aix_sighandle_frame_prev_register, | |
164 | NULL, | |
165 | aix_sighandle_frame_sniffer | |
166 | }; | |
7a61a01c UW |
167 | |
168 | /* Core file support. */ | |
169 | ||
170 | static struct ppc_reg_offsets rs6000_aix32_reg_offsets = | |
171 | { | |
172 | /* General-purpose registers. */ | |
173 | 208, /* r0_offset */ | |
f2db237a AM |
174 | 4, /* gpr_size */ |
175 | 4, /* xr_size */ | |
7a61a01c UW |
176 | 24, /* pc_offset */ |
177 | 28, /* ps_offset */ | |
178 | 32, /* cr_offset */ | |
179 | 36, /* lr_offset */ | |
180 | 40, /* ctr_offset */ | |
181 | 44, /* xer_offset */ | |
182 | 48, /* mq_offset */ | |
183 | ||
184 | /* Floating-point registers. */ | |
185 | 336, /* f0_offset */ | |
186 | 56, /* fpscr_offset */ | |
1d75a658 | 187 | 4 /* fpscr_size */ |
7a61a01c UW |
188 | }; |
189 | ||
190 | static struct ppc_reg_offsets rs6000_aix64_reg_offsets = | |
191 | { | |
192 | /* General-purpose registers. */ | |
193 | 0, /* r0_offset */ | |
f2db237a AM |
194 | 8, /* gpr_size */ |
195 | 4, /* xr_size */ | |
7a61a01c UW |
196 | 264, /* pc_offset */ |
197 | 256, /* ps_offset */ | |
198 | 288, /* cr_offset */ | |
199 | 272, /* lr_offset */ | |
200 | 280, /* ctr_offset */ | |
201 | 292, /* xer_offset */ | |
202 | -1, /* mq_offset */ | |
203 | ||
204 | /* Floating-point registers. */ | |
205 | 312, /* f0_offset */ | |
206 | 296, /* fpscr_offset */ | |
1d75a658 | 207 | 4 /* fpscr_size */ |
7a61a01c UW |
208 | }; |
209 | ||
210 | ||
211 | /* Supply register REGNUM in the general-purpose register set REGSET | |
212 | from the buffer specified by GREGS and LEN to register cache | |
213 | REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ | |
214 | ||
215 | static void | |
216 | rs6000_aix_supply_regset (const struct regset *regset, | |
217 | struct regcache *regcache, int regnum, | |
218 | const void *gregs, size_t len) | |
219 | { | |
220 | ppc_supply_gregset (regset, regcache, regnum, gregs, len); | |
f2db237a | 221 | ppc_supply_fpregset (regset, regcache, regnum, gregs, len); |
7a61a01c UW |
222 | } |
223 | ||
224 | /* Collect register REGNUM in the general-purpose register set | |
0df8b418 | 225 | REGSET, from register cache REGCACHE into the buffer specified by |
7a61a01c UW |
226 | GREGS and LEN. If REGNUM is -1, do this for all registers in |
227 | REGSET. */ | |
228 | ||
229 | static void | |
230 | rs6000_aix_collect_regset (const struct regset *regset, | |
231 | const struct regcache *regcache, int regnum, | |
232 | void *gregs, size_t len) | |
233 | { | |
234 | ppc_collect_gregset (regset, regcache, regnum, gregs, len); | |
f2db237a | 235 | ppc_collect_fpregset (regset, regcache, regnum, gregs, len); |
7a61a01c UW |
236 | } |
237 | ||
238 | /* AIX register set. */ | |
239 | ||
3ca7dae4 | 240 | static const struct regset rs6000_aix32_regset = |
7a61a01c UW |
241 | { |
242 | &rs6000_aix32_reg_offsets, | |
243 | rs6000_aix_supply_regset, | |
244 | rs6000_aix_collect_regset, | |
245 | }; | |
246 | ||
3ca7dae4 | 247 | static const struct regset rs6000_aix64_regset = |
7a61a01c UW |
248 | { |
249 | &rs6000_aix64_reg_offsets, | |
250 | rs6000_aix_supply_regset, | |
251 | rs6000_aix_collect_regset, | |
252 | }; | |
253 | ||
23ea9aeb | 254 | /* Iterate over core file register note sections. */ |
7a61a01c | 255 | |
23ea9aeb AA |
256 | static void |
257 | rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
258 | iterate_over_regset_sections_cb *cb, | |
259 | void *cb_data, | |
260 | const struct regcache *regcache) | |
7a61a01c UW |
261 | { |
262 | if (gdbarch_tdep (gdbarch)->wordsize == 4) | |
a616bb94 | 263 | cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data); |
7a61a01c | 264 | else |
a616bb94 | 265 | cb (".reg", 576, 576, &rs6000_aix64_regset, NULL, cb_data); |
7a61a01c UW |
266 | } |
267 | ||
268 | ||
0df8b418 | 269 | /* Pass the arguments in either registers, or in the stack. In RS/6000, |
4a7622d1 UW |
270 | the first eight words of the argument list (that might be less than |
271 | eight parameters if some parameters occupy more than one word) are | |
0df8b418 | 272 | passed in r3..r10 registers. Float and double parameters are |
4a7622d1 UW |
273 | passed in fpr's, in addition to that. Rest of the parameters if any |
274 | are passed in user stack. There might be cases in which half of the | |
275 | parameter is copied into registers, the other half is pushed into | |
276 | stack. | |
277 | ||
278 | Stack must be aligned on 64-bit boundaries when synthesizing | |
279 | function calls. | |
280 | ||
281 | If the function is returning a structure, then the return address is passed | |
282 | in r3, then the first 7 words of the parameters can be passed in registers, | |
283 | starting from r4. */ | |
284 | ||
285 | static CORE_ADDR | |
286 | rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function, | |
287 | struct regcache *regcache, CORE_ADDR bp_addr, | |
288 | int nargs, struct value **args, CORE_ADDR sp, | |
cf84fa6b AH |
289 | function_call_return_method return_method, |
290 | CORE_ADDR struct_addr) | |
4a7622d1 UW |
291 | { |
292 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
e17a4113 | 293 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
4a7622d1 UW |
294 | int ii; |
295 | int len = 0; | |
296 | int argno; /* current argument number */ | |
297 | int argbytes; /* current argument byte */ | |
298 | gdb_byte tmp_buffer[50]; | |
299 | int f_argno = 0; /* current floating point argno */ | |
300 | int wordsize = gdbarch_tdep (gdbarch)->wordsize; | |
301 | CORE_ADDR func_addr = find_function_addr (function, NULL); | |
302 | ||
303 | struct value *arg = 0; | |
304 | struct type *type; | |
305 | ||
306 | ULONGEST saved_sp; | |
307 | ||
308 | /* The calling convention this function implements assumes the | |
309 | processor has floating-point registers. We shouldn't be using it | |
310 | on PPC variants that lack them. */ | |
311 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
312 | ||
313 | /* The first eight words of ther arguments are passed in registers. | |
314 | Copy them appropriately. */ | |
315 | ii = 0; | |
316 | ||
317 | /* If the function is returning a `struct', then the first word | |
318 | (which will be passed in r3) is used for struct return address. | |
319 | In that case we should advance one word and start from r4 | |
320 | register to copy parameters. */ | |
cf84fa6b | 321 | if (return_method == return_method_struct) |
4a7622d1 UW |
322 | { |
323 | regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
324 | struct_addr); | |
325 | ii++; | |
326 | } | |
327 | ||
0df8b418 | 328 | /* effectively indirect call... gcc does... |
4a7622d1 UW |
329 | |
330 | return_val example( float, int); | |
331 | ||
332 | eabi: | |
333 | float in fp0, int in r3 | |
334 | offset of stack on overflow 8/16 | |
335 | for varargs, must go by type. | |
336 | power open: | |
337 | float in r3&r4, int in r5 | |
338 | offset of stack on overflow different | |
339 | both: | |
340 | return in r3 or f0. If no float, must study how gcc emulates floats; | |
0df8b418 | 341 | pay attention to arg promotion. |
4a7622d1 | 342 | User may have to cast\args to handle promotion correctly |
0df8b418 | 343 | since gdb won't know if prototype supplied or not. */ |
4a7622d1 UW |
344 | |
345 | for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii) | |
346 | { | |
347 | int reg_size = register_size (gdbarch, ii + 3); | |
348 | ||
349 | arg = args[argno]; | |
350 | type = check_typedef (value_type (arg)); | |
351 | len = TYPE_LENGTH (type); | |
352 | ||
78134374 | 353 | if (type->code () == TYPE_CODE_FLT) |
4a7622d1 | 354 | { |
4a7622d1 | 355 | /* Floating point arguments are passed in fpr's, as well as gpr's. |
0df8b418 | 356 | There are 13 fpr's reserved for passing parameters. At this point |
36d1c68c JB |
357 | there is no way we would run out of them. |
358 | ||
359 | Always store the floating point value using the register's | |
360 | floating-point format. */ | |
361 | const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno; | |
0f068fb5 | 362 | gdb_byte reg_val[PPC_MAX_REGISTER_SIZE]; |
36d1c68c | 363 | struct type *reg_type = register_type (gdbarch, fp_regnum); |
4a7622d1 UW |
364 | |
365 | gdb_assert (len <= 8); | |
366 | ||
3b2ca824 | 367 | target_float_convert (value_contents (arg), type, reg_val, reg_type); |
b66f5587 | 368 | regcache->cooked_write (fp_regnum, reg_val); |
4a7622d1 UW |
369 | ++f_argno; |
370 | } | |
371 | ||
372 | if (len > reg_size) | |
373 | { | |
374 | ||
375 | /* Argument takes more than one register. */ | |
376 | while (argbytes < len) | |
377 | { | |
0f068fb5 | 378 | gdb_byte word[PPC_MAX_REGISTER_SIZE]; |
4a7622d1 UW |
379 | memset (word, 0, reg_size); |
380 | memcpy (word, | |
381 | ((char *) value_contents (arg)) + argbytes, | |
382 | (len - argbytes) > reg_size | |
dda83cd7 | 383 | ? reg_size : len - argbytes); |
b66f5587 | 384 | regcache->cooked_write (tdep->ppc_gp0_regnum + 3 + ii, word); |
4a7622d1 UW |
385 | ++ii, argbytes += reg_size; |
386 | ||
387 | if (ii >= 8) | |
388 | goto ran_out_of_registers_for_arguments; | |
389 | } | |
390 | argbytes = 0; | |
391 | --ii; | |
392 | } | |
393 | else | |
394 | { | |
395 | /* Argument can fit in one register. No problem. */ | |
0f068fb5 | 396 | gdb_byte word[PPC_MAX_REGISTER_SIZE]; |
4a7622d1 UW |
397 | |
398 | memset (word, 0, reg_size); | |
399 | memcpy (word, value_contents (arg), len); | |
b66f5587 | 400 | regcache->cooked_write (tdep->ppc_gp0_regnum + 3 +ii, word); |
4a7622d1 UW |
401 | } |
402 | ++argno; | |
403 | } | |
404 | ||
405 | ran_out_of_registers_for_arguments: | |
406 | ||
407 | regcache_cooked_read_unsigned (regcache, | |
408 | gdbarch_sp_regnum (gdbarch), | |
409 | &saved_sp); | |
410 | ||
411 | /* Location for 8 parameters are always reserved. */ | |
412 | sp -= wordsize * 8; | |
413 | ||
414 | /* Another six words for back chain, TOC register, link register, etc. */ | |
415 | sp -= wordsize * 6; | |
416 | ||
417 | /* Stack pointer must be quadword aligned. */ | |
418 | sp &= -16; | |
419 | ||
420 | /* If there are more arguments, allocate space for them in | |
421 | the stack, then push them starting from the ninth one. */ | |
422 | ||
423 | if ((argno < nargs) || argbytes) | |
424 | { | |
425 | int space = 0, jj; | |
426 | ||
427 | if (argbytes) | |
428 | { | |
429 | space += ((len - argbytes + 3) & -4); | |
430 | jj = argno + 1; | |
431 | } | |
432 | else | |
433 | jj = argno; | |
434 | ||
435 | for (; jj < nargs; ++jj) | |
436 | { | |
437 | struct value *val = args[jj]; | |
438 | space += ((TYPE_LENGTH (value_type (val))) + 3) & -4; | |
439 | } | |
440 | ||
441 | /* Add location required for the rest of the parameters. */ | |
442 | space = (space + 15) & -16; | |
443 | sp -= space; | |
444 | ||
445 | /* This is another instance we need to be concerned about | |
dda83cd7 SM |
446 | securing our stack space. If we write anything underneath %sp |
447 | (r1), we might conflict with the kernel who thinks he is free | |
448 | to use this area. So, update %sp first before doing anything | |
449 | else. */ | |
4a7622d1 UW |
450 | |
451 | regcache_raw_write_signed (regcache, | |
452 | gdbarch_sp_regnum (gdbarch), sp); | |
453 | ||
454 | /* If the last argument copied into the registers didn't fit there | |
dda83cd7 | 455 | completely, push the rest of it into stack. */ |
4a7622d1 UW |
456 | |
457 | if (argbytes) | |
458 | { | |
459 | write_memory (sp + 24 + (ii * 4), | |
460 | value_contents (arg) + argbytes, | |
461 | len - argbytes); | |
462 | ++argno; | |
463 | ii += ((len - argbytes + 3) & -4) / 4; | |
464 | } | |
465 | ||
466 | /* Push the rest of the arguments into stack. */ | |
467 | for (; argno < nargs; ++argno) | |
468 | { | |
469 | ||
470 | arg = args[argno]; | |
471 | type = check_typedef (value_type (arg)); | |
472 | len = TYPE_LENGTH (type); | |
473 | ||
474 | ||
475 | /* Float types should be passed in fpr's, as well as in the | |
dda83cd7 | 476 | stack. */ |
78134374 | 477 | if (type->code () == TYPE_CODE_FLT && f_argno < 13) |
4a7622d1 UW |
478 | { |
479 | ||
480 | gdb_assert (len <= 8); | |
481 | ||
b66f5587 SM |
482 | regcache->cooked_write (tdep->ppc_fp0_regnum + 1 + f_argno, |
483 | value_contents (arg)); | |
4a7622d1 UW |
484 | ++f_argno; |
485 | } | |
486 | ||
487 | write_memory (sp + 24 + (ii * 4), value_contents (arg), len); | |
488 | ii += ((len + 3) & -4) / 4; | |
489 | } | |
490 | } | |
491 | ||
492 | /* Set the stack pointer. According to the ABI, the SP is meant to | |
493 | be set _before_ the corresponding stack space is used. On AIX, | |
494 | this even applies when the target has been completely stopped! | |
495 | Not doing this can lead to conflicts with the kernel which thinks | |
496 | that it still has control over this not-yet-allocated stack | |
497 | region. */ | |
498 | regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); | |
499 | ||
500 | /* Set back chain properly. */ | |
e17a4113 | 501 | store_unsigned_integer (tmp_buffer, wordsize, byte_order, saved_sp); |
4a7622d1 UW |
502 | write_memory (sp, tmp_buffer, wordsize); |
503 | ||
504 | /* Point the inferior function call's return address at the dummy's | |
505 | breakpoint. */ | |
506 | regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); | |
507 | ||
4d1eb6b4 JB |
508 | /* Set the TOC register value. */ |
509 | regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum, | |
510 | solib_aix_get_toc_value (func_addr)); | |
4a7622d1 UW |
511 | |
512 | target_store_registers (regcache, -1); | |
513 | return sp; | |
514 | } | |
515 | ||
516 | static enum return_value_convention | |
6a3a010b | 517 | rs6000_return_value (struct gdbarch *gdbarch, struct value *function, |
4a7622d1 UW |
518 | struct type *valtype, struct regcache *regcache, |
519 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
520 | { | |
521 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
e17a4113 | 522 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
4a7622d1 UW |
523 | |
524 | /* The calling convention this function implements assumes the | |
525 | processor has floating-point registers. We shouldn't be using it | |
526 | on PowerPC variants that lack them. */ | |
527 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
528 | ||
529 | /* AltiVec extension: Functions that declare a vector data type as a | |
530 | return value place that return value in VR2. */ | |
bd63c870 | 531 | if (valtype->code () == TYPE_CODE_ARRAY && valtype->is_vector () |
4a7622d1 UW |
532 | && TYPE_LENGTH (valtype) == 16) |
533 | { | |
534 | if (readbuf) | |
dca08e1f | 535 | regcache->cooked_read (tdep->ppc_vr0_regnum + 2, readbuf); |
4a7622d1 | 536 | if (writebuf) |
b66f5587 | 537 | regcache->cooked_write (tdep->ppc_vr0_regnum + 2, writebuf); |
4a7622d1 UW |
538 | |
539 | return RETURN_VALUE_REGISTER_CONVENTION; | |
540 | } | |
541 | ||
542 | /* If the called subprogram returns an aggregate, there exists an | |
543 | implicit first argument, whose value is the address of a caller- | |
544 | allocated buffer into which the callee is assumed to store its | |
0df8b418 | 545 | return value. All explicit parameters are appropriately |
4a7622d1 | 546 | relabeled. */ |
78134374 SM |
547 | if (valtype->code () == TYPE_CODE_STRUCT |
548 | || valtype->code () == TYPE_CODE_UNION | |
549 | || valtype->code () == TYPE_CODE_ARRAY) | |
4a7622d1 UW |
550 | return RETURN_VALUE_STRUCT_CONVENTION; |
551 | ||
552 | /* Scalar floating-point values are returned in FPR1 for float or | |
553 | double, and in FPR1:FPR2 for quadword precision. Fortran | |
554 | complex*8 and complex*16 are returned in FPR1:FPR2, and | |
555 | complex*32 is returned in FPR1:FPR4. */ | |
78134374 | 556 | if (valtype->code () == TYPE_CODE_FLT |
4a7622d1 UW |
557 | && (TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8)) |
558 | { | |
559 | struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); | |
560 | gdb_byte regval[8]; | |
561 | ||
562 | /* FIXME: kettenis/2007-01-01: Add support for quadword | |
563 | precision and complex. */ | |
564 | ||
565 | if (readbuf) | |
566 | { | |
dca08e1f | 567 | regcache->cooked_read (tdep->ppc_fp0_regnum + 1, regval); |
3b2ca824 | 568 | target_float_convert (regval, regtype, readbuf, valtype); |
4a7622d1 UW |
569 | } |
570 | if (writebuf) | |
571 | { | |
3b2ca824 | 572 | target_float_convert (writebuf, valtype, regval, regtype); |
b66f5587 | 573 | regcache->cooked_write (tdep->ppc_fp0_regnum + 1, regval); |
4a7622d1 UW |
574 | } |
575 | ||
576 | return RETURN_VALUE_REGISTER_CONVENTION; | |
577 | } | |
578 | ||
579 | /* Values of the types int, long, short, pointer, and char (length | |
580 | is less than or equal to four bytes), as well as bit values of | |
581 | lengths less than or equal to 32 bits, must be returned right | |
582 | justified in GPR3 with signed values sign extended and unsigned | |
583 | values zero extended, as necessary. */ | |
584 | if (TYPE_LENGTH (valtype) <= tdep->wordsize) | |
585 | { | |
586 | if (readbuf) | |
587 | { | |
588 | ULONGEST regval; | |
589 | ||
590 | /* For reading we don't have to worry about sign extension. */ | |
591 | regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
592 | ®val); | |
e17a4113 UW |
593 | store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order, |
594 | regval); | |
4a7622d1 UW |
595 | } |
596 | if (writebuf) | |
597 | { | |
598 | /* For writing, use unpack_long since that should handle any | |
599 | required sign extension. */ | |
600 | regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
601 | unpack_long (valtype, writebuf)); | |
602 | } | |
603 | ||
604 | return RETURN_VALUE_REGISTER_CONVENTION; | |
605 | } | |
606 | ||
607 | /* Eight-byte non-floating-point scalar values must be returned in | |
608 | GPR3:GPR4. */ | |
609 | ||
610 | if (TYPE_LENGTH (valtype) == 8) | |
611 | { | |
78134374 | 612 | gdb_assert (valtype->code () != TYPE_CODE_FLT); |
4a7622d1 UW |
613 | gdb_assert (tdep->wordsize == 4); |
614 | ||
615 | if (readbuf) | |
616 | { | |
617 | gdb_byte regval[8]; | |
618 | ||
dca08e1f SM |
619 | regcache->cooked_read (tdep->ppc_gp0_regnum + 3, regval); |
620 | regcache->cooked_read (tdep->ppc_gp0_regnum + 4, regval + 4); | |
4a7622d1 UW |
621 | memcpy (readbuf, regval, 8); |
622 | } | |
623 | if (writebuf) | |
624 | { | |
b66f5587 SM |
625 | regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf); |
626 | regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4); | |
4a7622d1 UW |
627 | } |
628 | ||
629 | return RETURN_VALUE_REGISTER_CONVENTION; | |
630 | } | |
631 | ||
632 | return RETURN_VALUE_STRUCT_CONVENTION; | |
633 | } | |
634 | ||
635 | /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG). | |
636 | ||
637 | Usually a function pointer's representation is simply the address | |
0df8b418 MS |
638 | of the function. On the RS/6000 however, a function pointer is |
639 | represented by a pointer to an OPD entry. This OPD entry contains | |
4a7622d1 UW |
640 | three words, the first word is the address of the function, the |
641 | second word is the TOC pointer (r2), and the third word is the | |
642 | static chain value. Throughout GDB it is currently assumed that a | |
643 | function pointer contains the address of the function, which is not | |
644 | easy to fix. In addition, the conversion of a function address to | |
645 | a function pointer would require allocation of an OPD entry in the | |
646 | inferior's memory space, with all its drawbacks. To be able to | |
647 | call C++ virtual methods in the inferior (which are called via | |
648 | function pointers), find_function_addr uses this function to get the | |
649 | function address from a function pointer. */ | |
650 | ||
651 | /* Return real function address if ADDR (a function pointer) is in the data | |
652 | space and is therefore a special function pointer. */ | |
653 | ||
654 | static CORE_ADDR | |
655 | rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch, | |
656 | CORE_ADDR addr, | |
657 | struct target_ops *targ) | |
658 | { | |
e17a4113 UW |
659 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
660 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
4a7622d1 UW |
661 | struct obj_section *s; |
662 | ||
663 | s = find_pc_section (addr); | |
4a7622d1 | 664 | |
40adab56 JB |
665 | /* Normally, functions live inside a section that is executable. |
666 | So, if ADDR points to a non-executable section, then treat it | |
667 | as a function descriptor and return the target address iff | |
668 | the target address itself points to a section that is executable. */ | |
669 | if (s && (s->the_bfd_section->flags & SEC_CODE) == 0) | |
670 | { | |
57174f31 | 671 | CORE_ADDR pc = 0; |
2971b56b | 672 | struct obj_section *pc_section; |
2971b56b | 673 | |
a70b8144 | 674 | try |
dda83cd7 SM |
675 | { |
676 | pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order); | |
677 | } | |
230d2906 | 678 | catch (const gdb_exception_error &e) |
dda83cd7 SM |
679 | { |
680 | /* An error occured during reading. Probably a memory error | |
681 | due to the section not being loaded yet. This address | |
682 | cannot be a function descriptor. */ | |
683 | return addr; | |
684 | } | |
492d29ea | 685 | |
2971b56b | 686 | pc_section = find_pc_section (pc); |
40adab56 JB |
687 | |
688 | if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE)) | |
dda83cd7 | 689 | return pc; |
40adab56 JB |
690 | } |
691 | ||
692 | return addr; | |
4a7622d1 UW |
693 | } |
694 | ||
695 | ||
696 | /* Calculate the destination of a branch/jump. Return -1 if not a branch. */ | |
697 | ||
698 | static CORE_ADDR | |
41e26ad3 | 699 | branch_dest (struct regcache *regcache, int opcode, int instr, |
4a7622d1 UW |
700 | CORE_ADDR pc, CORE_ADDR safety) |
701 | { | |
ac7936df | 702 | struct gdbarch *gdbarch = regcache->arch (); |
e17a4113 UW |
703 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
704 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
4a7622d1 UW |
705 | CORE_ADDR dest; |
706 | int immediate; | |
707 | int absolute; | |
708 | int ext_op; | |
709 | ||
710 | absolute = (int) ((instr >> 1) & 1); | |
711 | ||
712 | switch (opcode) | |
713 | { | |
714 | case 18: | |
715 | immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */ | |
716 | if (absolute) | |
717 | dest = immediate; | |
718 | else | |
719 | dest = pc + immediate; | |
720 | break; | |
721 | ||
722 | case 16: | |
723 | immediate = ((instr & ~3) << 16) >> 16; /* br conditional */ | |
724 | if (absolute) | |
725 | dest = immediate; | |
726 | else | |
727 | dest = pc + immediate; | |
728 | break; | |
729 | ||
730 | case 19: | |
731 | ext_op = (instr >> 1) & 0x3ff; | |
732 | ||
733 | if (ext_op == 16) /* br conditional register */ | |
734 | { | |
dda83cd7 | 735 | dest = regcache_raw_get_unsigned (regcache, tdep->ppc_lr_regnum) & ~3; |
4a7622d1 UW |
736 | |
737 | /* If we are about to return from a signal handler, dest is | |
738 | something like 0x3c90. The current frame is a signal handler | |
739 | caller frame, upon completion of the sigreturn system call | |
740 | execution will return to the saved PC in the frame. */ | |
741 | if (dest < AIX_TEXT_SEGMENT_BASE) | |
41e26ad3 YQ |
742 | { |
743 | struct frame_info *frame = get_current_frame (); | |
744 | ||
745 | dest = read_memory_unsigned_integer | |
746 | (get_frame_base (frame) + SIG_FRAME_PC_OFFSET, | |
747 | tdep->wordsize, byte_order); | |
748 | } | |
4a7622d1 UW |
749 | } |
750 | ||
751 | else if (ext_op == 528) /* br cond to count reg */ | |
752 | { | |
dda83cd7 | 753 | dest = regcache_raw_get_unsigned (regcache, |
41e26ad3 | 754 | tdep->ppc_ctr_regnum) & ~3; |
4a7622d1 UW |
755 | |
756 | /* If we are about to execute a system call, dest is something | |
757 | like 0x22fc or 0x3b00. Upon completion the system call | |
758 | will return to the address in the link register. */ | |
759 | if (dest < AIX_TEXT_SEGMENT_BASE) | |
dda83cd7 | 760 | dest = regcache_raw_get_unsigned (regcache, |
41e26ad3 | 761 | tdep->ppc_lr_regnum) & ~3; |
4a7622d1 UW |
762 | } |
763 | else | |
764 | return -1; | |
765 | break; | |
766 | ||
767 | default: | |
768 | return -1; | |
769 | } | |
770 | return (dest < AIX_TEXT_SEGMENT_BASE) ? safety : dest; | |
771 | } | |
772 | ||
773 | /* AIX does not support PT_STEP. Simulate it. */ | |
774 | ||
a0ff9e1a | 775 | static std::vector<CORE_ADDR> |
f5ea389a | 776 | rs6000_software_single_step (struct regcache *regcache) |
4a7622d1 | 777 | { |
ac7936df | 778 | struct gdbarch *gdbarch = regcache->arch (); |
e17a4113 | 779 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
4a7622d1 UW |
780 | int ii, insn; |
781 | CORE_ADDR loc; | |
782 | CORE_ADDR breaks[2]; | |
783 | int opcode; | |
784 | ||
41e26ad3 | 785 | loc = regcache_read_pc (regcache); |
4a7622d1 | 786 | |
e17a4113 | 787 | insn = read_memory_integer (loc, 4, byte_order); |
4a7622d1 | 788 | |
a0ff9e1a SM |
789 | std::vector<CORE_ADDR> next_pcs = ppc_deal_with_atomic_sequence (regcache); |
790 | if (!next_pcs.empty ()) | |
93f9a11f | 791 | return next_pcs; |
4a7622d1 UW |
792 | |
793 | breaks[0] = loc + PPC_INSN_SIZE; | |
794 | opcode = insn >> 26; | |
41e26ad3 | 795 | breaks[1] = branch_dest (regcache, opcode, insn, loc, breaks[0]); |
4a7622d1 | 796 | |
0df8b418 | 797 | /* Don't put two breakpoints on the same address. */ |
4a7622d1 UW |
798 | if (breaks[1] == breaks[0]) |
799 | breaks[1] = -1; | |
800 | ||
801 | for (ii = 0; ii < 2; ++ii) | |
802 | { | |
0df8b418 | 803 | /* ignore invalid breakpoint. */ |
4a7622d1 UW |
804 | if (breaks[ii] == -1) |
805 | continue; | |
a0ff9e1a SM |
806 | |
807 | next_pcs.push_back (breaks[ii]); | |
4a7622d1 UW |
808 | } |
809 | ||
0df8b418 | 810 | errno = 0; /* FIXME, don't ignore errors! */ |
4a7622d1 | 811 | /* What errors? {read,write}_memory call error(). */ |
93f9a11f | 812 | return next_pcs; |
4a7622d1 UW |
813 | } |
814 | ||
38a69d0a JB |
815 | /* Implement the "auto_wide_charset" gdbarch method for this platform. */ |
816 | ||
817 | static const char * | |
818 | rs6000_aix_auto_wide_charset (void) | |
819 | { | |
820 | return "UTF-16"; | |
821 | } | |
822 | ||
beb4b03c JB |
823 | /* Implement an osabi sniffer for RS6000/AIX. |
824 | ||
825 | This function assumes that ABFD's flavour is XCOFF. In other words, | |
826 | it should be registered as a sniffer for bfd_target_xcoff_flavour | |
827 | objfiles only. A failed assertion will be raised if this condition | |
828 | is not met. */ | |
829 | ||
1f82754b JB |
830 | static enum gdb_osabi |
831 | rs6000_aix_osabi_sniffer (bfd *abfd) | |
832 | { | |
beb4b03c | 833 | gdb_assert (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour); |
1f82754b | 834 | |
d5367fe1 JB |
835 | /* The only noticeable difference between Lynx178 XCOFF files and |
836 | AIX XCOFF files comes from the fact that there are no shared | |
837 | libraries on Lynx178. On AIX, we are betting that an executable | |
838 | linked with no shared library will never exist. */ | |
839 | if (xcoff_get_n_import_files (abfd) <= 0) | |
840 | return GDB_OSABI_UNKNOWN; | |
841 | ||
beb4b03c | 842 | return GDB_OSABI_AIX; |
1f82754b JB |
843 | } |
844 | ||
356a5233 JB |
845 | /* A structure encoding the offset and size of a field within |
846 | a struct. */ | |
847 | ||
848 | struct field_info | |
849 | { | |
850 | int offset; | |
851 | int size; | |
852 | }; | |
853 | ||
854 | /* A structure describing the layout of all the fields of interest | |
855 | in AIX's struct ld_info. Each field in this struct corresponds | |
856 | to the field of the same name in struct ld_info. */ | |
857 | ||
858 | struct ld_info_desc | |
859 | { | |
860 | struct field_info ldinfo_next; | |
861 | struct field_info ldinfo_fd; | |
862 | struct field_info ldinfo_textorg; | |
863 | struct field_info ldinfo_textsize; | |
864 | struct field_info ldinfo_dataorg; | |
865 | struct field_info ldinfo_datasize; | |
866 | struct field_info ldinfo_filename; | |
867 | }; | |
868 | ||
869 | /* The following data has been generated by compiling and running | |
870 | the following program on AIX 5.3. */ | |
871 | ||
872 | #if 0 | |
1c432e72 JB |
873 | #include <stddef.h> |
874 | #include <stdio.h> | |
875 | #define __LDINFO_PTRACE32__ | |
876 | #define __LDINFO_PTRACE64__ | |
877 | #include <sys/ldr.h> | |
878 | ||
879 | #define pinfo(type,member) \ | |
880 | { \ | |
881 | struct type ldi = {0}; \ | |
dda83cd7 | 882 | \ |
1c432e72 | 883 | printf (" {%d, %d},\t/* %s */\n", \ |
dda83cd7 SM |
884 | offsetof (struct type, member), \ |
885 | sizeof (ldi.member), \ | |
886 | #member); \ | |
1c432e72 JB |
887 | } \ |
888 | while (0) | |
889 | ||
890 | int | |
891 | main (void) | |
892 | { | |
893 | printf ("static const struct ld_info_desc ld_info32_desc =\n{\n"); | |
894 | pinfo (__ld_info32, ldinfo_next); | |
895 | pinfo (__ld_info32, ldinfo_fd); | |
896 | pinfo (__ld_info32, ldinfo_textorg); | |
897 | pinfo (__ld_info32, ldinfo_textsize); | |
898 | pinfo (__ld_info32, ldinfo_dataorg); | |
899 | pinfo (__ld_info32, ldinfo_datasize); | |
900 | pinfo (__ld_info32, ldinfo_filename); | |
901 | printf ("};\n"); | |
902 | ||
903 | printf ("\n"); | |
904 | ||
905 | printf ("static const struct ld_info_desc ld_info64_desc =\n{\n"); | |
906 | pinfo (__ld_info64, ldinfo_next); | |
907 | pinfo (__ld_info64, ldinfo_fd); | |
908 | pinfo (__ld_info64, ldinfo_textorg); | |
909 | pinfo (__ld_info64, ldinfo_textsize); | |
910 | pinfo (__ld_info64, ldinfo_dataorg); | |
911 | pinfo (__ld_info64, ldinfo_datasize); | |
912 | pinfo (__ld_info64, ldinfo_filename); | |
913 | printf ("};\n"); | |
914 | ||
915 | return 0; | |
916 | } | |
356a5233 JB |
917 | #endif /* 0 */ |
918 | ||
919 | /* Layout of the 32bit version of struct ld_info. */ | |
920 | ||
921 | static const struct ld_info_desc ld_info32_desc = | |
922 | { | |
923 | {0, 4}, /* ldinfo_next */ | |
924 | {4, 4}, /* ldinfo_fd */ | |
925 | {8, 4}, /* ldinfo_textorg */ | |
926 | {12, 4}, /* ldinfo_textsize */ | |
927 | {16, 4}, /* ldinfo_dataorg */ | |
928 | {20, 4}, /* ldinfo_datasize */ | |
929 | {24, 2}, /* ldinfo_filename */ | |
930 | }; | |
931 | ||
932 | /* Layout of the 64bit version of struct ld_info. */ | |
933 | ||
934 | static const struct ld_info_desc ld_info64_desc = | |
935 | { | |
936 | {0, 4}, /* ldinfo_next */ | |
937 | {8, 4}, /* ldinfo_fd */ | |
938 | {16, 8}, /* ldinfo_textorg */ | |
939 | {24, 8}, /* ldinfo_textsize */ | |
940 | {32, 8}, /* ldinfo_dataorg */ | |
941 | {40, 8}, /* ldinfo_datasize */ | |
942 | {48, 2}, /* ldinfo_filename */ | |
943 | }; | |
944 | ||
945 | /* A structured representation of one entry read from the ld_info | |
946 | binary data provided by the AIX loader. */ | |
947 | ||
948 | struct ld_info | |
949 | { | |
950 | ULONGEST next; | |
951 | int fd; | |
952 | CORE_ADDR textorg; | |
953 | ULONGEST textsize; | |
954 | CORE_ADDR dataorg; | |
955 | ULONGEST datasize; | |
956 | char *filename; | |
957 | char *member_name; | |
958 | }; | |
959 | ||
960 | /* Return a struct ld_info object corresponding to the entry at | |
961 | LDI_BUF. | |
962 | ||
963 | Note that the filename and member_name strings still point | |
964 | to the data in LDI_BUF. So LDI_BUF must not be deallocated | |
965 | while the struct ld_info object returned is in use. */ | |
966 | ||
967 | static struct ld_info | |
968 | rs6000_aix_extract_ld_info (struct gdbarch *gdbarch, | |
969 | const gdb_byte *ldi_buf) | |
970 | { | |
971 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
972 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
973 | struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; | |
974 | const struct ld_info_desc desc | |
975 | = tdep->wordsize == 8 ? ld_info64_desc : ld_info32_desc; | |
976 | struct ld_info info; | |
977 | ||
978 | info.next = extract_unsigned_integer (ldi_buf + desc.ldinfo_next.offset, | |
979 | desc.ldinfo_next.size, | |
980 | byte_order); | |
981 | info.fd = extract_signed_integer (ldi_buf + desc.ldinfo_fd.offset, | |
982 | desc.ldinfo_fd.size, | |
983 | byte_order); | |
984 | info.textorg = extract_typed_address (ldi_buf + desc.ldinfo_textorg.offset, | |
985 | ptr_type); | |
986 | info.textsize | |
987 | = extract_unsigned_integer (ldi_buf + desc.ldinfo_textsize.offset, | |
988 | desc.ldinfo_textsize.size, | |
989 | byte_order); | |
990 | info.dataorg = extract_typed_address (ldi_buf + desc.ldinfo_dataorg.offset, | |
991 | ptr_type); | |
992 | info.datasize | |
993 | = extract_unsigned_integer (ldi_buf + desc.ldinfo_datasize.offset, | |
994 | desc.ldinfo_datasize.size, | |
995 | byte_order); | |
996 | info.filename = (char *) ldi_buf + desc.ldinfo_filename.offset; | |
997 | info.member_name = info.filename + strlen (info.filename) + 1; | |
998 | ||
999 | return info; | |
1000 | } | |
1001 | ||
1002 | /* Append to OBJSTACK an XML string description of the shared library | |
1003 | corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX | |
1004 | format. */ | |
1005 | ||
1006 | static void | |
1007 | rs6000_aix_shared_library_to_xml (struct ld_info *ldi, | |
1008 | struct obstack *obstack) | |
1009 | { | |
356a5233 | 1010 | obstack_grow_str (obstack, "<library name=\""); |
5e187554 SM |
1011 | std::string p = xml_escape_text (ldi->filename); |
1012 | obstack_grow_str (obstack, p.c_str ()); | |
356a5233 JB |
1013 | obstack_grow_str (obstack, "\""); |
1014 | ||
1015 | if (ldi->member_name[0] != '\0') | |
1016 | { | |
1017 | obstack_grow_str (obstack, " member=\""); | |
1018 | p = xml_escape_text (ldi->member_name); | |
5e187554 | 1019 | obstack_grow_str (obstack, p.c_str ()); |
356a5233 JB |
1020 | obstack_grow_str (obstack, "\""); |
1021 | } | |
1022 | ||
1023 | obstack_grow_str (obstack, " text_addr=\""); | |
1024 | obstack_grow_str (obstack, core_addr_to_string (ldi->textorg)); | |
1025 | obstack_grow_str (obstack, "\""); | |
1026 | ||
1027 | obstack_grow_str (obstack, " text_size=\""); | |
1028 | obstack_grow_str (obstack, pulongest (ldi->textsize)); | |
1029 | obstack_grow_str (obstack, "\""); | |
1030 | ||
1031 | obstack_grow_str (obstack, " data_addr=\""); | |
1032 | obstack_grow_str (obstack, core_addr_to_string (ldi->dataorg)); | |
1033 | obstack_grow_str (obstack, "\""); | |
1034 | ||
1035 | obstack_grow_str (obstack, " data_size=\""); | |
1036 | obstack_grow_str (obstack, pulongest (ldi->datasize)); | |
1037 | obstack_grow_str (obstack, "\""); | |
1038 | ||
1039 | obstack_grow_str (obstack, "></library>"); | |
1040 | } | |
1041 | ||
1042 | /* Convert the ld_info binary data provided by the AIX loader into | |
1043 | an XML representation following the TARGET_OBJECT_LIBRARIES_AIX | |
1044 | format. | |
1045 | ||
1046 | LDI_BUF is a buffer containing the ld_info data. | |
1047 | READBUF, OFFSET and LEN follow the same semantics as target_ops' | |
1048 | to_xfer_partial target_ops method. | |
1049 | ||
1050 | If CLOSE_LDINFO_FD is nonzero, then this routine also closes | |
1051 | the ldinfo_fd file descriptor. This is useful when the ldinfo | |
1052 | data is obtained via ptrace, as ptrace opens a file descriptor | |
1053 | for each and every entry; but we cannot use this descriptor | |
1054 | as the consumer of the XML library list might live in a different | |
1055 | process. */ | |
1056 | ||
c09f20e4 | 1057 | ULONGEST |
356a5233 | 1058 | rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf, |
b55e14c7 | 1059 | gdb_byte *readbuf, ULONGEST offset, ULONGEST len, |
356a5233 JB |
1060 | int close_ldinfo_fd) |
1061 | { | |
1062 | struct obstack obstack; | |
1063 | const char *buf; | |
c09f20e4 | 1064 | ULONGEST len_avail; |
356a5233 JB |
1065 | |
1066 | obstack_init (&obstack); | |
1067 | obstack_grow_str (&obstack, "<library-list-aix version=\"1.0\">\n"); | |
1068 | ||
1069 | while (1) | |
1070 | { | |
1071 | struct ld_info ldi = rs6000_aix_extract_ld_info (gdbarch, ldi_buf); | |
1072 | ||
1073 | rs6000_aix_shared_library_to_xml (&ldi, &obstack); | |
1074 | if (close_ldinfo_fd) | |
1075 | close (ldi.fd); | |
1076 | ||
1077 | if (!ldi.next) | |
1078 | break; | |
1079 | ldi_buf = ldi_buf + ldi.next; | |
1080 | } | |
1081 | ||
1082 | obstack_grow_str0 (&obstack, "</library-list-aix>\n"); | |
1083 | ||
224c3ddb | 1084 | buf = (const char *) obstack_finish (&obstack); |
356a5233 JB |
1085 | len_avail = strlen (buf); |
1086 | if (offset >= len_avail) | |
1087 | len= 0; | |
1088 | else | |
1089 | { | |
1090 | if (len > len_avail - offset) | |
dda83cd7 | 1091 | len = len_avail - offset; |
356a5233 JB |
1092 | memcpy (readbuf, buf + offset, len); |
1093 | } | |
1094 | ||
1095 | obstack_free (&obstack, NULL); | |
1096 | return len; | |
1097 | } | |
1098 | ||
1099 | /* Implement the core_xfer_shared_libraries_aix gdbarch method. */ | |
1100 | ||
c09f20e4 | 1101 | static ULONGEST |
356a5233 JB |
1102 | rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, |
1103 | gdb_byte *readbuf, | |
1104 | ULONGEST offset, | |
7ec1862d | 1105 | ULONGEST len) |
356a5233 JB |
1106 | { |
1107 | struct bfd_section *ldinfo_sec; | |
1108 | int ldinfo_size; | |
356a5233 JB |
1109 | |
1110 | ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo"); | |
1111 | if (ldinfo_sec == NULL) | |
1112 | error (_("cannot find .ldinfo section from core file: %s"), | |
1113 | bfd_errmsg (bfd_get_error ())); | |
fd361982 | 1114 | ldinfo_size = bfd_section_size (ldinfo_sec); |
356a5233 | 1115 | |
984c7238 | 1116 | gdb::byte_vector ldinfo_buf (ldinfo_size); |
356a5233 JB |
1117 | |
1118 | if (! bfd_get_section_contents (core_bfd, ldinfo_sec, | |
984c7238 | 1119 | ldinfo_buf.data (), 0, ldinfo_size)) |
356a5233 JB |
1120 | error (_("unable to read .ldinfo section from core file: %s"), |
1121 | bfd_errmsg (bfd_get_error ())); | |
1122 | ||
984c7238 TT |
1123 | return rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf.data (), readbuf, |
1124 | offset, len, 0); | |
356a5233 JB |
1125 | } |
1126 | ||
1f82754b JB |
1127 | static void |
1128 | rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1129 | { | |
4a7622d1 UW |
1130 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1131 | ||
1f82754b JB |
1132 | /* RS6000/AIX does not support PT_STEP. Has to be simulated. */ |
1133 | set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step); | |
6f7f3f0d | 1134 | |
2454a024 | 1135 | /* Displaced stepping is currently not supported in combination with |
187b041e SM |
1136 | software single-stepping. These override the values set by |
1137 | rs6000_gdbarch_init. */ | |
2454a024 UW |
1138 | set_gdbarch_displaced_step_copy_insn (gdbarch, NULL); |
1139 | set_gdbarch_displaced_step_fixup (gdbarch, NULL); | |
187b041e SM |
1140 | set_gdbarch_displaced_step_prepare (gdbarch, NULL); |
1141 | set_gdbarch_displaced_step_finish (gdbarch, NULL); | |
2454a024 | 1142 | |
4a7622d1 UW |
1143 | set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call); |
1144 | set_gdbarch_return_value (gdbarch, rs6000_return_value); | |
1145 | set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); | |
1146 | ||
1147 | /* Handle RS/6000 function pointers (which are really function | |
1148 | descriptors). */ | |
1149 | set_gdbarch_convert_from_func_ptr_addr | |
1150 | (gdbarch, rs6000_convert_from_func_ptr_addr); | |
1151 | ||
7a61a01c | 1152 | /* Core file support. */ |
23ea9aeb AA |
1153 | set_gdbarch_iterate_over_regset_sections |
1154 | (gdbarch, rs6000_aix_iterate_over_regset_sections); | |
356a5233 JB |
1155 | set_gdbarch_core_xfer_shared_libraries_aix |
1156 | (gdbarch, rs6000_aix_core_xfer_shared_libraries_aix); | |
7a61a01c | 1157 | |
4a7622d1 UW |
1158 | if (tdep->wordsize == 8) |
1159 | tdep->lr_frame_offset = 16; | |
1160 | else | |
1161 | tdep->lr_frame_offset = 8; | |
1162 | ||
1163 | if (tdep->wordsize == 4) | |
1164 | /* PowerOpen / AIX 32 bit. The saved area or red zone consists of | |
1165 | 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes. | |
1166 | Problem is, 220 isn't frame (16 byte) aligned. Round it up to | |
1167 | 224. */ | |
1168 | set_gdbarch_frame_red_zone_size (gdbarch, 224); | |
1169 | else | |
1170 | set_gdbarch_frame_red_zone_size (gdbarch, 0); | |
38a69d0a | 1171 | |
53375380 PA |
1172 | if (tdep->wordsize == 8) |
1173 | set_gdbarch_wchar_bit (gdbarch, 32); | |
1174 | else | |
1175 | set_gdbarch_wchar_bit (gdbarch, 16); | |
1176 | set_gdbarch_wchar_signed (gdbarch, 0); | |
38a69d0a | 1177 | set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset); |
4d1eb6b4 JB |
1178 | |
1179 | set_solib_ops (gdbarch, &solib_aix_so_ops); | |
cdcda965 | 1180 | frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind); |
1f82754b JB |
1181 | } |
1182 | ||
6c265988 | 1183 | void _initialize_rs6000_aix_tdep (); |
1f82754b | 1184 | void |
6c265988 | 1185 | _initialize_rs6000_aix_tdep () |
1f82754b JB |
1186 | { |
1187 | gdbarch_register_osabi_sniffer (bfd_arch_rs6000, | |
dda83cd7 SM |
1188 | bfd_target_xcoff_flavour, |
1189 | rs6000_aix_osabi_sniffer); | |
7a61a01c | 1190 | gdbarch_register_osabi_sniffer (bfd_arch_powerpc, |
dda83cd7 SM |
1191 | bfd_target_xcoff_flavour, |
1192 | rs6000_aix_osabi_sniffer); | |
1f82754b JB |
1193 | |
1194 | gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_AIX, | |
dda83cd7 | 1195 | rs6000_aix_init_osabi); |
7a61a01c | 1196 | gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_AIX, |
dda83cd7 | 1197 | rs6000_aix_init_osabi); |
1f82754b JB |
1198 | } |
1199 |