b9a1a250a0be7e5ba4273dd7b55e3fc5863e0016
[deliverable/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 "target.h"
30 #include "gdbcore.h"
31 #include "command.h"
32 #include "symtab.h"
33 #include "symfile.h" /* for struct complaint */
34
35 #include "gdb_string.h"
36 #include <errno.h>
37 #include <fcntl.h>
38 #include <sys/types.h>
39 #include <sys/time.h>
40 #include <sys/socket.h>
41
42 #ifdef _AIX /* IBM claims "void *malloc()" not char * */
43 #define malloc bogon_malloc
44 #endif
45
46 #include <rpc/rpc.h>
47 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
48 #include <netdb.h>
49 #include "vx-share/ptrace.h"
50 #include "vx-share/xdr_ptrace.h"
51 #include "vx-share/xdr_ld.h"
52 #include "vx-share/xdr_rdb.h"
53 #include "vx-share/dbgRpcLib.h"
54
55 /* get rid of value.h if possible */
56 #include <value.h>
57 #include <symtab.h>
58
59 /* Flag set if target has fpu */
60
61 extern int target_has_fp;
62
63 /* sparc floating point format descriptor, from "sparc-tdep.c." */
64
65 extern struct ext_format ext_format_sparc;
66
67 /* Generic register read/write routines in remote-vx.c. */
68
69 extern void net_read_registers ();
70 extern void net_write_registers ();
71
72 /* Read a register or registers from the VxWorks target.
73 REGNO is the register to read, or -1 for all; currently,
74 it is ignored. FIXME look at regno to improve efficiency. */
75
76 void
77 vx_read_register (int regno)
78 {
79 char sparc_greg_packet[SPARC_GREG_PLEN];
80 char sparc_fpreg_packet[SPARC_FPREG_PLEN];
81 CORE_ADDR sp;
82
83 /* Get general-purpose registers. When copying values into
84 registers [], don't assume that a location in registers []
85 is properly aligned for the target data type. */
86
87 net_read_registers (sparc_greg_packet, SPARC_GREG_PLEN, PTRACE_GETREGS);
88
89 /* Now copy the register values into registers[].
90 Note that this code depends on the ordering of the REGNUMs
91 as defined in "tm-sparc.h". */
92
93 bcopy (&sparc_greg_packet[SPARC_R_G0],
94 &registers[REGISTER_BYTE (G0_REGNUM)], 32 * SPARC_GREG_SIZE);
95 bcopy (&sparc_greg_packet[SPARC_R_Y],
96 &registers[REGISTER_BYTE (Y_REGNUM)], 6 * SPARC_GREG_SIZE);
97
98 /* Now write the local and in registers to the register window
99 spill area in the frame. VxWorks does not do this for the
100 active frame automatically; it greatly simplifies debugging
101 (FRAME_FIND_SAVED_REGS, in particular, depends on this). */
102
103 sp = extract_address (&registers[REGISTER_BYTE (SP_REGNUM)],
104 REGISTER_RAW_SIZE (CORE_ADDR));
105 write_memory (sp, &registers[REGISTER_BYTE (L0_REGNUM)],
106 16 * REGISTER_RAW_SIZE (L0_REGNUM));
107
108 /* If the target has floating point registers, fetch them.
109 Otherwise, zero the floating point register values in
110 registers[] for good measure, even though we might not
111 need to. */
112
113 if (target_has_fp)
114 {
115 net_read_registers (sparc_fpreg_packet, SPARC_FPREG_PLEN,
116 PTRACE_GETFPREGS);
117 bcopy (&sparc_fpreg_packet[SPARC_R_FP0],
118 &registers[REGISTER_BYTE (FP0_REGNUM)], 32 * SPARC_FPREG_SIZE);
119 bcopy (&sparc_fpreg_packet[SPARC_R_FSR],
120 &registers[REGISTER_BYTE (FPS_REGNUM)], 1 * SPARC_FPREG_SIZE);
121 }
122 else
123 {
124 bzero (&registers[REGISTER_BYTE (FP0_REGNUM)], 32 * SPARC_FPREG_SIZE);
125 bzero (&registers[REGISTER_BYTE (FPS_REGNUM)], 1 * SPARC_FPREG_SIZE);
126 }
127
128 /* Mark the register cache valid. */
129
130 registers_fetched ();
131 }
132
133 /* Store a register or registers into the VxWorks target.
134 REGNO is the register to store, or -1 for all; currently,
135 it is ignored. FIXME look at regno to improve efficiency. */
136
137 void
138 vx_write_register (int regno)
139 {
140 char sparc_greg_packet[SPARC_GREG_PLEN];
141 char sparc_fpreg_packet[SPARC_FPREG_PLEN];
142 int in_gp_regs;
143 int in_fp_regs;
144 CORE_ADDR sp;
145
146 /* Store general purpose registers. When copying values from
147 registers [], don't assume that a location in registers []
148 is properly aligned for the target data type. */
149
150 in_gp_regs = 1;
151 in_fp_regs = 1;
152 if (regno >= 0)
153 {
154 if ((G0_REGNUM <= regno && regno <= I7_REGNUM)
155 || (Y_REGNUM <= regno && regno <= NPC_REGNUM))
156 in_fp_regs = 0;
157 else
158 in_gp_regs = 0;
159 }
160 if (in_gp_regs)
161 {
162 bcopy (&registers[REGISTER_BYTE (G0_REGNUM)],
163 &sparc_greg_packet[SPARC_R_G0], 32 * SPARC_GREG_SIZE);
164 bcopy (&registers[REGISTER_BYTE (Y_REGNUM)],
165 &sparc_greg_packet[SPARC_R_Y], 6 * SPARC_GREG_SIZE);
166
167 net_write_registers (sparc_greg_packet, SPARC_GREG_PLEN, PTRACE_SETREGS);
168
169 /* If this is a local or in register, or we're storing all
170 registers, update the register window spill area. */
171
172 if (regno < 0 || (L0_REGNUM <= regno && regno <= I7_REGNUM))
173 {
174 sp = extract_address (&registers[REGISTER_BYTE (SP_REGNUM)],
175 REGISTER_RAW_SIZE (CORE_ADDR));
176 write_memory (sp, &registers[REGISTER_BYTE (L0_REGNUM)],
177 16 * REGISTER_RAW_SIZE (L0_REGNUM));
178 }
179 }
180
181 /* Store floating point registers if the target has them. */
182
183 if (in_fp_regs && target_has_fp)
184 {
185 bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],
186 &sparc_fpreg_packet[SPARC_R_FP0], 32 * SPARC_FPREG_SIZE);
187 bcopy (&registers[REGISTER_BYTE (FPS_REGNUM)],
188 &sparc_fpreg_packet[SPARC_R_FSR], 1 * SPARC_FPREG_SIZE);
189
190 net_write_registers (sparc_fpreg_packet, SPARC_FPREG_PLEN,
191 PTRACE_SETFPREGS);
192 }
193 }
This page took 0.040824 seconds and 4 git commands to generate.