import gdb-19990422 snapshot
[deliverable/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
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "inferior.h"
22#include "gdbcore.h"
23
24#include <sys/ptrace.h>
25#define KERNEL /* To get floating point reg definitions */
26#include <machine/reg.h>
27
28static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR));
29
30void
31fetch_inferior_registers (regno)
32 int regno;
33{
34 struct regs inferior_registers;
35#ifdef FP0_REGNUM
36 struct fp_status inferior_fp_registers;
37#endif
c906108c
SS
38
39 registers_fetched ();
40
41 ptrace (PTRACE_GETREGS, inferior_pid,
42 (PTRACE_ARG3_TYPE) &inferior_registers);
43#ifdef FP0_REGNUM
44 ptrace (PTRACE_GETFPREGS, inferior_pid,
45 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
46#endif
47
48 memcpy (registers, &inferior_registers, 16 * 4);
49#ifdef FP0_REGNUM
50 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
51 sizeof inferior_fp_registers.fps_regs);
52#endif
53 *(int *)&registers[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
54 *(int *)&registers[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
55#ifdef FP0_REGNUM
56 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
57 &inferior_fp_registers.fps_control,
58 sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
59#endif
60}
61
62/* Store our register values back into the inferior.
63 If REGNO is -1, do this for all registers.
64 Otherwise, REGNO specifies which register (so we can save time). */
65
66void
67store_inferior_registers (regno)
68 int regno;
69{
70 struct regs inferior_registers;
71#ifdef FP0_REGNUM
72 struct fp_status inferior_fp_registers;
73#endif
c906108c
SS
74
75 memcpy (&inferior_registers, registers, 16 * 4);
76#ifdef FP0_REGNUM
77 memcpy (&inferior_fp_registers, &registers[REGISTER_BYTE (FP0_REGNUM)],
78 sizeof inferior_fp_registers.fps_regs);
79#endif
80 inferior_registers.r_ps = *(int *)&registers[REGISTER_BYTE (PS_REGNUM)];
81 inferior_registers.r_pc = *(int *)&registers[REGISTER_BYTE (PC_REGNUM)];
82
83#ifdef FP0_REGNUM
84 memcpy (&inferior_fp_registers.fps_control,
85 &registers[REGISTER_BYTE (FPC_REGNUM)],
86 sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
87#endif
88
89 ptrace (PTRACE_SETREGS, inferior_pid,
90 (PTRACE_ARG3_TYPE) &inferior_registers);
91#if FP0_REGNUM
92 ptrace (PTRACE_SETFPREGS, inferior_pid,
93 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
94#endif
95}
96
97
98/* All of this stuff is only relevant if both host and target are sun3. */
99/* Machine-dependent code for pulling registers out of a Sun-3 core file. */
100
101static void
102fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
103 char *core_reg_sect;
104 unsigned core_reg_size;
105 int which;
106 CORE_ADDR reg_addr; /* Unused in this version */
107{
c906108c
SS
108 struct regs *regs = (struct regs *) core_reg_sect;
109
110 if (which == 0) {
111 if (core_reg_size < sizeof (struct regs))
112 error ("Can't find registers in core file");
113
114 memcpy (registers, (char *)regs, 16 * 4);
115 supply_register (PS_REGNUM, (char *)&regs->r_ps);
116 supply_register (PC_REGNUM, (char *)&regs->r_pc);
117
118 } else if (which == 2) {
119
120#define fpustruct ((struct fpu *) core_reg_sect)
121
122 if (core_reg_size >= sizeof (struct fpu))
123 {
124#ifdef FP0_REGNUM
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#endif
133 }
134 else
135 fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n");
136 }
137}
138
139\f
140/* Register that we are able to handle sun3 core file formats.
141 FIXME: is this really bfd_target_unknown_flavour? */
142
143static struct core_fns sun3_core_fns =
144{
145 bfd_target_unknown_flavour,
146 fetch_core_registers,
147 NULL
148};
149
150void
151_initialize_core_sun3 ()
152{
153 add_core_fns (&sun3_core_fns);
154}
This page took 0.031147 seconds and 4 git commands to generate.