OSDN Git Service

* configure.in (AC_CHECK_HEADERS): Add sys/file.h.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / remote-vxmips.c
1 /* MIPS-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 #include <rpc/rpc.h>
42 #include <sys/time.h>           /* UTek's <rpc/rpc.h> doesn't #incl this */
43 #include <netdb.h>
44 #include "vx-share/ptrace.h"
45 #include "vx-share/xdr_ptrace.h"
46 #include "vx-share/xdr_ld.h"
47 #include "vx-share/xdr_rdb.h"
48 #include "vx-share/dbgRpcLib.h"
49
50 /* get rid of value.h if possible */
51 #include <value.h>
52 #include <symtab.h>
53
54 /* Flag set if target has fpu */
55
56 extern int target_has_fp;
57
58 /* Generic register read/write routines in remote-vx.c.  */
59
60 extern void net_read_registers ();
61 extern void net_write_registers ();
62
63 /* Read a register or registers from the VxWorks target.
64    REGNO is the register to read, or -1 for all; currently,
65    it is ignored.  FIXME look at regno to improve efficiency.  */
66
67 void
68 vx_read_register (int regno)
69 {
70   char mips_greg_packet[MIPS_GREG_PLEN];
71   char mips_fpreg_packet[MIPS_FPREG_PLEN];
72
73   /* Get general-purpose registers.  */
74
75   net_read_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_GETREGS);
76
77   /* this code copies the registers obtained by RPC 
78      stored in a structure(s) like this :
79
80      Register(s)                Offset(s)
81      gp 0-31                    0x00
82      hi                 0x80
83      lo                 0x84
84      sr                 0x88
85      pc                 0x8c
86
87      into a stucture like this:
88
89      0x00       GP 0-31
90      0x80       SR
91      0x84       LO
92      0x88       HI
93      0x8C       BAD             --- Not available currently
94      0x90       CAUSE           --- Not available currently
95      0x94       PC
96      0x98       FP 0-31
97      0x118      FCSR
98      0x11C      FIR             --- Not available currently
99      0x120      FP              --- Not available currently
100
101      structure is 0x124 (292) bytes in length */
102
103   /* Copy the general registers.  */
104
105   bcopy (&mips_greg_packet[MIPS_R_GP0], &registers[0], 32 * MIPS_GREG_SIZE);
106
107   /* Copy SR, LO, HI, and PC.  */
108
109   bcopy (&mips_greg_packet[MIPS_R_SR],
110          &registers[REGISTER_BYTE (PS_REGNUM)], MIPS_GREG_SIZE);
111   bcopy (&mips_greg_packet[MIPS_R_LO],
112          &registers[REGISTER_BYTE (LO_REGNUM)], MIPS_GREG_SIZE);
113   bcopy (&mips_greg_packet[MIPS_R_HI],
114          &registers[REGISTER_BYTE (HI_REGNUM)], MIPS_GREG_SIZE);
115   bcopy (&mips_greg_packet[MIPS_R_PC],
116          &registers[REGISTER_BYTE (PC_REGNUM)], MIPS_GREG_SIZE);
117
118   /* If the target has floating point registers, fetch them.
119      Otherwise, zero the floating point register values in
120      registers[] for good measure, even though we might not
121      need to.  */
122
123   if (target_has_fp)
124     {
125       net_read_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
126                           PTRACE_GETFPREGS);
127
128       /* Copy the floating point registers.  */
129
130       bcopy (&mips_fpreg_packet[MIPS_R_FP0],
131              &registers[REGISTER_BYTE (FP0_REGNUM)],
132              REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
133
134       /* Copy the floating point control/status register (fpcsr).  */
135
136       bcopy (&mips_fpreg_packet[MIPS_R_FPCSR],
137              &registers[REGISTER_BYTE (FCRCS_REGNUM)],
138              REGISTER_RAW_SIZE (FCRCS_REGNUM));
139     }
140   else
141     {
142       bzero ((char *) &registers[REGISTER_BYTE (FP0_REGNUM)],
143              REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
144       bzero ((char *) &registers[REGISTER_BYTE (FCRCS_REGNUM)],
145              REGISTER_RAW_SIZE (FCRCS_REGNUM));
146     }
147
148   /* Mark the register cache valid.  */
149
150   registers_fetched ();
151 }
152
153 /* Store a register or registers into the VxWorks target.
154    REGNO is the register to store, or -1 for all; currently,
155    it is ignored.  FIXME look at regno to improve efficiency.  */
156
157 vx_write_register (int regno)
158 {
159   char mips_greg_packet[MIPS_GREG_PLEN];
160   char mips_fpreg_packet[MIPS_FPREG_PLEN];
161
162   /* Store general registers.  */
163
164   bcopy (&registers[0], &mips_greg_packet[MIPS_R_GP0], 32 * MIPS_GREG_SIZE);
165
166   /* Copy SR, LO, HI, and PC.  */
167
168   bcopy (&registers[REGISTER_BYTE (PS_REGNUM)],
169          &mips_greg_packet[MIPS_R_SR], MIPS_GREG_SIZE);
170   bcopy (&registers[REGISTER_BYTE (LO_REGNUM)],
171          &mips_greg_packet[MIPS_R_LO], MIPS_GREG_SIZE);
172   bcopy (&registers[REGISTER_BYTE (HI_REGNUM)],
173          &mips_greg_packet[MIPS_R_HI], MIPS_GREG_SIZE);
174   bcopy (&registers[REGISTER_BYTE (PC_REGNUM)],
175          &mips_greg_packet[MIPS_R_PC], MIPS_GREG_SIZE);
176
177   net_write_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_SETREGS);
178
179   /* Store floating point registers if the target has them.  */
180
181   if (target_has_fp)
182     {
183       /* Copy the floating point data registers.  */
184
185       bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],
186              &mips_fpreg_packet[MIPS_R_FP0],
187              REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
188
189       /* Copy the floating point control/status register (fpcsr).  */
190
191       bcopy (&registers[REGISTER_BYTE (FCRCS_REGNUM)],
192              &mips_fpreg_packet[MIPS_R_FPCSR],
193              REGISTER_RAW_SIZE (FCRCS_REGNUM));
194
195       net_write_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
196                            PTRACE_SETFPREGS);
197     }
198 }