1/* Native support for MIPS running SVR4, for GDB. 2 Copyright 1994, 1995, 2000, 2001 Free Software Foundation, Inc. 3 4 This file is part of GDB. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. */ 20 21#include "defs.h" 22#include "inferior.h" 23#include "gdbcore.h" 24#include "target.h" 25#include "regcache.h" 26 27#include <sys/time.h> 28#include <sys/procfs.h> 29#include <setjmp.h> /* For JB_XXX. */ 30 31/* Prototypes for supply_gregset etc. */ 32#include "gregset.h" 33 34/* Size of elements in jmpbuf */ 35 36#define JB_ELEMENT_SIZE 4 37 38/* 39 * See the comment in m68k-tdep.c regarding the utility of these functions. 40 * 41 * These definitions are from the MIPS SVR4 ABI, so they may work for 42 * any MIPS SVR4 target. 43 */ 44 45void 46supply_gregset (gregset_t *gregsetp) 47{ 48 int regi; 49 greg_t *regp = &(*gregsetp)[0]; 50 char zerobuf[MAX_REGISTER_SIZE]; 51 memset (zerobuf, 0, MAX_REGISTER_SIZE); 52 53 for (regi = 0; regi <= CXT_RA; regi++) 54 supply_register (regi, (char *) (regp + regi)); 55 56 supply_register (mips_regnum (current_gdbarch)->pc, 57 (char *) (regp + CXT_EPC)); 58 supply_register (mips_regnum (current_gdbarch)->hi, 59 (char *) (regp + CXT_MDHI)); 60 supply_register (mips_regnum (current_gdbarch)->lo, 61 (char *) (regp + CXT_MDLO)); 62 supply_register (mips_regnum (current_gdbarch)->cause, 63 (char *) (regp + CXT_CAUSE)); 64 65 /* Fill inaccessible registers with zero. */ 66 supply_register (PS_REGNUM, zerobuf); 67 supply_register (mips_regnum (current_gdbarch)->badvaddr, zerobuf); 68 supply_register (DEPRECATED_FP_REGNUM, zerobuf); 69 supply_register (UNUSED_REGNUM, zerobuf); 70 for (regi = FIRST_EMBED_REGNUM; regi <= LAST_EMBED_REGNUM; regi++) 71 supply_register (regi, zerobuf); 72} 73 74void 75fill_gregset (gregset_t *gregsetp, int regno) 76{ 77 int regi; 78 greg_t *regp = &(*gregsetp)[0]; 79 80 for (regi = 0; regi <= 32; regi++) 81 if ((regno == -1) || (regno == regi)) 82 *(regp + regi) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)]; 83 84 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->pc)) 85 *(regp + CXT_EPC) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)]; 86 87 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause)) 88 *(regp + CXT_CAUSE) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->cause)]; 89 90 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->hi)) 91 *(regp + CXT_MDHI) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)]; 92 93 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo)) 94 *(regp + CXT_MDLO) = *(greg_t *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)]; 95} 96 97/* 98 * Now we do the same thing for floating-point registers. 99 * We don't bother to condition on FP0 regnum since any 100 * reasonable MIPS configuration has an R3010 in it. 101 * 102 * Again, see the comments in m68k-tdep.c. 103 */ 104 105void 106supply_fpregset (fpregset_t *fpregsetp) 107{ 108 int regi; 109 char zerobuf[MAX_REGISTER_SIZE]; 110 memset (zerobuf, 0, MAX_REGISTER_SIZE); 111 112 for (regi = 0; regi < 32; regi++) 113 supply_register (mips_regnum (current_gdbarch)->fp0 + regi, 114 (char *) &fpregsetp->fp_r.fp_regs[regi]); 115 116 supply_register (mips_regnum (current_gdbarch)->fp_control_status, 117 (char *) &fpregsetp->fp_csr); 118 119 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */ 120 supply_register (mips_regnum (current_gdbarch)->fp_implementation_revision, 121 zerobuf); 122} 123 124void 125fill_fpregset (fpregset_t *fpregsetp, int regno) 126{ 127 int regi; 128 char *from, *to; 129 130 for (regi = mips_regnum (current_gdbarch)->fp0; 131 regi < mips_regnum (current_gdbarch)->fp0 + 32; regi++) 132 { 133 if ((regno == -1) || (regno == regi)) 134 { 135 from = (char *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)]; 136 to = (char *) &(fpregsetp->fp_r.fp_regs[regi - mips_regnum (current_gdbarch)->fp0]); 137 memcpy (to, from, DEPRECATED_REGISTER_RAW_SIZE (regi)); 138 } 139 } 140 141 if ((regno == -1) 142 || (regno == mips_regnum (current_gdbarch)->fp_control_status)) 143 fpregsetp->fp_csr = *(unsigned *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)]; 144} 145 146 147/* Figure out where the longjmp will land. 148 We expect the first arg to be a pointer to the jmp_buf structure from which 149 we extract the pc (_JB_PC) that we will land at. The pc is copied into PC. 150 This routine returns true on success. */ 151 152int 153get_longjmp_target (CORE_ADDR *pc) 154{ 155 char *buf; 156 CORE_ADDR jb_addr; 157 158 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); 159 jb_addr = read_register (A0_REGNUM); 160 161 if (target_read_memory (jb_addr + _JB_PC * JB_ELEMENT_SIZE, buf, 162 TARGET_PTR_BIT / TARGET_CHAR_BIT)) 163 return 0; 164 165 *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); 166 167 return 1; 168} 169