| 1 |
/* Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
This file is part of GDB. |
| 4 |
|
| 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. |
| 9 |
|
| 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. |
| 14 |
|
| 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/>. */ |
| 17 |
|
| 18 |
#include <sys/types.h> |
| 19 |
#include <sys/ptrace.h> |
| 20 |
#include <limits.h> |
| 21 |
|
| 22 |
#include "netbsd-low.h" |
| 23 |
#include "gdbsupport/x86-xstate.h" |
| 24 |
#include "arch/i386.h" |
| 25 |
#include "x86-tdesc.h" |
| 26 |
#include "tdesc.h" |
| 27 |
|
| 28 |
/* The index of various registers inside the regcache. */ |
| 29 |
|
| 30 |
enum netbsd_i386_gdb_regnum |
| 31 |
{ |
| 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) */ |
| 49 |
}; |
| 50 |
|
| 51 |
/* The fill_function for the general-purpose register set. */ |
| 52 |
|
| 53 |
static void |
| 54 |
netbsd_i386_fill_gregset (struct regcache *regcache, char *buf) |
| 55 |
{ |
| 56 |
struct reg *r = (struct reg *) buf; |
| 57 |
|
| 58 |
#define netbsd_i386_collect_gp(regnum, fld) do { \ |
| 59 |
collect_register (regcache, regnum, &r->r_##fld); \ |
| 60 |
} while (0) |
| 61 |
|
| 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); |
| 78 |
} |
| 79 |
|
| 80 |
/* The store_function for the general-purpose register set. */ |
| 81 |
|
| 82 |
static void |
| 83 |
netbsd_i386_store_gregset (struct regcache *regcache, const char *buf) |
| 84 |
{ |
| 85 |
struct reg *r = (struct reg *) buf; |
| 86 |
|
| 87 |
#define netbsd_i386_supply_gp(regnum, fld) do { \ |
| 88 |
supply_register (regcache, regnum, &r->r_##fld); \ |
| 89 |
} while(0) |
| 90 |
|
| 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); |
| 107 |
} |
| 108 |
|
| 109 |
/* Description of all the x86-netbsd register sets. */ |
| 110 |
|
| 111 |
static const struct netbsd_regset_info netbsd_target_regsets[] = |
| 112 |
{ |
| 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 } |
| 118 |
}; |
| 119 |
|
| 120 |
/* NetBSD target op definitions for the amd64 architecture. */ |
| 121 |
|
| 122 |
class netbsd_i386_target : public netbsd_process_target |
| 123 |
{ |
| 124 |
public: |
| 125 |
const netbsd_regset_info *get_regs_info () override; |
| 126 |
|
| 127 |
void low_arch_setup () override; |
| 128 |
}; |
| 129 |
|
| 130 |
const netbsd_regset_info * |
| 131 |
netbsd_i386_target::get_regs_info () |
| 132 |
{ |
| 133 |
return netbsd_target_regsets; |
| 134 |
} |
| 135 |
|
| 136 |
/* Initialize the target description for the architecture of the |
| 137 |
inferior. */ |
| 138 |
|
| 139 |
void |
| 140 |
netbsd_i386_target::low_arch_setup () |
| 141 |
{ |
| 142 |
target_desc *tdesc |
| 143 |
= i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); |
| 144 |
|
| 145 |
init_target_desc (tdesc, i386_expedite_regs, GDB_OSABI_NETBSD); |
| 146 |
|
| 147 |
current_process ()->tdesc = tdesc; |
| 148 |
} |
| 149 |
|
| 150 |
/* The singleton target ops object. */ |
| 151 |
|
| 152 |
static netbsd_i386_target the_netbsd_i386_target; |
| 153 |
|
| 154 |
/* The NetBSD target ops object. */ |
| 155 |
|
| 156 |
netbsd_process_target *the_netbsd_target = &the_netbsd_i386_target; |