Home | History | Annotate | Line # | Download | only in gdb
sparc64-tdep.c revision 1.9.2.1
      1      1.1  christos /* Target-dependent code for UltraSPARC.
      2      1.1  christos 
      3  1.9.2.1  perseant    Copyright (C) 2003-2023 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    This file is part of GDB.
      6      1.1  christos 
      7      1.1  christos    This program is free software; you can redistribute it and/or modify
      8      1.1  christos    it under the terms of the GNU General Public License as published by
      9      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos    (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos    This program is distributed in the hope that it will be useful,
     13      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos    GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos    You should have received a copy of the GNU General Public License
     18      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19      1.1  christos 
     20      1.1  christos #include "defs.h"
     21      1.1  christos #include "arch-utils.h"
     22      1.9  christos #include "dwarf2/frame.h"
     23      1.1  christos #include "frame.h"
     24      1.1  christos #include "frame-base.h"
     25      1.1  christos #include "frame-unwind.h"
     26      1.1  christos #include "gdbcore.h"
     27      1.1  christos #include "gdbtypes.h"
     28      1.1  christos #include "inferior.h"
     29      1.1  christos #include "symtab.h"
     30      1.1  christos #include "objfiles.h"
     31      1.1  christos #include "osabi.h"
     32      1.1  christos #include "regcache.h"
     33      1.7  christos #include "target-descriptions.h"
     34      1.1  christos #include "target.h"
     35      1.1  christos #include "value.h"
     36      1.1  christos #include "sparc64-tdep.h"
     37      1.9  christos #include <forward_list>
     38      1.1  christos 
     39      1.1  christos /* This file implements the SPARC 64-bit ABI as defined by the
     40      1.1  christos    section "Low-Level System Information" of the SPARC Compliance
     41      1.1  christos    Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
     42      1.1  christos    SPARC.  */
     43      1.1  christos 
     44      1.1  christos /* Please use the sparc32_-prefix for 32-bit specific code, the
     45      1.1  christos    sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
     46      1.1  christos    code can handle both.  */
     47      1.1  christos 
     48      1.8  christos /* The M7 processor supports an Application Data Integrity (ADI) feature
     50      1.8  christos    that detects invalid data accesses.  When software allocates memory and
     51      1.8  christos    enables ADI on the allocated memory, it chooses a 4-bit version number,
     52      1.8  christos    sets the version in the upper 4 bits of the 64-bit pointer to that data,
     53      1.8  christos    and stores the 4-bit version in every cacheline of the object.  Hardware
     54      1.8  christos    saves the latter in spare bits in the cache and memory hierarchy. On each
     55      1.8  christos    load and store, the processor compares the upper 4 VA (virtual address) bits
     56      1.8  christos    to the cacheline's version. If there is a mismatch, the processor generates
     57      1.8  christos    a version mismatch trap which can be either precise or disrupting.
     58      1.8  christos    The trap is an error condition which the kernel delivers to the process
     59      1.8  christos    as a SIGSEGV signal.
     60      1.8  christos 
     61      1.8  christos    The upper 4 bits of the VA represent a version and are not part of the
     62      1.8  christos    true address.  The processor clears these bits and sign extends bit 59
     63      1.8  christos    to generate the true address.
     64      1.8  christos 
     65      1.8  christos    Note that 32-bit applications cannot use ADI. */
     66      1.8  christos 
     67      1.8  christos 
     68      1.8  christos #include <algorithm>
     69      1.8  christos #include "cli/cli-utils.h"
     70      1.8  christos #include "gdbcmd.h"
     71      1.8  christos #include "auxv.h"
     72      1.8  christos 
     73      1.8  christos #define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/9999/adi/lstatus")
     74      1.8  christos 
     75      1.8  christos /* ELF Auxiliary vectors */
     76      1.8  christos #ifndef AT_ADI_BLKSZ
     77      1.8  christos #define AT_ADI_BLKSZ    34
     78      1.8  christos #endif
     79      1.8  christos #ifndef AT_ADI_NBITS
     80      1.8  christos #define AT_ADI_NBITS    35
     81      1.8  christos #endif
     82      1.8  christos #ifndef AT_ADI_UEONADI
     83      1.8  christos #define AT_ADI_UEONADI  36
     84      1.8  christos #endif
     85      1.8  christos 
     86      1.8  christos /* ADI command list.  */
     87      1.8  christos static struct cmd_list_element *sparc64adilist = NULL;
     88      1.8  christos 
     89      1.8  christos /* ADI stat settings.  */
     90      1.8  christos struct adi_stat_t
     91      1.8  christos {
     92      1.8  christos   /* The ADI block size.  */
     93      1.8  christos   unsigned long blksize;
     94      1.8  christos 
     95      1.8  christos   /* Number of bits used for an ADI version tag which can be
     96      1.8  christos      used together with the shift value for an ADI version tag
     97      1.8  christos      to encode or extract the ADI version value in a pointer.  */
     98      1.8  christos   unsigned long nbits;
     99      1.8  christos 
    100      1.8  christos   /* The maximum ADI version tag value supported.  */
    101      1.8  christos   int max_version;
    102      1.8  christos 
    103      1.8  christos   /* ADI version tag file.  */
    104      1.8  christos   int tag_fd = 0;
    105      1.8  christos 
    106      1.8  christos   /* ADI availability check has been done.  */
    107      1.8  christos   bool checked_avail = false;
    108      1.8  christos 
    109      1.8  christos   /* ADI is available.  */
    110      1.8  christos   bool is_avail = false;
    111      1.8  christos 
    112      1.8  christos };
    113      1.8  christos 
    114      1.8  christos /* Per-process ADI stat info.  */
    115      1.9  christos 
    116      1.8  christos struct sparc64_adi_info
    117      1.8  christos {
    118      1.8  christos   sparc64_adi_info (pid_t pid_)
    119      1.8  christos     : pid (pid_)
    120      1.8  christos   {}
    121      1.8  christos 
    122      1.8  christos   /* The process identifier.  */
    123      1.8  christos   pid_t pid;
    124      1.8  christos 
    125      1.8  christos   /* The ADI stat.  */
    126      1.8  christos   adi_stat_t stat = {};
    127      1.9  christos 
    128      1.8  christos };
    129      1.8  christos 
    130      1.8  christos static std::forward_list<sparc64_adi_info> adi_proc_list;
    131      1.8  christos 
    132      1.8  christos 
    133      1.8  christos /* Get ADI info for process PID, creating one if it doesn't exist.  */
    134      1.8  christos 
    135      1.8  christos static sparc64_adi_info *
    136      1.8  christos get_adi_info_proc (pid_t pid)
    137      1.8  christos {
    138  1.9.2.1  perseant   auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (),
    139  1.9.2.1  perseant 			     [&pid] (const sparc64_adi_info &info)
    140  1.9.2.1  perseant 			     {
    141  1.9.2.1  perseant 			       return info.pid == pid;
    142      1.8  christos 			     });
    143      1.8  christos 
    144      1.8  christos   if (found == adi_proc_list.end ())
    145      1.8  christos     {
    146      1.8  christos       adi_proc_list.emplace_front (pid);
    147      1.8  christos       return &adi_proc_list.front ();
    148      1.8  christos     }
    149      1.8  christos   else
    150      1.8  christos     {
    151      1.8  christos       return &(*found);
    152      1.8  christos     }
    153      1.8  christos }
    154      1.8  christos 
    155      1.8  christos static adi_stat_t
    156      1.8  christos get_adi_info (pid_t pid)
    157      1.8  christos {
    158      1.8  christos   sparc64_adi_info *proc;
    159      1.8  christos 
    160      1.8  christos   proc = get_adi_info_proc (pid);
    161      1.8  christos   return proc->stat;
    162      1.8  christos }
    163      1.8  christos 
    164      1.8  christos /* Is called when GDB is no longer debugging process PID.  It
    165      1.8  christos    deletes data structure that keeps track of the ADI stat.  */
    166      1.8  christos 
    167      1.8  christos void
    168      1.8  christos sparc64_forget_process (pid_t pid)
    169  1.9.2.1  perseant {
    170      1.8  christos   fileio_error target_errno;
    171      1.8  christos 
    172      1.8  christos   for (auto pit = adi_proc_list.before_begin (),
    173      1.8  christos 	 it = std::next (pit);
    174      1.8  christos        it != adi_proc_list.end ();
    175      1.8  christos        )
    176      1.8  christos     {
    177      1.8  christos       if ((*it).pid == pid)
    178  1.9.2.1  perseant 	{
    179  1.9.2.1  perseant 	  if ((*it).stat.tag_fd > 0)
    180      1.8  christos 	    target_fileio_close ((*it).stat.tag_fd, &target_errno);
    181  1.9.2.1  perseant 	  adi_proc_list.erase_after (pit);
    182      1.8  christos 	  break;
    183      1.8  christos 	}
    184      1.8  christos       else
    185      1.8  christos 	pit = it++;
    186      1.8  christos     }
    187      1.8  christos 
    188      1.8  christos }
    189      1.8  christos 
    190      1.8  christos /* Read attributes of a maps entry in /proc/[pid]/adi/maps.  */
    191      1.8  christos 
    192      1.8  christos static void
    193  1.9.2.1  perseant read_maps_entry (const char *line,
    194      1.8  christos 	      ULONGEST *addr, ULONGEST *endaddr)
    195      1.8  christos {
    196      1.8  christos   const char *p = line;
    197      1.8  christos 
    198      1.8  christos   *addr = strtoulst (p, &p, 16);
    199      1.8  christos   if (*p == '-')
    200      1.8  christos     p++;
    201      1.8  christos 
    202      1.8  christos   *endaddr = strtoulst (p, &p, 16);
    203      1.8  christos }
    204      1.8  christos 
    205      1.8  christos /* Check if ADI is available.  */
    206      1.8  christos 
    207      1.8  christos static bool
    208      1.8  christos adi_available (void)
    209      1.8  christos {
    210      1.8  christos   pid_t pid = inferior_ptid.pid ();
    211      1.8  christos   sparc64_adi_info *proc = get_adi_info_proc (pid);
    212      1.8  christos   CORE_ADDR value;
    213      1.8  christos 
    214      1.8  christos   if (proc->stat.checked_avail)
    215      1.8  christos     return proc->stat.is_avail;
    216      1.8  christos 
    217  1.9.2.1  perseant   proc->stat.checked_avail = true;
    218      1.8  christos   if (target_auxv_search (AT_ADI_BLKSZ, &value) <= 0)
    219      1.8  christos     return false;
    220  1.9.2.1  perseant   proc->stat.blksize = value;
    221      1.8  christos   target_auxv_search (AT_ADI_NBITS, &value);
    222      1.8  christos   proc->stat.nbits = value;
    223      1.8  christos   proc->stat.max_version = (1 << proc->stat.nbits) - 2;
    224      1.8  christos   proc->stat.is_avail = true;
    225      1.8  christos 
    226      1.8  christos   return proc->stat.is_avail;
    227      1.8  christos }
    228      1.8  christos 
    229      1.8  christos /* Normalize a versioned address - a VA with ADI bits (63-60) set.  */
    230      1.8  christos 
    231      1.8  christos static CORE_ADDR
    232      1.8  christos adi_normalize_address (CORE_ADDR addr)
    233      1.8  christos {
    234      1.8  christos   adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
    235      1.8  christos 
    236      1.8  christos   if (ast.nbits)
    237      1.8  christos     {
    238      1.8  christos       /* Clear upper bits.  */
    239      1.8  christos       addr &= ((uint64_t) -1) >> ast.nbits;
    240      1.8  christos 
    241      1.8  christos       /* Sign extend.  */
    242      1.8  christos       CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
    243      1.8  christos       return (addr ^ signbit) - signbit;
    244      1.8  christos     }
    245      1.8  christos   return addr;
    246      1.8  christos }
    247      1.8  christos 
    248      1.8  christos /* Align a normalized address - a VA with bit 59 sign extended into
    249      1.8  christos    ADI bits.  */
    250      1.8  christos 
    251      1.8  christos static CORE_ADDR
    252      1.8  christos adi_align_address (CORE_ADDR naddr)
    253      1.8  christos {
    254      1.8  christos   adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
    255      1.8  christos 
    256      1.8  christos   return (naddr - (naddr % ast.blksize)) / ast.blksize;
    257      1.8  christos }
    258      1.8  christos 
    259      1.8  christos /* Convert a byte count to count at a ratio of 1:adi_blksz.  */
    260      1.8  christos 
    261      1.8  christos static int
    262      1.8  christos adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl)
    263      1.8  christos {
    264      1.8  christos   adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
    265      1.8  christos 
    266      1.8  christos   return ((naddr + nbytes + ast.blksize - 1) / ast.blksize) - locl;
    267      1.8  christos }
    268      1.8  christos 
    269      1.8  christos /* The /proc/[pid]/adi/tags file, which allows gdb to get/set ADI
    270      1.8  christos    version in a target process, maps linearly to the address space
    271      1.8  christos    of the target process at a ratio of 1:adi_blksz.
    272      1.8  christos 
    273      1.8  christos    A read (or write) at offset K in the file returns (or modifies)
    274      1.8  christos    the ADI version tag stored in the cacheline containing address
    275      1.8  christos    K * adi_blksz, encoded as 1 version tag per byte.  The allowed
    276      1.8  christos    version tag values are between 0 and adi_stat.max_version.  */
    277      1.8  christos 
    278      1.8  christos static int
    279      1.8  christos adi_tag_fd (void)
    280      1.8  christos {
    281      1.8  christos   pid_t pid = inferior_ptid.pid ();
    282      1.8  christos   sparc64_adi_info *proc = get_adi_info_proc (pid);
    283      1.8  christos 
    284      1.8  christos   if (proc->stat.tag_fd != 0)
    285      1.8  christos     return proc->stat.tag_fd;
    286      1.8  christos 
    287      1.8  christos   char cl_name[MAX_PROC_NAME_SIZE];
    288  1.9.2.1  perseant   snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid);
    289      1.8  christos   fileio_error target_errno;
    290  1.9.2.1  perseant   proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL,
    291      1.8  christos 					  false, 0, &target_errno);
    292      1.8  christos   return proc->stat.tag_fd;
    293      1.8  christos }
    294      1.8  christos 
    295      1.8  christos /* Check if an address set is ADI enabled, using /proc/[pid]/adi/maps
    296      1.8  christos    which was exported by the kernel and contains the currently ADI
    297      1.8  christos    mapped memory regions and their access permissions.  */
    298      1.8  christos 
    299      1.8  christos static bool
    300      1.8  christos adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt)
    301      1.8  christos {
    302      1.8  christos   char filename[MAX_PROC_NAME_SIZE];
    303      1.8  christos   size_t i = 0;
    304      1.8  christos 
    305      1.8  christos   pid_t pid = inferior_ptid.pid ();
    306      1.8  christos   snprintf (filename, sizeof filename, "/proc/%ld/adi/maps", (long) pid);
    307      1.8  christos   gdb::unique_xmalloc_ptr<char> data
    308      1.8  christos     = target_fileio_read_stralloc (NULL, filename);
    309      1.8  christos   if (data)
    310      1.8  christos     {
    311      1.9  christos       adi_stat_t adi_stat = get_adi_info (pid);
    312      1.9  christos       char *saveptr;
    313      1.9  christos       for (char *line = strtok_r (data.get (), "\n", &saveptr);
    314      1.9  christos 	   line;
    315  1.9.2.1  perseant 	   line = strtok_r (NULL, "\n", &saveptr))
    316  1.9.2.1  perseant 	{
    317      1.8  christos 	  ULONGEST addr, endaddr;
    318  1.9.2.1  perseant 
    319      1.8  christos 	  read_maps_entry (line, &addr, &endaddr);
    320  1.9.2.1  perseant 
    321  1.9.2.1  perseant 	  while (((vaddr + i) * adi_stat.blksize) >= addr
    322  1.9.2.1  perseant 		 && ((vaddr + i) * adi_stat.blksize) < endaddr)
    323  1.9.2.1  perseant 	    {
    324      1.8  christos 	      if (++i == cnt)
    325  1.9.2.1  perseant 		return true;
    326  1.9.2.1  perseant 	    }
    327      1.8  christos 	}
    328  1.9.2.1  perseant       }
    329  1.9.2.1  perseant   else
    330      1.8  christos     warning (_("unable to open /proc file '%s'"), filename);
    331      1.8  christos 
    332      1.8  christos   return false;
    333      1.8  christos }
    334      1.8  christos 
    335      1.8  christos /* Read ADI version tag value for memory locations starting at "VADDR"
    336      1.8  christos    for "SIZE" number of bytes.  */
    337      1.8  christos 
    338      1.8  christos static int
    339      1.8  christos adi_read_versions (CORE_ADDR vaddr, size_t size, gdb_byte *tags)
    340      1.8  christos {
    341      1.8  christos   int fd = adi_tag_fd ();
    342      1.8  christos   if (fd == -1)
    343      1.8  christos     return -1;
    344      1.8  christos 
    345      1.8  christos   if (!adi_is_addr_mapped (vaddr, size))
    346      1.8  christos     {
    347      1.8  christos       adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
    348  1.9.2.1  perseant       error(_("Address at %s is not in ADI maps"),
    349      1.8  christos 	    paddress (target_gdbarch (), vaddr * ast.blksize));
    350      1.8  christos     }
    351  1.9.2.1  perseant 
    352      1.8  christos   fileio_error target_errno;
    353      1.8  christos   return target_fileio_pread (fd, tags, size, vaddr, &target_errno);
    354      1.8  christos }
    355      1.8  christos 
    356      1.8  christos /* Write ADI version tag for memory locations starting at "VADDR" for
    357      1.8  christos  "SIZE" number of bytes to "TAGS".  */
    358      1.8  christos 
    359      1.8  christos static int
    360      1.8  christos adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
    361      1.8  christos {
    362      1.8  christos   int fd = adi_tag_fd ();
    363      1.8  christos   if (fd == -1)
    364      1.8  christos     return -1;
    365      1.8  christos 
    366      1.8  christos   if (!adi_is_addr_mapped (vaddr, size))
    367      1.8  christos     {
    368      1.8  christos       adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
    369  1.9.2.1  perseant       error(_("Address at %s is not in ADI maps"),
    370      1.8  christos 	    paddress (target_gdbarch (), vaddr * ast.blksize));
    371      1.8  christos     }
    372  1.9.2.1  perseant 
    373      1.8  christos   fileio_error target_errno;
    374      1.8  christos   return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno);
    375      1.8  christos }
    376      1.8  christos 
    377      1.8  christos /* Print ADI version tag value in "TAGS" for memory locations starting
    378      1.8  christos    at "VADDR" with number of "CNT".  */
    379      1.8  christos 
    380      1.8  christos static void
    381      1.8  christos adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
    382      1.8  christos {
    383      1.8  christos   int v_idx = 0;
    384      1.8  christos   const int maxelts = 8;  /* # of elements per line */
    385      1.8  christos 
    386      1.8  christos   adi_stat_t adi_stat = get_adi_info (inferior_ptid.pid ());
    387      1.8  christos 
    388      1.8  christos   while (cnt > 0)
    389      1.8  christos     {
    390  1.9.2.1  perseant       QUIT;
    391  1.9.2.1  perseant       gdb_printf ("%s:\t",
    392      1.8  christos 		  paddress (target_gdbarch (), vaddr * adi_stat.blksize));
    393  1.9.2.1  perseant       for (int i = maxelts; i > 0 && cnt > 0; i--, cnt--)
    394  1.9.2.1  perseant 	{
    395  1.9.2.1  perseant 	  if (tags[v_idx] == 0xff)    /* no version tag */
    396  1.9.2.1  perseant 	    gdb_printf ("-");
    397  1.9.2.1  perseant 	  else
    398      1.8  christos 	    gdb_printf ("%1X", tags[v_idx]);
    399  1.9.2.1  perseant 	  if (cnt > 1)
    400  1.9.2.1  perseant 	    gdb_printf (" ");
    401  1.9.2.1  perseant 	  ++v_idx;
    402  1.9.2.1  perseant 	}
    403      1.8  christos       gdb_printf ("\n");
    404      1.8  christos       vaddr += maxelts;
    405      1.8  christos     }
    406      1.8  christos }
    407      1.8  christos 
    408      1.8  christos static void
    409      1.8  christos do_examine (CORE_ADDR start, int bcnt)
    410      1.8  christos {
    411      1.8  christos   CORE_ADDR vaddr = adi_normalize_address (start);
    412      1.8  christos 
    413      1.8  christos   CORE_ADDR vstart = adi_align_address (vaddr);
    414      1.8  christos   int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
    415      1.8  christos   gdb::def_vector<gdb_byte> buf (cnt);
    416      1.8  christos   int read_cnt = adi_read_versions (vstart, cnt, buf.data ());
    417      1.8  christos   if (read_cnt == -1)
    418      1.8  christos     error (_("No ADI information"));
    419      1.8  christos   else if (read_cnt < cnt)
    420      1.8  christos     error(_("No ADI information at %s"), paddress (target_gdbarch (), vaddr));
    421      1.8  christos 
    422      1.8  christos   adi_print_versions (vstart, cnt, buf.data ());
    423      1.8  christos }
    424      1.8  christos 
    425      1.8  christos static void
    426      1.8  christos do_assign (CORE_ADDR start, size_t bcnt, int version)
    427      1.8  christos {
    428      1.8  christos   CORE_ADDR vaddr = adi_normalize_address (start);
    429      1.8  christos 
    430      1.8  christos   CORE_ADDR vstart = adi_align_address (vaddr);
    431      1.8  christos   int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
    432      1.8  christos   std::vector<unsigned char> buf (cnt, version);
    433      1.8  christos   int set_cnt = adi_write_versions (vstart, cnt, buf.data ());
    434      1.8  christos 
    435      1.8  christos   if (set_cnt == -1)
    436      1.8  christos     error (_("No ADI information"));
    437      1.8  christos   else if (set_cnt < cnt)
    438      1.8  christos     error(_("No ADI information at %s"), paddress (target_gdbarch (), vaddr));
    439      1.8  christos 
    440      1.8  christos }
    441      1.8  christos 
    442      1.8  christos /* ADI examine version tag command.
    443      1.8  christos 
    444      1.8  christos    Command syntax:
    445      1.8  christos 
    446      1.8  christos      adi (examine|x)[/COUNT] [ADDR] */
    447      1.8  christos 
    448      1.8  christos static void
    449      1.8  christos adi_examine_command (const char *args, int from_tty)
    450      1.8  christos {
    451  1.9.2.1  perseant   /* make sure program is active and adi is available */
    452      1.8  christos   if (!target_has_execution ())
    453      1.8  christos     error (_("ADI command requires a live process/thread"));
    454      1.8  christos 
    455      1.8  christos   if (!adi_available ())
    456      1.8  christos     error (_("No ADI information"));
    457      1.8  christos 
    458      1.8  christos   int cnt = 1;
    459      1.8  christos   const char *p = args;
    460      1.8  christos   if (p && *p == '/')
    461      1.8  christos     {
    462      1.8  christos       p++;
    463      1.8  christos       cnt = get_number (&p);
    464      1.8  christos     }
    465      1.8  christos 
    466      1.8  christos   CORE_ADDR next_address = 0;
    467      1.8  christos   if (p != 0 && *p != 0)
    468      1.8  christos     next_address = parse_and_eval_address (p);
    469      1.8  christos   if (!cnt || !next_address)
    470      1.8  christos     error (_("Usage: adi examine|x[/COUNT] [ADDR]"));
    471      1.8  christos 
    472      1.8  christos   do_examine (next_address, cnt);
    473      1.8  christos }
    474      1.8  christos 
    475      1.8  christos /* ADI assign version tag command.
    476      1.8  christos 
    477      1.8  christos    Command syntax:
    478      1.8  christos 
    479      1.8  christos      adi (assign|a)[/COUNT] ADDR = VERSION  */
    480      1.8  christos 
    481      1.8  christos static void
    482      1.8  christos adi_assign_command (const char *args, int from_tty)
    483      1.8  christos {
    484      1.8  christos   static const char *adi_usage
    485      1.8  christos     = N_("Usage: adi assign|a[/COUNT] ADDR = VERSION");
    486      1.8  christos 
    487  1.9.2.1  perseant   /* make sure program is active and adi is available */
    488      1.8  christos   if (!target_has_execution ())
    489      1.8  christos     error (_("ADI command requires a live process/thread"));
    490      1.8  christos 
    491      1.8  christos   if (!adi_available ())
    492      1.8  christos     error (_("No ADI information"));
    493      1.8  christos 
    494      1.8  christos   const char *exp = args;
    495      1.8  christos   if (exp == 0)
    496      1.8  christos     error_no_arg (_(adi_usage));
    497      1.8  christos 
    498      1.8  christos   char *q = (char *) strchr (exp, '=');
    499      1.8  christos   if (q)
    500      1.8  christos     *q++ = 0;
    501      1.8  christos   else
    502      1.8  christos     error ("%s", _(adi_usage));
    503      1.8  christos 
    504      1.8  christos   size_t cnt = 1;
    505      1.8  christos   const char *p = args;
    506      1.8  christos   if (exp && *exp == '/')
    507      1.8  christos     {
    508      1.8  christos       p = exp + 1;
    509      1.8  christos       cnt = get_number (&p);
    510      1.8  christos     }
    511      1.8  christos 
    512      1.8  christos   CORE_ADDR next_address = 0;
    513      1.8  christos   if (p != 0 && *p != 0)
    514      1.8  christos     next_address = parse_and_eval_address (p);
    515      1.8  christos   else
    516      1.8  christos     error ("%s", _(adi_usage));
    517      1.8  christos 
    518      1.8  christos   int version = 0;
    519      1.8  christos   if (q != NULL)           /* parse version tag */
    520      1.8  christos     {
    521      1.8  christos       adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
    522      1.8  christos       version = parse_and_eval_long (q);
    523  1.9.2.1  perseant       if (version < 0 || version > ast.max_version)
    524      1.8  christos 	error (_("Invalid ADI version tag %d"), version);
    525      1.8  christos     }
    526      1.8  christos 
    527      1.8  christos   do_assign (next_address, cnt, version);
    528      1.8  christos }
    529      1.9  christos 
    530      1.8  christos void _initialize_sparc64_adi_tdep ();
    531      1.9  christos void
    532      1.8  christos _initialize_sparc64_adi_tdep ()
    533      1.9  christos {
    534      1.9  christos   add_basic_prefix_cmd ("adi", class_support,
    535  1.9.2.1  perseant 			_("ADI version related commands."),
    536  1.9.2.1  perseant 			&sparc64adilist, 0, &cmdlist);
    537  1.9.2.1  perseant   cmd_list_element *adi_examine_cmd
    538  1.9.2.1  perseant     = add_cmd ("examine", class_support, adi_examine_command,
    539  1.9.2.1  perseant 	       _("Examine ADI versions."), &sparc64adilist);
    540      1.8  christos   add_alias_cmd ("x", adi_examine_cmd, no_class, 1, &sparc64adilist);
    541  1.9.2.1  perseant   add_cmd ("assign", class_support, adi_assign_command,
    542      1.8  christos 	   _("Assign ADI versions."), &sparc64adilist);
    543      1.8  christos 
    544      1.8  christos }
    545      1.8  christos 
    546      1.1  christos 
    548      1.1  christos /* The functions on this page are intended to be used to classify
    549      1.1  christos    function arguments.  */
    550      1.1  christos 
    551      1.1  christos /* Check whether TYPE is "Integral or Pointer".  */
    552      1.1  christos 
    553      1.1  christos static int
    554      1.9  christos sparc64_integral_or_pointer_p (const struct type *type)
    555      1.1  christos {
    556      1.1  christos   switch (type->code ())
    557      1.1  christos     {
    558      1.1  christos     case TYPE_CODE_INT:
    559      1.1  christos     case TYPE_CODE_BOOL:
    560      1.1  christos     case TYPE_CODE_CHAR:
    561      1.1  christos     case TYPE_CODE_ENUM:
    562  1.9.2.1  perseant     case TYPE_CODE_RANGE:
    563      1.1  christos       {
    564      1.1  christos 	int len = type->length ();
    565      1.1  christos 	gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
    566      1.1  christos       }
    567      1.1  christos       return 1;
    568      1.7  christos     case TYPE_CODE_PTR:
    569      1.1  christos     case TYPE_CODE_REF:
    570  1.9.2.1  perseant     case TYPE_CODE_RVALUE_REF:
    571      1.1  christos       {
    572      1.1  christos 	int len = type->length ();
    573      1.1  christos 	gdb_assert (len == 8);
    574      1.1  christos       }
    575      1.1  christos       return 1;
    576      1.1  christos     default:
    577      1.1  christos       break;
    578      1.1  christos     }
    579      1.1  christos 
    580      1.1  christos   return 0;
    581      1.1  christos }
    582      1.1  christos 
    583      1.1  christos /* Check whether TYPE is "Floating".  */
    584      1.1  christos 
    585      1.1  christos static int
    586      1.9  christos sparc64_floating_p (const struct type *type)
    587      1.1  christos {
    588      1.1  christos   switch (type->code ())
    589      1.1  christos     {
    590  1.9.2.1  perseant     case TYPE_CODE_FLT:
    591      1.1  christos       {
    592      1.1  christos 	int len = type->length ();
    593      1.1  christos 	gdb_assert (len == 4 || len == 8 || len == 16);
    594      1.1  christos       }
    595      1.1  christos       return 1;
    596      1.1  christos     default:
    597      1.1  christos       break;
    598      1.1  christos     }
    599      1.1  christos 
    600      1.1  christos   return 0;
    601      1.1  christos }
    602      1.1  christos 
    603      1.1  christos /* Check whether TYPE is "Complex Floating".  */
    604      1.1  christos 
    605      1.1  christos static int
    606      1.9  christos sparc64_complex_floating_p (const struct type *type)
    607      1.1  christos {
    608      1.1  christos   switch (type->code ())
    609      1.1  christos     {
    610  1.9.2.1  perseant     case TYPE_CODE_COMPLEX:
    611      1.1  christos       {
    612      1.1  christos 	int len = type->length ();
    613      1.1  christos 	gdb_assert (len == 8 || len == 16 || len == 32);
    614      1.1  christos       }
    615      1.1  christos       return 1;
    616      1.1  christos     default:
    617      1.1  christos       break;
    618      1.1  christos     }
    619      1.1  christos 
    620      1.1  christos   return 0;
    621      1.1  christos }
    622      1.1  christos 
    623      1.1  christos /* Check whether TYPE is "Structure or Union".
    624      1.1  christos 
    625      1.1  christos    In terms of Ada subprogram calls, arrays are treated the same as
    626      1.1  christos    struct and union types.  So this function also returns non-zero
    627      1.1  christos    for array types.  */
    628      1.1  christos 
    629      1.1  christos static int
    630      1.9  christos sparc64_structure_or_union_p (const struct type *type)
    631      1.1  christos {
    632      1.1  christos   switch (type->code ())
    633      1.1  christos     {
    634      1.1  christos     case TYPE_CODE_STRUCT:
    635      1.1  christos     case TYPE_CODE_UNION:
    636      1.1  christos     case TYPE_CODE_ARRAY:
    637      1.1  christos       return 1;
    638      1.1  christos     default:
    639      1.1  christos       break;
    640      1.1  christos     }
    641      1.1  christos 
    642      1.1  christos   return 0;
    643      1.1  christos }
    644      1.1  christos 
    645      1.1  christos 
    647      1.1  christos /* Construct types for ISA-specific registers.  */
    648      1.1  christos 
    649  1.9.2.1  perseant static struct type *
    650      1.1  christos sparc64_pstate_type (struct gdbarch *gdbarch)
    651      1.1  christos {
    652      1.1  christos   sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
    653      1.1  christos 
    654      1.1  christos   if (!tdep->sparc64_pstate_type)
    655      1.8  christos     {
    656      1.1  christos       struct type *type;
    657      1.1  christos 
    658      1.1  christos       type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 64);
    659      1.1  christos       append_flags_type_flag (type, 0, "AG");
    660      1.1  christos       append_flags_type_flag (type, 1, "IE");
    661      1.1  christos       append_flags_type_flag (type, 2, "PRIV");
    662      1.1  christos       append_flags_type_flag (type, 3, "AM");
    663      1.1  christos       append_flags_type_flag (type, 4, "PEF");
    664      1.1  christos       append_flags_type_flag (type, 5, "RED");
    665      1.1  christos       append_flags_type_flag (type, 8, "TLE");
    666      1.1  christos       append_flags_type_flag (type, 9, "CLE");
    667      1.1  christos       append_flags_type_flag (type, 10, "PID0");
    668      1.1  christos       append_flags_type_flag (type, 11, "PID1");
    669      1.1  christos 
    670      1.1  christos       tdep->sparc64_pstate_type = type;
    671      1.1  christos     }
    672      1.1  christos 
    673      1.1  christos   return tdep->sparc64_pstate_type;
    674      1.7  christos }
    675      1.7  christos 
    676  1.9.2.1  perseant static struct type *
    677      1.7  christos sparc64_ccr_type (struct gdbarch *gdbarch)
    678      1.7  christos {
    679      1.7  christos   sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
    680      1.7  christos 
    681      1.7  christos   if (tdep->sparc64_ccr_type == NULL)
    682      1.8  christos     {
    683      1.7  christos       struct type *type;
    684      1.7  christos 
    685      1.7  christos       type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 64);
    686      1.7  christos       append_flags_type_flag (type, 0, "icc.c");
    687      1.7  christos       append_flags_type_flag (type, 1, "icc.v");
    688      1.7  christos       append_flags_type_flag (type, 2, "icc.z");
    689      1.7  christos       append_flags_type_flag (type, 3, "icc.n");
    690      1.7  christos       append_flags_type_flag (type, 4, "xcc.c");
    691      1.7  christos       append_flags_type_flag (type, 5, "xcc.v");
    692      1.7  christos       append_flags_type_flag (type, 6, "xcc.z");
    693      1.7  christos       append_flags_type_flag (type, 7, "xcc.n");
    694      1.7  christos 
    695      1.7  christos       tdep->sparc64_ccr_type = type;
    696      1.7  christos     }
    697      1.7  christos 
    698      1.7  christos   return tdep->sparc64_ccr_type;
    699      1.1  christos }
    700      1.1  christos 
    701  1.9.2.1  perseant static struct type *
    702      1.1  christos sparc64_fsr_type (struct gdbarch *gdbarch)
    703      1.1  christos {
    704      1.1  christos   sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
    705      1.1  christos 
    706      1.1  christos   if (!tdep->sparc64_fsr_type)
    707      1.8  christos     {
    708      1.7  christos       struct type *type;
    709      1.7  christos 
    710      1.7  christos       type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 64);
    711      1.7  christos       append_flags_type_flag (type, 0, "NXC");
    712      1.7  christos       append_flags_type_flag (type, 1, "DZC");
    713      1.7  christos       append_flags_type_flag (type, 2, "UFC");
    714      1.7  christos       append_flags_type_flag (type, 3, "OFC");
    715      1.7  christos       append_flags_type_flag (type, 4, "NVC");
    716      1.7  christos       append_flags_type_flag (type, 5, "NXA");
    717      1.7  christos       append_flags_type_flag (type, 6, "DZA");
    718      1.1  christos       append_flags_type_flag (type, 7, "UFA");
    719      1.1  christos       append_flags_type_flag (type, 8, "OFA");
    720      1.1  christos       append_flags_type_flag (type, 9, "NVA");
    721      1.1  christos       append_flags_type_flag (type, 22, "NS");
    722      1.1  christos       append_flags_type_flag (type, 23, "NXM");
    723      1.1  christos       append_flags_type_flag (type, 24, "DZM");
    724      1.1  christos       append_flags_type_flag (type, 25, "UFM");
    725      1.1  christos       append_flags_type_flag (type, 26, "OFM");
    726      1.1  christos       append_flags_type_flag (type, 27, "NVM");
    727      1.1  christos 
    728      1.1  christos       tdep->sparc64_fsr_type = type;
    729      1.1  christos     }
    730      1.1  christos 
    731      1.1  christos   return tdep->sparc64_fsr_type;
    732      1.1  christos }
    733      1.1  christos 
    734  1.9.2.1  perseant static struct type *
    735      1.1  christos sparc64_fprs_type (struct gdbarch *gdbarch)
    736      1.1  christos {
    737      1.1  christos   sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
    738      1.1  christos 
    739      1.1  christos   if (!tdep->sparc64_fprs_type)
    740      1.8  christos     {
    741      1.1  christos       struct type *type;
    742      1.1  christos 
    743      1.1  christos       type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 64);
    744      1.1  christos       append_flags_type_flag (type, 0, "DL");
    745      1.1  christos       append_flags_type_flag (type, 1, "DU");
    746      1.1  christos       append_flags_type_flag (type, 2, "FEF");
    747      1.1  christos 
    748      1.1  christos       tdep->sparc64_fprs_type = type;
    749      1.1  christos     }
    750      1.1  christos 
    751      1.1  christos   return tdep->sparc64_fprs_type;
    752      1.1  christos }
    753      1.7  christos 
    754      1.7  christos 
    755      1.7  christos /* Register information.  */
    756      1.7  christos #define SPARC64_FPU_REGISTERS                             \
    757      1.7  christos   "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",         \
    758      1.7  christos   "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",   \
    759      1.7  christos   "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
    760      1.7  christos   "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
    761      1.7  christos   "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
    762      1.7  christos   "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62"
    763      1.7  christos #define SPARC64_CP0_REGISTERS                                             \
    764      1.7  christos   "pc", "npc",                                                            \
    765      1.7  christos   /* FIXME: Give "state" a name until we start using register groups.  */ \
    766      1.7  christos   "state",                                                                \
    767      1.7  christos   "fsr",                                                                  \
    768  1.9.2.1  perseant   "fprs",                                                                 \
    769  1.9.2.1  perseant   "y"
    770  1.9.2.1  perseant 
    771  1.9.2.1  perseant static const char * const sparc64_fpu_register_names[] = {
    772  1.9.2.1  perseant   SPARC64_FPU_REGISTERS
    773  1.9.2.1  perseant };
    774      1.1  christos static const char * const sparc64_cp0_register_names[] = {
    775  1.9.2.1  perseant   SPARC64_CP0_REGISTERS
    776      1.1  christos };
    777      1.7  christos 
    778      1.7  christos static const char * const sparc64_register_names[] =
    779      1.7  christos {
    780      1.1  christos   SPARC_CORE_REGISTERS,
    781      1.1  christos   SPARC64_FPU_REGISTERS,
    782      1.1  christos   SPARC64_CP0_REGISTERS
    783      1.1  christos };
    784      1.1  christos 
    785      1.1  christos /* Total number of registers.  */
    786      1.1  christos #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
    787      1.1  christos 
    788  1.9.2.1  perseant /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
    789      1.1  christos    registers as "psuedo" registers.  */
    790      1.1  christos 
    791      1.1  christos static const char * const sparc64_pseudo_register_names[] =
    792      1.1  christos {
    793      1.1  christos   "cwp", "pstate", "asi", "ccr",
    794      1.1  christos 
    795      1.1  christos   "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
    796      1.1  christos   "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
    797      1.1  christos   "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
    798      1.1  christos   "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
    799      1.1  christos 
    800      1.1  christos   "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
    801      1.1  christos   "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
    802      1.1  christos };
    803      1.1  christos 
    804      1.7  christos /* Total number of pseudo registers.  */
    805      1.7  christos #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
    806      1.7  christos 
    807      1.7  christos /* Return the name of pseudo register REGNUM.  */
    808      1.7  christos 
    809      1.7  christos static const char *
    810      1.7  christos sparc64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
    811  1.9.2.1  perseant {
    812  1.9.2.1  perseant   regnum -= gdbarch_num_regs (gdbarch);
    813      1.7  christos 
    814      1.7  christos   gdb_assert (regnum < SPARC64_NUM_PSEUDO_REGS);
    815      1.1  christos   return sparc64_pseudo_register_names[regnum];
    816      1.1  christos }
    817      1.1  christos 
    818      1.1  christos /* Return the name of register REGNUM.  */
    819      1.1  christos 
    820      1.7  christos static const char *
    821      1.7  christos sparc64_register_name (struct gdbarch *gdbarch, int regnum)
    822      1.7  christos {
    823      1.7  christos   if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
    824      1.1  christos     return tdesc_register_name (gdbarch, regnum);
    825      1.1  christos 
    826      1.7  christos   if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
    827      1.7  christos     return sparc64_register_names[regnum];
    828      1.7  christos 
    829      1.7  christos   return sparc64_pseudo_register_name (gdbarch, regnum);
    830      1.7  christos }
    831      1.7  christos 
    832      1.7  christos /* Return the GDB type object for the "standard" data type of data in
    833      1.7  christos    pseudo register REGNUM.  */
    834      1.7  christos 
    835      1.7  christos static struct type *
    836      1.1  christos sparc64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
    837      1.7  christos {
    838      1.7  christos   regnum -= gdbarch_num_regs (gdbarch);
    839      1.7  christos 
    840      1.7  christos   if (regnum == SPARC64_CWP_REGNUM)
    841      1.7  christos     return builtin_type (gdbarch)->builtin_int64;
    842      1.7  christos   if (regnum == SPARC64_PSTATE_REGNUM)
    843      1.7  christos     return sparc64_pstate_type (gdbarch);
    844      1.7  christos   if (regnum == SPARC64_ASI_REGNUM)
    845      1.7  christos     return builtin_type (gdbarch)->builtin_int64;
    846      1.7  christos   if (regnum == SPARC64_CCR_REGNUM)
    847      1.7  christos     return sparc64_ccr_type (gdbarch);
    848      1.7  christos   if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM)
    849      1.7  christos     return builtin_type (gdbarch)->builtin_double;
    850  1.9.2.1  perseant   if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM)
    851  1.9.2.1  perseant     return builtin_type (gdbarch)->builtin_long_double;
    852      1.1  christos 
    853      1.1  christos   internal_error (_("sparc64_pseudo_register_type: bad register number %d"),
    854      1.1  christos 		  regnum);
    855      1.1  christos }
    856      1.1  christos 
    857      1.1  christos /* Return the GDB type object for the "standard" data type of data in
    858      1.1  christos    register REGNUM.  */
    859      1.1  christos 
    860      1.7  christos static struct type *
    861      1.7  christos sparc64_register_type (struct gdbarch *gdbarch, int regnum)
    862      1.7  christos {
    863      1.1  christos   if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
    864      1.1  christos     return tdesc_register_type (gdbarch, regnum);
    865      1.1  christos 
    866      1.1  christos   /* Raw registers.  */
    867      1.1  christos   if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
    868      1.1  christos     return builtin_type (gdbarch)->builtin_data_ptr;
    869      1.1  christos   if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM)
    870      1.1  christos     return builtin_type (gdbarch)->builtin_int64;
    871      1.1  christos   if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
    872      1.1  christos     return builtin_type (gdbarch)->builtin_float;
    873      1.1  christos   if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)
    874      1.1  christos     return builtin_type (gdbarch)->builtin_double;
    875      1.1  christos   if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
    876      1.1  christos     return builtin_type (gdbarch)->builtin_func_ptr;
    877      1.1  christos   /* This raw register contains the contents of %cwp, %pstate, %asi
    878      1.1  christos      and %ccr as laid out in a %tstate register.  */
    879      1.1  christos   if (regnum == SPARC64_STATE_REGNUM)
    880      1.1  christos     return builtin_type (gdbarch)->builtin_int64;
    881      1.1  christos   if (regnum == SPARC64_FSR_REGNUM)
    882      1.1  christos     return sparc64_fsr_type (gdbarch);
    883      1.1  christos   if (regnum == SPARC64_FPRS_REGNUM)
    884      1.1  christos     return sparc64_fprs_type (gdbarch);
    885      1.1  christos   /* "Although Y is a 64-bit register, its high-order 32 bits are
    886      1.1  christos      reserved and always read as 0."  */
    887      1.1  christos   if (regnum == SPARC64_Y_REGNUM)
    888      1.7  christos     return builtin_type (gdbarch)->builtin_int64;
    889      1.7  christos 
    890      1.1  christos   /* Pseudo registers.  */
    891  1.9.2.1  perseant   if (regnum >= gdbarch_num_regs (gdbarch))
    892      1.1  christos     return sparc64_pseudo_register_type (gdbarch, regnum);
    893      1.1  christos 
    894      1.1  christos   internal_error (_("invalid regnum"));
    895      1.1  christos }
    896      1.8  christos 
    897      1.1  christos static enum register_status
    898      1.1  christos sparc64_pseudo_register_read (struct gdbarch *gdbarch,
    899      1.1  christos 			      readable_regcache *regcache,
    900      1.1  christos 			      int regnum, gdb_byte *buf)
    901      1.1  christos {
    902      1.7  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    903      1.1  christos   enum register_status status;
    904      1.1  christos 
    905      1.1  christos   regnum -= gdbarch_num_regs (gdbarch);
    906      1.1  christos 
    907      1.8  christos   if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
    908      1.1  christos     {
    909      1.8  christos       regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
    910      1.1  christos       status = regcache->raw_read (regnum, buf);
    911      1.1  christos       if (status == REG_VALID)
    912      1.1  christos 	status = regcache->raw_read (regnum + 1, buf + 4);
    913      1.1  christos       return status;
    914      1.1  christos     }
    915      1.8  christos   else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
    916      1.1  christos     {
    917      1.1  christos       regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
    918      1.1  christos       return regcache->raw_read (regnum, buf);
    919      1.1  christos     }
    920      1.1  christos   else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
    921      1.8  christos     {
    922      1.1  christos       regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
    923      1.8  christos 
    924      1.1  christos       status = regcache->raw_read (regnum, buf);
    925      1.8  christos       if (status == REG_VALID)
    926      1.1  christos 	status = regcache->raw_read (regnum + 1, buf + 4);
    927      1.8  christos       if (status == REG_VALID)
    928      1.1  christos 	status = regcache->raw_read (regnum + 2, buf + 8);
    929      1.1  christos       if (status == REG_VALID)
    930      1.1  christos 	status = regcache->raw_read (regnum + 3, buf + 12);
    931      1.1  christos 
    932      1.1  christos       return status;
    933      1.1  christos     }
    934      1.1  christos   else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
    935      1.8  christos     {
    936      1.1  christos       regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
    937      1.8  christos 
    938      1.1  christos       status = regcache->raw_read (regnum, buf);
    939      1.1  christos       if (status == REG_VALID)
    940      1.1  christos 	status = regcache->raw_read (regnum + 1, buf + 8);
    941      1.1  christos 
    942      1.1  christos       return status;
    943      1.1  christos     }
    944      1.1  christos   else if (regnum == SPARC64_CWP_REGNUM
    945      1.1  christos 	   || regnum == SPARC64_PSTATE_REGNUM
    946      1.1  christos 	   || regnum == SPARC64_ASI_REGNUM
    947      1.1  christos 	   || regnum == SPARC64_CCR_REGNUM)
    948      1.8  christos     {
    949      1.1  christos       ULONGEST state;
    950      1.1  christos 
    951      1.1  christos       status = regcache->raw_read (SPARC64_STATE_REGNUM, &state);
    952      1.1  christos       if (status != REG_VALID)
    953      1.1  christos 	return status;
    954      1.1  christos 
    955      1.1  christos       switch (regnum)
    956      1.1  christos 	{
    957      1.1  christos 	case SPARC64_CWP_REGNUM:
    958      1.1  christos 	  state = (state >> 0) & ((1 << 5) - 1);
    959      1.1  christos 	  break;
    960      1.1  christos 	case SPARC64_PSTATE_REGNUM:
    961      1.1  christos 	  state = (state >> 8) & ((1 << 12) - 1);
    962      1.1  christos 	  break;
    963      1.1  christos 	case SPARC64_ASI_REGNUM:
    964      1.1  christos 	  state = (state >> 24) & ((1 << 8) - 1);
    965      1.1  christos 	  break;
    966      1.1  christos 	case SPARC64_CCR_REGNUM:
    967      1.1  christos 	  state = (state >> 32) & ((1 << 8) - 1);
    968      1.1  christos 	  break;
    969      1.1  christos 	}
    970      1.1  christos       store_unsigned_integer (buf, 8, byte_order, state);
    971      1.1  christos     }
    972      1.1  christos 
    973      1.1  christos   return REG_VALID;
    974      1.1  christos }
    975      1.1  christos 
    976      1.1  christos static void
    977      1.1  christos sparc64_pseudo_register_write (struct gdbarch *gdbarch,
    978      1.1  christos 			       struct regcache *regcache,
    979      1.7  christos 			       int regnum, const gdb_byte *buf)
    980      1.7  christos {
    981      1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    982      1.1  christos 
    983      1.1  christos   regnum -= gdbarch_num_regs (gdbarch);
    984      1.1  christos 
    985      1.8  christos   if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
    986      1.8  christos     {
    987      1.1  christos       regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
    988      1.1  christos       regcache->raw_write (regnum, buf);
    989      1.1  christos       regcache->raw_write (regnum + 1, buf + 4);
    990      1.1  christos     }
    991      1.8  christos   else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
    992      1.1  christos     {
    993      1.1  christos       regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
    994      1.1  christos       regcache->raw_write (regnum, buf);
    995      1.1  christos     }
    996      1.8  christos   else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
    997      1.8  christos     {
    998      1.8  christos       regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
    999      1.8  christos       regcache->raw_write (regnum, buf);
   1000      1.1  christos       regcache->raw_write (regnum + 1, buf + 4);
   1001      1.1  christos       regcache->raw_write (regnum + 2, buf + 8);
   1002      1.1  christos       regcache->raw_write (regnum + 3, buf + 12);
   1003      1.1  christos     }
   1004      1.8  christos   else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
   1005      1.8  christos     {
   1006      1.1  christos       regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
   1007      1.1  christos       regcache->raw_write (regnum, buf);
   1008      1.1  christos       regcache->raw_write (regnum + 1, buf + 8);
   1009      1.1  christos     }
   1010      1.1  christos   else if (regnum == SPARC64_CWP_REGNUM
   1011      1.1  christos 	   || regnum == SPARC64_PSTATE_REGNUM
   1012      1.1  christos 	   || regnum == SPARC64_ASI_REGNUM
   1013      1.1  christos 	   || regnum == SPARC64_CCR_REGNUM)
   1014      1.1  christos     {
   1015      1.1  christos       ULONGEST state, bits;
   1016      1.1  christos 
   1017      1.1  christos       regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
   1018      1.1  christos       bits = extract_unsigned_integer (buf, 8, byte_order);
   1019      1.1  christos       switch (regnum)
   1020      1.1  christos 	{
   1021      1.1  christos 	case SPARC64_CWP_REGNUM:
   1022      1.1  christos 	  state |= ((bits & ((1 << 5) - 1)) << 0);
   1023      1.1  christos 	  break;
   1024      1.1  christos 	case SPARC64_PSTATE_REGNUM:
   1025      1.1  christos 	  state |= ((bits & ((1 << 12) - 1)) << 8);
   1026      1.1  christos 	  break;
   1027      1.1  christos 	case SPARC64_ASI_REGNUM:
   1028      1.1  christos 	  state |= ((bits & ((1 << 8) - 1)) << 24);
   1029      1.1  christos 	  break;
   1030      1.1  christos 	case SPARC64_CCR_REGNUM:
   1031      1.1  christos 	  state |= ((bits & ((1 << 8) - 1)) << 32);
   1032      1.1  christos 	  break;
   1033      1.1  christos 	}
   1034      1.1  christos       regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
   1035      1.1  christos     }
   1036      1.1  christos }
   1037      1.1  christos 
   1038      1.1  christos 
   1040      1.1  christos /* Return PC of first real instruction of the function starting at
   1041      1.1  christos    START_PC.  */
   1042      1.1  christos 
   1043      1.1  christos static CORE_ADDR
   1044      1.1  christos sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
   1045      1.1  christos {
   1046      1.1  christos   struct symtab_and_line sal;
   1047      1.1  christos   CORE_ADDR func_start, func_end;
   1048      1.1  christos   struct sparc_frame_cache cache;
   1049      1.1  christos 
   1050      1.1  christos   /* This is the preferred method, find the end of the prologue by
   1051      1.1  christos      using the debugging information.  */
   1052      1.1  christos   if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
   1053      1.1  christos     {
   1054      1.1  christos       sal = find_pc_line (func_start, 0);
   1055      1.1  christos 
   1056      1.1  christos       if (sal.end < func_end
   1057      1.1  christos 	  && start_pc <= sal.end)
   1058      1.1  christos 	return sal.end;
   1059      1.1  christos     }
   1060      1.1  christos 
   1061      1.1  christos   return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL,
   1062      1.1  christos 				 &cache);
   1063      1.1  christos }
   1064  1.9.2.1  perseant 
   1065      1.1  christos /* Normal frames.  */
   1066      1.1  christos 
   1067      1.1  christos static struct sparc_frame_cache *
   1068      1.1  christos sparc64_frame_cache (frame_info_ptr this_frame, void **this_cache)
   1069      1.1  christos {
   1070  1.9.2.1  perseant   return sparc_frame_cache (this_frame, this_cache);
   1071      1.1  christos }
   1072      1.1  christos 
   1073      1.1  christos static void
   1074      1.1  christos sparc64_frame_this_id (frame_info_ptr this_frame, void **this_cache,
   1075      1.1  christos 		       struct frame_id *this_id)
   1076      1.1  christos {
   1077      1.1  christos   struct sparc_frame_cache *cache =
   1078      1.1  christos     sparc64_frame_cache (this_frame, this_cache);
   1079      1.1  christos 
   1080      1.1  christos   /* This marks the outermost frame.  */
   1081      1.1  christos   if (cache->base == 0)
   1082      1.1  christos     return;
   1083      1.1  christos 
   1084  1.9.2.1  perseant   (*this_id) = frame_id_build (cache->base, cache->pc);
   1085      1.1  christos }
   1086      1.1  christos 
   1087      1.1  christos static struct value *
   1088      1.1  christos sparc64_frame_prev_register (frame_info_ptr this_frame, void **this_cache,
   1089      1.1  christos 			     int regnum)
   1090      1.1  christos {
   1091      1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   1092      1.1  christos   struct sparc_frame_cache *cache =
   1093      1.1  christos     sparc64_frame_cache (this_frame, this_cache);
   1094      1.1  christos 
   1095      1.1  christos   if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
   1096      1.1  christos     {
   1097      1.1  christos       CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0;
   1098      1.1  christos 
   1099      1.1  christos       regnum =
   1100      1.1  christos 	(cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
   1101      1.1  christos       pc += get_frame_register_unsigned (this_frame, regnum) + 8;
   1102      1.1  christos       return frame_unwind_got_constant (this_frame, regnum, pc);
   1103      1.1  christos     }
   1104      1.1  christos 
   1105      1.1  christos   /* Handle StackGhost.  */
   1106      1.1  christos   {
   1107  1.9.2.1  perseant     ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
   1108  1.9.2.1  perseant 
   1109      1.1  christos     if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM)
   1110  1.9.2.1  perseant       {
   1111  1.9.2.1  perseant 	CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
   1112  1.9.2.1  perseant 	ULONGEST i7;
   1113      1.1  christos 
   1114      1.1  christos 	/* Read the value in from memory.  */
   1115      1.1  christos 	i7 = get_frame_memory_unsigned (this_frame, addr, 8);
   1116      1.1  christos 	return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie);
   1117      1.1  christos       }
   1118      1.1  christos   }
   1119      1.1  christos 
   1120      1.1  christos   /* The previous frame's `local' and `in' registers may have been saved
   1121      1.1  christos      in the register save area.  */
   1122      1.1  christos   if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
   1123      1.1  christos       && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM))))
   1124      1.1  christos     {
   1125      1.1  christos       CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
   1126      1.1  christos 
   1127      1.1  christos       return frame_unwind_got_memory (this_frame, regnum, addr);
   1128      1.1  christos     }
   1129      1.1  christos 
   1130      1.1  christos   /* The previous frame's `out' registers may be accessible as the current
   1131      1.1  christos      frame's `in' registers.  */
   1132      1.1  christos   if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM
   1133      1.1  christos       && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))))
   1134      1.1  christos     regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
   1135      1.1  christos 
   1136      1.1  christos   return frame_unwind_got_register (this_frame, regnum, regnum);
   1137  1.9.2.1  perseant }
   1138      1.1  christos 
   1139      1.1  christos static const struct frame_unwind sparc64_frame_unwind =
   1140      1.1  christos {
   1141      1.1  christos   "sparc64 prologue",
   1142      1.1  christos   NORMAL_FRAME,
   1143      1.1  christos   default_frame_unwind_stop_reason,
   1144      1.1  christos   sparc64_frame_this_id,
   1145      1.1  christos   sparc64_frame_prev_register,
   1146      1.1  christos   NULL,
   1147      1.1  christos   default_frame_sniffer
   1148  1.9.2.1  perseant };
   1149      1.1  christos 
   1150      1.1  christos 
   1152      1.1  christos static CORE_ADDR
   1153      1.1  christos sparc64_frame_base_address (frame_info_ptr this_frame, void **this_cache)
   1154      1.1  christos {
   1155      1.1  christos   struct sparc_frame_cache *cache =
   1156      1.1  christos     sparc64_frame_cache (this_frame, this_cache);
   1157      1.1  christos 
   1158      1.1  christos   return cache->base;
   1159      1.1  christos }
   1160      1.1  christos 
   1161      1.1  christos static const struct frame_base sparc64_frame_base =
   1162      1.1  christos {
   1163      1.1  christos   &sparc64_frame_unwind,
   1164      1.1  christos   sparc64_frame_base_address,
   1165      1.1  christos   sparc64_frame_base_address,
   1166      1.1  christos   sparc64_frame_base_address
   1167      1.1  christos };
   1168      1.1  christos 
   1169      1.9  christos /* Check whether TYPE must be 16-byte aligned.  */
   1171  1.9.2.1  perseant 
   1172      1.8  christos static int
   1173      1.8  christos sparc64_16_byte_align_p (struct type *type)
   1174  1.9.2.1  perseant {
   1175      1.8  christos   if (type->code () == TYPE_CODE_ARRAY)
   1176  1.9.2.1  perseant     {
   1177      1.1  christos       struct type *t = check_typedef (type->target_type ());
   1178      1.1  christos 
   1179      1.1  christos       if (sparc64_floating_p (t))
   1180      1.1  christos 	return 1;
   1181      1.1  christos     }
   1182      1.1  christos   if (sparc64_floating_p (type) && type->length () == 16)
   1183      1.9  christos     return 1;
   1184      1.1  christos 
   1185      1.9  christos   if (sparc64_structure_or_union_p (type))
   1186      1.1  christos     {
   1187      1.1  christos       int i;
   1188      1.1  christos 
   1189      1.1  christos       for (i = 0; i < type->num_fields (); i++)
   1190      1.1  christos 	{
   1191      1.1  christos 	  struct type *subtype = check_typedef (type->field (i).type ());
   1192      1.1  christos 
   1193      1.1  christos 	  if (sparc64_16_byte_align_p (subtype))
   1194      1.1  christos 	    return 1;
   1195      1.1  christos 	}
   1196      1.1  christos     }
   1197      1.9  christos 
   1198      1.1  christos   return 0;
   1199      1.1  christos }
   1200      1.1  christos 
   1201      1.1  christos /* Store floating fields of element ELEMENT of an "parameter array"
   1202      1.1  christos    that has type TYPE and is stored at BITPOS in VALBUF in the
   1203      1.1  christos    appropriate registers of REGCACHE.  This function can be called
   1204      1.1  christos    recursively and therefore handles floating types in addition to
   1205      1.8  christos    structures.  */
   1206  1.9.2.1  perseant 
   1207      1.1  christos static void
   1208      1.1  christos sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
   1209      1.1  christos 			       const gdb_byte *valbuf, int element, int bitpos)
   1210      1.9  christos {
   1211      1.8  christos   struct gdbarch *gdbarch = regcache->arch ();
   1212      1.8  christos   int len = type->length ();
   1213      1.8  christos 
   1214      1.8  christos   gdb_assert (element < 16);
   1215      1.8  christos 
   1216      1.8  christos   if (type->code () == TYPE_CODE_ARRAY)
   1217  1.9.2.1  perseant     {
   1218  1.9.2.1  perseant       gdb_byte buf[8];
   1219  1.9.2.1  perseant       int regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
   1220  1.9.2.1  perseant 
   1221  1.9.2.1  perseant       valbuf += bitpos / 8;
   1222  1.9.2.1  perseant       if (len < 8)
   1223      1.8  christos 	{
   1224  1.9.2.1  perseant 	  memset (buf, 0, 8 - len);
   1225      1.8  christos 	  memcpy (buf + 8 - len, valbuf, len);
   1226      1.8  christos 	  valbuf = buf;
   1227      1.1  christos 	  len = 8;
   1228      1.1  christos 	}
   1229      1.1  christos       for (int n = 0; n < (len + 3) / 4; n++)
   1230      1.1  christos 	regcache->cooked_write (regnum + n, valbuf + n * 4);
   1231      1.1  christos     }
   1232      1.1  christos   else if (sparc64_floating_p (type)
   1233      1.1  christos       || (sparc64_complex_floating_p (type) && len <= 16))
   1234      1.1  christos     {
   1235      1.1  christos       int regnum;
   1236      1.7  christos 
   1237      1.8  christos       if (len == 16)
   1238      1.1  christos 	{
   1239      1.1  christos 	  gdb_assert (bitpos == 0);
   1240      1.1  christos 	  gdb_assert ((element % 2) == 0);
   1241      1.1  christos 
   1242      1.1  christos 	  regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM + element / 2;
   1243      1.7  christos 	  regcache->cooked_write (regnum, valbuf);
   1244  1.9.2.1  perseant 	}
   1245      1.8  christos       else if (len == 8)
   1246      1.1  christos 	{
   1247      1.1  christos 	  gdb_assert (bitpos == 0 || bitpos == 64);
   1248      1.1  christos 
   1249      1.1  christos 	  regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
   1250      1.1  christos 		   + element + bitpos / 64;
   1251      1.1  christos 	  regcache->cooked_write (regnum, valbuf + (bitpos / 8));
   1252      1.1  christos 	}
   1253      1.8  christos       else
   1254      1.1  christos 	{
   1255      1.1  christos 	  gdb_assert (len == 4);
   1256      1.1  christos 	  gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128);
   1257      1.1  christos 
   1258      1.1  christos 	  regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
   1259      1.1  christos 	  regcache->cooked_write (regnum, valbuf + (bitpos / 8));
   1260      1.9  christos 	}
   1261      1.1  christos     }
   1262      1.9  christos   else if (sparc64_structure_or_union_p (type))
   1263  1.9.2.1  perseant     {
   1264      1.1  christos       int i;
   1265      1.1  christos 
   1266      1.1  christos       for (i = 0; i < type->num_fields (); i++)
   1267      1.1  christos 	{
   1268      1.1  christos 	  struct type *subtype = check_typedef (type->field (i).type ());
   1269      1.1  christos 	  int subpos = bitpos + type->field (i).loc_bitpos ();
   1270  1.9.2.1  perseant 
   1271  1.9.2.1  perseant 	  sparc64_store_floating_fields (regcache, subtype, valbuf,
   1272  1.9.2.1  perseant 					 element, subpos);
   1273  1.9.2.1  perseant 	}
   1274  1.9.2.1  perseant 
   1275  1.9.2.1  perseant       /* GCC has an interesting bug.  If TYPE is a structure that has
   1276  1.9.2.1  perseant 	 a single `float' member, GCC doesn't treat it as a structure
   1277  1.9.2.1  perseant 	 at all, but rather as an ordinary `float' argument.  This
   1278      1.9  christos 	 argument will be stored in %f1, as required by the psABI.
   1279      1.1  christos 	 However, as a member of a structure the psABI requires it to
   1280      1.9  christos 	 be stored in %f0.  This bug is present in GCC 3.3.2, but
   1281      1.1  christos 	 probably in older releases to.  To appease GCC, if a
   1282  1.9.2.1  perseant 	 structure has only a single `float' member, we store its
   1283      1.8  christos 	 value in %f1 too (we already have stored in %f0).  */
   1284      1.1  christos       if (type->num_fields () == 1)
   1285      1.1  christos 	{
   1286      1.1  christos 	  struct type *subtype = check_typedef (type->field (0).type ());
   1287      1.1  christos 
   1288      1.1  christos 	  if (sparc64_floating_p (subtype) && subtype->length () == 4)
   1289      1.1  christos 	    regcache->cooked_write (SPARC_F1_REGNUM, valbuf);
   1290      1.1  christos 	}
   1291      1.1  christos     }
   1292      1.1  christos }
   1293      1.1  christos 
   1294      1.1  christos /* Fetch floating fields from a variable of type TYPE from the
   1295      1.1  christos    appropriate registers for BITPOS in REGCACHE and store it at BITPOS
   1296      1.1  christos    in VALBUF.  This function can be called recursively and therefore
   1297      1.8  christos    handles floating types in addition to structures.  */
   1298      1.7  christos 
   1299      1.9  christos static void
   1300      1.8  christos sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
   1301  1.9.2.1  perseant 				 gdb_byte *valbuf, int bitpos)
   1302      1.8  christos {
   1303      1.8  christos   struct gdbarch *gdbarch = regcache->arch ();
   1304      1.8  christos 
   1305      1.8  christos   if (type->code () == TYPE_CODE_ARRAY)
   1306  1.9.2.1  perseant     {
   1307  1.9.2.1  perseant       int len = type->length ();
   1308  1.9.2.1  perseant       int regnum =  SPARC_F0_REGNUM + bitpos / 32;
   1309  1.9.2.1  perseant 
   1310  1.9.2.1  perseant       valbuf += bitpos / 8;
   1311      1.8  christos       if (len < 4)
   1312  1.9.2.1  perseant 	{
   1313  1.9.2.1  perseant 	  gdb_byte buf[4];
   1314      1.8  christos 	  regcache->cooked_read (regnum, buf);
   1315      1.8  christos 	  memcpy (valbuf, buf + 4 - len, len);
   1316      1.1  christos 	}
   1317  1.9.2.1  perseant       else
   1318      1.1  christos 	for (int i = 0; i < (len + 3) / 4; i++)
   1319      1.1  christos 	  regcache->cooked_read (regnum + i, valbuf + i * 4);
   1320      1.1  christos     }
   1321      1.1  christos   else if (sparc64_floating_p (type))
   1322      1.1  christos     {
   1323      1.1  christos       int len = type->length ();
   1324      1.7  christos       int regnum;
   1325  1.9.2.1  perseant 
   1326      1.8  christos       if (len == 16)
   1327      1.1  christos 	{
   1328      1.1  christos 	  gdb_assert (bitpos == 0 || bitpos == 128);
   1329      1.1  christos 
   1330      1.1  christos 	  regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
   1331      1.1  christos 		   + bitpos / 128;
   1332      1.7  christos 	  regcache->cooked_read (regnum, valbuf + (bitpos / 8));
   1333      1.8  christos 	}
   1334      1.1  christos       else if (len == 8)
   1335      1.1  christos 	{
   1336      1.1  christos 	  gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256);
   1337      1.1  christos 
   1338      1.1  christos 	  regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + bitpos / 64;
   1339      1.1  christos 	  regcache->cooked_read (regnum, valbuf + (bitpos / 8));
   1340      1.1  christos 	}
   1341      1.8  christos       else
   1342      1.1  christos 	{
   1343      1.1  christos 	  gdb_assert (len == 4);
   1344      1.1  christos 	  gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256);
   1345      1.1  christos 
   1346      1.1  christos 	  regnum = SPARC_F0_REGNUM + bitpos / 32;
   1347      1.1  christos 	  regcache->cooked_read (regnum, valbuf + (bitpos / 8));
   1348      1.9  christos 	}
   1349      1.1  christos     }
   1350      1.9  christos   else if (sparc64_structure_or_union_p (type))
   1351  1.9.2.1  perseant     {
   1352      1.1  christos       int i;
   1353      1.1  christos 
   1354      1.1  christos       for (i = 0; i < type->num_fields (); i++)
   1355      1.1  christos 	{
   1356      1.1  christos 	  struct type *subtype = check_typedef (type->field (i).type ());
   1357      1.1  christos 	  int subpos = bitpos + type->field (i).loc_bitpos ();
   1358      1.1  christos 
   1359      1.1  christos 	  sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos);
   1360      1.1  christos 	}
   1361      1.1  christos     }
   1362      1.1  christos }
   1363      1.1  christos 
   1364      1.8  christos /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
   1365      1.8  christos    non-zero) in REGCACHE and on the stack (starting from address SP).  */
   1366      1.1  christos 
   1367      1.8  christos static CORE_ADDR
   1368      1.1  christos sparc64_store_arguments (struct regcache *regcache, int nargs,
   1369      1.1  christos 			 struct value **args, CORE_ADDR sp,
   1370      1.1  christos 			 function_call_return_method return_method,
   1371      1.1  christos 			 CORE_ADDR struct_addr)
   1372      1.1  christos {
   1373      1.1  christos   struct gdbarch *gdbarch = regcache->arch ();
   1374      1.1  christos   /* Number of extended words in the "parameter array".  */
   1375      1.1  christos   int num_elements = 0;
   1376      1.1  christos   int element = 0;
   1377      1.1  christos   int i;
   1378      1.1  christos 
   1379      1.8  christos   /* Take BIAS into account.  */
   1380      1.1  christos   sp += BIAS;
   1381      1.1  christos 
   1382      1.1  christos   /* First we calculate the number of extended words in the "parameter
   1383      1.1  christos      array".  While doing so we also convert some of the arguments.  */
   1384      1.1  christos 
   1385  1.9.2.1  perseant   if (return_method == return_method_struct)
   1386      1.1  christos     num_elements++;
   1387      1.1  christos 
   1388      1.1  christos   for (i = 0; i < nargs; i++)
   1389      1.1  christos     {
   1390      1.1  christos       struct type *type = value_type (args[i]);
   1391      1.1  christos       int len = type->length ();
   1392      1.1  christos 
   1393      1.1  christos       if (sparc64_structure_or_union_p (type)
   1394      1.1  christos 	  || (sparc64_complex_floating_p (type) && len == 32))
   1395      1.1  christos 	{
   1396      1.1  christos 	  /* Structure or Union arguments.  */
   1397      1.1  christos 	  if (len <= 16)
   1398      1.1  christos 	    {
   1399      1.1  christos 	      if (num_elements % 2 && sparc64_16_byte_align_p (type))
   1400      1.1  christos 		num_elements++;
   1401      1.1  christos 	      num_elements += ((len + 7) / 8);
   1402      1.1  christos 	    }
   1403      1.1  christos 	  else
   1404      1.1  christos 	    {
   1405      1.1  christos 	      /* The psABI says that "Structures or unions larger than
   1406      1.1  christos 		 sixteen bytes are copied by the caller and passed
   1407      1.1  christos 		 indirectly; the caller will pass the address of a
   1408      1.1  christos 		 correctly aligned structure value.  This sixty-four
   1409      1.1  christos 		 bit address will occupy one word in the parameter
   1410  1.9.2.1  perseant 		 array, and may be promoted to an %o register like any
   1411  1.9.2.1  perseant 		 other pointer value."  Allocate memory for these
   1412      1.1  christos 		 values on the stack.  */
   1413      1.1  christos 	      sp -= len;
   1414  1.9.2.1  perseant 
   1415      1.1  christos 	      /* Use 16-byte alignment for these values.  That's
   1416      1.1  christos 		 always correct, and wasting a few bytes shouldn't be
   1417      1.1  christos 		 a problem.  */
   1418      1.1  christos 	      sp &= ~0xf;
   1419      1.1  christos 
   1420      1.1  christos 	      write_memory (sp, value_contents (args[i]).data (), len);
   1421      1.1  christos 	      args[i] = value_from_pointer (lookup_pointer_type (type), sp);
   1422      1.1  christos 	      num_elements++;
   1423      1.1  christos 	    }
   1424      1.1  christos 	}
   1425  1.9.2.1  perseant       else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
   1426  1.9.2.1  perseant 	{
   1427      1.1  christos 	  /* Floating arguments.  */
   1428      1.1  christos 	  if (len == 16)
   1429      1.1  christos 	    {
   1430  1.9.2.1  perseant 	      /* The psABI says that "Each quad-precision parameter
   1431  1.9.2.1  perseant 		 value will be assigned to two extended words in the
   1432  1.9.2.1  perseant 		 parameter array.  */
   1433      1.3  christos 	      num_elements += 2;
   1434      1.1  christos 
   1435      1.1  christos 	      /* The psABI says that "Long doubles must be
   1436      1.1  christos 		 quad-aligned, and thus a hole might be introduced
   1437      1.1  christos 		 into the parameter array to force alignment."  Skip
   1438      1.1  christos 		 an element if necessary.  */
   1439      1.1  christos 	      if ((num_elements % 2) && sparc64_16_byte_align_p (type))
   1440      1.1  christos 		num_elements++;
   1441      1.1  christos 	    }
   1442      1.1  christos 	  else
   1443      1.1  christos 	    num_elements++;
   1444      1.1  christos 	}
   1445      1.1  christos       else
   1446      1.1  christos 	{
   1447      1.1  christos 	  /* Integral and pointer arguments.  */
   1448      1.1  christos 	  gdb_assert (sparc64_integral_or_pointer_p (type));
   1449      1.1  christos 
   1450      1.1  christos 	  /* The psABI says that "Each argument value of integral type
   1451      1.1  christos 	     smaller than an extended word will be widened by the
   1452      1.1  christos 	     caller to an extended word according to the signed-ness
   1453      1.1  christos 	     of the argument type."  */
   1454      1.1  christos 	  if (len < 8)
   1455      1.1  christos 	    args[i] = value_cast (builtin_type (gdbarch)->builtin_int64,
   1456      1.1  christos 				  args[i]);
   1457      1.1  christos 	  num_elements++;
   1458      1.1  christos 	}
   1459      1.1  christos     }
   1460      1.1  christos 
   1461      1.9  christos   /* Allocate the "parameter array".  */
   1462      1.1  christos   sp -= num_elements * 8;
   1463      1.1  christos 
   1464      1.1  christos   /* The psABI says that "Every stack frame must be 16-byte aligned."  */
   1465      1.1  christos   sp &= ~0xf;
   1466      1.1  christos 
   1467      1.1  christos   /* Now we store the arguments in to the "parameter array".  Some
   1468      1.1  christos      Integer or Pointer arguments and Structure or Union arguments
   1469      1.1  christos      will be passed in %o registers.  Some Floating arguments and
   1470      1.1  christos      floating members of structures are passed in floating-point
   1471      1.1  christos      registers.  However, for functions with variable arguments,
   1472      1.1  christos      floating arguments are stored in an %0 register, and for
   1473      1.1  christos      functions without a prototype floating arguments are stored in
   1474      1.1  christos      both a floating-point and an %o registers, or a floating-point
   1475      1.8  christos      register and memory.  To simplify the logic here we always pass
   1476      1.1  christos      arguments in memory, an %o register, and a floating-point
   1477      1.1  christos      register if appropriate.  This should be no problem since the
   1478      1.1  christos      contents of any unused memory or registers in the "parameter
   1479      1.1  christos      array" are undefined.  */
   1480      1.1  christos 
   1481      1.1  christos   if (return_method == return_method_struct)
   1482      1.1  christos     {
   1483  1.9.2.1  perseant       regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
   1484      1.1  christos       element++;
   1485  1.9.2.1  perseant     }
   1486      1.1  christos 
   1487      1.1  christos   for (i = 0; i < nargs; i++)
   1488      1.1  christos     {
   1489      1.1  christos       const gdb_byte *valbuf = value_contents (args[i]).data ();
   1490      1.1  christos       struct type *type = value_type (args[i]);
   1491      1.1  christos       int len = type->length ();
   1492      1.3  christos       int regnum = -1;
   1493      1.1  christos       gdb_byte buf[16];
   1494      1.1  christos 
   1495      1.6  christos       if (sparc64_structure_or_union_p (type)
   1496      1.6  christos 	  || (sparc64_complex_floating_p (type) && len == 32))
   1497      1.1  christos 	{
   1498      1.1  christos 	  /* Structure, Union or long double Complex arguments.  */
   1499      1.1  christos 	  gdb_assert (len <= 16);
   1500      1.1  christos 	  memset (buf, 0, sizeof (buf));
   1501      1.1  christos 	  memcpy (buf, valbuf, len);
   1502      1.1  christos 	  valbuf = buf;
   1503      1.1  christos 
   1504      1.1  christos 	  if (element % 2 && sparc64_16_byte_align_p (type))
   1505      1.8  christos 	    element++;
   1506      1.1  christos 
   1507      1.1  christos 	  if (element < 6)
   1508      1.1  christos 	    {
   1509      1.1  christos 	      regnum = SPARC_O0_REGNUM + element;
   1510      1.1  christos 	      if (len > 8 && element < 5)
   1511      1.3  christos 		regcache->cooked_write (regnum + 1, valbuf + 8);
   1512      1.3  christos 	    }
   1513      1.3  christos 
   1514      1.3  christos 	  if (element < 16)
   1515      1.3  christos 	    sparc64_store_floating_fields (regcache, type, valbuf, element, 0);
   1516      1.7  christos 	}
   1517      1.3  christos       else if (sparc64_complex_floating_p (type))
   1518      1.3  christos 	{
   1519      1.3  christos 	  /* Float Complex or double Complex arguments.  */
   1520      1.7  christos 	  if (element < 16)
   1521      1.8  christos 	    {
   1522      1.7  christos 	      regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + element;
   1523      1.8  christos 
   1524      1.8  christos 	      if (len == 16)
   1525      1.3  christos 		{
   1526      1.3  christos 		  if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D30_REGNUM)
   1527      1.3  christos 		    regcache->cooked_write (regnum + 1, valbuf + 8);
   1528      1.3  christos 		  if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D10_REGNUM)
   1529      1.1  christos 		    regcache->cooked_write (SPARC_O0_REGNUM + element + 1,
   1530      1.1  christos 					    valbuf + 8);
   1531      1.1  christos 		}
   1532      1.1  christos 	    }
   1533      1.1  christos 	}
   1534      1.1  christos       else if (sparc64_floating_p (type))
   1535      1.1  christos 	{
   1536      1.7  christos 	  /* Floating arguments.  */
   1537  1.9.2.1  perseant 	  if (len == 16)
   1538      1.1  christos 	    {
   1539      1.1  christos 	      if (element % 2)
   1540      1.1  christos 		element++;
   1541      1.1  christos 	      if (element < 16)
   1542      1.7  christos 		regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
   1543  1.9.2.1  perseant 			 + element / 2;
   1544      1.1  christos 	    }
   1545      1.1  christos 	  else if (len == 8)
   1546      1.1  christos 	    {
   1547      1.1  christos 	      if (element < 16)
   1548  1.9.2.1  perseant 		regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
   1549  1.9.2.1  perseant 			 + element;
   1550  1.9.2.1  perseant 	    }
   1551  1.9.2.1  perseant 	  else if (len == 4)
   1552  1.9.2.1  perseant 	    {
   1553      1.1  christos 	      /* The psABI says "Each single-precision parameter value
   1554      1.1  christos 		 will be assigned to one extended word in the
   1555      1.1  christos 		 parameter array, and right-justified within that
   1556      1.1  christos 		 word; the left half (even float register) is
   1557      1.1  christos 		 undefined."  Even though the psABI says that "the
   1558      1.7  christos 		 left half is undefined", set it to zero here.  */
   1559  1.9.2.1  perseant 	      memset (buf, 0, 4);
   1560      1.1  christos 	      memcpy (buf + 4, valbuf, 4);
   1561      1.1  christos 	      valbuf = buf;
   1562      1.1  christos 	      len = 8;
   1563      1.1  christos 	      if (element < 16)
   1564      1.1  christos 		regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
   1565      1.1  christos 			 + element;
   1566      1.1  christos 	    }
   1567      1.1  christos 	}
   1568      1.1  christos       else
   1569      1.1  christos 	{
   1570      1.1  christos 	  /* Integral and pointer arguments.  */
   1571      1.1  christos 	  gdb_assert (len == 8);
   1572      1.8  christos 	  if (element < 6)
   1573      1.1  christos 	    regnum = SPARC_O0_REGNUM + element;
   1574      1.1  christos 	}
   1575  1.9.2.1  perseant 
   1576      1.7  christos       if (regnum != -1)
   1577  1.9.2.1  perseant 	{
   1578  1.9.2.1  perseant 	  regcache->cooked_write (regnum, valbuf);
   1579      1.7  christos 
   1580  1.9.2.1  perseant 	  /* If we're storing the value in a floating-point register,
   1581  1.9.2.1  perseant 	     also store it in the corresponding %0 register(s).  */
   1582  1.9.2.1  perseant 	  if (regnum >= gdbarch_num_regs (gdbarch))
   1583  1.9.2.1  perseant 	    {
   1584  1.9.2.1  perseant 	      regnum -= gdbarch_num_regs (gdbarch);
   1585  1.9.2.1  perseant 
   1586  1.9.2.1  perseant 	      if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM)
   1587  1.9.2.1  perseant 		{
   1588  1.9.2.1  perseant 		  gdb_assert (element < 6);
   1589  1.9.2.1  perseant 		  regnum = SPARC_O0_REGNUM + element;
   1590  1.9.2.1  perseant 		  regcache->cooked_write (regnum, valbuf);
   1591  1.9.2.1  perseant 		}
   1592  1.9.2.1  perseant 	      else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM)
   1593  1.9.2.1  perseant 		{
   1594      1.1  christos 		  gdb_assert (element < 5);
   1595      1.1  christos 		  regnum = SPARC_O0_REGNUM + element;
   1596      1.1  christos 		  regcache->cooked_write (regnum, valbuf);
   1597      1.1  christos 		  regcache->cooked_write (regnum + 1, valbuf + 8);
   1598      1.1  christos 		}
   1599      1.1  christos 	    }
   1600      1.1  christos 	}
   1601      1.1  christos 
   1602      1.1  christos       /* Always store the argument in memory.  */
   1603      1.1  christos       write_memory (sp + element * 8, valbuf, len);
   1604      1.1  christos       element += ((len + 7) / 8);
   1605      1.1  christos     }
   1606      1.1  christos 
   1607      1.1  christos   gdb_assert (element == num_elements);
   1608      1.1  christos 
   1609      1.1  christos   /* Take BIAS into account.  */
   1610      1.1  christos   sp -= BIAS;
   1611      1.1  christos   return sp;
   1612      1.1  christos }
   1613      1.1  christos 
   1614      1.1  christos static CORE_ADDR
   1615      1.1  christos sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
   1616      1.1  christos {
   1617      1.1  christos   /* The ABI requires 16-byte alignment.  */
   1618      1.1  christos   return address & ~0xf;
   1619      1.8  christos }
   1620      1.8  christos 
   1621      1.1  christos static CORE_ADDR
   1622      1.1  christos sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   1623      1.1  christos 			 struct regcache *regcache, CORE_ADDR bp_addr,
   1624      1.1  christos 			 int nargs, struct value **args, CORE_ADDR sp,
   1625      1.1  christos 			 function_call_return_method return_method,
   1626      1.8  christos 			 CORE_ADDR struct_addr)
   1627      1.8  christos {
   1628      1.1  christos   /* Set return address.  */
   1629      1.1  christos   regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
   1630      1.1  christos 
   1631      1.1  christos   /* Set up function arguments.  */
   1632      1.1  christos   sp = sparc64_store_arguments (regcache, nargs, args, sp, return_method,
   1633      1.1  christos 				struct_addr);
   1634      1.1  christos 
   1635      1.1  christos   /* Allocate the register save area.  */
   1636      1.1  christos   sp -= 16 * 8;
   1637      1.1  christos 
   1638      1.1  christos   /* Stack should be 16-byte aligned at this point.  */
   1639      1.1  christos   gdb_assert ((sp + BIAS) % 16 == 0);
   1640      1.1  christos 
   1641      1.1  christos   /* Finally, update the stack pointer.  */
   1642      1.1  christos   regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp);
   1643      1.1  christos 
   1644      1.1  christos   return sp + BIAS;
   1645      1.1  christos }
   1646      1.1  christos 
   1647      1.1  christos 
   1649  1.9.2.1  perseant /* Extract from an array REGBUF containing the (raw) register state, a
   1650      1.1  christos    function return value of TYPE, and copy that into VALBUF.  */
   1651      1.1  christos 
   1652      1.1  christos static void
   1653      1.1  christos sparc64_extract_return_value (struct type *type, struct regcache *regcache,
   1654      1.1  christos 			      gdb_byte *valbuf)
   1655      1.1  christos {
   1656      1.1  christos   int len = type->length ();
   1657      1.1  christos   gdb_byte buf[32];
   1658      1.1  christos   int i;
   1659      1.8  christos 
   1660      1.9  christos   if (sparc64_structure_or_union_p (type))
   1661      1.1  christos     {
   1662      1.1  christos       /* Structure or Union return values.  */
   1663      1.1  christos       gdb_assert (len <= 32);
   1664      1.1  christos 
   1665      1.1  christos       for (i = 0; i < ((len + 7) / 8); i++)
   1666      1.1  christos 	regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
   1667      1.1  christos       if (type->code () != TYPE_CODE_UNION)
   1668      1.8  christos 	sparc64_extract_floating_fields (regcache, type, buf, 0);
   1669      1.1  christos       memcpy (valbuf, buf, len);
   1670      1.1  christos     }
   1671      1.9  christos   else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
   1672      1.1  christos     {
   1673      1.1  christos       /* Floating return values.  */
   1674      1.1  christos       for (i = 0; i < len / 4; i++)
   1675      1.1  christos 	regcache->cooked_read (SPARC_F0_REGNUM + i, buf + i * 4);
   1676      1.1  christos       memcpy (valbuf, buf, len);
   1677      1.8  christos     }
   1678      1.1  christos   else if (type->code () == TYPE_CODE_ARRAY)
   1679      1.1  christos     {
   1680      1.1  christos       /* Small arrays are returned the same way as small structures.  */
   1681      1.1  christos       gdb_assert (len <= 32);
   1682      1.1  christos 
   1683      1.1  christos       for (i = 0; i < ((len + 7) / 8); i++)
   1684      1.1  christos 	regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
   1685      1.1  christos       memcpy (valbuf, buf, len);
   1686  1.9.2.1  perseant     }
   1687      1.8  christos   else
   1688      1.1  christos     {
   1689      1.1  christos       /* Integral and pointer return values.  */
   1690      1.1  christos       gdb_assert (sparc64_integral_or_pointer_p (type));
   1691      1.1  christos 
   1692      1.1  christos       /* Just stripping off any unused bytes should preserve the
   1693      1.1  christos 	 signed-ness just fine.  */
   1694      1.1  christos       regcache->cooked_read (SPARC_O0_REGNUM, buf);
   1695      1.1  christos       memcpy (valbuf, buf + 8 - len, len);
   1696      1.1  christos     }
   1697      1.1  christos }
   1698      1.1  christos 
   1699  1.9.2.1  perseant /* Write into the appropriate registers a function return value stored
   1700      1.1  christos    in VALBUF of type TYPE.  */
   1701      1.1  christos 
   1702      1.1  christos static void
   1703      1.1  christos sparc64_store_return_value (struct type *type, struct regcache *regcache,
   1704      1.1  christos 			    const gdb_byte *valbuf)
   1705      1.1  christos {
   1706      1.1  christos   int len = type->length ();
   1707      1.1  christos   gdb_byte buf[16];
   1708      1.1  christos   int i;
   1709  1.9.2.1  perseant 
   1710  1.9.2.1  perseant   if (sparc64_structure_or_union_p (type))
   1711      1.1  christos     {
   1712      1.1  christos       /* Structure or Union return values.  */
   1713      1.1  christos       gdb_assert (len <= 32);
   1714      1.8  christos 
   1715      1.9  christos       /* Simplify matters by storing the complete value (including
   1716      1.1  christos 	 floating members) into %o0 and %o1.  Floating members are
   1717      1.1  christos 	 also store in the appropriate floating-point registers.  */
   1718      1.1  christos       memset (buf, 0, sizeof (buf));
   1719      1.1  christos       memcpy (buf, valbuf, len);
   1720      1.1  christos       for (i = 0; i < ((len + 7) / 8); i++)
   1721      1.1  christos 	regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
   1722      1.1  christos       if (type->code () != TYPE_CODE_UNION)
   1723      1.8  christos 	sparc64_store_floating_fields (regcache, type, buf, 0, 0);
   1724      1.1  christos     }
   1725      1.9  christos   else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
   1726      1.1  christos     {
   1727      1.1  christos       /* Floating return values.  */
   1728      1.1  christos       memcpy (buf, valbuf, len);
   1729      1.1  christos       for (i = 0; i < len / 4; i++)
   1730      1.1  christos 	regcache->cooked_write (SPARC_F0_REGNUM + i, buf + i * 4);
   1731      1.1  christos     }
   1732      1.1  christos   else if (type->code () == TYPE_CODE_ARRAY)
   1733      1.8  christos     {
   1734      1.1  christos       /* Small arrays are returned the same way as small structures.  */
   1735      1.1  christos       gdb_assert (len <= 32);
   1736      1.1  christos 
   1737      1.1  christos       memset (buf, 0, sizeof (buf));
   1738      1.1  christos       memcpy (buf, valbuf, len);
   1739      1.1  christos       for (i = 0; i < ((len + 7) / 8); i++)
   1740      1.1  christos 	regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
   1741      1.1  christos     }
   1742      1.1  christos   else
   1743      1.8  christos     {
   1744      1.1  christos       /* Integral and pointer return values.  */
   1745      1.1  christos       gdb_assert (sparc64_integral_or_pointer_p (type));
   1746      1.1  christos 
   1747      1.1  christos       /* ??? Do we need to do any sign-extension here?  */
   1748      1.1  christos       memset (buf, 0, 8);
   1749      1.1  christos       memcpy (buf + 8 - len, valbuf, len);
   1750      1.1  christos       regcache->cooked_write (SPARC_O0_REGNUM, buf);
   1751      1.1  christos     }
   1752  1.9.2.1  perseant }
   1753      1.1  christos 
   1754      1.1  christos static enum return_value_convention
   1755      1.1  christos sparc64_return_value (struct gdbarch *gdbarch, struct value *function,
   1756      1.1  christos 		      struct type *type, struct regcache *regcache,
   1757      1.1  christos 		      gdb_byte *readbuf, const gdb_byte *writebuf)
   1758      1.1  christos {
   1759      1.1  christos   if (type->length () > 32)
   1760      1.1  christos     return RETURN_VALUE_STRUCT_CONVENTION;
   1761      1.1  christos 
   1762      1.1  christos   if (readbuf)
   1763      1.1  christos     sparc64_extract_return_value (type, regcache, readbuf);
   1764      1.1  christos   if (writebuf)
   1765      1.1  christos     sparc64_store_return_value (type, regcache, writebuf);
   1766      1.1  christos 
   1767  1.9.2.1  perseant   return RETURN_VALUE_REGISTER_CONVENTION;
   1768      1.1  christos }
   1769      1.1  christos 
   1770      1.1  christos 
   1772      1.1  christos static void
   1773      1.1  christos sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
   1774      1.1  christos 			       struct dwarf2_frame_state_reg *reg,
   1775      1.1  christos 			       frame_info_ptr this_frame)
   1776      1.1  christos {
   1777      1.1  christos   switch (regnum)
   1778      1.1  christos     {
   1779      1.1  christos     case SPARC_G0_REGNUM:
   1780      1.1  christos       /* Since %g0 is always zero, there is no point in saving it, and
   1781      1.1  christos 	 people will be inclined omit it from the CFI.  Make sure we
   1782      1.1  christos 	 don't warn about that.  */
   1783      1.1  christos       reg->how = DWARF2_FRAME_REG_SAME_VALUE;
   1784      1.1  christos       break;
   1785      1.1  christos     case SPARC_SP_REGNUM:
   1786      1.1  christos       reg->how = DWARF2_FRAME_REG_CFA;
   1787      1.1  christos       break;
   1788      1.1  christos     case SPARC64_PC_REGNUM:
   1789      1.1  christos       reg->how = DWARF2_FRAME_REG_RA_OFFSET;
   1790      1.1  christos       reg->loc.offset = 8;
   1791      1.8  christos       break;
   1792      1.8  christos     case SPARC64_NPC_REGNUM:
   1793      1.8  christos       reg->how = DWARF2_FRAME_REG_RA_OFFSET;
   1794      1.8  christos       reg->loc.offset = 12;
   1795      1.8  christos       break;
   1796      1.8  christos     }
   1797      1.8  christos }
   1798      1.8  christos 
   1799      1.1  christos /* sparc64_addr_bits_remove - remove useless address bits  */
   1800      1.1  christos 
   1801      1.1  christos static CORE_ADDR
   1802  1.9.2.1  perseant sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
   1803      1.1  christos {
   1804      1.1  christos   return adi_normalize_address (addr);
   1805      1.1  christos }
   1806      1.7  christos 
   1807      1.7  christos void
   1808      1.7  christos sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   1809      1.7  christos {
   1810      1.1  christos   sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
   1811      1.1  christos 
   1812      1.1  christos   tdep->pc_regnum = SPARC64_PC_REGNUM;
   1813      1.1  christos   tdep->npc_regnum = SPARC64_NPC_REGNUM;
   1814      1.1  christos   tdep->fpu_register_names = sparc64_fpu_register_names;
   1815      1.1  christos   tdep->fpu_registers_num = ARRAY_SIZE (sparc64_fpu_register_names);
   1816      1.7  christos   tdep->cp0_register_names = sparc64_cp0_register_names;
   1817      1.7  christos   tdep->cp0_registers_num = ARRAY_SIZE (sparc64_cp0_register_names);
   1818      1.7  christos 
   1819      1.1  christos   /* This is what all the fuss is about.  */
   1820      1.1  christos   set_gdbarch_long_bit (gdbarch, 64);
   1821      1.1  christos   set_gdbarch_long_long_bit (gdbarch, 64);
   1822      1.1  christos   set_gdbarch_ptr_bit (gdbarch, 64);
   1823      1.7  christos 
   1824      1.7  christos   set_gdbarch_wchar_bit (gdbarch, 16);
   1825      1.1  christos   set_gdbarch_wchar_signed (gdbarch, 0);
   1826      1.1  christos 
   1827      1.1  christos   set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS);
   1828      1.1  christos   set_gdbarch_register_name (gdbarch, sparc64_register_name);
   1829      1.1  christos   set_gdbarch_register_type (gdbarch, sparc64_register_type);
   1830      1.1  christos   set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS);
   1831      1.1  christos   set_tdesc_pseudo_register_name (gdbarch, sparc64_pseudo_register_name);
   1832      1.1  christos   set_tdesc_pseudo_register_type (gdbarch, sparc64_pseudo_register_type);
   1833      1.1  christos   set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read);
   1834      1.1  christos   set_gdbarch_pseudo_register_write (gdbarch, sparc64_pseudo_register_write);
   1835      1.1  christos 
   1836      1.1  christos   /* Register numbers of various important registers.  */
   1837      1.1  christos   set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */
   1838      1.1  christos 
   1839      1.1  christos   /* Call dummy code.  */
   1840      1.1  christos   set_gdbarch_frame_align (gdbarch, sparc64_frame_align);
   1841      1.1  christos   set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
   1842      1.5  christos   set_gdbarch_push_dummy_code (gdbarch, NULL);
   1843      1.1  christos   set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call);
   1844      1.1  christos 
   1845      1.1  christos   set_gdbarch_return_value (gdbarch, sparc64_return_value);
   1846      1.1  christos   set_gdbarch_stabs_argument_has_addr
   1847      1.1  christos     (gdbarch, default_stabs_argument_has_addr);
   1848      1.1  christos 
   1849      1.1  christos   set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue);
   1850      1.1  christos   set_gdbarch_stack_frame_destroyed_p (gdbarch, sparc_stack_frame_destroyed_p);
   1851      1.8  christos 
   1852      1.8  christos   /* Hook in the DWARF CFI frame unwinder.  */
   1853      1.1  christos   dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg);
   1854      1.1  christos   /* FIXME: kettenis/20050423: Don't enable the unwinder until the
   1855      1.1  christos      StackGhost issues have been resolved.  */
   1856      1.1  christos 
   1857      1.1  christos   frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind);
   1858      1.1  christos   frame_base_set_default (gdbarch, &sparc64_frame_base);
   1859      1.1  christos 
   1860      1.1  christos   set_gdbarch_addr_bits_remove (gdbarch, sparc64_addr_bits_remove);
   1861      1.1  christos }
   1862      1.1  christos 
   1863      1.8  christos 
   1865      1.8  christos /* Helper functions for dealing with register sets.  */
   1866      1.1  christos 
   1867      1.8  christos #define TSTATE_CWP	0x000000000000001fULL
   1868      1.1  christos #define TSTATE_ICC	0x0000000f00000000ULL
   1869      1.8  christos #define TSTATE_XCC	0x000000f000000000ULL
   1870      1.1  christos 
   1871      1.1  christos #define PSR_S		0x00000080
   1872      1.1  christos #ifndef PSR_ICC
   1873      1.1  christos #define PSR_ICC		0x00f00000
   1874      1.3  christos #endif
   1875      1.1  christos #define PSR_VERS	0x0f000000
   1876      1.1  christos #ifndef PSR_IMPL
   1877      1.1  christos #define PSR_IMPL	0xf0000000
   1878      1.8  christos #endif
   1879      1.1  christos #define PSR_V8PLUS	0xff000000
   1880      1.1  christos #define PSR_XCC		0x000f0000
   1881      1.6  christos 
   1882      1.1  christos void
   1883      1.1  christos sparc64_supply_gregset (const struct sparc_gregmap *gregmap,
   1884      1.1  christos 			struct regcache *regcache,
   1885      1.1  christos 			int regnum, const void *gregs)
   1886      1.1  christos {
   1887      1.1  christos   struct gdbarch *gdbarch = regcache->arch ();
   1888      1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   1889      1.3  christos   int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
   1890      1.1  christos   const gdb_byte *regs = (const gdb_byte *) gregs;
   1891      1.1  christos   gdb_byte zero[8] = { 0 };
   1892      1.1  christos   int i;
   1893      1.1  christos 
   1894      1.1  christos   if (sparc32)
   1895      1.1  christos     {
   1896      1.1  christos       if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
   1897      1.8  christos 	{
   1898      1.1  christos 	  int offset = gregmap->r_tstate_offset;
   1899      1.1  christos 	  ULONGEST tstate, psr;
   1900      1.1  christos 	  gdb_byte buf[4];
   1901      1.8  christos 
   1902      1.8  christos 	  tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
   1903      1.1  christos 	  psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12)
   1904      1.1  christos 		 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS);
   1905      1.8  christos 	  store_unsigned_integer (buf, 4, byte_order, psr);
   1906      1.8  christos 	  regcache->raw_supply (SPARC32_PSR_REGNUM, buf);
   1907      1.1  christos 	}
   1908      1.1  christos 
   1909      1.1  christos       if (regnum == SPARC32_PC_REGNUM || regnum == -1)
   1910      1.3  christos 	regcache->raw_supply (SPARC32_PC_REGNUM,
   1911      1.8  christos 			      regs + gregmap->r_pc_offset + 4);
   1912      1.1  christos 
   1913      1.1  christos       if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
   1914      1.1  christos 	regcache->raw_supply (SPARC32_NPC_REGNUM,
   1915      1.1  christos 			      regs + gregmap->r_npc_offset + 4);
   1916      1.1  christos 
   1917      1.8  christos       if (regnum == SPARC32_Y_REGNUM || regnum == -1)
   1918      1.8  christos 	{
   1919      1.1  christos 	  int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
   1920      1.1  christos 	  regcache->raw_supply (SPARC32_Y_REGNUM, regs + offset);
   1921      1.8  christos 	}
   1922      1.8  christos     }
   1923      1.1  christos   else
   1924      1.1  christos     {
   1925      1.8  christos       if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
   1926      1.8  christos 	regcache->raw_supply (SPARC64_STATE_REGNUM,
   1927      1.1  christos 			      regs + gregmap->r_tstate_offset);
   1928      1.1  christos 
   1929      1.1  christos       if (regnum == SPARC64_PC_REGNUM || regnum == -1)
   1930      1.1  christos 	regcache->raw_supply (SPARC64_PC_REGNUM,
   1931      1.1  christos 			      regs + gregmap->r_pc_offset);
   1932      1.1  christos 
   1933      1.3  christos       if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
   1934      1.3  christos 	regcache->raw_supply (SPARC64_NPC_REGNUM,
   1935      1.8  christos 			      regs + gregmap->r_npc_offset);
   1936      1.1  christos 
   1937      1.1  christos       if (regnum == SPARC64_Y_REGNUM || regnum == -1)
   1938      1.1  christos 	{
   1939      1.3  christos 	  gdb_byte buf[8];
   1940      1.8  christos 
   1941      1.8  christos 	  memset (buf, 0, 8);
   1942      1.1  christos 	  memcpy (buf + 8 - gregmap->r_y_size,
   1943      1.1  christos 		  regs + gregmap->r_y_offset, gregmap->r_y_size);
   1944      1.1  christos 	  regcache->raw_supply (SPARC64_Y_REGNUM, buf);
   1945      1.8  christos 	}
   1946      1.1  christos 
   1947      1.1  christos       if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
   1948      1.1  christos 	  && gregmap->r_fprs_offset != -1)
   1949      1.3  christos 	regcache->raw_supply (SPARC64_FPRS_REGNUM,
   1950      1.1  christos 			      regs + gregmap->r_fprs_offset);
   1951      1.1  christos     }
   1952      1.1  christos 
   1953      1.1  christos   if (regnum == SPARC_G0_REGNUM || regnum == -1)
   1954      1.1  christos     regcache->raw_supply (SPARC_G0_REGNUM, &zero);
   1955      1.1  christos 
   1956      1.1  christos   if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
   1957      1.8  christos     {
   1958      1.1  christos       int offset = gregmap->r_g1_offset;
   1959      1.1  christos 
   1960      1.1  christos       if (sparc32)
   1961      1.1  christos 	offset += 4;
   1962      1.1  christos 
   1963      1.1  christos       for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
   1964      1.1  christos 	{
   1965  1.9.2.1  perseant 	  if (regnum == i || regnum == -1)
   1966      1.3  christos 	    regcache->raw_supply (i, regs + offset);
   1967      1.1  christos 	  offset += 8;
   1968      1.1  christos 	}
   1969      1.1  christos     }
   1970      1.1  christos 
   1971      1.1  christos   if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
   1972      1.1  christos     {
   1973      1.1  christos       /* Not all of the register set variants include Locals and
   1974      1.1  christos 	 Inputs.  For those that don't, we read them off the stack.  */
   1975      1.3  christos       if (gregmap->r_l0_offset == -1)
   1976      1.1  christos 	{
   1977      1.1  christos 	  ULONGEST sp;
   1978      1.1  christos 
   1979      1.1  christos 	  regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
   1980      1.1  christos 	  sparc_supply_rwindow (regcache, sp, regnum);
   1981      1.1  christos 	}
   1982      1.1  christos       else
   1983      1.8  christos 	{
   1984      1.1  christos 	  int offset = gregmap->r_l0_offset;
   1985      1.1  christos 
   1986      1.1  christos 	  if (sparc32)
   1987      1.1  christos 	    offset += 4;
   1988      1.1  christos 
   1989      1.1  christos 	  for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
   1990      1.1  christos 	    {
   1991      1.3  christos 	      if (regnum == i || regnum == -1)
   1992      1.1  christos 		regcache->raw_supply (i, regs + offset);
   1993      1.1  christos 	      offset += 8;
   1994      1.1  christos 	    }
   1995      1.8  christos 	}
   1996      1.1  christos     }
   1997      1.1  christos }
   1998      1.6  christos 
   1999      1.1  christos void
   2000      1.1  christos sparc64_collect_gregset (const struct sparc_gregmap *gregmap,
   2001      1.1  christos 			 const struct regcache *regcache,
   2002      1.1  christos 			 int regnum, void *gregs)
   2003      1.1  christos {
   2004      1.1  christos   struct gdbarch *gdbarch = regcache->arch ();
   2005      1.3  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   2006      1.1  christos   int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
   2007      1.1  christos   gdb_byte *regs = (gdb_byte *) gregs;
   2008      1.1  christos   int i;
   2009      1.1  christos 
   2010      1.8  christos   if (sparc32)
   2011      1.1  christos     {
   2012      1.1  christos       if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
   2013      1.1  christos 	{
   2014      1.1  christos 	  int offset = gregmap->r_tstate_offset;
   2015      1.1  christos 	  ULONGEST tstate, psr;
   2016      1.1  christos 	  gdb_byte buf[8];
   2017      1.1  christos 
   2018      1.1  christos 	  tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
   2019      1.1  christos 	  regcache->raw_collect (SPARC32_PSR_REGNUM, buf);
   2020      1.8  christos 	  psr = extract_unsigned_integer (buf, 4, byte_order);
   2021      1.8  christos 	  tstate |= (psr & PSR_ICC) << 12;
   2022      1.1  christos 	  if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS)
   2023      1.1  christos 	    tstate |= (psr & PSR_XCC) << 20;
   2024      1.8  christos 	  store_unsigned_integer (buf, 8, byte_order, tstate);
   2025      1.8  christos 	  memcpy (regs + offset, buf, 8);
   2026      1.1  christos 	}
   2027      1.1  christos 
   2028      1.1  christos       if (regnum == SPARC32_PC_REGNUM || regnum == -1)
   2029      1.3  christos 	regcache->raw_collect (SPARC32_PC_REGNUM,
   2030      1.8  christos 			       regs + gregmap->r_pc_offset + 4);
   2031      1.1  christos 
   2032      1.1  christos       if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
   2033      1.1  christos 	regcache->raw_collect (SPARC32_NPC_REGNUM,
   2034      1.1  christos 			       regs + gregmap->r_npc_offset + 4);
   2035      1.1  christos 
   2036      1.8  christos       if (regnum == SPARC32_Y_REGNUM || regnum == -1)
   2037      1.8  christos 	{
   2038      1.1  christos 	  int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
   2039      1.1  christos 	  regcache->raw_collect (SPARC32_Y_REGNUM, regs + offset);
   2040      1.8  christos 	}
   2041      1.8  christos     }
   2042      1.1  christos   else
   2043      1.1  christos     {
   2044      1.8  christos       if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
   2045      1.8  christos 	regcache->raw_collect (SPARC64_STATE_REGNUM,
   2046      1.1  christos 			       regs + gregmap->r_tstate_offset);
   2047      1.1  christos 
   2048      1.1  christos       if (regnum == SPARC64_PC_REGNUM || regnum == -1)
   2049      1.1  christos 	regcache->raw_collect (SPARC64_PC_REGNUM,
   2050      1.1  christos 			       regs + gregmap->r_pc_offset);
   2051      1.8  christos 
   2052      1.3  christos       if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
   2053      1.3  christos 	regcache->raw_collect (SPARC64_NPC_REGNUM,
   2054      1.1  christos 			       regs + gregmap->r_npc_offset);
   2055      1.1  christos 
   2056      1.1  christos       if (regnum == SPARC64_Y_REGNUM || regnum == -1)
   2057      1.3  christos 	{
   2058      1.8  christos 	  gdb_byte buf[8];
   2059      1.8  christos 
   2060      1.1  christos 	  regcache->raw_collect (SPARC64_Y_REGNUM, buf);
   2061      1.1  christos 	  memcpy (regs + gregmap->r_y_offset,
   2062      1.1  christos 		  buf + 8 - gregmap->r_y_size, gregmap->r_y_size);
   2063      1.1  christos 	}
   2064      1.1  christos 
   2065      1.3  christos       if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
   2066      1.1  christos 	  && gregmap->r_fprs_offset != -1)
   2067      1.1  christos 	regcache->raw_collect (SPARC64_FPRS_REGNUM,
   2068      1.1  christos 			       regs + gregmap->r_fprs_offset);
   2069      1.1  christos 
   2070      1.1  christos     }
   2071      1.1  christos 
   2072      1.1  christos   if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
   2073      1.1  christos     {
   2074      1.8  christos       int offset = gregmap->r_g1_offset;
   2075      1.1  christos 
   2076      1.1  christos       if (sparc32)
   2077      1.1  christos 	offset += 4;
   2078      1.1  christos 
   2079      1.1  christos       /* %g0 is always zero.  */
   2080      1.1  christos       for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
   2081      1.1  christos 	{
   2082  1.9.2.1  perseant 	  if (regnum == i || regnum == -1)
   2083      1.3  christos 	    regcache->raw_collect (i, regs + offset);
   2084      1.1  christos 	  offset += 8;
   2085      1.3  christos 	}
   2086      1.1  christos     }
   2087      1.1  christos 
   2088      1.1  christos   if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
   2089      1.1  christos     {
   2090      1.1  christos       /* Not all of the register set variants include Locals and
   2091      1.1  christos 	 Inputs.  For those that don't, we read them off the stack.  */
   2092      1.1  christos       if (gregmap->r_l0_offset != -1)
   2093      1.8  christos 	{
   2094      1.1  christos 	  int offset = gregmap->r_l0_offset;
   2095      1.1  christos 
   2096      1.1  christos 	  if (sparc32)
   2097      1.1  christos 	    offset += 4;
   2098      1.1  christos 
   2099      1.1  christos 	  for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
   2100      1.1  christos 	    {
   2101      1.3  christos 	      if (regnum == i || regnum == -1)
   2102      1.1  christos 		regcache->raw_collect (i, regs + offset);
   2103      1.1  christos 	      offset += 8;
   2104      1.1  christos 	    }
   2105      1.8  christos 	}
   2106      1.6  christos     }
   2107      1.1  christos }
   2108      1.1  christos 
   2109      1.1  christos void
   2110      1.1  christos sparc64_supply_fpregset (const struct sparc_fpregmap *fpregmap,
   2111      1.1  christos 			 struct regcache *regcache,
   2112      1.8  christos 			 int regnum, const void *fpregs)
   2113      1.8  christos {
   2114      1.1  christos   int sparc32 = (gdbarch_ptr_bit (regcache->arch ()) == 32);
   2115      1.1  christos   const gdb_byte *regs = (const gdb_byte *) fpregs;
   2116      1.1  christos   int i;
   2117      1.1  christos 
   2118      1.1  christos   for (i = 0; i < 32; i++)
   2119      1.8  christos     {
   2120      1.3  christos       if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
   2121      1.1  christos 	regcache->raw_supply (SPARC_F0_REGNUM + i,
   2122      1.1  christos 			      regs + fpregmap->r_f0_offset + (i * 4));
   2123      1.1  christos     }
   2124      1.1  christos 
   2125      1.1  christos   if (sparc32)
   2126      1.1  christos     {
   2127      1.8  christos       if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
   2128      1.8  christos 	regcache->raw_supply (SPARC32_FSR_REGNUM,
   2129      1.8  christos 			     regs + fpregmap->r_fsr_offset);
   2130      1.1  christos     }
   2131      1.1  christos   else
   2132      1.1  christos     {
   2133      1.8  christos       for (i = 0; i < 16; i++)
   2134      1.8  christos 	{
   2135      1.1  christos 	  if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
   2136      1.1  christos 	    regcache->raw_supply
   2137      1.1  christos 	      (SPARC64_F32_REGNUM + i,
   2138      1.1  christos 	       regs + fpregmap->r_f0_offset + (32 * 4) + (i * 8));
   2139      1.3  christos 	}
   2140      1.1  christos 
   2141      1.1  christos       if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
   2142      1.1  christos 	regcache->raw_supply (SPARC64_FSR_REGNUM,
   2143      1.8  christos 			      regs + fpregmap->r_fsr_offset);
   2144      1.6  christos     }
   2145      1.1  christos }
   2146      1.1  christos 
   2147      1.1  christos void
   2148      1.1  christos sparc64_collect_fpregset (const struct sparc_fpregmap *fpregmap,
   2149      1.1  christos 			  const struct regcache *regcache,
   2150      1.8  christos 			  int regnum, void *fpregs)
   2151      1.8  christos {
   2152      1.1  christos   int sparc32 = (gdbarch_ptr_bit (regcache->arch ()) == 32);
   2153      1.1  christos   gdb_byte *regs = (gdb_byte *) fpregs;
   2154      1.1  christos   int i;
   2155      1.1  christos 
   2156      1.1  christos   for (i = 0; i < 32; i++)
   2157      1.8  christos     {
   2158      1.8  christos       if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
   2159      1.1  christos 	regcache->raw_collect (SPARC_F0_REGNUM + i,
   2160      1.1  christos 			       regs + fpregmap->r_f0_offset + (i * 4));
   2161      1.1  christos     }
   2162      1.1  christos 
   2163      1.1  christos   if (sparc32)
   2164      1.1  christos     {
   2165      1.8  christos       if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
   2166      1.8  christos 	regcache->raw_collect (SPARC32_FSR_REGNUM,
   2167      1.8  christos 			       regs + fpregmap->r_fsr_offset);
   2168      1.1  christos     }
   2169      1.1  christos   else
   2170      1.1  christos     {
   2171      1.8  christos       for (i = 0; i < 16; i++)
   2172      1.8  christos 	{
   2173      1.1  christos 	  if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
   2174      1.1  christos 	    regcache->raw_collect (SPARC64_F32_REGNUM + i,
   2175      1.1  christos 				   (regs + fpregmap->r_f0_offset
   2176      1.3  christos 				    + (32 * 4) + (i * 8)));
   2177      1.1  christos 	}
   2178      1.1  christos 
   2179      1.1  christos       if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
   2180      1.1  christos 	regcache->raw_collect (SPARC64_FSR_REGNUM,
   2181                    			       regs + fpregmap->r_fsr_offset);
   2182                        }
   2183                    }
   2184                    
   2185                    const struct sparc_fpregmap sparc64_bsd_fpregmap =
   2186                    {
   2187                      0 * 8,			/* %f0 */
   2188                      32 * 8,			/* %fsr */
   2189                    };
   2190