1/***********************************************************************
2Copyright 2003-2006 Raza Microelectronics, Inc.(RMI).
3This is a derived work from software originally provided by the external
4entity identified below. The licensing terms and warranties specified in
5the header of the original work apply to this derived work.
6Contribution by RMI:
7*****************************#RMI_1#**********************************/
8/* Native-dependent code for MIPS systems running NetBSD.
9   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
10
11   This file is part of GDB.
12
13   This program is free software; you can redistribute it and/or modify
14   it under the terms of the GNU General Public License as published by
15   the Free Software Foundation; either version 2 of the License, or
16   (at your option) any later version.
17
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program; if not, write to the Free Software
25   Foundation, Inc., 59 Temple Place - Suite 330,
26   Boston, MA 02111-1307, USA.  */
27
28#include "defs.h"
29#include "inferior.h"
30#include "regcache.h"
31
32#include "mipsfbsd-tdep.h"
33
34#include <sys/types.h>
35#include <sys/ptrace.h>
36#include <machine/reg.h>
37
38/* Determine if PT_GETREGS fetches this register.  */
39static int
40getregs_supplies (int regno)
41{
42  return ((regno) >= ZERO_REGNUM && (regno) <= PC_REGNUM);
43}
44
45void
46fetch_inferior_registers (int regno)
47{
48  if (regno == -1 || getregs_supplies (regno))
49    {
50      struct reg regs;
51
52      if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
53		  (PTRACE_ARG3_TYPE) &regs, 0) == -1)
54	perror_with_name ("Couldn't get registers");
55
56      mipsfbsd_supply_reg ((char *) &regs, regno);
57      if (regno != -1)
58	return;
59    }
60
61  if (regno == -1 || regno >= FP0_REGNUM)
62    {
63      struct fpreg fpregs;
64
65      if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
66		  (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
67	perror_with_name ("Couldn't get floating point status");
68
69      mipsfbsd_supply_fpreg ((char *) &fpregs, regno);
70    }
71}
72
73void
74store_inferior_registers (int regno)
75{
76  if (regno == -1 || getregs_supplies (regno))
77    {
78      struct reg regs;
79
80      if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
81		  (PTRACE_ARG3_TYPE) &regs, 0) == -1)
82	perror_with_name ("Couldn't get registers");
83
84      mipsfbsd_fill_reg ((char *) &regs, regno);
85
86      if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
87		  (PTRACE_ARG3_TYPE) &regs, 0) == -1)
88	perror_with_name ("Couldn't write registers");
89
90      if (regno != -1)
91	return;
92    }
93
94  if (regno == -1 || regno >= FP0_REGNUM)
95    {
96      struct fpreg fpregs;
97
98      if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
99		  (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
100	perror_with_name ("Couldn't get floating point status");
101
102      mipsfbsd_fill_fpreg ((char *) &fpregs, regno);
103
104      if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
105		  (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
106	perror_with_name ("Couldn't write floating point status");
107    }
108}
109