* dvp-opc.c (parse_vif_unpackloc,insert_vif_unpackloc): Delete.
[deliverable/binutils-gdb.git] / gdb / mips-nat.c
CommitLineData
2268d619 1/* Low level DECstation interface to ptrace, for GDB when running native.
3f403f6a 2 Copyright 1988, 1989, 1991, 1992, 1995 Free Software Foundation, Inc.
a70dc898
RP
3 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
4 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
6c9638b4 20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
a70dc898
RP
21
22#include "defs.h"
23#include "inferior.h"
24#include "gdbcore.h"
2268d619 25#include <sys/ptrace.h>
56fc16c7
SG
26#include <sys/types.h>
27#include <sys/param.h>
56fc16c7 28#include <sys/user.h>
2675499b
SG
29#undef JB_S0
30#undef JB_S1
31#undef JB_S2
32#undef JB_S3
33#undef JB_S4
34#undef JB_S5
35#undef JB_S6
36#undef JB_S7
37#undef JB_SP
38#undef JB_S8
39#undef JB_PC
40#undef JB_SR
41#undef NJBREGS
42#include <setjmp.h> /* For JB_XXX. */
56fc16c7 43
2268d619 44/* Size of elements in jmpbuf */
a70dc898 45
2268d619 46#define JB_ELEMENT_SIZE 4
a70dc898
RP
47
48/* Map gdb internal register number to ptrace ``address''.
49 These ``addresses'' are defined in DECstation <sys/ptrace.h> */
50
51#define REGISTER_PTRACE_ADDR(regno) \
52 (regno < 32 ? GPR_BASE + regno \
53 : regno == PC_REGNUM ? PC \
54 : regno == CAUSE_REGNUM ? CAUSE \
55 : regno == HI_REGNUM ? MMHI \
56 : regno == LO_REGNUM ? MMLO \
57 : regno == FCRCS_REGNUM ? FPC_CSR \
58 : regno == FCRIR_REGNUM ? FPC_EIR \
59 : regno >= FP0_REGNUM ? FPR_BASE + (regno - FP0_REGNUM) \
60 : 0)
61
3496b745 62static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
a70dc898 63
948a9d92
FF
64static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR));
65
a70dc898
RP
66/* Get all registers from the inferior */
67
68void
69fetch_inferior_registers (regno)
70 int regno;
71{
72 register unsigned int regaddr;
73 char buf[MAX_REGISTER_RAW_SIZE];
74 register int i;
75
76 registers_fetched ();
77
78 for (regno = 1; regno < NUM_REGS; regno++)
79 {
80 regaddr = REGISTER_PTRACE_ADDR (regno);
81 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
82 {
83 *(int *) &buf[i] = ptrace (PT_READ_U, inferior_pid,
84 (PTRACE_ARG3_TYPE) regaddr, 0);
85 regaddr += sizeof (int);
86 }
87 supply_register (regno, buf);
88 }
89
90 supply_register (ZERO_REGNUM, zerobuf);
91 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
92 supply_register (FP_REGNUM, zerobuf);
93}
94
95/* Store our register values back into the inferior.
96 If REGNO is -1, do this for all registers.
97 Otherwise, REGNO specifies which register (so we can save time). */
98
99void
100store_inferior_registers (regno)
101 int regno;
102{
103 register unsigned int regaddr;
104 char buf[80];
105
a70dc898
RP
106 if (regno > 0)
107 {
3f403f6a
PS
108 if (regno == ZERO_REGNUM || regno == PS_REGNUM
109 || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
110 || regno == FCRIR_REGNUM || regno == FP_REGNUM
111 || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM))
112 return;
a70dc898
RP
113 regaddr = REGISTER_PTRACE_ADDR (regno);
114 errno = 0;
115 ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
116 read_register (regno));
117 if (errno != 0)
118 {
119 sprintf (buf, "writing register number %d", regno);
120 perror_with_name (buf);
121 }
122 }
123 else
124 {
125 for (regno = 0; regno < NUM_REGS; regno++)
3f403f6a 126 store_inferior_registers (regno);
a70dc898
RP
127 }
128}
129
a70dc898 130
2268d619
JG
131/* Figure out where the longjmp will land.
132 We expect the first arg to be a pointer to the jmp_buf structure from which
133 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
134 This routine returns true on success. */
135
136int
137get_longjmp_target(pc)
138 CORE_ADDR *pc;
139{
140 CORE_ADDR jb_addr;
34df79fc 141 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
2268d619 142
34df79fc 143 jb_addr = read_register (A0_REGNUM);
a70dc898 144
34df79fc
JK
145 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
146 TARGET_PTR_BIT / TARGET_CHAR_BIT))
2268d619
JG
147 return 0;
148
34df79fc 149 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
2268d619
JG
150
151 return 1;
152}
56fc16c7
SG
153
154/* Extract the register values out of the core file and store
155 them where `read_register' will find them.
156
157 CORE_REG_SECT points to the register values themselves, read into memory.
158 CORE_REG_SIZE is the size of that area.
159 WHICH says which set of registers we are handling (0 = int, 2 = float
160 on machines where they are discontiguous).
161 REG_ADDR is the offset from u.u_ar0 to the register values relative to
162 core_reg_sect. This is used with old-fashioned core files to
163 locate the registers in a large upage-plus-stack ".reg" section.
164 Original upage address X is at location core_reg_sect+x+reg_addr.
165 */
166
a1df8e78 167static void
56fc16c7
SG
168fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
169 char *core_reg_sect;
170 unsigned core_reg_size;
171 int which;
948a9d92 172 CORE_ADDR reg_addr;
56fc16c7
SG
173{
174 register int regno;
175 register unsigned int addr;
176 int bad_reg = -1;
177 register reg_ptr = -reg_addr; /* Original u.u_ar0 is -reg_addr. */
178
179 /* If u.u_ar0 was an absolute address in the core file, relativize it now,
180 so we can use it as an offset into core_reg_sect. When we're done,
181 "register 0" will be at core_reg_sect+reg_ptr, and we can use
182 register_addr to offset to the other registers. If this is a modern
183 core file without a upage, reg_ptr will be zero and this is all a big
184 NOP. */
185 if (reg_ptr > core_reg_size)
3762d624 186#ifdef KERNEL_U_ADDR
56fc16c7 187 reg_ptr -= KERNEL_U_ADDR;
3762d624
JK
188#else
189 error ("Old mips core file can't be processed on this machine.");
190#endif
56fc16c7
SG
191
192 for (regno = 0; regno < NUM_REGS; regno++)
193 {
194 addr = register_addr (regno, reg_ptr);
195 if (addr >= core_reg_size) {
196 if (bad_reg < 0)
197 bad_reg = regno;
198 } else {
199 supply_register (regno, core_reg_sect + addr);
200 }
201 }
202 if (bad_reg >= 0)
203 {
204 error ("Register %s not found in core file.", reg_names[bad_reg]);
205 }
206 supply_register (ZERO_REGNUM, zerobuf);
207 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
208 supply_register (FP_REGNUM, zerobuf);
209}
210
211/* Return the address in the core dump or inferior of register REGNO.
212 BLOCKEND is the address of the end of the user structure. */
213
948a9d92 214CORE_ADDR
56fc16c7
SG
215register_addr (regno, blockend)
216 int regno;
948a9d92 217 CORE_ADDR blockend;
56fc16c7 218{
948a9d92 219 CORE_ADDR addr;
56fc16c7
SG
220
221 if (regno < 0 || regno >= NUM_REGS)
222 error ("Invalid register number %d.", regno);
223
224 REGISTER_U_ADDR (addr, blockend, regno);
225
226 return addr;
227}
a1df8e78
FF
228
229\f
230/* Register that we are able to handle mips core file formats.
231 FIXME: is this really bfd_target_unknown_flavour? */
232
233static struct core_fns mips_core_fns =
234{
235 bfd_target_unknown_flavour,
236 fetch_core_registers,
237 NULL
238};
239
240void
241_initialize_core_mips ()
242{
243 add_core_fns (&mips_core_fns);
244}
This page took 0.305134 seconds and 4 git commands to generate.