1 /* Target-dependent code for UltraSPARC.
3 Copyright (C) 2003-2014 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"
39 #include "sparc64-tdep.h"
41 /* This file implements the SPARC 64-bit ABI as defined by the
42 section "Low-Level System Information" of the SPARC Compliance
43 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
46 /* Please use the sparc32_-prefix for 32-bit specific code, the
47 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
48 code can handle both. */
50 /* The functions on this page are intended to be used to classify
51 function arguments. */
53 /* Check whether TYPE is "Integral or Pointer". */
56 sparc64_integral_or_pointer_p (const struct type
*type
)
58 switch (TYPE_CODE (type
))
66 int len
= TYPE_LENGTH (type
);
67 gdb_assert (len
== 1 || len
== 2 || len
== 4 || len
== 8);
73 int len
= TYPE_LENGTH (type
);
74 gdb_assert (len
== 8);
84 /* Check whether TYPE is "Floating". */
87 sparc64_floating_p (const struct type
*type
)
89 switch (TYPE_CODE (type
))
93 int len
= TYPE_LENGTH (type
);
94 gdb_assert (len
== 4 || len
== 8 || len
== 16);
104 /* Check whether TYPE is "Complex Floating". */
107 sparc64_complex_floating_p (const struct type
*type
)
109 switch (TYPE_CODE (type
))
111 case TYPE_CODE_COMPLEX
:
113 int len
= TYPE_LENGTH (type
);
114 gdb_assert (len
== 8 || len
== 16 || len
== 32);
124 /* Check whether TYPE is "Structure or Union".
126 In terms of Ada subprogram calls, arrays are treated the same as
127 struct and union types. So this function also returns non-zero
131 sparc64_structure_or_union_p (const struct type
*type
)
133 switch (TYPE_CODE (type
))
135 case TYPE_CODE_STRUCT
:
136 case TYPE_CODE_UNION
:
137 case TYPE_CODE_ARRAY
:
147 /* Construct types for ISA-specific registers. */
150 sparc64_pstate_type (struct gdbarch
*gdbarch
)
152 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
154 if (!tdep
->sparc64_pstate_type
)
158 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_pstate", 8);
159 append_flags_type_flag (type
, 0, "AG");
160 append_flags_type_flag (type
, 1, "IE");
161 append_flags_type_flag (type
, 2, "PRIV");
162 append_flags_type_flag (type
, 3, "AM");
163 append_flags_type_flag (type
, 4, "PEF");
164 append_flags_type_flag (type
, 5, "RED");
165 append_flags_type_flag (type
, 8, "TLE");
166 append_flags_type_flag (type
, 9, "CLE");
167 append_flags_type_flag (type
, 10, "PID0");
168 append_flags_type_flag (type
, 11, "PID1");
170 tdep
->sparc64_pstate_type
= type
;
173 return tdep
->sparc64_pstate_type
;
177 sparc64_fsr_type (struct gdbarch
*gdbarch
)
179 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
181 if (!tdep
->sparc64_fsr_type
)
185 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_fsr", 8);
186 append_flags_type_flag (type
, 0, "NXA");
187 append_flags_type_flag (type
, 1, "DZA");
188 append_flags_type_flag (type
, 2, "UFA");
189 append_flags_type_flag (type
, 3, "OFA");
190 append_flags_type_flag (type
, 4, "NVA");
191 append_flags_type_flag (type
, 5, "NXC");
192 append_flags_type_flag (type
, 6, "DZC");
193 append_flags_type_flag (type
, 7, "UFC");
194 append_flags_type_flag (type
, 8, "OFC");
195 append_flags_type_flag (type
, 9, "NVC");
196 append_flags_type_flag (type
, 22, "NS");
197 append_flags_type_flag (type
, 23, "NXM");
198 append_flags_type_flag (type
, 24, "DZM");
199 append_flags_type_flag (type
, 25, "UFM");
200 append_flags_type_flag (type
, 26, "OFM");
201 append_flags_type_flag (type
, 27, "NVM");
203 tdep
->sparc64_fsr_type
= type
;
206 return tdep
->sparc64_fsr_type
;
210 sparc64_fprs_type (struct gdbarch
*gdbarch
)
212 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
214 if (!tdep
->sparc64_fprs_type
)
218 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_fprs", 8);
219 append_flags_type_flag (type
, 0, "DL");
220 append_flags_type_flag (type
, 1, "DU");
221 append_flags_type_flag (type
, 2, "FEF");
223 tdep
->sparc64_fprs_type
= type
;
226 return tdep
->sparc64_fprs_type
;
230 /* Register information. */
232 static const char *sparc64_register_names
[] =
234 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
235 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
236 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
237 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7",
239 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
240 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
241 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
242 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
243 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
244 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
248 /* FIXME: Give "state" a name until we start using register groups. */
255 /* Total number of registers. */
256 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
258 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
259 registers as "psuedo" registers. */
261 static const char *sparc64_pseudo_register_names
[] =
263 "cwp", "pstate", "asi", "ccr",
265 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
266 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
267 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
268 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
270 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
271 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
274 /* Total number of pseudo registers. */
275 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
277 /* Return the name of register REGNUM. */
280 sparc64_register_name (struct gdbarch
*gdbarch
, int regnum
)
282 if (regnum
>= 0 && regnum
< SPARC64_NUM_REGS
)
283 return sparc64_register_names
[regnum
];
285 if (regnum
>= SPARC64_NUM_REGS
286 && regnum
< SPARC64_NUM_REGS
+ SPARC64_NUM_PSEUDO_REGS
)
287 return sparc64_pseudo_register_names
[regnum
- SPARC64_NUM_REGS
];
292 /* Return the GDB type object for the "standard" data type of data in
296 sparc64_register_type (struct gdbarch
*gdbarch
, int regnum
)
300 if (regnum
== SPARC_SP_REGNUM
|| regnum
== SPARC_FP_REGNUM
)
301 return builtin_type (gdbarch
)->builtin_data_ptr
;
302 if (regnum
>= SPARC_G0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
)
303 return builtin_type (gdbarch
)->builtin_int64
;
304 if (regnum
>= SPARC_F0_REGNUM
&& regnum
<= SPARC_F31_REGNUM
)
305 return builtin_type (gdbarch
)->builtin_float
;
306 if (regnum
>= SPARC64_F32_REGNUM
&& regnum
<= SPARC64_F62_REGNUM
)
307 return builtin_type (gdbarch
)->builtin_double
;
308 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
309 return builtin_type (gdbarch
)->builtin_func_ptr
;
310 /* This raw register contains the contents of %cwp, %pstate, %asi
311 and %ccr as laid out in a %tstate register. */
312 if (regnum
== SPARC64_STATE_REGNUM
)
313 return builtin_type (gdbarch
)->builtin_int64
;
314 if (regnum
== SPARC64_FSR_REGNUM
)
315 return sparc64_fsr_type (gdbarch
);
316 if (regnum
== SPARC64_FPRS_REGNUM
)
317 return sparc64_fprs_type (gdbarch
);
318 /* "Although Y is a 64-bit register, its high-order 32 bits are
319 reserved and always read as 0." */
320 if (regnum
== SPARC64_Y_REGNUM
)
321 return builtin_type (gdbarch
)->builtin_int64
;
323 /* Pseudo registers. */
325 if (regnum
== SPARC64_CWP_REGNUM
)
326 return builtin_type (gdbarch
)->builtin_int64
;
327 if (regnum
== SPARC64_PSTATE_REGNUM
)
328 return sparc64_pstate_type (gdbarch
);
329 if (regnum
== SPARC64_ASI_REGNUM
)
330 return builtin_type (gdbarch
)->builtin_int64
;
331 if (regnum
== SPARC64_CCR_REGNUM
)
332 return builtin_type (gdbarch
)->builtin_int64
;
333 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
334 return builtin_type (gdbarch
)->builtin_double
;
335 if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
336 return builtin_type (gdbarch
)->builtin_long_double
;
338 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
341 static enum register_status
342 sparc64_pseudo_register_read (struct gdbarch
*gdbarch
,
343 struct regcache
*regcache
,
344 int regnum
, gdb_byte
*buf
)
346 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
347 enum register_status status
;
349 gdb_assert (regnum
>= SPARC64_NUM_REGS
);
351 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
353 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
354 status
= regcache_raw_read (regcache
, regnum
, buf
);
355 if (status
== REG_VALID
)
356 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 4);
359 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
361 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
362 return regcache_raw_read (regcache
, regnum
, buf
);
364 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
366 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
368 status
= regcache_raw_read (regcache
, regnum
, buf
);
369 if (status
== REG_VALID
)
370 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 4);
371 if (status
== REG_VALID
)
372 status
= regcache_raw_read (regcache
, regnum
+ 2, buf
+ 8);
373 if (status
== REG_VALID
)
374 status
= regcache_raw_read (regcache
, regnum
+ 3, buf
+ 12);
378 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
380 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
382 status
= regcache_raw_read (regcache
, regnum
, buf
);
383 if (status
== REG_VALID
)
384 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 8);
388 else if (regnum
== SPARC64_CWP_REGNUM
389 || regnum
== SPARC64_PSTATE_REGNUM
390 || regnum
== SPARC64_ASI_REGNUM
391 || regnum
== SPARC64_CCR_REGNUM
)
395 status
= regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
396 if (status
!= REG_VALID
)
401 case SPARC64_CWP_REGNUM
:
402 state
= (state
>> 0) & ((1 << 5) - 1);
404 case SPARC64_PSTATE_REGNUM
:
405 state
= (state
>> 8) & ((1 << 12) - 1);
407 case SPARC64_ASI_REGNUM
:
408 state
= (state
>> 24) & ((1 << 8) - 1);
410 case SPARC64_CCR_REGNUM
:
411 state
= (state
>> 32) & ((1 << 8) - 1);
414 store_unsigned_integer (buf
, 8, byte_order
, state
);
421 sparc64_pseudo_register_write (struct gdbarch
*gdbarch
,
422 struct regcache
*regcache
,
423 int regnum
, const gdb_byte
*buf
)
425 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
426 gdb_assert (regnum
>= SPARC64_NUM_REGS
);
428 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
430 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
431 regcache_raw_write (regcache
, regnum
, buf
);
432 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 4);
434 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
436 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
437 regcache_raw_write (regcache
, regnum
, buf
);
439 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
441 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
442 regcache_raw_write (regcache
, regnum
, buf
);
443 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 4);
444 regcache_raw_write (regcache
, regnum
+ 2, buf
+ 8);
445 regcache_raw_write (regcache
, regnum
+ 3, buf
+ 12);
447 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
449 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
450 regcache_raw_write (regcache
, regnum
, buf
);
451 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 8);
453 else if (regnum
== SPARC64_CWP_REGNUM
454 || regnum
== SPARC64_PSTATE_REGNUM
455 || regnum
== SPARC64_ASI_REGNUM
456 || regnum
== SPARC64_CCR_REGNUM
)
458 ULONGEST state
, bits
;
460 regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
461 bits
= extract_unsigned_integer (buf
, 8, byte_order
);
464 case SPARC64_CWP_REGNUM
:
465 state
|= ((bits
& ((1 << 5) - 1)) << 0);
467 case SPARC64_PSTATE_REGNUM
:
468 state
|= ((bits
& ((1 << 12) - 1)) << 8);
470 case SPARC64_ASI_REGNUM
:
471 state
|= ((bits
& ((1 << 8) - 1)) << 24);
473 case SPARC64_CCR_REGNUM
:
474 state
|= ((bits
& ((1 << 8) - 1)) << 32);
477 regcache_raw_write_unsigned (regcache
, SPARC64_STATE_REGNUM
, state
);
482 /* Return PC of first real instruction of the function starting at
486 sparc64_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR start_pc
)
488 struct symtab_and_line sal
;
489 CORE_ADDR func_start
, func_end
;
490 struct sparc_frame_cache cache
;
492 /* This is the preferred method, find the end of the prologue by
493 using the debugging information. */
494 if (find_pc_partial_function (start_pc
, NULL
, &func_start
, &func_end
))
496 sal
= find_pc_line (func_start
, 0);
498 if (sal
.end
< func_end
499 && start_pc
<= sal
.end
)
503 return sparc_analyze_prologue (gdbarch
, start_pc
, 0xffffffffffffffffULL
,
509 static struct sparc_frame_cache
*
510 sparc64_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
512 return sparc_frame_cache (this_frame
, this_cache
);
516 sparc64_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
517 struct frame_id
*this_id
)
519 struct sparc_frame_cache
*cache
=
520 sparc64_frame_cache (this_frame
, this_cache
);
522 /* This marks the outermost frame. */
523 if (cache
->base
== 0)
526 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
529 static struct value
*
530 sparc64_frame_prev_register (struct frame_info
*this_frame
, void **this_cache
,
533 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
534 struct sparc_frame_cache
*cache
=
535 sparc64_frame_cache (this_frame
, this_cache
);
537 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
539 CORE_ADDR pc
= (regnum
== SPARC64_NPC_REGNUM
) ? 4 : 0;
542 (cache
->copied_regs_mask
& 0x80) ? SPARC_I7_REGNUM
: SPARC_O7_REGNUM
;
543 pc
+= get_frame_register_unsigned (this_frame
, regnum
) + 8;
544 return frame_unwind_got_constant (this_frame
, regnum
, pc
);
547 /* Handle StackGhost. */
549 ULONGEST wcookie
= sparc_fetch_wcookie (gdbarch
);
551 if (wcookie
!= 0 && !cache
->frameless_p
&& regnum
== SPARC_I7_REGNUM
)
553 CORE_ADDR addr
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
556 /* Read the value in from memory. */
557 i7
= get_frame_memory_unsigned (this_frame
, addr
, 8);
558 return frame_unwind_got_constant (this_frame
, regnum
, i7
^ wcookie
);
562 /* The previous frame's `local' and `in' registers may have been saved
563 in the register save area. */
564 if (regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
565 && (cache
->saved_regs_mask
& (1 << (regnum
- SPARC_L0_REGNUM
))))
567 CORE_ADDR addr
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
569 return frame_unwind_got_memory (this_frame
, regnum
, addr
);
572 /* The previous frame's `out' registers may be accessible as the current
573 frame's `in' registers. */
574 if (regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
575 && (cache
->copied_regs_mask
& (1 << (regnum
- SPARC_O0_REGNUM
))))
576 regnum
+= (SPARC_I0_REGNUM
- SPARC_O0_REGNUM
);
578 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
581 static const struct frame_unwind sparc64_frame_unwind
=
584 default_frame_unwind_stop_reason
,
585 sparc64_frame_this_id
,
586 sparc64_frame_prev_register
,
588 default_frame_sniffer
593 sparc64_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
595 struct sparc_frame_cache
*cache
=
596 sparc64_frame_cache (this_frame
, this_cache
);
601 static const struct frame_base sparc64_frame_base
=
603 &sparc64_frame_unwind
,
604 sparc64_frame_base_address
,
605 sparc64_frame_base_address
,
606 sparc64_frame_base_address
609 /* Check whether TYPE must be 16-byte aligned. */
612 sparc64_16_byte_align_p (struct type
*type
)
614 if (sparc64_floating_p (type
) && TYPE_LENGTH (type
) == 16)
617 if (sparc64_structure_or_union_p (type
))
621 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
623 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
625 if (sparc64_16_byte_align_p (subtype
))
633 /* Store floating fields of element ELEMENT of an "parameter array"
634 that has type TYPE and is stored at BITPOS in VALBUF in the
635 apropriate registers of REGCACHE. This function can be called
636 recursively and therefore handles floating types in addition to
640 sparc64_store_floating_fields (struct regcache
*regcache
, struct type
*type
,
641 const gdb_byte
*valbuf
, int element
, int bitpos
)
643 int len
= TYPE_LENGTH (type
);
645 gdb_assert (element
< 16);
647 if (sparc64_floating_p (type
)
648 || (sparc64_complex_floating_p (type
) && len
<= 16))
654 gdb_assert (bitpos
== 0);
655 gdb_assert ((element
% 2) == 0);
657 regnum
= SPARC64_Q0_REGNUM
+ element
/ 2;
658 regcache_cooked_write (regcache
, regnum
, valbuf
);
662 gdb_assert (bitpos
== 0 || bitpos
== 64);
664 regnum
= SPARC64_D0_REGNUM
+ element
+ bitpos
/ 64;
665 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
669 gdb_assert (len
== 4);
670 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 128);
672 regnum
= SPARC_F0_REGNUM
+ element
* 2 + bitpos
/ 32;
673 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
676 else if (sparc64_structure_or_union_p (type
))
680 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
682 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
683 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
685 sparc64_store_floating_fields (regcache
, subtype
, valbuf
,
689 /* GCC has an interesting bug. If TYPE is a structure that has
690 a single `float' member, GCC doesn't treat it as a structure
691 at all, but rather as an ordinary `float' argument. This
692 argument will be stored in %f1, as required by the psABI.
693 However, as a member of a structure the psABI requires it to
694 be stored in %f0. This bug is present in GCC 3.3.2, but
695 probably in older releases to. To appease GCC, if a
696 structure has only a single `float' member, we store its
697 value in %f1 too (we already have stored in %f0). */
698 if (TYPE_NFIELDS (type
) == 1)
700 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
702 if (sparc64_floating_p (subtype
) && TYPE_LENGTH (subtype
) == 4)
703 regcache_cooked_write (regcache
, SPARC_F1_REGNUM
, valbuf
);
708 /* Fetch floating fields from a variable of type TYPE from the
709 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
710 in VALBUF. This function can be called recursively and therefore
711 handles floating types in addition to structures. */
714 sparc64_extract_floating_fields (struct regcache
*regcache
, struct type
*type
,
715 gdb_byte
*valbuf
, int bitpos
)
717 if (sparc64_floating_p (type
))
719 int len
= TYPE_LENGTH (type
);
724 gdb_assert (bitpos
== 0 || bitpos
== 128);
726 regnum
= SPARC64_Q0_REGNUM
+ bitpos
/ 128;
727 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
731 gdb_assert (bitpos
% 64 == 0 && bitpos
>= 0 && bitpos
< 256);
733 regnum
= SPARC64_D0_REGNUM
+ bitpos
/ 64;
734 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
738 gdb_assert (len
== 4);
739 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 256);
741 regnum
= SPARC_F0_REGNUM
+ bitpos
/ 32;
742 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
745 else if (sparc64_structure_or_union_p (type
))
749 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
751 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
752 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
754 sparc64_extract_floating_fields (regcache
, subtype
, valbuf
, subpos
);
759 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
760 non-zero) in REGCACHE and on the stack (starting from address SP). */
763 sparc64_store_arguments (struct regcache
*regcache
, int nargs
,
764 struct value
**args
, CORE_ADDR sp
,
765 int struct_return
, CORE_ADDR struct_addr
)
767 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
768 /* Number of extended words in the "parameter array". */
769 int num_elements
= 0;
773 /* Take BIAS into account. */
776 /* First we calculate the number of extended words in the "parameter
777 array". While doing so we also convert some of the arguments. */
782 for (i
= 0; i
< nargs
; i
++)
784 struct type
*type
= value_type (args
[i
]);
785 int len
= TYPE_LENGTH (type
);
787 if (sparc64_structure_or_union_p (type
)
788 || (sparc64_complex_floating_p (type
) && len
== 32))
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
) || sparc64_complex_floating_p (type
))
821 /* Floating arguments. */
824 /* The psABI says that "Each quad-precision parameter
825 value will be assigned to two extended words in the
829 /* The psABI says that "Long doubles must be
830 quad-aligned, and thus a hole might be introduced
831 into the parameter array to force alignment." Skip
832 an element if necessary. */
833 if ((num_elements
% 2) && sparc64_16_byte_align_p (type
))
841 /* Integral and pointer arguments. */
842 gdb_assert (sparc64_integral_or_pointer_p (type
));
844 /* The psABI says that "Each argument value of integral type
845 smaller than an extended word will be widened by the
846 caller to an extended word according to the signed-ness
847 of the argument type." */
849 args
[i
] = value_cast (builtin_type (gdbarch
)->builtin_int64
,
855 /* Allocate the "parameter array". */
856 sp
-= num_elements
* 8;
858 /* The psABI says that "Every stack frame must be 16-byte aligned." */
861 /* Now we store the arguments in to the "paramater array". Some
862 Integer or Pointer arguments and Structure or Union arguments
863 will be passed in %o registers. Some Floating arguments and
864 floating members of structures are passed in floating-point
865 registers. However, for functions with variable arguments,
866 floating arguments are stored in an %0 register, and for
867 functions without a prototype floating arguments are stored in
868 both a floating-point and an %o registers, or a floating-point
869 register and memory. To simplify the logic here we always pass
870 arguments in memory, an %o register, and a floating-point
871 register if appropriate. This should be no problem since the
872 contents of any unused memory or registers in the "parameter
873 array" are undefined. */
877 regcache_cooked_write_unsigned (regcache
, SPARC_O0_REGNUM
, struct_addr
);
881 for (i
= 0; i
< nargs
; i
++)
883 const gdb_byte
*valbuf
= value_contents (args
[i
]);
884 struct type
*type
= value_type (args
[i
]);
885 int len
= TYPE_LENGTH (type
);
889 if (sparc64_structure_or_union_p (type
)
890 || (sparc64_complex_floating_p (type
) && len
== 32))
892 /* Structure, Union or long double Complex 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_complex_floating_p (type
))
912 /* Float Complex or double Complex arguments. */
915 regnum
= SPARC64_D0_REGNUM
+ element
;
919 if (regnum
< SPARC64_D30_REGNUM
)
920 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
921 if (regnum
< SPARC64_D10_REGNUM
)
922 regcache_cooked_write (regcache
,
923 SPARC_O0_REGNUM
+ element
+ 1,
928 else if (sparc64_floating_p (type
))
930 /* Floating arguments. */
936 regnum
= SPARC64_Q0_REGNUM
+ element
/ 2;
941 regnum
= SPARC64_D0_REGNUM
+ element
;
945 /* The psABI says "Each single-precision parameter value
946 will be assigned to one extended word in the
947 parameter array, and right-justified within that
948 word; the left half (even float register) is
949 undefined." Even though the psABI says that "the
950 left half is undefined", set it to zero here. */
952 memcpy (buf
+ 4, valbuf
, 4);
956 regnum
= SPARC64_D0_REGNUM
+ element
;
961 /* Integral and pointer arguments. */
962 gdb_assert (len
== 8);
964 regnum
= SPARC_O0_REGNUM
+ element
;
969 regcache_cooked_write (regcache
, regnum
, valbuf
);
971 /* If we're storing the value in a floating-point register,
972 also store it in the corresponding %0 register(s). */
973 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D10_REGNUM
)
975 gdb_assert (element
< 6);
976 regnum
= SPARC_O0_REGNUM
+ element
;
977 regcache_cooked_write (regcache
, regnum
, valbuf
);
979 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q8_REGNUM
)
981 gdb_assert (element
< 5);
982 regnum
= SPARC_O0_REGNUM
+ element
;
983 regcache_cooked_write (regcache
, regnum
, valbuf
);
984 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
988 /* Always store the argument in memory. */
989 write_memory (sp
+ element
* 8, valbuf
, len
);
990 element
+= ((len
+ 7) / 8);
993 gdb_assert (element
== num_elements
);
995 /* Take BIAS into account. */
1001 sparc64_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR address
)
1003 /* The ABI requires 16-byte alignment. */
1004 return address
& ~0xf;
1008 sparc64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
1009 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1010 int nargs
, struct value
**args
, CORE_ADDR sp
,
1011 int struct_return
, CORE_ADDR struct_addr
)
1013 /* Set return address. */
1014 regcache_cooked_write_unsigned (regcache
, SPARC_O7_REGNUM
, bp_addr
- 8);
1016 /* Set up function arguments. */
1017 sp
= sparc64_store_arguments (regcache
, nargs
, args
, sp
,
1018 struct_return
, struct_addr
);
1020 /* Allocate the register save area. */
1023 /* Stack should be 16-byte aligned at this point. */
1024 gdb_assert ((sp
+ BIAS
) % 16 == 0);
1026 /* Finally, update the stack pointer. */
1027 regcache_cooked_write_unsigned (regcache
, SPARC_SP_REGNUM
, sp
);
1033 /* Extract from an array REGBUF containing the (raw) register state, a
1034 function return value of TYPE, and copy that into VALBUF. */
1037 sparc64_extract_return_value (struct type
*type
, struct regcache
*regcache
,
1040 int len
= TYPE_LENGTH (type
);
1044 if (sparc64_structure_or_union_p (type
))
1046 /* Structure or Union return values. */
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 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1052 sparc64_extract_floating_fields (regcache
, type
, buf
, 0);
1053 memcpy (valbuf
, buf
, len
);
1055 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
1057 /* Floating return values. */
1058 for (i
= 0; i
< len
/ 4; i
++)
1059 regcache_cooked_read (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1060 memcpy (valbuf
, buf
, len
);
1062 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1064 /* Small arrays are returned the same way as small structures. */
1065 gdb_assert (len
<= 32);
1067 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1068 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1069 memcpy (valbuf
, buf
, len
);
1073 /* Integral and pointer return values. */
1074 gdb_assert (sparc64_integral_or_pointer_p (type
));
1076 /* Just stripping off any unused bytes should preserve the
1077 signed-ness just fine. */
1078 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
, buf
);
1079 memcpy (valbuf
, buf
+ 8 - len
, len
);
1083 /* Write into the appropriate registers a function return value stored
1084 in VALBUF of type TYPE. */
1087 sparc64_store_return_value (struct type
*type
, struct regcache
*regcache
,
1088 const gdb_byte
*valbuf
)
1090 int len
= TYPE_LENGTH (type
);
1094 if (sparc64_structure_or_union_p (type
))
1096 /* Structure or Union return values. */
1097 gdb_assert (len
<= 32);
1099 /* Simplify matters by storing the complete value (including
1100 floating members) into %o0 and %o1. Floating members are
1101 also store in the appropriate floating-point registers. */
1102 memset (buf
, 0, sizeof (buf
));
1103 memcpy (buf
, valbuf
, len
);
1104 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1105 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1106 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1107 sparc64_store_floating_fields (regcache
, type
, buf
, 0, 0);
1109 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
1111 /* Floating return values. */
1112 memcpy (buf
, valbuf
, len
);
1113 for (i
= 0; i
< len
/ 4; i
++)
1114 regcache_cooked_write (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1116 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1118 /* Small arrays are returned the same way as small structures. */
1119 gdb_assert (len
<= 32);
1121 memset (buf
, 0, sizeof (buf
));
1122 memcpy (buf
, valbuf
, len
);
1123 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1124 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1128 /* Integral and pointer return values. */
1129 gdb_assert (sparc64_integral_or_pointer_p (type
));
1131 /* ??? Do we need to do any sign-extension here? */
1133 memcpy (buf
+ 8 - len
, valbuf
, len
);
1134 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
, buf
);
1138 static enum return_value_convention
1139 sparc64_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1140 struct type
*type
, struct regcache
*regcache
,
1141 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1143 if (TYPE_LENGTH (type
) > 32)
1144 return RETURN_VALUE_STRUCT_CONVENTION
;
1147 sparc64_extract_return_value (type
, regcache
, readbuf
);
1149 sparc64_store_return_value (type
, regcache
, writebuf
);
1151 return RETURN_VALUE_REGISTER_CONVENTION
;
1156 sparc64_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1157 struct dwarf2_frame_state_reg
*reg
,
1158 struct frame_info
*this_frame
)
1162 case SPARC_G0_REGNUM
:
1163 /* Since %g0 is always zero, there is no point in saving it, and
1164 people will be inclined omit it from the CFI. Make sure we
1165 don't warn about that. */
1166 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1168 case SPARC_SP_REGNUM
:
1169 reg
->how
= DWARF2_FRAME_REG_CFA
;
1171 case SPARC64_PC_REGNUM
:
1172 reg
->how
= DWARF2_FRAME_REG_RA_OFFSET
;
1173 reg
->loc
.offset
= 8;
1175 case SPARC64_NPC_REGNUM
:
1176 reg
->how
= DWARF2_FRAME_REG_RA_OFFSET
;
1177 reg
->loc
.offset
= 12;
1183 sparc64_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1185 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1187 tdep
->pc_regnum
= SPARC64_PC_REGNUM
;
1188 tdep
->npc_regnum
= SPARC64_NPC_REGNUM
;
1190 /* This is what all the fuss is about. */
1191 set_gdbarch_long_bit (gdbarch
, 64);
1192 set_gdbarch_long_long_bit (gdbarch
, 64);
1193 set_gdbarch_ptr_bit (gdbarch
, 64);
1195 set_gdbarch_num_regs (gdbarch
, SPARC64_NUM_REGS
);
1196 set_gdbarch_register_name (gdbarch
, sparc64_register_name
);
1197 set_gdbarch_register_type (gdbarch
, sparc64_register_type
);
1198 set_gdbarch_num_pseudo_regs (gdbarch
, SPARC64_NUM_PSEUDO_REGS
);
1199 set_gdbarch_pseudo_register_read (gdbarch
, sparc64_pseudo_register_read
);
1200 set_gdbarch_pseudo_register_write (gdbarch
, sparc64_pseudo_register_write
);
1202 /* Register numbers of various important registers. */
1203 set_gdbarch_pc_regnum (gdbarch
, SPARC64_PC_REGNUM
); /* %pc */
1205 /* Call dummy code. */
1206 set_gdbarch_frame_align (gdbarch
, sparc64_frame_align
);
1207 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
1208 set_gdbarch_push_dummy_code (gdbarch
, NULL
);
1209 set_gdbarch_push_dummy_call (gdbarch
, sparc64_push_dummy_call
);
1211 set_gdbarch_return_value (gdbarch
, sparc64_return_value
);
1212 set_gdbarch_stabs_argument_has_addr
1213 (gdbarch
, default_stabs_argument_has_addr
);
1215 set_gdbarch_skip_prologue (gdbarch
, sparc64_skip_prologue
);
1216 set_gdbarch_in_function_epilogue_p (gdbarch
, sparc_in_function_epilogue_p
);
1218 /* Hook in the DWARF CFI frame unwinder. */
1219 dwarf2_frame_set_init_reg (gdbarch
, sparc64_dwarf2_frame_init_reg
);
1220 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1221 StackGhost issues have been resolved. */
1223 frame_unwind_append_unwinder (gdbarch
, &sparc64_frame_unwind
);
1224 frame_base_set_default (gdbarch
, &sparc64_frame_base
);
1228 /* Helper functions for dealing with register sets. */
1230 #define TSTATE_CWP 0x000000000000001fULL
1231 #define TSTATE_ICC 0x0000000f00000000ULL
1232 #define TSTATE_XCC 0x000000f000000000ULL
1234 #define PSR_S 0x00000080
1235 #define PSR_ICC 0x00f00000
1236 #define PSR_VERS 0x0f000000
1237 #define PSR_IMPL 0xf0000000
1238 #define PSR_V8PLUS 0xff000000
1239 #define PSR_XCC 0x000f0000
1242 sparc64_supply_gregset (const struct sparc_gregmap
*gregmap
,
1243 struct regcache
*regcache
,
1244 int regnum
, const void *gregs
)
1246 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1247 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1248 int sparc32
= (gdbarch_ptr_bit (gdbarch
) == 32);
1249 const gdb_byte
*regs
= gregs
;
1250 gdb_byte zero
[8] = { 0 };
1255 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1257 int offset
= gregmap
->r_tstate_offset
;
1258 ULONGEST tstate
, psr
;
1261 tstate
= extract_unsigned_integer (regs
+ offset
, 8, byte_order
);
1262 psr
= ((tstate
& TSTATE_CWP
) | PSR_S
| ((tstate
& TSTATE_ICC
) >> 12)
1263 | ((tstate
& TSTATE_XCC
) >> 20) | PSR_V8PLUS
);
1264 store_unsigned_integer (buf
, 4, byte_order
, psr
);
1265 regcache_raw_supply (regcache
, SPARC32_PSR_REGNUM
, buf
);
1268 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1269 regcache_raw_supply (regcache
, SPARC32_PC_REGNUM
,
1270 regs
+ gregmap
->r_pc_offset
+ 4);
1272 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1273 regcache_raw_supply (regcache
, SPARC32_NPC_REGNUM
,
1274 regs
+ gregmap
->r_npc_offset
+ 4);
1276 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1278 int offset
= gregmap
->r_y_offset
+ 8 - gregmap
->r_y_size
;
1279 regcache_raw_supply (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1284 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1285 regcache_raw_supply (regcache
, SPARC64_STATE_REGNUM
,
1286 regs
+ gregmap
->r_tstate_offset
);
1288 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1289 regcache_raw_supply (regcache
, SPARC64_PC_REGNUM
,
1290 regs
+ gregmap
->r_pc_offset
);
1292 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1293 regcache_raw_supply (regcache
, SPARC64_NPC_REGNUM
,
1294 regs
+ gregmap
->r_npc_offset
);
1296 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1301 memcpy (buf
+ 8 - gregmap
->r_y_size
,
1302 regs
+ gregmap
->r_y_offset
, gregmap
->r_y_size
);
1303 regcache_raw_supply (regcache
, SPARC64_Y_REGNUM
, buf
);
1306 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1307 && gregmap
->r_fprs_offset
!= -1)
1308 regcache_raw_supply (regcache
, SPARC64_FPRS_REGNUM
,
1309 regs
+ gregmap
->r_fprs_offset
);
1312 if (regnum
== SPARC_G0_REGNUM
|| regnum
== -1)
1313 regcache_raw_supply (regcache
, SPARC_G0_REGNUM
, &zero
);
1315 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1317 int offset
= gregmap
->r_g1_offset
;
1322 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1324 if (regnum
== i
|| regnum
== -1)
1325 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1330 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1332 /* Not all of the register set variants include Locals and
1333 Inputs. For those that don't, we read them off the stack. */
1334 if (gregmap
->r_l0_offset
== -1)
1338 regcache_cooked_read_unsigned (regcache
, SPARC_SP_REGNUM
, &sp
);
1339 sparc_supply_rwindow (regcache
, sp
, regnum
);
1343 int offset
= gregmap
->r_l0_offset
;
1348 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1350 if (regnum
== i
|| regnum
== -1)
1351 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1359 sparc64_collect_gregset (const struct sparc_gregmap
*gregmap
,
1360 const struct regcache
*regcache
,
1361 int regnum
, void *gregs
)
1363 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1364 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1365 int sparc32
= (gdbarch_ptr_bit (gdbarch
) == 32);
1366 gdb_byte
*regs
= gregs
;
1371 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1373 int offset
= gregmap
->r_tstate_offset
;
1374 ULONGEST tstate
, psr
;
1377 tstate
= extract_unsigned_integer (regs
+ offset
, 8, byte_order
);
1378 regcache_raw_collect (regcache
, SPARC32_PSR_REGNUM
, buf
);
1379 psr
= extract_unsigned_integer (buf
, 4, byte_order
);
1380 tstate
|= (psr
& PSR_ICC
) << 12;
1381 if ((psr
& (PSR_VERS
| PSR_IMPL
)) == PSR_V8PLUS
)
1382 tstate
|= (psr
& PSR_XCC
) << 20;
1383 store_unsigned_integer (buf
, 8, byte_order
, tstate
);
1384 memcpy (regs
+ offset
, buf
, 8);
1387 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1388 regcache_raw_collect (regcache
, SPARC32_PC_REGNUM
,
1389 regs
+ gregmap
->r_pc_offset
+ 4);
1391 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1392 regcache_raw_collect (regcache
, SPARC32_NPC_REGNUM
,
1393 regs
+ gregmap
->r_npc_offset
+ 4);
1395 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1397 int offset
= gregmap
->r_y_offset
+ 8 - gregmap
->r_y_size
;
1398 regcache_raw_collect (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1403 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1404 regcache_raw_collect (regcache
, SPARC64_STATE_REGNUM
,
1405 regs
+ gregmap
->r_tstate_offset
);
1407 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1408 regcache_raw_collect (regcache
, SPARC64_PC_REGNUM
,
1409 regs
+ gregmap
->r_pc_offset
);
1411 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1412 regcache_raw_collect (regcache
, SPARC64_NPC_REGNUM
,
1413 regs
+ gregmap
->r_npc_offset
);
1415 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1419 regcache_raw_collect (regcache
, SPARC64_Y_REGNUM
, buf
);
1420 memcpy (regs
+ gregmap
->r_y_offset
,
1421 buf
+ 8 - gregmap
->r_y_size
, gregmap
->r_y_size
);
1424 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1425 && gregmap
->r_fprs_offset
!= -1)
1426 regcache_raw_collect (regcache
, SPARC64_FPRS_REGNUM
,
1427 regs
+ gregmap
->r_fprs_offset
);
1431 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1433 int offset
= gregmap
->r_g1_offset
;
1438 /* %g0 is always zero. */
1439 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1441 if (regnum
== i
|| regnum
== -1)
1442 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1447 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1449 /* Not all of the register set variants include Locals and
1450 Inputs. For those that don't, we read them off the stack. */
1451 if (gregmap
->r_l0_offset
!= -1)
1453 int offset
= gregmap
->r_l0_offset
;
1458 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1460 if (regnum
== i
|| regnum
== -1)
1461 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1469 sparc64_supply_fpregset (const struct sparc_fpregmap
*fpregmap
,
1470 struct regcache
*regcache
,
1471 int regnum
, const void *fpregs
)
1473 int sparc32
= (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32);
1474 const gdb_byte
*regs
= fpregs
;
1477 for (i
= 0; i
< 32; i
++)
1479 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1480 regcache_raw_supply (regcache
, SPARC_F0_REGNUM
+ i
,
1481 regs
+ fpregmap
->r_f0_offset
+ (i
* 4));
1486 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1487 regcache_raw_supply (regcache
, SPARC32_FSR_REGNUM
,
1488 regs
+ fpregmap
->r_fsr_offset
);
1492 for (i
= 0; i
< 16; i
++)
1494 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1495 regcache_raw_supply (regcache
, SPARC64_F32_REGNUM
+ i
,
1496 (regs
+ fpregmap
->r_f0_offset
1497 + (32 * 4) + (i
* 8)));
1500 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1501 regcache_raw_supply (regcache
, SPARC64_FSR_REGNUM
,
1502 regs
+ fpregmap
->r_fsr_offset
);
1507 sparc64_collect_fpregset (const struct sparc_fpregmap
*fpregmap
,
1508 const struct regcache
*regcache
,
1509 int regnum
, void *fpregs
)
1511 int sparc32
= (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32);
1512 gdb_byte
*regs
= fpregs
;
1515 for (i
= 0; i
< 32; i
++)
1517 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1518 regcache_raw_collect (regcache
, SPARC_F0_REGNUM
+ i
,
1519 regs
+ fpregmap
->r_f0_offset
+ (i
* 4));
1524 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1525 regcache_raw_collect (regcache
, SPARC32_FSR_REGNUM
,
1526 regs
+ fpregmap
->r_fsr_offset
);
1530 for (i
= 0; i
< 16; i
++)
1532 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1533 regcache_raw_collect (regcache
, SPARC64_F32_REGNUM
+ i
,
1534 (regs
+ fpregmap
->r_f0_offset
1535 + (32 * 4) + (i
* 8)));
1538 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1539 regcache_raw_collect (regcache
, SPARC64_FSR_REGNUM
,
1540 regs
+ fpregmap
->r_fsr_offset
);
1544 const struct sparc_fpregmap sparc64_bsd_fpregmap
=