]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Host-dependent code for Sun-3 for GDB, the GNU debugger. |
b6ba6518 KB |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1996, 1999, 2000, 2001 |
3 | Free Software Foundation, Inc. | |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program 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 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program 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. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "inferior.h" | |
24 | #include "gdbcore.h" | |
4e052eda | 25 | #include "regcache.h" |
c906108c SS |
26 | |
27 | #include <sys/ptrace.h> | |
c5aa993b | 28 | #define KERNEL /* To get floating point reg definitions */ |
c906108c SS |
29 | #include <machine/reg.h> |
30 | ||
a14ed312 | 31 | static void fetch_core_registers (char *, unsigned, int, CORE_ADDR); |
c906108c SS |
32 | |
33 | void | |
fba45db2 | 34 | fetch_inferior_registers (int regno) |
c906108c SS |
35 | { |
36 | struct regs inferior_registers; | |
c906108c | 37 | struct fp_status inferior_fp_registers; |
c906108c SS |
38 | |
39 | registers_fetched (); | |
c5aa993b | 40 | |
39f77062 | 41 | ptrace (PTRACE_GETREGS, PIDGET (inferior_ptid), |
c5aa993b | 42 | (PTRACE_ARG3_TYPE) & inferior_registers); |
60054393 MS |
43 | |
44 | if (FP0_REGNUM >= 0) | |
39f77062 | 45 | ptrace (PTRACE_GETFPREGS, PIDGET (inferior_ptid), |
60054393 | 46 | (PTRACE_ARG3_TYPE) & inferior_fp_registers); |
c5aa993b | 47 | |
c906108c | 48 | memcpy (registers, &inferior_registers, 16 * 4); |
60054393 MS |
49 | if (FP0_REGNUM >= 0) |
50 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers, | |
51 | sizeof inferior_fp_registers.fps_regs); | |
52 | ||
c5aa993b JM |
53 | *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps; |
54 | *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc; | |
60054393 MS |
55 | if (FP0_REGNUM >= 0) |
56 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
57 | &inferior_fp_registers.fps_control, | |
58 | sizeof inferior_fp_registers - | |
59 | sizeof inferior_fp_registers.fps_regs); | |
c906108c SS |
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 | ||
66 | void | |
fba45db2 | 67 | store_inferior_registers (int regno) |
c906108c SS |
68 | { |
69 | struct regs inferior_registers; | |
c906108c | 70 | struct fp_status inferior_fp_registers; |
c906108c SS |
71 | |
72 | memcpy (&inferior_registers, registers, 16 * 4); | |
60054393 MS |
73 | if (FP0_REGNUM >= 0) |
74 | memcpy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
75 | sizeof inferior_fp_registers.fps_regs); | |
76 | ||
c5aa993b JM |
77 | inferior_registers.r_ps = *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)]; |
78 | inferior_registers.r_pc = *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)]; | |
c906108c | 79 | |
60054393 MS |
80 | if (FP0_REGNUM >= 0) |
81 | memcpy (&inferior_fp_registers.fps_control, | |
82 | ®isters[REGISTER_BYTE (FPC_REGNUM)], | |
83 | sizeof inferior_fp_registers - | |
84 | sizeof inferior_fp_registers.fps_regs); | |
c906108c | 85 | |
39f77062 | 86 | ptrace (PTRACE_SETREGS, PIDGET (inferior_ptid), |
c5aa993b | 87 | (PTRACE_ARG3_TYPE) & inferior_registers); |
60054393 | 88 | if (FP0_REGNUM >= 0) |
39f77062 | 89 | ptrace (PTRACE_SETFPREGS, PIDGET (inferior_ptid), |
60054393 | 90 | (PTRACE_ARG3_TYPE) & inferior_fp_registers); |
c906108c SS |
91 | } |
92 | ||
93 | ||
94 | /* All of this stuff is only relevant if both host and target are sun3. */ | |
38ef650e KB |
95 | |
96 | /* Provide registers to GDB from a core file. | |
97 | ||
98 | CORE_REG_SECT points to an array of bytes, which were obtained from | |
99 | a core file which BFD thinks might contain register contents. | |
100 | CORE_REG_SIZE is its size. | |
101 | ||
102 | WHICH says which register set corelow suspects this is: | |
103 | 0 --- the general-purpose register set | |
104 | 2 --- the floating-point register set | |
105 | ||
106 | REG_ADDR isn't used. */ | |
c906108c SS |
107 | |
108 | static void | |
38ef650e KB |
109 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
110 | int which, CORE_ADDR reg_addr) | |
c906108c | 111 | { |
c906108c SS |
112 | struct regs *regs = (struct regs *) core_reg_sect; |
113 | ||
c5aa993b JM |
114 | if (which == 0) |
115 | { | |
116 | if (core_reg_size < sizeof (struct regs)) | |
117 | error ("Can't find registers in core file"); | |
c906108c | 118 | |
c5aa993b JM |
119 | memcpy (registers, (char *) regs, 16 * 4); |
120 | supply_register (PS_REGNUM, (char *) ®s->r_ps); | |
121 | supply_register (PC_REGNUM, (char *) ®s->r_pc); | |
c906108c | 122 | |
c5aa993b JM |
123 | } |
124 | else if (which == 2) | |
125 | { | |
c906108c SS |
126 | |
127 | #define fpustruct ((struct fpu *) core_reg_sect) | |
128 | ||
c5aa993b JM |
129 | if (core_reg_size >= sizeof (struct fpu)) |
130 | { | |
60054393 MS |
131 | if (FP0_REGNUM >= 0) |
132 | { | |
133 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], | |
134 | fpustruct->f_fpstatus.fps_regs, | |
135 | sizeof fpustruct->f_fpstatus.fps_regs); | |
136 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
137 | &fpustruct->f_fpstatus.fps_control, | |
138 | sizeof fpustruct->f_fpstatus - | |
139 | sizeof fpustruct->f_fpstatus.fps_regs); | |
140 | } | |
c5aa993b JM |
141 | } |
142 | else | |
60054393 MS |
143 | fprintf_unfiltered (gdb_stderr, |
144 | "Couldn't read float regs from core file\n"); | |
c5aa993b | 145 | } |
c906108c | 146 | } |
c906108c | 147 | \f |
c5aa993b | 148 | |
c906108c SS |
149 | /* Register that we are able to handle sun3 core file formats. |
150 | FIXME: is this really bfd_target_unknown_flavour? */ | |
151 | ||
152 | static struct core_fns sun3_core_fns = | |
153 | { | |
2acceee2 JM |
154 | bfd_target_unknown_flavour, /* core_flavour */ |
155 | default_check_format, /* check_format */ | |
156 | default_core_sniffer, /* core_sniffer */ | |
157 | fetch_core_registers, /* core_read_registers */ | |
158 | NULL /* next */ | |
c906108c SS |
159 | }; |
160 | ||
161 | void | |
fba45db2 | 162 | _initialize_core_sun3 (void) |
c906108c SS |
163 | { |
164 | add_core_fns (&sun3_core_fns); | |
165 | } |