]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sun3-nat.c
2000-05-08 Michael Snyder <msnyder@seadog.cygnus.com>
[thirdparty/binutils-gdb.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 PARAMS ((char *, unsigned, int, CORE_ADDR));
30
31 void
32 fetch_inferior_registers (regno)
33 int regno;
34 {
35 struct regs inferior_registers;
36 struct fp_status inferior_fp_registers;
37
38 registers_fetched ();
39
40 ptrace (PTRACE_GETREGS, inferior_pid,
41 (PTRACE_ARG3_TYPE) & inferior_registers);
42
43 if (FP0_REGNUM >= 0)
44 ptrace (PTRACE_GETFPREGS, inferior_pid,
45 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
46
47 memcpy (registers, &inferior_registers, 16 * 4);
48 if (FP0_REGNUM >= 0)
49 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
50 sizeof inferior_fp_registers.fps_regs);
51
52 *(int *) &registers[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
53 *(int *) &registers[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
54 if (FP0_REGNUM >= 0)
55 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
56 &inferior_fp_registers.fps_control,
57 sizeof inferior_fp_registers -
58 sizeof inferior_fp_registers.fps_regs);
59 }
60
61 /* Store our register values back into the inferior.
62 If REGNO is -1, do this for all registers.
63 Otherwise, REGNO specifies which register (so we can save time). */
64
65 void
66 store_inferior_registers (regno)
67 int regno;
68 {
69 struct regs inferior_registers;
70 struct fp_status inferior_fp_registers;
71
72 memcpy (&inferior_registers, registers, 16 * 4);
73 if (FP0_REGNUM >= 0)
74 memcpy (&inferior_fp_registers, &registers[REGISTER_BYTE (FP0_REGNUM)],
75 sizeof inferior_fp_registers.fps_regs);
76
77 inferior_registers.r_ps = *(int *) &registers[REGISTER_BYTE (PS_REGNUM)];
78 inferior_registers.r_pc = *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
79
80 if (FP0_REGNUM >= 0)
81 memcpy (&inferior_fp_registers.fps_control,
82 &registers[REGISTER_BYTE (FPC_REGNUM)],
83 sizeof inferior_fp_registers -
84 sizeof inferior_fp_registers.fps_regs);
85
86 ptrace (PTRACE_SETREGS, inferior_pid,
87 (PTRACE_ARG3_TYPE) & inferior_registers);
88 if (FP0_REGNUM >= 0)
89 ptrace (PTRACE_SETFPREGS, inferior_pid,
90 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
91 }
92
93
94 /* All of this stuff is only relevant if both host and target are sun3. */
95 /* Machine-dependent code for pulling registers out of a Sun-3 core file. */
96
97 static void
98 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
99 char *core_reg_sect;
100 unsigned core_reg_size;
101 int which;
102 CORE_ADDR reg_addr; /* Unused in this version */
103 {
104 struct regs *regs = (struct regs *) core_reg_sect;
105
106 if (which == 0)
107 {
108 if (core_reg_size < sizeof (struct regs))
109 error ("Can't find registers in core file");
110
111 memcpy (registers, (char *) regs, 16 * 4);
112 supply_register (PS_REGNUM, (char *) &regs->r_ps);
113 supply_register (PC_REGNUM, (char *) &regs->r_pc);
114
115 }
116 else if (which == 2)
117 {
118
119 #define fpustruct ((struct fpu *) core_reg_sect)
120
121 if (core_reg_size >= sizeof (struct fpu))
122 {
123 if (FP0_REGNUM >= 0)
124 {
125 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
126 fpustruct->f_fpstatus.fps_regs,
127 sizeof fpustruct->f_fpstatus.fps_regs);
128 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
129 &fpustruct->f_fpstatus.fps_control,
130 sizeof fpustruct->f_fpstatus -
131 sizeof fpustruct->f_fpstatus.fps_regs);
132 }
133 }
134 else
135 fprintf_unfiltered (gdb_stderr,
136 "Couldn't read float regs from core file\n");
137 }
138 }
139 \f
140
141 /* Register that we are able to handle sun3 core file formats.
142 FIXME: is this really bfd_target_unknown_flavour? */
143
144 static struct core_fns sun3_core_fns =
145 {
146 bfd_target_unknown_flavour, /* core_flavour */
147 default_check_format, /* check_format */
148 default_core_sniffer, /* core_sniffer */
149 fetch_core_registers, /* core_read_registers */
150 NULL /* next */
151 };
152
153 void
154 _initialize_core_sun3 ()
155 {
156 add_core_fns (&sun3_core_fns);
157 }