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>
22 #include "netbsd-low.h"
23 #include "gdbsupport/x86-xstate.h"
24 #include "arch/i386.h"
25 #include "x86-tdesc.h"
28 /* The index of various registers inside the regcache. */
30 enum netbsd_i386_gdb_regnum
32 I386_EAX_REGNUM
, /* %eax */
33 I386_ECX_REGNUM
, /* %ecx */
34 I386_EDX_REGNUM
, /* %edx */
35 I386_EBX_REGNUM
, /* %ebx */
36 I386_ESP_REGNUM
, /* %esp */
37 I386_EBP_REGNUM
, /* %ebp */
38 I386_ESI_REGNUM
, /* %esi */
39 I386_EDI_REGNUM
, /* %edi */
40 I386_EIP_REGNUM
, /* %eip */
41 I386_EFLAGS_REGNUM
, /* %eflags */
42 I386_CS_REGNUM
, /* %cs */
43 I386_SS_REGNUM
, /* %ss */
44 I386_DS_REGNUM
, /* %ds */
45 I386_ES_REGNUM
, /* %es */
46 I386_FS_REGNUM
, /* %fs */
47 I386_GS_REGNUM
, /* %gs */
48 I386_ST0_REGNUM
/* %st(0) */
51 /* The fill_function for the general-purpose register set. */
54 netbsd_i386_fill_gregset (struct regcache
*regcache
, char *buf
)
56 struct reg
*r
= (struct reg
*) buf
;
58 #define netbsd_i386_collect_gp(regnum, fld) do { \
59 collect_register (regcache, regnum, &r->r_##fld); \
62 netbsd_i386_collect_gp (I386_EAX_REGNUM
, eax
);
63 netbsd_i386_collect_gp (I386_EBX_REGNUM
, ebx
);
64 netbsd_i386_collect_gp (I386_ECX_REGNUM
, ecx
);
65 netbsd_i386_collect_gp (I386_EDX_REGNUM
, edx
);
66 netbsd_i386_collect_gp (I386_ESP_REGNUM
, esp
);
67 netbsd_i386_collect_gp (I386_EBP_REGNUM
, ebp
);
68 netbsd_i386_collect_gp (I386_ESI_REGNUM
, esi
);
69 netbsd_i386_collect_gp (I386_EDI_REGNUM
, edi
);
70 netbsd_i386_collect_gp (I386_EIP_REGNUM
, eip
);
71 netbsd_i386_collect_gp (I386_EFLAGS_REGNUM
, eflags
);
72 netbsd_i386_collect_gp (I386_CS_REGNUM
, cs
);
73 netbsd_i386_collect_gp (I386_SS_REGNUM
, ss
);
74 netbsd_i386_collect_gp (I386_DS_REGNUM
, ds
);
75 netbsd_i386_collect_gp (I386_ES_REGNUM
, es
);
76 netbsd_i386_collect_gp (I386_FS_REGNUM
, fs
);
77 netbsd_i386_collect_gp (I386_GS_REGNUM
, gs
);
80 /* The store_function for the general-purpose register set. */
83 netbsd_i386_store_gregset (struct regcache
*regcache
, const char *buf
)
85 struct reg
*r
= (struct reg
*) buf
;
87 #define netbsd_i386_supply_gp(regnum, fld) do { \
88 supply_register (regcache, regnum, &r->r_##fld); \
91 netbsd_i386_supply_gp (I386_EAX_REGNUM
, eax
);
92 netbsd_i386_supply_gp (I386_EBX_REGNUM
, ebx
);
93 netbsd_i386_supply_gp (I386_ECX_REGNUM
, ecx
);
94 netbsd_i386_supply_gp (I386_EDX_REGNUM
, edx
);
95 netbsd_i386_supply_gp (I386_ESP_REGNUM
, esp
);
96 netbsd_i386_supply_gp (I386_EBP_REGNUM
, ebp
);
97 netbsd_i386_supply_gp (I386_ESI_REGNUM
, esi
);
98 netbsd_i386_supply_gp (I386_EDI_REGNUM
, edi
);
99 netbsd_i386_supply_gp (I386_EIP_REGNUM
, eip
);
100 netbsd_i386_supply_gp (I386_EFLAGS_REGNUM
, eflags
);
101 netbsd_i386_supply_gp (I386_CS_REGNUM
, cs
);
102 netbsd_i386_supply_gp (I386_SS_REGNUM
, ss
);
103 netbsd_i386_supply_gp (I386_DS_REGNUM
, ds
);
104 netbsd_i386_supply_gp (I386_ES_REGNUM
, es
);
105 netbsd_i386_supply_gp (I386_FS_REGNUM
, fs
);
106 netbsd_i386_supply_gp (I386_GS_REGNUM
, gs
);
109 /* Description of all the x86-netbsd register sets. */
111 static const struct netbsd_regset_info netbsd_target_regsets
[] =
113 /* General Purpose Registers. */
114 {PT_GETREGS
, PT_SETREGS
, sizeof (struct reg
),
115 netbsd_i386_fill_gregset
, netbsd_i386_store_gregset
},
116 /* End of list marker. */
117 {0, 0, -1, NULL
, NULL
}
120 /* NetBSD target op definitions for the amd64 architecture. */
122 class netbsd_i386_target
: public netbsd_process_target
125 const netbsd_regset_info
*get_regs_info () override
;
127 void low_arch_setup () override
;
130 const netbsd_regset_info
*
131 netbsd_i386_target::get_regs_info ()
133 return netbsd_target_regsets
;
136 /* Initialize the target description for the architecture of the
140 netbsd_i386_target::low_arch_setup ()
143 = i386_create_target_description (X86_XSTATE_SSE_MASK
, false, false);
145 init_target_desc (tdesc
, i386_expedite_regs
, GDB_OSABI_NETBSD
);
147 current_process ()->tdesc
= tdesc
;
150 /* The singleton target ops object. */
152 static netbsd_i386_target the_netbsd_i386_target
;
154 /* The NetBSD target ops object. */
156 netbsd_process_target
*the_netbsd_target
= &the_netbsd_i386_target
;