]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/amd64bsd-nat.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / amd64bsd-nat.c
1 /* Native-dependent code for AMD64 BSD's.
2
3 Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
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
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include "defs.h"
23 #include "inferior.h"
24 #include "regcache.h"
25 #include "target.h"
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
35 #include "amd64-tdep.h"
36 #include "amd64-nat.h"
37 #include "inf-ptrace.h"
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
43 static void
44 amd64bsd_fetch_inferior_registers (int regnum)
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),
51 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
52 perror_with_name (_("Couldn't get registers"));
53
54 amd64_supply_native_gregset (current_regcache, &regs, -1);
55 if (regnum != -1)
56 return;
57 }
58
59 if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum))
60 {
61 struct fpreg fpregs;
62
63 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
64 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
65 perror_with_name (_("Couldn't get floating point status"));
66
67 amd64_supply_fxsave (current_regcache, -1, &fpregs);
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
74 static void
75 amd64bsd_store_inferior_registers (int regnum)
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),
82 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
83 perror_with_name (_("Couldn't get registers"));
84
85 amd64_collect_native_gregset (current_regcache, &regs, regnum);
86
87 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
88 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
89 perror_with_name (_("Couldn't write registers"));
90
91 if (regnum != -1)
92 return;
93 }
94
95 if (regnum == -1 || !amd64_native_gregset_supplies_p (regnum))
96 {
97 struct fpreg fpregs;
98
99 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
100 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
101 perror_with_name (_("Couldn't get floating point status"));
102
103 amd64_collect_fxsave (current_regcache, regnum, &fpregs);
104
105 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
106 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
107 perror_with_name (_("Couldn't write floating point status"));
108 }
109 }
110
111 /* Create a prototype *BSD/amd64 target. The client can override it
112 with local methods. */
113
114 struct target_ops *
115 amd64bsd_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 }