Commit | Line | Data |
---|---|---|
7b112f9c JT |
1 | /* Target-dependent code for PowerPC systems using the SVR4 ABI |
2 | for GDB, the GNU debugger. | |
3 | ||
6066c3de | 4 | Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
7b112f9c JT |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "gdbcore.h" | |
25 | #include "inferior.h" | |
26 | #include "regcache.h" | |
27 | #include "value.h" | |
bdf64bac | 28 | #include "gdb_string.h" |
8be9034a | 29 | #include "gdb_assert.h" |
7b112f9c | 30 | #include "ppc-tdep.h" |
6066c3de | 31 | #include "target.h" |
0a90bcdd | 32 | #include "objfiles.h" |
7b112f9c | 33 | |
7b112f9c JT |
34 | /* Pass the arguments in either registers, or in the stack. Using the |
35 | ppc sysv ABI, the first eight words of the argument list (that might | |
36 | be less than eight parameters if some parameters occupy more than one | |
37 | word) are passed in r3..r10 registers. float and double parameters are | |
38 | passed in fpr's, in addition to that. Rest of the parameters if any | |
39 | are passed in user stack. | |
40 | ||
41 | If the function is returning a structure, then the return address is passed | |
42 | in r3, then the first 7 words of the parametes can be passed in registers, | |
43 | starting from r4. */ | |
44 | ||
45 | CORE_ADDR | |
77b2b6d4 AC |
46 | ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr, |
47 | struct regcache *regcache, CORE_ADDR bp_addr, | |
48 | int nargs, struct value **args, CORE_ADDR sp, | |
49 | int struct_return, CORE_ADDR struct_addr) | |
7b112f9c | 50 | { |
0a613259 | 51 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
68856ea3 AC |
52 | const CORE_ADDR saved_sp = read_sp (); |
53 | int argspace = 0; /* 0 is an initial wrong guess. */ | |
54 | int write_pass; | |
7b112f9c | 55 | |
68856ea3 | 56 | /* Go through the argument list twice. |
7b112f9c | 57 | |
68856ea3 AC |
58 | Pass 1: Figure out how much new stack space is required for |
59 | arguments and pushed values. Unlike the PowerOpen ABI, the SysV | |
60 | ABI doesn't reserve any extra space for parameters which are put | |
61 | in registers, but does always push structures and then pass their | |
62 | address. | |
7a41266b | 63 | |
68856ea3 AC |
64 | Pass 2: Replay the same computation but this time also write the |
65 | values out to the target. */ | |
7b112f9c | 66 | |
68856ea3 AC |
67 | for (write_pass = 0; write_pass < 2; write_pass++) |
68 | { | |
69 | int argno; | |
70 | /* Next available floating point register for float and double | |
71 | arguments. */ | |
72 | int freg = 1; | |
73 | /* Next available general register for non-float, non-vector | |
74 | arguments. */ | |
75 | int greg = 3; | |
76 | /* Next available vector register for vector arguments. */ | |
77 | int vreg = 2; | |
78 | /* Arguments start above the "LR save word" and "Back chain". */ | |
79 | int argoffset = 2 * tdep->wordsize; | |
80 | /* Structures start after the arguments. */ | |
81 | int structoffset = argoffset + argspace; | |
82 | ||
83 | /* If the function is returning a `struct', then the first word | |
944fcfab AC |
84 | (which will be passed in r3) is used for struct return |
85 | address. In that case we should advance one word and start | |
86 | from r4 register to copy parameters. */ | |
68856ea3 | 87 | if (struct_return) |
7b112f9c | 88 | { |
68856ea3 AC |
89 | if (write_pass) |
90 | regcache_cooked_write_signed (regcache, | |
91 | tdep->ppc_gp0_regnum + greg, | |
92 | struct_addr); | |
93 | greg++; | |
7b112f9c | 94 | } |
68856ea3 AC |
95 | |
96 | for (argno = 0; argno < nargs; argno++) | |
7b112f9c | 97 | { |
68856ea3 AC |
98 | struct value *arg = args[argno]; |
99 | struct type *type = check_typedef (VALUE_TYPE (arg)); | |
100 | int len = TYPE_LENGTH (type); | |
101 | char *val = VALUE_CONTENTS (arg); | |
102 | ||
103 | if (TYPE_CODE (type) == TYPE_CODE_FLT | |
944fcfab | 104 | && ppc_floating_point_unit_p (current_gdbarch) && len <= 8) |
7b112f9c | 105 | { |
68856ea3 | 106 | /* Floating point value converted to "double" then |
944fcfab AC |
107 | passed in an FP register, when the registers run out, |
108 | 8 byte aligned stack is used. */ | |
68856ea3 AC |
109 | if (freg <= 8) |
110 | { | |
111 | if (write_pass) | |
112 | { | |
113 | /* Always store the floating point value using | |
944fcfab | 114 | the register's floating-point format. */ |
68856ea3 AC |
115 | char regval[MAX_REGISTER_SIZE]; |
116 | struct type *regtype | |
366f009f | 117 | = register_type (gdbarch, tdep->ppc_fp0_regnum + freg); |
68856ea3 | 118 | convert_typed_floating (val, type, regval, regtype); |
366f009f JB |
119 | regcache_cooked_write (regcache, |
120 | tdep->ppc_fp0_regnum + freg, | |
68856ea3 AC |
121 | regval); |
122 | } | |
123 | freg++; | |
124 | } | |
7b112f9c JT |
125 | else |
126 | { | |
68856ea3 | 127 | /* SysV ABI converts floats to doubles before |
944fcfab | 128 | writing them to an 8 byte aligned stack location. */ |
68856ea3 AC |
129 | argoffset = align_up (argoffset, 8); |
130 | if (write_pass) | |
131 | { | |
132 | char memval[8]; | |
133 | struct type *memtype; | |
134 | switch (TARGET_BYTE_ORDER) | |
135 | { | |
136 | case BFD_ENDIAN_BIG: | |
137 | memtype = builtin_type_ieee_double_big; | |
138 | break; | |
139 | case BFD_ENDIAN_LITTLE: | |
140 | memtype = builtin_type_ieee_double_little; | |
141 | break; | |
142 | default: | |
143 | internal_error (__FILE__, __LINE__, "bad switch"); | |
144 | } | |
145 | convert_typed_floating (val, type, memval, memtype); | |
146 | write_memory (sp + argoffset, val, len); | |
147 | } | |
148 | argoffset += 8; | |
7b112f9c JT |
149 | } |
150 | } | |
944fcfab AC |
151 | else if (len == 8 && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */ |
152 | || (!ppc_floating_point_unit_p (current_gdbarch) && TYPE_CODE (type) == TYPE_CODE_FLT))) /* double */ | |
7b112f9c | 153 | { |
68856ea3 | 154 | /* "long long" or "double" passed in an odd/even |
944fcfab AC |
155 | register pair with the low addressed word in the odd |
156 | register and the high addressed word in the even | |
157 | register, or when the registers run out an 8 byte | |
158 | aligned stack location. */ | |
68856ea3 AC |
159 | if (greg > 9) |
160 | { | |
161 | /* Just in case GREG was 10. */ | |
162 | greg = 11; | |
163 | argoffset = align_up (argoffset, 8); | |
164 | if (write_pass) | |
165 | write_memory (sp + argoffset, val, len); | |
166 | argoffset += 8; | |
167 | } | |
168 | else if (tdep->wordsize == 8) | |
169 | { | |
170 | if (write_pass) | |
171 | regcache_cooked_write (regcache, | |
944fcfab | 172 | tdep->ppc_gp0_regnum + greg, val); |
68856ea3 AC |
173 | greg += 1; |
174 | } | |
175 | else | |
176 | { | |
177 | /* Must start on an odd register - r3/r4 etc. */ | |
178 | if ((greg & 1) == 0) | |
179 | greg++; | |
180 | if (write_pass) | |
181 | { | |
182 | regcache_cooked_write (regcache, | |
183 | tdep->ppc_gp0_regnum + greg + 0, | |
184 | val + 0); | |
185 | regcache_cooked_write (regcache, | |
186 | tdep->ppc_gp0_regnum + greg + 1, | |
187 | val + 4); | |
188 | } | |
189 | greg += 2; | |
190 | } | |
7b112f9c | 191 | } |
68856ea3 AC |
192 | else if (len == 16 |
193 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
944fcfab | 194 | && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0) |
7b112f9c | 195 | { |
68856ea3 | 196 | /* Vector parameter passed in an Altivec register, or |
944fcfab | 197 | when that runs out, 16 byte aligned stack location. */ |
7b112f9c JT |
198 | if (vreg <= 13) |
199 | { | |
68856ea3 AC |
200 | if (write_pass) |
201 | regcache_cooked_write (current_regcache, | |
944fcfab | 202 | tdep->ppc_vr0_regnum + vreg, val); |
7b112f9c JT |
203 | vreg++; |
204 | } | |
205 | else | |
206 | { | |
68856ea3 AC |
207 | argoffset = align_up (argoffset, 16); |
208 | if (write_pass) | |
209 | write_memory (sp + argoffset, val, 16); | |
7b112f9c JT |
210 | argoffset += 16; |
211 | } | |
212 | } | |
944fcfab | 213 | else if (len == 8 |
0a613259 | 214 | && TYPE_CODE (type) == TYPE_CODE_ARRAY |
944fcfab AC |
215 | && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0) |
216 | { | |
68856ea3 | 217 | /* Vector parameter passed in an e500 register, or when |
944fcfab AC |
218 | that runs out, 8 byte aligned stack location. Note |
219 | that since e500 vector and general purpose registers | |
220 | both map onto the same underlying register set, a | |
221 | "greg" and not a "vreg" is consumed here. A cooked | |
222 | write stores the value in the correct locations | |
223 | within the raw register cache. */ | |
224 | if (greg <= 10) | |
225 | { | |
68856ea3 AC |
226 | if (write_pass) |
227 | regcache_cooked_write (current_regcache, | |
944fcfab AC |
228 | tdep->ppc_ev0_regnum + greg, val); |
229 | greg++; | |
230 | } | |
231 | else | |
232 | { | |
68856ea3 AC |
233 | argoffset = align_up (argoffset, 8); |
234 | if (write_pass) | |
235 | write_memory (sp + argoffset, val, 8); | |
944fcfab AC |
236 | argoffset += 8; |
237 | } | |
238 | } | |
68856ea3 AC |
239 | else |
240 | { | |
241 | /* Reduce the parameter down to something that fits in a | |
944fcfab | 242 | "word". */ |
68856ea3 AC |
243 | char word[MAX_REGISTER_SIZE]; |
244 | memset (word, 0, MAX_REGISTER_SIZE); | |
245 | if (len > tdep->wordsize | |
246 | || TYPE_CODE (type) == TYPE_CODE_STRUCT | |
247 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
248 | { | |
249 | /* Structs and large values are put on an 8 byte | |
944fcfab | 250 | aligned stack ... */ |
68856ea3 AC |
251 | structoffset = align_up (structoffset, 8); |
252 | if (write_pass) | |
253 | write_memory (sp + structoffset, val, len); | |
254 | /* ... and then a "word" pointing to that address is | |
944fcfab | 255 | passed as the parameter. */ |
68856ea3 AC |
256 | store_unsigned_integer (word, tdep->wordsize, |
257 | sp + structoffset); | |
258 | structoffset += len; | |
259 | } | |
260 | else if (TYPE_CODE (type) == TYPE_CODE_INT) | |
261 | /* Sign or zero extend the "int" into a "word". */ | |
262 | store_unsigned_integer (word, tdep->wordsize, | |
263 | unpack_long (type, val)); | |
264 | else | |
265 | /* Always goes in the low address. */ | |
266 | memcpy (word, val, len); | |
267 | /* Store that "word" in a register, or on the stack. | |
944fcfab | 268 | The words have "4" byte alignment. */ |
68856ea3 AC |
269 | if (greg <= 10) |
270 | { | |
271 | if (write_pass) | |
272 | regcache_cooked_write (regcache, | |
944fcfab | 273 | tdep->ppc_gp0_regnum + greg, word); |
68856ea3 AC |
274 | greg++; |
275 | } | |
276 | else | |
277 | { | |
278 | argoffset = align_up (argoffset, tdep->wordsize); | |
279 | if (write_pass) | |
280 | write_memory (sp + argoffset, word, tdep->wordsize); | |
281 | argoffset += tdep->wordsize; | |
282 | } | |
283 | } | |
284 | } | |
285 | ||
286 | /* Compute the actual stack space requirements. */ | |
287 | if (!write_pass) | |
288 | { | |
289 | /* Remember the amount of space needed by the arguments. */ | |
290 | argspace = argoffset; | |
291 | /* Allocate space for both the arguments and the structures. */ | |
292 | sp -= (argoffset + structoffset); | |
293 | /* Ensure that the stack is still 16 byte aligned. */ | |
294 | sp = align_down (sp, 16); | |
295 | } | |
7b112f9c JT |
296 | } |
297 | ||
68856ea3 AC |
298 | /* Update %sp. */ |
299 | regcache_cooked_write_signed (regcache, SP_REGNUM, sp); | |
300 | ||
301 | /* Write the backchain (it occupies WORDSIZED bytes). */ | |
302 | write_memory_signed_integer (sp, tdep->wordsize, saved_sp); | |
303 | ||
e56a0ecc AC |
304 | /* Point the inferior function call's return address at the dummy's |
305 | breakpoint. */ | |
68856ea3 | 306 | regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); |
e56a0ecc | 307 | |
7b112f9c JT |
308 | return sp; |
309 | } | |
310 | ||
e754ae69 AC |
311 | /* Handle the return-value conventions specified by the SysV 32-bit |
312 | PowerPC ABI (including all the supplements): | |
313 | ||
314 | no floating-point: floating-point values returned using 32-bit | |
315 | general-purpose registers. | |
316 | ||
317 | Altivec: 128-bit vectors returned using vector registers. | |
318 | ||
319 | e500: 64-bit vectors returned using the full full 64 bit EV | |
320 | register, floating-point values returned using 32-bit | |
321 | general-purpose registers. | |
322 | ||
323 | GCC (broken): Small struct values right (instead of left) aligned | |
324 | when returned in general-purpose registers. */ | |
325 | ||
326 | static enum return_value_convention | |
05580c65 | 327 | do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type, |
963e2bb7 AC |
328 | struct regcache *regcache, void *readbuf, |
329 | const void *writebuf, int broken_gcc) | |
e754ae69 | 330 | { |
05580c65 | 331 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e754ae69 AC |
332 | gdb_assert (tdep->wordsize == 4); |
333 | if (TYPE_CODE (type) == TYPE_CODE_FLT | |
334 | && TYPE_LENGTH (type) <= 8 | |
05580c65 | 335 | && ppc_floating_point_unit_p (gdbarch)) |
e754ae69 | 336 | { |
963e2bb7 | 337 | if (readbuf) |
e754ae69 AC |
338 | { |
339 | /* Floats and doubles stored in "f1". Convert the value to | |
340 | the required type. */ | |
341 | char regval[MAX_REGISTER_SIZE]; | |
366f009f JB |
342 | struct type *regtype = register_type (gdbarch, |
343 | tdep->ppc_fp0_regnum + 1); | |
344 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); | |
963e2bb7 | 345 | convert_typed_floating (regval, regtype, readbuf, type); |
e754ae69 | 346 | } |
963e2bb7 | 347 | if (writebuf) |
e754ae69 AC |
348 | { |
349 | /* Floats and doubles stored in "f1". Convert the value to | |
350 | the register's "double" type. */ | |
351 | char regval[MAX_REGISTER_SIZE]; | |
366f009f | 352 | struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 353 | convert_typed_floating (writebuf, type, regval, regtype); |
366f009f | 354 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); |
e754ae69 AC |
355 | } |
356 | return RETURN_VALUE_REGISTER_CONVENTION; | |
357 | } | |
358 | if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8) | |
359 | || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)) | |
360 | { | |
963e2bb7 | 361 | if (readbuf) |
e754ae69 AC |
362 | { |
363 | /* A long long, or a double stored in the 32 bit r3/r4. */ | |
364 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 365 | (bfd_byte *) readbuf + 0); |
e754ae69 | 366 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, |
963e2bb7 | 367 | (bfd_byte *) readbuf + 4); |
e754ae69 | 368 | } |
963e2bb7 | 369 | if (writebuf) |
e754ae69 AC |
370 | { |
371 | /* A long long, or a double stored in the 32 bit r3/r4. */ | |
372 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 373 | (const bfd_byte *) writebuf + 0); |
e754ae69 | 374 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, |
963e2bb7 | 375 | (const bfd_byte *) writebuf + 4); |
e754ae69 AC |
376 | } |
377 | return RETURN_VALUE_REGISTER_CONVENTION; | |
378 | } | |
379 | if (TYPE_CODE (type) == TYPE_CODE_INT | |
380 | && TYPE_LENGTH (type) <= tdep->wordsize) | |
381 | { | |
963e2bb7 | 382 | if (readbuf) |
e754ae69 AC |
383 | { |
384 | /* Some sort of integer stored in r3. Since TYPE isn't | |
385 | bigger than the register, sign extension isn't a problem | |
386 | - just do everything unsigned. */ | |
387 | ULONGEST regval; | |
388 | regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
389 | ®val); | |
963e2bb7 | 390 | store_unsigned_integer (readbuf, TYPE_LENGTH (type), regval); |
e754ae69 | 391 | } |
963e2bb7 | 392 | if (writebuf) |
e754ae69 AC |
393 | { |
394 | /* Some sort of integer stored in r3. Use unpack_long since | |
395 | that should handle any required sign extension. */ | |
396 | regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 397 | unpack_long (type, writebuf)); |
e754ae69 AC |
398 | } |
399 | return RETURN_VALUE_REGISTER_CONVENTION; | |
400 | } | |
401 | if (TYPE_LENGTH (type) == 16 | |
402 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
403 | && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0) | |
404 | { | |
963e2bb7 | 405 | if (readbuf) |
e754ae69 AC |
406 | { |
407 | /* Altivec places the return value in "v2". */ | |
963e2bb7 | 408 | regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); |
e754ae69 | 409 | } |
963e2bb7 | 410 | if (writebuf) |
e754ae69 AC |
411 | { |
412 | /* Altivec places the return value in "v2". */ | |
963e2bb7 | 413 | regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); |
e754ae69 AC |
414 | } |
415 | return RETURN_VALUE_REGISTER_CONVENTION; | |
416 | } | |
417 | if (TYPE_LENGTH (type) == 8 | |
418 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
419 | && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0) | |
420 | { | |
421 | /* The e500 ABI places return values for the 64-bit DSP types | |
422 | (__ev64_opaque__) in r3. However, in GDB-speak, ev3 | |
423 | corresponds to the entire r3 value for e500, whereas GDB's r3 | |
424 | only corresponds to the least significant 32-bits. So place | |
425 | the 64-bit DSP type's value in ev3. */ | |
963e2bb7 AC |
426 | if (readbuf) |
427 | regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf); | |
428 | if (writebuf) | |
429 | regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf); | |
e754ae69 AC |
430 | return RETURN_VALUE_REGISTER_CONVENTION; |
431 | } | |
432 | if (broken_gcc && TYPE_LENGTH (type) <= 8) | |
433 | { | |
963e2bb7 | 434 | if (readbuf) |
e754ae69 AC |
435 | { |
436 | /* GCC screwed up. The last register isn't "left" aligned. | |
437 | Need to extract the least significant part of each | |
438 | register and then store that. */ | |
439 | /* Transfer any full words. */ | |
440 | int word = 0; | |
441 | while (1) | |
442 | { | |
443 | ULONGEST reg; | |
444 | int len = TYPE_LENGTH (type) - word * tdep->wordsize; | |
445 | if (len <= 0) | |
446 | break; | |
447 | if (len > tdep->wordsize) | |
448 | len = tdep->wordsize; | |
449 | regcache_cooked_read_unsigned (regcache, | |
450 | tdep->ppc_gp0_regnum + 3 + word, | |
451 | ®); | |
963e2bb7 | 452 | store_unsigned_integer (((bfd_byte *) readbuf |
e754ae69 AC |
453 | + word * tdep->wordsize), len, reg); |
454 | word++; | |
455 | } | |
456 | } | |
963e2bb7 | 457 | if (writebuf) |
e754ae69 AC |
458 | { |
459 | /* GCC screwed up. The last register isn't "left" aligned. | |
460 | Need to extract the least significant part of each | |
461 | register and then store that. */ | |
462 | /* Transfer any full words. */ | |
463 | int word = 0; | |
464 | while (1) | |
465 | { | |
466 | ULONGEST reg; | |
467 | int len = TYPE_LENGTH (type) - word * tdep->wordsize; | |
468 | if (len <= 0) | |
469 | break; | |
470 | if (len > tdep->wordsize) | |
471 | len = tdep->wordsize; | |
963e2bb7 | 472 | reg = extract_unsigned_integer (((const bfd_byte *) writebuf |
e754ae69 AC |
473 | + word * tdep->wordsize), len); |
474 | regcache_cooked_write_unsigned (regcache, | |
475 | tdep->ppc_gp0_regnum + 3 + word, | |
476 | reg); | |
477 | word++; | |
478 | } | |
479 | } | |
480 | return RETURN_VALUE_REGISTER_CONVENTION; | |
481 | } | |
482 | if (TYPE_LENGTH (type) <= 8) | |
483 | { | |
963e2bb7 | 484 | if (readbuf) |
e754ae69 AC |
485 | { |
486 | /* This matches SVr4 PPC, it does not match GCC. */ | |
487 | /* The value is right-padded to 8 bytes and then loaded, as | |
488 | two "words", into r3/r4. */ | |
489 | char regvals[MAX_REGISTER_SIZE * 2]; | |
490 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, | |
491 | regvals + 0 * tdep->wordsize); | |
492 | if (TYPE_LENGTH (type) > tdep->wordsize) | |
493 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
494 | regvals + 1 * tdep->wordsize); | |
963e2bb7 | 495 | memcpy (readbuf, regvals, TYPE_LENGTH (type)); |
e754ae69 | 496 | } |
963e2bb7 | 497 | if (writebuf) |
e754ae69 AC |
498 | { |
499 | /* This matches SVr4 PPC, it does not match GCC. */ | |
500 | /* The value is padded out to 8 bytes and then loaded, as | |
501 | two "words" into r3/r4. */ | |
502 | char regvals[MAX_REGISTER_SIZE * 2]; | |
503 | memset (regvals, 0, sizeof regvals); | |
963e2bb7 | 504 | memcpy (regvals, writebuf, TYPE_LENGTH (type)); |
e754ae69 AC |
505 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, |
506 | regvals + 0 * tdep->wordsize); | |
507 | if (TYPE_LENGTH (type) > tdep->wordsize) | |
508 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
509 | regvals + 1 * tdep->wordsize); | |
510 | } | |
511 | return RETURN_VALUE_REGISTER_CONVENTION; | |
512 | } | |
513 | return RETURN_VALUE_STRUCT_CONVENTION; | |
514 | } | |
515 | ||
05580c65 AC |
516 | enum return_value_convention |
517 | ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype, | |
963e2bb7 AC |
518 | struct regcache *regcache, void *readbuf, |
519 | const void *writebuf) | |
e754ae69 | 520 | { |
963e2bb7 AC |
521 | return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf, |
522 | writebuf, 0); | |
e754ae69 AC |
523 | } |
524 | ||
05580c65 | 525 | enum return_value_convention |
963e2bb7 AC |
526 | ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch, |
527 | struct type *valtype, | |
528 | struct regcache *regcache, | |
529 | void *readbuf, const void *writebuf) | |
e754ae69 | 530 | { |
963e2bb7 AC |
531 | return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf, |
532 | writebuf, 1); | |
944fcfab | 533 | } |
afd48b75 | 534 | |
8be9034a AC |
535 | /* Pass the arguments in either registers, or in the stack. Using the |
536 | ppc 64 bit SysV ABI. | |
537 | ||
538 | This implements a dumbed down version of the ABI. It always writes | |
539 | values to memory, GPR and FPR, even when not necessary. Doing this | |
540 | greatly simplifies the logic. */ | |
541 | ||
542 | CORE_ADDR | |
543 | ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr, | |
544 | struct regcache *regcache, CORE_ADDR bp_addr, | |
545 | int nargs, struct value **args, CORE_ADDR sp, | |
546 | int struct_return, CORE_ADDR struct_addr) | |
547 | { | |
548 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
549 | /* By this stage in the proceedings, SP has been decremented by "red | |
550 | zone size" + "struct return size". Fetch the stack-pointer from | |
551 | before this and use that as the BACK_CHAIN. */ | |
552 | const CORE_ADDR back_chain = read_sp (); | |
553 | /* See for-loop comment below. */ | |
554 | int write_pass; | |
555 | /* Size of the Altivec's vector parameter region, the final value is | |
556 | computed in the for-loop below. */ | |
557 | LONGEST vparam_size = 0; | |
558 | /* Size of the general parameter region, the final value is computed | |
559 | in the for-loop below. */ | |
560 | LONGEST gparam_size = 0; | |
561 | /* Kevin writes ... I don't mind seeing tdep->wordsize used in the | |
562 | calls to align_up(), align_down(), etc. because this makes it | |
563 | easier to reuse this code (in a copy/paste sense) in the future, | |
564 | but it is a 64-bit ABI and asserting that the wordsize is 8 bytes | |
565 | at some point makes it easier to verify that this function is | |
566 | correct without having to do a non-local analysis to figure out | |
567 | the possible values of tdep->wordsize. */ | |
568 | gdb_assert (tdep->wordsize == 8); | |
569 | ||
570 | /* Go through the argument list twice. | |
571 | ||
572 | Pass 1: Compute the function call's stack space and register | |
573 | requirements. | |
574 | ||
575 | Pass 2: Replay the same computation but this time also write the | |
576 | values out to the target. */ | |
577 | ||
578 | for (write_pass = 0; write_pass < 2; write_pass++) | |
579 | { | |
580 | int argno; | |
581 | /* Next available floating point register for float and double | |
582 | arguments. */ | |
583 | int freg = 1; | |
584 | /* Next available general register for non-vector (but possibly | |
585 | float) arguments. */ | |
586 | int greg = 3; | |
587 | /* Next available vector register for vector arguments. */ | |
588 | int vreg = 2; | |
589 | /* The address, at which the next general purpose parameter | |
590 | (integer, struct, float, ...) should be saved. */ | |
591 | CORE_ADDR gparam; | |
592 | /* Address, at which the next Altivec vector parameter should be | |
593 | saved. */ | |
594 | CORE_ADDR vparam; | |
595 | ||
596 | if (!write_pass) | |
597 | { | |
598 | /* During the first pass, GPARAM and VPARAM are more like | |
599 | offsets (start address zero) than addresses. That way | |
600 | the accumulate the total stack space each region | |
601 | requires. */ | |
602 | gparam = 0; | |
603 | vparam = 0; | |
604 | } | |
605 | else | |
606 | { | |
607 | /* Decrement the stack pointer making space for the Altivec | |
608 | and general on-stack parameters. Set vparam and gparam | |
609 | to their corresponding regions. */ | |
610 | vparam = align_down (sp - vparam_size, 16); | |
611 | gparam = align_down (vparam - gparam_size, 16); | |
612 | /* Add in space for the TOC, link editor double word, | |
613 | compiler double word, LR save area, CR save area. */ | |
614 | sp = align_down (gparam - 48, 16); | |
615 | } | |
616 | ||
617 | /* If the function is returning a `struct', then there is an | |
618 | extra hidden parameter (which will be passed in r3) | |
619 | containing the address of that struct.. In that case we | |
620 | should advance one word and start from r4 register to copy | |
621 | parameters. This also consumes one on-stack parameter slot. */ | |
622 | if (struct_return) | |
623 | { | |
624 | if (write_pass) | |
625 | regcache_cooked_write_signed (regcache, | |
626 | tdep->ppc_gp0_regnum + greg, | |
627 | struct_addr); | |
628 | greg++; | |
629 | gparam = align_up (gparam + tdep->wordsize, tdep->wordsize); | |
630 | } | |
631 | ||
632 | for (argno = 0; argno < nargs; argno++) | |
633 | { | |
634 | struct value *arg = args[argno]; | |
635 | struct type *type = check_typedef (VALUE_TYPE (arg)); | |
636 | char *val = VALUE_CONTENTS (arg); | |
637 | if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8) | |
638 | { | |
639 | /* Floats and Doubles go in f1 .. f13. They also | |
640 | consume a left aligned GREG,, and can end up in | |
641 | memory. */ | |
642 | if (write_pass) | |
643 | { | |
644 | if (ppc_floating_point_unit_p (current_gdbarch) | |
645 | && freg <= 13) | |
646 | { | |
647 | char regval[MAX_REGISTER_SIZE]; | |
366f009f JB |
648 | struct type *regtype |
649 | = register_type (gdbarch, tdep->ppc_fp0_regnum); | |
8be9034a | 650 | convert_typed_floating (val, type, regval, regtype); |
366f009f JB |
651 | regcache_cooked_write (regcache, |
652 | tdep->ppc_fp0_regnum + freg, | |
8be9034a AC |
653 | regval); |
654 | } | |
655 | if (greg <= 10) | |
656 | { | |
657 | /* The ABI states "Single precision floating | |
658 | point values are mapped to the first word in | |
659 | a single doubleword" and "... floating point | |
660 | values mapped to the first eight doublewords | |
661 | of the parameter save area are also passed in | |
662 | general registers"). | |
663 | ||
664 | This code interprets that to mean: store it, | |
665 | left aligned, in the general register. */ | |
666 | char regval[MAX_REGISTER_SIZE]; | |
667 | memset (regval, 0, sizeof regval); | |
668 | memcpy (regval, val, TYPE_LENGTH (type)); | |
669 | regcache_cooked_write (regcache, | |
670 | tdep->ppc_gp0_regnum + greg, | |
671 | regval); | |
672 | } | |
673 | write_memory (gparam, val, TYPE_LENGTH (type)); | |
674 | } | |
675 | /* Always consume parameter stack space. */ | |
676 | freg++; | |
677 | greg++; | |
678 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
679 | } | |
680 | else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type) | |
681 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
682 | && tdep->ppc_vr0_regnum >= 0) | |
683 | { | |
684 | /* In the Altivec ABI, vectors go in the vector | |
685 | registers v2 .. v13, or when that runs out, a vector | |
686 | annex which goes above all the normal parameters. | |
687 | NOTE: cagney/2003-09-21: This is a guess based on the | |
688 | PowerOpen Altivec ABI. */ | |
689 | if (vreg <= 13) | |
690 | { | |
691 | if (write_pass) | |
692 | regcache_cooked_write (regcache, | |
693 | tdep->ppc_vr0_regnum + vreg, val); | |
694 | vreg++; | |
695 | } | |
696 | else | |
697 | { | |
698 | if (write_pass) | |
699 | write_memory (vparam, val, TYPE_LENGTH (type)); | |
700 | vparam = align_up (vparam + TYPE_LENGTH (type), 16); | |
701 | } | |
702 | } | |
703 | else if ((TYPE_CODE (type) == TYPE_CODE_INT | |
704 | || TYPE_CODE (type) == TYPE_CODE_ENUM) | |
705 | && TYPE_LENGTH (type) <= 8) | |
706 | { | |
707 | /* Scalars get sign[un]extended and go in gpr3 .. gpr10. | |
708 | They can also end up in memory. */ | |
709 | if (write_pass) | |
710 | { | |
711 | /* Sign extend the value, then store it unsigned. */ | |
712 | ULONGEST word = unpack_long (type, val); | |
713 | if (greg <= 10) | |
714 | regcache_cooked_write_unsigned (regcache, | |
715 | tdep->ppc_gp0_regnum + | |
716 | greg, word); | |
717 | write_memory_unsigned_integer (gparam, tdep->wordsize, | |
718 | word); | |
719 | } | |
720 | greg++; | |
721 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
722 | } | |
723 | else | |
724 | { | |
725 | int byte; | |
726 | for (byte = 0; byte < TYPE_LENGTH (type); | |
727 | byte += tdep->wordsize) | |
728 | { | |
729 | if (write_pass && greg <= 10) | |
730 | { | |
731 | char regval[MAX_REGISTER_SIZE]; | |
732 | int len = TYPE_LENGTH (type) - byte; | |
733 | if (len > tdep->wordsize) | |
734 | len = tdep->wordsize; | |
735 | memset (regval, 0, sizeof regval); | |
736 | /* WARNING: cagney/2003-09-21: As best I can | |
737 | tell, the ABI specifies that the value should | |
738 | be left aligned. Unfortunately, GCC doesn't | |
739 | do this - it instead right aligns even sized | |
740 | values and puts odd sized values on the | |
741 | stack. Work around that by putting both a | |
742 | left and right aligned value into the | |
743 | register (hopefully no one notices :-^). | |
744 | Arrrgh! */ | |
745 | /* Left aligned (8 byte values such as pointers | |
746 | fill the buffer). */ | |
747 | memcpy (regval, val + byte, len); | |
748 | /* Right aligned (but only if even). */ | |
749 | if (len == 1 || len == 2 || len == 4) | |
750 | memcpy (regval + tdep->wordsize - len, | |
751 | val + byte, len); | |
752 | regcache_cooked_write (regcache, greg, regval); | |
753 | } | |
754 | greg++; | |
755 | } | |
756 | if (write_pass) | |
757 | /* WARNING: cagney/2003-09-21: Strictly speaking, this | |
758 | isn't necessary, unfortunately, GCC appears to get | |
759 | "struct convention" parameter passing wrong putting | |
760 | odd sized structures in memory instead of in a | |
761 | register. Work around this by always writing the | |
762 | value to memory. Fortunately, doing this | |
763 | simplifies the code. */ | |
764 | write_memory (gparam, val, TYPE_LENGTH (type)); | |
765 | /* Always consume parameter stack space. */ | |
766 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
767 | } | |
768 | } | |
769 | ||
770 | if (!write_pass) | |
771 | { | |
772 | /* Save the true region sizes ready for the second pass. */ | |
773 | vparam_size = vparam; | |
774 | /* Make certain that the general parameter save area is at | |
775 | least the minimum 8 registers (or doublewords) in size. */ | |
776 | if (greg < 8) | |
777 | gparam_size = 8 * tdep->wordsize; | |
778 | else | |
779 | gparam_size = gparam; | |
780 | } | |
781 | } | |
782 | ||
783 | /* Update %sp. */ | |
784 | regcache_cooked_write_signed (regcache, SP_REGNUM, sp); | |
785 | ||
786 | /* Write the backchain (it occupies WORDSIZED bytes). */ | |
787 | write_memory_signed_integer (sp, tdep->wordsize, back_chain); | |
788 | ||
789 | /* Point the inferior function call's return address at the dummy's | |
790 | breakpoint. */ | |
791 | regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); | |
792 | ||
793 | /* Find a value for the TOC register. Every symbol should have both | |
794 | ".FN" and "FN" in the minimal symbol table. "FN" points at the | |
795 | FN's descriptor, while ".FN" points at the entry point (which | |
796 | matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the | |
0a90bcdd AC |
797 | FN's descriptor address (while at the same time being careful to |
798 | find "FN" in the same object file as ".FN"). */ | |
8be9034a AC |
799 | { |
800 | /* Find the minimal symbol that corresponds to FUNC_ADDR (should | |
801 | have the name ".FN"). */ | |
802 | struct minimal_symbol *dot_fn = lookup_minimal_symbol_by_pc (func_addr); | |
803 | if (dot_fn != NULL && SYMBOL_LINKAGE_NAME (dot_fn)[0] == '.') | |
804 | { | |
0a90bcdd AC |
805 | /* Get the section that contains FUNC_ADR. Need this for the |
806 | "objfile" that it contains. */ | |
807 | struct obj_section *dot_fn_section = find_pc_section (func_addr); | |
808 | if (dot_fn_section != NULL && dot_fn_section->objfile != NULL) | |
8be9034a | 809 | { |
0a90bcdd AC |
810 | /* Now find the corresponding "FN" (dropping ".") minimal |
811 | symbol's address. Only look for the minimal symbol in | |
812 | ".FN"'s object file - avoids problems when two object | |
813 | files (i.e., shared libraries) contain a minimal symbol | |
814 | with the same name. */ | |
815 | struct minimal_symbol *fn = | |
816 | lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL, | |
817 | dot_fn_section->objfile); | |
818 | if (fn != NULL) | |
819 | { | |
820 | /* Got the address of that descriptor. The TOC is the | |
821 | second double word. */ | |
822 | CORE_ADDR toc = | |
823 | read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn) | |
824 | + tdep->wordsize, | |
825 | tdep->wordsize); | |
826 | regcache_cooked_write_unsigned (regcache, | |
827 | tdep->ppc_gp0_regnum + 2, toc); | |
828 | } | |
8be9034a AC |
829 | } |
830 | } | |
831 | } | |
832 | ||
833 | return sp; | |
834 | } | |
835 | ||
afd48b75 AC |
836 | |
837 | /* The 64 bit ABI retun value convention. | |
838 | ||
839 | Return non-zero if the return-value is stored in a register, return | |
840 | 0 if the return-value is instead stored on the stack (a.k.a., | |
841 | struct return convention). | |
842 | ||
963e2bb7 | 843 | For a return-value stored in a register: when WRITEBUF is non-NULL, |
afd48b75 | 844 | copy the buffer to the corresponding register return-value location |
963e2bb7 | 845 | location; when READBUF is non-NULL, fill the buffer from the |
afd48b75 | 846 | corresponding register return-value location. */ |
05580c65 AC |
847 | enum return_value_convention |
848 | ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype, | |
963e2bb7 AC |
849 | struct regcache *regcache, void *readbuf, |
850 | const void *writebuf) | |
afd48b75 | 851 | { |
05580c65 | 852 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
16796152 JB |
853 | |
854 | /* This function exists to support a calling convention that | |
855 | requires floating-point registers. It shouldn't be used on | |
856 | processors that lack them. */ | |
857 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
858 | ||
afd48b75 | 859 | /* Floats and doubles in F1. */ |
944fcfab | 860 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8) |
afd48b75 AC |
861 | { |
862 | char regval[MAX_REGISTER_SIZE]; | |
366f009f | 863 | struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 864 | if (writebuf != NULL) |
afd48b75 | 865 | { |
963e2bb7 | 866 | convert_typed_floating (writebuf, valtype, regval, regtype); |
366f009f | 867 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); |
afd48b75 | 868 | } |
963e2bb7 | 869 | if (readbuf != NULL) |
afd48b75 | 870 | { |
366f009f | 871 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); |
963e2bb7 | 872 | convert_typed_floating (regval, regtype, readbuf, valtype); |
afd48b75 AC |
873 | } |
874 | return RETURN_VALUE_REGISTER_CONVENTION; | |
875 | } | |
944fcfab | 876 | if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 8) |
afd48b75 AC |
877 | { |
878 | /* Integers in r3. */ | |
963e2bb7 | 879 | if (writebuf != NULL) |
afd48b75 AC |
880 | { |
881 | /* Be careful to sign extend the value. */ | |
882 | regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 883 | unpack_long (valtype, writebuf)); |
afd48b75 | 884 | } |
963e2bb7 | 885 | if (readbuf != NULL) |
afd48b75 AC |
886 | { |
887 | /* Extract the integer from r3. Since this is truncating the | |
888 | value, there isn't a sign extension problem. */ | |
889 | ULONGEST regval; | |
890 | regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
891 | ®val); | |
963e2bb7 | 892 | store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), regval); |
afd48b75 AC |
893 | } |
894 | return RETURN_VALUE_REGISTER_CONVENTION; | |
895 | } | |
896 | /* All pointers live in r3. */ | |
897 | if (TYPE_CODE (valtype) == TYPE_CODE_PTR) | |
898 | { | |
899 | /* All pointers live in r3. */ | |
963e2bb7 AC |
900 | if (writebuf != NULL) |
901 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); | |
902 | if (readbuf != NULL) | |
903 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf); | |
afd48b75 AC |
904 | return RETURN_VALUE_REGISTER_CONVENTION; |
905 | } | |
906 | if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY | |
907 | && TYPE_LENGTH (valtype) <= 8 | |
908 | && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT | |
909 | && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1) | |
910 | { | |
911 | /* Small character arrays are returned, right justified, in r3. */ | |
05580c65 | 912 | int offset = (register_size (gdbarch, tdep->ppc_gp0_regnum + 3) |
afd48b75 | 913 | - TYPE_LENGTH (valtype)); |
963e2bb7 | 914 | if (writebuf != NULL) |
afd48b75 | 915 | regcache_cooked_write_part (regcache, tdep->ppc_gp0_regnum + 3, |
963e2bb7 AC |
916 | offset, TYPE_LENGTH (valtype), writebuf); |
917 | if (readbuf != NULL) | |
afd48b75 | 918 | regcache_cooked_read_part (regcache, tdep->ppc_gp0_regnum + 3, |
963e2bb7 | 919 | offset, TYPE_LENGTH (valtype), readbuf); |
afd48b75 AC |
920 | return RETURN_VALUE_REGISTER_CONVENTION; |
921 | } | |
922 | /* Big floating point values get stored in adjacent floating | |
923 | point registers. */ | |
924 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT | |
944fcfab | 925 | && (TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 32)) |
afd48b75 | 926 | { |
963e2bb7 | 927 | if (writebuf || readbuf != NULL) |
afd48b75 AC |
928 | { |
929 | int i; | |
930 | for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++) | |
931 | { | |
963e2bb7 | 932 | if (writebuf != NULL) |
366f009f | 933 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 AC |
934 | (const bfd_byte *) writebuf + i * 8); |
935 | if (readbuf != NULL) | |
366f009f | 936 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 | 937 | (bfd_byte *) readbuf + i * 8); |
afd48b75 AC |
938 | } |
939 | } | |
940 | return RETURN_VALUE_REGISTER_CONVENTION; | |
941 | } | |
942 | /* Complex values get returned in f1:f2, need to convert. */ | |
943 | if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX | |
944 | && (TYPE_LENGTH (valtype) == 8 || TYPE_LENGTH (valtype) == 16)) | |
945 | { | |
946 | if (regcache != NULL) | |
947 | { | |
948 | int i; | |
949 | for (i = 0; i < 2; i++) | |
950 | { | |
951 | char regval[MAX_REGISTER_SIZE]; | |
944fcfab | 952 | struct type *regtype = |
366f009f | 953 | register_type (current_gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 954 | if (writebuf != NULL) |
afd48b75 | 955 | { |
963e2bb7 | 956 | convert_typed_floating ((const bfd_byte *) writebuf + |
944fcfab | 957 | i * (TYPE_LENGTH (valtype) / 2), |
afd48b75 | 958 | valtype, regval, regtype); |
366f009f JB |
959 | regcache_cooked_write (regcache, |
960 | tdep->ppc_fp0_regnum + 1 + i, | |
944fcfab | 961 | regval); |
afd48b75 | 962 | } |
963e2bb7 | 963 | if (readbuf != NULL) |
afd48b75 | 964 | { |
366f009f JB |
965 | regcache_cooked_read (regcache, |
966 | tdep->ppc_fp0_regnum + 1 + i, | |
967 | regval); | |
afd48b75 | 968 | convert_typed_floating (regval, regtype, |
963e2bb7 | 969 | (bfd_byte *) readbuf + |
944fcfab | 970 | i * (TYPE_LENGTH (valtype) / 2), |
afd48b75 AC |
971 | valtype); |
972 | } | |
973 | } | |
974 | } | |
975 | return RETURN_VALUE_REGISTER_CONVENTION; | |
976 | } | |
977 | /* Big complex values get stored in f1:f4. */ | |
944fcfab | 978 | if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && TYPE_LENGTH (valtype) == 32) |
afd48b75 AC |
979 | { |
980 | if (regcache != NULL) | |
981 | { | |
982 | int i; | |
983 | for (i = 0; i < 4; i++) | |
984 | { | |
963e2bb7 | 985 | if (writebuf != NULL) |
366f009f | 986 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 AC |
987 | (const bfd_byte *) writebuf + i * 8); |
988 | if (readbuf != NULL) | |
366f009f | 989 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 | 990 | (bfd_byte *) readbuf + i * 8); |
afd48b75 AC |
991 | } |
992 | } | |
993 | return RETURN_VALUE_REGISTER_CONVENTION; | |
994 | } | |
995 | return RETURN_VALUE_STRUCT_CONVENTION; | |
996 | } | |
997 | ||
6066c3de AC |
998 | CORE_ADDR |
999 | ppc64_sysv_abi_adjust_breakpoint_address (struct gdbarch *gdbarch, | |
1000 | CORE_ADDR bpaddr) | |
1001 | { | |
1002 | /* PPC64 SYSV specifies that the minimal-symbol "FN" should point at | |
1003 | a function-descriptor while the corresponding minimal-symbol | |
1004 | ".FN" should point at the entry point. Consequently, a command | |
1005 | like "break FN" applied to an object file with only minimal | |
1006 | symbols, will insert the breakpoint into the descriptor at "FN" | |
1007 | and not the function at ".FN". Avoid this confusion by adjusting | |
1008 | any attempt to set a descriptor breakpoint into a corresponding | |
1009 | function breakpoint. Note that GDB warns the user when this | |
1010 | adjustment is applied - that's ok as otherwise the user will have | |
1011 | no way of knowing why their breakpoint at "FN" resulted in the | |
1012 | program stopping at ".FN". */ | |
1013 | return gdbarch_convert_from_func_ptr_addr (gdbarch, bpaddr, ¤t_target); | |
1014 | } |