GDB (API)
/home/stan/gdb/src/gdb/sh-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for Renesas Super-H, for GDB.
00002 
00003    Copyright (C) 1993-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 /* Contributed by Steve Chamberlain
00021    sac@cygnus.com.  */
00022 
00023 #include "defs.h"
00024 #include "frame.h"
00025 #include "frame-base.h"
00026 #include "frame-unwind.h"
00027 #include "dwarf2-frame.h"
00028 #include "symtab.h"
00029 #include "gdbtypes.h"
00030 #include "gdbcmd.h"
00031 #include "gdbcore.h"
00032 #include "value.h"
00033 #include "dis-asm.h"
00034 #include "inferior.h"
00035 #include "gdb_string.h"
00036 #include "gdb_assert.h"
00037 #include "arch-utils.h"
00038 #include "floatformat.h"
00039 #include "regcache.h"
00040 #include "doublest.h"
00041 #include "osabi.h"
00042 #include "reggroups.h"
00043 #include "regset.h"
00044 #include "objfiles.h"
00045 
00046 #include "sh-tdep.h"
00047 #include "sh64-tdep.h"
00048 
00049 #include "elf-bfd.h"
00050 #include "solib-svr4.h"
00051 
00052 /* sh flags */
00053 #include "elf/sh.h"
00054 #include "dwarf2.h"
00055 /* registers numbers shared with the simulator.  */
00056 #include "gdb/sim-sh.h"
00057 
00058 /* List of "set sh ..." and "show sh ..." commands.  */
00059 static struct cmd_list_element *setshcmdlist = NULL;
00060 static struct cmd_list_element *showshcmdlist = NULL;
00061 
00062 static const char sh_cc_gcc[] = "gcc";
00063 static const char sh_cc_renesas[] = "renesas";
00064 static const char *const sh_cc_enum[] = {
00065   sh_cc_gcc,
00066   sh_cc_renesas, 
00067   NULL
00068 };
00069 
00070 static const char *sh_active_calling_convention = sh_cc_gcc;
00071 
00072 #define SH_NUM_REGS 67
00073 
00074 struct sh_frame_cache
00075 {
00076   /* Base address.  */
00077   CORE_ADDR base;
00078   LONGEST sp_offset;
00079   CORE_ADDR pc;
00080 
00081   /* Flag showing that a frame has been created in the prologue code.  */
00082   int uses_fp;
00083 
00084   /* Saved registers.  */
00085   CORE_ADDR saved_regs[SH_NUM_REGS];
00086   CORE_ADDR saved_sp;
00087 };
00088 
00089 static int
00090 sh_is_renesas_calling_convention (struct type *func_type)
00091 {
00092   int val = 0;
00093 
00094   if (func_type)
00095     {
00096       func_type = check_typedef (func_type);
00097 
00098       if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
00099         func_type = check_typedef (TYPE_TARGET_TYPE (func_type));
00100 
00101       if (TYPE_CODE (func_type) == TYPE_CODE_FUNC
00102           && TYPE_CALLING_CONVENTION (func_type) == DW_CC_GNU_renesas_sh)
00103         val = 1;
00104     }
00105 
00106   if (sh_active_calling_convention == sh_cc_renesas)
00107     val = 1;
00108 
00109   return val;
00110 }
00111 
00112 static const char *
00113 sh_sh_register_name (struct gdbarch *gdbarch, int reg_nr)
00114 {
00115   static char *register_names[] = {
00116     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00117     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00118     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00119     "", "",
00120     "", "", "", "", "", "", "", "",
00121     "", "", "", "", "", "", "", "",
00122     "", "",
00123     "", "", "", "", "", "", "", "",
00124     "", "", "", "", "", "", "", "",
00125     "", "", "", "", "", "", "", "",
00126   };
00127   if (reg_nr < 0)
00128     return NULL;
00129   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00130     return NULL;
00131   return register_names[reg_nr];
00132 }
00133 
00134 static const char *
00135 sh_sh3_register_name (struct gdbarch *gdbarch, int reg_nr)
00136 {
00137   static char *register_names[] = {
00138     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00139     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00140     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00141     "", "",
00142     "", "", "", "", "", "", "", "",
00143     "", "", "", "", "", "", "", "",
00144     "ssr", "spc",
00145     "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
00146     "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1"
00147     "", "", "", "", "", "", "", "",
00148   };
00149   if (reg_nr < 0)
00150     return NULL;
00151   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00152     return NULL;
00153   return register_names[reg_nr];
00154 }
00155 
00156 static const char *
00157 sh_sh3e_register_name (struct gdbarch *gdbarch, int reg_nr)
00158 {
00159   static char *register_names[] = {
00160     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00161     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00162     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00163     "fpul", "fpscr",
00164     "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
00165     "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
00166     "ssr", "spc",
00167     "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
00168     "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
00169     "", "", "", "", "", "", "", "",
00170   };
00171   if (reg_nr < 0)
00172     return NULL;
00173   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00174     return NULL;
00175   return register_names[reg_nr];
00176 }
00177 
00178 static const char *
00179 sh_sh2e_register_name (struct gdbarch *gdbarch, int reg_nr)
00180 {
00181   static char *register_names[] = {
00182     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00183     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00184     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00185     "fpul", "fpscr",
00186     "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
00187     "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
00188     "", "",
00189     "", "", "", "", "", "", "", "",
00190     "", "", "", "", "", "", "", "",
00191     "", "", "", "", "", "", "", "",
00192   };
00193   if (reg_nr < 0)
00194     return NULL;
00195   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00196     return NULL;
00197   return register_names[reg_nr];
00198 }
00199 
00200 static const char *
00201 sh_sh2a_register_name (struct gdbarch *gdbarch, int reg_nr)
00202 {
00203   static char *register_names[] = {
00204     /* general registers 0-15 */
00205     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00206     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00207     /* 16 - 22 */
00208     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00209     /* 23, 24 */
00210     "fpul", "fpscr",
00211     /* floating point registers 25 - 40 */
00212     "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
00213     "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
00214     /* 41, 42 */
00215     "", "",
00216     /* 43 - 62.  Banked registers.  The bank number used is determined by
00217        the bank register (63).  */
00218     "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
00219     "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b",
00220     "machb", "ivnb", "prb", "gbrb", "maclb",
00221     /* 63: register bank number, not a real register but used to
00222        communicate the register bank currently get/set.  This register
00223        is hidden to the user, who manipulates it using the pseudo
00224        register called "bank" (67).  See below.  */
00225     "",
00226     /* 64 - 66 */
00227     "ibcr", "ibnr", "tbr",
00228     /* 67: register bank number, the user visible pseudo register.  */
00229     "bank",
00230     /* double precision (pseudo) 68 - 75 */
00231     "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
00232   };
00233   if (reg_nr < 0)
00234     return NULL;
00235   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00236     return NULL;
00237   return register_names[reg_nr];
00238 }
00239 
00240 static const char *
00241 sh_sh2a_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
00242 {
00243   static char *register_names[] = {
00244     /* general registers 0-15 */
00245     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00246     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00247     /* 16 - 22 */
00248     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00249     /* 23, 24 */
00250     "", "",
00251     /* floating point registers 25 - 40 */
00252     "", "", "", "", "", "", "", "",
00253     "", "", "", "", "", "", "", "",
00254     /* 41, 42 */
00255     "", "",
00256     /* 43 - 62.  Banked registers.  The bank number used is determined by
00257        the bank register (63).  */
00258     "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
00259     "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b",
00260     "machb", "ivnb", "prb", "gbrb", "maclb",
00261     /* 63: register bank number, not a real register but used to
00262        communicate the register bank currently get/set.  This register
00263        is hidden to the user, who manipulates it using the pseudo
00264        register called "bank" (67).  See below.  */
00265     "",
00266     /* 64 - 66 */
00267     "ibcr", "ibnr", "tbr",
00268     /* 67: register bank number, the user visible pseudo register.  */
00269     "bank",
00270     /* double precision (pseudo) 68 - 75 */
00271     "", "", "", "", "", "", "", "",
00272   };
00273   if (reg_nr < 0)
00274     return NULL;
00275   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00276     return NULL;
00277   return register_names[reg_nr];
00278 }
00279 
00280 static const char *
00281 sh_sh_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
00282 {
00283   static char *register_names[] = {
00284     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00285     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00286     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00287     "", "dsr",
00288     "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
00289     "y0", "y1", "", "", "", "", "", "mod",
00290     "", "",
00291     "rs", "re", "", "", "", "", "", "",
00292     "", "", "", "", "", "", "", "",
00293     "", "", "", "", "", "", "", "",
00294   };
00295   if (reg_nr < 0)
00296     return NULL;
00297   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00298     return NULL;
00299   return register_names[reg_nr];
00300 }
00301 
00302 static const char *
00303 sh_sh3_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
00304 {
00305   static char *register_names[] = {
00306     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00307     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00308     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00309     "", "dsr",
00310     "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
00311     "y0", "y1", "", "", "", "", "", "mod",
00312     "ssr", "spc",
00313     "rs", "re", "", "", "", "", "", "",
00314     "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
00315     "", "", "", "", "", "", "", "",
00316     "", "", "", "", "", "", "", "",
00317   };
00318   if (reg_nr < 0)
00319     return NULL;
00320   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00321     return NULL;
00322   return register_names[reg_nr];
00323 }
00324 
00325 static const char *
00326 sh_sh4_register_name (struct gdbarch *gdbarch, int reg_nr)
00327 {
00328   static char *register_names[] = {
00329     /* general registers 0-15 */
00330     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00331     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00332     /* 16 - 22 */
00333     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00334     /* 23, 24 */
00335     "fpul", "fpscr",
00336     /* floating point registers 25 - 40 */
00337     "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
00338     "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
00339     /* 41, 42 */
00340     "ssr", "spc",
00341     /* bank 0 43 - 50 */
00342     "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
00343     /* bank 1 51 - 58 */
00344     "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
00345     /* 59 - 66 */
00346     "", "", "", "", "", "", "", "",
00347     /* pseudo bank register.  */
00348     "",
00349     /* double precision (pseudo) 68 - 75 */
00350     "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
00351     /* vectors (pseudo) 76 - 79 */
00352     "fv0", "fv4", "fv8", "fv12",
00353     /* FIXME: missing XF */
00354     /* FIXME: missing XD */
00355   };
00356   if (reg_nr < 0)
00357     return NULL;
00358   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00359     return NULL;
00360   return register_names[reg_nr];
00361 }
00362 
00363 static const char *
00364 sh_sh4_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
00365 {
00366   static char *register_names[] = {
00367     /* general registers 0-15 */
00368     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00369     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00370     /* 16 - 22 */
00371     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00372     /* 23, 24 */
00373     "", "",
00374     /* floating point registers 25 - 40 -- not for nofpu target */
00375     "", "", "", "", "", "", "", "",
00376     "", "", "", "", "", "", "", "",
00377     /* 41, 42 */
00378     "ssr", "spc",
00379     /* bank 0 43 - 50 */
00380     "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
00381     /* bank 1 51 - 58 */
00382     "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
00383     /* 59 - 66 */
00384     "", "", "", "", "", "", "", "",
00385     /* pseudo bank register.  */
00386     "",
00387     /* double precision (pseudo) 68 - 75 -- not for nofpu target */
00388     "", "", "", "", "", "", "", "",
00389     /* vectors (pseudo) 76 - 79 -- not for nofpu target */
00390     "", "", "", "",
00391   };
00392   if (reg_nr < 0)
00393     return NULL;
00394   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00395     return NULL;
00396   return register_names[reg_nr];
00397 }
00398 
00399 static const char *
00400 sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
00401 {
00402   static char *register_names[] = {
00403     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00404     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00405     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
00406     "", "dsr",
00407     "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
00408     "y0", "y1", "", "", "", "", "", "mod",
00409     "ssr", "spc",
00410     "rs", "re", "", "", "", "", "", "",
00411     "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
00412     "", "", "", "", "", "", "", "",
00413     "", "", "", "", "", "", "", "",
00414   };
00415   if (reg_nr < 0)
00416     return NULL;
00417   if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
00418     return NULL;
00419   return register_names[reg_nr];
00420 }
00421 
00422 static const unsigned char *
00423 sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
00424 {
00425   /* 0xc3c3 is trapa #c3, and it works in big and little endian modes.  */
00426   static unsigned char breakpoint[] = { 0xc3, 0xc3 };
00427 
00428   /* For remote stub targets, trapa #20 is used.  */
00429   if (strcmp (target_shortname, "remote") == 0)
00430     {
00431       static unsigned char big_remote_breakpoint[] = { 0xc3, 0x20 };
00432       static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
00433 
00434       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
00435         {
00436           *lenptr = sizeof (big_remote_breakpoint);
00437           return big_remote_breakpoint;
00438         }
00439       else
00440         {
00441           *lenptr = sizeof (little_remote_breakpoint);
00442           return little_remote_breakpoint;
00443         }
00444     }
00445 
00446   *lenptr = sizeof (breakpoint);
00447   return breakpoint;
00448 }
00449 
00450 /* Prologue looks like
00451    mov.l        r14,@-r15
00452    sts.l        pr,@-r15
00453    mov.l        <regs>,@-r15
00454    sub          <room_for_loca_vars>,r15
00455    mov          r15,r14
00456 
00457    Actually it can be more complicated than this but that's it, basically.  */
00458 
00459 #define GET_SOURCE_REG(x)       (((x) >> 4) & 0xf)
00460 #define GET_TARGET_REG(x)       (((x) >> 8) & 0xf)
00461 
00462 /* JSR @Rm         0100mmmm00001011 */
00463 #define IS_JSR(x)               (((x) & 0xf0ff) == 0x400b)
00464 
00465 /* STS.L PR,@-r15  0100111100100010
00466    r15-4-->r15, PR-->(r15) */
00467 #define IS_STS(x)               ((x) == 0x4f22)
00468 
00469 /* STS.L MACL,@-r15  0100111100010010
00470    r15-4-->r15, MACL-->(r15) */
00471 #define IS_MACL_STS(x)          ((x) == 0x4f12)
00472 
00473 /* MOV.L Rm,@-r15  00101111mmmm0110
00474    r15-4-->r15, Rm-->(R15) */
00475 #define IS_PUSH(x)              (((x) & 0xff0f) == 0x2f06)
00476 
00477 /* MOV r15,r14     0110111011110011
00478    r15-->r14  */
00479 #define IS_MOV_SP_FP(x)         ((x) == 0x6ef3)
00480 
00481 /* ADD #imm,r15    01111111iiiiiiii
00482    r15+imm-->r15 */
00483 #define IS_ADD_IMM_SP(x)        (((x) & 0xff00) == 0x7f00)
00484 
00485 #define IS_MOV_R3(x)            (((x) & 0xff00) == 0x1a00)
00486 #define IS_SHLL_R3(x)           ((x) == 0x4300)
00487 
00488 /* ADD r3,r15      0011111100111100
00489    r15+r3-->r15 */
00490 #define IS_ADD_R3SP(x)          ((x) == 0x3f3c)
00491 
00492 /* FMOV.S FRm,@-Rn  Rn-4-->Rn, FRm-->(Rn)     1111nnnnmmmm1011
00493    FMOV DRm,@-Rn    Rn-8-->Rn, DRm-->(Rn)     1111nnnnmmm01011
00494    FMOV XDm,@-Rn    Rn-8-->Rn, XDm-->(Rn)     1111nnnnmmm11011 */
00495 /* CV, 2003-08-28: Only suitable with Rn == SP, therefore name changed to
00496                    make this entirely clear.  */
00497 /* #define IS_FMOV(x)           (((x) & 0xf00f) == 0xf00b) */
00498 #define IS_FPUSH(x)             (((x) & 0xff0f) == 0xff0b)
00499 
00500 /* MOV Rm,Rn          Rm-->Rn        0110nnnnmmmm0011  4 <= m <= 7 */
00501 #define IS_MOV_ARG_TO_REG(x) \
00502         (((x) & 0xf00f) == 0x6003 && \
00503          ((x) & 0x00f0) >= 0x0040 && \
00504          ((x) & 0x00f0) <= 0x0070)
00505 /* MOV.L Rm,@Rn               0010nnnnmmmm0010  n = 14, 4 <= m <= 7 */
00506 #define IS_MOV_ARG_TO_IND_R14(x) \
00507         (((x) & 0xff0f) == 0x2e02 && \
00508          ((x) & 0x00f0) >= 0x0040 && \
00509          ((x) & 0x00f0) <= 0x0070)
00510 /* MOV.L Rm,@(disp*4,Rn)      00011110mmmmdddd  n = 14, 4 <= m <= 7 */
00511 #define IS_MOV_ARG_TO_IND_R14_WITH_DISP(x) \
00512         (((x) & 0xff00) == 0x1e00 && \
00513          ((x) & 0x00f0) >= 0x0040 && \
00514          ((x) & 0x00f0) <= 0x0070)
00515 
00516 /* MOV.W @(disp*2,PC),Rn      1001nnnndddddddd */
00517 #define IS_MOVW_PCREL_TO_REG(x) (((x) & 0xf000) == 0x9000)
00518 /* MOV.L @(disp*4,PC),Rn      1101nnnndddddddd */
00519 #define IS_MOVL_PCREL_TO_REG(x) (((x) & 0xf000) == 0xd000)
00520 /* MOVI20 #imm20,Rn           0000nnnniiii0000 */
00521 #define IS_MOVI20(x)            (((x) & 0xf00f) == 0x0000)
00522 /* SUB Rn,R15                 00111111nnnn1000 */
00523 #define IS_SUB_REG_FROM_SP(x)   (((x) & 0xff0f) == 0x3f08)
00524 
00525 #define FPSCR_SZ                (1 << 20)
00526 
00527 /* The following instructions are used for epilogue testing.  */
00528 #define IS_RESTORE_FP(x)        ((x) == 0x6ef6)
00529 #define IS_RTS(x)               ((x) == 0x000b)
00530 #define IS_LDS(x)               ((x) == 0x4f26)
00531 #define IS_MACL_LDS(x)          ((x) == 0x4f16)
00532 #define IS_MOV_FP_SP(x)         ((x) == 0x6fe3)
00533 #define IS_ADD_REG_TO_FP(x)     (((x) & 0xff0f) == 0x3e0c)
00534 #define IS_ADD_IMM_FP(x)        (((x) & 0xff00) == 0x7e00)
00535 
00536 static CORE_ADDR
00537 sh_analyze_prologue (struct gdbarch *gdbarch,
00538                      CORE_ADDR pc, CORE_ADDR limit_pc,
00539                      struct sh_frame_cache *cache, ULONGEST fpscr)
00540 {
00541   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00542   ULONGEST inst;
00543   int offset;
00544   int sav_offset = 0;
00545   int r3_val = 0;
00546   int reg, sav_reg = -1;
00547 
00548   cache->uses_fp = 0;
00549   for (; pc < limit_pc; pc += 2)
00550     {
00551       inst = read_memory_unsigned_integer (pc, 2, byte_order);
00552       /* See where the registers will be saved to.  */
00553       if (IS_PUSH (inst))
00554         {
00555           cache->saved_regs[GET_SOURCE_REG (inst)] = cache->sp_offset;
00556           cache->sp_offset += 4;
00557         }
00558       else if (IS_STS (inst))
00559         {
00560           cache->saved_regs[PR_REGNUM] = cache->sp_offset;
00561           cache->sp_offset += 4;
00562         }
00563       else if (IS_MACL_STS (inst))
00564         {
00565           cache->saved_regs[MACL_REGNUM] = cache->sp_offset;
00566           cache->sp_offset += 4;
00567         }
00568       else if (IS_MOV_R3 (inst))
00569         {
00570           r3_val = ((inst & 0xff) ^ 0x80) - 0x80;
00571         }
00572       else if (IS_SHLL_R3 (inst))
00573         {
00574           r3_val <<= 1;
00575         }
00576       else if (IS_ADD_R3SP (inst))
00577         {
00578           cache->sp_offset += -r3_val;
00579         }
00580       else if (IS_ADD_IMM_SP (inst))
00581         {
00582           offset = ((inst & 0xff) ^ 0x80) - 0x80;
00583           cache->sp_offset -= offset;
00584         }
00585       else if (IS_MOVW_PCREL_TO_REG (inst))
00586         {
00587           if (sav_reg < 0)
00588             {
00589               reg = GET_TARGET_REG (inst);
00590               if (reg < 14)
00591                 {
00592                   sav_reg = reg;
00593                   offset = (inst & 0xff) << 1;
00594                   sav_offset =
00595                     read_memory_integer ((pc + 4) + offset, 2, byte_order);
00596                 }
00597             }
00598         }
00599       else if (IS_MOVL_PCREL_TO_REG (inst))
00600         {
00601           if (sav_reg < 0)
00602             {
00603               reg = GET_TARGET_REG (inst);
00604               if (reg < 14)
00605                 {
00606                   sav_reg = reg;
00607                   offset = (inst & 0xff) << 2;
00608                   sav_offset =
00609                     read_memory_integer (((pc & 0xfffffffc) + 4) + offset,
00610                                          4, byte_order);
00611                 }
00612             }
00613         }
00614       else if (IS_MOVI20 (inst)
00615                && (pc + 2 < limit_pc))
00616         {
00617           if (sav_reg < 0)
00618             {
00619               reg = GET_TARGET_REG (inst);
00620               if (reg < 14)
00621                 {
00622                   sav_reg = reg;
00623                   sav_offset = GET_SOURCE_REG (inst) << 16;
00624                   /* MOVI20 is a 32 bit instruction!  */
00625                   pc += 2;
00626                   sav_offset
00627                     |= read_memory_unsigned_integer (pc, 2, byte_order);
00628                   /* Now sav_offset contains an unsigned 20 bit value.
00629                      It must still get sign extended.  */
00630                   if (sav_offset & 0x00080000)
00631                     sav_offset |= 0xfff00000;
00632                 }
00633             }
00634         }
00635       else if (IS_SUB_REG_FROM_SP (inst))
00636         {
00637           reg = GET_SOURCE_REG (inst);
00638           if (sav_reg > 0 && reg == sav_reg)
00639             {
00640               sav_reg = -1;
00641             }
00642           cache->sp_offset += sav_offset;
00643         }
00644       else if (IS_FPUSH (inst))
00645         {
00646           if (fpscr & FPSCR_SZ)
00647             {
00648               cache->sp_offset += 8;
00649             }
00650           else
00651             {
00652               cache->sp_offset += 4;
00653             }
00654         }
00655       else if (IS_MOV_SP_FP (inst))
00656         {
00657           pc += 2;
00658           /* Don't go any further than six more instructions.  */
00659           limit_pc = min (limit_pc, pc + (2 * 6));
00660 
00661           cache->uses_fp = 1;
00662           /* At this point, only allow argument register moves to other
00663              registers or argument register moves to @(X,fp) which are
00664              moving the register arguments onto the stack area allocated
00665              by a former add somenumber to SP call.  Don't allow moving
00666              to an fp indirect address above fp + cache->sp_offset.  */
00667           for (; pc < limit_pc; pc += 2)
00668             {
00669               inst = read_memory_integer (pc, 2, byte_order);
00670               if (IS_MOV_ARG_TO_IND_R14 (inst))
00671                 {
00672                   reg = GET_SOURCE_REG (inst);
00673                   if (cache->sp_offset > 0)
00674                     cache->saved_regs[reg] = cache->sp_offset;
00675                 }
00676               else if (IS_MOV_ARG_TO_IND_R14_WITH_DISP (inst))
00677                 {
00678                   reg = GET_SOURCE_REG (inst);
00679                   offset = (inst & 0xf) * 4;
00680                   if (cache->sp_offset > offset)
00681                     cache->saved_regs[reg] = cache->sp_offset - offset;
00682                 }
00683               else if (IS_MOV_ARG_TO_REG (inst))
00684                 continue;
00685               else
00686                 break;
00687             }
00688           break;
00689         }
00690       else if (IS_JSR (inst))
00691         {
00692           /* We have found a jsr that has been scheduled into the prologue.
00693              If we continue the scan and return a pc someplace after this,
00694              then setting a breakpoint on this function will cause it to
00695              appear to be called after the function it is calling via the
00696              jsr, which will be very confusing.  Most likely the next
00697              instruction is going to be IS_MOV_SP_FP in the delay slot.  If
00698              so, note that before returning the current pc.  */
00699           if (pc + 2 < limit_pc)
00700             {
00701               inst = read_memory_integer (pc + 2, 2, byte_order);
00702               if (IS_MOV_SP_FP (inst))
00703                 cache->uses_fp = 1;
00704             }
00705           break;
00706         }
00707 #if 0           /* This used to just stop when it found an instruction
00708                    that was not considered part of the prologue.  Now,
00709                    we just keep going looking for likely
00710                    instructions.  */
00711       else
00712         break;
00713 #endif
00714     }
00715 
00716   return pc;
00717 }
00718 
00719 /* Skip any prologue before the guts of a function.  */
00720 static CORE_ADDR
00721 sh_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
00722 {
00723   CORE_ADDR post_prologue_pc, func_addr, func_end_addr, limit_pc;
00724   struct sh_frame_cache cache;
00725 
00726   /* See if we can determine the end of the prologue via the symbol table.
00727      If so, then return either PC, or the PC after the prologue, whichever
00728      is greater.  */
00729   if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr))
00730     {
00731       post_prologue_pc = skip_prologue_using_sal (gdbarch, func_addr);
00732       if (post_prologue_pc != 0)
00733         return max (pc, post_prologue_pc);
00734     }
00735 
00736   /* Can't determine prologue from the symbol table, need to examine
00737      instructions.  */
00738 
00739   /* Find an upper limit on the function prologue using the debug
00740      information.  If the debug information could not be used to provide
00741      that bound, then use an arbitrary large number as the upper bound.  */
00742   limit_pc = skip_prologue_using_sal (gdbarch, pc);
00743   if (limit_pc == 0)
00744     /* Don't go any further than 28 instructions.  */
00745     limit_pc = pc + (2 * 28);
00746 
00747   /* Do not allow limit_pc to be past the function end, if we know
00748      where that end is...  */
00749   if (func_end_addr != 0)
00750     limit_pc = min (limit_pc, func_end_addr);
00751 
00752   cache.sp_offset = -4;
00753   post_prologue_pc = sh_analyze_prologue (gdbarch, pc, limit_pc, &cache, 0);
00754   if (cache.uses_fp)
00755     pc = post_prologue_pc;
00756 
00757   return pc;
00758 }
00759 
00760 /* The ABI says:
00761 
00762    Aggregate types not bigger than 8 bytes that have the same size and
00763    alignment as one of the integer scalar types are returned in the
00764    same registers as the integer type they match.
00765 
00766    For example, a 2-byte aligned structure with size 2 bytes has the
00767    same size and alignment as a short int, and will be returned in R0.
00768    A 4-byte aligned structure with size 8 bytes has the same size and
00769    alignment as a long long int, and will be returned in R0 and R1.
00770 
00771    When an aggregate type is returned in R0 and R1, R0 contains the
00772    first four bytes of the aggregate, and R1 contains the
00773    remainder.  If the size of the aggregate type is not a multiple of 4
00774    bytes, the aggregate is tail-padded up to a multiple of 4
00775    bytes.  The value of the padding is undefined.  For little-endian
00776    targets the padding will appear at the most significant end of the
00777    last element, for big-endian targets the padding appears at the
00778    least significant end of the last element.
00779 
00780    All other aggregate types are returned by address.  The caller
00781    function passes the address of an area large enough to hold the
00782    aggregate value in R2.  The called function stores the result in
00783    this location.
00784 
00785    To reiterate, structs smaller than 8 bytes could also be returned
00786    in memory, if they don't pass the "same size and alignment as an
00787    integer type" rule.
00788 
00789    For example, in
00790 
00791    struct s { char c[3]; } wibble;
00792    struct s foo(void) {  return wibble; }
00793 
00794    the return value from foo() will be in memory, not
00795    in R0, because there is no 3-byte integer type.
00796 
00797    Similarly, in 
00798 
00799    struct s { char c[2]; } wibble;
00800    struct s foo(void) {  return wibble; }
00801 
00802    because a struct containing two chars has alignment 1, that matches
00803    type char, but size 2, that matches type short.  There's no integer
00804    type that has alignment 1 and size 2, so the struct is returned in
00805    memory.  */
00806 
00807 static int
00808 sh_use_struct_convention (int renesas_abi, struct type *type)
00809 {
00810   int len = TYPE_LENGTH (type);
00811   int nelem = TYPE_NFIELDS (type);
00812 
00813   /* The Renesas ABI returns aggregate types always on stack.  */
00814   if (renesas_abi && (TYPE_CODE (type) == TYPE_CODE_STRUCT
00815                       || TYPE_CODE (type) == TYPE_CODE_UNION))
00816     return 1;
00817 
00818   /* Non-power of 2 length types and types bigger than 8 bytes (which don't
00819      fit in two registers anyway) use struct convention.  */
00820   if (len != 1 && len != 2 && len != 4 && len != 8)
00821     return 1;
00822 
00823   /* Scalar types and aggregate types with exactly one field are aligned
00824      by definition.  They are returned in registers.  */
00825   if (nelem <= 1)
00826     return 0;
00827 
00828   /* If the first field in the aggregate has the same length as the entire
00829      aggregate type, the type is returned in registers.  */
00830   if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == len)
00831     return 0;
00832 
00833   /* If the size of the aggregate is 8 bytes and the first field is
00834      of size 4 bytes its alignment is equal to long long's alignment,
00835      so it's returned in registers.  */
00836   if (len == 8 && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4)
00837     return 0;
00838 
00839   /* Otherwise use struct convention.  */
00840   return 1;
00841 }
00842 
00843 static int
00844 sh_use_struct_convention_nofpu (int renesas_abi, struct type *type)
00845 {
00846   /* The Renesas ABI returns long longs/doubles etc. always on stack.  */
00847   if (renesas_abi && TYPE_NFIELDS (type) == 0 && TYPE_LENGTH (type) >= 8)
00848     return 1;
00849   return sh_use_struct_convention (renesas_abi, type);
00850 }
00851 
00852 static CORE_ADDR
00853 sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
00854 {
00855   return sp & ~3;
00856 }
00857 
00858 /* Function: push_dummy_call (formerly push_arguments)
00859    Setup the function arguments for calling a function in the inferior.
00860 
00861    On the Renesas SH architecture, there are four registers (R4 to R7)
00862    which are dedicated for passing function arguments.  Up to the first
00863    four arguments (depending on size) may go into these registers.
00864    The rest go on the stack.
00865 
00866    MVS: Except on SH variants that have floating point registers.
00867    In that case, float and double arguments are passed in the same
00868    manner, but using FP registers instead of GP registers.
00869 
00870    Arguments that are smaller than 4 bytes will still take up a whole
00871    register or a whole 32-bit word on the stack, and will be 
00872    right-justified in the register or the stack word.  This includes
00873    chars, shorts, and small aggregate types.
00874 
00875    Arguments that are larger than 4 bytes may be split between two or 
00876    more registers.  If there are not enough registers free, an argument
00877    may be passed partly in a register (or registers), and partly on the
00878    stack.  This includes doubles, long longs, and larger aggregates.
00879    As far as I know, there is no upper limit to the size of aggregates 
00880    that will be passed in this way; in other words, the convention of 
00881    passing a pointer to a large aggregate instead of a copy is not used.
00882 
00883    MVS: The above appears to be true for the SH variants that do not
00884    have an FPU, however those that have an FPU appear to copy the
00885    aggregate argument onto the stack (and not place it in registers)
00886    if it is larger than 16 bytes (four GP registers).
00887 
00888    An exceptional case exists for struct arguments (and possibly other
00889    aggregates such as arrays) if the size is larger than 4 bytes but 
00890    not a multiple of 4 bytes.  In this case the argument is never split 
00891    between the registers and the stack, but instead is copied in its
00892    entirety onto the stack, AND also copied into as many registers as 
00893    there is room for.  In other words, space in registers permitting, 
00894    two copies of the same argument are passed in.  As far as I can tell,
00895    only the one on the stack is used, although that may be a function 
00896    of the level of compiler optimization.  I suspect this is a compiler
00897    bug.  Arguments of these odd sizes are left-justified within the 
00898    word (as opposed to arguments smaller than 4 bytes, which are 
00899    right-justified).
00900 
00901    If the function is to return an aggregate type such as a struct, it 
00902    is either returned in the normal return value register R0 (if its 
00903    size is no greater than one byte), or else the caller must allocate
00904    space into which the callee will copy the return value (if the size
00905    is greater than one byte).  In this case, a pointer to the return 
00906    value location is passed into the callee in register R2, which does 
00907    not displace any of the other arguments passed in via registers R4
00908    to R7.  */
00909 
00910 /* Helper function to justify value in register according to endianess.  */
00911 static const gdb_byte *
00912 sh_justify_value_in_reg (struct gdbarch *gdbarch, struct value *val, int len)
00913 {
00914   static gdb_byte valbuf[4];
00915 
00916   memset (valbuf, 0, sizeof (valbuf));
00917   if (len < 4)
00918     {
00919       /* value gets right-justified in the register or stack word.  */
00920       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
00921         memcpy (valbuf + (4 - len), value_contents (val), len);
00922       else
00923         memcpy (valbuf, value_contents (val), len);
00924       return valbuf;
00925     }
00926   return value_contents (val);
00927 }
00928 
00929 /* Helper function to eval number of bytes to allocate on stack.  */
00930 static CORE_ADDR
00931 sh_stack_allocsize (int nargs, struct value **args)
00932 {
00933   int stack_alloc = 0;
00934   while (nargs-- > 0)
00935     stack_alloc += ((TYPE_LENGTH (value_type (args[nargs])) + 3) & ~3);
00936   return stack_alloc;
00937 }
00938 
00939 /* Helper functions for getting the float arguments right.  Registers usage
00940    depends on the ABI and the endianess.  The comments should enlighten how
00941    it's intended to work.  */
00942 
00943 /* This array stores which of the float arg registers are already in use.  */
00944 static int flt_argreg_array[FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM + 1];
00945 
00946 /* This function just resets the above array to "no reg used so far".  */
00947 static void
00948 sh_init_flt_argreg (void)
00949 {
00950   memset (flt_argreg_array, 0, sizeof flt_argreg_array);
00951 }
00952 
00953 /* This function returns the next register to use for float arg passing.
00954    It returns either a valid value between FLOAT_ARG0_REGNUM and
00955    FLOAT_ARGLAST_REGNUM if a register is available, otherwise it returns 
00956    FLOAT_ARGLAST_REGNUM + 1 to indicate that no register is available.
00957 
00958    Note that register number 0 in flt_argreg_array corresponds with the
00959    real float register fr4.  In contrast to FLOAT_ARG0_REGNUM (value is
00960    29) the parity of the register number is preserved, which is important
00961    for the double register passing test (see the "argreg & 1" test below).  */
00962 static int
00963 sh_next_flt_argreg (struct gdbarch *gdbarch, int len, struct type *func_type)
00964 {
00965   int argreg;
00966 
00967   /* First search for the next free register.  */
00968   for (argreg = 0; argreg <= FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM;
00969        ++argreg)
00970     if (!flt_argreg_array[argreg])
00971       break;
00972 
00973   /* No register left?  */
00974   if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
00975     return FLOAT_ARGLAST_REGNUM + 1;
00976 
00977   if (len == 8)
00978     {
00979       /* Doubles are always starting in a even register number.  */
00980       if (argreg & 1)
00981         {
00982           /* In gcc ABI, the skipped register is lost for further argument
00983              passing now.  Not so in Renesas ABI.  */
00984           if (!sh_is_renesas_calling_convention (func_type))
00985             flt_argreg_array[argreg] = 1;
00986 
00987           ++argreg;
00988 
00989           /* No register left?  */
00990           if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
00991             return FLOAT_ARGLAST_REGNUM + 1;
00992         }
00993       /* Also mark the next register as used.  */
00994       flt_argreg_array[argreg + 1] = 1;
00995     }
00996   else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
00997            && !sh_is_renesas_calling_convention (func_type))
00998     {
00999       /* In little endian, gcc passes floats like this: f5, f4, f7, f6, ...  */
01000       if (!flt_argreg_array[argreg + 1])
01001         ++argreg;
01002     }
01003   flt_argreg_array[argreg] = 1;
01004   return FLOAT_ARG0_REGNUM + argreg;
01005 }
01006 
01007 /* Helper function which figures out, if a type is treated like a float type.
01008 
01009    The FPU ABIs have a special way how to treat types as float types.
01010    Structures with exactly one member, which is of type float or double, are
01011    treated exactly as the base types float or double:
01012 
01013      struct sf {
01014        float f;
01015      };
01016 
01017      struct sd {
01018        double d;
01019      };
01020 
01021    are handled the same way as just
01022 
01023      float f;
01024 
01025      double d;
01026 
01027    As a result, arguments of these struct types are pushed into floating point
01028    registers exactly as floats or doubles, using the same decision algorithm.
01029 
01030    The same is valid if these types are used as function return types.  The
01031    above structs are returned in fr0 resp. fr0,fr1 instead of in r0, r0,r1
01032    or even using struct convention as it is for other structs.  */
01033 
01034 static int
01035 sh_treat_as_flt_p (struct type *type)
01036 {
01037   /* Ordinary float types are obviously treated as float.  */
01038   if (TYPE_CODE (type) == TYPE_CODE_FLT)
01039     return 1;
01040   /* Otherwise non-struct types are not treated as float.  */
01041   if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
01042     return 0;
01043   /* Otherwise structs with more than one memeber are not treated as float.  */
01044   if (TYPE_NFIELDS (type) != 1)
01045     return 0;
01046   /* Otherwise if the type of that member is float, the whole type is
01047      treated as float.  */
01048   if (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT)
01049     return 1;
01050   /* Otherwise it's not treated as float.  */
01051   return 0;
01052 }
01053 
01054 static CORE_ADDR
01055 sh_push_dummy_call_fpu (struct gdbarch *gdbarch,
01056                         struct value *function,
01057                         struct regcache *regcache,
01058                         CORE_ADDR bp_addr, int nargs,
01059                         struct value **args,
01060                         CORE_ADDR sp, int struct_return,
01061                         CORE_ADDR struct_addr)
01062 {
01063   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01064   int stack_offset = 0;
01065   int argreg = ARG0_REGNUM;
01066   int flt_argreg = 0;
01067   int argnum;
01068   struct type *func_type = value_type (function);
01069   struct type *type;
01070   CORE_ADDR regval;
01071   const gdb_byte *val;
01072   int len, reg_size = 0;
01073   int pass_on_stack = 0;
01074   int treat_as_flt;
01075   int last_reg_arg = INT_MAX;
01076 
01077   /* The Renesas ABI expects all varargs arguments, plus the last
01078      non-vararg argument to be on the stack, no matter how many
01079      registers have been used so far.  */
01080   if (sh_is_renesas_calling_convention (func_type)
01081       && TYPE_VARARGS (func_type))
01082     last_reg_arg = TYPE_NFIELDS (func_type) - 2;
01083 
01084   /* First force sp to a 4-byte alignment.  */
01085   sp = sh_frame_align (gdbarch, sp);
01086 
01087   /* Make room on stack for args.  */
01088   sp -= sh_stack_allocsize (nargs, args);
01089 
01090   /* Initialize float argument mechanism.  */
01091   sh_init_flt_argreg ();
01092 
01093   /* Now load as many as possible of the first arguments into
01094      registers, and push the rest onto the stack.  There are 16 bytes
01095      in four registers available.  Loop thru args from first to last.  */
01096   for (argnum = 0; argnum < nargs; argnum++)
01097     {
01098       type = value_type (args[argnum]);
01099       len = TYPE_LENGTH (type);
01100       val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
01101 
01102       /* Some decisions have to be made how various types are handled.
01103          This also differs in different ABIs.  */
01104       pass_on_stack = 0;
01105 
01106       /* Find out the next register to use for a floating point value.  */
01107       treat_as_flt = sh_treat_as_flt_p (type);
01108       if (treat_as_flt)
01109         flt_argreg = sh_next_flt_argreg (gdbarch, len, func_type);
01110       /* In Renesas ABI, long longs and aggregate types are always passed
01111          on stack.  */
01112       else if (sh_is_renesas_calling_convention (func_type)
01113                && ((TYPE_CODE (type) == TYPE_CODE_INT && len == 8)
01114                    || TYPE_CODE (type) == TYPE_CODE_STRUCT
01115                    || TYPE_CODE (type) == TYPE_CODE_UNION))
01116         pass_on_stack = 1;
01117       /* In contrast to non-FPU CPUs, arguments are never split between
01118          registers and stack.  If an argument doesn't fit in the remaining
01119          registers it's always pushed entirely on the stack.  */
01120       else if (len > ((ARGLAST_REGNUM - argreg + 1) * 4))
01121         pass_on_stack = 1;
01122 
01123       while (len > 0)
01124         {
01125           if ((treat_as_flt && flt_argreg > FLOAT_ARGLAST_REGNUM)
01126               || (!treat_as_flt && (argreg > ARGLAST_REGNUM
01127                                     || pass_on_stack))
01128               || argnum > last_reg_arg)
01129             {
01130               /* The data goes entirely on the stack, 4-byte aligned.  */
01131               reg_size = (len + 3) & ~3;
01132               write_memory (sp + stack_offset, val, reg_size);
01133               stack_offset += reg_size;
01134             }
01135           else if (treat_as_flt && flt_argreg <= FLOAT_ARGLAST_REGNUM)
01136             {
01137               /* Argument goes in a float argument register.  */
01138               reg_size = register_size (gdbarch, flt_argreg);
01139               regval = extract_unsigned_integer (val, reg_size, byte_order);
01140               /* In little endian mode, float types taking two registers
01141                  (doubles on sh4, long doubles on sh2e, sh3e and sh4) must
01142                  be stored swapped in the argument registers.  The below
01143                  code first writes the first 32 bits in the next but one
01144                  register, increments the val and len values accordingly
01145                  and then proceeds as normal by writing the second 32 bits
01146                  into the next register.  */
01147               if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
01148                   && TYPE_LENGTH (type) == 2 * reg_size)
01149                 {
01150                   regcache_cooked_write_unsigned (regcache, flt_argreg + 1,
01151                                                   regval);
01152                   val += reg_size;
01153                   len -= reg_size;
01154                   regval = extract_unsigned_integer (val, reg_size,
01155                                                      byte_order);
01156                 }
01157               regcache_cooked_write_unsigned (regcache, flt_argreg++, regval);
01158             }
01159           else if (!treat_as_flt && argreg <= ARGLAST_REGNUM)
01160             {
01161               /* there's room in a register */
01162               reg_size = register_size (gdbarch, argreg);
01163               regval = extract_unsigned_integer (val, reg_size, byte_order);
01164               regcache_cooked_write_unsigned (regcache, argreg++, regval);
01165             }
01166           /* Store the value one register at a time or in one step on
01167              stack.  */
01168           len -= reg_size;
01169           val += reg_size;
01170         }
01171     }
01172 
01173   if (struct_return)
01174     {
01175       if (sh_is_renesas_calling_convention (func_type))
01176         /* If the function uses the Renesas ABI, subtract another 4 bytes from
01177            the stack and store the struct return address there.  */
01178         write_memory_unsigned_integer (sp -= 4, 4, byte_order, struct_addr);
01179       else
01180         /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
01181            its own dedicated register.  */
01182         regcache_cooked_write_unsigned (regcache,
01183                                         STRUCT_RETURN_REGNUM, struct_addr);
01184     }
01185 
01186   /* Store return address.  */
01187   regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
01188 
01189   /* Update stack pointer.  */
01190   regcache_cooked_write_unsigned (regcache,
01191                                   gdbarch_sp_regnum (gdbarch), sp);
01192 
01193   return sp;
01194 }
01195 
01196 static CORE_ADDR
01197 sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
01198                           struct value *function,
01199                           struct regcache *regcache,
01200                           CORE_ADDR bp_addr,
01201                           int nargs, struct value **args,
01202                           CORE_ADDR sp, int struct_return,
01203                           CORE_ADDR struct_addr)
01204 {
01205   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01206   int stack_offset = 0;
01207   int argreg = ARG0_REGNUM;
01208   int argnum;
01209   struct type *func_type = value_type (function);
01210   struct type *type;
01211   CORE_ADDR regval;
01212   const gdb_byte *val;
01213   int len, reg_size = 0;
01214   int pass_on_stack = 0;
01215   int last_reg_arg = INT_MAX;
01216 
01217   /* The Renesas ABI expects all varargs arguments, plus the last
01218      non-vararg argument to be on the stack, no matter how many
01219      registers have been used so far.  */
01220   if (sh_is_renesas_calling_convention (func_type)
01221       && TYPE_VARARGS (func_type))
01222     last_reg_arg = TYPE_NFIELDS (func_type) - 2;
01223 
01224   /* First force sp to a 4-byte alignment.  */
01225   sp = sh_frame_align (gdbarch, sp);
01226 
01227   /* Make room on stack for args.  */
01228   sp -= sh_stack_allocsize (nargs, args);
01229 
01230   /* Now load as many as possible of the first arguments into
01231      registers, and push the rest onto the stack.  There are 16 bytes
01232      in four registers available.  Loop thru args from first to last.  */
01233   for (argnum = 0; argnum < nargs; argnum++)
01234     {
01235       type = value_type (args[argnum]);
01236       len = TYPE_LENGTH (type);
01237       val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
01238 
01239       /* Some decisions have to be made how various types are handled.
01240          This also differs in different ABIs.  */
01241       pass_on_stack = 0;
01242       /* Renesas ABI pushes doubles and long longs entirely on stack.
01243          Same goes for aggregate types.  */
01244       if (sh_is_renesas_calling_convention (func_type)
01245           && ((TYPE_CODE (type) == TYPE_CODE_INT && len >= 8)
01246               || (TYPE_CODE (type) == TYPE_CODE_FLT && len >= 8)
01247               || TYPE_CODE (type) == TYPE_CODE_STRUCT
01248               || TYPE_CODE (type) == TYPE_CODE_UNION))
01249         pass_on_stack = 1;
01250       while (len > 0)
01251         {
01252           if (argreg > ARGLAST_REGNUM || pass_on_stack
01253               || argnum > last_reg_arg)
01254             {
01255               /* The remainder of the data goes entirely on the stack,
01256                  4-byte aligned.  */
01257               reg_size = (len + 3) & ~3;
01258               write_memory (sp + stack_offset, val, reg_size);
01259               stack_offset += reg_size;
01260             }
01261           else if (argreg <= ARGLAST_REGNUM)
01262             {
01263               /* There's room in a register.  */
01264               reg_size = register_size (gdbarch, argreg);
01265               regval = extract_unsigned_integer (val, reg_size, byte_order);
01266               regcache_cooked_write_unsigned (regcache, argreg++, regval);
01267             }
01268           /* Store the value reg_size bytes at a time.  This means that things
01269              larger than reg_size bytes may go partly in registers and partly
01270              on the stack.  */
01271           len -= reg_size;
01272           val += reg_size;
01273         }
01274     }
01275 
01276   if (struct_return)
01277     {
01278       if (sh_is_renesas_calling_convention (func_type))
01279         /* If the function uses the Renesas ABI, subtract another 4 bytes from
01280            the stack and store the struct return address there.  */
01281         write_memory_unsigned_integer (sp -= 4, 4, byte_order, struct_addr);
01282       else
01283         /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
01284            its own dedicated register.  */
01285         regcache_cooked_write_unsigned (regcache,
01286                                         STRUCT_RETURN_REGNUM, struct_addr);
01287     }
01288 
01289   /* Store return address.  */
01290   regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
01291 
01292   /* Update stack pointer.  */
01293   regcache_cooked_write_unsigned (regcache,
01294                                   gdbarch_sp_regnum (gdbarch), sp);
01295 
01296   return sp;
01297 }
01298 
01299 /* Find a function's return value in the appropriate registers (in
01300    regbuf), and copy it into valbuf.  Extract from an array REGBUF
01301    containing the (raw) register state a function return value of type
01302    TYPE, and copy that, in virtual format, into VALBUF.  */
01303 static void
01304 sh_extract_return_value_nofpu (struct type *type, struct regcache *regcache,
01305                                gdb_byte *valbuf)
01306 {
01307   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01308   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01309   int len = TYPE_LENGTH (type);
01310   int return_register = R0_REGNUM;
01311   int offset;
01312 
01313   if (len <= 4)
01314     {
01315       ULONGEST c;
01316 
01317       regcache_cooked_read_unsigned (regcache, R0_REGNUM, &c);
01318       store_unsigned_integer (valbuf, len, byte_order, c);
01319     }
01320   else if (len == 8)
01321     {
01322       int i, regnum = R0_REGNUM;
01323       for (i = 0; i < len; i += 4)
01324         regcache_raw_read (regcache, regnum++, valbuf + i);
01325     }
01326   else
01327     error (_("bad size for return value"));
01328 }
01329 
01330 static void
01331 sh_extract_return_value_fpu (struct type *type, struct regcache *regcache,
01332                              gdb_byte *valbuf)
01333 {
01334   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01335   if (sh_treat_as_flt_p (type))
01336     {
01337       int len = TYPE_LENGTH (type);
01338       int i, regnum = gdbarch_fp0_regnum (gdbarch);
01339       for (i = 0; i < len; i += 4)
01340         if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
01341           regcache_raw_read (regcache, regnum++,
01342                              valbuf + len - 4 - i);
01343         else
01344           regcache_raw_read (regcache, regnum++, valbuf + i);
01345     }
01346   else
01347     sh_extract_return_value_nofpu (type, regcache, valbuf);
01348 }
01349 
01350 /* Write into appropriate registers a function return value
01351    of type TYPE, given in virtual format.
01352    If the architecture is sh4 or sh3e, store a function's return value
01353    in the R0 general register or in the FP0 floating point register,
01354    depending on the type of the return value.  In all the other cases
01355    the result is stored in r0, left-justified.  */
01356 static void
01357 sh_store_return_value_nofpu (struct type *type, struct regcache *regcache,
01358                              const gdb_byte *valbuf)
01359 {
01360   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01361   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01362   ULONGEST val;
01363   int len = TYPE_LENGTH (type);
01364 
01365   if (len <= 4)
01366     {
01367       val = extract_unsigned_integer (valbuf, len, byte_order);
01368       regcache_cooked_write_unsigned (regcache, R0_REGNUM, val);
01369     }
01370   else
01371     {
01372       int i, regnum = R0_REGNUM;
01373       for (i = 0; i < len; i += 4)
01374         regcache_raw_write (regcache, regnum++, valbuf + i);
01375     }
01376 }
01377 
01378 static void
01379 sh_store_return_value_fpu (struct type *type, struct regcache *regcache,
01380                            const gdb_byte *valbuf)
01381 {
01382   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01383   if (sh_treat_as_flt_p (type))
01384     {
01385       int len = TYPE_LENGTH (type);
01386       int i, regnum = gdbarch_fp0_regnum (gdbarch);
01387       for (i = 0; i < len; i += 4)
01388         if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
01389           regcache_raw_write (regcache, regnum++,
01390                               valbuf + len - 4 - i);
01391         else
01392           regcache_raw_write (regcache, regnum++, valbuf + i);
01393     }
01394   else
01395     sh_store_return_value_nofpu (type, regcache, valbuf);
01396 }
01397 
01398 static enum return_value_convention
01399 sh_return_value_nofpu (struct gdbarch *gdbarch, struct value *function,
01400                        struct type *type, struct regcache *regcache,
01401                        gdb_byte *readbuf, const gdb_byte *writebuf)
01402 {
01403   struct type *func_type = function ? value_type (function) : NULL;
01404 
01405   if (sh_use_struct_convention_nofpu (
01406         sh_is_renesas_calling_convention (func_type), type))
01407     return RETURN_VALUE_STRUCT_CONVENTION;
01408   if (writebuf)
01409     sh_store_return_value_nofpu (type, regcache, writebuf);
01410   else if (readbuf)
01411     sh_extract_return_value_nofpu (type, regcache, readbuf);
01412   return RETURN_VALUE_REGISTER_CONVENTION;
01413 }
01414 
01415 static enum return_value_convention
01416 sh_return_value_fpu (struct gdbarch *gdbarch, struct value *function,
01417                      struct type *type, struct regcache *regcache,
01418                      gdb_byte *readbuf, const gdb_byte *writebuf)
01419 {
01420   struct type *func_type = function ? value_type (function) : NULL;
01421 
01422   if (sh_use_struct_convention (
01423         sh_is_renesas_calling_convention (func_type), type))
01424     return RETURN_VALUE_STRUCT_CONVENTION;
01425   if (writebuf)
01426     sh_store_return_value_fpu (type, regcache, writebuf);
01427   else if (readbuf)
01428     sh_extract_return_value_fpu (type, regcache, readbuf);
01429   return RETURN_VALUE_REGISTER_CONVENTION;
01430 }
01431 
01432 static struct type *
01433 sh_sh2a_register_type (struct gdbarch *gdbarch, int reg_nr)
01434 {
01435   if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
01436        && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
01437     return builtin_type (gdbarch)->builtin_float;
01438   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
01439     return builtin_type (gdbarch)->builtin_double;
01440   else
01441     return builtin_type (gdbarch)->builtin_int;
01442 }
01443 
01444 /* Return the GDB type object for the "standard" data type
01445    of data in register N.  */
01446 static struct type *
01447 sh_sh3e_register_type (struct gdbarch *gdbarch, int reg_nr)
01448 {
01449   if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
01450        && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
01451     return builtin_type (gdbarch)->builtin_float;
01452   else
01453     return builtin_type (gdbarch)->builtin_int;
01454 }
01455 
01456 static struct type *
01457 sh_sh4_build_float_register_type (struct gdbarch *gdbarch, int high)
01458 {
01459   return lookup_array_range_type (builtin_type (gdbarch)->builtin_float,
01460                                   0, high);
01461 }
01462 
01463 static struct type *
01464 sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
01465 {
01466   if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
01467        && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
01468     return builtin_type (gdbarch)->builtin_float;
01469   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
01470     return builtin_type (gdbarch)->builtin_double;
01471   else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
01472     return sh_sh4_build_float_register_type (gdbarch, 3);
01473   else
01474     return builtin_type (gdbarch)->builtin_int;
01475 }
01476 
01477 static struct type *
01478 sh_default_register_type (struct gdbarch *gdbarch, int reg_nr)
01479 {
01480   return builtin_type (gdbarch)->builtin_int;
01481 }
01482 
01483 /* Is a register in a reggroup?
01484    The default code in reggroup.c doesn't identify system registers, some
01485    float registers or any of the vector registers.
01486    TODO: sh2a and dsp registers.  */
01487 static int
01488 sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
01489                         struct reggroup *reggroup)
01490 {
01491   if (gdbarch_register_name (gdbarch, regnum) == NULL
01492       || *gdbarch_register_name (gdbarch, regnum) == '\0')
01493     return 0;
01494 
01495   if (reggroup == float_reggroup
01496       && (regnum == FPUL_REGNUM
01497           || regnum == FPSCR_REGNUM))
01498     return 1;
01499 
01500   if (regnum >= FV0_REGNUM && regnum <= FV_LAST_REGNUM)
01501     {
01502       if (reggroup == vector_reggroup || reggroup == float_reggroup)
01503         return 1;
01504       if (reggroup == general_reggroup)
01505         return 0;
01506     }
01507 
01508   if (regnum == VBR_REGNUM
01509       || regnum == SR_REGNUM
01510       || regnum == FPSCR_REGNUM
01511       || regnum == SSR_REGNUM
01512       || regnum == SPC_REGNUM)
01513     {
01514       if (reggroup == system_reggroup)
01515         return 1;
01516       if (reggroup == general_reggroup)
01517         return 0;
01518     }
01519 
01520   /* The default code can cope with any other registers.  */
01521   return default_register_reggroup_p (gdbarch, regnum, reggroup);
01522 }
01523 
01524 /* On the sh4, the DRi pseudo registers are problematic if the target
01525    is little endian.  When the user writes one of those registers, for
01526    instance with 'set var $dr0=1', we want the double to be stored
01527    like this: 
01528    fr0 = 0x00 0x00 0xf0 0x3f 
01529    fr1 = 0x00 0x00 0x00 0x00 
01530 
01531    This corresponds to little endian byte order & big endian word
01532    order.  However if we let gdb write the register w/o conversion, it
01533    will write fr0 and fr1 this way:
01534    fr0 = 0x00 0x00 0x00 0x00
01535    fr1 = 0x00 0x00 0xf0 0x3f
01536    because it will consider fr0 and fr1 as a single LE stretch of memory.
01537    
01538    To achieve what we want we must force gdb to store things in
01539    floatformat_ieee_double_littlebyte_bigword (which is defined in
01540    include/floatformat.h and libiberty/floatformat.c.
01541 
01542    In case the target is big endian, there is no problem, the
01543    raw bytes will look like:
01544    fr0 = 0x3f 0xf0 0x00 0x00
01545    fr1 = 0x00 0x00 0x00 0x00
01546 
01547    The other pseudo registers (the FVs) also don't pose a problem
01548    because they are stored as 4 individual FP elements.  */
01549 
01550 static void
01551 sh_register_convert_to_virtual (struct gdbarch *gdbarch, int regnum,
01552                                 struct type *type, gdb_byte *from, gdb_byte *to)
01553 {
01554   if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_LITTLE)
01555     {
01556       /* It is a no-op.  */
01557       memcpy (to, from, register_size (gdbarch, regnum));
01558       return;
01559     }
01560 
01561   if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
01562     {
01563       DOUBLEST val;
01564       floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword,
01565                                from, &val);
01566       store_typed_floating (to, type, val);
01567     }
01568   else
01569     error
01570       ("sh_register_convert_to_virtual called with non DR register number");
01571 }
01572 
01573 static void
01574 sh_register_convert_to_raw (struct gdbarch *gdbarch, struct type *type,
01575                             int regnum, const gdb_byte *from, gdb_byte *to)
01576 {
01577   if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_LITTLE)
01578     {
01579       /* It is a no-op.  */
01580       memcpy (to, from, register_size (gdbarch, regnum));
01581       return;
01582     }
01583 
01584   if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
01585     {
01586       DOUBLEST val = extract_typed_floating (from, type);
01587       floatformat_from_doublest (&floatformat_ieee_double_littlebyte_bigword,
01588                                  &val, to);
01589     }
01590   else
01591     error (_("sh_register_convert_to_raw called with non DR register number"));
01592 }
01593 
01594 /* For vectors of 4 floating point registers.  */
01595 static int
01596 fv_reg_base_num (struct gdbarch *gdbarch, int fv_regnum)
01597 {
01598   int fp_regnum;
01599 
01600   fp_regnum = gdbarch_fp0_regnum (gdbarch)
01601               + (fv_regnum - FV0_REGNUM) * 4;
01602   return fp_regnum;
01603 }
01604 
01605 /* For double precision floating point registers, i.e 2 fp regs.  */
01606 static int
01607 dr_reg_base_num (struct gdbarch *gdbarch, int dr_regnum)
01608 {
01609   int fp_regnum;
01610 
01611   fp_regnum = gdbarch_fp0_regnum (gdbarch)
01612               + (dr_regnum - DR0_REGNUM) * 2;
01613   return fp_regnum;
01614 }
01615 
01616 /* Concatenate PORTIONS contiguous raw registers starting at
01617    BASE_REGNUM into BUFFER.  */
01618 
01619 static enum register_status
01620 pseudo_register_read_portions (struct gdbarch *gdbarch,
01621                                struct regcache *regcache,
01622                                int portions,
01623                                int base_regnum, gdb_byte *buffer)
01624 {
01625   int portion;
01626 
01627   for (portion = 0; portion < portions; portion++)
01628     {
01629       enum register_status status;
01630       gdb_byte *b;
01631 
01632       b = buffer + register_size (gdbarch, base_regnum) * portion;
01633       status = regcache_raw_read (regcache, base_regnum + portion, b);
01634       if (status != REG_VALID)
01635         return status;
01636     }
01637 
01638   return REG_VALID;
01639 }
01640 
01641 static enum register_status
01642 sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
01643                          int reg_nr, gdb_byte *buffer)
01644 {
01645   int base_regnum;
01646   gdb_byte temp_buffer[MAX_REGISTER_SIZE];
01647   enum register_status status;
01648 
01649   if (reg_nr == PSEUDO_BANK_REGNUM)
01650     return regcache_raw_read (regcache, BANK_REGNUM, buffer);
01651   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
01652     {
01653       base_regnum = dr_reg_base_num (gdbarch, reg_nr);
01654 
01655       /* Build the value in the provided buffer.  */
01656       /* Read the real regs for which this one is an alias.  */
01657       status = pseudo_register_read_portions (gdbarch, regcache,
01658                                               2, base_regnum, temp_buffer);
01659       if (status == REG_VALID)
01660         {
01661           /* We must pay attention to the endiannes. */
01662           sh_register_convert_to_virtual (gdbarch, reg_nr,
01663                                           register_type (gdbarch, reg_nr),
01664                                           temp_buffer, buffer);
01665         }
01666       return status;
01667     }
01668   else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
01669     {
01670       base_regnum = fv_reg_base_num (gdbarch, reg_nr);
01671 
01672       /* Read the real regs for which this one is an alias.  */
01673       return pseudo_register_read_portions (gdbarch, regcache,
01674                                             4, base_regnum, buffer);
01675     }
01676   else
01677     gdb_assert_not_reached ("invalid pseudo register number");
01678 }
01679 
01680 static void
01681 sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
01682                           int reg_nr, const gdb_byte *buffer)
01683 {
01684   int base_regnum, portion;
01685   gdb_byte temp_buffer[MAX_REGISTER_SIZE];
01686 
01687   if (reg_nr == PSEUDO_BANK_REGNUM)
01688     {
01689       /* When the bank register is written to, the whole register bank
01690          is switched and all values in the bank registers must be read
01691          from the target/sim again.  We're just invalidating the regcache
01692          so that a re-read happens next time it's necessary.  */
01693       int bregnum;
01694 
01695       regcache_raw_write (regcache, BANK_REGNUM, buffer);
01696       for (bregnum = R0_BANK0_REGNUM; bregnum < MACLB_REGNUM; ++bregnum)
01697         regcache_invalidate (regcache, bregnum);
01698     }
01699   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
01700     {
01701       base_regnum = dr_reg_base_num (gdbarch, reg_nr);
01702 
01703       /* We must pay attention to the endiannes.  */
01704       sh_register_convert_to_raw (gdbarch, register_type (gdbarch, reg_nr),
01705                                   reg_nr, buffer, temp_buffer);
01706 
01707       /* Write the real regs for which this one is an alias.  */
01708       for (portion = 0; portion < 2; portion++)
01709         regcache_raw_write (regcache, base_regnum + portion,
01710                             (temp_buffer
01711                              + register_size (gdbarch,
01712                                               base_regnum) * portion));
01713     }
01714   else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
01715     {
01716       base_regnum = fv_reg_base_num (gdbarch, reg_nr);
01717 
01718       /* Write the real regs for which this one is an alias.  */
01719       for (portion = 0; portion < 4; portion++)
01720         regcache_raw_write (regcache, base_regnum + portion,
01721                             (buffer
01722                              + register_size (gdbarch,
01723                                               base_regnum) * portion));
01724     }
01725 }
01726 
01727 static int
01728 sh_dsp_register_sim_regno (struct gdbarch *gdbarch, int nr)
01729 {
01730   if (legacy_register_sim_regno (gdbarch, nr) < 0)
01731     return legacy_register_sim_regno (gdbarch, nr);
01732   if (nr >= DSR_REGNUM && nr <= Y1_REGNUM)
01733     return nr - DSR_REGNUM + SIM_SH_DSR_REGNUM;
01734   if (nr == MOD_REGNUM)
01735     return SIM_SH_MOD_REGNUM;
01736   if (nr == RS_REGNUM)
01737     return SIM_SH_RS_REGNUM;
01738   if (nr == RE_REGNUM)
01739     return SIM_SH_RE_REGNUM;
01740   if (nr >= DSP_R0_BANK_REGNUM && nr <= DSP_R7_BANK_REGNUM)
01741     return nr - DSP_R0_BANK_REGNUM + SIM_SH_R0_BANK_REGNUM;
01742   return nr;
01743 }
01744 
01745 static int
01746 sh_sh2a_register_sim_regno (struct gdbarch *gdbarch, int nr)
01747 {
01748   switch (nr)
01749     {
01750       case TBR_REGNUM:
01751         return SIM_SH_TBR_REGNUM;
01752       case IBNR_REGNUM:
01753         return SIM_SH_IBNR_REGNUM;
01754       case IBCR_REGNUM:
01755         return SIM_SH_IBCR_REGNUM;
01756       case BANK_REGNUM:
01757         return SIM_SH_BANK_REGNUM;
01758       case MACLB_REGNUM:
01759         return SIM_SH_BANK_MACL_REGNUM;
01760       case GBRB_REGNUM:
01761         return SIM_SH_BANK_GBR_REGNUM;
01762       case PRB_REGNUM:
01763         return SIM_SH_BANK_PR_REGNUM;
01764       case IVNB_REGNUM:
01765         return SIM_SH_BANK_IVN_REGNUM;
01766       case MACHB_REGNUM:
01767         return SIM_SH_BANK_MACH_REGNUM;
01768       default:
01769         break;
01770     }
01771   return legacy_register_sim_regno (gdbarch, nr);
01772 }
01773 
01774 /* Set up the register unwinding such that call-clobbered registers are
01775    not displayed in frames >0 because the true value is not certain.
01776    The 'undefined' registers will show up as 'not available' unless the
01777    CFI says otherwise.
01778 
01779    This function is currently set up for SH4 and compatible only.  */
01780 
01781 static void
01782 sh_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
01783                           struct dwarf2_frame_state_reg *reg,
01784                           struct frame_info *this_frame)
01785 {
01786   /* Mark the PC as the destination for the return address.  */
01787   if (regnum == gdbarch_pc_regnum (gdbarch))
01788     reg->how = DWARF2_FRAME_REG_RA;
01789 
01790   /* Mark the stack pointer as the call frame address.  */
01791   else if (regnum == gdbarch_sp_regnum (gdbarch))
01792     reg->how = DWARF2_FRAME_REG_CFA;
01793 
01794   /* The above was taken from the default init_reg in dwarf2-frame.c
01795      while the below is SH specific.  */
01796 
01797   /* Caller save registers.  */
01798   else if ((regnum >= R0_REGNUM && regnum <= R0_REGNUM+7)
01799            || (regnum >= FR0_REGNUM && regnum <= FR0_REGNUM+11)
01800            || (regnum >= DR0_REGNUM && regnum <= DR0_REGNUM+5)
01801            || (regnum >= FV0_REGNUM && regnum <= FV0_REGNUM+2)
01802            || (regnum == MACH_REGNUM)
01803            || (regnum == MACL_REGNUM)
01804            || (regnum == FPUL_REGNUM)
01805            || (regnum == SR_REGNUM))
01806     reg->how = DWARF2_FRAME_REG_UNDEFINED;
01807 
01808   /* Callee save registers.  */
01809   else if ((regnum >= R0_REGNUM+8 && regnum <= R0_REGNUM+15)
01810            || (regnum >= FR0_REGNUM+12 && regnum <= FR0_REGNUM+15)
01811            || (regnum >= DR0_REGNUM+6 && regnum <= DR0_REGNUM+8)
01812            || (regnum == FV0_REGNUM+3))
01813     reg->how = DWARF2_FRAME_REG_SAME_VALUE;
01814 
01815   /* Other registers.  These are not in the ABI and may or may not
01816      mean anything in frames >0 so don't show them.  */
01817   else if ((regnum >= R0_BANK0_REGNUM && regnum <= R0_BANK0_REGNUM+15)
01818            || (regnum == GBR_REGNUM)
01819            || (regnum == VBR_REGNUM)
01820            || (regnum == FPSCR_REGNUM)
01821            || (regnum == SSR_REGNUM)
01822            || (regnum == SPC_REGNUM))
01823     reg->how = DWARF2_FRAME_REG_UNDEFINED;
01824 }
01825 
01826 static struct sh_frame_cache *
01827 sh_alloc_frame_cache (void)
01828 {
01829   struct sh_frame_cache *cache;
01830   int i;
01831 
01832   cache = FRAME_OBSTACK_ZALLOC (struct sh_frame_cache);
01833 
01834   /* Base address.  */
01835   cache->base = 0;
01836   cache->saved_sp = 0;
01837   cache->sp_offset = 0;
01838   cache->pc = 0;
01839 
01840   /* Frameless until proven otherwise.  */
01841   cache->uses_fp = 0;
01842 
01843   /* Saved registers.  We initialize these to -1 since zero is a valid
01844      offset (that's where fp is supposed to be stored).  */
01845   for (i = 0; i < SH_NUM_REGS; i++)
01846     {
01847       cache->saved_regs[i] = -1;
01848     }
01849 
01850   return cache;
01851 }
01852 
01853 static struct sh_frame_cache *
01854 sh_frame_cache (struct frame_info *this_frame, void **this_cache)
01855 {
01856   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01857   struct sh_frame_cache *cache;
01858   CORE_ADDR current_pc;
01859   int i;
01860 
01861   if (*this_cache)
01862     return *this_cache;
01863 
01864   cache = sh_alloc_frame_cache ();
01865   *this_cache = cache;
01866 
01867   /* In principle, for normal frames, fp holds the frame pointer,
01868      which holds the base address for the current stack frame.
01869      However, for functions that don't need it, the frame pointer is
01870      optional.  For these "frameless" functions the frame pointer is
01871      actually the frame pointer of the calling frame.  */
01872   cache->base = get_frame_register_unsigned (this_frame, FP_REGNUM);
01873   if (cache->base == 0)
01874     return cache;
01875 
01876   cache->pc = get_frame_func (this_frame);
01877   current_pc = get_frame_pc (this_frame);
01878   if (cache->pc != 0)
01879     {
01880       ULONGEST fpscr;
01881 
01882       /* Check for the existence of the FPSCR register.  If it exists,
01883          fetch its value for use in prologue analysis.  Passing a zero
01884          value is the best choice for architecture variants upon which
01885          there's no FPSCR register.  */
01886       if (gdbarch_register_reggroup_p (gdbarch, FPSCR_REGNUM, all_reggroup))
01887         fpscr = get_frame_register_unsigned (this_frame, FPSCR_REGNUM);
01888       else
01889         fpscr = 0;
01890 
01891       sh_analyze_prologue (gdbarch, cache->pc, current_pc, cache, fpscr);
01892     }
01893 
01894   if (!cache->uses_fp)
01895     {
01896       /* We didn't find a valid frame, which means that CACHE->base
01897          currently holds the frame pointer for our calling frame.  If
01898          we're at the start of a function, or somewhere half-way its
01899          prologue, the function's frame probably hasn't been fully
01900          setup yet.  Try to reconstruct the base address for the stack
01901          frame by looking at the stack pointer.  For truly "frameless"
01902          functions this might work too.  */
01903       cache->base = get_frame_register_unsigned
01904                      (this_frame, gdbarch_sp_regnum (gdbarch));
01905     }
01906 
01907   /* Now that we have the base address for the stack frame we can
01908      calculate the value of sp in the calling frame.  */
01909   cache->saved_sp = cache->base + cache->sp_offset;
01910 
01911   /* Adjust all the saved registers such that they contain addresses
01912      instead of offsets.  */
01913   for (i = 0; i < SH_NUM_REGS; i++)
01914     if (cache->saved_regs[i] != -1)
01915       cache->saved_regs[i] = cache->saved_sp - cache->saved_regs[i] - 4;
01916 
01917   return cache;
01918 }
01919 
01920 static struct value *
01921 sh_frame_prev_register (struct frame_info *this_frame,
01922                         void **this_cache, int regnum)
01923 {
01924   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01925   struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
01926 
01927   gdb_assert (regnum >= 0);
01928 
01929   if (regnum == gdbarch_sp_regnum (gdbarch) && cache->saved_sp)
01930     return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
01931 
01932   /* The PC of the previous frame is stored in the PR register of
01933      the current frame.  Frob regnum so that we pull the value from
01934      the correct place.  */
01935   if (regnum == gdbarch_pc_regnum (gdbarch))
01936     regnum = PR_REGNUM;
01937 
01938   if (regnum < SH_NUM_REGS && cache->saved_regs[regnum] != -1)
01939     return frame_unwind_got_memory (this_frame, regnum,
01940                                     cache->saved_regs[regnum]);
01941 
01942   return frame_unwind_got_register (this_frame, regnum, regnum);
01943 }
01944 
01945 static void
01946 sh_frame_this_id (struct frame_info *this_frame, void **this_cache,
01947                   struct frame_id *this_id)
01948 {
01949   struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
01950 
01951   /* This marks the outermost frame.  */
01952   if (cache->base == 0)
01953     return;
01954 
01955   *this_id = frame_id_build (cache->saved_sp, cache->pc);
01956 }
01957 
01958 static const struct frame_unwind sh_frame_unwind = {
01959   NORMAL_FRAME,
01960   default_frame_unwind_stop_reason,
01961   sh_frame_this_id,
01962   sh_frame_prev_register,
01963   NULL,
01964   default_frame_sniffer
01965 };
01966 
01967 static CORE_ADDR
01968 sh_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
01969 {
01970   return frame_unwind_register_unsigned (next_frame,
01971                                          gdbarch_sp_regnum (gdbarch));
01972 }
01973 
01974 static CORE_ADDR
01975 sh_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
01976 {
01977   return frame_unwind_register_unsigned (next_frame,
01978                                          gdbarch_pc_regnum (gdbarch));
01979 }
01980 
01981 static struct frame_id
01982 sh_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
01983 {
01984   CORE_ADDR sp = get_frame_register_unsigned (this_frame,
01985                                               gdbarch_sp_regnum (gdbarch));
01986   return frame_id_build (sp, get_frame_pc (this_frame));
01987 }
01988 
01989 static CORE_ADDR
01990 sh_frame_base_address (struct frame_info *this_frame, void **this_cache)
01991 {
01992   struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
01993 
01994   return cache->base;
01995 }
01996 
01997 static const struct frame_base sh_frame_base = {
01998   &sh_frame_unwind,
01999   sh_frame_base_address,
02000   sh_frame_base_address,
02001   sh_frame_base_address
02002 };
02003 
02004 static struct sh_frame_cache *
02005 sh_make_stub_cache (struct frame_info *this_frame)
02006 {
02007   struct gdbarch *gdbarch = get_frame_arch (this_frame);
02008   struct sh_frame_cache *cache;
02009 
02010   cache = sh_alloc_frame_cache ();
02011 
02012   cache->saved_sp
02013     = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
02014 
02015   return cache;
02016 }
02017 
02018 static void
02019 sh_stub_this_id (struct frame_info *this_frame, void **this_cache,
02020                  struct frame_id *this_id)
02021 {
02022   struct sh_frame_cache *cache;
02023 
02024   if (*this_cache == NULL)
02025     *this_cache = sh_make_stub_cache (this_frame);
02026   cache = *this_cache;
02027 
02028   *this_id = frame_id_build (cache->saved_sp, get_frame_pc (this_frame));
02029 }
02030 
02031 static int
02032 sh_stub_unwind_sniffer (const struct frame_unwind *self,
02033                         struct frame_info *this_frame,
02034                         void **this_prologue_cache)
02035 {
02036   CORE_ADDR addr_in_block;
02037 
02038   addr_in_block = get_frame_address_in_block (this_frame);
02039   if (in_plt_section (addr_in_block))
02040     return 1;
02041 
02042   return 0;
02043 }
02044 
02045 static const struct frame_unwind sh_stub_unwind =
02046 {
02047   NORMAL_FRAME,
02048   default_frame_unwind_stop_reason,
02049   sh_stub_this_id,
02050   sh_frame_prev_register,
02051   NULL,
02052   sh_stub_unwind_sniffer
02053 };
02054 
02055 /* The epilogue is defined here as the area at the end of a function,
02056    either on the `ret' instruction itself or after an instruction which
02057    destroys the function's stack frame.  */
02058 static int
02059 sh_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
02060 {
02061   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
02062   CORE_ADDR func_addr = 0, func_end = 0;
02063 
02064   if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
02065     {
02066       ULONGEST inst;
02067       /* The sh epilogue is max. 14 bytes long.  Give another 14 bytes
02068          for a nop and some fixed data (e.g. big offsets) which are
02069          unfortunately also treated as part of the function (which
02070          means, they are below func_end.  */
02071       CORE_ADDR addr = func_end - 28;
02072       if (addr < func_addr + 4)
02073         addr = func_addr + 4;
02074       if (pc < addr)
02075         return 0;
02076 
02077       /* First search forward until hitting an rts.  */
02078       while (addr < func_end
02079              && !IS_RTS (read_memory_unsigned_integer (addr, 2, byte_order)))
02080         addr += 2;
02081       if (addr >= func_end)
02082         return 0;
02083 
02084       /* At this point we should find a mov.l @r15+,r14 instruction,
02085          either before or after the rts.  If not, then the function has
02086          probably no "normal" epilogue and we bail out here.  */
02087       inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
02088       if (IS_RESTORE_FP (read_memory_unsigned_integer (addr - 2, 2,
02089                                                        byte_order)))
02090         addr -= 2;
02091       else if (!IS_RESTORE_FP (read_memory_unsigned_integer (addr + 2, 2,
02092                                                              byte_order)))
02093         return 0;
02094 
02095       inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
02096 
02097       /* Step over possible lds.l @r15+,macl.  */
02098       if (IS_MACL_LDS (inst))
02099         {
02100           addr -= 2;
02101           inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
02102         }
02103 
02104       /* Step over possible lds.l @r15+,pr.  */
02105       if (IS_LDS (inst))
02106         {
02107           addr -= 2;
02108           inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
02109         }
02110 
02111       /* Step over possible mov r14,r15.  */
02112       if (IS_MOV_FP_SP (inst))
02113         {
02114           addr -= 2;
02115           inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
02116         }
02117 
02118       /* Now check for FP adjustments, using add #imm,r14 or add rX, r14
02119          instructions.  */
02120       while (addr > func_addr + 4
02121              && (IS_ADD_REG_TO_FP (inst) || IS_ADD_IMM_FP (inst)))
02122         {
02123           addr -= 2;
02124           inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
02125         }
02126 
02127       /* On SH2a check if the previous instruction was perhaps a MOVI20.
02128          That's allowed for the epilogue.  */
02129       if ((gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh2a
02130            || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh2a_nofpu)
02131           && addr > func_addr + 6
02132           && IS_MOVI20 (read_memory_unsigned_integer (addr - 4, 2,
02133                                                       byte_order)))
02134         addr -= 4;
02135 
02136       if (pc >= addr)
02137         return 1;
02138     }
02139   return 0;
02140 }
02141 
02142 
02143 /* Supply register REGNUM from the buffer specified by REGS and LEN
02144    in the register set REGSET to register cache REGCACHE.
02145    REGTABLE specifies where each register can be found in REGS.
02146    If REGNUM is -1, do this for all registers in REGSET.  */
02147 
02148 void
02149 sh_corefile_supply_regset (const struct regset *regset,
02150                            struct regcache *regcache,
02151                            int regnum, const void *regs, size_t len)
02152 {
02153   struct gdbarch *gdbarch = get_regcache_arch (regcache);
02154   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
02155   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
02156                                              ? tdep->core_gregmap
02157                                              : tdep->core_fpregmap);
02158   int i;
02159 
02160   for (i = 0; regmap[i].regnum != -1; i++)
02161     {
02162       if ((regnum == -1 || regnum == regmap[i].regnum)
02163           && regmap[i].offset + 4 <= len)
02164         regcache_raw_supply (regcache, regmap[i].regnum,
02165                              (char *)regs + regmap[i].offset);
02166     }
02167 }
02168 
02169 /* Collect register REGNUM in the register set REGSET from register cache
02170    REGCACHE into the buffer specified by REGS and LEN.
02171    REGTABLE specifies where each register can be found in REGS.
02172    If REGNUM is -1, do this for all registers in REGSET.  */
02173 
02174 void
02175 sh_corefile_collect_regset (const struct regset *regset,
02176                             const struct regcache *regcache,
02177                             int regnum, void *regs, size_t len)
02178 {
02179   struct gdbarch *gdbarch = get_regcache_arch (regcache);
02180   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
02181   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
02182                                              ? tdep->core_gregmap
02183                                              : tdep->core_fpregmap);
02184   int i;
02185 
02186   for (i = 0; regmap[i].regnum != -1; i++)
02187     {
02188       if ((regnum == -1 || regnum == regmap[i].regnum)
02189           && regmap[i].offset + 4 <= len)
02190         regcache_raw_collect (regcache, regmap[i].regnum,
02191                               (char *)regs + regmap[i].offset);
02192     }
02193 }
02194 
02195 /* The following two regsets have the same contents, so it is tempting to
02196    unify them, but they are distiguished by their address, so don't.  */
02197 
02198 struct regset sh_corefile_gregset =
02199 {
02200   NULL,
02201   sh_corefile_supply_regset,
02202   sh_corefile_collect_regset
02203 };
02204 
02205 static struct regset sh_corefile_fpregset =
02206 {
02207   NULL,
02208   sh_corefile_supply_regset,
02209   sh_corefile_collect_regset
02210 };
02211 
02212 static const struct regset *
02213 sh_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name,
02214                              size_t sect_size)
02215 {
02216   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
02217 
02218   if (tdep->core_gregmap && strcmp (sect_name, ".reg") == 0)
02219     return &sh_corefile_gregset;
02220 
02221   if (tdep->core_fpregmap && strcmp (sect_name, ".reg2") == 0)
02222     return &sh_corefile_fpregset;
02223 
02224   return NULL;
02225 }
02226 
02227 /* This is the implementation of gdbarch method
02228    return_in_first_hidden_param_p.  */
02229 
02230 static int
02231 sh_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
02232                                      struct type *type)
02233 {
02234   return 0;
02235 }
02236 
02237 
02238 
02239 static struct gdbarch *
02240 sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
02241 {
02242   struct gdbarch *gdbarch;
02243   struct gdbarch_tdep *tdep;
02244 
02245   /* SH5 is handled entirely in sh64-tdep.c.  */
02246   if (info.bfd_arch_info->mach == bfd_mach_sh5)
02247     return sh64_gdbarch_init (info, arches);
02248 
02249   /* If there is already a candidate, use it.  */
02250   arches = gdbarch_list_lookup_by_info (arches, &info);
02251   if (arches != NULL)
02252     return arches->gdbarch;
02253 
02254   /* None found, create a new architecture from the information
02255      provided.  */
02256   tdep = XZALLOC (struct gdbarch_tdep);
02257   gdbarch = gdbarch_alloc (&info, tdep);
02258 
02259   set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
02260   set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
02261   set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
02262   set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
02263   set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
02264   set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
02265   set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
02266   set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
02267 
02268   set_gdbarch_num_regs (gdbarch, SH_NUM_REGS);
02269   set_gdbarch_sp_regnum (gdbarch, 15);
02270   set_gdbarch_pc_regnum (gdbarch, 16);
02271   set_gdbarch_fp0_regnum (gdbarch, -1);
02272   set_gdbarch_num_pseudo_regs (gdbarch, 0);
02273 
02274   set_gdbarch_register_type (gdbarch, sh_default_register_type);
02275   set_gdbarch_register_reggroup_p (gdbarch, sh_register_reggroup_p);
02276 
02277   set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
02278 
02279   set_gdbarch_print_insn (gdbarch, print_insn_sh);
02280   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
02281 
02282   set_gdbarch_return_value (gdbarch, sh_return_value_nofpu);
02283 
02284   set_gdbarch_skip_prologue (gdbarch, sh_skip_prologue);
02285   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
02286 
02287   set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_nofpu);
02288   set_gdbarch_return_in_first_hidden_param_p (gdbarch,
02289                                               sh_return_in_first_hidden_param_p);
02290 
02291   set_gdbarch_believe_pcc_promotion (gdbarch, 1);
02292 
02293   set_gdbarch_frame_align (gdbarch, sh_frame_align);
02294   set_gdbarch_unwind_sp (gdbarch, sh_unwind_sp);
02295   set_gdbarch_unwind_pc (gdbarch, sh_unwind_pc);
02296   set_gdbarch_dummy_id (gdbarch, sh_dummy_id);
02297   frame_base_set_default (gdbarch, &sh_frame_base);
02298 
02299   set_gdbarch_in_function_epilogue_p (gdbarch, sh_in_function_epilogue_p);
02300 
02301   dwarf2_frame_set_init_reg (gdbarch, sh_dwarf2_frame_init_reg);
02302 
02303   set_gdbarch_regset_from_core_section (gdbarch, sh_regset_from_core_section);
02304 
02305   switch (info.bfd_arch_info->mach)
02306     {
02307     case bfd_mach_sh:
02308       set_gdbarch_register_name (gdbarch, sh_sh_register_name);
02309       break;
02310 
02311     case bfd_mach_sh2:
02312       set_gdbarch_register_name (gdbarch, sh_sh_register_name);
02313       break;
02314 
02315     case bfd_mach_sh2e:
02316       /* doubles on sh2e and sh3e are actually 4 byte.  */
02317       set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
02318       set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
02319 
02320       set_gdbarch_register_name (gdbarch, sh_sh2e_register_name);
02321       set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
02322       set_gdbarch_fp0_regnum (gdbarch, 25);
02323       set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
02324       set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
02325       break;
02326 
02327     case bfd_mach_sh2a:
02328       set_gdbarch_register_name (gdbarch, sh_sh2a_register_name);
02329       set_gdbarch_register_type (gdbarch, sh_sh2a_register_type);
02330       set_gdbarch_register_sim_regno (gdbarch, sh_sh2a_register_sim_regno);
02331 
02332       set_gdbarch_fp0_regnum (gdbarch, 25);
02333       set_gdbarch_num_pseudo_regs (gdbarch, 9);
02334       set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
02335       set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
02336       set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
02337       set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
02338       break;
02339 
02340     case bfd_mach_sh2a_nofpu:
02341       set_gdbarch_register_name (gdbarch, sh_sh2a_nofpu_register_name);
02342       set_gdbarch_register_sim_regno (gdbarch, sh_sh2a_register_sim_regno);
02343 
02344       set_gdbarch_num_pseudo_regs (gdbarch, 1);
02345       set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
02346       set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
02347       break;
02348 
02349     case bfd_mach_sh_dsp:
02350       set_gdbarch_register_name (gdbarch, sh_sh_dsp_register_name);
02351       set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
02352       break;
02353 
02354     case bfd_mach_sh3:
02355     case bfd_mach_sh3_nommu:
02356     case bfd_mach_sh2a_nofpu_or_sh3_nommu:
02357       set_gdbarch_register_name (gdbarch, sh_sh3_register_name);
02358       break;
02359 
02360     case bfd_mach_sh3e:
02361     case bfd_mach_sh2a_or_sh3e:
02362       /* doubles on sh2e and sh3e are actually 4 byte.  */
02363       set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
02364       set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
02365 
02366       set_gdbarch_register_name (gdbarch, sh_sh3e_register_name);
02367       set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
02368       set_gdbarch_fp0_regnum (gdbarch, 25);
02369       set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
02370       set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
02371       break;
02372 
02373     case bfd_mach_sh3_dsp:
02374       set_gdbarch_register_name (gdbarch, sh_sh3_dsp_register_name);
02375       set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
02376       break;
02377 
02378     case bfd_mach_sh4:
02379     case bfd_mach_sh4a:
02380     case bfd_mach_sh2a_or_sh4:
02381       set_gdbarch_register_name (gdbarch, sh_sh4_register_name);
02382       set_gdbarch_register_type (gdbarch, sh_sh4_register_type);
02383       set_gdbarch_fp0_regnum (gdbarch, 25);
02384       set_gdbarch_num_pseudo_regs (gdbarch, 13);
02385       set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
02386       set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
02387       set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
02388       set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
02389       break;
02390 
02391     case bfd_mach_sh4_nofpu:
02392     case bfd_mach_sh4a_nofpu:
02393     case bfd_mach_sh4_nommu_nofpu:
02394     case bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu:
02395       set_gdbarch_register_name (gdbarch, sh_sh4_nofpu_register_name);
02396       break;
02397 
02398     case bfd_mach_sh4al_dsp:
02399       set_gdbarch_register_name (gdbarch, sh_sh4al_dsp_register_name);
02400       set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
02401       break;
02402 
02403     default:
02404       set_gdbarch_register_name (gdbarch, sh_sh_register_name);
02405       break;
02406     }
02407 
02408   /* Hook in ABI-specific overrides, if they have been registered.  */
02409   gdbarch_init_osabi (info, gdbarch);
02410 
02411   dwarf2_append_unwinders (gdbarch);
02412   frame_unwind_append_unwinder (gdbarch, &sh_stub_unwind);
02413   frame_unwind_append_unwinder (gdbarch, &sh_frame_unwind);
02414 
02415   return gdbarch;
02416 }
02417 
02418 static void
02419 show_sh_command (char *args, int from_tty)
02420 {
02421   help_list (showshcmdlist, "show sh ", all_commands, gdb_stdout);
02422 }
02423 
02424 static void
02425 set_sh_command (char *args, int from_tty)
02426 {
02427   printf_unfiltered
02428     ("\"set sh\" must be followed by an appropriate subcommand.\n");
02429   help_list (setshcmdlist, "set sh ", all_commands, gdb_stdout);
02430 }
02431 
02432 extern initialize_file_ftype _initialize_sh_tdep;  /* -Wmissing-prototypes */
02433 
02434 void
02435 _initialize_sh_tdep (void)
02436 {
02437   gdbarch_register (bfd_arch_sh, sh_gdbarch_init, NULL);
02438 
02439   add_prefix_cmd ("sh", no_class, set_sh_command, "SH specific commands.",
02440                   &setshcmdlist, "set sh ", 0, &setlist);
02441   add_prefix_cmd ("sh", no_class, show_sh_command, "SH specific commands.",
02442                   &showshcmdlist, "show sh ", 0, &showlist);
02443   
02444   add_setshow_enum_cmd ("calling-convention", class_vars, sh_cc_enum,
02445                         &sh_active_calling_convention,
02446                         _("Set calling convention used when calling target "
02447                           "functions from GDB."),
02448                         _("Show calling convention used when calling target "
02449                           "functions from GDB."),
02450                         _("gcc       - Use GCC calling convention (default).\n"
02451                           "renesas   - Enforce Renesas calling convention."),
02452                         NULL, NULL,
02453                         &setshcmdlist, &showshcmdlist);
02454 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines