Phase 1 of the ptid_t changes.
[external/binutils.git] / gdb / ppcnbsd-nat.c
1 /* Native-dependent code for PowerPC's running NetBSD, for GDB.
2    Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001
3    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 <sys/types.h>
23 #include <sys/ptrace.h>
24 #include <machine/reg.h>
25 #include <machine/frame.h>
26
27 #include "defs.h"
28 #include "inferior.h"
29 #include "gdbcore.h"
30 #include "ppc-tdep.h"
31 #include "regcache.h"
32
33 #define RF(dst, src) \
34         memcpy(&registers[REGISTER_BYTE(dst)], &src, sizeof(src))
35    
36 #define RS(src, dst) \
37         memcpy(&dst, &registers[REGISTER_BYTE(src)], sizeof(dst))
38
39 void
40 fetch_inferior_registers (int regno)
41 {
42   struct reg inferior_registers;
43 #ifdef PT_GETFPREGS
44   struct fpreg inferior_fp_registers;
45 #endif
46   int i;
47
48   ptrace (PT_GETREGS, PIDGET (inferior_ptid),
49           (PTRACE_ARG3_TYPE) & inferior_registers, 0);
50   for (i = 0; i < 32; i++)
51     RF (i, inferior_registers.fixreg[i]);
52   RF (PPC_LR_REGNUM, inferior_registers.lr);
53   RF (PPC_CR_REGNUM, inferior_registers.cr);
54   RF (PPC_XER_REGNUM, inferior_registers.xer);
55   RF (PPC_CTR_REGNUM, inferior_registers.ctr);
56   RF (PC_REGNUM, inferior_registers.pc);
57
58 #ifdef PT_GETFPREGS
59   ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
60           (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
61   for (i = 0; i < 32; i++)
62     RF (FP0_REGNUM + i, inferior_fp_registers.fpreg[i]);
63 #endif
64
65   registers_fetched ();
66 }
67
68 void
69 store_inferior_registers (int regno)
70 {
71   struct reg inferior_registers;
72 #ifdef PT_SETFPREGS
73   struct fpreg inferior_fp_registers;
74 #endif
75   int i;
76
77   for (i = 0; i < 32; i++)
78     RS (i, inferior_registers.fixreg[i]);
79   RS (PPC_LR_REGNUM, inferior_registers.lr);
80   RS (PPC_CR_REGNUM, inferior_registers.cr);
81   RS (PPC_XER_REGNUM, inferior_registers.xer);
82   RS (PPC_CTR_REGNUM, inferior_registers.ctr);
83   RS (PC_REGNUM, inferior_registers.pc);
84
85   ptrace (PT_SETREGS, PIDGET (inferior_ptid),
86           (PTRACE_ARG3_TYPE) & inferior_registers, 0);
87
88 #ifdef PT_SETFPREGS
89   for (i = 0; i < 32; i++)
90     RS (FP0_REGNUM + i, inferior_fp_registers.fpreg[i]);
91   ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
92           (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0);
93 #endif
94 }
95
96 struct md_core
97 {
98   struct reg intreg;
99 #ifdef PT_GETFPREGS
100   struct fpreg freg;
101 #endif
102 };
103
104 void
105 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
106                       CORE_ADDR ignore)
107 {
108   struct md_core *core_reg = (struct md_core *) core_reg_sect;
109   int i;
110
111   /* Integer registers */
112   for (i = 0; i < 32; i++)
113     RF (i, core_reg->intreg.fixreg[i]);
114   RF (PPC_LR_REGNUM, core_reg->intreg.lr);
115   RF (PPC_CR_REGNUM, core_reg->intreg.cr);
116   RF (PPC_XER_REGNUM, core_reg->intreg.xer);
117   RF (PPC_CTR_REGNUM, core_reg->intreg.ctr);
118   RF (PC_REGNUM, core_reg->intreg.pc);
119
120 #ifdef PT_FPGETREGS
121   /* Floating point registers */
122   for (i = 0; i < 32; i++)
123     RF (FP0_REGNUM + i, core_reg->freg.fpreg[i]);
124 #endif
125
126   registers_fetched ();
127 }
128
129 /* Register that we are able to handle ppcnbsd core file formats.
130    FIXME: is this really bfd_target_unknown_flavour? */
131
132 static struct core_fns ppcnbsd_core_fns =
133 {
134   bfd_target_unknown_flavour,           /* core_flavour */
135   default_check_format,                 /* check_format */
136   default_core_sniffer,                 /* core_sniffer */
137   fetch_core_registers,                 /* core_read_registers */
138   NULL                                  /* next */
139 };
140
141 void
142 _initialize_ppcnbsd_nat (void)
143 {
144   add_core_fns (&ppcnbsd_core_fns);
145 }