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