]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/amd64bsd-nat.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / amd64bsd-nat.c
CommitLineData
cced5e27
MK
1/* Native-dependent code for AMD64 BSD's.
2
6aba47ca 3 Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
cced5e27
MK
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
cced5e27
MK
21
22#include "defs.h"
23#include "inferior.h"
24#include "regcache.h"
6a5c78a3 25#include "target.h"
cced5e27
MK
26
27/* We include <signal.h> to make sure `struct fxsave64' is defined on
28 NetBSD, since NetBSD's <machine/reg.h> needs it. */
29#include "gdb_assert.h"
30#include <signal.h>
31#include <sys/types.h>
32#include <sys/ptrace.h>
33#include <machine/reg.h>
34
85be1ca6 35#include "amd64-tdep.h"
cced5e27 36#include "amd64-nat.h"
6a5c78a3 37#include "inf-ptrace.h"
cced5e27
MK
38\f
39
40/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
41 for all registers (including the floating-point registers). */
42
6a5c78a3
MK
43static void
44amd64bsd_fetch_inferior_registers (int regnum)
cced5e27
MK
45{
46 if (regnum == -1 || amd64_native_gregset_supplies_p (regnum))
47 {
48 struct reg regs;
49
50 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
9f8e0089 51 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
edefbb7c 52 perror_with_name (_("Couldn't get registers"));
cced5e27
MK
53
54 amd64_supply_native_gregset (current_regcache, &regs, -1);
55 if (regnum != -1)
56 return;
57 }
58
18bbbd9e 59 if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum))
cced5e27
MK
60 {
61 struct fpreg fpregs;
62
63 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
9f8e0089 64 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 65 perror_with_name (_("Couldn't get floating point status"));
cced5e27 66
90f90721 67 amd64_supply_fxsave (current_regcache, -1, &fpregs);
cced5e27
MK
68 }
69}
70
71/* Store register REGNUM back into the inferior. If REGNUM is -1, do
72 this for all registers (including the floating-point registers). */
73
6a5c78a3
MK
74static void
75amd64bsd_store_inferior_registers (int regnum)
cced5e27
MK
76{
77 if (regnum == -1 || amd64_native_gregset_supplies_p (regnum))
78 {
79 struct reg regs;
80
81 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
9f8e0089 82 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
edefbb7c 83 perror_with_name (_("Couldn't get registers"));
cced5e27
MK
84
85 amd64_collect_native_gregset (current_regcache, &regs, regnum);
86
87 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
9f8e0089 88 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
edefbb7c 89 perror_with_name (_("Couldn't write registers"));
cced5e27
MK
90
91 if (regnum != -1)
92 return;
93 }
94
18bbbd9e 95 if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum))
cced5e27
MK
96 {
97 struct fpreg fpregs;
98
99 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
9f8e0089 100 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 101 perror_with_name (_("Couldn't get floating point status"));
cced5e27 102
722d18c2 103 amd64_collect_fxsave (current_regcache, regnum, &fpregs);
cced5e27
MK
104
105 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
9f8e0089 106 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 107 perror_with_name (_("Couldn't write floating point status"));
cced5e27
MK
108 }
109}
6a5c78a3
MK
110
111/* Create a prototype *BSD/amd64 target. The client can override it
112 with local methods. */
113
114struct target_ops *
115amd64bsd_target (void)
116{
117 struct target_ops *t;
118
119 t = inf_ptrace_target ();
120 t->to_fetch_registers = amd64bsd_fetch_inferior_registers;
121 t->to_store_registers = amd64bsd_store_inferior_registers;
122 return t;
123}