| 1 | /* Native support code for PPC AIX, for GDB the GNU debugger. |
| 2 | |
| 3 | Copyright (C) 2006, 2007 Free Software Foundation, Inc. |
| 4 | |
| 5 | Free Software Foundation, Inc. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "gdb_string.h" |
| 24 | #include "osabi.h" |
| 25 | #include "regcache.h" |
| 26 | #include "regset.h" |
| 27 | #include "rs6000-tdep.h" |
| 28 | #include "ppc-tdep.h" |
| 29 | |
| 30 | |
| 31 | /* Core file support. */ |
| 32 | |
| 33 | static struct ppc_reg_offsets rs6000_aix32_reg_offsets = |
| 34 | { |
| 35 | /* General-purpose registers. */ |
| 36 | 208, /* r0_offset */ |
| 37 | 4, /* gpr_size */ |
| 38 | 4, /* xr_size */ |
| 39 | 24, /* pc_offset */ |
| 40 | 28, /* ps_offset */ |
| 41 | 32, /* cr_offset */ |
| 42 | 36, /* lr_offset */ |
| 43 | 40, /* ctr_offset */ |
| 44 | 44, /* xer_offset */ |
| 45 | 48, /* mq_offset */ |
| 46 | |
| 47 | /* Floating-point registers. */ |
| 48 | 336, /* f0_offset */ |
| 49 | 56, /* fpscr_offset */ |
| 50 | 4, /* fpscr_size */ |
| 51 | |
| 52 | /* AltiVec registers. */ |
| 53 | -1, /* vr0_offset */ |
| 54 | -1, /* vscr_offset */ |
| 55 | -1 /* vrsave_offset */ |
| 56 | }; |
| 57 | |
| 58 | static struct ppc_reg_offsets rs6000_aix64_reg_offsets = |
| 59 | { |
| 60 | /* General-purpose registers. */ |
| 61 | 0, /* r0_offset */ |
| 62 | 8, /* gpr_size */ |
| 63 | 4, /* xr_size */ |
| 64 | 264, /* pc_offset */ |
| 65 | 256, /* ps_offset */ |
| 66 | 288, /* cr_offset */ |
| 67 | 272, /* lr_offset */ |
| 68 | 280, /* ctr_offset */ |
| 69 | 292, /* xer_offset */ |
| 70 | -1, /* mq_offset */ |
| 71 | |
| 72 | /* Floating-point registers. */ |
| 73 | 312, /* f0_offset */ |
| 74 | 296, /* fpscr_offset */ |
| 75 | 4, /* fpscr_size */ |
| 76 | |
| 77 | /* AltiVec registers. */ |
| 78 | -1, /* vr0_offset */ |
| 79 | -1, /* vscr_offset */ |
| 80 | -1 /* vrsave_offset */ |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | /* Supply register REGNUM in the general-purpose register set REGSET |
| 85 | from the buffer specified by GREGS and LEN to register cache |
| 86 | REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ |
| 87 | |
| 88 | static void |
| 89 | rs6000_aix_supply_regset (const struct regset *regset, |
| 90 | struct regcache *regcache, int regnum, |
| 91 | const void *gregs, size_t len) |
| 92 | { |
| 93 | ppc_supply_gregset (regset, regcache, regnum, gregs, len); |
| 94 | ppc_supply_fpregset (regset, regcache, regnum, gregs, len); |
| 95 | } |
| 96 | |
| 97 | /* Collect register REGNUM in the general-purpose register set |
| 98 | REGSET. from register cache REGCACHE into the buffer specified by |
| 99 | GREGS and LEN. If REGNUM is -1, do this for all registers in |
| 100 | REGSET. */ |
| 101 | |
| 102 | static void |
| 103 | rs6000_aix_collect_regset (const struct regset *regset, |
| 104 | const struct regcache *regcache, int regnum, |
| 105 | void *gregs, size_t len) |
| 106 | { |
| 107 | ppc_collect_gregset (regset, regcache, regnum, gregs, len); |
| 108 | ppc_collect_fpregset (regset, regcache, regnum, gregs, len); |
| 109 | } |
| 110 | |
| 111 | /* AIX register set. */ |
| 112 | |
| 113 | static struct regset rs6000_aix32_regset = |
| 114 | { |
| 115 | &rs6000_aix32_reg_offsets, |
| 116 | rs6000_aix_supply_regset, |
| 117 | rs6000_aix_collect_regset, |
| 118 | }; |
| 119 | |
| 120 | static struct regset rs6000_aix64_regset = |
| 121 | { |
| 122 | &rs6000_aix64_reg_offsets, |
| 123 | rs6000_aix_supply_regset, |
| 124 | rs6000_aix_collect_regset, |
| 125 | }; |
| 126 | |
| 127 | /* Return the appropriate register set for the core section identified |
| 128 | by SECT_NAME and SECT_SIZE. */ |
| 129 | |
| 130 | static const struct regset * |
| 131 | rs6000_aix_regset_from_core_section (struct gdbarch *gdbarch, |
| 132 | const char *sect_name, size_t sect_size) |
| 133 | { |
| 134 | if (gdbarch_tdep (gdbarch)->wordsize == 4) |
| 135 | { |
| 136 | if (strcmp (sect_name, ".reg") == 0 && sect_size >= 592) |
| 137 | return &rs6000_aix32_regset; |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | if (strcmp (sect_name, ".reg") == 0 && sect_size >= 576) |
| 142 | return &rs6000_aix64_regset; |
| 143 | } |
| 144 | |
| 145 | return NULL; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | static enum gdb_osabi |
| 150 | rs6000_aix_osabi_sniffer (bfd *abfd) |
| 151 | { |
| 152 | |
| 153 | if (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour); |
| 154 | return GDB_OSABI_AIX; |
| 155 | |
| 156 | return GDB_OSABI_UNKNOWN; |
| 157 | } |
| 158 | |
| 159 | static void |
| 160 | rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 161 | { |
| 162 | /* RS6000/AIX does not support PT_STEP. Has to be simulated. */ |
| 163 | set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step); |
| 164 | |
| 165 | /* Core file support. */ |
| 166 | set_gdbarch_regset_from_core_section |
| 167 | (gdbarch, rs6000_aix_regset_from_core_section); |
| 168 | |
| 169 | /* Minimum possible text address in AIX. */ |
| 170 | gdbarch_tdep (gdbarch)->text_segment_base = 0x10000000; |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | _initialize_rs6000_aix_tdep (void) |
| 175 | { |
| 176 | gdbarch_register_osabi_sniffer (bfd_arch_rs6000, |
| 177 | bfd_target_xcoff_flavour, |
| 178 | rs6000_aix_osabi_sniffer); |
| 179 | gdbarch_register_osabi_sniffer (bfd_arch_powerpc, |
| 180 | bfd_target_xcoff_flavour, |
| 181 | rs6000_aix_osabi_sniffer); |
| 182 | |
| 183 | gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_AIX, |
| 184 | rs6000_aix_init_osabi); |
| 185 | gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_AIX, |
| 186 | rs6000_aix_init_osabi); |
| 187 | } |
| 188 | |