1 /* Low level MIPS interface to ptrace, for GDB when running under Unix.
2 Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
4 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
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 /* For now we stub this out; sgi core format is super-hairy (and completely
27 different in the new release).
28 For most mips systems, this function is defined in coredep.c. */
32 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
34 unsigned core_reg_size
;
36 unsigned int reg_addr
;
42 /* Access to the inferior is only good for native systems, not cross.
43 I am not sure why this is stubbed out on SGI... --gnu@cygnus.com */
45 #if defined(sgi) || !defined(GDB_TARGET_IS_MIPS)
49 fetch_inferior_registers (regno
)
57 store_inferior_registers (regno
)
66 /* DECstation native... */
68 #include <sys/ptrace.h>
70 /* Map gdb internal register number to ptrace ``address''.
71 These ``addresses'' are defined in DECstation <sys/ptrace.h> */
73 #define REGISTER_PTRACE_ADDR(regno) \
74 (regno < 32 ? GPR_BASE + regno \
75 : regno == PC_REGNUM ? PC \
76 : regno == CAUSE_REGNUM ? CAUSE \
77 : regno == HI_REGNUM ? MMHI \
78 : regno == LO_REGNUM ? MMLO \
79 : regno == FCRCS_REGNUM ? FPC_CSR \
80 : regno == FCRIR_REGNUM ? FPC_EIR \
81 : regno >= FP0_REGNUM ? FPR_BASE + (regno - FP0_REGNUM) \
84 static const char zerobuf
[MAX_REGISTER_RAW_SIZE
];
86 /* Get all registers from the inferior */
89 fetch_inferior_registers (regno
)
92 register unsigned int regaddr
;
93 char buf
[MAX_REGISTER_RAW_SIZE
];
98 for (regno
= 1; regno
< NUM_REGS
; regno
++)
100 regaddr
= REGISTER_PTRACE_ADDR (regno
);
101 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
103 *(int *) &buf
[i
] = ptrace (PT_READ_U
, inferior_pid
,
104 (PTRACE_ARG3_TYPE
) regaddr
, 0);
105 regaddr
+= sizeof (int);
107 supply_register (regno
, buf
);
110 supply_register (ZERO_REGNUM
, zerobuf
);
111 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
112 supply_register (FP_REGNUM
, zerobuf
);
115 /* Store our register values back into the inferior.
116 If REGNO is -1, do this for all registers.
117 Otherwise, REGNO specifies which register (so we can save time). */
120 store_inferior_registers (regno
)
123 register unsigned int regaddr
;
131 regaddr
= REGISTER_PTRACE_ADDR (regno
);
133 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
134 read_register (regno
));
137 sprintf (buf
, "writing register number %d", regno
);
138 perror_with_name (buf
);
143 for (regno
= 0; regno
< NUM_REGS
; regno
++)
145 if (regno
== ZERO_REGNUM
|| regno
== PS_REGNUM
146 || regno
== BADVADDR_REGNUM
|| regno
== CAUSE_REGNUM
147 || regno
== FCRIR_REGNUM
|| regno
== FP_REGNUM
148 || (regno
>= FIRST_EMBED_REGNUM
&& regno
<= LAST_EMBED_REGNUM
))
150 regaddr
= register_addr (regno
, 1);
152 ptrace (6, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
153 read_register (regno
));
156 sprintf (buf
, "writing all regs, number %d", regno
);
157 perror_with_name (buf
);