gdb/m68k-tdep.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for the Motorola 68000 series.

  2.    Copyright (C) 1990-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "dwarf2-frame.h"
  16. #include "frame.h"
  17. #include "frame-base.h"
  18. #include "frame-unwind.h"
  19. #include "gdbtypes.h"
  20. #include "symtab.h"
  21. #include "gdbcore.h"
  22. #include "value.h"
  23. #include "inferior.h"
  24. #include "regcache.h"
  25. #include "arch-utils.h"
  26. #include "osabi.h"
  27. #include "dis-asm.h"
  28. #include "target-descriptions.h"

  29. #include "m68k-tdep.h"


  30. #define P_LINKL_FP        0x480e
  31. #define P_LINKW_FP        0x4e56
  32. #define P_PEA_FP        0x4856
  33. #define P_MOVEAL_SP_FP        0x2c4f
  34. #define P_ADDAW_SP        0xdefc
  35. #define P_ADDAL_SP        0xdffc
  36. #define P_SUBQW_SP        0x514f
  37. #define P_SUBQL_SP        0x518f
  38. #define P_LEA_SP_SP        0x4fef
  39. #define P_LEA_PC_A5        0x4bfb0170
  40. #define P_FMOVEMX_SP        0xf227
  41. #define P_MOVEL_SP        0x2f00
  42. #define P_MOVEML_SP        0x48e7

  43. /* Offset from SP to first arg on stack at first instruction of a function.  */
  44. #define SP_ARG0 (1 * 4)

  45. #if !defined (BPT_VECTOR)
  46. #define BPT_VECTOR 0xf
  47. #endif

  48. static const gdb_byte *
  49. m68k_local_breakpoint_from_pc (struct gdbarch *gdbarch,
  50.                                CORE_ADDR *pcptr, int *lenptr)
  51. {
  52.   static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
  53.   *lenptr = sizeof (break_insn);
  54.   return break_insn;
  55. }


  56. /* Construct types for ISA-specific registers.  */
  57. static struct type *
  58. m68k_ps_type (struct gdbarch *gdbarch)
  59. {
  60.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  61.   if (!tdep->m68k_ps_type)
  62.     {
  63.       struct type *type;

  64.       type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 4);
  65.       append_flags_type_flag (type, 0, "C");
  66.       append_flags_type_flag (type, 1, "V");
  67.       append_flags_type_flag (type, 2, "Z");
  68.       append_flags_type_flag (type, 3, "N");
  69.       append_flags_type_flag (type, 4, "X");
  70.       append_flags_type_flag (type, 8, "I0");
  71.       append_flags_type_flag (type, 9, "I1");
  72.       append_flags_type_flag (type, 10, "I2");
  73.       append_flags_type_flag (type, 12, "M");
  74.       append_flags_type_flag (type, 13, "S");
  75.       append_flags_type_flag (type, 14, "T0");
  76.       append_flags_type_flag (type, 15, "T1");

  77.       tdep->m68k_ps_type = type;
  78.     }

  79.   return tdep->m68k_ps_type;
  80. }

  81. static struct type *
  82. m68881_ext_type (struct gdbarch *gdbarch)
  83. {
  84.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  85.   if (!tdep->m68881_ext_type)
  86.     tdep->m68881_ext_type
  87.       = arch_float_type (gdbarch, -1, "builtin_type_m68881_ext",
  88.                          floatformats_m68881_ext);

  89.   return tdep->m68881_ext_type;
  90. }

  91. /* Return the GDB type object for the "standard" data type of data in
  92.    register N.  This should be int for D0-D7, SR, FPCONTROL and
  93.    FPSTATUS, long double for FP0-FP7, and void pointer for all others
  94.    (A0-A7, PC, FPIADDR).  Note, for registers which contain
  95.    addresses return pointer to void, not pointer to char, because we
  96.    don't want to attempt to print the string after printing the
  97.    address.  */

  98. static struct type *
  99. m68k_register_type (struct gdbarch *gdbarch, int regnum)
  100. {
  101.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  102.   if (tdep->fpregs_present)
  103.     {
  104.       if (regnum >= gdbarch_fp0_regnum (gdbarch)
  105.           && regnum <= gdbarch_fp0_regnum (gdbarch) + 7)
  106.         {
  107.           if (tdep->flavour == m68k_coldfire_flavour)
  108.             return builtin_type (gdbarch)->builtin_double;
  109.           else
  110.             return m68881_ext_type (gdbarch);
  111.         }

  112.       if (regnum == M68K_FPI_REGNUM)
  113.         return builtin_type (gdbarch)->builtin_func_ptr;

  114.       if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM)
  115.         return builtin_type (gdbarch)->builtin_int32;
  116.     }
  117.   else
  118.     {
  119.       if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM)
  120.         return builtin_type (gdbarch)->builtin_int0;
  121.     }

  122.   if (regnum == gdbarch_pc_regnum (gdbarch))
  123.     return builtin_type (gdbarch)->builtin_func_ptr;

  124.   if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
  125.     return builtin_type (gdbarch)->builtin_data_ptr;

  126.   if (regnum == M68K_PS_REGNUM)
  127.     return m68k_ps_type (gdbarch);

  128.   return builtin_type (gdbarch)->builtin_int32;
  129. }

  130. static const char *m68k_register_names[] = {
  131.     "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
  132.     "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
  133.     "ps", "pc",
  134.     "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
  135.     "fpcontrol", "fpstatus", "fpiaddr"
  136.   };

  137. /* Function: m68k_register_name
  138.    Returns the name of the standard m68k register regnum.  */

  139. static const char *
  140. m68k_register_name (struct gdbarch *gdbarch, int regnum)
  141. {
  142.   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
  143.     internal_error (__FILE__, __LINE__,
  144.                     _("m68k_register_name: illegal register number %d"),
  145.                     regnum);
  146.   else if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
  147.            && gdbarch_tdep (gdbarch)->fpregs_present == 0)
  148.     return "";
  149.   else
  150.     return m68k_register_names[regnum];
  151. }

  152. /* Return nonzero if a value of type TYPE stored in register REGNUM
  153.    needs any special handling.  */

  154. static int
  155. m68k_convert_register_p (struct gdbarch *gdbarch,
  156.                          int regnum, struct type *type)
  157. {
  158.   if (!gdbarch_tdep (gdbarch)->fpregs_present)
  159.     return 0;
  160.   return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
  161.           && type != register_type (gdbarch, M68K_FP0_REGNUM));
  162. }

  163. /* Read a value of type TYPE from register REGNUM in frame FRAME, and
  164.    return its contents in TO.  */

  165. static int
  166. m68k_register_to_value (struct frame_info *frame, int regnum,
  167.                         struct type *type, gdb_byte *to,
  168.                         int *optimizedp, int *unavailablep)
  169. {
  170.   gdb_byte from[M68K_MAX_REGISTER_SIZE];
  171.   struct type *fpreg_type = register_type (get_frame_arch (frame),
  172.                                            M68K_FP0_REGNUM);

  173.   /* We only support floating-point values.  */
  174.   if (TYPE_CODE (type) != TYPE_CODE_FLT)
  175.     {
  176.       warning (_("Cannot convert floating-point register value "
  177.                "to non-floating-point type."));
  178.       *optimizedp = *unavailablep = 0;
  179.       return 0;
  180.     }

  181.   /* Convert to TYPE.  */

  182.   /* Convert to TYPE.  */
  183.   if (!get_frame_register_bytes (frame, regnum, 0, TYPE_LENGTH (type),
  184.                                  from, optimizedp, unavailablep))
  185.     return 0;

  186.   convert_typed_floating (from, fpreg_type, to, type);
  187.   *optimizedp = *unavailablep = 0;
  188.   return 1;
  189. }

  190. /* Write the contents FROM of a value of type TYPE into register
  191.    REGNUM in frame FRAME.  */

  192. static void
  193. m68k_value_to_register (struct frame_info *frame, int regnum,
  194.                         struct type *type, const gdb_byte *from)
  195. {
  196.   gdb_byte to[M68K_MAX_REGISTER_SIZE];
  197.   struct type *fpreg_type = register_type (get_frame_arch (frame),
  198.                                            M68K_FP0_REGNUM);

  199.   /* We only support floating-point values.  */
  200.   if (TYPE_CODE (type) != TYPE_CODE_FLT)
  201.     {
  202.       warning (_("Cannot convert non-floating-point type "
  203.                "to floating-point register value."));
  204.       return;
  205.     }

  206.   /* Convert from TYPE.  */
  207.   convert_typed_floating (from, type, to, fpreg_type);
  208.   put_frame_register (frame, regnum, to);
  209. }


  210. /* There is a fair number of calling conventions that are in somewhat
  211.    wide use.  The 68000/08/10 don't support an FPU, not even as a
  212.    coprocessor.  All function return values are stored in %d0/%d1.
  213.    Structures are returned in a static buffer, a pointer to which is
  214.    returned in %d0.  This means that functions returning a structure
  215.    are not re-entrant.  To avoid this problem some systems use a
  216.    convention where the caller passes a pointer to a buffer in %a1
  217.    where the return values is to be stored.  This convention is the
  218.    default, and is implemented in the function m68k_return_value.

  219.    The 68020/030/040/060 do support an FPU, either as a coprocessor
  220.    (68881/2) or built-in (68040/68060).  That's why System V release 4
  221.    (SVR4) instroduces a new calling convention specified by the SVR4
  222.    psABI.  Integer values are returned in %d0/%d1, pointer return
  223.    values in %a0 and floating values in %fp0.  When calling functions
  224.    returning a structure the caller should pass a pointer to a buffer
  225.    for the return value in %a0.  This convention is implemented in the
  226.    function m68k_svr4_return_value, and by appropriately setting the
  227.    struct_value_regnum member of `struct gdbarch_tdep'.

  228.    GNU/Linux returns values in the same way as SVR4 does, but uses %a1
  229.    for passing the structure return value buffer.

  230.    GCC can also generate code where small structures are returned in
  231.    %d0/%d1 instead of in memory by using -freg-struct-return.  This is
  232.    the default on NetBSD a.out, OpenBSD and GNU/Linux and several
  233.    embedded systems.  This convention is implemented by setting the
  234.    struct_return member of `struct gdbarch_tdep' to reg_struct_return.  */

  235. /* Read a function return value of TYPE from REGCACHE, and copy that
  236.    into VALBUF.  */

  237. static void
  238. m68k_extract_return_value (struct type *type, struct regcache *regcache,
  239.                            gdb_byte *valbuf)
  240. {
  241.   int len = TYPE_LENGTH (type);
  242.   gdb_byte buf[M68K_MAX_REGISTER_SIZE];

  243.   if (len <= 4)
  244.     {
  245.       regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
  246.       memcpy (valbuf, buf + (4 - len), len);
  247.     }
  248.   else if (len <= 8)
  249.     {
  250.       regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
  251.       memcpy (valbuf, buf + (8 - len), len - 4);
  252.       regcache_raw_read (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
  253.     }
  254.   else
  255.     internal_error (__FILE__, __LINE__,
  256.                     _("Cannot extract return value of %d bytes long."), len);
  257. }

  258. static void
  259. m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
  260.                                 gdb_byte *valbuf)
  261. {
  262.   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
  263.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  264.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  265.   if (tdep->float_return && TYPE_CODE (type) == TYPE_CODE_FLT)
  266.     {
  267.       struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
  268.       regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
  269.       convert_typed_floating (buf, fpreg_type, valbuf, type);
  270.     }
  271.   else if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_LENGTH (type) == 4)
  272.     regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
  273.   else
  274.     m68k_extract_return_value (type, regcache, valbuf);
  275. }

  276. /* Write a function return value of TYPE from VALBUF into REGCACHE.  */

  277. static void
  278. m68k_store_return_value (struct type *type, struct regcache *regcache,
  279.                          const gdb_byte *valbuf)
  280. {
  281.   int len = TYPE_LENGTH (type);

  282.   if (len <= 4)
  283.     regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf);
  284.   else if (len <= 8)
  285.     {
  286.       regcache_raw_write_part (regcache, M68K_D0_REGNUM, 8 - len,
  287.                                len - 4, valbuf);
  288.       regcache_raw_write (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
  289.     }
  290.   else
  291.     internal_error (__FILE__, __LINE__,
  292.                     _("Cannot store return value of %d bytes long."), len);
  293. }

  294. static void
  295. m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
  296.                               const gdb_byte *valbuf)
  297. {
  298.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  299.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  300.   if (tdep->float_return && TYPE_CODE (type) == TYPE_CODE_FLT)
  301.     {
  302.       struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
  303.       gdb_byte buf[M68K_MAX_REGISTER_SIZE];
  304.       convert_typed_floating (valbuf, type, buf, fpreg_type);
  305.       regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
  306.     }
  307.   else if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_LENGTH (type) == 4)
  308.     {
  309.       regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
  310.       regcache_raw_write (regcache, M68K_D0_REGNUM, valbuf);
  311.     }
  312.   else
  313.     m68k_store_return_value (type, regcache, valbuf);
  314. }

  315. /* Return non-zero if TYPE, which is assumed to be a structure, union or
  316.    complex type, should be returned in registers for architecture
  317.    GDBARCH.  */

  318. static int
  319. m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
  320. {
  321.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  322.   enum type_code code = TYPE_CODE (type);
  323.   int len = TYPE_LENGTH (type);

  324.   gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
  325.               || code == TYPE_CODE_COMPLEX);

  326.   if (tdep->struct_return == pcc_struct_return)
  327.     return 0;

  328.   return (len == 1 || len == 2 || len == 4 || len == 8);
  329. }

  330. /* Determine, for architecture GDBARCH, how a return value of TYPE
  331.    should be returned.  If it is supposed to be returned in registers,
  332.    and READBUF is non-zero, read the appropriate value from REGCACHE,
  333.    and copy it into READBUF.  If WRITEBUF is non-zero, write the value
  334.    from WRITEBUF into REGCACHE.  */

  335. static enum return_value_convention
  336. m68k_return_value (struct gdbarch *gdbarch, struct value *function,
  337.                    struct type *type, struct regcache *regcache,
  338.                    gdb_byte *readbuf, const gdb_byte *writebuf)
  339. {
  340.   enum type_code code = TYPE_CODE (type);

  341.   /* GCC returns a `long double' in memory too.  */
  342.   if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
  343.         || code == TYPE_CODE_COMPLEX)
  344.        && !m68k_reg_struct_return_p (gdbarch, type))
  345.       || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12))
  346.     {
  347.       /* The default on m68k is to return structures in static memory.
  348.          Consequently a function must return the address where we can
  349.          find the return value.  */

  350.       if (readbuf)
  351.         {
  352.           ULONGEST addr;

  353.           regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
  354.           read_memory (addr, readbuf, TYPE_LENGTH (type));
  355.         }

  356.       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
  357.     }

  358.   if (readbuf)
  359.     m68k_extract_return_value (type, regcache, readbuf);
  360.   if (writebuf)
  361.     m68k_store_return_value (type, regcache, writebuf);

  362.   return RETURN_VALUE_REGISTER_CONVENTION;
  363. }

  364. static enum return_value_convention
  365. m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
  366.                         struct type *type, struct regcache *regcache,
  367.                         gdb_byte *readbuf, const gdb_byte *writebuf)
  368. {
  369.   enum type_code code = TYPE_CODE (type);

  370.   if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
  371.        || code == TYPE_CODE_COMPLEX)
  372.       && !m68k_reg_struct_return_p (gdbarch, type))
  373.     {
  374.       /* The System V ABI says that:

  375.          "A function returning a structure or union also sets %a0 to
  376.          the value it finds in %a0.  Thus when the caller receives
  377.          control again, the address of the returned object resides in
  378.          register %a0."

  379.          So the ABI guarantees that we can always find the return
  380.          value just after the function has returned.  */

  381.       if (readbuf)
  382.         {
  383.           ULONGEST addr;

  384.           regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr);
  385.           read_memory (addr, readbuf, TYPE_LENGTH (type));
  386.         }

  387.       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
  388.     }

  389.   /* This special case is for structures consisting of a single
  390.      `float' or `double' member.  These structures are returned in
  391.      %fp0.  For these structures, we call ourselves recursively,
  392.      changing TYPE into the type of the first member of the structure.
  393.      Since that should work for all structures that have only one
  394.      member, we don't bother to check the member's type here.  */
  395.   if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
  396.     {
  397.       type = check_typedef (TYPE_FIELD_TYPE (type, 0));
  398.       return m68k_svr4_return_value (gdbarch, function, type, regcache,
  399.                                      readbuf, writebuf);
  400.     }

  401.   if (readbuf)
  402.     m68k_svr4_extract_return_value (type, regcache, readbuf);
  403.   if (writebuf)
  404.     m68k_svr4_store_return_value (type, regcache, writebuf);

  405.   return RETURN_VALUE_REGISTER_CONVENTION;
  406. }


  407. /* Always align the frame to a 4-byte boundary.  This is required on
  408.    coldfire and harmless on the rest.  */

  409. static CORE_ADDR
  410. m68k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
  411. {
  412.   /* Align the stack to four bytes.  */
  413.   return sp & ~3;
  414. }

  415. static CORE_ADDR
  416. m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  417.                       struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
  418.                       struct value **args, CORE_ADDR sp, int struct_return,
  419.                       CORE_ADDR struct_addr)
  420. {
  421.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  422.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  423.   gdb_byte buf[4];
  424.   int i;

  425.   /* Push arguments in reverse order.  */
  426.   for (i = nargs - 1; i >= 0; i--)
  427.     {
  428.       struct type *value_type = value_enclosing_type (args[i]);
  429.       int len = TYPE_LENGTH (value_type);
  430.       int container_len = (len + 3) & ~3;
  431.       int offset;

  432.       /* Non-scalars bigger than 4 bytes are left aligned, others are
  433.          right aligned.  */
  434.       if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT
  435.            || TYPE_CODE (value_type) == TYPE_CODE_UNION
  436.            || TYPE_CODE (value_type) == TYPE_CODE_ARRAY)
  437.           && len > 4)
  438.         offset = 0;
  439.       else
  440.         offset = container_len - len;
  441.       sp -= container_len;
  442.       write_memory (sp + offset, value_contents_all (args[i]), len);
  443.     }

  444.   /* Store struct value address.  */
  445.   if (struct_return)
  446.     {
  447.       store_unsigned_integer (buf, 4, byte_order, struct_addr);
  448.       regcache_cooked_write (regcache, tdep->struct_value_regnum, buf);
  449.     }

  450.   /* Store return address.  */
  451.   sp -= 4;
  452.   store_unsigned_integer (buf, 4, byte_order, bp_addr);
  453.   write_memory (sp, buf, 4);

  454.   /* Finally, update the stack pointer...  */
  455.   store_unsigned_integer (buf, 4, byte_order, sp);
  456.   regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);

  457.   /* ...and fake a frame pointer.  */
  458.   regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);

  459.   /* DWARF2/GCC uses the stack address *before* the function call as a
  460.      frame's CFA.  */
  461.   return sp + 8;
  462. }

  463. /* Convert a dwarf or dwarf2 regnumber to a GDB regnum.  */

  464. static int
  465. m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
  466. {
  467.   if (num < 8)
  468.     /* d0..7 */
  469.     return (num - 0) + M68K_D0_REGNUM;
  470.   else if (num < 16)
  471.     /* a0..7 */
  472.     return (num - 8) + M68K_A0_REGNUM;
  473.   else if (num < 24 && gdbarch_tdep (gdbarch)->fpregs_present)
  474.     /* fp0..7 */
  475.     return (num - 16) + M68K_FP0_REGNUM;
  476.   else if (num == 25)
  477.     /* pc */
  478.     return M68K_PC_REGNUM;
  479.   else
  480.     return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
  481. }


  482. struct m68k_frame_cache
  483. {
  484.   /* Base address.  */
  485.   CORE_ADDR base;
  486.   CORE_ADDR sp_offset;
  487.   CORE_ADDR pc;

  488.   /* Saved registers.  */
  489.   CORE_ADDR saved_regs[M68K_NUM_REGS];
  490.   CORE_ADDR saved_sp;

  491.   /* Stack space reserved for local variables.  */
  492.   long locals;
  493. };

  494. /* Allocate and initialize a frame cache.  */

  495. static struct m68k_frame_cache *
  496. m68k_alloc_frame_cache (void)
  497. {
  498.   struct m68k_frame_cache *cache;
  499.   int i;

  500.   cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);

  501.   /* Base address.  */
  502.   cache->base = 0;
  503.   cache->sp_offset = -4;
  504.   cache->pc = 0;

  505.   /* Saved registers.  We initialize these to -1 since zero is a valid
  506.      offset (that's where %fp is supposed to be stored).  */
  507.   for (i = 0; i < M68K_NUM_REGS; i++)
  508.     cache->saved_regs[i] = -1;

  509.   /* Frameless until proven otherwise.  */
  510.   cache->locals = -1;

  511.   return cache;
  512. }

  513. /* Check whether PC points at a code that sets up a new stack frame.
  514.    If so, it updates CACHE and returns the address of the first
  515.    instruction after the sequence that sets removes the "hidden"
  516.    argument from the stack or CURRENT_PC, whichever is smaller.
  517.    Otherwise, return PC.  */

  518. static CORE_ADDR
  519. m68k_analyze_frame_setup (struct gdbarch *gdbarch,
  520.                           CORE_ADDR pc, CORE_ADDR current_pc,
  521.                           struct m68k_frame_cache *cache)
  522. {
  523.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  524.   int op;

  525.   if (pc >= current_pc)
  526.     return current_pc;

  527.   op = read_memory_unsigned_integer (pc, 2, byte_order);

  528.   if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
  529.     {
  530.       cache->saved_regs[M68K_FP_REGNUM] = 0;
  531.       cache->sp_offset += 4;
  532.       if (op == P_LINKW_FP)
  533.         {
  534.           /* link.w %fp, #-N */
  535.           /* link.w %fp, #0; adda.l #-N, %sp */
  536.           cache->locals = -read_memory_integer (pc + 2, 2, byte_order);

  537.           if (pc + 4 < current_pc && cache->locals == 0)
  538.             {
  539.               op = read_memory_unsigned_integer (pc + 4, 2, byte_order);
  540.               if (op == P_ADDAL_SP)
  541.                 {
  542.                   cache->locals = read_memory_integer (pc + 6, 4, byte_order);
  543.                   return pc + 10;
  544.                 }
  545.             }

  546.           return pc + 4;
  547.         }
  548.       else if (op == P_LINKL_FP)
  549.         {
  550.           /* link.l %fp, #-N */
  551.           cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
  552.           return pc + 6;
  553.         }
  554.       else
  555.         {
  556.           /* pea (%fp); movea.l %sp, %fp */
  557.           cache->locals = 0;

  558.           if (pc + 2 < current_pc)
  559.             {
  560.               op = read_memory_unsigned_integer (pc + 2, 2, byte_order);

  561.               if (op == P_MOVEAL_SP_FP)
  562.                 {
  563.                   /* move.l %sp, %fp */
  564.                   return pc + 4;
  565.                 }
  566.             }

  567.           return pc + 2;
  568.         }
  569.     }
  570.   else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
  571.     {
  572.       /* subq.[wl] #N,%sp */
  573.       /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
  574.       cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
  575.       if (pc + 2 < current_pc)
  576.         {
  577.           op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
  578.           if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
  579.             {
  580.               cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
  581.               return pc + 4;
  582.             }
  583.         }
  584.       return pc + 2;
  585.     }
  586.   else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
  587.     {
  588.       /* adda.w #-N,%sp */
  589.       /* lea (-N,%sp),%sp */
  590.       cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
  591.       return pc + 4;
  592.     }
  593.   else if (op == P_ADDAL_SP)
  594.     {
  595.       /* adda.l #-N,%sp */
  596.       cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
  597.       return pc + 6;
  598.     }

  599.   return pc;
  600. }

  601. /* Check whether PC points at code that saves registers on the stack.
  602.    If so, it updates CACHE and returns the address of the first
  603.    instruction after the register saves or CURRENT_PC, whichever is
  604.    smaller.  Otherwise, return PC.  */

  605. static CORE_ADDR
  606. m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
  607.                              CORE_ADDR current_pc,
  608.                              struct m68k_frame_cache *cache)
  609. {
  610.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  611.   if (cache->locals >= 0)
  612.     {
  613.       CORE_ADDR offset;
  614.       int op;
  615.       int i, mask, regno;

  616.       offset = -4 - cache->locals;
  617.       while (pc < current_pc)
  618.         {
  619.           op = read_memory_unsigned_integer (pc, 2, byte_order);
  620.           if (op == P_FMOVEMX_SP
  621.               && gdbarch_tdep (gdbarch)->fpregs_present)
  622.             {
  623.               /* fmovem.x REGS,-(%sp) */
  624.               op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
  625.               if ((op & 0xff00) == 0xe000)
  626.                 {
  627.                   mask = op & 0xff;
  628.                   for (i = 0; i < 16; i++, mask >>= 1)
  629.                     {
  630.                       if (mask & 1)
  631.                         {
  632.                           cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
  633.                           offset -= 12;
  634.                         }
  635.                     }
  636.                   pc += 4;
  637.                 }
  638.               else
  639.                 break;
  640.             }
  641.           else if ((op & 0177760) == P_MOVEL_SP)
  642.             {
  643.               /* move.l %R,-(%sp) */
  644.               regno = op & 017;
  645.               cache->saved_regs[regno] = offset;
  646.               offset -= 4;
  647.               pc += 2;
  648.             }
  649.           else if (op == P_MOVEML_SP)
  650.             {
  651.               /* movem.l REGS,-(%sp) */
  652.               mask = read_memory_unsigned_integer (pc + 2, 2, byte_order);
  653.               for (i = 0; i < 16; i++, mask >>= 1)
  654.                 {
  655.                   if (mask & 1)
  656.                     {
  657.                       cache->saved_regs[15 - i] = offset;
  658.                       offset -= 4;
  659.                     }
  660.                 }
  661.               pc += 4;
  662.             }
  663.           else
  664.             break;
  665.         }
  666.     }

  667.   return pc;
  668. }


  669. /* Do a full analysis of the prologue at PC and update CACHE
  670.    accordingly.  Bail out early if CURRENT_PC is reached.  Return the
  671.    address where the analysis stopped.

  672.    We handle all cases that can be generated by gcc.

  673.    For allocating a stack frame:

  674.    link.w %a6,#-N
  675.    link.l %a6,#-N
  676.    pea (%fp); move.l %sp,%fp
  677.    link.w %a6,#0; add.l #-N,%sp
  678.    subq.l #N,%sp
  679.    subq.w #N,%sp
  680.    subq.w #8,%sp; subq.w #N-8,%sp
  681.    add.w #-N,%sp
  682.    lea (-N,%sp),%sp
  683.    add.l #-N,%sp

  684.    For saving registers:

  685.    fmovem.x REGS,-(%sp)
  686.    move.l R1,-(%sp)
  687.    move.l R1,-(%sp); move.l R2,-(%sp)
  688.    movem.l REGS,-(%sp)

  689.    For setting up the PIC register:

  690.    lea (%pc,N),%a5

  691.    */

  692. static CORE_ADDR
  693. m68k_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
  694.                        CORE_ADDR current_pc, struct m68k_frame_cache *cache)
  695. {
  696.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  697.   unsigned int op;

  698.   pc = m68k_analyze_frame_setup (gdbarch, pc, current_pc, cache);
  699.   pc = m68k_analyze_register_saves (gdbarch, pc, current_pc, cache);
  700.   if (pc >= current_pc)
  701.     return current_pc;

  702.   /* Check for GOT setup.  */
  703.   op = read_memory_unsigned_integer (pc, 4, byte_order);
  704.   if (op == P_LEA_PC_A5)
  705.     {
  706.       /* lea (%pc,N),%a5 */
  707.       return pc + 8;
  708.     }

  709.   return pc;
  710. }

  711. /* Return PC of first real instruction.  */

  712. static CORE_ADDR
  713. m68k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
  714. {
  715.   struct m68k_frame_cache cache;
  716.   CORE_ADDR pc;

  717.   cache.locals = -1;
  718.   pc = m68k_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache);
  719.   if (cache.locals < 0)
  720.     return start_pc;
  721.   return pc;
  722. }

  723. static CORE_ADDR
  724. m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  725. {
  726.   gdb_byte buf[8];

  727.   frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
  728.   return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
  729. }

  730. /* Normal frames.  */

  731. static struct m68k_frame_cache *
  732. m68k_frame_cache (struct frame_info *this_frame, void **this_cache)
  733. {
  734.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  735.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  736.   struct m68k_frame_cache *cache;
  737.   gdb_byte buf[4];
  738.   int i;

  739.   if (*this_cache)
  740.     return *this_cache;

  741.   cache = m68k_alloc_frame_cache ();
  742.   *this_cache = cache;

  743.   /* In principle, for normal frames, %fp holds the frame pointer,
  744.      which holds the base address for the current stack frame.
  745.      However, for functions that don't need it, the frame pointer is
  746.      optional.  For these "frameless" functions the frame pointer is
  747.      actually the frame pointer of the calling frame.  Signal
  748.      trampolines are just a special case of a "frameless" function.
  749.      They (usually) share their frame pointer with the frame that was
  750.      in progress when the signal occurred.  */

  751.   get_frame_register (this_frame, M68K_FP_REGNUM, buf);
  752.   cache->base = extract_unsigned_integer (buf, 4, byte_order);
  753.   if (cache->base == 0)
  754.     return cache;

  755.   /* For normal frames, %pc is stored at 4(%fp).  */
  756.   cache->saved_regs[M68K_PC_REGNUM] = 4;

  757.   cache->pc = get_frame_func (this_frame);
  758.   if (cache->pc != 0)
  759.     m68k_analyze_prologue (get_frame_arch (this_frame), cache->pc,
  760.                            get_frame_pc (this_frame), cache);

  761.   if (cache->locals < 0)
  762.     {
  763.       /* We didn't find a valid frame, which means that CACHE->base
  764.          currently holds the frame pointer for our calling frame.  If
  765.          we're at the start of a function, or somewhere half-way its
  766.          prologue, the function's frame probably hasn't been fully
  767.          setup yet.  Try to reconstruct the base address for the stack
  768.          frame by looking at the stack pointer.  For truly "frameless"
  769.          functions this might work too.  */

  770.       get_frame_register (this_frame, M68K_SP_REGNUM, buf);
  771.       cache->base = extract_unsigned_integer (buf, 4, byte_order)
  772.                     + cache->sp_offset;
  773.     }

  774.   /* Now that we have the base address for the stack frame we can
  775.      calculate the value of %sp in the calling frame.  */
  776.   cache->saved_sp = cache->base + 8;

  777.   /* Adjust all the saved registers such that they contain addresses
  778.      instead of offsets.  */
  779.   for (i = 0; i < M68K_NUM_REGS; i++)
  780.     if (cache->saved_regs[i] != -1)
  781.       cache->saved_regs[i] += cache->base;

  782.   return cache;
  783. }

  784. static void
  785. m68k_frame_this_id (struct frame_info *this_frame, void **this_cache,
  786.                     struct frame_id *this_id)
  787. {
  788.   struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);

  789.   /* This marks the outermost frame.  */
  790.   if (cache->base == 0)
  791.     return;

  792.   /* See the end of m68k_push_dummy_call.  */
  793.   *this_id = frame_id_build (cache->base + 8, cache->pc);
  794. }

  795. static struct value *
  796. m68k_frame_prev_register (struct frame_info *this_frame, void **this_cache,
  797.                           int regnum)
  798. {
  799.   struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);

  800.   gdb_assert (regnum >= 0);

  801.   if (regnum == M68K_SP_REGNUM && cache->saved_sp)
  802.     return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);

  803.   if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
  804.     return frame_unwind_got_memory (this_frame, regnum,
  805.                                     cache->saved_regs[regnum]);

  806.   return frame_unwind_got_register (this_frame, regnum, regnum);
  807. }

  808. static const struct frame_unwind m68k_frame_unwind =
  809. {
  810.   NORMAL_FRAME,
  811.   default_frame_unwind_stop_reason,
  812.   m68k_frame_this_id,
  813.   m68k_frame_prev_register,
  814.   NULL,
  815.   default_frame_sniffer
  816. };

  817. static CORE_ADDR
  818. m68k_frame_base_address (struct frame_info *this_frame, void **this_cache)
  819. {
  820.   struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);

  821.   return cache->base;
  822. }

  823. static const struct frame_base m68k_frame_base =
  824. {
  825.   &m68k_frame_unwind,
  826.   m68k_frame_base_address,
  827.   m68k_frame_base_address,
  828.   m68k_frame_base_address
  829. };

  830. static struct frame_id
  831. m68k_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  832. {
  833.   CORE_ADDR fp;

  834.   fp = get_frame_register_unsigned (this_frame, M68K_FP_REGNUM);

  835.   /* See the end of m68k_push_dummy_call.  */
  836.   return frame_id_build (fp + 8, get_frame_pc (this_frame));
  837. }


  838. /* Figure out where the longjmp will land.  Slurp the args out of the stack.
  839.    We expect the first arg to be a pointer to the jmp_buf structure from which
  840.    we extract the pc (JB_PC) that we will land at.  The pc is copied into PC.
  841.    This routine returns true on success.  */

  842. static int
  843. m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  844. {
  845.   gdb_byte *buf;
  846.   CORE_ADDR sp, jb_addr;
  847.   struct gdbarch *gdbarch = get_frame_arch (frame);
  848.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  849.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  850.   if (tdep->jb_pc < 0)
  851.     {
  852.       internal_error (__FILE__, __LINE__,
  853.                       _("m68k_get_longjmp_target: not implemented"));
  854.       return 0;
  855.     }

  856.   buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
  857.   sp = get_frame_register_unsigned (frame, gdbarch_sp_regnum (gdbarch));

  858.   if (target_read_memory (sp + SP_ARG0,        /* Offset of first arg on stack.  */
  859.                           buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
  860.     return 0;

  861.   jb_addr = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
  862.                                              / TARGET_CHAR_BIT, byte_order);

  863.   if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
  864.                           gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT),
  865.                           byte_order)
  866.     return 0;

  867.   *pc = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
  868.                                          / TARGET_CHAR_BIT, byte_order);
  869.   return 1;
  870. }


  871. /* This is the implementation of gdbarch method
  872.    return_in_first_hidden_param_p.  */

  873. static int
  874. m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
  875.                                      struct type *type)
  876. {
  877.   return 0;
  878. }

  879. /* System V Release 4 (SVR4).  */

  880. void
  881. m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  882. {
  883.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  884.   /* SVR4 uses a different calling convention.  */
  885.   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);

  886.   /* SVR4 uses %a0 instead of %a1.  */
  887.   tdep->struct_value_regnum = M68K_A0_REGNUM;
  888. }


  889. /* Function: m68k_gdbarch_init
  890.    Initializer function for the m68k gdbarch vector.
  891.    Called by gdbarch.  Sets up the gdbarch vector(s) for this target.  */

  892. static struct gdbarch *
  893. m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  894. {
  895.   struct gdbarch_tdep *tdep = NULL;
  896.   struct gdbarch *gdbarch;
  897.   struct gdbarch_list *best_arch;
  898.   struct tdesc_arch_data *tdesc_data = NULL;
  899.   int i;
  900.   enum m68k_flavour flavour = m68k_no_flavour;
  901.   int has_fp = 1;
  902.   const struct floatformat **long_double_format = floatformats_m68881_ext;

  903.   /* Check any target description for validity.  */
  904.   if (tdesc_has_registers (info.target_desc))
  905.     {
  906.       const struct tdesc_feature *feature;
  907.       int valid_p;

  908.       feature = tdesc_find_feature (info.target_desc,
  909.                                     "org.gnu.gdb.m68k.core");

  910.       if (feature == NULL)
  911.         {
  912.           feature = tdesc_find_feature (info.target_desc,
  913.                                         "org.gnu.gdb.coldfire.core");
  914.           if (feature != NULL)
  915.             flavour = m68k_coldfire_flavour;
  916.         }

  917.       if (feature == NULL)
  918.         {
  919.           feature = tdesc_find_feature (info.target_desc,
  920.                                         "org.gnu.gdb.fido.core");
  921.           if (feature != NULL)
  922.             flavour = m68k_fido_flavour;
  923.         }

  924.       if (feature == NULL)
  925.         return NULL;

  926.       tdesc_data = tdesc_data_alloc ();

  927.       valid_p = 1;
  928.       for (i = 0; i <= M68K_PC_REGNUM; i++)
  929.         valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
  930.                                             m68k_register_names[i]);

  931.       if (!valid_p)
  932.         {
  933.           tdesc_data_cleanup (tdesc_data);
  934.           return NULL;
  935.         }

  936.       feature = tdesc_find_feature (info.target_desc,
  937.                                     "org.gnu.gdb.coldfire.fp");
  938.       if (feature != NULL)
  939.         {
  940.           valid_p = 1;
  941.           for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++)
  942.             valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
  943.                                                 m68k_register_names[i]);
  944.           if (!valid_p)
  945.             {
  946.               tdesc_data_cleanup (tdesc_data);
  947.               return NULL;
  948.             }
  949.         }
  950.       else
  951.         has_fp = 0;
  952.     }

  953.   /* The mechanism for returning floating values from function
  954.      and the type of long double depend on whether we're
  955.      on ColdFire or standard m68k.  */

  956.   if (info.bfd_arch_info && info.bfd_arch_info->mach != 0)
  957.     {
  958.       const bfd_arch_info_type *coldfire_arch =
  959.         bfd_lookup_arch (bfd_arch_m68k, bfd_mach_mcf_isa_a_nodiv);

  960.       if (coldfire_arch
  961.           && ((*info.bfd_arch_info->compatible)
  962.               (info.bfd_arch_info, coldfire_arch)))
  963.         flavour = m68k_coldfire_flavour;
  964.     }

  965.   /* If there is already a candidate, use it.  */
  966.   for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
  967.        best_arch != NULL;
  968.        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
  969.     {
  970.       if (flavour != gdbarch_tdep (best_arch->gdbarch)->flavour)
  971.         continue;

  972.       if (has_fp != gdbarch_tdep (best_arch->gdbarch)->fpregs_present)
  973.         continue;

  974.       break;
  975.     }

  976.   if (best_arch != NULL)
  977.     {
  978.       if (tdesc_data != NULL)
  979.         tdesc_data_cleanup (tdesc_data);
  980.       return best_arch->gdbarch;
  981.     }

  982.   tdep = xzalloc (sizeof (struct gdbarch_tdep));
  983.   gdbarch = gdbarch_alloc (&info, tdep);
  984.   tdep->fpregs_present = has_fp;
  985.   tdep->flavour = flavour;

  986.   if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
  987.     long_double_format = floatformats_ieee_double;
  988.   set_gdbarch_long_double_format (gdbarch, long_double_format);
  989.   set_gdbarch_long_double_bit (gdbarch, long_double_format[0]->totalsize);

  990.   set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
  991.   set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);

  992.   /* Stack grows down.  */
  993.   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  994.   set_gdbarch_frame_align (gdbarch, m68k_frame_align);

  995.   set_gdbarch_believe_pcc_promotion (gdbarch, 1);
  996.   if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
  997.     set_gdbarch_decr_pc_after_break (gdbarch, 2);

  998.   set_gdbarch_frame_args_skip (gdbarch, 8);
  999.   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);

  1000.   set_gdbarch_register_type (gdbarch, m68k_register_type);
  1001.   set_gdbarch_register_name (gdbarch, m68k_register_name);
  1002.   set_gdbarch_num_regs (gdbarch, M68K_NUM_REGS);
  1003.   set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
  1004.   set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
  1005.   set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
  1006.   set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
  1007.   set_gdbarch_register_to_value (gdbarchm68k_register_to_value);
  1008.   set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);

  1009.   if (has_fp)
  1010.     set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);

  1011.   /* Try to figure out if the arch uses floating registers to return
  1012.      floating point values from functions.  */
  1013.   if (has_fp)
  1014.     {
  1015.       /* On ColdFire, floating point values are returned in D0.  */
  1016.       if (flavour == m68k_coldfire_flavour)
  1017.         tdep->float_return = 0;
  1018.       else
  1019.         tdep->float_return = 1;
  1020.     }
  1021.   else
  1022.     {
  1023.       /* No floating registers, so can't use them for returning values.  */
  1024.       tdep->float_return = 0;
  1025.     }

  1026.   /* Function call & return.  */
  1027.   set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
  1028.   set_gdbarch_return_value (gdbarch, m68k_return_value);
  1029.   set_gdbarch_return_in_first_hidden_param_p (gdbarch,
  1030.                                               m68k_return_in_first_hidden_param_p);


  1031.   /* Disassembler.  */
  1032.   set_gdbarch_print_insn (gdbarch, print_insn_m68k);

  1033. #if defined JB_PC && defined JB_ELEMENT_SIZE
  1034.   tdep->jb_pc = JB_PC;
  1035.   tdep->jb_elt_size = JB_ELEMENT_SIZE;
  1036. #else
  1037.   tdep->jb_pc = -1;
  1038. #endif
  1039.   tdep->struct_value_regnum = M68K_A1_REGNUM;
  1040.   tdep->struct_return = reg_struct_return;

  1041.   /* Frame unwinder.  */
  1042.   set_gdbarch_dummy_id (gdbarch, m68k_dummy_id);
  1043.   set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);

  1044.   /* Hook in the DWARF CFI frame unwinder.  */
  1045.   dwarf2_append_unwinders (gdbarch);

  1046.   frame_base_set_default (gdbarch, &m68k_frame_base);

  1047.   /* Hook in ABI-specific overrides, if they have been registered.  */
  1048.   gdbarch_init_osabi (info, gdbarch);

  1049.   /* Now we have tuned the configuration, set a few final things,
  1050.      based on what the OS ABI has told us.  */

  1051.   if (tdep->jb_pc >= 0)
  1052.     set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);

  1053.   frame_unwind_append_unwinder (gdbarch, &m68k_frame_unwind);

  1054.   if (tdesc_data)
  1055.     tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);

  1056.   return gdbarch;
  1057. }


  1058. static void
  1059. m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
  1060. {
  1061.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  1062.   if (tdep == NULL)
  1063.     return;
  1064. }

  1065. extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */

  1066. void
  1067. _initialize_m68k_tdep (void)
  1068. {
  1069.   gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
  1070. }