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