mips-fbsd-nat.c revision 1.1.1.1.2.2 1 1.1.1.1.2.2 christos /* Native-dependent code for FreeBSD/mips.
2 1.1.1.1.2.2 christos
3 1.1.1.1.2.2 christos Copyright (C) 2017 Free Software Foundation, Inc.
4 1.1.1.1.2.2 christos
5 1.1.1.1.2.2 christos This file is part of GDB.
6 1.1.1.1.2.2 christos
7 1.1.1.1.2.2 christos This program is free software; you can redistribute it and/or modify
8 1.1.1.1.2.2 christos it under the terms of the GNU General Public License as published by
9 1.1.1.1.2.2 christos the Free Software Foundation; either version 3 of the License, or
10 1.1.1.1.2.2 christos (at your option) any later version.
11 1.1.1.1.2.2 christos
12 1.1.1.1.2.2 christos This program is distributed in the hope that it will be useful,
13 1.1.1.1.2.2 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1.1.1.2.2 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1.1.1.2.2 christos GNU General Public License for more details.
16 1.1.1.1.2.2 christos
17 1.1.1.1.2.2 christos You should have received a copy of the GNU General Public License
18 1.1.1.1.2.2 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1.1.1.2.2 christos
20 1.1.1.1.2.2 christos #include "defs.h"
21 1.1.1.1.2.2 christos #include "inferior.h"
22 1.1.1.1.2.2 christos #include "regcache.h"
23 1.1.1.1.2.2 christos #include "target.h"
24 1.1.1.1.2.2 christos
25 1.1.1.1.2.2 christos #include <sys/types.h>
26 1.1.1.1.2.2 christos #include <sys/ptrace.h>
27 1.1.1.1.2.2 christos #include <machine/reg.h>
28 1.1.1.1.2.2 christos
29 1.1.1.1.2.2 christos #include "fbsd-nat.h"
30 1.1.1.1.2.2 christos #include "mips-tdep.h"
31 1.1.1.1.2.2 christos #include "mips-fbsd-tdep.h"
32 1.1.1.1.2.2 christos #include "inf-ptrace.h"
33 1.1.1.1.2.2 christos
34 1.1.1.1.2.2 christos /* Determine if PT_GETREGS fetches this register. */
35 1.1.1.1.2.2 christos
36 1.1.1.1.2.2 christos static bool
37 1.1.1.1.2.2 christos getregs_supplies (struct gdbarch *gdbarch, int regnum)
38 1.1.1.1.2.2 christos {
39 1.1.1.1.2.2 christos return (regnum >= MIPS_ZERO_REGNUM
40 1.1.1.1.2.2 christos && regnum <= gdbarch_pc_regnum (gdbarch));
41 1.1.1.1.2.2 christos }
42 1.1.1.1.2.2 christos
43 1.1.1.1.2.2 christos /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
44 1.1.1.1.2.2 christos for all registers. */
45 1.1.1.1.2.2 christos
46 1.1.1.1.2.2 christos static void
47 1.1.1.1.2.2 christos mips_fbsd_fetch_inferior_registers (struct target_ops *ops,
48 1.1.1.1.2.2 christos struct regcache *regcache, int regnum)
49 1.1.1.1.2.2 christos {
50 1.1.1.1.2.2 christos pid_t pid = get_ptrace_pid (regcache_get_ptid (regcache));
51 1.1.1.1.2.2 christos
52 1.1.1.1.2.2 christos struct gdbarch *gdbarch = get_regcache_arch (regcache);
53 1.1.1.1.2.2 christos if (regnum == -1 || getregs_supplies (gdbarch, regnum))
54 1.1.1.1.2.2 christos {
55 1.1.1.1.2.2 christos struct reg regs;
56 1.1.1.1.2.2 christos
57 1.1.1.1.2.2 christos if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
58 1.1.1.1.2.2 christos perror_with_name (_("Couldn't get registers"));
59 1.1.1.1.2.2 christos
60 1.1.1.1.2.2 christos mips_fbsd_supply_gregs (regcache, regnum, ®s, sizeof (register_t));
61 1.1.1.1.2.2 christos if (regnum != -1)
62 1.1.1.1.2.2 christos return;
63 1.1.1.1.2.2 christos }
64 1.1.1.1.2.2 christos
65 1.1.1.1.2.2 christos if (regnum == -1
66 1.1.1.1.2.2 christos || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
67 1.1.1.1.2.2 christos {
68 1.1.1.1.2.2 christos struct fpreg fpregs;
69 1.1.1.1.2.2 christos
70 1.1.1.1.2.2 christos if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
71 1.1.1.1.2.2 christos perror_with_name (_("Couldn't get floating point status"));
72 1.1.1.1.2.2 christos
73 1.1.1.1.2.2 christos mips_fbsd_supply_fpregs (regcache, regnum, &fpregs,
74 1.1.1.1.2.2 christos sizeof (f_register_t));
75 1.1.1.1.2.2 christos }
76 1.1.1.1.2.2 christos }
77 1.1.1.1.2.2 christos
78 1.1.1.1.2.2 christos /* Store register REGNUM back into the inferior. If REGNUM is -1, do
79 1.1.1.1.2.2 christos this for all registers. */
80 1.1.1.1.2.2 christos
81 1.1.1.1.2.2 christos static void
82 1.1.1.1.2.2 christos mips_fbsd_store_inferior_registers (struct target_ops *ops,
83 1.1.1.1.2.2 christos struct regcache *regcache, int regnum)
84 1.1.1.1.2.2 christos {
85 1.1.1.1.2.2 christos pid_t pid = get_ptrace_pid (regcache_get_ptid (regcache));
86 1.1.1.1.2.2 christos
87 1.1.1.1.2.2 christos struct gdbarch *gdbarch = get_regcache_arch (regcache);
88 1.1.1.1.2.2 christos if (regnum == -1 || getregs_supplies (gdbarch, regnum))
89 1.1.1.1.2.2 christos {
90 1.1.1.1.2.2 christos struct reg regs;
91 1.1.1.1.2.2 christos
92 1.1.1.1.2.2 christos if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
93 1.1.1.1.2.2 christos perror_with_name (_("Couldn't get registers"));
94 1.1.1.1.2.2 christos
95 1.1.1.1.2.2 christos mips_fbsd_collect_gregs (regcache, regnum, (char *) ®s,
96 1.1.1.1.2.2 christos sizeof (register_t));
97 1.1.1.1.2.2 christos
98 1.1.1.1.2.2 christos if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
99 1.1.1.1.2.2 christos perror_with_name (_("Couldn't write registers"));
100 1.1.1.1.2.2 christos
101 1.1.1.1.2.2 christos if (regnum != -1)
102 1.1.1.1.2.2 christos return;
103 1.1.1.1.2.2 christos }
104 1.1.1.1.2.2 christos
105 1.1.1.1.2.2 christos if (regnum == -1
106 1.1.1.1.2.2 christos || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
107 1.1.1.1.2.2 christos {
108 1.1.1.1.2.2 christos struct fpreg fpregs;
109 1.1.1.1.2.2 christos
110 1.1.1.1.2.2 christos if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
111 1.1.1.1.2.2 christos perror_with_name (_("Couldn't get floating point status"));
112 1.1.1.1.2.2 christos
113 1.1.1.1.2.2 christos mips_fbsd_collect_fpregs (regcache, regnum, (char *) &fpregs,
114 1.1.1.1.2.2 christos sizeof (f_register_t));
115 1.1.1.1.2.2 christos
116 1.1.1.1.2.2 christos if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
117 1.1.1.1.2.2 christos perror_with_name (_("Couldn't write floating point status"));
118 1.1.1.1.2.2 christos }
119 1.1.1.1.2.2 christos }
120 1.1.1.1.2.2 christos
121 1.1.1.1.2.2 christos
123 1.1.1.1.2.2 christos /* Provide a prototype to silence -Wmissing-prototypes. */
124 1.1.1.1.2.2 christos void _initialize_mips_fbsd_nat (void);
125 1.1.1.1.2.2 christos
126 1.1.1.1.2.2 christos void
127 1.1.1.1.2.2 christos _initialize_mips_fbsd_nat (void)
128 1.1.1.1.2.2 christos {
129 1.1.1.1.2.2 christos struct target_ops *t;
130 1.1.1.1.2.2 christos
131 1.1.1.1.2.2 christos t = inf_ptrace_target ();
132 1.1.1.1.2.2 christos t->to_fetch_registers = mips_fbsd_fetch_inferior_registers;
133 1.1.1.1.2.2 christos t->to_store_registers = mips_fbsd_store_inferior_registers;
134 1.1.1.1.2.2 christos fbsd_nat_add_target (t);
135 }
136