]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/sun3-nat.c
import gdb-1999-07-07 post reformat
[thirdparty/binutils-gdb.git] / gdb / sun3-nat.c
CommitLineData
c906108c
SS
1/* Host-dependent code for Sun-3 for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b
JM
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. */
c906108c
SS
20
21#include "defs.h"
22#include "inferior.h"
23#include "gdbcore.h"
24
25#include <sys/ptrace.h>
c5aa993b 26#define KERNEL /* To get floating point reg definitions */
c906108c
SS
27#include <machine/reg.h>
28
29static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR));
30
31void
32fetch_inferior_registers (regno)
33 int regno;
34{
35 struct regs inferior_registers;
36#ifdef FP0_REGNUM
37 struct fp_status inferior_fp_registers;
38#endif
c906108c
SS
39
40 registers_fetched ();
c5aa993b 41
c906108c 42 ptrace (PTRACE_GETREGS, inferior_pid,
c5aa993b 43 (PTRACE_ARG3_TYPE) & inferior_registers);
c906108c
SS
44#ifdef FP0_REGNUM
45 ptrace (PTRACE_GETFPREGS, inferior_pid,
c5aa993b
JM
46 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
47#endif
48
c906108c
SS
49 memcpy (registers, &inferior_registers, 16 * 4);
50#ifdef FP0_REGNUM
51 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
c5aa993b
JM
52 sizeof inferior_fp_registers.fps_regs);
53#endif
54 *(int *) &registers[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
55 *(int *) &registers[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
c906108c
SS
56#ifdef FP0_REGNUM
57 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
c5aa993b
JM
58 &inferior_fp_registers.fps_control,
59 sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
60#endif
c906108c
SS
61}
62
63/* Store our register values back into the inferior.
64 If REGNO is -1, do this for all registers.
65 Otherwise, REGNO specifies which register (so we can save time). */
66
67void
68store_inferior_registers (regno)
69 int regno;
70{
71 struct regs inferior_registers;
72#ifdef FP0_REGNUM
73 struct fp_status inferior_fp_registers;
74#endif
c906108c
SS
75
76 memcpy (&inferior_registers, registers, 16 * 4);
77#ifdef FP0_REGNUM
78 memcpy (&inferior_fp_registers, &registers[REGISTER_BYTE (FP0_REGNUM)],
c5aa993b 79 sizeof inferior_fp_registers.fps_regs);
c906108c 80#endif
c5aa993b
JM
81 inferior_registers.r_ps = *(int *) &registers[REGISTER_BYTE (PS_REGNUM)];
82 inferior_registers.r_pc = *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
c906108c
SS
83
84#ifdef FP0_REGNUM
85 memcpy (&inferior_fp_registers.fps_control,
c5aa993b
JM
86 &registers[REGISTER_BYTE (FPC_REGNUM)],
87 sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
c906108c
SS
88#endif
89
90 ptrace (PTRACE_SETREGS, inferior_pid,
c5aa993b 91 (PTRACE_ARG3_TYPE) & inferior_registers);
c906108c
SS
92#if FP0_REGNUM
93 ptrace (PTRACE_SETFPREGS, inferior_pid,
c5aa993b 94 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
c906108c
SS
95#endif
96}
97
98
99/* All of this stuff is only relevant if both host and target are sun3. */
100/* Machine-dependent code for pulling registers out of a Sun-3 core file. */
101
102static void
103fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
104 char *core_reg_sect;
105 unsigned core_reg_size;
106 int which;
107 CORE_ADDR reg_addr; /* Unused in this version */
108{
c906108c
SS
109 struct regs *regs = (struct regs *) core_reg_sect;
110
c5aa993b
JM
111 if (which == 0)
112 {
113 if (core_reg_size < sizeof (struct regs))
114 error ("Can't find registers in core file");
c906108c 115
c5aa993b
JM
116 memcpy (registers, (char *) regs, 16 * 4);
117 supply_register (PS_REGNUM, (char *) &regs->r_ps);
118 supply_register (PC_REGNUM, (char *) &regs->r_pc);
c906108c 119
c5aa993b
JM
120 }
121 else if (which == 2)
122 {
c906108c
SS
123
124#define fpustruct ((struct fpu *) core_reg_sect)
125
c5aa993b
JM
126 if (core_reg_size >= sizeof (struct fpu))
127 {
c906108c 128#ifdef FP0_REGNUM
c5aa993b
JM
129 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
130 fpustruct->f_fpstatus.fps_regs,
131 sizeof fpustruct->f_fpstatus.fps_regs);
132 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
133 &fpustruct->f_fpstatus.fps_control,
134 sizeof fpustruct->f_fpstatus -
135 sizeof fpustruct->f_fpstatus.fps_regs);
c906108c 136#endif
c5aa993b
JM
137 }
138 else
139 fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n");
140 }
c906108c 141}
c906108c 142\f
c5aa993b 143
c906108c
SS
144/* Register that we are able to handle sun3 core file formats.
145 FIXME: is this really bfd_target_unknown_flavour? */
146
147static struct core_fns sun3_core_fns =
148{
149 bfd_target_unknown_flavour,
150 fetch_core_registers,
151 NULL
152};
153
154void
155_initialize_core_sun3 ()
156{
157 add_core_fns (&sun3_core_fns);
158}