Automatic date update in version.in
[binutils-gdb.git] / gdb / sparc64-tdep.c
bloba55107fa32d9edc1912a7f11dd8149d7727f8be0
1 /* Target-dependent code for UltraSPARC.
3 Copyright (C) 2003-2024 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/>. */
20 #include "arch-utils.h"
21 #include "dwarf2/frame.h"
22 #include "frame.h"
23 #include "frame-base.h"
24 #include "frame-unwind.h"
25 #include "gdbcore.h"
26 #include "gdbtypes.h"
27 #include "inferior.h"
28 #include "symtab.h"
29 #include "objfiles.h"
30 #include "osabi.h"
31 #include "regcache.h"
32 #include "target-descriptions.h"
33 #include "target.h"
34 #include "value.h"
35 #include "sparc64-tdep.h"
36 #include <forward_list>
38 /* This file implements the SPARC 64-bit ABI as defined by the
39 section "Low-Level System Information" of the SPARC Compliance
40 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
41 SPARC. */
43 /* Please use the sparc32_-prefix for 32-bit specific code, the
44 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
45 code can handle both. */
47 /* The M7 processor supports an Application Data Integrity (ADI) feature
48 that detects invalid data accesses. When software allocates memory and
49 enables ADI on the allocated memory, it chooses a 4-bit version number,
50 sets the version in the upper 4 bits of the 64-bit pointer to that data,
51 and stores the 4-bit version in every cacheline of the object. Hardware
52 saves the latter in spare bits in the cache and memory hierarchy. On each
53 load and store, the processor compares the upper 4 VA (virtual address) bits
54 to the cacheline's version. If there is a mismatch, the processor generates
55 a version mismatch trap which can be either precise or disrupting.
56 The trap is an error condition which the kernel delivers to the process
57 as a SIGSEGV signal.
59 The upper 4 bits of the VA represent a version and are not part of the
60 true address. The processor clears these bits and sign extends bit 59
61 to generate the true address.
63 Note that 32-bit applications cannot use ADI. */
66 #include <algorithm>
67 #include "cli/cli-utils.h"
68 #include "gdbcmd.h"
69 #include "auxv.h"
71 #define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/9999/adi/lstatus")
73 /* ELF Auxiliary vectors */
74 #ifndef AT_ADI_BLKSZ
75 #define AT_ADI_BLKSZ 34
76 #endif
77 #ifndef AT_ADI_NBITS
78 #define AT_ADI_NBITS 35
79 #endif
80 #ifndef AT_ADI_UEONADI
81 #define AT_ADI_UEONADI 36
82 #endif
84 /* ADI command list. */
85 static struct cmd_list_element *sparc64adilist = NULL;
87 /* ADI stat settings. */
88 struct adi_stat_t
90 /* The ADI block size. */
91 unsigned long blksize;
93 /* Number of bits used for an ADI version tag which can be
94 used together with the shift value for an ADI version tag
95 to encode or extract the ADI version value in a pointer. */
96 unsigned long nbits;
98 /* The maximum ADI version tag value supported. */
99 int max_version;
101 /* ADI version tag file. */
102 int tag_fd = 0;
104 /* ADI availability check has been done. */
105 bool checked_avail = false;
107 /* ADI is available. */
108 bool is_avail = false;
112 /* Per-process ADI stat info. */
114 struct sparc64_adi_info
116 sparc64_adi_info (pid_t pid_)
117 : pid (pid_)
120 /* The process identifier. */
121 pid_t pid;
123 /* The ADI stat. */
124 adi_stat_t stat = {};
128 static std::forward_list<sparc64_adi_info> adi_proc_list;
131 /* Get ADI info for process PID, creating one if it doesn't exist. */
133 static sparc64_adi_info *
134 get_adi_info_proc (pid_t pid)
136 auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (),
137 [&pid] (const sparc64_adi_info &info)
139 return info.pid == pid;
142 if (found == adi_proc_list.end ())
144 adi_proc_list.emplace_front (pid);
145 return &adi_proc_list.front ();
147 else
149 return &(*found);
153 static adi_stat_t
154 get_adi_info (pid_t pid)
156 sparc64_adi_info *proc;
158 proc = get_adi_info_proc (pid);
159 return proc->stat;
162 /* Is called when GDB is no longer debugging process PID. It
163 deletes data structure that keeps track of the ADI stat. */
165 void
166 sparc64_forget_process (pid_t pid)
168 fileio_error target_errno;
170 for (auto pit = adi_proc_list.before_begin (),
171 it = std::next (pit);
172 it != adi_proc_list.end ();
175 if ((*it).pid == pid)
177 if ((*it).stat.tag_fd > 0)
178 target_fileio_close ((*it).stat.tag_fd, &target_errno);
179 adi_proc_list.erase_after (pit);
180 break;
182 else
183 pit = it++;
188 /* Read attributes of a maps entry in /proc/[pid]/adi/maps. */
190 static void
191 read_maps_entry (const char *line,
192 ULONGEST *addr, ULONGEST *endaddr)
194 const char *p = line;
196 *addr = strtoulst (p, &p, 16);
197 if (*p == '-')
198 p++;
200 *endaddr = strtoulst (p, &p, 16);
203 /* Check if ADI is available. */
205 static bool
206 adi_available (void)
208 pid_t pid = inferior_ptid.pid ();
209 sparc64_adi_info *proc = get_adi_info_proc (pid);
210 CORE_ADDR value;
212 if (proc->stat.checked_avail)
213 return proc->stat.is_avail;
215 proc->stat.checked_avail = true;
216 if (target_auxv_search (AT_ADI_BLKSZ, &value) <= 0)
217 return false;
218 proc->stat.blksize = value;
219 target_auxv_search (AT_ADI_NBITS, &value);
220 proc->stat.nbits = value;
221 proc->stat.max_version = (1 << proc->stat.nbits) - 2;
222 proc->stat.is_avail = true;
224 return proc->stat.is_avail;
227 /* Normalize a versioned address - a VA with ADI bits (63-60) set. */
229 static CORE_ADDR
230 adi_normalize_address (CORE_ADDR addr)
232 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
234 if (ast.nbits)
236 /* Clear upper bits. */
237 addr &= ((uint64_t) -1) >> ast.nbits;
239 /* Sign extend. */
240 CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
241 return (addr ^ signbit) - signbit;
243 return addr;
246 /* Align a normalized address - a VA with bit 59 sign extended into
247 ADI bits. */
249 static CORE_ADDR
250 adi_align_address (CORE_ADDR naddr)
252 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
254 return (naddr - (naddr % ast.blksize)) / ast.blksize;
257 /* Convert a byte count to count at a ratio of 1:adi_blksz. */
259 static int
260 adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl)
262 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
264 return ((naddr + nbytes + ast.blksize - 1) / ast.blksize) - locl;
267 /* The /proc/[pid]/adi/tags file, which allows gdb to get/set ADI
268 version in a target process, maps linearly to the address space
269 of the target process at a ratio of 1:adi_blksz.
271 A read (or write) at offset K in the file returns (or modifies)
272 the ADI version tag stored in the cacheline containing address
273 K * adi_blksz, encoded as 1 version tag per byte. The allowed
274 version tag values are between 0 and adi_stat.max_version. */
276 static int
277 adi_tag_fd (void)
279 pid_t pid = inferior_ptid.pid ();
280 sparc64_adi_info *proc = get_adi_info_proc (pid);
282 if (proc->stat.tag_fd != 0)
283 return proc->stat.tag_fd;
285 char cl_name[MAX_PROC_NAME_SIZE];
286 snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid);
287 fileio_error target_errno;
288 proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL,
289 false, 0, &target_errno);
290 return proc->stat.tag_fd;
293 /* Check if an address set is ADI enabled, using /proc/[pid]/adi/maps
294 which was exported by the kernel and contains the currently ADI
295 mapped memory regions and their access permissions. */
297 static bool
298 adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt)
300 char filename[MAX_PROC_NAME_SIZE];
301 size_t i = 0;
303 pid_t pid = inferior_ptid.pid ();
304 snprintf (filename, sizeof filename, "/proc/%ld/adi/maps", (long) pid);
305 gdb::unique_xmalloc_ptr<char> data
306 = target_fileio_read_stralloc (NULL, filename);
307 if (data)
309 adi_stat_t adi_stat = get_adi_info (pid);
310 char *saveptr;
311 for (char *line = strtok_r (data.get (), "\n", &saveptr);
312 line;
313 line = strtok_r (NULL, "\n", &saveptr))
315 ULONGEST addr, endaddr;
317 read_maps_entry (line, &addr, &endaddr);
319 while (((vaddr + i) * adi_stat.blksize) >= addr
320 && ((vaddr + i) * adi_stat.blksize) < endaddr)
322 if (++i == cnt)
323 return true;
327 else
328 warning (_("unable to open /proc file '%s'"), filename);
330 return false;
333 /* Read ADI version tag value for memory locations starting at "VADDR"
334 for "SIZE" number of bytes. */
336 static int
337 adi_read_versions (CORE_ADDR vaddr, size_t size, gdb_byte *tags)
339 int fd = adi_tag_fd ();
340 if (fd == -1)
341 return -1;
343 if (!adi_is_addr_mapped (vaddr, size))
345 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
346 error(_("Address at %s is not in ADI maps"),
347 paddress (current_inferior ()->arch (), vaddr * ast.blksize));
350 fileio_error target_errno;
351 return target_fileio_pread (fd, tags, size, vaddr, &target_errno);
354 /* Write ADI version tag for memory locations starting at "VADDR" for
355 "SIZE" number of bytes to "TAGS". */
357 static int
358 adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
360 int fd = adi_tag_fd ();
361 if (fd == -1)
362 return -1;
364 if (!adi_is_addr_mapped (vaddr, size))
366 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
367 error(_("Address at %s is not in ADI maps"),
368 paddress (current_inferior ()->arch (), vaddr * ast.blksize));
371 fileio_error target_errno;
372 return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno);
375 /* Print ADI version tag value in "TAGS" for memory locations starting
376 at "VADDR" with number of "CNT". */
378 static void
379 adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
381 int v_idx = 0;
382 const int maxelts = 8; /* # of elements per line */
384 adi_stat_t adi_stat = get_adi_info (inferior_ptid.pid ());
386 while (cnt > 0)
388 QUIT;
389 gdb_printf ("%s:\t",
390 paddress (current_inferior ()->arch (),
391 vaddr * adi_stat.blksize));
392 for (int i = maxelts; i > 0 && cnt > 0; i--, cnt--)
394 if (tags[v_idx] == 0xff) /* no version tag */
395 gdb_printf ("-");
396 else
397 gdb_printf ("%1X", tags[v_idx]);
398 if (cnt > 1)
399 gdb_printf (" ");
400 ++v_idx;
402 gdb_printf ("\n");
403 vaddr += maxelts;
407 static void
408 do_examine (CORE_ADDR start, int bcnt)
410 CORE_ADDR vaddr = adi_normalize_address (start);
412 CORE_ADDR vstart = adi_align_address (vaddr);
413 int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
414 gdb::byte_vector buf (cnt);
415 int read_cnt = adi_read_versions (vstart, cnt, buf.data ());
416 if (read_cnt == -1)
417 error (_("No ADI information"));
418 else if (read_cnt < cnt)
419 error(_("No ADI information at %s"),
420 paddress (current_inferior ()->arch (), vaddr));
422 adi_print_versions (vstart, cnt, buf.data ());
425 static void
426 do_assign (CORE_ADDR start, size_t bcnt, int version)
428 CORE_ADDR vaddr = adi_normalize_address (start);
430 CORE_ADDR vstart = adi_align_address (vaddr);
431 int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
432 std::vector<unsigned char> buf (cnt, version);
433 int set_cnt = adi_write_versions (vstart, cnt, buf.data ());
435 if (set_cnt == -1)
436 error (_("No ADI information"));
437 else if (set_cnt < cnt)
438 error(_("No ADI information at %s"),
439 paddress (current_inferior ()->arch (), vaddr));
442 /* ADI examine version tag command.
444 Command syntax:
446 adi (examine|x)[/COUNT] [ADDR] */
448 static void
449 adi_examine_command (const char *args, int from_tty)
451 /* make sure program is active and adi is available */
452 if (!target_has_execution ())
453 error (_("ADI command requires a live process/thread"));
455 if (!adi_available ())
456 error (_("No ADI information"));
458 int cnt = 1;
459 const char *p = args;
460 if (p && *p == '/')
462 p++;
463 cnt = get_number (&p);
466 CORE_ADDR next_address = 0;
467 if (p != 0 && *p != 0)
468 next_address = parse_and_eval_address (p);
469 if (!cnt || !next_address)
470 error (_("Usage: adi examine|x[/COUNT] [ADDR]"));
472 do_examine (next_address, cnt);
475 /* ADI assign version tag command.
477 Command syntax:
479 adi (assign|a)[/COUNT] ADDR = VERSION */
481 static void
482 adi_assign_command (const char *args, int from_tty)
484 static const char *adi_usage
485 = N_("Usage: adi assign|a[/COUNT] ADDR = VERSION");
487 /* make sure program is active and adi is available */
488 if (!target_has_execution ())
489 error (_("ADI command requires a live process/thread"));
491 if (!adi_available ())
492 error (_("No ADI information"));
494 const char *exp = args;
495 if (exp == 0)
496 error_no_arg (_(adi_usage));
498 char *q = (char *) strchr (exp, '=');
499 if (q)
500 *q++ = 0;
501 else
502 error ("%s", _(adi_usage));
504 size_t cnt = 1;
505 const char *p = args;
506 if (exp && *exp == '/')
508 p = exp + 1;
509 cnt = get_number (&p);
512 CORE_ADDR next_address = 0;
513 if (p != 0 && *p != 0)
514 next_address = parse_and_eval_address (p);
515 else
516 error ("%s", _(adi_usage));
518 int version = 0;
519 if (q != NULL) /* parse version tag */
521 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
522 version = parse_and_eval_long (q);
523 if (version < 0 || version > ast.max_version)
524 error (_("Invalid ADI version tag %d"), version);
527 do_assign (next_address, cnt, version);
530 void _initialize_sparc64_adi_tdep ();
531 void
532 _initialize_sparc64_adi_tdep ()
534 add_basic_prefix_cmd ("adi", class_support,
535 _("ADI version related commands."),
536 &sparc64adilist, 0, &cmdlist);
537 cmd_list_element *adi_examine_cmd
538 = add_cmd ("examine", class_support, adi_examine_command,
539 _("Examine ADI versions."), &sparc64adilist);
540 add_alias_cmd ("x", adi_examine_cmd, no_class, 1, &sparc64adilist);
541 add_cmd ("assign", class_support, adi_assign_command,
542 _("Assign ADI versions."), &sparc64adilist);
547 /* The functions on this page are intended to be used to classify
548 function arguments. */
550 /* Check whether TYPE is "Integral or Pointer". */
552 static int
553 sparc64_integral_or_pointer_p (const struct type *type)
555 switch (type->code ())
557 case TYPE_CODE_INT:
558 case TYPE_CODE_BOOL:
559 case TYPE_CODE_CHAR:
560 case TYPE_CODE_ENUM:
561 case TYPE_CODE_RANGE:
563 int len = type->length ();
564 gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
566 return 1;
567 case TYPE_CODE_PTR:
568 case TYPE_CODE_REF:
569 case TYPE_CODE_RVALUE_REF:
571 int len = type->length ();
572 gdb_assert (len == 8);
574 return 1;
575 default:
576 break;
579 return 0;
582 /* Check whether TYPE is "Floating". */
584 static int
585 sparc64_floating_p (const struct type *type)
587 switch (type->code ())
589 case TYPE_CODE_FLT:
591 int len = type->length ();
592 gdb_assert (len == 4 || len == 8 || len == 16);
594 return 1;
595 default:
596 break;
599 return 0;
602 /* Check whether TYPE is "Complex Floating". */
604 static int
605 sparc64_complex_floating_p (const struct type *type)
607 switch (type->code ())
609 case TYPE_CODE_COMPLEX:
611 int len = type->length ();
612 gdb_assert (len == 8 || len == 16 || len == 32);
614 return 1;
615 default:
616 break;
619 return 0;
622 /* Check whether TYPE is "Structure or Union".
624 In terms of Ada subprogram calls, arrays are treated the same as
625 struct and union types. So this function also returns non-zero
626 for array types. */
628 static int
629 sparc64_structure_or_union_p (const struct type *type)
631 switch (type->code ())
633 case TYPE_CODE_STRUCT:
634 case TYPE_CODE_UNION:
635 case TYPE_CODE_ARRAY:
636 return 1;
637 default:
638 break;
641 return 0;
645 /* Construct types for ISA-specific registers. */
647 static struct type *
648 sparc64_pstate_type (struct gdbarch *gdbarch)
650 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
652 if (!tdep->sparc64_pstate_type)
654 struct type *type;
656 type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 64);
657 append_flags_type_flag (type, 0, "AG");
658 append_flags_type_flag (type, 1, "IE");
659 append_flags_type_flag (type, 2, "PRIV");
660 append_flags_type_flag (type, 3, "AM");
661 append_flags_type_flag (type, 4, "PEF");
662 append_flags_type_flag (type, 5, "RED");
663 append_flags_type_flag (type, 8, "TLE");
664 append_flags_type_flag (type, 9, "CLE");
665 append_flags_type_flag (type, 10, "PID0");
666 append_flags_type_flag (type, 11, "PID1");
668 tdep->sparc64_pstate_type = type;
671 return tdep->sparc64_pstate_type;
674 static struct type *
675 sparc64_ccr_type (struct gdbarch *gdbarch)
677 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
679 if (tdep->sparc64_ccr_type == NULL)
681 struct type *type;
683 type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 64);
684 append_flags_type_flag (type, 0, "icc.c");
685 append_flags_type_flag (type, 1, "icc.v");
686 append_flags_type_flag (type, 2, "icc.z");
687 append_flags_type_flag (type, 3, "icc.n");
688 append_flags_type_flag (type, 4, "xcc.c");
689 append_flags_type_flag (type, 5, "xcc.v");
690 append_flags_type_flag (type, 6, "xcc.z");
691 append_flags_type_flag (type, 7, "xcc.n");
693 tdep->sparc64_ccr_type = type;
696 return tdep->sparc64_ccr_type;
699 static struct type *
700 sparc64_fsr_type (struct gdbarch *gdbarch)
702 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
704 if (!tdep->sparc64_fsr_type)
706 struct type *type;
708 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 64);
709 append_flags_type_flag (type, 0, "NXC");
710 append_flags_type_flag (type, 1, "DZC");
711 append_flags_type_flag (type, 2, "UFC");
712 append_flags_type_flag (type, 3, "OFC");
713 append_flags_type_flag (type, 4, "NVC");
714 append_flags_type_flag (type, 5, "NXA");
715 append_flags_type_flag (type, 6, "DZA");
716 append_flags_type_flag (type, 7, "UFA");
717 append_flags_type_flag (type, 8, "OFA");
718 append_flags_type_flag (type, 9, "NVA");
719 append_flags_type_flag (type, 22, "NS");
720 append_flags_type_flag (type, 23, "NXM");
721 append_flags_type_flag (type, 24, "DZM");
722 append_flags_type_flag (type, 25, "UFM");
723 append_flags_type_flag (type, 26, "OFM");
724 append_flags_type_flag (type, 27, "NVM");
726 tdep->sparc64_fsr_type = type;
729 return tdep->sparc64_fsr_type;
732 static struct type *
733 sparc64_fprs_type (struct gdbarch *gdbarch)
735 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
737 if (!tdep->sparc64_fprs_type)
739 struct type *type;
741 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 64);
742 append_flags_type_flag (type, 0, "DL");
743 append_flags_type_flag (type, 1, "DU");
744 append_flags_type_flag (type, 2, "FEF");
746 tdep->sparc64_fprs_type = type;
749 return tdep->sparc64_fprs_type;
753 /* Register information. */
754 #define SPARC64_FPU_REGISTERS \
755 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
756 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
757 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
758 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
759 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
760 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62"
761 #define SPARC64_CP0_REGISTERS \
762 "pc", "npc", \
763 /* FIXME: Give "state" a name until we start using register groups. */ \
764 "state", \
765 "fsr", \
766 "fprs", \
769 static const char * const sparc64_fpu_register_names[] = {
770 SPARC64_FPU_REGISTERS
772 static const char * const sparc64_cp0_register_names[] = {
773 SPARC64_CP0_REGISTERS
776 static const char * const sparc64_register_names[] =
778 SPARC_CORE_REGISTERS,
779 SPARC64_FPU_REGISTERS,
780 SPARC64_CP0_REGISTERS
783 /* Total number of registers. */
784 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
786 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
787 registers as "psuedo" registers. */
789 static const char * const sparc64_pseudo_register_names[] =
791 "cwp", "pstate", "asi", "ccr",
793 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
794 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
795 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
796 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
798 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
799 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
802 /* Total number of pseudo registers. */
803 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
805 /* Return the name of pseudo register REGNUM. */
807 static const char *
808 sparc64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
810 regnum -= gdbarch_num_regs (gdbarch);
812 gdb_assert (regnum < SPARC64_NUM_PSEUDO_REGS);
813 return sparc64_pseudo_register_names[regnum];
816 /* Return the name of register REGNUM. */
818 static const char *
819 sparc64_register_name (struct gdbarch *gdbarch, int regnum)
821 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
822 return tdesc_register_name (gdbarch, regnum);
824 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
825 return sparc64_register_names[regnum];
827 return sparc64_pseudo_register_name (gdbarch, regnum);
830 /* Return the GDB type object for the "standard" data type of data in
831 pseudo register REGNUM. */
833 static struct type *
834 sparc64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
836 regnum -= gdbarch_num_regs (gdbarch);
838 if (regnum == SPARC64_CWP_REGNUM)
839 return builtin_type (gdbarch)->builtin_int64;
840 if (regnum == SPARC64_PSTATE_REGNUM)
841 return sparc64_pstate_type (gdbarch);
842 if (regnum == SPARC64_ASI_REGNUM)
843 return builtin_type (gdbarch)->builtin_int64;
844 if (regnum == SPARC64_CCR_REGNUM)
845 return sparc64_ccr_type (gdbarch);
846 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM)
847 return builtin_type (gdbarch)->builtin_double;
848 if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM)
849 return builtin_type (gdbarch)->builtin_long_double;
851 internal_error (_("sparc64_pseudo_register_type: bad register number %d"),
852 regnum);
855 /* Return the GDB type object for the "standard" data type of data in
856 register REGNUM. */
858 static struct type *
859 sparc64_register_type (struct gdbarch *gdbarch, int regnum)
861 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
862 return tdesc_register_type (gdbarch, regnum);
864 /* Raw registers. */
865 if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
866 return builtin_type (gdbarch)->builtin_data_ptr;
867 if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM)
868 return builtin_type (gdbarch)->builtin_int64;
869 if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
870 return builtin_type (gdbarch)->builtin_float;
871 if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)
872 return builtin_type (gdbarch)->builtin_double;
873 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
874 return builtin_type (gdbarch)->builtin_func_ptr;
875 /* This raw register contains the contents of %cwp, %pstate, %asi
876 and %ccr as laid out in a %tstate register. */
877 if (regnum == SPARC64_STATE_REGNUM)
878 return builtin_type (gdbarch)->builtin_int64;
879 if (regnum == SPARC64_FSR_REGNUM)
880 return sparc64_fsr_type (gdbarch);
881 if (regnum == SPARC64_FPRS_REGNUM)
882 return sparc64_fprs_type (gdbarch);
883 /* "Although Y is a 64-bit register, its high-order 32 bits are
884 reserved and always read as 0." */
885 if (regnum == SPARC64_Y_REGNUM)
886 return builtin_type (gdbarch)->builtin_int64;
888 /* Pseudo registers. */
889 if (regnum >= gdbarch_num_regs (gdbarch))
890 return sparc64_pseudo_register_type (gdbarch, regnum);
892 internal_error (_("invalid regnum"));
895 static enum register_status
896 sparc64_pseudo_register_read (struct gdbarch *gdbarch,
897 readable_regcache *regcache,
898 int regnum, gdb_byte *buf)
900 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
901 enum register_status status;
903 regnum -= gdbarch_num_regs (gdbarch);
905 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
907 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
908 status = regcache->raw_read (regnum, buf);
909 if (status == REG_VALID)
910 status = regcache->raw_read (regnum + 1, buf + 4);
911 return status;
913 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
915 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
916 return regcache->raw_read (regnum, buf);
918 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
920 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
922 status = regcache->raw_read (regnum, buf);
923 if (status == REG_VALID)
924 status = regcache->raw_read (regnum + 1, buf + 4);
925 if (status == REG_VALID)
926 status = regcache->raw_read (regnum + 2, buf + 8);
927 if (status == REG_VALID)
928 status = regcache->raw_read (regnum + 3, buf + 12);
930 return status;
932 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
934 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
936 status = regcache->raw_read (regnum, buf);
937 if (status == REG_VALID)
938 status = regcache->raw_read (regnum + 1, buf + 8);
940 return status;
942 else if (regnum == SPARC64_CWP_REGNUM
943 || regnum == SPARC64_PSTATE_REGNUM
944 || regnum == SPARC64_ASI_REGNUM
945 || regnum == SPARC64_CCR_REGNUM)
947 ULONGEST state;
949 status = regcache->raw_read (SPARC64_STATE_REGNUM, &state);
950 if (status != REG_VALID)
951 return status;
953 switch (regnum)
955 case SPARC64_CWP_REGNUM:
956 state = (state >> 0) & ((1 << 5) - 1);
957 break;
958 case SPARC64_PSTATE_REGNUM:
959 state = (state >> 8) & ((1 << 12) - 1);
960 break;
961 case SPARC64_ASI_REGNUM:
962 state = (state >> 24) & ((1 << 8) - 1);
963 break;
964 case SPARC64_CCR_REGNUM:
965 state = (state >> 32) & ((1 << 8) - 1);
966 break;
968 store_unsigned_integer (buf, 8, byte_order, state);
971 return REG_VALID;
974 static void
975 sparc64_pseudo_register_write (struct gdbarch *gdbarch,
976 struct regcache *regcache,
977 int regnum, const gdb_byte *buf)
979 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
981 regnum -= gdbarch_num_regs (gdbarch);
983 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
985 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
986 regcache->raw_write (regnum, buf);
987 regcache->raw_write (regnum + 1, buf + 4);
989 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
991 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
992 regcache->raw_write (regnum, buf);
994 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
996 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
997 regcache->raw_write (regnum, buf);
998 regcache->raw_write (regnum + 1, buf + 4);
999 regcache->raw_write (regnum + 2, buf + 8);
1000 regcache->raw_write (regnum + 3, buf + 12);
1002 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
1004 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
1005 regcache->raw_write (regnum, buf);
1006 regcache->raw_write (regnum + 1, buf + 8);
1008 else if (regnum == SPARC64_CWP_REGNUM
1009 || regnum == SPARC64_PSTATE_REGNUM
1010 || regnum == SPARC64_ASI_REGNUM
1011 || regnum == SPARC64_CCR_REGNUM)
1013 ULONGEST state, bits;
1015 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
1016 bits = extract_unsigned_integer (buf, 8, byte_order);
1017 switch (regnum)
1019 case SPARC64_CWP_REGNUM:
1020 state |= ((bits & ((1 << 5) - 1)) << 0);
1021 break;
1022 case SPARC64_PSTATE_REGNUM:
1023 state |= ((bits & ((1 << 12) - 1)) << 8);
1024 break;
1025 case SPARC64_ASI_REGNUM:
1026 state |= ((bits & ((1 << 8) - 1)) << 24);
1027 break;
1028 case SPARC64_CCR_REGNUM:
1029 state |= ((bits & ((1 << 8) - 1)) << 32);
1030 break;
1032 regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
1037 /* Return PC of first real instruction of the function starting at
1038 START_PC. */
1040 static CORE_ADDR
1041 sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
1043 struct symtab_and_line sal;
1044 CORE_ADDR func_start, func_end;
1045 struct sparc_frame_cache cache;
1047 /* This is the preferred method, find the end of the prologue by
1048 using the debugging information. */
1049 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
1051 sal = find_pc_line (func_start, 0);
1053 if (sal.end < func_end
1054 && start_pc <= sal.end)
1055 return sal.end;
1058 return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL,
1059 &cache);
1062 /* Normal frames. */
1064 static struct sparc_frame_cache *
1065 sparc64_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
1067 return sparc_frame_cache (this_frame, this_cache);
1070 static void
1071 sparc64_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
1072 struct frame_id *this_id)
1074 struct sparc_frame_cache *cache =
1075 sparc64_frame_cache (this_frame, this_cache);
1077 /* This marks the outermost frame. */
1078 if (cache->base == 0)
1079 return;
1081 (*this_id) = frame_id_build (cache->base, cache->pc);
1084 static struct value *
1085 sparc64_frame_prev_register (const frame_info_ptr &this_frame, void **this_cache,
1086 int regnum)
1088 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1089 struct sparc_frame_cache *cache =
1090 sparc64_frame_cache (this_frame, this_cache);
1092 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
1094 CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0;
1096 regnum =
1097 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
1098 pc += get_frame_register_unsigned (this_frame, regnum) + 8;
1099 return frame_unwind_got_constant (this_frame, regnum, pc);
1102 /* Handle StackGhost. */
1104 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
1106 if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM)
1108 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
1109 ULONGEST i7;
1111 /* Read the value in from memory. */
1112 i7 = get_frame_memory_unsigned (this_frame, addr, 8);
1113 return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie);
1117 /* The previous frame's `local' and `in' registers may have been saved
1118 in the register save area. */
1119 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
1120 && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM))))
1122 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
1124 return frame_unwind_got_memory (this_frame, regnum, addr);
1127 /* The previous frame's `out' registers may be accessible as the current
1128 frame's `in' registers. */
1129 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM
1130 && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))))
1131 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
1133 return frame_unwind_got_register (this_frame, regnum, regnum);
1136 static const struct frame_unwind sparc64_frame_unwind =
1138 "sparc64 prologue",
1139 NORMAL_FRAME,
1140 default_frame_unwind_stop_reason,
1141 sparc64_frame_this_id,
1142 sparc64_frame_prev_register,
1143 NULL,
1144 default_frame_sniffer
1148 static CORE_ADDR
1149 sparc64_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
1151 struct sparc_frame_cache *cache =
1152 sparc64_frame_cache (this_frame, this_cache);
1154 return cache->base;
1157 static const struct frame_base sparc64_frame_base =
1159 &sparc64_frame_unwind,
1160 sparc64_frame_base_address,
1161 sparc64_frame_base_address,
1162 sparc64_frame_base_address
1165 /* Check whether TYPE must be 16-byte aligned. */
1167 static int
1168 sparc64_16_byte_align_p (struct type *type)
1170 if (type->code () == TYPE_CODE_ARRAY)
1172 struct type *t = check_typedef (type->target_type ());
1174 if (sparc64_floating_p (t))
1175 return 1;
1177 if (sparc64_floating_p (type) && type->length () == 16)
1178 return 1;
1180 if (sparc64_structure_or_union_p (type))
1182 int i;
1184 for (i = 0; i < type->num_fields (); i++)
1186 struct type *subtype = check_typedef (type->field (i).type ());
1188 if (sparc64_16_byte_align_p (subtype))
1189 return 1;
1193 return 0;
1196 /* Store floating fields of element ELEMENT of an "parameter array"
1197 that has type TYPE and is stored at BITPOS in VALBUF in the
1198 appropriate registers of REGCACHE. This function can be called
1199 recursively and therefore handles floating types in addition to
1200 structures. */
1202 static void
1203 sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
1204 const gdb_byte *valbuf, int element, int bitpos)
1206 struct gdbarch *gdbarch = regcache->arch ();
1207 int len = type->length ();
1209 gdb_assert (element < 16);
1211 if (type->code () == TYPE_CODE_ARRAY)
1213 gdb_byte buf[8];
1214 int regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
1216 valbuf += bitpos / 8;
1217 if (len < 8)
1219 memset (buf, 0, 8 - len);
1220 memcpy (buf + 8 - len, valbuf, len);
1221 valbuf = buf;
1222 len = 8;
1224 for (int n = 0; n < (len + 3) / 4; n++)
1225 regcache->cooked_write (regnum + n, valbuf + n * 4);
1227 else if (sparc64_floating_p (type)
1228 || (sparc64_complex_floating_p (type) && len <= 16))
1230 int regnum;
1232 if (len == 16)
1234 gdb_assert (bitpos == 0);
1235 gdb_assert ((element % 2) == 0);
1237 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM + element / 2;
1238 regcache->cooked_write (regnum, valbuf);
1240 else if (len == 8)
1242 gdb_assert (bitpos == 0 || bitpos == 64);
1244 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
1245 + element + bitpos / 64;
1246 regcache->cooked_write (regnum, valbuf + (bitpos / 8));
1248 else
1250 gdb_assert (len == 4);
1251 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128);
1253 regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
1254 regcache->cooked_write (regnum, valbuf + (bitpos / 8));
1257 else if (sparc64_structure_or_union_p (type))
1259 int i;
1261 for (i = 0; i < type->num_fields (); i++)
1263 struct type *subtype = check_typedef (type->field (i).type ());
1264 int subpos = bitpos + type->field (i).loc_bitpos ();
1266 sparc64_store_floating_fields (regcache, subtype, valbuf,
1267 element, subpos);
1270 /* GCC has an interesting bug. If TYPE is a structure that has
1271 a single `float' member, GCC doesn't treat it as a structure
1272 at all, but rather as an ordinary `float' argument. This
1273 argument will be stored in %f1, as required by the psABI.
1274 However, as a member of a structure the psABI requires it to
1275 be stored in %f0. This bug is present in GCC 3.3.2, but
1276 probably in older releases to. To appease GCC, if a
1277 structure has only a single `float' member, we store its
1278 value in %f1 too (we already have stored in %f0). */
1279 if (type->num_fields () == 1)
1281 struct type *subtype = check_typedef (type->field (0).type ());
1283 if (sparc64_floating_p (subtype) && subtype->length () == 4)
1284 regcache->cooked_write (SPARC_F1_REGNUM, valbuf);
1289 /* Fetch floating fields from a variable of type TYPE from the
1290 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
1291 in VALBUF. This function can be called recursively and therefore
1292 handles floating types in addition to structures. */
1294 static void
1295 sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
1296 gdb_byte *valbuf, int bitpos)
1298 struct gdbarch *gdbarch = regcache->arch ();
1300 if (type->code () == TYPE_CODE_ARRAY)
1302 int len = type->length ();
1303 int regnum = SPARC_F0_REGNUM + bitpos / 32;
1305 valbuf += bitpos / 8;
1306 if (len < 4)
1308 gdb_byte buf[4];
1309 regcache->cooked_read (regnum, buf);
1310 memcpy (valbuf, buf + 4 - len, len);
1312 else
1313 for (int i = 0; i < (len + 3) / 4; i++)
1314 regcache->cooked_read (regnum + i, valbuf + i * 4);
1316 else if (sparc64_floating_p (type))
1318 int len = type->length ();
1319 int regnum;
1321 if (len == 16)
1323 gdb_assert (bitpos == 0 || bitpos == 128);
1325 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
1326 + bitpos / 128;
1327 regcache->cooked_read (regnum, valbuf + (bitpos / 8));
1329 else if (len == 8)
1331 gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256);
1333 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + bitpos / 64;
1334 regcache->cooked_read (regnum, valbuf + (bitpos / 8));
1336 else
1338 gdb_assert (len == 4);
1339 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256);
1341 regnum = SPARC_F0_REGNUM + bitpos / 32;
1342 regcache->cooked_read (regnum, valbuf + (bitpos / 8));
1345 else if (sparc64_structure_or_union_p (type))
1347 int i;
1349 for (i = 0; i < type->num_fields (); i++)
1351 struct type *subtype = check_typedef (type->field (i).type ());
1352 int subpos = bitpos + type->field (i).loc_bitpos ();
1354 sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos);
1359 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
1360 non-zero) in REGCACHE and on the stack (starting from address SP). */
1362 static CORE_ADDR
1363 sparc64_store_arguments (struct regcache *regcache, int nargs,
1364 struct value **args, CORE_ADDR sp,
1365 function_call_return_method return_method,
1366 CORE_ADDR struct_addr)
1368 struct gdbarch *gdbarch = regcache->arch ();
1369 /* Number of extended words in the "parameter array". */
1370 int num_elements = 0;
1371 int element = 0;
1372 int i;
1374 /* Take BIAS into account. */
1375 sp += BIAS;
1377 /* First we calculate the number of extended words in the "parameter
1378 array". While doing so we also convert some of the arguments. */
1380 if (return_method == return_method_struct)
1381 num_elements++;
1383 for (i = 0; i < nargs; i++)
1385 struct type *type = args[i]->type ();
1386 int len = type->length ();
1388 if (sparc64_structure_or_union_p (type)
1389 || (sparc64_complex_floating_p (type) && len == 32))
1391 /* Structure or Union arguments. */
1392 if (len <= 16)
1394 if (num_elements % 2 && sparc64_16_byte_align_p (type))
1395 num_elements++;
1396 num_elements += ((len + 7) / 8);
1398 else
1400 /* The psABI says that "Structures or unions larger than
1401 sixteen bytes are copied by the caller and passed
1402 indirectly; the caller will pass the address of a
1403 correctly aligned structure value. This sixty-four
1404 bit address will occupy one word in the parameter
1405 array, and may be promoted to an %o register like any
1406 other pointer value." Allocate memory for these
1407 values on the stack. */
1408 sp -= len;
1410 /* Use 16-byte alignment for these values. That's
1411 always correct, and wasting a few bytes shouldn't be
1412 a problem. */
1413 sp &= ~0xf;
1415 write_memory (sp, args[i]->contents ().data (), len);
1416 args[i] = value_from_pointer (lookup_pointer_type (type), sp);
1417 num_elements++;
1420 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1422 /* Floating arguments. */
1423 if (len == 16)
1425 /* The psABI says that "Each quad-precision parameter
1426 value will be assigned to two extended words in the
1427 parameter array. */
1428 num_elements += 2;
1430 /* The psABI says that "Long doubles must be
1431 quad-aligned, and thus a hole might be introduced
1432 into the parameter array to force alignment." Skip
1433 an element if necessary. */
1434 if ((num_elements % 2) && sparc64_16_byte_align_p (type))
1435 num_elements++;
1437 else
1438 num_elements++;
1440 else
1442 /* Integral and pointer arguments. */
1443 gdb_assert (sparc64_integral_or_pointer_p (type));
1445 /* The psABI says that "Each argument value of integral type
1446 smaller than an extended word will be widened by the
1447 caller to an extended word according to the signed-ness
1448 of the argument type." */
1449 if (len < 8)
1450 args[i] = value_cast (builtin_type (gdbarch)->builtin_int64,
1451 args[i]);
1452 num_elements++;
1456 /* Allocate the "parameter array". */
1457 sp -= num_elements * 8;
1459 /* The psABI says that "Every stack frame must be 16-byte aligned." */
1460 sp &= ~0xf;
1462 /* Now we store the arguments in to the "parameter array". Some
1463 Integer or Pointer arguments and Structure or Union arguments
1464 will be passed in %o registers. Some Floating arguments and
1465 floating members of structures are passed in floating-point
1466 registers. However, for functions with variable arguments,
1467 floating arguments are stored in an %0 register, and for
1468 functions without a prototype floating arguments are stored in
1469 both a floating-point and an %o registers, or a floating-point
1470 register and memory. To simplify the logic here we always pass
1471 arguments in memory, an %o register, and a floating-point
1472 register if appropriate. This should be no problem since the
1473 contents of any unused memory or registers in the "parameter
1474 array" are undefined. */
1476 if (return_method == return_method_struct)
1478 regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
1479 element++;
1482 for (i = 0; i < nargs; i++)
1484 const gdb_byte *valbuf = args[i]->contents ().data ();
1485 struct type *type = args[i]->type ();
1486 int len = type->length ();
1487 int regnum = -1;
1488 gdb_byte buf[16];
1490 if (sparc64_structure_or_union_p (type)
1491 || (sparc64_complex_floating_p (type) && len == 32))
1493 /* Structure, Union or long double Complex arguments. */
1494 gdb_assert (len <= 16);
1495 memset (buf, 0, sizeof (buf));
1496 memcpy (buf, valbuf, len);
1497 valbuf = buf;
1499 if (element % 2 && sparc64_16_byte_align_p (type))
1500 element++;
1502 if (element < 6)
1504 regnum = SPARC_O0_REGNUM + element;
1505 if (len > 8 && element < 5)
1506 regcache->cooked_write (regnum + 1, valbuf + 8);
1509 if (element < 16)
1510 sparc64_store_floating_fields (regcache, type, valbuf, element, 0);
1512 else if (sparc64_complex_floating_p (type))
1514 /* Float Complex or double Complex arguments. */
1515 if (element < 16)
1517 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + element;
1519 if (len == 16)
1521 if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D30_REGNUM)
1522 regcache->cooked_write (regnum + 1, valbuf + 8);
1523 if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D10_REGNUM)
1524 regcache->cooked_write (SPARC_O0_REGNUM + element + 1,
1525 valbuf + 8);
1529 else if (sparc64_floating_p (type))
1531 /* Floating arguments. */
1532 if (len == 16)
1534 if (element % 2)
1535 element++;
1536 if (element < 16)
1537 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
1538 + element / 2;
1540 else if (len == 8)
1542 if (element < 16)
1543 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
1544 + element;
1546 else if (len == 4)
1548 /* The psABI says "Each single-precision parameter value
1549 will be assigned to one extended word in the
1550 parameter array, and right-justified within that
1551 word; the left half (even float register) is
1552 undefined." Even though the psABI says that "the
1553 left half is undefined", set it to zero here. */
1554 memset (buf, 0, 4);
1555 memcpy (buf + 4, valbuf, 4);
1556 valbuf = buf;
1557 len = 8;
1558 if (element < 16)
1559 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
1560 + element;
1563 else
1565 /* Integral and pointer arguments. */
1566 gdb_assert (len == 8);
1567 if (element < 6)
1568 regnum = SPARC_O0_REGNUM + element;
1571 if (regnum != -1)
1573 regcache->cooked_write (regnum, valbuf);
1575 /* If we're storing the value in a floating-point register,
1576 also store it in the corresponding %0 register(s). */
1577 if (regnum >= gdbarch_num_regs (gdbarch))
1579 regnum -= gdbarch_num_regs (gdbarch);
1581 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM)
1583 gdb_assert (element < 6);
1584 regnum = SPARC_O0_REGNUM + element;
1585 regcache->cooked_write (regnum, valbuf);
1587 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM)
1589 gdb_assert (element < 5);
1590 regnum = SPARC_O0_REGNUM + element;
1591 regcache->cooked_write (regnum, valbuf);
1592 regcache->cooked_write (regnum + 1, valbuf + 8);
1597 /* Always store the argument in memory. */
1598 write_memory (sp + element * 8, valbuf, len);
1599 element += ((len + 7) / 8);
1602 gdb_assert (element == num_elements);
1604 /* Take BIAS into account. */
1605 sp -= BIAS;
1606 return sp;
1609 static CORE_ADDR
1610 sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
1612 /* The ABI requires 16-byte alignment. */
1613 return address & ~0xf;
1616 static CORE_ADDR
1617 sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1618 struct regcache *regcache, CORE_ADDR bp_addr,
1619 int nargs, struct value **args, CORE_ADDR sp,
1620 function_call_return_method return_method,
1621 CORE_ADDR struct_addr)
1623 /* Set return address. */
1624 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
1626 /* Set up function arguments. */
1627 sp = sparc64_store_arguments (regcache, nargs, args, sp, return_method,
1628 struct_addr);
1630 /* Allocate the register save area. */
1631 sp -= 16 * 8;
1633 /* Stack should be 16-byte aligned at this point. */
1634 gdb_assert ((sp + BIAS) % 16 == 0);
1636 /* Finally, update the stack pointer. */
1637 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp);
1639 return sp + BIAS;
1643 /* Extract from an array REGBUF containing the (raw) register state, a
1644 function return value of TYPE, and copy that into VALBUF. */
1646 static void
1647 sparc64_extract_return_value (struct type *type, struct regcache *regcache,
1648 gdb_byte *valbuf)
1650 int len = type->length ();
1651 gdb_byte buf[32];
1652 int i;
1654 if (sparc64_structure_or_union_p (type))
1656 /* Structure or Union return values. */
1657 gdb_assert (len <= 32);
1659 for (i = 0; i < ((len + 7) / 8); i++)
1660 regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
1661 if (type->code () != TYPE_CODE_UNION)
1662 sparc64_extract_floating_fields (regcache, type, buf, 0);
1663 memcpy (valbuf, buf, len);
1665 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1667 /* Floating return values. */
1668 for (i = 0; i < len / 4; i++)
1669 regcache->cooked_read (SPARC_F0_REGNUM + i, buf + i * 4);
1670 memcpy (valbuf, buf, len);
1672 else if (type->code () == TYPE_CODE_ARRAY)
1674 /* Small arrays are returned the same way as small structures. */
1675 gdb_assert (len <= 32);
1677 for (i = 0; i < ((len + 7) / 8); i++)
1678 regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
1679 memcpy (valbuf, buf, len);
1681 else
1683 /* Integral and pointer return values. */
1684 gdb_assert (sparc64_integral_or_pointer_p (type));
1686 /* Just stripping off any unused bytes should preserve the
1687 signed-ness just fine. */
1688 regcache->cooked_read (SPARC_O0_REGNUM, buf);
1689 memcpy (valbuf, buf + 8 - len, len);
1693 /* Write into the appropriate registers a function return value stored
1694 in VALBUF of type TYPE. */
1696 static void
1697 sparc64_store_return_value (struct type *type, struct regcache *regcache,
1698 const gdb_byte *valbuf)
1700 int len = type->length ();
1701 gdb_byte buf[16];
1702 int i;
1704 if (sparc64_structure_or_union_p (type))
1706 /* Structure or Union return values. */
1707 gdb_assert (len <= 32);
1709 /* Simplify matters by storing the complete value (including
1710 floating members) into %o0 and %o1. Floating members are
1711 also store in the appropriate floating-point registers. */
1712 memset (buf, 0, sizeof (buf));
1713 memcpy (buf, valbuf, len);
1714 for (i = 0; i < ((len + 7) / 8); i++)
1715 regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
1716 if (type->code () != TYPE_CODE_UNION)
1717 sparc64_store_floating_fields (regcache, type, buf, 0, 0);
1719 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1721 /* Floating return values. */
1722 memcpy (buf, valbuf, len);
1723 for (i = 0; i < len / 4; i++)
1724 regcache->cooked_write (SPARC_F0_REGNUM + i, buf + i * 4);
1726 else if (type->code () == TYPE_CODE_ARRAY)
1728 /* Small arrays are returned the same way as small structures. */
1729 gdb_assert (len <= 32);
1731 memset (buf, 0, sizeof (buf));
1732 memcpy (buf, valbuf, len);
1733 for (i = 0; i < ((len + 7) / 8); i++)
1734 regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
1736 else
1738 /* Integral and pointer return values. */
1739 gdb_assert (sparc64_integral_or_pointer_p (type));
1741 /* ??? Do we need to do any sign-extension here? */
1742 memset (buf, 0, 8);
1743 memcpy (buf + 8 - len, valbuf, len);
1744 regcache->cooked_write (SPARC_O0_REGNUM, buf);
1748 static enum return_value_convention
1749 sparc64_return_value (struct gdbarch *gdbarch, struct value *function,
1750 struct type *type, struct regcache *regcache,
1751 gdb_byte *readbuf, const gdb_byte *writebuf)
1753 if (type->length () > 32)
1754 return RETURN_VALUE_STRUCT_CONVENTION;
1756 if (readbuf)
1757 sparc64_extract_return_value (type, regcache, readbuf);
1758 if (writebuf)
1759 sparc64_store_return_value (type, regcache, writebuf);
1761 return RETURN_VALUE_REGISTER_CONVENTION;
1765 static void
1766 sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1767 struct dwarf2_frame_state_reg *reg,
1768 const frame_info_ptr &this_frame)
1770 switch (regnum)
1772 case SPARC_G0_REGNUM:
1773 /* Since %g0 is always zero, there is no point in saving it, and
1774 people will be inclined omit it from the CFI. Make sure we
1775 don't warn about that. */
1776 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1777 break;
1778 case SPARC_SP_REGNUM:
1779 reg->how = DWARF2_FRAME_REG_CFA;
1780 break;
1781 case SPARC64_PC_REGNUM:
1782 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1783 reg->loc.offset = 8;
1784 break;
1785 case SPARC64_NPC_REGNUM:
1786 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1787 reg->loc.offset = 12;
1788 break;
1792 /* sparc64_addr_bits_remove - remove useless address bits */
1794 static CORE_ADDR
1795 sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
1797 return adi_normalize_address (addr);
1800 void
1801 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1803 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
1805 tdep->pc_regnum = SPARC64_PC_REGNUM;
1806 tdep->npc_regnum = SPARC64_NPC_REGNUM;
1807 tdep->fpu_register_names = sparc64_fpu_register_names;
1808 tdep->fpu_registers_num = ARRAY_SIZE (sparc64_fpu_register_names);
1809 tdep->cp0_register_names = sparc64_cp0_register_names;
1810 tdep->cp0_registers_num = ARRAY_SIZE (sparc64_cp0_register_names);
1812 /* This is what all the fuss is about. */
1813 set_gdbarch_long_bit (gdbarch, 64);
1814 set_gdbarch_long_long_bit (gdbarch, 64);
1815 set_gdbarch_ptr_bit (gdbarch, 64);
1817 set_gdbarch_wchar_bit (gdbarch, 16);
1818 set_gdbarch_wchar_signed (gdbarch, 0);
1820 set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS);
1821 set_gdbarch_register_name (gdbarch, sparc64_register_name);
1822 set_gdbarch_register_type (gdbarch, sparc64_register_type);
1823 set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS);
1824 set_tdesc_pseudo_register_name (gdbarch, sparc64_pseudo_register_name);
1825 set_tdesc_pseudo_register_type (gdbarch, sparc64_pseudo_register_type);
1826 set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read);
1827 set_gdbarch_deprecated_pseudo_register_write (gdbarch,
1828 sparc64_pseudo_register_write);
1830 /* Register numbers of various important registers. */
1831 set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */
1833 /* Call dummy code. */
1834 set_gdbarch_frame_align (gdbarch, sparc64_frame_align);
1835 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1836 set_gdbarch_push_dummy_code (gdbarch, NULL);
1837 set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call);
1839 set_gdbarch_return_value (gdbarch, sparc64_return_value);
1840 set_gdbarch_return_value_as_value (gdbarch, default_gdbarch_return_value);
1841 set_gdbarch_stabs_argument_has_addr
1842 (gdbarch, default_stabs_argument_has_addr);
1844 set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue);
1845 set_gdbarch_stack_frame_destroyed_p (gdbarch, sparc_stack_frame_destroyed_p);
1847 /* Hook in the DWARF CFI frame unwinder. */
1848 dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg);
1849 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1850 StackGhost issues have been resolved. */
1852 frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind);
1853 frame_base_set_default (gdbarch, &sparc64_frame_base);
1855 set_gdbarch_addr_bits_remove (gdbarch, sparc64_addr_bits_remove);
1859 /* Helper functions for dealing with register sets. */
1861 #define TSTATE_CWP 0x000000000000001fULL
1862 #define TSTATE_ICC 0x0000000f00000000ULL
1863 #define TSTATE_XCC 0x000000f000000000ULL
1865 #define PSR_S 0x00000080
1866 #ifndef PSR_ICC
1867 #define PSR_ICC 0x00f00000
1868 #endif
1869 #define PSR_VERS 0x0f000000
1870 #ifndef PSR_IMPL
1871 #define PSR_IMPL 0xf0000000
1872 #endif
1873 #define PSR_V8PLUS 0xff000000
1874 #define PSR_XCC 0x000f0000
1876 void
1877 sparc64_supply_gregset (const struct sparc_gregmap *gregmap,
1878 struct regcache *regcache,
1879 int regnum, const void *gregs)
1881 struct gdbarch *gdbarch = regcache->arch ();
1882 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1883 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
1884 const gdb_byte *regs = (const gdb_byte *) gregs;
1885 gdb_byte zero[8] = { 0 };
1886 int i;
1888 if (sparc32)
1890 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1892 int offset = gregmap->r_tstate_offset;
1893 ULONGEST tstate, psr;
1894 gdb_byte buf[4];
1896 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
1897 psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12)
1898 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS);
1899 store_unsigned_integer (buf, 4, byte_order, psr);
1900 regcache->raw_supply (SPARC32_PSR_REGNUM, buf);
1903 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1904 regcache->raw_supply (SPARC32_PC_REGNUM,
1905 regs + gregmap->r_pc_offset + 4);
1907 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1908 regcache->raw_supply (SPARC32_NPC_REGNUM,
1909 regs + gregmap->r_npc_offset + 4);
1911 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
1913 int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
1914 regcache->raw_supply (SPARC32_Y_REGNUM, regs + offset);
1917 else
1919 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1920 regcache->raw_supply (SPARC64_STATE_REGNUM,
1921 regs + gregmap->r_tstate_offset);
1923 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1924 regcache->raw_supply (SPARC64_PC_REGNUM,
1925 regs + gregmap->r_pc_offset);
1927 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1928 regcache->raw_supply (SPARC64_NPC_REGNUM,
1929 regs + gregmap->r_npc_offset);
1931 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
1933 gdb_byte buf[8];
1935 memset (buf, 0, 8);
1936 memcpy (buf + 8 - gregmap->r_y_size,
1937 regs + gregmap->r_y_offset, gregmap->r_y_size);
1938 regcache->raw_supply (SPARC64_Y_REGNUM, buf);
1941 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1942 && gregmap->r_fprs_offset != -1)
1943 regcache->raw_supply (SPARC64_FPRS_REGNUM,
1944 regs + gregmap->r_fprs_offset);
1947 if (regnum == SPARC_G0_REGNUM || regnum == -1)
1948 regcache->raw_supply (SPARC_G0_REGNUM, &zero);
1950 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1952 int offset = gregmap->r_g1_offset;
1954 if (sparc32)
1955 offset += 4;
1957 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1959 if (regnum == i || regnum == -1)
1960 regcache->raw_supply (i, regs + offset);
1961 offset += 8;
1965 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1967 /* Not all of the register set variants include Locals and
1968 Inputs. For those that don't, we read them off the stack. */
1969 if (gregmap->r_l0_offset == -1)
1971 ULONGEST sp;
1973 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
1974 sparc_supply_rwindow (regcache, sp, regnum);
1976 else
1978 int offset = gregmap->r_l0_offset;
1980 if (sparc32)
1981 offset += 4;
1983 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
1985 if (regnum == i || regnum == -1)
1986 regcache->raw_supply (i, regs + offset);
1987 offset += 8;
1993 void
1994 sparc64_collect_gregset (const struct sparc_gregmap *gregmap,
1995 const struct regcache *regcache,
1996 int regnum, void *gregs)
1998 struct gdbarch *gdbarch = regcache->arch ();
1999 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2000 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
2001 gdb_byte *regs = (gdb_byte *) gregs;
2002 int i;
2004 if (sparc32)
2006 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
2008 int offset = gregmap->r_tstate_offset;
2009 ULONGEST tstate, psr;
2010 gdb_byte buf[8];
2012 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
2013 regcache->raw_collect (SPARC32_PSR_REGNUM, buf);
2014 psr = extract_unsigned_integer (buf, 4, byte_order);
2015 tstate |= (psr & PSR_ICC) << 12;
2016 if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS)
2017 tstate |= (psr & PSR_XCC) << 20;
2018 store_unsigned_integer (buf, 8, byte_order, tstate);
2019 memcpy (regs + offset, buf, 8);
2022 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
2023 regcache->raw_collect (SPARC32_PC_REGNUM,
2024 regs + gregmap->r_pc_offset + 4);
2026 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
2027 regcache->raw_collect (SPARC32_NPC_REGNUM,
2028 regs + gregmap->r_npc_offset + 4);
2030 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
2032 int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
2033 regcache->raw_collect (SPARC32_Y_REGNUM, regs + offset);
2036 else
2038 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
2039 regcache->raw_collect (SPARC64_STATE_REGNUM,
2040 regs + gregmap->r_tstate_offset);
2042 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
2043 regcache->raw_collect (SPARC64_PC_REGNUM,
2044 regs + gregmap->r_pc_offset);
2046 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
2047 regcache->raw_collect (SPARC64_NPC_REGNUM,
2048 regs + gregmap->r_npc_offset);
2050 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
2052 gdb_byte buf[8];
2054 regcache->raw_collect (SPARC64_Y_REGNUM, buf);
2055 memcpy (regs + gregmap->r_y_offset,
2056 buf + 8 - gregmap->r_y_size, gregmap->r_y_size);
2059 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
2060 && gregmap->r_fprs_offset != -1)
2061 regcache->raw_collect (SPARC64_FPRS_REGNUM,
2062 regs + gregmap->r_fprs_offset);
2066 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
2068 int offset = gregmap->r_g1_offset;
2070 if (sparc32)
2071 offset += 4;
2073 /* %g0 is always zero. */
2074 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
2076 if (regnum == i || regnum == -1)
2077 regcache->raw_collect (i, regs + offset);
2078 offset += 8;
2082 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
2084 /* Not all of the register set variants include Locals and
2085 Inputs. For those that don't, we read them off the stack. */
2086 if (gregmap->r_l0_offset != -1)
2088 int offset = gregmap->r_l0_offset;
2090 if (sparc32)
2091 offset += 4;
2093 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
2095 if (regnum == i || regnum == -1)
2096 regcache->raw_collect (i, regs + offset);
2097 offset += 8;
2103 void
2104 sparc64_supply_fpregset (const struct sparc_fpregmap *fpregmap,
2105 struct regcache *regcache,
2106 int regnum, const void *fpregs)
2108 int sparc32 = (gdbarch_ptr_bit (regcache->arch ()) == 32);
2109 const gdb_byte *regs = (const gdb_byte *) fpregs;
2110 int i;
2112 for (i = 0; i < 32; i++)
2114 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
2115 regcache->raw_supply (SPARC_F0_REGNUM + i,
2116 regs + fpregmap->r_f0_offset + (i * 4));
2119 if (sparc32)
2121 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
2122 regcache->raw_supply (SPARC32_FSR_REGNUM,
2123 regs + fpregmap->r_fsr_offset);
2125 else
2127 for (i = 0; i < 16; i++)
2129 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
2130 regcache->raw_supply
2131 (SPARC64_F32_REGNUM + i,
2132 regs + fpregmap->r_f0_offset + (32 * 4) + (i * 8));
2135 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
2136 regcache->raw_supply (SPARC64_FSR_REGNUM,
2137 regs + fpregmap->r_fsr_offset);
2141 void
2142 sparc64_collect_fpregset (const struct sparc_fpregmap *fpregmap,
2143 const struct regcache *regcache,
2144 int regnum, void *fpregs)
2146 int sparc32 = (gdbarch_ptr_bit (regcache->arch ()) == 32);
2147 gdb_byte *regs = (gdb_byte *) fpregs;
2148 int i;
2150 for (i = 0; i < 32; i++)
2152 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
2153 regcache->raw_collect (SPARC_F0_REGNUM + i,
2154 regs + fpregmap->r_f0_offset + (i * 4));
2157 if (sparc32)
2159 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
2160 regcache->raw_collect (SPARC32_FSR_REGNUM,
2161 regs + fpregmap->r_fsr_offset);
2163 else
2165 for (i = 0; i < 16; i++)
2167 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
2168 regcache->raw_collect (SPARC64_F32_REGNUM + i,
2169 (regs + fpregmap->r_f0_offset
2170 + (32 * 4) + (i * 8)));
2173 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
2174 regcache->raw_collect (SPARC64_FSR_REGNUM,
2175 regs + fpregmap->r_fsr_offset);
2179 const struct sparc_fpregmap sparc64_bsd_fpregmap =
2181 0 * 8, /* %f0 */
2182 32 * 8, /* %fsr */