OSDN Git Service

add i18n markup in error message (utils.c:parse_escape)
[pf3gnuchains/sourceware.git] / gdb / alphabsd-nat.c
1 /* Native-dependent code for Alpha BSD's.
2
3    Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4    2011 Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 #include "defs.h"
22 #include "inferior.h"
23 #include "regcache.h"
24
25 #include "alpha-tdep.h"
26 #include "alphabsd-tdep.h"
27 #include "inf-ptrace.h"
28
29 #include <sys/types.h>
30 #include <sys/ptrace.h>
31 #include <machine/reg.h>
32
33 #ifdef HAVE_SYS_PROCFS_H
34 #include <sys/procfs.h>
35 #endif
36
37 #ifndef HAVE_GREGSET_T
38 typedef struct reg gregset_t;
39 #endif
40
41 #ifndef HAVE_FPREGSET_T 
42 typedef struct fpreg fpregset_t; 
43 #endif 
44
45 #include "gregset.h"
46
47 /* Provide *regset() wrappers around the generic Alpha BSD register
48    supply/fill routines.  */
49
50 void
51 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
52 {
53   alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
54 }
55
56 void
57 fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
58 {
59   alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
60 }
61
62 void
63 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
64 {
65   alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
66 }
67
68 void
69 fill_fpregset (const struct regcache *regcache,
70                fpregset_t *fpregsetp, int regno)
71 {
72   alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
73 }
74 \f
75 /* Determine if PT_GETREGS fetches this register.  */
76
77 static int
78 getregs_supplies (int regno)
79 {
80   return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
81           || regno >= ALPHA_PC_REGNUM);
82 }
83
84 /* Fetch register REGNO from the inferior.  If REGNO is -1, do this
85    for all registers (including the floating point registers).  */
86
87 static void
88 alphabsd_fetch_inferior_registers (struct target_ops *ops,
89                                    struct regcache *regcache, int regno)
90 {
91   if (regno == -1 || getregs_supplies (regno))
92     {
93       struct reg gregs;
94
95       if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
96                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
97         perror_with_name (_("Couldn't get registers"));
98
99       alphabsd_supply_reg (regcache, (char *) &gregs, regno);
100       if (regno != -1)
101         return;
102     }
103
104   if (regno == -1
105       || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
106     {
107       struct fpreg fpregs;
108
109       if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
110                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
111         perror_with_name (_("Couldn't get floating point status"));
112
113       alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
114     }
115 }
116
117 /* Store register REGNO back into the inferior.  If REGNO is -1, do
118    this for all registers (including the floating point registers).  */
119
120 static void
121 alphabsd_store_inferior_registers (struct target_ops *ops,
122                                    struct regcache *regcache, int regno)
123 {
124   if (regno == -1 || getregs_supplies (regno))
125     {
126       struct reg gregs;
127       if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
128                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
129         perror_with_name (_("Couldn't get registers"));
130
131       alphabsd_fill_reg (regcache, (char *) &gregs, regno);
132
133       if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
134                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
135         perror_with_name (_("Couldn't write registers"));
136
137       if (regno != -1)
138         return;
139     }
140
141   if (regno == -1
142       || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
143     {
144       struct fpreg fpregs;
145
146       if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
147                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
148         perror_with_name (_("Couldn't get floating point status"));
149
150       alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
151
152       if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
153                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
154         perror_with_name (_("Couldn't write floating point status"));
155     }
156 }
157 \f
158
159 /* Support for debugging kernel virtual memory images.  */
160
161 #include <sys/types.h>
162 #include <sys/signal.h>
163 #include <machine/pcb.h>
164
165 #include "bsd-kvm.h"
166
167 static int
168 alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
169 {
170   int regnum;
171
172   /* The following is true for OpenBSD 3.9:
173
174      The pcb contains the register state at the context switch inside
175      cpu_switch().  */
176
177   /* The stack pointer shouldn't be zero.  */
178   if (pcb->pcb_hw.apcb_ksp == 0)
179     return 0;
180
181   regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
182
183   for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
184     regcache_raw_supply (regcache, regnum,
185                          &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
186   regcache_raw_supply (regcache, ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
187
188   return 1;
189 }
190 \f
191
192 /* Provide a prototype to silence -Wmissing-prototypes.  */
193 void _initialize_alphabsd_nat (void);
194
195 void
196 _initialize_alphabsd_nat (void)
197 {
198   struct target_ops *t;
199
200   t = inf_ptrace_target ();
201   t->to_fetch_registers = alphabsd_fetch_inferior_registers;
202   t->to_store_registers = alphabsd_store_inferior_registers;
203   add_target (t);
204
205   /* Support debugging kernel virtual memory images.  */
206   bsd_kvm_add_target (alphabsd_supply_pcb);
207 }