1 1.1 christos /* Target-dependent code for GDB, the GNU debugger. 2 1.1 christos 3 1.11 christos Copyright (C) 1986-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.11 christos #include "extract-store-integer.h" 21 1.1 christos #include "frame.h" 22 1.1 christos #include "inferior.h" 23 1.3 christos #include "infrun.h" 24 1.1 christos #include "symtab.h" 25 1.1 christos #include "target.h" 26 1.1 christos #include "gdbcore.h" 27 1.11 christos #include "cli/cli-cmds.h" 28 1.1 christos #include "objfiles.h" 29 1.1 christos #include "arch-utils.h" 30 1.1 christos #include "regcache.h" 31 1.1 christos #include "regset.h" 32 1.8 christos #include "target-float.h" 33 1.1 christos #include "value.h" 34 1.1 christos #include "parser-defs.h" 35 1.1 christos #include "osabi.h" 36 1.1 christos #include "infcall.h" 37 1.1 christos #include "sim-regno.h" 38 1.11 christos #include "sim/sim-ppc.h" 39 1.1 christos #include "reggroups.h" 40 1.9 christos #include "dwarf2/frame.h" 41 1.1 christos #include "target-descriptions.h" 42 1.1 christos #include "user-regs.h" 43 1.3 christos #include "record-full.h" 44 1.3 christos #include "auxv.h" 45 1.1 christos 46 1.11 christos #include "coff/internal.h" 47 1.11 christos #include "libcoff.h" 48 1.1 christos #include "coff/xcoff.h" 49 1.1 christos #include "libxcoff.h" 50 1.1 christos 51 1.1 christos #include "elf-bfd.h" 52 1.1 christos #include "elf/ppc.h" 53 1.3 christos #include "elf/ppc64.h" 54 1.1 christos 55 1.1 christos #include "solib-svr4.h" 56 1.1 christos #include "ppc-tdep.h" 57 1.1 christos #include "ppc-ravenscar-thread.h" 58 1.1 christos 59 1.1 christos #include "dis-asm.h" 60 1.1 christos 61 1.1 christos #include "trad-frame.h" 62 1.1 christos #include "frame-unwind.h" 63 1.1 christos #include "frame-base.h" 64 1.1 christos 65 1.6 christos #include "ax.h" 66 1.6 christos #include "ax-gdb.h" 67 1.7 christos #include <algorithm> 68 1.6 christos 69 1.1 christos #include "features/rs6000/powerpc-32.c" 70 1.1 christos #include "features/rs6000/powerpc-altivec32.c" 71 1.1 christos #include "features/rs6000/powerpc-vsx32.c" 72 1.1 christos #include "features/rs6000/powerpc-403.c" 73 1.1 christos #include "features/rs6000/powerpc-403gc.c" 74 1.1 christos #include "features/rs6000/powerpc-405.c" 75 1.1 christos #include "features/rs6000/powerpc-505.c" 76 1.1 christos #include "features/rs6000/powerpc-601.c" 77 1.1 christos #include "features/rs6000/powerpc-602.c" 78 1.1 christos #include "features/rs6000/powerpc-603.c" 79 1.1 christos #include "features/rs6000/powerpc-604.c" 80 1.1 christos #include "features/rs6000/powerpc-64.c" 81 1.1 christos #include "features/rs6000/powerpc-altivec64.c" 82 1.1 christos #include "features/rs6000/powerpc-vsx64.c" 83 1.1 christos #include "features/rs6000/powerpc-7400.c" 84 1.1 christos #include "features/rs6000/powerpc-750.c" 85 1.1 christos #include "features/rs6000/powerpc-860.c" 86 1.1 christos #include "features/rs6000/powerpc-e500.c" 87 1.1 christos #include "features/rs6000/rs6000.c" 88 1.1 christos 89 1.1 christos /* Determine if regnum is an SPE pseudo-register. */ 90 1.1 christos #define IS_SPE_PSEUDOREG(tdep, regnum) ((tdep)->ppc_ev0_regnum >= 0 \ 91 1.1 christos && (regnum) >= (tdep)->ppc_ev0_regnum \ 92 1.1 christos && (regnum) < (tdep)->ppc_ev0_regnum + 32) 93 1.1 christos 94 1.1 christos /* Determine if regnum is a decimal float pseudo-register. */ 95 1.1 christos #define IS_DFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_dl0_regnum >= 0 \ 96 1.1 christos && (regnum) >= (tdep)->ppc_dl0_regnum \ 97 1.1 christos && (regnum) < (tdep)->ppc_dl0_regnum + 16) 98 1.1 christos 99 1.8 christos /* Determine if regnum is a "vX" alias for the raw "vrX" vector 100 1.8 christos registers. */ 101 1.8 christos #define IS_V_ALIAS_PSEUDOREG(tdep, regnum) (\ 102 1.8 christos (tdep)->ppc_v0_alias_regnum >= 0 \ 103 1.8 christos && (regnum) >= (tdep)->ppc_v0_alias_regnum \ 104 1.8 christos && (regnum) < (tdep)->ppc_v0_alias_regnum + ppc_num_vrs) 105 1.8 christos 106 1.1 christos /* Determine if regnum is a POWER7 VSX register. */ 107 1.1 christos #define IS_VSX_PSEUDOREG(tdep, regnum) ((tdep)->ppc_vsr0_regnum >= 0 \ 108 1.1 christos && (regnum) >= (tdep)->ppc_vsr0_regnum \ 109 1.1 christos && (regnum) < (tdep)->ppc_vsr0_regnum + ppc_num_vsrs) 110 1.1 christos 111 1.1 christos /* Determine if regnum is a POWER7 Extended FP register. */ 112 1.1 christos #define IS_EFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_efpr0_regnum >= 0 \ 113 1.1 christos && (regnum) >= (tdep)->ppc_efpr0_regnum \ 114 1.1 christos && (regnum) < (tdep)->ppc_efpr0_regnum + ppc_num_efprs) 115 1.1 christos 116 1.8 christos /* Determine if regnum is a checkpointed decimal float 117 1.8 christos pseudo-register. */ 118 1.8 christos #define IS_CDFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_cdl0_regnum >= 0 \ 119 1.8 christos && (regnum) >= (tdep)->ppc_cdl0_regnum \ 120 1.8 christos && (regnum) < (tdep)->ppc_cdl0_regnum + 16) 121 1.8 christos 122 1.8 christos /* Determine if regnum is a Checkpointed POWER7 VSX register. */ 123 1.8 christos #define IS_CVSX_PSEUDOREG(tdep, regnum) ((tdep)->ppc_cvsr0_regnum >= 0 \ 124 1.8 christos && (regnum) >= (tdep)->ppc_cvsr0_regnum \ 125 1.8 christos && (regnum) < (tdep)->ppc_cvsr0_regnum + ppc_num_vsrs) 126 1.8 christos 127 1.8 christos /* Determine if regnum is a Checkpointed POWER7 Extended FP register. */ 128 1.8 christos #define IS_CEFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_cefpr0_regnum >= 0 \ 129 1.8 christos && (regnum) >= (tdep)->ppc_cefpr0_regnum \ 130 1.8 christos && (regnum) < (tdep)->ppc_cefpr0_regnum + ppc_num_efprs) 131 1.8 christos 132 1.7 christos /* Holds the current set of options to be passed to the disassembler. */ 133 1.11 christos static std::string powerpc_disassembler_options; 134 1.7 christos 135 1.1 christos /* The list of available "set powerpc ..." and "show powerpc ..." 136 1.1 christos commands. */ 137 1.1 christos static struct cmd_list_element *setpowerpccmdlist = NULL; 138 1.1 christos static struct cmd_list_element *showpowerpccmdlist = NULL; 139 1.1 christos 140 1.1 christos static enum auto_boolean powerpc_soft_float_global = AUTO_BOOLEAN_AUTO; 141 1.1 christos 142 1.1 christos /* The vector ABI to use. Keep this in sync with powerpc_vector_abi. */ 143 1.1 christos static const char *const powerpc_vector_strings[] = 144 1.1 christos { 145 1.1 christos "auto", 146 1.1 christos "generic", 147 1.1 christos "altivec", 148 1.1 christos "spe", 149 1.1 christos NULL 150 1.1 christos }; 151 1.1 christos 152 1.1 christos /* A variable that can be configured by the user. */ 153 1.1 christos static enum powerpc_vector_abi powerpc_vector_abi_global = POWERPC_VEC_AUTO; 154 1.1 christos static const char *powerpc_vector_abi_string = "auto"; 155 1.1 christos 156 1.10 christos /* PowerPC-related per-inferior data. */ 157 1.10 christos 158 1.10 christos static const registry<inferior>::key<ppc_inferior_data> ppc_inferior_data_key; 159 1.10 christos 160 1.10 christos /* Get the per-inferior PowerPC data for INF. */ 161 1.10 christos 162 1.10 christos ppc_inferior_data * 163 1.10 christos get_ppc_per_inferior (inferior *inf) 164 1.10 christos { 165 1.10 christos ppc_inferior_data *per_inf = ppc_inferior_data_key.get (inf); 166 1.10 christos 167 1.10 christos if (per_inf == nullptr) 168 1.10 christos per_inf = ppc_inferior_data_key.emplace (inf); 169 1.10 christos 170 1.10 christos return per_inf; 171 1.10 christos } 172 1.10 christos 173 1.1 christos /* To be used by skip_prologue. */ 174 1.1 christos 175 1.1 christos struct rs6000_framedata 176 1.1 christos { 177 1.1 christos int offset; /* total size of frame --- the distance 178 1.1 christos by which we decrement sp to allocate 179 1.1 christos the frame */ 180 1.1 christos int saved_gpr; /* smallest # of saved gpr */ 181 1.1 christos unsigned int gpr_mask; /* Each bit is an individual saved GPR. */ 182 1.1 christos int saved_fpr; /* smallest # of saved fpr */ 183 1.1 christos int saved_vr; /* smallest # of saved vr */ 184 1.1 christos int saved_ev; /* smallest # of saved ev */ 185 1.1 christos int alloca_reg; /* alloca register number (frame ptr) */ 186 1.1 christos char frameless; /* true if frameless functions. */ 187 1.1 christos char nosavedpc; /* true if pc not saved. */ 188 1.1 christos char used_bl; /* true if link register clobbered */ 189 1.1 christos int gpr_offset; /* offset of saved gprs from prev sp */ 190 1.1 christos int fpr_offset; /* offset of saved fprs from prev sp */ 191 1.1 christos int vr_offset; /* offset of saved vrs from prev sp */ 192 1.1 christos int ev_offset; /* offset of saved evs from prev sp */ 193 1.1 christos int lr_offset; /* offset of saved lr */ 194 1.1 christos int lr_register; /* register of saved lr, if trustworthy */ 195 1.1 christos int cr_offset; /* offset of saved cr */ 196 1.1 christos int vrsave_offset; /* offset of saved vrsave register */ 197 1.1 christos }; 198 1.1 christos 199 1.1 christos 200 1.1 christos /* Is REGNO a VSX register? Return 1 if so, 0 otherwise. */ 201 1.1 christos int 202 1.1 christos vsx_register_p (struct gdbarch *gdbarch, int regno) 203 1.1 christos { 204 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 205 1.1 christos if (tdep->ppc_vsr0_regnum < 0) 206 1.1 christos return 0; 207 1.1 christos else 208 1.1 christos return (regno >= tdep->ppc_vsr0_upper_regnum && regno 209 1.1 christos <= tdep->ppc_vsr0_upper_regnum + 31); 210 1.1 christos } 211 1.1 christos 212 1.1 christos /* Is REGNO an AltiVec register? Return 1 if so, 0 otherwise. */ 213 1.1 christos int 214 1.1 christos altivec_register_p (struct gdbarch *gdbarch, int regno) 215 1.1 christos { 216 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 217 1.1 christos if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0) 218 1.1 christos return 0; 219 1.1 christos else 220 1.1 christos return (regno >= tdep->ppc_vr0_regnum && regno <= tdep->ppc_vrsave_regnum); 221 1.1 christos } 222 1.1 christos 223 1.1 christos 224 1.1 christos /* Return true if REGNO is an SPE register, false otherwise. */ 225 1.1 christos int 226 1.1 christos spe_register_p (struct gdbarch *gdbarch, int regno) 227 1.1 christos { 228 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 229 1.1 christos 230 1.1 christos /* Is it a reference to EV0 -- EV31, and do we have those? */ 231 1.1 christos if (IS_SPE_PSEUDOREG (tdep, regno)) 232 1.1 christos return 1; 233 1.1 christos 234 1.1 christos /* Is it a reference to one of the raw upper GPR halves? */ 235 1.1 christos if (tdep->ppc_ev0_upper_regnum >= 0 236 1.1 christos && tdep->ppc_ev0_upper_regnum <= regno 237 1.1 christos && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs) 238 1.1 christos return 1; 239 1.1 christos 240 1.1 christos /* Is it a reference to the 64-bit accumulator, and do we have that? */ 241 1.1 christos if (tdep->ppc_acc_regnum >= 0 242 1.1 christos && tdep->ppc_acc_regnum == regno) 243 1.1 christos return 1; 244 1.1 christos 245 1.1 christos /* Is it a reference to the SPE floating-point status and control register, 246 1.1 christos and do we have that? */ 247 1.1 christos if (tdep->ppc_spefscr_regnum >= 0 248 1.1 christos && tdep->ppc_spefscr_regnum == regno) 249 1.1 christos return 1; 250 1.1 christos 251 1.1 christos return 0; 252 1.1 christos } 253 1.1 christos 254 1.1 christos 255 1.1 christos /* Return non-zero if the architecture described by GDBARCH has 256 1.1 christos floating-point registers (f0 --- f31 and fpscr). */ 257 1.1 christos int 258 1.1 christos ppc_floating_point_unit_p (struct gdbarch *gdbarch) 259 1.1 christos { 260 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 261 1.1 christos 262 1.1 christos return (tdep->ppc_fp0_regnum >= 0 263 1.10 christos && tdep->ppc_fpscr_regnum >= 0); 264 1.1 christos } 265 1.1 christos 266 1.1 christos /* Return non-zero if the architecture described by GDBARCH has 267 1.1 christos Altivec registers (vr0 --- vr31, vrsave and vscr). */ 268 1.1 christos int 269 1.1 christos ppc_altivec_support_p (struct gdbarch *gdbarch) 270 1.1 christos { 271 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 272 1.1 christos 273 1.1 christos return (tdep->ppc_vr0_regnum >= 0 274 1.10 christos && tdep->ppc_vrsave_regnum >= 0); 275 1.1 christos } 276 1.1 christos 277 1.1 christos /* Check that TABLE[GDB_REGNO] is not already initialized, and then 278 1.1 christos set it to SIM_REGNO. 279 1.1 christos 280 1.1 christos This is a helper function for init_sim_regno_table, constructing 281 1.1 christos the table mapping GDB register numbers to sim register numbers; we 282 1.1 christos initialize every element in that table to -1 before we start 283 1.1 christos filling it in. */ 284 1.1 christos static void 285 1.1 christos set_sim_regno (int *table, int gdb_regno, int sim_regno) 286 1.1 christos { 287 1.1 christos /* Make sure we don't try to assign any given GDB register a sim 288 1.1 christos register number more than once. */ 289 1.1 christos gdb_assert (table[gdb_regno] == -1); 290 1.1 christos table[gdb_regno] = sim_regno; 291 1.1 christos } 292 1.1 christos 293 1.1 christos 294 1.1 christos /* Initialize ARCH->tdep->sim_regno, the table mapping GDB register 295 1.1 christos numbers to simulator register numbers, based on the values placed 296 1.1 christos in the ARCH->tdep->ppc_foo_regnum members. */ 297 1.1 christos static void 298 1.1 christos init_sim_regno_table (struct gdbarch *arch) 299 1.1 christos { 300 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch); 301 1.1 christos int total_regs = gdbarch_num_regs (arch); 302 1.1 christos int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int); 303 1.1 christos int i; 304 1.1 christos static const char *const segment_regs[] = { 305 1.1 christos "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7", 306 1.1 christos "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15" 307 1.1 christos }; 308 1.1 christos 309 1.1 christos /* Presume that all registers not explicitly mentioned below are 310 1.1 christos unavailable from the sim. */ 311 1.1 christos for (i = 0; i < total_regs; i++) 312 1.1 christos sim_regno[i] = -1; 313 1.1 christos 314 1.1 christos /* General-purpose registers. */ 315 1.1 christos for (i = 0; i < ppc_num_gprs; i++) 316 1.1 christos set_sim_regno (sim_regno, tdep->ppc_gp0_regnum + i, sim_ppc_r0_regnum + i); 317 1.1 christos 318 1.1 christos /* Floating-point registers. */ 319 1.1 christos if (tdep->ppc_fp0_regnum >= 0) 320 1.1 christos for (i = 0; i < ppc_num_fprs; i++) 321 1.1 christos set_sim_regno (sim_regno, 322 1.10 christos tdep->ppc_fp0_regnum + i, 323 1.10 christos sim_ppc_f0_regnum + i); 324 1.1 christos if (tdep->ppc_fpscr_regnum >= 0) 325 1.1 christos set_sim_regno (sim_regno, tdep->ppc_fpscr_regnum, sim_ppc_fpscr_regnum); 326 1.1 christos 327 1.1 christos set_sim_regno (sim_regno, gdbarch_pc_regnum (arch), sim_ppc_pc_regnum); 328 1.1 christos set_sim_regno (sim_regno, tdep->ppc_ps_regnum, sim_ppc_ps_regnum); 329 1.1 christos set_sim_regno (sim_regno, tdep->ppc_cr_regnum, sim_ppc_cr_regnum); 330 1.1 christos 331 1.1 christos /* Segment registers. */ 332 1.1 christos for (i = 0; i < ppc_num_srs; i++) 333 1.1 christos { 334 1.1 christos int gdb_regno; 335 1.1 christos 336 1.1 christos gdb_regno = user_reg_map_name_to_regnum (arch, segment_regs[i], -1); 337 1.1 christos if (gdb_regno >= 0) 338 1.1 christos set_sim_regno (sim_regno, gdb_regno, sim_ppc_sr0_regnum + i); 339 1.1 christos } 340 1.1 christos 341 1.1 christos /* Altivec registers. */ 342 1.1 christos if (tdep->ppc_vr0_regnum >= 0) 343 1.1 christos { 344 1.1 christos for (i = 0; i < ppc_num_vrs; i++) 345 1.10 christos set_sim_regno (sim_regno, 346 1.10 christos tdep->ppc_vr0_regnum + i, 347 1.10 christos sim_ppc_vr0_regnum + i); 348 1.1 christos 349 1.1 christos /* FIXME: jimb/2004-07-15: when we have tdep->ppc_vscr_regnum, 350 1.10 christos we can treat this more like the other cases. */ 351 1.1 christos set_sim_regno (sim_regno, 352 1.10 christos tdep->ppc_vr0_regnum + ppc_num_vrs, 353 1.10 christos sim_ppc_vscr_regnum); 354 1.1 christos } 355 1.1 christos /* vsave is a special-purpose register, so the code below handles it. */ 356 1.1 christos 357 1.1 christos /* SPE APU (E500) registers. */ 358 1.1 christos if (tdep->ppc_ev0_upper_regnum >= 0) 359 1.1 christos for (i = 0; i < ppc_num_gprs; i++) 360 1.1 christos set_sim_regno (sim_regno, 361 1.10 christos tdep->ppc_ev0_upper_regnum + i, 362 1.10 christos sim_ppc_rh0_regnum + i); 363 1.1 christos if (tdep->ppc_acc_regnum >= 0) 364 1.1 christos set_sim_regno (sim_regno, tdep->ppc_acc_regnum, sim_ppc_acc_regnum); 365 1.1 christos /* spefscr is a special-purpose register, so the code below handles it. */ 366 1.1 christos 367 1.6 christos #ifdef WITH_PPC_SIM 368 1.1 christos /* Now handle all special-purpose registers. Verify that they 369 1.1 christos haven't mistakenly been assigned numbers by any of the above 370 1.1 christos code. */ 371 1.1 christos for (i = 0; i < sim_ppc_num_sprs; i++) 372 1.1 christos { 373 1.1 christos const char *spr_name = sim_spr_register_name (i); 374 1.1 christos int gdb_regno = -1; 375 1.1 christos 376 1.1 christos if (spr_name != NULL) 377 1.1 christos gdb_regno = user_reg_map_name_to_regnum (arch, spr_name, -1); 378 1.1 christos 379 1.1 christos if (gdb_regno != -1) 380 1.1 christos set_sim_regno (sim_regno, gdb_regno, sim_ppc_spr0_regnum + i); 381 1.1 christos } 382 1.1 christos #endif 383 1.1 christos 384 1.1 christos /* Drop the initialized array into place. */ 385 1.1 christos tdep->sim_regno = sim_regno; 386 1.1 christos } 387 1.1 christos 388 1.1 christos 389 1.1 christos /* Given a GDB register number REG, return the corresponding SIM 390 1.1 christos register number. */ 391 1.1 christos static int 392 1.1 christos rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg) 393 1.1 christos { 394 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 395 1.1 christos int sim_regno; 396 1.1 christos 397 1.1 christos if (tdep->sim_regno == NULL) 398 1.1 christos init_sim_regno_table (gdbarch); 399 1.1 christos 400 1.8 christos gdb_assert (0 <= reg && reg <= gdbarch_num_cooked_regs (gdbarch)); 401 1.1 christos sim_regno = tdep->sim_regno[reg]; 402 1.1 christos 403 1.1 christos if (sim_regno >= 0) 404 1.1 christos return sim_regno; 405 1.1 christos else 406 1.1 christos return LEGACY_SIM_REGNO_IGNORE; 407 1.1 christos } 408 1.1 christos 409 1.1 christos 410 1.1 christos 412 1.1 christos /* Register set support functions. */ 413 1.1 christos 414 1.1 christos /* REGS + OFFSET contains register REGNUM in a field REGSIZE wide. 415 1.1 christos Write the register to REGCACHE. */ 416 1.1 christos 417 1.1 christos void 418 1.1 christos ppc_supply_reg (struct regcache *regcache, int regnum, 419 1.1 christos const gdb_byte *regs, size_t offset, int regsize) 420 1.1 christos { 421 1.1 christos if (regnum != -1 && offset != -1) 422 1.1 christos { 423 1.1 christos if (regsize > 4) 424 1.8 christos { 425 1.1 christos struct gdbarch *gdbarch = regcache->arch (); 426 1.1 christos int gdb_regsize = register_size (gdbarch, regnum); 427 1.1 christos if (gdb_regsize < regsize 428 1.1 christos && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 429 1.1 christos offset += regsize - gdb_regsize; 430 1.8 christos } 431 1.1 christos regcache->raw_supply (regnum, regs + offset); 432 1.1 christos } 433 1.1 christos } 434 1.1 christos 435 1.1 christos /* Read register REGNUM from REGCACHE and store to REGS + OFFSET 436 1.1 christos in a field REGSIZE wide. Zero pad as necessary. */ 437 1.1 christos 438 1.1 christos void 439 1.1 christos ppc_collect_reg (const struct regcache *regcache, int regnum, 440 1.1 christos gdb_byte *regs, size_t offset, int regsize) 441 1.1 christos { 442 1.1 christos if (regnum != -1 && offset != -1) 443 1.1 christos { 444 1.1 christos if (regsize > 4) 445 1.8 christos { 446 1.1 christos struct gdbarch *gdbarch = regcache->arch (); 447 1.1 christos int gdb_regsize = register_size (gdbarch, regnum); 448 1.1 christos if (gdb_regsize < regsize) 449 1.1 christos { 450 1.1 christos if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 451 1.1 christos { 452 1.1 christos memset (regs + offset, 0, regsize - gdb_regsize); 453 1.1 christos offset += regsize - gdb_regsize; 454 1.1 christos } 455 1.1 christos else 456 1.1 christos memset (regs + offset + regsize - gdb_regsize, 0, 457 1.1 christos regsize - gdb_regsize); 458 1.1 christos } 459 1.8 christos } 460 1.1 christos regcache->raw_collect (regnum, regs + offset); 461 1.1 christos } 462 1.1 christos } 463 1.1 christos 464 1.1 christos static int 465 1.10 christos ppc_greg_offset (struct gdbarch *gdbarch, 466 1.1 christos ppc_gdbarch_tdep *tdep, 467 1.1 christos const struct ppc_reg_offsets *offsets, 468 1.1 christos int regnum, 469 1.1 christos int *regsize) 470 1.1 christos { 471 1.1 christos *regsize = offsets->gpr_size; 472 1.1 christos if (regnum >= tdep->ppc_gp0_regnum 473 1.1 christos && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs) 474 1.1 christos return (offsets->r0_offset 475 1.1 christos + (regnum - tdep->ppc_gp0_regnum) * offsets->gpr_size); 476 1.1 christos 477 1.1 christos if (regnum == gdbarch_pc_regnum (gdbarch)) 478 1.1 christos return offsets->pc_offset; 479 1.1 christos 480 1.1 christos if (regnum == tdep->ppc_ps_regnum) 481 1.1 christos return offsets->ps_offset; 482 1.1 christos 483 1.1 christos if (regnum == tdep->ppc_lr_regnum) 484 1.1 christos return offsets->lr_offset; 485 1.1 christos 486 1.1 christos if (regnum == tdep->ppc_ctr_regnum) 487 1.1 christos return offsets->ctr_offset; 488 1.1 christos 489 1.1 christos *regsize = offsets->xr_size; 490 1.1 christos if (regnum == tdep->ppc_cr_regnum) 491 1.1 christos return offsets->cr_offset; 492 1.1 christos 493 1.1 christos if (regnum == tdep->ppc_xer_regnum) 494 1.1 christos return offsets->xer_offset; 495 1.1 christos 496 1.1 christos if (regnum == tdep->ppc_mq_regnum) 497 1.1 christos return offsets->mq_offset; 498 1.1 christos 499 1.1 christos return -1; 500 1.1 christos } 501 1.1 christos 502 1.10 christos static int 503 1.1 christos ppc_fpreg_offset (ppc_gdbarch_tdep *tdep, 504 1.1 christos const struct ppc_reg_offsets *offsets, 505 1.1 christos int regnum) 506 1.1 christos { 507 1.1 christos if (regnum >= tdep->ppc_fp0_regnum 508 1.1 christos && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs) 509 1.1 christos return offsets->f0_offset + (regnum - tdep->ppc_fp0_regnum) * 8; 510 1.1 christos 511 1.1 christos if (regnum == tdep->ppc_fpscr_regnum) 512 1.1 christos return offsets->fpscr_offset; 513 1.1 christos 514 1.1 christos return -1; 515 1.1 christos } 516 1.1 christos 517 1.1 christos /* Supply register REGNUM in the general-purpose register set REGSET 518 1.1 christos from the buffer specified by GREGS and LEN to register cache 519 1.1 christos REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 520 1.1 christos 521 1.1 christos void 522 1.1 christos ppc_supply_gregset (const struct regset *regset, struct regcache *regcache, 523 1.1 christos int regnum, const void *gregs, size_t len) 524 1.8 christos { 525 1.10 christos struct gdbarch *gdbarch = regcache->arch (); 526 1.6 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 527 1.6 christos const struct ppc_reg_offsets *offsets 528 1.1 christos = (const struct ppc_reg_offsets *) regset->regmap; 529 1.1 christos size_t offset; 530 1.1 christos int regsize; 531 1.1 christos 532 1.1 christos if (regnum == -1) 533 1.1 christos { 534 1.1 christos int i; 535 1.1 christos int gpr_size = offsets->gpr_size; 536 1.1 christos 537 1.1 christos for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset; 538 1.1 christos i < tdep->ppc_gp0_regnum + ppc_num_gprs; 539 1.6 christos i++, offset += gpr_size) 540 1.6 christos ppc_supply_reg (regcache, i, (const gdb_byte *) gregs, offset, 541 1.1 christos gpr_size); 542 1.1 christos 543 1.6 christos ppc_supply_reg (regcache, gdbarch_pc_regnum (gdbarch), 544 1.1 christos (const gdb_byte *) gregs, offsets->pc_offset, gpr_size); 545 1.6 christos ppc_supply_reg (regcache, tdep->ppc_ps_regnum, 546 1.1 christos (const gdb_byte *) gregs, offsets->ps_offset, gpr_size); 547 1.6 christos ppc_supply_reg (regcache, tdep->ppc_lr_regnum, 548 1.1 christos (const gdb_byte *) gregs, offsets->lr_offset, gpr_size); 549 1.6 christos ppc_supply_reg (regcache, tdep->ppc_ctr_regnum, 550 1.1 christos (const gdb_byte *) gregs, offsets->ctr_offset, gpr_size); 551 1.6 christos ppc_supply_reg (regcache, tdep->ppc_cr_regnum, 552 1.6 christos (const gdb_byte *) gregs, offsets->cr_offset, 553 1.1 christos offsets->xr_size); 554 1.6 christos ppc_supply_reg (regcache, tdep->ppc_xer_regnum, 555 1.6 christos (const gdb_byte *) gregs, offsets->xer_offset, 556 1.1 christos offsets->xr_size); 557 1.6 christos ppc_supply_reg (regcache, tdep->ppc_mq_regnum, 558 1.6 christos (const gdb_byte *) gregs, offsets->mq_offset, 559 1.1 christos offsets->xr_size); 560 1.1 christos return; 561 1.1 christos } 562 1.1 christos 563 1.6 christos offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, ®size); 564 1.1 christos ppc_supply_reg (regcache, regnum, (const gdb_byte *) gregs, offset, regsize); 565 1.1 christos } 566 1.1 christos 567 1.1 christos /* Supply register REGNUM in the floating-point register set REGSET 568 1.1 christos from the buffer specified by FPREGS and LEN to register cache 569 1.1 christos REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 570 1.1 christos 571 1.1 christos void 572 1.1 christos ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache, 573 1.1 christos int regnum, const void *fpregs, size_t len) 574 1.8 christos { 575 1.1 christos struct gdbarch *gdbarch = regcache->arch (); 576 1.1 christos const struct ppc_reg_offsets *offsets; 577 1.1 christos size_t offset; 578 1.1 christos 579 1.1 christos if (!ppc_floating_point_unit_p (gdbarch)) 580 1.1 christos return; 581 1.10 christos 582 1.6 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 583 1.1 christos offsets = (const struct ppc_reg_offsets *) regset->regmap; 584 1.1 christos if (regnum == -1) 585 1.1 christos { 586 1.1 christos int i; 587 1.1 christos 588 1.1 christos for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset; 589 1.1 christos i < tdep->ppc_fp0_regnum + ppc_num_fprs; 590 1.6 christos i++, offset += 8) 591 1.1 christos ppc_supply_reg (regcache, i, (const gdb_byte *) fpregs, offset, 8); 592 1.1 christos 593 1.6 christos ppc_supply_reg (regcache, tdep->ppc_fpscr_regnum, 594 1.6 christos (const gdb_byte *) fpregs, offsets->fpscr_offset, 595 1.1 christos offsets->fpscr_size); 596 1.1 christos return; 597 1.1 christos } 598 1.1 christos 599 1.6 christos offset = ppc_fpreg_offset (tdep, offsets, regnum); 600 1.1 christos ppc_supply_reg (regcache, regnum, (const gdb_byte *) fpregs, offset, 601 1.1 christos regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8); 602 1.1 christos } 603 1.1 christos 604 1.1 christos /* Collect register REGNUM in the general-purpose register set 605 1.1 christos REGSET from register cache REGCACHE into the buffer specified by 606 1.1 christos GREGS and LEN. If REGNUM is -1, do this for all registers in 607 1.1 christos REGSET. */ 608 1.1 christos 609 1.1 christos void 610 1.1 christos ppc_collect_gregset (const struct regset *regset, 611 1.1 christos const struct regcache *regcache, 612 1.1 christos int regnum, void *gregs, size_t len) 613 1.8 christos { 614 1.10 christos struct gdbarch *gdbarch = regcache->arch (); 615 1.6 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 616 1.6 christos const struct ppc_reg_offsets *offsets 617 1.1 christos = (const struct ppc_reg_offsets *) regset->regmap; 618 1.1 christos size_t offset; 619 1.1 christos int regsize; 620 1.1 christos 621 1.1 christos if (regnum == -1) 622 1.1 christos { 623 1.1 christos int i; 624 1.1 christos int gpr_size = offsets->gpr_size; 625 1.1 christos 626 1.1 christos for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset; 627 1.1 christos i < tdep->ppc_gp0_regnum + ppc_num_gprs; 628 1.6 christos i++, offset += gpr_size) 629 1.1 christos ppc_collect_reg (regcache, i, (gdb_byte *) gregs, offset, gpr_size); 630 1.1 christos 631 1.6 christos ppc_collect_reg (regcache, gdbarch_pc_regnum (gdbarch), 632 1.1 christos (gdb_byte *) gregs, offsets->pc_offset, gpr_size); 633 1.6 christos ppc_collect_reg (regcache, tdep->ppc_ps_regnum, 634 1.1 christos (gdb_byte *) gregs, offsets->ps_offset, gpr_size); 635 1.6 christos ppc_collect_reg (regcache, tdep->ppc_lr_regnum, 636 1.1 christos (gdb_byte *) gregs, offsets->lr_offset, gpr_size); 637 1.6 christos ppc_collect_reg (regcache, tdep->ppc_ctr_regnum, 638 1.1 christos (gdb_byte *) gregs, offsets->ctr_offset, gpr_size); 639 1.6 christos ppc_collect_reg (regcache, tdep->ppc_cr_regnum, 640 1.6 christos (gdb_byte *) gregs, offsets->cr_offset, 641 1.1 christos offsets->xr_size); 642 1.6 christos ppc_collect_reg (regcache, tdep->ppc_xer_regnum, 643 1.6 christos (gdb_byte *) gregs, offsets->xer_offset, 644 1.1 christos offsets->xr_size); 645 1.6 christos ppc_collect_reg (regcache, tdep->ppc_mq_regnum, 646 1.6 christos (gdb_byte *) gregs, offsets->mq_offset, 647 1.1 christos offsets->xr_size); 648 1.1 christos return; 649 1.1 christos } 650 1.1 christos 651 1.6 christos offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, ®size); 652 1.1 christos ppc_collect_reg (regcache, regnum, (gdb_byte *) gregs, offset, regsize); 653 1.1 christos } 654 1.1 christos 655 1.1 christos /* Collect register REGNUM in the floating-point register set 656 1.1 christos REGSET from register cache REGCACHE into the buffer specified by 657 1.1 christos FPREGS and LEN. If REGNUM is -1, do this for all registers in 658 1.1 christos REGSET. */ 659 1.1 christos 660 1.1 christos void 661 1.1 christos ppc_collect_fpregset (const struct regset *regset, 662 1.1 christos const struct regcache *regcache, 663 1.1 christos int regnum, void *fpregs, size_t len) 664 1.8 christos { 665 1.1 christos struct gdbarch *gdbarch = regcache->arch (); 666 1.1 christos const struct ppc_reg_offsets *offsets; 667 1.1 christos size_t offset; 668 1.1 christos 669 1.1 christos if (!ppc_floating_point_unit_p (gdbarch)) 670 1.1 christos return; 671 1.10 christos 672 1.6 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 673 1.1 christos offsets = (const struct ppc_reg_offsets *) regset->regmap; 674 1.1 christos if (regnum == -1) 675 1.1 christos { 676 1.1 christos int i; 677 1.1 christos 678 1.1 christos for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset; 679 1.1 christos i < tdep->ppc_fp0_regnum + ppc_num_fprs; 680 1.6 christos i++, offset += 8) 681 1.1 christos ppc_collect_reg (regcache, i, (gdb_byte *) fpregs, offset, 8); 682 1.1 christos 683 1.6 christos ppc_collect_reg (regcache, tdep->ppc_fpscr_regnum, 684 1.6 christos (gdb_byte *) fpregs, offsets->fpscr_offset, 685 1.1 christos offsets->fpscr_size); 686 1.1 christos return; 687 1.1 christos } 688 1.1 christos 689 1.6 christos offset = ppc_fpreg_offset (tdep, offsets, regnum); 690 1.1 christos ppc_collect_reg (regcache, regnum, (gdb_byte *) fpregs, offset, 691 1.1 christos regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8); 692 1.1 christos } 693 1.1 christos 694 1.1 christos static int 695 1.1 christos insn_changes_sp_or_jumps (unsigned long insn) 696 1.1 christos { 697 1.1 christos int opcode = (insn >> 26) & 0x03f; 698 1.1 christos int sd = (insn >> 21) & 0x01f; 699 1.1 christos int a = (insn >> 16) & 0x01f; 700 1.1 christos int subcode = (insn >> 1) & 0x3ff; 701 1.1 christos 702 1.1 christos /* Changes the stack pointer. */ 703 1.1 christos 704 1.10 christos /* NOTE: There are many ways to change the value of a given register. 705 1.10 christos The ways below are those used when the register is R1, the SP, 706 1.1 christos in a funtion's epilogue. */ 707 1.1 christos 708 1.1 christos if (opcode == 31 && subcode == 444 && a == 1) 709 1.1 christos return 1; /* mr R1,Rn */ 710 1.1 christos if (opcode == 14 && sd == 1) 711 1.1 christos return 1; /* addi R1,Rn,simm */ 712 1.1 christos if (opcode == 58 && sd == 1) 713 1.1 christos return 1; /* ld R1,ds(Rn) */ 714 1.1 christos 715 1.1 christos /* Transfers control. */ 716 1.1 christos 717 1.1 christos if (opcode == 18) 718 1.1 christos return 1; /* b */ 719 1.1 christos if (opcode == 16) 720 1.1 christos return 1; /* bc */ 721 1.1 christos if (opcode == 19 && subcode == 16) 722 1.1 christos return 1; /* bclr */ 723 1.1 christos if (opcode == 19 && subcode == 528) 724 1.1 christos return 1; /* bcctr */ 725 1.1 christos 726 1.1 christos return 0; 727 1.1 christos } 728 1.1 christos 729 1.1 christos /* Return true if we are in the function's epilogue, i.e. after the 730 1.1 christos instruction that destroyed the function's stack frame. 731 1.1 christos 732 1.1 christos 1) scan forward from the point of execution: 733 1.10 christos a) If you find an instruction that modifies the stack pointer 734 1.10 christos or transfers control (except a return), execution is not in 735 1.1 christos an epilogue, return. 736 1.10 christos b) Stop scanning if you find a return instruction or reach the 737 1.10 christos end of the function or reach the hard limit for the size of 738 1.1 christos an epilogue. 739 1.10 christos 2) scan backward from the point of execution: 740 1.10 christos a) If you find an instruction that modifies the stack pointer, 741 1.10 christos execution *is* in an epilogue, return. 742 1.10 christos b) Stop scanning if you reach an instruction that transfers 743 1.10 christos control or the beginning of the function or reach the hard 744 1.1 christos limit for the size of an epilogue. */ 745 1.1 christos 746 1.11 christos static int 747 1.3 christos rs6000_in_function_epilogue_frame_p (const frame_info_ptr &curfrm, 748 1.1 christos struct gdbarch *gdbarch, CORE_ADDR pc) 749 1.10 christos { 750 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 751 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 752 1.1 christos bfd_byte insn_buf[PPC_INSN_SIZE]; 753 1.1 christos CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end; 754 1.1 christos unsigned long insn; 755 1.1 christos 756 1.1 christos /* Find the search limits based on function boundaries and hard limit. */ 757 1.1 christos 758 1.1 christos if (!find_pc_partial_function (pc, NULL, &func_start, &func_end)) 759 1.1 christos return 0; 760 1.1 christos 761 1.1 christos epilogue_start = pc - PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE; 762 1.1 christos if (epilogue_start < func_start) epilogue_start = func_start; 763 1.1 christos 764 1.1 christos epilogue_end = pc + PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE; 765 1.1 christos if (epilogue_end > func_end) epilogue_end = func_end; 766 1.1 christos 767 1.1 christos /* Scan forward until next 'blr'. */ 768 1.1 christos 769 1.1 christos for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += PPC_INSN_SIZE) 770 1.10 christos { 771 1.10 christos if (!safe_frame_unwind_memory (curfrm, scan_pc, 772 1.10 christos {insn_buf, PPC_INSN_SIZE})) 773 1.1 christos return 0; 774 1.1 christos insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order); 775 1.10 christos if (insn == 0x4e800020) 776 1.1 christos break; 777 1.1 christos /* Assume a bctr is a tail call unless it points strictly within 778 1.1 christos this function. */ 779 1.1 christos if (insn == 0x4e800420) 780 1.1 christos { 781 1.1 christos CORE_ADDR ctr = get_frame_register_unsigned (curfrm, 782 1.1 christos tdep->ppc_ctr_regnum); 783 1.1 christos if (ctr > func_start && ctr < func_end) 784 1.1 christos return 0; 785 1.1 christos else 786 1.1 christos break; 787 1.1 christos } 788 1.10 christos if (insn_changes_sp_or_jumps (insn)) 789 1.1 christos return 0; 790 1.1 christos } 791 1.1 christos 792 1.1 christos /* Scan backward until adjustment to stack pointer (R1). */ 793 1.1 christos 794 1.1 christos for (scan_pc = pc - PPC_INSN_SIZE; 795 1.1 christos scan_pc >= epilogue_start; 796 1.1 christos scan_pc -= PPC_INSN_SIZE) 797 1.10 christos { 798 1.10 christos if (!safe_frame_unwind_memory (curfrm, scan_pc, 799 1.10 christos {insn_buf, PPC_INSN_SIZE})) 800 1.1 christos return 0; 801 1.1 christos insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order); 802 1.10 christos if (insn_changes_sp_or_jumps (insn)) 803 1.1 christos return 1; 804 1.1 christos } 805 1.1 christos 806 1.1 christos return 0; 807 1.1 christos } 808 1.5 christos 809 1.3 christos /* Implement the stack_frame_destroyed_p gdbarch method. */ 810 1.3 christos 811 1.5 christos static int 812 1.3 christos rs6000_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) 813 1.3 christos { 814 1.3 christos return rs6000_in_function_epilogue_frame_p (get_current_frame (), 815 1.3 christos gdbarch, pc); 816 1.3 christos } 817 1.1 christos 818 1.1 christos /* Get the ith function argument for the current function. */ 819 1.11 christos static CORE_ADDR 820 1.1 christos rs6000_fetch_pointer_argument (const frame_info_ptr &frame, int argi, 821 1.1 christos struct type *type) 822 1.1 christos { 823 1.1 christos return get_frame_register_unsigned (frame, 3 + argi); 824 1.1 christos } 825 1.1 christos 826 1.1 christos /* Sequence of bytes for breakpoint instruction. */ 827 1.10 christos 828 1.10 christos constexpr gdb_byte big_breakpoint[] = { 0x7f, 0xe0, 0x00, 0x08 }; 829 1.7 christos constexpr gdb_byte little_breakpoint[] = { 0x08, 0x00, 0xe0, 0x7f }; 830 1.7 christos 831 1.7 christos typedef BP_MANIPULATION_ENDIAN (little_breakpoint, big_breakpoint) 832 1.1 christos rs6000_breakpoint; 833 1.1 christos 834 1.10 christos /* Instruction masks for displaced stepping. */ 835 1.1 christos #define OP_MASK 0xfc000000 836 1.1 christos #define BP_MASK 0xFC0007FE 837 1.1 christos #define B_INSN 0x48000000 838 1.1 christos #define BC_INSN 0x40000000 839 1.1 christos #define BXL_INSN 0x4c000000 840 1.1 christos #define BP_INSN 0x7C000008 841 1.6 christos 842 1.6 christos /* Instruction masks used during single-stepping of atomic 843 1.7 christos sequences. */ 844 1.6 christos #define LOAD_AND_RESERVE_MASK 0xfc0007fe 845 1.6 christos #define LWARX_INSTRUCTION 0x7c000028 846 1.7 christos #define LDARX_INSTRUCTION 0x7c0000A8 847 1.7 christos #define LBARX_INSTRUCTION 0x7c000068 848 1.7 christos #define LHARX_INSTRUCTION 0x7c0000e8 849 1.7 christos #define LQARX_INSTRUCTION 0x7c000228 850 1.6 christos #define STORE_CONDITIONAL_MASK 0xfc0007ff 851 1.6 christos #define STWCX_INSTRUCTION 0x7c00012d 852 1.7 christos #define STDCX_INSTRUCTION 0x7c0001ad 853 1.7 christos #define STBCX_INSTRUCTION 0x7c00056d 854 1.7 christos #define STHCX_INSTRUCTION 0x7c0005ad 855 1.7 christos #define STQCX_INSTRUCTION 0x7c00016d 856 1.10 christos 857 1.10 christos /* Instruction masks for single-stepping of addpcis/lnia. */ 858 1.10 christos #define ADDPCIS_INSN 0x4c000004 859 1.10 christos #define ADDPCIS_INSN_MASK 0xfc00003e 860 1.10 christos #define ADDPCIS_TARGET_REGISTER 0x03F00000 861 1.10 christos #define ADDPCIS_INSN_REGSHIFT 21 862 1.10 christos 863 1.10 christos #define PNOP_MASK 0xfff3ffff 864 1.10 christos #define PNOP_INSN 0x07000000 865 1.10 christos #define R_MASK 0x00100000 866 1.10 christos #define R_ZERO 0x00000000 867 1.7 christos 868 1.7 christos /* Check if insn is one of the Load And Reserve instructions used for atomic 869 1.7 christos sequences. */ 870 1.7 christos #define IS_LOAD_AND_RESERVE_INSN(insn) ((insn & LOAD_AND_RESERVE_MASK) == LWARX_INSTRUCTION \ 871 1.7 christos || (insn & LOAD_AND_RESERVE_MASK) == LDARX_INSTRUCTION \ 872 1.7 christos || (insn & LOAD_AND_RESERVE_MASK) == LBARX_INSTRUCTION \ 873 1.7 christos || (insn & LOAD_AND_RESERVE_MASK) == LHARX_INSTRUCTION \ 874 1.7 christos || (insn & LOAD_AND_RESERVE_MASK) == LQARX_INSTRUCTION) 875 1.7 christos /* Check if insn is one of the Store Conditional instructions used for atomic 876 1.7 christos sequences. */ 877 1.7 christos #define IS_STORE_CONDITIONAL_INSN(insn) ((insn & STORE_CONDITIONAL_MASK) == STWCX_INSTRUCTION \ 878 1.7 christos || (insn & STORE_CONDITIONAL_MASK) == STDCX_INSTRUCTION \ 879 1.7 christos || (insn & STORE_CONDITIONAL_MASK) == STBCX_INSTRUCTION \ 880 1.7 christos || (insn & STORE_CONDITIONAL_MASK) == STHCX_INSTRUCTION \ 881 1.6 christos || (insn & STORE_CONDITIONAL_MASK) == STQCX_INSTRUCTION) 882 1.10 christos 883 1.10 christos typedef buf_displaced_step_copy_insn_closure 884 1.8 christos ppc_displaced_step_copy_insn_closure; 885 1.8 christos 886 1.6 christos /* We can't displaced step atomic sequences. */ 887 1.10 christos 888 1.6 christos static displaced_step_copy_insn_closure_up 889 1.6 christos ppc_displaced_step_copy_insn (struct gdbarch *gdbarch, 890 1.6 christos CORE_ADDR from, CORE_ADDR to, 891 1.6 christos struct regcache *regs) 892 1.11 christos { 893 1.11 christos size_t len = gdbarch_displaced_step_buffer_length (gdbarch); 894 1.10 christos gdb_assert (len > PPC_INSN_SIZE); 895 1.10 christos std::unique_ptr<ppc_displaced_step_copy_insn_closure> closure 896 1.8 christos (new ppc_displaced_step_copy_insn_closure (len)); 897 1.6 christos gdb_byte *buf = closure->buf.data (); 898 1.6 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 899 1.6 christos int insn; 900 1.10 christos 901 1.10 christos len = target_read (current_inferior()->top_target(), TARGET_OBJECT_MEMORY, NULL, 902 1.10 christos buf, from, len); 903 1.10 christos if ((ssize_t) len < PPC_INSN_SIZE) 904 1.6 christos memory_error (TARGET_XFER_E_IO, from); 905 1.6 christos 906 1.6 christos insn = extract_signed_integer (buf, PPC_INSN_SIZE, byte_order); 907 1.10 christos 908 1.10 christos /* Check for PNOP and for prefixed instructions with R=0. Those 909 1.10 christos instructions are safe to displace. Prefixed instructions with R=1 910 1.10 christos will read/write data to/from locations relative to the current PC. 911 1.10 christos We would not be able to fixup after an instruction has written data 912 1.10 christos into a displaced location, so decline to displace those instructions. */ 913 1.10 christos if ((insn & OP_MASK) == 1 << 26) 914 1.10 christos { 915 1.10 christos if (((insn & PNOP_MASK) != PNOP_INSN) 916 1.10 christos && ((insn & R_MASK) != R_ZERO)) 917 1.10 christos { 918 1.10 christos displaced_debug_printf ("Not displacing prefixed instruction %08x at %s", 919 1.10 christos insn, paddress (gdbarch, from)); 920 1.10 christos return NULL; 921 1.10 christos } 922 1.10 christos } 923 1.10 christos else 924 1.10 christos /* Non-prefixed instructions.. */ 925 1.10 christos { 926 1.10 christos /* Set the instruction length to 4 to match the actual instruction 927 1.10 christos length. */ 928 1.10 christos len = 4; 929 1.10 christos } 930 1.7 christos 931 1.7 christos /* Assume all atomic sequences start with a Load and Reserve instruction. */ 932 1.6 christos if (IS_LOAD_AND_RESERVE_INSN (insn)) 933 1.10 christos { 934 1.6 christos displaced_debug_printf ("can't displaced step atomic sequence at %s", 935 1.8 christos paddress (gdbarch, from)); 936 1.6 christos 937 1.6 christos return NULL; 938 1.6 christos } 939 1.6 christos 940 1.6 christos write_memory (to, buf, len); 941 1.10 christos 942 1.10 christos displaced_debug_printf ("copy %s->%s: %s", 943 1.11 christos paddress (gdbarch, from), paddress (gdbarch, to), 944 1.6 christos bytes_to_string (buf, len).c_str ()); 945 1.9 christos 946 1.10 christos /* This is a work around for a problem with g++ 4.8. */ 947 1.6 christos return displaced_step_copy_insn_closure_up (closure.release ()); 948 1.6 christos } 949 1.1 christos 950 1.1 christos /* Fix up the state of registers and memory after having single-stepped 951 1.1 christos a displaced instruction. */ 952 1.1 christos static void 953 1.10 christos ppc_displaced_step_fixup (struct gdbarch *gdbarch, 954 1.1 christos struct displaced_step_copy_insn_closure *closure_, 955 1.11 christos CORE_ADDR from, CORE_ADDR to, 956 1.1 christos struct regcache *regs, bool completed_p) 957 1.11 christos { 958 1.11 christos /* If the displaced instruction didn't complete successfully then all we 959 1.11 christos need to do is restore the program counter. */ 960 1.11 christos if (!completed_p) 961 1.11 christos { 962 1.11 christos CORE_ADDR pc = regcache_read_pc (regs); 963 1.11 christos pc = from + (pc - to); 964 1.11 christos regcache_write_pc (regs, pc); 965 1.11 christos return; 966 1.11 christos } 967 1.1 christos 968 1.6 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 969 1.10 christos /* Our closure is a copy of the instruction. */ 970 1.10 christos ppc_displaced_step_copy_insn_closure *closure 971 1.8 christos = (ppc_displaced_step_copy_insn_closure *) closure_; 972 1.8 christos ULONGEST insn = extract_unsigned_integer (closure->buf.data (), 973 1.10 christos PPC_INSN_SIZE, byte_order); 974 1.1 christos ULONGEST opcode; 975 1.10 christos /* Offset for non PC-relative instructions. */ 976 1.1 christos LONGEST offset; 977 1.10 christos 978 1.1 christos opcode = insn & OP_MASK; 979 1.10 christos 980 1.10 christos /* Set offset to 8 if this is an 8-byte (prefixed) instruction. */ 981 1.10 christos if ((opcode) == 1 << 26) 982 1.10 christos offset = 2 * PPC_INSN_SIZE; 983 1.10 christos else 984 1.1 christos offset = PPC_INSN_SIZE; 985 1.10 christos 986 1.10 christos displaced_debug_printf ("(ppc) fixup (%s, %s)", 987 1.1 christos paddress (gdbarch, from), paddress (gdbarch, to)); 988 1.10 christos 989 1.10 christos /* Handle the addpcis/lnia instruction. */ 990 1.10 christos if ((insn & ADDPCIS_INSN_MASK) == ADDPCIS_INSN) 991 1.10 christos { 992 1.10 christos LONGEST displaced_offset; 993 1.10 christos ULONGEST current_val; 994 1.10 christos /* Measure the displacement. */ 995 1.10 christos displaced_offset = from - to; 996 1.10 christos /* Identify the target register that was updated by the instruction. */ 997 1.10 christos int regnum = (insn & ADDPCIS_TARGET_REGISTER) >> ADDPCIS_INSN_REGSHIFT; 998 1.10 christos /* Read and update the target value. */ 999 1.10 christos regcache_cooked_read_unsigned (regs, regnum , ¤t_val); 1000 1.10 christos displaced_debug_printf ("addpcis target regnum %d was %s now %s", 1001 1.10 christos regnum, paddress (gdbarch, current_val), 1002 1.10 christos paddress (gdbarch, current_val 1003 1.10 christos + displaced_offset)); 1004 1.10 christos regcache_cooked_write_unsigned (regs, regnum, 1005 1.10 christos current_val + displaced_offset); 1006 1.10 christos /* point the PC back at the non-displaced instruction. */ 1007 1.10 christos regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), 1008 1.10 christos from + offset); 1009 1.1 christos } 1010 1.10 christos /* Handle PC-relative branch instructions. */ 1011 1.1 christos else if (opcode == B_INSN || opcode == BC_INSN || opcode == BXL_INSN) 1012 1.1 christos { 1013 1.1 christos ULONGEST current_pc; 1014 1.1 christos 1015 1.1 christos /* Read the current PC value after the instruction has been executed 1016 1.1 christos in a displaced location. Calculate the offset to be applied to the 1017 1.1 christos original PC value before the displaced stepping. */ 1018 1.1 christos regcache_cooked_read_unsigned (regs, gdbarch_pc_regnum (gdbarch), 1019 1.1 christos ¤t_pc); 1020 1.1 christos offset = current_pc - to; 1021 1.1 christos 1022 1.1 christos if (opcode != BXL_INSN) 1023 1.1 christos { 1024 1.1 christos /* Check for AA bit indicating whether this is an absolute 1025 1.1 christos addressing or PC-relative (1: absolute, 0: relative). */ 1026 1.1 christos if (!(insn & 0x2)) 1027 1.1 christos { 1028 1.10 christos /* PC-relative addressing is being used in the branch. */ 1029 1.10 christos displaced_debug_printf ("(ppc) branch instruction: %s", 1030 1.10 christos paddress (gdbarch, insn)); 1031 1.10 christos displaced_debug_printf ("(ppc) adjusted PC from %s to %s", 1032 1.10 christos paddress (gdbarch, current_pc), 1033 1.1 christos paddress (gdbarch, from + offset)); 1034 1.1 christos 1035 1.1 christos regcache_cooked_write_unsigned (regs, 1036 1.1 christos gdbarch_pc_regnum (gdbarch), 1037 1.1 christos from + offset); 1038 1.1 christos } 1039 1.1 christos } 1040 1.1 christos else 1041 1.1 christos { 1042 1.1 christos /* If we're here, it means we have a branch to LR or CTR. If the 1043 1.1 christos branch was taken, the offset is probably greater than 4 (the next 1044 1.1 christos instruction), so it's safe to assume that an offset of 4 means we 1045 1.1 christos did not take the branch. */ 1046 1.1 christos if (offset == PPC_INSN_SIZE) 1047 1.1 christos regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), 1048 1.1 christos from + PPC_INSN_SIZE); 1049 1.1 christos } 1050 1.1 christos 1051 1.1 christos /* Check for LK bit indicating whether we should set the link 1052 1.1 christos register to point to the next instruction 1053 1.1 christos (1: Set, 0: Don't set). */ 1054 1.1 christos if (insn & 0x1) 1055 1.1 christos { 1056 1.10 christos /* Link register needs to be set to the next instruction's PC. */ 1057 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 1058 1.10 christos regcache_cooked_write_unsigned (regs, 1059 1.1 christos tdep->ppc_lr_regnum, 1060 1.10 christos from + PPC_INSN_SIZE); 1061 1.10 christos displaced_debug_printf ("(ppc) adjusted LR to %s", 1062 1.1 christos paddress (gdbarch, from + PPC_INSN_SIZE)); 1063 1.1 christos 1064 1.1 christos } 1065 1.1 christos } 1066 1.1 christos /* Check for breakpoints in the inferior. If we've found one, place the PC 1067 1.1 christos right at the breakpoint instruction. */ 1068 1.1 christos else if ((insn & BP_MASK) == BP_INSN) 1069 1.1 christos regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), from); 1070 1.10 christos else 1071 1.10 christos { 1072 1.11 christos /* Handle any other instructions that do not fit in the categories 1073 1.10 christos above. */ 1074 1.10 christos regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), 1075 1.10 christos from + offset); 1076 1.10 christos } 1077 1.10 christos } 1078 1.10 christos 1079 1.10 christos /* Implementation of gdbarch_displaced_step_prepare. */ 1080 1.10 christos 1081 1.10 christos static displaced_step_prepare_status 1082 1.10 christos ppc_displaced_step_prepare (gdbarch *arch, thread_info *thread, 1083 1.10 christos CORE_ADDR &displaced_pc) 1084 1.10 christos { 1085 1.10 christos ppc_inferior_data *per_inferior = get_ppc_per_inferior (thread->inf); 1086 1.10 christos 1087 1.10 christos if (!per_inferior->disp_step_buf.has_value ()) 1088 1.10 christos { 1089 1.10 christos /* Figure out where the displaced step buffer is. */ 1090 1.11 christos CORE_ADDR disp_step_buf_addr 1091 1.10 christos = displaced_step_at_entry_point (thread->inf->arch ()); 1092 1.10 christos 1093 1.10 christos per_inferior->disp_step_buf.emplace (disp_step_buf_addr); 1094 1.10 christos } 1095 1.10 christos 1096 1.10 christos return per_inferior->disp_step_buf->prepare (thread, displaced_pc); 1097 1.10 christos } 1098 1.10 christos 1099 1.10 christos /* Implementation of gdbarch_displaced_step_finish. */ 1100 1.10 christos 1101 1.10 christos static displaced_step_finish_status 1102 1.11 christos ppc_displaced_step_finish (gdbarch *arch, thread_info *thread, 1103 1.10 christos const target_waitstatus &status) 1104 1.10 christos { 1105 1.10 christos ppc_inferior_data *per_inferior = get_ppc_per_inferior (thread->inf); 1106 1.10 christos 1107 1.10 christos gdb_assert (per_inferior->disp_step_buf.has_value ()); 1108 1.11 christos 1109 1.10 christos return per_inferior->disp_step_buf->finish (arch, thread, status); 1110 1.10 christos } 1111 1.10 christos 1112 1.10 christos /* Implementation of gdbarch_displaced_step_restore_all_in_ptid. */ 1113 1.10 christos 1114 1.10 christos static void 1115 1.10 christos ppc_displaced_step_restore_all_in_ptid (inferior *parent_inf, ptid_t ptid) 1116 1.10 christos { 1117 1.10 christos ppc_inferior_data *per_inferior = ppc_inferior_data_key.get (parent_inf); 1118 1.10 christos 1119 1.10 christos if (per_inferior == nullptr 1120 1.10 christos || !per_inferior->disp_step_buf.has_value ()) 1121 1.10 christos return; 1122 1.10 christos 1123 1.1 christos per_inferior->disp_step_buf->restore_in_ptid (ptid); 1124 1.1 christos } 1125 1.1 christos 1126 1.1 christos /* Always use hardware single-stepping to execute the 1127 1.10 christos displaced instruction. */ 1128 1.10 christos static bool 1129 1.1 christos ppc_displaced_step_hw_singlestep (struct gdbarch *gdbarch) 1130 1.10 christos { 1131 1.1 christos return true; 1132 1.1 christos } 1133 1.7 christos 1134 1.7 christos /* Checks for an atomic sequence of instructions beginning with a 1135 1.7 christos Load And Reserve instruction and ending with a Store Conditional 1136 1.7 christos instruction. If such a sequence is found, attempt to step through it. 1137 1.8 christos A breakpoint is placed at the end of the sequence. */ 1138 1.7 christos std::vector<CORE_ADDR> 1139 1.1 christos ppc_deal_with_atomic_sequence (struct regcache *regcache) 1140 1.8 christos { 1141 1.1 christos struct gdbarch *gdbarch = regcache->arch (); 1142 1.7 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 1143 1.8 christos CORE_ADDR pc = regcache_read_pc (regcache); 1144 1.1 christos CORE_ADDR breaks[2] = {CORE_ADDR_MAX, CORE_ADDR_MAX}; 1145 1.1 christos CORE_ADDR loc = pc; 1146 1.1 christos CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence. */ 1147 1.1 christos int insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order); 1148 1.1 christos int insn_count; 1149 1.1 christos int index; 1150 1.1 christos int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ 1151 1.1 christos const int atomic_sequence_length = 16; /* Instruction sequence length. */ 1152 1.1 christos int bc_insn_count = 0; /* Conditional branch instruction count. */ 1153 1.7 christos 1154 1.7 christos /* Assume all atomic sequences start with a Load And Reserve instruction. */ 1155 1.8 christos if (!IS_LOAD_AND_RESERVE_INSN (insn)) 1156 1.1 christos return {}; 1157 1.1 christos 1158 1.1 christos /* Assume that no atomic sequence is longer than "atomic_sequence_length" 1159 1.1 christos instructions. */ 1160 1.1 christos for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count) 1161 1.10 christos { 1162 1.10 christos if ((insn & OP_MASK) == 1 << 26) 1163 1.10 christos loc += 2 * PPC_INSN_SIZE; 1164 1.10 christos else 1165 1.1 christos loc += PPC_INSN_SIZE; 1166 1.1 christos insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order); 1167 1.1 christos 1168 1.10 christos /* Assume that there is at most one conditional branch in the atomic 1169 1.10 christos sequence. If a conditional branch is found, put a breakpoint in 1170 1.10 christos its destination address. */ 1171 1.10 christos if ((insn & OP_MASK) == BC_INSN) 1172 1.10 christos { 1173 1.10 christos int immediate = ((insn & 0xfffc) ^ 0x8000) - 0x8000; 1174 1.10 christos int absolute = insn & 2; 1175 1.10 christos 1176 1.10 christos if (bc_insn_count >= 1) 1177 1.10 christos return {}; /* More than one conditional branch found, fallback 1178 1.1 christos to the standard single-step code. */ 1179 1.1 christos 1180 1.1 christos if (absolute) 1181 1.1 christos breaks[1] = immediate; 1182 1.1 christos else 1183 1.1 christos breaks[1] = loc + immediate; 1184 1.1 christos 1185 1.1 christos bc_insn_count++; 1186 1.10 christos last_breakpoint++; 1187 1.1 christos } 1188 1.7 christos 1189 1.10 christos if (IS_STORE_CONDITIONAL_INSN (insn)) 1190 1.1 christos break; 1191 1.1 christos } 1192 1.7 christos 1193 1.7 christos /* Assume that the atomic sequence ends with a Store Conditional 1194 1.7 christos instruction. */ 1195 1.8 christos if (!IS_STORE_CONDITIONAL_INSN (insn)) 1196 1.1 christos return {}; 1197 1.1 christos 1198 1.1 christos closing_insn = loc; 1199 1.1 christos loc += PPC_INSN_SIZE; 1200 1.1 christos 1201 1.1 christos /* Insert a breakpoint right after the end of the atomic sequence. */ 1202 1.1 christos breaks[0] = loc; 1203 1.1 christos 1204 1.1 christos /* Check for duplicated breakpoints. Check also for a breakpoint 1205 1.1 christos placed (branch instruction's destination) anywhere in sequence. */ 1206 1.1 christos if (last_breakpoint 1207 1.1 christos && (breaks[1] == breaks[0] 1208 1.1 christos || (breaks[1] >= pc && breaks[1] <= closing_insn))) 1209 1.1 christos last_breakpoint = 0; 1210 1.8 christos 1211 1.8 christos std::vector<CORE_ADDR> next_pcs; 1212 1.1 christos 1213 1.8 christos for (index = 0; index <= last_breakpoint; index++) 1214 1.1 christos next_pcs.push_back (breaks[index]); 1215 1.7 christos 1216 1.1 christos return next_pcs; 1217 1.1 christos } 1218 1.1 christos 1219 1.1 christos 1220 1.1 christos #define SIGNED_SHORT(x) \ 1221 1.1 christos ((sizeof (short) == 2) \ 1222 1.1 christos ? ((int)(short)(x)) \ 1223 1.1 christos : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000))) 1224 1.1 christos 1225 1.1 christos #define GET_SRC_REG(x) (((x) >> 21) & 0x1f) 1226 1.1 christos 1227 1.1 christos /* Limit the number of skipped non-prologue instructions, as the examining 1228 1.1 christos of the prologue is expensive. */ 1229 1.1 christos static int max_skip_non_prologue_insns = 10; 1230 1.1 christos 1231 1.1 christos /* Return nonzero if the given instruction OP can be part of the prologue 1232 1.1 christos of a function and saves a parameter on the stack. FRAMEP should be 1233 1.1 christos set if one of the previous instructions in the function has set the 1234 1.1 christos Frame Pointer. */ 1235 1.1 christos 1236 1.1 christos static int 1237 1.1 christos store_param_on_stack_p (unsigned long op, int framep, int *r0_contains_arg) 1238 1.1 christos { 1239 1.1 christos /* Move parameters from argument registers to temporary register. */ 1240 1.1 christos if ((op & 0xfc0007fe) == 0x7c000378) /* mr(.) Rx,Ry */ 1241 1.1 christos { 1242 1.1 christos /* Rx must be scratch register r0. */ 1243 1.1 christos const int rx_regno = (op >> 16) & 31; 1244 1.1 christos /* Ry: Only r3 - r10 are used for parameter passing. */ 1245 1.1 christos const int ry_regno = GET_SRC_REG (op); 1246 1.1 christos 1247 1.10 christos if (rx_regno == 0 && ry_regno >= 3 && ry_regno <= 10) 1248 1.10 christos { 1249 1.10 christos *r0_contains_arg = 1; 1250 1.10 christos return 1; 1251 1.1 christos } 1252 1.10 christos else 1253 1.1 christos return 0; 1254 1.1 christos } 1255 1.1 christos 1256 1.1 christos /* Save a General Purpose Register on stack. */ 1257 1.1 christos 1258 1.1 christos if ((op & 0xfc1f0003) == 0xf8010000 || /* std Rx,NUM(r1) */ 1259 1.1 christos (op & 0xfc1f0000) == 0xd8010000) /* stfd Rx,NUM(r1) */ 1260 1.1 christos { 1261 1.1 christos /* Rx: Only r3 - r10 are used for parameter passing. */ 1262 1.1 christos const int rx_regno = GET_SRC_REG (op); 1263 1.1 christos 1264 1.1 christos return (rx_regno >= 3 && rx_regno <= 10); 1265 1.10 christos } 1266 1.1 christos 1267 1.1 christos /* Save a General Purpose Register on stack via the Frame Pointer. */ 1268 1.1 christos 1269 1.1 christos if (framep && 1270 1.1 christos ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r31) */ 1271 1.1 christos (op & 0xfc1f0000) == 0x981f0000 || /* stb Rx,NUM(r31) */ 1272 1.1 christos (op & 0xfc1f0000) == 0xd81f0000)) /* stfd Rx,NUM(r31) */ 1273 1.1 christos { 1274 1.10 christos /* Rx: Usually, only r3 - r10 are used for parameter passing. 1275 1.1 christos However, the compiler sometimes uses r0 to hold an argument. */ 1276 1.1 christos const int rx_regno = GET_SRC_REG (op); 1277 1.1 christos 1278 1.10 christos return ((rx_regno >= 3 && rx_regno <= 10) 1279 1.1 christos || (rx_regno == 0 && *r0_contains_arg)); 1280 1.1 christos } 1281 1.1 christos 1282 1.1 christos if ((op & 0xfc1f0000) == 0xfc010000) /* frsp, fp?,NUM(r1) */ 1283 1.1 christos { 1284 1.1 christos /* Only f2 - f8 are used for parameter passing. */ 1285 1.1 christos const int src_regno = GET_SRC_REG (op); 1286 1.1 christos 1287 1.1 christos return (src_regno >= 2 && src_regno <= 8); 1288 1.1 christos } 1289 1.1 christos 1290 1.1 christos if (framep && ((op & 0xfc1f0000) == 0xfc1f0000)) /* frsp, fp?,NUM(r31) */ 1291 1.1 christos { 1292 1.1 christos /* Only f2 - f8 are used for parameter passing. */ 1293 1.1 christos const int src_regno = GET_SRC_REG (op); 1294 1.1 christos 1295 1.1 christos return (src_regno >= 2 && src_regno <= 8); 1296 1.1 christos } 1297 1.1 christos 1298 1.1 christos /* Not an insn that saves a parameter on stack. */ 1299 1.1 christos return 0; 1300 1.1 christos } 1301 1.1 christos 1302 1.1 christos /* Assuming that INSN is a "bl" instruction located at PC, return 1303 1.1 christos nonzero if the destination of the branch is a "blrl" instruction. 1304 1.1 christos 1305 1.1 christos This sequence is sometimes found in certain function prologues. 1306 1.1 christos It allows the function to load the LR register with a value that 1307 1.1 christos they can use to access PIC data using PC-relative offsets. */ 1308 1.1 christos 1309 1.1 christos static int 1310 1.1 christos bl_to_blrl_insn_p (CORE_ADDR pc, int insn, enum bfd_endian byte_order) 1311 1.1 christos { 1312 1.1 christos CORE_ADDR dest; 1313 1.1 christos int immediate; 1314 1.1 christos int absolute; 1315 1.1 christos int dest_insn; 1316 1.1 christos 1317 1.1 christos absolute = (int) ((insn >> 1) & 1); 1318 1.1 christos immediate = ((insn & ~3) << 6) >> 6; 1319 1.1 christos if (absolute) 1320 1.1 christos dest = immediate; 1321 1.1 christos else 1322 1.1 christos dest = pc + immediate; 1323 1.1 christos 1324 1.1 christos dest_insn = read_memory_integer (dest, 4, byte_order); 1325 1.1 christos if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */ 1326 1.1 christos return 1; 1327 1.1 christos 1328 1.1 christos return 0; 1329 1.1 christos } 1330 1.8 christos 1331 1.8 christos /* Return true if OP is a stw or std instruction with 1332 1.8 christos register operands RS and RA and any immediate offset. 1333 1.8 christos 1334 1.8 christos If WITH_UPDATE is true, also return true if OP is 1335 1.8 christos a stwu or stdu instruction with the same operands. 1336 1.8 christos 1337 1.8 christos Return false otherwise. 1338 1.8 christos */ 1339 1.8 christos static bool 1340 1.8 christos store_insn_p (unsigned long op, unsigned long rs, 1341 1.8 christos unsigned long ra, bool with_update) 1342 1.8 christos { 1343 1.8 christos rs = rs << 21; 1344 1.8 christos ra = ra << 16; 1345 1.8 christos 1346 1.8 christos if (/* std RS, SIMM(RA) */ 1347 1.8 christos ((op & 0xffff0003) == (rs | ra | 0xf8000000)) || 1348 1.8 christos /* stw RS, SIMM(RA) */ 1349 1.8 christos ((op & 0xffff0000) == (rs | ra | 0x90000000))) 1350 1.8 christos return true; 1351 1.8 christos 1352 1.8 christos if (with_update) 1353 1.8 christos { 1354 1.8 christos if (/* stdu RS, SIMM(RA) */ 1355 1.8 christos ((op & 0xffff0003) == (rs | ra | 0xf8000001)) || 1356 1.8 christos /* stwu RS, SIMM(RA) */ 1357 1.8 christos ((op & 0xffff0000) == (rs | ra | 0x94000000))) 1358 1.8 christos return true; 1359 1.8 christos } 1360 1.8 christos 1361 1.8 christos return false; 1362 1.8 christos } 1363 1.1 christos 1364 1.1 christos /* Masks for decoding a branch-and-link (bl) instruction. 1365 1.1 christos 1366 1.1 christos BL_MASK and BL_INSTRUCTION are used in combination with each other. 1367 1.1 christos The former is anded with the opcode in question; if the result of 1368 1.1 christos this masking operation is equal to BL_INSTRUCTION, then the opcode in 1369 1.1 christos question is a ``bl'' instruction. 1370 1.9 christos 1371 1.1 christos BL_DISPLACEMENT_MASK is anded with the opcode in order to extract 1372 1.1 christos the branch displacement. */ 1373 1.1 christos 1374 1.1 christos #define BL_MASK 0xfc000001 1375 1.1 christos #define BL_INSTRUCTION 0x48000001 1376 1.1 christos #define BL_DISPLACEMENT_MASK 0x03fffffc 1377 1.1 christos 1378 1.1 christos static unsigned long 1379 1.1 christos rs6000_fetch_instruction (struct gdbarch *gdbarch, const CORE_ADDR pc) 1380 1.1 christos { 1381 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 1382 1.1 christos gdb_byte buf[4]; 1383 1.1 christos unsigned long op; 1384 1.1 christos 1385 1.1 christos /* Fetch the instruction and convert it to an integer. */ 1386 1.1 christos if (target_read_memory (pc, buf, 4)) 1387 1.1 christos return 0; 1388 1.1 christos op = extract_unsigned_integer (buf, 4, byte_order); 1389 1.1 christos 1390 1.1 christos return op; 1391 1.1 christos } 1392 1.1 christos 1393 1.1 christos /* GCC generates several well-known sequences of instructions at the begining 1394 1.1 christos of each function prologue when compiling with -fstack-check. If one of 1395 1.1 christos such sequences starts at START_PC, then return the address of the 1396 1.1 christos instruction immediately past this sequence. Otherwise, return START_PC. */ 1397 1.1 christos 1398 1.1 christos static CORE_ADDR 1399 1.1 christos rs6000_skip_stack_check (struct gdbarch *gdbarch, const CORE_ADDR start_pc) 1400 1.1 christos { 1401 1.1 christos CORE_ADDR pc = start_pc; 1402 1.1 christos unsigned long op = rs6000_fetch_instruction (gdbarch, pc); 1403 1.1 christos 1404 1.10 christos /* First possible sequence: A small number of probes. 1405 1.10 christos stw 0, -<some immediate>(1) 1406 1.1 christos [repeat this instruction any (small) number of times]. */ 1407 1.1 christos 1408 1.1 christos if ((op & 0xffff0000) == 0x90010000) 1409 1.1 christos { 1410 1.10 christos while ((op & 0xffff0000) == 0x90010000) 1411 1.10 christos { 1412 1.10 christos pc = pc + 4; 1413 1.10 christos op = rs6000_fetch_instruction (gdbarch, pc); 1414 1.1 christos } 1415 1.1 christos return pc; 1416 1.1 christos } 1417 1.1 christos 1418 1.10 christos /* Second sequence: A probing loop. 1419 1.10 christos addi 12,1,-<some immediate> 1420 1.10 christos lis 0,-<some immediate> 1421 1.10 christos [possibly ori 0,0,<some immediate>] 1422 1.10 christos add 0,12,0 1423 1.10 christos cmpw 0,12,0 1424 1.10 christos beq 0,<disp> 1425 1.10 christos addi 12,12,-<some immediate> 1426 1.10 christos stw 0,0(12) 1427 1.10 christos b <disp> 1428 1.1 christos [possibly one last probe: stw 0,<some immediate>(12)]. */ 1429 1.1 christos 1430 1.1 christos while (1) 1431 1.1 christos { 1432 1.1 christos /* addi 12,1,-<some immediate> */ 1433 1.10 christos if ((op & 0xffff0000) != 0x39810000) 1434 1.1 christos break; 1435 1.1 christos 1436 1.1 christos /* lis 0,-<some immediate> */ 1437 1.1 christos pc = pc + 4; 1438 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1439 1.10 christos if ((op & 0xffff0000) != 0x3c000000) 1440 1.1 christos break; 1441 1.1 christos 1442 1.1 christos pc = pc + 4; 1443 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1444 1.1 christos /* [possibly ori 0,0,<some immediate>] */ 1445 1.10 christos if ((op & 0xffff0000) == 0x60000000) 1446 1.10 christos { 1447 1.10 christos pc = pc + 4; 1448 1.10 christos op = rs6000_fetch_instruction (gdbarch, pc); 1449 1.1 christos } 1450 1.1 christos /* add 0,12,0 */ 1451 1.10 christos if (op != 0x7c0c0214) 1452 1.1 christos break; 1453 1.1 christos 1454 1.1 christos /* cmpw 0,12,0 */ 1455 1.1 christos pc = pc + 4; 1456 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1457 1.10 christos if (op != 0x7c0c0000) 1458 1.1 christos break; 1459 1.1 christos 1460 1.1 christos /* beq 0,<disp> */ 1461 1.1 christos pc = pc + 4; 1462 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1463 1.10 christos if ((op & 0xff9f0001) != 0x41820000) 1464 1.1 christos break; 1465 1.1 christos 1466 1.1 christos /* addi 12,12,-<some immediate> */ 1467 1.1 christos pc = pc + 4; 1468 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1469 1.10 christos if ((op & 0xffff0000) != 0x398c0000) 1470 1.1 christos break; 1471 1.1 christos 1472 1.1 christos /* stw 0,0(12) */ 1473 1.1 christos pc = pc + 4; 1474 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1475 1.10 christos if (op != 0x900c0000) 1476 1.1 christos break; 1477 1.1 christos 1478 1.1 christos /* b <disp> */ 1479 1.1 christos pc = pc + 4; 1480 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1481 1.10 christos if ((op & 0xfc000001) != 0x48000000) 1482 1.1 christos break; 1483 1.1 christos 1484 1.1 christos /* [possibly one last probe: stw 0,<some immediate>(12)]. */ 1485 1.1 christos pc = pc + 4; 1486 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1487 1.10 christos if ((op & 0xffff0000) == 0x900c0000) 1488 1.10 christos { 1489 1.10 christos pc = pc + 4; 1490 1.10 christos op = rs6000_fetch_instruction (gdbarch, pc); 1491 1.1 christos } 1492 1.1 christos 1493 1.1 christos /* We found a valid stack-check sequence, return the new PC. */ 1494 1.1 christos return pc; 1495 1.1 christos } 1496 1.9 christos 1497 1.1 christos /* Third sequence: No probe; instead, a comparison between the stack size 1498 1.1 christos limit (saved in a run-time global variable) and the current stack 1499 1.1 christos pointer: 1500 1.10 christos 1501 1.10 christos addi 0,1,-<some immediate> 1502 1.10 christos lis 12,__gnat_stack_limit@ha 1503 1.10 christos lwz 12,__gnat_stack_limit@l(12) 1504 1.1 christos twllt 0,12 1505 1.1 christos 1506 1.10 christos or, with a small variant in the case of a bigger stack frame: 1507 1.10 christos addis 0,1,<some immediate> 1508 1.10 christos addic 0,0,-<some immediate> 1509 1.10 christos lis 12,__gnat_stack_limit@ha 1510 1.10 christos lwz 12,__gnat_stack_limit@l(12) 1511 1.1 christos twllt 0,12 1512 1.1 christos */ 1513 1.1 christos while (1) 1514 1.1 christos { 1515 1.1 christos /* addi 0,1,-<some immediate> */ 1516 1.10 christos if ((op & 0xffff0000) != 0x38010000) 1517 1.10 christos { 1518 1.10 christos /* small stack frame variant not recognized; try the 1519 1.10 christos big stack frame variant: */ 1520 1.10 christos 1521 1.10 christos /* addis 0,1,<some immediate> */ 1522 1.10 christos if ((op & 0xffff0000) != 0x3c010000) 1523 1.10 christos break; 1524 1.10 christos 1525 1.10 christos /* addic 0,0,-<some immediate> */ 1526 1.10 christos pc = pc + 4; 1527 1.10 christos op = rs6000_fetch_instruction (gdbarch, pc); 1528 1.10 christos if ((op & 0xffff0000) != 0x30000000) 1529 1.10 christos break; 1530 1.1 christos } 1531 1.1 christos 1532 1.1 christos /* lis 12,<some immediate> */ 1533 1.1 christos pc = pc + 4; 1534 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1535 1.10 christos if ((op & 0xffff0000) != 0x3d800000) 1536 1.1 christos break; 1537 1.1 christos 1538 1.1 christos /* lwz 12,<some immediate>(12) */ 1539 1.1 christos pc = pc + 4; 1540 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1541 1.10 christos if ((op & 0xffff0000) != 0x818c0000) 1542 1.1 christos break; 1543 1.1 christos 1544 1.1 christos /* twllt 0,12 */ 1545 1.1 christos pc = pc + 4; 1546 1.1 christos op = rs6000_fetch_instruction (gdbarch, pc); 1547 1.10 christos if ((op & 0xfffffffe) != 0x7c406008) 1548 1.1 christos break; 1549 1.1 christos 1550 1.1 christos /* We found a valid stack-check sequence, return the new PC. */ 1551 1.1 christos return pc; 1552 1.1 christos } 1553 1.1 christos 1554 1.1 christos /* No stack check code in our prologue, return the start_pc. */ 1555 1.1 christos return start_pc; 1556 1.1 christos } 1557 1.1 christos 1558 1.1 christos /* return pc value after skipping a function prologue and also return 1559 1.1 christos information about a function frame. 1560 1.1 christos 1561 1.1 christos in struct rs6000_framedata fdata: 1562 1.1 christos - frameless is TRUE, if function does not have a frame. 1563 1.1 christos - nosavedpc is TRUE, if function does not save %pc value in its frame. 1564 1.1 christos - offset is the initial size of this stack frame --- the amount by 1565 1.1 christos which we decrement the sp to allocate the frame. 1566 1.1 christos - saved_gpr is the number of the first saved gpr. 1567 1.1 christos - saved_fpr is the number of the first saved fpr. 1568 1.1 christos - saved_vr is the number of the first saved vr. 1569 1.1 christos - saved_ev is the number of the first saved ev. 1570 1.1 christos - alloca_reg is the number of the register used for alloca() handling. 1571 1.1 christos Otherwise -1. 1572 1.1 christos - gpr_offset is the offset of the first saved gpr from the previous frame. 1573 1.1 christos - fpr_offset is the offset of the first saved fpr from the previous frame. 1574 1.1 christos - vr_offset is the offset of the first saved vr from the previous frame. 1575 1.1 christos - ev_offset is the offset of the first saved ev from the previous frame. 1576 1.1 christos - lr_offset is the offset of the saved lr 1577 1.1 christos - cr_offset is the offset of the saved cr 1578 1.1 christos - vrsave_offset is the offset of the saved vrsave register. */ 1579 1.1 christos 1580 1.1 christos static CORE_ADDR 1581 1.1 christos skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc, 1582 1.1 christos struct rs6000_framedata *fdata) 1583 1.1 christos { 1584 1.1 christos CORE_ADDR orig_pc = pc; 1585 1.1 christos CORE_ADDR last_prologue_pc = pc; 1586 1.1 christos CORE_ADDR li_found_pc = 0; 1587 1.1 christos gdb_byte buf[4]; 1588 1.1 christos unsigned long op; 1589 1.8 christos long offset = 0; 1590 1.1 christos long alloca_reg_offset = 0; 1591 1.1 christos long vr_saved_offset = 0; 1592 1.1 christos int lr_reg = -1; 1593 1.1 christos int cr_reg = -1; 1594 1.1 christos int vr_reg = -1; 1595 1.1 christos int ev_reg = -1; 1596 1.1 christos long ev_offset = 0; 1597 1.1 christos int vrsave_reg = -1; 1598 1.1 christos int reg; 1599 1.1 christos int framep = 0; 1600 1.1 christos int minimal_toc_loaded = 0; 1601 1.1 christos int prev_insn_was_prologue_insn = 1; 1602 1.1 christos int num_skip_non_prologue_insns = 0; 1603 1.1 christos int r0_contains_arg = 0; 1604 1.10 christos const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch); 1605 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 1606 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 1607 1.1 christos 1608 1.1 christos memset (fdata, 0, sizeof (struct rs6000_framedata)); 1609 1.1 christos fdata->saved_gpr = -1; 1610 1.1 christos fdata->saved_fpr = -1; 1611 1.1 christos fdata->saved_vr = -1; 1612 1.1 christos fdata->saved_ev = -1; 1613 1.1 christos fdata->alloca_reg = -1; 1614 1.1 christos fdata->frameless = 1; 1615 1.1 christos fdata->nosavedpc = 1; 1616 1.1 christos fdata->lr_register = -1; 1617 1.1 christos 1618 1.1 christos pc = rs6000_skip_stack_check (gdbarch, pc); 1619 1.1 christos if (pc >= lim_pc) 1620 1.1 christos pc = lim_pc; 1621 1.1 christos 1622 1.1 christos for (;; pc += 4) 1623 1.1 christos { 1624 1.10 christos /* Sometimes it isn't clear if an instruction is a prologue 1625 1.1 christos instruction or not. When we encounter one of these ambiguous 1626 1.1 christos cases, we'll set prev_insn_was_prologue_insn to 0 (false). 1627 1.1 christos Otherwise, we'll assume that it really is a prologue instruction. */ 1628 1.1 christos if (prev_insn_was_prologue_insn) 1629 1.1 christos last_prologue_pc = pc; 1630 1.1 christos 1631 1.1 christos /* Stop scanning if we've hit the limit. */ 1632 1.1 christos if (pc >= lim_pc) 1633 1.1 christos break; 1634 1.1 christos 1635 1.1 christos prev_insn_was_prologue_insn = 1; 1636 1.1 christos 1637 1.1 christos /* Fetch the instruction and convert it to an integer. */ 1638 1.1 christos if (target_read_memory (pc, buf, 4)) 1639 1.1 christos break; 1640 1.1 christos op = extract_unsigned_integer (buf, 4, byte_order); 1641 1.1 christos 1642 1.1 christos if ((op & 0xfc1fffff) == 0x7c0802a6) 1643 1.1 christos { /* mflr Rx */ 1644 1.1 christos /* Since shared library / PIC code, which needs to get its 1645 1.1 christos address at runtime, can appear to save more than one link 1646 1.1 christos register vis: 1647 1.1 christos 1648 1.1 christos stwu r1,-304(r1) 1649 1.1 christos mflr r3 1650 1.1 christos bl 0xff570d0 (blrl) 1651 1.1 christos stw r30,296(r1) 1652 1.1 christos mflr r30 1653 1.1 christos stw r31,300(r1) 1654 1.1 christos stw r3,308(r1); 1655 1.1 christos ... 1656 1.1 christos 1657 1.1 christos remember just the first one, but skip over additional 1658 1.1 christos ones. */ 1659 1.1 christos if (lr_reg == -1) 1660 1.10 christos lr_reg = (op & 0x03e00000) >> 21; 1661 1.10 christos if (lr_reg == 0) 1662 1.1 christos r0_contains_arg = 0; 1663 1.1 christos continue; 1664 1.1 christos } 1665 1.1 christos else if ((op & 0xfc1fffff) == 0x7c000026) 1666 1.8 christos { /* mfcr Rx */ 1667 1.10 christos cr_reg = (op & 0x03e00000) >> 21; 1668 1.10 christos if (cr_reg == 0) 1669 1.1 christos r0_contains_arg = 0; 1670 1.1 christos continue; 1671 1.1 christos 1672 1.1 christos } 1673 1.1 christos else if ((op & 0xfc1f0000) == 0xd8010000) 1674 1.1 christos { /* stfd Rx,NUM(r1) */ 1675 1.1 christos reg = GET_SRC_REG (op); 1676 1.1 christos if (fdata->saved_fpr == -1 || fdata->saved_fpr > reg) 1677 1.1 christos { 1678 1.1 christos fdata->saved_fpr = reg; 1679 1.1 christos fdata->fpr_offset = SIGNED_SHORT (op) + offset; 1680 1.1 christos } 1681 1.1 christos continue; 1682 1.1 christos 1683 1.1 christos } 1684 1.1 christos else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */ 1685 1.1 christos (((op & 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */ 1686 1.1 christos (op & 0xfc1f0003) == 0xf8010000) && /* std rx,NUM(r1) */ 1687 1.1 christos (op & 0x03e00000) >= 0x01a00000)) /* rx >= r13 */ 1688 1.1 christos { 1689 1.1 christos 1690 1.1 christos reg = GET_SRC_REG (op); 1691 1.1 christos if ((op & 0xfc1f0000) == 0xbc010000) 1692 1.1 christos fdata->gpr_mask |= ~((1U << reg) - 1); 1693 1.1 christos else 1694 1.1 christos fdata->gpr_mask |= 1U << reg; 1695 1.1 christos if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg) 1696 1.1 christos { 1697 1.1 christos fdata->saved_gpr = reg; 1698 1.1 christos if ((op & 0xfc1f0003) == 0xf8010000) 1699 1.1 christos op &= ~3UL; 1700 1.1 christos fdata->gpr_offset = SIGNED_SHORT (op) + offset; 1701 1.1 christos } 1702 1.1 christos continue; 1703 1.1 christos 1704 1.1 christos } 1705 1.1 christos else if ((op & 0xffff0000) == 0x3c4c0000 1706 1.1 christos || (op & 0xffff0000) == 0x3c400000 1707 1.1 christos || (op & 0xffff0000) == 0x38420000) 1708 1.1 christos { 1709 1.1 christos /* . 0: addis 2,12,.TOC.-0b@ha 1710 1.1 christos . addi 2,2,.TOC.-0b@l 1711 1.1 christos or 1712 1.1 christos . lis 2,.TOC.@ha 1713 1.1 christos . addi 2,2,.TOC.@l 1714 1.1 christos used by ELFv2 global entry points to set up r2. */ 1715 1.1 christos continue; 1716 1.1 christos } 1717 1.10 christos else if (op == 0x60000000) 1718 1.1 christos { 1719 1.1 christos /* nop */ 1720 1.1 christos /* Allow nops in the prologue, but do not consider them to 1721 1.1 christos be part of the prologue unless followed by other prologue 1722 1.1 christos instructions. */ 1723 1.1 christos prev_insn_was_prologue_insn = 0; 1724 1.1 christos continue; 1725 1.1 christos 1726 1.1 christos } 1727 1.1 christos else if ((op & 0xffff0000) == 0x3c000000) 1728 1.1 christos { /* addis 0,0,NUM, used for >= 32k frames */ 1729 1.1 christos fdata->offset = (op & 0x0000ffff) << 16; 1730 1.10 christos fdata->frameless = 0; 1731 1.1 christos r0_contains_arg = 0; 1732 1.1 christos continue; 1733 1.1 christos 1734 1.1 christos } 1735 1.1 christos else if ((op & 0xffff0000) == 0x60000000) 1736 1.1 christos { /* ori 0,0,NUM, 2nd half of >= 32k frames */ 1737 1.1 christos fdata->offset |= (op & 0x0000ffff); 1738 1.10 christos fdata->frameless = 0; 1739 1.1 christos r0_contains_arg = 0; 1740 1.1 christos continue; 1741 1.1 christos 1742 1.1 christos } 1743 1.8 christos else if (lr_reg >= 0 && 1744 1.8 christos ((store_insn_p (op, lr_reg, 1, true)) || 1745 1.8 christos (framep && 1746 1.8 christos (store_insn_p (op, lr_reg, 1747 1.8 christos fdata->alloca_reg - tdep->ppc_gp0_regnum, 1748 1.8 christos false))))) 1749 1.8 christos { 1750 1.8 christos if (store_insn_p (op, lr_reg, 1, true)) 1751 1.8 christos fdata->lr_offset = offset; 1752 1.8 christos else /* LR save through frame pointer. */ 1753 1.8 christos fdata->lr_offset = alloca_reg_offset; 1754 1.1 christos 1755 1.1 christos fdata->nosavedpc = 0; 1756 1.1 christos /* Invalidate lr_reg, but don't set it to -1. 1757 1.1 christos That would mean that it had never been set. */ 1758 1.1 christos lr_reg = -2; 1759 1.1 christos if ((op & 0xfc000003) == 0xf8000000 || /* std */ 1760 1.1 christos (op & 0xfc000000) == 0x90000000) /* stw */ 1761 1.1 christos { 1762 1.1 christos /* Does not update r1, so add displacement to lr_offset. */ 1763 1.1 christos fdata->lr_offset += SIGNED_SHORT (op); 1764 1.1 christos } 1765 1.1 christos continue; 1766 1.1 christos 1767 1.1 christos } 1768 1.8 christos else if (cr_reg >= 0 && 1769 1.8 christos (store_insn_p (op, cr_reg, 1, true))) 1770 1.1 christos { 1771 1.1 christos fdata->cr_offset = offset; 1772 1.1 christos /* Invalidate cr_reg, but don't set it to -1. 1773 1.1 christos That would mean that it had never been set. */ 1774 1.1 christos cr_reg = -2; 1775 1.1 christos if ((op & 0xfc000003) == 0xf8000000 || 1776 1.1 christos (op & 0xfc000000) == 0x90000000) 1777 1.1 christos { 1778 1.1 christos /* Does not update r1, so add displacement to cr_offset. */ 1779 1.1 christos fdata->cr_offset += SIGNED_SHORT (op); 1780 1.1 christos } 1781 1.1 christos continue; 1782 1.1 christos 1783 1.1 christos } 1784 1.1 christos else if ((op & 0xfe80ffff) == 0x42800005 && lr_reg != -1) 1785 1.1 christos { 1786 1.1 christos /* bcl 20,xx,.+4 is used to get the current PC, with or without 1787 1.1 christos prediction bits. If the LR has already been saved, we can 1788 1.1 christos skip it. */ 1789 1.1 christos continue; 1790 1.1 christos } 1791 1.1 christos else if (op == 0x48000005) 1792 1.1 christos { /* bl .+4 used in 1793 1.1 christos -mrelocatable */ 1794 1.1 christos fdata->used_bl = 1; 1795 1.1 christos continue; 1796 1.1 christos 1797 1.1 christos } 1798 1.1 christos else if (op == 0x48000004) 1799 1.1 christos { /* b .+4 (xlc) */ 1800 1.1 christos break; 1801 1.1 christos 1802 1.1 christos } 1803 1.1 christos else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used 1804 1.1 christos in V.4 -mminimal-toc */ 1805 1.1 christos (op & 0xffff0000) == 0x3bde0000) 1806 1.1 christos { /* addi 30,30,foo@l */ 1807 1.1 christos continue; 1808 1.1 christos 1809 1.1 christos } 1810 1.1 christos else if ((op & 0xfc000001) == 0x48000001) 1811 1.1 christos { /* bl foo, 1812 1.1 christos to save fprs??? */ 1813 1.1 christos 1814 1.1 christos fdata->frameless = 0; 1815 1.1 christos 1816 1.1 christos /* If the return address has already been saved, we can skip 1817 1.10 christos calls to blrl (for PIC). */ 1818 1.1 christos if (lr_reg != -1 && bl_to_blrl_insn_p (pc, op, byte_order)) 1819 1.1 christos { 1820 1.1 christos fdata->used_bl = 1; 1821 1.1 christos continue; 1822 1.1 christos } 1823 1.1 christos 1824 1.1 christos /* Don't skip over the subroutine call if it is not within 1825 1.1 christos the first three instructions of the prologue and either 1826 1.1 christos we have no line table information or the line info tells 1827 1.1 christos us that the subroutine call is not part of the line 1828 1.1 christos associated with the prologue. */ 1829 1.1 christos if ((pc - orig_pc) > 8) 1830 1.1 christos { 1831 1.1 christos struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0); 1832 1.1 christos struct symtab_and_line this_sal = find_pc_line (pc, 0); 1833 1.1 christos 1834 1.1 christos if ((prologue_sal.line == 0) 1835 1.1 christos || (prologue_sal.line != this_sal.line)) 1836 1.1 christos break; 1837 1.1 christos } 1838 1.1 christos 1839 1.1 christos op = read_memory_integer (pc + 4, 4, byte_order); 1840 1.1 christos 1841 1.1 christos /* At this point, make sure this is not a trampoline 1842 1.1 christos function (a function that simply calls another functions, 1843 1.1 christos and nothing else). If the next is not a nop, this branch 1844 1.1 christos was part of the function prologue. */ 1845 1.1 christos 1846 1.1 christos if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */ 1847 1.1 christos break; /* Don't skip over 1848 1.1 christos this branch. */ 1849 1.1 christos 1850 1.1 christos fdata->used_bl = 1; 1851 1.1 christos continue; 1852 1.1 christos } 1853 1.1 christos /* update stack pointer */ 1854 1.1 christos else if ((op & 0xfc1f0000) == 0x94010000) 1855 1.1 christos { /* stu rX,NUM(r1) || stwu rX,NUM(r1) */ 1856 1.1 christos fdata->frameless = 0; 1857 1.1 christos fdata->offset = SIGNED_SHORT (op); 1858 1.1 christos offset = fdata->offset; 1859 1.1 christos continue; 1860 1.8 christos } 1861 1.8 christos else if ((op & 0xfc1f07fa) == 0x7c01016a) 1862 1.1 christos { /* stwux rX,r1,rY || stdux rX,r1,rY */ 1863 1.1 christos /* No way to figure out what r1 is going to be. */ 1864 1.1 christos fdata->frameless = 0; 1865 1.1 christos offset = fdata->offset; 1866 1.1 christos continue; 1867 1.1 christos } 1868 1.1 christos else if ((op & 0xfc1f0003) == 0xf8010001) 1869 1.1 christos { /* stdu rX,NUM(r1) */ 1870 1.1 christos fdata->frameless = 0; 1871 1.1 christos fdata->offset = SIGNED_SHORT (op & ~3UL); 1872 1.1 christos offset = fdata->offset; 1873 1.1 christos continue; 1874 1.1 christos } 1875 1.10 christos else if ((op & 0xffff0000) == 0x38210000) 1876 1.10 christos { /* addi r1,r1,SIMM */ 1877 1.10 christos fdata->frameless = 0; 1878 1.10 christos fdata->offset += SIGNED_SHORT (op); 1879 1.10 christos offset = fdata->offset; 1880 1.10 christos continue; 1881 1.1 christos } 1882 1.1 christos /* Load up minimal toc pointer. Do not treat an epilogue restore 1883 1.1 christos of r31 as a minimal TOC load. */ 1884 1.1 christos else if (((op >> 22) == 0x20f || /* l r31,... or l r30,... */ 1885 1.1 christos (op >> 22) == 0x3af) /* ld r31,... or ld r30,... */ 1886 1.1 christos && !framep 1887 1.1 christos && !minimal_toc_loaded) 1888 1.1 christos { 1889 1.1 christos minimal_toc_loaded = 1; 1890 1.1 christos continue; 1891 1.1 christos 1892 1.10 christos /* move parameters from argument registers to local variable 1893 1.10 christos registers */ 1894 1.1 christos } 1895 1.10 christos else if ((op & 0xfc0007fe) == 0x7c000378 && /* mr(.) Rx,Ry */ 1896 1.10 christos (((op >> 21) & 31) >= 3) && /* R3 >= Ry >= R10 */ 1897 1.10 christos (((op >> 21) & 31) <= 10) && 1898 1.1 christos ((long) ((op >> 16) & 31) 1899 1.1 christos >= fdata->saved_gpr)) /* Rx: local var reg */ 1900 1.1 christos { 1901 1.1 christos continue; 1902 1.1 christos 1903 1.1 christos /* store parameters in stack */ 1904 1.1 christos } 1905 1.1 christos /* Move parameters from argument registers to temporary register. */ 1906 1.10 christos else if (store_param_on_stack_p (op, framep, &r0_contains_arg)) 1907 1.1 christos { 1908 1.1 christos continue; 1909 1.1 christos 1910 1.1 christos /* Set up frame pointer */ 1911 1.1 christos } 1912 1.1 christos else if (op == 0x603d0000) /* oril r29, r1, 0x0 */ 1913 1.1 christos { 1914 1.1 christos fdata->frameless = 0; 1915 1.1 christos framep = 1; 1916 1.8 christos fdata->alloca_reg = (tdep->ppc_gp0_regnum + 29); 1917 1.1 christos alloca_reg_offset = offset; 1918 1.1 christos continue; 1919 1.1 christos 1920 1.1 christos /* Another way to set up the frame pointer. */ 1921 1.1 christos } 1922 1.1 christos else if (op == 0x603f0000 /* oril r31, r1, 0x0 */ 1923 1.1 christos || op == 0x7c3f0b78) 1924 1.1 christos { /* mr r31, r1 */ 1925 1.1 christos fdata->frameless = 0; 1926 1.1 christos framep = 1; 1927 1.8 christos fdata->alloca_reg = (tdep->ppc_gp0_regnum + 31); 1928 1.1 christos alloca_reg_offset = offset; 1929 1.1 christos continue; 1930 1.1 christos 1931 1.1 christos /* Another way to set up the frame pointer. */ 1932 1.1 christos } 1933 1.1 christos else if ((op & 0xfc1fffff) == 0x38010000) 1934 1.1 christos { /* addi rX, r1, 0x0 */ 1935 1.1 christos fdata->frameless = 0; 1936 1.1 christos framep = 1; 1937 1.1 christos fdata->alloca_reg = (tdep->ppc_gp0_regnum 1938 1.8 christos + ((op & ~0x38010000) >> 21)); 1939 1.1 christos alloca_reg_offset = offset; 1940 1.1 christos continue; 1941 1.1 christos } 1942 1.1 christos /* AltiVec related instructions. */ 1943 1.1 christos /* Store the vrsave register (spr 256) in another register for 1944 1.1 christos later manipulation, or load a register into the vrsave 1945 1.1 christos register. 2 instructions are used: mfvrsave and 1946 1.1 christos mtvrsave. They are shorthand notation for mfspr Rn, SPR256 1947 1.1 christos and mtspr SPR256, Rn. */ 1948 1.1 christos /* mfspr Rn SPR256 == 011111 nnnnn 0000001000 01010100110 1949 1.1 christos mtspr SPR256 Rn == 011111 nnnnn 0000001000 01110100110 */ 1950 1.1 christos else if ((op & 0xfc1fffff) == 0x7c0042a6) /* mfvrsave Rn */ 1951 1.10 christos { 1952 1.1 christos vrsave_reg = GET_SRC_REG (op); 1953 1.1 christos continue; 1954 1.1 christos } 1955 1.10 christos else if ((op & 0xfc1fffff) == 0x7c0043a6) /* mtvrsave Rn */ 1956 1.10 christos { 1957 1.10 christos continue; 1958 1.1 christos } 1959 1.10 christos /* Store the register where vrsave was saved to onto the stack: 1960 1.1 christos rS is the register where vrsave was stored in a previous 1961 1.1 christos instruction. */ 1962 1.1 christos /* 100100 sssss 00001 dddddddd dddddddd */ 1963 1.10 christos else if ((op & 0xfc1f0000) == 0x90010000) /* stw rS, d(r1) */ 1964 1.10 christos { 1965 1.1 christos if (vrsave_reg == GET_SRC_REG (op)) 1966 1.1 christos { 1967 1.1 christos fdata->vrsave_offset = SIGNED_SHORT (op) + offset; 1968 1.1 christos vrsave_reg = -1; 1969 1.10 christos } 1970 1.10 christos continue; 1971 1.1 christos } 1972 1.10 christos /* Compute the new value of vrsave, by modifying the register 1973 1.1 christos where vrsave was saved to. */ 1974 1.1 christos else if (((op & 0xfc000000) == 0x64000000) /* oris Ra, Rs, UIMM */ 1975 1.1 christos || ((op & 0xfc000000) == 0x60000000))/* ori Ra, Rs, UIMM */ 1976 1.1 christos { 1977 1.1 christos continue; 1978 1.1 christos } 1979 1.1 christos /* li r0, SIMM (short for addi r0, 0, SIMM). This is the first 1980 1.1 christos in a pair of insns to save the vector registers on the 1981 1.1 christos stack. */ 1982 1.1 christos /* 001110 00000 00000 iiii iiii iiii iiii */ 1983 1.1 christos /* 001110 01110 00000 iiii iiii iiii iiii */ 1984 1.10 christos else if ((op & 0xffff0000) == 0x38000000 /* li r0, SIMM */ 1985 1.1 christos || (op & 0xffff0000) == 0x39c00000) /* li r14, SIMM */ 1986 1.10 christos { 1987 1.10 christos if ((op & 0xffff0000) == 0x38000000) 1988 1.1 christos r0_contains_arg = 0; 1989 1.1 christos li_found_pc = pc; 1990 1.1 christos vr_saved_offset = SIGNED_SHORT (op); 1991 1.10 christos 1992 1.10 christos /* This insn by itself is not part of the prologue, unless 1993 1.10 christos if part of the pair of insns mentioned above. So do not 1994 1.10 christos record this insn as part of the prologue yet. */ 1995 1.1 christos prev_insn_was_prologue_insn = 0; 1996 1.1 christos } 1997 1.1 christos /* Store vector register S at (r31+r0) aligned to 16 bytes. */ 1998 1.1 christos /* 011111 sssss 11111 00000 00111001110 */ 1999 1.10 christos else if ((op & 0xfc1fffff) == 0x7c1f01ce) /* stvx Vs, R31, R0 */ 2000 1.1 christos { 2001 1.1 christos if (pc == (li_found_pc + 4)) 2002 1.1 christos { 2003 1.1 christos vr_reg = GET_SRC_REG (op); 2004 1.1 christos /* If this is the first vector reg to be saved, or if 2005 1.1 christos it has a lower number than others previously seen, 2006 1.1 christos reupdate the frame info. */ 2007 1.1 christos if (fdata->saved_vr == -1 || fdata->saved_vr > vr_reg) 2008 1.1 christos { 2009 1.1 christos fdata->saved_vr = vr_reg; 2010 1.1 christos fdata->vr_offset = vr_saved_offset + offset; 2011 1.1 christos } 2012 1.1 christos vr_saved_offset = -1; 2013 1.1 christos vr_reg = -1; 2014 1.1 christos li_found_pc = 0; 2015 1.1 christos } 2016 1.1 christos } 2017 1.1 christos /* End AltiVec related instructions. */ 2018 1.1 christos 2019 1.1 christos /* Start BookE related instructions. */ 2020 1.10 christos /* Store gen register S at (r31+uimm). 2021 1.1 christos Any register less than r13 is volatile, so we don't care. */ 2022 1.1 christos /* 000100 sssss 11111 iiiii 01100100001 */ 2023 1.1 christos else if (arch_info->mach == bfd_mach_ppc_e500 2024 1.1 christos && (op & 0xfc1f07ff) == 0x101f0321) /* evstdd Rs,uimm(R31) */ 2025 1.10 christos { 2026 1.1 christos if ((op & 0x03e00000) >= 0x01a00000) /* Rs >= r13 */ 2027 1.10 christos { 2028 1.1 christos unsigned int imm; 2029 1.10 christos ev_reg = GET_SRC_REG (op); 2030 1.1 christos imm = (op >> 11) & 0x1f; 2031 1.1 christos ev_offset = imm * 8; 2032 1.1 christos /* If this is the first vector reg to be saved, or if 2033 1.1 christos it has a lower number than others previously seen, 2034 1.1 christos reupdate the frame info. */ 2035 1.1 christos if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 2036 1.1 christos { 2037 1.1 christos fdata->saved_ev = ev_reg; 2038 1.1 christos fdata->ev_offset = ev_offset + offset; 2039 1.1 christos } 2040 1.10 christos } 2041 1.10 christos continue; 2042 1.1 christos } 2043 1.1 christos /* Store gen register rS at (r1+rB). */ 2044 1.1 christos /* 000100 sssss 00001 bbbbb 01100100000 */ 2045 1.1 christos else if (arch_info->mach == bfd_mach_ppc_e500 2046 1.1 christos && (op & 0xffe007ff) == 0x13e00320) /* evstddx RS,R1,Rb */ 2047 1.10 christos { 2048 1.10 christos if (pc == (li_found_pc + 4)) 2049 1.10 christos { 2050 1.1 christos ev_reg = GET_SRC_REG (op); 2051 1.10 christos /* If this is the first vector reg to be saved, or if 2052 1.10 christos it has a lower number than others previously seen, 2053 1.10 christos reupdate the frame info. */ 2054 1.1 christos /* We know the contents of rB from the previous instruction. */ 2055 1.1 christos if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 2056 1.10 christos { 2057 1.10 christos fdata->saved_ev = ev_reg; 2058 1.1 christos fdata->ev_offset = vr_saved_offset + offset; 2059 1.1 christos } 2060 1.1 christos vr_saved_offset = -1; 2061 1.1 christos ev_reg = -1; 2062 1.10 christos li_found_pc = 0; 2063 1.10 christos } 2064 1.10 christos continue; 2065 1.1 christos } 2066 1.1 christos /* Store gen register r31 at (rA+uimm). */ 2067 1.1 christos /* 000100 11111 aaaaa iiiii 01100100001 */ 2068 1.1 christos else if (arch_info->mach == bfd_mach_ppc_e500 2069 1.10 christos && (op & 0xffe007ff) == 0x13e00321) /* evstdd R31,Ra,UIMM */ 2070 1.10 christos { 2071 1.10 christos /* Wwe know that the source register is 31 already, but 2072 1.1 christos it can't hurt to compute it. */ 2073 1.10 christos ev_reg = GET_SRC_REG (op); 2074 1.1 christos ev_offset = ((op >> 11) & 0x1f) * 8; 2075 1.1 christos /* If this is the first vector reg to be saved, or if 2076 1.1 christos it has a lower number than others previously seen, 2077 1.1 christos reupdate the frame info. */ 2078 1.1 christos if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 2079 1.1 christos { 2080 1.1 christos fdata->saved_ev = ev_reg; 2081 1.1 christos fdata->ev_offset = ev_offset + offset; 2082 1.1 christos } 2083 1.1 christos 2084 1.10 christos continue; 2085 1.1 christos } 2086 1.10 christos /* Store gen register S at (r31+r0). 2087 1.1 christos Store param on stack when offset from SP bigger than 4 bytes. */ 2088 1.1 christos /* 000100 sssss 11111 00000 01100100000 */ 2089 1.1 christos else if (arch_info->mach == bfd_mach_ppc_e500 2090 1.1 christos && (op & 0xfc1fffff) == 0x101f0320) /* evstddx Rs,R31,R0 */ 2091 1.10 christos { 2092 1.10 christos if (pc == (li_found_pc + 4)) 2093 1.10 christos { 2094 1.1 christos if ((op & 0x03e00000) >= 0x01a00000) 2095 1.1 christos { 2096 1.1 christos ev_reg = GET_SRC_REG (op); 2097 1.1 christos /* If this is the first vector reg to be saved, or if 2098 1.1 christos it has a lower number than others previously seen, 2099 1.10 christos reupdate the frame info. */ 2100 1.10 christos /* We know the contents of r0 from the previous 2101 1.1 christos instruction. */ 2102 1.1 christos if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 2103 1.1 christos { 2104 1.1 christos fdata->saved_ev = ev_reg; 2105 1.1 christos fdata->ev_offset = vr_saved_offset + offset; 2106 1.1 christos } 2107 1.1 christos ev_reg = -1; 2108 1.1 christos } 2109 1.1 christos vr_saved_offset = -1; 2110 1.1 christos li_found_pc = 0; 2111 1.10 christos continue; 2112 1.1 christos } 2113 1.1 christos } 2114 1.1 christos /* End BookE related instructions. */ 2115 1.1 christos 2116 1.1 christos else 2117 1.1 christos { 2118 1.1 christos /* Not a recognized prologue instruction. 2119 1.1 christos Handle optimizer code motions into the prologue by continuing 2120 1.1 christos the search if we have no valid frame yet or if the return 2121 1.1 christos address is not yet saved in the frame. Also skip instructions 2122 1.1 christos if some of the GPRs expected to be saved are not yet saved. */ 2123 1.8 christos if (fdata->frameless == 0 && fdata->nosavedpc == 0 2124 1.8 christos && fdata->saved_gpr != -1) 2125 1.8 christos { 2126 1.8 christos unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1); 2127 1.8 christos 2128 1.8 christos if ((fdata->gpr_mask & all_mask) == all_mask) 2129 1.8 christos break; 2130 1.1 christos } 2131 1.1 christos 2132 1.1 christos if (op == 0x4e800020 /* blr */ 2133 1.1 christos || op == 0x4e800420) /* bctr */ 2134 1.1 christos /* Do not scan past epilogue in frameless functions or 2135 1.1 christos trampolines. */ 2136 1.1 christos break; 2137 1.1 christos if ((op & 0xf4000000) == 0x40000000) /* bxx */ 2138 1.1 christos /* Never skip branches. */ 2139 1.1 christos break; 2140 1.10 christos 2141 1.10 christos /* Test based on opcode and mask values of 2142 1.10 christos powerpc_opcodes[svc..svcla] in opcodes/ppc-opc.c. */ 2143 1.10 christos if ((op & 0xffff0000) == 0x44000000) 2144 1.10 christos /* Never skip system calls. */ 2145 1.10 christos break; 2146 1.1 christos 2147 1.1 christos if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns) 2148 1.1 christos /* Do not scan too many insns, scanning insns is expensive with 2149 1.1 christos remote targets. */ 2150 1.1 christos break; 2151 1.1 christos 2152 1.1 christos /* Continue scanning. */ 2153 1.1 christos prev_insn_was_prologue_insn = 0; 2154 1.1 christos continue; 2155 1.1 christos } 2156 1.1 christos } 2157 1.1 christos 2158 1.1 christos #if 0 2159 1.1 christos /* I have problems with skipping over __main() that I need to address 2160 1.1 christos * sometime. Previously, I used to use misc_function_vector which 2161 1.1 christos * didn't work as well as I wanted to be. -MGO */ 2162 1.1 christos 2163 1.1 christos /* If the first thing after skipping a prolog is a branch to a function, 2164 1.1 christos this might be a call to an initializer in main(), introduced by gcc2. 2165 1.1 christos We'd like to skip over it as well. Fortunately, xlc does some extra 2166 1.1 christos work before calling a function right after a prologue, thus we can 2167 1.1 christos single out such gcc2 behaviour. */ 2168 1.1 christos 2169 1.1 christos 2170 1.1 christos if ((op & 0xfc000001) == 0x48000001) 2171 1.1 christos { /* bl foo, an initializer function? */ 2172 1.1 christos op = read_memory_integer (pc + 4, 4, byte_order); 2173 1.1 christos 2174 1.1 christos if (op == 0x4def7b82) 2175 1.1 christos { /* cror 0xf, 0xf, 0xf (nop) */ 2176 1.1 christos 2177 1.1 christos /* Check and see if we are in main. If so, skip over this 2178 1.1 christos initializer function as well. */ 2179 1.1 christos 2180 1.1 christos tmp = find_pc_misc_function (pc); 2181 1.1 christos if (tmp >= 0 2182 1.1 christos && strcmp (misc_function_vector[tmp].name, main_name ()) == 0) 2183 1.1 christos return pc + 8; 2184 1.1 christos } 2185 1.1 christos } 2186 1.1 christos #endif /* 0 */ 2187 1.1 christos 2188 1.1 christos if (pc == lim_pc && lr_reg >= 0) 2189 1.1 christos fdata->lr_register = lr_reg; 2190 1.1 christos 2191 1.1 christos fdata->offset = -fdata->offset; 2192 1.1 christos return last_prologue_pc; 2193 1.1 christos } 2194 1.1 christos 2195 1.1 christos static CORE_ADDR 2196 1.1 christos rs6000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 2197 1.1 christos { 2198 1.1 christos struct rs6000_framedata frame; 2199 1.1 christos CORE_ADDR limit_pc, func_addr, func_end_addr = 0; 2200 1.1 christos 2201 1.1 christos /* See if we can determine the end of the prologue via the symbol table. 2202 1.1 christos If so, then return either PC, or the PC after the prologue, whichever 2203 1.1 christos is greater. */ 2204 1.1 christos if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr)) 2205 1.1 christos { 2206 1.1 christos CORE_ADDR post_prologue_pc 2207 1.1 christos = skip_prologue_using_sal (gdbarch, func_addr); 2208 1.7 christos if (post_prologue_pc != 0) 2209 1.1 christos return std::max (pc, post_prologue_pc); 2210 1.1 christos } 2211 1.1 christos 2212 1.1 christos /* Can't determine prologue from the symbol table, need to examine 2213 1.1 christos instructions. */ 2214 1.1 christos 2215 1.1 christos /* Find an upper limit on the function prologue using the debug 2216 1.1 christos information. If the debug information could not be used to provide 2217 1.1 christos that bound, then use an arbitrary large number as the upper bound. */ 2218 1.1 christos limit_pc = skip_prologue_using_sal (gdbarch, pc); 2219 1.1 christos if (limit_pc == 0) 2220 1.1 christos limit_pc = pc + 100; /* Magic. */ 2221 1.1 christos 2222 1.1 christos /* Do not allow limit_pc to be past the function end, if we know 2223 1.1 christos where that end is... */ 2224 1.1 christos if (func_end_addr && limit_pc > func_end_addr) 2225 1.1 christos limit_pc = func_end_addr; 2226 1.1 christos 2227 1.1 christos pc = skip_prologue (gdbarch, pc, limit_pc, &frame); 2228 1.1 christos return pc; 2229 1.1 christos } 2230 1.1 christos 2231 1.1 christos /* When compiling for EABI, some versions of GCC emit a call to __eabi 2232 1.1 christos in the prologue of main(). 2233 1.1 christos 2234 1.1 christos The function below examines the code pointed at by PC and checks to 2235 1.1 christos see if it corresponds to a call to __eabi. If so, it returns the 2236 1.1 christos address of the instruction following that call. Otherwise, it simply 2237 1.1 christos returns PC. */ 2238 1.1 christos 2239 1.1 christos static CORE_ADDR 2240 1.1 christos rs6000_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 2241 1.1 christos { 2242 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 2243 1.1 christos gdb_byte buf[4]; 2244 1.1 christos unsigned long op; 2245 1.1 christos 2246 1.1 christos if (target_read_memory (pc, buf, 4)) 2247 1.1 christos return pc; 2248 1.1 christos op = extract_unsigned_integer (buf, 4, byte_order); 2249 1.1 christos 2250 1.1 christos if ((op & BL_MASK) == BL_INSTRUCTION) 2251 1.1 christos { 2252 1.1 christos CORE_ADDR displ = op & BL_DISPLACEMENT_MASK; 2253 1.1 christos CORE_ADDR call_dest = pc + 4 + displ; 2254 1.1 christos struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest); 2255 1.1 christos 2256 1.10 christos /* We check for ___eabi (three leading underscores) in addition 2257 1.1 christos to __eabi in case the GCC option "-fleading-underscore" was 2258 1.1 christos used to compile the program. */ 2259 1.10 christos if (s.minsym != NULL 2260 1.9 christos && s.minsym->linkage_name () != NULL 2261 1.9 christos && (strcmp (s.minsym->linkage_name (), "__eabi") == 0 2262 1.1 christos || strcmp (s.minsym->linkage_name (), "___eabi") == 0)) 2263 1.1 christos pc += 4; 2264 1.1 christos } 2265 1.1 christos return pc; 2266 1.1 christos } 2267 1.1 christos 2268 1.1 christos /* All the ABI's require 16 byte alignment. */ 2269 1.1 christos static CORE_ADDR 2270 1.1 christos rs6000_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) 2271 1.1 christos { 2272 1.1 christos return (addr & -16); 2273 1.1 christos } 2274 1.1 christos 2275 1.1 christos /* Return whether handle_inferior_event() should proceed through code 2276 1.1 christos starting at PC in function NAME when stepping. 2277 1.1 christos 2278 1.1 christos The AIX -bbigtoc linker option generates functions @FIX0, @FIX1, etc. to 2279 1.1 christos handle memory references that are too distant to fit in instructions 2280 1.1 christos generated by the compiler. For example, if 'foo' in the following 2281 1.1 christos instruction: 2282 1.1 christos 2283 1.1 christos lwz r9,foo(r2) 2284 1.1 christos 2285 1.1 christos is greater than 32767, the linker might replace the lwz with a branch to 2286 1.1 christos somewhere in @FIX1 that does the load in 2 instructions and then branches 2287 1.1 christos back to where execution should continue. 2288 1.1 christos 2289 1.1 christos GDB should silently step over @FIX code, just like AIX dbx does. 2290 1.1 christos Unfortunately, the linker uses the "b" instruction for the 2291 1.1 christos branches, meaning that the link register doesn't get set. 2292 1.1 christos Therefore, GDB's usual step_over_function () mechanism won't work. 2293 1.1 christos 2294 1.1 christos Instead, use the gdbarch_skip_trampoline_code and 2295 1.1 christos gdbarch_skip_trampoline_code hooks in handle_inferior_event() to skip past 2296 1.1 christos @FIX code. */ 2297 1.1 christos 2298 1.1 christos static int 2299 1.1 christos rs6000_in_solib_return_trampoline (struct gdbarch *gdbarch, 2300 1.1 christos CORE_ADDR pc, const char *name) 2301 1.5 christos { 2302 1.1 christos return name && startswith (name, "@FIX"); 2303 1.1 christos } 2304 1.1 christos 2305 1.1 christos /* Skip code that the user doesn't want to see when stepping: 2306 1.1 christos 2307 1.1 christos 1. Indirect function calls use a piece of trampoline code to do context 2308 1.1 christos switching, i.e. to set the new TOC table. Skip such code if we are on 2309 1.1 christos its first instruction (as when we have single-stepped to here). 2310 1.1 christos 2311 1.1 christos 2. Skip shared library trampoline code (which is different from 2312 1.1 christos indirect function call trampolines). 2313 1.1 christos 2314 1.1 christos 3. Skip bigtoc fixup code. 2315 1.1 christos 2316 1.1 christos Result is desired PC to step until, or NULL if we are not in 2317 1.1 christos code that should be skipped. */ 2318 1.1 christos 2319 1.11 christos static CORE_ADDR 2320 1.1 christos rs6000_skip_trampoline_code (const frame_info_ptr &frame, CORE_ADDR pc) 2321 1.1 christos { 2322 1.10 christos struct gdbarch *gdbarch = get_frame_arch (frame); 2323 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2324 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 2325 1.1 christos unsigned int ii, op; 2326 1.1 christos int rel; 2327 1.1 christos CORE_ADDR solib_target_pc; 2328 1.1 christos struct bound_minimal_symbol msymbol; 2329 1.1 christos 2330 1.1 christos static unsigned trampoline_code[] = 2331 1.1 christos { 2332 1.1 christos 0x800b0000, /* l r0,0x0(r11) */ 2333 1.1 christos 0x90410014, /* st r2,0x14(r1) */ 2334 1.1 christos 0x7c0903a6, /* mtctr r0 */ 2335 1.1 christos 0x804b0004, /* l r2,0x4(r11) */ 2336 1.1 christos 0x816b0008, /* l r11,0x8(r11) */ 2337 1.1 christos 0x4e800420, /* bctr */ 2338 1.1 christos 0x4e800020, /* br */ 2339 1.1 christos 0 2340 1.1 christos }; 2341 1.1 christos 2342 1.1 christos /* Check for bigtoc fixup code. */ 2343 1.1 christos msymbol = lookup_minimal_symbol_by_pc (pc); 2344 1.1 christos if (msymbol.minsym 2345 1.9 christos && rs6000_in_solib_return_trampoline (gdbarch, pc, 2346 1.1 christos msymbol.minsym->linkage_name ())) 2347 1.1 christos { 2348 1.1 christos /* Double-check that the third instruction from PC is relative "b". */ 2349 1.1 christos op = read_memory_integer (pc + 8, 4, byte_order); 2350 1.1 christos if ((op & 0xfc000003) == 0x48000000) 2351 1.1 christos { 2352 1.1 christos /* Extract bits 6-29 as a signed 24-bit relative word address and 2353 1.1 christos add it to the containing PC. */ 2354 1.1 christos rel = ((int)(op << 6) >> 6); 2355 1.1 christos return pc + 8 + rel; 2356 1.1 christos } 2357 1.1 christos } 2358 1.1 christos 2359 1.1 christos /* If pc is in a shared library trampoline, return its target. */ 2360 1.1 christos solib_target_pc = find_solib_trampoline_target (frame, pc); 2361 1.1 christos if (solib_target_pc) 2362 1.1 christos return solib_target_pc; 2363 1.1 christos 2364 1.1 christos for (ii = 0; trampoline_code[ii]; ++ii) 2365 1.1 christos { 2366 1.1 christos op = read_memory_integer (pc + (ii * 4), 4, byte_order); 2367 1.1 christos if (op != trampoline_code[ii]) 2368 1.1 christos return 0; 2369 1.1 christos } 2370 1.1 christos ii = get_frame_register_unsigned (frame, 11); /* r11 holds destination 2371 1.1 christos addr. */ 2372 1.1 christos pc = read_memory_unsigned_integer (ii, tdep->wordsize, byte_order); 2373 1.1 christos return pc; 2374 1.1 christos } 2375 1.1 christos 2376 1.1 christos /* ISA-specific vector types. */ 2377 1.1 christos 2378 1.1 christos static struct type * 2379 1.1 christos rs6000_builtin_type_vec64 (struct gdbarch *gdbarch) 2380 1.10 christos { 2381 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2382 1.1 christos 2383 1.1 christos if (!tdep->ppc_builtin_type_vec64) 2384 1.1 christos { 2385 1.1 christos const struct builtin_type *bt = builtin_type (gdbarch); 2386 1.1 christos 2387 1.1 christos /* The type we're building is this: */ 2388 1.1 christos #if 0 2389 1.1 christos union __gdb_builtin_type_vec64 2390 1.1 christos { 2391 1.1 christos int64_t uint64; 2392 1.1 christos float v2_float[2]; 2393 1.1 christos int32_t v2_int32[2]; 2394 1.1 christos int16_t v4_int16[4]; 2395 1.1 christos int8_t v8_int8[8]; 2396 1.1 christos }; 2397 1.1 christos #endif 2398 1.1 christos 2399 1.1 christos struct type *t; 2400 1.1 christos 2401 1.1 christos t = arch_composite_type (gdbarch, 2402 1.1 christos "__ppc_builtin_type_vec64", TYPE_CODE_UNION); 2403 1.1 christos append_composite_type_field (t, "uint64", bt->builtin_int64); 2404 1.1 christos append_composite_type_field (t, "v2_float", 2405 1.1 christos init_vector_type (bt->builtin_float, 2)); 2406 1.1 christos append_composite_type_field (t, "v2_int32", 2407 1.1 christos init_vector_type (bt->builtin_int32, 2)); 2408 1.1 christos append_composite_type_field (t, "v4_int16", 2409 1.1 christos init_vector_type (bt->builtin_int16, 4)); 2410 1.1 christos append_composite_type_field (t, "v8_int8", 2411 1.1 christos init_vector_type (bt->builtin_int8, 8)); 2412 1.10 christos 2413 1.9 christos t->set_is_vector (true); 2414 1.1 christos t->set_name ("ppc_builtin_type_vec64"); 2415 1.1 christos tdep->ppc_builtin_type_vec64 = t; 2416 1.1 christos } 2417 1.1 christos 2418 1.1 christos return tdep->ppc_builtin_type_vec64; 2419 1.1 christos } 2420 1.1 christos 2421 1.1 christos /* Vector 128 type. */ 2422 1.1 christos 2423 1.1 christos static struct type * 2424 1.1 christos rs6000_builtin_type_vec128 (struct gdbarch *gdbarch) 2425 1.10 christos { 2426 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2427 1.1 christos 2428 1.1 christos if (!tdep->ppc_builtin_type_vec128) 2429 1.1 christos { 2430 1.1 christos const struct builtin_type *bt = builtin_type (gdbarch); 2431 1.1 christos 2432 1.1 christos /* The type we're building is this 2433 1.1 christos 2434 1.10 christos type = union __ppc_builtin_type_vec128 { 2435 1.1 christos float128_t float128; 2436 1.1 christos uint128_t uint128; 2437 1.1 christos double v2_double[2]; 2438 1.1 christos float v4_float[4]; 2439 1.1 christos int32_t v4_int32[4]; 2440 1.1 christos int16_t v8_int16[8]; 2441 1.1 christos int8_t v16_int8[16]; 2442 1.1 christos } 2443 1.1 christos */ 2444 1.10 christos 2445 1.11 christos /* PPC specific type for IEEE 128-bit float field */ 2446 1.10 christos type_allocator alloc (gdbarch); 2447 1.11 christos struct type *t_float128 2448 1.10 christos = init_float_type (alloc, 128, "float128_t", floatformats_ieee_quad); 2449 1.1 christos 2450 1.1 christos struct type *t; 2451 1.1 christos 2452 1.1 christos t = arch_composite_type (gdbarch, 2453 1.10 christos "__ppc_builtin_type_vec128", TYPE_CODE_UNION); 2454 1.1 christos append_composite_type_field (t, "float128", t_float128); 2455 1.1 christos append_composite_type_field (t, "uint128", bt->builtin_uint128); 2456 1.1 christos append_composite_type_field (t, "v2_double", 2457 1.1 christos init_vector_type (bt->builtin_double, 2)); 2458 1.1 christos append_composite_type_field (t, "v4_float", 2459 1.1 christos init_vector_type (bt->builtin_float, 4)); 2460 1.1 christos append_composite_type_field (t, "v4_int32", 2461 1.1 christos init_vector_type (bt->builtin_int32, 4)); 2462 1.1 christos append_composite_type_field (t, "v8_int16", 2463 1.1 christos init_vector_type (bt->builtin_int16, 8)); 2464 1.1 christos append_composite_type_field (t, "v16_int8", 2465 1.1 christos init_vector_type (bt->builtin_int8, 16)); 2466 1.10 christos 2467 1.9 christos t->set_is_vector (true); 2468 1.1 christos t->set_name ("ppc_builtin_type_vec128"); 2469 1.1 christos tdep->ppc_builtin_type_vec128 = t; 2470 1.1 christos } 2471 1.1 christos 2472 1.1 christos return tdep->ppc_builtin_type_vec128; 2473 1.1 christos } 2474 1.1 christos 2475 1.1 christos /* Return the name of register number REGNO, or the empty string if it 2476 1.1 christos is an anonymous register. */ 2477 1.1 christos 2478 1.1 christos static const char * 2479 1.1 christos rs6000_register_name (struct gdbarch *gdbarch, int regno) 2480 1.10 christos { 2481 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2482 1.1 christos 2483 1.1 christos /* The upper half "registers" have names in the XML description, 2484 1.1 christos but we present only the low GPRs and the full 64-bit registers 2485 1.1 christos to the user. */ 2486 1.1 christos if (tdep->ppc_ev0_upper_regnum >= 0 2487 1.1 christos && tdep->ppc_ev0_upper_regnum <= regno 2488 1.1 christos && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs) 2489 1.1 christos return ""; 2490 1.1 christos 2491 1.1 christos /* Hide the upper halves of the vs0~vs31 registers. */ 2492 1.1 christos if (tdep->ppc_vsr0_regnum >= 0 2493 1.1 christos && tdep->ppc_vsr0_upper_regnum <= regno 2494 1.1 christos && regno < tdep->ppc_vsr0_upper_regnum + ppc_num_gprs) 2495 1.1 christos return ""; 2496 1.8 christos 2497 1.8 christos /* Hide the upper halves of the cvs0~cvs31 registers. */ 2498 1.11 christos if (PPC_CVSR0_UPPER_REGNUM <= regno 2499 1.11 christos && regno < (to_underlying (PPC_CVSR0_UPPER_REGNUM) 2500 1.8 christos + to_underlying (ppc_num_gprs))) 2501 1.8 christos return ""; 2502 1.1 christos 2503 1.1 christos /* Check if the SPE pseudo registers are available. */ 2504 1.1 christos if (IS_SPE_PSEUDOREG (tdep, regno)) 2505 1.1 christos { 2506 1.1 christos static const char *const spe_regnames[] = { 2507 1.1 christos "ev0", "ev1", "ev2", "ev3", "ev4", "ev5", "ev6", "ev7", 2508 1.1 christos "ev8", "ev9", "ev10", "ev11", "ev12", "ev13", "ev14", "ev15", 2509 1.1 christos "ev16", "ev17", "ev18", "ev19", "ev20", "ev21", "ev22", "ev23", 2510 1.1 christos "ev24", "ev25", "ev26", "ev27", "ev28", "ev29", "ev30", "ev31", 2511 1.1 christos }; 2512 1.1 christos return spe_regnames[regno - tdep->ppc_ev0_regnum]; 2513 1.1 christos } 2514 1.1 christos 2515 1.1 christos /* Check if the decimal128 pseudo-registers are available. */ 2516 1.1 christos if (IS_DFP_PSEUDOREG (tdep, regno)) 2517 1.1 christos { 2518 1.1 christos static const char *const dfp128_regnames[] = { 2519 1.1 christos "dl0", "dl1", "dl2", "dl3", 2520 1.1 christos "dl4", "dl5", "dl6", "dl7", 2521 1.1 christos "dl8", "dl9", "dl10", "dl11", 2522 1.1 christos "dl12", "dl13", "dl14", "dl15" 2523 1.1 christos }; 2524 1.1 christos return dfp128_regnames[regno - tdep->ppc_dl0_regnum]; 2525 1.1 christos } 2526 1.8 christos 2527 1.8 christos /* Check if this is a vX alias for a raw vrX vector register. */ 2528 1.8 christos if (IS_V_ALIAS_PSEUDOREG (tdep, regno)) 2529 1.8 christos { 2530 1.8 christos static const char *const vector_alias_regnames[] = { 2531 1.8 christos "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", 2532 1.8 christos "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", 2533 1.8 christos "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", 2534 1.8 christos "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31" 2535 1.8 christos }; 2536 1.8 christos return vector_alias_regnames[regno - tdep->ppc_v0_alias_regnum]; 2537 1.8 christos } 2538 1.1 christos 2539 1.1 christos /* Check if this is a VSX pseudo-register. */ 2540 1.1 christos if (IS_VSX_PSEUDOREG (tdep, regno)) 2541 1.1 christos { 2542 1.1 christos static const char *const vsx_regnames[] = { 2543 1.1 christos "vs0", "vs1", "vs2", "vs3", "vs4", "vs5", "vs6", "vs7", 2544 1.1 christos "vs8", "vs9", "vs10", "vs11", "vs12", "vs13", "vs14", 2545 1.1 christos "vs15", "vs16", "vs17", "vs18", "vs19", "vs20", "vs21", 2546 1.1 christos "vs22", "vs23", "vs24", "vs25", "vs26", "vs27", "vs28", 2547 1.1 christos "vs29", "vs30", "vs31", "vs32", "vs33", "vs34", "vs35", 2548 1.1 christos "vs36", "vs37", "vs38", "vs39", "vs40", "vs41", "vs42", 2549 1.1 christos "vs43", "vs44", "vs45", "vs46", "vs47", "vs48", "vs49", 2550 1.1 christos "vs50", "vs51", "vs52", "vs53", "vs54", "vs55", "vs56", 2551 1.1 christos "vs57", "vs58", "vs59", "vs60", "vs61", "vs62", "vs63" 2552 1.1 christos }; 2553 1.1 christos return vsx_regnames[regno - tdep->ppc_vsr0_regnum]; 2554 1.1 christos } 2555 1.1 christos 2556 1.1 christos /* Check if the this is a Extended FP pseudo-register. */ 2557 1.1 christos if (IS_EFP_PSEUDOREG (tdep, regno)) 2558 1.1 christos { 2559 1.1 christos static const char *const efpr_regnames[] = { 2560 1.1 christos "f32", "f33", "f34", "f35", "f36", "f37", "f38", 2561 1.1 christos "f39", "f40", "f41", "f42", "f43", "f44", "f45", 2562 1.1 christos "f46", "f47", "f48", "f49", "f50", "f51", 2563 1.1 christos "f52", "f53", "f54", "f55", "f56", "f57", 2564 1.1 christos "f58", "f59", "f60", "f61", "f62", "f63" 2565 1.1 christos }; 2566 1.1 christos return efpr_regnames[regno - tdep->ppc_efpr0_regnum]; 2567 1.1 christos } 2568 1.8 christos 2569 1.8 christos /* Check if this is a Checkpointed DFP pseudo-register. */ 2570 1.8 christos if (IS_CDFP_PSEUDOREG (tdep, regno)) 2571 1.8 christos { 2572 1.8 christos static const char *const cdfp128_regnames[] = { 2573 1.8 christos "cdl0", "cdl1", "cdl2", "cdl3", 2574 1.8 christos "cdl4", "cdl5", "cdl6", "cdl7", 2575 1.8 christos "cdl8", "cdl9", "cdl10", "cdl11", 2576 1.8 christos "cdl12", "cdl13", "cdl14", "cdl15" 2577 1.8 christos }; 2578 1.8 christos return cdfp128_regnames[regno - tdep->ppc_cdl0_regnum]; 2579 1.8 christos } 2580 1.8 christos 2581 1.8 christos /* Check if this is a Checkpointed VSX pseudo-register. */ 2582 1.8 christos if (IS_CVSX_PSEUDOREG (tdep, regno)) 2583 1.8 christos { 2584 1.8 christos static const char *const cvsx_regnames[] = { 2585 1.8 christos "cvs0", "cvs1", "cvs2", "cvs3", "cvs4", "cvs5", "cvs6", "cvs7", 2586 1.8 christos "cvs8", "cvs9", "cvs10", "cvs11", "cvs12", "cvs13", "cvs14", 2587 1.8 christos "cvs15", "cvs16", "cvs17", "cvs18", "cvs19", "cvs20", "cvs21", 2588 1.8 christos "cvs22", "cvs23", "cvs24", "cvs25", "cvs26", "cvs27", "cvs28", 2589 1.8 christos "cvs29", "cvs30", "cvs31", "cvs32", "cvs33", "cvs34", "cvs35", 2590 1.8 christos "cvs36", "cvs37", "cvs38", "cvs39", "cvs40", "cvs41", "cvs42", 2591 1.8 christos "cvs43", "cvs44", "cvs45", "cvs46", "cvs47", "cvs48", "cvs49", 2592 1.8 christos "cvs50", "cvs51", "cvs52", "cvs53", "cvs54", "cvs55", "cvs56", 2593 1.8 christos "cvs57", "cvs58", "cvs59", "cvs60", "cvs61", "cvs62", "cvs63" 2594 1.8 christos }; 2595 1.8 christos return cvsx_regnames[regno - tdep->ppc_cvsr0_regnum]; 2596 1.8 christos } 2597 1.8 christos 2598 1.8 christos /* Check if the this is a Checkpointed Extended FP pseudo-register. */ 2599 1.8 christos if (IS_CEFP_PSEUDOREG (tdep, regno)) 2600 1.8 christos { 2601 1.8 christos static const char *const cefpr_regnames[] = { 2602 1.8 christos "cf32", "cf33", "cf34", "cf35", "cf36", "cf37", "cf38", 2603 1.8 christos "cf39", "cf40", "cf41", "cf42", "cf43", "cf44", "cf45", 2604 1.8 christos "cf46", "cf47", "cf48", "cf49", "cf50", "cf51", 2605 1.8 christos "cf52", "cf53", "cf54", "cf55", "cf56", "cf57", 2606 1.8 christos "cf58", "cf59", "cf60", "cf61", "cf62", "cf63" 2607 1.8 christos }; 2608 1.8 christos return cefpr_regnames[regno - tdep->ppc_cefpr0_regnum]; 2609 1.8 christos } 2610 1.1 christos 2611 1.1 christos return tdesc_register_name (gdbarch, regno); 2612 1.1 christos } 2613 1.1 christos 2614 1.1 christos /* Return the GDB type object for the "standard" data type of data in 2615 1.1 christos register N. */ 2616 1.1 christos 2617 1.1 christos static struct type * 2618 1.1 christos rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum) 2619 1.10 christos { 2620 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2621 1.1 christos 2622 1.1 christos /* These are the e500 pseudo-registers. */ 2623 1.1 christos if (IS_SPE_PSEUDOREG (tdep, regnum)) 2624 1.8 christos return rs6000_builtin_type_vec64 (gdbarch); 2625 1.8 christos else if (IS_DFP_PSEUDOREG (tdep, regnum) 2626 1.1 christos || IS_CDFP_PSEUDOREG (tdep, regnum)) 2627 1.1 christos /* PPC decimal128 pseudo-registers. */ 2628 1.8 christos return builtin_type (gdbarch)->builtin_declong; 2629 1.8 christos else if (IS_V_ALIAS_PSEUDOREG (tdep, regnum)) 2630 1.8 christos return gdbarch_register_type (gdbarch, 2631 1.8 christos tdep->ppc_vr0_regnum 2632 1.8 christos + (regnum 2633 1.8 christos - tdep->ppc_v0_alias_regnum)); 2634 1.8 christos else if (IS_VSX_PSEUDOREG (tdep, regnum) 2635 1.1 christos || IS_CVSX_PSEUDOREG (tdep, regnum)) 2636 1.1 christos /* POWER7 VSX pseudo-registers. */ 2637 1.8 christos return rs6000_builtin_type_vec128 (gdbarch); 2638 1.8 christos else if (IS_EFP_PSEUDOREG (tdep, regnum) 2639 1.1 christos || IS_CEFP_PSEUDOREG (tdep, regnum)) 2640 1.1 christos /* POWER7 Extended FP pseudo-registers. */ 2641 1.8 christos return builtin_type (gdbarch)->builtin_double; 2642 1.10 christos else 2643 1.8 christos internal_error (_("rs6000_pseudo_register_type: " 2644 1.8 christos "called on unexpected register '%s' (%d)"), 2645 1.1 christos gdbarch_register_name (gdbarch, regnum), regnum); 2646 1.1 christos } 2647 1.8 christos 2648 1.8 christos /* Check if REGNUM is a member of REGGROUP. We only need to handle 2649 1.8 christos the vX aliases for the vector registers by always returning false 2650 1.8 christos to avoid duplicated information in "info register vector/all", 2651 1.8 christos since the raw vrX registers will already show in these cases. For 2652 1.8 christos other pseudo-registers we use the default membership function. */ 2653 1.1 christos 2654 1.1 christos static int 2655 1.10 christos rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum, 2656 1.1 christos const struct reggroup *group) 2657 1.10 christos { 2658 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2659 1.8 christos 2660 1.8 christos if (IS_V_ALIAS_PSEUDOREG (tdep, regnum)) 2661 1.1 christos return 0; 2662 1.8 christos else 2663 1.1 christos return default_register_reggroup_p (gdbarch, regnum, group); 2664 1.1 christos } 2665 1.1 christos 2666 1.1 christos /* The register format for RS/6000 floating point registers is always 2667 1.1 christos double, we need a conversion if the memory format is float. */ 2668 1.1 christos 2669 1.1 christos static int 2670 1.1 christos rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum, 2671 1.1 christos struct type *type) 2672 1.10 christos { 2673 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2674 1.1 christos 2675 1.1 christos return (tdep->ppc_fp0_regnum >= 0 2676 1.1 christos && regnum >= tdep->ppc_fp0_regnum 2677 1.9 christos && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs 2678 1.10 christos && type->code () == TYPE_CODE_FLT 2679 1.11 christos && (type->length () 2680 1.11 christos == builtin_type (gdbarch)->builtin_float->length ())); 2681 1.11 christos } 2682 1.11 christos 2683 1.11 christos static int 2684 1.11 christos ieee_128_float_regnum_adjust (struct gdbarch *gdbarch, struct type *type, 2685 1.11 christos int regnum) 2686 1.11 christos { 2687 1.11 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2688 1.11 christos 2689 1.11 christos /* If we have the an IEEE 128-bit floating point value, need to map the 2690 1.11 christos register number to the corresponding VSR. */ 2691 1.11 christos if (tdep->ppc_vsr0_regnum != -1 2692 1.11 christos && regnum >= tdep->ppc_fp0_regnum 2693 1.11 christos && regnum < (tdep->ppc_fp0_regnum + ppc_num_fprs) 2694 1.11 christos && (gdbarch_long_double_format (gdbarch) == floatformats_ieee_quad) 2695 1.11 christos && (type->length() == 16)) 2696 1.11 christos regnum = regnum - tdep->ppc_fp0_regnum + tdep->ppc_vsr0_regnum; 2697 1.11 christos 2698 1.1 christos return regnum; 2699 1.1 christos } 2700 1.1 christos 2701 1.11 christos static int 2702 1.10 christos rs6000_register_to_value (const frame_info_ptr &frame, 2703 1.10 christos int regnum, 2704 1.10 christos struct type *type, 2705 1.1 christos gdb_byte *to, 2706 1.1 christos int *optimizedp, int *unavailablep) 2707 1.1 christos { 2708 1.8 christos struct gdbarch *gdbarch = get_frame_arch (frame); 2709 1.1 christos gdb_byte from[PPC_MAX_REGISTER_SIZE]; 2710 1.9 christos 2711 1.1 christos gdb_assert (type->code () == TYPE_CODE_FLT); 2712 1.11 christos 2713 1.11 christos /* We have an IEEE 128-bit float -- need to change regnum mapping from 2714 1.11 christos fpr to vsr. */ 2715 1.11 christos regnum = ieee_128_float_regnum_adjust (gdbarch, type, regnum); 2716 1.11 christos 2717 1.11 christos auto from_view 2718 1.11 christos = gdb::make_array_view (from, register_size (gdbarch, regnum)); 2719 1.11 christos frame_info_ptr next_frame = get_next_frame_sentinel_okay (frame); 2720 1.11 christos if (!get_frame_register_bytes (next_frame, regnum, 0, from_view, optimizedp, 2721 1.1 christos unavailablep)) 2722 1.1 christos return 0; 2723 1.8 christos 2724 1.8 christos target_float_convert (from, builtin_type (gdbarch)->builtin_double, 2725 1.1 christos to, type); 2726 1.1 christos *optimizedp = *unavailablep = 0; 2727 1.1 christos return 1; 2728 1.1 christos } 2729 1.1 christos 2730 1.11 christos static void 2731 1.10 christos rs6000_value_to_register (const frame_info_ptr &frame, 2732 1.10 christos int regnum, 2733 1.10 christos struct type *type, 2734 1.1 christos const gdb_byte *from) 2735 1.1 christos { 2736 1.8 christos struct gdbarch *gdbarch = get_frame_arch (frame); 2737 1.1 christos gdb_byte to[PPC_MAX_REGISTER_SIZE]; 2738 1.9 christos 2739 1.1 christos gdb_assert (type->code () == TYPE_CODE_FLT); 2740 1.11 christos 2741 1.11 christos /* We have an IEEE 128-bit float -- need to change regnum mapping from 2742 1.11 christos fpr to vsr. */ 2743 1.11 christos regnum = ieee_128_float_regnum_adjust (gdbarch, type, regnum); 2744 1.11 christos 2745 1.11 christos struct type *to_type = builtin_type (gdbarch)->builtin_double; 2746 1.11 christos target_float_convert (from, type, to, to_type); 2747 1.11 christos auto to_view = gdb::make_array_view (to, to_type->length ()); 2748 1.11 christos put_frame_register (get_next_frame_sentinel_okay (frame), regnum, to_view); 2749 1.11 christos } 2750 1.11 christos 2751 1.11 christos static value * 2752 1.11 christos rs6000_value_from_register (gdbarch *gdbarch, type *type, int regnum, 2753 1.11 christos const frame_info_ptr &this_frame) 2754 1.11 christos { 2755 1.11 christos /* We have an IEEE 128-bit float -- need to change regnum mapping from 2756 1.11 christos fpr to vsr. */ 2757 1.11 christos regnum = ieee_128_float_regnum_adjust (gdbarch, type, regnum); 2758 1.11 christos 2759 1.11 christos value *value 2760 1.11 christos = value::allocate_register (get_next_frame_sentinel_okay (this_frame), 2761 1.11 christos regnum, type); 2762 1.11 christos 2763 1.11 christos /* Any structure stored in more than one register will always be 2764 1.11 christos an integral number of registers. Otherwise, you need to do 2765 1.11 christos some fiddling with the last register copied here for little 2766 1.11 christos endian machines. */ 2767 1.11 christos if (type_byte_order (type) == BFD_ENDIAN_BIG 2768 1.11 christos && type->length () < register_size (gdbarch, regnum)) 2769 1.11 christos /* Big-endian, and we want less than full size. */ 2770 1.11 christos value->set_offset (register_size (gdbarch, regnum) - type->length ()); 2771 1.11 christos else 2772 1.11 christos value->set_offset (0); 2773 1.11 christos 2774 1.1 christos return value; 2775 1.1 christos } 2776 1.1 christos 2777 1.1 christos /* The type of a function that moves the value of REG between CACHE 2778 1.1 christos or BUF --- in either direction. */ 2779 1.1 christos typedef enum register_status (*move_ev_register_func) (struct regcache *, 2780 1.1 christos int, void *); 2781 1.1 christos 2782 1.1 christos /* Move SPE vector register values between a 64-bit buffer and the two 2783 1.1 christos 32-bit raw register halves in a regcache. This function handles 2784 1.1 christos both splitting a 64-bit value into two 32-bit halves, and joining 2785 1.1 christos two halves into a whole 64-bit value, depending on the function 2786 1.1 christos passed as the MOVE argument. 2787 1.1 christos 2788 1.1 christos EV_REG must be the number of an SPE evN vector register --- a 2789 1.1 christos pseudoregister. REGCACHE must be a regcache, and BUFFER must be a 2790 1.1 christos 64-bit buffer. 2791 1.1 christos 2792 1.1 christos Call MOVE once for each 32-bit half of that register, passing 2793 1.1 christos REGCACHE, the number of the raw register corresponding to that 2794 1.1 christos half, and the address of the appropriate half of BUFFER. 2795 1.1 christos 2796 1.1 christos For example, passing 'regcache_raw_read' as the MOVE function will 2797 1.1 christos fill BUFFER with the full 64-bit contents of EV_REG. Or, passing 2798 1.1 christos 'regcache_raw_supply' will supply the contents of BUFFER to the 2799 1.1 christos appropriate pair of raw registers in REGCACHE. 2800 1.1 christos 2801 1.1 christos You may need to cast away some 'const' qualifiers when passing 2802 1.1 christos MOVE, since this function can't tell at compile-time which of 2803 1.1 christos REGCACHE or BUFFER is acting as the source of the data. If C had 2804 1.1 christos co-variant type qualifiers, ... */ 2805 1.1 christos 2806 1.1 christos static enum register_status 2807 1.1 christos e500_move_ev_register (move_ev_register_func move, 2808 1.1 christos struct regcache *regcache, int ev_reg, void *buffer) 2809 1.8 christos { 2810 1.10 christos struct gdbarch *arch = regcache->arch (); 2811 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch); 2812 1.6 christos int reg_index; 2813 1.1 christos gdb_byte *byte_buffer = (gdb_byte *) buffer; 2814 1.1 christos enum register_status status; 2815 1.1 christos 2816 1.1 christos gdb_assert (IS_SPE_PSEUDOREG (tdep, ev_reg)); 2817 1.1 christos 2818 1.1 christos reg_index = ev_reg - tdep->ppc_ev0_regnum; 2819 1.1 christos 2820 1.1 christos if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG) 2821 1.1 christos { 2822 1.1 christos status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index, 2823 1.1 christos byte_buffer); 2824 1.1 christos if (status == REG_VALID) 2825 1.1 christos status = move (regcache, tdep->ppc_gp0_regnum + reg_index, 2826 1.1 christos byte_buffer + 4); 2827 1.1 christos } 2828 1.1 christos else 2829 1.1 christos { 2830 1.1 christos status = move (regcache, tdep->ppc_gp0_regnum + reg_index, byte_buffer); 2831 1.1 christos if (status == REG_VALID) 2832 1.1 christos status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index, 2833 1.1 christos byte_buffer + 4); 2834 1.1 christos } 2835 1.1 christos 2836 1.1 christos return status; 2837 1.1 christos } 2838 1.1 christos 2839 1.1 christos static enum register_status 2840 1.1 christos do_regcache_raw_write (struct regcache *regcache, int regnum, void *buffer) 2841 1.8 christos { 2842 1.1 christos regcache->raw_write (regnum, (const gdb_byte *) buffer); 2843 1.1 christos 2844 1.1 christos return REG_VALID; 2845 1.1 christos } 2846 1.1 christos 2847 1.8 christos static enum register_status 2848 1.8 christos e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache, 2849 1.1 christos int ev_reg, gdb_byte *buffer) 2850 1.8 christos { 2851 1.10 christos struct gdbarch *arch = regcache->arch (); 2852 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2853 1.8 christos int reg_index; 2854 1.8 christos enum register_status status; 2855 1.8 christos 2856 1.8 christos gdb_assert (IS_SPE_PSEUDOREG (tdep, ev_reg)); 2857 1.8 christos 2858 1.8 christos reg_index = ev_reg - tdep->ppc_ev0_regnum; 2859 1.8 christos 2860 1.8 christos if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG) 2861 1.8 christos { 2862 1.8 christos status = regcache->raw_read (tdep->ppc_ev0_upper_regnum + reg_index, 2863 1.8 christos buffer); 2864 1.8 christos if (status == REG_VALID) 2865 1.8 christos status = regcache->raw_read (tdep->ppc_gp0_regnum + reg_index, 2866 1.8 christos buffer + 4); 2867 1.8 christos } 2868 1.8 christos else 2869 1.8 christos { 2870 1.8 christos status = regcache->raw_read (tdep->ppc_gp0_regnum + reg_index, buffer); 2871 1.8 christos if (status == REG_VALID) 2872 1.8 christos status = regcache->raw_read (tdep->ppc_ev0_upper_regnum + reg_index, 2873 1.8 christos buffer + 4); 2874 1.8 christos } 2875 1.8 christos 2876 1.8 christos return status; 2877 1.1 christos 2878 1.1 christos } 2879 1.1 christos 2880 1.1 christos static void 2881 1.1 christos e500_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 2882 1.1 christos int reg_nr, const gdb_byte *buffer) 2883 1.1 christos { 2884 1.1 christos e500_move_ev_register (do_regcache_raw_write, regcache, 2885 1.1 christos reg_nr, (void *) buffer); 2886 1.1 christos } 2887 1.1 christos 2888 1.1 christos /* Read method for DFP pseudo-registers. */ 2889 1.8 christos static enum register_status 2890 1.1 christos dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache, 2891 1.1 christos int reg_nr, gdb_byte *buffer) 2892 1.10 christos { 2893 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2894 1.1 christos int reg_index, fp0; 2895 1.1 christos enum register_status status; 2896 1.8 christos 2897 1.8 christos if (IS_DFP_PSEUDOREG (tdep, reg_nr)) 2898 1.8 christos { 2899 1.8 christos reg_index = reg_nr - tdep->ppc_dl0_regnum; 2900 1.8 christos fp0 = PPC_F0_REGNUM; 2901 1.8 christos } 2902 1.8 christos else 2903 1.8 christos { 2904 1.8 christos gdb_assert (IS_CDFP_PSEUDOREG (tdep, reg_nr)); 2905 1.8 christos 2906 1.8 christos reg_index = reg_nr - tdep->ppc_cdl0_regnum; 2907 1.8 christos fp0 = PPC_CF0_REGNUM; 2908 1.8 christos } 2909 1.1 christos 2910 1.1 christos if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 2911 1.1 christos { 2912 1.8 christos /* Read two FP registers to form a whole dl register. */ 2913 1.1 christos status = regcache->raw_read (fp0 + 2 * reg_index, buffer); 2914 1.8 christos if (status == REG_VALID) 2915 1.8 christos status = regcache->raw_read (fp0 + 2 * reg_index + 1, 2916 1.1 christos buffer + 8); 2917 1.1 christos } 2918 1.1 christos else 2919 1.8 christos { 2920 1.1 christos status = regcache->raw_read (fp0 + 2 * reg_index + 1, buffer); 2921 1.8 christos if (status == REG_VALID) 2922 1.1 christos status = regcache->raw_read (fp0 + 2 * reg_index, buffer + 8); 2923 1.1 christos } 2924 1.1 christos 2925 1.1 christos return status; 2926 1.1 christos } 2927 1.1 christos 2928 1.1 christos /* Write method for DFP pseudo-registers. */ 2929 1.1 christos static void 2930 1.1 christos dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 2931 1.1 christos int reg_nr, const gdb_byte *buffer) 2932 1.10 christos { 2933 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2934 1.8 christos int reg_index, fp0; 2935 1.8 christos 2936 1.8 christos if (IS_DFP_PSEUDOREG (tdep, reg_nr)) 2937 1.8 christos { 2938 1.8 christos reg_index = reg_nr - tdep->ppc_dl0_regnum; 2939 1.8 christos fp0 = PPC_F0_REGNUM; 2940 1.8 christos } 2941 1.8 christos else 2942 1.8 christos { 2943 1.8 christos gdb_assert (IS_CDFP_PSEUDOREG (tdep, reg_nr)); 2944 1.8 christos 2945 1.8 christos reg_index = reg_nr - tdep->ppc_cdl0_regnum; 2946 1.8 christos fp0 = PPC_CF0_REGNUM; 2947 1.1 christos } 2948 1.1 christos 2949 1.1 christos if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 2950 1.1 christos { 2951 1.8 christos /* Write each half of the dl register into a separate 2952 1.8 christos FP register. */ 2953 1.8 christos regcache->raw_write (fp0 + 2 * reg_index, buffer); 2954 1.1 christos regcache->raw_write (fp0 + 2 * reg_index + 1, buffer + 8); 2955 1.1 christos } 2956 1.1 christos else 2957 1.8 christos { 2958 1.8 christos regcache->raw_write (fp0 + 2 * reg_index + 1, buffer); 2959 1.1 christos regcache->raw_write (fp0 + 2 * reg_index, buffer + 8); 2960 1.1 christos } 2961 1.1 christos } 2962 1.8 christos 2963 1.8 christos /* Read method for the vX aliases for the raw vrX registers. */ 2964 1.8 christos 2965 1.8 christos static enum register_status 2966 1.8 christos v_alias_pseudo_register_read (struct gdbarch *gdbarch, 2967 1.8 christos readable_regcache *regcache, int reg_nr, 2968 1.8 christos gdb_byte *buffer) 2969 1.10 christos { 2970 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2971 1.8 christos gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr)); 2972 1.8 christos 2973 1.8 christos return regcache->raw_read (tdep->ppc_vr0_regnum 2974 1.8 christos + (reg_nr - tdep->ppc_v0_alias_regnum), 2975 1.8 christos buffer); 2976 1.8 christos } 2977 1.8 christos 2978 1.8 christos /* Write method for the vX aliases for the raw vrX registers. */ 2979 1.8 christos 2980 1.8 christos static void 2981 1.8 christos v_alias_pseudo_register_write (struct gdbarch *gdbarch, 2982 1.8 christos struct regcache *regcache, 2983 1.8 christos int reg_nr, const gdb_byte *buffer) 2984 1.10 christos { 2985 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2986 1.8 christos gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr)); 2987 1.8 christos 2988 1.8 christos regcache->raw_write (tdep->ppc_vr0_regnum 2989 1.8 christos + (reg_nr - tdep->ppc_v0_alias_regnum), buffer); 2990 1.8 christos } 2991 1.1 christos 2992 1.1 christos /* Read method for POWER7 VSX pseudo-registers. */ 2993 1.8 christos static enum register_status 2994 1.1 christos vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache, 2995 1.1 christos int reg_nr, gdb_byte *buffer) 2996 1.10 christos { 2997 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 2998 1.1 christos int reg_index, vr0, fp0, vsr0_upper; 2999 1.1 christos enum register_status status; 3000 1.8 christos 3001 1.8 christos if (IS_VSX_PSEUDOREG (tdep, reg_nr)) 3002 1.8 christos { 3003 1.8 christos reg_index = reg_nr - tdep->ppc_vsr0_regnum; 3004 1.8 christos vr0 = PPC_VR0_REGNUM; 3005 1.8 christos fp0 = PPC_F0_REGNUM; 3006 1.8 christos vsr0_upper = PPC_VSR0_UPPER_REGNUM; 3007 1.8 christos } 3008 1.8 christos else 3009 1.8 christos { 3010 1.8 christos gdb_assert (IS_CVSX_PSEUDOREG (tdep, reg_nr)); 3011 1.8 christos 3012 1.8 christos reg_index = reg_nr - tdep->ppc_cvsr0_regnum; 3013 1.8 christos vr0 = PPC_CVR0_REGNUM; 3014 1.8 christos fp0 = PPC_CF0_REGNUM; 3015 1.8 christos vsr0_upper = PPC_CVSR0_UPPER_REGNUM; 3016 1.8 christos } 3017 1.1 christos 3018 1.1 christos /* Read the portion that overlaps the VMX registers. */ 3019 1.8 christos if (reg_index > 31) 3020 1.1 christos status = regcache->raw_read (vr0 + reg_index - 32, buffer); 3021 1.1 christos else 3022 1.1 christos /* Read the portion that overlaps the FPR registers. */ 3023 1.1 christos if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 3024 1.8 christos { 3025 1.1 christos status = regcache->raw_read (fp0 + reg_index, buffer); 3026 1.8 christos if (status == REG_VALID) 3027 1.8 christos status = regcache->raw_read (vsr0_upper + reg_index, 3028 1.1 christos buffer + 8); 3029 1.1 christos } 3030 1.1 christos else 3031 1.8 christos { 3032 1.1 christos status = regcache->raw_read (fp0 + reg_index, buffer + 8); 3033 1.8 christos if (status == REG_VALID) 3034 1.1 christos status = regcache->raw_read (vsr0_upper + reg_index, buffer); 3035 1.1 christos } 3036 1.1 christos 3037 1.1 christos return status; 3038 1.1 christos } 3039 1.1 christos 3040 1.1 christos /* Write method for POWER7 VSX pseudo-registers. */ 3041 1.1 christos static void 3042 1.1 christos vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 3043 1.1 christos int reg_nr, const gdb_byte *buffer) 3044 1.10 christos { 3045 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3046 1.8 christos int reg_index, vr0, fp0, vsr0_upper; 3047 1.8 christos 3048 1.8 christos if (IS_VSX_PSEUDOREG (tdep, reg_nr)) 3049 1.8 christos { 3050 1.8 christos reg_index = reg_nr - tdep->ppc_vsr0_regnum; 3051 1.8 christos vr0 = PPC_VR0_REGNUM; 3052 1.8 christos fp0 = PPC_F0_REGNUM; 3053 1.8 christos vsr0_upper = PPC_VSR0_UPPER_REGNUM; 3054 1.8 christos } 3055 1.8 christos else 3056 1.8 christos { 3057 1.8 christos gdb_assert (IS_CVSX_PSEUDOREG (tdep, reg_nr)); 3058 1.8 christos 3059 1.8 christos reg_index = reg_nr - tdep->ppc_cvsr0_regnum; 3060 1.8 christos vr0 = PPC_CVR0_REGNUM; 3061 1.8 christos fp0 = PPC_CF0_REGNUM; 3062 1.8 christos vsr0_upper = PPC_CVSR0_UPPER_REGNUM; 3063 1.1 christos } 3064 1.1 christos 3065 1.1 christos /* Write the portion that overlaps the VMX registers. */ 3066 1.8 christos if (reg_index > 31) 3067 1.1 christos regcache->raw_write (vr0 + reg_index - 32, buffer); 3068 1.1 christos else 3069 1.1 christos /* Write the portion that overlaps the FPR registers. */ 3070 1.1 christos if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 3071 1.8 christos { 3072 1.8 christos regcache->raw_write (fp0 + reg_index, buffer); 3073 1.1 christos regcache->raw_write (vsr0_upper + reg_index, buffer + 8); 3074 1.1 christos } 3075 1.1 christos else 3076 1.8 christos { 3077 1.8 christos regcache->raw_write (fp0 + reg_index, buffer + 8); 3078 1.1 christos regcache->raw_write (vsr0_upper + reg_index, buffer); 3079 1.1 christos } 3080 1.1 christos } 3081 1.1 christos 3082 1.1 christos /* Read method for POWER7 Extended FP pseudo-registers. */ 3083 1.8 christos static enum register_status 3084 1.1 christos efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache, 3085 1.1 christos int reg_nr, gdb_byte *buffer) 3086 1.10 christos { 3087 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3088 1.8 christos int reg_index, vr0; 3089 1.8 christos 3090 1.8 christos if (IS_EFP_PSEUDOREG (tdep, reg_nr)) 3091 1.8 christos { 3092 1.8 christos reg_index = reg_nr - tdep->ppc_efpr0_regnum; 3093 1.8 christos vr0 = PPC_VR0_REGNUM; 3094 1.8 christos } 3095 1.8 christos else 3096 1.8 christos { 3097 1.8 christos gdb_assert (IS_CEFP_PSEUDOREG (tdep, reg_nr)); 3098 1.8 christos 3099 1.8 christos reg_index = reg_nr - tdep->ppc_cefpr0_regnum; 3100 1.8 christos vr0 = PPC_CVR0_REGNUM; 3101 1.8 christos } 3102 1.3 christos 3103 1.1 christos int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8; 3104 1.1 christos 3105 1.8 christos /* Read the portion that overlaps the VMX register. */ 3106 1.8 christos return regcache->raw_read_part (vr0 + reg_index, offset, 3107 1.8 christos register_size (gdbarch, reg_nr), 3108 1.1 christos buffer); 3109 1.1 christos } 3110 1.1 christos 3111 1.1 christos /* Write method for POWER7 Extended FP pseudo-registers. */ 3112 1.8 christos static void 3113 1.1 christos efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 3114 1.1 christos int reg_nr, const gdb_byte *buffer) 3115 1.10 christos { 3116 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3117 1.3 christos int reg_index, vr0; 3118 1.1 christos int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8; 3119 1.8 christos 3120 1.8 christos if (IS_EFP_PSEUDOREG (tdep, reg_nr)) 3121 1.8 christos { 3122 1.8 christos reg_index = reg_nr - tdep->ppc_efpr0_regnum; 3123 1.8 christos vr0 = PPC_VR0_REGNUM; 3124 1.8 christos } 3125 1.8 christos else 3126 1.8 christos { 3127 1.8 christos gdb_assert (IS_CEFP_PSEUDOREG (tdep, reg_nr)); 3128 1.8 christos 3129 1.8 christos reg_index = reg_nr - tdep->ppc_cefpr0_regnum; 3130 1.8 christos vr0 = PPC_CVR0_REGNUM; 3131 1.8 christos 3132 1.8 christos /* The call to raw_write_part fails silently if the initial read 3133 1.8 christos of the read-update-write sequence returns an invalid status, 3134 1.8 christos so we check this manually and throw an error if needed. */ 3135 1.8 christos regcache->raw_update (vr0 + reg_index); 3136 1.8 christos if (regcache->get_register_status (vr0 + reg_index) != REG_VALID) 3137 1.8 christos error (_("Cannot write to the checkpointed EFP register, " 3138 1.8 christos "the corresponding vector register is unavailable.")); 3139 1.8 christos } 3140 1.1 christos 3141 1.8 christos /* Write the portion that overlaps the VMX register. */ 3142 1.8 christos regcache->raw_write_part (vr0 + reg_index, offset, 3143 1.1 christos register_size (gdbarch, reg_nr), buffer); 3144 1.1 christos } 3145 1.1 christos 3146 1.1 christos static enum register_status 3147 1.8 christos rs6000_pseudo_register_read (struct gdbarch *gdbarch, 3148 1.1 christos readable_regcache *regcache, 3149 1.1 christos int reg_nr, gdb_byte *buffer) 3150 1.8 christos { 3151 1.10 christos struct gdbarch *regcache_arch = regcache->arch (); 3152 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3153 1.1 christos 3154 1.1 christos gdb_assert (regcache_arch == gdbarch); 3155 1.1 christos 3156 1.1 christos if (IS_SPE_PSEUDOREG (tdep, reg_nr)) 3157 1.8 christos return e500_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 3158 1.8 christos else if (IS_DFP_PSEUDOREG (tdep, reg_nr) 3159 1.1 christos || IS_CDFP_PSEUDOREG (tdep, reg_nr)) 3160 1.8 christos return dfp_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 3161 1.8 christos else if (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr)) 3162 1.8 christos return v_alias_pseudo_register_read (gdbarch, regcache, reg_nr, 3163 1.8 christos buffer); 3164 1.8 christos else if (IS_VSX_PSEUDOREG (tdep, reg_nr) 3165 1.1 christos || IS_CVSX_PSEUDOREG (tdep, reg_nr)) 3166 1.8 christos return vsx_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 3167 1.8 christos else if (IS_EFP_PSEUDOREG (tdep, reg_nr) 3168 1.8 christos || IS_CEFP_PSEUDOREG (tdep, reg_nr)) 3169 1.1 christos return efp_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 3170 1.10 christos else 3171 1.1 christos internal_error (_("rs6000_pseudo_register_read: " 3172 1.1 christos "called on unexpected register '%s' (%d)"), 3173 1.1 christos gdbarch_register_name (gdbarch, reg_nr), reg_nr); 3174 1.1 christos } 3175 1.1 christos 3176 1.1 christos static void 3177 1.1 christos rs6000_pseudo_register_write (struct gdbarch *gdbarch, 3178 1.1 christos struct regcache *regcache, 3179 1.1 christos int reg_nr, const gdb_byte *buffer) 3180 1.8 christos { 3181 1.10 christos struct gdbarch *regcache_arch = regcache->arch (); 3182 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3183 1.1 christos 3184 1.1 christos gdb_assert (regcache_arch == gdbarch); 3185 1.8 christos 3186 1.8 christos if (IS_SPE_PSEUDOREG (tdep, reg_nr)) 3187 1.8 christos e500_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 3188 1.8 christos else if (IS_DFP_PSEUDOREG (tdep, reg_nr) 3189 1.8 christos || IS_CDFP_PSEUDOREG (tdep, reg_nr)) 3190 1.8 christos dfp_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 3191 1.8 christos else if (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr)) 3192 1.8 christos v_alias_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 3193 1.8 christos else if (IS_VSX_PSEUDOREG (tdep, reg_nr) 3194 1.8 christos || IS_CVSX_PSEUDOREG (tdep, reg_nr)) 3195 1.8 christos vsx_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 3196 1.8 christos else if (IS_EFP_PSEUDOREG (tdep, reg_nr) 3197 1.8 christos || IS_CEFP_PSEUDOREG (tdep, reg_nr)) 3198 1.8 christos efp_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 3199 1.10 christos else 3200 1.8 christos internal_error (_("rs6000_pseudo_register_write: " 3201 1.8 christos "called on unexpected register '%s' (%d)"), 3202 1.8 christos gdbarch_register_name (gdbarch, reg_nr), reg_nr); 3203 1.8 christos } 3204 1.8 christos 3205 1.8 christos /* Set the register mask in AX with the registers that form the DFP or 3206 1.8 christos checkpointed DFP pseudo-register REG_NR. */ 3207 1.8 christos 3208 1.8 christos static void 3209 1.8 christos dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch, 3210 1.8 christos struct agent_expr *ax, int reg_nr) 3211 1.10 christos { 3212 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3213 1.8 christos int reg_index, fp0; 3214 1.8 christos 3215 1.8 christos if (IS_DFP_PSEUDOREG (tdep, reg_nr)) 3216 1.8 christos { 3217 1.8 christos reg_index = reg_nr - tdep->ppc_dl0_regnum; 3218 1.8 christos fp0 = PPC_F0_REGNUM; 3219 1.8 christos } 3220 1.8 christos else 3221 1.8 christos { 3222 1.8 christos gdb_assert (IS_CDFP_PSEUDOREG (tdep, reg_nr)); 3223 1.8 christos 3224 1.8 christos reg_index = reg_nr - tdep->ppc_cdl0_regnum; 3225 1.8 christos fp0 = PPC_CF0_REGNUM; 3226 1.8 christos } 3227 1.8 christos 3228 1.8 christos ax_reg_mask (ax, fp0 + 2 * reg_index); 3229 1.8 christos ax_reg_mask (ax, fp0 + 2 * reg_index + 1); 3230 1.8 christos } 3231 1.8 christos 3232 1.8 christos /* Set the register mask in AX with the raw vector register that 3233 1.8 christos corresponds to its REG_NR alias. */ 3234 1.8 christos 3235 1.8 christos static void 3236 1.8 christos v_alias_pseudo_register_collect (struct gdbarch *gdbarch, 3237 1.8 christos struct agent_expr *ax, int reg_nr) 3238 1.10 christos { 3239 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3240 1.8 christos gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr)); 3241 1.8 christos 3242 1.8 christos ax_reg_mask (ax, tdep->ppc_vr0_regnum 3243 1.8 christos + (reg_nr - tdep->ppc_v0_alias_regnum)); 3244 1.8 christos } 3245 1.8 christos 3246 1.8 christos /* Set the register mask in AX with the registers that form the VSX or 3247 1.8 christos checkpointed VSX pseudo-register REG_NR. */ 3248 1.8 christos 3249 1.8 christos static void 3250 1.8 christos vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch, 3251 1.8 christos struct agent_expr *ax, int reg_nr) 3252 1.10 christos { 3253 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3254 1.8 christos int reg_index, vr0, fp0, vsr0_upper; 3255 1.8 christos 3256 1.8 christos if (IS_VSX_PSEUDOREG (tdep, reg_nr)) 3257 1.8 christos { 3258 1.8 christos reg_index = reg_nr - tdep->ppc_vsr0_regnum; 3259 1.8 christos vr0 = PPC_VR0_REGNUM; 3260 1.8 christos fp0 = PPC_F0_REGNUM; 3261 1.8 christos vsr0_upper = PPC_VSR0_UPPER_REGNUM; 3262 1.8 christos } 3263 1.8 christos else 3264 1.8 christos { 3265 1.8 christos gdb_assert (IS_CVSX_PSEUDOREG (tdep, reg_nr)); 3266 1.8 christos 3267 1.8 christos reg_index = reg_nr - tdep->ppc_cvsr0_regnum; 3268 1.8 christos vr0 = PPC_CVR0_REGNUM; 3269 1.8 christos fp0 = PPC_CF0_REGNUM; 3270 1.8 christos vsr0_upper = PPC_CVSR0_UPPER_REGNUM; 3271 1.8 christos } 3272 1.8 christos 3273 1.8 christos if (reg_index > 31) 3274 1.8 christos { 3275 1.8 christos ax_reg_mask (ax, vr0 + reg_index - 32); 3276 1.8 christos } 3277 1.8 christos else 3278 1.8 christos { 3279 1.8 christos ax_reg_mask (ax, fp0 + reg_index); 3280 1.8 christos ax_reg_mask (ax, vsr0_upper + reg_index); 3281 1.8 christos } 3282 1.8 christos } 3283 1.8 christos 3284 1.8 christos /* Set the register mask in AX with the register that corresponds to 3285 1.8 christos the EFP or checkpointed EFP pseudo-register REG_NR. */ 3286 1.8 christos 3287 1.8 christos static void 3288 1.8 christos efp_ax_pseudo_register_collect (struct gdbarch *gdbarch, 3289 1.8 christos struct agent_expr *ax, int reg_nr) 3290 1.10 christos { 3291 1.8 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3292 1.8 christos int reg_index, vr0; 3293 1.8 christos 3294 1.8 christos if (IS_EFP_PSEUDOREG (tdep, reg_nr)) 3295 1.8 christos { 3296 1.8 christos reg_index = reg_nr - tdep->ppc_efpr0_regnum; 3297 1.8 christos vr0 = PPC_VR0_REGNUM; 3298 1.8 christos } 3299 1.8 christos else 3300 1.8 christos { 3301 1.8 christos gdb_assert (IS_CEFP_PSEUDOREG (tdep, reg_nr)); 3302 1.8 christos 3303 1.8 christos reg_index = reg_nr - tdep->ppc_cefpr0_regnum; 3304 1.8 christos vr0 = PPC_CVR0_REGNUM; 3305 1.8 christos } 3306 1.8 christos 3307 1.1 christos ax_reg_mask (ax, vr0 + reg_index); 3308 1.1 christos } 3309 1.6 christos 3310 1.6 christos static int 3311 1.6 christos rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch, 3312 1.6 christos struct agent_expr *ax, int reg_nr) 3313 1.10 christos { 3314 1.6 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3315 1.6 christos if (IS_SPE_PSEUDOREG (tdep, reg_nr)) 3316 1.6 christos { 3317 1.6 christos int reg_index = reg_nr - tdep->ppc_ev0_regnum; 3318 1.6 christos ax_reg_mask (ax, tdep->ppc_gp0_regnum + reg_index); 3319 1.6 christos ax_reg_mask (ax, tdep->ppc_ev0_upper_regnum + reg_index); 3320 1.8 christos } 3321 1.8 christos else if (IS_DFP_PSEUDOREG (tdep, reg_nr) 3322 1.8 christos || IS_CDFP_PSEUDOREG (tdep, reg_nr)) 3323 1.8 christos { 3324 1.8 christos dfp_ax_pseudo_register_collect (gdbarch, ax, reg_nr); 3325 1.8 christos } 3326 1.6 christos else if (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr)) 3327 1.8 christos { 3328 1.6 christos v_alias_pseudo_register_collect (gdbarch, ax, reg_nr); 3329 1.8 christos } 3330 1.8 christos else if (IS_VSX_PSEUDOREG (tdep, reg_nr) 3331 1.6 christos || IS_CVSX_PSEUDOREG (tdep, reg_nr)) 3332 1.8 christos { 3333 1.6 christos vsx_ax_pseudo_register_collect (gdbarch, ax, reg_nr); 3334 1.8 christos } 3335 1.8 christos else if (IS_EFP_PSEUDOREG (tdep, reg_nr) 3336 1.6 christos || IS_CEFP_PSEUDOREG (tdep, reg_nr)) 3337 1.8 christos { 3338 1.6 christos efp_ax_pseudo_register_collect (gdbarch, ax, reg_nr); 3339 1.6 christos } 3340 1.10 christos else 3341 1.6 christos internal_error (_("rs6000_pseudo_register_collect: " 3342 1.6 christos "called on unexpected register '%s' (%d)"), 3343 1.6 christos gdbarch_register_name (gdbarch, reg_nr), reg_nr); 3344 1.6 christos return 0; 3345 1.6 christos } 3346 1.6 christos 3347 1.6 christos 3348 1.6 christos static void 3349 1.6 christos rs6000_gen_return_address (struct gdbarch *gdbarch, 3350 1.6 christos struct agent_expr *ax, struct axs_value *value, 3351 1.6 christos CORE_ADDR scope) 3352 1.10 christos { 3353 1.6 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3354 1.6 christos value->type = register_type (gdbarch, tdep->ppc_lr_regnum); 3355 1.6 christos value->kind = axs_lvalue_register; 3356 1.6 christos value->u.reg = tdep->ppc_lr_regnum; 3357 1.6 christos } 3358 1.6 christos 3359 1.1 christos 3360 1.1 christos /* Convert a DBX STABS register number to a GDB register number. */ 3361 1.1 christos static int 3362 1.1 christos rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num) 3363 1.10 christos { 3364 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3365 1.1 christos 3366 1.1 christos if (0 <= num && num <= 31) 3367 1.1 christos return tdep->ppc_gp0_regnum + num; 3368 1.1 christos else if (32 <= num && num <= 63) 3369 1.1 christos /* FIXME: jimb/2004-05-05: What should we do when the debug info 3370 1.1 christos specifies registers the architecture doesn't have? Our 3371 1.1 christos callers don't check the value we return. */ 3372 1.1 christos return tdep->ppc_fp0_regnum + (num - 32); 3373 1.1 christos else if (77 <= num && num <= 108) 3374 1.1 christos return tdep->ppc_vr0_regnum + (num - 77); 3375 1.1 christos else if (1200 <= num && num < 1200 + 32) 3376 1.1 christos return tdep->ppc_ev0_upper_regnum + (num - 1200); 3377 1.1 christos else 3378 1.1 christos switch (num) 3379 1.1 christos { 3380 1.10 christos case 64: 3381 1.1 christos return tdep->ppc_mq_regnum; 3382 1.10 christos case 65: 3383 1.1 christos return tdep->ppc_lr_regnum; 3384 1.10 christos case 66: 3385 1.1 christos return tdep->ppc_ctr_regnum; 3386 1.10 christos case 76: 3387 1.1 christos return tdep->ppc_xer_regnum; 3388 1.10 christos case 109: 3389 1.1 christos return tdep->ppc_vrsave_regnum; 3390 1.10 christos case 110: 3391 1.1 christos return tdep->ppc_vrsave_regnum - 1; /* vscr */ 3392 1.10 christos case 111: 3393 1.1 christos return tdep->ppc_acc_regnum; 3394 1.10 christos case 112: 3395 1.1 christos return tdep->ppc_spefscr_regnum; 3396 1.10 christos default: 3397 1.1 christos return num; 3398 1.1 christos } 3399 1.1 christos } 3400 1.1 christos 3401 1.1 christos 3402 1.1 christos /* Convert a Dwarf 2 register number to a GDB register number. */ 3403 1.1 christos static int 3404 1.1 christos rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num) 3405 1.10 christos { 3406 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3407 1.1 christos 3408 1.1 christos if (0 <= num && num <= 31) 3409 1.1 christos return tdep->ppc_gp0_regnum + num; 3410 1.1 christos else if (32 <= num && num <= 63) 3411 1.1 christos /* FIXME: jimb/2004-05-05: What should we do when the debug info 3412 1.1 christos specifies registers the architecture doesn't have? Our 3413 1.1 christos callers don't check the value we return. */ 3414 1.1 christos return tdep->ppc_fp0_regnum + (num - 32); 3415 1.1 christos else if (1124 <= num && num < 1124 + 32) 3416 1.1 christos return tdep->ppc_vr0_regnum + (num - 1124); 3417 1.1 christos else if (1200 <= num && num < 1200 + 32) 3418 1.1 christos return tdep->ppc_ev0_upper_regnum + (num - 1200); 3419 1.1 christos else 3420 1.1 christos switch (num) 3421 1.1 christos { 3422 1.1 christos case 64: 3423 1.1 christos return tdep->ppc_cr_regnum; 3424 1.10 christos case 67: 3425 1.1 christos return tdep->ppc_vrsave_regnum - 1; /* vscr */ 3426 1.10 christos case 99: 3427 1.1 christos return tdep->ppc_acc_regnum; 3428 1.10 christos case 100: 3429 1.1 christos return tdep->ppc_mq_regnum; 3430 1.10 christos case 101: 3431 1.1 christos return tdep->ppc_xer_regnum; 3432 1.10 christos case 108: 3433 1.1 christos return tdep->ppc_lr_regnum; 3434 1.10 christos case 109: 3435 1.1 christos return tdep->ppc_ctr_regnum; 3436 1.10 christos case 356: 3437 1.1 christos return tdep->ppc_vrsave_regnum; 3438 1.10 christos case 612: 3439 1.1 christos return tdep->ppc_spefscr_regnum; 3440 1.10 christos } 3441 1.10 christos 3442 1.10 christos /* Unknown DWARF register number. */ 3443 1.1 christos return -1; 3444 1.1 christos } 3445 1.1 christos 3446 1.1 christos /* Translate a .eh_frame register to DWARF register, or adjust a 3447 1.1 christos .debug_frame register. */ 3448 1.1 christos 3449 1.1 christos static int 3450 1.1 christos rs6000_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p) 3451 1.1 christos { 3452 1.1 christos /* GCC releases before 3.4 use GCC internal register numbering in 3453 1.1 christos .debug_frame (and .debug_info, et cetera). The numbering is 3454 1.1 christos different from the standard SysV numbering for everything except 3455 1.1 christos for GPRs and FPRs. We can not detect this problem in most cases 3456 1.1 christos - to get accurate debug info for variables living in lr, ctr, v0, 3457 1.1 christos et cetera, use a newer version of GCC. But we must detect 3458 1.1 christos one important case - lr is in column 65 in .debug_frame output, 3459 1.1 christos instead of 108. 3460 1.1 christos 3461 1.1 christos GCC 3.4, and the "hammer" branch, have a related problem. They 3462 1.1 christos record lr register saves in .debug_frame as 108, but still record 3463 1.1 christos the return column as 65. We fix that up too. 3464 1.1 christos 3465 1.1 christos We can do this because 65 is assigned to fpsr, and GCC never 3466 1.1 christos generates debug info referring to it. To add support for 3467 1.1 christos handwritten debug info that restores fpsr, we would need to add a 3468 1.1 christos producer version check to this. */ 3469 1.1 christos if (!eh_frame_p) 3470 1.1 christos { 3471 1.1 christos if (num == 65) 3472 1.1 christos return 108; 3473 1.1 christos else 3474 1.1 christos return num; 3475 1.1 christos } 3476 1.1 christos 3477 1.1 christos /* .eh_frame is GCC specific. For binary compatibility, it uses GCC 3478 1.1 christos internal register numbering; translate that to the standard DWARF2 3479 1.1 christos register numbering. */ 3480 1.1 christos if (0 <= num && num <= 63) /* r0-r31,fp0-fp31 */ 3481 1.1 christos return num; 3482 1.1 christos else if (68 <= num && num <= 75) /* cr0-cr8 */ 3483 1.1 christos return num - 68 + 86; 3484 1.1 christos else if (77 <= num && num <= 108) /* vr0-vr31 */ 3485 1.1 christos return num - 77 + 1124; 3486 1.1 christos else 3487 1.1 christos switch (num) 3488 1.1 christos { 3489 1.1 christos case 64: /* mq */ 3490 1.1 christos return 100; 3491 1.1 christos case 65: /* lr */ 3492 1.1 christos return 108; 3493 1.1 christos case 66: /* ctr */ 3494 1.1 christos return 109; 3495 1.1 christos case 76: /* xer */ 3496 1.1 christos return 101; 3497 1.1 christos case 109: /* vrsave */ 3498 1.1 christos return 356; 3499 1.1 christos case 110: /* vscr */ 3500 1.1 christos return 67; 3501 1.1 christos case 111: /* spe_acc */ 3502 1.1 christos return 99; 3503 1.1 christos case 112: /* spefscr */ 3504 1.1 christos return 612; 3505 1.1 christos default: 3506 1.1 christos return num; 3507 1.1 christos } 3508 1.1 christos } 3509 1.1 christos 3510 1.1 christos 3512 1.1 christos /* Handling the various POWER/PowerPC variants. */ 3513 1.1 christos 3514 1.9 christos /* Information about a particular processor variant. */ 3515 1.1 christos 3516 1.1 christos struct ppc_variant 3517 1.7 christos { 3518 1.1 christos /* Name of this variant. */ 3519 1.1 christos const char *name; 3520 1.7 christos 3521 1.1 christos /* English description of the variant. */ 3522 1.1 christos const char *description; 3523 1.1 christos 3524 1.1 christos /* bfd_arch_info.arch corresponding to variant. */ 3525 1.1 christos enum bfd_architecture arch; 3526 1.1 christos 3527 1.1 christos /* bfd_arch_info.mach corresponding to variant. */ 3528 1.1 christos unsigned long mach; 3529 1.10 christos 3530 1.1 christos /* Target description for this variant. */ 3531 1.1 christos const struct target_desc **tdesc; 3532 1.9 christos }; 3533 1.1 christos 3534 1.1 christos static struct ppc_variant variants[] = 3535 1.1 christos { 3536 1.1 christos {"powerpc", "PowerPC user-level", bfd_arch_powerpc, 3537 1.1 christos bfd_mach_ppc, &tdesc_powerpc_altivec32}, 3538 1.1 christos {"power", "POWER user-level", bfd_arch_rs6000, 3539 1.1 christos bfd_mach_rs6k, &tdesc_rs6000}, 3540 1.1 christos {"403", "IBM PowerPC 403", bfd_arch_powerpc, 3541 1.1 christos bfd_mach_ppc_403, &tdesc_powerpc_403}, 3542 1.1 christos {"405", "IBM PowerPC 405", bfd_arch_powerpc, 3543 1.1 christos bfd_mach_ppc_405, &tdesc_powerpc_405}, 3544 1.1 christos {"601", "Motorola PowerPC 601", bfd_arch_powerpc, 3545 1.1 christos bfd_mach_ppc_601, &tdesc_powerpc_601}, 3546 1.1 christos {"602", "Motorola PowerPC 602", bfd_arch_powerpc, 3547 1.1 christos bfd_mach_ppc_602, &tdesc_powerpc_602}, 3548 1.1 christos {"603", "Motorola/IBM PowerPC 603 or 603e", bfd_arch_powerpc, 3549 1.1 christos bfd_mach_ppc_603, &tdesc_powerpc_603}, 3550 1.1 christos {"604", "Motorola PowerPC 604 or 604e", bfd_arch_powerpc, 3551 1.1 christos 604, &tdesc_powerpc_604}, 3552 1.1 christos {"403GC", "IBM PowerPC 403GC", bfd_arch_powerpc, 3553 1.1 christos bfd_mach_ppc_403gc, &tdesc_powerpc_403gc}, 3554 1.1 christos {"505", "Motorola PowerPC 505", bfd_arch_powerpc, 3555 1.1 christos bfd_mach_ppc_505, &tdesc_powerpc_505}, 3556 1.1 christos {"860", "Motorola PowerPC 860 or 850", bfd_arch_powerpc, 3557 1.1 christos bfd_mach_ppc_860, &tdesc_powerpc_860}, 3558 1.1 christos {"750", "Motorola/IBM PowerPC 750 or 740", bfd_arch_powerpc, 3559 1.1 christos bfd_mach_ppc_750, &tdesc_powerpc_750}, 3560 1.1 christos {"7400", "Motorola/IBM PowerPC 7400 (G4)", bfd_arch_powerpc, 3561 1.1 christos bfd_mach_ppc_7400, &tdesc_powerpc_7400}, 3562 1.1 christos {"e500", "Motorola PowerPC e500", bfd_arch_powerpc, 3563 1.1 christos bfd_mach_ppc_e500, &tdesc_powerpc_e500}, 3564 1.1 christos 3565 1.1 christos /* 64-bit */ 3566 1.1 christos {"powerpc64", "PowerPC 64-bit user-level", bfd_arch_powerpc, 3567 1.1 christos bfd_mach_ppc64, &tdesc_powerpc_altivec64}, 3568 1.1 christos {"620", "Motorola PowerPC 620", bfd_arch_powerpc, 3569 1.1 christos bfd_mach_ppc_620, &tdesc_powerpc_64}, 3570 1.1 christos {"630", "Motorola PowerPC 630", bfd_arch_powerpc, 3571 1.1 christos bfd_mach_ppc_630, &tdesc_powerpc_64}, 3572 1.1 christos {"a35", "PowerPC A35", bfd_arch_powerpc, 3573 1.1 christos bfd_mach_ppc_a35, &tdesc_powerpc_64}, 3574 1.1 christos {"rs64ii", "PowerPC rs64ii", bfd_arch_powerpc, 3575 1.1 christos bfd_mach_ppc_rs64ii, &tdesc_powerpc_64}, 3576 1.1 christos {"rs64iii", "PowerPC rs64iii", bfd_arch_powerpc, 3577 1.1 christos bfd_mach_ppc_rs64iii, &tdesc_powerpc_64}, 3578 1.1 christos 3579 1.1 christos /* FIXME: I haven't checked the register sets of the following. */ 3580 1.1 christos {"rs1", "IBM POWER RS1", bfd_arch_rs6000, 3581 1.1 christos bfd_mach_rs6k_rs1, &tdesc_rs6000}, 3582 1.1 christos {"rsc", "IBM POWER RSC", bfd_arch_rs6000, 3583 1.1 christos bfd_mach_rs6k_rsc, &tdesc_rs6000}, 3584 1.1 christos {"rs2", "IBM POWER RS2", bfd_arch_rs6000, 3585 1.6 christos bfd_mach_rs6k_rs2, &tdesc_rs6000}, 3586 1.1 christos 3587 1.1 christos {0, 0, (enum bfd_architecture) 0, 0, 0} 3588 1.1 christos }; 3589 1.1 christos 3590 1.1 christos /* Return the variant corresponding to architecture ARCH and machine number 3591 1.9 christos MACH. If no such variant exists, return null. */ 3592 1.1 christos 3593 1.1 christos static const struct ppc_variant * 3594 1.9 christos find_variant_by_arch (enum bfd_architecture arch, unsigned long mach) 3595 1.1 christos { 3596 1.1 christos const struct ppc_variant *v; 3597 1.1 christos 3598 1.1 christos for (v = variants; v->name; v++) 3599 1.1 christos if (arch == v->arch && mach == v->mach) 3600 1.1 christos return v; 3601 1.1 christos 3602 1.1 christos return NULL; 3603 1.1 christos } 3604 1.1 christos 3605 1.1 christos 3606 1.1 christos 3608 1.1 christos struct rs6000_frame_cache 3609 1.10 christos { 3610 1.6 christos CORE_ADDR base; 3611 1.6 christos CORE_ADDR initial_sp; 3612 1.6 christos trad_frame_saved_reg *saved_regs; 3613 1.6 christos 3614 1.6 christos /* Set BASE_P to true if this frame cache is properly initialized. 3615 1.6 christos Otherwise set to false because some registers or memory cannot 3616 1.6 christos collected. */ 3617 1.1 christos int base_p; 3618 1.1 christos /* Cache PC for building unavailable frame. */ 3619 1.1 christos CORE_ADDR pc; 3620 1.11 christos }; 3621 1.1 christos 3622 1.1 christos static struct rs6000_frame_cache * 3623 1.1 christos rs6000_frame_cache (const frame_info_ptr &this_frame, void **this_cache) 3624 1.10 christos { 3625 1.1 christos struct rs6000_frame_cache *cache; 3626 1.1 christos struct gdbarch *gdbarch = get_frame_arch (this_frame); 3627 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3628 1.6 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 3629 1.1 christos struct rs6000_framedata fdata; 3630 1.1 christos int wordsize = tdep->wordsize; 3631 1.6 christos CORE_ADDR func = 0, pc = 0; 3632 1.1 christos 3633 1.1 christos if ((*this_cache) != NULL) 3634 1.6 christos return (struct rs6000_frame_cache *) (*this_cache); 3635 1.1 christos cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache); 3636 1.1 christos (*this_cache) = cache; 3637 1.9 christos cache->pc = 0; 3638 1.6 christos cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); 3639 1.6 christos 3640 1.6 christos try 3641 1.6 christos { 3642 1.6 christos func = get_frame_func (this_frame); 3643 1.6 christos cache->pc = func; 3644 1.6 christos pc = get_frame_pc (this_frame); 3645 1.6 christos skip_prologue (gdbarch, func, pc, &fdata); 3646 1.6 christos 3647 1.6 christos /* Figure out the parent's stack pointer. */ 3648 1.6 christos 3649 1.6 christos /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most 3650 1.6 christos address of the current frame. Things might be easier if the 3651 1.6 christos ->frame pointed to the outer-most address of the frame. In 3652 1.6 christos the mean time, the address of the prev frame is used as the 3653 1.6 christos base address of this frame. */ 3654 1.9 christos cache->base = get_frame_register_unsigned 3655 1.6 christos (this_frame, gdbarch_sp_regnum (gdbarch)); 3656 1.6 christos } 3657 1.9 christos catch (const gdb_exception_error &ex) 3658 1.6 christos { 3659 1.6 christos if (ex.error != NOT_AVAILABLE_ERROR) 3660 1.1 christos throw; 3661 1.1 christos return (struct rs6000_frame_cache *) (*this_cache); 3662 1.1 christos } 3663 1.1 christos 3664 1.1 christos /* If the function appears to be frameless, check a couple of likely 3665 1.1 christos indicators that we have simply failed to find the frame setup. 3666 1.1 christos Two common cases of this are missing symbols (i.e. 3667 1.1 christos get_frame_func returns the wrong address or 0), and assembly 3668 1.1 christos stubs which have a fast exit path but set up a frame on the slow 3669 1.1 christos path. 3670 1.1 christos 3671 1.1 christos If the LR appears to return to this function, then presume that 3672 1.1 christos we have an ABI compliant frame that we failed to find. */ 3673 1.1 christos if (fdata.frameless && fdata.lr_offset == 0) 3674 1.1 christos { 3675 1.1 christos CORE_ADDR saved_lr; 3676 1.1 christos int make_frame = 0; 3677 1.1 christos 3678 1.1 christos saved_lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum); 3679 1.1 christos if (func == 0 && saved_lr == pc) 3680 1.1 christos make_frame = 1; 3681 1.1 christos else if (func != 0) 3682 1.1 christos { 3683 1.1 christos CORE_ADDR saved_func = get_pc_function_start (saved_lr); 3684 1.1 christos if (func == saved_func) 3685 1.1 christos make_frame = 1; 3686 1.1 christos } 3687 1.1 christos 3688 1.1 christos if (make_frame) 3689 1.1 christos { 3690 1.1 christos fdata.frameless = 0; 3691 1.1 christos fdata.lr_offset = tdep->lr_frame_offset; 3692 1.1 christos } 3693 1.3 christos } 3694 1.3 christos 3695 1.6 christos if (!fdata.frameless) 3696 1.3 christos { 3697 1.6 christos /* Frameless really means stackless. */ 3698 1.6 christos ULONGEST backchain; 3699 1.10 christos 3700 1.3 christos if (safe_read_memory_unsigned_integer (cache->base, wordsize, 3701 1.1 christos byte_order, &backchain)) 3702 1.10 christos cache->base = (CORE_ADDR) backchain; 3703 1.1 christos } 3704 1.1 christos 3705 1.1 christos cache->saved_regs[gdbarch_sp_regnum (gdbarch)].set_value (cache->base); 3706 1.1 christos 3707 1.1 christos /* if != -1, fdata.saved_fpr is the smallest number of saved_fpr. 3708 1.1 christos All fpr's from saved_fpr to fp31 are saved. */ 3709 1.1 christos 3710 1.1 christos if (fdata.saved_fpr >= 0) 3711 1.1 christos { 3712 1.1 christos int i; 3713 1.10 christos CORE_ADDR fpr_addr = cache->base + fdata.fpr_offset; 3714 1.10 christos 3715 1.10 christos /* If skip_prologue says floating-point registers were saved, 3716 1.1 christos but the current architecture has no floating-point registers, 3717 1.10 christos then that's strange. But we have no indices to even record 3718 1.10 christos the addresses under, so we just ignore it. */ 3719 1.10 christos if (ppc_floating_point_unit_p (gdbarch)) 3720 1.10 christos for (i = fdata.saved_fpr; i < ppc_num_fprs; i++) 3721 1.10 christos { 3722 1.1 christos cache->saved_regs[tdep->ppc_fp0_regnum + i].set_addr (fpr_addr); 3723 1.1 christos fpr_addr += 8; 3724 1.1 christos } 3725 1.1 christos } 3726 1.1 christos 3727 1.1 christos /* if != -1, fdata.saved_gpr is the smallest number of saved_gpr. 3728 1.1 christos All gpr's from saved_gpr to gpr31 are saved (except during the 3729 1.1 christos prologue). */ 3730 1.1 christos 3731 1.1 christos if (fdata.saved_gpr >= 0) 3732 1.1 christos { 3733 1.1 christos int i; 3734 1.1 christos CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset; 3735 1.10 christos for (i = fdata.saved_gpr; i < ppc_num_gprs; i++) 3736 1.1 christos { 3737 1.1 christos if (fdata.gpr_mask & (1U << i)) 3738 1.1 christos cache->saved_regs[tdep->ppc_gp0_regnum + i].set_addr (gpr_addr); 3739 1.1 christos gpr_addr += wordsize; 3740 1.1 christos } 3741 1.1 christos } 3742 1.1 christos 3743 1.1 christos /* if != -1, fdata.saved_vr is the smallest number of saved_vr. 3744 1.1 christos All vr's from saved_vr to vr31 are saved. */ 3745 1.1 christos if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1) 3746 1.1 christos { 3747 1.1 christos if (fdata.saved_vr >= 0) 3748 1.1 christos { 3749 1.1 christos int i; 3750 1.10 christos CORE_ADDR vr_addr = cache->base + fdata.vr_offset; 3751 1.1 christos for (i = fdata.saved_vr; i < 32; i++) 3752 1.1 christos { 3753 1.1 christos cache->saved_regs[tdep->ppc_vr0_regnum + i].set_addr (vr_addr); 3754 1.1 christos vr_addr += register_size (gdbarch, tdep->ppc_vr0_regnum); 3755 1.1 christos } 3756 1.1 christos } 3757 1.1 christos } 3758 1.1 christos 3759 1.1 christos /* if != -1, fdata.saved_ev is the smallest number of saved_ev. 3760 1.1 christos All vr's from saved_ev to ev31 are saved. ????? */ 3761 1.1 christos if (tdep->ppc_ev0_regnum != -1) 3762 1.1 christos { 3763 1.1 christos if (fdata.saved_ev >= 0) 3764 1.3 christos { 3765 1.3 christos int i; 3766 1.1 christos CORE_ADDR ev_addr = cache->base + fdata.ev_offset; 3767 1.1 christos CORE_ADDR off = (byte_order == BFD_ENDIAN_BIG ? 4 : 0); 3768 1.10 christos 3769 1.10 christos for (i = fdata.saved_ev; i < ppc_num_gprs; i++) 3770 1.10 christos { 3771 1.1 christos cache->saved_regs[tdep->ppc_ev0_regnum + i].set_addr (ev_addr); 3772 1.3 christos cache->saved_regs[tdep->ppc_gp0_regnum + i].set_addr (ev_addr 3773 1.1 christos + off); 3774 1.1 christos ev_addr += register_size (gdbarch, tdep->ppc_ev0_regnum); 3775 1.1 christos } 3776 1.1 christos } 3777 1.1 christos } 3778 1.1 christos 3779 1.10 christos /* If != 0, fdata.cr_offset is the offset from the frame that 3780 1.10 christos holds the CR. */ 3781 1.1 christos if (fdata.cr_offset != 0) 3782 1.1 christos cache->saved_regs[tdep->ppc_cr_regnum].set_addr (cache->base 3783 1.1 christos + fdata.cr_offset); 3784 1.1 christos 3785 1.10 christos /* If != 0, fdata.lr_offset is the offset from the frame that 3786 1.10 christos holds the LR. */ 3787 1.1 christos if (fdata.lr_offset != 0) 3788 1.10 christos cache->saved_regs[tdep->ppc_lr_regnum].set_addr (cache->base 3789 1.1 christos + fdata.lr_offset); 3790 1.1 christos else if (fdata.lr_register != -1) 3791 1.1 christos cache->saved_regs[tdep->ppc_lr_regnum].set_realreg (fdata.lr_register); 3792 1.1 christos /* The PC is found in the link register. */ 3793 1.1 christos cache->saved_regs[gdbarch_pc_regnum (gdbarch)] = 3794 1.1 christos cache->saved_regs[tdep->ppc_lr_regnum]; 3795 1.1 christos 3796 1.10 christos /* If != 0, fdata.vrsave_offset is the offset from the frame that 3797 1.10 christos holds the VRSAVE. */ 3798 1.1 christos if (fdata.vrsave_offset != 0) 3799 1.1 christos cache->saved_regs[tdep->ppc_vrsave_regnum].set_addr (cache->base 3800 1.1 christos + fdata.vrsave_offset); 3801 1.1 christos 3802 1.1 christos if (fdata.alloca_reg < 0) 3803 1.1 christos /* If no alloca register used, then fi->frame is the value of the 3804 1.1 christos %sp for this frame, and it is good enough. */ 3805 1.1 christos cache->initial_sp 3806 1.1 christos = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch)); 3807 1.1 christos else 3808 1.6 christos cache->initial_sp 3809 1.1 christos = get_frame_register_unsigned (this_frame, fdata.alloca_reg); 3810 1.1 christos 3811 1.1 christos cache->base_p = 1; 3812 1.1 christos return cache; 3813 1.11 christos } 3814 1.1 christos 3815 1.1 christos static void 3816 1.1 christos rs6000_frame_this_id (const frame_info_ptr &this_frame, void **this_cache, 3817 1.1 christos struct frame_id *this_id) 3818 1.6 christos { 3819 1.6 christos struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame, 3820 1.6 christos this_cache); 3821 1.6 christos 3822 1.6 christos if (!info->base_p) 3823 1.6 christos { 3824 1.6 christos (*this_id) = frame_id_build_unavailable_stack (info->pc); 3825 1.1 christos return; 3826 1.1 christos } 3827 1.1 christos 3828 1.1 christos /* This marks the outermost frame. */ 3829 1.1 christos if (info->base == 0) 3830 1.1 christos return; 3831 1.1 christos 3832 1.1 christos (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); 3833 1.11 christos } 3834 1.1 christos 3835 1.1 christos static struct value * 3836 1.1 christos rs6000_frame_prev_register (const frame_info_ptr &this_frame, 3837 1.1 christos void **this_cache, int regnum) 3838 1.1 christos { 3839 1.1 christos struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame, 3840 1.1 christos this_cache); 3841 1.1 christos return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); 3842 1.1 christos } 3843 1.10 christos 3844 1.1 christos static const struct frame_unwind rs6000_frame_unwind = 3845 1.1 christos { 3846 1.1 christos "rs6000 prologue", 3847 1.1 christos NORMAL_FRAME, 3848 1.1 christos default_frame_unwind_stop_reason, 3849 1.1 christos rs6000_frame_this_id, 3850 1.1 christos rs6000_frame_prev_register, 3851 1.3 christos NULL, 3852 1.3 christos default_frame_sniffer 3853 1.3 christos }; 3854 1.3 christos 3855 1.3 christos /* Allocate and initialize a frame cache for an epilogue frame. 3856 1.11 christos SP is restored and prev-PC is stored in LR. */ 3857 1.3 christos 3858 1.3 christos static struct rs6000_frame_cache * 3859 1.3 christos rs6000_epilogue_frame_cache (const frame_info_ptr &this_frame, void **this_cache) 3860 1.10 christos { 3861 1.11 christos struct rs6000_frame_cache *cache; 3862 1.11 christos struct gdbarch *gdbarch = get_frame_arch (this_frame); 3863 1.3 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 3864 1.3 christos struct rs6000_framedata fdata; 3865 1.6 christos int wordsize = tdep->wordsize; 3866 1.3 christos 3867 1.3 christos if (*this_cache) 3868 1.3 christos return (struct rs6000_frame_cache *) *this_cache; 3869 1.3 christos 3870 1.3 christos cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache); 3871 1.9 christos (*this_cache) = cache; 3872 1.3 christos cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); 3873 1.11 christos 3874 1.11 christos try 3875 1.11 christos { 3876 1.11 christos /* At this point the stack looks as if we just entered the function. 3877 1.11 christos The SP (r1) has been restored but the LR and r31 may not have been 3878 1.11 christos restored yet. Need to update the register unrolling information in 3879 1.11 christos the cache for the LR and the saved gprs. */ 3880 1.11 christos CORE_ADDR sp; 3881 1.11 christos CORE_ADDR func = 0, pc = 0; 3882 1.11 christos 3883 1.11 christos func = get_frame_func (this_frame); 3884 1.3 christos cache->pc = func; 3885 1.11 christos pc = get_frame_pc (this_frame); 3886 1.11 christos skip_prologue (gdbarch, func, pc, &fdata); 3887 1.11 christos 3888 1.3 christos /* SP is in r1 and it has been restored. Get the current value. */ 3889 1.3 christos sp = get_frame_register_unsigned (this_frame, 3890 1.3 christos gdbarch_sp_regnum (gdbarch)); 3891 1.3 christos 3892 1.11 christos cache->base = sp; 3893 1.11 christos cache->initial_sp = sp; 3894 1.11 christos 3895 1.11 christos /* Store the unwinding rules for the gpr registers that have not been 3896 1.11 christos restored yet, specifically r31. 3897 1.11 christos 3898 1.11 christos if != -1, fdata.saved_gpr is the smallest number of saved_gpr. 3899 1.11 christos All gpr's from saved_gpr to gpr31 are saved (except during the 3900 1.11 christos prologue). */ 3901 1.11 christos 3902 1.11 christos if (fdata.saved_gpr >= 0) 3903 1.11 christos { 3904 1.11 christos int i; 3905 1.11 christos CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset; 3906 1.11 christos 3907 1.11 christos for(i = fdata.saved_gpr; i < ppc_num_gprs; i++) 3908 1.11 christos { 3909 1.11 christos if (fdata.gpr_mask & (1U << i)) 3910 1.11 christos cache->saved_regs[tdep->ppc_gp0_regnum + i].set_addr (gpr_addr); 3911 1.11 christos gpr_addr += wordsize; 3912 1.11 christos } 3913 1.11 christos } 3914 1.11 christos 3915 1.11 christos /* Store the lr unwinding rules. */ 3916 1.11 christos if (fdata.lr_offset != 0) 3917 1.11 christos cache->saved_regs[tdep->ppc_lr_regnum].set_addr (cache->base 3918 1.11 christos + fdata.lr_offset); 3919 1.11 christos 3920 1.11 christos else if (fdata.lr_register != -1) 3921 1.11 christos cache->saved_regs[tdep->ppc_lr_regnum].set_realreg (fdata.lr_register); 3922 1.11 christos 3923 1.3 christos /* The PC is found in the link register. */ 3924 1.9 christos cache->saved_regs[gdbarch_pc_regnum (gdbarch)] 3925 1.5 christos = cache->saved_regs[tdep->ppc_lr_regnum]; 3926 1.5 christos } 3927 1.9 christos catch (const gdb_exception_error &ex) 3928 1.5 christos { 3929 1.3 christos if (ex.error != NOT_AVAILABLE_ERROR) 3930 1.3 christos throw; 3931 1.3 christos } 3932 1.3 christos 3933 1.3 christos return cache; 3934 1.3 christos } 3935 1.3 christos 3936 1.3 christos /* Implementation of frame_unwind.this_id, as defined in frame_unwind.h. 3937 1.11 christos Return the frame ID of an epilogue frame. */ 3938 1.3 christos 3939 1.3 christos static void 3940 1.3 christos rs6000_epilogue_frame_this_id (const frame_info_ptr &this_frame, 3941 1.3 christos void **this_cache, struct frame_id *this_id) 3942 1.3 christos { 3943 1.3 christos CORE_ADDR pc; 3944 1.3 christos struct rs6000_frame_cache *info = 3945 1.3 christos rs6000_epilogue_frame_cache (this_frame, this_cache); 3946 1.3 christos 3947 1.3 christos pc = get_frame_func (this_frame); 3948 1.3 christos if (info->base == 0) 3949 1.3 christos (*this_id) = frame_id_build_unavailable_stack (pc); 3950 1.3 christos else 3951 1.3 christos (*this_id) = frame_id_build (info->base, pc); 3952 1.3 christos } 3953 1.3 christos 3954 1.3 christos /* Implementation of frame_unwind.prev_register, as defined in frame_unwind.h. 3955 1.11 christos Return the register value of REGNUM in previous frame. */ 3956 1.3 christos 3957 1.3 christos static struct value * 3958 1.3 christos rs6000_epilogue_frame_prev_register (const frame_info_ptr &this_frame, 3959 1.3 christos void **this_cache, int regnum) 3960 1.3 christos { 3961 1.3 christos struct rs6000_frame_cache *info = 3962 1.3 christos rs6000_epilogue_frame_cache (this_frame, this_cache); 3963 1.3 christos return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); 3964 1.3 christos } 3965 1.3 christos 3966 1.3 christos /* Implementation of frame_unwind.sniffer, as defined in frame_unwind.h. 3967 1.3 christos Check whether this an epilogue frame. */ 3968 1.11 christos 3969 1.3 christos static int 3970 1.3 christos rs6000_epilogue_frame_sniffer (const struct frame_unwind *self, 3971 1.3 christos const frame_info_ptr &this_frame, 3972 1.3 christos void **this_prologue_cache) 3973 1.3 christos { 3974 1.3 christos if (frame_relative_level (this_frame) == 0) 3975 1.3 christos return rs6000_in_function_epilogue_frame_p (this_frame, 3976 1.3 christos get_frame_arch (this_frame), 3977 1.3 christos get_frame_pc (this_frame)); 3978 1.3 christos else 3979 1.3 christos return 0; 3980 1.3 christos } 3981 1.3 christos 3982 1.3 christos /* Frame unwinder for epilogue frame. This is required for reverse step-over 3983 1.3 christos a function without debug information. */ 3984 1.10 christos 3985 1.3 christos static const struct frame_unwind rs6000_epilogue_frame_unwind = 3986 1.3 christos { 3987 1.3 christos "rs6000 epilogue", 3988 1.3 christos NORMAL_FRAME, 3989 1.3 christos default_frame_unwind_stop_reason, 3990 1.3 christos rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register, 3991 1.1 christos NULL, 3992 1.1 christos rs6000_epilogue_frame_sniffer 3993 1.1 christos }; 3994 1.11 christos 3995 1.1 christos 3997 1.1 christos static CORE_ADDR 3998 1.1 christos rs6000_frame_base_address (const frame_info_ptr &this_frame, void **this_cache) 3999 1.1 christos { 4000 1.1 christos struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame, 4001 1.1 christos this_cache); 4002 1.1 christos return info->initial_sp; 4003 1.1 christos } 4004 1.1 christos 4005 1.1 christos static const struct frame_base rs6000_frame_base = { 4006 1.1 christos &rs6000_frame_unwind, 4007 1.1 christos rs6000_frame_base_address, 4008 1.1 christos rs6000_frame_base_address, 4009 1.11 christos rs6000_frame_base_address 4010 1.1 christos }; 4011 1.1 christos 4012 1.1 christos static const struct frame_base * 4013 1.1 christos rs6000_frame_base_sniffer (const frame_info_ptr &this_frame) 4014 1.1 christos { 4015 1.1 christos return &rs6000_frame_base; 4016 1.1 christos } 4017 1.1 christos 4018 1.1 christos /* DWARF-2 frame support. Used to handle the detection of 4019 1.1 christos clobbered registers during function calls. */ 4020 1.11 christos 4021 1.1 christos static void 4022 1.10 christos ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, 4023 1.1 christos struct dwarf2_frame_state_reg *reg, 4024 1.1 christos const frame_info_ptr &this_frame) 4025 1.1 christos { 4026 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 4027 1.1 christos 4028 1.1 christos /* PPC32 and PPC64 ABI's are the same regarding volatile and 4029 1.1 christos non-volatile registers. We will use the same code for both. */ 4030 1.1 christos 4031 1.1 christos /* Call-saved GP registers. */ 4032 1.1 christos if ((regnum >= tdep->ppc_gp0_regnum + 14 4033 1.1 christos && regnum <= tdep->ppc_gp0_regnum + 31) 4034 1.1 christos || (regnum == tdep->ppc_gp0_regnum + 1)) 4035 1.1 christos reg->how = DWARF2_FRAME_REG_SAME_VALUE; 4036 1.1 christos 4037 1.1 christos /* Call-clobbered GP registers. */ 4038 1.1 christos if ((regnum >= tdep->ppc_gp0_regnum + 3 4039 1.1 christos && regnum <= tdep->ppc_gp0_regnum + 12) 4040 1.1 christos || (regnum == tdep->ppc_gp0_regnum)) 4041 1.1 christos reg->how = DWARF2_FRAME_REG_UNDEFINED; 4042 1.1 christos 4043 1.1 christos /* Deal with FP registers, if supported. */ 4044 1.1 christos if (tdep->ppc_fp0_regnum >= 0) 4045 1.1 christos { 4046 1.1 christos /* Call-saved FP registers. */ 4047 1.1 christos if ((regnum >= tdep->ppc_fp0_regnum + 14 4048 1.1 christos && regnum <= tdep->ppc_fp0_regnum + 31)) 4049 1.1 christos reg->how = DWARF2_FRAME_REG_SAME_VALUE; 4050 1.1 christos 4051 1.1 christos /* Call-clobbered FP registers. */ 4052 1.1 christos if ((regnum >= tdep->ppc_fp0_regnum 4053 1.1 christos && regnum <= tdep->ppc_fp0_regnum + 13)) 4054 1.1 christos reg->how = DWARF2_FRAME_REG_UNDEFINED; 4055 1.1 christos } 4056 1.1 christos 4057 1.1 christos /* Deal with ALTIVEC registers, if supported. */ 4058 1.1 christos if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0) 4059 1.1 christos { 4060 1.1 christos /* Call-saved Altivec registers. */ 4061 1.1 christos if ((regnum >= tdep->ppc_vr0_regnum + 20 4062 1.1 christos && regnum <= tdep->ppc_vr0_regnum + 31) 4063 1.1 christos || regnum == tdep->ppc_vrsave_regnum) 4064 1.1 christos reg->how = DWARF2_FRAME_REG_SAME_VALUE; 4065 1.1 christos 4066 1.1 christos /* Call-clobbered Altivec registers. */ 4067 1.1 christos if ((regnum >= tdep->ppc_vr0_regnum 4068 1.1 christos && regnum <= tdep->ppc_vr0_regnum + 19)) 4069 1.1 christos reg->how = DWARF2_FRAME_REG_UNDEFINED; 4070 1.1 christos } 4071 1.1 christos 4072 1.1 christos /* Handle PC register and Stack Pointer correctly. */ 4073 1.1 christos if (regnum == gdbarch_pc_regnum (gdbarch)) 4074 1.1 christos reg->how = DWARF2_FRAME_REG_RA; 4075 1.1 christos else if (regnum == gdbarch_sp_regnum (gdbarch)) 4076 1.1 christos reg->how = DWARF2_FRAME_REG_CFA; 4077 1.1 christos } 4078 1.1 christos 4079 1.1 christos 4080 1.1 christos /* Return true if a .gnu_attributes section exists in BFD and it 4081 1.1 christos indicates we are using SPE extensions OR if a .PPC.EMB.apuinfo 4082 1.1 christos section exists in BFD and it indicates that SPE extensions are in 4083 1.1 christos use. Check the .gnu.attributes section first, as the binary might be 4084 1.1 christos compiled for SPE, but not actually using SPE instructions. */ 4085 1.1 christos 4086 1.1 christos static int 4087 1.1 christos bfd_uses_spe_extensions (bfd *abfd) 4088 1.1 christos { 4089 1.1 christos asection *sect; 4090 1.1 christos gdb_byte *contents = NULL; 4091 1.1 christos bfd_size_type size; 4092 1.1 christos gdb_byte *ptr; 4093 1.1 christos int success = 0; 4094 1.1 christos 4095 1.1 christos if (!abfd) 4096 1.1 christos return 0; 4097 1.1 christos 4098 1.8 christos #ifdef HAVE_ELF 4099 1.8 christos /* Using Tag_GNU_Power_ABI_Vector here is a bit of a hack, as the user 4100 1.1 christos could be using the SPE vector abi without actually using any spe 4101 1.1 christos bits whatsoever. But it's close enough for now. */ 4102 1.1 christos int vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU, 4103 1.1 christos Tag_GNU_Power_ABI_Vector); 4104 1.1 christos if (vector_abi == 3) 4105 1.1 christos return 1; 4106 1.1 christos #endif 4107 1.1 christos 4108 1.9 christos sect = bfd_get_section_by_name (abfd, ".PPC.EMB.apuinfo"); 4109 1.6 christos if (!sect) 4110 1.1 christos return 0; 4111 1.1 christos 4112 1.1 christos size = bfd_section_size (sect); 4113 1.1 christos contents = (gdb_byte *) xmalloc (size); 4114 1.1 christos if (!bfd_get_section_contents (abfd, sect, contents, 0, size)) 4115 1.1 christos { 4116 1.1 christos xfree (contents); 4117 1.1 christos return 0; 4118 1.1 christos } 4119 1.1 christos 4120 1.1 christos /* Parse the .PPC.EMB.apuinfo section. The layout is as follows: 4121 1.1 christos 4122 1.1 christos struct { 4123 1.1 christos uint32 name_len; 4124 1.1 christos uint32 data_len; 4125 1.1 christos uint32 type; 4126 1.1 christos char name[name_len rounded up to 4-byte alignment]; 4127 1.1 christos char data[data_len]; 4128 1.1 christos }; 4129 1.1 christos 4130 1.1 christos Technically, there's only supposed to be one such structure in a 4131 1.1 christos given apuinfo section, but the linker is not always vigilant about 4132 1.1 christos merging apuinfo sections from input files. Just go ahead and parse 4133 1.1 christos them all, exiting early when we discover the binary uses SPE 4134 1.1 christos insns. 4135 1.1 christos 4136 1.1 christos It's not specified in what endianness the information in this 4137 1.1 christos section is stored. Assume that it's the endianness of the BFD. */ 4138 1.1 christos ptr = contents; 4139 1.1 christos while (1) 4140 1.1 christos { 4141 1.1 christos unsigned int name_len; 4142 1.1 christos unsigned int data_len; 4143 1.1 christos unsigned int type; 4144 1.1 christos 4145 1.1 christos /* If we can't read the first three fields, we're done. */ 4146 1.1 christos if (size < 12) 4147 1.1 christos break; 4148 1.1 christos 4149 1.1 christos name_len = bfd_get_32 (abfd, ptr); 4150 1.1 christos name_len = (name_len + 3) & ~3U; /* Round to 4 bytes. */ 4151 1.1 christos data_len = bfd_get_32 (abfd, ptr + 4); 4152 1.1 christos type = bfd_get_32 (abfd, ptr + 8); 4153 1.1 christos ptr += 12; 4154 1.1 christos 4155 1.1 christos /* The name must be "APUinfo\0". */ 4156 1.1 christos if (name_len != 8 4157 1.1 christos && strcmp ((const char *) ptr, "APUinfo") != 0) 4158 1.1 christos break; 4159 1.1 christos ptr += name_len; 4160 1.1 christos 4161 1.1 christos /* The type must be 2. */ 4162 1.1 christos if (type != 2) 4163 1.1 christos break; 4164 1.1 christos 4165 1.1 christos /* The data is stored as a series of uint32. The upper half of 4166 1.1 christos each uint32 indicates the particular APU used and the lower 4167 1.1 christos half indicates the revision of that APU. We just care about 4168 1.1 christos the upper half. */ 4169 1.1 christos 4170 1.1 christos /* Not 4-byte quantities. */ 4171 1.1 christos if (data_len & 3U) 4172 1.1 christos break; 4173 1.1 christos 4174 1.1 christos while (data_len) 4175 1.1 christos { 4176 1.1 christos unsigned int apuinfo = bfd_get_32 (abfd, ptr); 4177 1.1 christos unsigned int apu = apuinfo >> 16; 4178 1.1 christos ptr += 4; 4179 1.1 christos data_len -= 4; 4180 1.1 christos 4181 1.1 christos /* The SPE APU is 0x100; the SPEFP APU is 0x101. Accept 4182 1.1 christos either. */ 4183 1.1 christos if (apu == 0x100 || apu == 0x101) 4184 1.1 christos { 4185 1.1 christos success = 1; 4186 1.1 christos data_len = 0; 4187 1.1 christos } 4188 1.1 christos } 4189 1.1 christos 4190 1.1 christos if (success) 4191 1.1 christos break; 4192 1.1 christos } 4193 1.1 christos 4194 1.3 christos xfree (contents); 4195 1.3 christos return success; 4196 1.3 christos } 4197 1.3 christos 4198 1.3 christos /* These are macros for parsing instruction fields (I.1.6.28) */ 4199 1.3 christos 4200 1.3 christos #define PPC_FIELD(value, from, len) \ 4201 1.3 christos (((value) >> (32 - (from) - (len))) & ((1 << (len)) - 1)) 4202 1.3 christos #define PPC_SEXT(v, bs) \ 4203 1.3 christos ((((CORE_ADDR) (v) & (((CORE_ADDR) 1 << (bs)) - 1)) \ 4204 1.3 christos ^ ((CORE_ADDR) 1 << ((bs) - 1))) \ 4205 1.3 christos - ((CORE_ADDR) 1 << ((bs) - 1))) 4206 1.3 christos #define PPC_OP6(insn) PPC_FIELD (insn, 0, 6) 4207 1.3 christos #define PPC_EXTOP(insn) PPC_FIELD (insn, 21, 10) 4208 1.3 christos #define PPC_RT(insn) PPC_FIELD (insn, 6, 5) 4209 1.3 christos #define PPC_RS(insn) PPC_FIELD (insn, 6, 5) 4210 1.3 christos #define PPC_RA(insn) PPC_FIELD (insn, 11, 5) 4211 1.3 christos #define PPC_RB(insn) PPC_FIELD (insn, 16, 5) 4212 1.3 christos #define PPC_NB(insn) PPC_FIELD (insn, 16, 5) 4213 1.3 christos #define PPC_VRT(insn) PPC_FIELD (insn, 6, 5) 4214 1.3 christos #define PPC_FRT(insn) PPC_FIELD (insn, 6, 5) 4215 1.3 christos #define PPC_SPR(insn) (PPC_FIELD (insn, 11, 5) \ 4216 1.3 christos | (PPC_FIELD (insn, 16, 5) << 5)) 4217 1.7 christos #define PPC_BO(insn) PPC_FIELD (insn, 6, 5) 4218 1.3 christos #define PPC_T(insn) PPC_FIELD (insn, 6, 5) 4219 1.3 christos #define PPC_D(insn) PPC_SEXT (PPC_FIELD (insn, 16, 16), 16) 4220 1.3 christos #define PPC_DS(insn) PPC_SEXT (PPC_FIELD (insn, 16, 14), 14) 4221 1.3 christos #define PPC_DQ(insn) PPC_SEXT (PPC_FIELD (insn, 16, 12), 12) 4222 1.3 christos #define PPC_BIT(insn,n) ((insn & (1 << (31 - (n)))) ? 1 : 0) 4223 1.3 christos #define PPC_OE(insn) PPC_BIT (insn, 21) 4224 1.3 christos #define PPC_RC(insn) PPC_BIT (insn, 31) 4225 1.3 christos #define PPC_Rc(insn) PPC_BIT (insn, 21) 4226 1.3 christos #define PPC_LK(insn) PPC_BIT (insn, 31) 4227 1.10 christos #define PPC_TX(insn) PPC_BIT (insn, 31) 4228 1.10 christos #define PPC_LEV(insn) PPC_FIELD (insn, 20, 7) 4229 1.10 christos 4230 1.10 christos #define PPC_XT(insn) ((PPC_TX (insn) << 5) | PPC_T (insn)) 4231 1.3 christos #define PPC_XTp(insn) ((PPC_BIT (insn, 10) << 5) \ 4232 1.3 christos | PPC_FIELD (insn, 6, 4) << 1) 4233 1.10 christos #define PPC_XSp(insn) ((PPC_BIT (insn, 10) << 5) \ 4234 1.10 christos | PPC_FIELD (insn, 6, 4) << 1) 4235 1.10 christos #define PPC_XER_NB(xer) (xer & 0x7f) 4236 1.10 christos 4237 1.10 christos /* The following macros are for the prefixed instructions. */ 4238 1.10 christos #define P_PPC_D(insn_prefix, insn_suffix) \ 4239 1.10 christos PPC_SEXT (PPC_FIELD (insn_prefix, 14, 18) << 16 \ 4240 1.10 christos | PPC_FIELD (insn_suffix, 16, 16), 34) 4241 1.10 christos #define P_PPC_TX5(insn_sufix) PPC_BIT (insn_suffix, 5) 4242 1.10 christos #define P_PPC_TX15(insn_suffix) PPC_BIT (insn_suffix, 15) 4243 1.10 christos #define P_PPC_XT(insn_suffix) ((PPC_TX (insn_suffix) << 5) \ 4244 1.10 christos | PPC_T (insn_suffix)) 4245 1.10 christos #define P_PPC_XT5(insn_suffix) ((P_PPC_TX5 (insn_suffix) << 5) \ 4246 1.3 christos | PPC_T (insn_suffix)) 4247 1.3 christos #define P_PPC_XT15(insn_suffix) \ 4248 1.3 christos ((P_PPC_TX15 (insn_suffix) << 5) | PPC_T (insn_suffix)) 4249 1.3 christos 4250 1.3 christos /* Record Vector-Scalar Registers. 4251 1.10 christos For VSR less than 32, it's represented by an FPR and an VSR-upper register. 4252 1.3 christos Otherwise, it's just a VR register. Record them accordingly. */ 4253 1.3 christos 4254 1.3 christos static int 4255 1.3 christos ppc_record_vsr (struct regcache *regcache, ppc_gdbarch_tdep *tdep, int vsr) 4256 1.3 christos { 4257 1.3 christos if (vsr < 0 || vsr >= 64) 4258 1.3 christos return -1; 4259 1.3 christos 4260 1.3 christos if (vsr >= 32) 4261 1.3 christos { 4262 1.3 christos if (tdep->ppc_vr0_regnum >= 0) 4263 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_vr0_regnum + vsr - 32); 4264 1.3 christos } 4265 1.3 christos else 4266 1.3 christos { 4267 1.3 christos if (tdep->ppc_fp0_regnum >= 0) 4268 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fp0_regnum + vsr); 4269 1.3 christos if (tdep->ppc_vsr0_upper_regnum >= 0) 4270 1.3 christos record_full_arch_list_add_reg (regcache, 4271 1.3 christos tdep->ppc_vsr0_upper_regnum + vsr); 4272 1.3 christos } 4273 1.10 christos 4274 1.10 christos return 0; 4275 1.10 christos } 4276 1.10 christos 4277 1.10 christos /* The ppc_record_ACC_fpscr() records the changes to the VSR registers 4278 1.10 christos modified by a floating point instruction. The ENTRY argument selects which 4279 1.10 christos of the eight AT entries needs to be recorded. The boolean SAVE_FPSCR 4280 1.10 christos argument is set to TRUE to indicate the FPSCR also needs to be recorded. 4281 1.10 christos The function returns 0 on success. */ 4282 1.10 christos 4283 1.10 christos static int 4284 1.10 christos ppc_record_ACC_fpscr (struct regcache *regcache, ppc_gdbarch_tdep *tdep, 4285 1.10 christos int entry, bool save_fpscr) 4286 1.10 christos { 4287 1.10 christos int i; 4288 1.10 christos if (entry < 0 || entry >= 8) 4289 1.10 christos return -1; 4290 1.10 christos 4291 1.11 christos /* The ACC register file consists of 8 register entries, each register 4292 1.11 christos entry consist of four 128-bit rows. 4293 1.11 christos 4294 1.11 christos The ACC rows map to specific VSR registers. 4295 1.11 christos ACC[0][0] -> VSR[0] 4296 1.11 christos ACC[0][1] -> VSR[1] 4297 1.11 christos ACC[0][2] -> VSR[2] 4298 1.11 christos ACC[0][3] -> VSR[3] 4299 1.11 christos ... 4300 1.10 christos ACC[7][0] -> VSR[28] 4301 1.10 christos ACC[7][1] -> VSR[29] 4302 1.10 christos ACC[7][2] -> VSR[30] 4303 1.10 christos ACC[7][3] -> VSR[31] 4304 1.10 christos 4305 1.10 christos NOTE: 4306 1.10 christos In ISA 3.1 the ACC is mapped on top of VSR[0] thru VSR[31]. 4307 1.10 christos 4308 1.10 christos In the future, the ACC may be implemented as an independent register file 4309 1.10 christos rather than mapping on top of the VSRs. This will then require the ACC to 4310 1.10 christos be assigned its own register number and the ptrace interface to be able 4311 1.10 christos access the ACC. Note the ptrace interface for the ACC will also need to 4312 1.10 christos be implemented. */ 4313 1.10 christos 4314 1.10 christos /* ACC maps over the same VSR space as the fp registers. */ 4315 1.10 christos for (i = 0; i < 4; i++) 4316 1.10 christos { 4317 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fp0_regnum 4318 1.10 christos + entry * 4 + i); 4319 1.10 christos record_full_arch_list_add_reg (regcache, 4320 1.10 christos tdep->ppc_vsr0_upper_regnum 4321 1.10 christos + entry * 4 + i); 4322 1.10 christos } 4323 1.10 christos 4324 1.10 christos if (save_fpscr) 4325 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 4326 1.3 christos 4327 1.3 christos return 0; 4328 1.3 christos } 4329 1.3 christos 4330 1.3 christos /* Parse and record instructions primary opcode-4 at ADDR. 4331 1.3 christos Return 0 if successful. */ 4332 1.3 christos 4333 1.10 christos static int 4334 1.3 christos ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache, 4335 1.7 christos CORE_ADDR addr, uint32_t insn) 4336 1.3 christos { 4337 1.3 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 4338 1.3 christos int ext = PPC_FIELD (insn, 21, 11); 4339 1.3 christos int vra = PPC_FIELD (insn, 11, 5); 4340 1.3 christos 4341 1.3 christos switch (ext & 0x3f) 4342 1.3 christos { 4343 1.3 christos case 32: /* Vector Multiply-High-Add Signed Halfword Saturate */ 4344 1.11 christos case 33: /* Vector Multiply-High-Round-Add Signed Halfword Saturate */ 4345 1.10 christos case 39: /* Vector Multiply-Sum Unsigned Halfword Saturate */ 4346 1.10 christos case 41: /* Vector Multiply-Sum Signed Halfword Saturate */ 4347 1.10 christos record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM); 4348 1.10 christos [[fallthrough]]; 4349 1.10 christos case 20: /* Move To VSR Byte Mask Immediate opcode, b2 = 0, 4350 1.10 christos ignore bit 31 */ 4351 1.10 christos case 21: /* Move To VSR Byte Mask Immediate opcode, b2 = 1, 4352 1.10 christos ignore bit 31 */ 4353 1.10 christos case 23: /* Vector Multiply-Sum & write Carry-out Unsigned 4354 1.10 christos Doubleword */ 4355 1.10 christos case 24: /* Vector Extract Double Unsigned Byte to VSR 4356 1.10 christos using GPR-specified Left-Index */ 4357 1.10 christos case 25: /* Vector Extract Double Unsigned Byte to VSR 4358 1.10 christos using GPR-specified Right-Index */ 4359 1.10 christos case 26: /* Vector Extract Double Unsigned Halfword to VSR 4360 1.10 christos using GPR-specified Left-Index */ 4361 1.10 christos case 27: /* Vector Extract Double Unsigned Halfword to VSR 4362 1.10 christos using GPR-specified Right-Index */ 4363 1.10 christos case 28: /* Vector Extract Double Unsigned Word to VSR 4364 1.10 christos using GPR-specified Left-Index */ 4365 1.10 christos case 29: /* Vector Extract Double Unsigned Word to VSR 4366 1.10 christos using GPR-specified Right-Index */ 4367 1.3 christos case 30: /* Vector Extract Double Unsigned Doubleword to VSR 4368 1.3 christos using GPR-specified Left-Index */ 4369 1.7 christos case 31: /* Vector Extract Double Unsigned Doubleword to VSR 4370 1.10 christos using GPR-specified Right-Index */ 4371 1.10 christos case 42: /* Vector Select */ 4372 1.10 christos case 43: /* Vector Permute */ 4373 1.3 christos case 59: /* Vector Permute Right-indexed */ 4374 1.3 christos case 22: /* Vector Shift 4375 1.3 christos Left Double by Bit Immediate if insn[21] = 0 4376 1.3 christos Right Double by Bit Immediate if insn[21] = 1 */ 4377 1.3 christos case 44: /* Vector Shift Left Double by Octet Immediate */ 4378 1.3 christos case 45: /* Vector Permute and Exclusive-OR */ 4379 1.3 christos case 60: /* Vector Add Extended Unsigned Quadword Modulo */ 4380 1.7 christos case 61: /* Vector Add Extended & write Carry Unsigned Quadword */ 4381 1.3 christos case 62: /* Vector Subtract Extended Unsigned Quadword Modulo */ 4382 1.3 christos case 63: /* Vector Subtract Extended & write Carry Unsigned Quadword */ 4383 1.3 christos case 34: /* Vector Multiply-Low-Add Unsigned Halfword Modulo */ 4384 1.3 christos case 35: /* Vector Multiply-Sum Unsigned Doubleword Modulo */ 4385 1.3 christos case 36: /* Vector Multiply-Sum Unsigned Byte Modulo */ 4386 1.3 christos case 37: /* Vector Multiply-Sum Mixed Byte Modulo */ 4387 1.3 christos case 38: /* Vector Multiply-Sum Unsigned Halfword Modulo */ 4388 1.3 christos case 40: /* Vector Multiply-Sum Signed Halfword Modulo */ 4389 1.3 christos case 46: /* Vector Multiply-Add Single-Precision */ 4390 1.7 christos case 47: /* Vector Negative Multiply-Subtract Single-Precision */ 4391 1.7 christos record_full_arch_list_add_reg (regcache, 4392 1.7 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4393 1.7 christos return 0; 4394 1.7 christos 4395 1.7 christos case 48: /* Multiply-Add High Doubleword */ 4396 1.7 christos case 49: /* Multiply-Add High Doubleword Unsigned */ 4397 1.3 christos case 51: /* Multiply-Add Low Doubleword */ 4398 1.3 christos record_full_arch_list_add_reg (regcache, 4399 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 4400 1.3 christos return 0; 4401 1.7 christos } 4402 1.7 christos 4403 1.7 christos switch ((ext & 0x1ff)) 4404 1.7 christos { 4405 1.7 christos case 385: 4406 1.7 christos if (vra != 0 /* Decimal Convert To Signed Quadword */ 4407 1.7 christos && vra != 2 /* Decimal Convert From Signed Quadword */ 4408 1.7 christos && vra != 4 /* Decimal Convert To Zoned */ 4409 1.7 christos && vra != 5 /* Decimal Convert To National */ 4410 1.11 christos && vra != 6 /* Decimal Convert From Zoned */ 4411 1.3 christos && vra != 7 /* Decimal Convert From National */ 4412 1.3 christos && vra != 31) /* Decimal Set Sign */ 4413 1.3 christos break; 4414 1.3 christos [[fallthrough]]; 4415 1.7 christos /* 5.16 Decimal Integer Arithmetic Instructions */ 4416 1.7 christos case 1: /* Decimal Add Modulo */ 4417 1.7 christos case 65: /* Decimal Subtract Modulo */ 4418 1.7 christos 4419 1.7 christos case 193: /* Decimal Shift */ 4420 1.7 christos case 129: /* Decimal Unsigned Shift */ 4421 1.7 christos case 449: /* Decimal Shift and Round */ 4422 1.3 christos 4423 1.3 christos case 257: /* Decimal Truncate */ 4424 1.3 christos case 321: /* Decimal Unsigned Truncate */ 4425 1.3 christos 4426 1.3 christos /* Bit-21 should be set. */ 4427 1.3 christos if (!PPC_BIT (insn, 21)) 4428 1.3 christos break; 4429 1.3 christos 4430 1.3 christos record_full_arch_list_add_reg (regcache, 4431 1.3 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4432 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 4433 1.3 christos return 0; 4434 1.3 christos } 4435 1.10 christos 4436 1.10 christos /* Bit-21 is used for RC */ 4437 1.10 christos switch (ext & 0x3ff) 4438 1.3 christos { 4439 1.3 christos case 5: /* Vector Rotate Left Quadword */ 4440 1.3 christos case 69: /* Vector Rotate Left Quadword then Mask Insert */ 4441 1.3 christos case 325: /* Vector Rotate Left Quadword then AND with Mask */ 4442 1.3 christos case 6: /* Vector Compare Equal To Unsigned Byte */ 4443 1.3 christos case 70: /* Vector Compare Equal To Unsigned Halfword */ 4444 1.3 christos case 134: /* Vector Compare Equal To Unsigned Word */ 4445 1.3 christos case 199: /* Vector Compare Equal To Unsigned Doubleword */ 4446 1.10 christos case 774: /* Vector Compare Greater Than Signed Byte */ 4447 1.3 christos case 838: /* Vector Compare Greater Than Signed Halfword */ 4448 1.3 christos case 902: /* Vector Compare Greater Than Signed Word */ 4449 1.3 christos case 967: /* Vector Compare Greater Than Signed Doubleword */ 4450 1.3 christos case 903: /* Vector Compare Greater Than Signed Quadword */ 4451 1.10 christos case 518: /* Vector Compare Greater Than Unsigned Byte */ 4452 1.3 christos case 646: /* Vector Compare Greater Than Unsigned Word */ 4453 1.3 christos case 582: /* Vector Compare Greater Than Unsigned Halfword */ 4454 1.3 christos case 711: /* Vector Compare Greater Than Unsigned Doubleword */ 4455 1.10 christos case 647: /* Vector Compare Greater Than Unsigned Quadword */ 4456 1.3 christos case 966: /* Vector Compare Bounds Single-Precision */ 4457 1.7 christos case 198: /* Vector Compare Equal To Single-Precision */ 4458 1.7 christos case 454: /* Vector Compare Greater Than or Equal To Single-Precision */ 4459 1.7 christos case 455: /* Vector Compare Equal Quadword */ 4460 1.7 christos case 710: /* Vector Compare Greater Than Single-Precision */ 4461 1.7 christos case 7: /* Vector Compare Not Equal Byte */ 4462 1.7 christos case 71: /* Vector Compare Not Equal Halfword */ 4463 1.3 christos case 135: /* Vector Compare Not Equal Word */ 4464 1.3 christos case 263: /* Vector Compare Not Equal or Zero Byte */ 4465 1.3 christos case 327: /* Vector Compare Not Equal or Zero Halfword */ 4466 1.3 christos case 391: /* Vector Compare Not Equal or Zero Word */ 4467 1.3 christos if (PPC_Rc (insn)) 4468 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 4469 1.10 christos record_full_arch_list_add_reg (regcache, 4470 1.10 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4471 1.10 christos return 0; 4472 1.10 christos 4473 1.10 christos case 13: 4474 1.10 christos switch (vra) /* Bit-21 is used for RC */ 4475 1.10 christos { 4476 1.10 christos case 0: /* Vector String Isolate Byte Left-justified */ 4477 1.10 christos case 1: /* Vector String Isolate Byte Right-justified */ 4478 1.10 christos case 2: /* Vector String Isolate Halfword Left-justified */ 4479 1.10 christos case 3: /* Vector String Isolate Halfword Right-justified */ 4480 1.10 christos if (PPC_Rc (insn)) 4481 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 4482 1.10 christos record_full_arch_list_add_reg (regcache, 4483 1.3 christos tdep->ppc_vr0_regnum 4484 1.3 christos + PPC_VRT (insn)); 4485 1.7 christos return 0; 4486 1.7 christos } 4487 1.7 christos } 4488 1.7 christos 4489 1.7 christos if (ext == 1538) 4490 1.7 christos { 4491 1.7 christos switch (vra) 4492 1.7 christos { 4493 1.7 christos case 0: /* Vector Count Leading Zero Least-Significant Bits 4494 1.7 christos Byte */ 4495 1.7 christos case 1: /* Vector Count Trailing Zero Least-Significant Bits 4496 1.7 christos Byte */ 4497 1.7 christos record_full_arch_list_add_reg (regcache, 4498 1.7 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 4499 1.7 christos return 0; 4500 1.7 christos 4501 1.7 christos case 6: /* Vector Negate Word */ 4502 1.7 christos case 7: /* Vector Negate Doubleword */ 4503 1.7 christos case 8: /* Vector Parity Byte Word */ 4504 1.7 christos case 9: /* Vector Parity Byte Doubleword */ 4505 1.7 christos case 10: /* Vector Parity Byte Quadword */ 4506 1.7 christos case 16: /* Vector Extend Sign Byte To Word */ 4507 1.10 christos case 17: /* Vector Extend Sign Halfword To Word */ 4508 1.7 christos case 24: /* Vector Extend Sign Byte To Doubleword */ 4509 1.7 christos case 25: /* Vector Extend Sign Halfword To Doubleword */ 4510 1.7 christos case 26: /* Vector Extend Sign Word To Doubleword */ 4511 1.7 christos case 27: /* Vector Extend Sign Doubleword To Quadword */ 4512 1.7 christos case 28: /* Vector Count Trailing Zeros Byte */ 4513 1.7 christos case 29: /* Vector Count Trailing Zeros Halfword */ 4514 1.7 christos case 30: /* Vector Count Trailing Zeros Word */ 4515 1.7 christos case 31: /* Vector Count Trailing Zeros Doubleword */ 4516 1.7 christos record_full_arch_list_add_reg (regcache, 4517 1.7 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4518 1.10 christos return 0; 4519 1.10 christos } 4520 1.10 christos } 4521 1.10 christos 4522 1.10 christos if (ext == 1602) 4523 1.10 christos { 4524 1.10 christos switch (vra) 4525 1.10 christos { 4526 1.10 christos case 0: /* Vector Expand Byte Mask */ 4527 1.10 christos case 1: /* Vector Expand Halfword Mask */ 4528 1.10 christos case 2: /* Vector Expand Word Mask */ 4529 1.10 christos case 3: /* Vector Expand Doubleword Mask */ 4530 1.10 christos case 4: /* Vector Expand Quadword Mask */ 4531 1.10 christos case 16: /* Move to VSR Byte Mask */ 4532 1.10 christos case 17: /* Move to VSR Halfword Mask */ 4533 1.10 christos case 18: /* Move to VSR Word Mask */ 4534 1.10 christos case 19: /* Move to VSR Doubleword Mask */ 4535 1.10 christos case 20: /* Move to VSR Quadword Mask */ 4536 1.10 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 4537 1.10 christos return 0; 4538 1.10 christos 4539 1.10 christos case 8: /* Vector Extract Byte Mask */ 4540 1.10 christos case 9: /* Vector Extract Halfword Mask */ 4541 1.10 christos case 10: /* Vector Extract Word Mask */ 4542 1.10 christos case 11: /* Vector Extract Doubleword Mask */ 4543 1.10 christos case 12: /* Vector Extract Quadword Mask */ 4544 1.10 christos 4545 1.10 christos /* Ignore the MP bit in the LSB position of the vra value. */ 4546 1.10 christos case 24: /* Vector Count Mask Bits Byte, MP = 0 */ 4547 1.10 christos case 25: /* Vector Count Mask Bits Byte, MP = 1 */ 4548 1.10 christos case 26: /* Vector Count Mask Bits Halfword, MP = 0 */ 4549 1.10 christos case 27: /* Vector Count Mask Bits Halfword, MP = 1 */ 4550 1.10 christos case 28: /* Vector Count Mask Bits Word, MP = 0 */ 4551 1.10 christos case 29: /* Vector Count Mask Bits Word, MP = 1 */ 4552 1.10 christos case 30: /* Vector Count Mask Bits Doubleword, MP = 0 */ 4553 1.10 christos case 31: /* Vector Count Mask Bits Doubleword, MP = 1 */ 4554 1.10 christos record_full_arch_list_add_reg (regcache, 4555 1.10 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 4556 1.10 christos record_full_arch_list_add_reg (regcache, 4557 1.10 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 4558 1.3 christos return 0; 4559 1.3 christos } 4560 1.10 christos } 4561 1.10 christos 4562 1.10 christos switch (ext) 4563 1.10 christos { 4564 1.10 christos 4565 1.10 christos case 257: /* Vector Compare Unsigned Quadword */ 4566 1.10 christos case 321: /* Vector Compare Signed Quadword */ 4567 1.10 christos /* Comparison tests that always set CR field BF */ 4568 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 4569 1.3 christos record_full_arch_list_add_reg (regcache, 4570 1.3 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4571 1.3 christos return 0; 4572 1.3 christos 4573 1.3 christos case 142: /* Vector Pack Unsigned Halfword Unsigned Saturate */ 4574 1.3 christos case 206: /* Vector Pack Unsigned Word Unsigned Saturate */ 4575 1.3 christos case 270: /* Vector Pack Signed Halfword Unsigned Saturate */ 4576 1.3 christos case 334: /* Vector Pack Signed Word Unsigned Saturate */ 4577 1.3 christos case 398: /* Vector Pack Signed Halfword Signed Saturate */ 4578 1.3 christos case 462: /* Vector Pack Signed Word Signed Saturate */ 4579 1.3 christos case 1230: /* Vector Pack Unsigned Doubleword Unsigned Saturate */ 4580 1.3 christos case 1358: /* Vector Pack Signed Doubleword Unsigned Saturate */ 4581 1.3 christos case 1486: /* Vector Pack Signed Doubleword Signed Saturate */ 4582 1.3 christos case 512: /* Vector Add Unsigned Byte Saturate */ 4583 1.3 christos case 576: /* Vector Add Unsigned Halfword Saturate */ 4584 1.3 christos case 640: /* Vector Add Unsigned Word Saturate */ 4585 1.3 christos case 768: /* Vector Add Signed Byte Saturate */ 4586 1.3 christos case 832: /* Vector Add Signed Halfword Saturate */ 4587 1.3 christos case 896: /* Vector Add Signed Word Saturate */ 4588 1.3 christos case 1536: /* Vector Subtract Unsigned Byte Saturate */ 4589 1.3 christos case 1600: /* Vector Subtract Unsigned Halfword Saturate */ 4590 1.3 christos case 1664: /* Vector Subtract Unsigned Word Saturate */ 4591 1.3 christos case 1792: /* Vector Subtract Signed Byte Saturate */ 4592 1.3 christos case 1856: /* Vector Subtract Signed Halfword Saturate */ 4593 1.3 christos case 1920: /* Vector Subtract Signed Word Saturate */ 4594 1.3 christos 4595 1.3 christos case 1544: /* Vector Sum across Quarter Unsigned Byte Saturate */ 4596 1.3 christos case 1800: /* Vector Sum across Quarter Signed Byte Saturate */ 4597 1.3 christos case 1608: /* Vector Sum across Quarter Signed Halfword Saturate */ 4598 1.3 christos case 1672: /* Vector Sum across Half Signed Word Saturate */ 4599 1.11 christos case 1928: /* Vector Sum across Signed Word Saturate */ 4600 1.3 christos case 970: /* Vector Convert To Signed Fixed-Point Word Saturate */ 4601 1.3 christos case 906: /* Vector Convert To Unsigned Fixed-Point Word Saturate */ 4602 1.3 christos record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM); 4603 1.3 christos [[fallthrough]]; 4604 1.3 christos case 12: /* Vector Merge High Byte */ 4605 1.3 christos case 14: /* Vector Pack Unsigned Halfword Unsigned Modulo */ 4606 1.3 christos case 76: /* Vector Merge High Halfword */ 4607 1.3 christos case 78: /* Vector Pack Unsigned Word Unsigned Modulo */ 4608 1.10 christos case 140: /* Vector Merge High Word */ 4609 1.10 christos case 268: /* Vector Merge Low Byte */ 4610 1.3 christos case 332: /* Vector Merge Low Halfword */ 4611 1.3 christos case 396: /* Vector Merge Low Word */ 4612 1.3 christos case 397: /* Vector Clear Leftmost Bytes */ 4613 1.3 christos case 461: /* Vector Clear Rightmost Bytes */ 4614 1.3 christos case 526: /* Vector Unpack High Signed Byte */ 4615 1.3 christos case 590: /* Vector Unpack High Signed Halfword */ 4616 1.3 christos case 654: /* Vector Unpack Low Signed Byte */ 4617 1.3 christos case 718: /* Vector Unpack Low Signed Halfword */ 4618 1.3 christos case 782: /* Vector Pack Pixel */ 4619 1.3 christos case 846: /* Vector Unpack High Pixel */ 4620 1.3 christos case 974: /* Vector Unpack Low Pixel */ 4621 1.3 christos case 1102: /* Vector Pack Unsigned Doubleword Unsigned Modulo */ 4622 1.3 christos case 1614: /* Vector Unpack High Signed Word */ 4623 1.3 christos case 1676: /* Vector Merge Odd Word */ 4624 1.3 christos case 1742: /* Vector Unpack Low Signed Word */ 4625 1.3 christos case 1932: /* Vector Merge Even Word */ 4626 1.3 christos case 524: /* Vector Splat Byte */ 4627 1.3 christos case 588: /* Vector Splat Halfword */ 4628 1.10 christos case 652: /* Vector Splat Word */ 4629 1.3 christos case 780: /* Vector Splat Immediate Signed Byte */ 4630 1.10 christos case 844: /* Vector Splat Immediate Signed Halfword */ 4631 1.3 christos case 908: /* Vector Splat Immediate Signed Word */ 4632 1.10 christos case 261: /* Vector Shift Left Quadword */ 4633 1.3 christos case 452: /* Vector Shift Left */ 4634 1.3 christos case 517: /* Vector Shift Right Quadword */ 4635 1.3 christos case 708: /* Vector Shift Right */ 4636 1.3 christos case 773: /* Vector Shift Right Algebraic Quadword */ 4637 1.3 christos case 1036: /* Vector Shift Left by Octet */ 4638 1.3 christos case 1100: /* Vector Shift Right by Octet */ 4639 1.3 christos case 0: /* Vector Add Unsigned Byte Modulo */ 4640 1.3 christos case 64: /* Vector Add Unsigned Halfword Modulo */ 4641 1.3 christos case 128: /* Vector Add Unsigned Word Modulo */ 4642 1.3 christos case 192: /* Vector Add Unsigned Doubleword Modulo */ 4643 1.3 christos case 256: /* Vector Add Unsigned Quadword Modulo */ 4644 1.3 christos case 320: /* Vector Add & write Carry Unsigned Quadword */ 4645 1.10 christos case 384: /* Vector Add and Write Carry-Out Unsigned Word */ 4646 1.3 christos case 8: /* Vector Multiply Odd Unsigned Byte */ 4647 1.3 christos case 72: /* Vector Multiply Odd Unsigned Halfword */ 4648 1.3 christos case 136: /* Vector Multiply Odd Unsigned Word */ 4649 1.10 christos case 200: /* Vector Multiply Odd Unsigned Doubleword */ 4650 1.3 christos case 264: /* Vector Multiply Odd Signed Byte */ 4651 1.3 christos case 328: /* Vector Multiply Odd Signed Halfword */ 4652 1.3 christos case 392: /* Vector Multiply Odd Signed Word */ 4653 1.10 christos case 456: /* Vector Multiply Odd Signed Doubleword */ 4654 1.3 christos case 520: /* Vector Multiply Even Unsigned Byte */ 4655 1.3 christos case 584: /* Vector Multiply Even Unsigned Halfword */ 4656 1.3 christos case 648: /* Vector Multiply Even Unsigned Word */ 4657 1.10 christos case 712: /* Vector Multiply Even Unsigned Doubleword */ 4658 1.10 christos case 776: /* Vector Multiply Even Signed Byte */ 4659 1.10 christos case 840: /* Vector Multiply Even Signed Halfword */ 4660 1.10 christos case 904: /* Vector Multiply Even Signed Word */ 4661 1.10 christos case 968: /* Vector Multiply Even Signed Doubleword */ 4662 1.10 christos case 457: /* Vector Multiply Low Doubleword */ 4663 1.10 christos case 649: /* Vector Multiply High Unsigned Word */ 4664 1.10 christos case 713: /* Vector Multiply High Unsigned Doubleword */ 4665 1.10 christos case 905: /* Vector Multiply High Signed Word */ 4666 1.10 christos case 969: /* Vector Multiply High Signed Doubleword */ 4667 1.10 christos case 11: /* Vector Divide Unsigned Quadword */ 4668 1.10 christos case 203: /* Vector Divide Unsigned Doubleword */ 4669 1.10 christos case 139: /* Vector Divide Unsigned Word */ 4670 1.10 christos case 267: /* Vector Divide Signed Quadword */ 4671 1.10 christos case 459: /* Vector Divide Signed Doubleword */ 4672 1.10 christos case 395: /* Vector Divide Signed Word */ 4673 1.10 christos case 523: /* Vector Divide Extended Unsigned Quadword */ 4674 1.10 christos case 715: /* Vector Divide Extended Unsigned Doubleword */ 4675 1.10 christos case 651: /* Vector Divide Extended Unsigned Word */ 4676 1.10 christos case 779: /* Vector Divide Extended Signed Quadword */ 4677 1.10 christos case 971: /* Vector Divide Extended Signed Doubleword */ 4678 1.10 christos case 907: /* Vector Divide Extended Unsigned Word */ 4679 1.10 christos case 1547: /* Vector Modulo Unsigned Quadword */ 4680 1.10 christos case 1675: /* Vector Modulo Unsigned Word */ 4681 1.10 christos case 1739: /* Vector Modulo Unsigned Doubleword */ 4682 1.3 christos case 1803: /* Vector Modulo Signed Quadword */ 4683 1.3 christos case 1931: /* Vector Modulo Signed Word */ 4684 1.3 christos case 1995: /* Vector Modulo Signed Doubleword */ 4685 1.3 christos 4686 1.3 christos case 137: /* Vector Multiply Unsigned Word Modulo */ 4687 1.3 christos case 1024: /* Vector Subtract Unsigned Byte Modulo */ 4688 1.3 christos case 1088: /* Vector Subtract Unsigned Halfword Modulo */ 4689 1.3 christos case 1152: /* Vector Subtract Unsigned Word Modulo */ 4690 1.3 christos case 1216: /* Vector Subtract Unsigned Doubleword Modulo */ 4691 1.3 christos case 1280: /* Vector Subtract Unsigned Quadword Modulo */ 4692 1.3 christos case 1344: /* Vector Subtract & write Carry Unsigned Quadword */ 4693 1.3 christos case 1408: /* Vector Subtract and Write Carry-Out Unsigned Word */ 4694 1.3 christos case 1282: /* Vector Average Signed Byte */ 4695 1.3 christos case 1346: /* Vector Average Signed Halfword */ 4696 1.3 christos case 1410: /* Vector Average Signed Word */ 4697 1.3 christos case 1026: /* Vector Average Unsigned Byte */ 4698 1.3 christos case 1090: /* Vector Average Unsigned Halfword */ 4699 1.3 christos case 1154: /* Vector Average Unsigned Word */ 4700 1.3 christos case 258: /* Vector Maximum Signed Byte */ 4701 1.3 christos case 322: /* Vector Maximum Signed Halfword */ 4702 1.3 christos case 386: /* Vector Maximum Signed Word */ 4703 1.3 christos case 450: /* Vector Maximum Signed Doubleword */ 4704 1.3 christos case 2: /* Vector Maximum Unsigned Byte */ 4705 1.3 christos case 66: /* Vector Maximum Unsigned Halfword */ 4706 1.3 christos case 130: /* Vector Maximum Unsigned Word */ 4707 1.3 christos case 194: /* Vector Maximum Unsigned Doubleword */ 4708 1.3 christos case 770: /* Vector Minimum Signed Byte */ 4709 1.3 christos case 834: /* Vector Minimum Signed Halfword */ 4710 1.3 christos case 898: /* Vector Minimum Signed Word */ 4711 1.3 christos case 962: /* Vector Minimum Signed Doubleword */ 4712 1.3 christos case 514: /* Vector Minimum Unsigned Byte */ 4713 1.3 christos case 578: /* Vector Minimum Unsigned Halfword */ 4714 1.3 christos case 642: /* Vector Minimum Unsigned Word */ 4715 1.3 christos case 706: /* Vector Minimum Unsigned Doubleword */ 4716 1.3 christos case 1028: /* Vector Logical AND */ 4717 1.3 christos case 1668: /* Vector Logical Equivalent */ 4718 1.3 christos case 1092: /* Vector Logical AND with Complement */ 4719 1.3 christos case 1412: /* Vector Logical NAND */ 4720 1.3 christos case 1348: /* Vector Logical OR with Complement */ 4721 1.3 christos case 1156: /* Vector Logical OR */ 4722 1.3 christos case 1284: /* Vector Logical NOR */ 4723 1.3 christos case 1220: /* Vector Logical XOR */ 4724 1.3 christos case 4: /* Vector Rotate Left Byte */ 4725 1.3 christos case 132: /* Vector Rotate Left Word VX-form */ 4726 1.3 christos case 68: /* Vector Rotate Left Halfword */ 4727 1.3 christos case 196: /* Vector Rotate Left Doubleword */ 4728 1.3 christos case 260: /* Vector Shift Left Byte */ 4729 1.3 christos case 388: /* Vector Shift Left Word */ 4730 1.3 christos case 324: /* Vector Shift Left Halfword */ 4731 1.3 christos case 1476: /* Vector Shift Left Doubleword */ 4732 1.3 christos case 516: /* Vector Shift Right Byte */ 4733 1.3 christos case 644: /* Vector Shift Right Word */ 4734 1.3 christos case 580: /* Vector Shift Right Halfword */ 4735 1.3 christos case 1732: /* Vector Shift Right Doubleword */ 4736 1.3 christos case 772: /* Vector Shift Right Algebraic Byte */ 4737 1.3 christos case 900: /* Vector Shift Right Algebraic Word */ 4738 1.3 christos case 836: /* Vector Shift Right Algebraic Halfword */ 4739 1.3 christos case 964: /* Vector Shift Right Algebraic Doubleword */ 4740 1.3 christos case 10: /* Vector Add Single-Precision */ 4741 1.3 christos case 74: /* Vector Subtract Single-Precision */ 4742 1.3 christos case 1034: /* Vector Maximum Single-Precision */ 4743 1.3 christos case 1098: /* Vector Minimum Single-Precision */ 4744 1.3 christos case 842: /* Vector Convert From Signed Fixed-Point Word */ 4745 1.3 christos case 778: /* Vector Convert From Unsigned Fixed-Point Word */ 4746 1.3 christos case 714: /* Vector Round to Single-Precision Integer toward -Infinity */ 4747 1.3 christos case 522: /* Vector Round to Single-Precision Integer Nearest */ 4748 1.3 christos case 650: /* Vector Round to Single-Precision Integer toward +Infinity */ 4749 1.3 christos case 586: /* Vector Round to Single-Precision Integer toward Zero */ 4750 1.3 christos case 394: /* Vector 2 Raised to the Exponent Estimate Floating-Point */ 4751 1.3 christos case 458: /* Vector Log Base 2 Estimate Floating-Point */ 4752 1.3 christos case 266: /* Vector Reciprocal Estimate Single-Precision */ 4753 1.3 christos case 330: /* Vector Reciprocal Square Root Estimate Single-Precision */ 4754 1.3 christos case 1288: /* Vector AES Cipher */ 4755 1.3 christos case 1289: /* Vector AES Cipher Last */ 4756 1.3 christos case 1352: /* Vector AES Inverse Cipher */ 4757 1.3 christos case 1353: /* Vector AES Inverse Cipher Last */ 4758 1.3 christos case 1480: /* Vector AES SubBytes */ 4759 1.3 christos case 1730: /* Vector SHA-512 Sigma Doubleword */ 4760 1.3 christos case 1666: /* Vector SHA-256 Sigma Word */ 4761 1.3 christos case 1032: /* Vector Polynomial Multiply-Sum Byte */ 4762 1.3 christos case 1160: /* Vector Polynomial Multiply-Sum Word */ 4763 1.3 christos case 1096: /* Vector Polynomial Multiply-Sum Halfword */ 4764 1.3 christos case 1224: /* Vector Polynomial Multiply-Sum Doubleword */ 4765 1.10 christos case 1292: /* Vector Gather Bits by Bytes by Doubleword */ 4766 1.10 christos case 1794: /* Vector Count Leading Zeros Byte */ 4767 1.3 christos case 1858: /* Vector Count Leading Zeros Halfword */ 4768 1.10 christos case 1922: /* Vector Count Leading Zeros Word */ 4769 1.10 christos case 1924: /* Vector Count Leading Zeros Doubleword under 4770 1.3 christos bit Mask*/ 4771 1.3 christos case 1986: /* Vector Count Leading Zeros Doubleword */ 4772 1.3 christos case 1988: /* Vector Count Trailing Zeros Doubleword under bit 4773 1.3 christos Mask */ 4774 1.3 christos case 1795: /* Vector Population Count Byte */ 4775 1.7 christos case 1859: /* Vector Population Count Halfword */ 4776 1.7 christos case 1923: /* Vector Population Count Word */ 4777 1.7 christos case 1987: /* Vector Population Count Doubleword */ 4778 1.7 christos case 1356: /* Vector Bit Permute Quadword */ 4779 1.7 christos case 1484: /* Vector Bit Permute Doubleword */ 4780 1.7 christos case 513: /* Vector Multiply-by-10 Unsigned Quadword */ 4781 1.7 christos case 1: /* Vector Multiply-by-10 & write Carry Unsigned 4782 1.7 christos Quadword */ 4783 1.7 christos case 577: /* Vector Multiply-by-10 Extended Unsigned Quadword */ 4784 1.7 christos case 65: /* Vector Multiply-by-10 Extended & write Carry 4785 1.7 christos Unsigned Quadword */ 4786 1.7 christos case 1027: /* Vector Absolute Difference Unsigned Byte */ 4787 1.7 christos case 1091: /* Vector Absolute Difference Unsigned Halfword */ 4788 1.7 christos case 1155: /* Vector Absolute Difference Unsigned Word */ 4789 1.7 christos case 1796: /* Vector Shift Right Variable */ 4790 1.7 christos case 1860: /* Vector Shift Left Variable */ 4791 1.7 christos case 133: /* Vector Rotate Left Word then Mask Insert */ 4792 1.7 christos case 197: /* Vector Rotate Left Doubleword then Mask Insert */ 4793 1.7 christos case 389: /* Vector Rotate Left Word then AND with Mask */ 4794 1.7 christos case 453: /* Vector Rotate Left Doubleword then AND with Mask */ 4795 1.10 christos case 525: /* Vector Extract Unsigned Byte */ 4796 1.10 christos case 589: /* Vector Extract Unsigned Halfword */ 4797 1.10 christos case 653: /* Vector Extract Unsigned Word */ 4798 1.10 christos case 717: /* Vector Extract Doubleword */ 4799 1.10 christos case 15: /* Vector Insert Byte from VSR using GPR-specified 4800 1.10 christos Left-Index */ 4801 1.10 christos case 79: /* Vector Insert Halfword from VSR using GPR-specified 4802 1.10 christos Left-Index */ 4803 1.10 christos case 143: /* Vector Insert Word from VSR using GPR-specified 4804 1.10 christos Left-Index */ 4805 1.10 christos case 207: /* Vector Insert Word from GPR using 4806 1.10 christos immediate-specified index */ 4807 1.10 christos case 463: /* Vector Insert Doubleword from GPR using 4808 1.10 christos immediate-specified index */ 4809 1.10 christos case 271: /* Vector Insert Byte from VSR using GPR-specified 4810 1.10 christos Right-Index */ 4811 1.10 christos case 335: /* Vector Insert Halfword from VSR using GPR-specified 4812 1.10 christos Right-Index */ 4813 1.10 christos case 399: /* Vector Insert Word from VSR using GPR-specified 4814 1.10 christos Right-Index */ 4815 1.10 christos case 527: /* Vector Insert Byte from GPR using GPR-specified 4816 1.10 christos Left-Index */ 4817 1.10 christos case 591: /* Vector Insert Halfword from GPR using GPR-specified 4818 1.10 christos Left-Index */ 4819 1.10 christos case 655: /* Vector Insert Word from GPR using GPR-specified 4820 1.10 christos Left-Index */ 4821 1.10 christos case 719: /* Vector Insert Doubleword from GPR using 4822 1.10 christos GPR-specified Left-Index */ 4823 1.10 christos case 783: /* Vector Insert Byte from GPR using GPR-specified 4824 1.10 christos Right-Index */ 4825 1.10 christos case 847: /* Vector Insert Halfword from GPR using GPR-specified 4826 1.10 christos Left-Index */ 4827 1.7 christos case 911: /* Vector Insert Word from GPR using GPR-specified 4828 1.7 christos Left-Index */ 4829 1.7 christos case 975: /* Vector Insert Doubleword from GPR using 4830 1.7 christos GPR-specified Right-Index */ 4831 1.10 christos case 781: /* Vector Insert Byte */ 4832 1.10 christos case 845: /* Vector Insert Halfword */ 4833 1.10 christos case 909: /* Vector Insert Word */ 4834 1.3 christos case 973: /* Vector Insert Doubleword */ 4835 1.3 christos case 1357: /* Vector Centrifuge Doubleword */ 4836 1.3 christos case 1421: /* Vector Parallel Bits Extract Doubleword */ 4837 1.3 christos case 1485: /* Vector Parallel Bits Deposit Doubleword */ 4838 1.10 christos record_full_arch_list_add_reg (regcache, 4839 1.7 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4840 1.7 christos return 0; 4841 1.7 christos 4842 1.7 christos case 1228: /* Vector Gather every Nth Bit */ 4843 1.7 christos case 1549: /* Vector Extract Unsigned Byte Left-Indexed */ 4844 1.7 christos case 1613: /* Vector Extract Unsigned Halfword Left-Indexed */ 4845 1.7 christos case 1677: /* Vector Extract Unsigned Word Left-Indexed */ 4846 1.7 christos case 1805: /* Vector Extract Unsigned Byte Right-Indexed */ 4847 1.7 christos case 1869: /* Vector Extract Unsigned Halfword Right-Indexed */ 4848 1.7 christos case 1933: /* Vector Extract Unsigned Word Right-Indexed */ 4849 1.3 christos record_full_arch_list_add_reg (regcache, 4850 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 4851 1.3 christos return 0; 4852 1.3 christos 4853 1.3 christos case 1604: /* Move To Vector Status and Control Register */ 4854 1.3 christos record_full_arch_list_add_reg (regcache, PPC_VSCR_REGNUM); 4855 1.3 christos return 0; 4856 1.7 christos case 1540: /* Move From Vector Status and Control Register */ 4857 1.7 christos record_full_arch_list_add_reg (regcache, 4858 1.7 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4859 1.7 christos return 0; 4860 1.7 christos case 833: /* Decimal Copy Sign */ 4861 1.3 christos record_full_arch_list_add_reg (regcache, 4862 1.3 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 4863 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 4864 1.10 christos return 0; 4865 1.10 christos } 4866 1.10 christos 4867 1.10 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 4868 1.10 christos "at %s, 4-%d.\n", insn, paddress (gdbarch, addr), ext); 4869 1.10 christos return -1; 4870 1.10 christos } 4871 1.10 christos 4872 1.10 christos /* Parse and record instructions of primary opcode 6 at ADDR. 4873 1.10 christos Return 0 if successful. */ 4874 1.10 christos 4875 1.10 christos static int 4876 1.10 christos ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache, 4877 1.10 christos CORE_ADDR addr, uint32_t insn) 4878 1.10 christos { 4879 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 4880 1.10 christos int subtype = PPC_FIELD (insn, 28, 4); 4881 1.10 christos CORE_ADDR ea = 0; 4882 1.10 christos 4883 1.10 christos switch (subtype) 4884 1.10 christos { 4885 1.10 christos case 0: /* Load VSX Vector Paired */ 4886 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XTp (insn)); 4887 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XTp (insn) + 1); 4888 1.10 christos return 0; 4889 1.10 christos case 1: /* Store VSX Vector Paired */ 4890 1.10 christos if (PPC_RA (insn) != 0) 4891 1.10 christos regcache_raw_read_unsigned (regcache, 4892 1.10 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ea); 4893 1.3 christos ea += PPC_DQ (insn) << 4; 4894 1.3 christos record_full_arch_list_add_mem (ea, 32); 4895 1.3 christos return 0; 4896 1.3 christos } 4897 1.3 christos return -1; 4898 1.3 christos } 4899 1.3 christos 4900 1.3 christos /* Parse and record instructions of primary opcode-19 at ADDR. 4901 1.3 christos Return 0 if successful. */ 4902 1.3 christos 4903 1.10 christos static int 4904 1.3 christos ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache, 4905 1.3 christos CORE_ADDR addr, uint32_t insn) 4906 1.7 christos { 4907 1.7 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 4908 1.7 christos int ext = PPC_EXTOP (insn); 4909 1.7 christos 4910 1.7 christos switch (ext & 0x01f) 4911 1.7 christos { 4912 1.7 christos case 2: /* Add PC Immediate Shifted */ 4913 1.7 christos record_full_arch_list_add_reg (regcache, 4914 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 4915 1.3 christos return 0; 4916 1.3 christos } 4917 1.3 christos 4918 1.3 christos switch (ext) 4919 1.3 christos { 4920 1.3 christos case 0: /* Move Condition Register Field */ 4921 1.3 christos case 33: /* Condition Register NOR */ 4922 1.3 christos case 129: /* Condition Register AND with Complement */ 4923 1.3 christos case 193: /* Condition Register XOR */ 4924 1.3 christos case 225: /* Condition Register NAND */ 4925 1.3 christos case 257: /* Condition Register AND */ 4926 1.3 christos case 289: /* Condition Register Equivalent */ 4927 1.3 christos case 417: /* Condition Register OR with Complement */ 4928 1.3 christos case 449: /* Condition Register OR */ 4929 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 4930 1.3 christos return 0; 4931 1.3 christos 4932 1.11 christos case 16: /* Branch Conditional */ 4933 1.3 christos case 560: /* Branch Conditional to Branch Target Address Register */ 4934 1.3 christos if ((PPC_BO (insn) & 0x4) == 0) 4935 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum); 4936 1.3 christos [[fallthrough]]; 4937 1.3 christos case 528: /* Branch Conditional to Count Register */ 4938 1.3 christos if (PPC_LK (insn)) 4939 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum); 4940 1.3 christos return 0; 4941 1.3 christos 4942 1.3 christos case 150: /* Instruction Synchronize */ 4943 1.10 christos /* Do nothing. */ 4944 1.10 christos return 0; 4945 1.10 christos } 4946 1.10 christos 4947 1.10 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 4948 1.10 christos "at %s, 19-%d.\n", insn, paddress (gdbarch, addr), ext); 4949 1.10 christos return -1; 4950 1.10 christos } 4951 1.10 christos 4952 1.10 christos /* Parse and record instructions of primary opcode-31 with the extended opcode 4953 1.10 christos 177. The argument is the word instruction (insn). Return 0 if successful. 4954 1.10 christos */ 4955 1.10 christos 4956 1.10 christos static int 4957 1.10 christos ppc_process_record_op31_177 (struct gdbarch *gdbarch, 4958 1.10 christos struct regcache *regcache, 4959 1.10 christos uint32_t insn) 4960 1.10 christos { 4961 1.10 christos int RA_opcode = PPC_RA(insn); 4962 1.10 christos int as = PPC_FIELD (insn, 6, 3); 4963 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 4964 1.10 christos 4965 1.10 christos switch (RA_opcode) 4966 1.10 christos { 4967 1.10 christos case 0: /* VSX Move From Accumulator, xxmfacc */ 4968 1.10 christos case 1: /* VSX Move To Accumulator, xxmtacc */ 4969 1.3 christos case 3: /* VSX Set Accumulator to Zero, xxsetaccz */ 4970 1.3 christos ppc_record_ACC_fpscr (regcache, tdep, as, false); 4971 1.3 christos return 0; 4972 1.3 christos } 4973 1.3 christos return -1; 4974 1.3 christos } 4975 1.3 christos 4976 1.3 christos /* Parse and record instructions of primary opcode-31 at ADDR. 4977 1.3 christos Return 0 if successful. */ 4978 1.3 christos 4979 1.10 christos static int 4980 1.3 christos ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache, 4981 1.10 christos CORE_ADDR addr, uint32_t insn) 4982 1.3 christos { 4983 1.3 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 4984 1.3 christos int ext = PPC_EXTOP (insn); 4985 1.3 christos int tmp, nr, nb = 0, i; 4986 1.3 christos CORE_ADDR at_dcsz, ea = 0; 4987 1.3 christos ULONGEST rb, ra, xer; 4988 1.3 christos int size = 0; 4989 1.3 christos 4990 1.3 christos /* These instructions have OE bit. */ 4991 1.3 christos switch (ext & 0x1ff) 4992 1.3 christos { 4993 1.3 christos /* These write RT and XER. Update CR if RC is set. */ 4994 1.3 christos case 8: /* Subtract from carrying */ 4995 1.3 christos case 10: /* Add carrying */ 4996 1.3 christos case 136: /* Subtract from extended */ 4997 1.3 christos case 138: /* Add extended */ 4998 1.3 christos case 200: /* Subtract from zero extended */ 4999 1.3 christos case 202: /* Add to zero extended */ 5000 1.3 christos case 232: /* Subtract from minus one extended */ 5001 1.3 christos case 234: /* Add to minus one extended */ 5002 1.3 christos /* CA is always altered, but SO/OV are only altered when OE=1. 5003 1.3 christos In any case, XER is always altered. */ 5004 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5005 1.3 christos if (PPC_RC (insn)) 5006 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5007 1.3 christos record_full_arch_list_add_reg (regcache, 5008 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5009 1.3 christos return 0; 5010 1.3 christos 5011 1.3 christos /* These write RT. Update CR if RC is set and update XER if OE is set. */ 5012 1.3 christos case 40: /* Subtract from */ 5013 1.3 christos case 104: /* Negate */ 5014 1.3 christos case 233: /* Multiply low doubleword */ 5015 1.3 christos case 235: /* Multiply low word */ 5016 1.3 christos case 266: /* Add */ 5017 1.3 christos case 393: /* Divide Doubleword Extended Unsigned */ 5018 1.3 christos case 395: /* Divide Word Extended Unsigned */ 5019 1.3 christos case 425: /* Divide Doubleword Extended */ 5020 1.3 christos case 427: /* Divide Word Extended */ 5021 1.3 christos case 457: /* Divide Doubleword Unsigned */ 5022 1.3 christos case 459: /* Divide Word Unsigned */ 5023 1.11 christos case 489: /* Divide Doubleword */ 5024 1.3 christos case 491: /* Divide Word */ 5025 1.3 christos if (PPC_OE (insn)) 5026 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5027 1.3 christos [[fallthrough]]; 5028 1.3 christos case 9: /* Multiply High Doubleword Unsigned */ 5029 1.3 christos case 11: /* Multiply High Word Unsigned */ 5030 1.3 christos case 73: /* Multiply High Doubleword */ 5031 1.3 christos case 75: /* Multiply High Word */ 5032 1.3 christos if (PPC_RC (insn)) 5033 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5034 1.3 christos record_full_arch_list_add_reg (regcache, 5035 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5036 1.3 christos return 0; 5037 1.3 christos } 5038 1.3 christos 5039 1.3 christos if ((ext & 0x1f) == 15) 5040 1.3 christos { 5041 1.3 christos /* Integer Select. bit[16:20] is used for BC. */ 5042 1.3 christos record_full_arch_list_add_reg (regcache, 5043 1.7 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5044 1.7 christos return 0; 5045 1.7 christos } 5046 1.7 christos 5047 1.7 christos if ((ext & 0xff) == 170) 5048 1.7 christos { 5049 1.7 christos /* Add Extended using alternate carry bits */ 5050 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5051 1.7 christos record_full_arch_list_add_reg (regcache, 5052 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5053 1.3 christos return 0; 5054 1.3 christos } 5055 1.3 christos 5056 1.3 christos switch (ext) 5057 1.3 christos { 5058 1.3 christos case 78: /* Determine Leftmost Zero Byte */ 5059 1.3 christos if (PPC_RC (insn)) 5060 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5061 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5062 1.3 christos record_full_arch_list_add_reg (regcache, 5063 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5064 1.3 christos return 0; 5065 1.3 christos 5066 1.3 christos /* These only write RT. */ 5067 1.3 christos case 19: /* Move from condition register */ 5068 1.3 christos /* Move From One Condition Register Field */ 5069 1.3 christos case 74: /* Add and Generate Sixes */ 5070 1.7 christos case 74 | 0x200: /* Add and Generate Sixes (bit-21 dont-care) */ 5071 1.7 christos case 302: /* Move From Branch History Rolling Buffer */ 5072 1.10 christos case 339: /* Move From Special Purpose Register */ 5073 1.10 christos case 371: /* Move From Time Base [Phased-Out] */ 5074 1.10 christos case 309: /* Load Doubleword Monitored Indexed */ 5075 1.10 christos case 128: /* Set Boolean */ 5076 1.7 christos case 384: /* Set Boolean Condition */ 5077 1.3 christos case 416: /* Set Boolean Condition Reverse */ 5078 1.3 christos case 448: /* Set Negative Boolean Condition */ 5079 1.3 christos case 480: /* Set Negative Boolean Condition Reverse */ 5080 1.3 christos case 755: /* Deliver A Random Number */ 5081 1.3 christos record_full_arch_list_add_reg (regcache, 5082 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5083 1.10 christos return 0; 5084 1.3 christos 5085 1.3 christos /* These only write to RA. */ 5086 1.10 christos case 51: /* Move From VSR Doubleword */ 5087 1.10 christos case 59: /* Count Leading Zeros Doubleword under bit Mask */ 5088 1.10 christos case 115: /* Move From VSR Word and Zero */ 5089 1.10 christos case 122: /* Population count bytes */ 5090 1.10 christos case 155: /* Byte-Reverse Word */ 5091 1.10 christos case 156: /* Parallel Bits Deposit Doubleword */ 5092 1.3 christos case 187: /* Byte-Reverse Doubleword */ 5093 1.3 christos case 188: /* Parallel Bits Extract Doubleword */ 5094 1.3 christos case 219: /* Byte-Reverse Halfword */ 5095 1.3 christos case 220: /* Centrifuge Doubleword */ 5096 1.3 christos case 378: /* Population count words */ 5097 1.3 christos case 506: /* Population count doublewords */ 5098 1.3 christos case 154: /* Parity Word */ 5099 1.3 christos case 186: /* Parity Doubleword */ 5100 1.7 christos case 252: /* Bit Permute Doubleword */ 5101 1.10 christos case 282: /* Convert Declets To Binary Coded Decimal */ 5102 1.3 christos case 314: /* Convert Binary Coded Decimal To Declets */ 5103 1.3 christos case 508: /* Compare bytes */ 5104 1.3 christos case 307: /* Move From VSR Lower Doubleword */ 5105 1.3 christos case 571: /* Count Trailing Zeros Doubleword under bit Mask */ 5106 1.3 christos record_full_arch_list_add_reg (regcache, 5107 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 5108 1.3 christos return 0; 5109 1.3 christos 5110 1.3 christos /* These write CR and optional RA. */ 5111 1.3 christos case 792: /* Shift Right Algebraic Word */ 5112 1.3 christos case 794: /* Shift Right Algebraic Doubleword */ 5113 1.3 christos case 824: /* Shift Right Algebraic Word Immediate */ 5114 1.3 christos case 826: /* Shift Right Algebraic Doubleword Immediate (413) */ 5115 1.11 christos case 826 | 1: /* Shift Right Algebraic Doubleword Immediate (413) */ 5116 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5117 1.3 christos record_full_arch_list_add_reg (regcache, 5118 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 5119 1.3 christos [[fallthrough]]; 5120 1.7 christos case 0: /* Compare */ 5121 1.7 christos case 32: /* Compare logical */ 5122 1.7 christos case 144: /* Move To Condition Register Fields */ 5123 1.7 christos /* Move To One Condition Register Field */ 5124 1.7 christos case 192: /* Compare Ranged Byte */ 5125 1.7 christos case 224: /* Compare Equal Byte */ 5126 1.3 christos case 576: /* Move XER to CR Extended */ 5127 1.3 christos case 902: /* Paste (should always fail due to single-stepping and 5128 1.3 christos the memory location might not be accessible, so 5129 1.3 christos record only CR) */ 5130 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5131 1.3 christos return 0; 5132 1.3 christos 5133 1.3 christos /* These write to RT. Update RA if 'update indexed.' */ 5134 1.3 christos case 53: /* Load Doubleword with Update Indexed */ 5135 1.3 christos case 119: /* Load Byte and Zero with Update Indexed */ 5136 1.3 christos case 311: /* Load Halfword and Zero with Update Indexed */ 5137 1.3 christos case 55: /* Load Word and Zero with Update Indexed */ 5138 1.11 christos case 375: /* Load Halfword Algebraic with Update Indexed */ 5139 1.3 christos case 373: /* Load Word Algebraic with Update Indexed */ 5140 1.3 christos record_full_arch_list_add_reg (regcache, 5141 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 5142 1.3 christos [[fallthrough]]; 5143 1.3 christos case 21: /* Load Doubleword Indexed */ 5144 1.3 christos case 52: /* Load Byte And Reserve Indexed */ 5145 1.3 christos case 116: /* Load Halfword And Reserve Indexed */ 5146 1.3 christos case 20: /* Load Word And Reserve Indexed */ 5147 1.3 christos case 84: /* Load Doubleword And Reserve Indexed */ 5148 1.3 christos case 87: /* Load Byte and Zero Indexed */ 5149 1.3 christos case 279: /* Load Halfword and Zero Indexed */ 5150 1.3 christos case 23: /* Load Word and Zero Indexed */ 5151 1.3 christos case 343: /* Load Halfword Algebraic Indexed */ 5152 1.7 christos case 341: /* Load Word Algebraic Indexed */ 5153 1.7 christos case 790: /* Load Halfword Byte-Reverse Indexed */ 5154 1.7 christos case 534: /* Load Word Byte-Reverse Indexed */ 5155 1.7 christos case 532: /* Load Doubleword Byte-Reverse Indexed */ 5156 1.7 christos case 582: /* Load Word Atomic */ 5157 1.7 christos case 614: /* Load Doubleword Atomic */ 5158 1.3 christos case 265: /* Modulo Unsigned Doubleword */ 5159 1.3 christos case 777: /* Modulo Signed Doubleword */ 5160 1.3 christos case 267: /* Modulo Unsigned Word */ 5161 1.3 christos case 779: /* Modulo Signed Word */ 5162 1.3 christos record_full_arch_list_add_reg (regcache, 5163 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 5164 1.3 christos return 0; 5165 1.3 christos 5166 1.3 christos case 597: /* Load String Word Immediate */ 5167 1.3 christos case 533: /* Load String Word Indexed */ 5168 1.3 christos if (ext == 597) 5169 1.3 christos { 5170 1.3 christos nr = PPC_NB (insn); 5171 1.3 christos if (nr == 0) 5172 1.3 christos nr = 32; 5173 1.3 christos } 5174 1.3 christos else 5175 1.3 christos { 5176 1.3 christos regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer); 5177 1.3 christos nr = PPC_XER_NB (xer); 5178 1.3 christos } 5179 1.3 christos 5180 1.3 christos nr = (nr + 3) >> 2; 5181 1.3 christos 5182 1.3 christos /* If n=0, the contents of register RT are undefined. */ 5183 1.3 christos if (nr == 0) 5184 1.3 christos nr = 1; 5185 1.3 christos 5186 1.3 christos for (i = 0; i < nr; i++) 5187 1.3 christos record_full_arch_list_add_reg (regcache, 5188 1.3 christos tdep->ppc_gp0_regnum 5189 1.3 christos + ((PPC_RT (insn) + i) & 0x1f)); 5190 1.3 christos return 0; 5191 1.3 christos 5192 1.3 christos case 276: /* Load Quadword And Reserve Indexed */ 5193 1.3 christos tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1); 5194 1.3 christos record_full_arch_list_add_reg (regcache, tmp); 5195 1.3 christos record_full_arch_list_add_reg (regcache, tmp + 1); 5196 1.3 christos return 0; 5197 1.3 christos 5198 1.3 christos /* These write VRT. */ 5199 1.3 christos case 6: /* Load Vector for Shift Left Indexed */ 5200 1.3 christos case 38: /* Load Vector for Shift Right Indexed */ 5201 1.3 christos case 7: /* Load Vector Element Byte Indexed */ 5202 1.3 christos case 39: /* Load Vector Element Halfword Indexed */ 5203 1.3 christos case 71: /* Load Vector Element Word Indexed */ 5204 1.3 christos case 103: /* Load Vector Indexed */ 5205 1.3 christos case 359: /* Load Vector Indexed LRU */ 5206 1.3 christos record_full_arch_list_add_reg (regcache, 5207 1.3 christos tdep->ppc_vr0_regnum + PPC_VRT (insn)); 5208 1.3 christos return 0; 5209 1.3 christos 5210 1.3 christos /* These write FRT. Update RA if 'update indexed.' */ 5211 1.11 christos case 567: /* Load Floating-Point Single with Update Indexed */ 5212 1.3 christos case 631: /* Load Floating-Point Double with Update Indexed */ 5213 1.3 christos record_full_arch_list_add_reg (regcache, 5214 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 5215 1.3 christos [[fallthrough]]; 5216 1.3 christos case 535: /* Load Floating-Point Single Indexed */ 5217 1.3 christos case 599: /* Load Floating-Point Double Indexed */ 5218 1.3 christos case 855: /* Load Floating-Point as Integer Word Algebraic Indexed */ 5219 1.3 christos case 887: /* Load Floating-Point as Integer Word and Zero Indexed */ 5220 1.3 christos record_full_arch_list_add_reg (regcache, 5221 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 5222 1.3 christos return 0; 5223 1.3 christos 5224 1.3 christos case 791: /* Load Floating-Point Double Pair Indexed */ 5225 1.3 christos tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1); 5226 1.10 christos record_full_arch_list_add_reg (regcache, tmp); 5227 1.3 christos record_full_arch_list_add_reg (regcache, tmp + 1); 5228 1.3 christos return 0; 5229 1.3 christos 5230 1.3 christos /* These write to destination register PPC_XT. */ 5231 1.3 christos case 179: /* Move To VSR Doubleword */ 5232 1.3 christos case 211: /* Move To VSR Word Algebraic */ 5233 1.3 christos case 243: /* Move To VSR Word and Zero */ 5234 1.10 christos case 588: /* Load VSX Scalar Doubleword Indexed */ 5235 1.10 christos case 524: /* Load VSX Scalar Single-Precision Indexed */ 5236 1.10 christos case 76: /* Load VSX Scalar as Integer Word Algebraic Indexed */ 5237 1.10 christos case 12: /* Load VSX Scalar as Integer Word and Zero Indexed */ 5238 1.3 christos case 13: /* Load VSX Vector Rightmost Byte Indexed */ 5239 1.3 christos case 45: /* Load VSX Vector Rightmost Halfword Indexed */ 5240 1.3 christos case 77: /* Load VSX Vector Rightmost Word Indexed */ 5241 1.7 christos case 109: /* Load VSX Vector Rightmost Doubleword Indexed */ 5242 1.7 christos case 844: /* Load VSX Vector Doubleword*2 Indexed */ 5243 1.7 christos case 332: /* Load VSX Vector Doubleword & Splat Indexed */ 5244 1.7 christos case 780: /* Load VSX Vector Word*4 Indexed */ 5245 1.7 christos case 268: /* Load VSX Vector Indexed */ 5246 1.7 christos case 364: /* Load VSX Vector Word & Splat Indexed */ 5247 1.7 christos case 812: /* Load VSX Vector Halfword*8 Indexed */ 5248 1.7 christos case 876: /* Load VSX Vector Byte*16 Indexed */ 5249 1.7 christos case 269: /* Load VSX Vector with Length */ 5250 1.7 christos case 301: /* Load VSX Vector Left-justified with Length */ 5251 1.3 christos case 781: /* Load VSX Scalar as Integer Byte & Zero Indexed */ 5252 1.3 christos case 813: /* Load VSX Scalar as Integer Halfword & Zero Indexed */ 5253 1.3 christos case 403: /* Move To VSR Word & Splat */ 5254 1.10 christos case 435: /* Move To VSR Double Doubleword */ 5255 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 5256 1.10 christos return 0; 5257 1.10 christos 5258 1.10 christos case 333: /* Load VSX Vector Paired Indexed */ 5259 1.3 christos ppc_record_vsr (regcache, tdep, PPC_XTp (insn)); 5260 1.3 christos ppc_record_vsr (regcache, tdep, PPC_XTp (insn) + 1); 5261 1.3 christos return 0; 5262 1.3 christos 5263 1.3 christos /* These write RA. Update CR if RC is set. */ 5264 1.3 christos case 24: /* Shift Left Word */ 5265 1.3 christos case 26: /* Count Leading Zeros Word */ 5266 1.3 christos case 27: /* Shift Left Doubleword */ 5267 1.3 christos case 28: /* AND */ 5268 1.3 christos case 58: /* Count Leading Zeros Doubleword */ 5269 1.3 christos case 60: /* AND with Complement */ 5270 1.3 christos case 124: /* NOR */ 5271 1.3 christos case 284: /* Equivalent */ 5272 1.3 christos case 316: /* XOR */ 5273 1.3 christos case 476: /* NAND */ 5274 1.3 christos case 412: /* OR with Complement */ 5275 1.3 christos case 444: /* OR */ 5276 1.3 christos case 536: /* Shift Right Word */ 5277 1.7 christos case 539: /* Shift Right Doubleword */ 5278 1.7 christos case 922: /* Extend Sign Halfword */ 5279 1.7 christos case 954: /* Extend Sign Byte */ 5280 1.7 christos case 986: /* Extend Sign Word */ 5281 1.8 christos case 538: /* Count Trailing Zeros Word */ 5282 1.8 christos case 570: /* Count Trailing Zeros Doubleword */ 5283 1.8 christos case 890: /* Extend-Sign Word and Shift Left Immediate (445) */ 5284 1.8 christos case 890 | 1: /* Extend-Sign Word and Shift Left Immediate (445) */ 5285 1.8 christos 5286 1.8 christos if (ext == 444 && tdep->ppc_ppr_regnum >= 0 5287 1.8 christos && (PPC_RS (insn) == PPC_RA (insn)) 5288 1.8 christos && (PPC_RA (insn) == PPC_RB (insn)) 5289 1.8 christos && !PPC_RC (insn)) 5290 1.8 christos { 5291 1.8 christos /* or Rx,Rx,Rx alters PRI in PPR. */ 5292 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ppr_regnum); 5293 1.3 christos return 0; 5294 1.3 christos } 5295 1.3 christos 5296 1.3 christos if (PPC_RC (insn)) 5297 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5298 1.3 christos record_full_arch_list_add_reg (regcache, 5299 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 5300 1.3 christos return 0; 5301 1.3 christos 5302 1.3 christos /* Store memory. */ 5303 1.3 christos case 181: /* Store Doubleword with Update Indexed */ 5304 1.3 christos case 183: /* Store Word with Update Indexed */ 5305 1.3 christos case 247: /* Store Byte with Update Indexed */ 5306 1.3 christos case 439: /* Store Half Word with Update Indexed */ 5307 1.11 christos case 695: /* Store Floating-Point Single with Update Indexed */ 5308 1.3 christos case 759: /* Store Floating-Point Double with Update Indexed */ 5309 1.3 christos record_full_arch_list_add_reg (regcache, 5310 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 5311 1.3 christos [[fallthrough]]; 5312 1.3 christos case 135: /* Store Vector Element Byte Indexed */ 5313 1.3 christos case 167: /* Store Vector Element Halfword Indexed */ 5314 1.3 christos case 199: /* Store Vector Element Word Indexed */ 5315 1.3 christos case 231: /* Store Vector Indexed */ 5316 1.3 christos case 487: /* Store Vector Indexed LRU */ 5317 1.3 christos case 716: /* Store VSX Scalar Doubleword Indexed */ 5318 1.3 christos case 140: /* Store VSX Scalar as Integer Word Indexed */ 5319 1.3 christos case 652: /* Store VSX Scalar Single-Precision Indexed */ 5320 1.3 christos case 972: /* Store VSX Vector Doubleword*2 Indexed */ 5321 1.3 christos case 908: /* Store VSX Vector Word*4 Indexed */ 5322 1.3 christos case 149: /* Store Doubleword Indexed */ 5323 1.3 christos case 151: /* Store Word Indexed */ 5324 1.3 christos case 215: /* Store Byte Indexed */ 5325 1.3 christos case 407: /* Store Half Word Indexed */ 5326 1.3 christos case 694: /* Store Byte Conditional Indexed */ 5327 1.3 christos case 726: /* Store Halfword Conditional Indexed */ 5328 1.3 christos case 150: /* Store Word Conditional Indexed */ 5329 1.3 christos case 214: /* Store Doubleword Conditional Indexed */ 5330 1.3 christos case 182: /* Store Quadword Conditional Indexed */ 5331 1.3 christos case 662: /* Store Word Byte-Reverse Indexed */ 5332 1.3 christos case 918: /* Store Halfword Byte-Reverse Indexed */ 5333 1.3 christos case 660: /* Store Doubleword Byte-Reverse Indexed */ 5334 1.7 christos case 663: /* Store Floating-Point Single Indexed */ 5335 1.7 christos case 727: /* Store Floating-Point Double Indexed */ 5336 1.7 christos case 919: /* Store Floating-Point Double Pair Indexed */ 5337 1.7 christos case 983: /* Store Floating-Point as Integer Word Indexed */ 5338 1.7 christos case 396: /* Store VSX Vector Indexed */ 5339 1.3 christos case 940: /* Store VSX Vector Halfword*8 Indexed */ 5340 1.3 christos case 1004: /* Store VSX Vector Byte*16 Indexed */ 5341 1.3 christos case 909: /* Store VSX Scalar as Integer Byte Indexed */ 5342 1.3 christos case 941: /* Store VSX Scalar as Integer Halfword Indexed */ 5343 1.3 christos if (ext == 694 || ext == 726 || ext == 150 || ext == 214 || ext == 182) 5344 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5345 1.3 christos 5346 1.3 christos ra = 0; 5347 1.3 christos if (PPC_RA (insn) != 0) 5348 1.3 christos regcache_raw_read_unsigned (regcache, 5349 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5350 1.3 christos regcache_raw_read_unsigned (regcache, 5351 1.3 christos tdep->ppc_gp0_regnum + PPC_RB (insn), &rb); 5352 1.3 christos ea = ra + rb; 5353 1.3 christos 5354 1.3 christos switch (ext) 5355 1.3 christos { 5356 1.3 christos case 183: /* Store Word with Update Indexed */ 5357 1.3 christos case 199: /* Store Vector Element Word Indexed */ 5358 1.3 christos case 140: /* Store VSX Scalar as Integer Word Indexed */ 5359 1.3 christos case 652: /* Store VSX Scalar Single-Precision Indexed */ 5360 1.3 christos case 151: /* Store Word Indexed */ 5361 1.3 christos case 150: /* Store Word Conditional Indexed */ 5362 1.3 christos case 662: /* Store Word Byte-Reverse Indexed */ 5363 1.3 christos case 663: /* Store Floating-Point Single Indexed */ 5364 1.3 christos case 695: /* Store Floating-Point Single with Update Indexed */ 5365 1.3 christos case 983: /* Store Floating-Point as Integer Word Indexed */ 5366 1.3 christos size = 4; 5367 1.3 christos break; 5368 1.7 christos case 247: /* Store Byte with Update Indexed */ 5369 1.3 christos case 135: /* Store Vector Element Byte Indexed */ 5370 1.3 christos case 215: /* Store Byte Indexed */ 5371 1.3 christos case 694: /* Store Byte Conditional Indexed */ 5372 1.3 christos case 909: /* Store VSX Scalar as Integer Byte Indexed */ 5373 1.3 christos size = 1; 5374 1.3 christos break; 5375 1.3 christos case 439: /* Store Halfword with Update Indexed */ 5376 1.7 christos case 167: /* Store Vector Element Halfword Indexed */ 5377 1.3 christos case 407: /* Store Halfword Indexed */ 5378 1.3 christos case 726: /* Store Halfword Conditional Indexed */ 5379 1.3 christos case 918: /* Store Halfword Byte-Reverse Indexed */ 5380 1.3 christos case 941: /* Store VSX Scalar as Integer Halfword Indexed */ 5381 1.3 christos size = 2; 5382 1.3 christos break; 5383 1.3 christos case 181: /* Store Doubleword with Update Indexed */ 5384 1.3 christos case 716: /* Store VSX Scalar Doubleword Indexed */ 5385 1.3 christos case 149: /* Store Doubleword Indexed */ 5386 1.3 christos case 214: /* Store Doubleword Conditional Indexed */ 5387 1.3 christos case 660: /* Store Doubleword Byte-Reverse Indexed */ 5388 1.3 christos case 727: /* Store Floating-Point Double Indexed */ 5389 1.3 christos case 759: /* Store Floating-Point Double with Update Indexed */ 5390 1.3 christos size = 8; 5391 1.3 christos break; 5392 1.3 christos case 972: /* Store VSX Vector Doubleword*2 Indexed */ 5393 1.3 christos case 908: /* Store VSX Vector Word*4 Indexed */ 5394 1.7 christos case 182: /* Store Quadword Conditional Indexed */ 5395 1.7 christos case 231: /* Store Vector Indexed */ 5396 1.7 christos case 487: /* Store Vector Indexed LRU */ 5397 1.3 christos case 919: /* Store Floating-Point Double Pair Indexed */ 5398 1.3 christos case 396: /* Store VSX Vector Indexed */ 5399 1.3 christos case 940: /* Store VSX Vector Halfword*8 Indexed */ 5400 1.3 christos case 1004: /* Store VSX Vector Byte*16 Indexed */ 5401 1.3 christos size = 16; 5402 1.3 christos break; 5403 1.3 christos default: 5404 1.3 christos gdb_assert (0); 5405 1.3 christos } 5406 1.3 christos 5407 1.10 christos /* Align address for Store Vector instructions. */ 5408 1.3 christos switch (ext) 5409 1.3 christos { 5410 1.3 christos case 167: /* Store Vector Element Halfword Indexed */ 5411 1.10 christos ea = ea & ~0x1ULL; 5412 1.3 christos break; 5413 1.3 christos 5414 1.3 christos case 199: /* Store Vector Element Word Indexed */ 5415 1.3 christos ea = ea & ~0x3ULL; 5416 1.10 christos break; 5417 1.3 christos 5418 1.3 christos case 231: /* Store Vector Indexed */ 5419 1.3 christos case 487: /* Store Vector Indexed LRU */ 5420 1.10 christos ea = ea & ~0xfULL; 5421 1.10 christos break; 5422 1.10 christos } 5423 1.10 christos 5424 1.10 christos record_full_arch_list_add_mem (ea, size); 5425 1.10 christos return 0; 5426 1.10 christos 5427 1.10 christos case 141: /* Store VSX Vector Rightmost Byte Indexed */ 5428 1.10 christos case 173: /* Store VSX Vector Rightmost Halfword Indexed */ 5429 1.10 christos case 205: /* Store VSX Vector Rightmost Word Indexed */ 5430 1.10 christos case 237: /* Store VSX Vector Rightmost Doubleword Indexed */ 5431 1.10 christos switch(ext) 5432 1.10 christos { 5433 1.10 christos case 141: nb = 1; 5434 1.10 christos break; 5435 1.10 christos case 173: nb = 2; 5436 1.10 christos break; 5437 1.10 christos case 205: nb = 4; 5438 1.10 christos break; 5439 1.10 christos case 237: nb = 8; 5440 1.10 christos break; 5441 1.10 christos } 5442 1.10 christos ra = 0; 5443 1.10 christos if (PPC_RA (insn) != 0) 5444 1.10 christos regcache_raw_read_unsigned (regcache, 5445 1.10 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5446 1.3 christos regcache_raw_read_unsigned (regcache, 5447 1.3 christos tdep->ppc_gp0_regnum + PPC_RB (insn), &rb); 5448 1.7 christos ea = ra + rb; 5449 1.7 christos record_full_arch_list_add_mem (ea, nb); 5450 1.7 christos return 0; 5451 1.7 christos 5452 1.7 christos case 397: /* Store VSX Vector with Length */ 5453 1.7 christos case 429: /* Store VSX Vector Left-justified with Length */ 5454 1.7 christos ra = 0; 5455 1.7 christos if (PPC_RA (insn) != 0) 5456 1.7 christos regcache_raw_read_unsigned (regcache, 5457 1.7 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5458 1.7 christos ea = ra; 5459 1.7 christos regcache_raw_read_unsigned (regcache, 5460 1.7 christos tdep->ppc_gp0_regnum + PPC_RB (insn), &rb); 5461 1.7 christos /* Store up to 16 bytes. */ 5462 1.7 christos nb = (rb & 0xff) > 16 ? 16 : (rb & 0xff); 5463 1.10 christos if (nb > 0) 5464 1.10 christos record_full_arch_list_add_mem (ea, nb); 5465 1.10 christos return 0; 5466 1.10 christos 5467 1.10 christos case 461: /* Store VSX Vector Paired Indexed */ 5468 1.10 christos { 5469 1.10 christos if (PPC_RA (insn) != 0) 5470 1.10 christos regcache_raw_read_unsigned (regcache, 5471 1.10 christos tdep->ppc_gp0_regnum 5472 1.10 christos + PPC_RA (insn), &ea); 5473 1.10 christos regcache_raw_read_unsigned (regcache, 5474 1.10 christos tdep->ppc_gp0_regnum + PPC_RB (insn), &rb); 5475 1.10 christos ea += rb; 5476 1.7 christos record_full_arch_list_add_mem (ea, 32); 5477 1.7 christos return 0; 5478 1.7 christos } 5479 1.7 christos 5480 1.7 christos case 710: /* Store Word Atomic */ 5481 1.7 christos case 742: /* Store Doubleword Atomic */ 5482 1.7 christos ra = 0; 5483 1.7 christos if (PPC_RA (insn) != 0) 5484 1.7 christos regcache_raw_read_unsigned (regcache, 5485 1.7 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5486 1.7 christos ea = ra; 5487 1.7 christos switch (ext) 5488 1.7 christos { 5489 1.7 christos case 710: /* Store Word Atomic */ 5490 1.7 christos size = 8; 5491 1.7 christos break; 5492 1.7 christos case 742: /* Store Doubleword Atomic */ 5493 1.7 christos size = 16; 5494 1.7 christos break; 5495 1.7 christos default: 5496 1.7 christos gdb_assert (0); 5497 1.3 christos } 5498 1.3 christos record_full_arch_list_add_mem (ea, size); 5499 1.3 christos return 0; 5500 1.6 christos 5501 1.6 christos case 725: /* Store String Word Immediate */ 5502 1.3 christos ra = 0; 5503 1.3 christos if (PPC_RA (insn) != 0) 5504 1.3 christos regcache_raw_read_unsigned (regcache, 5505 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5506 1.3 christos ea += ra; 5507 1.3 christos 5508 1.3 christos nb = PPC_NB (insn); 5509 1.3 christos if (nb == 0) 5510 1.3 christos nb = 32; 5511 1.3 christos 5512 1.3 christos record_full_arch_list_add_mem (ea, nb); 5513 1.3 christos 5514 1.3 christos return 0; 5515 1.6 christos 5516 1.6 christos case 661: /* Store String Word Indexed */ 5517 1.3 christos ra = 0; 5518 1.3 christos if (PPC_RA (insn) != 0) 5519 1.3 christos regcache_raw_read_unsigned (regcache, 5520 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5521 1.3 christos ea += ra; 5522 1.3 christos 5523 1.3 christos regcache_raw_read_unsigned (regcache, tdep->ppc_xer_regnum, &xer); 5524 1.6 christos nb = PPC_XER_NB (xer); 5525 1.6 christos 5526 1.6 christos if (nb != 0) 5527 1.3 christos { 5528 1.3 christos regcache_raw_read_unsigned (regcache, 5529 1.3 christos tdep->ppc_gp0_regnum + PPC_RB (insn), 5530 1.3 christos &rb); 5531 1.3 christos ea += rb; 5532 1.3 christos record_full_arch_list_add_mem (ea, nb); 5533 1.3 christos } 5534 1.3 christos 5535 1.3 christos return 0; 5536 1.3 christos 5537 1.3 christos case 467: /* Move To Special Purpose Register */ 5538 1.3 christos switch (PPC_SPR (insn)) 5539 1.8 christos { 5540 1.8 christos case 1: /* XER */ 5541 1.8 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5542 1.8 christos return 0; 5543 1.3 christos case 3: /* DSCR */ 5544 1.3 christos if (tdep->ppc_dscr_regnum >= 0) 5545 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_dscr_regnum); 5546 1.3 christos return 0; 5547 1.3 christos case 8: /* LR */ 5548 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum); 5549 1.3 christos return 0; 5550 1.3 christos case 9: /* CTR */ 5551 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum); 5552 1.8 christos return 0; 5553 1.8 christos case 256: /* VRSAVE */ 5554 1.8 christos record_full_arch_list_add_reg (regcache, tdep->ppc_vrsave_regnum); 5555 1.8 christos return 0; 5556 1.8 christos case 815: /* TAR */ 5557 1.8 christos if (tdep->ppc_tar_regnum >= 0) 5558 1.8 christos record_full_arch_list_add_reg (regcache, tdep->ppc_tar_regnum); 5559 1.8 christos return 0; 5560 1.8 christos case 896: 5561 1.3 christos case 898: /* PPR */ 5562 1.3 christos if (tdep->ppc_ppr_regnum >= 0) 5563 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ppr_regnum); 5564 1.3 christos return 0; 5565 1.3 christos } 5566 1.3 christos 5567 1.3 christos goto UNKNOWN_OP; 5568 1.3 christos 5569 1.3 christos case 147: /* Move To Split Little Endian */ 5570 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ps_regnum); 5571 1.3 christos return 0; 5572 1.3 christos 5573 1.3 christos case 512: /* Move to Condition Register from XER */ 5574 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5575 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 5576 1.3 christos return 0; 5577 1.3 christos 5578 1.3 christos case 4: /* Trap Word */ 5579 1.7 christos case 68: /* Trap Doubleword */ 5580 1.3 christos case 430: /* Clear BHRB */ 5581 1.3 christos case 598: /* Synchronize */ 5582 1.3 christos case 62: /* Wait for Interrupt */ 5583 1.3 christos case 30: /* Wait */ 5584 1.3 christos case 22: /* Instruction Cache Block Touch */ 5585 1.3 christos case 854: /* Enforce In-order Execution of I/O */ 5586 1.3 christos case 246: /* Data Cache Block Touch for Store */ 5587 1.3 christos case 54: /* Data Cache Block Store */ 5588 1.7 christos case 86: /* Data Cache Block Flush */ 5589 1.7 christos case 278: /* Data Cache Block Touch */ 5590 1.3 christos case 758: /* Data Cache Block Allocate */ 5591 1.3 christos case 982: /* Instruction Cache Block Invalidate */ 5592 1.3 christos case 774: /* Copy */ 5593 1.3 christos case 838: /* CP_Abort */ 5594 1.3 christos return 0; 5595 1.3 christos 5596 1.3 christos case 654: /* Transaction Begin */ 5597 1.3 christos case 686: /* Transaction End */ 5598 1.3 christos case 750: /* Transaction Suspend or Resume */ 5599 1.3 christos case 782: /* Transaction Abort Word Conditional */ 5600 1.6 christos case 814: /* Transaction Abort Doubleword Conditional */ 5601 1.11 christos case 846: /* Transaction Abort Word Conditional Immediate */ 5602 1.6 christos case 878: /* Transaction Abort Doubleword Conditional Immediate */ 5603 1.6 christos case 910: /* Transaction Abort */ 5604 1.6 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ps_regnum); 5605 1.3 christos [[fallthrough]]; 5606 1.3 christos case 718: /* Transaction Check */ 5607 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5608 1.3 christos return 0; 5609 1.3 christos 5610 1.3 christos case 1014: /* Data Cache Block set to Zero */ 5611 1.6 christos if (target_auxv_search (AT_DCACHEBSIZE, &at_dcsz) <= 0 5612 1.3 christos || at_dcsz == 0) 5613 1.3 christos at_dcsz = 128; /* Assume 128-byte cache line size (POWER8) */ 5614 1.3 christos 5615 1.3 christos ra = 0; 5616 1.3 christos if (PPC_RA (insn) != 0) 5617 1.3 christos regcache_raw_read_unsigned (regcache, 5618 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn), &ra); 5619 1.3 christos regcache_raw_read_unsigned (regcache, 5620 1.10 christos tdep->ppc_gp0_regnum + PPC_RB (insn), &rb); 5621 1.10 christos ea = (ra + rb) & ~((ULONGEST) (at_dcsz - 1)); 5622 1.10 christos record_full_arch_list_add_mem (ea, at_dcsz); 5623 1.10 christos return 0; 5624 1.3 christos 5625 1.3 christos case 177: 5626 1.3 christos if (ppc_process_record_op31_177 (gdbarch, regcache, insn) == 0) 5627 1.10 christos return 0; 5628 1.10 christos } 5629 1.3 christos 5630 1.3 christos UNKNOWN_OP: 5631 1.3 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 5632 1.3 christos "at %s, 31-%d.\n", insn, paddress (gdbarch, addr), ext); 5633 1.3 christos return -1; 5634 1.3 christos } 5635 1.3 christos 5636 1.3 christos /* Parse and record instructions of primary opcode-59 at ADDR. 5637 1.10 christos Return 0 if successful. */ 5638 1.3 christos 5639 1.10 christos static int 5640 1.3 christos ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache, 5641 1.10 christos CORE_ADDR addr, uint32_t insn) 5642 1.10 christos { 5643 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 5644 1.10 christos int ext = PPC_EXTOP (insn); 5645 1.10 christos int at = PPC_FIELD (insn, 6, 3); 5646 1.3 christos 5647 1.3 christos /* Note the mnemonics for the pmxvf64ger* instructions were officially 5648 1.3 christos changed to pmdmxvf64ger*. The old mnemonics are still supported as 5649 1.3 christos extended mnemonics. */ 5650 1.3 christos 5651 1.3 christos switch (ext & 0x1f) 5652 1.3 christos { 5653 1.3 christos case 18: /* Floating Divide */ 5654 1.3 christos case 20: /* Floating Subtract */ 5655 1.3 christos case 21: /* Floating Add */ 5656 1.3 christos case 22: /* Floating Square Root */ 5657 1.3 christos case 24: /* Floating Reciprocal Estimate */ 5658 1.3 christos case 25: /* Floating Multiply */ 5659 1.3 christos case 26: /* Floating Reciprocal Square Root Estimate */ 5660 1.3 christos case 28: /* Floating Multiply-Subtract */ 5661 1.3 christos case 29: /* Floating Multiply-Add */ 5662 1.3 christos case 30: /* Floating Negative Multiply-Subtract */ 5663 1.3 christos case 31: /* Floating Negative Multiply-Add */ 5664 1.3 christos record_full_arch_list_add_reg (regcache, 5665 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 5666 1.3 christos if (PPC_RC (insn)) 5667 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5668 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5669 1.10 christos 5670 1.10 christos return 0; 5671 1.10 christos } 5672 1.10 christos 5673 1.10 christos /* MMA instructions, keep looking. */ 5674 1.10 christos switch (ext >> 2) /* Additional opcode field is upper 8-bits of ext */ 5675 1.10 christos { 5676 1.10 christos case 3: /* VSX Vector 8-bit Signed/Unsigned Integer GER, xvi8ger4 */ 5677 1.10 christos case 2: /* VSX Vector 8-bit Signed/Unsigned Integer GER Positive 5678 1.10 christos multiply, Positive accumulate, xvi8ger4pp */ 5679 1.10 christos 5680 1.10 christos case 99: /* VSX Vector 8-bit Signed/Unsigned Integer GER with 5681 1.10 christos Saturate Positive multiply, Positive accumulate, 5682 1.10 christos xvi8ger4spp */ 5683 1.10 christos 5684 1.10 christos case 35: /* VSX Vector 4-bit Signed Integer GER, xvi4ger8 */ 5685 1.10 christos case 34: /* VSX Vector 4-bit Signed Integer GER Positive multiply, 5686 1.10 christos Positive accumulate, xvi4ger8pp */ 5687 1.10 christos 5688 1.10 christos case 75: /* VSX Vector 16-bit Signed Integer GER, xvi16ger2 */ 5689 1.10 christos case 107: /* VSX Vector 16-bit Signed Integer GER Positive multiply, 5690 1.10 christos Positive accumulate, xvi16ger2pp */ 5691 1.10 christos 5692 1.10 christos case 43: /* VSX Vector 16-bit Signed Integer GER with Saturation, 5693 1.10 christos xvi16ger2s */ 5694 1.10 christos case 42: /* VSX Vector 16-bit Signed Integer GER with Saturation 5695 1.10 christos Positive multiply, Positive accumulate, xvi16ger2spp */ 5696 1.10 christos ppc_record_ACC_fpscr (regcache, tdep, at, false); 5697 1.10 christos return 0; 5698 1.10 christos 5699 1.10 christos case 19: /* VSX Vector 16-bit Floating-Point GER, xvf16ger2 */ 5700 1.10 christos case 18: /* VSX Vector 16-bit Floating-Point GER Positive multiply, 5701 1.10 christos Positive accumulate, xvf16ger2pp */ 5702 1.10 christos case 146: /* VSX Vector 16-bit Floating-Point GER Positive multiply, 5703 1.10 christos Negative accumulate, xvf16ger2pn */ 5704 1.10 christos case 82: /* VSX Vector 16-bit Floating-Point GER Negative multiply, 5705 1.10 christos Positive accumulate, xvf16ger2np */ 5706 1.10 christos case 210: /* VSX Vector 16-bit Floating-Point GER Negative multiply, 5707 1.10 christos Negative accumulate, xvf16ger2nn */ 5708 1.10 christos 5709 1.10 christos case 27: /* VSX Vector 32-bit Floating-Point GER, xvf32ger */ 5710 1.10 christos case 26: /* VSX Vector 32-bit Floating-Point GER Positive multiply, 5711 1.10 christos Positive accumulate, xvf32gerpp */ 5712 1.10 christos case 154: /* VSX Vector 32-bit Floating-Point GER Positive multiply, 5713 1.10 christos Negative accumulate, xvf32gerpn */ 5714 1.10 christos case 90: /* VSX Vector 32-bit Floating-Point GER Negative multiply, 5715 1.10 christos Positive accumulate, xvf32gernp */ 5716 1.10 christos case 218: /* VSX Vector 32-bit Floating-Point GER Negative multiply, 5717 1.10 christos Negative accumulate, xvf32gernn */ 5718 1.10 christos 5719 1.10 christos case 59: /* VSX Vector 64-bit Floating-Point GER, pmdmxvf64ger 5720 1.10 christos (pmxvf64ger) */ 5721 1.10 christos case 58: /* VSX Vector 64-bit Floating-Point GER Positive multiply, 5722 1.10 christos Positive accumulate, xvf64gerpp */ 5723 1.10 christos case 186: /* VSX Vector 64-bit Floating-Point GER Positive multiply, 5724 1.10 christos Negative accumulate, xvf64gerpn */ 5725 1.10 christos case 122: /* VSX Vector 64-bit Floating-Point GER Negative multiply, 5726 1.10 christos Positive accumulate, xvf64gernp */ 5727 1.10 christos case 250: /* VSX Vector 64-bit Floating-Point GER Negative multiply, 5728 1.10 christos Negative accumulate, pmdmxvf64gernn (pmxvf64gernn) */ 5729 1.10 christos 5730 1.10 christos case 51: /* VSX Vector bfloat16 GER, xvbf16ger2 */ 5731 1.10 christos case 50: /* VSX Vector bfloat16 GER Positive multiply, 5732 1.10 christos Positive accumulate, xvbf16ger2pp */ 5733 1.10 christos case 178: /* VSX Vector bfloat16 GER Positive multiply, 5734 1.10 christos Negative accumulate, xvbf16ger2pn */ 5735 1.10 christos case 114: /* VSX Vector bfloat16 GER Negative multiply, 5736 1.10 christos Positive accumulate, xvbf16ger2np */ 5737 1.10 christos case 242: /* VSX Vector bfloat16 GER Negative multiply, 5738 1.10 christos Negative accumulate, xvbf16ger2nn */ 5739 1.3 christos ppc_record_ACC_fpscr (regcache, tdep, at, true); 5740 1.3 christos return 0; 5741 1.3 christos } 5742 1.3 christos 5743 1.3 christos switch (ext) 5744 1.3 christos { 5745 1.3 christos case 2: /* DFP Add */ 5746 1.3 christos case 3: /* DFP Quantize */ 5747 1.3 christos case 34: /* DFP Multiply */ 5748 1.3 christos case 35: /* DFP Reround */ 5749 1.3 christos case 67: /* DFP Quantize Immediate */ 5750 1.3 christos case 99: /* DFP Round To FP Integer With Inexact */ 5751 1.3 christos case 227: /* DFP Round To FP Integer Without Inexact */ 5752 1.3 christos case 258: /* DFP Convert To DFP Long! */ 5753 1.3 christos case 290: /* DFP Convert To Fixed */ 5754 1.3 christos case 514: /* DFP Subtract */ 5755 1.3 christos case 546: /* DFP Divide */ 5756 1.3 christos case 770: /* DFP Round To DFP Short! */ 5757 1.3 christos case 802: /* DFP Convert From Fixed */ 5758 1.3 christos case 834: /* DFP Encode BCD To DPD */ 5759 1.3 christos if (PPC_RC (insn)) 5760 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5761 1.3 christos record_full_arch_list_add_reg (regcache, 5762 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 5763 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5764 1.3 christos return 0; 5765 1.3 christos 5766 1.3 christos case 130: /* DFP Compare Ordered */ 5767 1.3 christos case 162: /* DFP Test Exponent */ 5768 1.7 christos case 194: /* DFP Test Data Class */ 5769 1.3 christos case 226: /* DFP Test Data Group */ 5770 1.3 christos case 642: /* DFP Compare Unordered */ 5771 1.3 christos case 674: /* DFP Test Significance */ 5772 1.3 christos case 675: /* DFP Test Significance Immediate */ 5773 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5774 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5775 1.3 christos return 0; 5776 1.3 christos 5777 1.3 christos case 66: /* DFP Shift Significand Left Immediate */ 5778 1.3 christos case 98: /* DFP Shift Significand Right Immediate */ 5779 1.3 christos case 322: /* DFP Decode DPD To BCD */ 5780 1.3 christos case 354: /* DFP Extract Biased Exponent */ 5781 1.3 christos case 866: /* DFP Insert Biased Exponent */ 5782 1.3 christos record_full_arch_list_add_reg (regcache, 5783 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 5784 1.3 christos if (PPC_RC (insn)) 5785 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5786 1.3 christos return 0; 5787 1.3 christos 5788 1.3 christos case 846: /* Floating Convert From Integer Doubleword Single */ 5789 1.3 christos case 974: /* Floating Convert From Integer Doubleword Unsigned 5790 1.3 christos Single */ 5791 1.3 christos record_full_arch_list_add_reg (regcache, 5792 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 5793 1.3 christos if (PPC_RC (insn)) 5794 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5795 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5796 1.10 christos 5797 1.10 christos return 0; 5798 1.10 christos } 5799 1.10 christos 5800 1.10 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 5801 1.10 christos "at %s, 59-%d.\n", insn, paddress (gdbarch, addr), ext); 5802 1.10 christos return -1; 5803 1.10 christos } 5804 1.10 christos 5805 1.10 christos /* Parse and record an XX2-Form instruction with opcode 60 at ADDR. The 5806 1.10 christos word instruction is an argument insn. Return 0 if successful. */ 5807 1.10 christos 5808 1.10 christos static int 5809 1.10 christos ppc_process_record_op60_XX2 (struct gdbarch *gdbarch, 5810 1.10 christos struct regcache *regcache, 5811 1.10 christos CORE_ADDR addr, uint32_t insn) 5812 1.10 christos { 5813 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 5814 1.10 christos int RA_opcode = PPC_RA(insn); 5815 1.10 christos 5816 1.10 christos switch (RA_opcode) 5817 1.10 christos { 5818 1.10 christos case 2: /* VSX Vector Test Least-Significant Bit by Byte */ 5819 1.10 christos case 25: /* VSX Vector round and Convert Single-Precision format 5820 1.10 christos to Half-Precision format. Only changes the CR 5821 1.10 christos field. */ 5822 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5823 1.10 christos return 0; 5824 1.10 christos case 17: /* VSX Vector Convert with round Single-Precision 5825 1.11 christos to bfloat16 format */ 5826 1.10 christos case 24: /* VSX Vector Convert Half-Precision format to 5827 1.10 christos Single-Precision format */ 5828 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5829 1.10 christos [[fallthrough]]; 5830 1.10 christos case 0: /* VSX Vector Extract Exponent Double-Precision */ 5831 1.10 christos case 1: /* VSX Vector Extract Significand Double-Precision */ 5832 1.10 christos case 7: /* VSX Vector Byte-Reverse Halfword */ 5833 1.10 christos case 8: /* VSX Vector Extract Exponent Single-Precision */ 5834 1.10 christos case 9: /* VSX Vector Extract Significand Single-Precision */ 5835 1.10 christos case 15: /* VSX Vector Byte-Reverse Word */ 5836 1.10 christos case 16: /* VSX Vector Convert bfloat16 to Single-Precision 5837 1.10 christos format Non-signaling */ 5838 1.10 christos case 23: /* VSX Vector Byte-Reverse Doubleword */ 5839 1.10 christos case 31: /* VSX Vector Byte-Reverse Quadword */ 5840 1.3 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 5841 1.3 christos return 0; 5842 1.3 christos } 5843 1.3 christos 5844 1.3 christos return -1; 5845 1.3 christos } 5846 1.3 christos 5847 1.3 christos /* Parse and record instructions of primary opcode-60 at ADDR. 5848 1.3 christos Return 0 if successful. */ 5849 1.3 christos 5850 1.10 christos static int 5851 1.3 christos ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache, 5852 1.3 christos CORE_ADDR addr, uint32_t insn) 5853 1.3 christos { 5854 1.3 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 5855 1.3 christos int ext = PPC_EXTOP (insn); 5856 1.3 christos 5857 1.3 christos switch (ext >> 2) 5858 1.3 christos { 5859 1.3 christos case 0: /* VSX Scalar Add Single-Precision */ 5860 1.3 christos case 32: /* VSX Scalar Add Double-Precision */ 5861 1.3 christos case 24: /* VSX Scalar Divide Single-Precision */ 5862 1.3 christos case 56: /* VSX Scalar Divide Double-Precision */ 5863 1.3 christos case 176: /* VSX Scalar Copy Sign Double-Precision */ 5864 1.3 christos case 33: /* VSX Scalar Multiply-Add Double-Precision */ 5865 1.3 christos case 41: /* ditto */ 5866 1.3 christos case 1: /* VSX Scalar Multiply-Add Single-Precision */ 5867 1.3 christos case 9: /* ditto */ 5868 1.3 christos case 160: /* VSX Scalar Maximum Double-Precision */ 5869 1.3 christos case 168: /* VSX Scalar Minimum Double-Precision */ 5870 1.3 christos case 49: /* VSX Scalar Multiply-Subtract Double-Precision */ 5871 1.3 christos case 57: /* ditto */ 5872 1.3 christos case 17: /* VSX Scalar Multiply-Subtract Single-Precision */ 5873 1.3 christos case 25: /* ditto */ 5874 1.3 christos case 48: /* VSX Scalar Multiply Double-Precision */ 5875 1.3 christos case 16: /* VSX Scalar Multiply Single-Precision */ 5876 1.3 christos case 161: /* VSX Scalar Negative Multiply-Add Double-Precision */ 5877 1.3 christos case 169: /* ditto */ 5878 1.3 christos case 129: /* VSX Scalar Negative Multiply-Add Single-Precision */ 5879 1.3 christos case 137: /* ditto */ 5880 1.3 christos case 177: /* VSX Scalar Negative Multiply-Subtract Double-Precision */ 5881 1.3 christos case 185: /* ditto */ 5882 1.3 christos case 145: /* VSX Scalar Negative Multiply-Subtract Single-Precision */ 5883 1.3 christos case 153: /* ditto */ 5884 1.3 christos case 40: /* VSX Scalar Subtract Double-Precision */ 5885 1.3 christos case 8: /* VSX Scalar Subtract Single-Precision */ 5886 1.3 christos case 96: /* VSX Vector Add Double-Precision */ 5887 1.3 christos case 64: /* VSX Vector Add Single-Precision */ 5888 1.3 christos case 120: /* VSX Vector Divide Double-Precision */ 5889 1.3 christos case 88: /* VSX Vector Divide Single-Precision */ 5890 1.3 christos case 97: /* VSX Vector Multiply-Add Double-Precision */ 5891 1.3 christos case 105: /* ditto */ 5892 1.3 christos case 65: /* VSX Vector Multiply-Add Single-Precision */ 5893 1.3 christos case 73: /* ditto */ 5894 1.3 christos case 224: /* VSX Vector Maximum Double-Precision */ 5895 1.3 christos case 192: /* VSX Vector Maximum Single-Precision */ 5896 1.3 christos case 232: /* VSX Vector Minimum Double-Precision */ 5897 1.3 christos case 200: /* VSX Vector Minimum Single-Precision */ 5898 1.3 christos case 113: /* VSX Vector Multiply-Subtract Double-Precision */ 5899 1.3 christos case 121: /* ditto */ 5900 1.3 christos case 81: /* VSX Vector Multiply-Subtract Single-Precision */ 5901 1.3 christos case 89: /* ditto */ 5902 1.3 christos case 112: /* VSX Vector Multiply Double-Precision */ 5903 1.3 christos case 80: /* VSX Vector Multiply Single-Precision */ 5904 1.3 christos case 225: /* VSX Vector Negative Multiply-Add Double-Precision */ 5905 1.3 christos case 233: /* ditto */ 5906 1.3 christos case 193: /* VSX Vector Negative Multiply-Add Single-Precision */ 5907 1.3 christos case 201: /* ditto */ 5908 1.3 christos case 241: /* VSX Vector Negative Multiply-Subtract Double-Precision */ 5909 1.3 christos case 249: /* ditto */ 5910 1.7 christos case 209: /* VSX Vector Negative Multiply-Subtract Single-Precision */ 5911 1.7 christos case 217: /* ditto */ 5912 1.7 christos case 104: /* VSX Vector Subtract Double-Precision */ 5913 1.7 christos case 72: /* VSX Vector Subtract Single-Precision */ 5914 1.7 christos case 128: /* VSX Scalar Maximum Type-C Double-Precision */ 5915 1.7 christos case 136: /* VSX Scalar Minimum Type-C Double-Precision */ 5916 1.7 christos case 144: /* VSX Scalar Maximum Type-J Double-Precision */ 5917 1.7 christos case 152: /* VSX Scalar Minimum Type-J Double-Precision */ 5918 1.3 christos case 3: /* VSX Scalar Compare Equal Double-Precision */ 5919 1.11 christos case 11: /* VSX Scalar Compare Greater Than Double-Precision */ 5920 1.3 christos case 19: /* VSX Scalar Compare Greater Than or Equal 5921 1.3 christos Double-Precision */ 5922 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5923 1.3 christos [[fallthrough]]; 5924 1.3 christos case 240: /* VSX Vector Copy Sign Double-Precision */ 5925 1.3 christos case 208: /* VSX Vector Copy Sign Single-Precision */ 5926 1.3 christos case 130: /* VSX Logical AND */ 5927 1.3 christos case 138: /* VSX Logical AND with Complement */ 5928 1.3 christos case 186: /* VSX Logical Equivalence */ 5929 1.3 christos case 178: /* VSX Logical NAND */ 5930 1.3 christos case 170: /* VSX Logical OR with Complement */ 5931 1.3 christos case 162: /* VSX Logical NOR */ 5932 1.3 christos case 146: /* VSX Logical OR */ 5933 1.3 christos case 154: /* VSX Logical XOR */ 5934 1.3 christos case 18: /* VSX Merge High Word */ 5935 1.3 christos case 50: /* VSX Merge Low Word */ 5936 1.3 christos case 10: /* VSX Permute Doubleword Immediate (DM=0) */ 5937 1.3 christos case 10 | 0x20: /* VSX Permute Doubleword Immediate (DM=1) */ 5938 1.3 christos case 10 | 0x40: /* VSX Permute Doubleword Immediate (DM=2) */ 5939 1.3 christos case 10 | 0x60: /* VSX Permute Doubleword Immediate (DM=3) */ 5940 1.7 christos case 2: /* VSX Shift Left Double by Word Immediate (SHW=0) */ 5941 1.7 christos case 2 | 0x20: /* VSX Shift Left Double by Word Immediate (SHW=1) */ 5942 1.7 christos case 2 | 0x40: /* VSX Shift Left Double by Word Immediate (SHW=2) */ 5943 1.7 christos case 2 | 0x60: /* VSX Shift Left Double by Word Immediate (SHW=3) */ 5944 1.7 christos case 216: /* VSX Vector Insert Exponent Single-Precision */ 5945 1.7 christos case 248: /* VSX Vector Insert Exponent Double-Precision */ 5946 1.7 christos case 26: /* VSX Vector Permute */ 5947 1.7 christos case 58: /* VSX Vector Permute Right-indexed */ 5948 1.3 christos case 213: /* VSX Vector Test Data Class Single-Precision (DC=0) */ 5949 1.3 christos case 213 | 0x8: /* VSX Vector Test Data Class Single-Precision (DC=1) */ 5950 1.3 christos case 245: /* VSX Vector Test Data Class Double-Precision (DC=0) */ 5951 1.3 christos case 245 | 0x8: /* VSX Vector Test Data Class Double-Precision (DC=1) */ 5952 1.3 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 5953 1.3 christos return 0; 5954 1.3 christos 5955 1.3 christos case 61: /* VSX Scalar Test for software Divide Double-Precision */ 5956 1.3 christos case 125: /* VSX Vector Test for software Divide Double-Precision */ 5957 1.3 christos case 93: /* VSX Vector Test for software Divide Single-Precision */ 5958 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5959 1.7 christos return 0; 5960 1.3 christos 5961 1.3 christos case 35: /* VSX Scalar Compare Unordered Double-Precision */ 5962 1.3 christos case 43: /* VSX Scalar Compare Ordered Double-Precision */ 5963 1.3 christos case 59: /* VSX Scalar Compare Exponents Double-Precision */ 5964 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5965 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5966 1.3 christos return 0; 5967 1.3 christos } 5968 1.3 christos 5969 1.3 christos switch ((ext >> 2) & 0x7f) /* Mask out Rc-bit. */ 5970 1.3 christos { 5971 1.3 christos case 99: /* VSX Vector Compare Equal To Double-Precision */ 5972 1.3 christos case 67: /* VSX Vector Compare Equal To Single-Precision */ 5973 1.3 christos case 115: /* VSX Vector Compare Greater Than or 5974 1.3 christos Equal To Double-Precision */ 5975 1.3 christos case 83: /* VSX Vector Compare Greater Than or 5976 1.3 christos Equal To Single-Precision */ 5977 1.3 christos case 107: /* VSX Vector Compare Greater Than Double-Precision */ 5978 1.3 christos case 75: /* VSX Vector Compare Greater Than Single-Precision */ 5979 1.3 christos if (PPC_Rc (insn)) 5980 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 5981 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 5982 1.3 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 5983 1.3 christos return 0; 5984 1.3 christos } 5985 1.3 christos 5986 1.3 christos switch (ext >> 1) 5987 1.3 christos { 5988 1.3 christos case 265: /* VSX Scalar round Double-Precision to 5989 1.3 christos Single-Precision and Convert to 5990 1.3 christos Single-Precision format */ 5991 1.3 christos case 344: /* VSX Scalar truncate Double-Precision to 5992 1.3 christos Integer and Convert to Signed Integer 5993 1.3 christos Doubleword format with Saturate */ 5994 1.3 christos case 88: /* VSX Scalar truncate Double-Precision to 5995 1.3 christos Integer and Convert to Signed Integer Word 5996 1.3 christos Format with Saturate */ 5997 1.3 christos case 328: /* VSX Scalar truncate Double-Precision integer 5998 1.3 christos and Convert to Unsigned Integer Doubleword 5999 1.3 christos Format with Saturate */ 6000 1.3 christos case 72: /* VSX Scalar truncate Double-Precision to 6001 1.3 christos Integer and Convert to Unsigned Integer Word 6002 1.3 christos Format with Saturate */ 6003 1.3 christos case 329: /* VSX Scalar Convert Single-Precision to 6004 1.3 christos Double-Precision format */ 6005 1.3 christos case 376: /* VSX Scalar Convert Signed Integer 6006 1.3 christos Doubleword to floating-point format and 6007 1.3 christos Round to Double-Precision format */ 6008 1.3 christos case 312: /* VSX Scalar Convert Signed Integer 6009 1.3 christos Doubleword to floating-point format and 6010 1.3 christos round to Single-Precision */ 6011 1.3 christos case 360: /* VSX Scalar Convert Unsigned Integer 6012 1.3 christos Doubleword to floating-point format and 6013 1.3 christos Round to Double-Precision format */ 6014 1.3 christos case 296: /* VSX Scalar Convert Unsigned Integer 6015 1.3 christos Doubleword to floating-point format and 6016 1.3 christos Round to Single-Precision */ 6017 1.3 christos case 73: /* VSX Scalar Round to Double-Precision Integer 6018 1.3 christos Using Round to Nearest Away */ 6019 1.3 christos case 107: /* VSX Scalar Round to Double-Precision Integer 6020 1.3 christos Exact using Current rounding mode */ 6021 1.3 christos case 121: /* VSX Scalar Round to Double-Precision Integer 6022 1.3 christos Using Round toward -Infinity */ 6023 1.3 christos case 105: /* VSX Scalar Round to Double-Precision Integer 6024 1.3 christos Using Round toward +Infinity */ 6025 1.3 christos case 89: /* VSX Scalar Round to Double-Precision Integer 6026 1.3 christos Using Round toward Zero */ 6027 1.3 christos case 90: /* VSX Scalar Reciprocal Estimate Double-Precision */ 6028 1.3 christos case 26: /* VSX Scalar Reciprocal Estimate Single-Precision */ 6029 1.3 christos case 281: /* VSX Scalar Round to Single-Precision */ 6030 1.3 christos case 74: /* VSX Scalar Reciprocal Square Root Estimate 6031 1.3 christos Double-Precision */ 6032 1.3 christos case 10: /* VSX Scalar Reciprocal Square Root Estimate 6033 1.3 christos Single-Precision */ 6034 1.3 christos case 75: /* VSX Scalar Square Root Double-Precision */ 6035 1.3 christos case 11: /* VSX Scalar Square Root Single-Precision */ 6036 1.3 christos case 393: /* VSX Vector round Double-Precision to 6037 1.3 christos Single-Precision and Convert to 6038 1.3 christos Single-Precision format */ 6039 1.3 christos case 472: /* VSX Vector truncate Double-Precision to 6040 1.3 christos Integer and Convert to Signed Integer 6041 1.3 christos Doubleword format with Saturate */ 6042 1.3 christos case 216: /* VSX Vector truncate Double-Precision to 6043 1.3 christos Integer and Convert to Signed Integer Word 6044 1.3 christos Format with Saturate */ 6045 1.3 christos case 456: /* VSX Vector truncate Double-Precision to 6046 1.3 christos Integer and Convert to Unsigned Integer 6047 1.3 christos Doubleword format with Saturate */ 6048 1.3 christos case 200: /* VSX Vector truncate Double-Precision to 6049 1.3 christos Integer and Convert to Unsigned Integer Word 6050 1.3 christos Format with Saturate */ 6051 1.3 christos case 457: /* VSX Vector Convert Single-Precision to 6052 1.3 christos Double-Precision format */ 6053 1.3 christos case 408: /* VSX Vector truncate Single-Precision to 6054 1.3 christos Integer and Convert to Signed Integer 6055 1.3 christos Doubleword format with Saturate */ 6056 1.3 christos case 152: /* VSX Vector truncate Single-Precision to 6057 1.3 christos Integer and Convert to Signed Integer Word 6058 1.3 christos Format with Saturate */ 6059 1.3 christos case 392: /* VSX Vector truncate Single-Precision to 6060 1.3 christos Integer and Convert to Unsigned Integer 6061 1.3 christos Doubleword format with Saturate */ 6062 1.3 christos case 136: /* VSX Vector truncate Single-Precision to 6063 1.3 christos Integer and Convert to Unsigned Integer Word 6064 1.3 christos Format with Saturate */ 6065 1.3 christos case 504: /* VSX Vector Convert and round Signed Integer 6066 1.3 christos Doubleword to Double-Precision format */ 6067 1.3 christos case 440: /* VSX Vector Convert and round Signed Integer 6068 1.3 christos Doubleword to Single-Precision format */ 6069 1.3 christos case 248: /* VSX Vector Convert Signed Integer Word to 6070 1.3 christos Double-Precision format */ 6071 1.3 christos case 184: /* VSX Vector Convert and round Signed Integer 6072 1.3 christos Word to Single-Precision format */ 6073 1.3 christos case 488: /* VSX Vector Convert and round Unsigned 6074 1.3 christos Integer Doubleword to Double-Precision format */ 6075 1.3 christos case 424: /* VSX Vector Convert and round Unsigned 6076 1.3 christos Integer Doubleword to Single-Precision format */ 6077 1.3 christos case 232: /* VSX Vector Convert and round Unsigned 6078 1.3 christos Integer Word to Double-Precision format */ 6079 1.3 christos case 168: /* VSX Vector Convert and round Unsigned 6080 1.3 christos Integer Word to Single-Precision format */ 6081 1.3 christos case 201: /* VSX Vector Round to Double-Precision 6082 1.3 christos Integer using round to Nearest Away */ 6083 1.3 christos case 235: /* VSX Vector Round to Double-Precision 6084 1.3 christos Integer Exact using Current rounding mode */ 6085 1.3 christos case 249: /* VSX Vector Round to Double-Precision 6086 1.3 christos Integer using round toward -Infinity */ 6087 1.3 christos case 233: /* VSX Vector Round to Double-Precision 6088 1.3 christos Integer using round toward +Infinity */ 6089 1.3 christos case 217: /* VSX Vector Round to Double-Precision 6090 1.3 christos Integer using round toward Zero */ 6091 1.3 christos case 218: /* VSX Vector Reciprocal Estimate Double-Precision */ 6092 1.3 christos case 154: /* VSX Vector Reciprocal Estimate Single-Precision */ 6093 1.3 christos case 137: /* VSX Vector Round to Single-Precision Integer 6094 1.3 christos Using Round to Nearest Away */ 6095 1.3 christos case 171: /* VSX Vector Round to Single-Precision Integer 6096 1.3 christos Exact Using Current rounding mode */ 6097 1.3 christos case 185: /* VSX Vector Round to Single-Precision Integer 6098 1.3 christos Using Round toward -Infinity */ 6099 1.3 christos case 169: /* VSX Vector Round to Single-Precision Integer 6100 1.3 christos Using Round toward +Infinity */ 6101 1.3 christos case 153: /* VSX Vector Round to Single-Precision Integer 6102 1.3 christos Using round toward Zero */ 6103 1.3 christos case 202: /* VSX Vector Reciprocal Square Root Estimate 6104 1.3 christos Double-Precision */ 6105 1.3 christos case 138: /* VSX Vector Reciprocal Square Root Estimate 6106 1.11 christos Single-Precision */ 6107 1.3 christos case 203: /* VSX Vector Square Root Double-Precision */ 6108 1.3 christos case 139: /* VSX Vector Square Root Single-Precision */ 6109 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6110 1.3 christos [[fallthrough]]; 6111 1.3 christos case 345: /* VSX Scalar Absolute Value Double-Precision */ 6112 1.3 christos case 267: /* VSX Scalar Convert Scalar Single-Precision to 6113 1.3 christos Vector Single-Precision format Non-signalling */ 6114 1.3 christos case 331: /* VSX Scalar Convert Single-Precision to 6115 1.3 christos Double-Precision format Non-signalling */ 6116 1.3 christos case 361: /* VSX Scalar Negative Absolute Value Double-Precision */ 6117 1.3 christos case 377: /* VSX Scalar Negate Double-Precision */ 6118 1.3 christos case 473: /* VSX Vector Absolute Value Double-Precision */ 6119 1.3 christos case 409: /* VSX Vector Absolute Value Single-Precision */ 6120 1.3 christos case 489: /* VSX Vector Negative Absolute Value Double-Precision */ 6121 1.7 christos case 425: /* VSX Vector Negative Absolute Value Single-Precision */ 6122 1.7 christos case 505: /* VSX Vector Negate Double-Precision */ 6123 1.3 christos case 441: /* VSX Vector Negate Single-Precision */ 6124 1.3 christos case 164: /* VSX Splat Word */ 6125 1.3 christos case 165: /* VSX Vector Extract Unsigned Word */ 6126 1.7 christos case 181: /* VSX Vector Insert Word */ 6127 1.7 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6128 1.7 christos return 0; 6129 1.11 christos 6130 1.3 christos case 298: /* VSX Scalar Test Data Class Single-Precision */ 6131 1.3 christos case 362: /* VSX Scalar Test Data Class Double-Precision */ 6132 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6133 1.3 christos [[fallthrough]]; 6134 1.3 christos case 106: /* VSX Scalar Test for software Square Root 6135 1.3 christos Double-Precision */ 6136 1.3 christos case 234: /* VSX Vector Test for software Square Root 6137 1.3 christos Double-Precision */ 6138 1.7 christos case 170: /* VSX Vector Test for software Square Root 6139 1.7 christos Single-Precision */ 6140 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6141 1.7 christos return 0; 6142 1.7 christos 6143 1.7 christos case 347: 6144 1.10 christos switch (PPC_FIELD (insn, 11, 5)) 6145 1.7 christos { 6146 1.7 christos case 0: /* VSX Scalar Extract Exponent Double-Precision */ 6147 1.7 christos case 1: /* VSX Scalar Extract Significand Double-Precision */ 6148 1.7 christos record_full_arch_list_add_reg (regcache, 6149 1.7 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 6150 1.7 christos return 0; 6151 1.7 christos case 16: /* VSX Scalar Convert Half-Precision format to 6152 1.7 christos Double-Precision format */ 6153 1.7 christos case 17: /* VSX Scalar round & Convert Double-Precision format 6154 1.7 christos to Half-Precision format */ 6155 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6156 1.7 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6157 1.7 christos return 0; 6158 1.10 christos } 6159 1.10 christos break; 6160 1.10 christos 6161 1.10 christos case 475: 6162 1.10 christos if (ppc_process_record_op60_XX2 (gdbarch, regcache, addr, insn) != 0) 6163 1.10 christos return -1; 6164 1.10 christos return 0; 6165 1.10 christos } 6166 1.10 christos 6167 1.7 christos switch (ext) 6168 1.7 christos { 6169 1.7 christos case 360: 6170 1.7 christos if (PPC_FIELD (insn, 11, 2) == 0) /* VSX Vector Splat Immediate Byte */ 6171 1.10 christos { 6172 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6173 1.7 christos return 0; 6174 1.7 christos } 6175 1.7 christos if (PPC_FIELD (insn, 11, 5) == 31) /* Load VSX Vector Special Value 6176 1.7 christos Quadword */ 6177 1.7 christos { 6178 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6179 1.10 christos return 0; 6180 1.10 christos } 6181 1.10 christos break; 6182 1.7 christos case 916: /* VSX Vector Generate PCV from Byte Mask */ 6183 1.7 christos case 917: /* VSX Vector Generate PCV from Halfword Mask */ 6184 1.7 christos case 948: /* VSX Vector Generate PCV from Word Mask */ 6185 1.3 christos case 949: /* VSX Vector Generate PCV from Doubleword Mask */ 6186 1.3 christos case 918: /* VSX Scalar Insert Exponent Double-Precision */ 6187 1.3 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6188 1.3 christos return 0; 6189 1.3 christos } 6190 1.3 christos 6191 1.3 christos if (((ext >> 3) & 0x3) == 3) /* VSX Select */ 6192 1.3 christos { 6193 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6194 1.10 christos return 0; 6195 1.3 christos } 6196 1.3 christos 6197 1.3 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 6198 1.7 christos "at %s, 60-%d.\n", insn, paddress (gdbarch, addr), ext); 6199 1.7 christos return -1; 6200 1.7 christos } 6201 1.7 christos 6202 1.7 christos /* Parse and record instructions of primary opcode-61 at ADDR. 6203 1.7 christos Return 0 if successful. */ 6204 1.7 christos 6205 1.10 christos static int 6206 1.7 christos ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache, 6207 1.7 christos CORE_ADDR addr, uint32_t insn) 6208 1.7 christos { 6209 1.7 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6210 1.7 christos ULONGEST ea = 0; 6211 1.7 christos int size; 6212 1.7 christos 6213 1.7 christos switch (insn & 0x3) 6214 1.7 christos { 6215 1.7 christos case 0: /* Store Floating-Point Double Pair */ 6216 1.7 christos case 2: /* Store VSX Scalar Doubleword */ 6217 1.7 christos case 3: /* Store VSX Scalar Single */ 6218 1.7 christos if (PPC_RA (insn) != 0) 6219 1.7 christos regcache_raw_read_unsigned (regcache, 6220 1.7 christos tdep->ppc_gp0_regnum + PPC_RA (insn), 6221 1.7 christos &ea); 6222 1.7 christos ea += PPC_DS (insn) << 2; 6223 1.7 christos switch (insn & 0x3) 6224 1.7 christos { 6225 1.7 christos case 0: /* Store Floating-Point Double Pair */ 6226 1.7 christos size = 16; 6227 1.7 christos break; 6228 1.7 christos case 2: /* Store VSX Scalar Doubleword */ 6229 1.7 christos size = 8; 6230 1.7 christos break; 6231 1.7 christos case 3: /* Store VSX Scalar Single */ 6232 1.7 christos size = 4; 6233 1.7 christos break; 6234 1.7 christos default: 6235 1.7 christos gdb_assert (0); 6236 1.7 christos } 6237 1.7 christos record_full_arch_list_add_mem (ea, size); 6238 1.7 christos return 0; 6239 1.7 christos } 6240 1.7 christos 6241 1.7 christos switch (insn & 0x7) 6242 1.7 christos { 6243 1.7 christos case 1: /* Load VSX Vector */ 6244 1.7 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn)); 6245 1.7 christos return 0; 6246 1.7 christos case 5: /* Store VSX Vector */ 6247 1.7 christos if (PPC_RA (insn) != 0) 6248 1.7 christos regcache_raw_read_unsigned (regcache, 6249 1.7 christos tdep->ppc_gp0_regnum + PPC_RA (insn), 6250 1.7 christos &ea); 6251 1.7 christos ea += PPC_DQ (insn) << 4; 6252 1.10 christos record_full_arch_list_add_mem (ea, 16); 6253 1.10 christos return 0; 6254 1.7 christos } 6255 1.7 christos 6256 1.7 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 6257 1.3 christos "at %s.\n", insn, paddress (gdbarch, addr)); 6258 1.3 christos return -1; 6259 1.3 christos } 6260 1.3 christos 6261 1.3 christos /* Parse and record instructions of primary opcode-63 at ADDR. 6262 1.3 christos Return 0 if successful. */ 6263 1.3 christos 6264 1.10 christos static int 6265 1.3 christos ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache, 6266 1.3 christos CORE_ADDR addr, uint32_t insn) 6267 1.3 christos { 6268 1.3 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6269 1.3 christos int ext = PPC_EXTOP (insn); 6270 1.3 christos int tmp; 6271 1.3 christos 6272 1.3 christos switch (ext & 0x1f) 6273 1.3 christos { 6274 1.3 christos case 18: /* Floating Divide */ 6275 1.3 christos case 20: /* Floating Subtract */ 6276 1.3 christos case 21: /* Floating Add */ 6277 1.3 christos case 22: /* Floating Square Root */ 6278 1.3 christos case 24: /* Floating Reciprocal Estimate */ 6279 1.3 christos case 25: /* Floating Multiply */ 6280 1.3 christos case 26: /* Floating Reciprocal Square Root Estimate */ 6281 1.3 christos case 28: /* Floating Multiply-Subtract */ 6282 1.3 christos case 29: /* Floating Multiply-Add */ 6283 1.3 christos case 30: /* Floating Negative Multiply-Subtract */ 6284 1.3 christos case 31: /* Floating Negative Multiply-Add */ 6285 1.3 christos record_full_arch_list_add_reg (regcache, 6286 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6287 1.3 christos if (PPC_RC (insn)) 6288 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6289 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6290 1.3 christos return 0; 6291 1.3 christos 6292 1.3 christos case 23: /* Floating Select */ 6293 1.7 christos record_full_arch_list_add_reg (regcache, 6294 1.7 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6295 1.7 christos if (PPC_RC (insn)) 6296 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6297 1.7 christos return 0; 6298 1.7 christos } 6299 1.7 christos 6300 1.7 christos switch (ext & 0xff) 6301 1.7 christos { 6302 1.7 christos case 5: /* VSX Scalar Round to Quad-Precision Integer */ 6303 1.7 christos case 37: /* VSX Scalar Round Quad-Precision to Double-Extended 6304 1.3 christos Precision */ 6305 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6306 1.3 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 6307 1.3 christos return 0; 6308 1.3 christos } 6309 1.3 christos 6310 1.3 christos switch (ext) 6311 1.3 christos { 6312 1.3 christos case 2: /* DFP Add Quad */ 6313 1.3 christos case 3: /* DFP Quantize Quad */ 6314 1.3 christos case 34: /* DFP Multiply Quad */ 6315 1.3 christos case 35: /* DFP Reround Quad */ 6316 1.3 christos case 67: /* DFP Quantize Immediate Quad */ 6317 1.3 christos case 99: /* DFP Round To FP Integer With Inexact Quad */ 6318 1.3 christos case 227: /* DFP Round To FP Integer Without Inexact Quad */ 6319 1.3 christos case 258: /* DFP Convert To DFP Extended Quad */ 6320 1.3 christos case 514: /* DFP Subtract Quad */ 6321 1.3 christos case 546: /* DFP Divide Quad */ 6322 1.3 christos case 770: /* DFP Round To DFP Long Quad */ 6323 1.3 christos case 802: /* DFP Convert From Fixed Quad */ 6324 1.3 christos case 834: /* DFP Encode BCD To DPD Quad */ 6325 1.3 christos if (PPC_RC (insn)) 6326 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6327 1.3 christos tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1); 6328 1.3 christos record_full_arch_list_add_reg (regcache, tmp); 6329 1.3 christos record_full_arch_list_add_reg (regcache, tmp + 1); 6330 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6331 1.3 christos return 0; 6332 1.3 christos 6333 1.3 christos case 130: /* DFP Compare Ordered Quad */ 6334 1.3 christos case 162: /* DFP Test Exponent Quad */ 6335 1.7 christos case 194: /* DFP Test Data Class Quad */ 6336 1.3 christos case 226: /* DFP Test Data Group Quad */ 6337 1.3 christos case 642: /* DFP Compare Unordered Quad */ 6338 1.3 christos case 674: /* DFP Test Significance Quad */ 6339 1.3 christos case 675: /* DFP Test Significance Immediate Quad */ 6340 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6341 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6342 1.3 christos return 0; 6343 1.3 christos 6344 1.3 christos case 66: /* DFP Shift Significand Left Immediate Quad */ 6345 1.3 christos case 98: /* DFP Shift Significand Right Immediate Quad */ 6346 1.3 christos case 322: /* DFP Decode DPD To BCD Quad */ 6347 1.3 christos case 866: /* DFP Insert Biased Exponent Quad */ 6348 1.3 christos tmp = tdep->ppc_fp0_regnum + (PPC_FRT (insn) & ~1); 6349 1.3 christos record_full_arch_list_add_reg (regcache, tmp); 6350 1.3 christos record_full_arch_list_add_reg (regcache, tmp + 1); 6351 1.3 christos if (PPC_RC (insn)) 6352 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6353 1.3 christos return 0; 6354 1.3 christos 6355 1.3 christos case 290: /* DFP Convert To Fixed Quad */ 6356 1.3 christos record_full_arch_list_add_reg (regcache, 6357 1.7 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6358 1.3 christos if (PPC_RC (insn)) 6359 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6360 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6361 1.3 christos return 0; 6362 1.3 christos 6363 1.3 christos case 354: /* DFP Extract Biased Exponent Quad */ 6364 1.3 christos record_full_arch_list_add_reg (regcache, 6365 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6366 1.3 christos if (PPC_RC (insn)) 6367 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6368 1.3 christos return 0; 6369 1.3 christos 6370 1.3 christos case 12: /* Floating Round to Single-Precision */ 6371 1.3 christos case 14: /* Floating Convert To Integer Word */ 6372 1.3 christos case 15: /* Floating Convert To Integer Word 6373 1.3 christos with round toward Zero */ 6374 1.3 christos case 142: /* Floating Convert To Integer Word Unsigned */ 6375 1.3 christos case 143: /* Floating Convert To Integer Word Unsigned 6376 1.3 christos with round toward Zero */ 6377 1.3 christos case 392: /* Floating Round to Integer Nearest */ 6378 1.3 christos case 424: /* Floating Round to Integer Toward Zero */ 6379 1.3 christos case 456: /* Floating Round to Integer Plus */ 6380 1.3 christos case 488: /* Floating Round to Integer Minus */ 6381 1.3 christos case 814: /* Floating Convert To Integer Doubleword */ 6382 1.3 christos case 815: /* Floating Convert To Integer Doubleword 6383 1.3 christos with round toward Zero */ 6384 1.3 christos case 846: /* Floating Convert From Integer Doubleword */ 6385 1.3 christos case 942: /* Floating Convert To Integer Doubleword Unsigned */ 6386 1.3 christos case 943: /* Floating Convert To Integer Doubleword Unsigned 6387 1.3 christos with round toward Zero */ 6388 1.3 christos case 974: /* Floating Convert From Integer Doubleword Unsigned */ 6389 1.3 christos record_full_arch_list_add_reg (regcache, 6390 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6391 1.3 christos if (PPC_RC (insn)) 6392 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6393 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6394 1.10 christos return 0; 6395 1.7 christos 6396 1.7 christos case 583: 6397 1.7 christos switch (PPC_FIELD (insn, 11, 5)) 6398 1.7 christos { 6399 1.7 christos case 1: /* Move From FPSCR & Clear Enables */ 6400 1.7 christos case 20: /* Move From FPSCR Control & set DRN */ 6401 1.11 christos case 21: /* Move From FPSCR Control & set DRN Immediate */ 6402 1.7 christos case 22: /* Move From FPSCR Control & set RN */ 6403 1.7 christos case 23: /* Move From FPSCR Control & set RN Immediate */ 6404 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6405 1.7 christos [[fallthrough]]; 6406 1.7 christos case 0: /* Move From FPSCR */ 6407 1.7 christos case 24: /* Move From FPSCR Lightweight */ 6408 1.7 christos if (PPC_FIELD (insn, 11, 5) == 0 && PPC_RC (insn)) 6409 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6410 1.10 christos record_full_arch_list_add_reg (regcache, 6411 1.7 christos tdep->ppc_fp0_regnum 6412 1.7 christos + PPC_FRT (insn)); 6413 1.3 christos return 0; 6414 1.3 christos } 6415 1.3 christos break; 6416 1.3 christos 6417 1.3 christos case 8: /* Floating Copy Sign */ 6418 1.3 christos case 40: /* Floating Negate */ 6419 1.3 christos case 72: /* Floating Move Register */ 6420 1.3 christos case 136: /* Floating Negative Absolute Value */ 6421 1.3 christos case 264: /* Floating Absolute Value */ 6422 1.3 christos record_full_arch_list_add_reg (regcache, 6423 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6424 1.3 christos if (PPC_RC (insn)) 6425 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6426 1.3 christos return 0; 6427 1.3 christos 6428 1.3 christos case 838: /* Floating Merge Odd Word */ 6429 1.3 christos case 966: /* Floating Merge Even Word */ 6430 1.3 christos record_full_arch_list_add_reg (regcache, 6431 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 6432 1.3 christos return 0; 6433 1.3 christos 6434 1.3 christos case 38: /* Move To FPSCR Bit 1 */ 6435 1.3 christos case 70: /* Move To FPSCR Bit 0 */ 6436 1.3 christos case 134: /* Move To FPSCR Field Immediate */ 6437 1.7 christos case 711: /* Move To FPSCR Fields */ 6438 1.3 christos if (PPC_RC (insn)) 6439 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6440 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6441 1.3 christos return 0; 6442 1.7 christos 6443 1.7 christos case 0: /* Floating Compare Unordered */ 6444 1.7 christos case 32: /* Floating Compare Ordered */ 6445 1.7 christos case 64: /* Move to Condition Register from FPSCR */ 6446 1.3 christos case 132: /* VSX Scalar Compare Ordered Quad-Precision */ 6447 1.11 christos case 164: /* VSX Scalar Compare Exponents Quad-Precision */ 6448 1.3 christos case 644: /* VSX Scalar Compare Unordered Quad-Precision */ 6449 1.3 christos case 708: /* VSX Scalar Test Data Class Quad-Precision */ 6450 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6451 1.3 christos [[fallthrough]]; 6452 1.3 christos case 128: /* Floating Test for software Divide */ 6453 1.7 christos case 160: /* Floating Test for software Square Root */ 6454 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 6455 1.7 christos return 0; 6456 1.7 christos 6457 1.7 christos case 4: /* VSX Scalar Add Quad-Precision */ 6458 1.7 christos case 36: /* VSX Scalar Multiply Quad-Precision */ 6459 1.7 christos case 388: /* VSX Scalar Multiply-Add Quad-Precision */ 6460 1.7 christos case 420: /* VSX Scalar Multiply-Subtract Quad-Precision */ 6461 1.7 christos case 452: /* VSX Scalar Negative Multiply-Add Quad-Precision */ 6462 1.10 christos case 484: /* VSX Scalar Negative Multiply-Subtract 6463 1.10 christos Quad-Precision */ 6464 1.10 christos case 516: /* VSX Scalar Subtract Quad-Precision */ 6465 1.10 christos case 548: /* VSX Scalar Divide Quad-Precision */ 6466 1.10 christos case 994: 6467 1.10 christos { 6468 1.10 christos switch (PPC_FIELD (insn, 11, 5)) 6469 1.10 christos { 6470 1.10 christos case 0: /* DFP Convert From Fixed Quadword Quad */ 6471 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6472 1.10 christos 6473 1.10 christos record_full_arch_list_add_reg (regcache, 6474 1.10 christos tdep->ppc_fp0_regnum 6475 1.10 christos + PPC_FRT (insn)); 6476 1.10 christos record_full_arch_list_add_reg (regcache, 6477 1.10 christos tdep->ppc_fp0_regnum 6478 1.10 christos + PPC_FRT (insn) + 1); 6479 1.10 christos return 0; 6480 1.10 christos case 1: /* DFP Convert To Fixed Quadword Quad */ 6481 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6482 1.10 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 6483 1.10 christos return 0; 6484 1.11 christos } 6485 1.10 christos } 6486 1.10 christos 6487 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6488 1.10 christos [[fallthrough]]; 6489 1.10 christos case 68: /* VSX Scalar Compare Equal Quad-Precision */ 6490 1.10 christos case 196: /* VSX Scalar Compare Greater Than or Equal 6491 1.7 christos Quad-Precision */ 6492 1.11 christos case 228: /* VSX Scalar Compare Greater Than Quad-Precision */ 6493 1.7 christos case 676: /* VSX Scalar Maximum Type-C Quad-Precision */ 6494 1.7 christos case 740: /* VSX Scalar Minimum Type-C Quad-Precision */ 6495 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6496 1.7 christos [[fallthrough]]; 6497 1.7 christos case 100: /* VSX Scalar Copy Sign Quad-Precision */ 6498 1.7 christos case 868: /* VSX Scalar Insert Exponent Quad-Precision */ 6499 1.7 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 6500 1.7 christos return 0; 6501 1.7 christos 6502 1.7 christos case 804: 6503 1.11 christos switch (PPC_FIELD (insn, 11, 5)) 6504 1.7 christos { 6505 1.7 christos case 27: /* VSX Scalar Square Root Quad-Precision */ 6506 1.7 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6507 1.7 christos [[fallthrough]]; 6508 1.7 christos case 0: /* VSX Scalar Absolute Quad-Precision */ 6509 1.7 christos case 2: /* VSX Scalar Extract Exponent Quad-Precision */ 6510 1.7 christos case 8: /* VSX Scalar Negative Absolute Quad-Precision */ 6511 1.7 christos case 16: /* VSX Scalar Negate Quad-Precision */ 6512 1.7 christos case 18: /* VSX Scalar Extract Significand Quad-Precision */ 6513 1.7 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 6514 1.7 christos return 0; 6515 1.7 christos } 6516 1.7 christos break; 6517 1.10 christos 6518 1.10 christos case 836: 6519 1.7 christos switch (PPC_FIELD (insn, 11, 5)) 6520 1.7 christos { 6521 1.7 christos case 0: /* VSX Scalar Convert with round to zero 6522 1.7 christos Quad-Precision to Unsigned Quadword */ 6523 1.10 christos case 1: /* VSX Scalar truncate & Convert Quad-Precision format 6524 1.10 christos to Unsigned Word format */ 6525 1.10 christos case 2: /* VSX Scalar Convert Unsigned Doubleword format to 6526 1.10 christos Quad-Precision format */ 6527 1.7 christos case 3: /* VSX Scalar Convert with round 6528 1.7 christos Unsigned Quadword to Quad-Precision */ 6529 1.7 christos case 8: /* VSX Scalar Convert with round to zero 6530 1.7 christos Quad-Precision to Signed Quadword */ 6531 1.10 christos case 9: /* VSX Scalar truncate & Convert Quad-Precision format 6532 1.10 christos to Signed Word format */ 6533 1.7 christos case 10: /* VSX Scalar Convert Signed Doubleword format to 6534 1.7 christos Quad-Precision format */ 6535 1.7 christos case 11: /* VSX Scalar Convert with round 6536 1.7 christos Signed Quadword to Quad-Precision */ 6537 1.7 christos case 17: /* VSX Scalar truncate & Convert Quad-Precision format 6538 1.7 christos to Unsigned Doubleword format */ 6539 1.7 christos case 20: /* VSX Scalar round & Convert Quad-Precision format to 6540 1.7 christos Double-Precision format */ 6541 1.7 christos case 22: /* VSX Scalar Convert Double-Precision format to 6542 1.7 christos Quad-Precision format */ 6543 1.7 christos case 25: /* VSX Scalar truncate & Convert Quad-Precision format 6544 1.7 christos to Signed Doubleword format */ 6545 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_fpscr_regnum); 6546 1.3 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 6547 1.10 christos return 0; 6548 1.10 christos } 6549 1.3 christos } 6550 1.3 christos 6551 1.3 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 6552 1.10 christos "at %s, 63-%d.\n", insn, paddress (gdbarch, addr), ext); 6553 1.10 christos return -1; 6554 1.10 christos } 6555 1.10 christos 6556 1.10 christos /* Record the prefixed instructions with primary opcode 32. The arguments are 6557 1.10 christos the first 32-bits of the instruction (insn_prefix), and the second 32-bits 6558 1.10 christos of the instruction (insn_suffix). Return 0 on success. */ 6559 1.10 christos 6560 1.10 christos static int 6561 1.10 christos ppc_process_record_prefix_op42 (struct gdbarch *gdbarch, 6562 1.10 christos struct regcache *regcache, 6563 1.10 christos uint32_t insn_prefix, uint32_t insn_suffix) 6564 1.10 christos { 6565 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6566 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6567 1.10 christos int ST1 = PPC_FIELD (insn_prefix, 8, 1); 6568 1.10 christos 6569 1.10 christos if (ST1 != 0) 6570 1.10 christos return -1; 6571 1.10 christos 6572 1.10 christos switch (type) 6573 1.10 christos { 6574 1.10 christos case 0: /* Prefixed Load VSX Scalar Doubleword, plxsd */ 6575 1.10 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn_suffix) + 32); 6576 1.10 christos break; 6577 1.10 christos case 2: /* Prefixed Load Halfword Algebraic, plha */ 6578 1.10 christos record_full_arch_list_add_reg (regcache, 6579 1.10 christos tdep->ppc_gp0_regnum 6580 1.10 christos + PPC_RT (insn_suffix)); 6581 1.10 christos break; 6582 1.10 christos default: 6583 1.10 christos return -1; 6584 1.10 christos } 6585 1.10 christos return 0; 6586 1.10 christos } 6587 1.10 christos 6588 1.10 christos /* Record the prefixed XX3-Form instructions with primary opcode 59. The 6589 1.10 christos arguments are the first 32-bits of the instruction (insn_prefix), and the 6590 1.10 christos second 32-bits of the instruction (insn_suffix). Return 0 on success. */ 6591 1.10 christos 6592 1.10 christos static int 6593 1.10 christos ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch, 6594 1.10 christos struct regcache *regcache, 6595 1.10 christos uint32_t insn_prefix, uint32_t insn_suffix) 6596 1.10 christos { 6597 1.10 christos int opcode = PPC_FIELD (insn_suffix, 21, 8); 6598 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6599 1.10 christos int ST4 = PPC_FIELD (insn_prefix, 8, 4); 6600 1.10 christos int at = PPC_FIELD (insn_suffix, 6, 3); 6601 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6602 1.10 christos 6603 1.10 christos /* Note, the mnemonics for the pmxvf16ger*, pmxvf32ger*,pmxvf64ger*, 6604 1.10 christos pmxvi4ger8*, pmxvi8ger4* pmxvi16ger2* instructions were officially 6605 1.10 christos changed to pmdmxbf16ger*, pmdmxvf32ger*, pmdmxvf64ger*, pmdmxvi4ger8*, 6606 1.10 christos pmdmxvi8ger4*, pmdmxvi16ger* respectively. The old mnemonics are still 6607 1.10 christos supported by the assembler as extended mnemonics. The disassembler 6608 1.10 christos generates the new mnemonics. */ 6609 1.10 christos if (type == 3) 6610 1.10 christos { 6611 1.10 christos if (ST4 == 9) 6612 1.10 christos switch (opcode) 6613 1.10 christos { 6614 1.10 christos case 35: /* Prefixed Masked VSX Vector 4-bit Signed Integer GER 6615 1.10 christos MMIRR, pmdmxvi4ger8 (pmxvi4ger8) */ 6616 1.10 christos case 34: /* Prefixed Masked VSX Vector 4-bit Signed Integer GER 6617 1.10 christos MMIRR, pmdmxvi4ger8pp (pmxvi4ger8pp) */ 6618 1.10 christos 6619 1.10 christos case 99: /* Prefixed Masked VSX Vector 8-bit Signed/Unsigned 6620 1.10 christos Integer GER with Saturate Positive multiply, 6621 1.10 christos Positive accumulate, xvi8ger4spp */ 6622 1.10 christos 6623 1.10 christos case 3: /* Prefixed Masked VSX Vector 8-bit Signed/Unsigned 6624 1.10 christos Integer GER MMIRR, pmdmxvi8ger4 (pmxvi8ger4) */ 6625 1.10 christos case 2: /* Prefixed Masked VSX Vector 8-bit Signed/Unsigned 6626 1.10 christos Integer GER Positive multiply, Positive accumulate 6627 1.10 christos MMIRR, pmdmxvi8ger4pp (pmxvi8ger4pp) */ 6628 1.10 christos 6629 1.10 christos case 75: /* Prefixed Masked VSX Vector 16-bit Signed Integer 6630 1.10 christos GER MMIRR, pmdmxvi16ger2 (pmxvi16ger2) */ 6631 1.10 christos case 107: /* Prefixed Masked VSX Vector 16-bit Signed Integer 6632 1.10 christos GER Positive multiply, Positive accumulate, 6633 1.10 christos pmdmxvi16ger2pp (pmxvi16ger2pp) */ 6634 1.10 christos 6635 1.10 christos case 43: /* Prefixed Masked VSX Vector 16-bit Signed Integer 6636 1.10 christos GER with Saturation MMIRR, pmdmxvi16ger2s 6637 1.10 christos (pmxvi16ger2s) */ 6638 1.10 christos case 42: /* Prefixed Masked VSX Vector 16-bit Signed Integer 6639 1.10 christos GER with Saturation Positive multiply, Positive 6640 1.10 christos accumulate MMIRR, pmdmxvi16ger2spp (pmxvi16ger2spp) 6641 1.10 christos */ 6642 1.10 christos ppc_record_ACC_fpscr (regcache, tdep, at, false); 6643 1.10 christos return 0; 6644 1.10 christos 6645 1.10 christos case 19: /* Prefixed Masked VSX Vector 16-bit Floating-Point 6646 1.10 christos GER MMIRR, pmdmxvf16ger2 (pmxvf16ger2) */ 6647 1.10 christos case 18: /* Prefixed Masked VSX Vector 16-bit Floating-Point 6648 1.10 christos GER Positive multiply, Positive accumulate MMIRR, 6649 1.10 christos pmdmxvf16ger2pp (pmxvf16ger2pp) */ 6650 1.10 christos case 146: /* Prefixed Masked VSX Vector 16-bit Floating-Point 6651 1.10 christos GER Positive multiply, Negative accumulate MMIRR, 6652 1.10 christos pmdmxvf16ger2pn (pmxvf16ger2pn) */ 6653 1.10 christos case 82: /* Prefixed Masked VSX Vector 16-bit Floating-Point 6654 1.10 christos GER Negative multiply, Positive accumulate MMIRR, 6655 1.10 christos pmdmxvf16ger2np (pmxvf16ger2np) */ 6656 1.10 christos case 210: /* Prefixed Masked VSX Vector 16-bit Floating-Point 6657 1.10 christos GER Negative multiply, Negative accumulate MMIRR, 6658 1.10 christos pmdmxvf16ger2nn (pmxvf16ger2nn) */ 6659 1.10 christos 6660 1.10 christos case 27: /* Prefixed Masked VSX Vector 32-bit Floating-Point 6661 1.10 christos GER MMIRR, pmdmxvf32ger (pmxvf32ger) */ 6662 1.10 christos case 26: /* Prefixed Masked VSX Vector 32-bit Floating-Point 6663 1.10 christos GER Positive multiply, Positive accumulate MMIRR, 6664 1.10 christos pmdmxvf32gerpp (pmxvf32gerpp) */ 6665 1.10 christos case 154: /* Prefixed Masked VSX Vector 32-bit Floating-Point 6666 1.10 christos GER Positive multiply, Negative accumulate MMIRR, 6667 1.10 christos pmdmxvf32gerpn (pmxvf32gerpn) */ 6668 1.10 christos case 90: /* Prefixed Masked VSX Vector 32-bit Floating-Point 6669 1.10 christos GER Negative multiply, Positive accumulate MMIRR, 6670 1.10 christos pmdmxvf32gernp (pmxvf32gernp )*/ 6671 1.10 christos case 218: /* Prefixed Masked VSX Vector 32-bit Floating-Point 6672 1.10 christos GER Negative multiply, Negative accumulate MMIRR, 6673 1.10 christos pmdmxvf32gernn (pmxvf32gernn) */ 6674 1.10 christos 6675 1.10 christos case 59: /* Prefixed Masked VSX Vector 64-bit Floating-Point 6676 1.10 christos GER MMIRR, pmdmxvf64ger (pmxvf64ger) */ 6677 1.10 christos case 58: /* Floating-Point GER Positive multiply, Positive 6678 1.10 christos accumulate MMIRR, pmdmxvf64gerpp (pmxvf64gerpp) */ 6679 1.10 christos case 186: /* Prefixed Masked VSX Vector 64-bit Floating-Point 6680 1.10 christos GER Positive multiply, Negative accumulate MMIRR, 6681 1.10 christos pmdmxvf64gerpn (pmxvf64gerpn) */ 6682 1.10 christos case 122: /* Prefixed Masked VSX Vector 64-bit Floating-Point 6683 1.10 christos GER Negative multiply, Positive accumulate MMIRR, 6684 1.10 christos pmdmxvf64gernp (pmxvf64gernp) */ 6685 1.10 christos case 250: /* Prefixed Masked VSX Vector 64-bit Floating-Point 6686 1.10 christos GER Negative multiply, Negative accumulate MMIRR, 6687 1.10 christos pmdmxvf64gernn (pmxvf64gernn) */ 6688 1.10 christos 6689 1.10 christos case 51: /* Prefixed Masked VSX Vector bfloat16 GER MMIRR, 6690 1.10 christos pmdmxvbf16ger2 (pmxvbf16ger2) */ 6691 1.10 christos case 50: /* Prefixed Masked VSX Vector bfloat16 GER Positive 6692 1.10 christos multiply, Positive accumulate MMIRR, 6693 1.10 christos pmdmxvbf16ger2pp (pmxvbf16ger2pp) */ 6694 1.10 christos case 178: /* Prefixed Masked VSX Vector bfloat16 GER Positive 6695 1.10 christos multiply, Negative accumulate MMIRR, 6696 1.10 christos pmdmxvbf16ger2pn (pmxvbf16ger2pn) */ 6697 1.10 christos case 114: /* Prefixed Masked VSX Vector bfloat16 GER Negative 6698 1.10 christos multiply, Positive accumulate MMIRR, 6699 1.10 christos pmdmxvbf16ger2np (pmxvbf16ger2np) */ 6700 1.10 christos case 242: /* Prefixed Masked VSX Vector bfloat16 GER Negative 6701 1.10 christos multiply, Negative accumulate MMIRR, 6702 1.10 christos pmdmxvbf16ger2nn (pmxvbf16ger2nn) */ 6703 1.10 christos ppc_record_ACC_fpscr (regcache, tdep, at, true); 6704 1.10 christos return 0; 6705 1.10 christos } 6706 1.10 christos } 6707 1.10 christos else 6708 1.10 christos return -1; 6709 1.10 christos 6710 1.10 christos return 0; 6711 1.10 christos } 6712 1.10 christos 6713 1.10 christos /* Record the prefixed store instructions. The arguments are the instruction 6714 1.10 christos address, the first 32-bits of the instruction(insn_prefix) and the following 6715 1.10 christos 32-bits of the instruction (insn_suffix). Return 0 on success. */ 6716 1.10 christos 6717 1.10 christos static int 6718 1.10 christos ppc_process_record_prefix_store (struct gdbarch *gdbarch, 6719 1.10 christos struct regcache *regcache, 6720 1.10 christos CORE_ADDR addr, uint32_t insn_prefix, 6721 1.10 christos uint32_t insn_suffix) 6722 1.10 christos { 6723 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6724 1.10 christos ULONGEST iaddr = 0; 6725 1.10 christos int size; 6726 1.10 christos int R = PPC_BIT (insn_prefix, 11); 6727 1.10 christos int op6 = PPC_OP6 (insn_suffix); 6728 1.10 christos 6729 1.10 christos if (R == 0) 6730 1.10 christos { 6731 1.10 christos if (PPC_RA (insn_suffix) != 0) 6732 1.10 christos regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum 6733 1.10 christos + PPC_RA (insn_suffix), &iaddr); 6734 1.10 christos } 6735 1.10 christos else 6736 1.10 christos { 6737 1.10 christos iaddr = addr; /* PC relative */ 6738 1.10 christos } 6739 1.10 christos 6740 1.10 christos switch (op6) 6741 1.10 christos { 6742 1.10 christos case 38: 6743 1.10 christos size = 1; /* store byte, pstb */ 6744 1.10 christos break; 6745 1.10 christos case 44: 6746 1.10 christos size = 2; /* store halfword, psth */ 6747 1.10 christos break; 6748 1.10 christos case 36: 6749 1.10 christos case 52: 6750 1.10 christos size = 4; /* store word, pstw, pstfs */ 6751 1.10 christos break; 6752 1.10 christos case 54: 6753 1.10 christos case 61: 6754 1.10 christos size = 8; /* store double word, pstd, pstfd */ 6755 1.10 christos break; 6756 1.10 christos case 60: 6757 1.10 christos size = 16; /* store quadword, pstq */ 6758 1.10 christos break; 6759 1.10 christos default: return -1; 6760 1.10 christos } 6761 1.10 christos 6762 1.10 christos iaddr += P_PPC_D (insn_prefix, insn_suffix); 6763 1.10 christos record_full_arch_list_add_mem (iaddr, size); 6764 1.10 christos return 0; 6765 1.10 christos } 6766 1.10 christos 6767 1.10 christos /* Record the prefixed instructions with primary op code 32. The arguments 6768 1.10 christos are the first 32-bits of the instruction (insn_prefix) and the following 6769 1.10 christos 32-bits of the instruction (insn_suffix). Return 0 on success. */ 6770 1.10 christos 6771 1.10 christos static int 6772 1.10 christos ppc_process_record_prefix_op32 (struct gdbarch *gdbarch, 6773 1.10 christos struct regcache *regcache, 6774 1.10 christos uint32_t insn_prefix, uint32_t insn_suffix) 6775 1.10 christos { 6776 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6777 1.10 christos int ST1 = PPC_FIELD (insn_prefix, 8, 1); 6778 1.10 christos int ST4 = PPC_FIELD (insn_prefix, 8, 4); 6779 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6780 1.10 christos 6781 1.10 christos if (type == 1) 6782 1.10 christos { 6783 1.10 christos if (ST4 == 0) 6784 1.10 christos { 6785 1.10 christos switch (PPC_FIELD (insn_suffix, 11, 3)) 6786 1.10 christos { 6787 1.10 christos case 0: /* VSX Vector Splat Immediate Word 8RR, xxsplti32dx */ 6788 1.10 christos ppc_record_vsr (regcache, tdep, P_PPC_XT15 (insn_suffix)); 6789 1.10 christos return 0; 6790 1.10 christos } 6791 1.10 christos 6792 1.10 christos switch (PPC_FIELD (insn_suffix, 11, 4)) 6793 1.10 christos { 6794 1.10 christos case 2: /* VSX Vector Splat Immediate Double-Precision 6795 1.10 christos 8RR, xxspltidp */ 6796 1.10 christos case 3: /* VSX Vector Splat Immediate Word 8RR, xxspltiw */ 6797 1.10 christos ppc_record_vsr (regcache, tdep, P_PPC_XT15 (insn_suffix)); 6798 1.10 christos return 0; 6799 1.10 christos default: 6800 1.10 christos return -1; 6801 1.10 christos } 6802 1.10 christos } 6803 1.10 christos else 6804 1.10 christos return -1; 6805 1.10 christos 6806 1.10 christos } 6807 1.10 christos else if (type == 2) 6808 1.10 christos { 6809 1.10 christos if (ST1 == 0) /* Prefixed Load Word and Zero, plwz */ 6810 1.10 christos record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum 6811 1.10 christos + PPC_RT (insn_suffix)); 6812 1.10 christos else 6813 1.10 christos return -1; 6814 1.10 christos 6815 1.10 christos } 6816 1.10 christos else 6817 1.10 christos return -1; 6818 1.10 christos 6819 1.10 christos return 0; 6820 1.10 christos } 6821 1.10 christos 6822 1.10 christos /* Record the prefixed instructions with primary op code 33. The arguments 6823 1.10 christos are the first 32-bits of the instruction(insn_prefix) and the following 6824 1.10 christos 32-bits of the instruction (insn_suffix). Return 0 on success. */ 6825 1.10 christos 6826 1.10 christos static int 6827 1.10 christos ppc_process_record_prefix_op33 (struct gdbarch *gdbarch, 6828 1.10 christos struct regcache *regcache, 6829 1.10 christos uint32_t insn_prefix, uint32_t insn_suffix) 6830 1.10 christos { 6831 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6832 1.10 christos int ST4 = PPC_FIELD (insn_prefix, 8, 4); 6833 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6834 1.10 christos 6835 1.10 christos if (type == 1) 6836 1.10 christos { 6837 1.10 christos if (ST4 == 0) 6838 1.10 christos switch (PPC_FIELD (insn_suffix, 26, 2)) 6839 1.10 christos { 6840 1.10 christos case 0: /* VSX Vector Blend Variable Byte 8RR, xxblendvb */ 6841 1.10 christos case 1: /* VSX Vector Blend Variable Halfword, xxblendvh */ 6842 1.10 christos case 2: /* VSX Vector Blend Variable Word, xxblendvw */ 6843 1.10 christos case 3: /* VSX Vector Blend Variable Doubleword, xxblendvd */ 6844 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XT (insn_suffix)); 6845 1.10 christos break; 6846 1.10 christos default: 6847 1.10 christos return -1; 6848 1.10 christos } 6849 1.10 christos else 6850 1.10 christos return -1; 6851 1.10 christos 6852 1.10 christos } 6853 1.10 christos else 6854 1.10 christos return -1; 6855 1.10 christos 6856 1.10 christos return 0; 6857 1.10 christos } 6858 1.10 christos 6859 1.10 christos /* Record the prefixed instructions with primary op code 34. The arguments 6860 1.10 christos are the first 32-bits of the instruction(insn_prefix) and the following 6861 1.10 christos 32-bits of the instruction (insn_suffix). Return 0 on success. */ 6862 1.10 christos 6863 1.10 christos static int 6864 1.10 christos ppc_process_record_prefix_op34 (struct gdbarch *gdbarch, 6865 1.10 christos struct regcache *regcache, 6866 1.10 christos uint32_t insn_prefix, uint32_t insn_suffix) 6867 1.10 christos { 6868 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6869 1.10 christos int ST1 = PPC_FIELD (insn_prefix, 8, 1); 6870 1.10 christos int ST4 = PPC_FIELD (insn_prefix, 8, 4); 6871 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6872 1.10 christos 6873 1.10 christos if (type == 1) 6874 1.10 christos { 6875 1.10 christos if (ST4 == 0) 6876 1.10 christos switch (PPC_FIELD (insn_suffix, 26, 2)) 6877 1.10 christos { 6878 1.10 christos case 0: /* VSX Vector Permute Extended 8RR, xxpermx */ 6879 1.10 christos case 1: /* VSX Vector Evaluate 8RR, xxeval */ 6880 1.10 christos ppc_record_vsr (regcache, tdep, P_PPC_XT (insn_suffix)); 6881 1.10 christos break; 6882 1.10 christos default: 6883 1.10 christos return -1; 6884 1.10 christos } 6885 1.10 christos else 6886 1.10 christos return -1; 6887 1.10 christos 6888 1.10 christos } 6889 1.10 christos else if (type == 2) 6890 1.10 christos { 6891 1.10 christos if (ST1 == 0) /* Prefixed Load Word and Zero, plbz */ 6892 1.10 christos record_full_arch_list_add_reg (regcache, 6893 1.10 christos tdep->ppc_gp0_regnum 6894 1.10 christos + PPC_RT (insn_suffix)); 6895 1.10 christos else 6896 1.10 christos return -1; 6897 1.10 christos 6898 1.10 christos } 6899 1.10 christos else 6900 1.10 christos return -1; 6901 1.10 christos 6902 1.10 christos return 0; 6903 1.10 christos } 6904 1.10 christos 6905 1.10 christos /* Record the prefixed VSX store, form DS, instructions. The arguments are the 6906 1.10 christos instruction address (addr), the first 32-bits of the instruction 6907 1.10 christos (insn_prefix) followed by the 32-bit instruction suffix (insn_suffix). 6908 1.10 christos Return 0 on success. */ 6909 1.10 christos 6910 1.10 christos static int 6911 1.10 christos ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch, 6912 1.10 christos struct regcache *regcache, 6913 1.10 christos CORE_ADDR addr, 6914 1.10 christos uint32_t insn_prefix, 6915 1.10 christos uint32_t insn_suffix) 6916 1.10 christos { 6917 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6918 1.10 christos ULONGEST ea = 0; 6919 1.10 christos int size; 6920 1.10 christos int R = PPC_BIT (insn_prefix, 11); 6921 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6922 1.10 christos int ST1 = PPC_FIELD (insn_prefix, 8, 1); 6923 1.10 christos 6924 1.10 christos if ((type == 0) && (ST1 == 0)) 6925 1.10 christos { 6926 1.10 christos if (R == 0) 6927 1.10 christos { 6928 1.10 christos if (PPC_RA (insn_suffix) != 0) 6929 1.10 christos regcache_raw_read_unsigned (regcache, 6930 1.10 christos tdep->ppc_gp0_regnum 6931 1.10 christos + PPC_RA (insn_suffix), 6932 1.10 christos &ea); 6933 1.10 christos } 6934 1.10 christos else 6935 1.10 christos { 6936 1.10 christos ea = addr; /* PC relative */ 6937 1.10 christos } 6938 1.10 christos 6939 1.10 christos ea += P_PPC_D (insn_prefix, insn_suffix); 6940 1.10 christos switch (PPC_FIELD (insn_suffix, 0, 6)) 6941 1.10 christos { 6942 1.10 christos case 46: /* Prefixed Store VSX Scalar Doubleword, pstxsd */ 6943 1.10 christos size = 8; 6944 1.10 christos break; 6945 1.10 christos case 47: /* Prefixed,Store VSX Scalar Single-Precision, pstxssp */ 6946 1.10 christos size = 4; 6947 1.10 christos break; 6948 1.10 christos default: 6949 1.10 christos return -1; 6950 1.10 christos } 6951 1.10 christos record_full_arch_list_add_mem (ea, size); 6952 1.10 christos return 0; 6953 1.10 christos } 6954 1.10 christos else 6955 1.10 christos return -1; 6956 1.10 christos } 6957 1.10 christos 6958 1.10 christos /* Record the prefixed VSX, form D, instructions. The arguments are the 6959 1.10 christos instruction address for PC-relative addresss (addr), the first 32-bits of 6960 1.10 christos the instruction (insn_prefix) and the following 32-bits of the instruction 6961 1.10 christos (insn_suffix). Return 0 on success. */ 6962 1.10 christos 6963 1.10 christos static int 6964 1.10 christos ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch, 6965 1.10 christos struct regcache *regcache, 6966 1.10 christos CORE_ADDR addr, 6967 1.10 christos uint32_t insn_prefix, 6968 1.10 christos uint32_t insn_suffix) 6969 1.10 christos { 6970 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 6971 1.10 christos ULONGEST ea = 0; 6972 1.10 christos int size; 6973 1.10 christos int R = PPC_BIT (insn_prefix, 11); 6974 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 6975 1.10 christos int ST1 = PPC_FIELD (insn_prefix, 8, 1); 6976 1.10 christos 6977 1.10 christos if ((type == 0) && (ST1 == 0)) 6978 1.10 christos { 6979 1.10 christos switch (PPC_FIELD (insn_suffix, 0, 5)) 6980 1.10 christos { 6981 1.10 christos case 25: /* Prefixed Load VSX Vector, plxv */ 6982 1.10 christos ppc_record_vsr (regcache, tdep, P_PPC_XT5 (insn_prefix)); 6983 1.10 christos return 0; 6984 1.10 christos case 27: /* Prefixed Store VSX Vector 8LS, pstxv */ 6985 1.10 christos { 6986 1.10 christos size = 16; 6987 1.10 christos if (R == 0) 6988 1.10 christos { 6989 1.10 christos if (PPC_RA (insn_suffix) != 0) 6990 1.10 christos regcache_raw_read_unsigned (regcache, 6991 1.10 christos tdep->ppc_gp0_regnum 6992 1.10 christos + PPC_RA (insn_suffix), 6993 1.10 christos &ea); 6994 1.10 christos } 6995 1.10 christos else 6996 1.10 christos { 6997 1.10 christos ea = addr; /* PC relative */ 6998 1.10 christos } 6999 1.10 christos 7000 1.10 christos ea += P_PPC_D (insn_prefix, insn_suffix); 7001 1.10 christos record_full_arch_list_add_mem (ea, size); 7002 1.10 christos return 0; 7003 1.10 christos } 7004 1.10 christos } 7005 1.10 christos return -1; 7006 1.10 christos } 7007 1.3 christos else 7008 1.3 christos return -1; 7009 1.3 christos } 7010 1.3 christos 7011 1.10 christos /* Parse the current instruction and record the values of the registers and 7012 1.10 christos memory that will be changed in current instruction to "record_arch_list". 7013 1.10 christos Return -1 if something wrong. */ 7014 1.10 christos 7015 1.10 christos /* This handles the recording of the various prefix instructions. It takes 7016 1.10 christos the instruction address, the first 32-bits of the instruction (insn_prefix) 7017 1.10 christos and the following 32-bits of the instruction (insn_suffix). Return 0 on 7018 1.10 christos success. */ 7019 1.10 christos 7020 1.10 christos static int 7021 1.10 christos ppc_process_prefix_instruction (int insn_prefix, int insn_suffix, 7022 1.10 christos CORE_ADDR addr, struct gdbarch *gdbarch, 7023 1.10 christos struct regcache *regcache) 7024 1.10 christos { 7025 1.10 christos int type = PPC_FIELD (insn_prefix, 6, 2); 7026 1.10 christos int ST1 = PPC_FIELD (insn_prefix, 8, 1); 7027 1.10 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 7028 1.10 christos int op6; 7029 1.10 christos 7030 1.10 christos /* D-form has uses a 5-bit opcode in the instruction suffix */ 7031 1.10 christos if (ppc_process_record_prefix_vsx_d_form ( gdbarch, regcache, addr, 7032 1.10 christos insn_prefix, insn_suffix) == 0) 7033 1.10 christos goto SUCCESS; 7034 1.10 christos 7035 1.10 christos op6 = PPC_OP6 (insn_suffix); /* 6-bit opcode in the instruction suffix */ 7036 1.10 christos 7037 1.10 christos switch (op6) 7038 1.10 christos { 7039 1.10 christos case 14: /* Prefixed Add Immediate, paddi */ 7040 1.10 christos if ((type == 2) && (ST1 == 0)) 7041 1.10 christos record_full_arch_list_add_reg (regcache, 7042 1.10 christos tdep->ppc_gp0_regnum 7043 1.10 christos + PPC_RT (insn_suffix)); 7044 1.10 christos else 7045 1.10 christos goto UNKNOWN_PREFIX_OP; 7046 1.10 christos break; 7047 1.10 christos 7048 1.10 christos case 32: 7049 1.10 christos if (ppc_process_record_prefix_op32 (gdbarch, regcache, 7050 1.10 christos insn_prefix, insn_suffix) != 0) 7051 1.10 christos goto UNKNOWN_PREFIX_OP; 7052 1.10 christos break; 7053 1.10 christos 7054 1.10 christos case 33: 7055 1.10 christos if (ppc_process_record_prefix_op33 (gdbarch, regcache, 7056 1.10 christos insn_prefix, insn_suffix) != 0) 7057 1.10 christos goto UNKNOWN_PREFIX_OP; 7058 1.10 christos break; 7059 1.10 christos 7060 1.10 christos case 34: /* Prefixed Load Byte and Zero, plbz */ 7061 1.10 christos if (ppc_process_record_prefix_op34 (gdbarch, regcache, 7062 1.10 christos insn_prefix, insn_suffix) != 0) 7063 1.10 christos goto UNKNOWN_PREFIX_OP; 7064 1.10 christos break; 7065 1.10 christos case 40: /* Prefixed Load Halfword and Zero, plhz */ 7066 1.10 christos if ((type == 2) && (ST1 == 0)) 7067 1.10 christos record_full_arch_list_add_reg (regcache, 7068 1.10 christos tdep->ppc_gp0_regnum 7069 1.10 christos + PPC_RT (insn_suffix)); 7070 1.10 christos else 7071 1.10 christos goto UNKNOWN_PREFIX_OP; 7072 1.10 christos break; 7073 1.10 christos 7074 1.10 christos break; 7075 1.10 christos 7076 1.10 christos case 36: /* Prefixed Store Word, pstw */ 7077 1.10 christos case 38: /* Prefixed Store Byte, pstb */ 7078 1.10 christos case 44: /* Prefixed Store Halfword, psth */ 7079 1.10 christos case 52: /* Prefixed Store Floating-Point Single, pstfs */ 7080 1.10 christos case 54: /* Prefixed Store Floating-Point Double, pstfd */ 7081 1.10 christos case 60: /* Prefixed Store Quadword, pstq */ 7082 1.10 christos case 61: /* Prefixed Store Doubleword, pstd */ 7083 1.10 christos if (ppc_process_record_prefix_store (gdbarch, regcache, addr, 7084 1.10 christos insn_prefix, insn_suffix) != 0) 7085 1.10 christos goto UNKNOWN_PREFIX_OP; 7086 1.10 christos break; 7087 1.10 christos 7088 1.10 christos case 42: 7089 1.10 christos if (ppc_process_record_prefix_op42 (gdbarch, regcache, 7090 1.10 christos insn_prefix, insn_suffix) != 0) 7091 1.10 christos goto UNKNOWN_PREFIX_OP; 7092 1.10 christos break; 7093 1.10 christos 7094 1.10 christos case 43: /* Prefixed Load VSX Scalar Single-Precision, plxssp */ 7095 1.10 christos if ((type == 0) && (ST1 == 0)) 7096 1.10 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn_suffix) + 32); 7097 1.10 christos else 7098 1.10 christos goto UNKNOWN_PREFIX_OP; 7099 1.10 christos break; 7100 1.10 christos 7101 1.10 christos case 46: 7102 1.10 christos case 47: 7103 1.10 christos if (ppc_process_record_prefix_store_vsx_ds_form (gdbarch, regcache, addr, 7104 1.10 christos insn_prefix, insn_suffix) != 0) 7105 1.10 christos goto UNKNOWN_PREFIX_OP; 7106 1.10 christos break; 7107 1.10 christos 7108 1.10 christos case 56: /* Prefixed Load Quadword, plq */ 7109 1.10 christos { 7110 1.10 christos if ((type == 0) && (ST1 == 0)) 7111 1.10 christos { 7112 1.10 christos int tmp; 7113 1.10 christos tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn_suffix) & ~1); 7114 1.10 christos record_full_arch_list_add_reg (regcache, tmp); 7115 1.10 christos record_full_arch_list_add_reg (regcache, tmp + 1); 7116 1.10 christos } 7117 1.10 christos else 7118 1.10 christos goto UNKNOWN_PREFIX_OP; 7119 1.10 christos break; 7120 1.10 christos } 7121 1.10 christos 7122 1.10 christos case 41: /* Prefixed Load Word Algebraic, plwa */ 7123 1.10 christos case 57: /* Prefixed Load Doubleword, pld */ 7124 1.10 christos if ((type == 0) && (ST1 == 0)) 7125 1.10 christos record_full_arch_list_add_reg (regcache, 7126 1.10 christos tdep->ppc_gp0_regnum 7127 1.10 christos + PPC_RT (insn_suffix)); 7128 1.10 christos else 7129 1.10 christos goto UNKNOWN_PREFIX_OP; 7130 1.10 christos break; 7131 1.10 christos 7132 1.10 christos case 48: /* Prefixed Load Floating-Point Single, plfs */ 7133 1.10 christos case 50: /* Prefixed Load Floating-Point Double, plfd */ 7134 1.10 christos if ((type == 2) && (ST1 == 0)) 7135 1.10 christos record_full_arch_list_add_reg (regcache, 7136 1.10 christos tdep->ppc_fp0_regnum 7137 1.10 christos + PPC_FRT (insn_suffix)); 7138 1.10 christos else 7139 1.10 christos goto UNKNOWN_PREFIX_OP; 7140 1.10 christos break; 7141 1.10 christos 7142 1.10 christos case 58: /* Prefixed Load VSX Vector Paired, plxvp */ 7143 1.10 christos if ((type == 0) && (ST1 == 0)) 7144 1.10 christos { 7145 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XTp (insn_suffix)); 7146 1.10 christos ppc_record_vsr (regcache, tdep, PPC_XTp (insn_suffix) + 1); 7147 1.10 christos } 7148 1.10 christos else 7149 1.10 christos goto UNKNOWN_PREFIX_OP; 7150 1.10 christos break; 7151 1.10 christos 7152 1.10 christos case 59: 7153 1.10 christos if (ppc_process_record_prefix_op59_XX3 (gdbarch, regcache, insn_prefix, 7154 1.10 christos insn_suffix) != 0) 7155 1.10 christos goto UNKNOWN_PREFIX_OP; 7156 1.10 christos break; 7157 1.10 christos 7158 1.10 christos case 62: /* Prefixed Store VSX Vector Paired 8LS, pstxvp */ 7159 1.10 christos if ((type == 0) && (ST1 == 0)) 7160 1.10 christos { 7161 1.10 christos int R = PPC_BIT (insn_prefix, 11); 7162 1.10 christos CORE_ADDR ea = 0; 7163 1.10 christos 7164 1.10 christos if (R == 0) 7165 1.10 christos { 7166 1.10 christos if (PPC_RA (insn_suffix) != 0) 7167 1.10 christos regcache_raw_read_unsigned (regcache, 7168 1.10 christos tdep->ppc_gp0_regnum 7169 1.10 christos + PPC_RA (insn_suffix), &ea); 7170 1.10 christos } 7171 1.10 christos else 7172 1.10 christos { 7173 1.10 christos ea = addr; /* PC relative */ 7174 1.10 christos } 7175 1.10 christos 7176 1.10 christos ea += P_PPC_D (insn_prefix, insn_suffix) << 4; 7177 1.10 christos record_full_arch_list_add_mem (ea, 32); 7178 1.10 christos } 7179 1.10 christos else 7180 1.10 christos goto UNKNOWN_PREFIX_OP; 7181 1.10 christos break; 7182 1.10 christos 7183 1.10 christos default: 7184 1.10 christos UNKNOWN_PREFIX_OP: 7185 1.10 christos gdb_printf (gdb_stdlog, 7186 1.10 christos "Warning: Don't know how to record prefix instruction " 7187 1.10 christos "%08x %08x at %s, %d.\n", 7188 1.10 christos insn_prefix, insn_suffix, paddress (gdbarch, addr), 7189 1.10 christos op6); 7190 1.10 christos return -1; 7191 1.10 christos } 7192 1.10 christos 7193 1.10 christos SUCCESS: 7194 1.10 christos if (record_full_arch_list_add_reg (regcache, PPC_PC_REGNUM)) 7195 1.10 christos return -1; 7196 1.10 christos 7197 1.10 christos if (record_full_arch_list_add_end ()) 7198 1.3 christos return -1; 7199 1.3 christos return 0; 7200 1.3 christos } 7201 1.3 christos 7202 1.10 christos int 7203 1.3 christos ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache, 7204 1.10 christos CORE_ADDR addr) 7205 1.3 christos { 7206 1.3 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 7207 1.3 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 7208 1.3 christos uint32_t insn, insn_suffix; 7209 1.3 christos int op6, tmp, i; 7210 1.3 christos 7211 1.3 christos insn = read_memory_unsigned_integer (addr, 4, byte_order); 7212 1.10 christos op6 = PPC_OP6 (insn); 7213 1.10 christos 7214 1.10 christos switch (op6) 7215 1.10 christos { 7216 1.10 christos case 1: /* prefixed instruction */ 7217 1.10 christos { 7218 1.10 christos /* Get the lower 32-bits of the prefixed instruction. */ 7219 1.3 christos insn_suffix = read_memory_unsigned_integer (addr+4, 4, byte_order); 7220 1.3 christos return ppc_process_prefix_instruction (insn, insn_suffix, addr, 7221 1.3 christos gdbarch, regcache); 7222 1.3 christos } 7223 1.3 christos case 2: /* Trap Doubleword Immediate */ 7224 1.10 christos case 3: /* Trap Word Immediate */ 7225 1.3 christos /* Do nothing. */ 7226 1.3 christos break; 7227 1.3 christos 7228 1.3 christos case 4: /* Vector Integer, Compare, Logical, Shift, etc. */ 7229 1.10 christos if (ppc_process_record_op4 (gdbarch, regcache, addr, insn) != 0) 7230 1.10 christos return -1; 7231 1.10 christos break; 7232 1.10 christos 7233 1.10 christos case 6: /* Vector Load and Store */ 7234 1.3 christos if (ppc_process_record_op6 (gdbarch, regcache, addr, insn) != 0) 7235 1.3 christos return -1; 7236 1.3 christos break; 7237 1.3 christos 7238 1.3 christos case 17: /* System call */ 7239 1.3 christos if (PPC_LEV (insn) != 0) 7240 1.3 christos goto UNKNOWN_OP; 7241 1.3 christos 7242 1.3 christos if (tdep->ppc_syscall_record != NULL) 7243 1.3 christos { 7244 1.3 christos if (tdep->ppc_syscall_record (regcache) != 0) 7245 1.10 christos return -1; 7246 1.3 christos } 7247 1.3 christos else 7248 1.3 christos { 7249 1.3 christos gdb_printf (gdb_stderr, _("no syscall record support\n")); 7250 1.3 christos return -1; 7251 1.3 christos } 7252 1.3 christos break; 7253 1.3 christos 7254 1.3 christos case 7: /* Multiply Low Immediate */ 7255 1.3 christos record_full_arch_list_add_reg (regcache, 7256 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 7257 1.3 christos break; 7258 1.3 christos 7259 1.3 christos case 8: /* Subtract From Immediate Carrying */ 7260 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 7261 1.3 christos record_full_arch_list_add_reg (regcache, 7262 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 7263 1.3 christos break; 7264 1.3 christos 7265 1.3 christos case 10: /* Compare Logical Immediate */ 7266 1.3 christos case 11: /* Compare Immediate */ 7267 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 7268 1.11 christos break; 7269 1.3 christos 7270 1.3 christos case 13: /* Add Immediate Carrying and Record */ 7271 1.11 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 7272 1.3 christos [[fallthrough]]; 7273 1.3 christos case 12: /* Add Immediate Carrying */ 7274 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum); 7275 1.3 christos [[fallthrough]]; 7276 1.3 christos case 14: /* Add Immediate */ 7277 1.3 christos case 15: /* Add Immediate Shifted */ 7278 1.3 christos record_full_arch_list_add_reg (regcache, 7279 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 7280 1.3 christos break; 7281 1.11 christos 7282 1.3 christos case 16: /* Branch Conditional */ 7283 1.3 christos if ((PPC_BO (insn) & 0x4) == 0) 7284 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum); 7285 1.3 christos [[fallthrough]]; 7286 1.3 christos case 18: /* Branch */ 7287 1.3 christos if (PPC_LK (insn)) 7288 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum); 7289 1.3 christos break; 7290 1.3 christos 7291 1.3 christos case 19: 7292 1.3 christos if (ppc_process_record_op19 (gdbarch, regcache, addr, insn) != 0) 7293 1.3 christos return -1; 7294 1.3 christos break; 7295 1.3 christos 7296 1.3 christos case 20: /* Rotate Left Word Immediate then Mask Insert */ 7297 1.3 christos case 21: /* Rotate Left Word Immediate then AND with Mask */ 7298 1.3 christos case 23: /* Rotate Left Word then AND with Mask */ 7299 1.3 christos case 30: /* Rotate Left Doubleword Immediate then Clear Left */ 7300 1.3 christos /* Rotate Left Doubleword Immediate then Clear Right */ 7301 1.3 christos /* Rotate Left Doubleword Immediate then Clear */ 7302 1.3 christos /* Rotate Left Doubleword then Clear Left */ 7303 1.3 christos /* Rotate Left Doubleword then Clear Right */ 7304 1.3 christos /* Rotate Left Doubleword Immediate then Mask Insert */ 7305 1.3 christos if (PPC_RC (insn)) 7306 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 7307 1.3 christos record_full_arch_list_add_reg (regcache, 7308 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 7309 1.3 christos break; 7310 1.11 christos 7311 1.3 christos case 28: /* AND Immediate */ 7312 1.3 christos case 29: /* AND Immediate Shifted */ 7313 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum); 7314 1.3 christos [[fallthrough]]; 7315 1.3 christos case 24: /* OR Immediate */ 7316 1.3 christos case 25: /* OR Immediate Shifted */ 7317 1.3 christos case 26: /* XOR Immediate */ 7318 1.3 christos case 27: /* XOR Immediate Shifted */ 7319 1.3 christos record_full_arch_list_add_reg (regcache, 7320 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 7321 1.3 christos break; 7322 1.3 christos 7323 1.3 christos case 31: 7324 1.3 christos if (ppc_process_record_op31 (gdbarch, regcache, addr, insn) != 0) 7325 1.3 christos return -1; 7326 1.3 christos break; 7327 1.3 christos 7328 1.3 christos case 33: /* Load Word and Zero with Update */ 7329 1.3 christos case 35: /* Load Byte and Zero with Update */ 7330 1.11 christos case 41: /* Load Halfword and Zero with Update */ 7331 1.3 christos case 43: /* Load Halfword Algebraic with Update */ 7332 1.3 christos record_full_arch_list_add_reg (regcache, 7333 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 7334 1.3 christos [[fallthrough]]; 7335 1.3 christos case 32: /* Load Word and Zero */ 7336 1.3 christos case 34: /* Load Byte and Zero */ 7337 1.3 christos case 40: /* Load Halfword and Zero */ 7338 1.3 christos case 42: /* Load Halfword Algebraic */ 7339 1.3 christos record_full_arch_list_add_reg (regcache, 7340 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 7341 1.3 christos break; 7342 1.3 christos 7343 1.3 christos case 46: /* Load Multiple Word */ 7344 1.3 christos for (i = PPC_RT (insn); i < 32; i++) 7345 1.3 christos record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i); 7346 1.3 christos break; 7347 1.3 christos 7348 1.3 christos case 56: /* Load Quadword */ 7349 1.3 christos tmp = tdep->ppc_gp0_regnum + (PPC_RT (insn) & ~1); 7350 1.3 christos record_full_arch_list_add_reg (regcache, tmp); 7351 1.3 christos record_full_arch_list_add_reg (regcache, tmp + 1); 7352 1.3 christos break; 7353 1.3 christos 7354 1.11 christos case 49: /* Load Floating-Point Single with Update */ 7355 1.3 christos case 51: /* Load Floating-Point Double with Update */ 7356 1.3 christos record_full_arch_list_add_reg (regcache, 7357 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 7358 1.3 christos [[fallthrough]]; 7359 1.3 christos case 48: /* Load Floating-Point Single */ 7360 1.3 christos case 50: /* Load Floating-Point Double */ 7361 1.3 christos record_full_arch_list_add_reg (regcache, 7362 1.3 christos tdep->ppc_fp0_regnum + PPC_FRT (insn)); 7363 1.8 christos break; 7364 1.3 christos 7365 1.3 christos case 47: /* Store Multiple Word */ 7366 1.3 christos { 7367 1.3 christos ULONGEST iaddr = 0; 7368 1.8 christos 7369 1.3 christos if (PPC_RA (insn) != 0) 7370 1.8 christos regcache_raw_read_unsigned (regcache, 7371 1.8 christos tdep->ppc_gp0_regnum + PPC_RA (insn), 7372 1.3 christos &iaddr); 7373 1.3 christos 7374 1.3 christos iaddr += PPC_D (insn); 7375 1.3 christos record_full_arch_list_add_mem (iaddr, 4 * (32 - PPC_RS (insn))); 7376 1.3 christos } 7377 1.3 christos break; 7378 1.3 christos 7379 1.3 christos case 37: /* Store Word with Update */ 7380 1.3 christos case 39: /* Store Byte with Update */ 7381 1.3 christos case 45: /* Store Halfword with Update */ 7382 1.11 christos case 53: /* Store Floating-Point Single with Update */ 7383 1.3 christos case 55: /* Store Floating-Point Double with Update */ 7384 1.3 christos record_full_arch_list_add_reg (regcache, 7385 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 7386 1.3 christos [[fallthrough]]; 7387 1.3 christos case 36: /* Store Word */ 7388 1.3 christos case 38: /* Store Byte */ 7389 1.8 christos case 44: /* Store Halfword */ 7390 1.3 christos case 52: /* Store Floating-Point Single */ 7391 1.3 christos case 54: /* Store Floating-Point Double */ 7392 1.3 christos { 7393 1.3 christos ULONGEST iaddr = 0; 7394 1.3 christos int size = -1; 7395 1.8 christos 7396 1.8 christos if (PPC_RA (insn) != 0) 7397 1.3 christos regcache_raw_read_unsigned (regcache, 7398 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn), 7399 1.3 christos &iaddr); 7400 1.3 christos iaddr += PPC_D (insn); 7401 1.3 christos 7402 1.3 christos if (op6 == 36 || op6 == 37 || op6 == 52 || op6 == 53) 7403 1.3 christos size = 4; 7404 1.3 christos else if (op6 == 54 || op6 == 55) 7405 1.3 christos size = 8; 7406 1.3 christos else if (op6 == 44 || op6 == 45) 7407 1.3 christos size = 2; 7408 1.3 christos else if (op6 == 38 || op6 == 39) 7409 1.8 christos size = 1; 7410 1.3 christos else 7411 1.3 christos gdb_assert (0); 7412 1.3 christos 7413 1.7 christos record_full_arch_list_add_mem (iaddr, size); 7414 1.7 christos } 7415 1.10 christos break; 7416 1.7 christos 7417 1.7 christos case 57: 7418 1.7 christos switch (insn & 0x3) 7419 1.7 christos { 7420 1.7 christos case 0: /* Load Floating-Point Double Pair */ 7421 1.7 christos tmp = tdep->ppc_fp0_regnum + (PPC_RT (insn) & ~1); 7422 1.7 christos record_full_arch_list_add_reg (regcache, tmp); 7423 1.7 christos record_full_arch_list_add_reg (regcache, tmp + 1); 7424 1.7 christos break; 7425 1.7 christos case 2: /* Load VSX Scalar Doubleword */ 7426 1.7 christos case 3: /* Load VSX Scalar Single */ 7427 1.7 christos ppc_record_vsr (regcache, tdep, PPC_VRT (insn) + 32); 7428 1.3 christos break; 7429 1.3 christos default: 7430 1.3 christos goto UNKNOWN_OP; 7431 1.3 christos } 7432 1.3 christos break; 7433 1.3 christos 7434 1.3 christos case 58: /* Load Doubleword */ 7435 1.3 christos /* Load Doubleword with Update */ 7436 1.3 christos /* Load Word Algebraic */ 7437 1.3 christos if (PPC_FIELD (insn, 30, 2) > 2) 7438 1.3 christos goto UNKNOWN_OP; 7439 1.3 christos 7440 1.3 christos record_full_arch_list_add_reg (regcache, 7441 1.3 christos tdep->ppc_gp0_regnum + PPC_RT (insn)); 7442 1.3 christos if (PPC_BIT (insn, 31)) 7443 1.3 christos record_full_arch_list_add_reg (regcache, 7444 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn)); 7445 1.3 christos break; 7446 1.3 christos 7447 1.3 christos case 59: 7448 1.3 christos if (ppc_process_record_op59 (gdbarch, regcache, addr, insn) != 0) 7449 1.3 christos return -1; 7450 1.3 christos break; 7451 1.3 christos 7452 1.3 christos case 60: 7453 1.7 christos if (ppc_process_record_op60 (gdbarch, regcache, addr, insn) != 0) 7454 1.7 christos return -1; 7455 1.7 christos break; 7456 1.7 christos 7457 1.7 christos case 61: 7458 1.3 christos if (ppc_process_record_op61 (gdbarch, regcache, addr, insn) != 0) 7459 1.3 christos return -1; 7460 1.3 christos break; 7461 1.3 christos 7462 1.8 christos case 62: /* Store Doubleword */ 7463 1.3 christos /* Store Doubleword with Update */ 7464 1.3 christos /* Store Quadword with Update */ 7465 1.3 christos { 7466 1.7 christos ULONGEST iaddr = 0; 7467 1.3 christos int size; 7468 1.3 christos int sub2 = PPC_FIELD (insn, 30, 2); 7469 1.3 christos 7470 1.3 christos if (sub2 > 2) 7471 1.3 christos goto UNKNOWN_OP; 7472 1.8 christos 7473 1.3 christos if (PPC_RA (insn) != 0) 7474 1.7 christos regcache_raw_read_unsigned (regcache, 7475 1.3 christos tdep->ppc_gp0_regnum + PPC_RA (insn), 7476 1.8 christos &iaddr); 7477 1.8 christos 7478 1.3 christos size = (sub2 == 2) ? 16 : 8; 7479 1.3 christos 7480 1.3 christos iaddr += PPC_DS (insn) << 2; 7481 1.3 christos record_full_arch_list_add_mem (iaddr, size); 7482 1.3 christos 7483 1.3 christos if (op6 == 62 && sub2 == 1) 7484 1.3 christos record_full_arch_list_add_reg (regcache, 7485 1.3 christos tdep->ppc_gp0_regnum + 7486 1.3 christos PPC_RA (insn)); 7487 1.3 christos 7488 1.3 christos break; 7489 1.3 christos } 7490 1.3 christos 7491 1.3 christos case 63: 7492 1.3 christos if (ppc_process_record_op63 (gdbarch, regcache, addr, insn) != 0) 7493 1.3 christos return -1; 7494 1.10 christos break; 7495 1.10 christos 7496 1.3 christos default: 7497 1.3 christos UNKNOWN_OP: 7498 1.3 christos gdb_printf (gdb_stdlog, "Warning: Don't know how to record %08x " 7499 1.3 christos "at %s, %d.\n", insn, paddress (gdbarch, addr), op6); 7500 1.3 christos return -1; 7501 1.3 christos } 7502 1.3 christos 7503 1.3 christos if (record_full_arch_list_add_reg (regcache, PPC_PC_REGNUM)) 7504 1.3 christos return -1; 7505 1.3 christos if (record_full_arch_list_add_end ()) 7506 1.10 christos return -1; 7507 1.10 christos return 0; 7508 1.10 christos } 7509 1.10 christos 7510 1.10 christos /* Used for matching tw, twi, td and tdi instructions for POWER. */ 7511 1.10 christos 7512 1.10 christos static constexpr uint32_t TX_INSN_MASK = 0xFC0007FF; 7513 1.10 christos static constexpr uint32_t TW_INSN = 0x7C000008; 7514 1.10 christos static constexpr uint32_t TD_INSN = 0x7C000088; 7515 1.10 christos 7516 1.10 christos static constexpr uint32_t TXI_INSN_MASK = 0xFC000000; 7517 1.10 christos static constexpr uint32_t TWI_INSN = 0x0C000000; 7518 1.10 christos static constexpr uint32_t TDI_INSN = 0x08000000; 7519 1.10 christos 7520 1.10 christos static inline bool 7521 1.10 christos is_tw_insn (uint32_t insn) 7522 1.10 christos { 7523 1.10 christos return (insn & TX_INSN_MASK) == TW_INSN; 7524 1.10 christos } 7525 1.10 christos 7526 1.10 christos static inline bool 7527 1.10 christos is_twi_insn (uint32_t insn) 7528 1.10 christos { 7529 1.10 christos return (insn & TXI_INSN_MASK) == TWI_INSN; 7530 1.10 christos } 7531 1.10 christos 7532 1.10 christos static inline bool 7533 1.10 christos is_td_insn (uint32_t insn) 7534 1.10 christos { 7535 1.10 christos return (insn & TX_INSN_MASK) == TD_INSN; 7536 1.10 christos } 7537 1.10 christos 7538 1.10 christos static inline bool 7539 1.10 christos is_tdi_insn (uint32_t insn) 7540 1.10 christos { 7541 1.10 christos return (insn & TXI_INSN_MASK) == TDI_INSN; 7542 1.10 christos } 7543 1.10 christos 7544 1.10 christos /* Implementation of gdbarch_program_breakpoint_here_p for POWER. */ 7545 1.10 christos 7546 1.10 christos static bool 7547 1.10 christos rs6000_program_breakpoint_here_p (gdbarch *gdbarch, CORE_ADDR address) 7548 1.10 christos { 7549 1.10 christos gdb_byte target_mem[PPC_INSN_SIZE]; 7550 1.10 christos 7551 1.10 christos /* Enable the automatic memory restoration from breakpoints while 7552 1.10 christos we read the memory. Otherwise we may find temporary breakpoints, ones 7553 1.10 christos inserted by GDB, and flag them as permanent breakpoints. */ 7554 1.10 christos scoped_restore restore_memory 7555 1.10 christos = make_scoped_restore_show_memory_breakpoints (0); 7556 1.11 christos 7557 1.10 christos if (target_read_memory (address, target_mem, PPC_INSN_SIZE) == 0) 7558 1.10 christos { 7559 1.11 christos uint32_t insn = (uint32_t) extract_unsigned_integer 7560 1.11 christos (target_mem, PPC_INSN_SIZE, gdbarch_byte_order_for_code (gdbarch)); 7561 1.10 christos 7562 1.11 christos /* Check if INSN is a TW, TWI, TD or TDI instruction. There 7563 1.11 christos are multiple choices of such instructions with different registers 7564 1.10 christos and / or immediate values but they all cause a break. */ 7565 1.10 christos if (is_tw_insn (insn) || is_twi_insn (insn) || is_td_insn (insn) 7566 1.10 christos || is_tdi_insn (insn)) 7567 1.10 christos return true; 7568 1.10 christos } 7569 1.11 christos 7570 1.11 christos return false; 7571 1.11 christos } 7572 1.11 christos 7573 1.11 christos /* Implement the update_call_site_pc arch hook. */ 7574 1.11 christos 7575 1.11 christos static CORE_ADDR 7576 1.11 christos ppc64_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc) 7577 1.11 christos { 7578 1.11 christos /* Some versions of GCC emit: 7579 1.11 christos 7580 1.11 christos . bl function 7581 1.11 christos . nop 7582 1.11 christos . ... 7583 1.11 christos 7584 1.11 christos but emit DWARF where the DW_AT_call_return_pc points to 7585 1.11 christos instruction after the 'nop'. Note that while the compiler emits 7586 1.11 christos a 'nop', the linker might put some other instruction there -- so 7587 1.1 christos we just unconditionally check the next instruction. */ 7588 1.1 christos return pc + 4; 7589 1.1 christos } 7590 1.1 christos 7591 1.1 christos /* Initialize the current architecture based on INFO. If possible, re-use an 7592 1.1 christos architecture from ARCHES, which is a list of architectures already created 7593 1.1 christos during this debugging session. 7594 1.1 christos 7595 1.1 christos Called e.g. at program startup, when reading a core file, and when reading 7596 1.1 christos a binary file. */ 7597 1.1 christos 7598 1.1 christos static struct gdbarch * 7599 1.1 christos rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 7600 1.1 christos { 7601 1.1 christos int wordsize, from_xcoff_exec, from_elf_exec; 7602 1.1 christos enum bfd_architecture arch; 7603 1.8 christos unsigned long mach; 7604 1.1 christos bfd abfd; 7605 1.3 christos enum auto_boolean soft_float_flag = powerpc_soft_float_global; 7606 1.8 christos int soft_float; 7607 1.8 christos enum powerpc_long_double_abi long_double_abi = POWERPC_LONG_DOUBLE_AUTO; 7608 1.8 christos enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global; 7609 1.8 christos enum powerpc_elf_abi elf_abi = POWERPC_ELF_AUTO; 7610 1.8 christos int have_fpu = 0, have_spe = 0, have_mq = 0, have_altivec = 0; 7611 1.8 christos int have_dfp = 0, have_vsx = 0, have_ppr = 0, have_dscr = 0; 7612 1.1 christos int have_tar = 0, have_ebb = 0, have_pmu = 0, have_htm_spr = 0; 7613 1.1 christos int have_htm_core = 0, have_htm_fpu = 0, have_htm_altivec = 0; 7614 1.10 christos int have_htm_vsx = 0, have_htm_ppr = 0, have_htm_dscr = 0; 7615 1.1 christos int have_htm_tar = 0; 7616 1.1 christos int tdesc_wordsize = -1; 7617 1.1 christos const struct target_desc *tdesc = info.target_desc; 7618 1.1 christos tdesc_arch_data_up tdesc_data; 7619 1.1 christos int num_pseudoregs = 0; 7620 1.1 christos int cur_reg; 7621 1.1 christos 7622 1.1 christos from_xcoff_exec = info.abfd && info.abfd->format == bfd_object && 7623 1.1 christos bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour; 7624 1.1 christos 7625 1.1 christos from_elf_exec = info.abfd && info.abfd->format == bfd_object && 7626 1.1 christos bfd_get_flavour (info.abfd) == bfd_target_elf_flavour; 7627 1.1 christos 7628 1.1 christos /* Check word size. If INFO is from a binary file, infer it from 7629 1.1 christos that, else choose a likely default. */ 7630 1.1 christos if (from_xcoff_exec) 7631 1.1 christos { 7632 1.1 christos if (bfd_xcoff_is_xcoff64 (info.abfd)) 7633 1.1 christos wordsize = 8; 7634 1.1 christos else 7635 1.1 christos wordsize = 4; 7636 1.1 christos } 7637 1.1 christos else if (from_elf_exec) 7638 1.1 christos { 7639 1.1 christos if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) 7640 1.1 christos wordsize = 8; 7641 1.1 christos else 7642 1.1 christos wordsize = 4; 7643 1.1 christos } 7644 1.1 christos else if (tdesc_has_registers (tdesc)) 7645 1.5 christos wordsize = -1; 7646 1.5 christos else 7647 1.1 christos { 7648 1.1 christos if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0) 7649 1.1 christos wordsize = (info.bfd_arch_info->bits_per_word 7650 1.1 christos / info.bfd_arch_info->bits_per_byte); 7651 1.1 christos else 7652 1.1 christos wordsize = 4; 7653 1.1 christos } 7654 1.1 christos 7655 1.1 christos /* Get the architecture and machine from the BFD. */ 7656 1.1 christos arch = info.bfd_arch_info->arch; 7657 1.1 christos mach = info.bfd_arch_info->mach; 7658 1.1 christos 7659 1.1 christos /* For e500 executables, the apuinfo section is of help here. Such 7660 1.1 christos section contains the identifier and revision number of each 7661 1.1 christos Application-specific Processing Unit that is present on the 7662 1.1 christos chip. The content of the section is determined by the assembler 7663 1.1 christos which looks at each instruction and determines which unit (and 7664 1.1 christos which version of it) can execute it. Grovel through the section 7665 1.1 christos looking for relevant e500 APUs. */ 7666 1.1 christos 7667 1.1 christos if (bfd_uses_spe_extensions (info.abfd)) 7668 1.1 christos { 7669 1.1 christos arch = info.bfd_arch_info->arch; 7670 1.1 christos mach = bfd_mach_ppc_e500; 7671 1.1 christos bfd_default_set_arch_mach (&abfd, arch, mach); 7672 1.1 christos info.bfd_arch_info = bfd_get_arch_info (&abfd); 7673 1.1 christos } 7674 1.1 christos 7675 1.9 christos /* Find a default target description which describes our register 7676 1.1 christos layout, if we do not already have one. */ 7677 1.1 christos if (! tdesc_has_registers (tdesc)) 7678 1.1 christos { 7679 1.1 christos const struct ppc_variant *v; 7680 1.1 christos 7681 1.1 christos /* Choose variant. */ 7682 1.1 christos v = find_variant_by_arch (arch, mach); 7683 1.1 christos if (!v) 7684 1.1 christos return NULL; 7685 1.1 christos 7686 1.1 christos tdesc = *v->tdesc; 7687 1.1 christos } 7688 1.1 christos 7689 1.1 christos gdb_assert (tdesc_has_registers (tdesc)); 7690 1.1 christos 7691 1.1 christos /* Check any target description for validity. */ 7692 1.1 christos if (tdesc_has_registers (tdesc)) 7693 1.1 christos { 7694 1.1 christos static const char *const gprs[] = { 7695 1.1 christos "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 7696 1.1 christos "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 7697 1.1 christos "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 7698 1.1 christos "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 7699 1.1 christos }; 7700 1.1 christos const struct tdesc_feature *feature; 7701 1.1 christos int i, valid_p; 7702 1.1 christos static const char *const msr_names[] = { "msr", "ps" }; 7703 1.1 christos static const char *const cr_names[] = { "cr", "cnd" }; 7704 1.1 christos static const char *const ctr_names[] = { "ctr", "cnt" }; 7705 1.1 christos 7706 1.1 christos feature = tdesc_find_feature (tdesc, 7707 1.1 christos "org.gnu.gdb.power.core"); 7708 1.1 christos if (feature == NULL) 7709 1.1 christos return NULL; 7710 1.1 christos 7711 1.10 christos tdesc_data = tdesc_data_alloc (); 7712 1.10 christos 7713 1.10 christos valid_p = 1; 7714 1.10 christos for (i = 0; i < ppc_num_gprs; i++) 7715 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7716 1.10 christos i, gprs[i]); 7717 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7718 1.10 christos PPC_PC_REGNUM, "pc"); 7719 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7720 1.11 christos PPC_LR_REGNUM, "lr"); 7721 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7722 1.10 christos PPC_XER_REGNUM, "xer"); 7723 1.1 christos 7724 1.10 christos /* Allow alternate names for these registers, to accommodate GDB's 7725 1.1 christos historic naming. */ 7726 1.10 christos valid_p &= tdesc_numbered_register_choices (feature, tdesc_data.get (), 7727 1.1 christos PPC_MSR_REGNUM, msr_names); 7728 1.1 christos valid_p &= tdesc_numbered_register_choices (feature, tdesc_data.get (), 7729 1.1 christos PPC_CR_REGNUM, cr_names); 7730 1.10 christos valid_p &= tdesc_numbered_register_choices (feature, tdesc_data.get (), 7731 1.1 christos PPC_CTR_REGNUM, ctr_names); 7732 1.10 christos 7733 1.10 christos if (!valid_p) 7734 1.1 christos return NULL; 7735 1.8 christos 7736 1.1 christos have_mq = tdesc_numbered_register (feature, tdesc_data.get (), 7737 1.1 christos PPC_MQ_REGNUM, "mq"); 7738 1.1 christos 7739 1.1 christos tdesc_wordsize = tdesc_register_bitsize (feature, "pc") / 8; 7740 1.1 christos if (wordsize == -1) 7741 1.1 christos wordsize = tdesc_wordsize; 7742 1.1 christos 7743 1.1 christos feature = tdesc_find_feature (tdesc, 7744 1.1 christos "org.gnu.gdb.power.fpu"); 7745 1.1 christos if (feature != NULL) 7746 1.1 christos { 7747 1.1 christos static const char *const fprs[] = { 7748 1.1 christos "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 7749 1.1 christos "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 7750 1.1 christos "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 7751 1.10 christos "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31" 7752 1.1 christos }; 7753 1.10 christos valid_p = 1; 7754 1.1 christos for (i = 0; i < ppc_num_fprs; i++) 7755 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7756 1.1 christos PPC_F0_REGNUM + i, fprs[i]); 7757 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7758 1.1 christos PPC_FPSCR_REGNUM, "fpscr"); 7759 1.8 christos 7760 1.8 christos if (!valid_p) 7761 1.8 christos return NULL; 7762 1.8 christos have_fpu = 1; 7763 1.8 christos 7764 1.8 christos /* The fpscr register was expanded in isa 2.05 to 64 bits 7765 1.1 christos along with the addition of the decimal floating point 7766 1.1 christos facility. */ 7767 1.1 christos if (tdesc_register_bitsize (feature, "fpscr") > 32) 7768 1.1 christos have_dfp = 1; 7769 1.1 christos } 7770 1.1 christos else 7771 1.1 christos have_fpu = 0; 7772 1.1 christos 7773 1.1 christos feature = tdesc_find_feature (tdesc, 7774 1.1 christos "org.gnu.gdb.power.altivec"); 7775 1.1 christos if (feature != NULL) 7776 1.1 christos { 7777 1.1 christos static const char *const vector_regs[] = { 7778 1.1 christos "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7", 7779 1.1 christos "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15", 7780 1.1 christos "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23", 7781 1.1 christos "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31" 7782 1.10 christos }; 7783 1.1 christos 7784 1.1 christos valid_p = 1; 7785 1.10 christos for (i = 0; i < ppc_num_gprs; i++) 7786 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7787 1.10 christos PPC_VR0_REGNUM + i, 7788 1.1 christos vector_regs[i]); 7789 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7790 1.1 christos PPC_VSCR_REGNUM, "vscr"); 7791 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7792 1.1 christos PPC_VRSAVE_REGNUM, "vrsave"); 7793 1.1 christos 7794 1.1 christos if (have_spe || !valid_p) 7795 1.1 christos return NULL; 7796 1.1 christos have_altivec = 1; 7797 1.1 christos } 7798 1.1 christos else 7799 1.1 christos have_altivec = 0; 7800 1.1 christos 7801 1.1 christos /* Check for POWER7 VSX registers support. */ 7802 1.1 christos feature = tdesc_find_feature (tdesc, 7803 1.1 christos "org.gnu.gdb.power.vsx"); 7804 1.1 christos 7805 1.1 christos if (feature != NULL) 7806 1.1 christos { 7807 1.1 christos static const char *const vsx_regs[] = { 7808 1.1 christos "vs0h", "vs1h", "vs2h", "vs3h", "vs4h", "vs5h", 7809 1.1 christos "vs6h", "vs7h", "vs8h", "vs9h", "vs10h", "vs11h", 7810 1.1 christos "vs12h", "vs13h", "vs14h", "vs15h", "vs16h", "vs17h", 7811 1.1 christos "vs18h", "vs19h", "vs20h", "vs21h", "vs22h", "vs23h", 7812 1.1 christos "vs24h", "vs25h", "vs26h", "vs27h", "vs28h", "vs29h", 7813 1.1 christos "vs30h", "vs31h" 7814 1.1 christos }; 7815 1.10 christos 7816 1.1 christos valid_p = 1; 7817 1.1 christos 7818 1.8 christos for (i = 0; i < ppc_num_vshrs; i++) 7819 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7820 1.10 christos PPC_VSR0_UPPER_REGNUM + i, 7821 1.1 christos vsx_regs[i]); 7822 1.1 christos 7823 1.1 christos if (!valid_p || !have_fpu || !have_altivec) 7824 1.1 christos return NULL; 7825 1.1 christos 7826 1.1 christos have_vsx = 1; 7827 1.1 christos } 7828 1.1 christos else 7829 1.1 christos have_vsx = 0; 7830 1.1 christos 7831 1.1 christos /* On machines supporting the SPE APU, the general-purpose registers 7832 1.1 christos are 64 bits long. There are SIMD vector instructions to treat them 7833 1.1 christos as pairs of floats, but the rest of the instruction set treats them 7834 1.1 christos as 32-bit registers, and only operates on their lower halves. 7835 1.1 christos 7836 1.1 christos In the GDB regcache, we treat their high and low halves as separate 7837 1.1 christos registers. The low halves we present as the general-purpose 7838 1.1 christos registers, and then we have pseudo-registers that stitch together 7839 1.1 christos the upper and lower halves and present them as pseudo-registers. 7840 1.1 christos 7841 1.1 christos Thus, the target description is expected to supply the upper 7842 1.1 christos halves separately. */ 7843 1.1 christos 7844 1.1 christos feature = tdesc_find_feature (tdesc, 7845 1.1 christos "org.gnu.gdb.power.spe"); 7846 1.1 christos if (feature != NULL) 7847 1.1 christos { 7848 1.1 christos static const char *const upper_spe[] = { 7849 1.1 christos "ev0h", "ev1h", "ev2h", "ev3h", 7850 1.1 christos "ev4h", "ev5h", "ev6h", "ev7h", 7851 1.1 christos "ev8h", "ev9h", "ev10h", "ev11h", 7852 1.1 christos "ev12h", "ev13h", "ev14h", "ev15h", 7853 1.1 christos "ev16h", "ev17h", "ev18h", "ev19h", 7854 1.1 christos "ev20h", "ev21h", "ev22h", "ev23h", 7855 1.1 christos "ev24h", "ev25h", "ev26h", "ev27h", 7856 1.1 christos "ev28h", "ev29h", "ev30h", "ev31h" 7857 1.10 christos }; 7858 1.1 christos 7859 1.1 christos valid_p = 1; 7860 1.10 christos for (i = 0; i < ppc_num_gprs; i++) 7861 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7862 1.10 christos PPC_SPE_UPPER_GP0_REGNUM + i, 7863 1.1 christos upper_spe[i]); 7864 1.1 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7865 1.1 christos PPC_SPE_ACC_REGNUM, "acc"); 7866 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7867 1.1 christos PPC_SPE_FSCR_REGNUM, "spefscr"); 7868 1.1 christos 7869 1.1 christos if (have_mq || have_fpu || !valid_p) 7870 1.1 christos return NULL; 7871 1.8 christos have_spe = 1; 7872 1.8 christos } 7873 1.8 christos else 7874 1.8 christos have_spe = 0; 7875 1.8 christos 7876 1.8 christos /* Program Priority Register. */ 7877 1.8 christos feature = tdesc_find_feature (tdesc, 7878 1.10 christos "org.gnu.gdb.power.ppr"); 7879 1.8 christos if (feature != NULL) 7880 1.8 christos { 7881 1.8 christos valid_p = 1; 7882 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7883 1.8 christos PPC_PPR_REGNUM, "ppr"); 7884 1.8 christos 7885 1.8 christos if (!valid_p) 7886 1.8 christos return NULL; 7887 1.8 christos have_ppr = 1; 7888 1.8 christos } 7889 1.8 christos else 7890 1.8 christos have_ppr = 0; 7891 1.8 christos 7892 1.8 christos /* Data Stream Control Register. */ 7893 1.8 christos feature = tdesc_find_feature (tdesc, 7894 1.10 christos "org.gnu.gdb.power.dscr"); 7895 1.8 christos if (feature != NULL) 7896 1.8 christos { 7897 1.8 christos valid_p = 1; 7898 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7899 1.8 christos PPC_DSCR_REGNUM, "dscr"); 7900 1.8 christos 7901 1.8 christos if (!valid_p) 7902 1.8 christos return NULL; 7903 1.8 christos have_dscr = 1; 7904 1.8 christos } 7905 1.8 christos else 7906 1.8 christos have_dscr = 0; 7907 1.8 christos 7908 1.8 christos /* Target Address Register. */ 7909 1.8 christos feature = tdesc_find_feature (tdesc, 7910 1.10 christos "org.gnu.gdb.power.tar"); 7911 1.8 christos if (feature != NULL) 7912 1.8 christos { 7913 1.8 christos valid_p = 1; 7914 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7915 1.8 christos PPC_TAR_REGNUM, "tar"); 7916 1.8 christos 7917 1.8 christos if (!valid_p) 7918 1.8 christos return NULL; 7919 1.8 christos have_tar = 1; 7920 1.8 christos } 7921 1.8 christos else 7922 1.8 christos have_tar = 0; 7923 1.8 christos 7924 1.8 christos /* Event-based Branching Registers. */ 7925 1.8 christos feature = tdesc_find_feature (tdesc, 7926 1.8 christos "org.gnu.gdb.power.ebb"); 7927 1.8 christos if (feature != NULL) 7928 1.8 christos { 7929 1.8 christos static const char *const ebb_regs[] = { 7930 1.8 christos "bescr", "ebbhr", "ebbrr" 7931 1.10 christos }; 7932 1.8 christos 7933 1.8 christos valid_p = 1; 7934 1.8 christos for (i = 0; i < ARRAY_SIZE (ebb_regs); i++) 7935 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7936 1.8 christos PPC_BESCR_REGNUM + i, 7937 1.8 christos ebb_regs[i]); 7938 1.8 christos if (!valid_p) 7939 1.8 christos return NULL; 7940 1.8 christos have_ebb = 1; 7941 1.8 christos } 7942 1.8 christos else 7943 1.8 christos have_ebb = 0; 7944 1.8 christos 7945 1.8 christos /* Subset of the ISA 2.07 Performance Monitor Registers provided 7946 1.8 christos by Linux. */ 7947 1.8 christos feature = tdesc_find_feature (tdesc, 7948 1.8 christos "org.gnu.gdb.power.linux.pmu"); 7949 1.10 christos if (feature != NULL) 7950 1.8 christos { 7951 1.8 christos valid_p = 1; 7952 1.10 christos 7953 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7954 1.8 christos PPC_MMCR0_REGNUM, 7955 1.10 christos "mmcr0"); 7956 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7957 1.8 christos PPC_MMCR2_REGNUM, 7958 1.10 christos "mmcr2"); 7959 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7960 1.8 christos PPC_SIAR_REGNUM, 7961 1.10 christos "siar"); 7962 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7963 1.8 christos PPC_SDAR_REGNUM, 7964 1.8 christos "sdar"); 7965 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7966 1.10 christos PPC_SIER_REGNUM, 7967 1.8 christos "sier"); 7968 1.8 christos 7969 1.8 christos if (!valid_p) 7970 1.8 christos return NULL; 7971 1.8 christos have_pmu = 1; 7972 1.8 christos } 7973 1.8 christos else 7974 1.8 christos have_pmu = 0; 7975 1.8 christos 7976 1.8 christos /* Hardware Transactional Memory Registers. */ 7977 1.8 christos feature = tdesc_find_feature (tdesc, 7978 1.8 christos "org.gnu.gdb.power.htm.spr"); 7979 1.8 christos if (feature != NULL) 7980 1.8 christos { 7981 1.8 christos static const char *const tm_spr_regs[] = { 7982 1.8 christos "tfhar", "texasr", "tfiar" 7983 1.10 christos }; 7984 1.8 christos 7985 1.8 christos valid_p = 1; 7986 1.8 christos for (i = 0; i < ARRAY_SIZE (tm_spr_regs); i++) 7987 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 7988 1.8 christos PPC_TFHAR_REGNUM + i, 7989 1.8 christos tm_spr_regs[i]); 7990 1.8 christos if (!valid_p) 7991 1.8 christos return NULL; 7992 1.8 christos 7993 1.8 christos have_htm_spr = 1; 7994 1.8 christos } 7995 1.8 christos else 7996 1.8 christos have_htm_spr = 0; 7997 1.8 christos 7998 1.8 christos feature = tdesc_find_feature (tdesc, 7999 1.8 christos "org.gnu.gdb.power.htm.core"); 8000 1.8 christos if (feature != NULL) 8001 1.8 christos { 8002 1.8 christos static const char *const cgprs[] = { 8003 1.8 christos "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", 8004 1.8 christos "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", 8005 1.8 christos "cr15", "cr16", "cr17", "cr18", "cr19", "cr20", "cr21", 8006 1.8 christos "cr22", "cr23", "cr24", "cr25", "cr26", "cr27", "cr28", 8007 1.8 christos "cr29", "cr30", "cr31", "ccr", "cxer", "clr", "cctr" 8008 1.8 christos }; 8009 1.10 christos 8010 1.8 christos valid_p = 1; 8011 1.8 christos 8012 1.8 christos for (i = 0; i < ARRAY_SIZE (cgprs); i++) 8013 1.10 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 8014 1.8 christos PPC_CR0_REGNUM + i, 8015 1.8 christos cgprs[i]); 8016 1.8 christos if (!valid_p) 8017 1.8 christos return NULL; 8018 1.8 christos 8019 1.8 christos have_htm_core = 1; 8020 1.8 christos } 8021 1.8 christos else 8022 1.8 christos have_htm_core = 0; 8023 1.8 christos 8024 1.8 christos feature = tdesc_find_feature (tdesc, 8025 1.8 christos "org.gnu.gdb.power.htm.fpu"); 8026 1.8 christos if (feature != NULL) 8027 1.8 christos { 8028 1.8 christos valid_p = 1; 8029 1.8 christos 8030 1.8 christos static const char *const cfprs[] = { 8031 1.8 christos "cf0", "cf1", "cf2", "cf3", "cf4", "cf5", "cf6", "cf7", 8032 1.8 christos "cf8", "cf9", "cf10", "cf11", "cf12", "cf13", "cf14", "cf15", 8033 1.8 christos "cf16", "cf17", "cf18", "cf19", "cf20", "cf21", "cf22", 8034 1.8 christos "cf23", "cf24", "cf25", "cf26", "cf27", "cf28", "cf29", 8035 1.10 christos "cf30", "cf31", "cfpscr" 8036 1.8 christos }; 8037 1.8 christos 8038 1.8 christos for (i = 0; i < ARRAY_SIZE (cfprs); i++) 8039 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 8040 1.10 christos PPC_CF0_REGNUM + i, 8041 1.8 christos cfprs[i]); 8042 1.8 christos 8043 1.8 christos if (!valid_p) 8044 1.8 christos return NULL; 8045 1.8 christos have_htm_fpu = 1; 8046 1.8 christos } 8047 1.8 christos else 8048 1.8 christos have_htm_fpu = 0; 8049 1.8 christos 8050 1.8 christos feature = tdesc_find_feature (tdesc, 8051 1.8 christos "org.gnu.gdb.power.htm.altivec"); 8052 1.8 christos if (feature != NULL) 8053 1.8 christos { 8054 1.8 christos valid_p = 1; 8055 1.8 christos 8056 1.8 christos static const char *const cvmx[] = { 8057 1.8 christos "cvr0", "cvr1", "cvr2", "cvr3", "cvr4", "cvr5", "cvr6", 8058 1.8 christos "cvr7", "cvr8", "cvr9", "cvr10", "cvr11", "cvr12", "cvr13", 8059 1.8 christos "cvr14", "cvr15","cvr16", "cvr17", "cvr18", "cvr19", "cvr20", 8060 1.8 christos "cvr21", "cvr22", "cvr23", "cvr24", "cvr25", "cvr26", 8061 1.8 christos "cvr27", "cvr28", "cvr29", "cvr30", "cvr31", "cvscr", 8062 1.10 christos "cvrsave" 8063 1.8 christos }; 8064 1.8 christos 8065 1.8 christos for (i = 0; i < ARRAY_SIZE (cvmx); i++) 8066 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 8067 1.10 christos PPC_CVR0_REGNUM + i, 8068 1.8 christos cvmx[i]); 8069 1.8 christos 8070 1.8 christos if (!valid_p) 8071 1.8 christos return NULL; 8072 1.8 christos have_htm_altivec = 1; 8073 1.8 christos } 8074 1.8 christos else 8075 1.8 christos have_htm_altivec = 0; 8076 1.8 christos 8077 1.8 christos feature = tdesc_find_feature (tdesc, 8078 1.8 christos "org.gnu.gdb.power.htm.vsx"); 8079 1.8 christos if (feature != NULL) 8080 1.8 christos { 8081 1.8 christos valid_p = 1; 8082 1.8 christos 8083 1.8 christos static const char *const cvsx[] = { 8084 1.8 christos "cvs0h", "cvs1h", "cvs2h", "cvs3h", "cvs4h", "cvs5h", 8085 1.8 christos "cvs6h", "cvs7h", "cvs8h", "cvs9h", "cvs10h", "cvs11h", 8086 1.8 christos "cvs12h", "cvs13h", "cvs14h", "cvs15h", "cvs16h", "cvs17h", 8087 1.8 christos "cvs18h", "cvs19h", "cvs20h", "cvs21h", "cvs22h", "cvs23h", 8088 1.8 christos "cvs24h", "cvs25h", "cvs26h", "cvs27h", "cvs28h", "cvs29h", 8089 1.10 christos "cvs30h", "cvs31h" 8090 1.8 christos }; 8091 1.8 christos 8092 1.8 christos for (i = 0; i < ARRAY_SIZE (cvsx); i++) 8093 1.8 christos valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), 8094 1.8 christos (PPC_CVSR0_UPPER_REGNUM 8095 1.10 christos + i), 8096 1.8 christos cvsx[i]); 8097 1.8 christos 8098 1.8 christos if (!valid_p || !have_htm_fpu || !have_htm_altivec) 8099 1.8 christos return NULL; 8100 1.8 christos have_htm_vsx = 1; 8101 1.8 christos } 8102 1.8 christos else 8103 1.8 christos have_htm_vsx = 0; 8104 1.8 christos 8105 1.10 christos feature = tdesc_find_feature (tdesc, 8106 1.8 christos "org.gnu.gdb.power.htm.ppr"); 8107 1.8 christos if (feature != NULL) 8108 1.8 christos { 8109 1.10 christos valid_p = tdesc_numbered_register (feature, tdesc_data.get (), 8110 1.8 christos PPC_CPPR_REGNUM, "cppr"); 8111 1.8 christos 8112 1.8 christos if (!valid_p) 8113 1.8 christos return NULL; 8114 1.8 christos have_htm_ppr = 1; 8115 1.8 christos } 8116 1.8 christos else 8117 1.8 christos have_htm_ppr = 0; 8118 1.8 christos 8119 1.10 christos feature = tdesc_find_feature (tdesc, 8120 1.8 christos "org.gnu.gdb.power.htm.dscr"); 8121 1.8 christos if (feature != NULL) 8122 1.8 christos { 8123 1.10 christos valid_p = tdesc_numbered_register (feature, tdesc_data.get (), 8124 1.8 christos PPC_CDSCR_REGNUM, "cdscr"); 8125 1.8 christos 8126 1.8 christos if (!valid_p) 8127 1.8 christos return NULL; 8128 1.8 christos have_htm_dscr = 1; 8129 1.8 christos } 8130 1.8 christos else 8131 1.8 christos have_htm_dscr = 0; 8132 1.8 christos 8133 1.10 christos feature = tdesc_find_feature (tdesc, 8134 1.8 christos "org.gnu.gdb.power.htm.tar"); 8135 1.8 christos if (feature != NULL) 8136 1.8 christos { 8137 1.10 christos valid_p = tdesc_numbered_register (feature, tdesc_data.get (), 8138 1.8 christos PPC_CTAR_REGNUM, "ctar"); 8139 1.8 christos 8140 1.8 christos if (!valid_p) 8141 1.8 christos return NULL; 8142 1.1 christos have_htm_tar = 1; 8143 1.1 christos } 8144 1.1 christos else 8145 1.1 christos have_htm_tar = 0; 8146 1.1 christos } 8147 1.1 christos 8148 1.1 christos /* If we have a 64-bit binary on a 32-bit target, complain. Also 8149 1.1 christos complain for a 32-bit binary on a 64-bit target; we do not yet 8150 1.1 christos support that. For instance, the 32-bit ABI routines expect 8151 1.1 christos 32-bit GPRs. 8152 1.1 christos 8153 1.1 christos As long as there isn't an explicit target description, we'll 8154 1.1 christos choose one based on the BFD architecture and get a word size 8155 1.1 christos matching the binary (probably powerpc:common or 8156 1.10 christos powerpc:common64). So there is only trouble if a 64-bit target 8157 1.1 christos supplies a 64-bit description while debugging a 32-bit 8158 1.1 christos binary. */ 8159 1.3 christos if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize) 8160 1.3 christos return NULL; 8161 1.3 christos 8162 1.3 christos #ifdef HAVE_ELF 8163 1.3 christos if (from_elf_exec) 8164 1.3 christos { 8165 1.3 christos switch (elf_elfheader (info.abfd)->e_flags & EF_PPC64_ABI) 8166 1.3 christos { 8167 1.3 christos case 1: 8168 1.3 christos elf_abi = POWERPC_ELF_V1; 8169 1.3 christos break; 8170 1.3 christos case 2: 8171 1.3 christos elf_abi = POWERPC_ELF_V2; 8172 1.3 christos break; 8173 1.3 christos default: 8174 1.1 christos break; 8175 1.1 christos } 8176 1.1 christos } 8177 1.8 christos 8178 1.1 christos if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec) 8179 1.1 christos { 8180 1.1 christos switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, 8181 1.1 christos Tag_GNU_Power_ABI_FP) & 3) 8182 1.1 christos { 8183 1.1 christos case 1: 8184 1.1 christos soft_float_flag = AUTO_BOOLEAN_FALSE; 8185 1.1 christos break; 8186 1.1 christos case 2: 8187 1.1 christos soft_float_flag = AUTO_BOOLEAN_TRUE; 8188 1.1 christos break; 8189 1.1 christos default: 8190 1.8 christos break; 8191 1.8 christos } 8192 1.8 christos } 8193 1.8 christos 8194 1.8 christos if (long_double_abi == POWERPC_LONG_DOUBLE_AUTO && from_elf_exec) 8195 1.8 christos { 8196 1.8 christos switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, 8197 1.8 christos Tag_GNU_Power_ABI_FP) >> 2) 8198 1.8 christos { 8199 1.8 christos case 1: 8200 1.8 christos long_double_abi = POWERPC_LONG_DOUBLE_IBM128; 8201 1.8 christos break; 8202 1.8 christos case 3: 8203 1.8 christos long_double_abi = POWERPC_LONG_DOUBLE_IEEE128; 8204 1.8 christos break; 8205 1.8 christos default: 8206 1.1 christos break; 8207 1.1 christos } 8208 1.1 christos } 8209 1.1 christos 8210 1.1 christos if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec) 8211 1.1 christos { 8212 1.1 christos switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, 8213 1.1 christos Tag_GNU_Power_ABI_Vector)) 8214 1.1 christos { 8215 1.1 christos case 1: 8216 1.1 christos vector_abi = POWERPC_VEC_GENERIC; 8217 1.1 christos break; 8218 1.1 christos case 2: 8219 1.1 christos vector_abi = POWERPC_VEC_ALTIVEC; 8220 1.1 christos break; 8221 1.1 christos case 3: 8222 1.1 christos vector_abi = POWERPC_VEC_SPE; 8223 1.1 christos break; 8224 1.1 christos default: 8225 1.1 christos break; 8226 1.3 christos } 8227 1.3 christos } 8228 1.3 christos #endif 8229 1.3 christos 8230 1.3 christos /* At this point, the only supported ELF-based 64-bit little-endian 8231 1.3 christos operating system is GNU/Linux, and this uses the ELFv2 ABI by 8232 1.3 christos default. All other supported ELF-based operating systems use the 8233 1.3 christos ELFv1 ABI by default. Therefore, if the ABI marker is missing, 8234 1.3 christos e.g. because we run a legacy binary, or have attached to a process 8235 1.3 christos and have not found any associated binary file, set the default 8236 1.10 christos according to this heuristic. */ 8237 1.3 christos if (elf_abi == POWERPC_ELF_AUTO) 8238 1.10 christos { 8239 1.3 christos if (wordsize == 8 && info.byte_order == BFD_ENDIAN_LITTLE) 8240 1.3 christos elf_abi = POWERPC_ELF_V2; 8241 1.1 christos else 8242 1.1 christos elf_abi = POWERPC_ELF_V1; 8243 1.1 christos } 8244 1.1 christos 8245 1.1 christos if (soft_float_flag == AUTO_BOOLEAN_TRUE) 8246 1.1 christos soft_float = 1; 8247 1.1 christos else if (soft_float_flag == AUTO_BOOLEAN_FALSE) 8248 1.1 christos soft_float = 0; 8249 1.1 christos else 8250 1.1 christos soft_float = !have_fpu; 8251 1.1 christos 8252 1.1 christos /* If we have a hard float binary or setting but no floating point 8253 1.1 christos registers, downgrade to soft float anyway. We're still somewhat 8254 1.1 christos useful in this scenario. */ 8255 1.1 christos if (!soft_float && !have_fpu) 8256 1.1 christos soft_float = 1; 8257 1.1 christos 8258 1.1 christos /* Similarly for vector registers. */ 8259 1.1 christos if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec) 8260 1.1 christos vector_abi = POWERPC_VEC_GENERIC; 8261 1.1 christos 8262 1.1 christos if (vector_abi == POWERPC_VEC_SPE && !have_spe) 8263 1.1 christos vector_abi = POWERPC_VEC_GENERIC; 8264 1.1 christos 8265 1.1 christos if (vector_abi == POWERPC_VEC_AUTO) 8266 1.1 christos { 8267 1.1 christos if (have_altivec) 8268 1.1 christos vector_abi = POWERPC_VEC_ALTIVEC; 8269 1.1 christos else if (have_spe) 8270 1.1 christos vector_abi = POWERPC_VEC_SPE; 8271 1.1 christos else 8272 1.1 christos vector_abi = POWERPC_VEC_GENERIC; 8273 1.1 christos } 8274 1.1 christos 8275 1.1 christos /* Do not limit the vector ABI based on available hardware, since we 8276 1.1 christos do not yet know what hardware we'll decide we have. Yuck! FIXME! */ 8277 1.1 christos 8278 1.1 christos /* Find a candidate among extant architectures. */ 8279 1.1 christos for (arches = gdbarch_list_lookup_by_info (arches, &info); 8280 1.10 christos arches != NULL; 8281 1.10 christos arches = gdbarch_list_lookup_by_info (arches->next, &info)) 8282 1.10 christos { 8283 1.10 christos /* Word size in the various PowerPC bfd_arch_info structs isn't 8284 1.3 christos meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform 8285 1.3 christos separate word size check. */ 8286 1.1 christos ppc_gdbarch_tdep *tdep 8287 1.1 christos = gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch); 8288 1.8 christos if (tdep && tdep->elf_abi != elf_abi) 8289 1.8 christos continue; 8290 1.1 christos if (tdep && tdep->soft_float != soft_float) 8291 1.1 christos continue; 8292 1.1 christos if (tdep && tdep->long_double_abi != long_double_abi) 8293 1.10 christos continue; 8294 1.1 christos if (tdep && tdep->vector_abi != vector_abi) 8295 1.1 christos continue; 8296 1.1 christos if (tdep && tdep->wordsize == wordsize) 8297 1.1 christos return arches->gdbarch; 8298 1.1 christos } 8299 1.1 christos 8300 1.1 christos /* None found, create a new architecture from INFO, whose bfd_arch_info 8301 1.1 christos validity depends on the source: 8302 1.1 christos - executable useless 8303 1.1 christos - rs6000_host_arch() good 8304 1.11 christos - core file good 8305 1.11 christos - "set arch" trust blindly 8306 1.11 christos - GDB startup useless but harmless */ 8307 1.11 christos 8308 1.1 christos gdbarch *gdbarch 8309 1.3 christos = gdbarch_alloc (&info, gdbarch_tdep_up (new ppc_gdbarch_tdep)); 8310 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 8311 1.8 christos 8312 1.1 christos tdep->wordsize = wordsize; 8313 1.1 christos tdep->elf_abi = elf_abi; 8314 1.1 christos tdep->soft_float = soft_float; 8315 1.1 christos tdep->long_double_abi = long_double_abi; 8316 1.1 christos tdep->vector_abi = vector_abi; 8317 1.1 christos 8318 1.1 christos tdep->ppc_gp0_regnum = PPC_R0_REGNUM; 8319 1.1 christos tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2; 8320 1.1 christos tdep->ppc_ps_regnum = PPC_MSR_REGNUM; 8321 1.1 christos tdep->ppc_cr_regnum = PPC_CR_REGNUM; 8322 1.1 christos tdep->ppc_lr_regnum = PPC_LR_REGNUM; 8323 1.1 christos tdep->ppc_ctr_regnum = PPC_CTR_REGNUM; 8324 1.1 christos tdep->ppc_xer_regnum = PPC_XER_REGNUM; 8325 1.1 christos tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1; 8326 1.1 christos 8327 1.1 christos tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1; 8328 1.1 christos tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1; 8329 1.1 christos tdep->ppc_vsr0_upper_regnum = have_vsx ? PPC_VSR0_UPPER_REGNUM : -1; 8330 1.1 christos tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1; 8331 1.8 christos tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1; 8332 1.8 christos tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1; 8333 1.8 christos tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1; 8334 1.8 christos tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1; 8335 1.8 christos tdep->ppc_ppr_regnum = have_ppr ? PPC_PPR_REGNUM : -1; 8336 1.8 christos tdep->ppc_dscr_regnum = have_dscr ? PPC_DSCR_REGNUM : -1; 8337 1.8 christos tdep->ppc_tar_regnum = have_tar ? PPC_TAR_REGNUM : -1; 8338 1.8 christos tdep->have_ebb = have_ebb; 8339 1.8 christos 8340 1.8 christos /* If additional pmu registers are added, care must be taken when 8341 1.8 christos setting new fields in the tdep below, to maintain compatibility 8342 1.8 christos with features that only provide some of the registers. Currently 8343 1.8 christos gdb access to the pmu registers is only supported in linux, and 8344 1.8 christos linux only provides a subset of the pmu registers defined in the 8345 1.8 christos architecture. */ 8346 1.8 christos 8347 1.8 christos tdep->ppc_mmcr0_regnum = have_pmu ? PPC_MMCR0_REGNUM : -1; 8348 1.8 christos tdep->ppc_mmcr2_regnum = have_pmu ? PPC_MMCR2_REGNUM : -1; 8349 1.8 christos tdep->ppc_siar_regnum = have_pmu ? PPC_SIAR_REGNUM : -1; 8350 1.8 christos tdep->ppc_sdar_regnum = have_pmu ? PPC_SDAR_REGNUM : -1; 8351 1.8 christos tdep->ppc_sier_regnum = have_pmu ? PPC_SIER_REGNUM : -1; 8352 1.8 christos 8353 1.8 christos tdep->have_htm_spr = have_htm_spr; 8354 1.8 christos tdep->have_htm_core = have_htm_core; 8355 1.8 christos tdep->have_htm_fpu = have_htm_fpu; 8356 1.8 christos tdep->have_htm_altivec = have_htm_altivec; 8357 1.1 christos tdep->have_htm_vsx = have_htm_vsx; 8358 1.1 christos tdep->ppc_cppr_regnum = have_htm_ppr ? PPC_CPPR_REGNUM : -1; 8359 1.1 christos tdep->ppc_cdscr_regnum = have_htm_dscr ? PPC_CDSCR_REGNUM : -1; 8360 1.1 christos tdep->ppc_ctar_regnum = have_htm_tar ? PPC_CTAR_REGNUM : -1; 8361 1.1 christos 8362 1.1 christos set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM); 8363 1.1 christos set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1); 8364 1.1 christos set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum); 8365 1.1 christos set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno); 8366 1.1 christos 8367 1.1 christos /* The XML specification for PowerPC sensibly calls the MSR "msr". 8368 1.1 christos GDB traditionally called it "ps", though, so let GDB add an 8369 1.10 christos alias. */ 8370 1.10 christos set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum); 8371 1.11 christos 8372 1.10 christos if (wordsize == 8) 8373 1.1 christos { 8374 1.1 christos set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value); 8375 1.11 christos set_gdbarch_update_call_site_pc (gdbarch, ppc64_update_call_site_pc); 8376 1.1 christos } 8377 1.1 christos else 8378 1.1 christos set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value); 8379 1.1 christos set_gdbarch_get_return_buf_addr (gdbarch, ppc_sysv_get_return_buf_addr); 8380 1.1 christos 8381 1.1 christos /* Set lr_frame_offset. */ 8382 1.1 christos if (wordsize == 8) 8383 1.8 christos tdep->lr_frame_offset = 16; 8384 1.8 christos else 8385 1.1 christos tdep->lr_frame_offset = 4; 8386 1.1 christos 8387 1.11 christos if (have_spe || have_dfp || have_altivec 8388 1.11 christos || have_vsx || have_htm_fpu || have_htm_vsx) 8389 1.6 christos { 8390 1.6 christos set_gdbarch_pseudo_register_read (gdbarch, rs6000_pseudo_register_read); 8391 1.1 christos set_gdbarch_deprecated_pseudo_register_write 8392 1.1 christos (gdbarch, rs6000_pseudo_register_write); 8393 1.6 christos set_gdbarch_ax_pseudo_register_collect (gdbarch, 8394 1.6 christos rs6000_ax_pseudo_register_collect); 8395 1.1 christos } 8396 1.1 christos 8397 1.1 christos set_gdbarch_gen_return_address (gdbarch, rs6000_gen_return_address); 8398 1.1 christos 8399 1.1 christos set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); 8400 1.1 christos 8401 1.1 christos set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS); 8402 1.1 christos 8403 1.8 christos if (have_spe) 8404 1.8 christos num_pseudoregs += 32; 8405 1.1 christos if (have_dfp) 8406 1.1 christos num_pseudoregs += 16; 8407 1.1 christos if (have_altivec) 8408 1.8 christos num_pseudoregs += 32; 8409 1.8 christos if (have_vsx) 8410 1.8 christos /* Include both VSX and Extended FP registers. */ 8411 1.8 christos num_pseudoregs += 96; 8412 1.8 christos if (have_htm_fpu) 8413 1.1 christos num_pseudoregs += 16; 8414 1.1 christos /* Include both checkpointed VSX and EFP registers. */ 8415 1.1 christos if (have_htm_vsx) 8416 1.1 christos num_pseudoregs += 64 + 32; 8417 1.1 christos 8418 1.1 christos set_gdbarch_num_pseudo_regs (gdbarch, num_pseudoregs); 8419 1.1 christos 8420 1.1 christos set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT); 8421 1.1 christos set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); 8422 1.1 christos set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT); 8423 1.1 christos set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT); 8424 1.1 christos set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); 8425 1.1 christos set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); 8426 1.1 christos set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 8427 1.1 christos set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT); 8428 1.1 christos set_gdbarch_char_signed (gdbarch, 0); 8429 1.1 christos 8430 1.1 christos set_gdbarch_frame_align (gdbarch, rs6000_frame_align); 8431 1.1 christos if (wordsize == 8) 8432 1.1 christos /* PPC64 SYSV. */ 8433 1.1 christos set_gdbarch_frame_red_zone_size (gdbarch, 288); 8434 1.11 christos 8435 1.1 christos set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p); 8436 1.1 christos set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value); 8437 1.1 christos set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register); 8438 1.1 christos set_gdbarch_value_from_register (gdbarch, rs6000_value_from_register); 8439 1.1 christos 8440 1.1 christos set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum); 8441 1.1 christos set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum); 8442 1.1 christos 8443 1.1 christos if (wordsize == 4) 8444 1.1 christos set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call); 8445 1.5 christos else if (wordsize == 8) 8446 1.1 christos set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call); 8447 1.1 christos 8448 1.1 christos set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue); 8449 1.7 christos set_gdbarch_stack_frame_destroyed_p (gdbarch, rs6000_stack_frame_destroyed_p); 8450 1.7 christos set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue); 8451 1.7 christos 8452 1.7 christos set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 8453 1.7 christos 8454 1.10 christos set_gdbarch_breakpoint_kind_from_pc (gdbarch, 8455 1.11 christos rs6000_breakpoint::kind_from_pc); 8456 1.1 christos set_gdbarch_sw_breakpoint_from_kind (gdbarch, 8457 1.1 christos rs6000_breakpoint::bp_from_kind); 8458 1.1 christos set_gdbarch_program_breakpoint_here_p (gdbarch, 8459 1.1 christos rs6000_program_breakpoint_here_p); 8460 1.1 christos 8461 1.1 christos /* The value of symbols of type N_SO and N_FUN maybe null when 8462 1.1 christos it shouldn't be. */ 8463 1.1 christos set_gdbarch_sofun_address_maybe_missing (gdbarch, 1); 8464 1.1 christos 8465 1.1 christos /* Handles single stepping of atomic sequences. */ 8466 1.1 christos set_gdbarch_software_single_step (gdbarch, ppc_deal_with_atomic_sequence); 8467 1.1 christos 8468 1.1 christos /* Not sure on this. FIXMEmgo */ 8469 1.1 christos set_gdbarch_frame_args_skip (gdbarch, 8); 8470 1.1 christos 8471 1.1 christos /* Helpers for function argument information. */ 8472 1.1 christos set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument); 8473 1.1 christos 8474 1.1 christos /* Trampoline. */ 8475 1.1 christos set_gdbarch_in_solib_return_trampoline 8476 1.1 christos (gdbarch, rs6000_in_solib_return_trampoline); 8477 1.1 christos set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code); 8478 1.1 christos 8479 1.1 christos /* Hook in the DWARF CFI frame unwinder. */ 8480 1.1 christos dwarf2_append_unwinders (gdbarch); 8481 1.1 christos dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum); 8482 1.1 christos 8483 1.1 christos /* Frame handling. */ 8484 1.6 christos dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg); 8485 1.1 christos 8486 1.1 christos /* Setup displaced stepping. */ 8487 1.1 christos set_gdbarch_displaced_step_copy_insn (gdbarch, 8488 1.10 christos ppc_displaced_step_copy_insn); 8489 1.10 christos set_gdbarch_displaced_step_hw_singlestep (gdbarch, 8490 1.10 christos ppc_displaced_step_hw_singlestep); 8491 1.10 christos set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup); 8492 1.11 christos set_gdbarch_displaced_step_prepare (gdbarch, ppc_displaced_step_prepare); 8493 1.1 christos set_gdbarch_displaced_step_finish (gdbarch, ppc_displaced_step_finish); 8494 1.11 christos set_gdbarch_displaced_step_restore_all_in_ptid 8495 1.1 christos (gdbarch, ppc_displaced_step_restore_all_in_ptid); 8496 1.1 christos set_gdbarch_displaced_step_buffer_length (gdbarch, 2 * PPC_INSN_SIZE); 8497 1.1 christos 8498 1.10 christos set_gdbarch_max_insn_length (gdbarch, PPC_INSN_SIZE); 8499 1.1 christos 8500 1.1 christos /* Hook in ABI-specific overrides, if they have been registered. */ 8501 1.1 christos info.target_desc = tdesc; 8502 1.1 christos info.tdesc_data = tdesc_data.get (); 8503 1.1 christos gdbarch_init_osabi (info, gdbarch); 8504 1.7 christos 8505 1.1 christos switch (info.osabi) 8506 1.3 christos { 8507 1.1 christos case GDB_OSABI_LINUX: 8508 1.1 christos case GDB_OSABI_NETBSD: 8509 1.1 christos case GDB_OSABI_UNKNOWN: 8510 1.1 christos frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind); 8511 1.1 christos frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind); 8512 1.1 christos frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer); 8513 1.3 christos break; 8514 1.1 christos default: 8515 1.1 christos set_gdbarch_believe_pcc_promotion (gdbarch, 1); 8516 1.1 christos 8517 1.1 christos frame_unwind_append_unwinder (gdbarch, &rs6000_epilogue_frame_unwind); 8518 1.1 christos frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind); 8519 1.1 christos frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer); 8520 1.1 christos } 8521 1.10 christos 8522 1.1 christos set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type); 8523 1.1 christos set_tdesc_pseudo_register_reggroup_p (gdbarch, 8524 1.1 christos rs6000_pseudo_register_reggroup_p); 8525 1.1 christos tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data)); 8526 1.1 christos 8527 1.1 christos /* Override the normal target description method to make the SPE upper 8528 1.1 christos halves anonymous. */ 8529 1.1 christos set_gdbarch_register_name (gdbarch, rs6000_register_name); 8530 1.8 christos 8531 1.1 christos /* Choose register numbers for all supported pseudo-registers. */ 8532 1.1 christos tdep->ppc_ev0_regnum = -1; 8533 1.8 christos tdep->ppc_dl0_regnum = -1; 8534 1.8 christos tdep->ppc_v0_alias_regnum = -1; 8535 1.8 christos tdep->ppc_vsr0_regnum = -1; 8536 1.1 christos tdep->ppc_efpr0_regnum = -1; 8537 1.1 christos tdep->ppc_cdl0_regnum = -1; 8538 1.1 christos tdep->ppc_cvsr0_regnum = -1; 8539 1.1 christos tdep->ppc_cefpr0_regnum = -1; 8540 1.1 christos 8541 1.1 christos cur_reg = gdbarch_num_regs (gdbarch); 8542 1.1 christos 8543 1.1 christos if (have_spe) 8544 1.1 christos { 8545 1.1 christos tdep->ppc_ev0_regnum = cur_reg; 8546 1.1 christos cur_reg += 32; 8547 1.1 christos } 8548 1.1 christos if (have_dfp) 8549 1.8 christos { 8550 1.8 christos tdep->ppc_dl0_regnum = cur_reg; 8551 1.8 christos cur_reg += 16; 8552 1.8 christos } 8553 1.8 christos if (have_altivec) 8554 1.1 christos { 8555 1.1 christos tdep->ppc_v0_alias_regnum = cur_reg; 8556 1.1 christos cur_reg += 32; 8557 1.1 christos } 8558 1.1 christos if (have_vsx) 8559 1.1 christos { 8560 1.1 christos tdep->ppc_vsr0_regnum = cur_reg; 8561 1.8 christos cur_reg += 64; 8562 1.8 christos tdep->ppc_efpr0_regnum = cur_reg; 8563 1.8 christos cur_reg += 32; 8564 1.8 christos } 8565 1.8 christos if (have_htm_fpu) 8566 1.8 christos { 8567 1.8 christos tdep->ppc_cdl0_regnum = cur_reg; 8568 1.8 christos cur_reg += 16; 8569 1.8 christos } 8570 1.8 christos if (have_htm_vsx) 8571 1.8 christos { 8572 1.8 christos tdep->ppc_cvsr0_regnum = cur_reg; 8573 1.1 christos cur_reg += 64; 8574 1.8 christos tdep->ppc_cefpr0_regnum = cur_reg; 8575 1.1 christos cur_reg += 32; 8576 1.1 christos } 8577 1.1 christos 8578 1.1 christos gdb_assert (gdbarch_num_cooked_regs (gdbarch) == cur_reg); 8579 1.1 christos 8580 1.1 christos /* Register the ravenscar_arch_ops. */ 8581 1.1 christos if (mach == bfd_mach_ppc_e500) 8582 1.7 christos register_e500_ravenscar_ops (gdbarch); 8583 1.7 christos else 8584 1.7 christos register_ppc_ravenscar_ops (gdbarch); 8585 1.7 christos 8586 1.1 christos set_gdbarch_disassembler_options (gdbarch, &powerpc_disassembler_options); 8587 1.1 christos set_gdbarch_valid_disassembler_options (gdbarch, 8588 1.1 christos disassembler_options_powerpc ()); 8589 1.1 christos 8590 1.1 christos return gdbarch; 8591 1.1 christos } 8592 1.10 christos 8593 1.1 christos static void 8594 1.1 christos rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) 8595 1.1 christos { 8596 1.1 christos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 8597 1.1 christos 8598 1.1 christos if (tdep == NULL) 8599 1.1 christos return; 8600 1.1 christos 8601 1.8 christos /* FIXME: Dump gdbarch_tdep. */ 8602 1.1 christos } 8603 1.1 christos 8604 1.1 christos static void 8605 1.1 christos powerpc_set_soft_float (const char *args, int from_tty, 8606 1.1 christos struct cmd_list_element *c) 8607 1.1 christos { 8608 1.10 christos struct gdbarch_info info; 8609 1.1 christos 8610 1.1 christos /* Update the architecture. */ 8611 1.1 christos if (!gdbarch_update_p (info)) 8612 1.8 christos internal_error (_("could not update architecture")); 8613 1.1 christos } 8614 1.1 christos 8615 1.5 christos static void 8616 1.1 christos powerpc_set_vector_abi (const char *args, int from_tty, 8617 1.1 christos struct cmd_list_element *c) 8618 1.1 christos { 8619 1.1 christos int vector_abi; 8620 1.1 christos 8621 1.1 christos for (vector_abi = POWERPC_VEC_AUTO; 8622 1.1 christos vector_abi != POWERPC_VEC_LAST; 8623 1.6 christos vector_abi++) 8624 1.1 christos if (strcmp (powerpc_vector_abi_string, 8625 1.1 christos powerpc_vector_strings[vector_abi]) == 0) 8626 1.1 christos { 8627 1.1 christos powerpc_vector_abi_global = (enum powerpc_vector_abi) vector_abi; 8628 1.10 christos break; 8629 1.1 christos } 8630 1.1 christos 8631 1.1 christos if (vector_abi == POWERPC_VEC_LAST) 8632 1.10 christos internal_error (_("Invalid vector ABI accepted: %s."), 8633 1.1 christos powerpc_vector_abi_string); 8634 1.10 christos 8635 1.1 christos /* Update the architecture. */ 8636 1.1 christos gdbarch_info info; 8637 1.1 christos if (!gdbarch_update_p (info)) 8638 1.1 christos internal_error (_("could not update architecture")); 8639 1.1 christos } 8640 1.1 christos 8641 1.1 christos /* Show the current setting of the exact watchpoints flag. */ 8642 1.1 christos 8643 1.1 christos static void 8644 1.10 christos show_powerpc_exact_watchpoints (struct ui_file *file, int from_tty, 8645 1.1 christos struct cmd_list_element *c, 8646 1.1 christos const char *value) 8647 1.1 christos { 8648 1.1 christos gdb_printf (file, _("Use of exact watchpoints is %s.\n"), value); 8649 1.1 christos } 8650 1.11 christos 8651 1.1 christos /* Read a PPC instruction from memory. */ 8652 1.1 christos 8653 1.1 christos static unsigned int 8654 1.1 christos read_insn (const frame_info_ptr &frame, CORE_ADDR pc) 8655 1.1 christos { 8656 1.1 christos struct gdbarch *gdbarch = get_frame_arch (frame); 8657 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 8658 1.1 christos 8659 1.1 christos return read_memory_unsigned_integer (pc, 4, byte_order); 8660 1.1 christos } 8661 1.1 christos 8662 1.1 christos /* Return non-zero if the instructions at PC match the series 8663 1.8 christos described in PATTERN, or zero otherwise. PATTERN is an array of 8664 1.1 christos 'struct ppc_insn_pattern' objects, terminated by an entry whose 8665 1.8 christos mask is zero. 8666 1.8 christos 8667 1.8 christos When the match is successful, fill INSNS[i] with what PATTERN[i] 8668 1.8 christos matched. If PATTERN[i] is optional, and the instruction wasn't 8669 1.8 christos present, set INSNS[i] to 0 (which is not a valid PPC instruction). 8670 1.1 christos INSNS should have as many elements as PATTERN, minus the terminator. 8671 1.1 christos Note that, if PATTERN contains optional instructions which aren't 8672 1.11 christos present in memory, then INSNS will have holes, so INSNS[i] isn't 8673 1.8 christos necessarily the i'th instruction in memory. */ 8674 1.1 christos 8675 1.1 christos int 8676 1.1 christos ppc_insns_match_pattern (const frame_info_ptr &frame, CORE_ADDR pc, 8677 1.1 christos const struct ppc_insn_pattern *pattern, 8678 1.1 christos unsigned int *insns) 8679 1.1 christos { 8680 1.1 christos int i; 8681 1.1 christos unsigned int insn; 8682 1.1 christos 8683 1.1 christos for (i = 0, insn = 0; pattern[i].mask; i++) 8684 1.1 christos { 8685 1.1 christos if (insn == 0) 8686 1.1 christos insn = read_insn (frame, pc); 8687 1.1 christos insns[i] = 0; 8688 1.1 christos if ((insn & pattern[i].mask) == pattern[i].data) 8689 1.1 christos { 8690 1.1 christos insns[i] = insn; 8691 1.1 christos pc += 4; 8692 1.1 christos insn = 0; 8693 1.1 christos } 8694 1.1 christos else if (!pattern[i].optional) 8695 1.1 christos return 0; 8696 1.1 christos } 8697 1.1 christos 8698 1.1 christos return 1; 8699 1.1 christos } 8700 1.1 christos 8701 1.1 christos /* Return the 'd' field of the d-form instruction INSN, properly 8702 1.1 christos sign-extended. */ 8703 1.1 christos 8704 1.1 christos CORE_ADDR 8705 1.1 christos ppc_insn_d_field (unsigned int insn) 8706 1.1 christos { 8707 1.1 christos return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000); 8708 1.1 christos } 8709 1.1 christos 8710 1.1 christos /* Return the 'ds' field of the ds-form instruction INSN, with the two 8711 1.1 christos zero bits concatenated at the right, and properly 8712 1.1 christos sign-extended. */ 8713 1.1 christos 8714 1.1 christos CORE_ADDR 8715 1.1 christos ppc_insn_ds_field (unsigned int insn) 8716 1.10 christos { 8717 1.10 christos return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000); 8718 1.10 christos } 8719 1.10 christos 8720 1.10 christos CORE_ADDR 8721 1.10 christos ppc_insn_prefix_dform (unsigned int insn1, unsigned int insn2) 8722 1.10 christos { 8723 1.10 christos /* result is 34-bits */ 8724 1.1 christos return (CORE_ADDR) ((((insn1 & 0x3ffff) ^ 0x20000) - 0x20000) << 16) 8725 1.1 christos | (CORE_ADDR)(insn2 & 0xffff); 8726 1.9 christos } 8727 1.1 christos 8728 1.9 christos /* Initialization code. */ 8729 1.1 christos 8730 1.1 christos void _initialize_rs6000_tdep (); 8731 1.1 christos void 8732 1.1 christos _initialize_rs6000_tdep () 8733 1.1 christos { 8734 1.1 christos gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep); 8735 1.1 christos gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep); 8736 1.1 christos 8737 1.1 christos /* Initialize the standard target descriptions. */ 8738 1.1 christos initialize_tdesc_powerpc_32 (); 8739 1.1 christos initialize_tdesc_powerpc_altivec32 (); 8740 1.1 christos initialize_tdesc_powerpc_vsx32 (); 8741 1.1 christos initialize_tdesc_powerpc_403 (); 8742 1.1 christos initialize_tdesc_powerpc_403gc (); 8743 1.1 christos initialize_tdesc_powerpc_405 (); 8744 1.1 christos initialize_tdesc_powerpc_505 (); 8745 1.1 christos initialize_tdesc_powerpc_601 (); 8746 1.1 christos initialize_tdesc_powerpc_602 (); 8747 1.1 christos initialize_tdesc_powerpc_603 (); 8748 1.1 christos initialize_tdesc_powerpc_604 (); 8749 1.1 christos initialize_tdesc_powerpc_64 (); 8750 1.1 christos initialize_tdesc_powerpc_altivec64 (); 8751 1.1 christos initialize_tdesc_powerpc_vsx64 (); 8752 1.1 christos initialize_tdesc_powerpc_7400 (); 8753 1.1 christos initialize_tdesc_powerpc_750 (); 8754 1.1 christos initialize_tdesc_powerpc_860 (); 8755 1.1 christos initialize_tdesc_powerpc_e500 (); 8756 1.10 christos initialize_tdesc_rs6000 (); 8757 1.10 christos 8758 1.10 christos /* Add root prefix command for all "set powerpc"/"show powerpc" 8759 1.10 christos commands. */ 8760 1.10 christos add_setshow_prefix_cmd ("powerpc", no_class, 8761 1.1 christos _("Various PowerPC-specific commands."), 8762 1.1 christos _("Various PowerPC-specific commands."), 8763 1.1 christos &setpowerpccmdlist, &showpowerpccmdlist, 8764 1.1 christos &setlist, &showlist); 8765 1.1 christos 8766 1.1 christos /* Add a command to allow the user to force the ABI. */ 8767 1.1 christos add_setshow_auto_boolean_cmd ("soft-float", class_support, 8768 1.1 christos &powerpc_soft_float_global, 8769 1.1 christos _("Set whether to use a soft-float ABI."), 8770 1.1 christos _("Show whether to use a soft-float ABI."), 8771 1.1 christos NULL, 8772 1.1 christos powerpc_set_soft_float, NULL, 8773 1.1 christos &setpowerpccmdlist, &showpowerpccmdlist); 8774 1.1 christos 8775 1.1 christos add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings, 8776 1.1 christos &powerpc_vector_abi_string, 8777 1.1 christos _("Set the vector ABI."), 8778 1.1 christos _("Show the vector ABI."), 8779 1.1 christos NULL, powerpc_set_vector_abi, NULL, 8780 1.1 christos &setpowerpccmdlist, &showpowerpccmdlist); 8781 1.1 christos 8782 1.1 christos add_setshow_boolean_cmd ("exact-watchpoints", class_support, 8783 1.1 christos &target_exact_watchpoints, 8784 1.1 christos _("\ 8785 1.1 christos Set whether to use just one debug register for watchpoints on scalars."), 8786 1.1 christos _("\ 8787 1.1 christos Show whether to use just one debug register for watchpoints on scalars."), 8788 1.1 christos _("\ 8789 1.1 christos If true, GDB will use only one debug register when watching a variable of\n\ 8790 1.1 christos scalar type, thus assuming that the variable is accessed through the address\n\ 8791 of its first byte."), 8792 NULL, show_powerpc_exact_watchpoints, 8793 &setpowerpccmdlist, &showpowerpccmdlist); 8794 } 8795