Johns release
[deliverable/binutils-gdb.git] / gdb / sun3-xdep.c
1 /* Sun-3 Machine-dependent code which would otherwise be in inflow.c and core.c,
2 for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 GDB is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
10 any later version.
11
12 GDB is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GDB; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include <stdio.h>
22 #include "defs.h"
23 #include "param.h"
24 #include "inferior.h"
25
26 #include <sys/ptrace.h>
27 #define KERNEL /* To get floating point reg definitions */
28 #include <machine/reg.h>
29
30 #include "gdbcore.h"
31
32 extern int errno;
33
34 void
35 fetch_inferior_registers ()
36 {
37 struct regs inferior_registers;
38 #ifdef FP0_REGNUM
39 struct fp_status inferior_fp_registers;
40 #endif
41 extern char registers[];
42
43 registers_fetched ();
44
45 ptrace (PTRACE_GETREGS, inferior_pid, &inferior_registers);
46 #ifdef FP0_REGNUM
47 ptrace (PTRACE_GETFPREGS, inferior_pid, &inferior_fp_registers);
48 #endif
49
50 bcopy (&inferior_registers, registers, 16 * 4);
51 #ifdef FP0_REGNUM
52 bcopy (&inferior_fp_registers, &registers[REGISTER_BYTE (FP0_REGNUM)],
53 sizeof inferior_fp_registers.fps_regs);
54 #endif
55 *(int *)&registers[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
56 *(int *)&registers[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
57 #ifdef FP0_REGNUM
58 bcopy (&inferior_fp_registers.fps_control,
59 &registers[REGISTER_BYTE (FPC_REGNUM)],
60 sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
61 #endif
62 }
63
64 /* Store our register values back into the inferior.
65 If REGNO is -1, do this for all registers.
66 Otherwise, REGNO specifies which register (so we can save time). */
67
68 store_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
75 extern char registers[];
76
77 bcopy (registers, &inferior_registers, 16 * 4);
78 #ifdef FP0_REGNUM
79 bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
80 sizeof inferior_fp_registers.fps_regs);
81 #endif
82 inferior_registers.r_ps = *(int *)&registers[REGISTER_BYTE (PS_REGNUM)];
83 inferior_registers.r_pc = *(int *)&registers[REGISTER_BYTE (PC_REGNUM)];
84
85 #ifdef FP0_REGNUM
86 bcopy (&registers[REGISTER_BYTE (FPC_REGNUM)],
87 &inferior_fp_registers.fps_control,
88 sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
89 #endif
90
91 ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers);
92 #if FP0_REGNUM
93 ptrace (PTRACE_SETFPREGS, inferior_pid, &inferior_fp_registers);
94 #endif
95 }
96
97 /* Machine-dependent code for pulling registers out of a Sun-3 core file. */
98
99 void
100 fetch_core_registers (core_reg_sect, core_reg_size, which)
101 char *core_reg_sect;
102 unsigned core_reg_size;
103 int which;
104 {
105 extern char registers[];
106 struct regs *regs = (struct regs *) core_reg_sect;
107
108 if (which == 0) {
109 if (core_reg_size < sizeof (struct regs))
110 error ("Can't find registers in core file");
111
112 bcopy ((char *)regs, registers, 16 * 4);
113 supply_register (PS_REGNUM, &regs->r_ps);
114 supply_register (PC_REGNUM, &regs->r_pc);
115
116 } else if (which == 2) {
117
118 #define fpustruct ((struct fpu *) core_reg_sect)
119
120 if (core_reg_size >= sizeof (struct fpu))
121 {
122 bcopy (fpustruct->f_fpstatus.fps_regs,
123 &registers[REGISTER_BYTE (FP0_REGNUM)],
124 sizeof fpustruct->f_fpstatus.fps_regs);
125 bcopy (&fpustruct->f_fpstatus.fps_control,
126 &registers[REGISTER_BYTE (FPC_REGNUM)],
127 sizeof fpustruct->f_fpstatus -
128 sizeof fpustruct->f_fpstatus.fps_regs);
129 }
130 else
131 fprintf (stderr, "Couldn't read float regs from core file\n");
132 }
133 }
This page took 0.03256 seconds and 5 git commands to generate.