1130812Smarcel/* MIPS-dependent portions of the RPC protocol
2130812Smarcel   used with a VxWorks target
3130812Smarcel
4130812Smarcel   Contributed by Wind River Systems.
5130812Smarcel
6130812Smarcel   This file is part of GDB.
7130812Smarcel
8130812Smarcel   This program is free software; you can redistribute it and/or modify
9130812Smarcel   it under the terms of the GNU General Public License as published by
10130812Smarcel   the Free Software Foundation; either version 2 of the License, or
11130812Smarcel   (at your option) any later version.
12130812Smarcel
13130812Smarcel   This program is distributed in the hope that it will be useful,
14130812Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
15130812Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16130812Smarcel   GNU General Public License for more details.
17130812Smarcel
18130812Smarcel   You should have received a copy of the GNU General Public License
19130812Smarcel   along with this program; if not, write to the Free Software
20130812Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
21130812Smarcel   Boston, MA 02111-1307, USA.  */
22130812Smarcel
23130812Smarcel#include <stdio.h>
24130812Smarcel#include "defs.h"
25130812Smarcel
26130812Smarcel#include "vx-share/regPacket.h"
27130812Smarcel#include "frame.h"
28130812Smarcel#include "inferior.h"
29130812Smarcel#include "target.h"
30130812Smarcel#include "gdbcore.h"
31130812Smarcel#include "command.h"
32130812Smarcel#include "symtab.h"
33130812Smarcel#include "symfile.h"
34130812Smarcel#include "regcache.h"
35130812Smarcel
36130812Smarcel#include "gdb_string.h"
37130812Smarcel#include <errno.h>
38130812Smarcel#include <fcntl.h>
39130812Smarcel#include <sys/types.h>
40130812Smarcel#include <sys/time.h>
41130812Smarcel#include <sys/socket.h>
42130812Smarcel#include <rpc/rpc.h>
43130812Smarcel#include <sys/time.h>		/* UTek's <rpc/rpc.h> doesn't #incl this */
44130812Smarcel#include <netdb.h>
45130812Smarcel#include "vx-share/ptrace.h"
46130812Smarcel#include "vx-share/xdr_ptrace.h"
47130812Smarcel#include "vx-share/xdr_ld.h"
48130812Smarcel#include "vx-share/xdr_rdb.h"
49130812Smarcel#include "vx-share/dbgRpcLib.h"
50130812Smarcel
51130812Smarcel/* get rid of value.h if possible */
52130812Smarcel#include <value.h>
53130812Smarcel#include <symtab.h>
54130812Smarcel
55130812Smarcel/* Flag set if target has fpu */
56130812Smarcel
57130812Smarcelextern int target_has_fp;
58130812Smarcel
59130812Smarcel/* Generic register read/write routines in remote-vx.c.  */
60130812Smarcel
61130812Smarcelextern void net_read_registers ();
62130812Smarcelextern void net_write_registers ();
63130812Smarcel
64130812Smarcel/* Read a register or registers from the VxWorks target.
65130812Smarcel   REGNO is the register to read, or -1 for all; currently,
66130812Smarcel   it is ignored.  FIXME look at regno to improve efficiency.  */
67130812Smarcel
68130812Smarcelvoid
69130812Smarcelvx_read_register (int regno)
70130812Smarcel{
71130812Smarcel  char mips_greg_packet[MIPS_GREG_PLEN];
72130812Smarcel  char mips_fpreg_packet[MIPS_FPREG_PLEN];
73130812Smarcel
74130812Smarcel  /* Get general-purpose registers.  */
75130812Smarcel
76130812Smarcel  net_read_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_GETREGS);
77130812Smarcel
78130812Smarcel  /* this code copies the registers obtained by RPC
79130812Smarcel     stored in a structure(s) like this :
80130812Smarcel
81130812Smarcel     Register(s)                Offset(s)
82130812Smarcel     gp 0-31                    0x00
83130812Smarcel     hi                 0x80
84130812Smarcel     lo                 0x84
85130812Smarcel     sr                 0x88
86130812Smarcel     pc                 0x8c
87130812Smarcel
88130812Smarcel     into a stucture like this:
89130812Smarcel
90130812Smarcel     0x00       GP 0-31
91130812Smarcel     0x80       SR
92130812Smarcel     0x84       LO
93130812Smarcel     0x88       HI
94130812Smarcel     0x8C       BAD             --- Not available currently
95130812Smarcel     0x90       CAUSE           --- Not available currently
96130812Smarcel     0x94       PC
97130812Smarcel     0x98       FP 0-31
98130812Smarcel     0x118      FCSR
99130812Smarcel     0x11C      FIR             --- Not available currently
100130812Smarcel     0x120      FP              --- Not available currently
101130812Smarcel
102130812Smarcel     structure is 0x124 (292) bytes in length */
103130812Smarcel
104130812Smarcel  /* Copy the general registers.  */
105130812Smarcel
106130812Smarcel  bcopy (&mips_greg_packet[MIPS_R_GP0], &deprecated_registers[0],
107130812Smarcel	 32 * MIPS_GREG_SIZE);
108130812Smarcel
109130812Smarcel  /* Copy SR, LO, HI, and PC.  */
110130812Smarcel
111130812Smarcel  bcopy (&mips_greg_packet[MIPS_R_SR],
112130812Smarcel	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)], MIPS_GREG_SIZE);
113130812Smarcel  bcopy (&mips_greg_packet[MIPS_R_LO],
114130812Smarcel	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)], MIPS_GREG_SIZE);
115130812Smarcel  bcopy (&mips_greg_packet[MIPS_R_HI],
116130812Smarcel	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)], MIPS_GREG_SIZE);
117130812Smarcel  bcopy (&mips_greg_packet[MIPS_R_PC],
118130812Smarcel	 &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)], MIPS_GREG_SIZE);
119130812Smarcel
120130812Smarcel  /* If the target has floating point registers, fetch them.
121130812Smarcel     Otherwise, zero the floating point register values in
122130812Smarcel     registers[] for good measure, even though we might not
123130812Smarcel     need to.  */
124130812Smarcel
125130812Smarcel  if (target_has_fp)
126130812Smarcel    {
127130812Smarcel      net_read_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
128130812Smarcel			  PTRACE_GETFPREGS);
129130812Smarcel
130130812Smarcel      /* Copy the floating point registers.  */
131130812Smarcel
132130812Smarcel      bcopy (&mips_fpreg_packet[MIPS_R_FP0],
133130812Smarcel	     &deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
134130812Smarcel	     DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
135130812Smarcel
136130812Smarcel      /* Copy the floating point control/status register (fpcsr).  */
137130812Smarcel
138130812Smarcel      bcopy (&mips_fpreg_packet[MIPS_R_FPCSR],
139130812Smarcel	     &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
140130812Smarcel	     DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->fp_control_status));
141130812Smarcel    }
142130812Smarcel  else
143130812Smarcel    {
144130812Smarcel      memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
145130812Smarcel	      0, DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
146130812Smarcel      memset (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
147130812Smarcel	      0, DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->fp_control_status));
148130812Smarcel    }
149130812Smarcel
150130812Smarcel  /* Mark the register cache valid.  */
151130812Smarcel
152130812Smarcel  deprecated_registers_fetched ();
153130812Smarcel}
154130812Smarcel
155130812Smarcel/* Store a register or registers into the VxWorks target.
156130812Smarcel   REGNO is the register to store, or -1 for all; currently,
157130812Smarcel   it is ignored.  FIXME look at regno to improve efficiency.  */
158130812Smarcel
159130812Smarcelvx_write_register (int regno)
160130812Smarcel{
161130812Smarcel  char mips_greg_packet[MIPS_GREG_PLEN];
162130812Smarcel  char mips_fpreg_packet[MIPS_FPREG_PLEN];
163130812Smarcel
164130812Smarcel  /* Store general registers.  */
165130812Smarcel
166130812Smarcel  bcopy (&deprecated_registers[0], &mips_greg_packet[MIPS_R_GP0],
167130812Smarcel	 32 * MIPS_GREG_SIZE);
168130812Smarcel
169130812Smarcel  /* Copy SR, LO, HI, and PC.  */
170130812Smarcel
171130812Smarcel  bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)],
172130812Smarcel	 &mips_greg_packet[MIPS_R_SR], MIPS_GREG_SIZE);
173130812Smarcel  bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)],
174130812Smarcel	 &mips_greg_packet[MIPS_R_LO], MIPS_GREG_SIZE);
175130812Smarcel  bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)],
176130812Smarcel	 &mips_greg_packet[MIPS_R_HI], MIPS_GREG_SIZE);
177130812Smarcel  bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)],
178130812Smarcel	 &mips_greg_packet[MIPS_R_PC], MIPS_GREG_SIZE);
179130812Smarcel
180130812Smarcel  net_write_registers (mips_greg_packet, MIPS_GREG_PLEN, PTRACE_SETREGS);
181130812Smarcel
182130812Smarcel  /* Store floating point registers if the target has them.  */
183130812Smarcel
184130812Smarcel  if (target_has_fp)
185130812Smarcel    {
186130812Smarcel      /* Copy the floating point data registers.  */
187130812Smarcel
188130812Smarcel      bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
189130812Smarcel	     &mips_fpreg_packet[MIPS_R_FP0],
190130812Smarcel	     DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
191130812Smarcel
192130812Smarcel      /* Copy the floating point control/status register (fpcsr).  */
193130812Smarcel
194130812Smarcel      bcopy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)],
195130812Smarcel	     &mips_fpreg_packet[MIPS_R_FPCSR],
196130812Smarcel	     DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->fp_control_status));
197130812Smarcel
198130812Smarcel      net_write_registers (mips_fpreg_packet, MIPS_FPREG_PLEN,
199130812Smarcel			   PTRACE_SETFPREGS);
200130812Smarcel    }
201130812Smarcel}
202