1e93f7393Sniklas /* MIPS-dependent portions of the RPC protocol
2e93f7393Sniklas    used with a VxWorks target
3e93f7393Sniklas 
4e93f7393Sniklas    Contributed by Wind River Systems.
5e93f7393Sniklas 
6e93f7393Sniklas    This file is part of GDB.
7e93f7393Sniklas 
8e93f7393Sniklas    This program is free software; you can redistribute it and/or modify
9e93f7393Sniklas    it under the terms of the GNU General Public License as published by
10e93f7393Sniklas    the Free Software Foundation; either version 2 of the License, or
11e93f7393Sniklas    (at your option) any later version.
12e93f7393Sniklas 
13e93f7393Sniklas    This program is distributed in the hope that it will be useful,
14e93f7393Sniklas    but WITHOUT ANY WARRANTY; without even the implied warranty of
15e93f7393Sniklas    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e93f7393Sniklas    GNU General Public License for more details.
17e93f7393Sniklas 
18e93f7393Sniklas    You should have received a copy of the GNU General Public License
19e93f7393Sniklas    along with this program; if not, write to the Free Software
20*b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
21*b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
22e93f7393Sniklas 
23e93f7393Sniklas #include <stdio.h>
24e93f7393Sniklas #include "defs.h"
25e93f7393Sniklas 
26e93f7393Sniklas #include "vx-share/regPacket.h"
27e93f7393Sniklas #include "frame.h"
28e93f7393Sniklas #include "inferior.h"
29e93f7393Sniklas #include "target.h"
30e93f7393Sniklas #include "gdbcore.h"
31e93f7393Sniklas #include "command.h"
32e93f7393Sniklas #include "symtab.h"
33*b725ae77Skettenis #include "symfile.h"
34*b725ae77Skettenis #include "regcache.h"
35e93f7393Sniklas 
36e93f7393Sniklas #include "gdb_string.h"
37e93f7393Sniklas #include <errno.h>
38e93f7393Sniklas #include <fcntl.h>
39e93f7393Sniklas #include <sys/types.h>
40e93f7393Sniklas #include <sys/time.h>
41e93f7393Sniklas #include <sys/socket.h>
42e93f7393Sniklas #include <rpc/rpc.h>
43e93f7393Sniklas #include <sys/time.h>		/* UTek's <rpc/rpc.h> doesn't #incl this */
44e93f7393Sniklas #include <netdb.h>
45e93f7393Sniklas #include "vx-share/ptrace.h"
46e93f7393Sniklas #include "vx-share/xdr_ptrace.h"
47e93f7393Sniklas #include "vx-share/xdr_ld.h"
48e93f7393Sniklas #include "vx-share/xdr_rdb.h"
49e93f7393Sniklas #include "vx-share/dbgRpcLib.h"
50e93f7393Sniklas 
51e93f7393Sniklas /* get rid of value.h if possible */
52e93f7393Sniklas #include <value.h>
53e93f7393Sniklas #include <symtab.h>
54e93f7393Sniklas 
55e93f7393Sniklas /* Flag set if target has fpu */
56e93f7393Sniklas 
57e93f7393Sniklas extern int target_has_fp;
58e93f7393Sniklas 
59e93f7393Sniklas /* Generic register read/write routines in remote-vx.c.  */
60e93f7393Sniklas 
61e93f7393Sniklas extern void net_read_registers ();
62e93f7393Sniklas extern void net_write_registers ();
63e93f7393Sniklas 
64e93f7393Sniklas /* Read a register or registers from the VxWorks target.
65e93f7393Sniklas    REGNO is the register to read, or -1 for all; currently,
66e93f7393Sniklas    it is ignored.  FIXME look at regno to improve efficiency.  */
67e93f7393Sniklas 
68e93f7393Sniklas void
69*b725ae77Skettenis vx_read_register (int regno)
70e93f7393Sniklas {
71e93f7393Sniklas   char mips_greg_packet[MIPS_GREG_PLEN];
72e93f7393Sniklas   char mips_fpreg_packet[MIPS_FPREG_PLEN];
73e93f7393Sniklas 
74e93f7393Sniklas   /* Get general-purpose registers.  */
75e93f7393Sniklas 
76e93f7393Sniklas   net_read_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_GETREGS);
77e93f7393Sniklas 
78e93f7393Sniklas   /* this code copies the registers obtained by RPC
79e93f7393Sniklas      stored in a structure(s) like this :
80e93f7393Sniklas 
81e93f7393Sniklas      Register(s)                Offset(s)
82e93f7393Sniklas      gp 0-31                    0x00
83e93f7393Sniklas      hi                 0x80
84e93f7393Sniklas      lo                 0x84
85e93f7393Sniklas      sr                 0x88
86e93f7393Sniklas      pc                 0x8c
87e93f7393Sniklas 
88e93f7393Sniklas      into a stucture like this:
89e93f7393Sniklas 
90e93f7393Sniklas      0x00       GP 0-31
91e93f7393Sniklas      0x80       SR
92e93f7393Sniklas      0x84       LO
93e93f7393Sniklas      0x88       HI
94e93f7393Sniklas      0x8C       BAD             --- Not available currently
95e93f7393Sniklas      0x90       CAUSE           --- Not available currently
96e93f7393Sniklas      0x94       PC
97e93f7393Sniklas      0x98       FP 0-31
98e93f7393Sniklas      0x118      FCSR
99e93f7393Sniklas      0x11C      FIR             --- Not available currently
100e93f7393Sniklas      0x120      FP              --- Not available currently
101e93f7393Sniklas 
102e93f7393Sniklas      structure is 0x124 (292) bytes in length */
103e93f7393Sniklas 
104e93f7393Sniklas   /* Copy the general registers.  */
105e93f7393Sniklas 
106*b725ae77Skettenis   bcopy (&mips_greg_packet[MIPS_R_GP0], &deprecated_registers[0],
107*b725ae77Skettenis 	 32 * MIPS_GREG_SIZE);
108e93f7393Sniklas 
109e93f7393Sniklas   /* Copy SR, LO, HI, and PC.  */
110e93f7393Sniklas 
111e93f7393Sniklas   bcopy (&mips_greg_packet[MIPS_R_SR],
112*b725ae77Skettenis 	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)], MIPS_GREG_SIZE);
113e93f7393Sniklas   bcopy (&mips_greg_packet[MIPS_R_LO],
114*b725ae77Skettenis 	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)], MIPS_GREG_SIZE);
115e93f7393Sniklas   bcopy (&mips_greg_packet[MIPS_R_HI],
116*b725ae77Skettenis 	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)], MIPS_GREG_SIZE);
117e93f7393Sniklas   bcopy (&mips_greg_packet[MIPS_R_PC],
118*b725ae77Skettenis 	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)], MIPS_GREG_SIZE);
119e93f7393Sniklas 
120e93f7393Sniklas   /* If the target has floating point registers, fetch them.
121e93f7393Sniklas      Otherwise, zero the floating point register values in
122e93f7393Sniklas      registers[] for good measure, even though we might not
123e93f7393Sniklas      need to.  */
124e93f7393Sniklas 
125e93f7393Sniklas   if (target_has_fp)
126e93f7393Sniklas     {
127e93f7393Sniklas       net_read_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
128e93f7393Sniklas 			  PTRACE_GETFPREGS);
129e93f7393Sniklas 
130e93f7393Sniklas       /* Copy the floating point registers.  */
131e93f7393Sniklas 
132e93f7393Sniklas       bcopy (&mips_fpreg_packet[MIPS_R_FP0],
133*b725ae77Skettenis 	     &deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
134*b725ae77Skettenis 	     DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
135e93f7393Sniklas 
136e93f7393Sniklas       /* Copy the floating point control/status register (fpcsr).  */
137e93f7393Sniklas 
138e93f7393Sniklas       bcopy (&mips_fpreg_packet[MIPS_R_FPCSR],
139*b725ae77Skettenis 	     &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
140*b725ae77Skettenis 	     DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->fp_control_status));
141e93f7393Sniklas     }
142e93f7393Sniklas   else
143e93f7393Sniklas     {
144*b725ae77Skettenis       memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
145*b725ae77Skettenis 	      0, DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
146*b725ae77Skettenis       memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
147*b725ae77Skettenis 	      0, DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->fp_control_status));
148e93f7393Sniklas     }
149e93f7393Sniklas 
150e93f7393Sniklas   /* Mark the register cache valid.  */
151e93f7393Sniklas 
152*b725ae77Skettenis   deprecated_registers_fetched ();
153e93f7393Sniklas }
154e93f7393Sniklas 
155e93f7393Sniklas /* Store a register or registers into the VxWorks target.
156e93f7393Sniklas    REGNO is the register to store, or -1 for all; currently,
157e93f7393Sniklas    it is ignored.  FIXME look at regno to improve efficiency.  */
158e93f7393Sniklas 
159*b725ae77Skettenis vx_write_register (int regno)
160e93f7393Sniklas {
161e93f7393Sniklas   char mips_greg_packet[MIPS_GREG_PLEN];
162e93f7393Sniklas   char mips_fpreg_packet[MIPS_FPREG_PLEN];
163e93f7393Sniklas 
164e93f7393Sniklas   /* Store general registers.  */
165e93f7393Sniklas 
166*b725ae77Skettenis   bcopy (&deprecated_registers[0], &mips_greg_packet[MIPS_R_GP0],
167*b725ae77Skettenis 	 32 * MIPS_GREG_SIZE);
168e93f7393Sniklas 
169e93f7393Sniklas   /* Copy SR, LO, HI, and PC.  */
170e93f7393Sniklas 
171*b725ae77Skettenis   bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)],
172e93f7393Sniklas 	 &mips_greg_packet[MIPS_R_SR], MIPS_GREG_SIZE);
173*b725ae77Skettenis   bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)],
174e93f7393Sniklas 	 &mips_greg_packet[MIPS_R_LO], MIPS_GREG_SIZE);
175*b725ae77Skettenis   bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)],
176e93f7393Sniklas 	 &mips_greg_packet[MIPS_R_HI], MIPS_GREG_SIZE);
177*b725ae77Skettenis   bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)],
178e93f7393Sniklas 	 &mips_greg_packet[MIPS_R_PC], MIPS_GREG_SIZE);
179e93f7393Sniklas 
180e93f7393Sniklas   net_write_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_SETREGS);
181e93f7393Sniklas 
182e93f7393Sniklas   /* Store floating point registers if the target has them.  */
183e93f7393Sniklas 
184e93f7393Sniklas   if (target_has_fp)
185e93f7393Sniklas     {
186e93f7393Sniklas       /* Copy the floating point data registers.  */
187e93f7393Sniklas 
188*b725ae77Skettenis       bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
189e93f7393Sniklas 	     &mips_fpreg_packet[MIPS_R_FP0],
190*b725ae77Skettenis 	     DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
191e93f7393Sniklas 
192e93f7393Sniklas       /* Copy the floating point control/status register (fpcsr).  */
193e93f7393Sniklas 
194*b725ae77Skettenis       bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
195e93f7393Sniklas 	     &mips_fpreg_packet[MIPS_R_FPCSR],
196*b725ae77Skettenis 	     DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->fp_control_status));
197e93f7393Sniklas 
198e93f7393Sniklas       net_write_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
199e93f7393Sniklas 			   PTRACE_SETFPREGS);
200e93f7393Sniklas     }
201e93f7393Sniklas }
202