mips-fbsd-nat.c revision 1.1.1.5 1 1.1 christos /* Native-dependent code for FreeBSD/mips.
2 1.1 christos
3 1.1.1.5 christos Copyright (C) 2017-2024 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 "inferior.h"
21 1.1 christos #include "regcache.h"
22 1.1 christos #include "target.h"
23 1.1 christos
24 1.1 christos #include <sys/types.h>
25 1.1 christos #include <sys/ptrace.h>
26 1.1 christos #include <machine/reg.h>
27 1.1 christos
28 1.1 christos #include "fbsd-nat.h"
29 1.1 christos #include "mips-tdep.h"
30 1.1 christos #include "mips-fbsd-tdep.h"
31 1.1 christos #include "inf-ptrace.h"
32 1.1 christos
33 1.1.1.2 christos struct mips_fbsd_nat_target final : public fbsd_nat_target
34 1.1.1.2 christos {
35 1.1.1.2 christos void fetch_registers (struct regcache *, int) override;
36 1.1.1.2 christos void store_registers (struct regcache *, int) override;
37 1.1.1.2 christos };
38 1.1.1.2 christos
39 1.1.1.2 christos static mips_fbsd_nat_target the_mips_fbsd_nat_target;
40 1.1.1.2 christos
41 1.1.1.2 christos /* Determine if PT_GETREGS fetches REGNUM. */
42 1.1 christos
43 1.1 christos static bool
44 1.1 christos getregs_supplies (struct gdbarch *gdbarch, int regnum)
45 1.1 christos {
46 1.1 christos return (regnum >= MIPS_ZERO_REGNUM
47 1.1.1.2 christos && regnum <= mips_regnum (gdbarch)->pc);
48 1.1.1.2 christos }
49 1.1.1.2 christos
50 1.1.1.2 christos /* Determine if PT_GETFPREGS fetches REGNUM. */
51 1.1.1.2 christos
52 1.1.1.2 christos static bool
53 1.1.1.2 christos getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
54 1.1.1.2 christos {
55 1.1.1.2 christos return (regnum >= mips_regnum (gdbarch)->fp0
56 1.1.1.2 christos && regnum <= mips_regnum (gdbarch)->fp_implementation_revision);
57 1.1 christos }
58 1.1 christos
59 1.1 christos /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
60 1.1 christos for all registers. */
61 1.1 christos
62 1.1.1.2 christos void
63 1.1.1.2 christos mips_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
64 1.1 christos {
65 1.1.1.2 christos pid_t pid = get_ptrace_pid (regcache->ptid ());
66 1.1 christos
67 1.1.1.2 christos struct gdbarch *gdbarch = regcache->arch ();
68 1.1 christos if (regnum == -1 || getregs_supplies (gdbarch, regnum))
69 1.1 christos {
70 1.1 christos struct reg regs;
71 1.1 christos
72 1.1 christos if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
73 1.1 christos perror_with_name (_("Couldn't get registers"));
74 1.1 christos
75 1.1 christos mips_fbsd_supply_gregs (regcache, regnum, ®s, sizeof (register_t));
76 1.1 christos }
77 1.1 christos
78 1.1.1.2 christos if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
79 1.1 christos {
80 1.1 christos struct fpreg fpregs;
81 1.1 christos
82 1.1 christos if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
83 1.1 christos perror_with_name (_("Couldn't get floating point status"));
84 1.1 christos
85 1.1 christos mips_fbsd_supply_fpregs (regcache, regnum, &fpregs,
86 1.1 christos sizeof (f_register_t));
87 1.1 christos }
88 1.1 christos }
89 1.1 christos
90 1.1 christos /* Store register REGNUM back into the inferior. If REGNUM is -1, do
91 1.1 christos this for all registers. */
92 1.1 christos
93 1.1.1.2 christos void
94 1.1.1.2 christos mips_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
95 1.1 christos {
96 1.1.1.2 christos pid_t pid = get_ptrace_pid (regcache->ptid ());
97 1.1 christos
98 1.1.1.2 christos struct gdbarch *gdbarch = regcache->arch ();
99 1.1 christos if (regnum == -1 || getregs_supplies (gdbarch, regnum))
100 1.1 christos {
101 1.1 christos struct reg regs;
102 1.1 christos
103 1.1 christos if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
104 1.1 christos perror_with_name (_("Couldn't get registers"));
105 1.1 christos
106 1.1 christos mips_fbsd_collect_gregs (regcache, regnum, (char *) ®s,
107 1.1 christos sizeof (register_t));
108 1.1 christos
109 1.1 christos if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
110 1.1 christos perror_with_name (_("Couldn't write registers"));
111 1.1 christos }
112 1.1 christos
113 1.1.1.2 christos if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
114 1.1 christos {
115 1.1 christos struct fpreg fpregs;
116 1.1 christos
117 1.1 christos if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
118 1.1 christos perror_with_name (_("Couldn't get floating point status"));
119 1.1 christos
120 1.1 christos mips_fbsd_collect_fpregs (regcache, regnum, (char *) &fpregs,
121 1.1 christos sizeof (f_register_t));
122 1.1 christos
123 1.1 christos if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
124 1.1 christos perror_with_name (_("Couldn't write floating point status"));
125 1.1 christos }
126 1.1 christos }
127 1.1 christos
128 1.1.1.3 christos void _initialize_mips_fbsd_nat ();
129 1.1 christos void
130 1.1.1.3 christos _initialize_mips_fbsd_nat ()
131 1.1 christos {
132 1.1.1.2 christos add_inf_child_target (&the_mips_fbsd_nat_target);
133 1.1 christos }
134