Protoization.
[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 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include <sys/types.h>
22 #include <sys/ptrace.h>
23 #include <machine/reg.h>
24 #include <machine/frame.h>
25
26 #include "defs.h"
27 #include "inferior.h"
28 #include "gdbcore.h"
29
30 #define RF(dst, src) \
31         memcpy(&registers[REGISTER_BYTE(dst)], &src, sizeof(src))
32    
33 #define RS(src, dst) \
34         memcpy(&dst, &registers[REGISTER_BYTE(src)], sizeof(dst))
35
36 void
37 fetch_inferior_registers (int regno)
38 {
39   struct reg inferior_registers;
40   struct fpreg inferior_fp_registers;
41   int i;
42
43   ptrace (PT_GETREGS, inferior_pid,
44           (PTRACE_ARG3_TYPE) & inferior_registers, 0);
45   for (i = 0; i < 32; i++)
46     RF (i, inferior_registers.fixreg[i]);
47   RF (LR_REGNUM, inferior_registers.lr);
48   RF (CR_REGNUM, inferior_registers.cr);
49   RF (XER_REGNUM, inferior_registers.xer);
50   RF (CTR_REGNUM, inferior_registers.ctr);
51   RF (PC_REGNUM, inferior_registers.pc);
52
53   ptrace (PT_GETFPREGS, inferior_pid,
54           (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0);
55   for (i = 0; i < 32; i++)
56     RF (FP0_REGNUM + i, inferior_fp_registers.r_regs[i]);
57
58   registers_fetched ();
59 }
60
61 void
62 store_inferior_registers (int regno)
63 {
64   struct reg inferior_registers;
65   struct fpreg inferior_fp_registers;
66   int i;
67
68   for (i = 0; i < 32; i++)
69     RS (i, inferior_registers.fixreg[i]);
70   RS (LR_REGNUM, inferior_registers.lr);
71   RS (CR_REGNUM, inferior_registers.cr);
72   RS (XER_REGNUM, inferior_registers.xer);
73   RS (CTR_REGNUM, inferior_registers.ctr);
74   RS (PC_REGNUM, inferior_registers.pc);
75
76   ptrace (PT_SETREGS, inferior_pid,
77           (PTRACE_ARG3_TYPE) & inferior_registers, 0);
78
79   for (i = 0; i < 32; i++)
80     RS (FP0_REGNUM + i, inferior_fp_registers.r_regs[i]);
81   ptrace (PT_SETFPREGS, inferior_pid,
82           (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0);
83 }
84
85 struct md_core
86 {
87   struct reg intreg;
88   struct fpreg freg;
89 };
90
91 void
92 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
93                       CORE_ADDR ignore)
94 {
95   struct md_core *core_reg = (struct md_core *) core_reg_sect;
96   int i;
97
98   /* Integer registers */
99   for (i = 0; i < 32; i++)
100     RF (i, core_reg->intreg.fixreg[i]);
101   RF (LR_REGNUM, core_reg->intreg.lr);
102   RF (CR_REGNUM, core_reg->intreg.cr);
103   RF (XER_REGNUM, core_reg->intreg.xer);
104   RF (CTR_REGNUM, core_reg->intreg.ctr);
105   RF (PC_REGNUM, core_reg->intreg.pc);
106
107   /* Floating point registers */
108   for (i = 0; i < 32; i++)
109     RF (FP0_REGNUM + i, core_reg->freg.r_regs[i]);
110
111   registers_fetched ();
112 }
113
114 /* Register that we are able to handle ppcnbsd core file formats.
115    FIXME: is this really bfd_target_unknown_flavour? */
116
117 static struct core_fns ppcnbsd_core_fns =
118 {
119   bfd_target_unknown_flavour,           /* core_flavour */
120   default_check_format,                 /* check_format */
121   default_core_sniffer,                 /* core_sniffer */
122   fetch_core_registers,                 /* core_read_registers */
123   NULL                                  /* next */
124 };
125
126 void
127 _initialize_ppcnbsd_nat (void)
128 {
129   add_core_fns (&ppcnbsd_core_fns);
130 }