1*64f917f5Schristos /* Copyright (C) 2020-2024 Free Software Foundation, Inc. 24b169a6bSchristos 34b169a6bSchristos This file is part of GDB. 44b169a6bSchristos 54b169a6bSchristos This program is free software; you can redistribute it and/or modify 64b169a6bSchristos it under the terms of the GNU General Public License as published by 74b169a6bSchristos the Free Software Foundation; either version 3 of the License, or 84b169a6bSchristos (at your option) any later version. 94b169a6bSchristos 104b169a6bSchristos This program is distributed in the hope that it will be useful, 114b169a6bSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 124b169a6bSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134b169a6bSchristos GNU General Public License for more details. 144b169a6bSchristos 154b169a6bSchristos You should have received a copy of the GNU General Public License 164b169a6bSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 174b169a6bSchristos 184b169a6bSchristos #include <sys/types.h> 194b169a6bSchristos #include <sys/ptrace.h> 204b169a6bSchristos #include <limits.h> 214b169a6bSchristos 224b169a6bSchristos #include "netbsd-low.h" 234b169a6bSchristos #include "gdbsupport/x86-xstate.h" 244b169a6bSchristos #include "arch/i386.h" 254b169a6bSchristos #include "x86-tdesc.h" 264b169a6bSchristos #include "tdesc.h" 274b169a6bSchristos 284b169a6bSchristos /* The index of various registers inside the regcache. */ 294b169a6bSchristos 304b169a6bSchristos enum netbsd_i386_gdb_regnum 314b169a6bSchristos { 324b169a6bSchristos I386_EAX_REGNUM, /* %eax */ 334b169a6bSchristos I386_ECX_REGNUM, /* %ecx */ 344b169a6bSchristos I386_EDX_REGNUM, /* %edx */ 354b169a6bSchristos I386_EBX_REGNUM, /* %ebx */ 364b169a6bSchristos I386_ESP_REGNUM, /* %esp */ 374b169a6bSchristos I386_EBP_REGNUM, /* %ebp */ 384b169a6bSchristos I386_ESI_REGNUM, /* %esi */ 394b169a6bSchristos I386_EDI_REGNUM, /* %edi */ 404b169a6bSchristos I386_EIP_REGNUM, /* %eip */ 414b169a6bSchristos I386_EFLAGS_REGNUM, /* %eflags */ 424b169a6bSchristos I386_CS_REGNUM, /* %cs */ 434b169a6bSchristos I386_SS_REGNUM, /* %ss */ 444b169a6bSchristos I386_DS_REGNUM, /* %ds */ 454b169a6bSchristos I386_ES_REGNUM, /* %es */ 464b169a6bSchristos I386_FS_REGNUM, /* %fs */ 474b169a6bSchristos I386_GS_REGNUM, /* %gs */ 484b169a6bSchristos I386_ST0_REGNUM /* %st(0) */ 494b169a6bSchristos }; 504b169a6bSchristos 514b169a6bSchristos /* The fill_function for the general-purpose register set. */ 524b169a6bSchristos 534b169a6bSchristos static void 544b169a6bSchristos netbsd_i386_fill_gregset (struct regcache *regcache, char *buf) 554b169a6bSchristos { 564b169a6bSchristos struct reg *r = (struct reg *) buf; 574b169a6bSchristos 584b169a6bSchristos #define netbsd_i386_collect_gp(regnum, fld) do { \ 594b169a6bSchristos collect_register (regcache, regnum, &r->r_##fld); \ 604b169a6bSchristos } while (0) 614b169a6bSchristos 624b169a6bSchristos netbsd_i386_collect_gp (I386_EAX_REGNUM, eax); 634b169a6bSchristos netbsd_i386_collect_gp (I386_EBX_REGNUM, ebx); 644b169a6bSchristos netbsd_i386_collect_gp (I386_ECX_REGNUM, ecx); 654b169a6bSchristos netbsd_i386_collect_gp (I386_EDX_REGNUM, edx); 664b169a6bSchristos netbsd_i386_collect_gp (I386_ESP_REGNUM, esp); 674b169a6bSchristos netbsd_i386_collect_gp (I386_EBP_REGNUM, ebp); 684b169a6bSchristos netbsd_i386_collect_gp (I386_ESI_REGNUM, esi); 694b169a6bSchristos netbsd_i386_collect_gp (I386_EDI_REGNUM, edi); 704b169a6bSchristos netbsd_i386_collect_gp (I386_EIP_REGNUM, eip); 714b169a6bSchristos netbsd_i386_collect_gp (I386_EFLAGS_REGNUM, eflags); 724b169a6bSchristos netbsd_i386_collect_gp (I386_CS_REGNUM, cs); 734b169a6bSchristos netbsd_i386_collect_gp (I386_SS_REGNUM, ss); 744b169a6bSchristos netbsd_i386_collect_gp (I386_DS_REGNUM, ds); 754b169a6bSchristos netbsd_i386_collect_gp (I386_ES_REGNUM, es); 764b169a6bSchristos netbsd_i386_collect_gp (I386_FS_REGNUM, fs); 774b169a6bSchristos netbsd_i386_collect_gp (I386_GS_REGNUM, gs); 784b169a6bSchristos } 794b169a6bSchristos 804b169a6bSchristos /* The store_function for the general-purpose register set. */ 814b169a6bSchristos 824b169a6bSchristos static void 834b169a6bSchristos netbsd_i386_store_gregset (struct regcache *regcache, const char *buf) 844b169a6bSchristos { 854b169a6bSchristos struct reg *r = (struct reg *) buf; 864b169a6bSchristos 874b169a6bSchristos #define netbsd_i386_supply_gp(regnum, fld) do { \ 884b169a6bSchristos supply_register (regcache, regnum, &r->r_##fld); \ 894b169a6bSchristos } while(0) 904b169a6bSchristos 914b169a6bSchristos netbsd_i386_supply_gp (I386_EAX_REGNUM, eax); 924b169a6bSchristos netbsd_i386_supply_gp (I386_EBX_REGNUM, ebx); 934b169a6bSchristos netbsd_i386_supply_gp (I386_ECX_REGNUM, ecx); 944b169a6bSchristos netbsd_i386_supply_gp (I386_EDX_REGNUM, edx); 954b169a6bSchristos netbsd_i386_supply_gp (I386_ESP_REGNUM, esp); 964b169a6bSchristos netbsd_i386_supply_gp (I386_EBP_REGNUM, ebp); 974b169a6bSchristos netbsd_i386_supply_gp (I386_ESI_REGNUM, esi); 984b169a6bSchristos netbsd_i386_supply_gp (I386_EDI_REGNUM, edi); 994b169a6bSchristos netbsd_i386_supply_gp (I386_EIP_REGNUM, eip); 1004b169a6bSchristos netbsd_i386_supply_gp (I386_EFLAGS_REGNUM, eflags); 1014b169a6bSchristos netbsd_i386_supply_gp (I386_CS_REGNUM, cs); 1024b169a6bSchristos netbsd_i386_supply_gp (I386_SS_REGNUM, ss); 1034b169a6bSchristos netbsd_i386_supply_gp (I386_DS_REGNUM, ds); 1044b169a6bSchristos netbsd_i386_supply_gp (I386_ES_REGNUM, es); 1054b169a6bSchristos netbsd_i386_supply_gp (I386_FS_REGNUM, fs); 1064b169a6bSchristos netbsd_i386_supply_gp (I386_GS_REGNUM, gs); 1074b169a6bSchristos } 1084b169a6bSchristos 1094b169a6bSchristos /* Description of all the x86-netbsd register sets. */ 1104b169a6bSchristos 1114b169a6bSchristos static const struct netbsd_regset_info netbsd_target_regsets[] = 1124b169a6bSchristos { 1134b169a6bSchristos /* General Purpose Registers. */ 1144b169a6bSchristos {PT_GETREGS, PT_SETREGS, sizeof (struct reg), 1154b169a6bSchristos netbsd_i386_fill_gregset, netbsd_i386_store_gregset}, 1164b169a6bSchristos /* End of list marker. */ 1174b169a6bSchristos {0, 0, -1, NULL, NULL } 1184b169a6bSchristos }; 1194b169a6bSchristos 1204b169a6bSchristos /* NetBSD target op definitions for the amd64 architecture. */ 1214b169a6bSchristos 1224b169a6bSchristos class netbsd_i386_target : public netbsd_process_target 1234b169a6bSchristos { 1244b169a6bSchristos public: 1254b169a6bSchristos const netbsd_regset_info *get_regs_info () override; 1264b169a6bSchristos 1274b169a6bSchristos void low_arch_setup () override; 1284b169a6bSchristos }; 1294b169a6bSchristos 1304b169a6bSchristos const netbsd_regset_info * 1314b169a6bSchristos netbsd_i386_target::get_regs_info () 1324b169a6bSchristos { 1334b169a6bSchristos return netbsd_target_regsets; 1344b169a6bSchristos } 1354b169a6bSchristos 1364b169a6bSchristos /* Initialize the target description for the architecture of the 1374b169a6bSchristos inferior. */ 1384b169a6bSchristos 1394b169a6bSchristos void 1404b169a6bSchristos netbsd_i386_target::low_arch_setup () 1414b169a6bSchristos { 1424b169a6bSchristos target_desc *tdesc 1434b169a6bSchristos = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); 1444b169a6bSchristos 1454b169a6bSchristos init_target_desc (tdesc, i386_expedite_regs); 1464b169a6bSchristos 1474b169a6bSchristos current_process ()->tdesc = tdesc; 1484b169a6bSchristos } 1494b169a6bSchristos 1504b169a6bSchristos /* The singleton target ops object. */ 1514b169a6bSchristos 1524b169a6bSchristos static netbsd_i386_target the_netbsd_i386_target; 1534b169a6bSchristos 1544b169a6bSchristos /* The NetBSD target ops object. */ 1554b169a6bSchristos 1564b169a6bSchristos netbsd_process_target *the_netbsd_target = &the_netbsd_i386_target; 157