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