Commit | Line | Data |
---|---|---|
7b112f9c JT |
1 | /* Target-dependent code for PowerPC systems using the SVR4 ABI |
2 | for GDB, the GNU debugger. | |
3 | ||
61baf725 | 4 | Copyright (C) 2000-2017 Free Software Foundation, Inc. |
7b112f9c JT |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
7b112f9c JT |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7b112f9c JT |
20 | |
21 | #include "defs.h" | |
22 | #include "gdbcore.h" | |
23 | #include "inferior.h" | |
24 | #include "regcache.h" | |
25 | #include "value.h" | |
7b112f9c | 26 | #include "ppc-tdep.h" |
6066c3de | 27 | #include "target.h" |
0a90bcdd | 28 | #include "objfiles.h" |
7d9b040b | 29 | #include "infcall.h" |
54fcddd0 | 30 | #include "dwarf2.h" |
325fac50 | 31 | #include <algorithm> |
7b112f9c | 32 | |
88aed45e UW |
33 | |
34 | /* Check whether FTPYE is a (pointer to) function type that should use | |
35 | the OpenCL vector ABI. */ | |
36 | ||
37 | static int | |
38 | ppc_sysv_use_opencl_abi (struct type *ftype) | |
39 | { | |
40 | ftype = check_typedef (ftype); | |
41 | ||
42 | if (TYPE_CODE (ftype) == TYPE_CODE_PTR) | |
43 | ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); | |
44 | ||
45 | return (TYPE_CODE (ftype) == TYPE_CODE_FUNC | |
46 | && TYPE_CALLING_CONVENTION (ftype) == DW_CC_GDB_IBM_OpenCL); | |
47 | } | |
48 | ||
0df8b418 | 49 | /* Pass the arguments in either registers, or in the stack. Using the |
7b112f9c JT |
50 | ppc sysv ABI, the first eight words of the argument list (that might |
51 | be less than eight parameters if some parameters occupy more than one | |
52 | word) are passed in r3..r10 registers. float and double parameters are | |
0df8b418 MS |
53 | passed in fpr's, in addition to that. Rest of the parameters if any |
54 | are passed in user stack. | |
7b112f9c JT |
55 | |
56 | If the function is returning a structure, then the return address is passed | |
57 | in r3, then the first 7 words of the parametes can be passed in registers, | |
0df8b418 | 58 | starting from r4. */ |
7b112f9c JT |
59 | |
60 | CORE_ADDR | |
7d9b040b | 61 | ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
77b2b6d4 AC |
62 | struct regcache *regcache, CORE_ADDR bp_addr, |
63 | int nargs, struct value **args, CORE_ADDR sp, | |
64 | int struct_return, CORE_ADDR struct_addr) | |
7b112f9c | 65 | { |
40a6adc1 | 66 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 67 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
88aed45e | 68 | int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function)); |
fb4443d8 | 69 | ULONGEST saved_sp; |
68856ea3 AC |
70 | int argspace = 0; /* 0 is an initial wrong guess. */ |
71 | int write_pass; | |
7b112f9c | 72 | |
b14d30e1 JM |
73 | gdb_assert (tdep->wordsize == 4); |
74 | ||
40a6adc1 | 75 | regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), |
3e8c568d | 76 | &saved_sp); |
fb4443d8 | 77 | |
68856ea3 | 78 | /* Go through the argument list twice. |
7b112f9c | 79 | |
68856ea3 AC |
80 | Pass 1: Figure out how much new stack space is required for |
81 | arguments and pushed values. Unlike the PowerOpen ABI, the SysV | |
82 | ABI doesn't reserve any extra space for parameters which are put | |
83 | in registers, but does always push structures and then pass their | |
84 | address. | |
7a41266b | 85 | |
68856ea3 AC |
86 | Pass 2: Replay the same computation but this time also write the |
87 | values out to the target. */ | |
7b112f9c | 88 | |
68856ea3 AC |
89 | for (write_pass = 0; write_pass < 2; write_pass++) |
90 | { | |
91 | int argno; | |
92 | /* Next available floating point register for float and double | |
93 | arguments. */ | |
94 | int freg = 1; | |
95 | /* Next available general register for non-float, non-vector | |
96 | arguments. */ | |
97 | int greg = 3; | |
98 | /* Next available vector register for vector arguments. */ | |
99 | int vreg = 2; | |
100 | /* Arguments start above the "LR save word" and "Back chain". */ | |
101 | int argoffset = 2 * tdep->wordsize; | |
102 | /* Structures start after the arguments. */ | |
103 | int structoffset = argoffset + argspace; | |
104 | ||
105 | /* If the function is returning a `struct', then the first word | |
944fcfab AC |
106 | (which will be passed in r3) is used for struct return |
107 | address. In that case we should advance one word and start | |
108 | from r4 register to copy parameters. */ | |
68856ea3 | 109 | if (struct_return) |
7b112f9c | 110 | { |
68856ea3 AC |
111 | if (write_pass) |
112 | regcache_cooked_write_signed (regcache, | |
113 | tdep->ppc_gp0_regnum + greg, | |
114 | struct_addr); | |
115 | greg++; | |
7b112f9c | 116 | } |
68856ea3 AC |
117 | |
118 | for (argno = 0; argno < nargs; argno++) | |
7b112f9c | 119 | { |
68856ea3 | 120 | struct value *arg = args[argno]; |
df407dfe | 121 | struct type *type = check_typedef (value_type (arg)); |
68856ea3 | 122 | int len = TYPE_LENGTH (type); |
0fd88904 | 123 | const bfd_byte *val = value_contents (arg); |
68856ea3 | 124 | |
55eddb0f DJ |
125 | if (TYPE_CODE (type) == TYPE_CODE_FLT && len <= 8 |
126 | && !tdep->soft_float) | |
7b112f9c | 127 | { |
68856ea3 | 128 | /* Floating point value converted to "double" then |
944fcfab AC |
129 | passed in an FP register, when the registers run out, |
130 | 8 byte aligned stack is used. */ | |
68856ea3 AC |
131 | if (freg <= 8) |
132 | { | |
133 | if (write_pass) | |
134 | { | |
135 | /* Always store the floating point value using | |
944fcfab | 136 | the register's floating-point format. */ |
0f068fb5 | 137 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
68856ea3 | 138 | struct type *regtype |
366f009f | 139 | = register_type (gdbarch, tdep->ppc_fp0_regnum + freg); |
68856ea3 | 140 | convert_typed_floating (val, type, regval, regtype); |
366f009f JB |
141 | regcache_cooked_write (regcache, |
142 | tdep->ppc_fp0_regnum + freg, | |
68856ea3 AC |
143 | regval); |
144 | } | |
145 | freg++; | |
146 | } | |
7b112f9c JT |
147 | else |
148 | { | |
f964a756 MK |
149 | /* The SysV ABI tells us to convert floats to |
150 | doubles before writing them to an 8 byte aligned | |
151 | stack location. Unfortunately GCC does not do | |
152 | that, and stores floats into 4 byte aligned | |
153 | locations without converting them to doubles. | |
154 | Since there is no know compiler that actually | |
155 | follows the ABI here, we implement the GCC | |
156 | convention. */ | |
157 | ||
158 | /* Align to 4 bytes or 8 bytes depending on the type of | |
159 | the argument (float or double). */ | |
160 | argoffset = align_up (argoffset, len); | |
68856ea3 | 161 | if (write_pass) |
68856ea3 | 162 | write_memory (sp + argoffset, val, len); |
f964a756 | 163 | argoffset += len; |
7b112f9c JT |
164 | } |
165 | } | |
b14d30e1 JM |
166 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
167 | && len == 16 | |
168 | && !tdep->soft_float | |
40a6adc1 | 169 | && (gdbarch_long_double_format (gdbarch) |
b14d30e1 JM |
170 | == floatformats_ibm_long_double)) |
171 | { | |
172 | /* IBM long double passed in two FP registers if | |
173 | available, otherwise 8-byte aligned stack. */ | |
174 | if (freg <= 7) | |
175 | { | |
176 | if (write_pass) | |
177 | { | |
178 | regcache_cooked_write (regcache, | |
179 | tdep->ppc_fp0_regnum + freg, | |
180 | val); | |
181 | regcache_cooked_write (regcache, | |
182 | tdep->ppc_fp0_regnum + freg + 1, | |
183 | val + 8); | |
184 | } | |
185 | freg += 2; | |
186 | } | |
187 | else | |
188 | { | |
189 | argoffset = align_up (argoffset, 8); | |
190 | if (write_pass) | |
191 | write_memory (sp + argoffset, val, len); | |
192 | argoffset += 16; | |
193 | } | |
194 | } | |
55eddb0f DJ |
195 | else if (len == 8 |
196 | && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */ | |
00fbcec4 JM |
197 | || TYPE_CODE (type) == TYPE_CODE_FLT /* double */ |
198 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT | |
199 | && tdep->soft_float))) | |
7b112f9c | 200 | { |
00fbcec4 JM |
201 | /* "long long" or soft-float "double" or "_Decimal64" |
202 | passed in an odd/even register pair with the low | |
203 | addressed word in the odd register and the high | |
204 | addressed word in the even register, or when the | |
205 | registers run out an 8 byte aligned stack | |
206 | location. */ | |
68856ea3 AC |
207 | if (greg > 9) |
208 | { | |
209 | /* Just in case GREG was 10. */ | |
210 | greg = 11; | |
211 | argoffset = align_up (argoffset, 8); | |
212 | if (write_pass) | |
213 | write_memory (sp + argoffset, val, len); | |
214 | argoffset += 8; | |
215 | } | |
68856ea3 AC |
216 | else |
217 | { | |
218 | /* Must start on an odd register - r3/r4 etc. */ | |
219 | if ((greg & 1) == 0) | |
220 | greg++; | |
221 | if (write_pass) | |
222 | { | |
223 | regcache_cooked_write (regcache, | |
224 | tdep->ppc_gp0_regnum + greg + 0, | |
225 | val + 0); | |
226 | regcache_cooked_write (regcache, | |
227 | tdep->ppc_gp0_regnum + greg + 1, | |
228 | val + 4); | |
229 | } | |
230 | greg += 2; | |
231 | } | |
7b112f9c | 232 | } |
00fbcec4 JM |
233 | else if (len == 16 |
234 | && ((TYPE_CODE (type) == TYPE_CODE_FLT | |
235 | && (gdbarch_long_double_format (gdbarch) | |
236 | == floatformats_ibm_long_double)) | |
237 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT | |
238 | && tdep->soft_float))) | |
b14d30e1 | 239 | { |
00fbcec4 JM |
240 | /* Soft-float IBM long double or _Decimal128 passed in |
241 | four consecutive registers, or on the stack. The | |
242 | registers are not necessarily odd/even pairs. */ | |
b14d30e1 JM |
243 | if (greg > 7) |
244 | { | |
245 | greg = 11; | |
246 | argoffset = align_up (argoffset, 8); | |
247 | if (write_pass) | |
248 | write_memory (sp + argoffset, val, len); | |
249 | argoffset += 16; | |
250 | } | |
251 | else | |
252 | { | |
253 | if (write_pass) | |
254 | { | |
255 | regcache_cooked_write (regcache, | |
256 | tdep->ppc_gp0_regnum + greg + 0, | |
257 | val + 0); | |
258 | regcache_cooked_write (regcache, | |
259 | tdep->ppc_gp0_regnum + greg + 1, | |
260 | val + 4); | |
261 | regcache_cooked_write (regcache, | |
262 | tdep->ppc_gp0_regnum + greg + 2, | |
263 | val + 8); | |
264 | regcache_cooked_write (regcache, | |
265 | tdep->ppc_gp0_regnum + greg + 3, | |
266 | val + 12); | |
267 | } | |
268 | greg += 4; | |
269 | } | |
270 | } | |
1300a2f4 TJB |
271 | else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len <= 8 |
272 | && !tdep->soft_float) | |
273 | { | |
274 | /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can | |
275 | end up in memory. */ | |
276 | ||
277 | if (freg <= 8) | |
278 | { | |
279 | if (write_pass) | |
280 | { | |
0f068fb5 | 281 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
1300a2f4 TJB |
282 | const gdb_byte *p; |
283 | ||
284 | /* 32-bit decimal floats are right aligned in the | |
285 | doubleword. */ | |
286 | if (TYPE_LENGTH (type) == 4) | |
287 | { | |
288 | memcpy (regval + 4, val, 4); | |
289 | p = regval; | |
290 | } | |
291 | else | |
292 | p = val; | |
293 | ||
294 | regcache_cooked_write (regcache, | |
295 | tdep->ppc_fp0_regnum + freg, p); | |
296 | } | |
297 | ||
298 | freg++; | |
299 | } | |
300 | else | |
301 | { | |
302 | argoffset = align_up (argoffset, len); | |
303 | ||
304 | if (write_pass) | |
305 | /* Write value in the stack's parameter save area. */ | |
306 | write_memory (sp + argoffset, val, len); | |
307 | ||
308 | argoffset += len; | |
309 | } | |
310 | } | |
311 | else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len == 16 | |
312 | && !tdep->soft_float) | |
313 | { | |
314 | /* 128-bit decimal floats go in f2 .. f7, always in even/odd | |
315 | pairs. They can end up in memory, using two doublewords. */ | |
316 | ||
317 | if (freg <= 6) | |
318 | { | |
319 | /* Make sure freg is even. */ | |
320 | freg += freg & 1; | |
321 | ||
322 | if (write_pass) | |
323 | { | |
324 | regcache_cooked_write (regcache, | |
325 | tdep->ppc_fp0_regnum + freg, val); | |
326 | regcache_cooked_write (regcache, | |
327 | tdep->ppc_fp0_regnum + freg + 1, val + 8); | |
328 | } | |
329 | } | |
330 | else | |
331 | { | |
332 | argoffset = align_up (argoffset, 8); | |
333 | ||
334 | if (write_pass) | |
335 | write_memory (sp + argoffset, val, 16); | |
336 | ||
337 | argoffset += 16; | |
338 | } | |
339 | ||
340 | /* If a 128-bit decimal float goes to the stack because only f7 | |
341 | and f8 are free (thus there's no even/odd register pair | |
342 | available), these registers should be marked as occupied. | |
343 | Hence we increase freg even when writing to memory. */ | |
344 | freg += 2; | |
345 | } | |
54fcddd0 UW |
346 | else if (len < 16 |
347 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
348 | && TYPE_VECTOR (type) | |
349 | && opencl_abi) | |
350 | { | |
351 | /* OpenCL vectors shorter than 16 bytes are passed as if | |
352 | a series of independent scalars. */ | |
353 | struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type)); | |
354 | int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype); | |
355 | ||
356 | for (i = 0; i < nelt; i++) | |
357 | { | |
358 | const gdb_byte *elval = val + i * TYPE_LENGTH (eltype); | |
359 | ||
360 | if (TYPE_CODE (eltype) == TYPE_CODE_FLT && !tdep->soft_float) | |
361 | { | |
362 | if (freg <= 8) | |
363 | { | |
364 | if (write_pass) | |
365 | { | |
366 | int regnum = tdep->ppc_fp0_regnum + freg; | |
0f068fb5 | 367 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
54fcddd0 UW |
368 | struct type *regtype |
369 | = register_type (gdbarch, regnum); | |
370 | convert_typed_floating (elval, eltype, | |
371 | regval, regtype); | |
372 | regcache_cooked_write (regcache, regnum, regval); | |
373 | } | |
374 | freg++; | |
375 | } | |
376 | else | |
377 | { | |
378 | argoffset = align_up (argoffset, len); | |
379 | if (write_pass) | |
380 | write_memory (sp + argoffset, val, len); | |
381 | argoffset += len; | |
382 | } | |
383 | } | |
384 | else if (TYPE_LENGTH (eltype) == 8) | |
385 | { | |
386 | if (greg > 9) | |
387 | { | |
388 | /* Just in case GREG was 10. */ | |
389 | greg = 11; | |
390 | argoffset = align_up (argoffset, 8); | |
391 | if (write_pass) | |
392 | write_memory (sp + argoffset, elval, | |
393 | TYPE_LENGTH (eltype)); | |
394 | argoffset += 8; | |
395 | } | |
396 | else | |
397 | { | |
398 | /* Must start on an odd register - r3/r4 etc. */ | |
399 | if ((greg & 1) == 0) | |
400 | greg++; | |
401 | if (write_pass) | |
402 | { | |
403 | int regnum = tdep->ppc_gp0_regnum + greg; | |
404 | regcache_cooked_write (regcache, | |
405 | regnum + 0, elval + 0); | |
406 | regcache_cooked_write (regcache, | |
407 | regnum + 1, elval + 4); | |
408 | } | |
409 | greg += 2; | |
410 | } | |
411 | } | |
412 | else | |
413 | { | |
0f068fb5 | 414 | gdb_byte word[PPC_MAX_REGISTER_SIZE]; |
54fcddd0 UW |
415 | store_unsigned_integer (word, tdep->wordsize, byte_order, |
416 | unpack_long (eltype, elval)); | |
417 | ||
418 | if (greg <= 10) | |
419 | { | |
420 | if (write_pass) | |
421 | regcache_cooked_write (regcache, | |
422 | tdep->ppc_gp0_regnum + greg, | |
423 | word); | |
424 | greg++; | |
425 | } | |
426 | else | |
427 | { | |
428 | argoffset = align_up (argoffset, tdep->wordsize); | |
429 | if (write_pass) | |
430 | write_memory (sp + argoffset, word, tdep->wordsize); | |
431 | argoffset += tdep->wordsize; | |
432 | } | |
433 | } | |
434 | } | |
435 | } | |
436 | else if (len >= 16 | |
437 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
438 | && TYPE_VECTOR (type) | |
439 | && opencl_abi) | |
440 | { | |
441 | /* OpenCL vectors 16 bytes or longer are passed as if | |
442 | a series of AltiVec vectors. */ | |
443 | int i; | |
444 | ||
445 | for (i = 0; i < len / 16; i++) | |
446 | { | |
447 | const gdb_byte *elval = val + i * 16; | |
448 | ||
449 | if (vreg <= 13) | |
450 | { | |
451 | if (write_pass) | |
452 | regcache_cooked_write (regcache, | |
453 | tdep->ppc_vr0_regnum + vreg, | |
454 | elval); | |
455 | vreg++; | |
456 | } | |
457 | else | |
458 | { | |
459 | argoffset = align_up (argoffset, 16); | |
460 | if (write_pass) | |
461 | write_memory (sp + argoffset, elval, 16); | |
462 | argoffset += 16; | |
463 | } | |
464 | } | |
465 | } | |
68856ea3 AC |
466 | else if (len == 16 |
467 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
55eddb0f DJ |
468 | && TYPE_VECTOR (type) |
469 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC) | |
7b112f9c | 470 | { |
68856ea3 | 471 | /* Vector parameter passed in an Altivec register, or |
944fcfab | 472 | when that runs out, 16 byte aligned stack location. */ |
7b112f9c JT |
473 | if (vreg <= 13) |
474 | { | |
68856ea3 | 475 | if (write_pass) |
9c9acae0 | 476 | regcache_cooked_write (regcache, |
944fcfab | 477 | tdep->ppc_vr0_regnum + vreg, val); |
7b112f9c JT |
478 | vreg++; |
479 | } | |
480 | else | |
481 | { | |
68856ea3 AC |
482 | argoffset = align_up (argoffset, 16); |
483 | if (write_pass) | |
484 | write_memory (sp + argoffset, val, 16); | |
7b112f9c JT |
485 | argoffset += 16; |
486 | } | |
487 | } | |
944fcfab | 488 | else if (len == 8 |
0a613259 | 489 | && TYPE_CODE (type) == TYPE_CODE_ARRAY |
55eddb0f DJ |
490 | && TYPE_VECTOR (type) |
491 | && tdep->vector_abi == POWERPC_VEC_SPE) | |
944fcfab | 492 | { |
68856ea3 | 493 | /* Vector parameter passed in an e500 register, or when |
944fcfab AC |
494 | that runs out, 8 byte aligned stack location. Note |
495 | that since e500 vector and general purpose registers | |
496 | both map onto the same underlying register set, a | |
497 | "greg" and not a "vreg" is consumed here. A cooked | |
498 | write stores the value in the correct locations | |
499 | within the raw register cache. */ | |
500 | if (greg <= 10) | |
501 | { | |
68856ea3 | 502 | if (write_pass) |
9c9acae0 | 503 | regcache_cooked_write (regcache, |
944fcfab AC |
504 | tdep->ppc_ev0_regnum + greg, val); |
505 | greg++; | |
506 | } | |
507 | else | |
508 | { | |
68856ea3 AC |
509 | argoffset = align_up (argoffset, 8); |
510 | if (write_pass) | |
511 | write_memory (sp + argoffset, val, 8); | |
944fcfab AC |
512 | argoffset += 8; |
513 | } | |
514 | } | |
68856ea3 AC |
515 | else |
516 | { | |
517 | /* Reduce the parameter down to something that fits in a | |
944fcfab | 518 | "word". */ |
0f068fb5 AH |
519 | gdb_byte word[PPC_MAX_REGISTER_SIZE]; |
520 | memset (word, 0, PPC_MAX_REGISTER_SIZE); | |
68856ea3 AC |
521 | if (len > tdep->wordsize |
522 | || TYPE_CODE (type) == TYPE_CODE_STRUCT | |
523 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
524 | { | |
55eddb0f | 525 | /* Structs and large values are put in an |
0df8b418 | 526 | aligned stack slot ... */ |
55eddb0f DJ |
527 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
528 | && TYPE_VECTOR (type) | |
529 | && len >= 16) | |
530 | structoffset = align_up (structoffset, 16); | |
531 | else | |
532 | structoffset = align_up (structoffset, 8); | |
533 | ||
68856ea3 AC |
534 | if (write_pass) |
535 | write_memory (sp + structoffset, val, len); | |
536 | /* ... and then a "word" pointing to that address is | |
944fcfab | 537 | passed as the parameter. */ |
e17a4113 | 538 | store_unsigned_integer (word, tdep->wordsize, byte_order, |
68856ea3 AC |
539 | sp + structoffset); |
540 | structoffset += len; | |
541 | } | |
542 | else if (TYPE_CODE (type) == TYPE_CODE_INT) | |
543 | /* Sign or zero extend the "int" into a "word". */ | |
e17a4113 | 544 | store_unsigned_integer (word, tdep->wordsize, byte_order, |
68856ea3 AC |
545 | unpack_long (type, val)); |
546 | else | |
547 | /* Always goes in the low address. */ | |
548 | memcpy (word, val, len); | |
549 | /* Store that "word" in a register, or on the stack. | |
944fcfab | 550 | The words have "4" byte alignment. */ |
68856ea3 AC |
551 | if (greg <= 10) |
552 | { | |
553 | if (write_pass) | |
554 | regcache_cooked_write (regcache, | |
944fcfab | 555 | tdep->ppc_gp0_regnum + greg, word); |
68856ea3 AC |
556 | greg++; |
557 | } | |
558 | else | |
559 | { | |
560 | argoffset = align_up (argoffset, tdep->wordsize); | |
561 | if (write_pass) | |
562 | write_memory (sp + argoffset, word, tdep->wordsize); | |
563 | argoffset += tdep->wordsize; | |
564 | } | |
565 | } | |
566 | } | |
567 | ||
568 | /* Compute the actual stack space requirements. */ | |
569 | if (!write_pass) | |
570 | { | |
571 | /* Remember the amount of space needed by the arguments. */ | |
572 | argspace = argoffset; | |
573 | /* Allocate space for both the arguments and the structures. */ | |
574 | sp -= (argoffset + structoffset); | |
575 | /* Ensure that the stack is still 16 byte aligned. */ | |
576 | sp = align_down (sp, 16); | |
577 | } | |
65ada037 MK |
578 | |
579 | /* The psABI says that "A caller of a function that takes a | |
580 | variable argument list shall set condition register bit 6 to | |
581 | 1 if it passes one or more arguments in the floating-point | |
0df8b418 | 582 | registers. It is strongly recommended that the caller set the |
65ada037 MK |
583 | bit to 0 otherwise..." Doing this for normal functions too |
584 | shouldn't hurt. */ | |
585 | if (write_pass) | |
586 | { | |
587 | ULONGEST cr; | |
588 | ||
589 | regcache_cooked_read_unsigned (regcache, tdep->ppc_cr_regnum, &cr); | |
590 | if (freg > 1) | |
591 | cr |= 0x02000000; | |
592 | else | |
593 | cr &= ~0x02000000; | |
594 | regcache_cooked_write_unsigned (regcache, tdep->ppc_cr_regnum, cr); | |
595 | } | |
7b112f9c JT |
596 | } |
597 | ||
68856ea3 | 598 | /* Update %sp. */ |
40a6adc1 | 599 | regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); |
68856ea3 AC |
600 | |
601 | /* Write the backchain (it occupies WORDSIZED bytes). */ | |
e17a4113 | 602 | write_memory_signed_integer (sp, tdep->wordsize, byte_order, saved_sp); |
68856ea3 | 603 | |
e56a0ecc AC |
604 | /* Point the inferior function call's return address at the dummy's |
605 | breakpoint. */ | |
68856ea3 | 606 | regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); |
e56a0ecc | 607 | |
7b112f9c JT |
608 | return sp; |
609 | } | |
610 | ||
e765b44c | 611 | /* Handle the return-value conventions for Decimal Floating Point values. */ |
f486487f | 612 | static enum return_value_convention |
1300a2f4 TJB |
613 | get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype, |
614 | struct regcache *regcache, gdb_byte *readbuf, | |
615 | const gdb_byte *writebuf) | |
616 | { | |
617 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
618 | ||
619 | gdb_assert (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT); | |
620 | ||
621 | /* 32-bit and 64-bit decimal floats in f1. */ | |
622 | if (TYPE_LENGTH (valtype) <= 8) | |
623 | { | |
624 | if (writebuf != NULL) | |
625 | { | |
0f068fb5 | 626 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
1300a2f4 TJB |
627 | const gdb_byte *p; |
628 | ||
629 | /* 32-bit decimal float is right aligned in the doubleword. */ | |
630 | if (TYPE_LENGTH (valtype) == 4) | |
631 | { | |
632 | memcpy (regval + 4, writebuf, 4); | |
633 | p = regval; | |
634 | } | |
635 | else | |
636 | p = writebuf; | |
637 | ||
638 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, p); | |
639 | } | |
640 | if (readbuf != NULL) | |
641 | { | |
642 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf); | |
643 | ||
644 | /* Left align 32-bit decimal float. */ | |
645 | if (TYPE_LENGTH (valtype) == 4) | |
646 | memcpy (readbuf, readbuf + 4, 4); | |
647 | } | |
648 | } | |
649 | /* 128-bit decimal floats in f2,f3. */ | |
650 | else if (TYPE_LENGTH (valtype) == 16) | |
651 | { | |
652 | if (writebuf != NULL || readbuf != NULL) | |
653 | { | |
654 | int i; | |
655 | ||
656 | for (i = 0; i < 2; i++) | |
657 | { | |
658 | if (writebuf != NULL) | |
659 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2 + i, | |
660 | writebuf + i * 8); | |
661 | if (readbuf != NULL) | |
662 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2 + i, | |
663 | readbuf + i * 8); | |
664 | } | |
665 | } | |
666 | } | |
667 | else | |
668 | /* Can't happen. */ | |
9b20d036 | 669 | internal_error (__FILE__, __LINE__, _("Unknown decimal float size.")); |
1300a2f4 TJB |
670 | |
671 | return RETURN_VALUE_REGISTER_CONVENTION; | |
672 | } | |
673 | ||
e754ae69 AC |
674 | /* Handle the return-value conventions specified by the SysV 32-bit |
675 | PowerPC ABI (including all the supplements): | |
676 | ||
677 | no floating-point: floating-point values returned using 32-bit | |
678 | general-purpose registers. | |
679 | ||
680 | Altivec: 128-bit vectors returned using vector registers. | |
681 | ||
682 | e500: 64-bit vectors returned using the full full 64 bit EV | |
683 | register, floating-point values returned using 32-bit | |
684 | general-purpose registers. | |
685 | ||
686 | GCC (broken): Small struct values right (instead of left) aligned | |
687 | when returned in general-purpose registers. */ | |
688 | ||
689 | static enum return_value_convention | |
54fcddd0 UW |
690 | do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type, |
691 | struct type *type, struct regcache *regcache, | |
692 | gdb_byte *readbuf, const gdb_byte *writebuf, | |
693 | int broken_gcc) | |
e754ae69 | 694 | { |
05580c65 | 695 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 696 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
88aed45e | 697 | int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0; |
54fcddd0 | 698 | |
e754ae69 | 699 | gdb_assert (tdep->wordsize == 4); |
54fcddd0 | 700 | |
e754ae69 AC |
701 | if (TYPE_CODE (type) == TYPE_CODE_FLT |
702 | && TYPE_LENGTH (type) <= 8 | |
55eddb0f | 703 | && !tdep->soft_float) |
e754ae69 | 704 | { |
963e2bb7 | 705 | if (readbuf) |
e754ae69 AC |
706 | { |
707 | /* Floats and doubles stored in "f1". Convert the value to | |
708 | the required type. */ | |
0f068fb5 | 709 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
366f009f JB |
710 | struct type *regtype = register_type (gdbarch, |
711 | tdep->ppc_fp0_regnum + 1); | |
712 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); | |
963e2bb7 | 713 | convert_typed_floating (regval, regtype, readbuf, type); |
e754ae69 | 714 | } |
963e2bb7 | 715 | if (writebuf) |
e754ae69 AC |
716 | { |
717 | /* Floats and doubles stored in "f1". Convert the value to | |
718 | the register's "double" type. */ | |
0f068fb5 | 719 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
366f009f | 720 | struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); |
963e2bb7 | 721 | convert_typed_floating (writebuf, type, regval, regtype); |
366f009f | 722 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); |
e754ae69 AC |
723 | } |
724 | return RETURN_VALUE_REGISTER_CONVENTION; | |
725 | } | |
b14d30e1 JM |
726 | if (TYPE_CODE (type) == TYPE_CODE_FLT |
727 | && TYPE_LENGTH (type) == 16 | |
728 | && !tdep->soft_float | |
0df8b418 MS |
729 | && (gdbarch_long_double_format (gdbarch) |
730 | == floatformats_ibm_long_double)) | |
b14d30e1 JM |
731 | { |
732 | /* IBM long double stored in f1 and f2. */ | |
733 | if (readbuf) | |
734 | { | |
735 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf); | |
736 | regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2, | |
737 | readbuf + 8); | |
738 | } | |
739 | if (writebuf) | |
740 | { | |
741 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, writebuf); | |
742 | regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2, | |
743 | writebuf + 8); | |
744 | } | |
745 | return RETURN_VALUE_REGISTER_CONVENTION; | |
746 | } | |
00fbcec4 JM |
747 | if (TYPE_LENGTH (type) == 16 |
748 | && ((TYPE_CODE (type) == TYPE_CODE_FLT | |
0df8b418 MS |
749 | && (gdbarch_long_double_format (gdbarch) |
750 | == floatformats_ibm_long_double)) | |
00fbcec4 | 751 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float))) |
b14d30e1 | 752 | { |
00fbcec4 JM |
753 | /* Soft-float IBM long double or _Decimal128 stored in r3, r4, |
754 | r5, r6. */ | |
b14d30e1 JM |
755 | if (readbuf) |
756 | { | |
757 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf); | |
758 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
759 | readbuf + 4); | |
760 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5, | |
761 | readbuf + 8); | |
762 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6, | |
763 | readbuf + 12); | |
764 | } | |
765 | if (writebuf) | |
766 | { | |
767 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); | |
768 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
769 | writebuf + 4); | |
770 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5, | |
771 | writebuf + 8); | |
772 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6, | |
773 | writebuf + 12); | |
774 | } | |
775 | return RETURN_VALUE_REGISTER_CONVENTION; | |
776 | } | |
e754ae69 | 777 | if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8) |
00fbcec4 JM |
778 | || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
779 | || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 8 | |
780 | && tdep->soft_float)) | |
e754ae69 | 781 | { |
963e2bb7 | 782 | if (readbuf) |
e754ae69 | 783 | { |
00fbcec4 JM |
784 | /* A long long, double or _Decimal64 stored in the 32 bit |
785 | r3/r4. */ | |
e754ae69 | 786 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, |
55eddb0f | 787 | readbuf + 0); |
e754ae69 | 788 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, |
55eddb0f | 789 | readbuf + 4); |
e754ae69 | 790 | } |
963e2bb7 | 791 | if (writebuf) |
e754ae69 | 792 | { |
00fbcec4 JM |
793 | /* A long long, double or _Decimal64 stored in the 32 bit |
794 | r3/r4. */ | |
e754ae69 | 795 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, |
55eddb0f | 796 | writebuf + 0); |
e754ae69 | 797 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, |
55eddb0f | 798 | writebuf + 4); |
e754ae69 AC |
799 | } |
800 | return RETURN_VALUE_REGISTER_CONVENTION; | |
801 | } | |
1300a2f4 TJB |
802 | if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && !tdep->soft_float) |
803 | return get_decimal_float_return_value (gdbarch, type, regcache, readbuf, | |
804 | writebuf); | |
f0027ce2 DJ |
805 | else if ((TYPE_CODE (type) == TYPE_CODE_INT |
806 | || TYPE_CODE (type) == TYPE_CODE_CHAR | |
807 | || TYPE_CODE (type) == TYPE_CODE_BOOL | |
808 | || TYPE_CODE (type) == TYPE_CODE_PTR | |
aa006118 | 809 | || TYPE_IS_REFERENCE (type) |
f0027ce2 DJ |
810 | || TYPE_CODE (type) == TYPE_CODE_ENUM) |
811 | && TYPE_LENGTH (type) <= tdep->wordsize) | |
e754ae69 | 812 | { |
963e2bb7 | 813 | if (readbuf) |
e754ae69 AC |
814 | { |
815 | /* Some sort of integer stored in r3. Since TYPE isn't | |
816 | bigger than the register, sign extension isn't a problem | |
817 | - just do everything unsigned. */ | |
818 | ULONGEST regval; | |
819 | regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
820 | ®val); | |
e17a4113 UW |
821 | store_unsigned_integer (readbuf, TYPE_LENGTH (type), byte_order, |
822 | regval); | |
e754ae69 | 823 | } |
963e2bb7 | 824 | if (writebuf) |
e754ae69 AC |
825 | { |
826 | /* Some sort of integer stored in r3. Use unpack_long since | |
827 | that should handle any required sign extension. */ | |
828 | regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, | |
963e2bb7 | 829 | unpack_long (type, writebuf)); |
e754ae69 AC |
830 | } |
831 | return RETURN_VALUE_REGISTER_CONVENTION; | |
832 | } | |
54fcddd0 UW |
833 | /* OpenCL vectors < 16 bytes are returned as distinct |
834 | scalars in f1..f2 or r3..r10. */ | |
835 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
836 | && TYPE_VECTOR (type) | |
837 | && TYPE_LENGTH (type) < 16 | |
838 | && opencl_abi) | |
839 | { | |
840 | struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type)); | |
841 | int i, nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype); | |
842 | ||
843 | for (i = 0; i < nelt; i++) | |
844 | { | |
845 | int offset = i * TYPE_LENGTH (eltype); | |
846 | ||
847 | if (TYPE_CODE (eltype) == TYPE_CODE_FLT) | |
848 | { | |
849 | int regnum = tdep->ppc_fp0_regnum + 1 + i; | |
0f068fb5 | 850 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
54fcddd0 UW |
851 | struct type *regtype = register_type (gdbarch, regnum); |
852 | ||
853 | if (writebuf != NULL) | |
854 | { | |
855 | convert_typed_floating (writebuf + offset, eltype, | |
856 | regval, regtype); | |
857 | regcache_cooked_write (regcache, regnum, regval); | |
858 | } | |
859 | if (readbuf != NULL) | |
860 | { | |
861 | regcache_cooked_read (regcache, regnum, regval); | |
862 | convert_typed_floating (regval, regtype, | |
863 | readbuf + offset, eltype); | |
864 | } | |
865 | } | |
866 | else | |
867 | { | |
868 | int regnum = tdep->ppc_gp0_regnum + 3 + i; | |
869 | ULONGEST regval; | |
870 | ||
871 | if (writebuf != NULL) | |
872 | { | |
873 | regval = unpack_long (eltype, writebuf + offset); | |
874 | regcache_cooked_write_unsigned (regcache, regnum, regval); | |
875 | } | |
876 | if (readbuf != NULL) | |
877 | { | |
878 | regcache_cooked_read_unsigned (regcache, regnum, ®val); | |
879 | store_unsigned_integer (readbuf + offset, | |
880 | TYPE_LENGTH (eltype), byte_order, | |
881 | regval); | |
882 | } | |
883 | } | |
884 | } | |
885 | ||
886 | return RETURN_VALUE_REGISTER_CONVENTION; | |
887 | } | |
888 | /* OpenCL vectors >= 16 bytes are returned in v2..v9. */ | |
889 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
890 | && TYPE_VECTOR (type) | |
891 | && TYPE_LENGTH (type) >= 16 | |
892 | && opencl_abi) | |
893 | { | |
894 | int n_regs = TYPE_LENGTH (type) / 16; | |
895 | int i; | |
896 | ||
897 | for (i = 0; i < n_regs; i++) | |
898 | { | |
899 | int offset = i * 16; | |
900 | int regnum = tdep->ppc_vr0_regnum + 2 + i; | |
901 | ||
902 | if (writebuf != NULL) | |
903 | regcache_cooked_write (regcache, regnum, writebuf + offset); | |
904 | if (readbuf != NULL) | |
905 | regcache_cooked_read (regcache, regnum, readbuf + offset); | |
906 | } | |
907 | ||
908 | return RETURN_VALUE_REGISTER_CONVENTION; | |
909 | } | |
e754ae69 AC |
910 | if (TYPE_LENGTH (type) == 16 |
911 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
55eddb0f DJ |
912 | && TYPE_VECTOR (type) |
913 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC) | |
e754ae69 | 914 | { |
963e2bb7 | 915 | if (readbuf) |
e754ae69 AC |
916 | { |
917 | /* Altivec places the return value in "v2". */ | |
963e2bb7 | 918 | regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); |
e754ae69 | 919 | } |
963e2bb7 | 920 | if (writebuf) |
e754ae69 AC |
921 | { |
922 | /* Altivec places the return value in "v2". */ | |
963e2bb7 | 923 | regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); |
e754ae69 AC |
924 | } |
925 | return RETURN_VALUE_REGISTER_CONVENTION; | |
926 | } | |
55eddb0f DJ |
927 | if (TYPE_LENGTH (type) == 16 |
928 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
929 | && TYPE_VECTOR (type) | |
930 | && tdep->vector_abi == POWERPC_VEC_GENERIC) | |
931 | { | |
932 | /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6. | |
933 | GCC without AltiVec returns them in memory, but it warns about | |
934 | ABI risks in that case; we don't try to support it. */ | |
935 | if (readbuf) | |
936 | { | |
937 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, | |
938 | readbuf + 0); | |
939 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
940 | readbuf + 4); | |
941 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5, | |
942 | readbuf + 8); | |
943 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6, | |
944 | readbuf + 12); | |
945 | } | |
946 | if (writebuf) | |
947 | { | |
948 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, | |
949 | writebuf + 0); | |
950 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
951 | writebuf + 4); | |
952 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5, | |
953 | writebuf + 8); | |
954 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6, | |
955 | writebuf + 12); | |
956 | } | |
957 | return RETURN_VALUE_REGISTER_CONVENTION; | |
958 | } | |
e754ae69 AC |
959 | if (TYPE_LENGTH (type) == 8 |
960 | && TYPE_CODE (type) == TYPE_CODE_ARRAY | |
55eddb0f DJ |
961 | && TYPE_VECTOR (type) |
962 | && tdep->vector_abi == POWERPC_VEC_SPE) | |
e754ae69 AC |
963 | { |
964 | /* The e500 ABI places return values for the 64-bit DSP types | |
965 | (__ev64_opaque__) in r3. However, in GDB-speak, ev3 | |
966 | corresponds to the entire r3 value for e500, whereas GDB's r3 | |
967 | only corresponds to the least significant 32-bits. So place | |
968 | the 64-bit DSP type's value in ev3. */ | |
963e2bb7 AC |
969 | if (readbuf) |
970 | regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf); | |
971 | if (writebuf) | |
972 | regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf); | |
e754ae69 AC |
973 | return RETURN_VALUE_REGISTER_CONVENTION; |
974 | } | |
975 | if (broken_gcc && TYPE_LENGTH (type) <= 8) | |
976 | { | |
61bf9ae0 MK |
977 | /* GCC screwed up for structures or unions whose size is less |
978 | than or equal to 8 bytes.. Instead of left-aligning, it | |
979 | right-aligns the data into the buffer formed by r3, r4. */ | |
0f068fb5 | 980 | gdb_byte regvals[PPC_MAX_REGISTER_SIZE * 2]; |
61bf9ae0 MK |
981 | int len = TYPE_LENGTH (type); |
982 | int offset = (2 * tdep->wordsize - len) % tdep->wordsize; | |
983 | ||
963e2bb7 | 984 | if (readbuf) |
e754ae69 | 985 | { |
61bf9ae0 MK |
986 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, |
987 | regvals + 0 * tdep->wordsize); | |
988 | if (len > tdep->wordsize) | |
989 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
990 | regvals + 1 * tdep->wordsize); | |
991 | memcpy (readbuf, regvals + offset, len); | |
e754ae69 | 992 | } |
963e2bb7 | 993 | if (writebuf) |
e754ae69 | 994 | { |
61bf9ae0 MK |
995 | memset (regvals, 0, sizeof regvals); |
996 | memcpy (regvals + offset, writebuf, len); | |
997 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, | |
998 | regvals + 0 * tdep->wordsize); | |
999 | if (len > tdep->wordsize) | |
1000 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
1001 | regvals + 1 * tdep->wordsize); | |
e754ae69 | 1002 | } |
61bf9ae0 | 1003 | |
e754ae69 AC |
1004 | return RETURN_VALUE_REGISTER_CONVENTION; |
1005 | } | |
1006 | if (TYPE_LENGTH (type) <= 8) | |
1007 | { | |
963e2bb7 | 1008 | if (readbuf) |
e754ae69 AC |
1009 | { |
1010 | /* This matches SVr4 PPC, it does not match GCC. */ | |
1011 | /* The value is right-padded to 8 bytes and then loaded, as | |
1012 | two "words", into r3/r4. */ | |
0f068fb5 | 1013 | gdb_byte regvals[PPC_MAX_REGISTER_SIZE * 2]; |
e754ae69 AC |
1014 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, |
1015 | regvals + 0 * tdep->wordsize); | |
1016 | if (TYPE_LENGTH (type) > tdep->wordsize) | |
1017 | regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, | |
1018 | regvals + 1 * tdep->wordsize); | |
963e2bb7 | 1019 | memcpy (readbuf, regvals, TYPE_LENGTH (type)); |
e754ae69 | 1020 | } |
963e2bb7 | 1021 | if (writebuf) |
e754ae69 AC |
1022 | { |
1023 | /* This matches SVr4 PPC, it does not match GCC. */ | |
1024 | /* The value is padded out to 8 bytes and then loaded, as | |
1025 | two "words" into r3/r4. */ | |
0f068fb5 | 1026 | gdb_byte regvals[PPC_MAX_REGISTER_SIZE * 2]; |
e754ae69 | 1027 | memset (regvals, 0, sizeof regvals); |
963e2bb7 | 1028 | memcpy (regvals, writebuf, TYPE_LENGTH (type)); |
e754ae69 AC |
1029 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, |
1030 | regvals + 0 * tdep->wordsize); | |
1031 | if (TYPE_LENGTH (type) > tdep->wordsize) | |
1032 | regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, | |
1033 | regvals + 1 * tdep->wordsize); | |
1034 | } | |
1035 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1036 | } | |
1037 | return RETURN_VALUE_STRUCT_CONVENTION; | |
1038 | } | |
1039 | ||
05580c65 | 1040 | enum return_value_convention |
6a3a010b | 1041 | ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 CV |
1042 | struct type *valtype, struct regcache *regcache, |
1043 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
e754ae69 | 1044 | { |
6a3a010b MR |
1045 | return do_ppc_sysv_return_value (gdbarch, |
1046 | function ? value_type (function) : NULL, | |
1047 | valtype, regcache, readbuf, writebuf, 0); | |
e754ae69 AC |
1048 | } |
1049 | ||
05580c65 | 1050 | enum return_value_convention |
963e2bb7 | 1051 | ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch, |
6a3a010b | 1052 | struct value *function, |
963e2bb7 AC |
1053 | struct type *valtype, |
1054 | struct regcache *regcache, | |
50fd1280 | 1055 | gdb_byte *readbuf, const gdb_byte *writebuf) |
e754ae69 | 1056 | { |
6a3a010b MR |
1057 | return do_ppc_sysv_return_value (gdbarch, |
1058 | function ? value_type (function) : NULL, | |
1059 | valtype, regcache, readbuf, writebuf, 1); | |
944fcfab | 1060 | } |
afd48b75 | 1061 | |
b6e1c027 AC |
1062 | /* The helper function for 64-bit SYSV push_dummy_call. Converts the |
1063 | function's code address back into the function's descriptor | |
1064 | address. | |
1065 | ||
1066 | Find a value for the TOC register. Every symbol should have both | |
1067 | ".FN" and "FN" in the minimal symbol table. "FN" points at the | |
1068 | FN's descriptor, while ".FN" points at the entry point (which | |
1069 | matches FUNC_ADDR). Need to reverse from FUNC_ADDR back to the | |
1070 | FN's descriptor address (while at the same time being careful to | |
1071 | find "FN" in the same object file as ".FN"). */ | |
1072 | ||
1073 | static int | |
1074 | convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr) | |
1075 | { | |
1076 | struct obj_section *dot_fn_section; | |
7cbd4a93 | 1077 | struct bound_minimal_symbol dot_fn; |
3b7344d5 | 1078 | struct bound_minimal_symbol fn; |
7cbd4a93 | 1079 | |
b6e1c027 AC |
1080 | /* Find the minimal symbol that corresponds to CODE_ADDR (should |
1081 | have a name of the form ".FN"). */ | |
1082 | dot_fn = lookup_minimal_symbol_by_pc (code_addr); | |
efd66ac6 | 1083 | if (dot_fn.minsym == NULL || MSYMBOL_LINKAGE_NAME (dot_fn.minsym)[0] != '.') |
b6e1c027 AC |
1084 | return 0; |
1085 | /* Get the section that contains CODE_ADDR. Need this for the | |
1086 | "objfile" that it contains. */ | |
1087 | dot_fn_section = find_pc_section (code_addr); | |
1088 | if (dot_fn_section == NULL || dot_fn_section->objfile == NULL) | |
1089 | return 0; | |
1090 | /* Now find the corresponding "FN" (dropping ".") minimal symbol's | |
1091 | address. Only look for the minimal symbol in ".FN"'s object file | |
1092 | - avoids problems when two object files (i.e., shared libraries) | |
1093 | contain a minimal symbol with the same name. */ | |
efd66ac6 | 1094 | fn = lookup_minimal_symbol (MSYMBOL_LINKAGE_NAME (dot_fn.minsym) + 1, NULL, |
b6e1c027 | 1095 | dot_fn_section->objfile); |
3b7344d5 | 1096 | if (fn.minsym == NULL) |
b6e1c027 AC |
1097 | return 0; |
1098 | /* Found a descriptor. */ | |
77e371c0 | 1099 | (*desc_addr) = BMSYMBOL_VALUE_ADDRESS (fn); |
b6e1c027 AC |
1100 | return 1; |
1101 | } | |
1102 | ||
cc0e89c5 UW |
1103 | /* Walk down the type tree of TYPE counting consecutive base elements. |
1104 | If *FIELD_TYPE is NULL, then set it to the first valid floating point | |
1105 | or vector type. If a non-floating point or vector type is found, or | |
1106 | if a floating point or vector type that doesn't match a non-NULL | |
1107 | *FIELD_TYPE is found, then return -1, otherwise return the count in the | |
1108 | sub-tree. */ | |
1109 | ||
1110 | static LONGEST | |
1111 | ppc64_aggregate_candidate (struct type *type, | |
1112 | struct type **field_type) | |
1113 | { | |
1114 | type = check_typedef (type); | |
1115 | ||
1116 | switch (TYPE_CODE (type)) | |
1117 | { | |
1118 | case TYPE_CODE_FLT: | |
1119 | case TYPE_CODE_DECFLOAT: | |
1120 | if (!*field_type) | |
1121 | *field_type = type; | |
1122 | if (TYPE_CODE (*field_type) == TYPE_CODE (type) | |
1123 | && TYPE_LENGTH (*field_type) == TYPE_LENGTH (type)) | |
1124 | return 1; | |
1125 | break; | |
1126 | ||
1127 | case TYPE_CODE_COMPLEX: | |
1128 | type = TYPE_TARGET_TYPE (type); | |
1129 | if (TYPE_CODE (type) == TYPE_CODE_FLT | |
1130 | || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) | |
1131 | { | |
1132 | if (!*field_type) | |
1133 | *field_type = type; | |
1134 | if (TYPE_CODE (*field_type) == TYPE_CODE (type) | |
1135 | && TYPE_LENGTH (*field_type) == TYPE_LENGTH (type)) | |
1136 | return 2; | |
1137 | } | |
1138 | break; | |
1139 | ||
1140 | case TYPE_CODE_ARRAY: | |
1141 | if (TYPE_VECTOR (type)) | |
1142 | { | |
1143 | if (!*field_type) | |
1144 | *field_type = type; | |
1145 | if (TYPE_CODE (*field_type) == TYPE_CODE (type) | |
1146 | && TYPE_LENGTH (*field_type) == TYPE_LENGTH (type)) | |
1147 | return 1; | |
1148 | } | |
1149 | else | |
1150 | { | |
1151 | LONGEST count, low_bound, high_bound; | |
1152 | ||
1153 | count = ppc64_aggregate_candidate | |
1154 | (TYPE_TARGET_TYPE (type), field_type); | |
1155 | if (count == -1) | |
1156 | return -1; | |
1157 | ||
1158 | if (!get_array_bounds (type, &low_bound, &high_bound)) | |
1159 | return -1; | |
1160 | count *= high_bound - low_bound; | |
1161 | ||
1162 | /* There must be no padding. */ | |
1163 | if (count == 0) | |
1164 | return TYPE_LENGTH (type) == 0 ? 0 : -1; | |
1165 | else if (TYPE_LENGTH (type) != count * TYPE_LENGTH (*field_type)) | |
1166 | return -1; | |
1167 | ||
1168 | return count; | |
1169 | } | |
1170 | break; | |
1171 | ||
1172 | case TYPE_CODE_STRUCT: | |
1173 | case TYPE_CODE_UNION: | |
1174 | { | |
1175 | LONGEST count = 0; | |
1176 | int i; | |
1177 | ||
1178 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
1179 | { | |
1180 | LONGEST sub_count; | |
1181 | ||
1182 | if (field_is_static (&TYPE_FIELD (type, i))) | |
1183 | continue; | |
1184 | ||
1185 | sub_count = ppc64_aggregate_candidate | |
1186 | (TYPE_FIELD_TYPE (type, i), field_type); | |
1187 | if (sub_count == -1) | |
1188 | return -1; | |
1189 | ||
1190 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
1191 | count += sub_count; | |
1192 | else | |
325fac50 | 1193 | count = std::max (count, sub_count); |
cc0e89c5 UW |
1194 | } |
1195 | ||
1196 | /* There must be no padding. */ | |
1197 | if (count == 0) | |
1198 | return TYPE_LENGTH (type) == 0 ? 0 : -1; | |
1199 | else if (TYPE_LENGTH (type) != count * TYPE_LENGTH (*field_type)) | |
1200 | return -1; | |
1201 | ||
1202 | return count; | |
1203 | } | |
1204 | break; | |
1205 | ||
1206 | default: | |
1207 | break; | |
1208 | } | |
1209 | ||
1210 | return -1; | |
1211 | } | |
1212 | ||
1213 | /* If an argument of type TYPE is a homogeneous float or vector aggregate | |
1214 | that shall be passed in FP/vector registers according to the ELFv2 ABI, | |
1215 | return the homogeneous element type in *ELT_TYPE and the number of | |
1216 | elements in *N_ELTS, and return non-zero. Otherwise, return zero. */ | |
1217 | ||
1218 | static int | |
1219 | ppc64_elfv2_abi_homogeneous_aggregate (struct type *type, | |
1220 | struct type **elt_type, int *n_elts) | |
1221 | { | |
1222 | /* Complex types at the top level are treated separately. However, | |
1223 | complex types can be elements of homogeneous aggregates. */ | |
1224 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1225 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
1226 | || (TYPE_CODE (type) == TYPE_CODE_ARRAY && !TYPE_VECTOR (type))) | |
1227 | { | |
1228 | struct type *field_type = NULL; | |
1229 | LONGEST field_count = ppc64_aggregate_candidate (type, &field_type); | |
1230 | ||
1231 | if (field_count > 0) | |
1232 | { | |
1233 | int n_regs = ((TYPE_CODE (field_type) == TYPE_CODE_FLT | |
1234 | || TYPE_CODE (field_type) == TYPE_CODE_DECFLOAT)? | |
1235 | (TYPE_LENGTH (field_type) + 7) >> 3 : 1); | |
1236 | ||
1237 | /* The ELFv2 ABI allows homogeneous aggregates to occupy | |
1238 | up to 8 registers. */ | |
1239 | if (field_count * n_regs <= 8) | |
1240 | { | |
1241 | if (elt_type) | |
1242 | *elt_type = field_type; | |
1243 | if (n_elts) | |
1244 | *n_elts = (int) field_count; | |
1245 | /* Note that field_count is LONGEST since it may hold the size | |
1246 | of an array, while *n_elts is int since its value is bounded | |
1247 | by the number of registers used for argument passing. The | |
1248 | cast cannot overflow due to the bounds checking above. */ | |
1249 | return 1; | |
1250 | } | |
1251 | } | |
1252 | } | |
1253 | ||
1254 | return 0; | |
1255 | } | |
1256 | ||
e765b44c UW |
1257 | /* Structure holding the next argument position. */ |
1258 | struct ppc64_sysv_argpos | |
1259 | { | |
1260 | /* Register cache holding argument registers. If this is NULL, | |
1261 | we only simulate argument processing without actually updating | |
1262 | any registers or memory. */ | |
1263 | struct regcache *regcache; | |
1264 | /* Next available general-purpose argument register. */ | |
1265 | int greg; | |
1266 | /* Next available floating-point argument register. */ | |
1267 | int freg; | |
1268 | /* Next available vector argument register. */ | |
1269 | int vreg; | |
1270 | /* The address, at which the next general purpose parameter | |
1271 | (integer, struct, float, vector, ...) should be saved. */ | |
1272 | CORE_ADDR gparam; | |
1273 | /* The address, at which the next by-reference parameter | |
1274 | (non-Altivec vector, variably-sized type) should be saved. */ | |
1275 | CORE_ADDR refparam; | |
1276 | }; | |
1277 | ||
1278 | /* VAL is a value of length LEN. Store it into the argument area on the | |
1279 | stack and load it into the corresponding general-purpose registers | |
1280 | required by the ABI, and update ARGPOS. | |
1281 | ||
1282 | If ALIGN is nonzero, it specifies the minimum alignment required | |
1283 | for the on-stack copy of the argument. */ | |
d81e75c0 | 1284 | |
e765b44c UW |
1285 | static void |
1286 | ppc64_sysv_abi_push_val (struct gdbarch *gdbarch, | |
1287 | const bfd_byte *val, int len, int align, | |
1288 | struct ppc64_sysv_argpos *argpos) | |
1289 | { | |
1290 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1291 | int offset = 0; | |
1292 | ||
1293 | /* Enforce alignment of stack location, if requested. */ | |
1294 | if (align > tdep->wordsize) | |
1295 | { | |
1296 | CORE_ADDR aligned_gparam = align_up (argpos->gparam, align); | |
1297 | ||
1298 | argpos->greg += (aligned_gparam - argpos->gparam) / tdep->wordsize; | |
1299 | argpos->gparam = aligned_gparam; | |
1300 | } | |
1301 | ||
1302 | /* The ABI (version 1.9) specifies that values smaller than one | |
1303 | doubleword are right-aligned and those larger are left-aligned. | |
1304 | GCC versions before 3.4 implemented this incorrectly; see | |
1305 | <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */ | |
d63167af UW |
1306 | if (len < tdep->wordsize |
1307 | && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) | |
e765b44c UW |
1308 | offset = tdep->wordsize - len; |
1309 | ||
1310 | if (argpos->regcache) | |
1311 | write_memory (argpos->gparam + offset, val, len); | |
1312 | argpos->gparam = align_up (argpos->gparam + len, tdep->wordsize); | |
1313 | ||
1314 | while (len >= tdep->wordsize) | |
1315 | { | |
1316 | if (argpos->regcache && argpos->greg <= 10) | |
1317 | regcache_cooked_write (argpos->regcache, | |
1318 | tdep->ppc_gp0_regnum + argpos->greg, val); | |
1319 | argpos->greg++; | |
1320 | len -= tdep->wordsize; | |
1321 | val += tdep->wordsize; | |
1322 | } | |
1323 | ||
1324 | if (len > 0) | |
1325 | { | |
1326 | if (argpos->regcache && argpos->greg <= 10) | |
1327 | regcache_cooked_write_part (argpos->regcache, | |
1328 | tdep->ppc_gp0_regnum + argpos->greg, | |
1329 | offset, len, val); | |
1330 | argpos->greg++; | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | /* The same as ppc64_sysv_abi_push_val, but using a single-word integer | |
1335 | value VAL as argument. */ | |
d81e75c0 TD |
1336 | |
1337 | static void | |
e765b44c UW |
1338 | ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val, |
1339 | struct ppc64_sysv_argpos *argpos) | |
d81e75c0 | 1340 | { |
e765b44c UW |
1341 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1342 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
0f068fb5 | 1343 | gdb_byte buf[PPC_MAX_REGISTER_SIZE]; |
d81e75c0 | 1344 | |
e765b44c UW |
1345 | if (argpos->regcache) |
1346 | store_unsigned_integer (buf, tdep->wordsize, byte_order, val); | |
1347 | ppc64_sysv_abi_push_val (gdbarch, buf, tdep->wordsize, 0, argpos); | |
1348 | } | |
1349 | ||
1350 | /* VAL is a value of TYPE, a (binary or decimal) floating-point type. | |
1351 | Load it into a floating-point register if required by the ABI, | |
1352 | and update ARGPOS. */ | |
1353 | ||
1354 | static void | |
1355 | ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch, | |
1356 | struct type *type, const bfd_byte *val, | |
1357 | struct ppc64_sysv_argpos *argpos) | |
1358 | { | |
1359 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1360 | if (tdep->soft_float) | |
1361 | return; | |
1362 | ||
1363 | if (TYPE_LENGTH (type) <= 8 | |
1364 | && TYPE_CODE (type) == TYPE_CODE_FLT) | |
d81e75c0 | 1365 | { |
e765b44c UW |
1366 | /* Floats and doubles go in f1 .. f13. 32-bit floats are converted |
1367 | to double first. */ | |
1368 | if (argpos->regcache && argpos->freg <= 13) | |
1369 | { | |
1370 | int regnum = tdep->ppc_fp0_regnum + argpos->freg; | |
1371 | struct type *regtype = register_type (gdbarch, regnum); | |
0f068fb5 | 1372 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
d81e75c0 | 1373 | |
e765b44c UW |
1374 | convert_typed_floating (val, type, regval, regtype); |
1375 | regcache_cooked_write (argpos->regcache, regnum, regval); | |
1376 | } | |
d81e75c0 | 1377 | |
e765b44c UW |
1378 | argpos->freg++; |
1379 | } | |
1380 | else if (TYPE_LENGTH (type) <= 8 | |
1381 | && TYPE_CODE (type) == TYPE_CODE_DECFLOAT) | |
1382 | { | |
1383 | /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are | |
1384 | placed in the least significant word. */ | |
1385 | if (argpos->regcache && argpos->freg <= 13) | |
1386 | { | |
1387 | int regnum = tdep->ppc_fp0_regnum + argpos->freg; | |
5b757e5d UW |
1388 | int offset = 0; |
1389 | ||
1390 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) | |
1391 | offset = 8 - TYPE_LENGTH (type); | |
d81e75c0 | 1392 | |
e765b44c UW |
1393 | regcache_cooked_write_part (argpos->regcache, regnum, |
1394 | offset, TYPE_LENGTH (type), val); | |
1395 | } | |
d81e75c0 | 1396 | |
e765b44c UW |
1397 | argpos->freg++; |
1398 | } | |
1399 | else if (TYPE_LENGTH (type) == 16 | |
1400 | && TYPE_CODE (type) == TYPE_CODE_FLT | |
1401 | && (gdbarch_long_double_format (gdbarch) | |
1402 | == floatformats_ibm_long_double)) | |
1403 | { | |
1404 | /* IBM long double stored in two consecutive FPRs. */ | |
1405 | if (argpos->regcache && argpos->freg <= 13) | |
d81e75c0 | 1406 | { |
e765b44c UW |
1407 | int regnum = tdep->ppc_fp0_regnum + argpos->freg; |
1408 | ||
1409 | regcache_cooked_write (argpos->regcache, regnum, val); | |
1410 | if (argpos->freg <= 12) | |
1411 | regcache_cooked_write (argpos->regcache, regnum + 1, val + 8); | |
d81e75c0 | 1412 | } |
d81e75c0 | 1413 | |
e765b44c UW |
1414 | argpos->freg += 2; |
1415 | } | |
1416 | else if (TYPE_LENGTH (type) == 16 | |
1417 | && TYPE_CODE (type) == TYPE_CODE_DECFLOAT) | |
1418 | { | |
1419 | /* 128-bit decimal floating-point values are stored in and even/odd | |
1420 | pair of FPRs, with the even FPR holding the most significant half. */ | |
1421 | argpos->freg += argpos->freg & 1; | |
d81e75c0 | 1422 | |
e765b44c | 1423 | if (argpos->regcache && argpos->freg <= 12) |
d81e75c0 | 1424 | { |
e765b44c | 1425 | int regnum = tdep->ppc_fp0_regnum + argpos->freg; |
0ff3e01f UW |
1426 | int lopart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 : 0; |
1427 | int hipart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8; | |
d81e75c0 | 1428 | |
0ff3e01f UW |
1429 | regcache_cooked_write (argpos->regcache, regnum, val + hipart); |
1430 | regcache_cooked_write (argpos->regcache, regnum + 1, val + lopart); | |
d81e75c0 | 1431 | } |
e765b44c UW |
1432 | |
1433 | argpos->freg += 2; | |
d81e75c0 | 1434 | } |
e765b44c UW |
1435 | } |
1436 | ||
1437 | /* VAL is a value of AltiVec vector type. Load it into a vector register | |
1438 | if required by the ABI, and update ARGPOS. */ | |
1439 | ||
1440 | static void | |
1441 | ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val, | |
1442 | struct ppc64_sysv_argpos *argpos) | |
1443 | { | |
1444 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1445 | ||
1446 | if (argpos->regcache && argpos->vreg <= 13) | |
1447 | regcache_cooked_write (argpos->regcache, | |
1448 | tdep->ppc_vr0_regnum + argpos->vreg, val); | |
1449 | ||
1450 | argpos->vreg++; | |
1451 | } | |
1452 | ||
1453 | /* VAL is a value of TYPE. Load it into memory and/or registers | |
1454 | as required by the ABI, and update ARGPOS. */ | |
1455 | ||
1456 | static void | |
1457 | ppc64_sysv_abi_push_param (struct gdbarch *gdbarch, | |
1458 | struct type *type, const bfd_byte *val, | |
1459 | struct ppc64_sysv_argpos *argpos) | |
1460 | { | |
1461 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1462 | ||
1463 | if (TYPE_CODE (type) == TYPE_CODE_FLT | |
1464 | || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) | |
1465 | { | |
1466 | /* Floating-point scalars are passed in floating-point registers. */ | |
1467 | ppc64_sysv_abi_push_val (gdbarch, val, TYPE_LENGTH (type), 0, argpos); | |
1468 | ppc64_sysv_abi_push_freg (gdbarch, type, val, argpos); | |
1469 | } | |
1470 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) | |
1471 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC | |
1472 | && TYPE_LENGTH (type) == 16) | |
1473 | { | |
1474 | /* AltiVec vectors are passed aligned, and in vector registers. */ | |
1475 | ppc64_sysv_abi_push_val (gdbarch, val, TYPE_LENGTH (type), 16, argpos); | |
1476 | ppc64_sysv_abi_push_vreg (gdbarch, val, argpos); | |
1477 | } | |
1478 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) | |
1479 | && TYPE_LENGTH (type) >= 16) | |
d81e75c0 | 1480 | { |
e765b44c UW |
1481 | /* Non-Altivec vectors are passed by reference. */ |
1482 | ||
1483 | /* Copy value onto the stack ... */ | |
1484 | CORE_ADDR addr = align_up (argpos->refparam, 16); | |
1485 | if (argpos->regcache) | |
1486 | write_memory (addr, val, TYPE_LENGTH (type)); | |
1487 | argpos->refparam = align_up (addr + TYPE_LENGTH (type), tdep->wordsize); | |
1488 | ||
1489 | /* ... and pass a pointer to the copy as parameter. */ | |
1490 | ppc64_sysv_abi_push_integer (gdbarch, addr, argpos); | |
1491 | } | |
1492 | else if ((TYPE_CODE (type) == TYPE_CODE_INT | |
1493 | || TYPE_CODE (type) == TYPE_CODE_ENUM | |
1494 | || TYPE_CODE (type) == TYPE_CODE_BOOL | |
1495 | || TYPE_CODE (type) == TYPE_CODE_CHAR | |
1496 | || TYPE_CODE (type) == TYPE_CODE_PTR | |
aa006118 | 1497 | || TYPE_IS_REFERENCE (type)) |
e765b44c UW |
1498 | && TYPE_LENGTH (type) <= tdep->wordsize) |
1499 | { | |
1500 | ULONGEST word = 0; | |
1501 | ||
1502 | if (argpos->regcache) | |
d81e75c0 | 1503 | { |
e765b44c UW |
1504 | /* Sign extend the value, then store it unsigned. */ |
1505 | word = unpack_long (type, val); | |
1506 | ||
1507 | /* Convert any function code addresses into descriptors. */ | |
d4094b6a UW |
1508 | if (tdep->elf_abi == POWERPC_ELF_V1 |
1509 | && (TYPE_CODE (type) == TYPE_CODE_PTR | |
1510 | || TYPE_CODE (type) == TYPE_CODE_REF)) | |
e765b44c UW |
1511 | { |
1512 | struct type *target_type | |
1513 | = check_typedef (TYPE_TARGET_TYPE (type)); | |
1514 | ||
1515 | if (TYPE_CODE (target_type) == TYPE_CODE_FUNC | |
1516 | || TYPE_CODE (target_type) == TYPE_CODE_METHOD) | |
1517 | { | |
1518 | CORE_ADDR desc = word; | |
1519 | ||
1520 | convert_code_addr_to_desc_addr (word, &desc); | |
1521 | word = desc; | |
1522 | } | |
1523 | } | |
d81e75c0 | 1524 | } |
e765b44c UW |
1525 | |
1526 | ppc64_sysv_abi_push_integer (gdbarch, word, argpos); | |
1527 | } | |
1528 | else | |
1529 | { | |
1530 | ppc64_sysv_abi_push_val (gdbarch, val, TYPE_LENGTH (type), 0, argpos); | |
1531 | ||
1532 | /* The ABI (version 1.9) specifies that structs containing a | |
1533 | single floating-point value, at any level of nesting of | |
1534 | single-member structs, are passed in floating-point registers. */ | |
1535 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1536 | && TYPE_NFIELDS (type) == 1) | |
d81e75c0 | 1537 | { |
e765b44c UW |
1538 | while (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1539 | && TYPE_NFIELDS (type) == 1) | |
1540 | type = check_typedef (TYPE_FIELD_TYPE (type, 0)); | |
1541 | ||
1542 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
1543 | ppc64_sysv_abi_push_freg (gdbarch, type, val, argpos); | |
d81e75c0 | 1544 | } |
cc0e89c5 UW |
1545 | |
1546 | /* In the ELFv2 ABI, homogeneous floating-point or vector | |
1547 | aggregates are passed in a series of registers. */ | |
1548 | if (tdep->elf_abi == POWERPC_ELF_V2) | |
1549 | { | |
1550 | struct type *eltype; | |
1551 | int i, nelt; | |
1552 | ||
1553 | if (ppc64_elfv2_abi_homogeneous_aggregate (type, &eltype, &nelt)) | |
1554 | for (i = 0; i < nelt; i++) | |
1555 | { | |
1556 | const gdb_byte *elval = val + i * TYPE_LENGTH (eltype); | |
1557 | ||
1558 | if (TYPE_CODE (eltype) == TYPE_CODE_FLT | |
1559 | || TYPE_CODE (eltype) == TYPE_CODE_DECFLOAT) | |
1560 | ppc64_sysv_abi_push_freg (gdbarch, eltype, elval, argpos); | |
1561 | else if (TYPE_CODE (eltype) == TYPE_CODE_ARRAY | |
1562 | && TYPE_VECTOR (eltype) | |
1563 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC | |
1564 | && TYPE_LENGTH (eltype) == 16) | |
1565 | ppc64_sysv_abi_push_vreg (gdbarch, elval, argpos); | |
1566 | } | |
1567 | } | |
d81e75c0 TD |
1568 | } |
1569 | } | |
1570 | ||
0df8b418 | 1571 | /* Pass the arguments in either registers, or in the stack. Using the |
8be9034a AC |
1572 | ppc 64 bit SysV ABI. |
1573 | ||
1574 | This implements a dumbed down version of the ABI. It always writes | |
1575 | values to memory, GPR and FPR, even when not necessary. Doing this | |
0df8b418 | 1576 | greatly simplifies the logic. */ |
8be9034a AC |
1577 | |
1578 | CORE_ADDR | |
0df8b418 MS |
1579 | ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, |
1580 | struct value *function, | |
8be9034a AC |
1581 | struct regcache *regcache, CORE_ADDR bp_addr, |
1582 | int nargs, struct value **args, CORE_ADDR sp, | |
1583 | int struct_return, CORE_ADDR struct_addr) | |
1584 | { | |
7d9b040b | 1585 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
40a6adc1 | 1586 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 1587 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
88aed45e | 1588 | int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function)); |
fb4443d8 | 1589 | ULONGEST back_chain; |
8be9034a AC |
1590 | /* See for-loop comment below. */ |
1591 | int write_pass; | |
24e9cda0 UW |
1592 | /* Size of the by-reference parameter copy region, the final value is |
1593 | computed in the for-loop below. */ | |
1594 | LONGEST refparam_size = 0; | |
8be9034a AC |
1595 | /* Size of the general parameter region, the final value is computed |
1596 | in the for-loop below. */ | |
1597 | LONGEST gparam_size = 0; | |
1598 | /* Kevin writes ... I don't mind seeing tdep->wordsize used in the | |
0df8b418 | 1599 | calls to align_up(), align_down(), etc. because this makes it |
8be9034a AC |
1600 | easier to reuse this code (in a copy/paste sense) in the future, |
1601 | but it is a 64-bit ABI and asserting that the wordsize is 8 bytes | |
1602 | at some point makes it easier to verify that this function is | |
1603 | correct without having to do a non-local analysis to figure out | |
1604 | the possible values of tdep->wordsize. */ | |
1605 | gdb_assert (tdep->wordsize == 8); | |
1606 | ||
55eddb0f DJ |
1607 | /* This function exists to support a calling convention that |
1608 | requires floating-point registers. It shouldn't be used on | |
1609 | processors that lack them. */ | |
1610 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
1611 | ||
fb4443d8 UW |
1612 | /* By this stage in the proceedings, SP has been decremented by "red |
1613 | zone size" + "struct return size". Fetch the stack-pointer from | |
1614 | before this and use that as the BACK_CHAIN. */ | |
40a6adc1 | 1615 | regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), |
3e8c568d | 1616 | &back_chain); |
fb4443d8 | 1617 | |
8be9034a AC |
1618 | /* Go through the argument list twice. |
1619 | ||
1620 | Pass 1: Compute the function call's stack space and register | |
1621 | requirements. | |
1622 | ||
1623 | Pass 2: Replay the same computation but this time also write the | |
1624 | values out to the target. */ | |
1625 | ||
1626 | for (write_pass = 0; write_pass < 2; write_pass++) | |
1627 | { | |
1628 | int argno; | |
e765b44c UW |
1629 | |
1630 | struct ppc64_sysv_argpos argpos; | |
1631 | argpos.greg = 3; | |
1632 | argpos.freg = 1; | |
1633 | argpos.vreg = 2; | |
8be9034a AC |
1634 | |
1635 | if (!write_pass) | |
1636 | { | |
24e9cda0 UW |
1637 | /* During the first pass, GPARAM and REFPARAM are more like |
1638 | offsets (start address zero) than addresses. That way | |
1639 | they accumulate the total stack space each region | |
1640 | requires. */ | |
e765b44c UW |
1641 | argpos.regcache = NULL; |
1642 | argpos.gparam = 0; | |
1643 | argpos.refparam = 0; | |
8be9034a AC |
1644 | } |
1645 | else | |
1646 | { | |
24e9cda0 UW |
1647 | /* Decrement the stack pointer making space for the Altivec |
1648 | and general on-stack parameters. Set refparam and gparam | |
1649 | to their corresponding regions. */ | |
e765b44c UW |
1650 | argpos.regcache = regcache; |
1651 | argpos.refparam = align_down (sp - refparam_size, 16); | |
1652 | argpos.gparam = align_down (argpos.refparam - gparam_size, 16); | |
52f548e4 UW |
1653 | /* Add in space for the TOC, link editor double word (v1 only), |
1654 | compiler double word (v1 only), LR save area, CR save area, | |
1655 | and backchain. */ | |
1656 | if (tdep->elf_abi == POWERPC_ELF_V1) | |
1657 | sp = align_down (argpos.gparam - 48, 16); | |
1658 | else | |
1659 | sp = align_down (argpos.gparam - 32, 16); | |
8be9034a AC |
1660 | } |
1661 | ||
1662 | /* If the function is returning a `struct', then there is an | |
1663 | extra hidden parameter (which will be passed in r3) | |
1664 | containing the address of that struct.. In that case we | |
1665 | should advance one word and start from r4 register to copy | |
1666 | parameters. This also consumes one on-stack parameter slot. */ | |
1667 | if (struct_return) | |
e765b44c | 1668 | ppc64_sysv_abi_push_integer (gdbarch, struct_addr, &argpos); |
8be9034a AC |
1669 | |
1670 | for (argno = 0; argno < nargs; argno++) | |
1671 | { | |
1672 | struct value *arg = args[argno]; | |
df407dfe | 1673 | struct type *type = check_typedef (value_type (arg)); |
0fd88904 | 1674 | const bfd_byte *val = value_contents (arg); |
ce0451ad | 1675 | |
e765b44c | 1676 | if (TYPE_CODE (type) == TYPE_CODE_COMPLEX) |
8be9034a | 1677 | { |
e765b44c UW |
1678 | /* Complex types are passed as if two independent scalars. */ |
1679 | struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type)); | |
1300a2f4 | 1680 | |
e765b44c UW |
1681 | ppc64_sysv_abi_push_param (gdbarch, eltype, val, &argpos); |
1682 | ppc64_sysv_abi_push_param (gdbarch, eltype, | |
1683 | val + TYPE_LENGTH (eltype), &argpos); | |
1300a2f4 | 1684 | } |
e765b44c | 1685 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) |
54fcddd0 UW |
1686 | && opencl_abi) |
1687 | { | |
1688 | /* OpenCL vectors shorter than 16 bytes are passed as if | |
e765b44c UW |
1689 | a series of independent scalars; OpenCL vectors 16 bytes |
1690 | or longer are passed as if a series of AltiVec vectors. */ | |
1691 | struct type *eltype; | |
1692 | int i, nelt; | |
54fcddd0 | 1693 | |
e765b44c UW |
1694 | if (TYPE_LENGTH (type) < 16) |
1695 | eltype = check_typedef (TYPE_TARGET_TYPE (type)); | |
1696 | else | |
1697 | eltype = register_type (gdbarch, tdep->ppc_vr0_regnum); | |
1698 | ||
1699 | nelt = TYPE_LENGTH (type) / TYPE_LENGTH (eltype); | |
54fcddd0 UW |
1700 | for (i = 0; i < nelt; i++) |
1701 | { | |
1702 | const gdb_byte *elval = val + i * TYPE_LENGTH (eltype); | |
1703 | ||
e765b44c | 1704 | ppc64_sysv_abi_push_param (gdbarch, eltype, elval, &argpos); |
8be9034a | 1705 | } |
8be9034a AC |
1706 | } |
1707 | else | |
1708 | { | |
e765b44c UW |
1709 | /* All other types are passed as single arguments. */ |
1710 | ppc64_sysv_abi_push_param (gdbarch, type, val, &argpos); | |
8be9034a AC |
1711 | } |
1712 | } | |
1713 | ||
1714 | if (!write_pass) | |
1715 | { | |
24e9cda0 | 1716 | /* Save the true region sizes ready for the second pass. */ |
e765b44c | 1717 | refparam_size = argpos.refparam; |
24e9cda0 | 1718 | /* Make certain that the general parameter save area is at |
8be9034a | 1719 | least the minimum 8 registers (or doublewords) in size. */ |
e765b44c | 1720 | if (argpos.greg < 8) |
8be9034a AC |
1721 | gparam_size = 8 * tdep->wordsize; |
1722 | else | |
e765b44c | 1723 | gparam_size = argpos.gparam; |
8be9034a AC |
1724 | } |
1725 | } | |
1726 | ||
1727 | /* Update %sp. */ | |
40a6adc1 | 1728 | regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); |
8be9034a AC |
1729 | |
1730 | /* Write the backchain (it occupies WORDSIZED bytes). */ | |
e17a4113 | 1731 | write_memory_signed_integer (sp, tdep->wordsize, byte_order, back_chain); |
8be9034a AC |
1732 | |
1733 | /* Point the inferior function call's return address at the dummy's | |
1734 | breakpoint. */ | |
1735 | regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); | |
1736 | ||
d4094b6a UW |
1737 | /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use |
1738 | that to find the TOC. If we're calling via a function pointer, | |
1739 | the pointer itself identifies the descriptor. */ | |
1740 | if (tdep->elf_abi == POWERPC_ELF_V1) | |
1741 | { | |
1742 | struct type *ftype = check_typedef (value_type (function)); | |
1743 | CORE_ADDR desc_addr = value_as_address (function); | |
1744 | ||
1745 | if (TYPE_CODE (ftype) == TYPE_CODE_PTR | |
1746 | || convert_code_addr_to_desc_addr (func_addr, &desc_addr)) | |
1747 | { | |
1748 | /* The TOC is the second double word in the descriptor. */ | |
1749 | CORE_ADDR toc = | |
1750 | read_memory_unsigned_integer (desc_addr + tdep->wordsize, | |
1751 | tdep->wordsize, byte_order); | |
1752 | ||
1753 | regcache_cooked_write_unsigned (regcache, | |
1754 | tdep->ppc_gp0_regnum + 2, toc); | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | /* In the ELFv2 ABI, we need to pass the target address in r12 since | |
1759 | we may be calling a global entry point. */ | |
1760 | if (tdep->elf_abi == POWERPC_ELF_V2) | |
1761 | regcache_cooked_write_unsigned (regcache, | |
1762 | tdep->ppc_gp0_regnum + 12, func_addr); | |
8be9034a AC |
1763 | |
1764 | return sp; | |
1765 | } | |
1766 | ||
e765b44c UW |
1767 | /* Subroutine of ppc64_sysv_abi_return_value that handles "base" types: |
1768 | integer, floating-point, and AltiVec vector types. | |
afd48b75 | 1769 | |
e765b44c UW |
1770 | This routine also handles components of aggregate return types; |
1771 | INDEX describes which part of the aggregate is to be handled. | |
afd48b75 | 1772 | |
e765b44c UW |
1773 | Returns true if VALTYPE is some such base type that could be handled, |
1774 | false otherwise. */ | |
1775 | static int | |
1776 | ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype, | |
1777 | struct regcache *regcache, gdb_byte *readbuf, | |
1778 | const gdb_byte *writebuf, int index) | |
afd48b75 | 1779 | { |
05580c65 | 1780 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
16796152 | 1781 | |
e765b44c | 1782 | /* Integers live in GPRs starting at r3. */ |
b6e1c027 | 1783 | if ((TYPE_CODE (valtype) == TYPE_CODE_INT |
93d4208d UW |
1784 | || TYPE_CODE (valtype) == TYPE_CODE_ENUM |
1785 | || TYPE_CODE (valtype) == TYPE_CODE_CHAR | |
1786 | || TYPE_CODE (valtype) == TYPE_CODE_BOOL) | |
b6e1c027 | 1787 | && TYPE_LENGTH (valtype) <= 8) |
afd48b75 | 1788 | { |
e765b44c UW |
1789 | int regnum = tdep->ppc_gp0_regnum + 3 + index; |
1790 | ||
963e2bb7 | 1791 | if (writebuf != NULL) |
afd48b75 AC |
1792 | { |
1793 | /* Be careful to sign extend the value. */ | |
e765b44c | 1794 | regcache_cooked_write_unsigned (regcache, regnum, |
963e2bb7 | 1795 | unpack_long (valtype, writebuf)); |
afd48b75 | 1796 | } |
963e2bb7 | 1797 | if (readbuf != NULL) |
afd48b75 | 1798 | { |
e765b44c | 1799 | /* Extract the integer from GPR. Since this is truncating the |
afd48b75 AC |
1800 | value, there isn't a sign extension problem. */ |
1801 | ULONGEST regval; | |
e765b44c UW |
1802 | |
1803 | regcache_cooked_read_unsigned (regcache, regnum, ®val); | |
1804 | store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), | |
1805 | gdbarch_byte_order (gdbarch), regval); | |
afd48b75 | 1806 | } |
e765b44c | 1807 | return 1; |
afd48b75 | 1808 | } |
e765b44c UW |
1809 | |
1810 | /* Floats and doubles go in f1 .. f13. 32-bit floats are converted | |
1811 | to double first. */ | |
1812 | if (TYPE_LENGTH (valtype) <= 8 | |
1813 | && TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
afd48b75 | 1814 | { |
e765b44c UW |
1815 | int regnum = tdep->ppc_fp0_regnum + 1 + index; |
1816 | struct type *regtype = register_type (gdbarch, regnum); | |
0f068fb5 | 1817 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
e765b44c | 1818 | |
963e2bb7 | 1819 | if (writebuf != NULL) |
e765b44c UW |
1820 | { |
1821 | convert_typed_floating (writebuf, valtype, regval, regtype); | |
1822 | regcache_cooked_write (regcache, regnum, regval); | |
1823 | } | |
963e2bb7 | 1824 | if (readbuf != NULL) |
e765b44c UW |
1825 | { |
1826 | regcache_cooked_read (regcache, regnum, regval); | |
1827 | convert_typed_floating (regval, regtype, readbuf, valtype); | |
1828 | } | |
1829 | return 1; | |
afd48b75 | 1830 | } |
54fcddd0 | 1831 | |
e765b44c UW |
1832 | /* Floats and doubles go in f1 .. f13. 32-bit decimal floats are |
1833 | placed in the least significant word. */ | |
1834 | if (TYPE_LENGTH (valtype) <= 8 | |
1835 | && TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT) | |
1836 | { | |
1837 | int regnum = tdep->ppc_fp0_regnum + 1 + index; | |
5b757e5d UW |
1838 | int offset = 0; |
1839 | ||
1840 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) | |
1841 | offset = 8 - TYPE_LENGTH (valtype); | |
54fcddd0 | 1842 | |
e765b44c UW |
1843 | if (writebuf != NULL) |
1844 | regcache_cooked_write_part (regcache, regnum, | |
1845 | offset, TYPE_LENGTH (valtype), writebuf); | |
1846 | if (readbuf != NULL) | |
1847 | regcache_cooked_read_part (regcache, regnum, | |
1848 | offset, TYPE_LENGTH (valtype), readbuf); | |
1849 | return 1; | |
1850 | } | |
54fcddd0 | 1851 | |
e765b44c UW |
1852 | /* IBM long double stored in two consecutive FPRs. */ |
1853 | if (TYPE_LENGTH (valtype) == 16 | |
1854 | && TYPE_CODE (valtype) == TYPE_CODE_FLT | |
1855 | && (gdbarch_long_double_format (gdbarch) | |
1856 | == floatformats_ibm_long_double)) | |
1857 | { | |
1858 | int regnum = tdep->ppc_fp0_regnum + 1 + 2 * index; | |
54fcddd0 | 1859 | |
e765b44c UW |
1860 | if (writebuf != NULL) |
1861 | { | |
1862 | regcache_cooked_write (regcache, regnum, writebuf); | |
1863 | regcache_cooked_write (regcache, regnum + 1, writebuf + 8); | |
54fcddd0 | 1864 | } |
e765b44c UW |
1865 | if (readbuf != NULL) |
1866 | { | |
1867 | regcache_cooked_read (regcache, regnum, readbuf); | |
1868 | regcache_cooked_read (regcache, regnum + 1, readbuf + 8); | |
1869 | } | |
1870 | return 1; | |
54fcddd0 | 1871 | } |
e765b44c UW |
1872 | |
1873 | /* 128-bit decimal floating-point values are stored in an even/odd | |
1874 | pair of FPRs, with the even FPR holding the most significant half. */ | |
1875 | if (TYPE_LENGTH (valtype) == 16 | |
1876 | && TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT) | |
54fcddd0 | 1877 | { |
e765b44c | 1878 | int regnum = tdep->ppc_fp0_regnum + 2 + 2 * index; |
0ff3e01f UW |
1879 | int lopart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 : 0; |
1880 | int hipart = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8; | |
54fcddd0 | 1881 | |
e765b44c | 1882 | if (writebuf != NULL) |
54fcddd0 | 1883 | { |
0ff3e01f UW |
1884 | regcache_cooked_write (regcache, regnum, writebuf + hipart); |
1885 | regcache_cooked_write (regcache, regnum + 1, writebuf + lopart); | |
54fcddd0 | 1886 | } |
e765b44c UW |
1887 | if (readbuf != NULL) |
1888 | { | |
0ff3e01f UW |
1889 | regcache_cooked_read (regcache, regnum, readbuf + hipart); |
1890 | regcache_cooked_read (regcache, regnum + 1, readbuf + lopart); | |
e765b44c UW |
1891 | } |
1892 | return 1; | |
54fcddd0 | 1893 | } |
e765b44c UW |
1894 | |
1895 | /* AltiVec vectors are returned in VRs starting at v2. */ | |
a1da2672 UW |
1896 | if (TYPE_LENGTH (valtype) == 16 |
1897 | && TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype) | |
e765b44c | 1898 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC) |
afd48b75 | 1899 | { |
e765b44c UW |
1900 | int regnum = tdep->ppc_vr0_regnum + 2 + index; |
1901 | ||
1902 | if (writebuf != NULL) | |
1903 | regcache_cooked_write (regcache, regnum, writebuf); | |
1904 | if (readbuf != NULL) | |
1905 | regcache_cooked_read (regcache, regnum, readbuf); | |
1906 | return 1; | |
afd48b75 | 1907 | } |
e765b44c | 1908 | |
a1da2672 UW |
1909 | /* Short vectors are returned in GPRs starting at r3. */ |
1910 | if (TYPE_LENGTH (valtype) <= 8 | |
1911 | && TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype)) | |
1912 | { | |
1913 | int regnum = tdep->ppc_gp0_regnum + 3 + index; | |
1914 | int offset = 0; | |
1915 | ||
1916 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) | |
1917 | offset = 8 - TYPE_LENGTH (valtype); | |
1918 | ||
1919 | if (writebuf != NULL) | |
1920 | regcache_cooked_write_part (regcache, regnum, | |
1921 | offset, TYPE_LENGTH (valtype), writebuf); | |
1922 | if (readbuf != NULL) | |
1923 | regcache_cooked_read_part (regcache, regnum, | |
1924 | offset, TYPE_LENGTH (valtype), readbuf); | |
1925 | return 1; | |
1926 | } | |
1927 | ||
e765b44c UW |
1928 | return 0; |
1929 | } | |
1930 | ||
1931 | /* The 64 bit ABI return value convention. | |
1932 | ||
1933 | Return non-zero if the return-value is stored in a register, return | |
1934 | 0 if the return-value is instead stored on the stack (a.k.a., | |
1935 | struct return convention). | |
1936 | ||
1937 | For a return-value stored in a register: when WRITEBUF is non-NULL, | |
1938 | copy the buffer to the corresponding register return-value location | |
1939 | location; when READBUF is non-NULL, fill the buffer from the | |
1940 | corresponding register return-value location. */ | |
1941 | enum return_value_convention | |
1942 | ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, | |
1943 | struct type *valtype, struct regcache *regcache, | |
1944 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
1945 | { | |
1946 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1947 | struct type *func_type = function ? value_type (function) : NULL; | |
1948 | int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0; | |
1949 | struct type *eltype; | |
1950 | int nelt, i, ok; | |
1951 | ||
1952 | /* This function exists to support a calling convention that | |
1953 | requires floating-point registers. It shouldn't be used on | |
1954 | processors that lack them. */ | |
1955 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); | |
1956 | ||
1957 | /* Complex types are returned as if two independent scalars. */ | |
1958 | if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX) | |
afd48b75 | 1959 | { |
e765b44c UW |
1960 | eltype = check_typedef (TYPE_TARGET_TYPE (valtype)); |
1961 | ||
1962 | for (i = 0; i < 2; i++) | |
afd48b75 | 1963 | { |
e765b44c UW |
1964 | ok = ppc64_sysv_abi_return_value_base (gdbarch, eltype, regcache, |
1965 | readbuf, writebuf, i); | |
1966 | gdb_assert (ok); | |
1967 | ||
1968 | if (readbuf) | |
1969 | readbuf += TYPE_LENGTH (eltype); | |
1970 | if (writebuf) | |
1971 | writebuf += TYPE_LENGTH (eltype); | |
afd48b75 AC |
1972 | } |
1973 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1974 | } | |
e765b44c UW |
1975 | |
1976 | /* OpenCL vectors shorter than 16 bytes are returned as if | |
1977 | a series of independent scalars; OpenCL vectors 16 bytes | |
1978 | or longer are returned as if a series of AltiVec vectors. */ | |
1979 | if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype) | |
1980 | && opencl_abi) | |
afd48b75 | 1981 | { |
e765b44c UW |
1982 | if (TYPE_LENGTH (valtype) < 16) |
1983 | eltype = check_typedef (TYPE_TARGET_TYPE (valtype)); | |
1984 | else | |
1985 | eltype = register_type (gdbarch, tdep->ppc_vr0_regnum); | |
1986 | ||
1987 | nelt = TYPE_LENGTH (valtype) / TYPE_LENGTH (eltype); | |
1988 | for (i = 0; i < nelt; i++) | |
afd48b75 | 1989 | { |
e765b44c UW |
1990 | ok = ppc64_sysv_abi_return_value_base (gdbarch, eltype, regcache, |
1991 | readbuf, writebuf, i); | |
1992 | gdb_assert (ok); | |
1993 | ||
1994 | if (readbuf) | |
1995 | readbuf += TYPE_LENGTH (eltype); | |
1996 | if (writebuf) | |
1997 | writebuf += TYPE_LENGTH (eltype); | |
afd48b75 AC |
1998 | } |
1999 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2000 | } | |
e765b44c UW |
2001 | |
2002 | /* All pointers live in r3. */ | |
aa006118 | 2003 | if (TYPE_CODE (valtype) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (valtype)) |
afd48b75 | 2004 | { |
e765b44c UW |
2005 | int regnum = tdep->ppc_gp0_regnum + 3; |
2006 | ||
2007 | if (writebuf != NULL) | |
2008 | regcache_cooked_write (regcache, regnum, writebuf); | |
2009 | if (readbuf != NULL) | |
2010 | regcache_cooked_read (regcache, regnum, readbuf); | |
afd48b75 AC |
2011 | return RETURN_VALUE_REGISTER_CONVENTION; |
2012 | } | |
e765b44c UW |
2013 | |
2014 | /* Small character arrays are returned, right justified, in r3. */ | |
2015 | if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY | |
a1da2672 | 2016 | && !TYPE_VECTOR (valtype) |
e765b44c UW |
2017 | && TYPE_LENGTH (valtype) <= 8 |
2018 | && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT | |
2019 | && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1) | |
2020 | { | |
2021 | int regnum = tdep->ppc_gp0_regnum + 3; | |
2022 | int offset = (register_size (gdbarch, regnum) - TYPE_LENGTH (valtype)); | |
2023 | ||
2024 | if (writebuf != NULL) | |
2025 | regcache_cooked_write_part (regcache, regnum, | |
2026 | offset, TYPE_LENGTH (valtype), writebuf); | |
2027 | if (readbuf != NULL) | |
2028 | regcache_cooked_read_part (regcache, regnum, | |
2029 | offset, TYPE_LENGTH (valtype), readbuf); | |
2030 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2031 | } | |
2032 | ||
cc0e89c5 UW |
2033 | /* In the ELFv2 ABI, homogeneous floating-point or vector |
2034 | aggregates are returned in registers. */ | |
2035 | if (tdep->elf_abi == POWERPC_ELF_V2 | |
a1da2672 UW |
2036 | && ppc64_elfv2_abi_homogeneous_aggregate (valtype, &eltype, &nelt) |
2037 | && (TYPE_CODE (eltype) == TYPE_CODE_FLT | |
2038 | || TYPE_CODE (eltype) == TYPE_CODE_DECFLOAT | |
2039 | || (TYPE_CODE (eltype) == TYPE_CODE_ARRAY | |
2040 | && TYPE_VECTOR (eltype) | |
2041 | && tdep->vector_abi == POWERPC_VEC_ALTIVEC | |
2042 | && TYPE_LENGTH (eltype) == 16))) | |
cc0e89c5 UW |
2043 | { |
2044 | for (i = 0; i < nelt; i++) | |
2045 | { | |
2046 | ok = ppc64_sysv_abi_return_value_base (gdbarch, eltype, regcache, | |
2047 | readbuf, writebuf, i); | |
2048 | gdb_assert (ok); | |
2049 | ||
2050 | if (readbuf) | |
2051 | readbuf += TYPE_LENGTH (eltype); | |
2052 | if (writebuf) | |
2053 | writebuf += TYPE_LENGTH (eltype); | |
2054 | } | |
2055 | ||
2056 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2057 | } | |
2058 | ||
2059 | /* In the ELFv2 ABI, aggregate types of up to 16 bytes are | |
2060 | returned in registers r3:r4. */ | |
2061 | if (tdep->elf_abi == POWERPC_ELF_V2 | |
2062 | && TYPE_LENGTH (valtype) <= 16 | |
2063 | && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT | |
2064 | || TYPE_CODE (valtype) == TYPE_CODE_UNION | |
2065 | || (TYPE_CODE (valtype) == TYPE_CODE_ARRAY | |
2066 | && !TYPE_VECTOR (valtype)))) | |
2067 | { | |
2068 | int n_regs = ((TYPE_LENGTH (valtype) + tdep->wordsize - 1) | |
2069 | / tdep->wordsize); | |
2070 | int i; | |
2071 | ||
2072 | for (i = 0; i < n_regs; i++) | |
2073 | { | |
0f068fb5 | 2074 | gdb_byte regval[PPC_MAX_REGISTER_SIZE]; |
cc0e89c5 UW |
2075 | int regnum = tdep->ppc_gp0_regnum + 3 + i; |
2076 | int offset = i * tdep->wordsize; | |
2077 | int len = TYPE_LENGTH (valtype) - offset; | |
2078 | ||
2079 | if (len > tdep->wordsize) | |
2080 | len = tdep->wordsize; | |
2081 | ||
2082 | if (writebuf != NULL) | |
2083 | { | |
2084 | memset (regval, 0, sizeof regval); | |
2085 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG | |
2086 | && offset == 0) | |
2087 | memcpy (regval + tdep->wordsize - len, writebuf, len); | |
2088 | else | |
2089 | memcpy (regval, writebuf + offset, len); | |
2090 | regcache_cooked_write (regcache, regnum, regval); | |
2091 | } | |
2092 | if (readbuf != NULL) | |
2093 | { | |
2094 | regcache_cooked_read (regcache, regnum, regval); | |
2095 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG | |
2096 | && offset == 0) | |
2097 | memcpy (readbuf, regval + tdep->wordsize - len, len); | |
2098 | else | |
2099 | memcpy (readbuf + offset, regval, len); | |
2100 | } | |
2101 | } | |
2102 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2103 | } | |
2104 | ||
e765b44c UW |
2105 | /* Handle plain base types. */ |
2106 | if (ppc64_sysv_abi_return_value_base (gdbarch, valtype, regcache, | |
2107 | readbuf, writebuf, 0)) | |
2108 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2109 | ||
afd48b75 AC |
2110 | return RETURN_VALUE_STRUCT_CONVENTION; |
2111 | } | |
2112 |