GDB (API)
/home/stan/gdb/src/gdb/mips64obsd-nat.c
Go to the documentation of this file.
00001 /* Native-dependent code for OpenBSD/mips64.
00002 
00003    Copyright (C) 2004-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "inferior.h"
00022 #include "regcache.h"
00023 #include "target.h"
00024 
00025 #include <sys/types.h>
00026 #include <sys/ptrace.h>
00027 #include <machine/reg.h>
00028 
00029 #include "mips-tdep.h"
00030 #include "inf-ptrace.h"
00031 
00032 /* Shorthand for some register numbers used below.  */
00033 #define MIPS_PC_REGNUM  MIPS_EMBED_PC_REGNUM
00034 #define MIPS_FP0_REGNUM MIPS_EMBED_FP0_REGNUM
00035 #define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32
00036 
00037 /* Supply the general-purpose registers stored in GREGS to REGCACHE.  */
00038 
00039 static void
00040 mips64obsd_supply_gregset (struct regcache *regcache, const void *gregs)
00041 {
00042   const char *regs = gregs;
00043   int regnum;
00044 
00045   for (regnum = MIPS_ZERO_REGNUM; regnum <= MIPS_PC_REGNUM; regnum++)
00046     regcache_raw_supply (regcache, regnum, regs + regnum * 8);
00047 
00048   for (regnum = MIPS_FP0_REGNUM; regnum <= MIPS_FSR_REGNUM; regnum++)
00049     regcache_raw_supply (regcache, regnum, regs + (regnum + 2) * 8);
00050 }
00051 
00052 /* Collect the general-purpose registers from REGCACHE and store them
00053    in GREGS.  */
00054 
00055 static void
00056 mips64obsd_collect_gregset (const struct regcache *regcache,
00057                             void *gregs, int regnum)
00058 {
00059   char *regs = gregs;
00060   int i;
00061 
00062   for (i = MIPS_ZERO_REGNUM; i <= MIPS_PC_REGNUM; i++)
00063     {
00064       if (regnum == -1 || regnum == i)
00065         regcache_raw_collect (regcache, i, regs + i * 8);
00066     }
00067 
00068   for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++)
00069     {
00070       if (regnum == -1 || regnum == i)
00071         regcache_raw_collect (regcache, i, regs + (i + 2) * 8);
00072     }
00073 }
00074 
00075 
00076 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
00077    for all registers.  */
00078 
00079 static void
00080 mips64obsd_fetch_inferior_registers (struct target_ops *ops,
00081                                      struct regcache *regcache, int regnum)
00082 {
00083   struct reg regs;
00084 
00085   if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
00086               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00087     perror_with_name (_("Couldn't get registers"));
00088 
00089   mips64obsd_supply_gregset (regcache, &regs);
00090 }
00091 
00092 /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
00093    this for all registers.  */
00094 
00095 static void
00096 mips64obsd_store_inferior_registers (struct target_ops *ops,
00097                                      struct regcache *regcache, int regnum)
00098 {
00099   struct reg regs;
00100 
00101   if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
00102               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00103     perror_with_name (_("Couldn't get registers"));
00104 
00105   mips64obsd_collect_gregset (regcache, &regs, regnum);
00106 
00107   if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
00108               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00109     perror_with_name (_("Couldn't write registers"));
00110 }
00111 
00112 
00113 /* Provide a prototype to silence -Wmissing-prototypes.  */
00114 void _initialize_mips64obsd_nat (void);
00115 
00116 void
00117 _initialize_mips64obsd_nat (void)
00118 {
00119   struct target_ops *t;
00120 
00121   t = inf_ptrace_target ();
00122   t->to_fetch_registers = mips64obsd_fetch_inferior_registers;
00123   t->to_store_registers = mips64obsd_store_inferior_registers;
00124   add_target (t);
00125 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines