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
20b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
21b725ae77Skettenis    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"
33b725ae77Skettenis #include "symfile.h"
34b725ae77Skettenis #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
vx_read_register(int regno)69b725ae77Skettenis 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*63addd46Skettenis   memcpy (&deprecated_registers[0], &mips_greg_packet[MIPS_R_GP0],
107b725ae77Skettenis 	  32 * MIPS_GREG_SIZE);
108e93f7393Sniklas 
109e93f7393Sniklas   /* Copy SR, LO, HI, and PC.  */
110e93f7393Sniklas 
111*63addd46Skettenis   memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)],
112*63addd46Skettenis 	  &mips_greg_packet[MIPS_R_SR],
113*63addd46Skettenis 	  MIPS_GREG_SIZE);
114*63addd46Skettenis   memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)],
115*63addd46Skettenis 	  &mips_greg_packet[MIPS_R_LO],
116*63addd46Skettenis 	  MIPS_GREG_SIZE);
117*63addd46Skettenis   memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)],
118*63addd46Skettenis 	  &mips_greg_packet[MIPS_R_HI],
119*63addd46Skettenis 	  MIPS_GREG_SIZE);
120*63addd46Skettenis   memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)],
121*63addd46Skettenis 	  &mips_greg_packet[MIPS_R_PC],
122*63addd46Skettenis 	  MIPS_GREG_SIZE);
123e93f7393Sniklas 
124e93f7393Sniklas   /* If the target has floating point registers, fetch them.
125e93f7393Sniklas      Otherwise, zero the floating point register values in
126e93f7393Sniklas      registers[] for good measure, even though we might not
127e93f7393Sniklas      need to.  */
128e93f7393Sniklas 
129e93f7393Sniklas   if (target_has_fp)
130e93f7393Sniklas     {
131e93f7393Sniklas       net_read_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
132e93f7393Sniklas 			  PTRACE_GETFPREGS);
133e93f7393Sniklas 
134e93f7393Sniklas       /* Copy the floating point registers.  */
135e93f7393Sniklas 
136*63addd46Skettenis       memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
137*63addd46Skettenis 	      &mips_fpreg_packet[MIPS_R_FP0],
138*63addd46Skettenis 	      register_size (current_gdbarch, FP0_REGNUM) * 32);
139e93f7393Sniklas 
140e93f7393Sniklas       /* Copy the floating point control/status register (fpcsr).  */
141e93f7393Sniklas 
142*63addd46Skettenis       memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
143*63addd46Skettenis 	      &mips_fpreg_packet[MIPS_R_FPCSR],
144*63addd46Skettenis 	      register_size (current_gdbarch, mips_regnum (current_gdbarch)->fp_control_status));
145e93f7393Sniklas     }
146e93f7393Sniklas   else
147e93f7393Sniklas     {
148b725ae77Skettenis       memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
149*63addd46Skettenis 	      0, register_size (current_gdbarch, FP0_REGNUM) * 32);
150b725ae77Skettenis       memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
151*63addd46Skettenis 	      0, register_size (current_gdbarch, mips_regnum (current_gdbarch)->fp_control_status));
152e93f7393Sniklas     }
153e93f7393Sniklas 
154e93f7393Sniklas   /* Mark the register cache valid.  */
155e93f7393Sniklas 
156b725ae77Skettenis   deprecated_registers_fetched ();
157e93f7393Sniklas }
158e93f7393Sniklas 
159e93f7393Sniklas /* Store a register or registers into the VxWorks target.
160e93f7393Sniklas    REGNO is the register to store, or -1 for all; currently,
161e93f7393Sniklas    it is ignored.  FIXME look at regno to improve efficiency.  */
162e93f7393Sniklas 
vx_write_register(int regno)163b725ae77Skettenis vx_write_register (int regno)
164e93f7393Sniklas {
165e93f7393Sniklas   char mips_greg_packet[MIPS_GREG_PLEN];
166e93f7393Sniklas   char mips_fpreg_packet[MIPS_FPREG_PLEN];
167e93f7393Sniklas 
168e93f7393Sniklas   /* Store general registers.  */
169e93f7393Sniklas 
170*63addd46Skettenis   memcpy (&mips_greg_packet[MIPS_R_GP0], &deprecated_registers[0],
171b725ae77Skettenis 	  32 * MIPS_GREG_SIZE);
172e93f7393Sniklas 
173e93f7393Sniklas   /* Copy SR, LO, HI, and PC.  */
174e93f7393Sniklas 
175*63addd46Skettenis   memcpy (&mips_greg_packet[MIPS_R_SR],
176*63addd46Skettenis 	  &deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)],
177*63addd46Skettenis 	  MIPS_GREG_SIZE);
178*63addd46Skettenis   memcpy (&mips_greg_packet[MIPS_R_LO],
179*63addd46Skettenis 	  &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)],
180*63addd46Skettenis 	  MIPS_GREG_SIZE);
181*63addd46Skettenis   memcpy (&mips_greg_packet[MIPS_R_HI],
182*63addd46Skettenis 	  &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)],
183*63addd46Skettenis 	  MIPS_GREG_SIZE);
184*63addd46Skettenis   memcpy (&mips_greg_packet[MIPS_R_PC],
185*63addd46Skettenis 	  &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)],
186*63addd46Skettenis 	  MIPS_GREG_SIZE);
187e93f7393Sniklas 
188e93f7393Sniklas   net_write_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_SETREGS);
189e93f7393Sniklas 
190e93f7393Sniklas   /* Store floating point registers if the target has them.  */
191e93f7393Sniklas 
192e93f7393Sniklas   if (target_has_fp)
193e93f7393Sniklas     {
194e93f7393Sniklas       /* Copy the floating point data registers.  */
195e93f7393Sniklas 
196*63addd46Skettenis       memcpy (&mips_fpreg_packet[MIPS_R_FP0],
197*63addd46Skettenis 	      &deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
198*63addd46Skettenis 	      register_size (current_gdbarch, FP0_REGNUM) * 32);
199e93f7393Sniklas 
200e93f7393Sniklas       /* Copy the floating point control/status register (fpcsr).  */
201e93f7393Sniklas 
202*63addd46Skettenis       memcpy (&mips_fpreg_packet[MIPS_R_FPCSR],
203*63addd46Skettenis 	      &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
204*63addd46Skettenis 	      register_size (current_gdbarch, mips_regnum (current_gdbarch)->fp_control_status));
205e93f7393Sniklas 
206e93f7393Sniklas       net_write_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
207e93f7393Sniklas 			   PTRACE_SETFPREGS);
208e93f7393Sniklas     }
209e93f7393Sniklas }
210