Add --enable-gdb-build-warnings=... to configure{,.in}.
[external/binutils.git] / gdb / sun3-nat.c
1 /* Host-dependent code for Sun-3 for GDB, the GNU debugger.
2    Copyright 1986, 1987, 1989, 1991, 1992 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 "defs.h"
22 #include "inferior.h"
23 #include "gdbcore.h"
24
25 #include <sys/ptrace.h>
26 #define KERNEL                  /* To get floating point reg definitions */
27 #include <machine/reg.h>
28
29 static void fetch_core_registers (char *, unsigned, int, CORE_ADDR);
30
31 void
32 fetch_inferior_registers (int regno)
33 {
34   struct regs inferior_registers;
35   struct fp_status inferior_fp_registers;
36
37   registers_fetched ();
38
39   ptrace (PTRACE_GETREGS, inferior_pid,
40           (PTRACE_ARG3_TYPE) & inferior_registers);
41
42   if (FP0_REGNUM >= 0)
43     ptrace (PTRACE_GETFPREGS, inferior_pid,
44             (PTRACE_ARG3_TYPE) & inferior_fp_registers);
45
46   memcpy (registers, &inferior_registers, 16 * 4);
47   if (FP0_REGNUM >= 0)
48     memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
49             sizeof inferior_fp_registers.fps_regs);
50
51   *(int *) &registers[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
52   *(int *) &registers[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
53   if (FP0_REGNUM >= 0)
54     memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
55             &inferior_fp_registers.fps_control,
56             sizeof inferior_fp_registers - 
57             sizeof inferior_fp_registers.fps_regs);
58 }
59
60 /* Store our register values back into the inferior.
61    If REGNO is -1, do this for all registers.
62    Otherwise, REGNO specifies which register (so we can save time).  */
63
64 void
65 store_inferior_registers (int regno)
66 {
67   struct regs inferior_registers;
68   struct fp_status inferior_fp_registers;
69
70   memcpy (&inferior_registers, registers, 16 * 4);
71   if (FP0_REGNUM >= 0)
72     memcpy (&inferior_fp_registers, &registers[REGISTER_BYTE (FP0_REGNUM)],
73             sizeof inferior_fp_registers.fps_regs);
74
75   inferior_registers.r_ps = *(int *) &registers[REGISTER_BYTE (PS_REGNUM)];
76   inferior_registers.r_pc = *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
77
78   if (FP0_REGNUM >= 0)
79     memcpy (&inferior_fp_registers.fps_control,
80             &registers[REGISTER_BYTE (FPC_REGNUM)],
81             sizeof inferior_fp_registers - 
82             sizeof inferior_fp_registers.fps_regs);
83
84   ptrace (PTRACE_SETREGS, inferior_pid,
85           (PTRACE_ARG3_TYPE) & inferior_registers);
86   if (FP0_REGNUM >= 0)
87     ptrace (PTRACE_SETFPREGS, inferior_pid,
88             (PTRACE_ARG3_TYPE) & inferior_fp_registers);
89 }
90
91
92 /* All of this stuff is only relevant if both host and target are sun3.  */
93
94 /* Provide registers to GDB from a core file.
95
96    CORE_REG_SECT points to an array of bytes, which were obtained from
97    a core file which BFD thinks might contain register contents. 
98    CORE_REG_SIZE is its size.
99
100    WHICH says which register set corelow suspects this is:
101      0 --- the general-purpose register set
102      2 --- the floating-point register set
103
104    REG_ADDR isn't used.  */
105
106 static void
107 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
108                       int which, CORE_ADDR reg_addr)
109 {
110   struct regs *regs = (struct regs *) core_reg_sect;
111
112   if (which == 0)
113     {
114       if (core_reg_size < sizeof (struct regs))
115           error ("Can't find registers in core file");
116
117       memcpy (registers, (char *) regs, 16 * 4);
118       supply_register (PS_REGNUM, (char *) &regs->r_ps);
119       supply_register (PC_REGNUM, (char *) &regs->r_pc);
120
121     }
122   else if (which == 2)
123     {
124
125 #define fpustruct  ((struct fpu *) core_reg_sect)
126
127       if (core_reg_size >= sizeof (struct fpu))
128         {
129           if (FP0_REGNUM >= 0)
130             {
131               memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
132                       fpustruct->f_fpstatus.fps_regs,
133                       sizeof fpustruct->f_fpstatus.fps_regs);
134               memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
135                       &fpustruct->f_fpstatus.fps_control,
136                       sizeof fpustruct->f_fpstatus -
137                       sizeof fpustruct->f_fpstatus.fps_regs);
138             }
139         }
140       else
141         fprintf_unfiltered (gdb_stderr, 
142                             "Couldn't read float regs from core file\n");
143     }
144 }
145 \f
146
147 /* Register that we are able to handle sun3 core file formats.
148    FIXME: is this really bfd_target_unknown_flavour? */
149
150 static struct core_fns sun3_core_fns =
151 {
152   bfd_target_unknown_flavour,           /* core_flavour */
153   default_check_format,                 /* check_format */
154   default_core_sniffer,                 /* core_sniffer */
155   fetch_core_registers,                 /* core_read_registers */
156   NULL                                  /* next */
157 };
158
159 void
160 _initialize_core_sun3 (void)
161 {
162   add_core_fns (&sun3_core_fns);
163 }