1 /* Target-dependent code for UltraSPARC.
3 Copyright (C) 2003-2012 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 3 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, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
22 #include "dwarf2-frame.h"
23 #include "floatformat.h"
25 #include "frame-base.h"
26 #include "frame-unwind.h"
37 #include "gdb_assert.h"
38 #include "gdb_string.h"
40 #include "sparc64-tdep.h"
42 /* This file implements the SPARC 64-bit ABI as defined by the
43 section "Low-Level System Information" of the SPARC Compliance
44 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
47 /* Please use the sparc32_-prefix for 32-bit specific code, the
48 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
49 code can handle both. */
51 /* The functions on this page are intended to be used to classify
52 function arguments. */
54 /* Check whether TYPE is "Integral or Pointer". */
57 sparc64_integral_or_pointer_p (const struct type
*type
)
59 switch (TYPE_CODE (type
))
67 int len
= TYPE_LENGTH (type
);
68 gdb_assert (len
== 1 || len
== 2 || len
== 4 || len
== 8);
74 int len
= TYPE_LENGTH (type
);
75 gdb_assert (len
== 8);
85 /* Check whether TYPE is "Floating". */
88 sparc64_floating_p (const struct type
*type
)
90 switch (TYPE_CODE (type
))
94 int len
= TYPE_LENGTH (type
);
95 gdb_assert (len
== 4 || len
== 8 || len
== 16);
105 /* Check whether TYPE is "Complex Floating". */
108 sparc64_complex_floating_p (const struct type
*type
)
110 switch (TYPE_CODE (type
))
112 case TYPE_CODE_COMPLEX
:
114 int len
= TYPE_LENGTH (type
);
115 gdb_assert (len
== 8 || len
== 16 || len
== 32);
125 /* Check whether TYPE is "Structure or Union".
127 In terms of Ada subprogram calls, arrays are treated the same as
128 struct and union types. So this function also returns non-zero
132 sparc64_structure_or_union_p (const struct type
*type
)
134 switch (TYPE_CODE (type
))
136 case TYPE_CODE_STRUCT
:
137 case TYPE_CODE_UNION
:
138 case TYPE_CODE_ARRAY
:
148 /* Construct types for ISA-specific registers. */
151 sparc64_pstate_type (struct gdbarch
*gdbarch
)
153 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
155 if (!tdep
->sparc64_pstate_type
)
159 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_pstate", 8);
160 append_flags_type_flag (type
, 0, "AG");
161 append_flags_type_flag (type
, 1, "IE");
162 append_flags_type_flag (type
, 2, "PRIV");
163 append_flags_type_flag (type
, 3, "AM");
164 append_flags_type_flag (type
, 4, "PEF");
165 append_flags_type_flag (type
, 5, "RED");
166 append_flags_type_flag (type
, 8, "TLE");
167 append_flags_type_flag (type
, 9, "CLE");
168 append_flags_type_flag (type
, 10, "PID0");
169 append_flags_type_flag (type
, 11, "PID1");
171 tdep
->sparc64_pstate_type
= type
;
174 return tdep
->sparc64_pstate_type
;
178 sparc64_fsr_type (struct gdbarch
*gdbarch
)
180 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
182 if (!tdep
->sparc64_fsr_type
)
186 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_fsr", 8);
187 append_flags_type_flag (type
, 0, "NXA");
188 append_flags_type_flag (type
, 1, "DZA");
189 append_flags_type_flag (type
, 2, "UFA");
190 append_flags_type_flag (type
, 3, "OFA");
191 append_flags_type_flag (type
, 4, "NVA");
192 append_flags_type_flag (type
, 5, "NXC");
193 append_flags_type_flag (type
, 6, "DZC");
194 append_flags_type_flag (type
, 7, "UFC");
195 append_flags_type_flag (type
, 8, "OFC");
196 append_flags_type_flag (type
, 9, "NVC");
197 append_flags_type_flag (type
, 22, "NS");
198 append_flags_type_flag (type
, 23, "NXM");
199 append_flags_type_flag (type
, 24, "DZM");
200 append_flags_type_flag (type
, 25, "UFM");
201 append_flags_type_flag (type
, 26, "OFM");
202 append_flags_type_flag (type
, 27, "NVM");
204 tdep
->sparc64_fsr_type
= type
;
207 return tdep
->sparc64_fsr_type
;
211 sparc64_fprs_type (struct gdbarch
*gdbarch
)
213 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
215 if (!tdep
->sparc64_fprs_type
)
219 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_fprs", 8);
220 append_flags_type_flag (type
, 0, "DL");
221 append_flags_type_flag (type
, 1, "DU");
222 append_flags_type_flag (type
, 2, "FEF");
224 tdep
->sparc64_fprs_type
= type
;
227 return tdep
->sparc64_fprs_type
;
231 /* Register information. */
233 static const char *sparc64_register_names
[] =
235 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
236 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
237 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
238 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7",
240 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
241 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
242 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
243 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
244 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
245 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
249 /* FIXME: Give "state" a name until we start using register groups. */
256 /* Total number of registers. */
257 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
259 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
260 registers as "psuedo" registers. */
262 static const char *sparc64_pseudo_register_names
[] =
264 "cwp", "pstate", "asi", "ccr",
266 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
267 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
268 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
269 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
271 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
272 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
275 /* Total number of pseudo registers. */
276 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
278 /* Return the name of register REGNUM. */
281 sparc64_register_name (struct gdbarch
*gdbarch
, int regnum
)
283 if (regnum
>= 0 && regnum
< SPARC64_NUM_REGS
)
284 return sparc64_register_names
[regnum
];
286 if (regnum
>= SPARC64_NUM_REGS
287 && regnum
< SPARC64_NUM_REGS
+ SPARC64_NUM_PSEUDO_REGS
)
288 return sparc64_pseudo_register_names
[regnum
- SPARC64_NUM_REGS
];
293 /* Return the GDB type object for the "standard" data type of data in
297 sparc64_register_type (struct gdbarch
*gdbarch
, int regnum
)
301 if (regnum
== SPARC_SP_REGNUM
|| regnum
== SPARC_FP_REGNUM
)
302 return builtin_type (gdbarch
)->builtin_data_ptr
;
303 if (regnum
>= SPARC_G0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
)
304 return builtin_type (gdbarch
)->builtin_int64
;
305 if (regnum
>= SPARC_F0_REGNUM
&& regnum
<= SPARC_F31_REGNUM
)
306 return builtin_type (gdbarch
)->builtin_float
;
307 if (regnum
>= SPARC64_F32_REGNUM
&& regnum
<= SPARC64_F62_REGNUM
)
308 return builtin_type (gdbarch
)->builtin_double
;
309 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
310 return builtin_type (gdbarch
)->builtin_func_ptr
;
311 /* This raw register contains the contents of %cwp, %pstate, %asi
312 and %ccr as laid out in a %tstate register. */
313 if (regnum
== SPARC64_STATE_REGNUM
)
314 return builtin_type (gdbarch
)->builtin_int64
;
315 if (regnum
== SPARC64_FSR_REGNUM
)
316 return sparc64_fsr_type (gdbarch
);
317 if (regnum
== SPARC64_FPRS_REGNUM
)
318 return sparc64_fprs_type (gdbarch
);
319 /* "Although Y is a 64-bit register, its high-order 32 bits are
320 reserved and always read as 0." */
321 if (regnum
== SPARC64_Y_REGNUM
)
322 return builtin_type (gdbarch
)->builtin_int64
;
324 /* Pseudo registers. */
326 if (regnum
== SPARC64_CWP_REGNUM
)
327 return builtin_type (gdbarch
)->builtin_int64
;
328 if (regnum
== SPARC64_PSTATE_REGNUM
)
329 return sparc64_pstate_type (gdbarch
);
330 if (regnum
== SPARC64_ASI_REGNUM
)
331 return builtin_type (gdbarch
)->builtin_int64
;
332 if (regnum
== SPARC64_CCR_REGNUM
)
333 return builtin_type (gdbarch
)->builtin_int64
;
334 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
335 return builtin_type (gdbarch
)->builtin_double
;
336 if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
337 return builtin_type (gdbarch
)->builtin_long_double
;
339 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
342 static enum register_status
343 sparc64_pseudo_register_read (struct gdbarch
*gdbarch
,
344 struct regcache
*regcache
,
345 int regnum
, gdb_byte
*buf
)
347 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
348 enum register_status status
;
350 gdb_assert (regnum
>= SPARC64_NUM_REGS
);
352 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
354 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
355 status
= regcache_raw_read (regcache
, regnum
, buf
);
356 if (status
== REG_VALID
)
357 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 4);
360 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
362 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
363 return regcache_raw_read (regcache
, regnum
, buf
);
365 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
367 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
369 status
= regcache_raw_read (regcache
, regnum
, buf
);
370 if (status
== REG_VALID
)
371 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 4);
372 if (status
== REG_VALID
)
373 status
= regcache_raw_read (regcache
, regnum
+ 2, buf
+ 8);
374 if (status
== REG_VALID
)
375 status
= regcache_raw_read (regcache
, regnum
+ 3, buf
+ 12);
379 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
381 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
383 status
= regcache_raw_read (regcache
, regnum
, buf
);
384 if (status
== REG_VALID
)
385 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 8);
389 else if (regnum
== SPARC64_CWP_REGNUM
390 || regnum
== SPARC64_PSTATE_REGNUM
391 || regnum
== SPARC64_ASI_REGNUM
392 || regnum
== SPARC64_CCR_REGNUM
)
396 status
= regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
397 if (status
!= REG_VALID
)
402 case SPARC64_CWP_REGNUM
:
403 state
= (state
>> 0) & ((1 << 5) - 1);
405 case SPARC64_PSTATE_REGNUM
:
406 state
= (state
>> 8) & ((1 << 12) - 1);
408 case SPARC64_ASI_REGNUM
:
409 state
= (state
>> 24) & ((1 << 8) - 1);
411 case SPARC64_CCR_REGNUM
:
412 state
= (state
>> 32) & ((1 << 8) - 1);
415 store_unsigned_integer (buf
, 8, byte_order
, state
);
422 sparc64_pseudo_register_write (struct gdbarch
*gdbarch
,
423 struct regcache
*regcache
,
424 int regnum
, const gdb_byte
*buf
)
426 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
427 gdb_assert (regnum
>= SPARC64_NUM_REGS
);
429 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
431 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
432 regcache_raw_write (regcache
, regnum
, buf
);
433 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 4);
435 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
437 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
438 regcache_raw_write (regcache
, regnum
, buf
);
440 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
442 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
443 regcache_raw_write (regcache
, regnum
, buf
);
444 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 4);
445 regcache_raw_write (regcache
, regnum
+ 2, buf
+ 8);
446 regcache_raw_write (regcache
, regnum
+ 3, buf
+ 12);
448 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
450 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
451 regcache_raw_write (regcache
, regnum
, buf
);
452 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 8);
454 else if (regnum
== SPARC64_CWP_REGNUM
455 || regnum
== SPARC64_PSTATE_REGNUM
456 || regnum
== SPARC64_ASI_REGNUM
457 || regnum
== SPARC64_CCR_REGNUM
)
459 ULONGEST state
, bits
;
461 regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
462 bits
= extract_unsigned_integer (buf
, 8, byte_order
);
465 case SPARC64_CWP_REGNUM
:
466 state
|= ((bits
& ((1 << 5) - 1)) << 0);
468 case SPARC64_PSTATE_REGNUM
:
469 state
|= ((bits
& ((1 << 12) - 1)) << 8);
471 case SPARC64_ASI_REGNUM
:
472 state
|= ((bits
& ((1 << 8) - 1)) << 24);
474 case SPARC64_CCR_REGNUM
:
475 state
|= ((bits
& ((1 << 8) - 1)) << 32);
478 regcache_raw_write_unsigned (regcache
, SPARC64_STATE_REGNUM
, state
);
483 /* Return PC of first real instruction of the function starting at
487 sparc64_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR start_pc
)
489 struct symtab_and_line sal
;
490 CORE_ADDR func_start
, func_end
;
491 struct sparc_frame_cache cache
;
493 /* This is the preferred method, find the end of the prologue by
494 using the debugging information. */
495 if (find_pc_partial_function (start_pc
, NULL
, &func_start
, &func_end
))
497 sal
= find_pc_line (func_start
, 0);
499 if (sal
.end
< func_end
500 && start_pc
<= sal
.end
)
504 return sparc_analyze_prologue (gdbarch
, start_pc
, 0xffffffffffffffffULL
,
510 static struct sparc_frame_cache
*
511 sparc64_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
513 return sparc_frame_cache (this_frame
, this_cache
);
517 sparc64_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
518 struct frame_id
*this_id
)
520 struct sparc_frame_cache
*cache
=
521 sparc64_frame_cache (this_frame
, this_cache
);
523 /* This marks the outermost frame. */
524 if (cache
->base
== 0)
527 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
530 static struct value
*
531 sparc64_frame_prev_register (struct frame_info
*this_frame
, void **this_cache
,
534 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
535 struct sparc_frame_cache
*cache
=
536 sparc64_frame_cache (this_frame
, this_cache
);
538 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
540 CORE_ADDR pc
= (regnum
== SPARC64_NPC_REGNUM
) ? 4 : 0;
543 (cache
->copied_regs_mask
& 0x80) ? SPARC_I7_REGNUM
: SPARC_O7_REGNUM
;
544 pc
+= get_frame_register_unsigned (this_frame
, regnum
) + 8;
545 return frame_unwind_got_constant (this_frame
, regnum
, pc
);
548 /* Handle StackGhost. */
550 ULONGEST wcookie
= sparc_fetch_wcookie (gdbarch
);
552 if (wcookie
!= 0 && !cache
->frameless_p
&& regnum
== SPARC_I7_REGNUM
)
554 CORE_ADDR addr
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
557 /* Read the value in from memory. */
558 i7
= get_frame_memory_unsigned (this_frame
, addr
, 8);
559 return frame_unwind_got_constant (this_frame
, regnum
, i7
^ wcookie
);
563 /* The previous frame's `local' and `in' registers may have been saved
564 in the register save area. */
565 if (regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
566 && (cache
->saved_regs_mask
& (1 << (regnum
- SPARC_L0_REGNUM
))))
568 CORE_ADDR addr
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
570 return frame_unwind_got_memory (this_frame
, regnum
, addr
);
573 /* The previous frame's `out' registers may be accessible as the current
574 frame's `in' registers. */
575 if (regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
576 && (cache
->copied_regs_mask
& (1 << (regnum
- SPARC_O0_REGNUM
))))
577 regnum
+= (SPARC_I0_REGNUM
- SPARC_O0_REGNUM
);
579 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
582 static const struct frame_unwind sparc64_frame_unwind
=
585 default_frame_unwind_stop_reason
,
586 sparc64_frame_this_id
,
587 sparc64_frame_prev_register
,
589 default_frame_sniffer
594 sparc64_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
596 struct sparc_frame_cache
*cache
=
597 sparc64_frame_cache (this_frame
, this_cache
);
602 static const struct frame_base sparc64_frame_base
=
604 &sparc64_frame_unwind
,
605 sparc64_frame_base_address
,
606 sparc64_frame_base_address
,
607 sparc64_frame_base_address
610 /* Check whether TYPE must be 16-byte aligned. */
613 sparc64_16_byte_align_p (struct type
*type
)
615 if (sparc64_floating_p (type
) && TYPE_LENGTH (type
) == 16)
618 if (sparc64_structure_or_union_p (type
))
622 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
624 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
626 if (sparc64_16_byte_align_p (subtype
))
634 /* Store floating fields of element ELEMENT of an "parameter array"
635 that has type TYPE and is stored at BITPOS in VALBUF in the
636 apropriate registers of REGCACHE. This function can be called
637 recursively and therefore handles floating types in addition to
641 sparc64_store_floating_fields (struct regcache
*regcache
, struct type
*type
,
642 const gdb_byte
*valbuf
, int element
, int bitpos
)
644 int len
= TYPE_LENGTH (type
);
646 gdb_assert (element
< 16);
648 if (sparc64_floating_p (type
)
649 || (sparc64_complex_floating_p (type
) && len
<= 16))
655 gdb_assert (bitpos
== 0);
656 gdb_assert ((element
% 2) == 0);
658 regnum
= SPARC64_Q0_REGNUM
+ element
/ 2;
659 regcache_cooked_write (regcache
, regnum
, valbuf
);
663 gdb_assert (bitpos
== 0 || bitpos
== 64);
665 regnum
= SPARC64_D0_REGNUM
+ element
+ bitpos
/ 64;
666 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
670 gdb_assert (len
== 4);
671 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 128);
673 regnum
= SPARC_F0_REGNUM
+ element
* 2 + bitpos
/ 32;
674 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
677 else if (sparc64_structure_or_union_p (type
))
681 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
683 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
684 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
686 sparc64_store_floating_fields (regcache
, subtype
, valbuf
,
690 /* GCC has an interesting bug. If TYPE is a structure that has
691 a single `float' member, GCC doesn't treat it as a structure
692 at all, but rather as an ordinary `float' argument. This
693 argument will be stored in %f1, as required by the psABI.
694 However, as a member of a structure the psABI requires it to
695 be stored in %f0. This bug is present in GCC 3.3.2, but
696 probably in older releases to. To appease GCC, if a
697 structure has only a single `float' member, we store its
698 value in %f1 too (we already have stored in %f0). */
699 if (TYPE_NFIELDS (type
) == 1)
701 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
703 if (sparc64_floating_p (subtype
) && TYPE_LENGTH (subtype
) == 4)
704 regcache_cooked_write (regcache
, SPARC_F1_REGNUM
, valbuf
);
709 /* Fetch floating fields from a variable of type TYPE from the
710 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
711 in VALBUF. This function can be called recursively and therefore
712 handles floating types in addition to structures. */
715 sparc64_extract_floating_fields (struct regcache
*regcache
, struct type
*type
,
716 gdb_byte
*valbuf
, int bitpos
)
718 if (sparc64_floating_p (type
))
720 int len
= TYPE_LENGTH (type
);
725 gdb_assert (bitpos
== 0 || bitpos
== 128);
727 regnum
= SPARC64_Q0_REGNUM
+ bitpos
/ 128;
728 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
732 gdb_assert (bitpos
% 64 == 0 && bitpos
>= 0 && bitpos
< 256);
734 regnum
= SPARC64_D0_REGNUM
+ bitpos
/ 64;
735 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
739 gdb_assert (len
== 4);
740 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 256);
742 regnum
= SPARC_F0_REGNUM
+ bitpos
/ 32;
743 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
746 else if (sparc64_structure_or_union_p (type
))
750 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
752 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
753 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
755 sparc64_extract_floating_fields (regcache
, subtype
, valbuf
, subpos
);
760 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
761 non-zero) in REGCACHE and on the stack (starting from address SP). */
764 sparc64_store_arguments (struct regcache
*regcache
, int nargs
,
765 struct value
**args
, CORE_ADDR sp
,
766 int struct_return
, CORE_ADDR struct_addr
)
768 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
769 /* Number of extended words in the "parameter array". */
770 int num_elements
= 0;
774 /* Take BIAS into account. */
777 /* First we calculate the number of extended words in the "parameter
778 array". While doing so we also convert some of the arguments. */
783 for (i
= 0; i
< nargs
; i
++)
785 struct type
*type
= value_type (args
[i
]);
786 int len
= TYPE_LENGTH (type
);
788 if (sparc64_structure_or_union_p (type
))
790 /* Structure or Union arguments. */
793 if (num_elements
% 2 && sparc64_16_byte_align_p (type
))
795 num_elements
+= ((len
+ 7) / 8);
799 /* The psABI says that "Structures or unions larger than
800 sixteen bytes are copied by the caller and passed
801 indirectly; the caller will pass the address of a
802 correctly aligned structure value. This sixty-four
803 bit address will occupy one word in the parameter
804 array, and may be promoted to an %o register like any
805 other pointer value." Allocate memory for these
806 values on the stack. */
809 /* Use 16-byte alignment for these values. That's
810 always correct, and wasting a few bytes shouldn't be
814 write_memory (sp
, value_contents (args
[i
]), len
);
815 args
[i
] = value_from_pointer (lookup_pointer_type (type
), sp
);
819 else if (sparc64_floating_p (type
))
821 /* Floating arguments. */
825 /* The psABI says that "Each quad-precision parameter
826 value will be assigned to two extended words in the
830 /* The psABI says that "Long doubles must be
831 quad-aligned, and thus a hole might be introduced
832 into the parameter array to force alignment." Skip
833 an element if necessary. */
834 if (num_elements
% 2)
842 /* Integral and pointer arguments. */
843 gdb_assert (sparc64_integral_or_pointer_p (type
));
845 /* The psABI says that "Each argument value of integral type
846 smaller than an extended word will be widened by the
847 caller to an extended word according to the signed-ness
848 of the argument type." */
850 args
[i
] = value_cast (builtin_type (gdbarch
)->builtin_int64
,
856 /* Allocate the "parameter array". */
857 sp
-= num_elements
* 8;
859 /* The psABI says that "Every stack frame must be 16-byte aligned." */
862 /* Now we store the arguments in to the "paramater array". Some
863 Integer or Pointer arguments and Structure or Union arguments
864 will be passed in %o registers. Some Floating arguments and
865 floating members of structures are passed in floating-point
866 registers. However, for functions with variable arguments,
867 floating arguments are stored in an %0 register, and for
868 functions without a prototype floating arguments are stored in
869 both a floating-point and an %o registers, or a floating-point
870 register and memory. To simplify the logic here we always pass
871 arguments in memory, an %o register, and a floating-point
872 register if appropriate. This should be no problem since the
873 contents of any unused memory or registers in the "parameter
874 array" are undefined. */
878 regcache_cooked_write_unsigned (regcache
, SPARC_O0_REGNUM
, struct_addr
);
882 for (i
= 0; i
< nargs
; i
++)
884 const gdb_byte
*valbuf
= value_contents (args
[i
]);
885 struct type
*type
= value_type (args
[i
]);
886 int len
= TYPE_LENGTH (type
);
890 if (sparc64_structure_or_union_p (type
))
892 /* Structure or Union arguments. */
893 gdb_assert (len
<= 16);
894 memset (buf
, 0, sizeof (buf
));
895 valbuf
= memcpy (buf
, valbuf
, len
);
897 if (element
% 2 && sparc64_16_byte_align_p (type
))
902 regnum
= SPARC_O0_REGNUM
+ element
;
903 if (len
> 8 && element
< 5)
904 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
908 sparc64_store_floating_fields (regcache
, type
, valbuf
, element
, 0);
910 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
912 /* Floating arguments. */
918 regnum
= SPARC64_Q0_REGNUM
+ element
/ 2;
923 regnum
= SPARC64_D0_REGNUM
+ element
;
927 /* The psABI says "Each single-precision parameter value
928 will be assigned to one extended word in the
929 parameter array, and right-justified within that
930 word; the left half (even floatregister) is
931 undefined." Even though the psABI says that "the
932 left half is undefined", set it to zero here. */
934 memcpy (buf
+ 4, valbuf
, 4);
938 regnum
= SPARC64_D0_REGNUM
+ element
;
943 /* Integral and pointer arguments. */
944 gdb_assert (len
== 8);
946 regnum
= SPARC_O0_REGNUM
+ element
;
951 regcache_cooked_write (regcache
, regnum
, valbuf
);
953 /* If we're storing the value in a floating-point register,
954 also store it in the corresponding %0 register(s). */
955 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D10_REGNUM
)
957 gdb_assert (element
< 6);
958 regnum
= SPARC_O0_REGNUM
+ element
;
959 regcache_cooked_write (regcache
, regnum
, valbuf
);
961 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q8_REGNUM
)
963 gdb_assert (element
< 6);
964 regnum
= SPARC_O0_REGNUM
+ element
;
965 regcache_cooked_write (regcache
, regnum
, valbuf
);
966 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
970 /* Always store the argument in memory. */
971 write_memory (sp
+ element
* 8, valbuf
, len
);
972 element
+= ((len
+ 7) / 8);
975 gdb_assert (element
== num_elements
);
977 /* Take BIAS into account. */
983 sparc64_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR address
)
985 /* The ABI requires 16-byte alignment. */
986 return address
& ~0xf;
990 sparc64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
991 struct regcache
*regcache
, CORE_ADDR bp_addr
,
992 int nargs
, struct value
**args
, CORE_ADDR sp
,
993 int struct_return
, CORE_ADDR struct_addr
)
995 /* Set return address. */
996 regcache_cooked_write_unsigned (regcache
, SPARC_O7_REGNUM
, bp_addr
- 8);
998 /* Set up function arguments. */
999 sp
= sparc64_store_arguments (regcache
, nargs
, args
, sp
,
1000 struct_return
, struct_addr
);
1002 /* Allocate the register save area. */
1005 /* Stack should be 16-byte aligned at this point. */
1006 gdb_assert ((sp
+ BIAS
) % 16 == 0);
1008 /* Finally, update the stack pointer. */
1009 regcache_cooked_write_unsigned (regcache
, SPARC_SP_REGNUM
, sp
);
1015 /* Extract from an array REGBUF containing the (raw) register state, a
1016 function return value of TYPE, and copy that into VALBUF. */
1019 sparc64_extract_return_value (struct type
*type
, struct regcache
*regcache
,
1022 int len
= TYPE_LENGTH (type
);
1026 if (sparc64_structure_or_union_p (type
))
1028 /* Structure or Union return values. */
1029 gdb_assert (len
<= 32);
1031 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1032 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1033 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1034 sparc64_extract_floating_fields (regcache
, type
, buf
, 0);
1035 memcpy (valbuf
, buf
, len
);
1037 else if (sparc64_floating_p (type
))
1039 /* Floating return values. */
1040 for (i
= 0; i
< len
/ 4; i
++)
1041 regcache_cooked_read (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1042 memcpy (valbuf
, buf
, len
);
1044 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1046 /* Small arrays are returned the same way as small structures. */
1047 gdb_assert (len
<= 32);
1049 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1050 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1051 memcpy (valbuf
, buf
, len
);
1055 /* Integral and pointer return values. */
1056 gdb_assert (sparc64_integral_or_pointer_p (type
));
1058 /* Just stripping off any unused bytes should preserve the
1059 signed-ness just fine. */
1060 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
, buf
);
1061 memcpy (valbuf
, buf
+ 8 - len
, len
);
1065 /* Write into the appropriate registers a function return value stored
1066 in VALBUF of type TYPE. */
1069 sparc64_store_return_value (struct type
*type
, struct regcache
*regcache
,
1070 const gdb_byte
*valbuf
)
1072 int len
= TYPE_LENGTH (type
);
1076 if (sparc64_structure_or_union_p (type
))
1078 /* Structure or Union return values. */
1079 gdb_assert (len
<= 32);
1081 /* Simplify matters by storing the complete value (including
1082 floating members) into %o0 and %o1. Floating members are
1083 also store in the appropriate floating-point registers. */
1084 memset (buf
, 0, sizeof (buf
));
1085 memcpy (buf
, valbuf
, len
);
1086 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1087 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1088 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1089 sparc64_store_floating_fields (regcache
, type
, buf
, 0, 0);
1091 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
1093 /* Floating return values. */
1094 memcpy (buf
, valbuf
, len
);
1095 for (i
= 0; i
< len
/ 4; i
++)
1096 regcache_cooked_write (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1098 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1100 /* Small arrays are returned the same way as small structures. */
1101 gdb_assert (len
<= 32);
1103 memset (buf
, 0, sizeof (buf
));
1104 memcpy (buf
, valbuf
, len
);
1105 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1106 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1110 /* Integral and pointer return values. */
1111 gdb_assert (sparc64_integral_or_pointer_p (type
));
1113 /* ??? Do we need to do any sign-extension here? */
1115 memcpy (buf
+ 8 - len
, valbuf
, len
);
1116 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
, buf
);
1120 static enum return_value_convention
1121 sparc64_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
1122 struct type
*type
, struct regcache
*regcache
,
1123 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1125 if (TYPE_LENGTH (type
) > 32)
1126 return RETURN_VALUE_STRUCT_CONVENTION
;
1129 sparc64_extract_return_value (type
, regcache
, readbuf
);
1131 sparc64_store_return_value (type
, regcache
, writebuf
);
1133 return RETURN_VALUE_REGISTER_CONVENTION
;
1138 sparc64_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1139 struct dwarf2_frame_state_reg
*reg
,
1140 struct frame_info
*this_frame
)
1144 case SPARC_G0_REGNUM
:
1145 /* Since %g0 is always zero, there is no point in saving it, and
1146 people will be inclined omit it from the CFI. Make sure we
1147 don't warn about that. */
1148 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1150 case SPARC_SP_REGNUM
:
1151 reg
->how
= DWARF2_FRAME_REG_CFA
;
1153 case SPARC64_PC_REGNUM
:
1154 reg
->how
= DWARF2_FRAME_REG_RA_OFFSET
;
1155 reg
->loc
.offset
= 8;
1157 case SPARC64_NPC_REGNUM
:
1158 reg
->how
= DWARF2_FRAME_REG_RA_OFFSET
;
1159 reg
->loc
.offset
= 12;
1165 sparc64_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1167 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1169 tdep
->pc_regnum
= SPARC64_PC_REGNUM
;
1170 tdep
->npc_regnum
= SPARC64_NPC_REGNUM
;
1172 /* This is what all the fuss is about. */
1173 set_gdbarch_long_bit (gdbarch
, 64);
1174 set_gdbarch_long_long_bit (gdbarch
, 64);
1175 set_gdbarch_ptr_bit (gdbarch
, 64);
1177 set_gdbarch_num_regs (gdbarch
, SPARC64_NUM_REGS
);
1178 set_gdbarch_register_name (gdbarch
, sparc64_register_name
);
1179 set_gdbarch_register_type (gdbarch
, sparc64_register_type
);
1180 set_gdbarch_num_pseudo_regs (gdbarch
, SPARC64_NUM_PSEUDO_REGS
);
1181 set_gdbarch_pseudo_register_read (gdbarch
, sparc64_pseudo_register_read
);
1182 set_gdbarch_pseudo_register_write (gdbarch
, sparc64_pseudo_register_write
);
1184 /* Register numbers of various important registers. */
1185 set_gdbarch_pc_regnum (gdbarch
, SPARC64_PC_REGNUM
); /* %pc */
1187 /* Call dummy code. */
1188 set_gdbarch_frame_align (gdbarch
, sparc64_frame_align
);
1189 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
1190 set_gdbarch_push_dummy_code (gdbarch
, NULL
);
1191 set_gdbarch_push_dummy_call (gdbarch
, sparc64_push_dummy_call
);
1193 set_gdbarch_return_value (gdbarch
, sparc64_return_value
);
1194 set_gdbarch_stabs_argument_has_addr
1195 (gdbarch
, default_stabs_argument_has_addr
);
1197 set_gdbarch_skip_prologue (gdbarch
, sparc64_skip_prologue
);
1199 /* Hook in the DWARF CFI frame unwinder. */
1200 dwarf2_frame_set_init_reg (gdbarch
, sparc64_dwarf2_frame_init_reg
);
1201 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1202 StackGhost issues have been resolved. */
1204 frame_unwind_append_unwinder (gdbarch
, &sparc64_frame_unwind
);
1205 frame_base_set_default (gdbarch
, &sparc64_frame_base
);
1209 /* Helper functions for dealing with register sets. */
1211 #define TSTATE_CWP 0x000000000000001fULL
1212 #define TSTATE_ICC 0x0000000f00000000ULL
1213 #define TSTATE_XCC 0x000000f000000000ULL
1215 #define PSR_S 0x00000080
1216 #define PSR_ICC 0x00f00000
1217 #define PSR_VERS 0x0f000000
1218 #define PSR_IMPL 0xf0000000
1219 #define PSR_V8PLUS 0xff000000
1220 #define PSR_XCC 0x000f0000
1223 sparc64_supply_gregset (const struct sparc_gregset
*gregset
,
1224 struct regcache
*regcache
,
1225 int regnum
, const void *gregs
)
1227 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1228 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1229 int sparc32
= (gdbarch_ptr_bit (gdbarch
) == 32);
1230 const gdb_byte
*regs
= gregs
;
1231 gdb_byte zero
[8] = { 0 };
1236 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1238 int offset
= gregset
->r_tstate_offset
;
1239 ULONGEST tstate
, psr
;
1242 tstate
= extract_unsigned_integer (regs
+ offset
, 8, byte_order
);
1243 psr
= ((tstate
& TSTATE_CWP
) | PSR_S
| ((tstate
& TSTATE_ICC
) >> 12)
1244 | ((tstate
& TSTATE_XCC
) >> 20) | PSR_V8PLUS
);
1245 store_unsigned_integer (buf
, 4, byte_order
, psr
);
1246 regcache_raw_supply (regcache
, SPARC32_PSR_REGNUM
, buf
);
1249 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1250 regcache_raw_supply (regcache
, SPARC32_PC_REGNUM
,
1251 regs
+ gregset
->r_pc_offset
+ 4);
1253 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1254 regcache_raw_supply (regcache
, SPARC32_NPC_REGNUM
,
1255 regs
+ gregset
->r_npc_offset
+ 4);
1257 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1259 int offset
= gregset
->r_y_offset
+ 8 - gregset
->r_y_size
;
1260 regcache_raw_supply (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1265 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1266 regcache_raw_supply (regcache
, SPARC64_STATE_REGNUM
,
1267 regs
+ gregset
->r_tstate_offset
);
1269 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1270 regcache_raw_supply (regcache
, SPARC64_PC_REGNUM
,
1271 regs
+ gregset
->r_pc_offset
);
1273 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1274 regcache_raw_supply (regcache
, SPARC64_NPC_REGNUM
,
1275 regs
+ gregset
->r_npc_offset
);
1277 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1282 memcpy (buf
+ 8 - gregset
->r_y_size
,
1283 regs
+ gregset
->r_y_offset
, gregset
->r_y_size
);
1284 regcache_raw_supply (regcache
, SPARC64_Y_REGNUM
, buf
);
1287 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1288 && gregset
->r_fprs_offset
!= -1)
1289 regcache_raw_supply (regcache
, SPARC64_FPRS_REGNUM
,
1290 regs
+ gregset
->r_fprs_offset
);
1293 if (regnum
== SPARC_G0_REGNUM
|| regnum
== -1)
1294 regcache_raw_supply (regcache
, SPARC_G0_REGNUM
, &zero
);
1296 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1298 int offset
= gregset
->r_g1_offset
;
1303 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1305 if (regnum
== i
|| regnum
== -1)
1306 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1311 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1313 /* Not all of the register set variants include Locals and
1314 Inputs. For those that don't, we read them off the stack. */
1315 if (gregset
->r_l0_offset
== -1)
1319 regcache_cooked_read_unsigned (regcache
, SPARC_SP_REGNUM
, &sp
);
1320 sparc_supply_rwindow (regcache
, sp
, regnum
);
1324 int offset
= gregset
->r_l0_offset
;
1329 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1331 if (regnum
== i
|| regnum
== -1)
1332 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1340 sparc64_collect_gregset (const struct sparc_gregset
*gregset
,
1341 const struct regcache
*regcache
,
1342 int regnum
, void *gregs
)
1344 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1345 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1346 int sparc32
= (gdbarch_ptr_bit (gdbarch
) == 32);
1347 gdb_byte
*regs
= gregs
;
1352 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1354 int offset
= gregset
->r_tstate_offset
;
1355 ULONGEST tstate
, psr
;
1358 tstate
= extract_unsigned_integer (regs
+ offset
, 8, byte_order
);
1359 regcache_raw_collect (regcache
, SPARC32_PSR_REGNUM
, buf
);
1360 psr
= extract_unsigned_integer (buf
, 4, byte_order
);
1361 tstate
|= (psr
& PSR_ICC
) << 12;
1362 if ((psr
& (PSR_VERS
| PSR_IMPL
)) == PSR_V8PLUS
)
1363 tstate
|= (psr
& PSR_XCC
) << 20;
1364 store_unsigned_integer (buf
, 8, byte_order
, tstate
);
1365 memcpy (regs
+ offset
, buf
, 8);
1368 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1369 regcache_raw_collect (regcache
, SPARC32_PC_REGNUM
,
1370 regs
+ gregset
->r_pc_offset
+ 4);
1372 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1373 regcache_raw_collect (regcache
, SPARC32_NPC_REGNUM
,
1374 regs
+ gregset
->r_npc_offset
+ 4);
1376 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1378 int offset
= gregset
->r_y_offset
+ 8 - gregset
->r_y_size
;
1379 regcache_raw_collect (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1384 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1385 regcache_raw_collect (regcache
, SPARC64_STATE_REGNUM
,
1386 regs
+ gregset
->r_tstate_offset
);
1388 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1389 regcache_raw_collect (regcache
, SPARC64_PC_REGNUM
,
1390 regs
+ gregset
->r_pc_offset
);
1392 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1393 regcache_raw_collect (regcache
, SPARC64_NPC_REGNUM
,
1394 regs
+ gregset
->r_npc_offset
);
1396 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1400 regcache_raw_collect (regcache
, SPARC64_Y_REGNUM
, buf
);
1401 memcpy (regs
+ gregset
->r_y_offset
,
1402 buf
+ 8 - gregset
->r_y_size
, gregset
->r_y_size
);
1405 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1406 && gregset
->r_fprs_offset
!= -1)
1407 regcache_raw_collect (regcache
, SPARC64_FPRS_REGNUM
,
1408 regs
+ gregset
->r_fprs_offset
);
1412 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1414 int offset
= gregset
->r_g1_offset
;
1419 /* %g0 is always zero. */
1420 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1422 if (regnum
== i
|| regnum
== -1)
1423 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1428 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1430 /* Not all of the register set variants include Locals and
1431 Inputs. For those that don't, we read them off the stack. */
1432 if (gregset
->r_l0_offset
!= -1)
1434 int offset
= gregset
->r_l0_offset
;
1439 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1441 if (regnum
== i
|| regnum
== -1)
1442 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1450 sparc64_supply_fpregset (struct regcache
*regcache
,
1451 int regnum
, const void *fpregs
)
1453 int sparc32
= (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32);
1454 const gdb_byte
*regs
= fpregs
;
1457 for (i
= 0; i
< 32; i
++)
1459 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1460 regcache_raw_supply (regcache
, SPARC_F0_REGNUM
+ i
, regs
+ (i
* 4));
1465 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1466 regcache_raw_supply (regcache
, SPARC32_FSR_REGNUM
,
1467 regs
+ (32 * 4) + (16 * 8) + 4);
1471 for (i
= 0; i
< 16; i
++)
1473 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1474 regcache_raw_supply (regcache
, SPARC64_F32_REGNUM
+ i
,
1475 regs
+ (32 * 4) + (i
* 8));
1478 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1479 regcache_raw_supply (regcache
, SPARC64_FSR_REGNUM
,
1480 regs
+ (32 * 4) + (16 * 8));
1485 sparc64_collect_fpregset (const struct regcache
*regcache
,
1486 int regnum
, void *fpregs
)
1488 int sparc32
= (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32);
1489 gdb_byte
*regs
= fpregs
;
1492 for (i
= 0; i
< 32; i
++)
1494 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1495 regcache_raw_collect (regcache
, SPARC_F0_REGNUM
+ i
, regs
+ (i
* 4));
1500 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1501 regcache_raw_collect (regcache
, SPARC32_FSR_REGNUM
,
1502 regs
+ (32 * 4) + (16 * 8) + 4);
1506 for (i
= 0; i
< 16; i
++)
1508 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1509 regcache_raw_collect (regcache
, SPARC64_F32_REGNUM
+ i
,
1510 regs
+ (32 * 4) + (i
* 8));
1513 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1514 regcache_raw_collect (regcache
, SPARC64_FSR_REGNUM
,
1515 regs
+ (32 * 4) + (16 * 8));