2003-11-16 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / mipsv4-nat.c
CommitLineData
c906108c 1/* Native support for MIPS running SVR4, for GDB.
b6ba6518 2 Copyright 1994, 1995, 2000, 2001 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
c906108c 10
c5aa993b
JM
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
c906108c 15
c5aa993b
JM
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
c906108c
SS
20
21#include "defs.h"
22#include "inferior.h"
23#include "gdbcore.h"
24#include "target.h"
4e052eda 25#include "regcache.h"
c906108c
SS
26
27#include <sys/time.h>
28#include <sys/procfs.h>
29#include <setjmp.h> /* For JB_XXX. */
30
c60c0f5f
MS
31/* Prototypes for supply_gregset etc. */
32#include "gregset.h"
33
c906108c
SS
34/* Size of elements in jmpbuf */
35
36#define JB_ELEMENT_SIZE 4
37
38/*
39 * See the comment in m68k-tdep.c regarding the utility of these functions.
40 *
41 * These definitions are from the MIPS SVR4 ABI, so they may work for
42 * any MIPS SVR4 target.
43 */
44
c5aa993b 45void
fba45db2 46supply_gregset (gregset_t *gregsetp)
c906108c 47{
52f0bd74
AC
48 int regi;
49 greg_t *regp = &(*gregsetp)[0];
123a958e
AC
50 char zerobuf[MAX_REGISTER_SIZE];
51 memset (zerobuf, 0, MAX_REGISTER_SIZE);
c906108c
SS
52
53 for (regi = 0; regi <= CXT_RA; regi++)
c5aa993b 54 supply_register (regi, (char *) (regp + regi));
c906108c 55
56cea623
AC
56 supply_register (mips_regnum (current_gdbarch)->pc,
57 (char *) (regp + CXT_EPC));
58 supply_register (mips_regnum (current_gdbarch)->hi,
59 (char *) (regp + CXT_MDHI));
60 supply_register (mips_regnum (current_gdbarch)->lo,
61 (char *) (regp + CXT_MDLO));
62 supply_register (mips_regnum (current_gdbarch)->cause,
63 (char *) (regp + CXT_CAUSE));
c906108c
SS
64
65 /* Fill inaccessible registers with zero. */
66 supply_register (PS_REGNUM, zerobuf);
56cea623 67 supply_register (mips_regnum (current_gdbarch)->badvaddr, zerobuf);
0ba6dca9 68 supply_register (DEPRECATED_FP_REGNUM, zerobuf);
c906108c
SS
69 supply_register (UNUSED_REGNUM, zerobuf);
70 for (regi = FIRST_EMBED_REGNUM; regi <= LAST_EMBED_REGNUM; regi++)
71 supply_register (regi, zerobuf);
72}
73
74void
fba45db2 75fill_gregset (gregset_t *gregsetp, int regno)
c906108c
SS
76{
77 int regi;
52f0bd74 78 greg_t *regp = &(*gregsetp)[0];
c906108c
SS
79
80 for (regi = 0; regi <= 32; regi++)
81 if ((regno == -1) || (regno == regi))
62700349 82 *(regp + regi) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)];
c906108c 83
56cea623
AC
84 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->pc))
85 *(regp + CXT_EPC) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)];
c906108c 86
56cea623
AC
87 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause))
88 *(regp + CXT_CAUSE) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->cause)];
c906108c 89
56cea623
AC
90 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->hi))
91 *(regp + CXT_MDHI) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)];
c906108c 92
56cea623
AC
93 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo))
94 *(regp + CXT_MDLO) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)];
c906108c
SS
95}
96
97/*
98 * Now we do the same thing for floating-point registers.
56cea623 99 * We don't bother to condition on FP0 regnum since any
c906108c
SS
100 * reasonable MIPS configuration has an R3010 in it.
101 *
102 * Again, see the comments in m68k-tdep.c.
103 */
104
105void
fba45db2 106supply_fpregset (fpregset_t *fpregsetp)
c906108c 107{
52f0bd74 108 int regi;
123a958e
AC
109 char zerobuf[MAX_REGISTER_SIZE];
110 memset (zerobuf, 0, MAX_REGISTER_SIZE);
c906108c
SS
111
112 for (regi = 0; regi < 32; regi++)
56cea623 113 supply_register (mips_regnum (current_gdbarch)->fp0 + regi,
c5aa993b 114 (char *) &fpregsetp->fp_r.fp_regs[regi]);
c906108c 115
56cea623
AC
116 supply_register (mips_regnum (current_gdbarch)->fp_control_status,
117 (char *) &fpregsetp->fp_csr);
c906108c 118
56cea623
AC
119 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
120 supply_register (mips_regnum (current_gdbarch)->fp_implementation_revision,
121 zerobuf);
c906108c
SS
122}
123
124void
fba45db2 125fill_fpregset (fpregset_t *fpregsetp, int regno)
c906108c
SS
126{
127 int regi;
128 char *from, *to;
129
56cea623
AC
130 for (regi = mips_regnum (current_gdbarch)->fp0;
131 regi < mips_regnum (current_gdbarch)->fp0 + 32; regi++)
c906108c
SS
132 {
133 if ((regno == -1) || (regno == regi))
134 {
62700349 135 from = (char *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)];
56cea623 136 to = (char *) &(fpregsetp->fp_r.fp_regs[regi - mips_regnum (current_gdbarch)->fp0]);
12c266ea 137 memcpy (to, from, DEPRECATED_REGISTER_RAW_SIZE (regi));
c906108c
SS
138 }
139 }
140
56cea623
AC
141 if ((regno == -1)
142 || (regno == mips_regnum (current_gdbarch)->fp_control_status))
143 fpregsetp->fp_csr = *(unsigned *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)];
c906108c
SS
144}
145
146
147/* Figure out where the longjmp will land.
148 We expect the first arg to be a pointer to the jmp_buf structure from which
149 we extract the pc (_JB_PC) that we will land at. The pc is copied into PC.
150 This routine returns true on success. */
151
152int
fba45db2 153get_longjmp_target (CORE_ADDR *pc)
c906108c 154{
35fc8285 155 char *buf;
c906108c
SS
156 CORE_ADDR jb_addr;
157
35fc8285 158 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
c906108c
SS
159 jb_addr = read_register (A0_REGNUM);
160
161 if (target_read_memory (jb_addr + _JB_PC * JB_ELEMENT_SIZE, buf,
162 TARGET_PTR_BIT / TARGET_CHAR_BIT))
163 return 0;
164
7c0b4a20 165 *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
c906108c
SS
166
167 return 1;
168}
This page took 0.353598 seconds and 4 git commands to generate.