1130803Smarcel/* Native-dependent code for MIPS systems running NetBSD. 2130803Smarcel Copyright 2000, 2001, 2002 Free Software Foundation, Inc. 3130803Smarcel 4130803Smarcel This file is part of GDB. 5130803Smarcel 6130803Smarcel This program is free software; you can redistribute it and/or modify 7130803Smarcel it under the terms of the GNU General Public License as published by 8130803Smarcel the Free Software Foundation; either version 2 of the License, or 9130803Smarcel (at your option) any later version. 10130803Smarcel 11130803Smarcel This program is distributed in the hope that it will be useful, 12130803Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 13130803Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14130803Smarcel GNU General Public License for more details. 15130803Smarcel 16130803Smarcel You should have received a copy of the GNU General Public License 17130803Smarcel along with this program; if not, write to the Free Software 18130803Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 19130803Smarcel Boston, MA 02111-1307, USA. */ 20130803Smarcel 21130803Smarcel#include "defs.h" 22130803Smarcel#include "inferior.h" 23130803Smarcel#include "regcache.h" 24130803Smarcel 25130803Smarcel#include "mipsnbsd-tdep.h" 26130803Smarcel 27130803Smarcel#include <sys/types.h> 28130803Smarcel#include <sys/ptrace.h> 29130803Smarcel#include <machine/reg.h> 30130803Smarcel 31130803Smarcel/* Determine if PT_GETREGS fetches this register. */ 32130803Smarcelstatic int 33130803Smarcelgetregs_supplies (int regno) 34130803Smarcel{ 35130803Smarcel return ((regno) >= ZERO_REGNUM && (regno) <= PC_REGNUM); 36130803Smarcel} 37130803Smarcel 38130803Smarcelvoid 39130803Smarcelfetch_inferior_registers (int regno) 40130803Smarcel{ 41130803Smarcel if (regno == -1 || getregs_supplies (regno)) 42130803Smarcel { 43130803Smarcel struct reg regs; 44130803Smarcel 45130803Smarcel if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), 46130803Smarcel (PTRACE_ARG3_TYPE) ®s, 0) == -1) 47130803Smarcel perror_with_name ("Couldn't get registers"); 48130803Smarcel 49130803Smarcel mipsnbsd_supply_reg ((char *) ®s, regno); 50130803Smarcel if (regno != -1) 51130803Smarcel return; 52130803Smarcel } 53130803Smarcel 54130803Smarcel if (regno == -1 || regno >= FP0_REGNUM) 55130803Smarcel { 56130803Smarcel struct fpreg fpregs; 57130803Smarcel 58130803Smarcel if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), 59130803Smarcel (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) 60130803Smarcel perror_with_name ("Couldn't get floating point status"); 61130803Smarcel 62130803Smarcel mipsnbsd_supply_fpreg ((char *) &fpregs, regno); 63130803Smarcel } 64130803Smarcel} 65130803Smarcel 66130803Smarcelvoid 67130803Smarcelstore_inferior_registers (int regno) 68130803Smarcel{ 69130803Smarcel if (regno == -1 || getregs_supplies (regno)) 70130803Smarcel { 71130803Smarcel struct reg regs; 72130803Smarcel 73130803Smarcel if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), 74130803Smarcel (PTRACE_ARG3_TYPE) ®s, 0) == -1) 75130803Smarcel perror_with_name ("Couldn't get registers"); 76130803Smarcel 77130803Smarcel mipsnbsd_fill_reg ((char *) ®s, regno); 78130803Smarcel 79130803Smarcel if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), 80130803Smarcel (PTRACE_ARG3_TYPE) ®s, 0) == -1) 81130803Smarcel perror_with_name ("Couldn't write registers"); 82130803Smarcel 83130803Smarcel if (regno != -1) 84130803Smarcel return; 85130803Smarcel } 86130803Smarcel 87130803Smarcel if (regno == -1 || regno >= FP0_REGNUM) 88130803Smarcel { 89130803Smarcel struct fpreg fpregs; 90130803Smarcel 91130803Smarcel if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), 92130803Smarcel (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) 93130803Smarcel perror_with_name ("Couldn't get floating point status"); 94130803Smarcel 95130803Smarcel mipsnbsd_fill_fpreg ((char *) &fpregs, regno); 96130803Smarcel 97130803Smarcel if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), 98130803Smarcel (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) 99130803Smarcel perror_with_name ("Couldn't write floating point status"); 100130803Smarcel } 101130803Smarcel} 102