]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/remote-vxsparc.c
import gdb-1999-07-07 post reformat
[thirdparty/binutils-gdb.git] / gdb / remote-vxsparc.c
1 /* sparc-dependent portions of the RPC protocol
2 used with a VxWorks target
3
4 Contributed by Wind River Systems.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include <stdio.h>
24 #include "defs.h"
25
26 #include "vx-share/regPacket.h"
27 #include "frame.h"
28 #include "inferior.h"
29 #include "wait.h"
30 #include "target.h"
31 #include "gdbcore.h"
32 #include "command.h"
33 #include "symtab.h"
34 #include "symfile.h" /* for struct complaint */
35
36 #include "gdb_string.h"
37 #include <errno.h>
38 #include <signal.h>
39 #include <fcntl.h>
40 #include <sys/types.h>
41 #include <sys/time.h>
42 #include <sys/socket.h>
43
44 #ifdef _AIX /* IBM claims "void *malloc()" not char * */
45 #define malloc bogon_malloc
46 #endif
47
48 #include <rpc/rpc.h>
49 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
50 #include <netdb.h>
51 #include "vx-share/ptrace.h"
52 #include "vx-share/xdr_ptrace.h"
53 #include "vx-share/xdr_ld.h"
54 #include "vx-share/xdr_rdb.h"
55 #include "vx-share/dbgRpcLib.h"
56
57 /* get rid of value.h if possible */
58 #include <value.h>
59 #include <symtab.h>
60
61 /* Flag set if target has fpu */
62
63 extern int target_has_fp;
64
65 /* sparc floating point format descriptor, from "sparc-tdep.c." */
66
67 extern struct ext_format ext_format_sparc;
68
69 /* Generic register read/write routines in remote-vx.c. */
70
71 extern void net_read_registers ();
72 extern void net_write_registers ();
73
74 /* Read a register or registers from the VxWorks target.
75 REGNO is the register to read, or -1 for all; currently,
76 it is ignored. FIXME look at regno to improve efficiency. */
77
78 void
79 vx_read_register (regno)
80 int regno;
81 {
82 char sparc_greg_packet[SPARC_GREG_PLEN];
83 char sparc_fpreg_packet[SPARC_FPREG_PLEN];
84 CORE_ADDR sp;
85
86 /* Get general-purpose registers. When copying values into
87 registers [], don't assume that a location in registers []
88 is properly aligned for the target data type. */
89
90 net_read_registers (sparc_greg_packet, SPARC_GREG_PLEN, PTRACE_GETREGS);
91
92 /* Now copy the register values into registers[].
93 Note that this code depends on the ordering of the REGNUMs
94 as defined in "tm-sparc.h". */
95
96 bcopy (&sparc_greg_packet[SPARC_R_G0],
97 &registers[REGISTER_BYTE (G0_REGNUM)], 32 * SPARC_GREG_SIZE);
98 bcopy (&sparc_greg_packet[SPARC_R_Y],
99 &registers[REGISTER_BYTE (Y_REGNUM)], 6 * SPARC_GREG_SIZE);
100
101 /* Now write the local and in registers to the register window
102 spill area in the frame. VxWorks does not do this for the
103 active frame automatically; it greatly simplifies debugging
104 (FRAME_FIND_SAVED_REGS, in particular, depends on this). */
105
106 sp = extract_address (&registers[REGISTER_BYTE (SP_REGNUM)],
107 REGISTER_RAW_SIZE (CORE_ADDR));
108 write_memory (sp, &registers[REGISTER_BYTE (L0_REGNUM)],
109 16 * REGISTER_RAW_SIZE (L0_REGNUM));
110
111 /* If the target has floating point registers, fetch them.
112 Otherwise, zero the floating point register values in
113 registers[] for good measure, even though we might not
114 need to. */
115
116 if (target_has_fp)
117 {
118 net_read_registers (sparc_fpreg_packet, SPARC_FPREG_PLEN,
119 PTRACE_GETFPREGS);
120 bcopy (&sparc_fpreg_packet[SPARC_R_FP0],
121 &registers[REGISTER_BYTE (FP0_REGNUM)], 32 * SPARC_FPREG_SIZE);
122 bcopy (&sparc_fpreg_packet[SPARC_R_FSR],
123 &registers[REGISTER_BYTE (FPS_REGNUM)], 1 * SPARC_FPREG_SIZE);
124 }
125 else
126 {
127 bzero (&registers[REGISTER_BYTE (FP0_REGNUM)], 32 * SPARC_FPREG_SIZE);
128 bzero (&registers[REGISTER_BYTE (FPS_REGNUM)], 1 * SPARC_FPREG_SIZE);
129 }
130
131 /* Mark the register cache valid. */
132
133 registers_fetched ();
134 }
135
136 /* Store a register or registers into the VxWorks target.
137 REGNO is the register to store, or -1 for all; currently,
138 it is ignored. FIXME look at regno to improve efficiency. */
139
140 void
141 vx_write_register (regno)
142 int regno;
143 {
144 char sparc_greg_packet[SPARC_GREG_PLEN];
145 char sparc_fpreg_packet[SPARC_FPREG_PLEN];
146 int in_gp_regs;
147 int in_fp_regs;
148 CORE_ADDR sp;
149
150 /* Store general purpose registers. When copying values from
151 registers [], don't assume that a location in registers []
152 is properly aligned for the target data type. */
153
154 in_gp_regs = 1;
155 in_fp_regs = 1;
156 if (regno >= 0)
157 {
158 if ((G0_REGNUM <= regno && regno <= I7_REGNUM)
159 || (Y_REGNUM <= regno && regno <= NPC_REGNUM))
160 in_fp_regs = 0;
161 else
162 in_gp_regs = 0;
163 }
164 if (in_gp_regs)
165 {
166 bcopy (&registers[REGISTER_BYTE (G0_REGNUM)],
167 &sparc_greg_packet[SPARC_R_G0], 32 * SPARC_GREG_SIZE);
168 bcopy (&registers[REGISTER_BYTE (Y_REGNUM)],
169 &sparc_greg_packet[SPARC_R_Y], 6 * SPARC_GREG_SIZE);
170
171 net_write_registers (sparc_greg_packet, SPARC_GREG_PLEN, PTRACE_SETREGS);
172
173 /* If this is a local or in register, or we're storing all
174 registers, update the register window spill area. */
175
176 if (regno < 0 || (L0_REGNUM <= regno && regno <= I7_REGNUM))
177 {
178 sp = extract_address (&registers[REGISTER_BYTE (SP_REGNUM)],
179 REGISTER_RAW_SIZE (CORE_ADDR));
180 write_memory (sp, &registers[REGISTER_BYTE (L0_REGNUM)],
181 16 * REGISTER_RAW_SIZE (L0_REGNUM));
182 }
183 }
184
185 /* Store floating point registers if the target has them. */
186
187 if (in_fp_regs && target_has_fp)
188 {
189 bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],
190 &sparc_fpreg_packet[SPARC_R_FP0], 32 * SPARC_FPREG_SIZE);
191 bcopy (&registers[REGISTER_BYTE (FPS_REGNUM)],
192 &sparc_fpreg_packet[SPARC_R_FSR], 1 * SPARC_FPREG_SIZE);
193
194 net_write_registers (sparc_fpreg_packet, SPARC_FPREG_PLEN,
195 PTRACE_SETFPREGS);
196 }
197 }