1 /* Target-dependent code for UltraSPARC.
3 Copyright (C) 2003-2017 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 "sparc64-tdep.h"
39 /* This file implements the SPARC 64-bit ABI as defined by the
40 section "Low-Level System Information" of the SPARC Compliance
41 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
44 /* Please use the sparc32_-prefix for 32-bit specific code, the
45 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
46 code can handle both. */
48 /* The functions on this page are intended to be used to classify
49 function arguments. */
51 /* Check whether TYPE is "Integral or Pointer". */
54 sparc64_integral_or_pointer_p (const struct type
*type
)
56 switch (TYPE_CODE (type
))
64 int len
= TYPE_LENGTH (type
);
65 gdb_assert (len
== 1 || len
== 2 || len
== 4 || len
== 8);
71 int len
= TYPE_LENGTH (type
);
72 gdb_assert (len
== 8);
82 /* Check whether TYPE is "Floating". */
85 sparc64_floating_p (const struct type
*type
)
87 switch (TYPE_CODE (type
))
91 int len
= TYPE_LENGTH (type
);
92 gdb_assert (len
== 4 || len
== 8 || len
== 16);
102 /* Check whether TYPE is "Complex Floating". */
105 sparc64_complex_floating_p (const struct type
*type
)
107 switch (TYPE_CODE (type
))
109 case TYPE_CODE_COMPLEX
:
111 int len
= TYPE_LENGTH (type
);
112 gdb_assert (len
== 8 || len
== 16 || len
== 32);
122 /* Check whether TYPE is "Structure or Union".
124 In terms of Ada subprogram calls, arrays are treated the same as
125 struct and union types. So this function also returns non-zero
129 sparc64_structure_or_union_p (const struct type
*type
)
131 switch (TYPE_CODE (type
))
133 case TYPE_CODE_STRUCT
:
134 case TYPE_CODE_UNION
:
135 case TYPE_CODE_ARRAY
:
145 /* Construct types for ISA-specific registers. */
148 sparc64_pstate_type (struct gdbarch
*gdbarch
)
150 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
152 if (!tdep
->sparc64_pstate_type
)
156 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_pstate", 8);
157 append_flags_type_flag (type
, 0, "AG");
158 append_flags_type_flag (type
, 1, "IE");
159 append_flags_type_flag (type
, 2, "PRIV");
160 append_flags_type_flag (type
, 3, "AM");
161 append_flags_type_flag (type
, 4, "PEF");
162 append_flags_type_flag (type
, 5, "RED");
163 append_flags_type_flag (type
, 8, "TLE");
164 append_flags_type_flag (type
, 9, "CLE");
165 append_flags_type_flag (type
, 10, "PID0");
166 append_flags_type_flag (type
, 11, "PID1");
168 tdep
->sparc64_pstate_type
= type
;
171 return tdep
->sparc64_pstate_type
;
175 sparc64_fsr_type (struct gdbarch
*gdbarch
)
177 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
179 if (!tdep
->sparc64_fsr_type
)
183 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_fsr", 8);
184 append_flags_type_flag (type
, 0, "NXA");
185 append_flags_type_flag (type
, 1, "DZA");
186 append_flags_type_flag (type
, 2, "UFA");
187 append_flags_type_flag (type
, 3, "OFA");
188 append_flags_type_flag (type
, 4, "NVA");
189 append_flags_type_flag (type
, 5, "NXC");
190 append_flags_type_flag (type
, 6, "DZC");
191 append_flags_type_flag (type
, 7, "UFC");
192 append_flags_type_flag (type
, 8, "OFC");
193 append_flags_type_flag (type
, 9, "NVC");
194 append_flags_type_flag (type
, 22, "NS");
195 append_flags_type_flag (type
, 23, "NXM");
196 append_flags_type_flag (type
, 24, "DZM");
197 append_flags_type_flag (type
, 25, "UFM");
198 append_flags_type_flag (type
, 26, "OFM");
199 append_flags_type_flag (type
, 27, "NVM");
201 tdep
->sparc64_fsr_type
= type
;
204 return tdep
->sparc64_fsr_type
;
208 sparc64_fprs_type (struct gdbarch
*gdbarch
)
210 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
212 if (!tdep
->sparc64_fprs_type
)
216 type
= arch_flags_type (gdbarch
, "builtin_type_sparc64_fprs", 8);
217 append_flags_type_flag (type
, 0, "DL");
218 append_flags_type_flag (type
, 1, "DU");
219 append_flags_type_flag (type
, 2, "FEF");
221 tdep
->sparc64_fprs_type
= type
;
224 return tdep
->sparc64_fprs_type
;
228 /* Register information. */
229 #define SPARC64_FPU_REGISTERS \
230 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
231 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
232 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
233 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
234 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
235 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62"
236 #define SPARC64_CP0_REGISTERS \
238 /* FIXME: Give "state" a name until we start using register groups. */ \
244 static const char *sparc64_register_names
[] =
246 SPARC_CORE_REGISTERS
,
247 SPARC64_FPU_REGISTERS
,
248 SPARC64_CP0_REGISTERS
251 /* Total number of registers. */
252 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
254 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
255 registers as "psuedo" registers. */
257 static const char *sparc64_pseudo_register_names
[] =
259 "cwp", "pstate", "asi", "ccr",
261 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
262 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
263 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
264 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
266 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
267 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
270 /* Total number of pseudo registers. */
271 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
273 /* Return the name of pseudo register REGNUM. */
276 sparc64_pseudo_register_name (struct gdbarch
*gdbarch
, int regnum
)
278 regnum
-= gdbarch_num_regs (gdbarch
);
280 if (regnum
< SPARC64_NUM_PSEUDO_REGS
)
281 return sparc64_pseudo_register_names
[regnum
];
283 internal_error (__FILE__
, __LINE__
,
284 _("sparc64_pseudo_register_name: bad register number %d"),
288 /* Return the name of register REGNUM. */
291 sparc64_register_name (struct gdbarch
*gdbarch
, int regnum
)
293 if (regnum
>= 0 && regnum
< gdbarch_num_regs (gdbarch
))
294 return sparc64_register_names
[regnum
];
296 return sparc64_pseudo_register_name (gdbarch
, regnum
);
299 /* Return the GDB type object for the "standard" data type of data in
300 pseudo register REGNUM. */
303 sparc64_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
305 regnum
-= gdbarch_num_regs (gdbarch
);
307 if (regnum
== SPARC64_CWP_REGNUM
)
308 return builtin_type (gdbarch
)->builtin_int64
;
309 if (regnum
== SPARC64_PSTATE_REGNUM
)
310 return sparc64_pstate_type (gdbarch
);
311 if (regnum
== SPARC64_ASI_REGNUM
)
312 return builtin_type (gdbarch
)->builtin_int64
;
313 if (regnum
== SPARC64_CCR_REGNUM
)
314 return builtin_type (gdbarch
)->builtin_int64
;
315 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
316 return builtin_type (gdbarch
)->builtin_double
;
317 if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
318 return builtin_type (gdbarch
)->builtin_long_double
;
320 internal_error (__FILE__
, __LINE__
,
321 _("sparc64_pseudo_register_type: bad register number %d"),
325 /* Return the GDB type object for the "standard" data type of data in
329 sparc64_register_type (struct gdbarch
*gdbarch
, int regnum
)
332 if (regnum
== SPARC_SP_REGNUM
|| regnum
== SPARC_FP_REGNUM
)
333 return builtin_type (gdbarch
)->builtin_data_ptr
;
334 if (regnum
>= SPARC_G0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
)
335 return builtin_type (gdbarch
)->builtin_int64
;
336 if (regnum
>= SPARC_F0_REGNUM
&& regnum
<= SPARC_F31_REGNUM
)
337 return builtin_type (gdbarch
)->builtin_float
;
338 if (regnum
>= SPARC64_F32_REGNUM
&& regnum
<= SPARC64_F62_REGNUM
)
339 return builtin_type (gdbarch
)->builtin_double
;
340 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
341 return builtin_type (gdbarch
)->builtin_func_ptr
;
342 /* This raw register contains the contents of %cwp, %pstate, %asi
343 and %ccr as laid out in a %tstate register. */
344 if (regnum
== SPARC64_STATE_REGNUM
)
345 return builtin_type (gdbarch
)->builtin_int64
;
346 if (regnum
== SPARC64_FSR_REGNUM
)
347 return sparc64_fsr_type (gdbarch
);
348 if (regnum
== SPARC64_FPRS_REGNUM
)
349 return sparc64_fprs_type (gdbarch
);
350 /* "Although Y is a 64-bit register, its high-order 32 bits are
351 reserved and always read as 0." */
352 if (regnum
== SPARC64_Y_REGNUM
)
353 return builtin_type (gdbarch
)->builtin_int64
;
355 /* Pseudo registers. */
356 if (regnum
>= gdbarch_num_regs (gdbarch
))
357 return sparc64_pseudo_register_type (gdbarch
, regnum
);
359 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
362 static enum register_status
363 sparc64_pseudo_register_read (struct gdbarch
*gdbarch
,
364 struct regcache
*regcache
,
365 int regnum
, gdb_byte
*buf
)
367 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
368 enum register_status status
;
370 regnum
-= gdbarch_num_regs (gdbarch
);
372 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
374 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
375 status
= regcache_raw_read (regcache
, regnum
, buf
);
376 if (status
== REG_VALID
)
377 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 4);
380 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
382 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
383 return regcache_raw_read (regcache
, regnum
, buf
);
385 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
387 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
389 status
= regcache_raw_read (regcache
, regnum
, buf
);
390 if (status
== REG_VALID
)
391 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 4);
392 if (status
== REG_VALID
)
393 status
= regcache_raw_read (regcache
, regnum
+ 2, buf
+ 8);
394 if (status
== REG_VALID
)
395 status
= regcache_raw_read (regcache
, regnum
+ 3, buf
+ 12);
399 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
401 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
403 status
= regcache_raw_read (regcache
, regnum
, buf
);
404 if (status
== REG_VALID
)
405 status
= regcache_raw_read (regcache
, regnum
+ 1, buf
+ 8);
409 else if (regnum
== SPARC64_CWP_REGNUM
410 || regnum
== SPARC64_PSTATE_REGNUM
411 || regnum
== SPARC64_ASI_REGNUM
412 || regnum
== SPARC64_CCR_REGNUM
)
416 status
= regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
417 if (status
!= REG_VALID
)
422 case SPARC64_CWP_REGNUM
:
423 state
= (state
>> 0) & ((1 << 5) - 1);
425 case SPARC64_PSTATE_REGNUM
:
426 state
= (state
>> 8) & ((1 << 12) - 1);
428 case SPARC64_ASI_REGNUM
:
429 state
= (state
>> 24) & ((1 << 8) - 1);
431 case SPARC64_CCR_REGNUM
:
432 state
= (state
>> 32) & ((1 << 8) - 1);
435 store_unsigned_integer (buf
, 8, byte_order
, state
);
442 sparc64_pseudo_register_write (struct gdbarch
*gdbarch
,
443 struct regcache
*regcache
,
444 int regnum
, const gdb_byte
*buf
)
446 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
448 regnum
-= gdbarch_num_regs (gdbarch
);
450 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
452 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
453 regcache_raw_write (regcache
, regnum
, buf
);
454 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 4);
456 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
458 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
459 regcache_raw_write (regcache
, regnum
, buf
);
461 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
463 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
464 regcache_raw_write (regcache
, regnum
, buf
);
465 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 4);
466 regcache_raw_write (regcache
, regnum
+ 2, buf
+ 8);
467 regcache_raw_write (regcache
, regnum
+ 3, buf
+ 12);
469 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
471 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
472 regcache_raw_write (regcache
, regnum
, buf
);
473 regcache_raw_write (regcache
, regnum
+ 1, buf
+ 8);
475 else if (regnum
== SPARC64_CWP_REGNUM
476 || regnum
== SPARC64_PSTATE_REGNUM
477 || regnum
== SPARC64_ASI_REGNUM
478 || regnum
== SPARC64_CCR_REGNUM
)
480 ULONGEST state
, bits
;
482 regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
483 bits
= extract_unsigned_integer (buf
, 8, byte_order
);
486 case SPARC64_CWP_REGNUM
:
487 state
|= ((bits
& ((1 << 5) - 1)) << 0);
489 case SPARC64_PSTATE_REGNUM
:
490 state
|= ((bits
& ((1 << 12) - 1)) << 8);
492 case SPARC64_ASI_REGNUM
:
493 state
|= ((bits
& ((1 << 8) - 1)) << 24);
495 case SPARC64_CCR_REGNUM
:
496 state
|= ((bits
& ((1 << 8) - 1)) << 32);
499 regcache_raw_write_unsigned (regcache
, SPARC64_STATE_REGNUM
, state
);
504 /* Return PC of first real instruction of the function starting at
508 sparc64_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR start_pc
)
510 struct symtab_and_line sal
;
511 CORE_ADDR func_start
, func_end
;
512 struct sparc_frame_cache cache
;
514 /* This is the preferred method, find the end of the prologue by
515 using the debugging information. */
516 if (find_pc_partial_function (start_pc
, NULL
, &func_start
, &func_end
))
518 sal
= find_pc_line (func_start
, 0);
520 if (sal
.end
< func_end
521 && start_pc
<= sal
.end
)
525 return sparc_analyze_prologue (gdbarch
, start_pc
, 0xffffffffffffffffULL
,
531 static struct sparc_frame_cache
*
532 sparc64_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
534 return sparc_frame_cache (this_frame
, this_cache
);
538 sparc64_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
539 struct frame_id
*this_id
)
541 struct sparc_frame_cache
*cache
=
542 sparc64_frame_cache (this_frame
, this_cache
);
544 /* This marks the outermost frame. */
545 if (cache
->base
== 0)
548 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
551 static struct value
*
552 sparc64_frame_prev_register (struct frame_info
*this_frame
, void **this_cache
,
555 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
556 struct sparc_frame_cache
*cache
=
557 sparc64_frame_cache (this_frame
, this_cache
);
559 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
561 CORE_ADDR pc
= (regnum
== SPARC64_NPC_REGNUM
) ? 4 : 0;
564 (cache
->copied_regs_mask
& 0x80) ? SPARC_I7_REGNUM
: SPARC_O7_REGNUM
;
565 pc
+= get_frame_register_unsigned (this_frame
, regnum
) + 8;
566 return frame_unwind_got_constant (this_frame
, regnum
, pc
);
569 /* Handle StackGhost. */
571 ULONGEST wcookie
= sparc_fetch_wcookie (gdbarch
);
573 if (wcookie
!= 0 && !cache
->frameless_p
&& regnum
== SPARC_I7_REGNUM
)
575 CORE_ADDR addr
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
578 /* Read the value in from memory. */
579 i7
= get_frame_memory_unsigned (this_frame
, addr
, 8);
580 return frame_unwind_got_constant (this_frame
, regnum
, i7
^ wcookie
);
584 /* The previous frame's `local' and `in' registers may have been saved
585 in the register save area. */
586 if (regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
587 && (cache
->saved_regs_mask
& (1 << (regnum
- SPARC_L0_REGNUM
))))
589 CORE_ADDR addr
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
591 return frame_unwind_got_memory (this_frame
, regnum
, addr
);
594 /* The previous frame's `out' registers may be accessible as the current
595 frame's `in' registers. */
596 if (regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
597 && (cache
->copied_regs_mask
& (1 << (regnum
- SPARC_O0_REGNUM
))))
598 regnum
+= (SPARC_I0_REGNUM
- SPARC_O0_REGNUM
);
600 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
603 static const struct frame_unwind sparc64_frame_unwind
=
606 default_frame_unwind_stop_reason
,
607 sparc64_frame_this_id
,
608 sparc64_frame_prev_register
,
610 default_frame_sniffer
615 sparc64_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
617 struct sparc_frame_cache
*cache
=
618 sparc64_frame_cache (this_frame
, this_cache
);
623 static const struct frame_base sparc64_frame_base
=
625 &sparc64_frame_unwind
,
626 sparc64_frame_base_address
,
627 sparc64_frame_base_address
,
628 sparc64_frame_base_address
631 /* Check whether TYPE must be 16-byte aligned. */
634 sparc64_16_byte_align_p (struct type
*type
)
636 if (sparc64_floating_p (type
) && TYPE_LENGTH (type
) == 16)
639 if (sparc64_structure_or_union_p (type
))
643 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
645 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
647 if (sparc64_16_byte_align_p (subtype
))
655 /* Store floating fields of element ELEMENT of an "parameter array"
656 that has type TYPE and is stored at BITPOS in VALBUF in the
657 apropriate registers of REGCACHE. This function can be called
658 recursively and therefore handles floating types in addition to
662 sparc64_store_floating_fields (struct regcache
*regcache
, struct type
*type
,
663 const gdb_byte
*valbuf
, int element
, int bitpos
)
665 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
666 int len
= TYPE_LENGTH (type
);
668 gdb_assert (element
< 16);
670 if (sparc64_floating_p (type
)
671 || (sparc64_complex_floating_p (type
) && len
<= 16))
677 gdb_assert (bitpos
== 0);
678 gdb_assert ((element
% 2) == 0);
680 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_Q0_REGNUM
+ element
/ 2;
681 regcache_cooked_write (regcache
, regnum
, valbuf
);
685 gdb_assert (bitpos
== 0 || bitpos
== 64);
687 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_D0_REGNUM
688 + element
+ bitpos
/ 64;
689 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
693 gdb_assert (len
== 4);
694 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 128);
696 regnum
= SPARC_F0_REGNUM
+ element
* 2 + bitpos
/ 32;
697 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
700 else if (sparc64_structure_or_union_p (type
))
704 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
706 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
707 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
709 sparc64_store_floating_fields (regcache
, subtype
, valbuf
,
713 /* GCC has an interesting bug. If TYPE is a structure that has
714 a single `float' member, GCC doesn't treat it as a structure
715 at all, but rather as an ordinary `float' argument. This
716 argument will be stored in %f1, as required by the psABI.
717 However, as a member of a structure the psABI requires it to
718 be stored in %f0. This bug is present in GCC 3.3.2, but
719 probably in older releases to. To appease GCC, if a
720 structure has only a single `float' member, we store its
721 value in %f1 too (we already have stored in %f0). */
722 if (TYPE_NFIELDS (type
) == 1)
724 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
726 if (sparc64_floating_p (subtype
) && TYPE_LENGTH (subtype
) == 4)
727 regcache_cooked_write (regcache
, SPARC_F1_REGNUM
, valbuf
);
732 /* Fetch floating fields from a variable of type TYPE from the
733 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
734 in VALBUF. This function can be called recursively and therefore
735 handles floating types in addition to structures. */
738 sparc64_extract_floating_fields (struct regcache
*regcache
, struct type
*type
,
739 gdb_byte
*valbuf
, int bitpos
)
741 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
743 if (sparc64_floating_p (type
))
745 int len
= TYPE_LENGTH (type
);
750 gdb_assert (bitpos
== 0 || bitpos
== 128);
752 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_Q0_REGNUM
754 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
758 gdb_assert (bitpos
% 64 == 0 && bitpos
>= 0 && bitpos
< 256);
760 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_D0_REGNUM
+ bitpos
/ 64;
761 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
765 gdb_assert (len
== 4);
766 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 256);
768 regnum
= SPARC_F0_REGNUM
+ bitpos
/ 32;
769 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
772 else if (sparc64_structure_or_union_p (type
))
776 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
778 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
779 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
781 sparc64_extract_floating_fields (regcache
, subtype
, valbuf
, subpos
);
786 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
787 non-zero) in REGCACHE and on the stack (starting from address SP). */
790 sparc64_store_arguments (struct regcache
*regcache
, int nargs
,
791 struct value
**args
, CORE_ADDR sp
,
792 int struct_return
, CORE_ADDR struct_addr
)
794 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
795 /* Number of extended words in the "parameter array". */
796 int num_elements
= 0;
800 /* Take BIAS into account. */
803 /* First we calculate the number of extended words in the "parameter
804 array". While doing so we also convert some of the arguments. */
809 for (i
= 0; i
< nargs
; i
++)
811 struct type
*type
= value_type (args
[i
]);
812 int len
= TYPE_LENGTH (type
);
814 if (sparc64_structure_or_union_p (type
)
815 || (sparc64_complex_floating_p (type
) && len
== 32))
817 /* Structure or Union arguments. */
820 if (num_elements
% 2 && sparc64_16_byte_align_p (type
))
822 num_elements
+= ((len
+ 7) / 8);
826 /* The psABI says that "Structures or unions larger than
827 sixteen bytes are copied by the caller and passed
828 indirectly; the caller will pass the address of a
829 correctly aligned structure value. This sixty-four
830 bit address will occupy one word in the parameter
831 array, and may be promoted to an %o register like any
832 other pointer value." Allocate memory for these
833 values on the stack. */
836 /* Use 16-byte alignment for these values. That's
837 always correct, and wasting a few bytes shouldn't be
841 write_memory (sp
, value_contents (args
[i
]), len
);
842 args
[i
] = value_from_pointer (lookup_pointer_type (type
), sp
);
846 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
848 /* Floating arguments. */
851 /* The psABI says that "Each quad-precision parameter
852 value will be assigned to two extended words in the
856 /* The psABI says that "Long doubles must be
857 quad-aligned, and thus a hole might be introduced
858 into the parameter array to force alignment." Skip
859 an element if necessary. */
860 if ((num_elements
% 2) && sparc64_16_byte_align_p (type
))
868 /* Integral and pointer arguments. */
869 gdb_assert (sparc64_integral_or_pointer_p (type
));
871 /* The psABI says that "Each argument value of integral type
872 smaller than an extended word will be widened by the
873 caller to an extended word according to the signed-ness
874 of the argument type." */
876 args
[i
] = value_cast (builtin_type (gdbarch
)->builtin_int64
,
882 /* Allocate the "parameter array". */
883 sp
-= num_elements
* 8;
885 /* The psABI says that "Every stack frame must be 16-byte aligned." */
888 /* Now we store the arguments in to the "paramater array". Some
889 Integer or Pointer arguments and Structure or Union arguments
890 will be passed in %o registers. Some Floating arguments and
891 floating members of structures are passed in floating-point
892 registers. However, for functions with variable arguments,
893 floating arguments are stored in an %0 register, and for
894 functions without a prototype floating arguments are stored in
895 both a floating-point and an %o registers, or a floating-point
896 register and memory. To simplify the logic here we always pass
897 arguments in memory, an %o register, and a floating-point
898 register if appropriate. This should be no problem since the
899 contents of any unused memory or registers in the "parameter
900 array" are undefined. */
904 regcache_cooked_write_unsigned (regcache
, SPARC_O0_REGNUM
, struct_addr
);
908 for (i
= 0; i
< nargs
; i
++)
910 const gdb_byte
*valbuf
= value_contents (args
[i
]);
911 struct type
*type
= value_type (args
[i
]);
912 int len
= TYPE_LENGTH (type
);
916 if (sparc64_structure_or_union_p (type
)
917 || (sparc64_complex_floating_p (type
) && len
== 32))
919 /* Structure, Union or long double Complex arguments. */
920 gdb_assert (len
<= 16);
921 memset (buf
, 0, sizeof (buf
));
922 memcpy (buf
, valbuf
, len
);
925 if (element
% 2 && sparc64_16_byte_align_p (type
))
930 regnum
= SPARC_O0_REGNUM
+ element
;
931 if (len
> 8 && element
< 5)
932 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
936 sparc64_store_floating_fields (regcache
, type
, valbuf
, element
, 0);
938 else if (sparc64_complex_floating_p (type
))
940 /* Float Complex or double Complex arguments. */
943 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_D0_REGNUM
+ element
;
947 if (regnum
< gdbarch_num_regs (gdbarch
) + SPARC64_D30_REGNUM
)
948 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
949 if (regnum
< gdbarch_num_regs (gdbarch
) + SPARC64_D10_REGNUM
)
950 regcache_cooked_write (regcache
,
951 SPARC_O0_REGNUM
+ element
+ 1,
956 else if (sparc64_floating_p (type
))
958 /* Floating arguments. */
964 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_Q0_REGNUM
970 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_D0_REGNUM
975 /* The psABI says "Each single-precision parameter value
976 will be assigned to one extended word in the
977 parameter array, and right-justified within that
978 word; the left half (even float register) is
979 undefined." Even though the psABI says that "the
980 left half is undefined", set it to zero here. */
982 memcpy (buf
+ 4, valbuf
, 4);
986 regnum
= gdbarch_num_regs (gdbarch
) + SPARC64_D0_REGNUM
992 /* Integral and pointer arguments. */
993 gdb_assert (len
== 8);
995 regnum
= SPARC_O0_REGNUM
+ element
;
1000 regcache_cooked_write (regcache
, regnum
, valbuf
);
1002 /* If we're storing the value in a floating-point register,
1003 also store it in the corresponding %0 register(s). */
1004 if (regnum
>= gdbarch_num_regs (gdbarch
))
1006 regnum
-= gdbarch_num_regs (gdbarch
);
1008 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D10_REGNUM
)
1010 gdb_assert (element
< 6);
1011 regnum
= SPARC_O0_REGNUM
+ element
;
1012 regcache_cooked_write (regcache
, regnum
, valbuf
);
1014 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q8_REGNUM
)
1016 gdb_assert (element
< 5);
1017 regnum
= SPARC_O0_REGNUM
+ element
;
1018 regcache_cooked_write (regcache
, regnum
, valbuf
);
1019 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
1024 /* Always store the argument in memory. */
1025 write_memory (sp
+ element
* 8, valbuf
, len
);
1026 element
+= ((len
+ 7) / 8);
1029 gdb_assert (element
== num_elements
);
1031 /* Take BIAS into account. */
1037 sparc64_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR address
)
1039 /* The ABI requires 16-byte alignment. */
1040 return address
& ~0xf;
1044 sparc64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
1045 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1046 int nargs
, struct value
**args
, CORE_ADDR sp
,
1047 int struct_return
, CORE_ADDR struct_addr
)
1049 /* Set return address. */
1050 regcache_cooked_write_unsigned (regcache
, SPARC_O7_REGNUM
, bp_addr
- 8);
1052 /* Set up function arguments. */
1053 sp
= sparc64_store_arguments (regcache
, nargs
, args
, sp
,
1054 struct_return
, struct_addr
);
1056 /* Allocate the register save area. */
1059 /* Stack should be 16-byte aligned at this point. */
1060 gdb_assert ((sp
+ BIAS
) % 16 == 0);
1062 /* Finally, update the stack pointer. */
1063 regcache_cooked_write_unsigned (regcache
, SPARC_SP_REGNUM
, sp
);
1069 /* Extract from an array REGBUF containing the (raw) register state, a
1070 function return value of TYPE, and copy that into VALBUF. */
1073 sparc64_extract_return_value (struct type
*type
, struct regcache
*regcache
,
1076 int len
= TYPE_LENGTH (type
);
1080 if (sparc64_structure_or_union_p (type
))
1082 /* Structure or Union return values. */
1083 gdb_assert (len
<= 32);
1085 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1086 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1087 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1088 sparc64_extract_floating_fields (regcache
, type
, buf
, 0);
1089 memcpy (valbuf
, buf
, len
);
1091 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
1093 /* Floating return values. */
1094 for (i
= 0; i
< len
/ 4; i
++)
1095 regcache_cooked_read (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1096 memcpy (valbuf
, buf
, len
);
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 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1104 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1105 memcpy (valbuf
, buf
, len
);
1109 /* Integral and pointer return values. */
1110 gdb_assert (sparc64_integral_or_pointer_p (type
));
1112 /* Just stripping off any unused bytes should preserve the
1113 signed-ness just fine. */
1114 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
, buf
);
1115 memcpy (valbuf
, buf
+ 8 - len
, len
);
1119 /* Write into the appropriate registers a function return value stored
1120 in VALBUF of type TYPE. */
1123 sparc64_store_return_value (struct type
*type
, struct regcache
*regcache
,
1124 const gdb_byte
*valbuf
)
1126 int len
= TYPE_LENGTH (type
);
1130 if (sparc64_structure_or_union_p (type
))
1132 /* Structure or Union return values. */
1133 gdb_assert (len
<= 32);
1135 /* Simplify matters by storing the complete value (including
1136 floating members) into %o0 and %o1. Floating members are
1137 also store in the appropriate floating-point registers. */
1138 memset (buf
, 0, sizeof (buf
));
1139 memcpy (buf
, valbuf
, len
);
1140 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1141 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1142 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1143 sparc64_store_floating_fields (regcache
, type
, buf
, 0, 0);
1145 else if (sparc64_floating_p (type
) || sparc64_complex_floating_p (type
))
1147 /* Floating return values. */
1148 memcpy (buf
, valbuf
, len
);
1149 for (i
= 0; i
< len
/ 4; i
++)
1150 regcache_cooked_write (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1152 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1154 /* Small arrays are returned the same way as small structures. */
1155 gdb_assert (len
<= 32);
1157 memset (buf
, 0, sizeof (buf
));
1158 memcpy (buf
, valbuf
, len
);
1159 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1160 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1164 /* Integral and pointer return values. */
1165 gdb_assert (sparc64_integral_or_pointer_p (type
));
1167 /* ??? Do we need to do any sign-extension here? */
1169 memcpy (buf
+ 8 - len
, valbuf
, len
);
1170 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
, buf
);
1174 static enum return_value_convention
1175 sparc64_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
1176 struct type
*type
, struct regcache
*regcache
,
1177 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
1179 if (TYPE_LENGTH (type
) > 32)
1180 return RETURN_VALUE_STRUCT_CONVENTION
;
1183 sparc64_extract_return_value (type
, regcache
, readbuf
);
1185 sparc64_store_return_value (type
, regcache
, writebuf
);
1187 return RETURN_VALUE_REGISTER_CONVENTION
;
1192 sparc64_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1193 struct dwarf2_frame_state_reg
*reg
,
1194 struct frame_info
*this_frame
)
1198 case SPARC_G0_REGNUM
:
1199 /* Since %g0 is always zero, there is no point in saving it, and
1200 people will be inclined omit it from the CFI. Make sure we
1201 don't warn about that. */
1202 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1204 case SPARC_SP_REGNUM
:
1205 reg
->how
= DWARF2_FRAME_REG_CFA
;
1207 case SPARC64_PC_REGNUM
:
1208 reg
->how
= DWARF2_FRAME_REG_RA_OFFSET
;
1209 reg
->loc
.offset
= 8;
1211 case SPARC64_NPC_REGNUM
:
1212 reg
->how
= DWARF2_FRAME_REG_RA_OFFSET
;
1213 reg
->loc
.offset
= 12;
1219 sparc64_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1221 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1223 tdep
->pc_regnum
= SPARC64_PC_REGNUM
;
1224 tdep
->npc_regnum
= SPARC64_NPC_REGNUM
;
1226 /* This is what all the fuss is about. */
1227 set_gdbarch_long_bit (gdbarch
, 64);
1228 set_gdbarch_long_long_bit (gdbarch
, 64);
1229 set_gdbarch_ptr_bit (gdbarch
, 64);
1231 set_gdbarch_num_regs (gdbarch
, SPARC64_NUM_REGS
);
1232 set_gdbarch_register_name (gdbarch
, sparc64_register_name
);
1233 set_gdbarch_register_type (gdbarch
, sparc64_register_type
);
1234 set_gdbarch_num_pseudo_regs (gdbarch
, SPARC64_NUM_PSEUDO_REGS
);
1235 set_gdbarch_pseudo_register_read (gdbarch
, sparc64_pseudo_register_read
);
1236 set_gdbarch_pseudo_register_write (gdbarch
, sparc64_pseudo_register_write
);
1238 /* Register numbers of various important registers. */
1239 set_gdbarch_pc_regnum (gdbarch
, SPARC64_PC_REGNUM
); /* %pc */
1241 /* Call dummy code. */
1242 set_gdbarch_frame_align (gdbarch
, sparc64_frame_align
);
1243 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
1244 set_gdbarch_push_dummy_code (gdbarch
, NULL
);
1245 set_gdbarch_push_dummy_call (gdbarch
, sparc64_push_dummy_call
);
1247 set_gdbarch_return_value (gdbarch
, sparc64_return_value
);
1248 set_gdbarch_stabs_argument_has_addr
1249 (gdbarch
, default_stabs_argument_has_addr
);
1251 set_gdbarch_skip_prologue (gdbarch
, sparc64_skip_prologue
);
1252 set_gdbarch_stack_frame_destroyed_p (gdbarch
, sparc_stack_frame_destroyed_p
);
1254 /* Hook in the DWARF CFI frame unwinder. */
1255 dwarf2_frame_set_init_reg (gdbarch
, sparc64_dwarf2_frame_init_reg
);
1256 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1257 StackGhost issues have been resolved. */
1259 frame_unwind_append_unwinder (gdbarch
, &sparc64_frame_unwind
);
1260 frame_base_set_default (gdbarch
, &sparc64_frame_base
);
1264 /* Helper functions for dealing with register sets. */
1266 #define TSTATE_CWP 0x000000000000001fULL
1267 #define TSTATE_ICC 0x0000000f00000000ULL
1268 #define TSTATE_XCC 0x000000f000000000ULL
1270 #define PSR_S 0x00000080
1271 #define PSR_ICC 0x00f00000
1272 #define PSR_VERS 0x0f000000
1273 #define PSR_IMPL 0xf0000000
1274 #define PSR_V8PLUS 0xff000000
1275 #define PSR_XCC 0x000f0000
1278 sparc64_supply_gregset (const struct sparc_gregmap
*gregmap
,
1279 struct regcache
*regcache
,
1280 int regnum
, const void *gregs
)
1282 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1283 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1284 int sparc32
= (gdbarch_ptr_bit (gdbarch
) == 32);
1285 const gdb_byte
*regs
= (const gdb_byte
*) gregs
;
1286 gdb_byte zero
[8] = { 0 };
1291 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1293 int offset
= gregmap
->r_tstate_offset
;
1294 ULONGEST tstate
, psr
;
1297 tstate
= extract_unsigned_integer (regs
+ offset
, 8, byte_order
);
1298 psr
= ((tstate
& TSTATE_CWP
) | PSR_S
| ((tstate
& TSTATE_ICC
) >> 12)
1299 | ((tstate
& TSTATE_XCC
) >> 20) | PSR_V8PLUS
);
1300 store_unsigned_integer (buf
, 4, byte_order
, psr
);
1301 regcache_raw_supply (regcache
, SPARC32_PSR_REGNUM
, buf
);
1304 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1305 regcache_raw_supply (regcache
, SPARC32_PC_REGNUM
,
1306 regs
+ gregmap
->r_pc_offset
+ 4);
1308 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1309 regcache_raw_supply (regcache
, SPARC32_NPC_REGNUM
,
1310 regs
+ gregmap
->r_npc_offset
+ 4);
1312 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1314 int offset
= gregmap
->r_y_offset
+ 8 - gregmap
->r_y_size
;
1315 regcache_raw_supply (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1320 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1321 regcache_raw_supply (regcache
, SPARC64_STATE_REGNUM
,
1322 regs
+ gregmap
->r_tstate_offset
);
1324 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1325 regcache_raw_supply (regcache
, SPARC64_PC_REGNUM
,
1326 regs
+ gregmap
->r_pc_offset
);
1328 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1329 regcache_raw_supply (regcache
, SPARC64_NPC_REGNUM
,
1330 regs
+ gregmap
->r_npc_offset
);
1332 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1337 memcpy (buf
+ 8 - gregmap
->r_y_size
,
1338 regs
+ gregmap
->r_y_offset
, gregmap
->r_y_size
);
1339 regcache_raw_supply (regcache
, SPARC64_Y_REGNUM
, buf
);
1342 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1343 && gregmap
->r_fprs_offset
!= -1)
1344 regcache_raw_supply (regcache
, SPARC64_FPRS_REGNUM
,
1345 regs
+ gregmap
->r_fprs_offset
);
1348 if (regnum
== SPARC_G0_REGNUM
|| regnum
== -1)
1349 regcache_raw_supply (regcache
, SPARC_G0_REGNUM
, &zero
);
1351 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1353 int offset
= gregmap
->r_g1_offset
;
1358 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1360 if (regnum
== i
|| regnum
== -1)
1361 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1366 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1368 /* Not all of the register set variants include Locals and
1369 Inputs. For those that don't, we read them off the stack. */
1370 if (gregmap
->r_l0_offset
== -1)
1374 regcache_cooked_read_unsigned (regcache
, SPARC_SP_REGNUM
, &sp
);
1375 sparc_supply_rwindow (regcache
, sp
, regnum
);
1379 int offset
= gregmap
->r_l0_offset
;
1384 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1386 if (regnum
== i
|| regnum
== -1)
1387 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1395 sparc64_collect_gregset (const struct sparc_gregmap
*gregmap
,
1396 const struct regcache
*regcache
,
1397 int regnum
, void *gregs
)
1399 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1400 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1401 int sparc32
= (gdbarch_ptr_bit (gdbarch
) == 32);
1402 gdb_byte
*regs
= (gdb_byte
*) gregs
;
1407 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1409 int offset
= gregmap
->r_tstate_offset
;
1410 ULONGEST tstate
, psr
;
1413 tstate
= extract_unsigned_integer (regs
+ offset
, 8, byte_order
);
1414 regcache_raw_collect (regcache
, SPARC32_PSR_REGNUM
, buf
);
1415 psr
= extract_unsigned_integer (buf
, 4, byte_order
);
1416 tstate
|= (psr
& PSR_ICC
) << 12;
1417 if ((psr
& (PSR_VERS
| PSR_IMPL
)) == PSR_V8PLUS
)
1418 tstate
|= (psr
& PSR_XCC
) << 20;
1419 store_unsigned_integer (buf
, 8, byte_order
, tstate
);
1420 memcpy (regs
+ offset
, buf
, 8);
1423 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1424 regcache_raw_collect (regcache
, SPARC32_PC_REGNUM
,
1425 regs
+ gregmap
->r_pc_offset
+ 4);
1427 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1428 regcache_raw_collect (regcache
, SPARC32_NPC_REGNUM
,
1429 regs
+ gregmap
->r_npc_offset
+ 4);
1431 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1433 int offset
= gregmap
->r_y_offset
+ 8 - gregmap
->r_y_size
;
1434 regcache_raw_collect (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1439 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1440 regcache_raw_collect (regcache
, SPARC64_STATE_REGNUM
,
1441 regs
+ gregmap
->r_tstate_offset
);
1443 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1444 regcache_raw_collect (regcache
, SPARC64_PC_REGNUM
,
1445 regs
+ gregmap
->r_pc_offset
);
1447 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1448 regcache_raw_collect (regcache
, SPARC64_NPC_REGNUM
,
1449 regs
+ gregmap
->r_npc_offset
);
1451 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1455 regcache_raw_collect (regcache
, SPARC64_Y_REGNUM
, buf
);
1456 memcpy (regs
+ gregmap
->r_y_offset
,
1457 buf
+ 8 - gregmap
->r_y_size
, gregmap
->r_y_size
);
1460 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1461 && gregmap
->r_fprs_offset
!= -1)
1462 regcache_raw_collect (regcache
, SPARC64_FPRS_REGNUM
,
1463 regs
+ gregmap
->r_fprs_offset
);
1467 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1469 int offset
= gregmap
->r_g1_offset
;
1474 /* %g0 is always zero. */
1475 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1477 if (regnum
== i
|| regnum
== -1)
1478 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1483 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1485 /* Not all of the register set variants include Locals and
1486 Inputs. For those that don't, we read them off the stack. */
1487 if (gregmap
->r_l0_offset
!= -1)
1489 int offset
= gregmap
->r_l0_offset
;
1494 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1496 if (regnum
== i
|| regnum
== -1)
1497 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1505 sparc64_supply_fpregset (const struct sparc_fpregmap
*fpregmap
,
1506 struct regcache
*regcache
,
1507 int regnum
, const void *fpregs
)
1509 int sparc32
= (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32);
1510 const gdb_byte
*regs
= (const gdb_byte
*) fpregs
;
1513 for (i
= 0; i
< 32; i
++)
1515 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1516 regcache_raw_supply (regcache
, SPARC_F0_REGNUM
+ i
,
1517 regs
+ fpregmap
->r_f0_offset
+ (i
* 4));
1522 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1523 regcache_raw_supply (regcache
, SPARC32_FSR_REGNUM
,
1524 regs
+ fpregmap
->r_fsr_offset
);
1528 for (i
= 0; i
< 16; i
++)
1530 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1531 regcache_raw_supply (regcache
, SPARC64_F32_REGNUM
+ i
,
1532 (regs
+ fpregmap
->r_f0_offset
1533 + (32 * 4) + (i
* 8)));
1536 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1537 regcache_raw_supply (regcache
, SPARC64_FSR_REGNUM
,
1538 regs
+ fpregmap
->r_fsr_offset
);
1543 sparc64_collect_fpregset (const struct sparc_fpregmap
*fpregmap
,
1544 const struct regcache
*regcache
,
1545 int regnum
, void *fpregs
)
1547 int sparc32
= (gdbarch_ptr_bit (get_regcache_arch (regcache
)) == 32);
1548 gdb_byte
*regs
= (gdb_byte
*) fpregs
;
1551 for (i
= 0; i
< 32; i
++)
1553 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1554 regcache_raw_collect (regcache
, SPARC_F0_REGNUM
+ i
,
1555 regs
+ fpregmap
->r_f0_offset
+ (i
* 4));
1560 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1561 regcache_raw_collect (regcache
, SPARC32_FSR_REGNUM
,
1562 regs
+ fpregmap
->r_fsr_offset
);
1566 for (i
= 0; i
< 16; i
++)
1568 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1569 regcache_raw_collect (regcache
, SPARC64_F32_REGNUM
+ i
,
1570 (regs
+ fpregmap
->r_f0_offset
1571 + (32 * 4) + (i
* 8)));
1574 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1575 regcache_raw_collect (regcache
, SPARC64_FSR_REGNUM
,
1576 regs
+ fpregmap
->r_fsr_offset
);
1580 const struct sparc_fpregmap sparc64_bsd_fpregmap
=