GDB (API)
/home/stan/gdb/src/gdb/m68k-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for the Motorola 68000 series.
00002 
00003    Copyright (C) 1990-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "dwarf2-frame.h"
00022 #include "frame.h"
00023 #include "frame-base.h"
00024 #include "frame-unwind.h"
00025 #include "gdbtypes.h"
00026 #include "symtab.h"
00027 #include "gdbcore.h"
00028 #include "value.h"
00029 #include "gdb_string.h"
00030 #include "gdb_assert.h"
00031 #include "inferior.h"
00032 #include "regcache.h"
00033 #include "arch-utils.h"
00034 #include "osabi.h"
00035 #include "dis-asm.h"
00036 #include "target-descriptions.h"
00037 
00038 #include "m68k-tdep.h"
00039 
00040 
00041 #define P_LINKL_FP      0x480e
00042 #define P_LINKW_FP      0x4e56
00043 #define P_PEA_FP        0x4856
00044 #define P_MOVEAL_SP_FP  0x2c4f
00045 #define P_ADDAW_SP      0xdefc
00046 #define P_ADDAL_SP      0xdffc
00047 #define P_SUBQW_SP      0x514f
00048 #define P_SUBQL_SP      0x518f
00049 #define P_LEA_SP_SP     0x4fef
00050 #define P_LEA_PC_A5     0x4bfb0170
00051 #define P_FMOVEMX_SP    0xf227
00052 #define P_MOVEL_SP      0x2f00
00053 #define P_MOVEML_SP     0x48e7
00054 
00055 /* Offset from SP to first arg on stack at first instruction of a function.  */
00056 #define SP_ARG0 (1 * 4)
00057 
00058 #if !defined (BPT_VECTOR)
00059 #define BPT_VECTOR 0xf
00060 #endif
00061 
00062 static const gdb_byte *
00063 m68k_local_breakpoint_from_pc (struct gdbarch *gdbarch,
00064                                CORE_ADDR *pcptr, int *lenptr)
00065 {
00066   static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
00067   *lenptr = sizeof (break_insn);
00068   return break_insn;
00069 }
00070 
00071 
00072 /* Construct types for ISA-specific registers.  */
00073 static struct type *
00074 m68k_ps_type (struct gdbarch *gdbarch)
00075 {
00076   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00077 
00078   if (!tdep->m68k_ps_type)
00079     {
00080       struct type *type;
00081 
00082       type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 4);
00083       append_flags_type_flag (type, 0, "C");
00084       append_flags_type_flag (type, 1, "V");
00085       append_flags_type_flag (type, 2, "Z");
00086       append_flags_type_flag (type, 3, "N");
00087       append_flags_type_flag (type, 4, "X");
00088       append_flags_type_flag (type, 8, "I0");
00089       append_flags_type_flag (type, 9, "I1");
00090       append_flags_type_flag (type, 10, "I2");
00091       append_flags_type_flag (type, 12, "M");
00092       append_flags_type_flag (type, 13, "S");
00093       append_flags_type_flag (type, 14, "T0");
00094       append_flags_type_flag (type, 15, "T1");
00095 
00096       tdep->m68k_ps_type = type;
00097     }
00098 
00099   return tdep->m68k_ps_type;
00100 }
00101 
00102 static struct type *
00103 m68881_ext_type (struct gdbarch *gdbarch)
00104 {
00105   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00106 
00107   if (!tdep->m68881_ext_type)
00108     tdep->m68881_ext_type
00109       = arch_float_type (gdbarch, -1, "builtin_type_m68881_ext",
00110                          floatformats_m68881_ext);
00111 
00112   return tdep->m68881_ext_type;
00113 }
00114 
00115 /* Return the GDB type object for the "standard" data type of data in
00116    register N.  This should be int for D0-D7, SR, FPCONTROL and
00117    FPSTATUS, long double for FP0-FP7, and void pointer for all others
00118    (A0-A7, PC, FPIADDR).  Note, for registers which contain
00119    addresses return pointer to void, not pointer to char, because we
00120    don't want to attempt to print the string after printing the
00121    address.  */
00122 
00123 static struct type *
00124 m68k_register_type (struct gdbarch *gdbarch, int regnum)
00125 {
00126   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00127 
00128   if (tdep->fpregs_present)
00129     {
00130       if (regnum >= gdbarch_fp0_regnum (gdbarch)
00131           && regnum <= gdbarch_fp0_regnum (gdbarch) + 7)
00132         {
00133           if (tdep->flavour == m68k_coldfire_flavour)
00134             return builtin_type (gdbarch)->builtin_double;
00135           else
00136             return m68881_ext_type (gdbarch);
00137         }
00138 
00139       if (regnum == M68K_FPI_REGNUM)
00140         return builtin_type (gdbarch)->builtin_func_ptr;
00141 
00142       if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM)
00143         return builtin_type (gdbarch)->builtin_int32;
00144     }
00145   else
00146     {
00147       if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM)
00148         return builtin_type (gdbarch)->builtin_int0;
00149     }
00150 
00151   if (regnum == gdbarch_pc_regnum (gdbarch))
00152     return builtin_type (gdbarch)->builtin_func_ptr;
00153 
00154   if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
00155     return builtin_type (gdbarch)->builtin_data_ptr;
00156 
00157   if (regnum == M68K_PS_REGNUM)
00158     return m68k_ps_type (gdbarch);
00159 
00160   return builtin_type (gdbarch)->builtin_int32;
00161 }
00162 
00163 static const char *m68k_register_names[] = {
00164     "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
00165     "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
00166     "ps", "pc",
00167     "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
00168     "fpcontrol", "fpstatus", "fpiaddr"
00169   };
00170 
00171 /* Function: m68k_register_name
00172    Returns the name of the standard m68k register regnum.  */
00173 
00174 static const char *
00175 m68k_register_name (struct gdbarch *gdbarch, int regnum)
00176 {
00177   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
00178     internal_error (__FILE__, __LINE__,
00179                     _("m68k_register_name: illegal register number %d"),
00180                     regnum);
00181   else if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
00182            && gdbarch_tdep (gdbarch)->fpregs_present == 0)
00183     return "";
00184   else
00185     return m68k_register_names[regnum];
00186 }
00187 
00188 /* Return nonzero if a value of type TYPE stored in register REGNUM
00189    needs any special handling.  */
00190 
00191 static int
00192 m68k_convert_register_p (struct gdbarch *gdbarch,
00193                          int regnum, struct type *type)
00194 {
00195   if (!gdbarch_tdep (gdbarch)->fpregs_present)
00196     return 0;
00197   return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
00198           && type != register_type (gdbarch, M68K_FP0_REGNUM));
00199 }
00200 
00201 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
00202    return its contents in TO.  */
00203 
00204 static int
00205 m68k_register_to_value (struct frame_info *frame, int regnum,
00206                         struct type *type, gdb_byte *to,
00207                         int *optimizedp, int *unavailablep)
00208 {
00209   gdb_byte from[M68K_MAX_REGISTER_SIZE];
00210   struct type *fpreg_type = register_type (get_frame_arch (frame),
00211                                            M68K_FP0_REGNUM);
00212 
00213   /* We only support floating-point values.  */
00214   if (TYPE_CODE (type) != TYPE_CODE_FLT)
00215     {
00216       warning (_("Cannot convert floating-point register value "
00217                "to non-floating-point type."));
00218       *optimizedp = *unavailablep = 0;
00219       return 0;
00220     }
00221 
00222   /* Convert to TYPE.  */
00223 
00224   /* Convert to TYPE.  */
00225   if (!get_frame_register_bytes (frame, regnum, 0, TYPE_LENGTH (type),
00226                                  from, optimizedp, unavailablep))
00227     return 0;
00228 
00229   convert_typed_floating (from, fpreg_type, to, type);
00230   *optimizedp = *unavailablep = 0;
00231   return 1;
00232 }
00233 
00234 /* Write the contents FROM of a value of type TYPE into register
00235    REGNUM in frame FRAME.  */
00236 
00237 static void
00238 m68k_value_to_register (struct frame_info *frame, int regnum,
00239                         struct type *type, const gdb_byte *from)
00240 {
00241   gdb_byte to[M68K_MAX_REGISTER_SIZE];
00242   struct type *fpreg_type = register_type (get_frame_arch (frame),
00243                                            M68K_FP0_REGNUM);
00244 
00245   /* We only support floating-point values.  */
00246   if (TYPE_CODE (type) != TYPE_CODE_FLT)
00247     {
00248       warning (_("Cannot convert non-floating-point type "
00249                "to floating-point register value."));
00250       return;
00251     }
00252 
00253   /* Convert from TYPE.  */
00254   convert_typed_floating (from, type, to, fpreg_type);
00255   put_frame_register (frame, regnum, to);
00256 }
00257 
00258 
00259 /* There is a fair number of calling conventions that are in somewhat
00260    wide use.  The 68000/08/10 don't support an FPU, not even as a
00261    coprocessor.  All function return values are stored in %d0/%d1.
00262    Structures are returned in a static buffer, a pointer to which is
00263    returned in %d0.  This means that functions returning a structure
00264    are not re-entrant.  To avoid this problem some systems use a
00265    convention where the caller passes a pointer to a buffer in %a1
00266    where the return values is to be stored.  This convention is the
00267    default, and is implemented in the function m68k_return_value.
00268 
00269    The 68020/030/040/060 do support an FPU, either as a coprocessor
00270    (68881/2) or built-in (68040/68060).  That's why System V release 4
00271    (SVR4) instroduces a new calling convention specified by the SVR4
00272    psABI.  Integer values are returned in %d0/%d1, pointer return
00273    values in %a0 and floating values in %fp0.  When calling functions
00274    returning a structure the caller should pass a pointer to a buffer
00275    for the return value in %a0.  This convention is implemented in the
00276    function m68k_svr4_return_value, and by appropriately setting the
00277    struct_value_regnum member of `struct gdbarch_tdep'.
00278 
00279    GNU/Linux returns values in the same way as SVR4 does, but uses %a1
00280    for passing the structure return value buffer.
00281 
00282    GCC can also generate code where small structures are returned in
00283    %d0/%d1 instead of in memory by using -freg-struct-return.  This is
00284    the default on NetBSD a.out, OpenBSD and GNU/Linux and several
00285    embedded systems.  This convention is implemented by setting the
00286    struct_return member of `struct gdbarch_tdep' to reg_struct_return.  */
00287 
00288 /* Read a function return value of TYPE from REGCACHE, and copy that
00289    into VALBUF.  */
00290 
00291 static void
00292 m68k_extract_return_value (struct type *type, struct regcache *regcache,
00293                            gdb_byte *valbuf)
00294 {
00295   int len = TYPE_LENGTH (type);
00296   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
00297 
00298   if (len <= 4)
00299     {
00300       regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
00301       memcpy (valbuf, buf + (4 - len), len);
00302     }
00303   else if (len <= 8)
00304     {
00305       regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
00306       memcpy (valbuf, buf + (8 - len), len - 4);
00307       regcache_raw_read (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
00308     }
00309   else
00310     internal_error (__FILE__, __LINE__,
00311                     _("Cannot extract return value of %d bytes long."), len);
00312 }
00313 
00314 static void
00315 m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
00316                                 gdb_byte *valbuf)
00317 {
00318   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
00319   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00320   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00321 
00322   if (tdep->float_return && TYPE_CODE (type) == TYPE_CODE_FLT)
00323     {
00324       struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
00325       regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
00326       convert_typed_floating (buf, fpreg_type, valbuf, type);
00327     }
00328   else if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_LENGTH (type) == 4)
00329     regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
00330   else
00331     m68k_extract_return_value (type, regcache, valbuf);
00332 }
00333 
00334 /* Write a function return value of TYPE from VALBUF into REGCACHE.  */
00335 
00336 static void
00337 m68k_store_return_value (struct type *type, struct regcache *regcache,
00338                          const gdb_byte *valbuf)
00339 {
00340   int len = TYPE_LENGTH (type);
00341 
00342   if (len <= 4)
00343     regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf);
00344   else if (len <= 8)
00345     {
00346       regcache_raw_write_part (regcache, M68K_D0_REGNUM, 8 - len,
00347                                len - 4, valbuf);
00348       regcache_raw_write (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
00349     }
00350   else
00351     internal_error (__FILE__, __LINE__,
00352                     _("Cannot store return value of %d bytes long."), len);
00353 }
00354 
00355 static void
00356 m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
00357                               const gdb_byte *valbuf)
00358 {
00359   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00360   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00361 
00362   if (tdep->float_return && TYPE_CODE (type) == TYPE_CODE_FLT)
00363     {
00364       struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
00365       gdb_byte buf[M68K_MAX_REGISTER_SIZE];
00366       convert_typed_floating (valbuf, type, buf, fpreg_type);
00367       regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
00368     }
00369   else if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_LENGTH (type) == 4)
00370     {
00371       regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
00372       regcache_raw_write (regcache, M68K_D0_REGNUM, valbuf);
00373     }
00374   else
00375     m68k_store_return_value (type, regcache, valbuf);
00376 }
00377 
00378 /* Return non-zero if TYPE, which is assumed to be a structure, union or
00379    complex type, should be returned in registers for architecture
00380    GDBARCH.  */
00381 
00382 static int
00383 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
00384 {
00385   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00386   enum type_code code = TYPE_CODE (type);
00387   int len = TYPE_LENGTH (type);
00388 
00389   gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
00390               || code == TYPE_CODE_COMPLEX);
00391 
00392   if (tdep->struct_return == pcc_struct_return)
00393     return 0;
00394 
00395   return (len == 1 || len == 2 || len == 4 || len == 8);
00396 }
00397 
00398 /* Determine, for architecture GDBARCH, how a return value of TYPE
00399    should be returned.  If it is supposed to be returned in registers,
00400    and READBUF is non-zero, read the appropriate value from REGCACHE,
00401    and copy it into READBUF.  If WRITEBUF is non-zero, write the value
00402    from WRITEBUF into REGCACHE.  */
00403 
00404 static enum return_value_convention
00405 m68k_return_value (struct gdbarch *gdbarch, struct value *function,
00406                    struct type *type, struct regcache *regcache,
00407                    gdb_byte *readbuf, const gdb_byte *writebuf)
00408 {
00409   enum type_code code = TYPE_CODE (type);
00410 
00411   /* GCC returns a `long double' in memory too.  */
00412   if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
00413         || code == TYPE_CODE_COMPLEX)
00414        && !m68k_reg_struct_return_p (gdbarch, type))
00415       || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12))
00416     {
00417       /* The default on m68k is to return structures in static memory.
00418          Consequently a function must return the address where we can
00419          find the return value.  */
00420 
00421       if (readbuf)
00422         {
00423           ULONGEST addr;
00424 
00425           regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
00426           read_memory (addr, readbuf, TYPE_LENGTH (type));
00427         }
00428 
00429       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
00430     }
00431 
00432   if (readbuf)
00433     m68k_extract_return_value (type, regcache, readbuf);
00434   if (writebuf)
00435     m68k_store_return_value (type, regcache, writebuf);
00436 
00437   return RETURN_VALUE_REGISTER_CONVENTION;
00438 }
00439 
00440 static enum return_value_convention
00441 m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
00442                         struct type *type, struct regcache *regcache,
00443                         gdb_byte *readbuf, const gdb_byte *writebuf)
00444 {
00445   enum type_code code = TYPE_CODE (type);
00446 
00447   if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
00448        || code == TYPE_CODE_COMPLEX)
00449       && !m68k_reg_struct_return_p (gdbarch, type))
00450     {
00451       /* The System V ABI says that:
00452 
00453          "A function returning a structure or union also sets %a0 to
00454          the value it finds in %a0.  Thus when the caller receives
00455          control again, the address of the returned object resides in
00456          register %a0."
00457 
00458          So the ABI guarantees that we can always find the return
00459          value just after the function has returned.  */
00460 
00461       if (readbuf)
00462         {
00463           ULONGEST addr;
00464 
00465           regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr);
00466           read_memory (addr, readbuf, TYPE_LENGTH (type));
00467         }
00468 
00469       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
00470     }
00471 
00472   /* This special case is for structures consisting of a single
00473      `float' or `double' member.  These structures are returned in
00474      %fp0.  For these structures, we call ourselves recursively,
00475      changing TYPE into the type of the first member of the structure.
00476      Since that should work for all structures that have only one
00477      member, we don't bother to check the member's type here.  */
00478   if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
00479     {
00480       type = check_typedef (TYPE_FIELD_TYPE (type, 0));
00481       return m68k_svr4_return_value (gdbarch, function, type, regcache,
00482                                      readbuf, writebuf);
00483     }
00484 
00485   if (readbuf)
00486     m68k_svr4_extract_return_value (type, regcache, readbuf);
00487   if (writebuf)
00488     m68k_svr4_store_return_value (type, regcache, writebuf);
00489 
00490   return RETURN_VALUE_REGISTER_CONVENTION;
00491 }
00492 
00493 
00494 /* Always align the frame to a 4-byte boundary.  This is required on
00495    coldfire and harmless on the rest.  */
00496 
00497 static CORE_ADDR
00498 m68k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
00499 {
00500   /* Align the stack to four bytes.  */
00501   return sp & ~3;
00502 }
00503 
00504 static CORE_ADDR
00505 m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00506                       struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
00507                       struct value **args, CORE_ADDR sp, int struct_return,
00508                       CORE_ADDR struct_addr)
00509 {
00510   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00511   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00512   gdb_byte buf[4];
00513   int i;
00514 
00515   /* Push arguments in reverse order.  */
00516   for (i = nargs - 1; i >= 0; i--)
00517     {
00518       struct type *value_type = value_enclosing_type (args[i]);
00519       int len = TYPE_LENGTH (value_type);
00520       int container_len = (len + 3) & ~3;
00521       int offset;
00522 
00523       /* Non-scalars bigger than 4 bytes are left aligned, others are
00524          right aligned.  */
00525       if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT
00526            || TYPE_CODE (value_type) == TYPE_CODE_UNION
00527            || TYPE_CODE (value_type) == TYPE_CODE_ARRAY)
00528           && len > 4)
00529         offset = 0;
00530       else
00531         offset = container_len - len;
00532       sp -= container_len;
00533       write_memory (sp + offset, value_contents_all (args[i]), len);
00534     }
00535 
00536   /* Store struct value address.  */
00537   if (struct_return)
00538     {
00539       store_unsigned_integer (buf, 4, byte_order, struct_addr);
00540       regcache_cooked_write (regcache, tdep->struct_value_regnum, buf);
00541     }
00542 
00543   /* Store return address.  */
00544   sp -= 4;
00545   store_unsigned_integer (buf, 4, byte_order, bp_addr);
00546   write_memory (sp, buf, 4);
00547 
00548   /* Finally, update the stack pointer...  */
00549   store_unsigned_integer (buf, 4, byte_order, sp);
00550   regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);
00551 
00552   /* ...and fake a frame pointer.  */
00553   regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);
00554 
00555   /* DWARF2/GCC uses the stack address *before* the function call as a
00556      frame's CFA.  */
00557   return sp + 8;
00558 }
00559 
00560 /* Convert a dwarf or dwarf2 regnumber to a GDB regnum.  */
00561 
00562 static int
00563 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
00564 {
00565   if (num < 8)
00566     /* d0..7 */
00567     return (num - 0) + M68K_D0_REGNUM;
00568   else if (num < 16)
00569     /* a0..7 */
00570     return (num - 8) + M68K_A0_REGNUM;
00571   else if (num < 24 && gdbarch_tdep (gdbarch)->fpregs_present)
00572     /* fp0..7 */
00573     return (num - 16) + M68K_FP0_REGNUM;
00574   else if (num == 25)
00575     /* pc */
00576     return M68K_PC_REGNUM;
00577   else
00578     return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
00579 }
00580 
00581 
00582 struct m68k_frame_cache
00583 {
00584   /* Base address.  */
00585   CORE_ADDR base;
00586   CORE_ADDR sp_offset;
00587   CORE_ADDR pc;
00588 
00589   /* Saved registers.  */
00590   CORE_ADDR saved_regs[M68K_NUM_REGS];
00591   CORE_ADDR saved_sp;
00592 
00593   /* Stack space reserved for local variables.  */
00594   long locals;
00595 };
00596 
00597 /* Allocate and initialize a frame cache.  */
00598 
00599 static struct m68k_frame_cache *
00600 m68k_alloc_frame_cache (void)
00601 {
00602   struct m68k_frame_cache *cache;
00603   int i;
00604 
00605   cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
00606 
00607   /* Base address.  */
00608   cache->base = 0;
00609   cache->sp_offset = -4;
00610   cache->pc = 0;
00611 
00612   /* Saved registers.  We initialize these to -1 since zero is a valid
00613      offset (that's where %fp is supposed to be stored).  */
00614   for (i = 0; i < M68K_NUM_REGS; i++)
00615     cache->saved_regs[i] = -1;
00616 
00617   /* Frameless until proven otherwise.  */
00618   cache->locals = -1;
00619 
00620   return cache;
00621 }
00622 
00623 /* Check whether PC points at a code that sets up a new stack frame.
00624    If so, it updates CACHE and returns the address of the first
00625    instruction after the sequence that sets removes the "hidden"
00626    argument from the stack or CURRENT_PC, whichever is smaller.
00627    Otherwise, return PC.  */
00628 
00629 static CORE_ADDR
00630 m68k_analyze_frame_setup (struct gdbarch *gdbarch,
00631                           CORE_ADDR pc, CORE_ADDR current_pc,
00632                           struct m68k_frame_cache *cache)
00633 {
00634   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00635   int op;
00636 
00637   if (pc >= current_pc)
00638     return current_pc;
00639 
00640   op = read_memory_unsigned_integer (pc, 2, byte_order);
00641 
00642   if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
00643     {
00644       cache->saved_regs[M68K_FP_REGNUM] = 0;
00645       cache->sp_offset += 4;
00646       if (op == P_LINKW_FP)
00647         {
00648           /* link.w %fp, #-N */
00649           /* link.w %fp, #0; adda.l #-N, %sp */
00650           cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
00651 
00652           if (pc + 4 < current_pc && cache->locals == 0)
00653             {
00654               op = read_memory_unsigned_integer (pc + 4, 2, byte_order);
00655               if (op == P_ADDAL_SP)
00656                 {
00657                   cache->locals = read_memory_integer (pc + 6, 4, byte_order);
00658                   return pc + 10;
00659                 }
00660             }
00661 
00662           return pc + 4;
00663         }
00664       else if (op == P_LINKL_FP)
00665         {
00666           /* link.l %fp, #-N */
00667           cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
00668           return pc + 6;
00669         }
00670       else
00671         {
00672           /* pea (%fp); movea.l %sp, %fp */
00673           cache->locals = 0;
00674 
00675           if (pc + 2 < current_pc)
00676             {
00677               op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
00678 
00679               if (op == P_MOVEAL_SP_FP)
00680                 {
00681                   /* move.l %sp, %fp */
00682                   return pc + 4;
00683                 }
00684             }
00685 
00686           return pc + 2;
00687         }
00688     }
00689   else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
00690     {
00691       /* subq.[wl] #N,%sp */
00692       /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
00693       cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
00694       if (pc + 2 < current_pc)
00695         {
00696           op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
00697           if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
00698             {
00699               cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
00700               return pc + 4;
00701             }
00702         }
00703       return pc + 2;
00704     }
00705   else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
00706     {
00707       /* adda.w #-N,%sp */
00708       /* lea (-N,%sp),%sp */
00709       cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
00710       return pc + 4;
00711     }
00712   else if (op == P_ADDAL_SP)
00713     {
00714       /* adda.l #-N,%sp */
00715       cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
00716       return pc + 6;
00717     }
00718 
00719   return pc;
00720 }
00721 
00722 /* Check whether PC points at code that saves registers on the stack.
00723    If so, it updates CACHE and returns the address of the first
00724    instruction after the register saves or CURRENT_PC, whichever is
00725    smaller.  Otherwise, return PC.  */
00726 
00727 static CORE_ADDR
00728 m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
00729                              CORE_ADDR current_pc,
00730                              struct m68k_frame_cache *cache)
00731 {
00732   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00733 
00734   if (cache->locals >= 0)
00735     {
00736       CORE_ADDR offset;
00737       int op;
00738       int i, mask, regno;
00739 
00740       offset = -4 - cache->locals;
00741       while (pc < current_pc)
00742         {
00743           op = read_memory_unsigned_integer (pc, 2, byte_order);
00744           if (op == P_FMOVEMX_SP
00745               && gdbarch_tdep (gdbarch)->fpregs_present)
00746             {
00747               /* fmovem.x REGS,-(%sp) */
00748               op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
00749               if ((op & 0xff00) == 0xe000)
00750                 {
00751                   mask = op & 0xff;
00752                   for (i = 0; i < 16; i++, mask >>= 1)
00753                     {
00754                       if (mask & 1)
00755                         {
00756                           cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
00757                           offset -= 12;
00758                         }
00759                     }
00760                   pc += 4;
00761                 }
00762               else
00763                 break;
00764             }
00765           else if ((op & 0177760) == P_MOVEL_SP)
00766             {
00767               /* move.l %R,-(%sp) */
00768               regno = op & 017;
00769               cache->saved_regs[regno] = offset;
00770               offset -= 4;
00771               pc += 2;
00772             }
00773           else if (op == P_MOVEML_SP)
00774             {
00775               /* movem.l REGS,-(%sp) */
00776               mask = read_memory_unsigned_integer (pc + 2, 2, byte_order);
00777               for (i = 0; i < 16; i++, mask >>= 1)
00778                 {
00779                   if (mask & 1)
00780                     {
00781                       cache->saved_regs[15 - i] = offset;
00782                       offset -= 4;
00783                     }
00784                 }
00785               pc += 4;
00786             }
00787           else
00788             break;
00789         }
00790     }
00791 
00792   return pc;
00793 }
00794 
00795 
00796 /* Do a full analysis of the prologue at PC and update CACHE
00797    accordingly.  Bail out early if CURRENT_PC is reached.  Return the
00798    address where the analysis stopped.
00799 
00800    We handle all cases that can be generated by gcc.
00801 
00802    For allocating a stack frame:
00803 
00804    link.w %a6,#-N
00805    link.l %a6,#-N
00806    pea (%fp); move.l %sp,%fp
00807    link.w %a6,#0; add.l #-N,%sp
00808    subq.l #N,%sp
00809    subq.w #N,%sp
00810    subq.w #8,%sp; subq.w #N-8,%sp
00811    add.w #-N,%sp
00812    lea (-N,%sp),%sp
00813    add.l #-N,%sp
00814 
00815    For saving registers:
00816 
00817    fmovem.x REGS,-(%sp)
00818    move.l R1,-(%sp)
00819    move.l R1,-(%sp); move.l R2,-(%sp)
00820    movem.l REGS,-(%sp)
00821 
00822    For setting up the PIC register:
00823 
00824    lea (%pc,N),%a5
00825 
00826    */
00827 
00828 static CORE_ADDR
00829 m68k_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
00830                        CORE_ADDR current_pc, struct m68k_frame_cache *cache)
00831 {
00832   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00833   unsigned int op;
00834 
00835   pc = m68k_analyze_frame_setup (gdbarch, pc, current_pc, cache);
00836   pc = m68k_analyze_register_saves (gdbarch, pc, current_pc, cache);
00837   if (pc >= current_pc)
00838     return current_pc;
00839 
00840   /* Check for GOT setup.  */
00841   op = read_memory_unsigned_integer (pc, 4, byte_order);
00842   if (op == P_LEA_PC_A5)
00843     {
00844       /* lea (%pc,N),%a5 */
00845       return pc + 8;
00846     }
00847 
00848   return pc;
00849 }
00850 
00851 /* Return PC of first real instruction.  */
00852 
00853 static CORE_ADDR
00854 m68k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
00855 {
00856   struct m68k_frame_cache cache;
00857   CORE_ADDR pc;
00858 
00859   cache.locals = -1;
00860   pc = m68k_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache);
00861   if (cache.locals < 0)
00862     return start_pc;
00863   return pc;
00864 }
00865 
00866 static CORE_ADDR
00867 m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
00868 {
00869   gdb_byte buf[8];
00870 
00871   frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
00872   return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
00873 }
00874 
00875 /* Normal frames.  */
00876 
00877 static struct m68k_frame_cache *
00878 m68k_frame_cache (struct frame_info *this_frame, void **this_cache)
00879 {
00880   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00881   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00882   struct m68k_frame_cache *cache;
00883   gdb_byte buf[4];
00884   int i;
00885 
00886   if (*this_cache)
00887     return *this_cache;
00888 
00889   cache = m68k_alloc_frame_cache ();
00890   *this_cache = cache;
00891 
00892   /* In principle, for normal frames, %fp holds the frame pointer,
00893      which holds the base address for the current stack frame.
00894      However, for functions that don't need it, the frame pointer is
00895      optional.  For these "frameless" functions the frame pointer is
00896      actually the frame pointer of the calling frame.  Signal
00897      trampolines are just a special case of a "frameless" function.
00898      They (usually) share their frame pointer with the frame that was
00899      in progress when the signal occurred.  */
00900 
00901   get_frame_register (this_frame, M68K_FP_REGNUM, buf);
00902   cache->base = extract_unsigned_integer (buf, 4, byte_order);
00903   if (cache->base == 0)
00904     return cache;
00905 
00906   /* For normal frames, %pc is stored at 4(%fp).  */
00907   cache->saved_regs[M68K_PC_REGNUM] = 4;
00908 
00909   cache->pc = get_frame_func (this_frame);
00910   if (cache->pc != 0)
00911     m68k_analyze_prologue (get_frame_arch (this_frame), cache->pc,
00912                            get_frame_pc (this_frame), cache);
00913 
00914   if (cache->locals < 0)
00915     {
00916       /* We didn't find a valid frame, which means that CACHE->base
00917          currently holds the frame pointer for our calling frame.  If
00918          we're at the start of a function, or somewhere half-way its
00919          prologue, the function's frame probably hasn't been fully
00920          setup yet.  Try to reconstruct the base address for the stack
00921          frame by looking at the stack pointer.  For truly "frameless"
00922          functions this might work too.  */
00923 
00924       get_frame_register (this_frame, M68K_SP_REGNUM, buf);
00925       cache->base = extract_unsigned_integer (buf, 4, byte_order)
00926                     + cache->sp_offset;
00927     }
00928 
00929   /* Now that we have the base address for the stack frame we can
00930      calculate the value of %sp in the calling frame.  */
00931   cache->saved_sp = cache->base + 8;
00932 
00933   /* Adjust all the saved registers such that they contain addresses
00934      instead of offsets.  */
00935   for (i = 0; i < M68K_NUM_REGS; i++)
00936     if (cache->saved_regs[i] != -1)
00937       cache->saved_regs[i] += cache->base;
00938 
00939   return cache;
00940 }
00941 
00942 static void
00943 m68k_frame_this_id (struct frame_info *this_frame, void **this_cache,
00944                     struct frame_id *this_id)
00945 {
00946   struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
00947 
00948   /* This marks the outermost frame.  */
00949   if (cache->base == 0)
00950     return;
00951 
00952   /* See the end of m68k_push_dummy_call.  */
00953   *this_id = frame_id_build (cache->base + 8, cache->pc);
00954 }
00955 
00956 static struct value *
00957 m68k_frame_prev_register (struct frame_info *this_frame, void **this_cache,
00958                           int regnum)
00959 {
00960   struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
00961 
00962   gdb_assert (regnum >= 0);
00963 
00964   if (regnum == M68K_SP_REGNUM && cache->saved_sp)
00965     return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
00966 
00967   if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
00968     return frame_unwind_got_memory (this_frame, regnum,
00969                                     cache->saved_regs[regnum]);
00970 
00971   return frame_unwind_got_register (this_frame, regnum, regnum);
00972 }
00973 
00974 static const struct frame_unwind m68k_frame_unwind =
00975 {
00976   NORMAL_FRAME,
00977   default_frame_unwind_stop_reason,
00978   m68k_frame_this_id,
00979   m68k_frame_prev_register,
00980   NULL,
00981   default_frame_sniffer
00982 };
00983 
00984 static CORE_ADDR
00985 m68k_frame_base_address (struct frame_info *this_frame, void **this_cache)
00986 {
00987   struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
00988 
00989   return cache->base;
00990 }
00991 
00992 static const struct frame_base m68k_frame_base =
00993 {
00994   &m68k_frame_unwind,
00995   m68k_frame_base_address,
00996   m68k_frame_base_address,
00997   m68k_frame_base_address
00998 };
00999 
01000 static struct frame_id
01001 m68k_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
01002 {
01003   CORE_ADDR fp;
01004 
01005   fp = get_frame_register_unsigned (this_frame, M68K_FP_REGNUM);
01006 
01007   /* See the end of m68k_push_dummy_call.  */
01008   return frame_id_build (fp + 8, get_frame_pc (this_frame));
01009 }
01010 
01011 
01012 /* Figure out where the longjmp will land.  Slurp the args out of the stack.
01013    We expect the first arg to be a pointer to the jmp_buf structure from which
01014    we extract the pc (JB_PC) that we will land at.  The pc is copied into PC.
01015    This routine returns true on success.  */
01016 
01017 static int
01018 m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
01019 {
01020   gdb_byte *buf;
01021   CORE_ADDR sp, jb_addr;
01022   struct gdbarch *gdbarch = get_frame_arch (frame);
01023   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01024   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01025 
01026   if (tdep->jb_pc < 0)
01027     {
01028       internal_error (__FILE__, __LINE__,
01029                       _("m68k_get_longjmp_target: not implemented"));
01030       return 0;
01031     }
01032 
01033   buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
01034   sp = get_frame_register_unsigned (frame, gdbarch_sp_regnum (gdbarch));
01035 
01036   if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack.  */
01037                           buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
01038     return 0;
01039 
01040   jb_addr = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
01041                                              / TARGET_CHAR_BIT, byte_order);
01042 
01043   if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
01044                           gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT),
01045                           byte_order)
01046     return 0;
01047 
01048   *pc = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
01049                                          / TARGET_CHAR_BIT, byte_order);
01050   return 1;
01051 }
01052 
01053 
01054 /* This is the implementation of gdbarch method
01055    return_in_first_hidden_param_p.  */
01056 
01057 static int
01058 m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
01059                                      struct type *type)
01060 {
01061   return 0;
01062 }
01063 
01064 /* System V Release 4 (SVR4).  */
01065 
01066 void
01067 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
01068 {
01069   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01070 
01071   /* SVR4 uses a different calling convention.  */
01072   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
01073 
01074   /* SVR4 uses %a0 instead of %a1.  */
01075   tdep->struct_value_regnum = M68K_A0_REGNUM;
01076 }
01077 
01078 
01079 /* Function: m68k_gdbarch_init
01080    Initializer function for the m68k gdbarch vector.
01081    Called by gdbarch.  Sets up the gdbarch vector(s) for this target.  */
01082 
01083 static struct gdbarch *
01084 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
01085 {
01086   struct gdbarch_tdep *tdep = NULL;
01087   struct gdbarch *gdbarch;
01088   struct gdbarch_list *best_arch;
01089   struct tdesc_arch_data *tdesc_data = NULL;
01090   int i;
01091   enum m68k_flavour flavour = m68k_no_flavour;
01092   int has_fp = 1;
01093   const struct floatformat **long_double_format = floatformats_m68881_ext;
01094 
01095   /* Check any target description for validity.  */
01096   if (tdesc_has_registers (info.target_desc))
01097     {
01098       const struct tdesc_feature *feature;
01099       int valid_p;
01100 
01101       feature = tdesc_find_feature (info.target_desc,
01102                                     "org.gnu.gdb.m68k.core");
01103 
01104       if (feature == NULL)
01105         {
01106           feature = tdesc_find_feature (info.target_desc,
01107                                         "org.gnu.gdb.coldfire.core");
01108           if (feature != NULL)
01109             flavour = m68k_coldfire_flavour;
01110         }
01111 
01112       if (feature == NULL)
01113         {
01114           feature = tdesc_find_feature (info.target_desc,
01115                                         "org.gnu.gdb.fido.core");
01116           if (feature != NULL)
01117             flavour = m68k_fido_flavour;
01118         }
01119 
01120       if (feature == NULL)
01121         return NULL;
01122 
01123       tdesc_data = tdesc_data_alloc ();
01124 
01125       valid_p = 1;
01126       for (i = 0; i <= M68K_PC_REGNUM; i++)
01127         valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
01128                                             m68k_register_names[i]);
01129 
01130       if (!valid_p)
01131         {
01132           tdesc_data_cleanup (tdesc_data);
01133           return NULL;
01134         }
01135 
01136       feature = tdesc_find_feature (info.target_desc,
01137                                     "org.gnu.gdb.coldfire.fp");
01138       if (feature != NULL)
01139         {
01140           valid_p = 1;
01141           for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++)
01142             valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
01143                                                 m68k_register_names[i]);
01144           if (!valid_p)
01145             {
01146               tdesc_data_cleanup (tdesc_data);
01147               return NULL;
01148             }
01149         }
01150       else
01151         has_fp = 0;
01152     }
01153 
01154   /* The mechanism for returning floating values from function
01155      and the type of long double depend on whether we're
01156      on ColdFire or standard m68k.  */
01157 
01158   if (info.bfd_arch_info && info.bfd_arch_info->mach != 0)
01159     {
01160       const bfd_arch_info_type *coldfire_arch = 
01161         bfd_lookup_arch (bfd_arch_m68k, bfd_mach_mcf_isa_a_nodiv);
01162 
01163       if (coldfire_arch
01164           && ((*info.bfd_arch_info->compatible) 
01165               (info.bfd_arch_info, coldfire_arch)))
01166         flavour = m68k_coldfire_flavour;
01167     }
01168   
01169   /* If there is already a candidate, use it.  */
01170   for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
01171        best_arch != NULL;
01172        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
01173     {
01174       if (flavour != gdbarch_tdep (best_arch->gdbarch)->flavour)
01175         continue;
01176 
01177       if (has_fp != gdbarch_tdep (best_arch->gdbarch)->fpregs_present)
01178         continue;
01179 
01180       break;
01181     }
01182 
01183   if (best_arch != NULL)
01184     {
01185       if (tdesc_data != NULL)
01186         tdesc_data_cleanup (tdesc_data);
01187       return best_arch->gdbarch;
01188     }
01189 
01190   tdep = xzalloc (sizeof (struct gdbarch_tdep));
01191   gdbarch = gdbarch_alloc (&info, tdep);
01192   tdep->fpregs_present = has_fp;
01193   tdep->flavour = flavour;
01194 
01195   if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
01196     long_double_format = floatformats_ieee_double;
01197   set_gdbarch_long_double_format (gdbarch, long_double_format);
01198   set_gdbarch_long_double_bit (gdbarch, long_double_format[0]->totalsize);
01199 
01200   set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
01201   set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
01202 
01203   /* Stack grows down.  */
01204   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
01205   set_gdbarch_frame_align (gdbarch, m68k_frame_align);
01206 
01207   set_gdbarch_believe_pcc_promotion (gdbarch, 1);
01208   if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
01209     set_gdbarch_decr_pc_after_break (gdbarch, 2);
01210 
01211   set_gdbarch_frame_args_skip (gdbarch, 8);
01212   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
01213 
01214   set_gdbarch_register_type (gdbarch, m68k_register_type);
01215   set_gdbarch_register_name (gdbarch, m68k_register_name);
01216   set_gdbarch_num_regs (gdbarch, M68K_NUM_REGS);
01217   set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
01218   set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
01219   set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
01220   set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
01221   set_gdbarch_register_to_value (gdbarch,  m68k_register_to_value);
01222   set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);
01223 
01224   if (has_fp)
01225     set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
01226 
01227   /* Try to figure out if the arch uses floating registers to return
01228      floating point values from functions.  */
01229   if (has_fp)
01230     {
01231       /* On ColdFire, floating point values are returned in D0.  */
01232       if (flavour == m68k_coldfire_flavour)
01233         tdep->float_return = 0;
01234       else
01235         tdep->float_return = 1;
01236     }
01237   else
01238     {
01239       /* No floating registers, so can't use them for returning values.  */
01240       tdep->float_return = 0;
01241     }
01242 
01243   /* Function call & return.  */
01244   set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
01245   set_gdbarch_return_value (gdbarch, m68k_return_value);
01246   set_gdbarch_return_in_first_hidden_param_p (gdbarch,
01247                                               m68k_return_in_first_hidden_param_p);
01248 
01249 
01250   /* Disassembler.  */
01251   set_gdbarch_print_insn (gdbarch, print_insn_m68k);
01252 
01253 #if defined JB_PC && defined JB_ELEMENT_SIZE
01254   tdep->jb_pc = JB_PC;
01255   tdep->jb_elt_size = JB_ELEMENT_SIZE;
01256 #else
01257   tdep->jb_pc = -1;
01258 #endif
01259   tdep->struct_value_regnum = M68K_A1_REGNUM;
01260   tdep->struct_return = reg_struct_return;
01261 
01262   /* Frame unwinder.  */
01263   set_gdbarch_dummy_id (gdbarch, m68k_dummy_id);
01264   set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
01265 
01266   /* Hook in the DWARF CFI frame unwinder.  */
01267   dwarf2_append_unwinders (gdbarch);
01268 
01269   frame_base_set_default (gdbarch, &m68k_frame_base);
01270 
01271   /* Hook in ABI-specific overrides, if they have been registered.  */
01272   gdbarch_init_osabi (info, gdbarch);
01273 
01274   /* Now we have tuned the configuration, set a few final things,
01275      based on what the OS ABI has told us.  */
01276 
01277   if (tdep->jb_pc >= 0)
01278     set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
01279 
01280   frame_unwind_append_unwinder (gdbarch, &m68k_frame_unwind);
01281 
01282   if (tdesc_data)
01283     tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
01284 
01285   return gdbarch;
01286 }
01287 
01288 
01289 static void
01290 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
01291 {
01292   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01293 
01294   if (tdep == NULL)
01295     return;
01296 }
01297 
01298 extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */
01299 
01300 void
01301 _initialize_m68k_tdep (void)
01302 {
01303   gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
01304 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines