GDB (API)
|
00001 /* Target-dependent code for the NEC V850 for GDB, the GNU debugger. 00002 00003 Copyright (C) 1996-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 "frame-base.h" 00023 #include "trad-frame.h" 00024 #include "frame-unwind.h" 00025 #include "dwarf2-frame.h" 00026 #include "gdbtypes.h" 00027 #include "inferior.h" 00028 #include "gdb_string.h" 00029 #include "gdb_assert.h" 00030 #include "gdbcore.h" 00031 #include "arch-utils.h" 00032 #include "regcache.h" 00033 #include "dis-asm.h" 00034 #include "osabi.h" 00035 #include "elf-bfd.h" 00036 #include "elf/v850.h" 00037 00038 enum 00039 { 00040 /* General purpose registers. */ 00041 E_R0_REGNUM, 00042 E_R1_REGNUM, 00043 E_R2_REGNUM, 00044 E_R3_REGNUM, E_SP_REGNUM = E_R3_REGNUM, 00045 E_R4_REGNUM, 00046 E_R5_REGNUM, 00047 E_R6_REGNUM, E_ARG0_REGNUM = E_R6_REGNUM, 00048 E_R7_REGNUM, 00049 E_R8_REGNUM, 00050 E_R9_REGNUM, E_ARGLAST_REGNUM = E_R9_REGNUM, 00051 E_R10_REGNUM, E_V0_REGNUM = E_R10_REGNUM, 00052 E_R11_REGNUM, E_V1_REGNUM = E_R11_REGNUM, 00053 E_R12_REGNUM, 00054 E_R13_REGNUM, 00055 E_R14_REGNUM, 00056 E_R15_REGNUM, 00057 E_R16_REGNUM, 00058 E_R17_REGNUM, 00059 E_R18_REGNUM, 00060 E_R19_REGNUM, 00061 E_R20_REGNUM, 00062 E_R21_REGNUM, 00063 E_R22_REGNUM, 00064 E_R23_REGNUM, 00065 E_R24_REGNUM, 00066 E_R25_REGNUM, 00067 E_R26_REGNUM, 00068 E_R27_REGNUM, 00069 E_R28_REGNUM, 00070 E_R29_REGNUM, E_FP_REGNUM = E_R29_REGNUM, 00071 E_R30_REGNUM, E_EP_REGNUM = E_R30_REGNUM, 00072 E_R31_REGNUM, E_LP_REGNUM = E_R31_REGNUM, 00073 00074 /* System registers - main banks. */ 00075 E_R32_REGNUM, E_SR0_REGNUM = E_R32_REGNUM, 00076 E_R33_REGNUM, 00077 E_R34_REGNUM, 00078 E_R35_REGNUM, 00079 E_R36_REGNUM, 00080 E_R37_REGNUM, E_PS_REGNUM = E_R37_REGNUM, 00081 E_R38_REGNUM, 00082 E_R39_REGNUM, 00083 E_R40_REGNUM, 00084 E_R41_REGNUM, 00085 E_R42_REGNUM, 00086 E_R43_REGNUM, 00087 E_R44_REGNUM, 00088 E_R45_REGNUM, 00089 E_R46_REGNUM, 00090 E_R47_REGNUM, 00091 E_R48_REGNUM, 00092 E_R49_REGNUM, 00093 E_R50_REGNUM, 00094 E_R51_REGNUM, 00095 E_R52_REGNUM, E_CTBP_REGNUM = E_R52_REGNUM, 00096 E_R53_REGNUM, 00097 E_R54_REGNUM, 00098 E_R55_REGNUM, 00099 E_R56_REGNUM, 00100 E_R57_REGNUM, 00101 E_R58_REGNUM, 00102 E_R59_REGNUM, 00103 E_R60_REGNUM, 00104 E_R61_REGNUM, 00105 E_R62_REGNUM, 00106 E_R63_REGNUM, 00107 00108 /* PC. */ 00109 E_R64_REGNUM, E_PC_REGNUM = E_R64_REGNUM, 00110 E_R65_REGNUM, 00111 E_NUM_OF_V850_REGS, 00112 E_NUM_OF_V850E_REGS = E_NUM_OF_V850_REGS, 00113 00114 /* System registers - MPV (PROT00) bank. */ 00115 E_R66_REGNUM = E_NUM_OF_V850_REGS, 00116 E_R67_REGNUM, 00117 E_R68_REGNUM, 00118 E_R69_REGNUM, 00119 E_R70_REGNUM, 00120 E_R71_REGNUM, 00121 E_R72_REGNUM, 00122 E_R73_REGNUM, 00123 E_R74_REGNUM, 00124 E_R75_REGNUM, 00125 E_R76_REGNUM, 00126 E_R77_REGNUM, 00127 E_R78_REGNUM, 00128 E_R79_REGNUM, 00129 E_R80_REGNUM, 00130 E_R81_REGNUM, 00131 E_R82_REGNUM, 00132 E_R83_REGNUM, 00133 E_R84_REGNUM, 00134 E_R85_REGNUM, 00135 E_R86_REGNUM, 00136 E_R87_REGNUM, 00137 E_R88_REGNUM, 00138 E_R89_REGNUM, 00139 E_R90_REGNUM, 00140 E_R91_REGNUM, 00141 E_R92_REGNUM, 00142 E_R93_REGNUM, 00143 00144 /* System registers - MPU (PROT01) bank. */ 00145 E_R94_REGNUM, 00146 E_R95_REGNUM, 00147 E_R96_REGNUM, 00148 E_R97_REGNUM, 00149 E_R98_REGNUM, 00150 E_R99_REGNUM, 00151 E_R100_REGNUM, 00152 E_R101_REGNUM, 00153 E_R102_REGNUM, 00154 E_R103_REGNUM, 00155 E_R104_REGNUM, 00156 E_R105_REGNUM, 00157 E_R106_REGNUM, 00158 E_R107_REGNUM, 00159 E_R108_REGNUM, 00160 E_R109_REGNUM, 00161 E_R110_REGNUM, 00162 E_R111_REGNUM, 00163 E_R112_REGNUM, 00164 E_R113_REGNUM, 00165 E_R114_REGNUM, 00166 E_R115_REGNUM, 00167 E_R116_REGNUM, 00168 E_R117_REGNUM, 00169 E_R118_REGNUM, 00170 E_R119_REGNUM, 00171 E_R120_REGNUM, 00172 E_R121_REGNUM, 00173 00174 /* FPU system registers. */ 00175 E_R122_REGNUM, 00176 E_R123_REGNUM, 00177 E_R124_REGNUM, 00178 E_R125_REGNUM, 00179 E_R126_REGNUM, 00180 E_R127_REGNUM, 00181 E_R128_REGNUM, E_FPSR_REGNUM = E_R128_REGNUM, 00182 E_R129_REGNUM, E_FPEPC_REGNUM = E_R129_REGNUM, 00183 E_R130_REGNUM, E_FPST_REGNUM = E_R130_REGNUM, 00184 E_R131_REGNUM, E_FPCC_REGNUM = E_R131_REGNUM, 00185 E_R132_REGNUM, E_FPCFG_REGNUM = E_R132_REGNUM, 00186 E_R133_REGNUM, 00187 E_R134_REGNUM, 00188 E_R135_REGNUM, 00189 E_R136_REGNUM, 00190 E_R137_REGNUM, 00191 E_R138_REGNUM, 00192 E_R139_REGNUM, 00193 E_R140_REGNUM, 00194 E_R141_REGNUM, 00195 E_R142_REGNUM, 00196 E_R143_REGNUM, 00197 E_R144_REGNUM, 00198 E_R145_REGNUM, 00199 E_R146_REGNUM, 00200 E_R147_REGNUM, 00201 E_R148_REGNUM, 00202 E_R149_REGNUM, 00203 E_NUM_OF_V850E2_REGS, 00204 00205 /* v850e3v5 system registers, selID 1 thru 7. */ 00206 E_SELID_1_R0_REGNUM = E_NUM_OF_V850E2_REGS, 00207 E_SELID_1_R31_REGNUM = E_SELID_1_R0_REGNUM + 31, 00208 00209 E_SELID_2_R0_REGNUM, 00210 E_SELID_2_R31_REGNUM = E_SELID_2_R0_REGNUM + 31, 00211 00212 E_SELID_3_R0_REGNUM, 00213 E_SELID_3_R31_REGNUM = E_SELID_3_R0_REGNUM + 31, 00214 00215 E_SELID_4_R0_REGNUM, 00216 E_SELID_4_R31_REGNUM = E_SELID_4_R0_REGNUM + 31, 00217 00218 E_SELID_5_R0_REGNUM, 00219 E_SELID_5_R31_REGNUM = E_SELID_5_R0_REGNUM + 31, 00220 00221 E_SELID_6_R0_REGNUM, 00222 E_SELID_6_R31_REGNUM = E_SELID_6_R0_REGNUM + 31, 00223 00224 E_SELID_7_R0_REGNUM, 00225 E_SELID_7_R31_REGNUM = E_SELID_7_R0_REGNUM + 31, 00226 00227 /* v850e3v5 vector registers. */ 00228 E_VR0_REGNUM, 00229 E_VR31_REGNUM = E_VR0_REGNUM + 31, 00230 00231 E_NUM_OF_V850E3V5_REGS, 00232 00233 /* Total number of possible registers. */ 00234 E_NUM_REGS = E_NUM_OF_V850E3V5_REGS 00235 }; 00236 00237 enum 00238 { 00239 v850_reg_size = 4 00240 }; 00241 00242 /* Size of return datatype which fits into all return registers. */ 00243 enum 00244 { 00245 E_MAX_RETTYPE_SIZE_IN_REGS = 2 * v850_reg_size 00246 }; 00247 00248 /* When v850 support was added to GCC in the late nineties, the intention 00249 was to follow the Green Hills ABI for v850. In fact, the authors of 00250 that support at the time thought that they were doing so. As far as 00251 I can tell, the calling conventions are correct, but the return value 00252 conventions were not quite right. Over time, the return value code 00253 in this file was modified to mostly reflect what GCC was actually 00254 doing instead of to actually follow the Green Hills ABI as it did 00255 when the code was first written. 00256 00257 Renesas defined the RH850 ABI which they use in their compiler. It 00258 is similar to the original Green Hills ABI with some minor 00259 differences. */ 00260 00261 enum v850_abi 00262 { 00263 V850_ABI_GCC, 00264 V850_ABI_RH850 00265 }; 00266 00267 /* Architecture specific data. */ 00268 00269 struct gdbarch_tdep 00270 { 00271 /* Fields from the ELF header. */ 00272 int e_flags; 00273 int e_machine; 00274 00275 /* Which ABI are we using? */ 00276 enum v850_abi abi; 00277 int eight_byte_align; 00278 }; 00279 00280 struct v850_frame_cache 00281 { 00282 /* Base address. */ 00283 CORE_ADDR base; 00284 LONGEST sp_offset; 00285 CORE_ADDR pc; 00286 00287 /* Flag showing that a frame has been created in the prologue code. */ 00288 int uses_fp; 00289 00290 /* Saved registers. */ 00291 struct trad_frame_saved_reg *saved_regs; 00292 }; 00293 00294 /* Info gleaned from scanning a function's prologue. */ 00295 struct pifsr /* Info about one saved register. */ 00296 { 00297 int offset; /* Offset from sp or fp. */ 00298 int cur_frameoffset; /* Current frameoffset. */ 00299 int reg; /* Saved register number. */ 00300 }; 00301 00302 static const char * 00303 v850_register_name (struct gdbarch *gdbarch, int regnum) 00304 { 00305 static const char *v850_reg_names[] = 00306 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00307 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 00308 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 00309 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 00310 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7", 00311 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15", 00312 "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23", 00313 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31", 00314 "pc", "fp" 00315 }; 00316 if (regnum < 0 || regnum > E_NUM_OF_V850_REGS) 00317 return NULL; 00318 return v850_reg_names[regnum]; 00319 } 00320 00321 static const char * 00322 v850e_register_name (struct gdbarch *gdbarch, int regnum) 00323 { 00324 static const char *v850e_reg_names[] = 00325 { 00326 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00327 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 00328 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 00329 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 00330 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7", 00331 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15", 00332 "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "sr21", "sr22", "sr23", 00333 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31", 00334 "pc", "fp" 00335 }; 00336 if (regnum < 0 || regnum > E_NUM_OF_V850E_REGS) 00337 return NULL; 00338 return v850e_reg_names[regnum]; 00339 } 00340 00341 static const char * 00342 v850e2_register_name (struct gdbarch *gdbarch, int regnum) 00343 { 00344 static const char *v850e2_reg_names[] = 00345 { 00346 /* General purpose registers. */ 00347 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00348 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 00349 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 00350 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 00351 00352 /* System registers - main banks. */ 00353 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "pid", "cfg", 00354 "", "", "", "sccfg", "scbp", "eiic", "feic", "dbic", 00355 "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "dir", "", "", 00356 "", "", "", "", "eiwr", "fewr", "dbwr", "bsel", 00357 00358 00359 /* PC. */ 00360 "pc", "", 00361 00362 /* System registers - MPV (PROT00) bank. */ 00363 "vsecr", "vstid", "vsadr", "", "vmecr", "vmtid", "vmadr", "", 00364 "vpecr", "vptid", "vpadr", "", "", "", "", "", 00365 "", "", "", "", "", "", "", "", 00366 "mca", "mcs", "mcc", "mcr", 00367 00368 /* System registers - MPU (PROT01) bank. */ 00369 "mpm", "mpc", "tid", "", "", "", "ipa0l", "ipa0u", 00370 "ipa1l", "ipa1u", "ipa2l", "ipa2u", "ipa3l", "ipa3u", "ipa4l", "ipa4u", 00371 "dpa0l", "dpa0u", "dpa1l", "dpa1u", "dpa2l", "dpa2u", "dpa3l", "dpa3u", 00372 "dpa4l", "dpa4u", "dpa5l", "dpa5u", 00373 00374 /* FPU system registers. */ 00375 "", "", "", "", "", "", "fpsr", "fpepc", 00376 "fpst", "fpcc", "fpcfg", "fpec", "", "", "", "", 00377 "", "", "", "", "", "", "", "", 00378 "", "", "", "fpspc" 00379 }; 00380 if (regnum < 0 || regnum >= E_NUM_OF_V850E2_REGS) 00381 return NULL; 00382 return v850e2_reg_names[regnum]; 00383 } 00384 00385 /* Implement the "register_name" gdbarch method for v850e3v5. */ 00386 00387 static const char * 00388 v850e3v5_register_name (struct gdbarch *gdbarch, int regnum) 00389 { 00390 static const char *v850e3v5_reg_names[] = 00391 { 00392 /* General purpose registers. */ 00393 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00394 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 00395 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 00396 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 00397 00398 /* selID 0, not including FPU registers. The FPU registers are 00399 listed later on. */ 00400 "eipc", "eipsw", "fepc", "fepsw", 00401 "", "psw", "" /* fpsr */, "" /* fpepc */, 00402 "" /* fpst */, "" /* fpcc */, "" /* fpcfg */, "" /* fpec */, 00403 "sesr", "eiic", "feic", "", 00404 "ctpc", "ctpsw", "", "", "ctbp", "", "", "", 00405 "", "", "", "", "eiwr", "fewr", "", "bsel", 00406 00407 00408 /* PC. */ 00409 "pc", "", 00410 00411 /* v850e2 MPV bank. */ 00412 "", "", "", "", "", "", "", "", 00413 "", "", "", "", "", "", "", "", 00414 "", "", "", "", "", "", "", "", 00415 "", "", "", "", 00416 00417 /* Skip v850e2 MPU bank. It's tempting to reuse these, but we need 00418 32 entries for this bank. */ 00419 "", "", "", "", "", "", "", "", 00420 "", "", "", "", "", "", "", "", 00421 "", "", "", "", "", "", "", "", 00422 "", "", "", "", 00423 00424 /* FPU system registers. These are actually in selID 0, but 00425 are placed here to preserve register numbering compatibility 00426 with previous architectures. */ 00427 "", "", "", "", "", "", "fpsr", "fpepc", 00428 "fpst", "fpcc", "fpcfg", "fpec", "", "", "", "", 00429 "", "", "", "", "", "", "", "", 00430 "", "", "", "", 00431 00432 /* selID 1. */ 00433 "mcfg0", "mcfg1", "rbase", "ebase", "intbp", "mctl", "pid", "fpipr", 00434 "", "", "tcsel", "sccfg", "scbp", "hvccfg", "hvcbp", "vsel", 00435 "vmprt0", "vmprt1", "vmprt2", "", "", "", "", "vmscctl", 00436 "vmsctbl0", "vmsctbl1", "vmsctbl2", "vmsctbl3", "", "", "", "", 00437 00438 /* selID 2. */ 00439 "htcfg0", "", "", "", "", "htctl", "mea", "asid", 00440 "mei", "ispr", "pmr", "icsr", "intcfg", "", "", "", 00441 "tlbsch", "", "", "", "", "", "", "htscctl", 00442 "htsctbl0", "htsctbl1", "htsctbl2", "htsctbl3", 00443 "htsctbl4", "htsctbl5", "htsctbl6", "htsctbl7", 00444 00445 /* selID 3. */ 00446 "", "", "", "", "", "", "", "", 00447 "", "", "", "", "", "", "", "", 00448 "", "", "", "", "", "", "", "", 00449 "", "", "", "", "", "", "", "", 00450 00451 /* selID 4. */ 00452 "tlbidx", "", "", "", "telo0", "telo1", "tehi0", "tehi1", 00453 "", "", "tlbcfg", "", "bwerrl", "bwerrh", "brerrl", "brerrh", 00454 "ictagl", "ictagh", "icdatl", "icdath", 00455 "dctagl", "dctagh", "dcdatl", "dcdath", 00456 "icctrl", "dcctrl", "iccfg", "dccfg", "icerr", "dcerr", "", "", 00457 00458 /* selID 5. */ 00459 "mpm", "mprc", "", "", "mpbrgn", "mptrgn", "", "", 00460 "mca", "mcs", "mcc", "mcr", "", "", "", "", 00461 "", "", "", "", "mpprt0", "mpprt1", "mpprt2", "", 00462 "", "", "", "", "", "", "", "", 00463 00464 /* selID 6. */ 00465 "mpla0", "mpua0", "mpat0", "", "mpla1", "mpua1", "mpat1", "", 00466 "mpla2", "mpua2", "mpat2", "", "mpla3", "mpua3", "mpat3", "", 00467 "mpla4", "mpua4", "mpat4", "", "mpla5", "mpua5", "mpat5", "", 00468 "mpla6", "mpua6", "mpat6", "", "mpla7", "mpua7", "mpat7", "", 00469 00470 /* selID 7. */ 00471 "mpla8", "mpua8", "mpat8", "", "mpla9", "mpua9", "mpat9", "", 00472 "mpla10", "mpua10", "mpat10", "", "mpla11", "mpua11", "mpat11", "", 00473 "mpla12", "mpua12", "mpat12", "", "mpla13", "mpua13", "mpat13", "", 00474 "mpla14", "mpua14", "mpat14", "", "mpla15", "mpua15", "mpat15", "", 00475 00476 /* Vector Registers */ 00477 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7", 00478 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15", 00479 "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23", 00480 "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31", 00481 }; 00482 00483 if (regnum < 0 || regnum >= E_NUM_OF_V850E3V5_REGS) 00484 return NULL; 00485 return v850e3v5_reg_names[regnum]; 00486 } 00487 00488 /* Returns the default type for register N. */ 00489 00490 static struct type * 00491 v850_register_type (struct gdbarch *gdbarch, int regnum) 00492 { 00493 if (regnum == E_PC_REGNUM) 00494 return builtin_type (gdbarch)->builtin_func_ptr; 00495 else if (E_VR0_REGNUM <= regnum && regnum <= E_VR31_REGNUM) 00496 return builtin_type (gdbarch)->builtin_uint64; 00497 return builtin_type (gdbarch)->builtin_int32; 00498 } 00499 00500 static int 00501 v850_type_is_scalar (struct type *t) 00502 { 00503 return (TYPE_CODE (t) != TYPE_CODE_STRUCT 00504 && TYPE_CODE (t) != TYPE_CODE_UNION 00505 && TYPE_CODE (t) != TYPE_CODE_ARRAY); 00506 } 00507 00508 /* Should call_function allocate stack space for a struct return? */ 00509 00510 static int 00511 v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type) 00512 { 00513 int i; 00514 struct type *fld_type, *tgt_type; 00515 00516 if (gdbarch_tdep (gdbarch)->abi == V850_ABI_RH850) 00517 { 00518 if (v850_type_is_scalar (type) && TYPE_LENGTH(type) <= 8) 00519 return 0; 00520 00521 /* Structs are never returned in registers for this ABI. */ 00522 return 1; 00523 } 00524 /* 1. The value is greater than 8 bytes -> returned by copying. */ 00525 if (TYPE_LENGTH (type) > 8) 00526 return 1; 00527 00528 /* 2. The value is a single basic type -> returned in register. */ 00529 if (v850_type_is_scalar (type)) 00530 return 0; 00531 00532 /* The value is a structure or union with a single element and that 00533 element is either a single basic type or an array of a single basic 00534 type whose size is greater than or equal to 4 -> returned in register. */ 00535 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT 00536 || TYPE_CODE (type) == TYPE_CODE_UNION) 00537 && TYPE_NFIELDS (type) == 1) 00538 { 00539 fld_type = TYPE_FIELD_TYPE (type, 0); 00540 if (v850_type_is_scalar (fld_type) && TYPE_LENGTH (fld_type) >= 4) 00541 return 0; 00542 00543 if (TYPE_CODE (fld_type) == TYPE_CODE_ARRAY) 00544 { 00545 tgt_type = TYPE_TARGET_TYPE (fld_type); 00546 if (v850_type_is_scalar (tgt_type) && TYPE_LENGTH (tgt_type) >= 4) 00547 return 0; 00548 } 00549 } 00550 00551 /* The value is a structure whose first element is an integer or a float, 00552 and which contains no arrays of more than two elements -> returned in 00553 register. */ 00554 if (TYPE_CODE (type) == TYPE_CODE_STRUCT 00555 && v850_type_is_scalar (TYPE_FIELD_TYPE (type, 0)) 00556 && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4) 00557 { 00558 for (i = 1; i < TYPE_NFIELDS (type); ++i) 00559 { 00560 fld_type = TYPE_FIELD_TYPE (type, 0); 00561 if (TYPE_CODE (fld_type) == TYPE_CODE_ARRAY) 00562 { 00563 tgt_type = TYPE_TARGET_TYPE (fld_type); 00564 if (TYPE_LENGTH (fld_type) >= 0 && TYPE_LENGTH (tgt_type) >= 0 00565 && TYPE_LENGTH (fld_type) / TYPE_LENGTH (tgt_type) > 2) 00566 return 1; 00567 } 00568 } 00569 return 0; 00570 } 00571 00572 /* The value is a union which contains at least one field which 00573 would be returned in registers according to these rules -> 00574 returned in register. */ 00575 if (TYPE_CODE (type) == TYPE_CODE_UNION) 00576 { 00577 for (i = 0; i < TYPE_NFIELDS (type); ++i) 00578 { 00579 fld_type = TYPE_FIELD_TYPE (type, 0); 00580 if (!v850_use_struct_convention (gdbarch, fld_type)) 00581 return 0; 00582 } 00583 } 00584 00585 return 1; 00586 } 00587 00588 /* Structure for mapping bits in register lists to register numbers. */ 00589 00590 struct reg_list 00591 { 00592 long mask; 00593 int regno; 00594 }; 00595 00596 /* Helper function for v850_scan_prologue to handle prepare instruction. */ 00597 00598 static void 00599 v850_handle_prepare (int insn, int insn2, CORE_ADDR * current_pc_ptr, 00600 struct v850_frame_cache *pi, struct pifsr **pifsr_ptr) 00601 { 00602 CORE_ADDR current_pc = *current_pc_ptr; 00603 struct pifsr *pifsr = *pifsr_ptr; 00604 long next = insn2 & 0xffff; 00605 long list12 = ((insn & 1) << 16) + (next & 0xffe0); 00606 long offset = (insn & 0x3e) << 1; 00607 static struct reg_list reg_table[] = 00608 { 00609 {0x00800, 20}, /* r20 */ 00610 {0x00400, 21}, /* r21 */ 00611 {0x00200, 22}, /* r22 */ 00612 {0x00100, 23}, /* r23 */ 00613 {0x08000, 24}, /* r24 */ 00614 {0x04000, 25}, /* r25 */ 00615 {0x02000, 26}, /* r26 */ 00616 {0x01000, 27}, /* r27 */ 00617 {0x00080, 28}, /* r28 */ 00618 {0x00040, 29}, /* r29 */ 00619 {0x10000, 30}, /* ep */ 00620 {0x00020, 31}, /* lp */ 00621 {0, 0} /* end of table */ 00622 }; 00623 int i; 00624 00625 if ((next & 0x1f) == 0x0b) /* skip imm16 argument */ 00626 current_pc += 2; 00627 else if ((next & 0x1f) == 0x13) /* skip imm16 argument */ 00628 current_pc += 2; 00629 else if ((next & 0x1f) == 0x1b) /* skip imm32 argument */ 00630 current_pc += 4; 00631 00632 /* Calculate the total size of the saved registers, and add it to the 00633 immediate value used to adjust SP. */ 00634 for (i = 0; reg_table[i].mask != 0; i++) 00635 if (list12 & reg_table[i].mask) 00636 offset += v850_reg_size; 00637 pi->sp_offset -= offset; 00638 00639 /* Calculate the offsets of the registers relative to the value the SP 00640 will have after the registers have been pushed and the imm5 value has 00641 been subtracted from it. */ 00642 if (pifsr) 00643 { 00644 for (i = 0; reg_table[i].mask != 0; i++) 00645 { 00646 if (list12 & reg_table[i].mask) 00647 { 00648 int reg = reg_table[i].regno; 00649 offset -= v850_reg_size; 00650 pifsr->reg = reg; 00651 pifsr->offset = offset; 00652 pifsr->cur_frameoffset = pi->sp_offset; 00653 pifsr++; 00654 } 00655 } 00656 } 00657 00658 /* Set result parameters. */ 00659 *current_pc_ptr = current_pc; 00660 *pifsr_ptr = pifsr; 00661 } 00662 00663 00664 /* Helper function for v850_scan_prologue to handle pushm/pushl instructions. 00665 The SR bit of the register list is not supported. gcc does not generate 00666 this bit. */ 00667 00668 static void 00669 v850_handle_pushm (int insn, int insn2, struct v850_frame_cache *pi, 00670 struct pifsr **pifsr_ptr) 00671 { 00672 struct pifsr *pifsr = *pifsr_ptr; 00673 long list12 = ((insn & 0x0f) << 16) + (insn2 & 0xfff0); 00674 long offset = 0; 00675 static struct reg_list pushml_reg_table[] = 00676 { 00677 {0x80000, E_PS_REGNUM}, /* PSW */ 00678 {0x40000, 1}, /* r1 */ 00679 {0x20000, 2}, /* r2 */ 00680 {0x10000, 3}, /* r3 */ 00681 {0x00800, 4}, /* r4 */ 00682 {0x00400, 5}, /* r5 */ 00683 {0x00200, 6}, /* r6 */ 00684 {0x00100, 7}, /* r7 */ 00685 {0x08000, 8}, /* r8 */ 00686 {0x04000, 9}, /* r9 */ 00687 {0x02000, 10}, /* r10 */ 00688 {0x01000, 11}, /* r11 */ 00689 {0x00080, 12}, /* r12 */ 00690 {0x00040, 13}, /* r13 */ 00691 {0x00020, 14}, /* r14 */ 00692 {0x00010, 15}, /* r15 */ 00693 {0, 0} /* end of table */ 00694 }; 00695 static struct reg_list pushmh_reg_table[] = 00696 { 00697 {0x80000, 16}, /* r16 */ 00698 {0x40000, 17}, /* r17 */ 00699 {0x20000, 18}, /* r18 */ 00700 {0x10000, 19}, /* r19 */ 00701 {0x00800, 20}, /* r20 */ 00702 {0x00400, 21}, /* r21 */ 00703 {0x00200, 22}, /* r22 */ 00704 {0x00100, 23}, /* r23 */ 00705 {0x08000, 24}, /* r24 */ 00706 {0x04000, 25}, /* r25 */ 00707 {0x02000, 26}, /* r26 */ 00708 {0x01000, 27}, /* r27 */ 00709 {0x00080, 28}, /* r28 */ 00710 {0x00040, 29}, /* r29 */ 00711 {0x00010, 30}, /* r30 */ 00712 {0x00020, 31}, /* r31 */ 00713 {0, 0} /* end of table */ 00714 }; 00715 struct reg_list *reg_table; 00716 int i; 00717 00718 /* Is this a pushml or a pushmh? */ 00719 if ((insn2 & 7) == 1) 00720 reg_table = pushml_reg_table; 00721 else 00722 reg_table = pushmh_reg_table; 00723 00724 /* Calculate the total size of the saved registers, and add it to the 00725 immediate value used to adjust SP. */ 00726 for (i = 0; reg_table[i].mask != 0; i++) 00727 if (list12 & reg_table[i].mask) 00728 offset += v850_reg_size; 00729 pi->sp_offset -= offset; 00730 00731 /* Calculate the offsets of the registers relative to the value the SP 00732 will have after the registers have been pushed and the imm5 value is 00733 subtracted from it. */ 00734 if (pifsr) 00735 { 00736 for (i = 0; reg_table[i].mask != 0; i++) 00737 { 00738 if (list12 & reg_table[i].mask) 00739 { 00740 int reg = reg_table[i].regno; 00741 offset -= v850_reg_size; 00742 pifsr->reg = reg; 00743 pifsr->offset = offset; 00744 pifsr->cur_frameoffset = pi->sp_offset; 00745 pifsr++; 00746 } 00747 } 00748 } 00749 00750 /* Set result parameters. */ 00751 *pifsr_ptr = pifsr; 00752 } 00753 00754 /* Helper function to evaluate if register is one of the "save" registers. 00755 This allows to simplify conditionals in v850_analyze_prologue a lot. */ 00756 00757 static int 00758 v850_is_save_register (int reg) 00759 { 00760 /* The caller-save registers are R2, R20 - R29 and R31. All other 00761 registers are either special purpose (PC, SP), argument registers, 00762 or just considered free for use in the caller. */ 00763 return reg == E_R2_REGNUM 00764 || (reg >= E_R20_REGNUM && reg <= E_R29_REGNUM) 00765 || reg == E_R31_REGNUM; 00766 } 00767 00768 /* Scan the prologue of the function that contains PC, and record what 00769 we find in PI. Returns the pc after the prologue. Note that the 00770 addresses saved in frame->saved_regs are just frame relative (negative 00771 offsets from the frame pointer). This is because we don't know the 00772 actual value of the frame pointer yet. In some circumstances, the 00773 frame pointer can't be determined till after we have scanned the 00774 prologue. */ 00775 00776 static CORE_ADDR 00777 v850_analyze_prologue (struct gdbarch *gdbarch, 00778 CORE_ADDR func_addr, CORE_ADDR pc, 00779 struct v850_frame_cache *pi, ULONGEST ctbp) 00780 { 00781 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00782 CORE_ADDR prologue_end, current_pc; 00783 struct pifsr pifsrs[E_NUM_REGS + 1]; 00784 struct pifsr *pifsr, *pifsr_tmp; 00785 int ep_used; 00786 int reg; 00787 CORE_ADDR save_pc, save_end; 00788 int regsave_func_p; 00789 int r12_tmp; 00790 00791 memset (&pifsrs, 0, sizeof pifsrs); 00792 pifsr = &pifsrs[0]; 00793 00794 prologue_end = pc; 00795 00796 /* Now, search the prologue looking for instructions that setup fp, save 00797 rp, adjust sp and such. We also record the frame offset of any saved 00798 registers. */ 00799 00800 pi->sp_offset = 0; 00801 pi->uses_fp = 0; 00802 ep_used = 0; 00803 regsave_func_p = 0; 00804 save_pc = 0; 00805 save_end = 0; 00806 r12_tmp = 0; 00807 00808 for (current_pc = func_addr; current_pc < prologue_end;) 00809 { 00810 int insn; 00811 int insn2 = -1; /* dummy value */ 00812 00813 insn = read_memory_integer (current_pc, 2, byte_order); 00814 current_pc += 2; 00815 if ((insn & 0x0780) >= 0x0600) /* Four byte instruction? */ 00816 { 00817 insn2 = read_memory_integer (current_pc, 2, byte_order); 00818 current_pc += 2; 00819 } 00820 00821 if ((insn & 0xffc0) == ((10 << 11) | 0x0780) && !regsave_func_p) 00822 { /* jarl <func>,10 */ 00823 long low_disp = insn2 & ~(long) 1; 00824 long disp = (((((insn & 0x3f) << 16) + low_disp) 00825 & ~(long) 1) ^ 0x00200000) - 0x00200000; 00826 00827 save_pc = current_pc; 00828 save_end = prologue_end; 00829 regsave_func_p = 1; 00830 current_pc += disp - 4; 00831 prologue_end = (current_pc 00832 + (2 * 3) /* moves to/from ep */ 00833 + 4 /* addi <const>,sp,sp */ 00834 + 2 /* jmp [r10] */ 00835 + (2 * 12) /* sst.w to save r2, r20-r29, r31 */ 00836 + 20); /* slop area */ 00837 } 00838 else if ((insn & 0xffc0) == 0x0200 && !regsave_func_p) 00839 { /* callt <imm6> */ 00840 long adr = ctbp + ((insn & 0x3f) << 1); 00841 00842 save_pc = current_pc; 00843 save_end = prologue_end; 00844 regsave_func_p = 1; 00845 current_pc = ctbp + (read_memory_unsigned_integer (adr, 2, byte_order) 00846 & 0xffff); 00847 prologue_end = (current_pc 00848 + (2 * 3) /* prepare list2,imm5,sp/imm */ 00849 + 4 /* ctret */ 00850 + 20); /* slop area */ 00851 continue; 00852 } 00853 else if ((insn & 0xffc0) == 0x0780) /* prepare list2,imm5 */ 00854 { 00855 v850_handle_prepare (insn, insn2, ¤t_pc, pi, &pifsr); 00856 continue; 00857 } 00858 else if (insn == 0x07e0 && regsave_func_p && insn2 == 0x0144) 00859 { /* ctret after processing register save. */ 00860 current_pc = save_pc; 00861 prologue_end = save_end; 00862 regsave_func_p = 0; 00863 continue; 00864 } 00865 else if ((insn & 0xfff0) == 0x07e0 && (insn2 & 5) == 1) 00866 { /* pushml, pushmh */ 00867 v850_handle_pushm (insn, insn2, pi, &pifsr); 00868 continue; 00869 } 00870 else if ((insn & 0xffe0) == 0x0060 && regsave_func_p) 00871 { /* jmp after processing register save. */ 00872 current_pc = save_pc; 00873 prologue_end = save_end; 00874 regsave_func_p = 0; 00875 continue; 00876 } 00877 else if ((insn & 0x07c0) == 0x0780 /* jarl or jr */ 00878 || (insn & 0xffe0) == 0x0060 /* jmp */ 00879 || (insn & 0x0780) == 0x0580) /* branch */ 00880 { 00881 break; /* Ran into end of prologue. */ 00882 } 00883 00884 else if ((insn & 0xffe0) == ((E_SP_REGNUM << 11) | 0x0240)) 00885 /* add <imm>,sp */ 00886 pi->sp_offset += ((insn & 0x1f) ^ 0x10) - 0x10; 00887 else if (insn == ((E_SP_REGNUM << 11) | 0x0600 | E_SP_REGNUM)) 00888 /* addi <imm>,sp,sp */ 00889 pi->sp_offset += insn2; 00890 else if (insn == ((E_FP_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) 00891 /* mov sp,fp */ 00892 pi->uses_fp = 1; 00893 else if (insn == ((E_R12_REGNUM << 11) | 0x0640 | E_R0_REGNUM)) 00894 /* movhi hi(const),r0,r12 */ 00895 r12_tmp = insn2 << 16; 00896 else if (insn == ((E_R12_REGNUM << 11) | 0x0620 | E_R12_REGNUM)) 00897 /* movea lo(const),r12,r12 */ 00898 r12_tmp += insn2; 00899 else if (insn == ((E_SP_REGNUM << 11) | 0x01c0 | E_R12_REGNUM) && r12_tmp) 00900 /* add r12,sp */ 00901 pi->sp_offset += r12_tmp; 00902 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) 00903 /* mov sp,ep */ 00904 ep_used = 1; 00905 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_R1_REGNUM)) 00906 /* mov r1,ep */ 00907 ep_used = 0; 00908 else if (((insn & 0x07ff) == (0x0760 | E_SP_REGNUM) 00909 || (pi->uses_fp 00910 && (insn & 0x07ff) == (0x0760 | E_FP_REGNUM))) 00911 && pifsr 00912 && v850_is_save_register (reg = (insn >> 11) & 0x1f)) 00913 { 00914 /* st.w <reg>,<offset>[sp] or st.w <reg>,<offset>[fp] */ 00915 pifsr->reg = reg; 00916 pifsr->offset = insn2 & ~1; 00917 pifsr->cur_frameoffset = pi->sp_offset; 00918 pifsr++; 00919 } 00920 else if (ep_used 00921 && ((insn & 0x0781) == 0x0501) 00922 && pifsr 00923 && v850_is_save_register (reg = (insn >> 11) & 0x1f)) 00924 { 00925 /* sst.w <reg>,<offset>[ep] */ 00926 pifsr->reg = reg; 00927 pifsr->offset = (insn & 0x007e) << 1; 00928 pifsr->cur_frameoffset = pi->sp_offset; 00929 pifsr++; 00930 } 00931 } 00932 00933 /* Fix up any offsets to the final offset. If a frame pointer was created, 00934 use it instead of the stack pointer. */ 00935 for (pifsr_tmp = pifsrs; pifsr_tmp != pifsr; pifsr_tmp++) 00936 { 00937 pifsr_tmp->offset -= pi->sp_offset - pifsr_tmp->cur_frameoffset; 00938 pi->saved_regs[pifsr_tmp->reg].addr = pifsr_tmp->offset; 00939 } 00940 00941 return current_pc; 00942 } 00943 00944 /* Return the address of the first code past the prologue of the function. */ 00945 00946 static CORE_ADDR 00947 v850_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 00948 { 00949 CORE_ADDR func_addr, func_end; 00950 00951 /* See what the symbol table says. */ 00952 00953 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) 00954 { 00955 struct symtab_and_line sal; 00956 00957 sal = find_pc_line (func_addr, 0); 00958 if (sal.line != 0 && sal.end < func_end) 00959 return sal.end; 00960 00961 /* Either there's no line info, or the line after the prologue is after 00962 the end of the function. In this case, there probably isn't a 00963 prologue. */ 00964 return pc; 00965 } 00966 00967 /* We can't find the start of this function, so there's nothing we 00968 can do. */ 00969 return pc; 00970 } 00971 00972 /* Return 1 if the data structure has any 8-byte fields that'll require 00973 the entire data structure to be aligned. Otherwise, return 0. */ 00974 00975 static int 00976 v850_eight_byte_align_p (struct type *type) 00977 { 00978 type = check_typedef (type); 00979 00980 if (v850_type_is_scalar (type)) 00981 return (TYPE_LENGTH (type) == 8); 00982 else 00983 { 00984 int i; 00985 00986 for (i = 0; i < TYPE_NFIELDS (type); i++) 00987 { 00988 if (v850_eight_byte_align_p (TYPE_FIELD_TYPE (type, i))) 00989 return 1; 00990 } 00991 } 00992 return 0; 00993 } 00994 00995 static CORE_ADDR 00996 v850_frame_align (struct gdbarch *ignore, CORE_ADDR sp) 00997 { 00998 return sp & ~3; 00999 } 01000 01001 /* Setup arguments and LP for a call to the target. First four args 01002 go in R6->R9, subsequent args go into sp + 16 -> sp + ... Structs 01003 are passed by reference. 64 bit quantities (doubles and long longs) 01004 may be split between the regs and the stack. When calling a function 01005 that returns a struct, a pointer to the struct is passed in as a secret 01006 first argument (always in R6). 01007 01008 Stack space for the args has NOT been allocated: that job is up to us. */ 01009 01010 static CORE_ADDR 01011 v850_push_dummy_call (struct gdbarch *gdbarch, 01012 struct value *function, 01013 struct regcache *regcache, 01014 CORE_ADDR bp_addr, 01015 int nargs, 01016 struct value **args, 01017 CORE_ADDR sp, 01018 int struct_return, 01019 CORE_ADDR struct_addr) 01020 { 01021 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01022 int argreg; 01023 int argnum; 01024 int len = 0; 01025 int stack_offset; 01026 01027 if (gdbarch_tdep (gdbarch)->abi == V850_ABI_RH850) 01028 stack_offset = 0; 01029 else 01030 /* The offset onto the stack at which we will start copying parameters 01031 (after the registers are used up) begins at 16 rather than at zero. 01032 That's how the ABI is defined, though there's no indication that these 01033 16 bytes are used for anything, not even for saving incoming 01034 argument registers. */ 01035 stack_offset = 16; 01036 01037 /* Now make space on the stack for the args. */ 01038 for (argnum = 0; argnum < nargs; argnum++) 01039 len += ((TYPE_LENGTH (value_type (args[argnum])) + 3) & ~3); 01040 sp -= len + stack_offset; 01041 01042 argreg = E_ARG0_REGNUM; 01043 /* The struct_return pointer occupies the first parameter register. */ 01044 if (struct_return) 01045 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); 01046 01047 /* Now load as many as possible of the first arguments into 01048 registers, and push the rest onto the stack. There are 16 bytes 01049 in four registers available. Loop thru args from first to last. */ 01050 for (argnum = 0; argnum < nargs; argnum++) 01051 { 01052 int len; 01053 gdb_byte *val; 01054 gdb_byte valbuf[v850_reg_size]; 01055 01056 if (!v850_type_is_scalar (value_type (*args)) 01057 && gdbarch_tdep (gdbarch)->abi == V850_ABI_GCC 01058 && TYPE_LENGTH (value_type (*args)) > E_MAX_RETTYPE_SIZE_IN_REGS) 01059 { 01060 store_unsigned_integer (valbuf, 4, byte_order, 01061 value_address (*args)); 01062 len = 4; 01063 val = valbuf; 01064 } 01065 else 01066 { 01067 len = TYPE_LENGTH (value_type (*args)); 01068 val = (gdb_byte *) value_contents (*args); 01069 } 01070 01071 if (gdbarch_tdep (gdbarch)->eight_byte_align 01072 && v850_eight_byte_align_p (value_type (*args))) 01073 { 01074 if (argreg <= E_ARGLAST_REGNUM && (argreg & 1)) 01075 argreg++; 01076 else if (stack_offset & 0x4) 01077 stack_offset += 4; 01078 } 01079 01080 while (len > 0) 01081 if (argreg <= E_ARGLAST_REGNUM) 01082 { 01083 CORE_ADDR regval; 01084 01085 regval = extract_unsigned_integer (val, v850_reg_size, byte_order); 01086 regcache_cooked_write_unsigned (regcache, argreg, regval); 01087 01088 len -= v850_reg_size; 01089 val += v850_reg_size; 01090 argreg++; 01091 } 01092 else 01093 { 01094 write_memory (sp + stack_offset, val, 4); 01095 01096 len -= 4; 01097 val += 4; 01098 stack_offset += 4; 01099 } 01100 args++; 01101 } 01102 01103 /* Store return address. */ 01104 regcache_cooked_write_unsigned (regcache, E_LP_REGNUM, bp_addr); 01105 01106 /* Update stack pointer. */ 01107 regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp); 01108 01109 return sp; 01110 } 01111 01112 static void 01113 v850_extract_return_value (struct type *type, struct regcache *regcache, 01114 gdb_byte *valbuf) 01115 { 01116 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01117 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01118 int len = TYPE_LENGTH (type); 01119 01120 if (len <= v850_reg_size) 01121 { 01122 ULONGEST val; 01123 01124 regcache_cooked_read_unsigned (regcache, E_V0_REGNUM, &val); 01125 store_unsigned_integer (valbuf, len, byte_order, val); 01126 } 01127 else if (len <= 2 * v850_reg_size) 01128 { 01129 int i, regnum = E_V0_REGNUM; 01130 gdb_byte buf[v850_reg_size]; 01131 for (i = 0; len > 0; i += 4, len -= 4) 01132 { 01133 regcache_raw_read (regcache, regnum++, buf); 01134 memcpy (valbuf + i, buf, len > 4 ? 4 : len); 01135 } 01136 } 01137 } 01138 01139 static void 01140 v850_store_return_value (struct type *type, struct regcache *regcache, 01141 const gdb_byte *valbuf) 01142 { 01143 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01144 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01145 int len = TYPE_LENGTH (type); 01146 01147 if (len <= v850_reg_size) 01148 regcache_cooked_write_unsigned 01149 (regcache, E_V0_REGNUM, 01150 extract_unsigned_integer (valbuf, len, byte_order)); 01151 else if (len <= 2 * v850_reg_size) 01152 { 01153 int i, regnum = E_V0_REGNUM; 01154 for (i = 0; i < len; i += 4) 01155 regcache_raw_write (regcache, regnum++, valbuf + i); 01156 } 01157 } 01158 01159 static enum return_value_convention 01160 v850_return_value (struct gdbarch *gdbarch, struct value *function, 01161 struct type *type, struct regcache *regcache, 01162 gdb_byte *readbuf, const gdb_byte *writebuf) 01163 { 01164 if (v850_use_struct_convention (gdbarch, type)) 01165 return RETURN_VALUE_STRUCT_CONVENTION; 01166 if (writebuf) 01167 v850_store_return_value (type, regcache, writebuf); 01168 else if (readbuf) 01169 v850_extract_return_value (type, regcache, readbuf); 01170 return RETURN_VALUE_REGISTER_CONVENTION; 01171 } 01172 01173 static const unsigned char * 01174 v850_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, 01175 int *lenptr) 01176 { 01177 static unsigned char breakpoint[] = { 0x85, 0x05 }; 01178 01179 *lenptr = sizeof (breakpoint); 01180 return breakpoint; 01181 } 01182 01183 /* Implement software breakpoints by using the dbtrap instruction. 01184 Older architectures had no such instruction. For those, an 01185 unconditional branch to self instruction is used. */ 01186 01187 static const unsigned char * 01188 v850_dbtrap_breakpoint_from_pc (struct gdbarch *gdbarch, 01189 CORE_ADDR *pcptr, int *lenptr) 01190 { 01191 static unsigned char breakpoint[] = { 0x40, 0xf8 }; 01192 01193 *lenptr = sizeof (breakpoint); 01194 return breakpoint; 01195 } 01196 01197 static struct v850_frame_cache * 01198 v850_alloc_frame_cache (struct frame_info *this_frame) 01199 { 01200 struct v850_frame_cache *cache; 01201 01202 cache = FRAME_OBSTACK_ZALLOC (struct v850_frame_cache); 01203 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); 01204 01205 /* Base address. */ 01206 cache->base = 0; 01207 cache->sp_offset = 0; 01208 cache->pc = 0; 01209 01210 /* Frameless until proven otherwise. */ 01211 cache->uses_fp = 0; 01212 01213 return cache; 01214 } 01215 01216 static struct v850_frame_cache * 01217 v850_frame_cache (struct frame_info *this_frame, void **this_cache) 01218 { 01219 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01220 struct v850_frame_cache *cache; 01221 CORE_ADDR current_pc; 01222 int i; 01223 01224 if (*this_cache) 01225 return *this_cache; 01226 01227 cache = v850_alloc_frame_cache (this_frame); 01228 *this_cache = cache; 01229 01230 /* In principle, for normal frames, fp holds the frame pointer, 01231 which holds the base address for the current stack frame. 01232 However, for functions that don't need it, the frame pointer is 01233 optional. For these "frameless" functions the frame pointer is 01234 actually the frame pointer of the calling frame. */ 01235 cache->base = get_frame_register_unsigned (this_frame, E_FP_REGNUM); 01236 if (cache->base == 0) 01237 return cache; 01238 01239 cache->pc = get_frame_func (this_frame); 01240 current_pc = get_frame_pc (this_frame); 01241 if (cache->pc != 0) 01242 { 01243 ULONGEST ctbp; 01244 ctbp = get_frame_register_unsigned (this_frame, E_CTBP_REGNUM); 01245 v850_analyze_prologue (gdbarch, cache->pc, current_pc, cache, ctbp); 01246 } 01247 01248 if (!cache->uses_fp) 01249 { 01250 /* We didn't find a valid frame, which means that CACHE->base 01251 currently holds the frame pointer for our calling frame. If 01252 we're at the start of a function, or somewhere half-way its 01253 prologue, the function's frame probably hasn't been fully 01254 setup yet. Try to reconstruct the base address for the stack 01255 frame by looking at the stack pointer. For truly "frameless" 01256 functions this might work too. */ 01257 cache->base = get_frame_register_unsigned (this_frame, E_SP_REGNUM); 01258 } 01259 01260 /* Now that we have the base address for the stack frame we can 01261 calculate the value of sp in the calling frame. */ 01262 trad_frame_set_value (cache->saved_regs, E_SP_REGNUM, 01263 cache->base - cache->sp_offset); 01264 01265 /* Adjust all the saved registers such that they contain addresses 01266 instead of offsets. */ 01267 for (i = 0; i < gdbarch_num_regs (gdbarch); i++) 01268 if (trad_frame_addr_p (cache->saved_regs, i)) 01269 cache->saved_regs[i].addr += cache->base; 01270 01271 /* The call instruction moves the caller's PC in the callee's LP. 01272 Since this is an unwind, do the reverse. Copy the location of LP 01273 into PC (the address / regnum) so that a request for PC will be 01274 converted into a request for the LP. */ 01275 01276 cache->saved_regs[E_PC_REGNUM] = cache->saved_regs[E_LP_REGNUM]; 01277 01278 return cache; 01279 } 01280 01281 01282 static struct value * 01283 v850_frame_prev_register (struct frame_info *this_frame, 01284 void **this_cache, int regnum) 01285 { 01286 struct v850_frame_cache *cache = v850_frame_cache (this_frame, this_cache); 01287 01288 gdb_assert (regnum >= 0); 01289 01290 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum); 01291 } 01292 01293 static void 01294 v850_frame_this_id (struct frame_info *this_frame, void **this_cache, 01295 struct frame_id *this_id) 01296 { 01297 struct v850_frame_cache *cache = v850_frame_cache (this_frame, this_cache); 01298 01299 /* This marks the outermost frame. */ 01300 if (cache->base == 0) 01301 return; 01302 01303 *this_id = frame_id_build (cache->saved_regs[E_SP_REGNUM].addr, cache->pc); 01304 } 01305 01306 static const struct frame_unwind v850_frame_unwind = { 01307 NORMAL_FRAME, 01308 default_frame_unwind_stop_reason, 01309 v850_frame_this_id, 01310 v850_frame_prev_register, 01311 NULL, 01312 default_frame_sniffer 01313 }; 01314 01315 static CORE_ADDR 01316 v850_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) 01317 { 01318 return frame_unwind_register_unsigned (next_frame, 01319 gdbarch_sp_regnum (gdbarch)); 01320 } 01321 01322 static CORE_ADDR 01323 v850_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 01324 { 01325 return frame_unwind_register_unsigned (next_frame, 01326 gdbarch_pc_regnum (gdbarch)); 01327 } 01328 01329 static struct frame_id 01330 v850_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 01331 { 01332 CORE_ADDR sp = get_frame_register_unsigned (this_frame, 01333 gdbarch_sp_regnum (gdbarch)); 01334 return frame_id_build (sp, get_frame_pc (this_frame)); 01335 } 01336 01337 static CORE_ADDR 01338 v850_frame_base_address (struct frame_info *this_frame, void **this_cache) 01339 { 01340 struct v850_frame_cache *cache = v850_frame_cache (this_frame, this_cache); 01341 01342 return cache->base; 01343 } 01344 01345 static const struct frame_base v850_frame_base = { 01346 &v850_frame_unwind, 01347 v850_frame_base_address, 01348 v850_frame_base_address, 01349 v850_frame_base_address 01350 }; 01351 01352 static struct gdbarch * 01353 v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 01354 { 01355 struct gdbarch *gdbarch; 01356 struct gdbarch_tdep *tdep; 01357 int e_flags, e_machine; 01358 01359 /* Extract the elf_flags if available. */ 01360 if (info.abfd != NULL 01361 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) 01362 { 01363 e_flags = elf_elfheader (info.abfd)->e_flags; 01364 e_machine = elf_elfheader (info.abfd)->e_machine; 01365 } 01366 else 01367 { 01368 e_flags = 0; 01369 e_machine = 0; 01370 } 01371 01372 01373 /* Try to find the architecture in the list of already defined 01374 architectures. */ 01375 for (arches = gdbarch_list_lookup_by_info (arches, &info); 01376 arches != NULL; 01377 arches = gdbarch_list_lookup_by_info (arches->next, &info)) 01378 { 01379 if (gdbarch_tdep (arches->gdbarch)->e_flags != e_flags 01380 || gdbarch_tdep (arches->gdbarch)->e_machine != e_machine) 01381 continue; 01382 01383 return arches->gdbarch; 01384 } 01385 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); 01386 tdep->e_flags = e_flags; 01387 tdep->e_machine = e_machine; 01388 01389 switch (tdep->e_machine) 01390 { 01391 case EM_V800: 01392 tdep->abi = V850_ABI_RH850; 01393 break; 01394 default: 01395 tdep->abi = V850_ABI_GCC; 01396 break; 01397 } 01398 01399 tdep->eight_byte_align = (tdep->e_flags & EF_RH850_DATA_ALIGN8) ? 1 : 0; 01400 gdbarch = gdbarch_alloc (&info, tdep); 01401 01402 switch (info.bfd_arch_info->mach) 01403 { 01404 case bfd_mach_v850: 01405 set_gdbarch_register_name (gdbarch, v850_register_name); 01406 set_gdbarch_num_regs (gdbarch, E_NUM_OF_V850_REGS); 01407 break; 01408 case bfd_mach_v850e: 01409 case bfd_mach_v850e1: 01410 set_gdbarch_register_name (gdbarch, v850e_register_name); 01411 set_gdbarch_num_regs (gdbarch, E_NUM_OF_V850E_REGS); 01412 break; 01413 case bfd_mach_v850e2: 01414 case bfd_mach_v850e2v3: 01415 set_gdbarch_register_name (gdbarch, v850e2_register_name); 01416 set_gdbarch_num_regs (gdbarch, E_NUM_REGS); 01417 break; 01418 case bfd_mach_v850e3v5: 01419 set_gdbarch_register_name (gdbarch, v850e3v5_register_name); 01420 set_gdbarch_num_regs (gdbarch, E_NUM_OF_V850E3V5_REGS); 01421 break; 01422 } 01423 01424 set_gdbarch_num_pseudo_regs (gdbarch, 0); 01425 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM); 01426 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM); 01427 set_gdbarch_fp0_regnum (gdbarch, -1); 01428 01429 set_gdbarch_register_type (gdbarch, v850_register_type); 01430 01431 set_gdbarch_char_signed (gdbarch, 1); 01432 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); 01433 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT); 01434 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); 01435 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); 01436 01437 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); 01438 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 01439 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 01440 01441 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT); 01442 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT); 01443 01444 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 01445 switch (info.bfd_arch_info->mach) 01446 { 01447 case bfd_mach_v850e2: 01448 case bfd_mach_v850e2v3: 01449 case bfd_mach_v850e3v5: 01450 set_gdbarch_breakpoint_from_pc (gdbarch, v850_dbtrap_breakpoint_from_pc); 01451 break; 01452 default: 01453 set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc); 01454 break; 01455 } 01456 01457 set_gdbarch_return_value (gdbarch, v850_return_value); 01458 set_gdbarch_push_dummy_call (gdbarch, v850_push_dummy_call); 01459 set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue); 01460 01461 set_gdbarch_print_insn (gdbarch, print_insn_v850); 01462 01463 set_gdbarch_frame_align (gdbarch, v850_frame_align); 01464 set_gdbarch_unwind_sp (gdbarch, v850_unwind_sp); 01465 set_gdbarch_unwind_pc (gdbarch, v850_unwind_pc); 01466 set_gdbarch_dummy_id (gdbarch, v850_dummy_id); 01467 frame_base_set_default (gdbarch, &v850_frame_base); 01468 01469 /* Hook in ABI-specific overrides, if they have been registered. */ 01470 gdbarch_init_osabi (info, gdbarch); 01471 01472 dwarf2_append_unwinders (gdbarch); 01473 frame_unwind_append_unwinder (gdbarch, &v850_frame_unwind); 01474 01475 return gdbarch; 01476 } 01477 01478 extern initialize_file_ftype _initialize_v850_tdep; /* -Wmissing-prototypes */ 01479 01480 void 01481 _initialize_v850_tdep (void) 01482 { 01483 register_gdbarch_init (bfd_arch_v850, v850_gdbarch_init); 01484 register_gdbarch_init (bfd_arch_v850_rh850, v850_gdbarch_init); 01485 }