1/* Low level interface to IA-64 running AIX for GDB, the GNU debugger.
2
3   Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
4
5   This file is part of GDB.
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program; if not, write to the Free Software
19   Foundation, Inc., 59 Temple Place - Suite 330,
20   Boston, MA 02111-1307, USA.  */
21
22#include "defs.h"
23#include "inferior.h"
24#include "target.h"
25#include "gdbcore.h"
26#include "regcache.h"
27#include <sys/procfs.h>
28
29#include "symtab.h"
30#include "bfd.h"
31#include "symfile.h"
32#include "objfiles.h"
33
34#include <sys/types.h>
35#include <fcntl.h>
36#include "gdb_stat.h"
37
38void
39supply_gregset (prgregset_t *gregsetp)
40{
41  int regi;
42
43  for (regi = IA64_GR0_REGNUM; regi <= IA64_GR31_REGNUM; regi++)
44    {
45      regcache_raw_supply (current_regcache, regi,
46			   (char *) &(gregsetp->__gpr[regi - IA64_GR0_REGNUM]));
47    }
48
49  for (regi = IA64_BR0_REGNUM; regi <= IA64_BR7_REGNUM; regi++)
50    {
51      regcache_raw_supply (current_regcache, regi,
52			   (char *) &(gregsetp->__br[regi - IA64_BR0_REGNUM]));
53    }
54
55  regcache_raw_supply (current_regcache, IA64_PSR_REGNUM,
56		       (char *) &(gregsetp->__psr));
57  regcache_raw_supply (current_regcache, IA64_IP_REGNUM,
58		       (char *) &(gregsetp->__ip));
59  regcache_raw_supply (current_regcache, IA64_CFM_REGNUM,
60		       (char *) &(gregsetp->__ifs));
61  regcache_raw_supply (current_regcache, IA64_RSC_REGNUM,
62		       (char *) &(gregsetp->__rsc));
63  regcache_raw_supply (current_regcache, IA64_BSP_REGNUM,
64		       (char *) &(gregsetp->__bsp));
65  regcache_raw_supply (current_regcache, IA64_BSPSTORE_REGNUM,
66		       (char *) &(gregsetp->__bspstore));
67  regcache_raw_supply (current_regcache, IA64_RNAT_REGNUM,
68		       (char *) &(gregsetp->__rnat));
69  regcache_raw_supply (current_regcache, IA64_PFS_REGNUM,
70		       (char *) &(gregsetp->__pfs));
71  regcache_raw_supply (current_regcache, IA64_UNAT_REGNUM,
72		       (char *) &(gregsetp->__unat));
73  regcache_raw_supply (current_regcache, IA64_PR_REGNUM,
74		       (char *) &(gregsetp->__preds));
75  regcache_raw_supply (current_regcache, IA64_CCV_REGNUM,
76		       (char *) &(gregsetp->__ccv));
77  regcache_raw_supply (current_regcache, IA64_LC_REGNUM,
78		       (char *) &(gregsetp->__lc));
79  regcache_raw_supply (current_regcache, IA64_EC_REGNUM,
80		       (char *) &(gregsetp->__ec));
81  /* FIXME: __nats */
82  regcache_raw_supply (current_regcache, IA64_FPSR_REGNUM,
83		       (char *) &(gregsetp->__fpsr));
84
85  /* These (for the most part) are pseudo registers and are obtained
86     by other means.  Those that aren't are already handled by the
87     code above.  */
88  for (regi = IA64_GR32_REGNUM; regi <= IA64_GR127_REGNUM; regi++)
89    deprecated_register_valid[regi] = 1;
90  for (regi = IA64_PR0_REGNUM; regi <= IA64_PR63_REGNUM; regi++)
91    deprecated_register_valid[regi] = 1;
92  for (regi = IA64_VFP_REGNUM; regi <= NUM_REGS; regi++)
93    deprecated_register_valid[regi] = 1;
94}
95
96void
97fill_gregset (prgregset_t *gregsetp, int regno)
98{
99  int regi;
100
101#define COPY_REG(_fld_,_regi_) \
102  if ((regno == -1) || regno == _regi_) \
103    memcpy (&(gregsetp->_fld_), &deprecated_registers[DEPRECATED_REGISTER_BYTE (_regi_)], \
104	    register_size (current_gdbarch, _regi_))
105
106  for (regi = IA64_GR0_REGNUM; regi <= IA64_GR31_REGNUM; regi++)
107    {
108      COPY_REG (__gpr[regi - IA64_GR0_REGNUM], regi);
109    }
110
111  for (regi = IA64_BR0_REGNUM; regi <= IA64_BR7_REGNUM; regi++)
112    {
113      COPY_REG (__br[regi - IA64_BR0_REGNUM], regi);
114    }
115  COPY_REG (__psr, IA64_PSR_REGNUM);
116  COPY_REG (__ip, IA64_IP_REGNUM);
117  COPY_REG (__ifs, IA64_CFM_REGNUM);
118  COPY_REG (__rsc, IA64_RSC_REGNUM);
119  COPY_REG (__bsp, IA64_BSP_REGNUM);
120
121  /* Bad things happen if we don't update both bsp and bspstore at the
122     same time.  */
123  if (regno == IA64_BSP_REGNUM || regno == -1)
124    {
125      memcpy (&(gregsetp->__bspstore),
126	      &deprecated_registers[DEPRECATED_REGISTER_BYTE (IA64_BSP_REGNUM)],
127	      register_size (current_gdbarch, IA64_BSP_REGNUM));
128      memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (IA64_BSPSTORE_REGNUM)],
129	      &deprecated_registers[DEPRECATED_REGISTER_BYTE (IA64_BSP_REGNUM)],
130	      register_size (current_gdbarch, IA64_BSP_REGNUM));
131    }
132
133#if 0
134  /* We never actually write to bspstore, or we'd have to do the same thing
135     here too.  */
136  COPY_REG (__bspstore, IA64_BSPSTORE_REGNUM);
137#endif
138  COPY_REG (__rnat, IA64_RNAT_REGNUM);
139  COPY_REG (__pfs, IA64_PFS_REGNUM);
140  COPY_REG (__unat, IA64_UNAT_REGNUM);
141  COPY_REG (__preds, IA64_PR_REGNUM);
142  COPY_REG (__ccv, IA64_CCV_REGNUM);
143  COPY_REG (__lc, IA64_LC_REGNUM);
144  COPY_REG (__ec, IA64_EC_REGNUM);
145  /* FIXME: __nats */
146  COPY_REG (__fpsr, IA64_FPSR_REGNUM);
147#undef COPY_REG
148}
149
150void
151supply_fpregset (prfpregset_t *fpregsetp)
152{
153  int regi;
154
155  for (regi = IA64_FR0_REGNUM; regi <= IA64_FR127_REGNUM; regi++)
156    regcache_raw_supply (current_regcache, regi,
157                     (char *) &(fpregsetp->__fpr[regi - IA64_FR0_REGNUM]));
158}
159
160void
161fill_fpregset (prfpregset_t *fpregsetp, int regno)
162{
163  int regi;
164  char *to;
165  char *from;
166
167  for (regi = IA64_FR0_REGNUM; regi <= IA64_FR127_REGNUM; regi++)
168    {
169      if ((regno == -1) || (regno == regi))
170	{
171	  from = (char *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)];
172	  to = (char *) &(fpregsetp->__fpr[regi - IA64_FR0_REGNUM]);
173	  memcpy (to, from, register_size (current_gdbarch, regi));
174	}
175    }
176}
177