1 /* Copyright (C) 2020 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>
23 #include "netbsd-low.h"
24 #include "gdbsupport/x86-xstate.h"
25 #include "arch/i386.h"
26 #include "x86-tdesc.h"
29 /* The index of various registers inside the regcache. */
31 enum netbsd_i386_gdb_regnum
33 I386_EAX_REGNUM
, /* %eax */
34 I386_ECX_REGNUM
, /* %ecx */
35 I386_EDX_REGNUM
, /* %edx */
36 I386_EBX_REGNUM
, /* %ebx */
37 I386_ESP_REGNUM
, /* %esp */
38 I386_EBP_REGNUM
, /* %ebp */
39 I386_ESI_REGNUM
, /* %esi */
40 I386_EDI_REGNUM
, /* %edi */
41 I386_EIP_REGNUM
, /* %eip */
42 I386_EFLAGS_REGNUM
, /* %eflags */
43 I386_CS_REGNUM
, /* %cs */
44 I386_SS_REGNUM
, /* %ss */
45 I386_DS_REGNUM
, /* %ds */
46 I386_ES_REGNUM
, /* %es */
47 I386_FS_REGNUM
, /* %fs */
48 I386_GS_REGNUM
, /* %gs */
49 I386_ST0_REGNUM
/* %st(0) */
52 /* The fill_function for the general-purpose register set. */
55 netbsd_i386_fill_gregset (struct regcache
*regcache
, char *buf
)
57 struct reg
*r
= (struct reg
*) buf
;
59 #define netbsd_i386_collect_gp(regnum, fld) do { \
60 collect_register (regcache, regnum, &r->r_##fld); \
63 netbsd_i386_collect_gp (I386_EAX_REGNUM
, eax
);
64 netbsd_i386_collect_gp (I386_EBX_REGNUM
, ebx
);
65 netbsd_i386_collect_gp (I386_ECX_REGNUM
, ecx
);
66 netbsd_i386_collect_gp (I386_EDX_REGNUM
, edx
);
67 netbsd_i386_collect_gp (I386_ESP_REGNUM
, esp
);
68 netbsd_i386_collect_gp (I386_EBP_REGNUM
, ebp
);
69 netbsd_i386_collect_gp (I386_ESI_REGNUM
, esi
);
70 netbsd_i386_collect_gp (I386_EDI_REGNUM
, edi
);
71 netbsd_i386_collect_gp (I386_EIP_REGNUM
, eip
);
72 netbsd_i386_collect_gp (I386_EFLAGS_REGNUM
, eflags
);
73 netbsd_i386_collect_gp (I386_CS_REGNUM
, cs
);
74 netbsd_i386_collect_gp (I386_SS_REGNUM
, ss
);
75 netbsd_i386_collect_gp (I386_DS_REGNUM
, ds
);
76 netbsd_i386_collect_gp (I386_ES_REGNUM
, es
);
77 netbsd_i386_collect_gp (I386_FS_REGNUM
, fs
);
78 netbsd_i386_collect_gp (I386_GS_REGNUM
, gs
);
81 /* The store_function for the general-purpose register set. */
84 netbsd_i386_store_gregset (struct regcache
*regcache
, const char *buf
)
86 struct reg
*r
= (struct reg
*) buf
;
88 #define netbsd_i386_supply_gp(regnum, fld) do { \
89 supply_register (regcache, regnum, &r->r_##fld); \
92 netbsd_i386_supply_gp (I386_EAX_REGNUM
, eax
);
93 netbsd_i386_supply_gp (I386_EBX_REGNUM
, ebx
);
94 netbsd_i386_supply_gp (I386_ECX_REGNUM
, ecx
);
95 netbsd_i386_supply_gp (I386_EDX_REGNUM
, edx
);
96 netbsd_i386_supply_gp (I386_ESP_REGNUM
, esp
);
97 netbsd_i386_supply_gp (I386_EBP_REGNUM
, ebp
);
98 netbsd_i386_supply_gp (I386_ESI_REGNUM
, esi
);
99 netbsd_i386_supply_gp (I386_EDI_REGNUM
, edi
);
100 netbsd_i386_supply_gp (I386_EIP_REGNUM
, eip
);
101 netbsd_i386_supply_gp (I386_EFLAGS_REGNUM
, eflags
);
102 netbsd_i386_supply_gp (I386_CS_REGNUM
, cs
);
103 netbsd_i386_supply_gp (I386_SS_REGNUM
, ss
);
104 netbsd_i386_supply_gp (I386_DS_REGNUM
, ds
);
105 netbsd_i386_supply_gp (I386_ES_REGNUM
, es
);
106 netbsd_i386_supply_gp (I386_FS_REGNUM
, fs
);
107 netbsd_i386_supply_gp (I386_GS_REGNUM
, gs
);
110 /* Description of all the x86-netbsd register sets. */
112 static const struct netbsd_regset_info netbsd_target_regsets
[] =
114 /* General Purpose Registers. */
115 {PT_GETREGS
, PT_SETREGS
, sizeof (struct reg
),
116 netbsd_i386_fill_gregset
, netbsd_i386_store_gregset
},
117 /* End of list marker. */
118 {0, 0, -1, NULL
, NULL
}
121 /* NetBSD target op definitions for the amd64 architecture. */
123 class netbsd_i386_target
: public netbsd_process_target
126 const netbsd_regset_info
*get_regs_info () override
;
128 void low_arch_setup () override
;
131 const netbsd_regset_info
*
132 netbsd_i386_target::get_regs_info ()
134 return netbsd_target_regsets
;
137 /* Initialize the target description for the architecture of the
141 netbsd_i386_target::low_arch_setup ()
144 = i386_create_target_description (X86_XSTATE_SSE_MASK
, false, false);
146 init_target_desc (tdesc
, i386_expedite_regs
);
148 current_process ()->tdesc
= tdesc
;
151 /* The singleton target ops object. */
153 static netbsd_i386_target the_netbsd_i386_target
;
155 /* The NetBSD target ops object. */
157 netbsd_process_target
*the_netbsd_target
= &the_netbsd_i386_target
;