1 /* Low level DECstation interface to ptrace, for GDB when running native.
2 Copyright 1988, 1989, 1991, 1992, 1995 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include <sys/ptrace.h>
26 #include <sys/types.h>
27 #include <sys/param.h>
42 #include <setjmp.h> /* For JB_XXX. */
44 /* Size of elements in jmpbuf */
46 #define JB_ELEMENT_SIZE 4
48 /* Map gdb internal register number to ptrace ``address''.
49 These ``addresses'' are defined in DECstation <sys/ptrace.h> */
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) \
62 static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
64 /* Get all registers from the inferior */
67 fetch_inferior_registers (regno)
70 register unsigned int regaddr;
71 char buf[MAX_REGISTER_RAW_SIZE];
76 for (regno = 1; regno < NUM_REGS; regno++)
78 regaddr = REGISTER_PTRACE_ADDR (regno);
79 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
81 *(int *) &buf[i] = ptrace (PT_READ_U, inferior_pid,
82 (PTRACE_ARG3_TYPE) regaddr, 0);
83 regaddr += sizeof (int);
85 supply_register (regno, buf);
88 supply_register (ZERO_REGNUM, zerobuf);
89 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
90 supply_register (FP_REGNUM, zerobuf);
93 /* Store our register values back into the inferior.
94 If REGNO is -1, do this for all registers.
95 Otherwise, REGNO specifies which register (so we can save time). */
98 store_inferior_registers (regno)
101 register unsigned int regaddr;
106 if (regno == ZERO_REGNUM || regno == PS_REGNUM
107 || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
108 || regno == FCRIR_REGNUM || regno == FP_REGNUM
109 || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM))
111 regaddr = REGISTER_PTRACE_ADDR (regno);
113 ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
114 read_register (regno));
117 sprintf (buf, "writing register number %d", regno);
118 perror_with_name (buf);
123 for (regno = 0; regno < NUM_REGS; regno++)
124 store_inferior_registers (regno);
129 /* Figure out where the longjmp will land.
130 We expect the first arg to be a pointer to the jmp_buf structure from which
131 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
132 This routine returns true on success. */
135 get_longjmp_target(pc)
139 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
141 jb_addr = read_register (A0_REGNUM);
143 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
144 TARGET_PTR_BIT / TARGET_CHAR_BIT))
147 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
152 /* Extract the register values out of the core file and store
153 them where `read_register' will find them.
155 CORE_REG_SECT points to the register values themselves, read into memory.
156 CORE_REG_SIZE is the size of that area.
157 WHICH says which set of registers we are handling (0 = int, 2 = float
158 on machines where they are discontiguous).
159 REG_ADDR is the offset from u.u_ar0 to the register values relative to
160 core_reg_sect. This is used with old-fashioned core files to
161 locate the registers in a large upage-plus-stack ".reg" section.
162 Original upage address X is at location core_reg_sect+x+reg_addr.
166 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
168 unsigned core_reg_size;
173 register unsigned int addr;
175 register reg_ptr = -reg_addr; /* Original u.u_ar0 is -reg_addr. */
177 /* If u.u_ar0 was an absolute address in the core file, relativize it now,
178 so we can use it as an offset into core_reg_sect. When we're done,
179 "register 0" will be at core_reg_sect+reg_ptr, and we can use
180 register_addr to offset to the other registers. If this is a modern
181 core file without a upage, reg_ptr will be zero and this is all a big
183 if (reg_ptr > core_reg_size)
185 reg_ptr -= KERNEL_U_ADDR;
187 error ("Old mips core file can't be processed on this machine.");
190 for (regno = 0; regno < NUM_REGS; regno++)
192 addr = register_addr (regno, reg_ptr);
193 if (addr >= core_reg_size) {
197 supply_register (regno, core_reg_sect + addr);
202 error ("Register %s not found in core file.", reg_names[bad_reg]);
204 supply_register (ZERO_REGNUM, zerobuf);
205 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
206 supply_register (FP_REGNUM, zerobuf);
209 /* Return the address in the core dump or inferior of register REGNO.
210 BLOCKEND is the address of the end of the user structure. */
213 register_addr (regno, blockend)
219 if (regno < 0 || regno >= NUM_REGS)
220 error ("Invalid register number %d.", regno);
222 REGISTER_U_ADDR (addr, blockend, regno);
228 /* Register that we are able to handle mips core file formats.
229 FIXME: is this really bfd_target_unknown_flavour? */
231 static struct core_fns mips_core_fns =
233 bfd_target_unknown_flavour,
234 fetch_core_registers,
239 _initialize_core_mips ()
241 add_core_fns (&mips_core_fns);