| 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. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 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. |
| 12 | |
| 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. |
| 17 | |
| 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. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "inferior.h" |
| 24 | #include "gdbcore.h" |
| 25 | |
| 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. */ |
| 29 | |
| 30 | #if defined(sgi) |
| 31 | void |
| 32 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) |
| 33 | char *core_reg_sect; |
| 34 | unsigned core_reg_size; |
| 35 | int which; |
| 36 | unsigned int reg_addr; |
| 37 | { |
| 38 | return; |
| 39 | } |
| 40 | #endif |
| 41 | |
| 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 */ |
| 44 | |
| 45 | #if defined(sgi) || !defined(GDB_TARGET_IS_MIPS) |
| 46 | |
| 47 | /* ARGSUSED */ |
| 48 | void |
| 49 | fetch_inferior_registers (regno) |
| 50 | int regno; |
| 51 | { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | /* ARGSUSED */ |
| 56 | void |
| 57 | store_inferior_registers (regno) |
| 58 | int regno; |
| 59 | { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | #else |
| 65 | |
| 66 | /* Map gdb internal register number to ptrace address. */ |
| 67 | |
| 68 | #define REGISTER_PTRACE_ADDR(regno) \ |
| 69 | (regno < 32 ? regno \ |
| 70 | : regno == PC_REGNUM ? 96 \ |
| 71 | : regno == CAUSE_REGNUM ? 97 \ |
| 72 | : regno == HI_REGNUM ? 98 \ |
| 73 | : regno == LO_REGNUM ? 99 \ |
| 74 | : regno == FCRCS_REGNUM ? 100 \ |
| 75 | : regno == FCRIR_REGNUM ? 101 \ |
| 76 | : regno >= FP0_REGNUM ? regno - (FP0_REGNUM-32)\ |
| 77 | : 0) |
| 78 | |
| 79 | /* Get all registers from the inferior */ |
| 80 | |
| 81 | void |
| 82 | fetch_inferior_registers (regno) |
| 83 | int regno; |
| 84 | { |
| 85 | register unsigned int regaddr; |
| 86 | char buf[MAX_REGISTER_RAW_SIZE]; |
| 87 | register int i; |
| 88 | |
| 89 | registers_fetched (); |
| 90 | |
| 91 | for (regno = 1; regno < NUM_REGS; regno++) |
| 92 | { |
| 93 | regaddr = REGISTER_PTRACE_ADDR (regno); |
| 94 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) |
| 95 | { |
| 96 | *(int *) &buf[i] = ptrace (3, inferior_pid, |
| 97 | (PTRACE_ARG3_TYPE) regaddr, 0); |
| 98 | regaddr += sizeof (int); |
| 99 | } |
| 100 | supply_register (regno, buf); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /* Store our register values back into the inferior. |
| 105 | If REGNO is -1, do this for all registers. |
| 106 | Otherwise, REGNO specifies which register (so we can save time). */ |
| 107 | |
| 108 | void |
| 109 | store_inferior_registers (regno) |
| 110 | int regno; |
| 111 | { |
| 112 | register unsigned int regaddr; |
| 113 | char buf[80]; |
| 114 | |
| 115 | if (regno == 0) |
| 116 | return; |
| 117 | |
| 118 | if (regno > 0) |
| 119 | { |
| 120 | regaddr = REGISTER_PTRACE_ADDR (regno); |
| 121 | errno = 0; |
| 122 | ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, |
| 123 | read_register (regno)); |
| 124 | if (errno != 0) |
| 125 | { |
| 126 | sprintf (buf, "writing register number %d", regno); |
| 127 | perror_with_name (buf); |
| 128 | } |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | for (regno = 0; regno < NUM_REGS; regno++) |
| 133 | { |
| 134 | if (regno == ZERO_REGNUM || regno == PS_REGNUM |
| 135 | || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM |
| 136 | || regno == FCRIR_REGNUM || regno == FP_REGNUM |
| 137 | || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM)) |
| 138 | continue; |
| 139 | regaddr = register_addr (regno, 1); |
| 140 | errno = 0; |
| 141 | ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, |
| 142 | read_register (regno)); |
| 143 | if (errno != 0) |
| 144 | { |
| 145 | sprintf (buf, "writing all regs, number %d", regno); |
| 146 | perror_with_name (buf); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | #endif /* sgi */ |