GDB (API)
|
00001 /* Target-dependent code for GDB, the GNU debugger. 00002 00003 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "frame.h" 00022 #include "inferior.h" 00023 #include "symtab.h" 00024 #include "target.h" 00025 #include "gdbcore.h" 00026 #include "gdbcmd.h" 00027 #include "objfiles.h" 00028 #include "arch-utils.h" 00029 #include "regcache.h" 00030 #include "regset.h" 00031 #include "doublest.h" 00032 #include "value.h" 00033 #include "parser-defs.h" 00034 #include "osabi.h" 00035 #include "infcall.h" 00036 #include "sim-regno.h" 00037 #include "gdb/sim-ppc.h" 00038 #include "reggroups.h" 00039 #include "dwarf2-frame.h" 00040 #include "target-descriptions.h" 00041 #include "user-regs.h" 00042 00043 #include "libbfd.h" /* for bfd_default_set_arch_mach */ 00044 #include "coff/internal.h" /* for libcoff.h */ 00045 #include "libcoff.h" /* for xcoff_data */ 00046 #include "coff/xcoff.h" 00047 #include "libxcoff.h" 00048 00049 #include "elf-bfd.h" 00050 #include "elf/ppc.h" 00051 00052 #include "solib-svr4.h" 00053 #include "ppc-tdep.h" 00054 #include "ppc-ravenscar-thread.h" 00055 00056 #include "gdb_assert.h" 00057 #include "dis-asm.h" 00058 00059 #include "trad-frame.h" 00060 #include "frame-unwind.h" 00061 #include "frame-base.h" 00062 00063 #include "features/rs6000/powerpc-32.c" 00064 #include "features/rs6000/powerpc-altivec32.c" 00065 #include "features/rs6000/powerpc-vsx32.c" 00066 #include "features/rs6000/powerpc-403.c" 00067 #include "features/rs6000/powerpc-403gc.c" 00068 #include "features/rs6000/powerpc-405.c" 00069 #include "features/rs6000/powerpc-505.c" 00070 #include "features/rs6000/powerpc-601.c" 00071 #include "features/rs6000/powerpc-602.c" 00072 #include "features/rs6000/powerpc-603.c" 00073 #include "features/rs6000/powerpc-604.c" 00074 #include "features/rs6000/powerpc-64.c" 00075 #include "features/rs6000/powerpc-altivec64.c" 00076 #include "features/rs6000/powerpc-vsx64.c" 00077 #include "features/rs6000/powerpc-7400.c" 00078 #include "features/rs6000/powerpc-750.c" 00079 #include "features/rs6000/powerpc-860.c" 00080 #include "features/rs6000/powerpc-e500.c" 00081 #include "features/rs6000/rs6000.c" 00082 00083 /* Determine if regnum is an SPE pseudo-register. */ 00084 #define IS_SPE_PSEUDOREG(tdep, regnum) ((tdep)->ppc_ev0_regnum >= 0 \ 00085 && (regnum) >= (tdep)->ppc_ev0_regnum \ 00086 && (regnum) < (tdep)->ppc_ev0_regnum + 32) 00087 00088 /* Determine if regnum is a decimal float pseudo-register. */ 00089 #define IS_DFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_dl0_regnum >= 0 \ 00090 && (regnum) >= (tdep)->ppc_dl0_regnum \ 00091 && (regnum) < (tdep)->ppc_dl0_regnum + 16) 00092 00093 /* Determine if regnum is a POWER7 VSX register. */ 00094 #define IS_VSX_PSEUDOREG(tdep, regnum) ((tdep)->ppc_vsr0_regnum >= 0 \ 00095 && (regnum) >= (tdep)->ppc_vsr0_regnum \ 00096 && (regnum) < (tdep)->ppc_vsr0_regnum + ppc_num_vsrs) 00097 00098 /* Determine if regnum is a POWER7 Extended FP register. */ 00099 #define IS_EFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_efpr0_regnum >= 0 \ 00100 && (regnum) >= (tdep)->ppc_efpr0_regnum \ 00101 && (regnum) < (tdep)->ppc_efpr0_regnum + ppc_num_efprs) 00102 00103 /* The list of available "set powerpc ..." and "show powerpc ..." 00104 commands. */ 00105 static struct cmd_list_element *setpowerpccmdlist = NULL; 00106 static struct cmd_list_element *showpowerpccmdlist = NULL; 00107 00108 static enum auto_boolean powerpc_soft_float_global = AUTO_BOOLEAN_AUTO; 00109 00110 /* The vector ABI to use. Keep this in sync with powerpc_vector_abi. */ 00111 static const char *const powerpc_vector_strings[] = 00112 { 00113 "auto", 00114 "generic", 00115 "altivec", 00116 "spe", 00117 NULL 00118 }; 00119 00120 /* A variable that can be configured by the user. */ 00121 static enum powerpc_vector_abi powerpc_vector_abi_global = POWERPC_VEC_AUTO; 00122 static const char *powerpc_vector_abi_string = "auto"; 00123 00124 /* To be used by skip_prologue. */ 00125 00126 struct rs6000_framedata 00127 { 00128 int offset; /* total size of frame --- the distance 00129 by which we decrement sp to allocate 00130 the frame */ 00131 int saved_gpr; /* smallest # of saved gpr */ 00132 unsigned int gpr_mask; /* Each bit is an individual saved GPR. */ 00133 int saved_fpr; /* smallest # of saved fpr */ 00134 int saved_vr; /* smallest # of saved vr */ 00135 int saved_ev; /* smallest # of saved ev */ 00136 int alloca_reg; /* alloca register number (frame ptr) */ 00137 char frameless; /* true if frameless functions. */ 00138 char nosavedpc; /* true if pc not saved. */ 00139 char used_bl; /* true if link register clobbered */ 00140 int gpr_offset; /* offset of saved gprs from prev sp */ 00141 int fpr_offset; /* offset of saved fprs from prev sp */ 00142 int vr_offset; /* offset of saved vrs from prev sp */ 00143 int ev_offset; /* offset of saved evs from prev sp */ 00144 int lr_offset; /* offset of saved lr */ 00145 int lr_register; /* register of saved lr, if trustworthy */ 00146 int cr_offset; /* offset of saved cr */ 00147 int vrsave_offset; /* offset of saved vrsave register */ 00148 }; 00149 00150 00151 /* Is REGNO a VSX register? Return 1 if so, 0 otherwise. */ 00152 int 00153 vsx_register_p (struct gdbarch *gdbarch, int regno) 00154 { 00155 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00156 if (tdep->ppc_vsr0_regnum < 0) 00157 return 0; 00158 else 00159 return (regno >= tdep->ppc_vsr0_upper_regnum && regno 00160 <= tdep->ppc_vsr0_upper_regnum + 31); 00161 } 00162 00163 /* Is REGNO an AltiVec register? Return 1 if so, 0 otherwise. */ 00164 int 00165 altivec_register_p (struct gdbarch *gdbarch, int regno) 00166 { 00167 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00168 if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0) 00169 return 0; 00170 else 00171 return (regno >= tdep->ppc_vr0_regnum && regno <= tdep->ppc_vrsave_regnum); 00172 } 00173 00174 00175 /* Return true if REGNO is an SPE register, false otherwise. */ 00176 int 00177 spe_register_p (struct gdbarch *gdbarch, int regno) 00178 { 00179 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00180 00181 /* Is it a reference to EV0 -- EV31, and do we have those? */ 00182 if (IS_SPE_PSEUDOREG (tdep, regno)) 00183 return 1; 00184 00185 /* Is it a reference to one of the raw upper GPR halves? */ 00186 if (tdep->ppc_ev0_upper_regnum >= 0 00187 && tdep->ppc_ev0_upper_regnum <= regno 00188 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs) 00189 return 1; 00190 00191 /* Is it a reference to the 64-bit accumulator, and do we have that? */ 00192 if (tdep->ppc_acc_regnum >= 0 00193 && tdep->ppc_acc_regnum == regno) 00194 return 1; 00195 00196 /* Is it a reference to the SPE floating-point status and control register, 00197 and do we have that? */ 00198 if (tdep->ppc_spefscr_regnum >= 0 00199 && tdep->ppc_spefscr_regnum == regno) 00200 return 1; 00201 00202 return 0; 00203 } 00204 00205 00206 /* Return non-zero if the architecture described by GDBARCH has 00207 floating-point registers (f0 --- f31 and fpscr). */ 00208 int 00209 ppc_floating_point_unit_p (struct gdbarch *gdbarch) 00210 { 00211 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00212 00213 return (tdep->ppc_fp0_regnum >= 0 00214 && tdep->ppc_fpscr_regnum >= 0); 00215 } 00216 00217 /* Return non-zero if the architecture described by GDBARCH has 00218 VSX registers (vsr0 --- vsr63). */ 00219 static int 00220 ppc_vsx_support_p (struct gdbarch *gdbarch) 00221 { 00222 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00223 00224 return tdep->ppc_vsr0_regnum >= 0; 00225 } 00226 00227 /* Return non-zero if the architecture described by GDBARCH has 00228 Altivec registers (vr0 --- vr31, vrsave and vscr). */ 00229 int 00230 ppc_altivec_support_p (struct gdbarch *gdbarch) 00231 { 00232 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00233 00234 return (tdep->ppc_vr0_regnum >= 0 00235 && tdep->ppc_vrsave_regnum >= 0); 00236 } 00237 00238 /* Check that TABLE[GDB_REGNO] is not already initialized, and then 00239 set it to SIM_REGNO. 00240 00241 This is a helper function for init_sim_regno_table, constructing 00242 the table mapping GDB register numbers to sim register numbers; we 00243 initialize every element in that table to -1 before we start 00244 filling it in. */ 00245 static void 00246 set_sim_regno (int *table, int gdb_regno, int sim_regno) 00247 { 00248 /* Make sure we don't try to assign any given GDB register a sim 00249 register number more than once. */ 00250 gdb_assert (table[gdb_regno] == -1); 00251 table[gdb_regno] = sim_regno; 00252 } 00253 00254 00255 /* Initialize ARCH->tdep->sim_regno, the table mapping GDB register 00256 numbers to simulator register numbers, based on the values placed 00257 in the ARCH->tdep->ppc_foo_regnum members. */ 00258 static void 00259 init_sim_regno_table (struct gdbarch *arch) 00260 { 00261 struct gdbarch_tdep *tdep = gdbarch_tdep (arch); 00262 int total_regs = gdbarch_num_regs (arch); 00263 int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int); 00264 int i; 00265 static const char *const segment_regs[] = { 00266 "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7", 00267 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15" 00268 }; 00269 00270 /* Presume that all registers not explicitly mentioned below are 00271 unavailable from the sim. */ 00272 for (i = 0; i < total_regs; i++) 00273 sim_regno[i] = -1; 00274 00275 /* General-purpose registers. */ 00276 for (i = 0; i < ppc_num_gprs; i++) 00277 set_sim_regno (sim_regno, tdep->ppc_gp0_regnum + i, sim_ppc_r0_regnum + i); 00278 00279 /* Floating-point registers. */ 00280 if (tdep->ppc_fp0_regnum >= 0) 00281 for (i = 0; i < ppc_num_fprs; i++) 00282 set_sim_regno (sim_regno, 00283 tdep->ppc_fp0_regnum + i, 00284 sim_ppc_f0_regnum + i); 00285 if (tdep->ppc_fpscr_regnum >= 0) 00286 set_sim_regno (sim_regno, tdep->ppc_fpscr_regnum, sim_ppc_fpscr_regnum); 00287 00288 set_sim_regno (sim_regno, gdbarch_pc_regnum (arch), sim_ppc_pc_regnum); 00289 set_sim_regno (sim_regno, tdep->ppc_ps_regnum, sim_ppc_ps_regnum); 00290 set_sim_regno (sim_regno, tdep->ppc_cr_regnum, sim_ppc_cr_regnum); 00291 00292 /* Segment registers. */ 00293 for (i = 0; i < ppc_num_srs; i++) 00294 { 00295 int gdb_regno; 00296 00297 gdb_regno = user_reg_map_name_to_regnum (arch, segment_regs[i], -1); 00298 if (gdb_regno >= 0) 00299 set_sim_regno (sim_regno, gdb_regno, sim_ppc_sr0_regnum + i); 00300 } 00301 00302 /* Altivec registers. */ 00303 if (tdep->ppc_vr0_regnum >= 0) 00304 { 00305 for (i = 0; i < ppc_num_vrs; i++) 00306 set_sim_regno (sim_regno, 00307 tdep->ppc_vr0_regnum + i, 00308 sim_ppc_vr0_regnum + i); 00309 00310 /* FIXME: jimb/2004-07-15: when we have tdep->ppc_vscr_regnum, 00311 we can treat this more like the other cases. */ 00312 set_sim_regno (sim_regno, 00313 tdep->ppc_vr0_regnum + ppc_num_vrs, 00314 sim_ppc_vscr_regnum); 00315 } 00316 /* vsave is a special-purpose register, so the code below handles it. */ 00317 00318 /* SPE APU (E500) registers. */ 00319 if (tdep->ppc_ev0_upper_regnum >= 0) 00320 for (i = 0; i < ppc_num_gprs; i++) 00321 set_sim_regno (sim_regno, 00322 tdep->ppc_ev0_upper_regnum + i, 00323 sim_ppc_rh0_regnum + i); 00324 if (tdep->ppc_acc_regnum >= 0) 00325 set_sim_regno (sim_regno, tdep->ppc_acc_regnum, sim_ppc_acc_regnum); 00326 /* spefscr is a special-purpose register, so the code below handles it. */ 00327 00328 #ifdef WITH_SIM 00329 /* Now handle all special-purpose registers. Verify that they 00330 haven't mistakenly been assigned numbers by any of the above 00331 code. */ 00332 for (i = 0; i < sim_ppc_num_sprs; i++) 00333 { 00334 const char *spr_name = sim_spr_register_name (i); 00335 int gdb_regno = -1; 00336 00337 if (spr_name != NULL) 00338 gdb_regno = user_reg_map_name_to_regnum (arch, spr_name, -1); 00339 00340 if (gdb_regno != -1) 00341 set_sim_regno (sim_regno, gdb_regno, sim_ppc_spr0_regnum + i); 00342 } 00343 #endif 00344 00345 /* Drop the initialized array into place. */ 00346 tdep->sim_regno = sim_regno; 00347 } 00348 00349 00350 /* Given a GDB register number REG, return the corresponding SIM 00351 register number. */ 00352 static int 00353 rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg) 00354 { 00355 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00356 int sim_regno; 00357 00358 if (tdep->sim_regno == NULL) 00359 init_sim_regno_table (gdbarch); 00360 00361 gdb_assert (0 <= reg 00362 && reg <= gdbarch_num_regs (gdbarch) 00363 + gdbarch_num_pseudo_regs (gdbarch)); 00364 sim_regno = tdep->sim_regno[reg]; 00365 00366 if (sim_regno >= 0) 00367 return sim_regno; 00368 else 00369 return LEGACY_SIM_REGNO_IGNORE; 00370 } 00371 00372 00373 00374 /* Register set support functions. */ 00375 00376 /* REGS + OFFSET contains register REGNUM in a field REGSIZE wide. 00377 Write the register to REGCACHE. */ 00378 00379 void 00380 ppc_supply_reg (struct regcache *regcache, int regnum, 00381 const gdb_byte *regs, size_t offset, int regsize) 00382 { 00383 if (regnum != -1 && offset != -1) 00384 { 00385 if (regsize > 4) 00386 { 00387 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00388 int gdb_regsize = register_size (gdbarch, regnum); 00389 if (gdb_regsize < regsize 00390 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 00391 offset += regsize - gdb_regsize; 00392 } 00393 regcache_raw_supply (regcache, regnum, regs + offset); 00394 } 00395 } 00396 00397 /* Read register REGNUM from REGCACHE and store to REGS + OFFSET 00398 in a field REGSIZE wide. Zero pad as necessary. */ 00399 00400 void 00401 ppc_collect_reg (const struct regcache *regcache, int regnum, 00402 gdb_byte *regs, size_t offset, int regsize) 00403 { 00404 if (regnum != -1 && offset != -1) 00405 { 00406 if (regsize > 4) 00407 { 00408 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00409 int gdb_regsize = register_size (gdbarch, regnum); 00410 if (gdb_regsize < regsize) 00411 { 00412 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 00413 { 00414 memset (regs + offset, 0, regsize - gdb_regsize); 00415 offset += regsize - gdb_regsize; 00416 } 00417 else 00418 memset (regs + offset + regsize - gdb_regsize, 0, 00419 regsize - gdb_regsize); 00420 } 00421 } 00422 regcache_raw_collect (regcache, regnum, regs + offset); 00423 } 00424 } 00425 00426 static int 00427 ppc_greg_offset (struct gdbarch *gdbarch, 00428 struct gdbarch_tdep *tdep, 00429 const struct ppc_reg_offsets *offsets, 00430 int regnum, 00431 int *regsize) 00432 { 00433 *regsize = offsets->gpr_size; 00434 if (regnum >= tdep->ppc_gp0_regnum 00435 && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs) 00436 return (offsets->r0_offset 00437 + (regnum - tdep->ppc_gp0_regnum) * offsets->gpr_size); 00438 00439 if (regnum == gdbarch_pc_regnum (gdbarch)) 00440 return offsets->pc_offset; 00441 00442 if (regnum == tdep->ppc_ps_regnum) 00443 return offsets->ps_offset; 00444 00445 if (regnum == tdep->ppc_lr_regnum) 00446 return offsets->lr_offset; 00447 00448 if (regnum == tdep->ppc_ctr_regnum) 00449 return offsets->ctr_offset; 00450 00451 *regsize = offsets->xr_size; 00452 if (regnum == tdep->ppc_cr_regnum) 00453 return offsets->cr_offset; 00454 00455 if (regnum == tdep->ppc_xer_regnum) 00456 return offsets->xer_offset; 00457 00458 if (regnum == tdep->ppc_mq_regnum) 00459 return offsets->mq_offset; 00460 00461 return -1; 00462 } 00463 00464 static int 00465 ppc_fpreg_offset (struct gdbarch_tdep *tdep, 00466 const struct ppc_reg_offsets *offsets, 00467 int regnum) 00468 { 00469 if (regnum >= tdep->ppc_fp0_regnum 00470 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs) 00471 return offsets->f0_offset + (regnum - tdep->ppc_fp0_regnum) * 8; 00472 00473 if (regnum == tdep->ppc_fpscr_regnum) 00474 return offsets->fpscr_offset; 00475 00476 return -1; 00477 } 00478 00479 static int 00480 ppc_vrreg_offset (struct gdbarch_tdep *tdep, 00481 const struct ppc_reg_offsets *offsets, 00482 int regnum) 00483 { 00484 if (regnum >= tdep->ppc_vr0_regnum 00485 && regnum < tdep->ppc_vr0_regnum + ppc_num_vrs) 00486 return offsets->vr0_offset + (regnum - tdep->ppc_vr0_regnum) * 16; 00487 00488 if (regnum == tdep->ppc_vrsave_regnum - 1) 00489 return offsets->vscr_offset; 00490 00491 if (regnum == tdep->ppc_vrsave_regnum) 00492 return offsets->vrsave_offset; 00493 00494 return -1; 00495 } 00496 00497 /* Supply register REGNUM in the general-purpose register set REGSET 00498 from the buffer specified by GREGS and LEN to register cache 00499 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00500 00501 void 00502 ppc_supply_gregset (const struct regset *regset, struct regcache *regcache, 00503 int regnum, const void *gregs, size_t len) 00504 { 00505 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00506 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00507 const struct ppc_reg_offsets *offsets = regset->descr; 00508 size_t offset; 00509 int regsize; 00510 00511 if (regnum == -1) 00512 { 00513 int i; 00514 int gpr_size = offsets->gpr_size; 00515 00516 for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset; 00517 i < tdep->ppc_gp0_regnum + ppc_num_gprs; 00518 i++, offset += gpr_size) 00519 ppc_supply_reg (regcache, i, gregs, offset, gpr_size); 00520 00521 ppc_supply_reg (regcache, gdbarch_pc_regnum (gdbarch), 00522 gregs, offsets->pc_offset, gpr_size); 00523 ppc_supply_reg (regcache, tdep->ppc_ps_regnum, 00524 gregs, offsets->ps_offset, gpr_size); 00525 ppc_supply_reg (regcache, tdep->ppc_lr_regnum, 00526 gregs, offsets->lr_offset, gpr_size); 00527 ppc_supply_reg (regcache, tdep->ppc_ctr_regnum, 00528 gregs, offsets->ctr_offset, gpr_size); 00529 ppc_supply_reg (regcache, tdep->ppc_cr_regnum, 00530 gregs, offsets->cr_offset, offsets->xr_size); 00531 ppc_supply_reg (regcache, tdep->ppc_xer_regnum, 00532 gregs, offsets->xer_offset, offsets->xr_size); 00533 ppc_supply_reg (regcache, tdep->ppc_mq_regnum, 00534 gregs, offsets->mq_offset, offsets->xr_size); 00535 return; 00536 } 00537 00538 offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, ®size); 00539 ppc_supply_reg (regcache, regnum, gregs, offset, regsize); 00540 } 00541 00542 /* Supply register REGNUM in the floating-point register set REGSET 00543 from the buffer specified by FPREGS and LEN to register cache 00544 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00545 00546 void 00547 ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache, 00548 int regnum, const void *fpregs, size_t len) 00549 { 00550 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00551 struct gdbarch_tdep *tdep; 00552 const struct ppc_reg_offsets *offsets; 00553 size_t offset; 00554 00555 if (!ppc_floating_point_unit_p (gdbarch)) 00556 return; 00557 00558 tdep = gdbarch_tdep (gdbarch); 00559 offsets = regset->descr; 00560 if (regnum == -1) 00561 { 00562 int i; 00563 00564 for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset; 00565 i < tdep->ppc_fp0_regnum + ppc_num_fprs; 00566 i++, offset += 8) 00567 ppc_supply_reg (regcache, i, fpregs, offset, 8); 00568 00569 ppc_supply_reg (regcache, tdep->ppc_fpscr_regnum, 00570 fpregs, offsets->fpscr_offset, offsets->fpscr_size); 00571 return; 00572 } 00573 00574 offset = ppc_fpreg_offset (tdep, offsets, regnum); 00575 ppc_supply_reg (regcache, regnum, fpregs, offset, 00576 regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8); 00577 } 00578 00579 /* Supply register REGNUM in the VSX register set REGSET 00580 from the buffer specified by VSXREGS and LEN to register cache 00581 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00582 00583 void 00584 ppc_supply_vsxregset (const struct regset *regset, struct regcache *regcache, 00585 int regnum, const void *vsxregs, size_t len) 00586 { 00587 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00588 struct gdbarch_tdep *tdep; 00589 00590 if (!ppc_vsx_support_p (gdbarch)) 00591 return; 00592 00593 tdep = gdbarch_tdep (gdbarch); 00594 00595 if (regnum == -1) 00596 { 00597 int i; 00598 00599 for (i = tdep->ppc_vsr0_upper_regnum; 00600 i < tdep->ppc_vsr0_upper_regnum + 32; 00601 i++) 00602 ppc_supply_reg (regcache, i, vsxregs, 0, 8); 00603 00604 return; 00605 } 00606 else 00607 ppc_supply_reg (regcache, regnum, vsxregs, 0, 8); 00608 } 00609 00610 /* Supply register REGNUM in the Altivec register set REGSET 00611 from the buffer specified by VRREGS and LEN to register cache 00612 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00613 00614 void 00615 ppc_supply_vrregset (const struct regset *regset, struct regcache *regcache, 00616 int regnum, const void *vrregs, size_t len) 00617 { 00618 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00619 struct gdbarch_tdep *tdep; 00620 const struct ppc_reg_offsets *offsets; 00621 size_t offset; 00622 00623 if (!ppc_altivec_support_p (gdbarch)) 00624 return; 00625 00626 tdep = gdbarch_tdep (gdbarch); 00627 offsets = regset->descr; 00628 if (regnum == -1) 00629 { 00630 int i; 00631 00632 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset; 00633 i < tdep->ppc_vr0_regnum + ppc_num_vrs; 00634 i++, offset += 16) 00635 ppc_supply_reg (regcache, i, vrregs, offset, 16); 00636 00637 ppc_supply_reg (regcache, (tdep->ppc_vrsave_regnum - 1), 00638 vrregs, offsets->vscr_offset, 4); 00639 00640 ppc_supply_reg (regcache, tdep->ppc_vrsave_regnum, 00641 vrregs, offsets->vrsave_offset, 4); 00642 return; 00643 } 00644 00645 offset = ppc_vrreg_offset (tdep, offsets, regnum); 00646 if (regnum != tdep->ppc_vrsave_regnum 00647 && regnum != tdep->ppc_vrsave_regnum - 1) 00648 ppc_supply_reg (regcache, regnum, vrregs, offset, 16); 00649 else 00650 ppc_supply_reg (regcache, regnum, 00651 vrregs, offset, 4); 00652 } 00653 00654 /* Collect register REGNUM in the general-purpose register set 00655 REGSET from register cache REGCACHE into the buffer specified by 00656 GREGS and LEN. If REGNUM is -1, do this for all registers in 00657 REGSET. */ 00658 00659 void 00660 ppc_collect_gregset (const struct regset *regset, 00661 const struct regcache *regcache, 00662 int regnum, void *gregs, size_t len) 00663 { 00664 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00665 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00666 const struct ppc_reg_offsets *offsets = regset->descr; 00667 size_t offset; 00668 int regsize; 00669 00670 if (regnum == -1) 00671 { 00672 int i; 00673 int gpr_size = offsets->gpr_size; 00674 00675 for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset; 00676 i < tdep->ppc_gp0_regnum + ppc_num_gprs; 00677 i++, offset += gpr_size) 00678 ppc_collect_reg (regcache, i, gregs, offset, gpr_size); 00679 00680 ppc_collect_reg (regcache, gdbarch_pc_regnum (gdbarch), 00681 gregs, offsets->pc_offset, gpr_size); 00682 ppc_collect_reg (regcache, tdep->ppc_ps_regnum, 00683 gregs, offsets->ps_offset, gpr_size); 00684 ppc_collect_reg (regcache, tdep->ppc_lr_regnum, 00685 gregs, offsets->lr_offset, gpr_size); 00686 ppc_collect_reg (regcache, tdep->ppc_ctr_regnum, 00687 gregs, offsets->ctr_offset, gpr_size); 00688 ppc_collect_reg (regcache, tdep->ppc_cr_regnum, 00689 gregs, offsets->cr_offset, offsets->xr_size); 00690 ppc_collect_reg (regcache, tdep->ppc_xer_regnum, 00691 gregs, offsets->xer_offset, offsets->xr_size); 00692 ppc_collect_reg (regcache, tdep->ppc_mq_regnum, 00693 gregs, offsets->mq_offset, offsets->xr_size); 00694 return; 00695 } 00696 00697 offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, ®size); 00698 ppc_collect_reg (regcache, regnum, gregs, offset, regsize); 00699 } 00700 00701 /* Collect register REGNUM in the floating-point register set 00702 REGSET from register cache REGCACHE into the buffer specified by 00703 FPREGS and LEN. If REGNUM is -1, do this for all registers in 00704 REGSET. */ 00705 00706 void 00707 ppc_collect_fpregset (const struct regset *regset, 00708 const struct regcache *regcache, 00709 int regnum, void *fpregs, size_t len) 00710 { 00711 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00712 struct gdbarch_tdep *tdep; 00713 const struct ppc_reg_offsets *offsets; 00714 size_t offset; 00715 00716 if (!ppc_floating_point_unit_p (gdbarch)) 00717 return; 00718 00719 tdep = gdbarch_tdep (gdbarch); 00720 offsets = regset->descr; 00721 if (regnum == -1) 00722 { 00723 int i; 00724 00725 for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset; 00726 i < tdep->ppc_fp0_regnum + ppc_num_fprs; 00727 i++, offset += 8) 00728 ppc_collect_reg (regcache, i, fpregs, offset, 8); 00729 00730 ppc_collect_reg (regcache, tdep->ppc_fpscr_regnum, 00731 fpregs, offsets->fpscr_offset, offsets->fpscr_size); 00732 return; 00733 } 00734 00735 offset = ppc_fpreg_offset (tdep, offsets, regnum); 00736 ppc_collect_reg (regcache, regnum, fpregs, offset, 00737 regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8); 00738 } 00739 00740 /* Collect register REGNUM in the VSX register set 00741 REGSET from register cache REGCACHE into the buffer specified by 00742 VSXREGS and LEN. If REGNUM is -1, do this for all registers in 00743 REGSET. */ 00744 00745 void 00746 ppc_collect_vsxregset (const struct regset *regset, 00747 const struct regcache *regcache, 00748 int regnum, void *vsxregs, size_t len) 00749 { 00750 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00751 struct gdbarch_tdep *tdep; 00752 00753 if (!ppc_vsx_support_p (gdbarch)) 00754 return; 00755 00756 tdep = gdbarch_tdep (gdbarch); 00757 00758 if (regnum == -1) 00759 { 00760 int i; 00761 00762 for (i = tdep->ppc_vsr0_upper_regnum; 00763 i < tdep->ppc_vsr0_upper_regnum + 32; 00764 i++) 00765 ppc_collect_reg (regcache, i, vsxregs, 0, 8); 00766 00767 return; 00768 } 00769 else 00770 ppc_collect_reg (regcache, regnum, vsxregs, 0, 8); 00771 } 00772 00773 00774 /* Collect register REGNUM in the Altivec register set 00775 REGSET from register cache REGCACHE into the buffer specified by 00776 VRREGS and LEN. If REGNUM is -1, do this for all registers in 00777 REGSET. */ 00778 00779 void 00780 ppc_collect_vrregset (const struct regset *regset, 00781 const struct regcache *regcache, 00782 int regnum, void *vrregs, size_t len) 00783 { 00784 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00785 struct gdbarch_tdep *tdep; 00786 const struct ppc_reg_offsets *offsets; 00787 size_t offset; 00788 00789 if (!ppc_altivec_support_p (gdbarch)) 00790 return; 00791 00792 tdep = gdbarch_tdep (gdbarch); 00793 offsets = regset->descr; 00794 if (regnum == -1) 00795 { 00796 int i; 00797 00798 for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset; 00799 i < tdep->ppc_vr0_regnum + ppc_num_vrs; 00800 i++, offset += 16) 00801 ppc_collect_reg (regcache, i, vrregs, offset, 16); 00802 00803 ppc_collect_reg (regcache, (tdep->ppc_vrsave_regnum - 1), 00804 vrregs, offsets->vscr_offset, 4); 00805 00806 ppc_collect_reg (regcache, tdep->ppc_vrsave_regnum, 00807 vrregs, offsets->vrsave_offset, 4); 00808 return; 00809 } 00810 00811 offset = ppc_vrreg_offset (tdep, offsets, regnum); 00812 if (regnum != tdep->ppc_vrsave_regnum 00813 && regnum != tdep->ppc_vrsave_regnum - 1) 00814 ppc_collect_reg (regcache, regnum, vrregs, offset, 16); 00815 else 00816 ppc_collect_reg (regcache, regnum, 00817 vrregs, offset, 4); 00818 } 00819 00820 00821 static int 00822 insn_changes_sp_or_jumps (unsigned long insn) 00823 { 00824 int opcode = (insn >> 26) & 0x03f; 00825 int sd = (insn >> 21) & 0x01f; 00826 int a = (insn >> 16) & 0x01f; 00827 int subcode = (insn >> 1) & 0x3ff; 00828 00829 /* Changes the stack pointer. */ 00830 00831 /* NOTE: There are many ways to change the value of a given register. 00832 The ways below are those used when the register is R1, the SP, 00833 in a funtion's epilogue. */ 00834 00835 if (opcode == 31 && subcode == 444 && a == 1) 00836 return 1; /* mr R1,Rn */ 00837 if (opcode == 14 && sd == 1) 00838 return 1; /* addi R1,Rn,simm */ 00839 if (opcode == 58 && sd == 1) 00840 return 1; /* ld R1,ds(Rn) */ 00841 00842 /* Transfers control. */ 00843 00844 if (opcode == 18) 00845 return 1; /* b */ 00846 if (opcode == 16) 00847 return 1; /* bc */ 00848 if (opcode == 19 && subcode == 16) 00849 return 1; /* bclr */ 00850 if (opcode == 19 && subcode == 528) 00851 return 1; /* bcctr */ 00852 00853 return 0; 00854 } 00855 00856 /* Return true if we are in the function's epilogue, i.e. after the 00857 instruction that destroyed the function's stack frame. 00858 00859 1) scan forward from the point of execution: 00860 a) If you find an instruction that modifies the stack pointer 00861 or transfers control (except a return), execution is not in 00862 an epilogue, return. 00863 b) Stop scanning if you find a return instruction or reach the 00864 end of the function or reach the hard limit for the size of 00865 an epilogue. 00866 2) scan backward from the point of execution: 00867 a) If you find an instruction that modifies the stack pointer, 00868 execution *is* in an epilogue, return. 00869 b) Stop scanning if you reach an instruction that transfers 00870 control or the beginning of the function or reach the hard 00871 limit for the size of an epilogue. */ 00872 00873 static int 00874 rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) 00875 { 00876 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00877 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00878 bfd_byte insn_buf[PPC_INSN_SIZE]; 00879 CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end; 00880 unsigned long insn; 00881 struct frame_info *curfrm; 00882 00883 /* Find the search limits based on function boundaries and hard limit. */ 00884 00885 if (!find_pc_partial_function (pc, NULL, &func_start, &func_end)) 00886 return 0; 00887 00888 epilogue_start = pc - PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE; 00889 if (epilogue_start < func_start) epilogue_start = func_start; 00890 00891 epilogue_end = pc + PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE; 00892 if (epilogue_end > func_end) epilogue_end = func_end; 00893 00894 curfrm = get_current_frame (); 00895 00896 /* Scan forward until next 'blr'. */ 00897 00898 for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += PPC_INSN_SIZE) 00899 { 00900 if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE)) 00901 return 0; 00902 insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order); 00903 if (insn == 0x4e800020) 00904 break; 00905 /* Assume a bctr is a tail call unless it points strictly within 00906 this function. */ 00907 if (insn == 0x4e800420) 00908 { 00909 CORE_ADDR ctr = get_frame_register_unsigned (curfrm, 00910 tdep->ppc_ctr_regnum); 00911 if (ctr > func_start && ctr < func_end) 00912 return 0; 00913 else 00914 break; 00915 } 00916 if (insn_changes_sp_or_jumps (insn)) 00917 return 0; 00918 } 00919 00920 /* Scan backward until adjustment to stack pointer (R1). */ 00921 00922 for (scan_pc = pc - PPC_INSN_SIZE; 00923 scan_pc >= epilogue_start; 00924 scan_pc -= PPC_INSN_SIZE) 00925 { 00926 if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE)) 00927 return 0; 00928 insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order); 00929 if (insn_changes_sp_or_jumps (insn)) 00930 return 1; 00931 } 00932 00933 return 0; 00934 } 00935 00936 /* Get the ith function argument for the current function. */ 00937 static CORE_ADDR 00938 rs6000_fetch_pointer_argument (struct frame_info *frame, int argi, 00939 struct type *type) 00940 { 00941 return get_frame_register_unsigned (frame, 3 + argi); 00942 } 00943 00944 /* Sequence of bytes for breakpoint instruction. */ 00945 00946 static const unsigned char * 00947 rs6000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr, 00948 int *bp_size) 00949 { 00950 static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 }; 00951 static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d }; 00952 *bp_size = 4; 00953 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 00954 return big_breakpoint; 00955 else 00956 return little_breakpoint; 00957 } 00958 00959 /* Instruction masks for displaced stepping. */ 00960 #define BRANCH_MASK 0xfc000000 00961 #define BP_MASK 0xFC0007FE 00962 #define B_INSN 0x48000000 00963 #define BC_INSN 0x40000000 00964 #define BXL_INSN 0x4c000000 00965 #define BP_INSN 0x7C000008 00966 00967 /* Fix up the state of registers and memory after having single-stepped 00968 a displaced instruction. */ 00969 static void 00970 ppc_displaced_step_fixup (struct gdbarch *gdbarch, 00971 struct displaced_step_closure *closure, 00972 CORE_ADDR from, CORE_ADDR to, 00973 struct regcache *regs) 00974 { 00975 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00976 /* Since we use simple_displaced_step_copy_insn, our closure is a 00977 copy of the instruction. */ 00978 ULONGEST insn = extract_unsigned_integer ((gdb_byte *) closure, 00979 PPC_INSN_SIZE, byte_order); 00980 ULONGEST opcode = 0; 00981 /* Offset for non PC-relative instructions. */ 00982 LONGEST offset = PPC_INSN_SIZE; 00983 00984 opcode = insn & BRANCH_MASK; 00985 00986 if (debug_displaced) 00987 fprintf_unfiltered (gdb_stdlog, 00988 "displaced: (ppc) fixup (%s, %s)\n", 00989 paddress (gdbarch, from), paddress (gdbarch, to)); 00990 00991 00992 /* Handle PC-relative branch instructions. */ 00993 if (opcode == B_INSN || opcode == BC_INSN || opcode == BXL_INSN) 00994 { 00995 ULONGEST current_pc; 00996 00997 /* Read the current PC value after the instruction has been executed 00998 in a displaced location. Calculate the offset to be applied to the 00999 original PC value before the displaced stepping. */ 01000 regcache_cooked_read_unsigned (regs, gdbarch_pc_regnum (gdbarch), 01001 ¤t_pc); 01002 offset = current_pc - to; 01003 01004 if (opcode != BXL_INSN) 01005 { 01006 /* Check for AA bit indicating whether this is an absolute 01007 addressing or PC-relative (1: absolute, 0: relative). */ 01008 if (!(insn & 0x2)) 01009 { 01010 /* PC-relative addressing is being used in the branch. */ 01011 if (debug_displaced) 01012 fprintf_unfiltered 01013 (gdb_stdlog, 01014 "displaced: (ppc) branch instruction: %s\n" 01015 "displaced: (ppc) adjusted PC from %s to %s\n", 01016 paddress (gdbarch, insn), paddress (gdbarch, current_pc), 01017 paddress (gdbarch, from + offset)); 01018 01019 regcache_cooked_write_unsigned (regs, 01020 gdbarch_pc_regnum (gdbarch), 01021 from + offset); 01022 } 01023 } 01024 else 01025 { 01026 /* If we're here, it means we have a branch to LR or CTR. If the 01027 branch was taken, the offset is probably greater than 4 (the next 01028 instruction), so it's safe to assume that an offset of 4 means we 01029 did not take the branch. */ 01030 if (offset == PPC_INSN_SIZE) 01031 regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), 01032 from + PPC_INSN_SIZE); 01033 } 01034 01035 /* Check for LK bit indicating whether we should set the link 01036 register to point to the next instruction 01037 (1: Set, 0: Don't set). */ 01038 if (insn & 0x1) 01039 { 01040 /* Link register needs to be set to the next instruction's PC. */ 01041 regcache_cooked_write_unsigned (regs, 01042 gdbarch_tdep (gdbarch)->ppc_lr_regnum, 01043 from + PPC_INSN_SIZE); 01044 if (debug_displaced) 01045 fprintf_unfiltered (gdb_stdlog, 01046 "displaced: (ppc) adjusted LR to %s\n", 01047 paddress (gdbarch, from + PPC_INSN_SIZE)); 01048 01049 } 01050 } 01051 /* Check for breakpoints in the inferior. If we've found one, place the PC 01052 right at the breakpoint instruction. */ 01053 else if ((insn & BP_MASK) == BP_INSN) 01054 regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), from); 01055 else 01056 /* Handle any other instructions that do not fit in the categories above. */ 01057 regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), 01058 from + offset); 01059 } 01060 01061 /* Always use hardware single-stepping to execute the 01062 displaced instruction. */ 01063 static int 01064 ppc_displaced_step_hw_singlestep (struct gdbarch *gdbarch, 01065 struct displaced_step_closure *closure) 01066 { 01067 return 1; 01068 } 01069 01070 /* Instruction masks used during single-stepping of atomic sequences. */ 01071 #define LWARX_MASK 0xfc0007fe 01072 #define LWARX_INSTRUCTION 0x7c000028 01073 #define LDARX_INSTRUCTION 0x7c0000A8 01074 #define STWCX_MASK 0xfc0007ff 01075 #define STWCX_INSTRUCTION 0x7c00012d 01076 #define STDCX_INSTRUCTION 0x7c0001ad 01077 01078 /* Checks for an atomic sequence of instructions beginning with a LWARX/LDARX 01079 instruction and ending with a STWCX/STDCX instruction. If such a sequence 01080 is found, attempt to step through it. A breakpoint is placed at the end of 01081 the sequence. */ 01082 01083 int 01084 ppc_deal_with_atomic_sequence (struct frame_info *frame) 01085 { 01086 struct gdbarch *gdbarch = get_frame_arch (frame); 01087 struct address_space *aspace = get_frame_address_space (frame); 01088 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01089 CORE_ADDR pc = get_frame_pc (frame); 01090 CORE_ADDR breaks[2] = {-1, -1}; 01091 CORE_ADDR loc = pc; 01092 CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence. */ 01093 int insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order); 01094 int insn_count; 01095 int index; 01096 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ 01097 const int atomic_sequence_length = 16; /* Instruction sequence length. */ 01098 int opcode; /* Branch instruction's OPcode. */ 01099 int bc_insn_count = 0; /* Conditional branch instruction count. */ 01100 01101 /* Assume all atomic sequences start with a lwarx/ldarx instruction. */ 01102 if ((insn & LWARX_MASK) != LWARX_INSTRUCTION 01103 && (insn & LWARX_MASK) != LDARX_INSTRUCTION) 01104 return 0; 01105 01106 /* Assume that no atomic sequence is longer than "atomic_sequence_length" 01107 instructions. */ 01108 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count) 01109 { 01110 loc += PPC_INSN_SIZE; 01111 insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order); 01112 01113 /* Assume that there is at most one conditional branch in the atomic 01114 sequence. If a conditional branch is found, put a breakpoint in 01115 its destination address. */ 01116 if ((insn & BRANCH_MASK) == BC_INSN) 01117 { 01118 int immediate = ((insn & 0xfffc) ^ 0x8000) - 0x8000; 01119 int absolute = insn & 2; 01120 01121 if (bc_insn_count >= 1) 01122 return 0; /* More than one conditional branch found, fallback 01123 to the standard single-step code. */ 01124 01125 if (absolute) 01126 breaks[1] = immediate; 01127 else 01128 breaks[1] = loc + immediate; 01129 01130 bc_insn_count++; 01131 last_breakpoint++; 01132 } 01133 01134 if ((insn & STWCX_MASK) == STWCX_INSTRUCTION 01135 || (insn & STWCX_MASK) == STDCX_INSTRUCTION) 01136 break; 01137 } 01138 01139 /* Assume that the atomic sequence ends with a stwcx/stdcx instruction. */ 01140 if ((insn & STWCX_MASK) != STWCX_INSTRUCTION 01141 && (insn & STWCX_MASK) != STDCX_INSTRUCTION) 01142 return 0; 01143 01144 closing_insn = loc; 01145 loc += PPC_INSN_SIZE; 01146 insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order); 01147 01148 /* Insert a breakpoint right after the end of the atomic sequence. */ 01149 breaks[0] = loc; 01150 01151 /* Check for duplicated breakpoints. Check also for a breakpoint 01152 placed (branch instruction's destination) anywhere in sequence. */ 01153 if (last_breakpoint 01154 && (breaks[1] == breaks[0] 01155 || (breaks[1] >= pc && breaks[1] <= closing_insn))) 01156 last_breakpoint = 0; 01157 01158 /* Effectively inserts the breakpoints. */ 01159 for (index = 0; index <= last_breakpoint; index++) 01160 insert_single_step_breakpoint (gdbarch, aspace, breaks[index]); 01161 01162 return 1; 01163 } 01164 01165 01166 #define SIGNED_SHORT(x) \ 01167 ((sizeof (short) == 2) \ 01168 ? ((int)(short)(x)) \ 01169 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000))) 01170 01171 #define GET_SRC_REG(x) (((x) >> 21) & 0x1f) 01172 01173 /* Limit the number of skipped non-prologue instructions, as the examining 01174 of the prologue is expensive. */ 01175 static int max_skip_non_prologue_insns = 10; 01176 01177 /* Return nonzero if the given instruction OP can be part of the prologue 01178 of a function and saves a parameter on the stack. FRAMEP should be 01179 set if one of the previous instructions in the function has set the 01180 Frame Pointer. */ 01181 01182 static int 01183 store_param_on_stack_p (unsigned long op, int framep, int *r0_contains_arg) 01184 { 01185 /* Move parameters from argument registers to temporary register. */ 01186 if ((op & 0xfc0007fe) == 0x7c000378) /* mr(.) Rx,Ry */ 01187 { 01188 /* Rx must be scratch register r0. */ 01189 const int rx_regno = (op >> 16) & 31; 01190 /* Ry: Only r3 - r10 are used for parameter passing. */ 01191 const int ry_regno = GET_SRC_REG (op); 01192 01193 if (rx_regno == 0 && ry_regno >= 3 && ry_regno <= 10) 01194 { 01195 *r0_contains_arg = 1; 01196 return 1; 01197 } 01198 else 01199 return 0; 01200 } 01201 01202 /* Save a General Purpose Register on stack. */ 01203 01204 if ((op & 0xfc1f0003) == 0xf8010000 || /* std Rx,NUM(r1) */ 01205 (op & 0xfc1f0000) == 0xd8010000) /* stfd Rx,NUM(r1) */ 01206 { 01207 /* Rx: Only r3 - r10 are used for parameter passing. */ 01208 const int rx_regno = GET_SRC_REG (op); 01209 01210 return (rx_regno >= 3 && rx_regno <= 10); 01211 } 01212 01213 /* Save a General Purpose Register on stack via the Frame Pointer. */ 01214 01215 if (framep && 01216 ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r31) */ 01217 (op & 0xfc1f0000) == 0x981f0000 || /* stb Rx,NUM(r31) */ 01218 (op & 0xfc1f0000) == 0xd81f0000)) /* stfd Rx,NUM(r31) */ 01219 { 01220 /* Rx: Usually, only r3 - r10 are used for parameter passing. 01221 However, the compiler sometimes uses r0 to hold an argument. */ 01222 const int rx_regno = GET_SRC_REG (op); 01223 01224 return ((rx_regno >= 3 && rx_regno <= 10) 01225 || (rx_regno == 0 && *r0_contains_arg)); 01226 } 01227 01228 if ((op & 0xfc1f0000) == 0xfc010000) /* frsp, fp?,NUM(r1) */ 01229 { 01230 /* Only f2 - f8 are used for parameter passing. */ 01231 const int src_regno = GET_SRC_REG (op); 01232 01233 return (src_regno >= 2 && src_regno <= 8); 01234 } 01235 01236 if (framep && ((op & 0xfc1f0000) == 0xfc1f0000)) /* frsp, fp?,NUM(r31) */ 01237 { 01238 /* Only f2 - f8 are used for parameter passing. */ 01239 const int src_regno = GET_SRC_REG (op); 01240 01241 return (src_regno >= 2 && src_regno <= 8); 01242 } 01243 01244 /* Not an insn that saves a parameter on stack. */ 01245 return 0; 01246 } 01247 01248 /* Assuming that INSN is a "bl" instruction located at PC, return 01249 nonzero if the destination of the branch is a "blrl" instruction. 01250 01251 This sequence is sometimes found in certain function prologues. 01252 It allows the function to load the LR register with a value that 01253 they can use to access PIC data using PC-relative offsets. */ 01254 01255 static int 01256 bl_to_blrl_insn_p (CORE_ADDR pc, int insn, enum bfd_endian byte_order) 01257 { 01258 CORE_ADDR dest; 01259 int immediate; 01260 int absolute; 01261 int dest_insn; 01262 01263 absolute = (int) ((insn >> 1) & 1); 01264 immediate = ((insn & ~3) << 6) >> 6; 01265 if (absolute) 01266 dest = immediate; 01267 else 01268 dest = pc + immediate; 01269 01270 dest_insn = read_memory_integer (dest, 4, byte_order); 01271 if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */ 01272 return 1; 01273 01274 return 0; 01275 } 01276 01277 /* Masks for decoding a branch-and-link (bl) instruction. 01278 01279 BL_MASK and BL_INSTRUCTION are used in combination with each other. 01280 The former is anded with the opcode in question; if the result of 01281 this masking operation is equal to BL_INSTRUCTION, then the opcode in 01282 question is a ``bl'' instruction. 01283 01284 BL_DISPLACMENT_MASK is anded with the opcode in order to extract 01285 the branch displacement. */ 01286 01287 #define BL_MASK 0xfc000001 01288 #define BL_INSTRUCTION 0x48000001 01289 #define BL_DISPLACEMENT_MASK 0x03fffffc 01290 01291 static unsigned long 01292 rs6000_fetch_instruction (struct gdbarch *gdbarch, const CORE_ADDR pc) 01293 { 01294 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01295 gdb_byte buf[4]; 01296 unsigned long op; 01297 01298 /* Fetch the instruction and convert it to an integer. */ 01299 if (target_read_memory (pc, buf, 4)) 01300 return 0; 01301 op = extract_unsigned_integer (buf, 4, byte_order); 01302 01303 return op; 01304 } 01305 01306 /* GCC generates several well-known sequences of instructions at the begining 01307 of each function prologue when compiling with -fstack-check. If one of 01308 such sequences starts at START_PC, then return the address of the 01309 instruction immediately past this sequence. Otherwise, return START_PC. */ 01310 01311 static CORE_ADDR 01312 rs6000_skip_stack_check (struct gdbarch *gdbarch, const CORE_ADDR start_pc) 01313 { 01314 CORE_ADDR pc = start_pc; 01315 unsigned long op = rs6000_fetch_instruction (gdbarch, pc); 01316 01317 /* First possible sequence: A small number of probes. 01318 stw 0, -<some immediate>(1) 01319 [repeat this instruction any (small) number of times]. */ 01320 01321 if ((op & 0xffff0000) == 0x90010000) 01322 { 01323 while ((op & 0xffff0000) == 0x90010000) 01324 { 01325 pc = pc + 4; 01326 op = rs6000_fetch_instruction (gdbarch, pc); 01327 } 01328 return pc; 01329 } 01330 01331 /* Second sequence: A probing loop. 01332 addi 12,1,-<some immediate> 01333 lis 0,-<some immediate> 01334 [possibly ori 0,0,<some immediate>] 01335 add 0,12,0 01336 cmpw 0,12,0 01337 beq 0,<disp> 01338 addi 12,12,-<some immediate> 01339 stw 0,0(12) 01340 b <disp> 01341 [possibly one last probe: stw 0,<some immediate>(12)]. */ 01342 01343 while (1) 01344 { 01345 /* addi 12,1,-<some immediate> */ 01346 if ((op & 0xffff0000) != 0x39810000) 01347 break; 01348 01349 /* lis 0,-<some immediate> */ 01350 pc = pc + 4; 01351 op = rs6000_fetch_instruction (gdbarch, pc); 01352 if ((op & 0xffff0000) != 0x3c000000) 01353 break; 01354 01355 pc = pc + 4; 01356 op = rs6000_fetch_instruction (gdbarch, pc); 01357 /* [possibly ori 0,0,<some immediate>] */ 01358 if ((op & 0xffff0000) == 0x60000000) 01359 { 01360 pc = pc + 4; 01361 op = rs6000_fetch_instruction (gdbarch, pc); 01362 } 01363 /* add 0,12,0 */ 01364 if (op != 0x7c0c0214) 01365 break; 01366 01367 /* cmpw 0,12,0 */ 01368 pc = pc + 4; 01369 op = rs6000_fetch_instruction (gdbarch, pc); 01370 if (op != 0x7c0c0000) 01371 break; 01372 01373 /* beq 0,<disp> */ 01374 pc = pc + 4; 01375 op = rs6000_fetch_instruction (gdbarch, pc); 01376 if ((op & 0xff9f0001) != 0x41820000) 01377 break; 01378 01379 /* addi 12,12,-<some immediate> */ 01380 pc = pc + 4; 01381 op = rs6000_fetch_instruction (gdbarch, pc); 01382 if ((op & 0xffff0000) != 0x398c0000) 01383 break; 01384 01385 /* stw 0,0(12) */ 01386 pc = pc + 4; 01387 op = rs6000_fetch_instruction (gdbarch, pc); 01388 if (op != 0x900c0000) 01389 break; 01390 01391 /* b <disp> */ 01392 pc = pc + 4; 01393 op = rs6000_fetch_instruction (gdbarch, pc); 01394 if ((op & 0xfc000001) != 0x48000000) 01395 break; 01396 01397 /* [possibly one last probe: stw 0,<some immediate>(12)]. */ 01398 pc = pc + 4; 01399 op = rs6000_fetch_instruction (gdbarch, pc); 01400 if ((op & 0xffff0000) == 0x900c0000) 01401 { 01402 pc = pc + 4; 01403 op = rs6000_fetch_instruction (gdbarch, pc); 01404 } 01405 01406 /* We found a valid stack-check sequence, return the new PC. */ 01407 return pc; 01408 } 01409 01410 /* Third sequence: No probe; instead, a comparizon between the stack size 01411 limit (saved in a run-time global variable) and the current stack 01412 pointer: 01413 01414 addi 0,1,-<some immediate> 01415 lis 12,__gnat_stack_limit@ha 01416 lwz 12,__gnat_stack_limit@l(12) 01417 twllt 0,12 01418 01419 or, with a small variant in the case of a bigger stack frame: 01420 addis 0,1,<some immediate> 01421 addic 0,0,-<some immediate> 01422 lis 12,__gnat_stack_limit@ha 01423 lwz 12,__gnat_stack_limit@l(12) 01424 twllt 0,12 01425 */ 01426 while (1) 01427 { 01428 /* addi 0,1,-<some immediate> */ 01429 if ((op & 0xffff0000) != 0x38010000) 01430 { 01431 /* small stack frame variant not recognized; try the 01432 big stack frame variant: */ 01433 01434 /* addis 0,1,<some immediate> */ 01435 if ((op & 0xffff0000) != 0x3c010000) 01436 break; 01437 01438 /* addic 0,0,-<some immediate> */ 01439 pc = pc + 4; 01440 op = rs6000_fetch_instruction (gdbarch, pc); 01441 if ((op & 0xffff0000) != 0x30000000) 01442 break; 01443 } 01444 01445 /* lis 12,<some immediate> */ 01446 pc = pc + 4; 01447 op = rs6000_fetch_instruction (gdbarch, pc); 01448 if ((op & 0xffff0000) != 0x3d800000) 01449 break; 01450 01451 /* lwz 12,<some immediate>(12) */ 01452 pc = pc + 4; 01453 op = rs6000_fetch_instruction (gdbarch, pc); 01454 if ((op & 0xffff0000) != 0x818c0000) 01455 break; 01456 01457 /* twllt 0,12 */ 01458 pc = pc + 4; 01459 op = rs6000_fetch_instruction (gdbarch, pc); 01460 if ((op & 0xfffffffe) != 0x7c406008) 01461 break; 01462 01463 /* We found a valid stack-check sequence, return the new PC. */ 01464 return pc; 01465 } 01466 01467 /* No stack check code in our prologue, return the start_pc. */ 01468 return start_pc; 01469 } 01470 01471 /* return pc value after skipping a function prologue and also return 01472 information about a function frame. 01473 01474 in struct rs6000_framedata fdata: 01475 - frameless is TRUE, if function does not have a frame. 01476 - nosavedpc is TRUE, if function does not save %pc value in its frame. 01477 - offset is the initial size of this stack frame --- the amount by 01478 which we decrement the sp to allocate the frame. 01479 - saved_gpr is the number of the first saved gpr. 01480 - saved_fpr is the number of the first saved fpr. 01481 - saved_vr is the number of the first saved vr. 01482 - saved_ev is the number of the first saved ev. 01483 - alloca_reg is the number of the register used for alloca() handling. 01484 Otherwise -1. 01485 - gpr_offset is the offset of the first saved gpr from the previous frame. 01486 - fpr_offset is the offset of the first saved fpr from the previous frame. 01487 - vr_offset is the offset of the first saved vr from the previous frame. 01488 - ev_offset is the offset of the first saved ev from the previous frame. 01489 - lr_offset is the offset of the saved lr 01490 - cr_offset is the offset of the saved cr 01491 - vrsave_offset is the offset of the saved vrsave register. */ 01492 01493 static CORE_ADDR 01494 skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc, 01495 struct rs6000_framedata *fdata) 01496 { 01497 CORE_ADDR orig_pc = pc; 01498 CORE_ADDR last_prologue_pc = pc; 01499 CORE_ADDR li_found_pc = 0; 01500 gdb_byte buf[4]; 01501 unsigned long op; 01502 long offset = 0; 01503 long vr_saved_offset = 0; 01504 int lr_reg = -1; 01505 int cr_reg = -1; 01506 int vr_reg = -1; 01507 int ev_reg = -1; 01508 long ev_offset = 0; 01509 int vrsave_reg = -1; 01510 int reg; 01511 int framep = 0; 01512 int minimal_toc_loaded = 0; 01513 int prev_insn_was_prologue_insn = 1; 01514 int num_skip_non_prologue_insns = 0; 01515 int r0_contains_arg = 0; 01516 const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch); 01517 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01518 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01519 01520 memset (fdata, 0, sizeof (struct rs6000_framedata)); 01521 fdata->saved_gpr = -1; 01522 fdata->saved_fpr = -1; 01523 fdata->saved_vr = -1; 01524 fdata->saved_ev = -1; 01525 fdata->alloca_reg = -1; 01526 fdata->frameless = 1; 01527 fdata->nosavedpc = 1; 01528 fdata->lr_register = -1; 01529 01530 pc = rs6000_skip_stack_check (gdbarch, pc); 01531 if (pc >= lim_pc) 01532 pc = lim_pc; 01533 01534 for (;; pc += 4) 01535 { 01536 /* Sometimes it isn't clear if an instruction is a prologue 01537 instruction or not. When we encounter one of these ambiguous 01538 cases, we'll set prev_insn_was_prologue_insn to 0 (false). 01539 Otherwise, we'll assume that it really is a prologue instruction. */ 01540 if (prev_insn_was_prologue_insn) 01541 last_prologue_pc = pc; 01542 01543 /* Stop scanning if we've hit the limit. */ 01544 if (pc >= lim_pc) 01545 break; 01546 01547 prev_insn_was_prologue_insn = 1; 01548 01549 /* Fetch the instruction and convert it to an integer. */ 01550 if (target_read_memory (pc, buf, 4)) 01551 break; 01552 op = extract_unsigned_integer (buf, 4, byte_order); 01553 01554 if ((op & 0xfc1fffff) == 0x7c0802a6) 01555 { /* mflr Rx */ 01556 /* Since shared library / PIC code, which needs to get its 01557 address at runtime, can appear to save more than one link 01558 register vis: 01559 01560 *INDENT-OFF* 01561 stwu r1,-304(r1) 01562 mflr r3 01563 bl 0xff570d0 (blrl) 01564 stw r30,296(r1) 01565 mflr r30 01566 stw r31,300(r1) 01567 stw r3,308(r1); 01568 ... 01569 *INDENT-ON* 01570 01571 remember just the first one, but skip over additional 01572 ones. */ 01573 if (lr_reg == -1) 01574 lr_reg = (op & 0x03e00000) >> 21; 01575 if (lr_reg == 0) 01576 r0_contains_arg = 0; 01577 continue; 01578 } 01579 else if ((op & 0xfc1fffff) == 0x7c000026) 01580 { /* mfcr Rx */ 01581 cr_reg = (op & 0x03e00000); 01582 if (cr_reg == 0) 01583 r0_contains_arg = 0; 01584 continue; 01585 01586 } 01587 else if ((op & 0xfc1f0000) == 0xd8010000) 01588 { /* stfd Rx,NUM(r1) */ 01589 reg = GET_SRC_REG (op); 01590 if (fdata->saved_fpr == -1 || fdata->saved_fpr > reg) 01591 { 01592 fdata->saved_fpr = reg; 01593 fdata->fpr_offset = SIGNED_SHORT (op) + offset; 01594 } 01595 continue; 01596 01597 } 01598 else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */ 01599 (((op & 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */ 01600 (op & 0xfc1f0003) == 0xf8010000) && /* std rx,NUM(r1) */ 01601 (op & 0x03e00000) >= 0x01a00000)) /* rx >= r13 */ 01602 { 01603 01604 reg = GET_SRC_REG (op); 01605 if ((op & 0xfc1f0000) == 0xbc010000) 01606 fdata->gpr_mask |= ~((1U << reg) - 1); 01607 else 01608 fdata->gpr_mask |= 1U << reg; 01609 if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg) 01610 { 01611 fdata->saved_gpr = reg; 01612 if ((op & 0xfc1f0003) == 0xf8010000) 01613 op &= ~3UL; 01614 fdata->gpr_offset = SIGNED_SHORT (op) + offset; 01615 } 01616 continue; 01617 01618 } 01619 else if ((op & 0xffff0000) == 0x60000000) 01620 { 01621 /* nop */ 01622 /* Allow nops in the prologue, but do not consider them to 01623 be part of the prologue unless followed by other prologue 01624 instructions. */ 01625 prev_insn_was_prologue_insn = 0; 01626 continue; 01627 01628 } 01629 else if ((op & 0xffff0000) == 0x3c000000) 01630 { /* addis 0,0,NUM, used 01631 for >= 32k frames */ 01632 fdata->offset = (op & 0x0000ffff) << 16; 01633 fdata->frameless = 0; 01634 r0_contains_arg = 0; 01635 continue; 01636 01637 } 01638 else if ((op & 0xffff0000) == 0x60000000) 01639 { /* ori 0,0,NUM, 2nd ha 01640 lf of >= 32k frames */ 01641 fdata->offset |= (op & 0x0000ffff); 01642 fdata->frameless = 0; 01643 r0_contains_arg = 0; 01644 continue; 01645 01646 } 01647 else if (lr_reg >= 0 && 01648 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */ 01649 (((op & 0xffff0000) == (lr_reg | 0xf8010000)) || 01650 /* stw Rx, NUM(r1) */ 01651 ((op & 0xffff0000) == (lr_reg | 0x90010000)) || 01652 /* stwu Rx, NUM(r1) */ 01653 ((op & 0xffff0000) == (lr_reg | 0x94010000)))) 01654 { /* where Rx == lr */ 01655 fdata->lr_offset = offset; 01656 fdata->nosavedpc = 0; 01657 /* Invalidate lr_reg, but don't set it to -1. 01658 That would mean that it had never been set. */ 01659 lr_reg = -2; 01660 if ((op & 0xfc000003) == 0xf8000000 || /* std */ 01661 (op & 0xfc000000) == 0x90000000) /* stw */ 01662 { 01663 /* Does not update r1, so add displacement to lr_offset. */ 01664 fdata->lr_offset += SIGNED_SHORT (op); 01665 } 01666 continue; 01667 01668 } 01669 else if (cr_reg >= 0 && 01670 /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */ 01671 (((op & 0xffff0000) == (cr_reg | 0xf8010000)) || 01672 /* stw Rx, NUM(r1) */ 01673 ((op & 0xffff0000) == (cr_reg | 0x90010000)) || 01674 /* stwu Rx, NUM(r1) */ 01675 ((op & 0xffff0000) == (cr_reg | 0x94010000)))) 01676 { /* where Rx == cr */ 01677 fdata->cr_offset = offset; 01678 /* Invalidate cr_reg, but don't set it to -1. 01679 That would mean that it had never been set. */ 01680 cr_reg = -2; 01681 if ((op & 0xfc000003) == 0xf8000000 || 01682 (op & 0xfc000000) == 0x90000000) 01683 { 01684 /* Does not update r1, so add displacement to cr_offset. */ 01685 fdata->cr_offset += SIGNED_SHORT (op); 01686 } 01687 continue; 01688 01689 } 01690 else if ((op & 0xfe80ffff) == 0x42800005 && lr_reg != -1) 01691 { 01692 /* bcl 20,xx,.+4 is used to get the current PC, with or without 01693 prediction bits. If the LR has already been saved, we can 01694 skip it. */ 01695 continue; 01696 } 01697 else if (op == 0x48000005) 01698 { /* bl .+4 used in 01699 -mrelocatable */ 01700 fdata->used_bl = 1; 01701 continue; 01702 01703 } 01704 else if (op == 0x48000004) 01705 { /* b .+4 (xlc) */ 01706 break; 01707 01708 } 01709 else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used 01710 in V.4 -mminimal-toc */ 01711 (op & 0xffff0000) == 0x3bde0000) 01712 { /* addi 30,30,foo@l */ 01713 continue; 01714 01715 } 01716 else if ((op & 0xfc000001) == 0x48000001) 01717 { /* bl foo, 01718 to save fprs??? */ 01719 01720 fdata->frameless = 0; 01721 01722 /* If the return address has already been saved, we can skip 01723 calls to blrl (for PIC). */ 01724 if (lr_reg != -1 && bl_to_blrl_insn_p (pc, op, byte_order)) 01725 { 01726 fdata->used_bl = 1; 01727 continue; 01728 } 01729 01730 /* Don't skip over the subroutine call if it is not within 01731 the first three instructions of the prologue and either 01732 we have no line table information or the line info tells 01733 us that the subroutine call is not part of the line 01734 associated with the prologue. */ 01735 if ((pc - orig_pc) > 8) 01736 { 01737 struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0); 01738 struct symtab_and_line this_sal = find_pc_line (pc, 0); 01739 01740 if ((prologue_sal.line == 0) 01741 || (prologue_sal.line != this_sal.line)) 01742 break; 01743 } 01744 01745 op = read_memory_integer (pc + 4, 4, byte_order); 01746 01747 /* At this point, make sure this is not a trampoline 01748 function (a function that simply calls another functions, 01749 and nothing else). If the next is not a nop, this branch 01750 was part of the function prologue. */ 01751 01752 if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */ 01753 break; /* Don't skip over 01754 this branch. */ 01755 01756 fdata->used_bl = 1; 01757 continue; 01758 } 01759 /* update stack pointer */ 01760 else if ((op & 0xfc1f0000) == 0x94010000) 01761 { /* stu rX,NUM(r1) || stwu rX,NUM(r1) */ 01762 fdata->frameless = 0; 01763 fdata->offset = SIGNED_SHORT (op); 01764 offset = fdata->offset; 01765 continue; 01766 } 01767 else if ((op & 0xfc1f016a) == 0x7c01016e) 01768 { /* stwux rX,r1,rY */ 01769 /* No way to figure out what r1 is going to be. */ 01770 fdata->frameless = 0; 01771 offset = fdata->offset; 01772 continue; 01773 } 01774 else if ((op & 0xfc1f0003) == 0xf8010001) 01775 { /* stdu rX,NUM(r1) */ 01776 fdata->frameless = 0; 01777 fdata->offset = SIGNED_SHORT (op & ~3UL); 01778 offset = fdata->offset; 01779 continue; 01780 } 01781 else if ((op & 0xfc1f016a) == 0x7c01016a) 01782 { /* stdux rX,r1,rY */ 01783 /* No way to figure out what r1 is going to be. */ 01784 fdata->frameless = 0; 01785 offset = fdata->offset; 01786 continue; 01787 } 01788 else if ((op & 0xffff0000) == 0x38210000) 01789 { /* addi r1,r1,SIMM */ 01790 fdata->frameless = 0; 01791 fdata->offset += SIGNED_SHORT (op); 01792 offset = fdata->offset; 01793 continue; 01794 } 01795 /* Load up minimal toc pointer. Do not treat an epilogue restore 01796 of r31 as a minimal TOC load. */ 01797 else if (((op >> 22) == 0x20f || /* l r31,... or l r30,... */ 01798 (op >> 22) == 0x3af) /* ld r31,... or ld r30,... */ 01799 && !framep 01800 && !minimal_toc_loaded) 01801 { 01802 minimal_toc_loaded = 1; 01803 continue; 01804 01805 /* move parameters from argument registers to local variable 01806 registers */ 01807 } 01808 else if ((op & 0xfc0007fe) == 0x7c000378 && /* mr(.) Rx,Ry */ 01809 (((op >> 21) & 31) >= 3) && /* R3 >= Ry >= R10 */ 01810 (((op >> 21) & 31) <= 10) && 01811 ((long) ((op >> 16) & 31) 01812 >= fdata->saved_gpr)) /* Rx: local var reg */ 01813 { 01814 continue; 01815 01816 /* store parameters in stack */ 01817 } 01818 /* Move parameters from argument registers to temporary register. */ 01819 else if (store_param_on_stack_p (op, framep, &r0_contains_arg)) 01820 { 01821 continue; 01822 01823 /* Set up frame pointer */ 01824 } 01825 else if (op == 0x603d0000) /* oril r29, r1, 0x0 */ 01826 { 01827 fdata->frameless = 0; 01828 framep = 1; 01829 fdata->alloca_reg = (tdep->ppc_gp0_regnum + 29); 01830 continue; 01831 01832 /* Another way to set up the frame pointer. */ 01833 } 01834 else if (op == 0x603f0000 /* oril r31, r1, 0x0 */ 01835 || op == 0x7c3f0b78) 01836 { /* mr r31, r1 */ 01837 fdata->frameless = 0; 01838 framep = 1; 01839 fdata->alloca_reg = (tdep->ppc_gp0_regnum + 31); 01840 continue; 01841 01842 /* Another way to set up the frame pointer. */ 01843 } 01844 else if ((op & 0xfc1fffff) == 0x38010000) 01845 { /* addi rX, r1, 0x0 */ 01846 fdata->frameless = 0; 01847 framep = 1; 01848 fdata->alloca_reg = (tdep->ppc_gp0_regnum 01849 + ((op & ~0x38010000) >> 21)); 01850 continue; 01851 } 01852 /* AltiVec related instructions. */ 01853 /* Store the vrsave register (spr 256) in another register for 01854 later manipulation, or load a register into the vrsave 01855 register. 2 instructions are used: mfvrsave and 01856 mtvrsave. They are shorthand notation for mfspr Rn, SPR256 01857 and mtspr SPR256, Rn. */ 01858 /* mfspr Rn SPR256 == 011111 nnnnn 0000001000 01010100110 01859 mtspr SPR256 Rn == 011111 nnnnn 0000001000 01110100110 */ 01860 else if ((op & 0xfc1fffff) == 0x7c0042a6) /* mfvrsave Rn */ 01861 { 01862 vrsave_reg = GET_SRC_REG (op); 01863 continue; 01864 } 01865 else if ((op & 0xfc1fffff) == 0x7c0043a6) /* mtvrsave Rn */ 01866 { 01867 continue; 01868 } 01869 /* Store the register where vrsave was saved to onto the stack: 01870 rS is the register where vrsave was stored in a previous 01871 instruction. */ 01872 /* 100100 sssss 00001 dddddddd dddddddd */ 01873 else if ((op & 0xfc1f0000) == 0x90010000) /* stw rS, d(r1) */ 01874 { 01875 if (vrsave_reg == GET_SRC_REG (op)) 01876 { 01877 fdata->vrsave_offset = SIGNED_SHORT (op) + offset; 01878 vrsave_reg = -1; 01879 } 01880 continue; 01881 } 01882 /* Compute the new value of vrsave, by modifying the register 01883 where vrsave was saved to. */ 01884 else if (((op & 0xfc000000) == 0x64000000) /* oris Ra, Rs, UIMM */ 01885 || ((op & 0xfc000000) == 0x60000000))/* ori Ra, Rs, UIMM */ 01886 { 01887 continue; 01888 } 01889 /* li r0, SIMM (short for addi r0, 0, SIMM). This is the first 01890 in a pair of insns to save the vector registers on the 01891 stack. */ 01892 /* 001110 00000 00000 iiii iiii iiii iiii */ 01893 /* 001110 01110 00000 iiii iiii iiii iiii */ 01894 else if ((op & 0xffff0000) == 0x38000000 /* li r0, SIMM */ 01895 || (op & 0xffff0000) == 0x39c00000) /* li r14, SIMM */ 01896 { 01897 if ((op & 0xffff0000) == 0x38000000) 01898 r0_contains_arg = 0; 01899 li_found_pc = pc; 01900 vr_saved_offset = SIGNED_SHORT (op); 01901 01902 /* This insn by itself is not part of the prologue, unless 01903 if part of the pair of insns mentioned above. So do not 01904 record this insn as part of the prologue yet. */ 01905 prev_insn_was_prologue_insn = 0; 01906 } 01907 /* Store vector register S at (r31+r0) aligned to 16 bytes. */ 01908 /* 011111 sssss 11111 00000 00111001110 */ 01909 else if ((op & 0xfc1fffff) == 0x7c1f01ce) /* stvx Vs, R31, R0 */ 01910 { 01911 if (pc == (li_found_pc + 4)) 01912 { 01913 vr_reg = GET_SRC_REG (op); 01914 /* If this is the first vector reg to be saved, or if 01915 it has a lower number than others previously seen, 01916 reupdate the frame info. */ 01917 if (fdata->saved_vr == -1 || fdata->saved_vr > vr_reg) 01918 { 01919 fdata->saved_vr = vr_reg; 01920 fdata->vr_offset = vr_saved_offset + offset; 01921 } 01922 vr_saved_offset = -1; 01923 vr_reg = -1; 01924 li_found_pc = 0; 01925 } 01926 } 01927 /* End AltiVec related instructions. */ 01928 01929 /* Start BookE related instructions. */ 01930 /* Store gen register S at (r31+uimm). 01931 Any register less than r13 is volatile, so we don't care. */ 01932 /* 000100 sssss 11111 iiiii 01100100001 */ 01933 else if (arch_info->mach == bfd_mach_ppc_e500 01934 && (op & 0xfc1f07ff) == 0x101f0321) /* evstdd Rs,uimm(R31) */ 01935 { 01936 if ((op & 0x03e00000) >= 0x01a00000) /* Rs >= r13 */ 01937 { 01938 unsigned int imm; 01939 ev_reg = GET_SRC_REG (op); 01940 imm = (op >> 11) & 0x1f; 01941 ev_offset = imm * 8; 01942 /* If this is the first vector reg to be saved, or if 01943 it has a lower number than others previously seen, 01944 reupdate the frame info. */ 01945 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 01946 { 01947 fdata->saved_ev = ev_reg; 01948 fdata->ev_offset = ev_offset + offset; 01949 } 01950 } 01951 continue; 01952 } 01953 /* Store gen register rS at (r1+rB). */ 01954 /* 000100 sssss 00001 bbbbb 01100100000 */ 01955 else if (arch_info->mach == bfd_mach_ppc_e500 01956 && (op & 0xffe007ff) == 0x13e00320) /* evstddx RS,R1,Rb */ 01957 { 01958 if (pc == (li_found_pc + 4)) 01959 { 01960 ev_reg = GET_SRC_REG (op); 01961 /* If this is the first vector reg to be saved, or if 01962 it has a lower number than others previously seen, 01963 reupdate the frame info. */ 01964 /* We know the contents of rB from the previous instruction. */ 01965 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 01966 { 01967 fdata->saved_ev = ev_reg; 01968 fdata->ev_offset = vr_saved_offset + offset; 01969 } 01970 vr_saved_offset = -1; 01971 ev_reg = -1; 01972 li_found_pc = 0; 01973 } 01974 continue; 01975 } 01976 /* Store gen register r31 at (rA+uimm). */ 01977 /* 000100 11111 aaaaa iiiii 01100100001 */ 01978 else if (arch_info->mach == bfd_mach_ppc_e500 01979 && (op & 0xffe007ff) == 0x13e00321) /* evstdd R31,Ra,UIMM */ 01980 { 01981 /* Wwe know that the source register is 31 already, but 01982 it can't hurt to compute it. */ 01983 ev_reg = GET_SRC_REG (op); 01984 ev_offset = ((op >> 11) & 0x1f) * 8; 01985 /* If this is the first vector reg to be saved, or if 01986 it has a lower number than others previously seen, 01987 reupdate the frame info. */ 01988 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 01989 { 01990 fdata->saved_ev = ev_reg; 01991 fdata->ev_offset = ev_offset + offset; 01992 } 01993 01994 continue; 01995 } 01996 /* Store gen register S at (r31+r0). 01997 Store param on stack when offset from SP bigger than 4 bytes. */ 01998 /* 000100 sssss 11111 00000 01100100000 */ 01999 else if (arch_info->mach == bfd_mach_ppc_e500 02000 && (op & 0xfc1fffff) == 0x101f0320) /* evstddx Rs,R31,R0 */ 02001 { 02002 if (pc == (li_found_pc + 4)) 02003 { 02004 if ((op & 0x03e00000) >= 0x01a00000) 02005 { 02006 ev_reg = GET_SRC_REG (op); 02007 /* If this is the first vector reg to be saved, or if 02008 it has a lower number than others previously seen, 02009 reupdate the frame info. */ 02010 /* We know the contents of r0 from the previous 02011 instruction. */ 02012 if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg) 02013 { 02014 fdata->saved_ev = ev_reg; 02015 fdata->ev_offset = vr_saved_offset + offset; 02016 } 02017 ev_reg = -1; 02018 } 02019 vr_saved_offset = -1; 02020 li_found_pc = 0; 02021 continue; 02022 } 02023 } 02024 /* End BookE related instructions. */ 02025 02026 else 02027 { 02028 unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1); 02029 02030 /* Not a recognized prologue instruction. 02031 Handle optimizer code motions into the prologue by continuing 02032 the search if we have no valid frame yet or if the return 02033 address is not yet saved in the frame. Also skip instructions 02034 if some of the GPRs expected to be saved are not yet saved. */ 02035 if (fdata->frameless == 0 && fdata->nosavedpc == 0 02036 && (fdata->gpr_mask & all_mask) == all_mask) 02037 break; 02038 02039 if (op == 0x4e800020 /* blr */ 02040 || op == 0x4e800420) /* bctr */ 02041 /* Do not scan past epilogue in frameless functions or 02042 trampolines. */ 02043 break; 02044 if ((op & 0xf4000000) == 0x40000000) /* bxx */ 02045 /* Never skip branches. */ 02046 break; 02047 02048 if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns) 02049 /* Do not scan too many insns, scanning insns is expensive with 02050 remote targets. */ 02051 break; 02052 02053 /* Continue scanning. */ 02054 prev_insn_was_prologue_insn = 0; 02055 continue; 02056 } 02057 } 02058 02059 #if 0 02060 /* I have problems with skipping over __main() that I need to address 02061 * sometime. Previously, I used to use misc_function_vector which 02062 * didn't work as well as I wanted to be. -MGO */ 02063 02064 /* If the first thing after skipping a prolog is a branch to a function, 02065 this might be a call to an initializer in main(), introduced by gcc2. 02066 We'd like to skip over it as well. Fortunately, xlc does some extra 02067 work before calling a function right after a prologue, thus we can 02068 single out such gcc2 behaviour. */ 02069 02070 02071 if ((op & 0xfc000001) == 0x48000001) 02072 { /* bl foo, an initializer function? */ 02073 op = read_memory_integer (pc + 4, 4, byte_order); 02074 02075 if (op == 0x4def7b82) 02076 { /* cror 0xf, 0xf, 0xf (nop) */ 02077 02078 /* Check and see if we are in main. If so, skip over this 02079 initializer function as well. */ 02080 02081 tmp = find_pc_misc_function (pc); 02082 if (tmp >= 0 02083 && strcmp (misc_function_vector[tmp].name, main_name ()) == 0) 02084 return pc + 8; 02085 } 02086 } 02087 #endif /* 0 */ 02088 02089 if (pc == lim_pc && lr_reg >= 0) 02090 fdata->lr_register = lr_reg; 02091 02092 fdata->offset = -fdata->offset; 02093 return last_prologue_pc; 02094 } 02095 02096 static CORE_ADDR 02097 rs6000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 02098 { 02099 struct rs6000_framedata frame; 02100 CORE_ADDR limit_pc, func_addr, func_end_addr = 0; 02101 02102 /* See if we can determine the end of the prologue via the symbol table. 02103 If so, then return either PC, or the PC after the prologue, whichever 02104 is greater. */ 02105 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr)) 02106 { 02107 CORE_ADDR post_prologue_pc 02108 = skip_prologue_using_sal (gdbarch, func_addr); 02109 if (post_prologue_pc != 0) 02110 return max (pc, post_prologue_pc); 02111 } 02112 02113 /* Can't determine prologue from the symbol table, need to examine 02114 instructions. */ 02115 02116 /* Find an upper limit on the function prologue using the debug 02117 information. If the debug information could not be used to provide 02118 that bound, then use an arbitrary large number as the upper bound. */ 02119 limit_pc = skip_prologue_using_sal (gdbarch, pc); 02120 if (limit_pc == 0) 02121 limit_pc = pc + 100; /* Magic. */ 02122 02123 /* Do not allow limit_pc to be past the function end, if we know 02124 where that end is... */ 02125 if (func_end_addr && limit_pc > func_end_addr) 02126 limit_pc = func_end_addr; 02127 02128 pc = skip_prologue (gdbarch, pc, limit_pc, &frame); 02129 return pc; 02130 } 02131 02132 /* When compiling for EABI, some versions of GCC emit a call to __eabi 02133 in the prologue of main(). 02134 02135 The function below examines the code pointed at by PC and checks to 02136 see if it corresponds to a call to __eabi. If so, it returns the 02137 address of the instruction following that call. Otherwise, it simply 02138 returns PC. */ 02139 02140 static CORE_ADDR 02141 rs6000_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 02142 { 02143 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02144 gdb_byte buf[4]; 02145 unsigned long op; 02146 02147 if (target_read_memory (pc, buf, 4)) 02148 return pc; 02149 op = extract_unsigned_integer (buf, 4, byte_order); 02150 02151 if ((op & BL_MASK) == BL_INSTRUCTION) 02152 { 02153 CORE_ADDR displ = op & BL_DISPLACEMENT_MASK; 02154 CORE_ADDR call_dest = pc + 4 + displ; 02155 struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest); 02156 02157 /* We check for ___eabi (three leading underscores) in addition 02158 to __eabi in case the GCC option "-fleading-underscore" was 02159 used to compile the program. */ 02160 if (s.minsym != NULL 02161 && SYMBOL_LINKAGE_NAME (s.minsym) != NULL 02162 && (strcmp (SYMBOL_LINKAGE_NAME (s.minsym), "__eabi") == 0 02163 || strcmp (SYMBOL_LINKAGE_NAME (s.minsym), "___eabi") == 0)) 02164 pc += 4; 02165 } 02166 return pc; 02167 } 02168 02169 /* All the ABI's require 16 byte alignment. */ 02170 static CORE_ADDR 02171 rs6000_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) 02172 { 02173 return (addr & -16); 02174 } 02175 02176 /* Return whether handle_inferior_event() should proceed through code 02177 starting at PC in function NAME when stepping. 02178 02179 The AIX -bbigtoc linker option generates functions @FIX0, @FIX1, etc. to 02180 handle memory references that are too distant to fit in instructions 02181 generated by the compiler. For example, if 'foo' in the following 02182 instruction: 02183 02184 lwz r9,foo(r2) 02185 02186 is greater than 32767, the linker might replace the lwz with a branch to 02187 somewhere in @FIX1 that does the load in 2 instructions and then branches 02188 back to where execution should continue. 02189 02190 GDB should silently step over @FIX code, just like AIX dbx does. 02191 Unfortunately, the linker uses the "b" instruction for the 02192 branches, meaning that the link register doesn't get set. 02193 Therefore, GDB's usual step_over_function () mechanism won't work. 02194 02195 Instead, use the gdbarch_skip_trampoline_code and 02196 gdbarch_skip_trampoline_code hooks in handle_inferior_event() to skip past 02197 @FIX code. */ 02198 02199 static int 02200 rs6000_in_solib_return_trampoline (struct gdbarch *gdbarch, 02201 CORE_ADDR pc, const char *name) 02202 { 02203 return name && !strncmp (name, "@FIX", 4); 02204 } 02205 02206 /* Skip code that the user doesn't want to see when stepping: 02207 02208 1. Indirect function calls use a piece of trampoline code to do context 02209 switching, i.e. to set the new TOC table. Skip such code if we are on 02210 its first instruction (as when we have single-stepped to here). 02211 02212 2. Skip shared library trampoline code (which is different from 02213 indirect function call trampolines). 02214 02215 3. Skip bigtoc fixup code. 02216 02217 Result is desired PC to step until, or NULL if we are not in 02218 code that should be skipped. */ 02219 02220 static CORE_ADDR 02221 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) 02222 { 02223 struct gdbarch *gdbarch = get_frame_arch (frame); 02224 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02225 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02226 unsigned int ii, op; 02227 int rel; 02228 CORE_ADDR solib_target_pc; 02229 struct bound_minimal_symbol msymbol; 02230 02231 static unsigned trampoline_code[] = 02232 { 02233 0x800b0000, /* l r0,0x0(r11) */ 02234 0x90410014, /* st r2,0x14(r1) */ 02235 0x7c0903a6, /* mtctr r0 */ 02236 0x804b0004, /* l r2,0x4(r11) */ 02237 0x816b0008, /* l r11,0x8(r11) */ 02238 0x4e800420, /* bctr */ 02239 0x4e800020, /* br */ 02240 0 02241 }; 02242 02243 /* Check for bigtoc fixup code. */ 02244 msymbol = lookup_minimal_symbol_by_pc (pc); 02245 if (msymbol.minsym 02246 && rs6000_in_solib_return_trampoline (gdbarch, pc, 02247 SYMBOL_LINKAGE_NAME (msymbol.minsym))) 02248 { 02249 /* Double-check that the third instruction from PC is relative "b". */ 02250 op = read_memory_integer (pc + 8, 4, byte_order); 02251 if ((op & 0xfc000003) == 0x48000000) 02252 { 02253 /* Extract bits 6-29 as a signed 24-bit relative word address and 02254 add it to the containing PC. */ 02255 rel = ((int)(op << 6) >> 6); 02256 return pc + 8 + rel; 02257 } 02258 } 02259 02260 /* If pc is in a shared library trampoline, return its target. */ 02261 solib_target_pc = find_solib_trampoline_target (frame, pc); 02262 if (solib_target_pc) 02263 return solib_target_pc; 02264 02265 for (ii = 0; trampoline_code[ii]; ++ii) 02266 { 02267 op = read_memory_integer (pc + (ii * 4), 4, byte_order); 02268 if (op != trampoline_code[ii]) 02269 return 0; 02270 } 02271 ii = get_frame_register_unsigned (frame, 11); /* r11 holds destination 02272 addr. */ 02273 pc = read_memory_unsigned_integer (ii, tdep->wordsize, byte_order); 02274 return pc; 02275 } 02276 02277 /* ISA-specific vector types. */ 02278 02279 static struct type * 02280 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch) 02281 { 02282 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02283 02284 if (!tdep->ppc_builtin_type_vec64) 02285 { 02286 const struct builtin_type *bt = builtin_type (gdbarch); 02287 02288 /* The type we're building is this: */ 02289 #if 0 02290 union __gdb_builtin_type_vec64 02291 { 02292 int64_t uint64; 02293 float v2_float[2]; 02294 int32_t v2_int32[2]; 02295 int16_t v4_int16[4]; 02296 int8_t v8_int8[8]; 02297 }; 02298 #endif 02299 02300 struct type *t; 02301 02302 t = arch_composite_type (gdbarch, 02303 "__ppc_builtin_type_vec64", TYPE_CODE_UNION); 02304 append_composite_type_field (t, "uint64", bt->builtin_int64); 02305 append_composite_type_field (t, "v2_float", 02306 init_vector_type (bt->builtin_float, 2)); 02307 append_composite_type_field (t, "v2_int32", 02308 init_vector_type (bt->builtin_int32, 2)); 02309 append_composite_type_field (t, "v4_int16", 02310 init_vector_type (bt->builtin_int16, 4)); 02311 append_composite_type_field (t, "v8_int8", 02312 init_vector_type (bt->builtin_int8, 8)); 02313 02314 TYPE_VECTOR (t) = 1; 02315 TYPE_NAME (t) = "ppc_builtin_type_vec64"; 02316 tdep->ppc_builtin_type_vec64 = t; 02317 } 02318 02319 return tdep->ppc_builtin_type_vec64; 02320 } 02321 02322 /* Vector 128 type. */ 02323 02324 static struct type * 02325 rs6000_builtin_type_vec128 (struct gdbarch *gdbarch) 02326 { 02327 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02328 02329 if (!tdep->ppc_builtin_type_vec128) 02330 { 02331 const struct builtin_type *bt = builtin_type (gdbarch); 02332 02333 /* The type we're building is this 02334 02335 type = union __ppc_builtin_type_vec128 { 02336 uint128_t uint128; 02337 double v2_double[2]; 02338 float v4_float[4]; 02339 int32_t v4_int32[4]; 02340 int16_t v8_int16[8]; 02341 int8_t v16_int8[16]; 02342 } 02343 */ 02344 02345 struct type *t; 02346 02347 t = arch_composite_type (gdbarch, 02348 "__ppc_builtin_type_vec128", TYPE_CODE_UNION); 02349 append_composite_type_field (t, "uint128", bt->builtin_uint128); 02350 append_composite_type_field (t, "v2_double", 02351 init_vector_type (bt->builtin_double, 2)); 02352 append_composite_type_field (t, "v4_float", 02353 init_vector_type (bt->builtin_float, 4)); 02354 append_composite_type_field (t, "v4_int32", 02355 init_vector_type (bt->builtin_int32, 4)); 02356 append_composite_type_field (t, "v8_int16", 02357 init_vector_type (bt->builtin_int16, 8)); 02358 append_composite_type_field (t, "v16_int8", 02359 init_vector_type (bt->builtin_int8, 16)); 02360 02361 TYPE_VECTOR (t) = 1; 02362 TYPE_NAME (t) = "ppc_builtin_type_vec128"; 02363 tdep->ppc_builtin_type_vec128 = t; 02364 } 02365 02366 return tdep->ppc_builtin_type_vec128; 02367 } 02368 02369 /* Return the name of register number REGNO, or the empty string if it 02370 is an anonymous register. */ 02371 02372 static const char * 02373 rs6000_register_name (struct gdbarch *gdbarch, int regno) 02374 { 02375 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02376 02377 /* The upper half "registers" have names in the XML description, 02378 but we present only the low GPRs and the full 64-bit registers 02379 to the user. */ 02380 if (tdep->ppc_ev0_upper_regnum >= 0 02381 && tdep->ppc_ev0_upper_regnum <= regno 02382 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs) 02383 return ""; 02384 02385 /* Hide the upper halves of the vs0~vs31 registers. */ 02386 if (tdep->ppc_vsr0_regnum >= 0 02387 && tdep->ppc_vsr0_upper_regnum <= regno 02388 && regno < tdep->ppc_vsr0_upper_regnum + ppc_num_gprs) 02389 return ""; 02390 02391 /* Check if the SPE pseudo registers are available. */ 02392 if (IS_SPE_PSEUDOREG (tdep, regno)) 02393 { 02394 static const char *const spe_regnames[] = { 02395 "ev0", "ev1", "ev2", "ev3", "ev4", "ev5", "ev6", "ev7", 02396 "ev8", "ev9", "ev10", "ev11", "ev12", "ev13", "ev14", "ev15", 02397 "ev16", "ev17", "ev18", "ev19", "ev20", "ev21", "ev22", "ev23", 02398 "ev24", "ev25", "ev26", "ev27", "ev28", "ev29", "ev30", "ev31", 02399 }; 02400 return spe_regnames[regno - tdep->ppc_ev0_regnum]; 02401 } 02402 02403 /* Check if the decimal128 pseudo-registers are available. */ 02404 if (IS_DFP_PSEUDOREG (tdep, regno)) 02405 { 02406 static const char *const dfp128_regnames[] = { 02407 "dl0", "dl1", "dl2", "dl3", 02408 "dl4", "dl5", "dl6", "dl7", 02409 "dl8", "dl9", "dl10", "dl11", 02410 "dl12", "dl13", "dl14", "dl15" 02411 }; 02412 return dfp128_regnames[regno - tdep->ppc_dl0_regnum]; 02413 } 02414 02415 /* Check if this is a VSX pseudo-register. */ 02416 if (IS_VSX_PSEUDOREG (tdep, regno)) 02417 { 02418 static const char *const vsx_regnames[] = { 02419 "vs0", "vs1", "vs2", "vs3", "vs4", "vs5", "vs6", "vs7", 02420 "vs8", "vs9", "vs10", "vs11", "vs12", "vs13", "vs14", 02421 "vs15", "vs16", "vs17", "vs18", "vs19", "vs20", "vs21", 02422 "vs22", "vs23", "vs24", "vs25", "vs26", "vs27", "vs28", 02423 "vs29", "vs30", "vs31", "vs32", "vs33", "vs34", "vs35", 02424 "vs36", "vs37", "vs38", "vs39", "vs40", "vs41", "vs42", 02425 "vs43", "vs44", "vs45", "vs46", "vs47", "vs48", "vs49", 02426 "vs50", "vs51", "vs52", "vs53", "vs54", "vs55", "vs56", 02427 "vs57", "vs58", "vs59", "vs60", "vs61", "vs62", "vs63" 02428 }; 02429 return vsx_regnames[regno - tdep->ppc_vsr0_regnum]; 02430 } 02431 02432 /* Check if the this is a Extended FP pseudo-register. */ 02433 if (IS_EFP_PSEUDOREG (tdep, regno)) 02434 { 02435 static const char *const efpr_regnames[] = { 02436 "f32", "f33", "f34", "f35", "f36", "f37", "f38", 02437 "f39", "f40", "f41", "f42", "f43", "f44", "f45", 02438 "f46", "f47", "f48", "f49", "f50", "f51", 02439 "f52", "f53", "f54", "f55", "f56", "f57", 02440 "f58", "f59", "f60", "f61", "f62", "f63" 02441 }; 02442 return efpr_regnames[regno - tdep->ppc_efpr0_regnum]; 02443 } 02444 02445 return tdesc_register_name (gdbarch, regno); 02446 } 02447 02448 /* Return the GDB type object for the "standard" data type of data in 02449 register N. */ 02450 02451 static struct type * 02452 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum) 02453 { 02454 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02455 02456 /* These are the only pseudo-registers we support. */ 02457 gdb_assert (IS_SPE_PSEUDOREG (tdep, regnum) 02458 || IS_DFP_PSEUDOREG (tdep, regnum) 02459 || IS_VSX_PSEUDOREG (tdep, regnum) 02460 || IS_EFP_PSEUDOREG (tdep, regnum)); 02461 02462 /* These are the e500 pseudo-registers. */ 02463 if (IS_SPE_PSEUDOREG (tdep, regnum)) 02464 return rs6000_builtin_type_vec64 (gdbarch); 02465 else if (IS_DFP_PSEUDOREG (tdep, regnum)) 02466 /* PPC decimal128 pseudo-registers. */ 02467 return builtin_type (gdbarch)->builtin_declong; 02468 else if (IS_VSX_PSEUDOREG (tdep, regnum)) 02469 /* POWER7 VSX pseudo-registers. */ 02470 return rs6000_builtin_type_vec128 (gdbarch); 02471 else 02472 /* POWER7 Extended FP pseudo-registers. */ 02473 return builtin_type (gdbarch)->builtin_double; 02474 } 02475 02476 /* Is REGNUM a member of REGGROUP? */ 02477 static int 02478 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum, 02479 struct reggroup *group) 02480 { 02481 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02482 02483 /* These are the only pseudo-registers we support. */ 02484 gdb_assert (IS_SPE_PSEUDOREG (tdep, regnum) 02485 || IS_DFP_PSEUDOREG (tdep, regnum) 02486 || IS_VSX_PSEUDOREG (tdep, regnum) 02487 || IS_EFP_PSEUDOREG (tdep, regnum)); 02488 02489 /* These are the e500 pseudo-registers or the POWER7 VSX registers. */ 02490 if (IS_SPE_PSEUDOREG (tdep, regnum) || IS_VSX_PSEUDOREG (tdep, regnum)) 02491 return group == all_reggroup || group == vector_reggroup; 02492 else 02493 /* PPC decimal128 or Extended FP pseudo-registers. */ 02494 return group == all_reggroup || group == float_reggroup; 02495 } 02496 02497 /* The register format for RS/6000 floating point registers is always 02498 double, we need a conversion if the memory format is float. */ 02499 02500 static int 02501 rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum, 02502 struct type *type) 02503 { 02504 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02505 02506 return (tdep->ppc_fp0_regnum >= 0 02507 && regnum >= tdep->ppc_fp0_regnum 02508 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs 02509 && TYPE_CODE (type) == TYPE_CODE_FLT 02510 && TYPE_LENGTH (type) 02511 != TYPE_LENGTH (builtin_type (gdbarch)->builtin_double)); 02512 } 02513 02514 static int 02515 rs6000_register_to_value (struct frame_info *frame, 02516 int regnum, 02517 struct type *type, 02518 gdb_byte *to, 02519 int *optimizedp, int *unavailablep) 02520 { 02521 struct gdbarch *gdbarch = get_frame_arch (frame); 02522 gdb_byte from[MAX_REGISTER_SIZE]; 02523 02524 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT); 02525 02526 if (!get_frame_register_bytes (frame, regnum, 0, 02527 register_size (gdbarch, regnum), 02528 from, optimizedp, unavailablep)) 02529 return 0; 02530 02531 convert_typed_floating (from, builtin_type (gdbarch)->builtin_double, 02532 to, type); 02533 *optimizedp = *unavailablep = 0; 02534 return 1; 02535 } 02536 02537 static void 02538 rs6000_value_to_register (struct frame_info *frame, 02539 int regnum, 02540 struct type *type, 02541 const gdb_byte *from) 02542 { 02543 struct gdbarch *gdbarch = get_frame_arch (frame); 02544 gdb_byte to[MAX_REGISTER_SIZE]; 02545 02546 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT); 02547 02548 convert_typed_floating (from, type, 02549 to, builtin_type (gdbarch)->builtin_double); 02550 put_frame_register (frame, regnum, to); 02551 } 02552 02553 /* The type of a function that moves the value of REG between CACHE 02554 or BUF --- in either direction. */ 02555 typedef enum register_status (*move_ev_register_func) (struct regcache *, 02556 int, void *); 02557 02558 /* Move SPE vector register values between a 64-bit buffer and the two 02559 32-bit raw register halves in a regcache. This function handles 02560 both splitting a 64-bit value into two 32-bit halves, and joining 02561 two halves into a whole 64-bit value, depending on the function 02562 passed as the MOVE argument. 02563 02564 EV_REG must be the number of an SPE evN vector register --- a 02565 pseudoregister. REGCACHE must be a regcache, and BUFFER must be a 02566 64-bit buffer. 02567 02568 Call MOVE once for each 32-bit half of that register, passing 02569 REGCACHE, the number of the raw register corresponding to that 02570 half, and the address of the appropriate half of BUFFER. 02571 02572 For example, passing 'regcache_raw_read' as the MOVE function will 02573 fill BUFFER with the full 64-bit contents of EV_REG. Or, passing 02574 'regcache_raw_supply' will supply the contents of BUFFER to the 02575 appropriate pair of raw registers in REGCACHE. 02576 02577 You may need to cast away some 'const' qualifiers when passing 02578 MOVE, since this function can't tell at compile-time which of 02579 REGCACHE or BUFFER is acting as the source of the data. If C had 02580 co-variant type qualifiers, ... */ 02581 02582 static enum register_status 02583 e500_move_ev_register (move_ev_register_func move, 02584 struct regcache *regcache, int ev_reg, void *buffer) 02585 { 02586 struct gdbarch *arch = get_regcache_arch (regcache); 02587 struct gdbarch_tdep *tdep = gdbarch_tdep (arch); 02588 int reg_index; 02589 gdb_byte *byte_buffer = buffer; 02590 enum register_status status; 02591 02592 gdb_assert (IS_SPE_PSEUDOREG (tdep, ev_reg)); 02593 02594 reg_index = ev_reg - tdep->ppc_ev0_regnum; 02595 02596 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG) 02597 { 02598 status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index, 02599 byte_buffer); 02600 if (status == REG_VALID) 02601 status = move (regcache, tdep->ppc_gp0_regnum + reg_index, 02602 byte_buffer + 4); 02603 } 02604 else 02605 { 02606 status = move (regcache, tdep->ppc_gp0_regnum + reg_index, byte_buffer); 02607 if (status == REG_VALID) 02608 status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index, 02609 byte_buffer + 4); 02610 } 02611 02612 return status; 02613 } 02614 02615 static enum register_status 02616 do_regcache_raw_read (struct regcache *regcache, int regnum, void *buffer) 02617 { 02618 return regcache_raw_read (regcache, regnum, buffer); 02619 } 02620 02621 static enum register_status 02622 do_regcache_raw_write (struct regcache *regcache, int regnum, void *buffer) 02623 { 02624 regcache_raw_write (regcache, regnum, buffer); 02625 02626 return REG_VALID; 02627 } 02628 02629 static enum register_status 02630 e500_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, 02631 int reg_nr, gdb_byte *buffer) 02632 { 02633 return e500_move_ev_register (do_regcache_raw_read, regcache, reg_nr, buffer); 02634 } 02635 02636 static void 02637 e500_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 02638 int reg_nr, const gdb_byte *buffer) 02639 { 02640 e500_move_ev_register (do_regcache_raw_write, regcache, 02641 reg_nr, (void *) buffer); 02642 } 02643 02644 /* Read method for DFP pseudo-registers. */ 02645 static enum register_status 02646 dfp_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, 02647 int reg_nr, gdb_byte *buffer) 02648 { 02649 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02650 int reg_index = reg_nr - tdep->ppc_dl0_regnum; 02651 enum register_status status; 02652 02653 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 02654 { 02655 /* Read two FP registers to form a whole dl register. */ 02656 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum + 02657 2 * reg_index, buffer); 02658 if (status == REG_VALID) 02659 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum + 02660 2 * reg_index + 1, buffer + 8); 02661 } 02662 else 02663 { 02664 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum + 02665 2 * reg_index + 1, buffer + 8); 02666 if (status == REG_VALID) 02667 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum + 02668 2 * reg_index, buffer); 02669 } 02670 02671 return status; 02672 } 02673 02674 /* Write method for DFP pseudo-registers. */ 02675 static void 02676 dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 02677 int reg_nr, const gdb_byte *buffer) 02678 { 02679 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02680 int reg_index = reg_nr - tdep->ppc_dl0_regnum; 02681 02682 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 02683 { 02684 /* Write each half of the dl register into a separate 02685 FP register. */ 02686 regcache_raw_write (regcache, tdep->ppc_fp0_regnum + 02687 2 * reg_index, buffer); 02688 regcache_raw_write (regcache, tdep->ppc_fp0_regnum + 02689 2 * reg_index + 1, buffer + 8); 02690 } 02691 else 02692 { 02693 regcache_raw_write (regcache, tdep->ppc_fp0_regnum + 02694 2 * reg_index + 1, buffer + 8); 02695 regcache_raw_write (regcache, tdep->ppc_fp0_regnum + 02696 2 * reg_index, buffer); 02697 } 02698 } 02699 02700 /* Read method for POWER7 VSX pseudo-registers. */ 02701 static enum register_status 02702 vsx_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, 02703 int reg_nr, gdb_byte *buffer) 02704 { 02705 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02706 int reg_index = reg_nr - tdep->ppc_vsr0_regnum; 02707 enum register_status status; 02708 02709 /* Read the portion that overlaps the VMX registers. */ 02710 if (reg_index > 31) 02711 status = regcache_raw_read (regcache, tdep->ppc_vr0_regnum + 02712 reg_index - 32, buffer); 02713 else 02714 /* Read the portion that overlaps the FPR registers. */ 02715 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 02716 { 02717 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum + 02718 reg_index, buffer); 02719 if (status == REG_VALID) 02720 status = regcache_raw_read (regcache, tdep->ppc_vsr0_upper_regnum + 02721 reg_index, buffer + 8); 02722 } 02723 else 02724 { 02725 status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum + 02726 reg_index, buffer + 8); 02727 if (status == REG_VALID) 02728 status = regcache_raw_read (regcache, tdep->ppc_vsr0_upper_regnum + 02729 reg_index, buffer); 02730 } 02731 02732 return status; 02733 } 02734 02735 /* Write method for POWER7 VSX pseudo-registers. */ 02736 static void 02737 vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 02738 int reg_nr, const gdb_byte *buffer) 02739 { 02740 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02741 int reg_index = reg_nr - tdep->ppc_vsr0_regnum; 02742 02743 /* Write the portion that overlaps the VMX registers. */ 02744 if (reg_index > 31) 02745 regcache_raw_write (regcache, tdep->ppc_vr0_regnum + 02746 reg_index - 32, buffer); 02747 else 02748 /* Write the portion that overlaps the FPR registers. */ 02749 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) 02750 { 02751 regcache_raw_write (regcache, tdep->ppc_fp0_regnum + 02752 reg_index, buffer); 02753 regcache_raw_write (regcache, tdep->ppc_vsr0_upper_regnum + 02754 reg_index, buffer + 8); 02755 } 02756 else 02757 { 02758 regcache_raw_write (regcache, tdep->ppc_fp0_regnum + 02759 reg_index, buffer + 8); 02760 regcache_raw_write (regcache, tdep->ppc_vsr0_upper_regnum + 02761 reg_index, buffer); 02762 } 02763 } 02764 02765 /* Read method for POWER7 Extended FP pseudo-registers. */ 02766 static enum register_status 02767 efpr_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, 02768 int reg_nr, gdb_byte *buffer) 02769 { 02770 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02771 int reg_index = reg_nr - tdep->ppc_efpr0_regnum; 02772 02773 /* Read the portion that overlaps the VMX register. */ 02774 return regcache_raw_read_part (regcache, tdep->ppc_vr0_regnum + reg_index, 0, 02775 register_size (gdbarch, reg_nr), buffer); 02776 } 02777 02778 /* Write method for POWER7 Extended FP pseudo-registers. */ 02779 static void 02780 efpr_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 02781 int reg_nr, const gdb_byte *buffer) 02782 { 02783 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02784 int reg_index = reg_nr - tdep->ppc_efpr0_regnum; 02785 02786 /* Write the portion that overlaps the VMX register. */ 02787 regcache_raw_write_part (regcache, tdep->ppc_vr0_regnum + reg_index, 0, 02788 register_size (gdbarch, reg_nr), buffer); 02789 } 02790 02791 static enum register_status 02792 rs6000_pseudo_register_read (struct gdbarch *gdbarch, 02793 struct regcache *regcache, 02794 int reg_nr, gdb_byte *buffer) 02795 { 02796 struct gdbarch *regcache_arch = get_regcache_arch (regcache); 02797 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02798 02799 gdb_assert (regcache_arch == gdbarch); 02800 02801 if (IS_SPE_PSEUDOREG (tdep, reg_nr)) 02802 return e500_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 02803 else if (IS_DFP_PSEUDOREG (tdep, reg_nr)) 02804 return dfp_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 02805 else if (IS_VSX_PSEUDOREG (tdep, reg_nr)) 02806 return vsx_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 02807 else if (IS_EFP_PSEUDOREG (tdep, reg_nr)) 02808 return efpr_pseudo_register_read (gdbarch, regcache, reg_nr, buffer); 02809 else 02810 internal_error (__FILE__, __LINE__, 02811 _("rs6000_pseudo_register_read: " 02812 "called on unexpected register '%s' (%d)"), 02813 gdbarch_register_name (gdbarch, reg_nr), reg_nr); 02814 } 02815 02816 static void 02817 rs6000_pseudo_register_write (struct gdbarch *gdbarch, 02818 struct regcache *regcache, 02819 int reg_nr, const gdb_byte *buffer) 02820 { 02821 struct gdbarch *regcache_arch = get_regcache_arch (regcache); 02822 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02823 02824 gdb_assert (regcache_arch == gdbarch); 02825 02826 if (IS_SPE_PSEUDOREG (tdep, reg_nr)) 02827 e500_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 02828 else if (IS_DFP_PSEUDOREG (tdep, reg_nr)) 02829 dfp_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 02830 else if (IS_VSX_PSEUDOREG (tdep, reg_nr)) 02831 vsx_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 02832 else if (IS_EFP_PSEUDOREG (tdep, reg_nr)) 02833 efpr_pseudo_register_write (gdbarch, regcache, reg_nr, buffer); 02834 else 02835 internal_error (__FILE__, __LINE__, 02836 _("rs6000_pseudo_register_write: " 02837 "called on unexpected register '%s' (%d)"), 02838 gdbarch_register_name (gdbarch, reg_nr), reg_nr); 02839 } 02840 02841 /* Convert a DBX STABS register number to a GDB register number. */ 02842 static int 02843 rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num) 02844 { 02845 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02846 02847 if (0 <= num && num <= 31) 02848 return tdep->ppc_gp0_regnum + num; 02849 else if (32 <= num && num <= 63) 02850 /* FIXME: jimb/2004-05-05: What should we do when the debug info 02851 specifies registers the architecture doesn't have? Our 02852 callers don't check the value we return. */ 02853 return tdep->ppc_fp0_regnum + (num - 32); 02854 else if (77 <= num && num <= 108) 02855 return tdep->ppc_vr0_regnum + (num - 77); 02856 else if (1200 <= num && num < 1200 + 32) 02857 return tdep->ppc_ev0_upper_regnum + (num - 1200); 02858 else 02859 switch (num) 02860 { 02861 case 64: 02862 return tdep->ppc_mq_regnum; 02863 case 65: 02864 return tdep->ppc_lr_regnum; 02865 case 66: 02866 return tdep->ppc_ctr_regnum; 02867 case 76: 02868 return tdep->ppc_xer_regnum; 02869 case 109: 02870 return tdep->ppc_vrsave_regnum; 02871 case 110: 02872 return tdep->ppc_vrsave_regnum - 1; /* vscr */ 02873 case 111: 02874 return tdep->ppc_acc_regnum; 02875 case 112: 02876 return tdep->ppc_spefscr_regnum; 02877 default: 02878 return num; 02879 } 02880 } 02881 02882 02883 /* Convert a Dwarf 2 register number to a GDB register number. */ 02884 static int 02885 rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num) 02886 { 02887 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02888 02889 if (0 <= num && num <= 31) 02890 return tdep->ppc_gp0_regnum + num; 02891 else if (32 <= num && num <= 63) 02892 /* FIXME: jimb/2004-05-05: What should we do when the debug info 02893 specifies registers the architecture doesn't have? Our 02894 callers don't check the value we return. */ 02895 return tdep->ppc_fp0_regnum + (num - 32); 02896 else if (1124 <= num && num < 1124 + 32) 02897 return tdep->ppc_vr0_regnum + (num - 1124); 02898 else if (1200 <= num && num < 1200 + 32) 02899 return tdep->ppc_ev0_upper_regnum + (num - 1200); 02900 else 02901 switch (num) 02902 { 02903 case 64: 02904 return tdep->ppc_cr_regnum; 02905 case 67: 02906 return tdep->ppc_vrsave_regnum - 1; /* vscr */ 02907 case 99: 02908 return tdep->ppc_acc_regnum; 02909 case 100: 02910 return tdep->ppc_mq_regnum; 02911 case 101: 02912 return tdep->ppc_xer_regnum; 02913 case 108: 02914 return tdep->ppc_lr_regnum; 02915 case 109: 02916 return tdep->ppc_ctr_regnum; 02917 case 356: 02918 return tdep->ppc_vrsave_regnum; 02919 case 612: 02920 return tdep->ppc_spefscr_regnum; 02921 default: 02922 return num; 02923 } 02924 } 02925 02926 /* Translate a .eh_frame register to DWARF register, or adjust a 02927 .debug_frame register. */ 02928 02929 static int 02930 rs6000_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p) 02931 { 02932 /* GCC releases before 3.4 use GCC internal register numbering in 02933 .debug_frame (and .debug_info, et cetera). The numbering is 02934 different from the standard SysV numbering for everything except 02935 for GPRs and FPRs. We can not detect this problem in most cases 02936 - to get accurate debug info for variables living in lr, ctr, v0, 02937 et cetera, use a newer version of GCC. But we must detect 02938 one important case - lr is in column 65 in .debug_frame output, 02939 instead of 108. 02940 02941 GCC 3.4, and the "hammer" branch, have a related problem. They 02942 record lr register saves in .debug_frame as 108, but still record 02943 the return column as 65. We fix that up too. 02944 02945 We can do this because 65 is assigned to fpsr, and GCC never 02946 generates debug info referring to it. To add support for 02947 handwritten debug info that restores fpsr, we would need to add a 02948 producer version check to this. */ 02949 if (!eh_frame_p) 02950 { 02951 if (num == 65) 02952 return 108; 02953 else 02954 return num; 02955 } 02956 02957 /* .eh_frame is GCC specific. For binary compatibility, it uses GCC 02958 internal register numbering; translate that to the standard DWARF2 02959 register numbering. */ 02960 if (0 <= num && num <= 63) /* r0-r31,fp0-fp31 */ 02961 return num; 02962 else if (68 <= num && num <= 75) /* cr0-cr8 */ 02963 return num - 68 + 86; 02964 else if (77 <= num && num <= 108) /* vr0-vr31 */ 02965 return num - 77 + 1124; 02966 else 02967 switch (num) 02968 { 02969 case 64: /* mq */ 02970 return 100; 02971 case 65: /* lr */ 02972 return 108; 02973 case 66: /* ctr */ 02974 return 109; 02975 case 76: /* xer */ 02976 return 101; 02977 case 109: /* vrsave */ 02978 return 356; 02979 case 110: /* vscr */ 02980 return 67; 02981 case 111: /* spe_acc */ 02982 return 99; 02983 case 112: /* spefscr */ 02984 return 612; 02985 default: 02986 return num; 02987 } 02988 } 02989 02990 02991 /* Handling the various POWER/PowerPC variants. */ 02992 02993 /* Information about a particular processor variant. */ 02994 02995 struct variant 02996 { 02997 /* Name of this variant. */ 02998 char *name; 02999 03000 /* English description of the variant. */ 03001 char *description; 03002 03003 /* bfd_arch_info.arch corresponding to variant. */ 03004 enum bfd_architecture arch; 03005 03006 /* bfd_arch_info.mach corresponding to variant. */ 03007 unsigned long mach; 03008 03009 /* Target description for this variant. */ 03010 struct target_desc **tdesc; 03011 }; 03012 03013 static struct variant variants[] = 03014 { 03015 {"powerpc", "PowerPC user-level", bfd_arch_powerpc, 03016 bfd_mach_ppc, &tdesc_powerpc_altivec32}, 03017 {"power", "POWER user-level", bfd_arch_rs6000, 03018 bfd_mach_rs6k, &tdesc_rs6000}, 03019 {"403", "IBM PowerPC 403", bfd_arch_powerpc, 03020 bfd_mach_ppc_403, &tdesc_powerpc_403}, 03021 {"405", "IBM PowerPC 405", bfd_arch_powerpc, 03022 bfd_mach_ppc_405, &tdesc_powerpc_405}, 03023 {"601", "Motorola PowerPC 601", bfd_arch_powerpc, 03024 bfd_mach_ppc_601, &tdesc_powerpc_601}, 03025 {"602", "Motorola PowerPC 602", bfd_arch_powerpc, 03026 bfd_mach_ppc_602, &tdesc_powerpc_602}, 03027 {"603", "Motorola/IBM PowerPC 603 or 603e", bfd_arch_powerpc, 03028 bfd_mach_ppc_603, &tdesc_powerpc_603}, 03029 {"604", "Motorola PowerPC 604 or 604e", bfd_arch_powerpc, 03030 604, &tdesc_powerpc_604}, 03031 {"403GC", "IBM PowerPC 403GC", bfd_arch_powerpc, 03032 bfd_mach_ppc_403gc, &tdesc_powerpc_403gc}, 03033 {"505", "Motorola PowerPC 505", bfd_arch_powerpc, 03034 bfd_mach_ppc_505, &tdesc_powerpc_505}, 03035 {"860", "Motorola PowerPC 860 or 850", bfd_arch_powerpc, 03036 bfd_mach_ppc_860, &tdesc_powerpc_860}, 03037 {"750", "Motorola/IBM PowerPC 750 or 740", bfd_arch_powerpc, 03038 bfd_mach_ppc_750, &tdesc_powerpc_750}, 03039 {"7400", "Motorola/IBM PowerPC 7400 (G4)", bfd_arch_powerpc, 03040 bfd_mach_ppc_7400, &tdesc_powerpc_7400}, 03041 {"e500", "Motorola PowerPC e500", bfd_arch_powerpc, 03042 bfd_mach_ppc_e500, &tdesc_powerpc_e500}, 03043 03044 /* 64-bit */ 03045 {"powerpc64", "PowerPC 64-bit user-level", bfd_arch_powerpc, 03046 bfd_mach_ppc64, &tdesc_powerpc_altivec64}, 03047 {"620", "Motorola PowerPC 620", bfd_arch_powerpc, 03048 bfd_mach_ppc_620, &tdesc_powerpc_64}, 03049 {"630", "Motorola PowerPC 630", bfd_arch_powerpc, 03050 bfd_mach_ppc_630, &tdesc_powerpc_64}, 03051 {"a35", "PowerPC A35", bfd_arch_powerpc, 03052 bfd_mach_ppc_a35, &tdesc_powerpc_64}, 03053 {"rs64ii", "PowerPC rs64ii", bfd_arch_powerpc, 03054 bfd_mach_ppc_rs64ii, &tdesc_powerpc_64}, 03055 {"rs64iii", "PowerPC rs64iii", bfd_arch_powerpc, 03056 bfd_mach_ppc_rs64iii, &tdesc_powerpc_64}, 03057 03058 /* FIXME: I haven't checked the register sets of the following. */ 03059 {"rs1", "IBM POWER RS1", bfd_arch_rs6000, 03060 bfd_mach_rs6k_rs1, &tdesc_rs6000}, 03061 {"rsc", "IBM POWER RSC", bfd_arch_rs6000, 03062 bfd_mach_rs6k_rsc, &tdesc_rs6000}, 03063 {"rs2", "IBM POWER RS2", bfd_arch_rs6000, 03064 bfd_mach_rs6k_rs2, &tdesc_rs6000}, 03065 03066 {0, 0, 0, 0, 0} 03067 }; 03068 03069 /* Return the variant corresponding to architecture ARCH and machine number 03070 MACH. If no such variant exists, return null. */ 03071 03072 static const struct variant * 03073 find_variant_by_arch (enum bfd_architecture arch, unsigned long mach) 03074 { 03075 const struct variant *v; 03076 03077 for (v = variants; v->name; v++) 03078 if (arch == v->arch && mach == v->mach) 03079 return v; 03080 03081 return NULL; 03082 } 03083 03084 static int 03085 gdb_print_insn_powerpc (bfd_vma memaddr, disassemble_info *info) 03086 { 03087 if (info->endian == BFD_ENDIAN_BIG) 03088 return print_insn_big_powerpc (memaddr, info); 03089 else 03090 return print_insn_little_powerpc (memaddr, info); 03091 } 03092 03093 static CORE_ADDR 03094 rs6000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 03095 { 03096 return frame_unwind_register_unsigned (next_frame, 03097 gdbarch_pc_regnum (gdbarch)); 03098 } 03099 03100 static struct frame_id 03101 rs6000_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 03102 { 03103 return frame_id_build (get_frame_register_unsigned 03104 (this_frame, gdbarch_sp_regnum (gdbarch)), 03105 get_frame_pc (this_frame)); 03106 } 03107 03108 struct rs6000_frame_cache 03109 { 03110 CORE_ADDR base; 03111 CORE_ADDR initial_sp; 03112 struct trad_frame_saved_reg *saved_regs; 03113 }; 03114 03115 static struct rs6000_frame_cache * 03116 rs6000_frame_cache (struct frame_info *this_frame, void **this_cache) 03117 { 03118 struct rs6000_frame_cache *cache; 03119 struct gdbarch *gdbarch = get_frame_arch (this_frame); 03120 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 03121 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03122 struct rs6000_framedata fdata; 03123 int wordsize = tdep->wordsize; 03124 CORE_ADDR func, pc; 03125 03126 if ((*this_cache) != NULL) 03127 return (*this_cache); 03128 cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache); 03129 (*this_cache) = cache; 03130 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); 03131 03132 func = get_frame_func (this_frame); 03133 pc = get_frame_pc (this_frame); 03134 skip_prologue (gdbarch, func, pc, &fdata); 03135 03136 /* Figure out the parent's stack pointer. */ 03137 03138 /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most 03139 address of the current frame. Things might be easier if the 03140 ->frame pointed to the outer-most address of the frame. In 03141 the mean time, the address of the prev frame is used as the 03142 base address of this frame. */ 03143 cache->base = get_frame_register_unsigned 03144 (this_frame, gdbarch_sp_regnum (gdbarch)); 03145 03146 /* If the function appears to be frameless, check a couple of likely 03147 indicators that we have simply failed to find the frame setup. 03148 Two common cases of this are missing symbols (i.e. 03149 get_frame_func returns the wrong address or 0), and assembly 03150 stubs which have a fast exit path but set up a frame on the slow 03151 path. 03152 03153 If the LR appears to return to this function, then presume that 03154 we have an ABI compliant frame that we failed to find. */ 03155 if (fdata.frameless && fdata.lr_offset == 0) 03156 { 03157 CORE_ADDR saved_lr; 03158 int make_frame = 0; 03159 03160 saved_lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum); 03161 if (func == 0 && saved_lr == pc) 03162 make_frame = 1; 03163 else if (func != 0) 03164 { 03165 CORE_ADDR saved_func = get_pc_function_start (saved_lr); 03166 if (func == saved_func) 03167 make_frame = 1; 03168 } 03169 03170 if (make_frame) 03171 { 03172 fdata.frameless = 0; 03173 fdata.lr_offset = tdep->lr_frame_offset; 03174 } 03175 } 03176 03177 if (!fdata.frameless) 03178 /* Frameless really means stackless. */ 03179 cache->base 03180 = read_memory_unsigned_integer (cache->base, wordsize, byte_order); 03181 03182 trad_frame_set_value (cache->saved_regs, 03183 gdbarch_sp_regnum (gdbarch), cache->base); 03184 03185 /* if != -1, fdata.saved_fpr is the smallest number of saved_fpr. 03186 All fpr's from saved_fpr to fp31 are saved. */ 03187 03188 if (fdata.saved_fpr >= 0) 03189 { 03190 int i; 03191 CORE_ADDR fpr_addr = cache->base + fdata.fpr_offset; 03192 03193 /* If skip_prologue says floating-point registers were saved, 03194 but the current architecture has no floating-point registers, 03195 then that's strange. But we have no indices to even record 03196 the addresses under, so we just ignore it. */ 03197 if (ppc_floating_point_unit_p (gdbarch)) 03198 for (i = fdata.saved_fpr; i < ppc_num_fprs; i++) 03199 { 03200 cache->saved_regs[tdep->ppc_fp0_regnum + i].addr = fpr_addr; 03201 fpr_addr += 8; 03202 } 03203 } 03204 03205 /* if != -1, fdata.saved_gpr is the smallest number of saved_gpr. 03206 All gpr's from saved_gpr to gpr31 are saved (except during the 03207 prologue). */ 03208 03209 if (fdata.saved_gpr >= 0) 03210 { 03211 int i; 03212 CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset; 03213 for (i = fdata.saved_gpr; i < ppc_num_gprs; i++) 03214 { 03215 if (fdata.gpr_mask & (1U << i)) 03216 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr; 03217 gpr_addr += wordsize; 03218 } 03219 } 03220 03221 /* if != -1, fdata.saved_vr is the smallest number of saved_vr. 03222 All vr's from saved_vr to vr31 are saved. */ 03223 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1) 03224 { 03225 if (fdata.saved_vr >= 0) 03226 { 03227 int i; 03228 CORE_ADDR vr_addr = cache->base + fdata.vr_offset; 03229 for (i = fdata.saved_vr; i < 32; i++) 03230 { 03231 cache->saved_regs[tdep->ppc_vr0_regnum + i].addr = vr_addr; 03232 vr_addr += register_size (gdbarch, tdep->ppc_vr0_regnum); 03233 } 03234 } 03235 } 03236 03237 /* if != -1, fdata.saved_ev is the smallest number of saved_ev. 03238 All vr's from saved_ev to ev31 are saved. ????? */ 03239 if (tdep->ppc_ev0_regnum != -1) 03240 { 03241 if (fdata.saved_ev >= 0) 03242 { 03243 int i; 03244 CORE_ADDR ev_addr = cache->base + fdata.ev_offset; 03245 for (i = fdata.saved_ev; i < ppc_num_gprs; i++) 03246 { 03247 cache->saved_regs[tdep->ppc_ev0_regnum + i].addr = ev_addr; 03248 cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = ev_addr + 4; 03249 ev_addr += register_size (gdbarch, tdep->ppc_ev0_regnum); 03250 } 03251 } 03252 } 03253 03254 /* If != 0, fdata.cr_offset is the offset from the frame that 03255 holds the CR. */ 03256 if (fdata.cr_offset != 0) 03257 cache->saved_regs[tdep->ppc_cr_regnum].addr 03258 = cache->base + fdata.cr_offset; 03259 03260 /* If != 0, fdata.lr_offset is the offset from the frame that 03261 holds the LR. */ 03262 if (fdata.lr_offset != 0) 03263 cache->saved_regs[tdep->ppc_lr_regnum].addr 03264 = cache->base + fdata.lr_offset; 03265 else if (fdata.lr_register != -1) 03266 cache->saved_regs[tdep->ppc_lr_regnum].realreg = fdata.lr_register; 03267 /* The PC is found in the link register. */ 03268 cache->saved_regs[gdbarch_pc_regnum (gdbarch)] = 03269 cache->saved_regs[tdep->ppc_lr_regnum]; 03270 03271 /* If != 0, fdata.vrsave_offset is the offset from the frame that 03272 holds the VRSAVE. */ 03273 if (fdata.vrsave_offset != 0) 03274 cache->saved_regs[tdep->ppc_vrsave_regnum].addr 03275 = cache->base + fdata.vrsave_offset; 03276 03277 if (fdata.alloca_reg < 0) 03278 /* If no alloca register used, then fi->frame is the value of the 03279 %sp for this frame, and it is good enough. */ 03280 cache->initial_sp 03281 = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch)); 03282 else 03283 cache->initial_sp 03284 = get_frame_register_unsigned (this_frame, fdata.alloca_reg); 03285 03286 return cache; 03287 } 03288 03289 static void 03290 rs6000_frame_this_id (struct frame_info *this_frame, void **this_cache, 03291 struct frame_id *this_id) 03292 { 03293 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame, 03294 this_cache); 03295 /* This marks the outermost frame. */ 03296 if (info->base == 0) 03297 return; 03298 03299 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); 03300 } 03301 03302 static struct value * 03303 rs6000_frame_prev_register (struct frame_info *this_frame, 03304 void **this_cache, int regnum) 03305 { 03306 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame, 03307 this_cache); 03308 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); 03309 } 03310 03311 static const struct frame_unwind rs6000_frame_unwind = 03312 { 03313 NORMAL_FRAME, 03314 default_frame_unwind_stop_reason, 03315 rs6000_frame_this_id, 03316 rs6000_frame_prev_register, 03317 NULL, 03318 default_frame_sniffer 03319 }; 03320 03321 03322 static CORE_ADDR 03323 rs6000_frame_base_address (struct frame_info *this_frame, void **this_cache) 03324 { 03325 struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame, 03326 this_cache); 03327 return info->initial_sp; 03328 } 03329 03330 static const struct frame_base rs6000_frame_base = { 03331 &rs6000_frame_unwind, 03332 rs6000_frame_base_address, 03333 rs6000_frame_base_address, 03334 rs6000_frame_base_address 03335 }; 03336 03337 static const struct frame_base * 03338 rs6000_frame_base_sniffer (struct frame_info *this_frame) 03339 { 03340 return &rs6000_frame_base; 03341 } 03342 03343 /* DWARF-2 frame support. Used to handle the detection of 03344 clobbered registers during function calls. */ 03345 03346 static void 03347 ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, 03348 struct dwarf2_frame_state_reg *reg, 03349 struct frame_info *this_frame) 03350 { 03351 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 03352 03353 /* PPC32 and PPC64 ABI's are the same regarding volatile and 03354 non-volatile registers. We will use the same code for both. */ 03355 03356 /* Call-saved GP registers. */ 03357 if ((regnum >= tdep->ppc_gp0_regnum + 14 03358 && regnum <= tdep->ppc_gp0_regnum + 31) 03359 || (regnum == tdep->ppc_gp0_regnum + 1)) 03360 reg->how = DWARF2_FRAME_REG_SAME_VALUE; 03361 03362 /* Call-clobbered GP registers. */ 03363 if ((regnum >= tdep->ppc_gp0_regnum + 3 03364 && regnum <= tdep->ppc_gp0_regnum + 12) 03365 || (regnum == tdep->ppc_gp0_regnum)) 03366 reg->how = DWARF2_FRAME_REG_UNDEFINED; 03367 03368 /* Deal with FP registers, if supported. */ 03369 if (tdep->ppc_fp0_regnum >= 0) 03370 { 03371 /* Call-saved FP registers. */ 03372 if ((regnum >= tdep->ppc_fp0_regnum + 14 03373 && regnum <= tdep->ppc_fp0_regnum + 31)) 03374 reg->how = DWARF2_FRAME_REG_SAME_VALUE; 03375 03376 /* Call-clobbered FP registers. */ 03377 if ((regnum >= tdep->ppc_fp0_regnum 03378 && regnum <= tdep->ppc_fp0_regnum + 13)) 03379 reg->how = DWARF2_FRAME_REG_UNDEFINED; 03380 } 03381 03382 /* Deal with ALTIVEC registers, if supported. */ 03383 if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0) 03384 { 03385 /* Call-saved Altivec registers. */ 03386 if ((regnum >= tdep->ppc_vr0_regnum + 20 03387 && regnum <= tdep->ppc_vr0_regnum + 31) 03388 || regnum == tdep->ppc_vrsave_regnum) 03389 reg->how = DWARF2_FRAME_REG_SAME_VALUE; 03390 03391 /* Call-clobbered Altivec registers. */ 03392 if ((regnum >= tdep->ppc_vr0_regnum 03393 && regnum <= tdep->ppc_vr0_regnum + 19)) 03394 reg->how = DWARF2_FRAME_REG_UNDEFINED; 03395 } 03396 03397 /* Handle PC register and Stack Pointer correctly. */ 03398 if (regnum == gdbarch_pc_regnum (gdbarch)) 03399 reg->how = DWARF2_FRAME_REG_RA; 03400 else if (regnum == gdbarch_sp_regnum (gdbarch)) 03401 reg->how = DWARF2_FRAME_REG_CFA; 03402 } 03403 03404 03405 /* Return true if a .gnu_attributes section exists in BFD and it 03406 indicates we are using SPE extensions OR if a .PPC.EMB.apuinfo 03407 section exists in BFD and it indicates that SPE extensions are in 03408 use. Check the .gnu.attributes section first, as the binary might be 03409 compiled for SPE, but not actually using SPE instructions. */ 03410 03411 static int 03412 bfd_uses_spe_extensions (bfd *abfd) 03413 { 03414 asection *sect; 03415 gdb_byte *contents = NULL; 03416 bfd_size_type size; 03417 gdb_byte *ptr; 03418 int success = 0; 03419 int vector_abi; 03420 03421 if (!abfd) 03422 return 0; 03423 03424 #ifdef HAVE_ELF 03425 /* Using Tag_GNU_Power_ABI_Vector here is a bit of a hack, as the user 03426 could be using the SPE vector abi without actually using any spe 03427 bits whatsoever. But it's close enough for now. */ 03428 vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU, 03429 Tag_GNU_Power_ABI_Vector); 03430 if (vector_abi == 3) 03431 return 1; 03432 #endif 03433 03434 sect = bfd_get_section_by_name (abfd, ".PPC.EMB.apuinfo"); 03435 if (!sect) 03436 return 0; 03437 03438 size = bfd_get_section_size (sect); 03439 contents = xmalloc (size); 03440 if (!bfd_get_section_contents (abfd, sect, contents, 0, size)) 03441 { 03442 xfree (contents); 03443 return 0; 03444 } 03445 03446 /* Parse the .PPC.EMB.apuinfo section. The layout is as follows: 03447 03448 struct { 03449 uint32 name_len; 03450 uint32 data_len; 03451 uint32 type; 03452 char name[name_len rounded up to 4-byte alignment]; 03453 char data[data_len]; 03454 }; 03455 03456 Technically, there's only supposed to be one such structure in a 03457 given apuinfo section, but the linker is not always vigilant about 03458 merging apuinfo sections from input files. Just go ahead and parse 03459 them all, exiting early when we discover the binary uses SPE 03460 insns. 03461 03462 It's not specified in what endianness the information in this 03463 section is stored. Assume that it's the endianness of the BFD. */ 03464 ptr = contents; 03465 while (1) 03466 { 03467 unsigned int name_len; 03468 unsigned int data_len; 03469 unsigned int type; 03470 03471 /* If we can't read the first three fields, we're done. */ 03472 if (size < 12) 03473 break; 03474 03475 name_len = bfd_get_32 (abfd, ptr); 03476 name_len = (name_len + 3) & ~3U; /* Round to 4 bytes. */ 03477 data_len = bfd_get_32 (abfd, ptr + 4); 03478 type = bfd_get_32 (abfd, ptr + 8); 03479 ptr += 12; 03480 03481 /* The name must be "APUinfo\0". */ 03482 if (name_len != 8 03483 && strcmp ((const char *) ptr, "APUinfo") != 0) 03484 break; 03485 ptr += name_len; 03486 03487 /* The type must be 2. */ 03488 if (type != 2) 03489 break; 03490 03491 /* The data is stored as a series of uint32. The upper half of 03492 each uint32 indicates the particular APU used and the lower 03493 half indicates the revision of that APU. We just care about 03494 the upper half. */ 03495 03496 /* Not 4-byte quantities. */ 03497 if (data_len & 3U) 03498 break; 03499 03500 while (data_len) 03501 { 03502 unsigned int apuinfo = bfd_get_32 (abfd, ptr); 03503 unsigned int apu = apuinfo >> 16; 03504 ptr += 4; 03505 data_len -= 4; 03506 03507 /* The SPE APU is 0x100; the SPEFP APU is 0x101. Accept 03508 either. */ 03509 if (apu == 0x100 || apu == 0x101) 03510 { 03511 success = 1; 03512 data_len = 0; 03513 } 03514 } 03515 03516 if (success) 03517 break; 03518 } 03519 03520 xfree (contents); 03521 return success; 03522 } 03523 03524 /* Initialize the current architecture based on INFO. If possible, re-use an 03525 architecture from ARCHES, which is a list of architectures already created 03526 during this debugging session. 03527 03528 Called e.g. at program startup, when reading a core file, and when reading 03529 a binary file. */ 03530 03531 static struct gdbarch * 03532 rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 03533 { 03534 struct gdbarch *gdbarch; 03535 struct gdbarch_tdep *tdep; 03536 int wordsize, from_xcoff_exec, from_elf_exec; 03537 enum bfd_architecture arch; 03538 unsigned long mach; 03539 bfd abfd; 03540 enum auto_boolean soft_float_flag = powerpc_soft_float_global; 03541 int soft_float; 03542 enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global; 03543 int have_fpu = 1, have_spe = 0, have_mq = 0, have_altivec = 0, have_dfp = 0, 03544 have_vsx = 0; 03545 int tdesc_wordsize = -1; 03546 const struct target_desc *tdesc = info.target_desc; 03547 struct tdesc_arch_data *tdesc_data = NULL; 03548 int num_pseudoregs = 0; 03549 int cur_reg; 03550 03551 /* INFO may refer to a binary that is not of the PowerPC architecture, 03552 e.g. when debugging a stand-alone SPE executable on a Cell/B.E. system. 03553 In this case, we must not attempt to infer properties of the (PowerPC 03554 side) of the target system from properties of that executable. Trust 03555 the target description instead. */ 03556 if (info.abfd 03557 && bfd_get_arch (info.abfd) != bfd_arch_powerpc 03558 && bfd_get_arch (info.abfd) != bfd_arch_rs6000) 03559 info.abfd = NULL; 03560 03561 from_xcoff_exec = info.abfd && info.abfd->format == bfd_object && 03562 bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour; 03563 03564 from_elf_exec = info.abfd && info.abfd->format == bfd_object && 03565 bfd_get_flavour (info.abfd) == bfd_target_elf_flavour; 03566 03567 /* Check word size. If INFO is from a binary file, infer it from 03568 that, else choose a likely default. */ 03569 if (from_xcoff_exec) 03570 { 03571 if (bfd_xcoff_is_xcoff64 (info.abfd)) 03572 wordsize = 8; 03573 else 03574 wordsize = 4; 03575 } 03576 else if (from_elf_exec) 03577 { 03578 if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) 03579 wordsize = 8; 03580 else 03581 wordsize = 4; 03582 } 03583 else if (tdesc_has_registers (tdesc)) 03584 wordsize = -1; 03585 else 03586 { 03587 if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0) 03588 wordsize = info.bfd_arch_info->bits_per_word / 03589 info.bfd_arch_info->bits_per_byte; 03590 else 03591 wordsize = 4; 03592 } 03593 03594 /* Get the architecture and machine from the BFD. */ 03595 arch = info.bfd_arch_info->arch; 03596 mach = info.bfd_arch_info->mach; 03597 03598 /* For e500 executables, the apuinfo section is of help here. Such 03599 section contains the identifier and revision number of each 03600 Application-specific Processing Unit that is present on the 03601 chip. The content of the section is determined by the assembler 03602 which looks at each instruction and determines which unit (and 03603 which version of it) can execute it. Grovel through the section 03604 looking for relevant e500 APUs. */ 03605 03606 if (bfd_uses_spe_extensions (info.abfd)) 03607 { 03608 arch = info.bfd_arch_info->arch; 03609 mach = bfd_mach_ppc_e500; 03610 bfd_default_set_arch_mach (&abfd, arch, mach); 03611 info.bfd_arch_info = bfd_get_arch_info (&abfd); 03612 } 03613 03614 /* Find a default target description which describes our register 03615 layout, if we do not already have one. */ 03616 if (! tdesc_has_registers (tdesc)) 03617 { 03618 const struct variant *v; 03619 03620 /* Choose variant. */ 03621 v = find_variant_by_arch (arch, mach); 03622 if (!v) 03623 return NULL; 03624 03625 tdesc = *v->tdesc; 03626 } 03627 03628 gdb_assert (tdesc_has_registers (tdesc)); 03629 03630 /* Check any target description for validity. */ 03631 if (tdesc_has_registers (tdesc)) 03632 { 03633 static const char *const gprs[] = { 03634 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 03635 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 03636 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 03637 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 03638 }; 03639 static const char *const segment_regs[] = { 03640 "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7", 03641 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15" 03642 }; 03643 const struct tdesc_feature *feature; 03644 int i, valid_p; 03645 static const char *const msr_names[] = { "msr", "ps" }; 03646 static const char *const cr_names[] = { "cr", "cnd" }; 03647 static const char *const ctr_names[] = { "ctr", "cnt" }; 03648 03649 feature = tdesc_find_feature (tdesc, 03650 "org.gnu.gdb.power.core"); 03651 if (feature == NULL) 03652 return NULL; 03653 03654 tdesc_data = tdesc_data_alloc (); 03655 03656 valid_p = 1; 03657 for (i = 0; i < ppc_num_gprs; i++) 03658 valid_p &= tdesc_numbered_register (feature, tdesc_data, i, gprs[i]); 03659 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_PC_REGNUM, 03660 "pc"); 03661 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_LR_REGNUM, 03662 "lr"); 03663 valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_XER_REGNUM, 03664 "xer"); 03665 03666 /* Allow alternate names for these registers, to accomodate GDB's 03667 historic naming. */ 03668 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data, 03669 PPC_MSR_REGNUM, msr_names); 03670 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data, 03671 PPC_CR_REGNUM, cr_names); 03672 valid_p &= tdesc_numbered_register_choices (feature, tdesc_data, 03673 PPC_CTR_REGNUM, ctr_names); 03674 03675 if (!valid_p) 03676 { 03677 tdesc_data_cleanup (tdesc_data); 03678 return NULL; 03679 } 03680 03681 have_mq = tdesc_numbered_register (feature, tdesc_data, PPC_MQ_REGNUM, 03682 "mq"); 03683 03684 tdesc_wordsize = tdesc_register_size (feature, "pc") / 8; 03685 if (wordsize == -1) 03686 wordsize = tdesc_wordsize; 03687 03688 feature = tdesc_find_feature (tdesc, 03689 "org.gnu.gdb.power.fpu"); 03690 if (feature != NULL) 03691 { 03692 static const char *const fprs[] = { 03693 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 03694 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 03695 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 03696 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31" 03697 }; 03698 valid_p = 1; 03699 for (i = 0; i < ppc_num_fprs; i++) 03700 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03701 PPC_F0_REGNUM + i, fprs[i]); 03702 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03703 PPC_FPSCR_REGNUM, "fpscr"); 03704 03705 if (!valid_p) 03706 { 03707 tdesc_data_cleanup (tdesc_data); 03708 return NULL; 03709 } 03710 have_fpu = 1; 03711 } 03712 else 03713 have_fpu = 0; 03714 03715 /* The DFP pseudo-registers will be available when there are floating 03716 point registers. */ 03717 have_dfp = have_fpu; 03718 03719 feature = tdesc_find_feature (tdesc, 03720 "org.gnu.gdb.power.altivec"); 03721 if (feature != NULL) 03722 { 03723 static const char *const vector_regs[] = { 03724 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7", 03725 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15", 03726 "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23", 03727 "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31" 03728 }; 03729 03730 valid_p = 1; 03731 for (i = 0; i < ppc_num_gprs; i++) 03732 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03733 PPC_VR0_REGNUM + i, 03734 vector_regs[i]); 03735 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03736 PPC_VSCR_REGNUM, "vscr"); 03737 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03738 PPC_VRSAVE_REGNUM, "vrsave"); 03739 03740 if (have_spe || !valid_p) 03741 { 03742 tdesc_data_cleanup (tdesc_data); 03743 return NULL; 03744 } 03745 have_altivec = 1; 03746 } 03747 else 03748 have_altivec = 0; 03749 03750 /* Check for POWER7 VSX registers support. */ 03751 feature = tdesc_find_feature (tdesc, 03752 "org.gnu.gdb.power.vsx"); 03753 03754 if (feature != NULL) 03755 { 03756 static const char *const vsx_regs[] = { 03757 "vs0h", "vs1h", "vs2h", "vs3h", "vs4h", "vs5h", 03758 "vs6h", "vs7h", "vs8h", "vs9h", "vs10h", "vs11h", 03759 "vs12h", "vs13h", "vs14h", "vs15h", "vs16h", "vs17h", 03760 "vs18h", "vs19h", "vs20h", "vs21h", "vs22h", "vs23h", 03761 "vs24h", "vs25h", "vs26h", "vs27h", "vs28h", "vs29h", 03762 "vs30h", "vs31h" 03763 }; 03764 03765 valid_p = 1; 03766 03767 for (i = 0; i < ppc_num_vshrs; i++) 03768 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03769 PPC_VSR0_UPPER_REGNUM + i, 03770 vsx_regs[i]); 03771 if (!valid_p) 03772 { 03773 tdesc_data_cleanup (tdesc_data); 03774 return NULL; 03775 } 03776 03777 have_vsx = 1; 03778 } 03779 else 03780 have_vsx = 0; 03781 03782 /* On machines supporting the SPE APU, the general-purpose registers 03783 are 64 bits long. There are SIMD vector instructions to treat them 03784 as pairs of floats, but the rest of the instruction set treats them 03785 as 32-bit registers, and only operates on their lower halves. 03786 03787 In the GDB regcache, we treat their high and low halves as separate 03788 registers. The low halves we present as the general-purpose 03789 registers, and then we have pseudo-registers that stitch together 03790 the upper and lower halves and present them as pseudo-registers. 03791 03792 Thus, the target description is expected to supply the upper 03793 halves separately. */ 03794 03795 feature = tdesc_find_feature (tdesc, 03796 "org.gnu.gdb.power.spe"); 03797 if (feature != NULL) 03798 { 03799 static const char *const upper_spe[] = { 03800 "ev0h", "ev1h", "ev2h", "ev3h", 03801 "ev4h", "ev5h", "ev6h", "ev7h", 03802 "ev8h", "ev9h", "ev10h", "ev11h", 03803 "ev12h", "ev13h", "ev14h", "ev15h", 03804 "ev16h", "ev17h", "ev18h", "ev19h", 03805 "ev20h", "ev21h", "ev22h", "ev23h", 03806 "ev24h", "ev25h", "ev26h", "ev27h", 03807 "ev28h", "ev29h", "ev30h", "ev31h" 03808 }; 03809 03810 valid_p = 1; 03811 for (i = 0; i < ppc_num_gprs; i++) 03812 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03813 PPC_SPE_UPPER_GP0_REGNUM + i, 03814 upper_spe[i]); 03815 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03816 PPC_SPE_ACC_REGNUM, "acc"); 03817 valid_p &= tdesc_numbered_register (feature, tdesc_data, 03818 PPC_SPE_FSCR_REGNUM, "spefscr"); 03819 03820 if (have_mq || have_fpu || !valid_p) 03821 { 03822 tdesc_data_cleanup (tdesc_data); 03823 return NULL; 03824 } 03825 have_spe = 1; 03826 } 03827 else 03828 have_spe = 0; 03829 } 03830 03831 /* If we have a 64-bit binary on a 32-bit target, complain. Also 03832 complain for a 32-bit binary on a 64-bit target; we do not yet 03833 support that. For instance, the 32-bit ABI routines expect 03834 32-bit GPRs. 03835 03836 As long as there isn't an explicit target description, we'll 03837 choose one based on the BFD architecture and get a word size 03838 matching the binary (probably powerpc:common or 03839 powerpc:common64). So there is only trouble if a 64-bit target 03840 supplies a 64-bit description while debugging a 32-bit 03841 binary. */ 03842 if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize) 03843 { 03844 tdesc_data_cleanup (tdesc_data); 03845 return NULL; 03846 } 03847 03848 #ifdef HAVE_ELF 03849 if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec) 03850 { 03851 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, 03852 Tag_GNU_Power_ABI_FP)) 03853 { 03854 case 1: 03855 soft_float_flag = AUTO_BOOLEAN_FALSE; 03856 break; 03857 case 2: 03858 soft_float_flag = AUTO_BOOLEAN_TRUE; 03859 break; 03860 default: 03861 break; 03862 } 03863 } 03864 03865 if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec) 03866 { 03867 switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, 03868 Tag_GNU_Power_ABI_Vector)) 03869 { 03870 case 1: 03871 vector_abi = POWERPC_VEC_GENERIC; 03872 break; 03873 case 2: 03874 vector_abi = POWERPC_VEC_ALTIVEC; 03875 break; 03876 case 3: 03877 vector_abi = POWERPC_VEC_SPE; 03878 break; 03879 default: 03880 break; 03881 } 03882 } 03883 #endif 03884 03885 if (soft_float_flag == AUTO_BOOLEAN_TRUE) 03886 soft_float = 1; 03887 else if (soft_float_flag == AUTO_BOOLEAN_FALSE) 03888 soft_float = 0; 03889 else 03890 soft_float = !have_fpu; 03891 03892 /* If we have a hard float binary or setting but no floating point 03893 registers, downgrade to soft float anyway. We're still somewhat 03894 useful in this scenario. */ 03895 if (!soft_float && !have_fpu) 03896 soft_float = 1; 03897 03898 /* Similarly for vector registers. */ 03899 if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec) 03900 vector_abi = POWERPC_VEC_GENERIC; 03901 03902 if (vector_abi == POWERPC_VEC_SPE && !have_spe) 03903 vector_abi = POWERPC_VEC_GENERIC; 03904 03905 if (vector_abi == POWERPC_VEC_AUTO) 03906 { 03907 if (have_altivec) 03908 vector_abi = POWERPC_VEC_ALTIVEC; 03909 else if (have_spe) 03910 vector_abi = POWERPC_VEC_SPE; 03911 else 03912 vector_abi = POWERPC_VEC_GENERIC; 03913 } 03914 03915 /* Do not limit the vector ABI based on available hardware, since we 03916 do not yet know what hardware we'll decide we have. Yuck! FIXME! */ 03917 03918 /* Find a candidate among extant architectures. */ 03919 for (arches = gdbarch_list_lookup_by_info (arches, &info); 03920 arches != NULL; 03921 arches = gdbarch_list_lookup_by_info (arches->next, &info)) 03922 { 03923 /* Word size in the various PowerPC bfd_arch_info structs isn't 03924 meaningful, because 64-bit CPUs can run in 32-bit mode. So, perform 03925 separate word size check. */ 03926 tdep = gdbarch_tdep (arches->gdbarch); 03927 if (tdep && tdep->soft_float != soft_float) 03928 continue; 03929 if (tdep && tdep->vector_abi != vector_abi) 03930 continue; 03931 if (tdep && tdep->wordsize == wordsize) 03932 { 03933 if (tdesc_data != NULL) 03934 tdesc_data_cleanup (tdesc_data); 03935 return arches->gdbarch; 03936 } 03937 } 03938 03939 /* None found, create a new architecture from INFO, whose bfd_arch_info 03940 validity depends on the source: 03941 - executable useless 03942 - rs6000_host_arch() good 03943 - core file good 03944 - "set arch" trust blindly 03945 - GDB startup useless but harmless */ 03946 03947 tdep = XCALLOC (1, struct gdbarch_tdep); 03948 tdep->wordsize = wordsize; 03949 tdep->soft_float = soft_float; 03950 tdep->vector_abi = vector_abi; 03951 03952 gdbarch = gdbarch_alloc (&info, tdep); 03953 03954 tdep->ppc_gp0_regnum = PPC_R0_REGNUM; 03955 tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2; 03956 tdep->ppc_ps_regnum = PPC_MSR_REGNUM; 03957 tdep->ppc_cr_regnum = PPC_CR_REGNUM; 03958 tdep->ppc_lr_regnum = PPC_LR_REGNUM; 03959 tdep->ppc_ctr_regnum = PPC_CTR_REGNUM; 03960 tdep->ppc_xer_regnum = PPC_XER_REGNUM; 03961 tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1; 03962 03963 tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1; 03964 tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1; 03965 tdep->ppc_vsr0_upper_regnum = have_vsx ? PPC_VSR0_UPPER_REGNUM : -1; 03966 tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1; 03967 tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1; 03968 tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1; 03969 tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1; 03970 tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1; 03971 03972 set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM); 03973 set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1); 03974 set_gdbarch_deprecated_fp_regnum (gdbarch, PPC_R0_REGNUM + 1); 03975 set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum); 03976 set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno); 03977 03978 /* The XML specification for PowerPC sensibly calls the MSR "msr". 03979 GDB traditionally called it "ps", though, so let GDB add an 03980 alias. */ 03981 set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum); 03982 03983 if (wordsize == 8) 03984 set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value); 03985 else 03986 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value); 03987 03988 /* Set lr_frame_offset. */ 03989 if (wordsize == 8) 03990 tdep->lr_frame_offset = 16; 03991 else 03992 tdep->lr_frame_offset = 4; 03993 03994 if (have_spe || have_dfp || have_vsx) 03995 { 03996 set_gdbarch_pseudo_register_read (gdbarch, rs6000_pseudo_register_read); 03997 set_gdbarch_pseudo_register_write (gdbarch, 03998 rs6000_pseudo_register_write); 03999 } 04000 04001 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); 04002 04003 /* Select instruction printer. */ 04004 if (arch == bfd_arch_rs6000) 04005 set_gdbarch_print_insn (gdbarch, print_insn_rs6000); 04006 else 04007 set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc); 04008 04009 set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS); 04010 04011 if (have_spe) 04012 num_pseudoregs += 32; 04013 if (have_dfp) 04014 num_pseudoregs += 16; 04015 if (have_vsx) 04016 /* Include both VSX and Extended FP registers. */ 04017 num_pseudoregs += 96; 04018 04019 set_gdbarch_num_pseudo_regs (gdbarch, num_pseudoregs); 04020 04021 set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT); 04022 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); 04023 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT); 04024 set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT); 04025 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); 04026 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); 04027 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 04028 set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT); 04029 set_gdbarch_char_signed (gdbarch, 0); 04030 04031 set_gdbarch_frame_align (gdbarch, rs6000_frame_align); 04032 if (wordsize == 8) 04033 /* PPC64 SYSV. */ 04034 set_gdbarch_frame_red_zone_size (gdbarch, 288); 04035 04036 set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p); 04037 set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value); 04038 set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register); 04039 04040 set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum); 04041 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum); 04042 04043 if (wordsize == 4) 04044 set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call); 04045 else if (wordsize == 8) 04046 set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call); 04047 04048 set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue); 04049 set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p); 04050 set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue); 04051 04052 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 04053 set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc); 04054 04055 /* The value of symbols of type N_SO and N_FUN maybe null when 04056 it shouldn't be. */ 04057 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1); 04058 04059 /* Handles single stepping of atomic sequences. */ 04060 set_gdbarch_software_single_step (gdbarch, ppc_deal_with_atomic_sequence); 04061 04062 /* Not sure on this. FIXMEmgo */ 04063 set_gdbarch_frame_args_skip (gdbarch, 8); 04064 04065 /* Helpers for function argument information. */ 04066 set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument); 04067 04068 /* Trampoline. */ 04069 set_gdbarch_in_solib_return_trampoline 04070 (gdbarch, rs6000_in_solib_return_trampoline); 04071 set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code); 04072 04073 /* Hook in the DWARF CFI frame unwinder. */ 04074 dwarf2_append_unwinders (gdbarch); 04075 dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum); 04076 04077 /* Frame handling. */ 04078 dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg); 04079 04080 /* Setup displaced stepping. */ 04081 set_gdbarch_displaced_step_copy_insn (gdbarch, 04082 simple_displaced_step_copy_insn); 04083 set_gdbarch_displaced_step_hw_singlestep (gdbarch, 04084 ppc_displaced_step_hw_singlestep); 04085 set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup); 04086 set_gdbarch_displaced_step_free_closure (gdbarch, 04087 simple_displaced_step_free_closure); 04088 set_gdbarch_displaced_step_location (gdbarch, 04089 displaced_step_at_entry_point); 04090 04091 set_gdbarch_max_insn_length (gdbarch, PPC_INSN_SIZE); 04092 04093 /* Hook in ABI-specific overrides, if they have been registered. */ 04094 info.target_desc = tdesc; 04095 info.tdep_info = (void *) tdesc_data; 04096 gdbarch_init_osabi (info, gdbarch); 04097 04098 switch (info.osabi) 04099 { 04100 case GDB_OSABI_LINUX: 04101 case GDB_OSABI_NETBSD_AOUT: 04102 case GDB_OSABI_NETBSD_ELF: 04103 case GDB_OSABI_UNKNOWN: 04104 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc); 04105 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind); 04106 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id); 04107 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer); 04108 break; 04109 default: 04110 set_gdbarch_believe_pcc_promotion (gdbarch, 1); 04111 04112 set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc); 04113 frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind); 04114 set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id); 04115 frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer); 04116 } 04117 04118 set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type); 04119 set_tdesc_pseudo_register_reggroup_p (gdbarch, 04120 rs6000_pseudo_register_reggroup_p); 04121 tdesc_use_registers (gdbarch, tdesc, tdesc_data); 04122 04123 /* Override the normal target description method to make the SPE upper 04124 halves anonymous. */ 04125 set_gdbarch_register_name (gdbarch, rs6000_register_name); 04126 04127 /* Choose register numbers for all supported pseudo-registers. */ 04128 tdep->ppc_ev0_regnum = -1; 04129 tdep->ppc_dl0_regnum = -1; 04130 tdep->ppc_vsr0_regnum = -1; 04131 tdep->ppc_efpr0_regnum = -1; 04132 04133 cur_reg = gdbarch_num_regs (gdbarch); 04134 04135 if (have_spe) 04136 { 04137 tdep->ppc_ev0_regnum = cur_reg; 04138 cur_reg += 32; 04139 } 04140 if (have_dfp) 04141 { 04142 tdep->ppc_dl0_regnum = cur_reg; 04143 cur_reg += 16; 04144 } 04145 if (have_vsx) 04146 { 04147 tdep->ppc_vsr0_regnum = cur_reg; 04148 cur_reg += 64; 04149 tdep->ppc_efpr0_regnum = cur_reg; 04150 cur_reg += 32; 04151 } 04152 04153 gdb_assert (gdbarch_num_regs (gdbarch) 04154 + gdbarch_num_pseudo_regs (gdbarch) == cur_reg); 04155 04156 /* Register the ravenscar_arch_ops. */ 04157 if (mach == bfd_mach_ppc_e500) 04158 register_e500_ravenscar_ops (gdbarch); 04159 else 04160 register_ppc_ravenscar_ops (gdbarch); 04161 04162 return gdbarch; 04163 } 04164 04165 static void 04166 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) 04167 { 04168 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 04169 04170 if (tdep == NULL) 04171 return; 04172 04173 /* FIXME: Dump gdbarch_tdep. */ 04174 } 04175 04176 /* PowerPC-specific commands. */ 04177 04178 static void 04179 set_powerpc_command (char *args, int from_tty) 04180 { 04181 printf_unfiltered (_("\ 04182 \"set powerpc\" must be followed by an appropriate subcommand.\n")); 04183 help_list (setpowerpccmdlist, "set powerpc ", all_commands, gdb_stdout); 04184 } 04185 04186 static void 04187 show_powerpc_command (char *args, int from_tty) 04188 { 04189 cmd_show_list (showpowerpccmdlist, from_tty, ""); 04190 } 04191 04192 static void 04193 powerpc_set_soft_float (char *args, int from_tty, 04194 struct cmd_list_element *c) 04195 { 04196 struct gdbarch_info info; 04197 04198 /* Update the architecture. */ 04199 gdbarch_info_init (&info); 04200 if (!gdbarch_update_p (info)) 04201 internal_error (__FILE__, __LINE__, _("could not update architecture")); 04202 } 04203 04204 static void 04205 powerpc_set_vector_abi (char *args, int from_tty, 04206 struct cmd_list_element *c) 04207 { 04208 struct gdbarch_info info; 04209 enum powerpc_vector_abi vector_abi; 04210 04211 for (vector_abi = POWERPC_VEC_AUTO; 04212 vector_abi != POWERPC_VEC_LAST; 04213 vector_abi++) 04214 if (strcmp (powerpc_vector_abi_string, 04215 powerpc_vector_strings[vector_abi]) == 0) 04216 { 04217 powerpc_vector_abi_global = vector_abi; 04218 break; 04219 } 04220 04221 if (vector_abi == POWERPC_VEC_LAST) 04222 internal_error (__FILE__, __LINE__, _("Invalid vector ABI accepted: %s."), 04223 powerpc_vector_abi_string); 04224 04225 /* Update the architecture. */ 04226 gdbarch_info_init (&info); 04227 if (!gdbarch_update_p (info)) 04228 internal_error (__FILE__, __LINE__, _("could not update architecture")); 04229 } 04230 04231 /* Show the current setting of the exact watchpoints flag. */ 04232 04233 static void 04234 show_powerpc_exact_watchpoints (struct ui_file *file, int from_tty, 04235 struct cmd_list_element *c, 04236 const char *value) 04237 { 04238 fprintf_filtered (file, _("Use of exact watchpoints is %s.\n"), value); 04239 } 04240 04241 /* Read a PPC instruction from memory. */ 04242 04243 static unsigned int 04244 read_insn (struct frame_info *frame, CORE_ADDR pc) 04245 { 04246 struct gdbarch *gdbarch = get_frame_arch (frame); 04247 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 04248 04249 return read_memory_unsigned_integer (pc, 4, byte_order); 04250 } 04251 04252 /* Return non-zero if the instructions at PC match the series 04253 described in PATTERN, or zero otherwise. PATTERN is an array of 04254 'struct ppc_insn_pattern' objects, terminated by an entry whose 04255 mask is zero. 04256 04257 When the match is successful, fill INSN[i] with what PATTERN[i] 04258 matched. If PATTERN[i] is optional, and the instruction wasn't 04259 present, set INSN[i] to 0 (which is not a valid PPC instruction). 04260 INSN should have as many elements as PATTERN. Note that, if 04261 PATTERN contains optional instructions which aren't present in 04262 memory, then INSN will have holes, so INSN[i] isn't necessarily the 04263 i'th instruction in memory. */ 04264 04265 int 04266 ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc, 04267 struct ppc_insn_pattern *pattern, 04268 unsigned int *insns) 04269 { 04270 int i; 04271 unsigned int insn; 04272 04273 for (i = 0, insn = 0; pattern[i].mask; i++) 04274 { 04275 if (insn == 0) 04276 insn = read_insn (frame, pc); 04277 insns[i] = 0; 04278 if ((insn & pattern[i].mask) == pattern[i].data) 04279 { 04280 insns[i] = insn; 04281 pc += 4; 04282 insn = 0; 04283 } 04284 else if (!pattern[i].optional) 04285 return 0; 04286 } 04287 04288 return 1; 04289 } 04290 04291 /* Return the 'd' field of the d-form instruction INSN, properly 04292 sign-extended. */ 04293 04294 CORE_ADDR 04295 ppc_insn_d_field (unsigned int insn) 04296 { 04297 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000); 04298 } 04299 04300 /* Return the 'ds' field of the ds-form instruction INSN, with the two 04301 zero bits concatenated at the right, and properly 04302 sign-extended. */ 04303 04304 CORE_ADDR 04305 ppc_insn_ds_field (unsigned int insn) 04306 { 04307 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000); 04308 } 04309 04310 /* Initialization code. */ 04311 04312 /* -Wmissing-prototypes */ 04313 extern initialize_file_ftype _initialize_rs6000_tdep; 04314 04315 void 04316 _initialize_rs6000_tdep (void) 04317 { 04318 gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep); 04319 gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep); 04320 04321 /* Initialize the standard target descriptions. */ 04322 initialize_tdesc_powerpc_32 (); 04323 initialize_tdesc_powerpc_altivec32 (); 04324 initialize_tdesc_powerpc_vsx32 (); 04325 initialize_tdesc_powerpc_403 (); 04326 initialize_tdesc_powerpc_403gc (); 04327 initialize_tdesc_powerpc_405 (); 04328 initialize_tdesc_powerpc_505 (); 04329 initialize_tdesc_powerpc_601 (); 04330 initialize_tdesc_powerpc_602 (); 04331 initialize_tdesc_powerpc_603 (); 04332 initialize_tdesc_powerpc_604 (); 04333 initialize_tdesc_powerpc_64 (); 04334 initialize_tdesc_powerpc_altivec64 (); 04335 initialize_tdesc_powerpc_vsx64 (); 04336 initialize_tdesc_powerpc_7400 (); 04337 initialize_tdesc_powerpc_750 (); 04338 initialize_tdesc_powerpc_860 (); 04339 initialize_tdesc_powerpc_e500 (); 04340 initialize_tdesc_rs6000 (); 04341 04342 /* Add root prefix command for all "set powerpc"/"show powerpc" 04343 commands. */ 04344 add_prefix_cmd ("powerpc", no_class, set_powerpc_command, 04345 _("Various PowerPC-specific commands."), 04346 &setpowerpccmdlist, "set powerpc ", 0, &setlist); 04347 04348 add_prefix_cmd ("powerpc", no_class, show_powerpc_command, 04349 _("Various PowerPC-specific commands."), 04350 &showpowerpccmdlist, "show powerpc ", 0, &showlist); 04351 04352 /* Add a command to allow the user to force the ABI. */ 04353 add_setshow_auto_boolean_cmd ("soft-float", class_support, 04354 &powerpc_soft_float_global, 04355 _("Set whether to use a soft-float ABI."), 04356 _("Show whether to use a soft-float ABI."), 04357 NULL, 04358 powerpc_set_soft_float, NULL, 04359 &setpowerpccmdlist, &showpowerpccmdlist); 04360 04361 add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings, 04362 &powerpc_vector_abi_string, 04363 _("Set the vector ABI."), 04364 _("Show the vector ABI."), 04365 NULL, powerpc_set_vector_abi, NULL, 04366 &setpowerpccmdlist, &showpowerpccmdlist); 04367 04368 add_setshow_boolean_cmd ("exact-watchpoints", class_support, 04369 &target_exact_watchpoints, 04370 _("\ 04371 Set whether to use just one debug register for watchpoints on scalars."), 04372 _("\ 04373 Show whether to use just one debug register for watchpoints on scalars."), 04374 _("\ 04375 If true, GDB will use only one debug register when watching a variable of\n\ 04376 scalar type, thus assuming that the variable is accessed through the address\n\ 04377 of its first byte."), 04378 NULL, show_powerpc_exact_watchpoints, 04379 &setpowerpccmdlist, &showpowerpccmdlist); 04380 }