[gdb/testsuite] Factor out proc with_lock
[binutils-gdb.git] / gdbserver / netbsd-amd64-low.cc
blob2c8c7113f7ddc98fa7c2c6987aabb688cc9c233a
1 /* Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include <sys/types.h>
19 #include <sys/ptrace.h>
20 #include <limits.h>
22 #include "netbsd-low.h"
23 #include "gdbsupport/x86-xstate.h"
24 #include "arch/amd64.h"
25 #include "x86-tdesc.h"
26 #include "tdesc.h"
28 /* The index of various registers inside the regcache. */
30 enum netbsd_x86_64_gdb_regnum
32 AMD64_RAX_REGNUM, /* %rax */
33 AMD64_RBX_REGNUM, /* %rbx */
34 AMD64_RCX_REGNUM, /* %rcx */
35 AMD64_RDX_REGNUM, /* %rdx */
36 AMD64_RSI_REGNUM, /* %rsi */
37 AMD64_RDI_REGNUM, /* %rdi */
38 AMD64_RBP_REGNUM, /* %rbp */
39 AMD64_RSP_REGNUM, /* %rsp */
40 AMD64_R8_REGNUM, /* %r8 */
41 AMD64_R9_REGNUM, /* %r9 */
42 AMD64_R10_REGNUM, /* %r10 */
43 AMD64_R11_REGNUM, /* %r11 */
44 AMD64_R12_REGNUM, /* %r12 */
45 AMD64_R13_REGNUM, /* %r13 */
46 AMD64_R14_REGNUM, /* %r14 */
47 AMD64_R15_REGNUM, /* %r15 */
48 AMD64_RIP_REGNUM, /* %rip */
49 AMD64_EFLAGS_REGNUM, /* %eflags */
50 AMD64_CS_REGNUM, /* %cs */
51 AMD64_SS_REGNUM, /* %ss */
52 AMD64_DS_REGNUM, /* %ds */
53 AMD64_ES_REGNUM, /* %es */
54 AMD64_FS_REGNUM, /* %fs */
55 AMD64_GS_REGNUM, /* %gs */
56 AMD64_ST0_REGNUM = 24, /* %st0 */
57 AMD64_ST1_REGNUM, /* %st1 */
58 AMD64_FCTRL_REGNUM = AMD64_ST0_REGNUM + 8,
59 AMD64_FSTAT_REGNUM = AMD64_ST0_REGNUM + 9,
60 AMD64_FTAG_REGNUM = AMD64_ST0_REGNUM + 10,
61 AMD64_XMM0_REGNUM = 40, /* %xmm0 */
62 AMD64_XMM1_REGNUM, /* %xmm1 */
63 AMD64_MXCSR_REGNUM = AMD64_XMM0_REGNUM + 16,
64 AMD64_YMM0H_REGNUM, /* %ymm0h */
65 AMD64_YMM15H_REGNUM = AMD64_YMM0H_REGNUM + 15,
66 AMD64_BND0R_REGNUM = AMD64_YMM15H_REGNUM + 1,
67 AMD64_BND3R_REGNUM = AMD64_BND0R_REGNUM + 3,
68 AMD64_BNDCFGU_REGNUM,
69 AMD64_BNDSTATUS_REGNUM,
70 AMD64_XMM16_REGNUM,
71 AMD64_XMM31_REGNUM = AMD64_XMM16_REGNUM + 15,
72 AMD64_YMM16H_REGNUM,
73 AMD64_YMM31H_REGNUM = AMD64_YMM16H_REGNUM + 15,
74 AMD64_K0_REGNUM,
75 AMD64_K7_REGNUM = AMD64_K0_REGNUM + 7,
76 AMD64_ZMM0H_REGNUM,
77 AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31,
78 AMD64_PKRU_REGNUM,
79 AMD64_FSBASE_REGNUM,
80 AMD64_GSBASE_REGNUM
83 /* The fill_function for the general-purpose register set. */
85 static void
86 netbsd_x86_64_fill_gregset (struct regcache *regcache, char *buf)
88 struct reg *r = (struct reg *) buf;
90 #define netbsd_x86_64_collect_gp(regnum, fld) do { \
91 collect_register (regcache, regnum, &r->regs[_REG_##fld]); \
92 } while (0)
94 netbsd_x86_64_collect_gp (AMD64_RAX_REGNUM, RAX);
95 netbsd_x86_64_collect_gp (AMD64_RBX_REGNUM, RBX);
96 netbsd_x86_64_collect_gp (AMD64_RCX_REGNUM, RCX);
97 netbsd_x86_64_collect_gp (AMD64_RDX_REGNUM, RDX);
98 netbsd_x86_64_collect_gp (AMD64_RSI_REGNUM, RSI);
99 netbsd_x86_64_collect_gp (AMD64_RDI_REGNUM, RDI);
100 netbsd_x86_64_collect_gp (AMD64_RBP_REGNUM, RBP);
101 netbsd_x86_64_collect_gp (AMD64_RSP_REGNUM, RSP);
102 netbsd_x86_64_collect_gp (AMD64_R8_REGNUM, R8);
103 netbsd_x86_64_collect_gp (AMD64_R9_REGNUM, R9);
104 netbsd_x86_64_collect_gp (AMD64_R10_REGNUM, R10);
105 netbsd_x86_64_collect_gp (AMD64_R11_REGNUM, R11);
106 netbsd_x86_64_collect_gp (AMD64_R12_REGNUM, R12);
107 netbsd_x86_64_collect_gp (AMD64_R13_REGNUM, R13);
108 netbsd_x86_64_collect_gp (AMD64_R14_REGNUM, R14);
109 netbsd_x86_64_collect_gp (AMD64_R15_REGNUM, R15);
110 netbsd_x86_64_collect_gp (AMD64_RIP_REGNUM, RIP);
111 netbsd_x86_64_collect_gp (AMD64_EFLAGS_REGNUM, RFLAGS);
112 netbsd_x86_64_collect_gp (AMD64_CS_REGNUM, CS);
113 netbsd_x86_64_collect_gp (AMD64_SS_REGNUM, SS);
114 netbsd_x86_64_collect_gp (AMD64_DS_REGNUM, DS);
115 netbsd_x86_64_collect_gp (AMD64_ES_REGNUM, ES);
116 netbsd_x86_64_collect_gp (AMD64_FS_REGNUM, FS);
117 netbsd_x86_64_collect_gp (AMD64_GS_REGNUM, GS);
120 /* The store_function for the general-purpose register set. */
122 static void
123 netbsd_x86_64_store_gregset (struct regcache *regcache, const char *buf)
125 struct reg *r = (struct reg *) buf;
127 #define netbsd_x86_64_supply_gp(regnum, fld) do { \
128 supply_register (regcache, regnum, &r->regs[_REG_##fld]); \
129 } while(0)
131 netbsd_x86_64_supply_gp (AMD64_RAX_REGNUM, RAX);
132 netbsd_x86_64_supply_gp (AMD64_RBX_REGNUM, RBX);
133 netbsd_x86_64_supply_gp (AMD64_RCX_REGNUM, RCX);
134 netbsd_x86_64_supply_gp (AMD64_RDX_REGNUM, RDX);
135 netbsd_x86_64_supply_gp (AMD64_RSI_REGNUM, RSI);
136 netbsd_x86_64_supply_gp (AMD64_RDI_REGNUM, RDI);
137 netbsd_x86_64_supply_gp (AMD64_RBP_REGNUM, RBP);
138 netbsd_x86_64_supply_gp (AMD64_RSP_REGNUM, RSP);
139 netbsd_x86_64_supply_gp (AMD64_R8_REGNUM, R8);
140 netbsd_x86_64_supply_gp (AMD64_R9_REGNUM, R9);
141 netbsd_x86_64_supply_gp (AMD64_R10_REGNUM, R10);
142 netbsd_x86_64_supply_gp (AMD64_R11_REGNUM, R11);
143 netbsd_x86_64_supply_gp (AMD64_R12_REGNUM, R12);
144 netbsd_x86_64_supply_gp (AMD64_R13_REGNUM, R13);
145 netbsd_x86_64_supply_gp (AMD64_R14_REGNUM, R14);
146 netbsd_x86_64_supply_gp (AMD64_R15_REGNUM, R15);
147 netbsd_x86_64_supply_gp (AMD64_RIP_REGNUM, RIP);
148 netbsd_x86_64_supply_gp (AMD64_EFLAGS_REGNUM, RFLAGS);
149 netbsd_x86_64_supply_gp (AMD64_CS_REGNUM, CS);
150 netbsd_x86_64_supply_gp (AMD64_SS_REGNUM, SS);
151 netbsd_x86_64_supply_gp (AMD64_DS_REGNUM, DS);
152 netbsd_x86_64_supply_gp (AMD64_ES_REGNUM, ES);
153 netbsd_x86_64_supply_gp (AMD64_FS_REGNUM, FS);
154 netbsd_x86_64_supply_gp (AMD64_GS_REGNUM, GS);
157 /* Description of all the x86-netbsd register sets. */
159 static const struct netbsd_regset_info netbsd_target_regsets[] =
161 /* General Purpose Registers. */
162 {PT_GETREGS, PT_SETREGS, sizeof (struct reg),
163 netbsd_x86_64_fill_gregset, netbsd_x86_64_store_gregset},
164 /* End of list marker. */
165 {0, 0, -1, NULL, NULL }
168 /* NetBSD target op definitions for the amd64 architecture. */
170 class netbsd_amd64_target : public netbsd_process_target
172 protected:
173 const netbsd_regset_info *get_regs_info () override;
175 void low_arch_setup () override;
178 /* Return the information to access registers. */
180 const netbsd_regset_info *
181 netbsd_amd64_target::get_regs_info ()
183 return netbsd_target_regsets;
186 /* Architecture-specific setup for the current process. */
188 void
189 netbsd_amd64_target::low_arch_setup ()
191 target_desc *tdesc
192 = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, false, false);
194 init_target_desc (tdesc, amd64_expedite_regs);
196 current_process ()->tdesc = tdesc;
199 /* The singleton target ops object. */
201 static netbsd_amd64_target the_netbsd_amd64_target;
203 /* The NetBSD target ops object. */
205 netbsd_process_target *the_netbsd_target = &the_netbsd_amd64_target;