]>
Commit | Line | Data |
---|---|---|
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 | ||
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, 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 | ||
28 | static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR)); | |
29 | ||
30 | void | |
31 | fetch_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 | |
38 | extern char registers[]; | |
39 | ||
40 | registers_fetched (); | |
41 | ||
42 | ptrace (PTRACE_GETREGS, inferior_pid, | |
43 | (PTRACE_ARG3_TYPE) &inferior_registers); | |
44 | #ifdef FP0_REGNUM | |
45 | ptrace (PTRACE_GETFPREGS, inferior_pid, | |
46 | (PTRACE_ARG3_TYPE) &inferior_fp_registers); | |
47 | #endif | |
48 | ||
49 | memcpy (registers, &inferior_registers, 16 * 4); | |
50 | #ifdef FP0_REGNUM | |
51 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers, | |
52 | sizeof inferior_fp_registers.fps_regs); | |
53 | #endif | |
54 | *(int *)®isters[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps; | |
55 | *(int *)®isters[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc; | |
56 | #ifdef FP0_REGNUM | |
57 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
58 | &inferior_fp_registers.fps_control, | |
59 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs); | |
60 | #endif | |
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 | ||
67 | void | |
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 | memcpy (&inferior_registers, registers, 16 * 4); | |
78 | #ifdef FP0_REGNUM | |
79 | memcpy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
80 | sizeof inferior_fp_registers.fps_regs); | |
81 | #endif | |
82 | inferior_registers.r_ps = *(int *)®isters[REGISTER_BYTE (PS_REGNUM)]; | |
83 | inferior_registers.r_pc = *(int *)®isters[REGISTER_BYTE (PC_REGNUM)]; | |
84 | ||
85 | #ifdef FP0_REGNUM | |
86 | memcpy (&inferior_fp_registers.fps_control, | |
87 | ®isters[REGISTER_BYTE (FPC_REGNUM)], | |
88 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs); | |
89 | #endif | |
90 | ||
91 | ptrace (PTRACE_SETREGS, inferior_pid, | |
92 | (PTRACE_ARG3_TYPE) &inferior_registers); | |
93 | #if FP0_REGNUM | |
94 | ptrace (PTRACE_SETFPREGS, inferior_pid, | |
95 | (PTRACE_ARG3_TYPE) &inferior_fp_registers); | |
96 | #endif | |
97 | } | |
98 | ||
99 | ||
100 | /* All of this stuff is only relevant if both host and target are sun3. */ | |
101 | /* Machine-dependent code for pulling registers out of a Sun-3 core file. */ | |
102 | ||
103 | static void | |
104 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) | |
105 | char *core_reg_sect; | |
106 | unsigned core_reg_size; | |
107 | int which; | |
108 | CORE_ADDR reg_addr; /* Unused in this version */ | |
109 | { | |
110 | extern char registers[]; | |
111 | struct regs *regs = (struct regs *) core_reg_sect; | |
112 | ||
113 | if (which == 0) { | |
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 *)®s->r_ps); | |
119 | supply_register (PC_REGNUM, (char *)®s->r_pc); | |
120 | ||
121 | } else if (which == 2) { | |
122 | ||
123 | #define fpustruct ((struct fpu *) core_reg_sect) | |
124 | ||
125 | if (core_reg_size >= sizeof (struct fpu)) | |
126 | { | |
127 | #ifdef FP0_REGNUM | |
128 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], | |
129 | fpustruct->f_fpstatus.fps_regs, | |
130 | sizeof fpustruct->f_fpstatus.fps_regs); | |
131 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
132 | &fpustruct->f_fpstatus.fps_control, | |
133 | sizeof fpustruct->f_fpstatus - | |
134 | sizeof fpustruct->f_fpstatus.fps_regs); | |
135 | #endif | |
136 | } | |
137 | else | |
138 | fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n"); | |
139 | } | |
140 | } | |
141 | ||
142 | \f | |
143 | /* Register that we are able to handle sun3 core file formats. | |
144 | FIXME: is this really bfd_target_unknown_flavour? */ | |
145 | ||
146 | static struct core_fns sun3_core_fns = | |
147 | { | |
148 | bfd_target_unknown_flavour, | |
149 | fetch_core_registers, | |
150 | NULL | |
151 | }; | |
152 | ||
153 | void | |
154 | _initialize_core_sun3 () | |
155 | { | |
156 | add_core_fns (&sun3_core_fns); | |
157 | } |