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