GDB (API)
|
00001 /* Target-dependent code for OpenBSD/hppa 00002 00003 Copyright (C) 2004-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "osabi.h" 00022 #include "regcache.h" 00023 #include "regset.h" 00024 00025 #include "gdb_assert.h" 00026 #include "gdb_string.h" 00027 00028 #include "hppa-tdep.h" 00029 #include "hppabsd-tdep.h" 00030 00031 /* Core file support. */ 00032 00033 /* Sizeof `struct reg' in <machine/reg.h>. */ 00034 #define HPPAOBSD_SIZEOF_GREGS (34 * 4) /* OpenBSD 5.1 and earlier. */ 00035 #define HPPANBSD_SIZEOF_GREGS (46 * 4) /* NetBSD and OpenBSD 5.2 and later. */ 00036 00037 /* Sizeof `struct fpreg' in <machine/reg.h>. */ 00038 #define HPPAOBSD_SIZEOF_FPREGS (32 * 8) 00039 00040 /* Supply register REGNUM from the buffer specified by GREGS and LEN 00041 in the general-purpose register set REGSET to register cache 00042 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00043 00044 static void 00045 hppaobsd_supply_gregset (const struct regset *regset, 00046 struct regcache *regcache, 00047 int regnum, const void *gregs, size_t len) 00048 { 00049 gdb_byte zero[4] = { 0 }; 00050 const gdb_byte *regs = gregs; 00051 size_t offset; 00052 int i; 00053 00054 gdb_assert (len >= HPPAOBSD_SIZEOF_GREGS); 00055 00056 if (regnum == -1 || regnum == HPPA_R0_REGNUM) 00057 regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero); 00058 for (i = HPPA_R1_REGNUM, offset = 4; i <= HPPA_R31_REGNUM; i++, offset += 4) 00059 { 00060 if (regnum == -1 || regnum == i) 00061 regcache_raw_supply (regcache, i, regs + offset); 00062 } 00063 00064 if (len >= HPPANBSD_SIZEOF_GREGS) 00065 { 00066 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM) 00067 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs); 00068 if (regnum == -1 || regnum == HPPA_SAR_REGNUM) 00069 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4); 00070 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM) 00071 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4); 00072 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM) 00073 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4); 00074 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) 00075 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4); 00076 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) 00077 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4); 00078 if (regnum == -1 || regnum == HPPA_SR0_REGNUM) 00079 regcache_raw_supply (regcache, HPPA_SR0_REGNUM, regs + 37 * 4); 00080 if (regnum == -1 || regnum == HPPA_SR1_REGNUM) 00081 regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4); 00082 if (regnum == -1 || regnum == HPPA_SR2_REGNUM) 00083 regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4); 00084 if (regnum == -1 || regnum == HPPA_SR3_REGNUM) 00085 regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4); 00086 if (regnum == -1 || regnum == HPPA_SR4_REGNUM) 00087 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4); 00088 if (regnum == -1 || regnum == HPPA_SR5_REGNUM) 00089 regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4); 00090 if (regnum == -1 || regnum == HPPA_SR6_REGNUM) 00091 regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4); 00092 if (regnum == -1 || regnum == HPPA_SR7_REGNUM) 00093 regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4); 00094 if (regnum == -1 || regnum == HPPA_CR26_REGNUM) 00095 regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4); 00096 if (regnum == -1 || regnum == HPPA_CR27_REGNUM) 00097 regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4); 00098 } 00099 else 00100 { 00101 if (regnum == -1 || regnum == HPPA_SAR_REGNUM) 00102 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs); 00103 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) 00104 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); 00105 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) 00106 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); 00107 } 00108 } 00109 00110 /* Supply register REGNUM from the buffer specified by FPREGS and LEN 00111 in the floating-point register set REGSET to register cache 00112 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00113 00114 static void 00115 hppaobsd_supply_fpregset (const struct regset *regset, 00116 struct regcache *regcache, 00117 int regnum, const void *fpregs, size_t len) 00118 { 00119 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00120 const gdb_byte *regs = fpregs; 00121 int i; 00122 00123 gdb_assert (len >= HPPAOBSD_SIZEOF_FPREGS); 00124 00125 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i++) 00126 { 00127 if (regnum == i || regnum == -1) 00128 regcache_raw_supply (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4); 00129 } 00130 } 00131 00132 /* OpenBSD/hppa register sets. */ 00133 00134 static struct regset hppaobsd_gregset = 00135 { 00136 NULL, 00137 hppaobsd_supply_gregset 00138 }; 00139 00140 static struct regset hppaobsd_fpregset = 00141 { 00142 NULL, 00143 hppaobsd_supply_fpregset 00144 }; 00145 00146 /* Return the appropriate register set for the core section identified 00147 by SECT_NAME and SECT_SIZE. */ 00148 00149 static const struct regset * 00150 hppaobsd_regset_from_core_section (struct gdbarch *gdbarch, 00151 const char *sect_name, size_t sect_size) 00152 { 00153 if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPAOBSD_SIZEOF_GREGS) 00154 return &hppaobsd_gregset; 00155 00156 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= HPPAOBSD_SIZEOF_FPREGS) 00157 return &hppaobsd_fpregset; 00158 00159 return NULL; 00160 } 00161 00162 00163 static void 00164 hppaobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 00165 { 00166 /* Obviously OpenBSD is BSD-based. */ 00167 hppabsd_init_abi (info, gdbarch); 00168 00169 /* Core file support. */ 00170 set_gdbarch_regset_from_core_section 00171 (gdbarch, hppaobsd_regset_from_core_section); 00172 } 00173 00174 00175 /* OpenBSD uses uses the traditional NetBSD core file format, even for 00176 ports that use ELF. */ 00177 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF 00178 00179 static enum gdb_osabi 00180 hppaobsd_core_osabi_sniffer (bfd *abfd) 00181 { 00182 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0) 00183 return GDB_OSABI_NETBSD_CORE; 00184 00185 return GDB_OSABI_UNKNOWN; 00186 } 00187 00188 00189 /* Provide a prototype to silence -Wmissing-prototypes. */ 00190 void _initialize_hppabsd_tdep (void); 00191 00192 void 00193 _initialize_hppabsd_tdep (void) 00194 { 00195 /* BFD doesn't set a flavour for NetBSD style a.out core files. */ 00196 gdbarch_register_osabi_sniffer (bfd_arch_hppa, bfd_target_unknown_flavour, 00197 hppaobsd_core_osabi_sniffer); 00198 00199 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD_ELF, 00200 hppaobsd_init_abi); 00201 }