Fix RELOC_FOR_GLOBAL_SYMBOLS macro so that it can cope with user defined symbols...
[binutils-gdb.git] / gdb / sparc64-tdep.c
blob7d44b1e16a01fc521681dabe05bb9f069780c434
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 "event-top.h"
23 #include "extract-store-integer.h"
24 #include "frame.h"
25 #include "frame-base.h"
26 #include "frame-unwind.h"
27 #include "gdbcore.h"
28 #include "gdbtypes.h"
29 #include "inferior.h"
30 #include "symtab.h"
31 #include "objfiles.h"
32 #include "osabi.h"
33 #include "regcache.h"
34 #include "target-descriptions.h"
35 #include "target.h"
36 #include "value.h"
37 #include "sparc64-tdep.h"
38 #include <forward_list>
40 /* This file implements the SPARC 64-bit ABI as defined by the
41 section "Low-Level System Information" of the SPARC Compliance
42 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
43 SPARC. */
45 /* Please use the sparc32_-prefix for 32-bit specific code, the
46 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
47 code can handle both. */
49 /* The M7 processor supports an Application Data Integrity (ADI) feature
50 that detects invalid data accesses. When software allocates memory and
51 enables ADI on the allocated memory, it chooses a 4-bit version number,
52 sets the version in the upper 4 bits of the 64-bit pointer to that data,
53 and stores the 4-bit version in every cacheline of the object. Hardware
54 saves the latter in spare bits in the cache and memory hierarchy. On each
55 load and store, the processor compares the upper 4 VA (virtual address) bits
56 to the cacheline's version. If there is a mismatch, the processor generates
57 a version mismatch trap which can be either precise or disrupting.
58 The trap is an error condition which the kernel delivers to the process
59 as a SIGSEGV signal.
61 The upper 4 bits of the VA represent a version and are not part of the
62 true address. The processor clears these bits and sign extends bit 59
63 to generate the true address.
65 Note that 32-bit applications cannot use ADI. */
68 #include <algorithm>
69 #include "cli/cli-utils.h"
70 #include "cli/cli-cmds.h"
71 #include "auxv.h"
73 #define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/9999/adi/lstatus")
75 /* ELF Auxiliary vectors */
76 #ifndef AT_ADI_BLKSZ
77 #define AT_ADI_BLKSZ 34
78 #endif
79 #ifndef AT_ADI_NBITS
80 #define AT_ADI_NBITS 35
81 #endif
82 #ifndef AT_ADI_UEONADI
83 #define AT_ADI_UEONADI 36
84 #endif
86 /* ADI command list. */
87 static struct cmd_list_element *sparc64adilist = NULL;
89 /* ADI stat settings. */
90 struct adi_stat_t
92 /* The ADI block size. */
93 unsigned long blksize;
95 /* Number of bits used for an ADI version tag which can be
96 used together with the shift value for an ADI version tag
97 to encode or extract the ADI version value in a pointer. */
98 unsigned long nbits;
100 /* The maximum ADI version tag value supported. */
101 int max_version;
103 /* ADI version tag file. */
104 int tag_fd = 0;
106 /* ADI availability check has been done. */
107 bool checked_avail = false;
109 /* ADI is available. */
110 bool is_avail = false;
114 /* Per-process ADI stat info. */
116 struct sparc64_adi_info
118 sparc64_adi_info (pid_t pid_)
119 : pid (pid_)
122 /* The process identifier. */
123 pid_t pid;
125 /* The ADI stat. */
126 adi_stat_t stat = {};
130 static std::forward_list<sparc64_adi_info> adi_proc_list;
133 /* Get ADI info for process PID, creating one if it doesn't exist. */
135 static sparc64_adi_info *
136 get_adi_info_proc (pid_t pid)
138 auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (),
139 [&pid] (const sparc64_adi_info &info)
141 return info.pid == pid;
144 if (found == adi_proc_list.end ())
146 adi_proc_list.emplace_front (pid);
147 return &adi_proc_list.front ();
149 else
151 return &(*found);
155 static adi_stat_t
156 get_adi_info (pid_t pid)
158 sparc64_adi_info *proc;
160 proc = get_adi_info_proc (pid);
161 return proc->stat;
164 /* Is called when GDB is no longer debugging process PID. It
165 deletes data structure that keeps track of the ADI stat. */
167 void
168 sparc64_forget_process (pid_t pid)
170 fileio_error target_errno;
172 for (auto pit = adi_proc_list.before_begin (),
173 it = std::next (pit);
174 it != adi_proc_list.end ();
177 if ((*it).pid == pid)
179 if ((*it).stat.tag_fd > 0)
180 target_fileio_close ((*it).stat.tag_fd, &target_errno);
181 adi_proc_list.erase_after (pit);
182 break;
184 else
185 pit = it++;
190 /* Read attributes of a maps entry in /proc/[pid]/adi/maps. */
192 static void
193 read_maps_entry (const char *line,
194 ULONGEST *addr, ULONGEST *endaddr)
196 const char *p = line;
198 *addr = strtoulst (p, &p, 16);
199 if (*p == '-')
200 p++;
202 *endaddr = strtoulst (p, &p, 16);
205 /* Check if ADI is available. */
207 static bool
208 adi_available (void)
210 pid_t pid = inferior_ptid.pid ();
211 sparc64_adi_info *proc = get_adi_info_proc (pid);
212 CORE_ADDR value;
214 if (proc->stat.checked_avail)
215 return proc->stat.is_avail;
217 proc->stat.checked_avail = true;
218 if (target_auxv_search (AT_ADI_BLKSZ, &value) <= 0)
219 return false;
220 proc->stat.blksize = value;
221 target_auxv_search (AT_ADI_NBITS, &value);
222 proc->stat.nbits = value;
223 proc->stat.max_version = (1 << proc->stat.nbits) - 2;
224 proc->stat.is_avail = true;
226 return proc->stat.is_avail;
229 /* Normalize a versioned address - a VA with ADI bits (63-60) set. */
231 static CORE_ADDR
232 adi_normalize_address (CORE_ADDR addr)
234 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
236 if (ast.nbits)
238 /* Clear upper bits. */
239 addr &= ((uint64_t) -1) >> ast.nbits;
241 /* Sign extend. */
242 CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
243 return (addr ^ signbit) - signbit;
245 return addr;
248 /* Align a normalized address - a VA with bit 59 sign extended into
249 ADI bits. */
251 static CORE_ADDR
252 adi_align_address (CORE_ADDR naddr)
254 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
256 return (naddr - (naddr % ast.blksize)) / ast.blksize;
259 /* Convert a byte count to count at a ratio of 1:adi_blksz. */
261 static int
262 adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl)
264 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
266 return ((naddr + nbytes + ast.blksize - 1) / ast.blksize) - locl;
269 /* The /proc/[pid]/adi/tags file, which allows gdb to get/set ADI
270 version in a target process, maps linearly to the address space
271 of the target process at a ratio of 1:adi_blksz.
273 A read (or write) at offset K in the file returns (or modifies)
274 the ADI version tag stored in the cacheline containing address
275 K * adi_blksz, encoded as 1 version tag per byte. The allowed
276 version tag values are between 0 and adi_stat.max_version. */
278 static int
279 adi_tag_fd (void)
281 pid_t pid = inferior_ptid.pid ();
282 sparc64_adi_info *proc = get_adi_info_proc (pid);
284 if (proc->stat.tag_fd != 0)
285 return proc->stat.tag_fd;
287 char cl_name[MAX_PROC_NAME_SIZE];
288 snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid);
289 fileio_error target_errno;
290 proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL,
291 false, 0, &target_errno);
292 return proc->stat.tag_fd;
295 /* Check if an address set is ADI enabled, using /proc/[pid]/adi/maps
296 which was exported by the kernel and contains the currently ADI
297 mapped memory regions and their access permissions. */
299 static bool
300 adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt)
302 char filename[MAX_PROC_NAME_SIZE];
303 size_t i = 0;
305 pid_t pid = inferior_ptid.pid ();
306 snprintf (filename, sizeof filename, "/proc/%ld/adi/maps", (long) pid);
307 gdb::unique_xmalloc_ptr<char> data
308 = target_fileio_read_stralloc (NULL, filename);
309 if (data)
311 adi_stat_t adi_stat = get_adi_info (pid);
312 char *saveptr;
313 for (char *line = strtok_r (data.get (), "\n", &saveptr);
314 line;
315 line = strtok_r (NULL, "\n", &saveptr))
317 ULONGEST addr, endaddr;
319 read_maps_entry (line, &addr, &endaddr);
321 while (((vaddr + i) * adi_stat.blksize) >= addr
322 && ((vaddr + i) * adi_stat.blksize) < endaddr)
324 if (++i == cnt)
325 return true;
329 else
330 warning (_("unable to open /proc file '%s'"), filename);
332 return false;
335 /* Read ADI version tag value for memory locations starting at "VADDR"
336 for "SIZE" number of bytes. */
338 static int
339 adi_read_versions (CORE_ADDR vaddr, size_t size, gdb_byte *tags)
341 int fd = adi_tag_fd ();
342 if (fd == -1)
343 return -1;
345 if (!adi_is_addr_mapped (vaddr, size))
347 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
348 error(_("Address at %s is not in ADI maps"),
349 paddress (current_inferior ()->arch (), vaddr * ast.blksize));
352 fileio_error target_errno;
353 return target_fileio_pread (fd, tags, size, vaddr, &target_errno);
356 /* Write ADI version tag for memory locations starting at "VADDR" for
357 "SIZE" number of bytes to "TAGS". */
359 static int
360 adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
362 int fd = adi_tag_fd ();
363 if (fd == -1)
364 return -1;
366 if (!adi_is_addr_mapped (vaddr, size))
368 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
369 error(_("Address at %s is not in ADI maps"),
370 paddress (current_inferior ()->arch (), vaddr * ast.blksize));
373 fileio_error target_errno;
374 return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno);
377 /* Print ADI version tag value in "TAGS" for memory locations starting
378 at "VADDR" with number of "CNT". */
380 static void
381 adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
383 int v_idx = 0;
384 const int maxelts = 8; /* # of elements per line */
386 adi_stat_t adi_stat = get_adi_info (inferior_ptid.pid ());
388 while (cnt > 0)
390 QUIT;
391 gdb_printf ("%s:\t",
392 paddress (current_inferior ()->arch (),
393 vaddr * adi_stat.blksize));
394 for (int i = maxelts; i > 0 && cnt > 0; i--, cnt--)
396 if (tags[v_idx] == 0xff) /* no version tag */
397 gdb_printf ("-");
398 else
399 gdb_printf ("%1X", tags[v_idx]);
400 if (cnt > 1)
401 gdb_printf (" ");
402 ++v_idx;
404 gdb_printf ("\n");
405 vaddr += maxelts;
409 static void
410 do_examine (CORE_ADDR start, int bcnt)
412 CORE_ADDR vaddr = adi_normalize_address (start);
414 CORE_ADDR vstart = adi_align_address (vaddr);
415 int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
416 gdb::byte_vector buf (cnt);
417 int read_cnt = adi_read_versions (vstart, cnt, buf.data ());
418 if (read_cnt == -1)
419 error (_("No ADI information"));
420 else if (read_cnt < cnt)
421 error(_("No ADI information at %s"),
422 paddress (current_inferior ()->arch (), vaddr));
424 adi_print_versions (vstart, cnt, buf.data ());
427 static void
428 do_assign (CORE_ADDR start, size_t bcnt, int version)
430 CORE_ADDR vaddr = adi_normalize_address (start);
432 CORE_ADDR vstart = adi_align_address (vaddr);
433 int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
434 std::vector<unsigned char> buf (cnt, version);
435 int set_cnt = adi_write_versions (vstart, cnt, buf.data ());
437 if (set_cnt == -1)
438 error (_("No ADI information"));
439 else if (set_cnt < cnt)
440 error(_("No ADI information at %s"),
441 paddress (current_inferior ()->arch (), vaddr));
444 /* ADI examine version tag command.
446 Command syntax:
448 adi (examine|x)[/COUNT] [ADDR] */
450 static void
451 adi_examine_command (const char *args, int from_tty)
453 /* make sure program is active and adi is available */
454 if (!target_has_execution ())
455 error (_("ADI command requires a live process/thread"));
457 if (!adi_available ())
458 error (_("No ADI information"));
460 int cnt = 1;
461 const char *p = args;
462 if (p && *p == '/')
464 p++;
465 cnt = get_number (&p);
468 CORE_ADDR next_address = 0;
469 if (p != 0 && *p != 0)
470 next_address = parse_and_eval_address (p);
471 if (!cnt || !next_address)
472 error (_("Usage: adi examine|x[/COUNT] [ADDR]"));
474 do_examine (next_address, cnt);
477 /* ADI assign version tag command.
479 Command syntax:
481 adi (assign|a)[/COUNT] ADDR = VERSION */
483 static void
484 adi_assign_command (const char *args, int from_tty)
486 static const char *adi_usage
487 = N_("Usage: adi assign|a[/COUNT] ADDR = VERSION");
489 /* make sure program is active and adi is available */
490 if (!target_has_execution ())
491 error (_("ADI command requires a live process/thread"));
493 if (!adi_available ())
494 error (_("No ADI information"));
496 const char *exp = args;
497 if (exp == 0)
498 error_no_arg (_(adi_usage));
500 char *q = (char *) strchr (exp, '=');
501 if (q)
502 *q++ = 0;
503 else
504 error ("%s", _(adi_usage));
506 size_t cnt = 1;
507 const char *p = args;
508 if (exp && *exp == '/')
510 p = exp + 1;
511 cnt = get_number (&p);
514 CORE_ADDR next_address = 0;
515 if (p != 0 && *p != 0)
516 next_address = parse_and_eval_address (p);
517 else
518 error ("%s", _(adi_usage));
520 int version = 0;
521 if (q != NULL) /* parse version tag */
523 adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
524 version = parse_and_eval_long (q);
525 if (version < 0 || version > ast.max_version)
526 error (_("Invalid ADI version tag %d"), version);
529 do_assign (next_address, cnt, version);
532 void _initialize_sparc64_adi_tdep ();
533 void
534 _initialize_sparc64_adi_tdep ()
536 add_basic_prefix_cmd ("adi", class_support,
537 _("ADI version related commands."),
538 &sparc64adilist, 0, &cmdlist);
539 cmd_list_element *adi_examine_cmd
540 = add_cmd ("examine", class_support, adi_examine_command,
541 _("Examine ADI versions."), &sparc64adilist);
542 add_alias_cmd ("x", adi_examine_cmd, no_class, 1, &sparc64adilist);
543 add_cmd ("assign", class_support, adi_assign_command,
544 _("Assign ADI versions."), &sparc64adilist);
549 /* The functions on this page are intended to be used to classify
550 function arguments. */
552 /* Check whether TYPE is "Integral or Pointer". */
554 static int
555 sparc64_integral_or_pointer_p (const struct type *type)
557 switch (type->code ())
559 case TYPE_CODE_INT:
560 case TYPE_CODE_BOOL:
561 case TYPE_CODE_CHAR:
562 case TYPE_CODE_ENUM:
563 case TYPE_CODE_RANGE:
565 int len = type->length ();
566 gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
568 return 1;
569 case TYPE_CODE_PTR:
570 case TYPE_CODE_REF:
571 case TYPE_CODE_RVALUE_REF:
573 int len = type->length ();
574 gdb_assert (len == 8);
576 return 1;
577 default:
578 break;
581 return 0;
584 /* Check whether TYPE is "Floating". */
586 static int
587 sparc64_floating_p (const struct type *type)
589 switch (type->code ())
591 case TYPE_CODE_FLT:
593 int len = type->length ();
594 gdb_assert (len == 4 || len == 8 || len == 16);
596 return 1;
597 default:
598 break;
601 return 0;
604 /* Check whether TYPE is "Complex Floating". */
606 static int
607 sparc64_complex_floating_p (const struct type *type)
609 switch (type->code ())
611 case TYPE_CODE_COMPLEX:
613 int len = type->length ();
614 gdb_assert (len == 8 || len == 16 || len == 32);
616 return 1;
617 default:
618 break;
621 return 0;
624 /* Check whether TYPE is "Structure or Union".
626 In terms of Ada subprogram calls, arrays are treated the same as
627 struct and union types. So this function also returns non-zero
628 for array types. */
630 static int
631 sparc64_structure_or_union_p (const struct type *type)
633 switch (type->code ())
635 case TYPE_CODE_STRUCT:
636 case TYPE_CODE_UNION:
637 case TYPE_CODE_ARRAY:
638 return 1;
639 default:
640 break;
643 return 0;
647 /* Construct types for ISA-specific registers. */
649 static struct type *
650 sparc64_pstate_type (struct gdbarch *gdbarch)
652 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
654 if (!tdep->sparc64_pstate_type)
656 struct type *type;
658 type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 64);
659 append_flags_type_flag (type, 0, "AG");
660 append_flags_type_flag (type, 1, "IE");
661 append_flags_type_flag (type, 2, "PRIV");
662 append_flags_type_flag (type, 3, "AM");
663 append_flags_type_flag (type, 4, "PEF");
664 append_flags_type_flag (type, 5, "RED");
665 append_flags_type_flag (type, 8, "TLE");
666 append_flags_type_flag (type, 9, "CLE");
667 append_flags_type_flag (type, 10, "PID0");
668 append_flags_type_flag (type, 11, "PID1");
670 tdep->sparc64_pstate_type = type;
673 return tdep->sparc64_pstate_type;
676 static struct type *
677 sparc64_ccr_type (struct gdbarch *gdbarch)
679 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
681 if (tdep->sparc64_ccr_type == NULL)
683 struct type *type;
685 type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 64);
686 append_flags_type_flag (type, 0, "icc.c");
687 append_flags_type_flag (type, 1, "icc.v");
688 append_flags_type_flag (type, 2, "icc.z");
689 append_flags_type_flag (type, 3, "icc.n");
690 append_flags_type_flag (type, 4, "xcc.c");
691 append_flags_type_flag (type, 5, "xcc.v");
692 append_flags_type_flag (type, 6, "xcc.z");
693 append_flags_type_flag (type, 7, "xcc.n");
695 tdep->sparc64_ccr_type = type;
698 return tdep->sparc64_ccr_type;
701 static struct type *
702 sparc64_fsr_type (struct gdbarch *gdbarch)
704 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
706 if (!tdep->sparc64_fsr_type)
708 struct type *type;
710 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 64);
711 append_flags_type_flag (type, 0, "NXC");
712 append_flags_type_flag (type, 1, "DZC");
713 append_flags_type_flag (type, 2, "UFC");
714 append_flags_type_flag (type, 3, "OFC");
715 append_flags_type_flag (type, 4, "NVC");
716 append_flags_type_flag (type, 5, "NXA");
717 append_flags_type_flag (type, 6, "DZA");
718 append_flags_type_flag (type, 7, "UFA");
719 append_flags_type_flag (type, 8, "OFA");
720 append_flags_type_flag (type, 9, "NVA");
721 append_flags_type_flag (type, 22, "NS");
722 append_flags_type_flag (type, 23, "NXM");
723 append_flags_type_flag (type, 24, "DZM");
724 append_flags_type_flag (type, 25, "UFM");
725 append_flags_type_flag (type, 26, "OFM");
726 append_flags_type_flag (type, 27, "NVM");
728 tdep->sparc64_fsr_type = type;
731 return tdep->sparc64_fsr_type;
734 static struct type *
735 sparc64_fprs_type (struct gdbarch *gdbarch)
737 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
739 if (!tdep->sparc64_fprs_type)
741 struct type *type;
743 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 64);
744 append_flags_type_flag (type, 0, "DL");
745 append_flags_type_flag (type, 1, "DU");
746 append_flags_type_flag (type, 2, "FEF");
748 tdep->sparc64_fprs_type = type;
751 return tdep->sparc64_fprs_type;
755 /* Register information. */
756 #define SPARC64_FPU_REGISTERS \
757 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
758 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
759 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
760 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
761 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
762 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62"
763 #define SPARC64_CP0_REGISTERS \
764 "pc", "npc", \
765 /* FIXME: Give "state" a name until we start using register groups. */ \
766 "state", \
767 "fsr", \
768 "fprs", \
771 static const char * const sparc64_fpu_register_names[] = {
772 SPARC64_FPU_REGISTERS
774 static const char * const sparc64_cp0_register_names[] = {
775 SPARC64_CP0_REGISTERS
778 static const char * const sparc64_register_names[] =
780 SPARC_CORE_REGISTERS,
781 SPARC64_FPU_REGISTERS,
782 SPARC64_CP0_REGISTERS
785 /* Total number of registers. */
786 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
788 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
789 registers as "psuedo" registers. */
791 static const char * const sparc64_pseudo_register_names[] =
793 "cwp", "pstate", "asi", "ccr",
795 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
796 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
797 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
798 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
800 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
801 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
804 /* Total number of pseudo registers. */
805 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
807 /* Return the name of pseudo register REGNUM. */
809 static const char *
810 sparc64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
812 regnum -= gdbarch_num_regs (gdbarch);
814 gdb_assert (regnum < SPARC64_NUM_PSEUDO_REGS);
815 return sparc64_pseudo_register_names[regnum];
818 /* Return the name of register REGNUM. */
820 static const char *
821 sparc64_register_name (struct gdbarch *gdbarch, int regnum)
823 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
824 return tdesc_register_name (gdbarch, regnum);
826 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
827 return sparc64_register_names[regnum];
829 return sparc64_pseudo_register_name (gdbarch, regnum);
832 /* Return the GDB type object for the "standard" data type of data in
833 pseudo register REGNUM. */
835 static struct type *
836 sparc64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
838 regnum -= gdbarch_num_regs (gdbarch);
840 if (regnum == SPARC64_CWP_REGNUM)
841 return builtin_type (gdbarch)->builtin_int64;
842 if (regnum == SPARC64_PSTATE_REGNUM)
843 return sparc64_pstate_type (gdbarch);
844 if (regnum == SPARC64_ASI_REGNUM)
845 return builtin_type (gdbarch)->builtin_int64;
846 if (regnum == SPARC64_CCR_REGNUM)
847 return sparc64_ccr_type (gdbarch);
848 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM)
849 return builtin_type (gdbarch)->builtin_double;
850 if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM)
851 return builtin_type (gdbarch)->builtin_long_double;
853 internal_error (_("sparc64_pseudo_register_type: bad register number %d"),
854 regnum);
857 /* Return the GDB type object for the "standard" data type of data in
858 register REGNUM. */
860 static struct type *
861 sparc64_register_type (struct gdbarch *gdbarch, int regnum)
863 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
864 return tdesc_register_type (gdbarch, regnum);
866 /* Raw registers. */
867 if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
868 return builtin_type (gdbarch)->builtin_data_ptr;
869 if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM)
870 return builtin_type (gdbarch)->builtin_int64;
871 if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
872 return builtin_type (gdbarch)->builtin_float;
873 if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)
874 return builtin_type (gdbarch)->builtin_double;
875 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
876 return builtin_type (gdbarch)->builtin_func_ptr;
877 /* This raw register contains the contents of %cwp, %pstate, %asi
878 and %ccr as laid out in a %tstate register. */
879 if (regnum == SPARC64_STATE_REGNUM)
880 return builtin_type (gdbarch)->builtin_int64;
881 if (regnum == SPARC64_FSR_REGNUM)
882 return sparc64_fsr_type (gdbarch);
883 if (regnum == SPARC64_FPRS_REGNUM)
884 return sparc64_fprs_type (gdbarch);
885 /* "Although Y is a 64-bit register, its high-order 32 bits are
886 reserved and always read as 0." */
887 if (regnum == SPARC64_Y_REGNUM)
888 return builtin_type (gdbarch)->builtin_int64;
890 /* Pseudo registers. */
891 if (regnum >= gdbarch_num_regs (gdbarch))
892 return sparc64_pseudo_register_type (gdbarch, regnum);
894 internal_error (_("invalid regnum"));
897 static enum register_status
898 sparc64_pseudo_register_read (struct gdbarch *gdbarch,
899 readable_regcache *regcache,
900 int regnum, gdb_byte *buf)
902 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
903 enum register_status status;
905 regnum -= gdbarch_num_regs (gdbarch);
907 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
909 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
910 status = regcache->raw_read (regnum, buf);
911 if (status == REG_VALID)
912 status = regcache->raw_read (regnum + 1, buf + 4);
913 return status;
915 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
917 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
918 return regcache->raw_read (regnum, buf);
920 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
922 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
924 status = regcache->raw_read (regnum, buf);
925 if (status == REG_VALID)
926 status = regcache->raw_read (regnum + 1, buf + 4);
927 if (status == REG_VALID)
928 status = regcache->raw_read (regnum + 2, buf + 8);
929 if (status == REG_VALID)
930 status = regcache->raw_read (regnum + 3, buf + 12);
932 return status;
934 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
936 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
938 status = regcache->raw_read (regnum, buf);
939 if (status == REG_VALID)
940 status = regcache->raw_read (regnum + 1, buf + 8);
942 return status;
944 else if (regnum == SPARC64_CWP_REGNUM
945 || regnum == SPARC64_PSTATE_REGNUM
946 || regnum == SPARC64_ASI_REGNUM
947 || regnum == SPARC64_CCR_REGNUM)
949 ULONGEST state;
951 status = regcache->raw_read (SPARC64_STATE_REGNUM, &state);
952 if (status != REG_VALID)
953 return status;
955 switch (regnum)
957 case SPARC64_CWP_REGNUM:
958 state = (state >> 0) & ((1 << 5) - 1);
959 break;
960 case SPARC64_PSTATE_REGNUM:
961 state = (state >> 8) & ((1 << 12) - 1);
962 break;
963 case SPARC64_ASI_REGNUM:
964 state = (state >> 24) & ((1 << 8) - 1);
965 break;
966 case SPARC64_CCR_REGNUM:
967 state = (state >> 32) & ((1 << 8) - 1);
968 break;
970 store_unsigned_integer (buf, 8, byte_order, state);
973 return REG_VALID;
976 static void
977 sparc64_pseudo_register_write (struct gdbarch *gdbarch,
978 struct regcache *regcache,
979 int regnum, const gdb_byte *buf)
981 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
983 regnum -= gdbarch_num_regs (gdbarch);
985 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
987 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
988 regcache->raw_write (regnum, buf);
989 regcache->raw_write (regnum + 1, buf + 4);
991 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
993 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
994 regcache->raw_write (regnum, buf);
996 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
998 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
999 regcache->raw_write (regnum, buf);
1000 regcache->raw_write (regnum + 1, buf + 4);
1001 regcache->raw_write (regnum + 2, buf + 8);
1002 regcache->raw_write (regnum + 3, buf + 12);
1004 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
1006 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
1007 regcache->raw_write (regnum, buf);
1008 regcache->raw_write (regnum + 1, buf + 8);
1010 else if (regnum == SPARC64_CWP_REGNUM
1011 || regnum == SPARC64_PSTATE_REGNUM
1012 || regnum == SPARC64_ASI_REGNUM
1013 || regnum == SPARC64_CCR_REGNUM)
1015 ULONGEST state, bits;
1017 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
1018 bits = extract_unsigned_integer (buf, 8, byte_order);
1019 switch (regnum)
1021 case SPARC64_CWP_REGNUM:
1022 state |= ((bits & ((1 << 5) - 1)) << 0);
1023 break;
1024 case SPARC64_PSTATE_REGNUM:
1025 state |= ((bits & ((1 << 12) - 1)) << 8);
1026 break;
1027 case SPARC64_ASI_REGNUM:
1028 state |= ((bits & ((1 << 8) - 1)) << 24);
1029 break;
1030 case SPARC64_CCR_REGNUM:
1031 state |= ((bits & ((1 << 8) - 1)) << 32);
1032 break;
1034 regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
1039 /* Return PC of first real instruction of the function starting at
1040 START_PC. */
1042 static CORE_ADDR
1043 sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
1045 struct symtab_and_line sal;
1046 CORE_ADDR func_start, func_end;
1047 struct sparc_frame_cache cache;
1049 /* This is the preferred method, find the end of the prologue by
1050 using the debugging information. */
1051 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
1053 sal = find_pc_line (func_start, 0);
1055 if (sal.end < func_end
1056 && start_pc <= sal.end)
1057 return sal.end;
1060 return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL,
1061 &cache);
1064 /* Normal frames. */
1066 static struct sparc_frame_cache *
1067 sparc64_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
1069 return sparc_frame_cache (this_frame, this_cache);
1072 static void
1073 sparc64_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
1074 struct frame_id *this_id)
1076 struct sparc_frame_cache *cache =
1077 sparc64_frame_cache (this_frame, this_cache);
1079 /* This marks the outermost frame. */
1080 if (cache->base == 0)
1081 return;
1083 (*this_id) = frame_id_build (cache->base, cache->pc);
1086 static struct value *
1087 sparc64_frame_prev_register (const frame_info_ptr &this_frame, void **this_cache,
1088 int regnum)
1090 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1091 struct sparc_frame_cache *cache =
1092 sparc64_frame_cache (this_frame, this_cache);
1094 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
1096 CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0;
1098 regnum =
1099 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
1100 pc += get_frame_register_unsigned (this_frame, regnum) + 8;
1101 return frame_unwind_got_constant (this_frame, regnum, pc);
1104 /* Handle StackGhost. */
1106 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
1108 if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM)
1110 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
1111 ULONGEST i7;
1113 /* Read the value in from memory. */
1114 i7 = get_frame_memory_unsigned (this_frame, addr, 8);
1115 return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie);
1119 /* The previous frame's `local' and `in' registers may have been saved
1120 in the register save area. */
1121 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
1122 && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM))))
1124 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
1126 return frame_unwind_got_memory (this_frame, regnum, addr);
1129 /* The previous frame's `out' registers may be accessible as the current
1130 frame's `in' registers. */
1131 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM
1132 && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))))
1133 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
1135 return frame_unwind_got_register (this_frame, regnum, regnum);
1138 static const struct frame_unwind sparc64_frame_unwind =
1140 "sparc64 prologue",
1141 NORMAL_FRAME,
1142 default_frame_unwind_stop_reason,
1143 sparc64_frame_this_id,
1144 sparc64_frame_prev_register,
1145 NULL,
1146 default_frame_sniffer
1150 static CORE_ADDR
1151 sparc64_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
1153 struct sparc_frame_cache *cache =
1154 sparc64_frame_cache (this_frame, this_cache);
1156 return cache->base;
1159 static const struct frame_base sparc64_frame_base =
1161 &sparc64_frame_unwind,
1162 sparc64_frame_base_address,
1163 sparc64_frame_base_address,
1164 sparc64_frame_base_address
1167 /* Check whether TYPE must be 16-byte aligned. */
1169 static int
1170 sparc64_16_byte_align_p (struct type *type)
1172 if (type->code () == TYPE_CODE_ARRAY)
1174 struct type *t = check_typedef (type->target_type ());
1176 if (sparc64_floating_p (t))
1177 return 1;
1179 if (sparc64_floating_p (type) && type->length () == 16)
1180 return 1;
1182 if (sparc64_structure_or_union_p (type))
1184 int i;
1186 for (i = 0; i < type->num_fields (); i++)
1188 struct type *subtype = check_typedef (type->field (i).type ());
1190 if (sparc64_16_byte_align_p (subtype))
1191 return 1;
1195 return 0;
1198 /* Store floating fields of element ELEMENT of an "parameter array"
1199 that has type TYPE and is stored at BITPOS in VALBUF in the
1200 appropriate registers of REGCACHE. This function can be called
1201 recursively and therefore handles floating types in addition to
1202 structures. */
1204 static void
1205 sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
1206 const gdb_byte *valbuf, int element, int bitpos)
1208 struct gdbarch *gdbarch = regcache->arch ();
1209 int len = type->length ();
1211 gdb_assert (element < 16);
1213 if (type->code () == TYPE_CODE_ARRAY)
1215 gdb_byte buf[8];
1216 int regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
1218 valbuf += bitpos / 8;
1219 if (len < 8)
1221 memset (buf, 0, 8 - len);
1222 memcpy (buf + 8 - len, valbuf, len);
1223 valbuf = buf;
1224 len = 8;
1226 for (int n = 0; n < (len + 3) / 4; n++)
1227 regcache->cooked_write (regnum + n, valbuf + n * 4);
1229 else if (sparc64_floating_p (type)
1230 || (sparc64_complex_floating_p (type) && len <= 16))
1232 int regnum;
1234 if (len == 16)
1236 gdb_assert (bitpos == 0);
1237 gdb_assert ((element % 2) == 0);
1239 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM + element / 2;
1240 regcache->cooked_write (regnum, valbuf);
1242 else if (len == 8)
1244 gdb_assert (bitpos == 0 || bitpos == 64);
1246 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
1247 + element + bitpos / 64;
1248 regcache->cooked_write (regnum, valbuf + (bitpos / 8));
1250 else
1252 gdb_assert (len == 4);
1253 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128);
1255 regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
1256 regcache->cooked_write (regnum, valbuf + (bitpos / 8));
1259 else if (sparc64_structure_or_union_p (type))
1261 int i;
1263 for (i = 0; i < type->num_fields (); i++)
1265 struct type *subtype = check_typedef (type->field (i).type ());
1266 int subpos = bitpos + type->field (i).loc_bitpos ();
1268 sparc64_store_floating_fields (regcache, subtype, valbuf,
1269 element, subpos);
1272 /* GCC has an interesting bug. If TYPE is a structure that has
1273 a single `float' member, GCC doesn't treat it as a structure
1274 at all, but rather as an ordinary `float' argument. This
1275 argument will be stored in %f1, as required by the psABI.
1276 However, as a member of a structure the psABI requires it to
1277 be stored in %f0. This bug is present in GCC 3.3.2, but
1278 probably in older releases to. To appease GCC, if a
1279 structure has only a single `float' member, we store its
1280 value in %f1 too (we already have stored in %f0). */
1281 if (type->num_fields () == 1)
1283 struct type *subtype = check_typedef (type->field (0).type ());
1285 if (sparc64_floating_p (subtype) && subtype->length () == 4)
1286 regcache->cooked_write (SPARC_F1_REGNUM, valbuf);
1291 /* Fetch floating fields from a variable of type TYPE from the
1292 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
1293 in VALBUF. This function can be called recursively and therefore
1294 handles floating types in addition to structures. */
1296 static void
1297 sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
1298 gdb_byte *valbuf, int bitpos)
1300 struct gdbarch *gdbarch = regcache->arch ();
1302 if (type->code () == TYPE_CODE_ARRAY)
1304 int len = type->length ();
1305 int regnum = SPARC_F0_REGNUM + bitpos / 32;
1307 valbuf += bitpos / 8;
1308 if (len < 4)
1310 gdb_byte buf[4];
1311 regcache->cooked_read (regnum, buf);
1312 memcpy (valbuf, buf + 4 - len, len);
1314 else
1315 for (int i = 0; i < (len + 3) / 4; i++)
1316 regcache->cooked_read (regnum + i, valbuf + i * 4);
1318 else if (sparc64_floating_p (type))
1320 int len = type->length ();
1321 int regnum;
1323 if (len == 16)
1325 gdb_assert (bitpos == 0 || bitpos == 128);
1327 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
1328 + bitpos / 128;
1329 regcache->cooked_read (regnum, valbuf + (bitpos / 8));
1331 else if (len == 8)
1333 gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256);
1335 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + bitpos / 64;
1336 regcache->cooked_read (regnum, valbuf + (bitpos / 8));
1338 else
1340 gdb_assert (len == 4);
1341 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256);
1343 regnum = SPARC_F0_REGNUM + bitpos / 32;
1344 regcache->cooked_read (regnum, valbuf + (bitpos / 8));
1347 else if (sparc64_structure_or_union_p (type))
1349 int i;
1351 for (i = 0; i < type->num_fields (); i++)
1353 struct type *subtype = check_typedef (type->field (i).type ());
1354 int subpos = bitpos + type->field (i).loc_bitpos ();
1356 sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos);
1361 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
1362 non-zero) in REGCACHE and on the stack (starting from address SP). */
1364 static CORE_ADDR
1365 sparc64_store_arguments (struct regcache *regcache, int nargs,
1366 struct value **args, CORE_ADDR sp,
1367 function_call_return_method return_method,
1368 CORE_ADDR struct_addr)
1370 struct gdbarch *gdbarch = regcache->arch ();
1371 /* Number of extended words in the "parameter array". */
1372 int num_elements = 0;
1373 int element = 0;
1374 int i;
1376 /* Take BIAS into account. */
1377 sp += BIAS;
1379 /* First we calculate the number of extended words in the "parameter
1380 array". While doing so we also convert some of the arguments. */
1382 if (return_method == return_method_struct)
1383 num_elements++;
1385 for (i = 0; i < nargs; i++)
1387 struct type *type = args[i]->type ();
1388 int len = type->length ();
1390 if (sparc64_structure_or_union_p (type)
1391 || (sparc64_complex_floating_p (type) && len == 32))
1393 /* Structure or Union arguments. */
1394 if (len <= 16)
1396 if (num_elements % 2 && sparc64_16_byte_align_p (type))
1397 num_elements++;
1398 num_elements += ((len + 7) / 8);
1400 else
1402 /* The psABI says that "Structures or unions larger than
1403 sixteen bytes are copied by the caller and passed
1404 indirectly; the caller will pass the address of a
1405 correctly aligned structure value. This sixty-four
1406 bit address will occupy one word in the parameter
1407 array, and may be promoted to an %o register like any
1408 other pointer value." Allocate memory for these
1409 values on the stack. */
1410 sp -= len;
1412 /* Use 16-byte alignment for these values. That's
1413 always correct, and wasting a few bytes shouldn't be
1414 a problem. */
1415 sp &= ~0xf;
1417 write_memory (sp, args[i]->contents ().data (), len);
1418 args[i] = value_from_pointer (lookup_pointer_type (type), sp);
1419 num_elements++;
1422 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1424 /* Floating arguments. */
1425 if (len == 16)
1427 /* The psABI says that "Each quad-precision parameter
1428 value will be assigned to two extended words in the
1429 parameter array. */
1430 num_elements += 2;
1432 /* The psABI says that "Long doubles must be
1433 quad-aligned, and thus a hole might be introduced
1434 into the parameter array to force alignment." Skip
1435 an element if necessary. */
1436 if ((num_elements % 2) && sparc64_16_byte_align_p (type))
1437 num_elements++;
1439 else
1440 num_elements++;
1442 else
1444 /* Integral and pointer arguments. */
1445 gdb_assert (sparc64_integral_or_pointer_p (type));
1447 /* The psABI says that "Each argument value of integral type
1448 smaller than an extended word will be widened by the
1449 caller to an extended word according to the signed-ness
1450 of the argument type." */
1451 if (len < 8)
1452 args[i] = value_cast (builtin_type (gdbarch)->builtin_int64,
1453 args[i]);
1454 num_elements++;
1458 /* Allocate the "parameter array". */
1459 sp -= num_elements * 8;
1461 /* The psABI says that "Every stack frame must be 16-byte aligned." */
1462 sp &= ~0xf;
1464 /* Now we store the arguments in to the "parameter array". Some
1465 Integer or Pointer arguments and Structure or Union arguments
1466 will be passed in %o registers. Some Floating arguments and
1467 floating members of structures are passed in floating-point
1468 registers. However, for functions with variable arguments,
1469 floating arguments are stored in an %0 register, and for
1470 functions without a prototype floating arguments are stored in
1471 both a floating-point and an %o registers, or a floating-point
1472 register and memory. To simplify the logic here we always pass
1473 arguments in memory, an %o register, and a floating-point
1474 register if appropriate. This should be no problem since the
1475 contents of any unused memory or registers in the "parameter
1476 array" are undefined. */
1478 if (return_method == return_method_struct)
1480 regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
1481 element++;
1484 for (i = 0; i < nargs; i++)
1486 const gdb_byte *valbuf = args[i]->contents ().data ();
1487 struct type *type = args[i]->type ();
1488 int len = type->length ();
1489 int regnum = -1;
1490 gdb_byte buf[16];
1492 if (sparc64_structure_or_union_p (type)
1493 || (sparc64_complex_floating_p (type) && len == 32))
1495 /* Structure, Union or long double Complex arguments. */
1496 gdb_assert (len <= 16);
1497 memset (buf, 0, sizeof (buf));
1498 memcpy (buf, valbuf, len);
1499 valbuf = buf;
1501 if (element % 2 && sparc64_16_byte_align_p (type))
1502 element++;
1504 if (element < 6)
1506 regnum = SPARC_O0_REGNUM + element;
1507 if (len > 8 && element < 5)
1508 regcache->cooked_write (regnum + 1, valbuf + 8);
1511 if (element < 16)
1512 sparc64_store_floating_fields (regcache, type, valbuf, element, 0);
1514 else if (sparc64_complex_floating_p (type))
1516 /* Float Complex or double Complex arguments. */
1517 if (element < 16)
1519 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + element;
1521 if (len == 16)
1523 if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D30_REGNUM)
1524 regcache->cooked_write (regnum + 1, valbuf + 8);
1525 if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D10_REGNUM)
1526 regcache->cooked_write (SPARC_O0_REGNUM + element + 1,
1527 valbuf + 8);
1531 else if (sparc64_floating_p (type))
1533 /* Floating arguments. */
1534 if (len == 16)
1536 if (element % 2)
1537 element++;
1538 if (element < 16)
1539 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
1540 + element / 2;
1542 else if (len == 8)
1544 if (element < 16)
1545 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
1546 + element;
1548 else if (len == 4)
1550 /* The psABI says "Each single-precision parameter value
1551 will be assigned to one extended word in the
1552 parameter array, and right-justified within that
1553 word; the left half (even float register) is
1554 undefined." Even though the psABI says that "the
1555 left half is undefined", set it to zero here. */
1556 memset (buf, 0, 4);
1557 memcpy (buf + 4, valbuf, 4);
1558 valbuf = buf;
1559 len = 8;
1560 if (element < 16)
1561 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
1562 + element;
1565 else
1567 /* Integral and pointer arguments. */
1568 gdb_assert (len == 8);
1569 if (element < 6)
1570 regnum = SPARC_O0_REGNUM + element;
1573 if (regnum != -1)
1575 regcache->cooked_write (regnum, valbuf);
1577 /* If we're storing the value in a floating-point register,
1578 also store it in the corresponding %0 register(s). */
1579 if (regnum >= gdbarch_num_regs (gdbarch))
1581 regnum -= gdbarch_num_regs (gdbarch);
1583 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM)
1585 gdb_assert (element < 6);
1586 regnum = SPARC_O0_REGNUM + element;
1587 regcache->cooked_write (regnum, valbuf);
1589 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM)
1591 gdb_assert (element < 5);
1592 regnum = SPARC_O0_REGNUM + element;
1593 regcache->cooked_write (regnum, valbuf);
1594 regcache->cooked_write (regnum + 1, valbuf + 8);
1599 /* Always store the argument in memory. */
1600 write_memory (sp + element * 8, valbuf, len);
1601 element += ((len + 7) / 8);
1604 gdb_assert (element == num_elements);
1606 /* Take BIAS into account. */
1607 sp -= BIAS;
1608 return sp;
1611 static CORE_ADDR
1612 sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
1614 /* The ABI requires 16-byte alignment. */
1615 return address & ~0xf;
1618 static CORE_ADDR
1619 sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1620 struct regcache *regcache, CORE_ADDR bp_addr,
1621 int nargs, struct value **args, CORE_ADDR sp,
1622 function_call_return_method return_method,
1623 CORE_ADDR struct_addr)
1625 /* Set return address. */
1626 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
1628 /* Set up function arguments. */
1629 sp = sparc64_store_arguments (regcache, nargs, args, sp, return_method,
1630 struct_addr);
1632 /* Allocate the register save area. */
1633 sp -= 16 * 8;
1635 /* Stack should be 16-byte aligned at this point. */
1636 gdb_assert ((sp + BIAS) % 16 == 0);
1638 /* Finally, update the stack pointer. */
1639 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp);
1641 return sp + BIAS;
1645 /* Extract from an array REGBUF containing the (raw) register state, a
1646 function return value of TYPE, and copy that into VALBUF. */
1648 static void
1649 sparc64_extract_return_value (struct type *type, struct regcache *regcache,
1650 gdb_byte *valbuf)
1652 int len = type->length ();
1653 gdb_byte buf[32];
1654 int i;
1656 if (sparc64_structure_or_union_p (type))
1658 /* Structure or Union return values. */
1659 gdb_assert (len <= 32);
1661 for (i = 0; i < ((len + 7) / 8); i++)
1662 regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
1663 if (type->code () != TYPE_CODE_UNION)
1664 sparc64_extract_floating_fields (regcache, type, buf, 0);
1665 memcpy (valbuf, buf, len);
1667 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1669 /* Floating return values. */
1670 for (i = 0; i < len / 4; i++)
1671 regcache->cooked_read (SPARC_F0_REGNUM + i, buf + i * 4);
1672 memcpy (valbuf, buf, len);
1674 else if (type->code () == TYPE_CODE_ARRAY)
1676 /* Small arrays are returned the same way as small structures. */
1677 gdb_assert (len <= 32);
1679 for (i = 0; i < ((len + 7) / 8); i++)
1680 regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
1681 memcpy (valbuf, buf, len);
1683 else
1685 /* Integral and pointer return values. */
1686 gdb_assert (sparc64_integral_or_pointer_p (type));
1688 /* Just stripping off any unused bytes should preserve the
1689 signed-ness just fine. */
1690 regcache->cooked_read (SPARC_O0_REGNUM, buf);
1691 memcpy (valbuf, buf + 8 - len, len);
1695 /* Write into the appropriate registers a function return value stored
1696 in VALBUF of type TYPE. */
1698 static void
1699 sparc64_store_return_value (struct type *type, struct regcache *regcache,
1700 const gdb_byte *valbuf)
1702 int len = type->length ();
1703 gdb_byte buf[16];
1704 int i;
1706 if (sparc64_structure_or_union_p (type))
1708 /* Structure or Union return values. */
1709 gdb_assert (len <= 32);
1711 /* Simplify matters by storing the complete value (including
1712 floating members) into %o0 and %o1. Floating members are
1713 also store in the appropriate floating-point registers. */
1714 memset (buf, 0, sizeof (buf));
1715 memcpy (buf, valbuf, len);
1716 for (i = 0; i < ((len + 7) / 8); i++)
1717 regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
1718 if (type->code () != TYPE_CODE_UNION)
1719 sparc64_store_floating_fields (regcache, type, buf, 0, 0);
1721 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1723 /* Floating return values. */
1724 memcpy (buf, valbuf, len);
1725 for (i = 0; i < len / 4; i++)
1726 regcache->cooked_write (SPARC_F0_REGNUM + i, buf + i * 4);
1728 else if (type->code () == TYPE_CODE_ARRAY)
1730 /* Small arrays are returned the same way as small structures. */
1731 gdb_assert (len <= 32);
1733 memset (buf, 0, sizeof (buf));
1734 memcpy (buf, valbuf, len);
1735 for (i = 0; i < ((len + 7) / 8); i++)
1736 regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
1738 else
1740 /* Integral and pointer return values. */
1741 gdb_assert (sparc64_integral_or_pointer_p (type));
1743 /* ??? Do we need to do any sign-extension here? */
1744 memset (buf, 0, 8);
1745 memcpy (buf + 8 - len, valbuf, len);
1746 regcache->cooked_write (SPARC_O0_REGNUM, buf);
1750 static enum return_value_convention
1751 sparc64_return_value (struct gdbarch *gdbarch, struct value *function,
1752 struct type *type, struct regcache *regcache,
1753 gdb_byte *readbuf, const gdb_byte *writebuf)
1755 if (type->length () > 32)
1756 return RETURN_VALUE_STRUCT_CONVENTION;
1758 if (readbuf)
1759 sparc64_extract_return_value (type, regcache, readbuf);
1760 if (writebuf)
1761 sparc64_store_return_value (type, regcache, writebuf);
1763 return RETURN_VALUE_REGISTER_CONVENTION;
1767 static void
1768 sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1769 struct dwarf2_frame_state_reg *reg,
1770 const frame_info_ptr &this_frame)
1772 switch (regnum)
1774 case SPARC_G0_REGNUM:
1775 /* Since %g0 is always zero, there is no point in saving it, and
1776 people will be inclined omit it from the CFI. Make sure we
1777 don't warn about that. */
1778 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1779 break;
1780 case SPARC_SP_REGNUM:
1781 reg->how = DWARF2_FRAME_REG_CFA;
1782 break;
1783 case SPARC64_PC_REGNUM:
1784 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1785 reg->loc.offset = 8;
1786 break;
1787 case SPARC64_NPC_REGNUM:
1788 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1789 reg->loc.offset = 12;
1790 break;
1794 /* sparc64_addr_bits_remove - remove useless address bits */
1796 static CORE_ADDR
1797 sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
1799 return adi_normalize_address (addr);
1802 void
1803 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1805 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
1807 tdep->pc_regnum = SPARC64_PC_REGNUM;
1808 tdep->npc_regnum = SPARC64_NPC_REGNUM;
1809 tdep->fpu_register_names = sparc64_fpu_register_names;
1810 tdep->fpu_registers_num = ARRAY_SIZE (sparc64_fpu_register_names);
1811 tdep->cp0_register_names = sparc64_cp0_register_names;
1812 tdep->cp0_registers_num = ARRAY_SIZE (sparc64_cp0_register_names);
1814 /* This is what all the fuss is about. */
1815 set_gdbarch_long_bit (gdbarch, 64);
1816 set_gdbarch_long_long_bit (gdbarch, 64);
1817 set_gdbarch_ptr_bit (gdbarch, 64);
1819 set_gdbarch_wchar_bit (gdbarch, 16);
1820 set_gdbarch_wchar_signed (gdbarch, 0);
1822 set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS);
1823 set_gdbarch_register_name (gdbarch, sparc64_register_name);
1824 set_gdbarch_register_type (gdbarch, sparc64_register_type);
1825 set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS);
1826 set_tdesc_pseudo_register_name (gdbarch, sparc64_pseudo_register_name);
1827 set_tdesc_pseudo_register_type (gdbarch, sparc64_pseudo_register_type);
1828 set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read);
1829 set_gdbarch_deprecated_pseudo_register_write (gdbarch,
1830 sparc64_pseudo_register_write);
1832 /* Register numbers of various important registers. */
1833 set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */
1835 /* Call dummy code. */
1836 set_gdbarch_frame_align (gdbarch, sparc64_frame_align);
1837 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1838 set_gdbarch_push_dummy_code (gdbarch, NULL);
1839 set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call);
1841 set_gdbarch_return_value (gdbarch, sparc64_return_value);
1842 set_gdbarch_return_value_as_value (gdbarch, default_gdbarch_return_value);
1843 set_gdbarch_stabs_argument_has_addr
1844 (gdbarch, default_stabs_argument_has_addr);
1846 set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue);
1847 set_gdbarch_stack_frame_destroyed_p (gdbarch, sparc_stack_frame_destroyed_p);
1849 /* Hook in the DWARF CFI frame unwinder. */
1850 dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg);
1851 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1852 StackGhost issues have been resolved. */
1854 frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind);
1855 frame_base_set_default (gdbarch, &sparc64_frame_base);
1857 set_gdbarch_addr_bits_remove (gdbarch, sparc64_addr_bits_remove);
1861 /* Helper functions for dealing with register sets. */
1863 #define TSTATE_CWP 0x000000000000001fULL
1864 #define TSTATE_ICC 0x0000000f00000000ULL
1865 #define TSTATE_XCC 0x000000f000000000ULL
1867 #define PSR_S 0x00000080
1868 #ifndef PSR_ICC
1869 #define PSR_ICC 0x00f00000
1870 #endif
1871 #define PSR_VERS 0x0f000000
1872 #ifndef PSR_IMPL
1873 #define PSR_IMPL 0xf0000000
1874 #endif
1875 #define PSR_V8PLUS 0xff000000
1876 #define PSR_XCC 0x000f0000
1878 void
1879 sparc64_supply_gregset (const struct sparc_gregmap *gregmap,
1880 struct regcache *regcache,
1881 int regnum, const void *gregs)
1883 struct gdbarch *gdbarch = regcache->arch ();
1884 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1885 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
1886 const gdb_byte *regs = (const gdb_byte *) gregs;
1887 gdb_byte zero[8] = { 0 };
1888 int i;
1890 if (sparc32)
1892 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1894 int offset = gregmap->r_tstate_offset;
1895 ULONGEST tstate, psr;
1896 gdb_byte buf[4];
1898 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
1899 psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12)
1900 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS);
1901 store_unsigned_integer (buf, 4, byte_order, psr);
1902 regcache->raw_supply (SPARC32_PSR_REGNUM, buf);
1905 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1906 regcache->raw_supply (SPARC32_PC_REGNUM,
1907 regs + gregmap->r_pc_offset + 4);
1909 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1910 regcache->raw_supply (SPARC32_NPC_REGNUM,
1911 regs + gregmap->r_npc_offset + 4);
1913 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
1915 int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
1916 regcache->raw_supply (SPARC32_Y_REGNUM, regs + offset);
1919 else
1921 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1922 regcache->raw_supply (SPARC64_STATE_REGNUM,
1923 regs + gregmap->r_tstate_offset);
1925 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1926 regcache->raw_supply (SPARC64_PC_REGNUM,
1927 regs + gregmap->r_pc_offset);
1929 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1930 regcache->raw_supply (SPARC64_NPC_REGNUM,
1931 regs + gregmap->r_npc_offset);
1933 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
1935 gdb_byte buf[8];
1937 memset (buf, 0, 8);
1938 memcpy (buf + 8 - gregmap->r_y_size,
1939 regs + gregmap->r_y_offset, gregmap->r_y_size);
1940 regcache->raw_supply (SPARC64_Y_REGNUM, buf);
1943 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1944 && gregmap->r_fprs_offset != -1)
1945 regcache->raw_supply (SPARC64_FPRS_REGNUM,
1946 regs + gregmap->r_fprs_offset);
1949 if (regnum == SPARC_G0_REGNUM || regnum == -1)
1950 regcache->raw_supply (SPARC_G0_REGNUM, &zero);
1952 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1954 int offset = gregmap->r_g1_offset;
1956 if (sparc32)
1957 offset += 4;
1959 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1961 if (regnum == i || regnum == -1)
1962 regcache->raw_supply (i, regs + offset);
1963 offset += 8;
1967 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1969 /* Not all of the register set variants include Locals and
1970 Inputs. For those that don't, we read them off the stack. */
1971 if (gregmap->r_l0_offset == -1)
1973 ULONGEST sp;
1975 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
1976 sparc_supply_rwindow (regcache, sp, regnum);
1978 else
1980 int offset = gregmap->r_l0_offset;
1982 if (sparc32)
1983 offset += 4;
1985 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
1987 if (regnum == i || regnum == -1)
1988 regcache->raw_supply (i, regs + offset);
1989 offset += 8;
1995 void
1996 sparc64_collect_gregset (const struct sparc_gregmap *gregmap,
1997 const struct regcache *regcache,
1998 int regnum, void *gregs)
2000 struct gdbarch *gdbarch = regcache->arch ();
2001 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2002 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
2003 gdb_byte *regs = (gdb_byte *) gregs;
2004 int i;
2006 if (sparc32)
2008 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
2010 int offset = gregmap->r_tstate_offset;
2011 ULONGEST tstate, psr;
2012 gdb_byte buf[8];
2014 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
2015 regcache->raw_collect (SPARC32_PSR_REGNUM, buf);
2016 psr = extract_unsigned_integer (buf, 4, byte_order);
2017 tstate |= (psr & PSR_ICC) << 12;
2018 if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS)
2019 tstate |= (psr & PSR_XCC) << 20;
2020 store_unsigned_integer (buf, 8, byte_order, tstate);
2021 memcpy (regs + offset, buf, 8);
2024 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
2025 regcache->raw_collect (SPARC32_PC_REGNUM,
2026 regs + gregmap->r_pc_offset + 4);
2028 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
2029 regcache->raw_collect (SPARC32_NPC_REGNUM,
2030 regs + gregmap->r_npc_offset + 4);
2032 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
2034 int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
2035 regcache->raw_collect (SPARC32_Y_REGNUM, regs + offset);
2038 else
2040 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
2041 regcache->raw_collect (SPARC64_STATE_REGNUM,
2042 regs + gregmap->r_tstate_offset);
2044 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
2045 regcache->raw_collect (SPARC64_PC_REGNUM,
2046 regs + gregmap->r_pc_offset);
2048 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
2049 regcache->raw_collect (SPARC64_NPC_REGNUM,
2050 regs + gregmap->r_npc_offset);
2052 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
2054 gdb_byte buf[8];
2056 regcache->raw_collect (SPARC64_Y_REGNUM, buf);
2057 memcpy (regs + gregmap->r_y_offset,
2058 buf + 8 - gregmap->r_y_size, gregmap->r_y_size);
2061 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
2062 && gregmap->r_fprs_offset != -1)
2063 regcache->raw_collect (SPARC64_FPRS_REGNUM,
2064 regs + gregmap->r_fprs_offset);
2068 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
2070 int offset = gregmap->r_g1_offset;
2072 if (sparc32)
2073 offset += 4;
2075 /* %g0 is always zero. */
2076 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
2078 if (regnum == i || regnum == -1)
2079 regcache->raw_collect (i, regs + offset);
2080 offset += 8;
2084 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
2086 /* Not all of the register set variants include Locals and
2087 Inputs. For those that don't, we read them off the stack. */
2088 if (gregmap->r_l0_offset != -1)
2090 int offset = gregmap->r_l0_offset;
2092 if (sparc32)
2093 offset += 4;
2095 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
2097 if (regnum == i || regnum == -1)
2098 regcache->raw_collect (i, regs + offset);
2099 offset += 8;
2105 void
2106 sparc64_supply_fpregset (const struct sparc_fpregmap *fpregmap,
2107 struct regcache *regcache,
2108 int regnum, const void *fpregs)
2110 int sparc32 = (gdbarch_ptr_bit (regcache->arch ()) == 32);
2111 const gdb_byte *regs = (const gdb_byte *) fpregs;
2112 int i;
2114 for (i = 0; i < 32; i++)
2116 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
2117 regcache->raw_supply (SPARC_F0_REGNUM + i,
2118 regs + fpregmap->r_f0_offset + (i * 4));
2121 if (sparc32)
2123 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
2124 regcache->raw_supply (SPARC32_FSR_REGNUM,
2125 regs + fpregmap->r_fsr_offset);
2127 else
2129 for (i = 0; i < 16; i++)
2131 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
2132 regcache->raw_supply
2133 (SPARC64_F32_REGNUM + i,
2134 regs + fpregmap->r_f0_offset + (32 * 4) + (i * 8));
2137 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
2138 regcache->raw_supply (SPARC64_FSR_REGNUM,
2139 regs + fpregmap->r_fsr_offset);
2143 void
2144 sparc64_collect_fpregset (const struct sparc_fpregmap *fpregmap,
2145 const struct regcache *regcache,
2146 int regnum, void *fpregs)
2148 int sparc32 = (gdbarch_ptr_bit (regcache->arch ()) == 32);
2149 gdb_byte *regs = (gdb_byte *) fpregs;
2150 int i;
2152 for (i = 0; i < 32; i++)
2154 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
2155 regcache->raw_collect (SPARC_F0_REGNUM + i,
2156 regs + fpregmap->r_f0_offset + (i * 4));
2159 if (sparc32)
2161 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
2162 regcache->raw_collect (SPARC32_FSR_REGNUM,
2163 regs + fpregmap->r_fsr_offset);
2165 else
2167 for (i = 0; i < 16; i++)
2169 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
2170 regcache->raw_collect (SPARC64_F32_REGNUM + i,
2171 (regs + fpregmap->r_f0_offset
2172 + (32 * 4) + (i * 8)));
2175 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
2176 regcache->raw_collect (SPARC64_FSR_REGNUM,
2177 regs + fpregmap->r_fsr_offset);
2181 const struct sparc_fpregmap sparc64_bsd_fpregmap =
2183 0 * 8, /* %f0 */
2184 32 * 8, /* %fsr */