1 /* Target-dependent code for UltraSPARC.
3 Copyright 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "arch-utils.h"
24 #include "floatformat.h"
26 #include "frame-base.h"
27 #include "frame-unwind.h"
38 #include "gdb_assert.h"
39 #include "gdb_string.h"
41 #include "sparc64-tdep.h"
43 /* This file implements the The SPARC 64-bit ABI as defined by the
44 section "Low-Level System Information" of the SPARC Compliance
45 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
48 /* Please use the sparc32_-prefix for 32-bit specific code, the
49 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
50 code can handle both. */
52 /* The functions on this page are intended to be used to classify
53 function arguments. */
55 /* Return the contents if register REGNUM as an address. */
58 sparc_address_from_register (int regnum)
62 regcache_cooked_read_unsigned (current_regcache, regnum, &addr);
66 /* Check whether TYPE is "Integral or Pointer". */
69 sparc64_integral_or_pointer_p (const struct type *type)
71 switch (TYPE_CODE (type))
79 int len = TYPE_LENGTH (type);
80 gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
86 int len = TYPE_LENGTH (type);
87 gdb_assert (len == 8);
97 /* Check whether TYPE is "Floating". */
100 sparc64_floating_p (const struct type *type)
102 switch (TYPE_CODE (type))
106 int len = TYPE_LENGTH (type);
107 gdb_assert (len == 4 || len == 8 || len == 16);
117 /* Check whether TYPE is "Structure or Union". */
120 sparc64_structure_or_union_p (const struct type *type)
122 switch (TYPE_CODE (type))
124 case TYPE_CODE_STRUCT:
125 case TYPE_CODE_UNION:
134 /* Register information. */
136 struct sparc64_register_info
142 static struct sparc64_register_info sparc64_register_info[] =
144 { "g0", &builtin_type_int64 },
145 { "g1", &builtin_type_int64 },
146 { "g2", &builtin_type_int64 },
147 { "g3", &builtin_type_int64 },
148 { "g4", &builtin_type_int64 },
149 { "g5", &builtin_type_int64 },
150 { "g6", &builtin_type_int64 },
151 { "g7", &builtin_type_int64 },
153 { "o0", &builtin_type_int64 },
154 { "o1", &builtin_type_int64 },
155 { "o2", &builtin_type_int64 },
156 { "o3", &builtin_type_int64 },
157 { "o4", &builtin_type_int64 },
158 { "o5", &builtin_type_int64 },
159 { "sp", &builtin_type_void_data_ptr },
160 { "o7", &builtin_type_int64 },
162 { "l0", &builtin_type_int64 },
163 { "l1", &builtin_type_int64 },
164 { "l2", &builtin_type_int64 },
165 { "l3", &builtin_type_int64 },
166 { "l4", &builtin_type_int64 },
167 { "l5", &builtin_type_int64 },
168 { "l6", &builtin_type_int64 },
169 { "l7", &builtin_type_int64 },
171 { "i0", &builtin_type_int64 },
172 { "i1", &builtin_type_int64 },
173 { "i2", &builtin_type_int64 },
174 { "i3", &builtin_type_int64 },
175 { "i4", &builtin_type_int64 },
176 { "i5", &builtin_type_int64 },
177 { "fp", &builtin_type_void_data_ptr },
178 { "i7", &builtin_type_int64 },
180 { "f0", &builtin_type_float },
181 { "f1", &builtin_type_float },
182 { "f2", &builtin_type_float },
183 { "f3", &builtin_type_float },
184 { "f4", &builtin_type_float },
185 { "f5", &builtin_type_float },
186 { "f6", &builtin_type_float },
187 { "f7", &builtin_type_float },
188 { "f8", &builtin_type_float },
189 { "f9", &builtin_type_float },
190 { "f10", &builtin_type_float },
191 { "f11", &builtin_type_float },
192 { "f12", &builtin_type_float },
193 { "f13", &builtin_type_float },
194 { "f14", &builtin_type_float },
195 { "f15", &builtin_type_float },
196 { "f16", &builtin_type_float },
197 { "f17", &builtin_type_float },
198 { "f18", &builtin_type_float },
199 { "f19", &builtin_type_float },
200 { "f20", &builtin_type_float },
201 { "f21", &builtin_type_float },
202 { "f22", &builtin_type_float },
203 { "f23", &builtin_type_float },
204 { "f24", &builtin_type_float },
205 { "f25", &builtin_type_float },
206 { "f26", &builtin_type_float },
207 { "f27", &builtin_type_float },
208 { "f28", &builtin_type_float },
209 { "f29", &builtin_type_float },
210 { "f30", &builtin_type_float },
211 { "f31", &builtin_type_float },
212 { "f32", &builtin_type_double },
213 { "f34", &builtin_type_double },
214 { "f36", &builtin_type_double },
215 { "f38", &builtin_type_double },
216 { "f40", &builtin_type_double },
217 { "f42", &builtin_type_double },
218 { "f44", &builtin_type_double },
219 { "f46", &builtin_type_double },
220 { "f48", &builtin_type_double },
221 { "f50", &builtin_type_double },
222 { "f52", &builtin_type_double },
223 { "f54", &builtin_type_double },
224 { "f56", &builtin_type_double },
225 { "f58", &builtin_type_double },
226 { "f60", &builtin_type_double },
227 { "f62", &builtin_type_double },
229 { "pc", &builtin_type_void_func_ptr },
230 { "npc", &builtin_type_void_func_ptr },
232 /* This raw register contains the contents of %cwp, %pstate, %asi
233 and %ccr as laid out in a %tstate register. */
234 /* FIXME: Give it a name until we start using register groups. */
235 { "state", &builtin_type_int64 },
237 { "fsr", &builtin_type_int64 },
238 { "fprs", &builtin_type_int64 },
240 /* "Although Y is a 64-bit register, its high-order 32 bits are
241 reserved and always read as 0." */
242 { "y", &builtin_type_int64 }
245 /* Total number of registers. */
246 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_info)
248 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
249 registers as "psuedo" registers. */
251 static struct sparc64_register_info sparc64_pseudo_register_info[] =
253 { "cwp", &builtin_type_int64 },
254 { "pstate", &builtin_type_int64 },
255 { "asi", &builtin_type_int64 },
256 { "ccr", &builtin_type_int64 },
258 { "d0", &builtin_type_double },
259 { "d2", &builtin_type_double },
260 { "d4", &builtin_type_double },
261 { "d6", &builtin_type_double },
262 { "d8", &builtin_type_double },
263 { "d10", &builtin_type_double },
264 { "d12", &builtin_type_double },
265 { "d14", &builtin_type_double },
266 { "d16", &builtin_type_double },
267 { "d18", &builtin_type_double },
268 { "d20", &builtin_type_double },
269 { "d22", &builtin_type_double },
270 { "d24", &builtin_type_double },
271 { "d26", &builtin_type_double },
272 { "d28", &builtin_type_double },
273 { "d30", &builtin_type_double },
274 { "d32", &builtin_type_double },
275 { "d34", &builtin_type_double },
276 { "d36", &builtin_type_double },
277 { "d38", &builtin_type_double },
278 { "d40", &builtin_type_double },
279 { "d42", &builtin_type_double },
280 { "d44", &builtin_type_double },
281 { "d46", &builtin_type_double },
282 { "d48", &builtin_type_double },
283 { "d50", &builtin_type_double },
284 { "d52", &builtin_type_double },
285 { "d54", &builtin_type_double },
286 { "d56", &builtin_type_double },
287 { "d58", &builtin_type_double },
288 { "d60", &builtin_type_double },
289 { "d62", &builtin_type_double },
291 { "q0", &builtin_type_long_double },
292 { "q4", &builtin_type_long_double },
293 { "q8", &builtin_type_long_double },
294 { "q12", &builtin_type_long_double },
295 { "q16", &builtin_type_long_double },
296 { "q20", &builtin_type_long_double },
297 { "q24", &builtin_type_long_double },
298 { "q28", &builtin_type_long_double },
299 { "q32", &builtin_type_long_double },
300 { "q36", &builtin_type_long_double },
301 { "q40", &builtin_type_long_double },
302 { "q44", &builtin_type_long_double },
303 { "q48", &builtin_type_long_double },
304 { "q52", &builtin_type_long_double },
305 { "q56", &builtin_type_long_double },
306 { "q60", &builtin_type_long_double }
309 /* Total number of pseudo registers. */
310 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_info)
312 /* Return the name of register REGNUM. */
315 sparc64_register_name (int regnum)
317 if (regnum >= 0 && regnum < SPARC64_NUM_REGS)
318 return sparc64_register_info[regnum].name;
320 if (regnum >= SPARC64_NUM_REGS
321 && regnum < SPARC64_NUM_REGS + SPARC64_NUM_PSEUDO_REGS)
322 return sparc64_pseudo_register_info[regnum - SPARC64_NUM_REGS].name;
327 /* Return the GDB type object for the "standard" data type of data in
331 sparc64_register_type (struct gdbarch *gdbarch, int regnum)
333 if (regnum >= SPARC64_NUM_REGS
334 && regnum < SPARC64_NUM_REGS + SPARC64_NUM_PSEUDO_REGS)
335 return *sparc64_pseudo_register_info[regnum - SPARC64_NUM_REGS].type;
337 gdb_assert (regnum >= 0 && regnum < SPARC64_NUM_REGS);
338 return *sparc64_register_info[regnum].type;
342 sparc64_pseudo_register_read (struct gdbarch *gdbarch,
343 struct regcache *regcache,
344 int regnum, void *buf)
346 gdb_assert (regnum >= SPARC64_NUM_REGS);
348 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
350 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
351 regcache_raw_read (regcache, regnum, buf);
352 regcache_raw_read (regcache, regnum + 1, ((char *)buf) + 4);
354 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
356 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
357 regcache_raw_read (regcache, regnum, buf);
359 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
361 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
362 regcache_raw_read (regcache, regnum, buf);
363 regcache_raw_read (regcache, regnum + 1, ((char *)buf) + 4);
364 regcache_raw_read (regcache, regnum + 2, ((char *)buf) + 8);
365 regcache_raw_read (regcache, regnum + 3, ((char *)buf) + 12);
367 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
369 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
370 regcache_raw_read (regcache, regnum, buf);
371 regcache_raw_read (regcache, regnum + 1, ((char *)buf) + 8);
373 else if (regnum == SPARC64_CWP_REGNUM
374 || regnum == SPARC64_PSTATE_REGNUM
375 || regnum == SPARC64_ASI_REGNUM
376 || regnum == SPARC64_CCR_REGNUM)
380 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
383 case SPARC64_CWP_REGNUM:
384 state = (state >> 0) & ((1 << 5) - 1);
386 case SPARC64_PSTATE_REGNUM:
387 state = (state >> 8) & ((1 << 12) - 1);
389 case SPARC64_ASI_REGNUM:
390 state = (state >> 24) & ((1 << 8) - 1);
392 case SPARC64_CCR_REGNUM:
393 state = (state >> 32) & ((1 << 8) - 1);
396 store_unsigned_integer (buf, 8, state);
401 sparc64_pseudo_register_write (struct gdbarch *gdbarch,
402 struct regcache *regcache,
403 int regnum, const void *buf)
405 gdb_assert (regnum >= SPARC64_NUM_REGS);
407 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
409 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
410 regcache_raw_write (regcache, regnum, buf);
411 regcache_raw_write (regcache, regnum + 1, ((const char *)buf) + 4);
413 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
415 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
416 regcache_raw_write (regcache, regnum, buf);
418 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
420 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
421 regcache_raw_write (regcache, regnum, buf);
422 regcache_raw_write (regcache, regnum + 1, ((const char *)buf) + 4);
423 regcache_raw_write (regcache, regnum + 2, ((const char *)buf) + 8);
424 regcache_raw_write (regcache, regnum + 3, ((const char *)buf) + 12);
426 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
428 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
429 regcache_raw_write (regcache, regnum, buf);
430 regcache_raw_write (regcache, regnum + 1, ((const char *)buf) + 8);
432 else if (regnum == SPARC64_CWP_REGNUM
433 || regnum == SPARC64_PSTATE_REGNUM
434 || regnum == SPARC64_ASI_REGNUM
435 || regnum == SPARC64_CCR_REGNUM)
437 ULONGEST state, bits;
439 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
440 bits = extract_unsigned_integer (buf, 8);
443 case SPARC64_CWP_REGNUM:
444 state |= ((bits & ((1 << 5) - 1)) << 0);
446 case SPARC64_PSTATE_REGNUM:
447 state |= ((bits & ((1 << 12) - 1)) << 8);
449 case SPARC64_ASI_REGNUM:
450 state |= ((bits & ((1 << 8) - 1)) << 24);
452 case SPARC64_CCR_REGNUM:
453 state |= ((bits & ((1 << 8) - 1)) << 32);
456 regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
461 /* Return PC of first real instruction of the function starting at
465 sparc64_skip_prologue (CORE_ADDR start_pc)
467 struct symtab_and_line sal;
468 CORE_ADDR func_start, func_end;
469 struct sparc_frame_cache cache;
471 /* This is the preferred method, find the end of the prologue by
472 using the debugging information. */
473 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
475 sal = find_pc_line (func_start, 0);
477 if (sal.end < func_end
478 && start_pc <= sal.end)
482 return sparc_analyze_prologue (start_pc, 0xffffffffffffffffULL, &cache);
487 static struct sparc_frame_cache *
488 sparc64_frame_cache (struct frame_info *next_frame, void **this_cache)
490 return sparc_frame_cache (next_frame, this_cache);
494 sparc64_frame_this_id (struct frame_info *next_frame, void **this_cache,
495 struct frame_id *this_id)
497 struct sparc_frame_cache *cache =
498 sparc64_frame_cache (next_frame, this_cache);
500 /* This marks the outermost frame. */
501 if (cache->base == 0)
504 (*this_id) = frame_id_build (cache->base, cache->pc);
508 sparc64_frame_prev_register (struct frame_info *next_frame, void **this_cache,
509 int regnum, int *optimizedp,
510 enum lval_type *lvalp, CORE_ADDR *addrp,
511 int *realnump, void *valuep)
513 struct sparc_frame_cache *cache =
514 sparc64_frame_cache (next_frame, this_cache);
516 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
524 CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0;
526 regnum = cache->frameless_p ? SPARC_O7_REGNUM : SPARC_I7_REGNUM;
527 pc += frame_unwind_register_unsigned (next_frame, regnum) + 8;
528 store_unsigned_integer (valuep, 8, pc);
533 /* The previous frame's `local' and `in' registers have been saved
534 in the register save area. */
535 if (!cache->frameless_p
536 && regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM)
539 *lvalp = lval_memory;
540 *addrp = cache->base + BIAS + (regnum - SPARC_L0_REGNUM) * 8;
544 struct gdbarch *gdbarch = get_frame_arch (next_frame);
546 /* Read the value in from memory. */
547 read_memory (*addrp, valuep, register_size (gdbarch, regnum));
552 /* The previous frame's `out' registers are accessable as the
553 current frame's `in' registers. */
554 if (!cache->frameless_p
555 && regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
556 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
558 frame_register_unwind (next_frame, regnum,
559 optimizedp, lvalp, addrp, realnump, valuep);
562 static const struct frame_unwind sparc64_frame_unwind =
565 sparc64_frame_this_id,
566 sparc64_frame_prev_register
569 static const struct frame_unwind *
570 sparc64_frame_sniffer (struct frame_info *next_frame)
572 return &sparc64_frame_unwind;
577 sparc64_frame_base_address (struct frame_info *next_frame, void **this_cache)
579 struct sparc_frame_cache *cache =
580 sparc64_frame_cache (next_frame, this_cache);
582 /* ??? Should we take BIAS into account here? */
586 static const struct frame_base sparc64_frame_base =
588 &sparc64_frame_unwind,
589 sparc64_frame_base_address,
590 sparc64_frame_base_address,
591 sparc64_frame_base_address
594 /* Check whether TYPE must be 16-byte aligned. */
597 sparc64_16_byte_align_p (struct type *type)
599 if (sparc64_floating_p (type) && TYPE_LENGTH (type) == 16)
602 if (sparc64_structure_or_union_p (type))
606 for (i = 0; i < TYPE_NFIELDS (type); i++)
608 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
610 if (sparc64_16_byte_align_p (subtype))
618 /* Store floating fields of element ELEMENT of an "parameter array"
619 that has type TYPE and is stored at BITPOS in VALBUF in the
620 apropriate registers of REGCACHE. This function can be called
621 recursively and therefore handles floating types in addition to
625 sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
626 char *valbuf, int element, int bitpos)
628 gdb_assert (element < 16);
630 if (sparc64_floating_p (type))
632 int len = TYPE_LENGTH (type);
637 gdb_assert (bitpos == 0);
638 gdb_assert ((element % 2) == 0);
640 regnum = SPARC64_Q0_REGNUM + element / 2;
641 regcache_cooked_write (regcache, regnum, valbuf);
645 gdb_assert (bitpos == 0 || bitpos == 64);
647 regnum = SPARC64_D0_REGNUM + element + bitpos / 64;
648 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8));
652 gdb_assert (len == 4);
653 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128);
655 regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
656 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8));
659 else if (sparc64_structure_or_union_p (type))
663 for (i = 0; i < TYPE_NFIELDS (type); i++)
665 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
666 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
668 sparc64_store_floating_fields (regcache, subtype, valbuf,
674 /* Fetch floating fields from a variable of type TYPE from the
675 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
676 in VALBUF. This function can be called recursively and therefore
677 handles floating types in addition to structures. */
680 sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
681 char *valbuf, int bitpos)
683 if (sparc64_floating_p (type))
685 int len = TYPE_LENGTH (type);
690 gdb_assert (bitpos == 0 || bitpos == 128);
692 regnum = SPARC64_Q0_REGNUM + bitpos / 128;
693 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
697 gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256);
699 regnum = SPARC64_D0_REGNUM + bitpos / 64;
700 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
704 gdb_assert (len == 4);
705 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256);
707 regnum = SPARC_F0_REGNUM + bitpos / 32;
708 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
711 else if (sparc64_structure_or_union_p (type))
715 for (i = 0; i < TYPE_NFIELDS (type); i++)
717 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
718 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
720 sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos);
725 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
726 non-zero) in REGCACHE and on the stack (starting from address SP). */
729 sparc64_store_arguments (struct regcache *regcache, int nargs,
730 struct value **args, CORE_ADDR sp,
731 int struct_return, CORE_ADDR struct_addr)
733 /* Number of extended words in the "parameter array". */
734 int num_elements = 0;
738 /* Take BIAS into account. */
741 /* First we calculate the number of extended words in the "parameter
742 array". While doing so we also convert some of the arguments. */
747 for (i = 0; i < nargs; i++)
749 struct type *type = VALUE_TYPE (args[i]);
750 int len = TYPE_LENGTH (type);
752 if (sparc64_structure_or_union_p (type))
754 /* Structure or Union arguments. */
757 if (num_elements % 2 && sparc64_16_byte_align_p (type))
759 num_elements += ((len + 7) / 8);
763 /* The psABI says that "Structures or unions larger than
764 sixteen bytes are copied by the caller and passed
765 indirectly; the caller will pass the address of a
766 correctly aligned structure value. This sixty-four
767 bit address will occupy one word in the parameter
768 array, and may be promoted to an %o register like any
769 other pointer value." Allocate memory for these
770 values on the stack. */
773 /* Use 16-byte alignment for these values. That's
774 always correct, and wasting a few bytes shouldn't be
778 write_memory (sp, VALUE_CONTENTS (args[i]), len);
779 args[i] = value_from_pointer (lookup_pointer_type (type), sp);
783 else if (sparc64_floating_p (type))
785 /* Floating arguments. */
789 /* The psABI says that "Each quad-precision parameter
790 value will be assigned to two extended words in the
794 /* The psABI says that "Long doubles must be
795 quad-aligned, and thus a hole might be introduced
796 into the parameter array to force alignment." Skip
797 an element if necessary. */
798 if (num_elements % 2)
806 /* Integral and pointer arguments. */
807 gdb_assert (sparc64_integral_or_pointer_p (type));
809 /* The psABI says that "Each argument value of integral type
810 smaller than an extended word will be widened by the
811 caller to an extended word according to the signed-ness
812 of the argument type." */
814 args[i] = value_cast (builtin_type_int64, args[i]);
819 /* Allocate the "parameter array". */
820 sp -= num_elements * 8;
822 /* The psABI says that "Every stack frame must be 16-byte aligned." */
825 /* Now we store the arguments in to the "paramater array". Some
826 Integer or Pointer arguments and Structure or Union arguments
827 will be passed in %o registers. Some Floating arguments and
828 floating members of structures are passed in floating-point
829 registers. However, for functions with variable arguments,
830 floating arguments are stored in an %0 register, and for
831 functions without a prototype floating arguments are stored in
832 both a floating-point and an %o registers, or a floating-point
833 register and memory. To simplify the logic here we always pass
834 arguments in memory, an %o register, and a floating-point
835 register if appropriate. This should be no problem since the
836 contents of any unused memory or registers in the "parameter
837 array" are undefined. */
841 regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
845 for (i = 0; i < nargs; i++)
847 char *valbuf = VALUE_CONTENTS (args[i]);
848 struct type *type = VALUE_TYPE (args[i]);
849 int len = TYPE_LENGTH (type);
853 if (sparc64_structure_or_union_p (type))
855 /* Structure or Union arguments. */
856 gdb_assert (len <= 16);
857 memset (buf, 0, sizeof (buf));
858 valbuf = memcpy (buf, valbuf, len);
860 if (element % 2 && sparc64_16_byte_align_p (type))
865 regnum = SPARC_O0_REGNUM + element;
866 if (len > 8 && element < 5)
867 regcache_cooked_write (regcache, regnum + 1, valbuf + 8);
871 sparc64_store_floating_fields (regcache, type, valbuf, element, 0);
873 else if (sparc64_floating_p (type))
875 /* Floating arguments. */
881 regnum = SPARC64_Q0_REGNUM + element / 2;
886 regnum = SPARC64_D0_REGNUM + element;
890 /* The psABI says "Each single-precision parameter value
891 will be assigned to one extended word in the
892 parameter array, and right-justified within that
893 word; the left half (even floatregister) is
894 undefined." Even though the psABI says that "the
895 left half is undefined", set it to zero here. */
897 valbuf = memcpy (buf + 4, valbuf, 4);
900 regnum = SPARC64_D0_REGNUM;
905 /* Integral and pointer arguments. */
906 gdb_assert (len == 8);
908 regnum = SPARC_O0_REGNUM + element;
913 regcache_cooked_write (regcache, regnum, valbuf);
915 /* If we're storing the value in a floating-point register,
916 also store it in the corresponding %0 register(s). */
917 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM)
919 gdb_assert (element < 6);
920 regnum = SPARC_O0_REGNUM + element;
921 regcache_cooked_write (regcache, regnum, valbuf);
923 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM)
925 gdb_assert (element < 6);
926 regnum = SPARC_O0_REGNUM + element;
927 regcache_cooked_write (regcache, regnum, valbuf);
928 regcache_cooked_write (regcache, regnum + 1, valbuf);
932 /* Always store the argument in memeory. */
933 write_memory (sp + element * 8, valbuf, len);
934 element += ((len + 7) / 8);
937 gdb_assert (element == num_elements);
939 /* Take BIAS into account. */
945 sparc64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
946 struct regcache *regcache, CORE_ADDR bp_addr,
947 int nargs, struct value **args, CORE_ADDR sp,
948 int struct_return, CORE_ADDR struct_addr)
950 /* Set return address. */
951 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
953 /* Set up function arguments. */
954 sp = sparc64_store_arguments (regcache, nargs, args, sp,
955 struct_return, struct_addr);
957 /* Allocate the register save area. */
960 /* Stack should be 16-byte aligned at this point. */
961 gdb_assert ((sp + BIAS) % 16 == 0);
963 /* Finally, update the stack pointer. */
964 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp);
970 /* Extract from an array REGBUF containing the (raw) register state, a
971 function return value of TYPE, and copy that into VALBUF. */
974 sparc64_extract_return_value (struct type *type, struct regcache *regcache,
977 int len = TYPE_LENGTH (type);
981 if (sparc64_structure_or_union_p (type))
983 /* Structure or Union return values. */
984 gdb_assert (len <= 32);
986 for (i = 0; i < ((len + 7) / 8); i++)
987 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
988 if (TYPE_CODE (type) != TYPE_CODE_UNION)
989 sparc64_extract_floating_fields (regcache, type, buf, 0);
990 memcpy (valbuf, buf, len);
992 else if (sparc64_floating_p (type))
994 /* Floating return values. */
995 for (i = 0; i < len / 4; i++)
996 regcache_cooked_read (regcache, SPARC_F0_REGNUM + i, buf + i * 4);
997 memcpy (valbuf, buf, len);
1001 /* Integral and pointer return values. */
1002 gdb_assert (sparc64_integral_or_pointer_p (type));
1004 /* Just stripping off any unused bytes should preserve the
1005 signed-ness just fine. */
1006 regcache_cooked_read (regcache, SPARC_O0_REGNUM, buf);
1007 memcpy (valbuf, buf + 8 - len, len);
1011 /* Write into the appropriate registers a function return value stored
1012 in VALBUF of type TYPE. */
1015 sparc64_store_return_value (struct type *type, struct regcache *regcache,
1018 int len = TYPE_LENGTH (type);
1022 if (sparc64_structure_or_union_p (type))
1024 /* Structure or Union return values. */
1025 gdb_assert (len <= 32);
1027 /* Simplify matters by storing the complete value (including
1028 floating members) into %o0 and %o1. Floating members are
1029 also store in the appropriate floating-point registers. */
1030 memset (buf, 0, sizeof (buf));
1031 memcpy (buf, valbuf, len);
1032 for (i = 0; i < ((len + 7) / 8); i++)
1033 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1034 if (TYPE_CODE (type) != TYPE_CODE_UNION)
1035 sparc64_store_floating_fields (regcache, type, buf, 0, 0);
1037 else if (sparc64_floating_p (type))
1039 /* Floating return values. */
1040 memcpy (buf, valbuf, len);
1041 for (i = 0; i < len / 4; i++)
1042 regcache_cooked_write (regcache, SPARC_F0_REGNUM + i, buf + i * 4);
1046 /* Integral and pointer return values. */
1047 gdb_assert (sparc64_integral_or_pointer_p (type));
1049 /* ??? Do we need to do any sign-extension here? */
1051 memcpy (buf + 8 - len, valbuf, len);
1052 regcache_cooked_write (regcache, SPARC_O0_REGNUM, buf);
1056 static enum return_value_convention
1057 sparc64_return_value (struct gdbarch *gdbarch, struct type *type,
1058 struct regcache *regcache, void *readbuf,
1059 const void *writebuf)
1061 if (TYPE_LENGTH (type) > 32)
1062 return RETURN_VALUE_STRUCT_CONVENTION;
1065 sparc64_extract_return_value (type, regcache, readbuf);
1067 sparc64_store_return_value (type, regcache, writebuf);
1069 return RETURN_VALUE_REGISTER_CONVENTION;
1074 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1076 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1078 tdep->pc_regnum = SPARC64_PC_REGNUM;
1079 tdep->npc_regnum = SPARC64_NPC_REGNUM;
1081 /* This is what all the fuss is about. */
1082 set_gdbarch_long_bit (gdbarch, 64);
1083 set_gdbarch_long_long_bit (gdbarch, 64);
1084 set_gdbarch_ptr_bit (gdbarch, 64);
1086 set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS);
1087 set_gdbarch_register_name (gdbarch, sparc64_register_name);
1088 set_gdbarch_register_type (gdbarch, sparc64_register_type);
1089 set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS);
1090 set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read);
1091 set_gdbarch_pseudo_register_write (gdbarch, sparc64_pseudo_register_write);
1093 /* Register numbers of various important registers. */
1094 set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */
1096 /* Call dummy code. */
1097 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1098 set_gdbarch_push_dummy_code (gdbarch, NULL);
1099 set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call);
1101 set_gdbarch_return_value (gdbarch, sparc64_return_value);
1102 set_gdbarch_return_value_on_stack
1103 (gdbarch, generic_return_value_on_stack_not);
1104 set_gdbarch_stabs_argument_has_addr
1105 (gdbarch, default_stabs_argument_has_addr);
1107 set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue);
1109 frame_unwind_append_sniffer (gdbarch, sparc64_frame_sniffer);
1110 frame_base_set_default (gdbarch, &sparc64_frame_base);
1114 /* Helper functions for dealing with register sets. */
1116 #define TSTATE_CWP 0x000000000000001fULL
1117 #define TSTATE_ICC 0x0000000f00000000ULL
1118 #define TSTATE_XCC 0x000000f000000000ULL
1120 #define PSR_S 0x00000080
1121 #define PSR_ICC 0x00f00000
1122 #define PSR_VERS 0x0f000000
1123 #define PSR_IMPL 0xf0000000
1124 #define PSR_V8PLUS 0xff000000
1125 #define PSR_XCC 0x000f0000
1128 sparc64_supply_gregset (const struct sparc_gregset *gregset,
1129 struct regcache *regcache,
1130 int regnum, const void *gregs)
1132 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
1133 const char *regs = gregs;
1138 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1140 int offset = gregset->r_tstate_offset;
1141 ULONGEST tstate, psr;
1144 tstate = extract_unsigned_integer (regs + offset, 8);
1145 psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12)
1146 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS);
1147 store_unsigned_integer (buf, 4, psr);
1148 regcache_raw_supply (regcache, SPARC32_PSR_REGNUM, buf);
1151 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1152 regcache_raw_supply (regcache, SPARC32_PC_REGNUM,
1153 regs + gregset->r_pc_offset + 4);
1155 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1156 regcache_raw_supply (regcache, SPARC32_NPC_REGNUM,
1157 regs + gregset->r_npc_offset + 4);
1159 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
1161 int offset = gregset->r_y_offset + 8 - gregset->r_y_size;
1162 regcache_raw_supply (regcache, SPARC32_Y_REGNUM, regs + offset);
1167 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1168 regcache_raw_supply (regcache, SPARC64_STATE_REGNUM,
1169 regs + gregset->r_tstate_offset);
1171 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1172 regcache_raw_supply (regcache, SPARC64_PC_REGNUM,
1173 regs + gregset->r_pc_offset);
1175 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1176 regcache_raw_supply (regcache, SPARC64_NPC_REGNUM,
1177 regs + gregset->r_npc_offset);
1179 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
1184 memcpy (buf + 8 - gregset->r_y_size,
1185 regs + gregset->r_y_offset, gregset->r_y_size);
1186 regcache_raw_supply (regcache, SPARC64_Y_REGNUM, buf);
1189 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1190 && gregset->r_fprs_offset != -1)
1191 regcache_raw_supply (regcache, SPARC64_FPRS_REGNUM,
1192 regs + gregset->r_fprs_offset);
1195 if (regnum == SPARC_G0_REGNUM || regnum == -1)
1196 regcache_raw_supply (regcache, SPARC_G0_REGNUM, NULL);
1198 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1200 int offset = gregset->r_g1_offset;
1205 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1207 if (regnum == i || regnum == -1)
1208 regcache_raw_supply (regcache, i, regs + offset);
1213 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1215 /* Not all of the register set variants include Locals and
1216 Inputs. For those that don't, we read them off the stack. */
1217 if (gregset->r_l0_offset == -1)
1221 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
1222 sparc_supply_rwindow (regcache, sp, regnum);
1226 int offset = gregset->r_l0_offset;
1231 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
1233 if (regnum == i || regnum == -1)
1234 regcache_raw_supply (regcache, i, regs + offset);
1242 sparc64_collect_gregset (const struct sparc_gregset *gregset,
1243 const struct regcache *regcache,
1244 int regnum, void *gregs)
1246 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
1252 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1254 int offset = gregset->r_tstate_offset;
1255 ULONGEST tstate, psr;
1258 tstate = extract_unsigned_integer (regs + offset, 8);
1259 regcache_raw_collect (regcache, SPARC32_PSR_REGNUM, buf);
1260 psr = extract_unsigned_integer (buf, 4);
1261 tstate |= (psr & PSR_ICC) << 12;
1262 if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS)
1263 tstate |= (psr & PSR_XCC) << 20;
1264 store_unsigned_integer (buf, 8, tstate);
1265 memcpy (regs + offset, buf, 8);
1268 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1269 regcache_raw_collect (regcache, SPARC32_PC_REGNUM,
1270 regs + gregset->r_pc_offset + 4);
1272 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1273 regcache_raw_collect (regcache, SPARC32_NPC_REGNUM,
1274 regs + gregset->r_npc_offset + 4);
1276 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
1278 int offset = gregset->r_y_offset + 8 - gregset->r_y_size;
1279 regcache_raw_collect (regcache, SPARC32_Y_REGNUM, regs + offset);
1284 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1285 regcache_raw_collect (regcache, SPARC64_STATE_REGNUM,
1286 regs + gregset->r_tstate_offset);
1288 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1289 regcache_raw_collect (regcache, SPARC64_PC_REGNUM,
1290 regs + gregset->r_pc_offset);
1292 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1293 regcache_raw_collect (regcache, SPARC64_NPC_REGNUM,
1294 regs + gregset->r_npc_offset);
1296 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
1300 regcache_raw_collect (regcache, SPARC64_Y_REGNUM, buf);
1301 memcpy (regs + gregset->r_y_offset,
1302 buf + 8 - gregset->r_y_size, gregset->r_y_size);
1305 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1306 && gregset->r_fprs_offset != -1)
1307 regcache_raw_collect (regcache, SPARC64_FPRS_REGNUM,
1308 regs + gregset->r_fprs_offset);
1312 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1314 int offset = gregset->r_g1_offset;
1319 /* %g0 is always zero. */
1320 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1322 if (regnum == i || regnum == -1)
1323 regcache_raw_collect (regcache, i, regs + offset);
1328 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1330 /* Not all of the register set variants include Locals and
1331 Inputs. For those that don't, we read them off the stack. */
1332 if (gregset->r_l0_offset != -1)
1334 int offset = gregset->r_l0_offset;
1339 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
1341 if (regnum == i || regnum == -1)
1342 regcache_raw_collect (regcache, i, regs + offset);
1350 sparc64_supply_fpregset (struct regcache *regcache,
1351 int regnum, const void *fpregs)
1353 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
1354 const char *regs = fpregs;
1357 for (i = 0; i < 32; i++)
1359 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
1360 regcache_raw_supply (regcache, SPARC_F0_REGNUM + i, regs + (i * 4));
1365 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
1366 regcache_raw_supply (regcache, SPARC32_FSR_REGNUM,
1367 regs + (32 * 4) + (16 * 8) + 4);
1371 for (i = 0; i < 16; i++)
1373 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
1374 regcache_raw_supply (regcache, SPARC64_F32_REGNUM + i,
1375 regs + (32 * 4) + (i * 8));
1378 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
1379 regcache_raw_supply (regcache, SPARC64_FSR_REGNUM,
1380 regs + (32 * 4) + (16 * 8));
1385 sparc64_collect_fpregset (const struct regcache *regcache,
1386 int regnum, void *fpregs)
1388 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
1389 char *regs = fpregs;
1392 for (i = 0; i < 32; i++)
1394 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
1395 regcache_raw_collect (regcache, SPARC_F0_REGNUM + i, regs + (i * 4));
1400 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
1401 regcache_raw_collect (regcache, SPARC32_FSR_REGNUM,
1402 regs + (32 * 4) + (16 * 8) + 4);
1406 for (i = 0; i < 16; i++)
1408 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
1409 regcache_raw_collect (regcache, SPARC64_F32_REGNUM + i,
1410 regs + (32 * 4) + (i * 8));
1413 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
1414 regcache_raw_collect (regcache, SPARC64_FSR_REGNUM,
1415 regs + (32 * 4) + (16 * 8));