1 /* Low level MIPS interface to ptrace, for GDB when running under Unix.
2 Copyright (C) 1988, 1989, 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include <mips/inst.h>
35 #include <sys/types.h>
38 #include <sys/param.h>
41 #include <sys/ioctl.h>
42 /* #include <fcntl.h> Can we live without this? */
46 #include <sys/user.h> /* After a.out.h */
50 /* For now we stub this out; sgi format is super-hairy (and completely
51 different in the new release) */
55 fetch_core_registers ()
61 fetch_inferior_registers ()
66 store_inferior_registers (regno)
75 /* Map gdb internal register number to ptrace address. */
77 #define REGISTER_PTRACE_ADDR(regno) \
79 : regno == PC_REGNUM ? 96 \
80 : regno == CAUSE_REGNUM ? 97 \
81 : regno == HI_REGNUM ? 98 \
82 : regno == LO_REGNUM ? 99 \
83 : regno == FCRCS_REGNUM ? 100 \
84 : regno == FCRIR_REGNUM ? 101 \
85 : regno >= FP0_REGNUM ? regno - (FP0_REGNUM-32)\
88 /* Get all registers from the inferior */
91 fetch_inferior_registers ()
94 register unsigned int regaddr;
95 char buf[MAX_REGISTER_RAW_SIZE];
100 for (regno = 1; regno < NUM_REGS; regno++)
102 regaddr = REGISTER_PTRACE_ADDR (regno);
103 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
105 *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0);
106 regaddr += sizeof (int);
108 supply_register (regno, buf);
112 /* Store our register values back into the inferior.
113 If REGNO is -1, do this for all registers.
114 Otherwise, REGNO specifies which register (so we can save time). */
117 store_inferior_registers (regno)
120 register unsigned int regaddr;
128 regaddr = REGISTER_PTRACE_ADDR (regno);
130 ptrace (6, inferior_pid, regaddr, read_register (regno));
133 sprintf (buf, "writing register number %d", regno);
134 perror_with_name (buf);
139 for (regno = 0; regno < NUM_REGS; regno++)
141 if (regno == ZERO_REGNUM || regno == PS_REGNUM
142 || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
143 || regno == FCRIR_REGNUM || regno == FP_REGNUM)
145 regaddr = register_addr (regno, 1);
147 ptrace (6, inferior_pid, regaddr, read_register (regno));
150 sprintf (buf, "writing all regs, number %d", regno);
151 perror_with_name (buf);
161 fetch_core_registers ()
166 for (regno = 1; regno < NUM_REGS; regno++) {
167 char buf[MAX_REGISTER_RAW_SIZE];
169 val = bfd_seek (core_bfd, register_addr (regno, 0));
170 if (val < 0 || (val = bfd_read (core_bfd, buf, sizeof buf)) < 0) {
172 strcpy (buffer, "Reading register ");
173 strcat (buffer, reg_names[regno]);
175 perror_with_name (buffer);
177 supply_register (regno, buf);