Commit | Line | Data |
---|---|---|
7b112f9c JT |
1 | /* Target-dependent code for PowerPC systems using the SVR4 ABI |
2 | for GDB, the GNU debugger. | |
3 | ||
7b6bb8da | 4 | Copyright (C) 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011 |
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 | |
0df8b418 | 34 | /* Pass the arguments in either registers, or in the stack. Using the |
7b112f9c JT |
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 | |
0df8b418 MS |
38 | passed in fpr's, in addition to that. Rest of the parameters if any |
39 | are passed in user stack. | |
7b112f9c JT |
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, | |
0df8b418 | 43 | starting from r4. */ |
7b112f9c JT |
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 | { |
40a6adc1 | 51 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 52 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
fb4443d8 | 53 | ULONGEST saved_sp; |
68856ea3 AC |
54 | int argspace = 0; /* 0 is an initial wrong guess. */ |
55 | int write_pass; | |
7b112f9c | 56 | |
b14d30e1 JM |
57 | gdb_assert (tdep->wordsize == 4); |
58 | ||
40a6adc1 | 59 | regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), |
3e8c568d | 60 | &saved_sp); |
fb4443d8 | 61 | |
68856ea3 | 62 | /* Go through the argument list twice. |
7b112f9c | 63 | |
68856ea3 AC |
64 | Pass 1: Figure out how much new stack space is required for |
65 | arguments and pushed values. Unlike the PowerOpen ABI, the SysV | |
66 | ABI doesn't reserve any extra space for parameters which are put | |
67 | in registers, but does always push structures and then pass their | |
68 | address. | |
7a41266b | 69 | |
68856ea3 AC |
70 | Pass 2: Replay the same computation but this time also write the |
71 | values out to the target. */ | |
7b112f9c | 72 | |
68856ea3 AC |
73 | for (write_pass = 0; write_pass < 2; write_pass++) |
74 | { | |
75 | int argno; | |
76 | /* Next available floating point register for float and double | |
77 | arguments. */ | |
78 | int freg = 1; | |
79 | /* Next available general register for non-float, non-vector | |
80 | arguments. */ | |
81 | int greg = 3; | |
82 | /* Next available vector register for vector arguments. */ | |
83 | int vreg = 2; | |
84 | /* Arguments start above the "LR save word" and "Back chain". */ | |
85 | int argoffset = 2 * tdep->wordsize; | |
86 | /* Structures start after the arguments. */ | |
87 | int structoffset = argoffset + argspace; | |
88 | ||
89 | /* If the function is returning a `struct', then the first word | |
944fcfab AC |
90 | (which will be passed in r3) is used for struct return |
91 | address. In that case we should advance one word and start | |
92 | from r4 register to copy parameters. */ | |
68856ea3 | 93 | if (struct_return) |
7b112f9c | 94 | { |
68856ea3 AC |
95 | if (write_pass) |
96 | regcache_cooked_write_signed (regcache, | |
97 | tdep->ppc_gp0_regnum + greg, | |
98 | struct_addr); | |
99 | greg++; | |
7b112f9c | 100 | } |
68856ea3 AC |
101 | |
102 | for (argno = 0; argno < nargs; argno++) | |
7b112f9c | 103 | { |
68856ea3 | 104 | struct value *arg = args[argno]; |
df407dfe | 105 | struct type *type = check_typedef (value_type (arg)); |
68856ea3 | 106 | int len = TYPE_LENGTH (type); |
0fd88904 | 107 | const bfd_byte *val = value_contents (arg); |
68856ea3 | 108 | |
55eddb0f DJ |
109 | if (TYPE_CODE (type) == TYPE_CODE_FLT && len <= 8 |
110 | && !tdep->soft_float) | |
7b112f9c | 111 | { |
68856ea3 | 112 | /* Floating point value converted to "double" then |
944fcfab AC |
113 | passed in an FP register, when the registers run out, |
114 | 8 byte aligned stack is used. */ | |
68856ea3 AC |
115 | if (freg <= 8) |
116 | { | |
117 | if (write_pass) | |
118 | { | |
119 | /* Always store the floating point value using | |
944fcfab | 120 | the register's floating-point format. */ |
50fd1280 | 121 | gdb_byte regval[MAX_REGISTER_SIZE]; |
68856ea3 | 122 | struct type *regtype |
366f009f | 123 | = register_type (gdbarch, tdep->ppc_fp0_regnum + freg); |
68856ea3 | 124 | convert_typed_floating (val, type, regval, regtype); |
366f009f JB |
125 | regcache_cooked_write (regcache, |
126 | tdep->ppc_fp0_regnum + freg, | |
68856ea3 AC |
127 | regval); |
128 | } | |
129 | freg++; | |
130 | } | |
7b112f9c JT |
131 | else |
132 | { | |
f964a756 MK |
133 | /* The SysV ABI tells us to convert floats to |
134 | doubles before writing them to an 8 byte aligned | |
135 | stack location. Unfortunately GCC does not do | |
136 | that, and stores floats into 4 byte aligned | |
137 | locations without converting them to doubles. | |
138 | Since there is no know compiler that actually | |
139 | follows the ABI here, we implement the GCC | |
140 | convention. */ | |
141 | ||
142 | /* Align to 4 bytes or 8 bytes depending on the type of | |
143 | the argument (float or double). */ | |
144 | argoffset = align_up (argoffset, len); | |
68856ea3 | 145 | if (write_pass) |
68856ea3 | 146 | write_memory (sp + argoffset, val, len); |
f964a756 | 147 | argoffset += len; |
7b112f9c JT |
148 | } |
149 | } | |
b14d30e1 JM |
150 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
151 | && len == 16 | |
152 | && !tdep->soft_float | |
40a6adc1 | 153 | && (gdbarch_long_double_format (gdbarch) |
b14d30e1 JM |
154 | == floatformats_ibm_long_double)) |
155 | { | |
156 | /* IBM long double passed in two FP registers if | |
157 | available, otherwise 8-byte aligned stack. */ | |
158 | if (freg <= 7) | |
159 | { | |
160 | if (write_pass) | |
161 | { | |
162 | regcache_cooked_write (regcache, | |
163 | tdep->ppc_fp0_regnum + freg, | |
164 | val); | |
165 | regcache_cooked_write (regcache, | |
166 | tdep->ppc_fp0_regnum + freg + 1, | |
167 | val + 8); | |
168 | } | |
169 | freg += 2; | |
170 | } | |
171 | else | |
172 | { | |
173 | argoffset = align_up (argoffset, 8); | |
174 | if (write_pass) | |
175 | write_memory (sp + argoffset, val, len); | |
176 | argoffset += 16; | |
177 | } | |
178 | } | |
55eddb0f DJ |
179 | else if (len == 8 |
180 | && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */ | |
00fbcec4 JM |
181 | || TYPE_CODE (type) == TYPE_CODE_FLT /* double */ |
182 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT | |
183 | && tdep->soft_float))) | |
7b112f9c | 184 | { |
00fbcec4 JM |
185 | /* "long long" or soft-float "double" or "_Decimal64" |
186 | passed in an odd/even register pair with the low | |
187 | addressed word in the odd register and the high | |
188 | addressed word in the even register, or when the | |
189 | registers run out an 8 byte aligned stack | |
190 | location. */ | |
68856ea3 AC |
191 | if (greg > 9) |
192 | { | |
193 | /* Just in case GREG was 10. */ | |
194 | greg = 11; | |
195 | argoffset = align_up (argoffset, 8); | |
196 | if (write_pass) | |
197 | write_memory (sp + argoffset, val, len); | |
198 | argoffset += 8; | |
199 | } | |
68856ea3 AC |
200 | else |
201 | { | |
202 | /* Must start on an odd register - r3/r4 etc. */ | |
203 | if ((greg & 1) == 0) | |
204 | greg++; | |
205 | if (write_pass) | |
206 | { | |
207 | regcache_cooked_write (regcache, | |
208 | tdep->ppc_gp0_regnum + greg + 0, | |
209 | val + 0); | |
210 | regcache_cooked_write (regcache, | |
211 | tdep->ppc_gp0_regnum + greg + 1, | |
212 | val + 4); | |
213 | } | |
214 | greg += 2; | |
215 | } | |
7b112f9c | 216 | } |
00fbcec4 JM |
217 | else if (len == 16 |
218 | && ((TYPE_CODE (type) == TYPE_CODE_FLT | |
219 | && (gdbarch_long_double_format (gdbarch) | |
220 | == floatformats_ibm_long_double)) | |
221 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT | |
222 | && tdep->soft_float))) | |
b14d30e1 | 223 | { |
00fbcec4 JM |
224 | /* Soft-float IBM long double or _Decimal128 passed in |
225 | four consecutive registers, or on the stack. The | |
226 | registers are not necessarily odd/even pairs. */ | |
b14d30e1 JM |
227 | if (greg > 7) |
228 | { | |
229 | greg = 11; | |
230 | argoffset = align_up (argoffset, 8); | |
231 | if (write_pass) | |
232 | write_memory (sp + argoffset, val, len); | |
233 | argoffset += 16; | |
234 | } | |
235 | else | |
236 | { | |
237 | if (write_pass) | |
238 | { | |
239 | regcache_cooked_write (regcache, | |
240 | tdep->ppc_gp0_regnum + greg + 0, | |
241 | val + 0); | |
242 | regcache_cooked_write (regcache, | |
243 | tdep->ppc_gp0_regnum + greg + 1, | |
244 | val + 4); | |
245 | regcache_cooked_write (regcache, | |
246 | tdep->ppc_gp0_regnum + greg + 2, | |
247 | val + 8); | |
248 | regcache_cooked_write (regcache, | |
249 | tdep->ppc_gp0_regnum + greg + 3, | |
250 | val + 12); | |
251 | } | |
252 | greg += 4; | |
253 | } | |
254 | } | |
1300a2f4 TJB |
255 | else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len <= 8 |
256 | && !tdep->soft_float) | |
257 | { | |
258 | /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can | |
259 | end up in memory. */ | |
260 | ||
261 | if (freg <= 8) | |
262 | { | |
263 | if (write_pass) | |
264 | { | |
265 | gdb_byte regval[MAX_REGISTER_SIZE]; | |
266 | const gdb_byte *p; | |
267 | ||
268 | /* 32-bit decimal floats are right aligned in the | |
269 | doubleword. */ | |
270 | if (TYPE_LENGTH (type) == 4) | |
271 | { | |
272 | memcpy (regval + 4, val, 4); | |
273 | p = regval; | |
274 | } | |
275 | else | |
276 | p = val; | |
277 | ||
278 | regcache_cooked_write (regcache, | |
279 | tdep->ppc_fp0_regnum + freg, p); | |
280 | } | |
281 | ||
282 | freg++; | |
283 | } | |
284 | else | |
285 | { | |
286 | argoffset = align_up (argoffset, len); | |
287 | ||
288 | if (write_pass) | |
289 | /* Write value in the stack's parameter save area. */ | |
290 | write_memory (sp + argoffset, val, len); | |
291 | ||
292 | argoffset += len; | |
293 | } | |
294 | } | |
295 | else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len == 16 | |
296 | && !tdep->soft_float) | |
297 | { | |
298 | /* 128-bit decimal floats go in f2 .. f7, always in even/odd | |
299 | pairs. They can end up in memory, using two doublewords. */ | |
300 | ||
301 | if (freg <= 6) | |
302 | { | |
303 | /* Make sure freg is even. */ | |
304 | freg += freg & 1; | |
305 | ||
306 | if (write_pass) | |
307 | { | |
308 | regcache_cooked_write (regcache, | |
309 | tdep->ppc_fp0_regnum + freg, val); | |
310 | regcache_cooked_write (regcache, | |
311 | tdep->ppc_fp0_regnum + freg + 1, val + 8); | |
312 | } | |
313 | } | |
314 | else | |
315 | { | |
316 | argoffset = align_up (argoffset, 8); | |
317 | ||
318 | if (write_pass) | |
319 | write_memory (sp + argoffset, val, 16); | |
320 | ||
321 | argoffset += 16; | |
322 | } | |
323 | ||
324 | /* If a 128-bit decimal float goes to the stack because only f7 | |
325 | and f8 are free (thus there's no even/odd register pair | |
326 | available), these registers should be marked as occupied. | |
327 | Hence we increase freg even when writing to memory. */ | |
328 | freg += 2; | |
329 | } | |
68856ea3 AC |
330 | else if (len == 16 |
331 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
55eddb0f DJ |
332 | && TYPE_VECTOR (type) |
333 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC) | |
7b112f9c | 334 | { |
68856ea3 | 335 | /* Vector parameter passed in an Altivec register, or |
944fcfab | 336 | when that runs out, 16 byte aligned stack location. */ |
7b112f9c JT |
337 | if (vreg <= 13) |
338 | { | |
68856ea3 | 339 | if (write_pass) |
9c9acae0 | 340 | regcache_cooked_write (regcache, |
944fcfab | 341 | tdep->ppc_vr0_regnum + vreg, val); |
7b112f9c JT |
342 | vreg++; |
343 | } | |
344 | else | |
345 | { | |
68856ea3 AC |
346 | argoffset = align_up (argoffset, 16); |
347 | if (write_pass) | |
348 | write_memory (sp + argoffset, val, 16); | |
7b112f9c JT |
349 | argoffset += 16; |
350 | } | |
351 | } | |
944fcfab | 352 | else if (len == 8 |
0a613259 | 353 | && TYPE_CODE (type) == TYPE_CODE_ARRAY |
55eddb0f DJ |
354 | && TYPE_VECTOR (type) |
355 | && tdep->vector_abi == POWERPC_VEC_SPE) | |
944fcfab | 356 | { |
68856ea3 | 357 | /* Vector parameter passed in an e500 register, or when |
944fcfab AC |
358 | that runs out, 8 byte aligned stack location. Note |
359 | that since e500 vector and general purpose registers | |
360 | both map onto the same underlying register set, a | |
361 | "greg" and not a "vreg" is consumed here. A cooked | |
362 | write stores the value in the correct locations | |
363 | within the raw register cache. */ | |
364 | if (greg <= 10) | |
365 | { | |
68856ea3 | 366 | if (write_pass) |
9c9acae0 | 367 | regcache_cooked_write (regcache, |
944fcfab AC |
368 | tdep->ppc_ev0_regnum + greg, val); |
369 | greg++; | |
370 | } | |
371 | else | |
372 | { | |
68856ea3 AC |
373 | argoffset = align_up (argoffset, 8); |
374 | if (write_pass) | |
375 | write_memory (sp + argoffset, val, 8); | |
944fcfab AC |
376 | argoffset += 8; |
377 | } | |
378 | } | |
68856ea3 AC |
379 | else |
380 | { | |
381 | /* Reduce the parameter down to something that fits in a | |
944fcfab | 382 | "word". */ |
50fd1280 | 383 | gdb_byte word[MAX_REGISTER_SIZE]; |
68856ea3 AC |
384 | memset (word, 0, MAX_REGISTER_SIZE); |
385 | if (len > tdep->wordsize | |
386 | || TYPE_CODE (type) == TYPE_CODE_STRUCT | |
387 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
388 | { | |
55eddb0f | 389 | /* Structs and large values are put in an |
0df8b418 | 390 | aligned stack slot ... */ |
55eddb0f DJ |
391 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
392 | && TYPE_VECTOR (type) | |
393 | && len >= 16) | |
394 | structoffset = align_up (structoffset, 16); | |
395 | else | |
396 | structoffset = align_up (structoffset, 8); | |
397 | ||
68856ea3 AC |
398 | if (write_pass) |
399 | write_memory (sp + structoffset, val, len); | |
400 | /* ... and then a "word" pointing to that address is | |
944fcfab | 401 | passed as the parameter. */ |
e17a4113 | 402 | store_unsigned_integer (word, tdep->wordsize, byte_order, |
68856ea3 AC |
403 | sp + structoffset); |
404 | structoffset += len; | |
405 | } | |
406 | else if (TYPE_CODE (type) == TYPE_CODE_INT) | |
407 | /* Sign or zero extend the "int" into a "word". */ | |
e17a4113 | 408 | store_unsigned_integer (word, tdep->wordsize, byte_order, |
68856ea3 AC |
409 | unpack_long (type, val)); |
410 | else | |
411 | /* Always goes in the low address. */ | |
412 | memcpy (word, val, len); | |
413 | /* Store that "word" in a register, or on the stack. | |
944fcfab | 414 | The words have "4" byte alignment. */ |
68856ea3 AC |
415 | if (greg <= 10) |
416 | { | |
417 | if (write_pass) | |
418 | regcache_cooked_write (regcache, | |
944fcfab | 419 | tdep->ppc_gp0_regnum + greg, word); |
68856ea3 AC |
420 | greg++; |
421 | } | |
422 | else | |
423 | { | |
424 | argoffset = align_up (argoffset, tdep->wordsize); | |
425 | if (write_pass) | |
426 | write_memory (sp + argoffset, word, tdep->wordsize); | |
427 | argoffset += tdep->wordsize; | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | /* Compute the actual stack space requirements. */ | |
433 | if (!write_pass) | |
434 | { | |
435 | /* Remember the amount of space needed by the arguments. */ | |
436 | argspace = argoffset; | |
437 | /* Allocate space for both the arguments and the structures. */ | |
438 | sp -= (argoffset + structoffset); | |
439 | /* Ensure that the stack is still 16 byte aligned. */ | |
440 | sp = align_down (sp, 16); | |
441 | } | |
65ada037 MK |
442 | |
443 | /* The psABI says that "A caller of a function that takes a | |
444 | variable argument list shall set condition register bit 6 to | |
445 | 1 if it passes one or more arguments in the floating-point | |
0df8b418 | 446 | registers. It is strongly recommended that the caller set the |
65ada037 MK |
447 | bit to 0 otherwise..." Doing this for normal functions too |
448 | shouldn't hurt. */ | |
449 | if (write_pass) | |
450 | { | |
451 | ULONGEST cr; | |
452 | ||
453 | regcache_cooked_read_unsigned (regcache, tdep->ppc_cr_regnum, &cr); | |
454 | if (freg > 1) | |
455 | cr |= 0x02000000; | |
456 | else | |
457 | cr &= ~0x02000000; | |
458 | regcache_cooked_write_unsigned (regcache, tdep->ppc_cr_regnum, cr); | |
459 | } | |
7b112f9c JT |
460 | } |
461 | ||
68856ea3 | 462 | /* Update %sp. */ |
40a6adc1 | 463 | regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); |
68856ea3 AC |
464 | |
465 | /* Write the backchain (it occupies WORDSIZED bytes). */ | |
e17a4113 | 466 | write_memory_signed_integer (sp, tdep->wordsize, byte_order, saved_sp); |
68856ea3 | 467 | |
e56a0ecc AC |
468 | /* Point the inferior function call's return address at the dummy's |
469 | breakpoint. */ | |
68856ea3 | 470 | regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); |
e56a0ecc | 471 | |
7b112f9c JT |
472 | return sp; |
473 | } | |
474 | ||
1300a2f4 TJB |
475 | /* Handle the return-value conventions for Decimal Floating Point values |
476 | in both ppc32 and ppc64, which are the same. */ | |
477 | static int | |
478 | get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype, | |
479 | struct regcache *regcache, gdb_byte *readbuf, | |
480 | const gdb_byte *writebuf) | |
481 | { | |
482 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
483 | ||
484 | gdb_assert (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT); | |
485 | ||
486 | /* 32-bit and 64-bit decimal floats in f1. */ | |
487 | if (TYPE_LENGTH (valtype) <= 8) | |
488 | { | |
489 | if (writebuf != NULL) | |
490 | { | |
491 | gdb_byte regval[MAX_REGISTER_SIZE]; | |
492 | const gdb_byte *p; | |
493 | ||
494 | /* 32-bit decimal float is right aligned in the doubleword. */ | |
495 | if (TYPE_LENGTH (valtype) == 4) | |
496 | { | |
497 | memcpy (regval + 4, writebuf, 4); | |
498 | p = regval; | |
499 | } | |
500 | else | |
501 | p = writebuf; | |
502 | ||
503 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, p); | |
504 | } | |
505 | if (readbuf != NULL) | |
506 | { | |
507 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf); | |
508 | ||
509 | /* Left align 32-bit decimal float. */ | |
510 | if (TYPE_LENGTH (valtype) == 4) | |
511 | memcpy (readbuf, readbuf + 4, 4); | |
512 | } | |
513 | } | |
514 | /* 128-bit decimal floats in f2,f3. */ | |
515 | else if (TYPE_LENGTH (valtype) == 16) | |
516 | { | |
517 | if (writebuf != NULL || readbuf != NULL) | |
518 | { | |
519 | int i; | |
520 | ||
521 | for (i = 0; i < 2; i++) | |
522 | { | |
523 | if (writebuf != NULL) | |
524 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2 + i, | |
525 | writebuf + i * 8); | |
526 | if (readbuf != NULL) | |
527 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2 + i, | |
528 | readbuf + i * 8); | |
529 | } | |
530 | } | |
531 | } | |
532 | else | |
533 | /* Can't happen. */ | |
9b20d036 | 534 | internal_error (__FILE__, __LINE__, _("Unknown decimal float size.")); |
1300a2f4 TJB |
535 | |
536 | return RETURN_VALUE_REGISTER_CONVENTION; | |
537 | } | |
538 | ||
e754ae69 AC |
539 | /* Handle the return-value conventions specified by the SysV 32-bit |
540 | PowerPC ABI (including all the supplements): | |
541 | ||
542 | no floating-point: floating-point values returned using 32-bit | |
543 | general-purpose registers. | |
544 | ||
545 | Altivec: 128-bit vectors returned using vector registers. | |
546 | ||
547 | e500: 64-bit vectors returned using the full full 64 bit EV | |
548 | register, floating-point values returned using 32-bit | |
549 | general-purpose registers. | |
550 | ||
551 | GCC (broken): Small struct values right (instead of left) aligned | |
552 | when returned in general-purpose registers. */ | |
553 | ||
554 | static enum return_value_convention | |
05580c65 | 555 | do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type, |
55eddb0f DJ |
556 | struct regcache *regcache, gdb_byte *readbuf, |
557 | const gdb_byte *writebuf, int broken_gcc) | |
e754ae69 | 558 | { |
05580c65 | 559 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 560 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
e754ae69 AC |
561 | gdb_assert (tdep->wordsize == 4); |
562 | if (TYPE_CODE (type) == TYPE_CODE_FLT | |
563 | && TYPE_LENGTH (type) <= 8 | |
55eddb0f | 564 | && !tdep->soft_float) |
e754ae69 | 565 | { |
963e2bb7 | 566 | if (readbuf) |
e754ae69 AC |
567 | { |
568 | /* Floats and doubles stored in "f1". Convert the value to | |
569 | the required type. */ | |
50fd1280 | 570 | gdb_byte regval[MAX_REGISTER_SIZE]; |
366f009f JB |
571 | struct type *regtype = register_type (gdbarch, |
572 | tdep->ppc_fp0_regnum + 1); | |
573 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); | |
963e2bb7 | 574 | convert_typed_floating (regval, regtype, readbuf, type); |
e754ae69 | 575 | } |
963e2bb7 | 576 | if (writebuf) |
e754ae69 AC |
577 | { |
578 | /* Floats and doubles stored in "f1". Convert the value to | |
579 | the register's "double" type. */ | |
50fd1280 | 580 | gdb_byte regval[MAX_REGISTER_SIZE]; |
366f009f | 581 | struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 582 | convert_typed_floating (writebuf, type, regval, regtype); |
366f009f | 583 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); |
e754ae69 AC |
584 | } |
585 | return RETURN_VALUE_REGISTER_CONVENTION; | |
586 | } | |
b14d30e1 JM |
587 | if (TYPE_CODE (type) == TYPE_CODE_FLT |
588 | && TYPE_LENGTH (type) == 16 | |
589 | && !tdep->soft_float | |
0df8b418 MS |
590 | && (gdbarch_long_double_format (gdbarch) |
591 | == floatformats_ibm_long_double)) | |
b14d30e1 JM |
592 | { |
593 | /* IBM long double stored in f1 and f2. */ | |
594 | if (readbuf) | |
595 | { | |
596 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf); | |
597 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2, | |
598 | readbuf + 8); | |
599 | } | |
600 | if (writebuf) | |
601 | { | |
602 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, writebuf); | |
603 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2, | |
604 | writebuf + 8); | |
605 | } | |
606 | return RETURN_VALUE_REGISTER_CONVENTION; | |
607 | } | |
00fbcec4 JM |
608 | if (TYPE_LENGTH (type) == 16 |
609 | && ((TYPE_CODE (type) == TYPE_CODE_FLT | |
0df8b418 MS |
610 | && (gdbarch_long_double_format (gdbarch) |
611 | == floatformats_ibm_long_double)) | |
00fbcec4 | 612 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float))) |
b14d30e1 | 613 | { |
00fbcec4 JM |
614 | /* Soft-float IBM long double or _Decimal128 stored in r3, r4, |
615 | r5, r6. */ | |
b14d30e1 JM |
616 | if (readbuf) |
617 | { | |
618 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf); | |
619 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
620 | readbuf + 4); | |
621 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5, | |
622 | readbuf + 8); | |
623 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6, | |
624 | readbuf + 12); | |
625 | } | |
626 | if (writebuf) | |
627 | { | |
628 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); | |
629 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
630 | writebuf + 4); | |
631 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5, | |
632 | writebuf + 8); | |
633 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6, | |
634 | writebuf + 12); | |
635 | } | |
636 | return RETURN_VALUE_REGISTER_CONVENTION; | |
637 | } | |
e754ae69 | 638 | if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8) |
00fbcec4 JM |
639 | || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
640 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 8 | |
641 | && tdep->soft_float)) | |
e754ae69 | 642 | { |
963e2bb7 | 643 | if (readbuf) |
e754ae69 | 644 | { |
00fbcec4 JM |
645 | /* A long long, double or _Decimal64 stored in the 32 bit |
646 | r3/r4. */ | |
e754ae69 | 647 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, |
55eddb0f | 648 | readbuf + 0); |
e754ae69 | 649 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, |
55eddb0f | 650 | readbuf + 4); |
e754ae69 | 651 | } |
963e2bb7 | 652 | if (writebuf) |
e754ae69 | 653 | { |
00fbcec4 JM |
654 | /* A long long, double or _Decimal64 stored in the 32 bit |
655 | r3/r4. */ | |
e754ae69 | 656 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, |
55eddb0f | 657 | writebuf + 0); |
e754ae69 | 658 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, |
55eddb0f | 659 | writebuf + 4); |
e754ae69 AC |
660 | } |
661 | return RETURN_VALUE_REGISTER_CONVENTION; | |
662 | } | |
1300a2f4 TJB |
663 | if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && !tdep->soft_float) |
664 | return get_decimal_float_return_value (gdbarch, type, regcache, readbuf, | |
665 | writebuf); | |
f0027ce2 DJ |
666 | else if ((TYPE_CODE (type) == TYPE_CODE_INT |
667 | || TYPE_CODE (type) == TYPE_CODE_CHAR | |
668 | || TYPE_CODE (type) == TYPE_CODE_BOOL | |
669 | || TYPE_CODE (type) == TYPE_CODE_PTR | |
670 | || TYPE_CODE (type) == TYPE_CODE_REF | |
671 | || TYPE_CODE (type) == TYPE_CODE_ENUM) | |
672 | && TYPE_LENGTH (type) <= tdep->wordsize) | |
e754ae69 | 673 | { |
963e2bb7 | 674 | if (readbuf) |
e754ae69 AC |
675 | { |
676 | /* Some sort of integer stored in r3. Since TYPE isn't | |
677 | bigger than the register, sign extension isn't a problem | |
678 | - just do everything unsigned. */ | |
679 | ULONGEST regval; | |
680 | regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
681 | ®val); | |
e17a4113 UW |
682 | store_unsigned_integer (readbuf, TYPE_LENGTH (type), byte_order, |
683 | regval); | |
e754ae69 | 684 | } |
963e2bb7 | 685 | if (writebuf) |
e754ae69 AC |
686 | { |
687 | /* Some sort of integer stored in r3. Use unpack_long since | |
688 | that should handle any required sign extension. */ | |
689 | regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 690 | unpack_long (type, writebuf)); |
e754ae69 AC |
691 | } |
692 | return RETURN_VALUE_REGISTER_CONVENTION; | |
693 | } | |
694 | if (TYPE_LENGTH (type) == 16 | |
695 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
55eddb0f DJ |
696 | && TYPE_VECTOR (type) |
697 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC) | |
e754ae69 | 698 | { |
963e2bb7 | 699 | if (readbuf) |
e754ae69 AC |
700 | { |
701 | /* Altivec places the return value in "v2". */ | |
963e2bb7 | 702 | regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); |
e754ae69 | 703 | } |
963e2bb7 | 704 | if (writebuf) |
e754ae69 AC |
705 | { |
706 | /* Altivec places the return value in "v2". */ | |
963e2bb7 | 707 | regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); |
e754ae69 AC |
708 | } |
709 | return RETURN_VALUE_REGISTER_CONVENTION; | |
710 | } | |
55eddb0f DJ |
711 | if (TYPE_LENGTH (type) == 16 |
712 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
713 | && TYPE_VECTOR (type) | |
714 | && tdep->vector_abi == POWERPC_VEC_GENERIC) | |
715 | { | |
716 | /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6. | |
717 | GCC without AltiVec returns them in memory, but it warns about | |
718 | ABI risks in that case; we don't try to support it. */ | |
719 | if (readbuf) | |
720 | { | |
721 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, | |
722 | readbuf + 0); | |
723 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
724 | readbuf + 4); | |
725 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5, | |
726 | readbuf + 8); | |
727 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6, | |
728 | readbuf + 12); | |
729 | } | |
730 | if (writebuf) | |
731 | { | |
732 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, | |
733 | writebuf + 0); | |
734 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
735 | writebuf + 4); | |
736 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5, | |
737 | writebuf + 8); | |
738 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6, | |
739 | writebuf + 12); | |
740 | } | |
741 | return RETURN_VALUE_REGISTER_CONVENTION; | |
742 | } | |
e754ae69 AC |
743 | if (TYPE_LENGTH (type) == 8 |
744 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
55eddb0f DJ |
745 | && TYPE_VECTOR (type) |
746 | && tdep->vector_abi == POWERPC_VEC_SPE) | |
e754ae69 AC |
747 | { |
748 | /* The e500 ABI places return values for the 64-bit DSP types | |
749 | (__ev64_opaque__) in r3. However, in GDB-speak, ev3 | |
750 | corresponds to the entire r3 value for e500, whereas GDB's r3 | |
751 | only corresponds to the least significant 32-bits. So place | |
752 | the 64-bit DSP type's value in ev3. */ | |
963e2bb7 AC |
753 | if (readbuf) |
754 | regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf); | |
755 | if (writebuf) | |
756 | regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf); | |
e754ae69 AC |
757 | return RETURN_VALUE_REGISTER_CONVENTION; |
758 | } | |
759 | if (broken_gcc && TYPE_LENGTH (type) <= 8) | |
760 | { | |
61bf9ae0 MK |
761 | /* GCC screwed up for structures or unions whose size is less |
762 | than or equal to 8 bytes.. Instead of left-aligning, it | |
763 | right-aligns the data into the buffer formed by r3, r4. */ | |
764 | gdb_byte regvals[MAX_REGISTER_SIZE * 2]; | |
765 | int len = TYPE_LENGTH (type); | |
766 | int offset = (2 * tdep->wordsize - len) % tdep->wordsize; | |
767 | ||
963e2bb7 | 768 | if (readbuf) |
e754ae69 | 769 | { |
61bf9ae0 MK |
770 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, |
771 | regvals + 0 * tdep->wordsize); | |
772 | if (len > tdep->wordsize) | |
773 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
774 | regvals + 1 * tdep->wordsize); | |
775 | memcpy (readbuf, regvals + offset, len); | |
e754ae69 | 776 | } |
963e2bb7 | 777 | if (writebuf) |
e754ae69 | 778 | { |
61bf9ae0 MK |
779 | memset (regvals, 0, sizeof regvals); |
780 | memcpy (regvals + offset, writebuf, len); | |
781 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, | |
782 | regvals + 0 * tdep->wordsize); | |
783 | if (len > tdep->wordsize) | |
784 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
785 | regvals + 1 * tdep->wordsize); | |
e754ae69 | 786 | } |
61bf9ae0 | 787 | |
e754ae69 AC |
788 | return RETURN_VALUE_REGISTER_CONVENTION; |
789 | } | |
790 | if (TYPE_LENGTH (type) <= 8) | |
791 | { | |
963e2bb7 | 792 | if (readbuf) |
e754ae69 AC |
793 | { |
794 | /* This matches SVr4 PPC, it does not match GCC. */ | |
795 | /* The value is right-padded to 8 bytes and then loaded, as | |
796 | two "words", into r3/r4. */ | |
50fd1280 | 797 | gdb_byte regvals[MAX_REGISTER_SIZE * 2]; |
e754ae69 AC |
798 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, |
799 | regvals + 0 * tdep->wordsize); | |
800 | if (TYPE_LENGTH (type) > tdep->wordsize) | |
801 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
802 | regvals + 1 * tdep->wordsize); | |
963e2bb7 | 803 | memcpy (readbuf, regvals, TYPE_LENGTH (type)); |
e754ae69 | 804 | } |
963e2bb7 | 805 | if (writebuf) |
e754ae69 AC |
806 | { |
807 | /* This matches SVr4 PPC, it does not match GCC. */ | |
808 | /* The value is padded out to 8 bytes and then loaded, as | |
809 | two "words" into r3/r4. */ | |
50fd1280 | 810 | gdb_byte regvals[MAX_REGISTER_SIZE * 2]; |
e754ae69 | 811 | memset (regvals, 0, sizeof regvals); |
963e2bb7 | 812 | memcpy (regvals, writebuf, TYPE_LENGTH (type)); |
e754ae69 AC |
813 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, |
814 | regvals + 0 * tdep->wordsize); | |
815 | if (TYPE_LENGTH (type) > tdep->wordsize) | |
816 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
817 | regvals + 1 * tdep->wordsize); | |
818 | } | |
819 | return RETURN_VALUE_REGISTER_CONVENTION; | |
820 | } | |
821 | return RETURN_VALUE_STRUCT_CONVENTION; | |
822 | } | |
823 | ||
05580c65 | 824 | enum return_value_convention |
c055b101 CV |
825 | ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type, |
826 | struct type *valtype, struct regcache *regcache, | |
827 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
e754ae69 | 828 | { |
963e2bb7 AC |
829 | return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf, |
830 | writebuf, 0); | |
e754ae69 AC |
831 | } |
832 | ||
05580c65 | 833 | enum return_value_convention |
963e2bb7 | 834 | ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch, |
c055b101 | 835 | struct type *func_type, |
963e2bb7 AC |
836 | struct type *valtype, |
837 | struct regcache *regcache, | |
50fd1280 | 838 | gdb_byte *readbuf, const gdb_byte *writebuf) |
e754ae69 | 839 | { |
963e2bb7 AC |
840 | return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf, |
841 | writebuf, 1); | |
944fcfab | 842 | } |
afd48b75 | 843 | |
b6e1c027 AC |
844 | /* The helper function for 64-bit SYSV push_dummy_call. Converts the |
845 | function's code address back into the function's descriptor | |
846 | address. | |
847 | ||
848 | Find a value for the TOC register. Every symbol should have both | |
849 | ".FN" and "FN" in the minimal symbol table. "FN" points at the | |
850 | FN's descriptor, while ".FN" points at the entry point (which | |
851 | matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the | |
852 | FN's descriptor address (while at the same time being careful to | |
853 | find "FN" in the same object file as ".FN"). */ | |
854 | ||
855 | static int | |
856 | convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr) | |
857 | { | |
858 | struct obj_section *dot_fn_section; | |
859 | struct minimal_symbol *dot_fn; | |
860 | struct minimal_symbol *fn; | |
861 | CORE_ADDR toc; | |
862 | /* Find the minimal symbol that corresponds to CODE_ADDR (should | |
863 | have a name of the form ".FN"). */ | |
864 | dot_fn = lookup_minimal_symbol_by_pc (code_addr); | |
865 | if (dot_fn == NULL || SYMBOL_LINKAGE_NAME (dot_fn)[0] != '.') | |
866 | return 0; | |
867 | /* Get the section that contains CODE_ADDR. Need this for the | |
868 | "objfile" that it contains. */ | |
869 | dot_fn_section = find_pc_section (code_addr); | |
870 | if (dot_fn_section == NULL || dot_fn_section->objfile == NULL) | |
871 | return 0; | |
872 | /* Now find the corresponding "FN" (dropping ".") minimal symbol's | |
873 | address. Only look for the minimal symbol in ".FN"'s object file | |
874 | - avoids problems when two object files (i.e., shared libraries) | |
875 | contain a minimal symbol with the same name. */ | |
876 | fn = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL, | |
877 | dot_fn_section->objfile); | |
878 | if (fn == NULL) | |
879 | return 0; | |
880 | /* Found a descriptor. */ | |
881 | (*desc_addr) = SYMBOL_VALUE_ADDRESS (fn); | |
882 | return 1; | |
883 | } | |
884 | ||
0df8b418 | 885 | /* Pass the arguments in either registers, or in the stack. Using the |
8be9034a AC |
886 | ppc 64 bit SysV ABI. |
887 | ||
888 | This implements a dumbed down version of the ABI. It always writes | |
889 | values to memory, GPR and FPR, even when not necessary. Doing this | |
0df8b418 | 890 | greatly simplifies the logic. */ |
8be9034a AC |
891 | |
892 | CORE_ADDR | |
0df8b418 MS |
893 | ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, |
894 | struct value *function, | |
8be9034a AC |
895 | struct regcache *regcache, CORE_ADDR bp_addr, |
896 | int nargs, struct value **args, CORE_ADDR sp, | |
897 | int struct_return, CORE_ADDR struct_addr) | |
898 | { | |
7d9b040b | 899 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
40a6adc1 | 900 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 901 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
fb4443d8 | 902 | ULONGEST back_chain; |
8be9034a AC |
903 | /* See for-loop comment below. */ |
904 | int write_pass; | |
905 | /* Size of the Altivec's vector parameter region, the final value is | |
906 | computed in the for-loop below. */ | |
907 | LONGEST vparam_size = 0; | |
908 | /* Size of the general parameter region, the final value is computed | |
909 | in the for-loop below. */ | |
910 | LONGEST gparam_size = 0; | |
911 | /* Kevin writes ... I don't mind seeing tdep->wordsize used in the | |
0df8b418 | 912 | calls to align_up(), align_down(), etc. because this makes it |
8be9034a AC |
913 | easier to reuse this code (in a copy/paste sense) in the future, |
914 | but it is a 64-bit ABI and asserting that the wordsize is 8 bytes | |
915 | at some point makes it easier to verify that this function is | |
916 | correct without having to do a non-local analysis to figure out | |
917 | the possible values of tdep->wordsize. */ | |
918 | gdb_assert (tdep->wordsize == 8); | |
919 | ||
55eddb0f DJ |
920 | /* This function exists to support a calling convention that |
921 | requires floating-point registers. It shouldn't be used on | |
922 | processors that lack them. */ | |
923 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
924 | ||
fb4443d8 UW |
925 | /* By this stage in the proceedings, SP has been decremented by "red |
926 | zone size" + "struct return size". Fetch the stack-pointer from | |
927 | before this and use that as the BACK_CHAIN. */ | |
40a6adc1 | 928 | regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), |
3e8c568d | 929 | &back_chain); |
fb4443d8 | 930 | |
8be9034a AC |
931 | /* Go through the argument list twice. |
932 | ||
933 | Pass 1: Compute the function call's stack space and register | |
934 | requirements. | |
935 | ||
936 | Pass 2: Replay the same computation but this time also write the | |
937 | values out to the target. */ | |
938 | ||
939 | for (write_pass = 0; write_pass < 2; write_pass++) | |
940 | { | |
941 | int argno; | |
942 | /* Next available floating point register for float and double | |
943 | arguments. */ | |
944 | int freg = 1; | |
945 | /* Next available general register for non-vector (but possibly | |
946 | float) arguments. */ | |
947 | int greg = 3; | |
948 | /* Next available vector register for vector arguments. */ | |
949 | int vreg = 2; | |
950 | /* The address, at which the next general purpose parameter | |
951 | (integer, struct, float, ...) should be saved. */ | |
952 | CORE_ADDR gparam; | |
953 | /* Address, at which the next Altivec vector parameter should be | |
954 | saved. */ | |
955 | CORE_ADDR vparam; | |
956 | ||
957 | if (!write_pass) | |
958 | { | |
959 | /* During the first pass, GPARAM and VPARAM are more like | |
960 | offsets (start address zero) than addresses. That way | |
938f5214 | 961 | they accumulate the total stack space each region |
8be9034a AC |
962 | requires. */ |
963 | gparam = 0; | |
964 | vparam = 0; | |
965 | } | |
966 | else | |
967 | { | |
968 | /* Decrement the stack pointer making space for the Altivec | |
969 | and general on-stack parameters. Set vparam and gparam | |
970 | to their corresponding regions. */ | |
971 | vparam = align_down (sp - vparam_size, 16); | |
972 | gparam = align_down (vparam - gparam_size, 16); | |
973 | /* Add in space for the TOC, link editor double word, | |
974 | compiler double word, LR save area, CR save area. */ | |
975 | sp = align_down (gparam - 48, 16); | |
976 | } | |
977 | ||
978 | /* If the function is returning a `struct', then there is an | |
979 | extra hidden parameter (which will be passed in r3) | |
980 | containing the address of that struct.. In that case we | |
981 | should advance one word and start from r4 register to copy | |
982 | parameters. This also consumes one on-stack parameter slot. */ | |
983 | if (struct_return) | |
984 | { | |
985 | if (write_pass) | |
986 | regcache_cooked_write_signed (regcache, | |
987 | tdep->ppc_gp0_regnum + greg, | |
988 | struct_addr); | |
989 | greg++; | |
990 | gparam = align_up (gparam + tdep->wordsize, tdep->wordsize); | |
991 | } | |
992 | ||
993 | for (argno = 0; argno < nargs; argno++) | |
994 | { | |
995 | struct value *arg = args[argno]; | |
df407dfe | 996 | struct type *type = check_typedef (value_type (arg)); |
0fd88904 | 997 | const bfd_byte *val = value_contents (arg); |
ce0451ad | 998 | |
8be9034a AC |
999 | if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8) |
1000 | { | |
1001 | /* Floats and Doubles go in f1 .. f13. They also | |
1002 | consume a left aligned GREG,, and can end up in | |
1003 | memory. */ | |
1004 | if (write_pass) | |
1005 | { | |
ce0451ad TJB |
1006 | gdb_byte regval[MAX_REGISTER_SIZE]; |
1007 | const gdb_byte *p; | |
1008 | ||
1009 | /* Version 1.7 of the 64-bit PowerPC ELF ABI says: | |
1010 | ||
1011 | "Single precision floating point values are mapped to | |
1012 | the first word in a single doubleword." | |
1013 | ||
1014 | And version 1.9 says: | |
1015 | ||
1016 | "Single precision floating point values are mapped to | |
1017 | the second word in a single doubleword." | |
1018 | ||
1019 | GDB then writes single precision floating point values | |
1020 | at both words in a doubleword, to support both ABIs. */ | |
1021 | if (TYPE_LENGTH (type) == 4) | |
1022 | { | |
1023 | memcpy (regval, val, 4); | |
1024 | memcpy (regval + 4, val, 4); | |
1025 | p = regval; | |
1026 | } | |
1027 | else | |
1028 | p = val; | |
1029 | ||
1030 | /* Write value in the stack's parameter save area. */ | |
1031 | write_memory (gparam, p, 8); | |
1032 | ||
55eddb0f | 1033 | if (freg <= 13) |
8be9034a | 1034 | { |
366f009f JB |
1035 | struct type *regtype |
1036 | = register_type (gdbarch, tdep->ppc_fp0_regnum); | |
ce0451ad | 1037 | |
8be9034a | 1038 | convert_typed_floating (val, type, regval, regtype); |
366f009f JB |
1039 | regcache_cooked_write (regcache, |
1040 | tdep->ppc_fp0_regnum + freg, | |
8be9034a AC |
1041 | regval); |
1042 | } | |
1043 | if (greg <= 10) | |
ce0451ad TJB |
1044 | regcache_cooked_write (regcache, |
1045 | tdep->ppc_gp0_regnum + greg, | |
1046 | regval); | |
8be9034a | 1047 | } |
ce0451ad | 1048 | |
8be9034a AC |
1049 | freg++; |
1050 | greg++; | |
ce0451ad TJB |
1051 | /* Always consume parameter stack space. */ |
1052 | gparam = align_up (gparam + 8, tdep->wordsize); | |
8be9034a | 1053 | } |
b14d30e1 JM |
1054 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
1055 | && TYPE_LENGTH (type) == 16 | |
40a6adc1 | 1056 | && (gdbarch_long_double_format (gdbarch) |
b14d30e1 JM |
1057 | == floatformats_ibm_long_double)) |
1058 | { | |
1059 | /* IBM long double stored in two doublewords of the | |
1060 | parameter save area and corresponding registers. */ | |
1061 | if (write_pass) | |
1062 | { | |
1063 | if (!tdep->soft_float && freg <= 13) | |
1064 | { | |
1065 | regcache_cooked_write (regcache, | |
1066 | tdep->ppc_fp0_regnum + freg, | |
1067 | val); | |
1068 | if (freg <= 12) | |
1069 | regcache_cooked_write (regcache, | |
1070 | tdep->ppc_fp0_regnum + freg + 1, | |
1071 | val + 8); | |
1072 | } | |
1073 | if (greg <= 10) | |
1074 | { | |
1075 | regcache_cooked_write (regcache, | |
1076 | tdep->ppc_gp0_regnum + greg, | |
1077 | val); | |
1078 | if (greg <= 9) | |
1079 | regcache_cooked_write (regcache, | |
1080 | tdep->ppc_gp0_regnum + greg + 1, | |
1081 | val + 8); | |
1082 | } | |
1083 | write_memory (gparam, val, TYPE_LENGTH (type)); | |
1084 | } | |
1085 | freg += 2; | |
1086 | greg += 2; | |
1087 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
1088 | } | |
1300a2f4 TJB |
1089 | else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT |
1090 | && TYPE_LENGTH (type) <= 8) | |
1091 | { | |
1092 | /* 32-bit and 64-bit decimal floats go in f1 .. f13. They can | |
1093 | end up in memory. */ | |
1094 | if (write_pass) | |
1095 | { | |
1096 | gdb_byte regval[MAX_REGISTER_SIZE]; | |
1097 | const gdb_byte *p; | |
1098 | ||
1099 | /* 32-bit decimal floats are right aligned in the | |
1100 | doubleword. */ | |
1101 | if (TYPE_LENGTH (type) == 4) | |
1102 | { | |
1103 | memcpy (regval + 4, val, 4); | |
1104 | p = regval; | |
1105 | } | |
1106 | else | |
1107 | p = val; | |
1108 | ||
1109 | /* Write value in the stack's parameter save area. */ | |
1110 | write_memory (gparam, p, 8); | |
1111 | ||
1112 | if (freg <= 13) | |
1113 | regcache_cooked_write (regcache, | |
1114 | tdep->ppc_fp0_regnum + freg, p); | |
1115 | } | |
1116 | ||
1117 | freg++; | |
1118 | greg++; | |
1119 | /* Always consume parameter stack space. */ | |
1120 | gparam = align_up (gparam + 8, tdep->wordsize); | |
1121 | } | |
1122 | else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && | |
1123 | TYPE_LENGTH (type) == 16) | |
1124 | { | |
1125 | /* 128-bit decimal floats go in f2 .. f12, always in even/odd | |
1126 | pairs. They can end up in memory, using two doublewords. */ | |
1127 | if (write_pass) | |
1128 | { | |
1129 | if (freg <= 12) | |
1130 | { | |
1131 | /* Make sure freg is even. */ | |
1132 | freg += freg & 1; | |
1133 | regcache_cooked_write (regcache, | |
1134 | tdep->ppc_fp0_regnum + freg, val); | |
1135 | regcache_cooked_write (regcache, | |
1136 | tdep->ppc_fp0_regnum + freg + 1, val + 8); | |
1137 | } | |
1138 | ||
1139 | write_memory (gparam, val, TYPE_LENGTH (type)); | |
1140 | } | |
1141 | ||
1142 | freg += 2; | |
1143 | greg += 2; | |
1144 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
1145 | } | |
8be9034a AC |
1146 | else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type) |
1147 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
1148 | && tdep->ppc_vr0_regnum >= 0) | |
1149 | { | |
1150 | /* In the Altivec ABI, vectors go in the vector | |
1151 | registers v2 .. v13, or when that runs out, a vector | |
1152 | annex which goes above all the normal parameters. | |
1153 | NOTE: cagney/2003-09-21: This is a guess based on the | |
1154 | PowerOpen Altivec ABI. */ | |
1155 | if (vreg <= 13) | |
1156 | { | |
1157 | if (write_pass) | |
1158 | regcache_cooked_write (regcache, | |
1159 | tdep->ppc_vr0_regnum + vreg, val); | |
1160 | vreg++; | |
1161 | } | |
1162 | else | |
1163 | { | |
1164 | if (write_pass) | |
1165 | write_memory (vparam, val, TYPE_LENGTH (type)); | |
1166 | vparam = align_up (vparam + TYPE_LENGTH (type), 16); | |
1167 | } | |
1168 | } | |
1169 | else if ((TYPE_CODE (type) == TYPE_CODE_INT | |
b6e1c027 | 1170 | || TYPE_CODE (type) == TYPE_CODE_ENUM |
93d4208d UW |
1171 | || TYPE_CODE (type) == TYPE_CODE_BOOL |
1172 | || TYPE_CODE (type) == TYPE_CODE_CHAR | |
1173 | || TYPE_CODE (type) == TYPE_CODE_PTR | |
1174 | || TYPE_CODE (type) == TYPE_CODE_REF) | |
8be9034a AC |
1175 | && TYPE_LENGTH (type) <= 8) |
1176 | { | |
b6e1c027 AC |
1177 | /* Scalars and Pointers get sign[un]extended and go in |
1178 | gpr3 .. gpr10. They can also end up in memory. */ | |
8be9034a AC |
1179 | if (write_pass) |
1180 | { | |
1181 | /* Sign extend the value, then store it unsigned. */ | |
1182 | ULONGEST word = unpack_long (type, val); | |
b6e1c027 AC |
1183 | /* Convert any function code addresses into |
1184 | descriptors. */ | |
1185 | if (TYPE_CODE (type) == TYPE_CODE_PTR | |
93d4208d | 1186 | || TYPE_CODE (type) == TYPE_CODE_REF) |
b6e1c027 | 1187 | { |
93d4208d UW |
1188 | struct type *target_type; |
1189 | target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1190 | ||
1191 | if (TYPE_CODE (target_type) == TYPE_CODE_FUNC | |
1192 | || TYPE_CODE (target_type) == TYPE_CODE_METHOD) | |
1193 | { | |
1194 | CORE_ADDR desc = word; | |
1195 | convert_code_addr_to_desc_addr (word, &desc); | |
1196 | word = desc; | |
1197 | } | |
b6e1c027 | 1198 | } |
8be9034a AC |
1199 | if (greg <= 10) |
1200 | regcache_cooked_write_unsigned (regcache, | |
1201 | tdep->ppc_gp0_regnum + | |
1202 | greg, word); | |
1203 | write_memory_unsigned_integer (gparam, tdep->wordsize, | |
e17a4113 | 1204 | byte_order, word); |
8be9034a AC |
1205 | } |
1206 | greg++; | |
1207 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
1208 | } | |
1209 | else | |
1210 | { | |
1211 | int byte; | |
1212 | for (byte = 0; byte < TYPE_LENGTH (type); | |
1213 | byte += tdep->wordsize) | |
1214 | { | |
1215 | if (write_pass && greg <= 10) | |
1216 | { | |
50fd1280 | 1217 | gdb_byte regval[MAX_REGISTER_SIZE]; |
8be9034a AC |
1218 | int len = TYPE_LENGTH (type) - byte; |
1219 | if (len > tdep->wordsize) | |
1220 | len = tdep->wordsize; | |
1221 | memset (regval, 0, sizeof regval); | |
36815e57 JM |
1222 | /* The ABI (version 1.9) specifies that values |
1223 | smaller than one doubleword are right-aligned | |
1224 | and those larger are left-aligned. GCC | |
1225 | versions before 3.4 implemented this | |
1226 | incorrectly; see | |
1227 | <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */ | |
1228 | if (byte == 0) | |
8be9034a AC |
1229 | memcpy (regval + tdep->wordsize - len, |
1230 | val + byte, len); | |
36815e57 JM |
1231 | else |
1232 | memcpy (regval, val + byte, len); | |
8be9034a AC |
1233 | regcache_cooked_write (regcache, greg, regval); |
1234 | } | |
1235 | greg++; | |
1236 | } | |
1237 | if (write_pass) | |
93d4208d UW |
1238 | { |
1239 | /* WARNING: cagney/2003-09-21: Strictly speaking, this | |
1240 | isn't necessary, unfortunately, GCC appears to get | |
1241 | "struct convention" parameter passing wrong putting | |
1242 | odd sized structures in memory instead of in a | |
1243 | register. Work around this by always writing the | |
1244 | value to memory. Fortunately, doing this | |
1245 | simplifies the code. */ | |
1246 | int len = TYPE_LENGTH (type); | |
1247 | if (len < tdep->wordsize) | |
1248 | write_memory (gparam + tdep->wordsize - len, val, len); | |
1249 | else | |
1250 | write_memory (gparam, val, len); | |
1251 | } | |
36815e57 JM |
1252 | if (freg <= 13 |
1253 | && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1254 | && TYPE_NFIELDS (type) == 1 | |
1255 | && TYPE_LENGTH (type) <= 16) | |
1256 | { | |
1257 | /* The ABI (version 1.9) specifies that structs | |
1258 | containing a single floating-point value, at any | |
1259 | level of nesting of single-member structs, are | |
1260 | passed in floating-point registers. */ | |
1261 | while (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1262 | && TYPE_NFIELDS (type) == 1) | |
1263 | type = check_typedef (TYPE_FIELD_TYPE (type, 0)); | |
1264 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
1265 | { | |
1266 | if (TYPE_LENGTH (type) <= 8) | |
1267 | { | |
1268 | if (write_pass) | |
1269 | { | |
1270 | gdb_byte regval[MAX_REGISTER_SIZE]; | |
1271 | struct type *regtype | |
1272 | = register_type (gdbarch, | |
1273 | tdep->ppc_fp0_regnum); | |
1274 | convert_typed_floating (val, type, regval, | |
1275 | regtype); | |
1276 | regcache_cooked_write (regcache, | |
1277 | (tdep->ppc_fp0_regnum | |
1278 | + freg), | |
1279 | regval); | |
1280 | } | |
1281 | freg++; | |
1282 | } | |
1283 | else if (TYPE_LENGTH (type) == 16 | |
40a6adc1 | 1284 | && (gdbarch_long_double_format (gdbarch) |
36815e57 JM |
1285 | == floatformats_ibm_long_double)) |
1286 | { | |
1287 | if (write_pass) | |
1288 | { | |
1289 | regcache_cooked_write (regcache, | |
1290 | (tdep->ppc_fp0_regnum | |
1291 | + freg), | |
1292 | val); | |
1293 | if (freg <= 12) | |
1294 | regcache_cooked_write (regcache, | |
1295 | (tdep->ppc_fp0_regnum | |
1296 | + freg + 1), | |
1297 | val + 8); | |
1298 | } | |
1299 | freg += 2; | |
1300 | } | |
1301 | } | |
1302 | } | |
8be9034a AC |
1303 | /* Always consume parameter stack space. */ |
1304 | gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); | |
1305 | } | |
1306 | } | |
1307 | ||
1308 | if (!write_pass) | |
1309 | { | |
1310 | /* Save the true region sizes ready for the second pass. */ | |
1311 | vparam_size = vparam; | |
1312 | /* Make certain that the general parameter save area is at | |
1313 | least the minimum 8 registers (or doublewords) in size. */ | |
1314 | if (greg < 8) | |
1315 | gparam_size = 8 * tdep->wordsize; | |
1316 | else | |
1317 | gparam_size = gparam; | |
1318 | } | |
1319 | } | |
1320 | ||
1321 | /* Update %sp. */ | |
40a6adc1 | 1322 | regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); |
8be9034a AC |
1323 | |
1324 | /* Write the backchain (it occupies WORDSIZED bytes). */ | |
e17a4113 | 1325 | write_memory_signed_integer (sp, tdep->wordsize, byte_order, back_chain); |
8be9034a AC |
1326 | |
1327 | /* Point the inferior function call's return address at the dummy's | |
1328 | breakpoint. */ | |
1329 | regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); | |
1330 | ||
b6e1c027 | 1331 | /* Use the func_addr to find the descriptor, and use that to find |
69368a60 UW |
1332 | the TOC. If we're calling via a function pointer, the pointer |
1333 | itself identifies the descriptor. */ | |
8be9034a | 1334 | { |
69368a60 UW |
1335 | struct type *ftype = check_typedef (value_type (function)); |
1336 | CORE_ADDR desc_addr = value_as_address (function); | |
1337 | ||
1338 | if (TYPE_CODE (ftype) == TYPE_CODE_PTR | |
1339 | || convert_code_addr_to_desc_addr (func_addr, &desc_addr)) | |
8be9034a | 1340 | { |
b6e1c027 AC |
1341 | /* The TOC is the second double word in the descriptor. */ |
1342 | CORE_ADDR toc = | |
1343 | read_memory_unsigned_integer (desc_addr + tdep->wordsize, | |
e17a4113 | 1344 | tdep->wordsize, byte_order); |
b6e1c027 AC |
1345 | regcache_cooked_write_unsigned (regcache, |
1346 | tdep->ppc_gp0_regnum + 2, toc); | |
8be9034a AC |
1347 | } |
1348 | } | |
1349 | ||
1350 | return sp; | |
1351 | } | |
1352 | ||
afd48b75 | 1353 | |
55eddb0f | 1354 | /* The 64 bit ABI return value convention. |
afd48b75 AC |
1355 | |
1356 | Return non-zero if the return-value is stored in a register, return | |
1357 | 0 if the return-value is instead stored on the stack (a.k.a., | |
1358 | struct return convention). | |
1359 | ||
963e2bb7 | 1360 | For a return-value stored in a register: when WRITEBUF is non-NULL, |
afd48b75 | 1361 | copy the buffer to the corresponding register return-value location |
963e2bb7 | 1362 | location; when READBUF is non-NULL, fill the buffer from the |
afd48b75 | 1363 | corresponding register return-value location. */ |
05580c65 | 1364 | enum return_value_convention |
c055b101 CV |
1365 | ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type, |
1366 | struct type *valtype, struct regcache *regcache, | |
1367 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
afd48b75 | 1368 | { |
05580c65 | 1369 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 1370 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
16796152 JB |
1371 | |
1372 | /* This function exists to support a calling convention that | |
1373 | requires floating-point registers. It shouldn't be used on | |
1374 | processors that lack them. */ | |
1375 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
1376 | ||
afd48b75 | 1377 | /* Floats and doubles in F1. */ |
944fcfab | 1378 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8) |
afd48b75 | 1379 | { |
50fd1280 | 1380 | gdb_byte regval[MAX_REGISTER_SIZE]; |
366f009f | 1381 | struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 1382 | if (writebuf != NULL) |
afd48b75 | 1383 | { |
963e2bb7 | 1384 | convert_typed_floating (writebuf, valtype, regval, regtype); |
366f009f | 1385 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); |
afd48b75 | 1386 | } |
963e2bb7 | 1387 | if (readbuf != NULL) |
afd48b75 | 1388 | { |
366f009f | 1389 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); |
963e2bb7 | 1390 | convert_typed_floating (regval, regtype, readbuf, valtype); |
afd48b75 AC |
1391 | } |
1392 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1393 | } | |
1300a2f4 TJB |
1394 | if (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT) |
1395 | return get_decimal_float_return_value (gdbarch, valtype, regcache, readbuf, | |
1396 | writebuf); | |
3d8476bc | 1397 | /* Integers in r3. */ |
b6e1c027 | 1398 | if ((TYPE_CODE (valtype) == TYPE_CODE_INT |
93d4208d UW |
1399 | || TYPE_CODE (valtype) == TYPE_CODE_ENUM |
1400 | || TYPE_CODE (valtype) == TYPE_CODE_CHAR | |
1401 | || TYPE_CODE (valtype) == TYPE_CODE_BOOL) | |
b6e1c027 | 1402 | && TYPE_LENGTH (valtype) <= 8) |
afd48b75 | 1403 | { |
963e2bb7 | 1404 | if (writebuf != NULL) |
afd48b75 AC |
1405 | { |
1406 | /* Be careful to sign extend the value. */ | |
1407 | regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 1408 | unpack_long (valtype, writebuf)); |
afd48b75 | 1409 | } |
963e2bb7 | 1410 | if (readbuf != NULL) |
afd48b75 AC |
1411 | { |
1412 | /* Extract the integer from r3. Since this is truncating the | |
1413 | value, there isn't a sign extension problem. */ | |
1414 | ULONGEST regval; | |
1415 | regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
1416 | ®val); | |
e17a4113 UW |
1417 | store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order, |
1418 | regval); | |
afd48b75 AC |
1419 | } |
1420 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1421 | } | |
1422 | /* All pointers live in r3. */ | |
93d4208d UW |
1423 | if (TYPE_CODE (valtype) == TYPE_CODE_PTR |
1424 | || TYPE_CODE (valtype) == TYPE_CODE_REF) | |
afd48b75 AC |
1425 | { |
1426 | /* All pointers live in r3. */ | |
963e2bb7 AC |
1427 | if (writebuf != NULL) |
1428 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); | |
1429 | if (readbuf != NULL) | |
1430 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf); | |
afd48b75 AC |
1431 | return RETURN_VALUE_REGISTER_CONVENTION; |
1432 | } | |
3d8476bc PG |
1433 | /* Array type has more than one use. */ |
1434 | if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY) | |
afd48b75 AC |
1435 | { |
1436 | /* Small character arrays are returned, right justified, in r3. */ | |
3d8476bc PG |
1437 | if (TYPE_LENGTH (valtype) <= 8 |
1438 | && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT | |
1439 | && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1) | |
1440 | { | |
1441 | int offset = (register_size (gdbarch, tdep->ppc_gp0_regnum + 3) | |
1442 | - TYPE_LENGTH (valtype)); | |
1443 | if (writebuf != NULL) | |
1444 | regcache_cooked_write_part (regcache, tdep->ppc_gp0_regnum + 3, | |
1445 | offset, TYPE_LENGTH (valtype), writebuf); | |
1446 | if (readbuf != NULL) | |
1447 | regcache_cooked_read_part (regcache, tdep->ppc_gp0_regnum + 3, | |
1448 | offset, TYPE_LENGTH (valtype), readbuf); | |
1449 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1450 | } | |
1451 | /* A VMX vector is returned in v2. */ | |
1452 | if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY | |
1453 | && TYPE_VECTOR (valtype) && tdep->ppc_vr0_regnum >= 0) | |
1454 | { | |
1455 | if (readbuf) | |
1456 | regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); | |
1457 | if (writebuf) | |
0df8b418 MS |
1458 | regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, |
1459 | writebuf); | |
3d8476bc PG |
1460 | return RETURN_VALUE_REGISTER_CONVENTION; |
1461 | } | |
afd48b75 AC |
1462 | } |
1463 | /* Big floating point values get stored in adjacent floating | |
3d8476bc | 1464 | point registers, starting with F1. */ |
afd48b75 | 1465 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT |
944fcfab | 1466 | && (TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 32)) |
afd48b75 | 1467 | { |
963e2bb7 | 1468 | if (writebuf || readbuf != NULL) |
afd48b75 AC |
1469 | { |
1470 | int i; | |
1471 | for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++) | |
1472 | { | |
963e2bb7 | 1473 | if (writebuf != NULL) |
366f009f | 1474 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 AC |
1475 | (const bfd_byte *) writebuf + i * 8); |
1476 | if (readbuf != NULL) | |
366f009f | 1477 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 | 1478 | (bfd_byte *) readbuf + i * 8); |
afd48b75 AC |
1479 | } |
1480 | } | |
1481 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1482 | } | |
1483 | /* Complex values get returned in f1:f2, need to convert. */ | |
1484 | if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX | |
1485 | && (TYPE_LENGTH (valtype) == 8 || TYPE_LENGTH (valtype) == 16)) | |
1486 | { | |
1487 | if (regcache != NULL) | |
1488 | { | |
1489 | int i; | |
1490 | for (i = 0; i < 2; i++) | |
1491 | { | |
50fd1280 | 1492 | gdb_byte regval[MAX_REGISTER_SIZE]; |
944fcfab | 1493 | struct type *regtype = |
40a6adc1 | 1494 | register_type (gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 1495 | if (writebuf != NULL) |
afd48b75 | 1496 | { |
963e2bb7 | 1497 | convert_typed_floating ((const bfd_byte *) writebuf + |
944fcfab | 1498 | i * (TYPE_LENGTH (valtype) / 2), |
afd48b75 | 1499 | valtype, regval, regtype); |
366f009f JB |
1500 | regcache_cooked_write (regcache, |
1501 | tdep->ppc_fp0_regnum + 1 + i, | |
944fcfab | 1502 | regval); |
afd48b75 | 1503 | } |
963e2bb7 | 1504 | if (readbuf != NULL) |
afd48b75 | 1505 | { |
366f009f JB |
1506 | regcache_cooked_read (regcache, |
1507 | tdep->ppc_fp0_regnum + 1 + i, | |
1508 | regval); | |
afd48b75 | 1509 | convert_typed_floating (regval, regtype, |
963e2bb7 | 1510 | (bfd_byte *) readbuf + |
944fcfab | 1511 | i * (TYPE_LENGTH (valtype) / 2), |
afd48b75 AC |
1512 | valtype); |
1513 | } | |
1514 | } | |
1515 | } | |
1516 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1517 | } | |
1518 | /* Big complex values get stored in f1:f4. */ | |
944fcfab | 1519 | if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && TYPE_LENGTH (valtype) == 32) |
afd48b75 AC |
1520 | { |
1521 | if (regcache != NULL) | |
1522 | { | |
1523 | int i; | |
1524 | for (i = 0; i < 4; i++) | |
1525 | { | |
963e2bb7 | 1526 | if (writebuf != NULL) |
366f009f | 1527 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 AC |
1528 | (const bfd_byte *) writebuf + i * 8); |
1529 | if (readbuf != NULL) | |
366f009f | 1530 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, |
963e2bb7 | 1531 | (bfd_byte *) readbuf + i * 8); |
afd48b75 AC |
1532 | } |
1533 | } | |
1534 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1535 | } | |
1536 | return RETURN_VALUE_STRUCT_CONVENTION; | |
1537 | } | |
1538 |