]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/gdb/gdb/remote-vxsparc.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / gdb / gdb / remote-vxsparc.c
1 /* SPARC-specific portions of the RPC protocol for VxWorks.
2
3    Contributed by Wind River Systems.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include "regcache.h"
24
25 #include "gdb_string.h"
26
27 #include "sparc-tdep.h"
28
29 #include "vx-share/ptrace.h"
30 #include "vx-share/regPacket.h"
31
32 #define SPARC_R_G1      (SPARC_R_G0 + SPARC_GREG_SIZE)
33
34 const struct sparc_gregset vxsparc_gregset =
35 {
36   SPARC_R_PSR,                  /* %psr */
37   SPARC_R_PC,                   /* %pc */
38   SPARC_R_NPC,                  /* %npc */
39   SPARC_R_Y,                    /* %y */
40   SPARC_R_WIM,                  /* %wim */
41   SPARC_R_TBR,                  /* %tbr */
42   SPARC_R_G1,                   /* %g1 */
43   SPARC_R_I0                    /* %l0 */
44 };
45
46 /* Flag set if target has an FPU.  */
47
48 extern int target_has_fp;
49
50 /* Generic register read/write routines in remote-vx.c.  */
51
52 extern void net_read_registers ();
53 extern void net_write_registers ();
54
55 /* Read a register or registers from the VxWorks target.  REGNUM is
56    the register to read, or -1 for all; currently, it is ignored.
57    FIXME: Look at REGNUM to improve efficiency.  */
58
59 void
60 vx_read_register (int regnum)
61 {
62   struct regcache *regcache = current_regcache;
63   char gregs[SPARC_GREG_PLEN];
64   char fpregs[SPARC_FPREG_PLEN];
65   CORE_ADDR sp;
66
67   /* Get the general-purpose registers.  */
68   net_read_registers (gregs, SPARC_GREG_PLEN, PTRACE_GETREGS);
69   sparc32_supply_gregset (&vxsparc_gregset, regcache, -1, gregs);
70
71   /* If the target has floating-point registers, fetch them.
72      Otherwise, zero the floating-point register values in GDB's
73      register cache for good measure, even though we might not need
74      to.  */
75   if (target_has_fp)
76     net_read_registers (fpregs, SPARC_FPREG_PLEN, PTRACE_GETFPREGS);
77   else
78     memset (fpregs, 0, SPARC_FPREG_PLEN);
79   sparc32_supply_fpregset (regcache, -1, fpregs);
80 }
81
82 /* Store a register or registers into the VxWorks target.  REGNUM is
83    the register to store, or -1 for all; currently, it is ignored.
84    FIXME: Look at REGNUM to improve efficiency.  */
85
86 void
87 vx_write_register (int regnum)
88 {
89   struct regcache *regcache = current_regcache;
90   char gregs[SPARC_GREG_PLEN];
91   char fpregs[SPARC_FPREG_PLEN];
92   int gregs_p = 1;
93   int fpregs_p = 1;
94   CORE_ADDR sp;
95
96   if (regnum != -1)
97     {
98       if ((SPARC_G0_REGNUM <= regnum && regnum <= SPARC_I7_REGNUM)
99           || (SPARC32_Y_REGNUM <= regnum && regnum <= SPARC32_NPC_REGNUM))
100         fpregs_p = 0;
101       else
102         gregs_p = 0;
103     }
104
105   /* Store the general-purpose registers.  */
106   if (gregs_p)
107     {
108       sparc32_collect_gregset (&vxsparc_gregset, regcache, -1, gregs);
109       net_write_registers (gregs, SPARC_GREG_PLEN, PTRACE_SETREGS);
110
111       /* Deal with the stack regs.  */
112       if (regnum == -1 || regnum == SPARC_SP_REGNUM
113           || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM))
114         {
115           ULONGEST sp;
116
117           regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
118           sparc_collect_rwindow (regcache, sp, regnum);
119         }
120     }
121
122   /* Store the floating-point registers if the target has them.  */
123   if (fpregs_p && target_has_fp)
124     {
125       sparc32_collect_fpregset (regcache, -1, fpregs);
126       net_write_registers (fpregs, SPARC_FPREG_PLEN, PTRACE_SETFPREGS);
127     }
128 }