gdb/mt-tdep.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for Morpho mt processor, for GDB.

  2.    Copyright (C) 2005-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. /* Contributed by Michael Snyder, msnyder@redhat.com.  */

  15. #include "defs.h"
  16. #include "frame.h"
  17. #include "frame-unwind.h"
  18. #include "frame-base.h"
  19. #include "symtab.h"
  20. #include "dis-asm.h"
  21. #include "arch-utils.h"
  22. #include "gdbtypes.h"
  23. #include "regcache.h"
  24. #include "reggroups.h"
  25. #include "gdbcore.h"
  26. #include "trad-frame.h"
  27. #include "inferior.h"
  28. #include "dwarf2-frame.h"
  29. #include "infcall.h"
  30. #include "language.h"
  31. #include "valprint.h"

  32. enum mt_arch_constants
  33. {
  34.   MT_MAX_STRUCT_SIZE = 16
  35. };

  36. enum mt_gdb_regnums
  37. {
  38.   MT_R0_REGNUM,                        /* 32 bit regs.  */
  39.   MT_R1_REGNUM,
  40.   MT_1ST_ARGREG = MT_R1_REGNUM,
  41.   MT_R2_REGNUM,
  42.   MT_R3_REGNUM,
  43.   MT_R4_REGNUM,
  44.   MT_LAST_ARGREG = MT_R4_REGNUM,
  45.   MT_R5_REGNUM,
  46.   MT_R6_REGNUM,
  47.   MT_R7_REGNUM,
  48.   MT_R8_REGNUM,
  49.   MT_R9_REGNUM,
  50.   MT_R10_REGNUM,
  51.   MT_R11_REGNUM,
  52.   MT_R12_REGNUM,
  53.   MT_FP_REGNUM = MT_R12_REGNUM,
  54.   MT_R13_REGNUM,
  55.   MT_SP_REGNUM = MT_R13_REGNUM,
  56.   MT_R14_REGNUM,
  57.   MT_RA_REGNUM = MT_R14_REGNUM,
  58.   MT_R15_REGNUM,
  59.   MT_IRA_REGNUM = MT_R15_REGNUM,
  60.   MT_PC_REGNUM,

  61.   /* Interrupt Enable pseudo-register, exported by SID.  */
  62.   MT_INT_ENABLE_REGNUM,
  63.   /* End of CPU regs.  */

  64.   MT_NUM_CPU_REGS,

  65.   /* Co-processor registers.  */
  66.   MT_COPRO_REGNUM = MT_NUM_CPU_REGS,        /* 16 bit regs.  */
  67.   MT_CPR0_REGNUM,
  68.   MT_CPR1_REGNUM,
  69.   MT_CPR2_REGNUM,
  70.   MT_CPR3_REGNUM,
  71.   MT_CPR4_REGNUM,
  72.   MT_CPR5_REGNUM,
  73.   MT_CPR6_REGNUM,
  74.   MT_CPR7_REGNUM,
  75.   MT_CPR8_REGNUM,
  76.   MT_CPR9_REGNUM,
  77.   MT_CPR10_REGNUM,
  78.   MT_CPR11_REGNUM,
  79.   MT_CPR12_REGNUM,
  80.   MT_CPR13_REGNUM,
  81.   MT_CPR14_REGNUM,
  82.   MT_CPR15_REGNUM,
  83.   MT_BYPA_REGNUM,                /* 32 bit regs.  */
  84.   MT_BYPB_REGNUM,
  85.   MT_BYPC_REGNUM,
  86.   MT_FLAG_REGNUM,
  87.   MT_CONTEXT_REGNUM,                /* 38 bits (treat as array of
  88.                                    six bytes).  */
  89.   MT_MAC_REGNUM,                        /* 32 bits.  */
  90.   MT_Z1_REGNUM,                        /* 16 bits.  */
  91.   MT_Z2_REGNUM,                        /* 16 bits.  */
  92.   MT_ICHANNEL_REGNUM,                /* 32 bits.  */
  93.   MT_ISCRAMB_REGNUM,                /* 32 bits.  */
  94.   MT_QSCRAMB_REGNUM,                /* 32 bits.  */
  95.   MT_OUT_REGNUM,                        /* 16 bits.  */
  96.   MT_EXMAC_REGNUM,                /* 32 bits (8 used).  */
  97.   MT_QCHANNEL_REGNUM,                /* 32 bits.  */
  98.   MT_ZI2_REGNUM,                /* 16 bits.  */
  99.   MT_ZQ2_REGNUM,                /* 16 bits.  */
  100.   MT_CHANNEL2_REGNUM,           /* 32 bits.  */
  101.   MT_ISCRAMB2_REGNUM,           /* 32 bits.  */
  102.   MT_QSCRAMB2_REGNUM,           /* 32 bits.  */
  103.   MT_QCHANNEL2_REGNUM,          /* 32 bits.  */

  104.   /* Number of real registers.  */
  105.   MT_NUM_REGS,

  106.   /* Pseudo-registers.  */
  107.   MT_COPRO_PSEUDOREG_REGNUM = MT_NUM_REGS,
  108.   MT_MAC_PSEUDOREG_REGNUM,
  109.   MT_COPRO_PSEUDOREG_ARRAY,

  110.   MT_COPRO_PSEUDOREG_DIM_1 = 2,
  111.   MT_COPRO_PSEUDOREG_DIM_2 = 8,
  112.   /* The number of pseudo-registers for each coprocessor.  These
  113.      include the real coprocessor registers, the pseudo-registe for
  114.      the coprocessor number, and the pseudo-register for the MAC.  */
  115.   MT_COPRO_PSEUDOREG_REGS = MT_NUM_REGS - MT_NUM_CPU_REGS + 2,
  116.   /* The register number of the MAC, relative to a given coprocessor.  */
  117.   MT_COPRO_PSEUDOREG_MAC_REGNUM = MT_COPRO_PSEUDOREG_REGS - 1,

  118.   /* Two pseudo-regs ('coprocessor' and 'mac').  */
  119.   MT_NUM_PSEUDO_REGS = 2 + (MT_COPRO_PSEUDOREG_REGS
  120.                             * MT_COPRO_PSEUDOREG_DIM_1
  121.                             * MT_COPRO_PSEUDOREG_DIM_2)
  122. };

  123. /* The tdep structure.  */
  124. struct gdbarch_tdep
  125. {
  126.   /* ISA-specific types.  */
  127.   struct type *copro_type;
  128. };


  129. /* Return name of register number specified by REGNUM.  */

  130. static const char *
  131. mt_register_name (struct gdbarch *gdbarch, int regnum)
  132. {
  133.   static const char *const register_names[] = {
  134.     /* CPU regs.  */
  135.     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  136.     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  137.     "pc", "IE",
  138.     /* Co-processor regs.  */
  139.     "",                                /* copro register.  */
  140.     "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
  141.     "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
  142.     "bypa", "bypb", "bypc", "flag", "context", "" /* mac.  */ , "z1", "z2",
  143.     "Ichannel", "Iscramb", "Qscramb", "out", "" /* ex-mac.  */ , "Qchannel",
  144.     "zi2", "zq2", "Ichannel2", "Iscramb2", "Qscramb2", "Qchannel2",
  145.     /* Pseudo-registers.  */
  146.     "coprocessor", "MAC"
  147.   };
  148.   static const char *array_names[MT_COPRO_PSEUDOREG_REGS
  149.                                  * MT_COPRO_PSEUDOREG_DIM_1
  150.                                  * MT_COPRO_PSEUDOREG_DIM_2];

  151.   if (regnum < 0)
  152.     return "";
  153.   if (regnum < ARRAY_SIZE (register_names))
  154.     return register_names[regnum];
  155.   if (array_names[regnum - MT_COPRO_PSEUDOREG_ARRAY])
  156.     return array_names[regnum - MT_COPRO_PSEUDOREG_ARRAY];

  157.   {
  158.     char *name;
  159.     const char *stub;
  160.     unsigned dim_1;
  161.     unsigned dim_2;
  162.     unsigned index;

  163.     regnum -= MT_COPRO_PSEUDOREG_ARRAY;
  164.     index = regnum % MT_COPRO_PSEUDOREG_REGS;
  165.     dim_2 = (regnum / MT_COPRO_PSEUDOREG_REGS) % MT_COPRO_PSEUDOREG_DIM_2;
  166.     dim_1 = ((regnum / MT_COPRO_PSEUDOREG_REGS / MT_COPRO_PSEUDOREG_DIM_2)
  167.              %  MT_COPRO_PSEUDOREG_DIM_1);

  168.     if (index == MT_COPRO_PSEUDOREG_MAC_REGNUM)
  169.       stub = register_names[MT_MAC_PSEUDOREG_REGNUM];
  170.     else if (index >= MT_NUM_REGS - MT_CPR0_REGNUM)
  171.       stub = "";
  172.     else
  173.       stub = register_names[index + MT_CPR0_REGNUM];
  174.     if (!*stub)
  175.       {
  176.         array_names[regnum] = stub;
  177.         return stub;
  178.       }
  179.     name = xmalloc (30);
  180.     sprintf (name, "copro_%d_%d_%s", dim_1, dim_2, stub);
  181.     array_names[regnum] = name;
  182.     return name;
  183.   }
  184. }

  185. /* Return the type of a coprocessor register.  */

  186. static struct type *
  187. mt_copro_register_type (struct gdbarch *arch, int regnum)
  188. {
  189.   switch (regnum)
  190.     {
  191.     case MT_INT_ENABLE_REGNUM:
  192.     case MT_ICHANNEL_REGNUM:
  193.     case MT_QCHANNEL_REGNUM:
  194.     case MT_ISCRAMB_REGNUM:
  195.     case MT_QSCRAMB_REGNUM:
  196.       return builtin_type (arch)->builtin_int32;
  197.     case MT_BYPA_REGNUM:
  198.     case MT_BYPB_REGNUM:
  199.     case MT_BYPC_REGNUM:
  200.     case MT_Z1_REGNUM:
  201.     case MT_Z2_REGNUM:
  202.     case MT_OUT_REGNUM:
  203.     case MT_ZI2_REGNUM:
  204.     case MT_ZQ2_REGNUM:
  205.       return builtin_type (arch)->builtin_int16;
  206.     case MT_EXMAC_REGNUM:
  207.     case MT_MAC_REGNUM:
  208.       return builtin_type (arch)->builtin_uint32;
  209.     case MT_CONTEXT_REGNUM:
  210.       return builtin_type (arch)->builtin_long_long;
  211.     case MT_FLAG_REGNUM:
  212.       return builtin_type (arch)->builtin_unsigned_char;
  213.     default:
  214.       if (regnum >= MT_CPR0_REGNUM && regnum <= MT_CPR15_REGNUM)
  215.         return builtin_type (arch)->builtin_int16;
  216.       else if (regnum == MT_CPR0_REGNUM + MT_COPRO_PSEUDOREG_MAC_REGNUM)
  217.         {
  218.           if (gdbarch_bfd_arch_info (arch)->mach == bfd_mach_mrisc2
  219.               || gdbarch_bfd_arch_info (arch)->mach == bfd_mach_ms2)
  220.             return builtin_type (arch)->builtin_uint64;
  221.           else
  222.             return builtin_type (arch)->builtin_uint32;
  223.         }
  224.       else
  225.         return builtin_type (arch)->builtin_uint32;
  226.     }
  227. }

  228. /* Given ARCH and a register number specified by REGNUM, return the
  229.    type of that register.  */

  230. static struct type *
  231. mt_register_type (struct gdbarch *arch, int regnum)
  232. {
  233.   struct gdbarch_tdep *tdep = gdbarch_tdep (arch);

  234.   if (regnum >= 0 && regnum < MT_NUM_REGS + MT_NUM_PSEUDO_REGS)
  235.     {
  236.       switch (regnum)
  237.         {
  238.         case MT_PC_REGNUM:
  239.         case MT_RA_REGNUM:
  240.         case MT_IRA_REGNUM:
  241.           return builtin_type (arch)->builtin_func_ptr;
  242.         case MT_SP_REGNUM:
  243.         case MT_FP_REGNUM:
  244.           return builtin_type (arch)->builtin_data_ptr;
  245.         case MT_COPRO_REGNUM:
  246.         case MT_COPRO_PSEUDOREG_REGNUM:
  247.           if (tdep->copro_type == NULL)
  248.             {
  249.               struct type *elt = builtin_type (arch)->builtin_int16;
  250.               tdep->copro_type = lookup_array_range_type (elt, 0, 1);
  251.             }
  252.           return tdep->copro_type;
  253.         case MT_MAC_PSEUDOREG_REGNUM:
  254.           return mt_copro_register_type (arch,
  255.                                          MT_CPR0_REGNUM
  256.                                          + MT_COPRO_PSEUDOREG_MAC_REGNUM);
  257.         default:
  258.           if (regnum >= MT_R0_REGNUM && regnum <= MT_R15_REGNUM)
  259.             return builtin_type (arch)->builtin_int32;
  260.           else if (regnum < MT_COPRO_PSEUDOREG_ARRAY)
  261.             return mt_copro_register_type (arch, regnum);
  262.           else
  263.             {
  264.               regnum -= MT_COPRO_PSEUDOREG_ARRAY;
  265.               regnum %= MT_COPRO_PSEUDOREG_REGS;
  266.               regnum += MT_CPR0_REGNUM;
  267.               return mt_copro_register_type (arch, regnum);
  268.             }
  269.         }
  270.     }
  271.   internal_error (__FILE__, __LINE__,
  272.                   _("mt_register_type: illegal register number %d"), regnum);
  273. }

  274. /* Return true if register REGNUM is a member of the register group
  275.    specified by GROUP.  */

  276. static int
  277. mt_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  278.                          struct reggroup *group)
  279. {
  280.   /* Groups of registers that can be displayed via "info reg".  */
  281.   if (group == all_reggroup)
  282.     return (regnum >= 0
  283.             && regnum < MT_NUM_REGS + MT_NUM_PSEUDO_REGS
  284.             && mt_register_name (gdbarch, regnum)[0] != '\0');

  285.   if (group == general_reggroup)
  286.     return (regnum >= MT_R0_REGNUM && regnum <= MT_R15_REGNUM);

  287.   if (group == float_reggroup)
  288.     return 0;                        /* No float regs.  */

  289.   if (group == vector_reggroup)
  290.     return 0;                        /* No vector regs.  */

  291.   /* For any that are not handled above.  */
  292.   return default_register_reggroup_p (gdbarch, regnum, group);
  293. }

  294. /* Return the return value convention used for a given type TYPE.
  295.    Optionally, fetch or set the return value via READBUF or
  296.    WRITEBUF respectively using REGCACHE for the register
  297.    values.  */

  298. static enum return_value_convention
  299. mt_return_value (struct gdbarch *gdbarch, struct value *function,
  300.                  struct type *type, struct regcache *regcache,
  301.                  gdb_byte *readbuf, const gdb_byte *writebuf)
  302. {
  303.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  304.   if (TYPE_LENGTH (type) > 4)
  305.     {
  306.       /* Return values > 4 bytes are returned in memory,
  307.          pointed to by R11.  */
  308.       if (readbuf)
  309.         {
  310.           ULONGEST addr;

  311.           regcache_cooked_read_unsigned (regcache, MT_R11_REGNUM, &addr);
  312.           read_memory (addr, readbuf, TYPE_LENGTH (type));
  313.         }

  314.       if (writebuf)
  315.         {
  316.           ULONGEST addr;

  317.           regcache_cooked_read_unsigned (regcache, MT_R11_REGNUM, &addr);
  318.           write_memory (addr, writebuf, TYPE_LENGTH (type));
  319.         }

  320.       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
  321.     }
  322.   else
  323.     {
  324.       if (readbuf)
  325.         {
  326.           ULONGEST temp;

  327.           /* Return values of <= 4 bytes are returned in R11.  */
  328.           regcache_cooked_read_unsigned (regcache, MT_R11_REGNUM, &temp);
  329.           store_unsigned_integer (readbuf, TYPE_LENGTH (type),
  330.                                   byte_order, temp);
  331.         }

  332.       if (writebuf)
  333.         {
  334.           if (TYPE_LENGTH (type) < 4)
  335.             {
  336.               gdb_byte buf[4];
  337.               /* Add leading zeros to the value.  */
  338.               memset (buf, 0, sizeof (buf));
  339.               memcpy (buf + sizeof (buf) - TYPE_LENGTH (type),
  340.                       writebuf, TYPE_LENGTH (type));
  341.               regcache_cooked_write (regcache, MT_R11_REGNUM, buf);
  342.             }
  343.           else                        /* (TYPE_LENGTH (type) == 4 */
  344.             regcache_cooked_write (regcache, MT_R11_REGNUM, writebuf);
  345.         }

  346.       return RETURN_VALUE_REGISTER_CONVENTION;
  347.     }
  348. }

  349. /* If the input address, PC, is in a function prologue, return the
  350.    address of the end of the prologue, otherwise return the input
  351.    address.

  352.    Note:  PC is likely to be the function start, since this function
  353.    is mainly used for advancing a breakpoint to the first line, or
  354.    stepping to the first line when we have stepped into a function
  355.    call.  */

  356. static CORE_ADDR
  357. mt_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  358. {
  359.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  360.   CORE_ADDR func_addr = 0, func_end = 0;
  361.   const char *func_name;
  362.   unsigned long instr;

  363.   if (find_pc_partial_function (pc, &func_name, &func_addr, &func_end))
  364.     {
  365.       struct symtab_and_line sal;
  366.       struct symbol *sym;

  367.       /* Found a function.  */
  368.       sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL);
  369.       if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
  370.         {
  371.           /* Don't use this trick for assembly source files.  */
  372.           sal = find_pc_line (func_addr, 0);

  373.           if (sal.end && sal.end < func_end)
  374.             {
  375.               /* Found a line number, use it as end of prologue.  */
  376.               return sal.end;
  377.             }
  378.         }
  379.     }

  380.   /* No function symbol, or no line symbol.  Use prologue scanning method.  */
  381.   for (;; pc += 4)
  382.     {
  383.       instr = read_memory_unsigned_integer (pc, 4, byte_order);
  384.       if (instr == 0x12000000)        /* nop */
  385.         continue;
  386.       if (instr == 0x12ddc000)        /* copy sp into fp */
  387.         continue;
  388.       instr >>= 16;
  389.       if (instr == 0x05dd)        /* subi sp, sp, imm */
  390.         continue;
  391.       if (instr >= 0x43c0 && instr <= 0x43df)        /* push */
  392.         continue;
  393.       /* Not an obvious prologue instruction.  */
  394.       break;
  395.     }

  396.   return pc;
  397. }

  398. /* The breakpoint instruction must be the same size as the smallest
  399.    instruction in the instruction set.

  400.    The BP for ms1 is defined as 0x68000000 (BREAK).
  401.    The BP for ms2 is defined as 0x69000000 (illegal).  */

  402. static const gdb_byte *
  403. mt_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
  404.                        int *bp_size)
  405. {
  406.   static gdb_byte ms1_breakpoint[] = { 0x68, 0, 0, 0 };
  407.   static gdb_byte ms2_breakpoint[] = { 0x69, 0, 0, 0 };

  408.   *bp_size = 4;
  409.   if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_ms2)
  410.     return ms2_breakpoint;

  411.   return ms1_breakpoint;
  412. }

  413. /* Select the correct coprocessor register bank.  Return the pseudo
  414.    regnum we really want to read.  */

  415. static int
  416. mt_select_coprocessor (struct gdbarch *gdbarch,
  417.                         struct regcache *regcache, int regno)
  418. {
  419.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  420.   unsigned index, base;
  421.   gdb_byte copro[4];

  422.   /* Get the copro pseudo regnum.  */
  423.   regcache_raw_read (regcache, MT_COPRO_REGNUM, copro);
  424.   base = ((extract_signed_integer (&copro[0], 2, byte_order)
  425.            * MT_COPRO_PSEUDOREG_DIM_2)
  426.           + extract_signed_integer (&copro[2], 2, byte_order));

  427.   regno -= MT_COPRO_PSEUDOREG_ARRAY;
  428.   index = regno % MT_COPRO_PSEUDOREG_REGS;
  429.   regno /= MT_COPRO_PSEUDOREG_REGS;
  430.   if (base != regno)
  431.     {
  432.       /* Select the correct coprocessor register bank.  Invalidate the
  433.          coprocessor register cache.  */
  434.       unsigned ix;

  435.       store_signed_integer (&copro[0], 2, byte_order,
  436.                             regno / MT_COPRO_PSEUDOREG_DIM_2);
  437.       store_signed_integer (&copro[2], 2, byte_order,
  438.                             regno % MT_COPRO_PSEUDOREG_DIM_2);
  439.       regcache_raw_write (regcache, MT_COPRO_REGNUM, copro);

  440.       /* We must flush the cache, as it is now invalid.  */
  441.       for (ix = MT_NUM_CPU_REGS; ix != MT_NUM_REGS; ix++)
  442.         regcache_invalidate (regcache, ix);
  443.     }

  444.   return index;
  445. }

  446. /* Fetch the pseudo registers:

  447.    There are two regular pseudo-registers:
  448.    1) The 'coprocessor' pseudo-register (which mirrors the
  449.    "real" coprocessor register sent by the target), and
  450.    2) The 'MAC' pseudo-register (which represents the union
  451.    of the original 32 bit target MAC register and the new
  452.    8-bit extended-MAC register).

  453.    Additionally there is an array of coprocessor registers which track
  454.    the coprocessor registers for each coprocessor.  */

  455. static enum register_status
  456. mt_pseudo_register_read (struct gdbarch *gdbarch,
  457.                          struct regcache *regcache, int regno, gdb_byte *buf)
  458. {
  459.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  460.   switch (regno)
  461.     {
  462.     case MT_COPRO_REGNUM:
  463.     case MT_COPRO_PSEUDOREG_REGNUM:
  464.       return regcache_raw_read (regcache, MT_COPRO_REGNUM, buf);
  465.     case MT_MAC_REGNUM:
  466.     case MT_MAC_PSEUDOREG_REGNUM:
  467.       if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_mrisc2
  468.           || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_ms2)
  469.         {
  470.           enum register_status status;
  471.           ULONGEST oldmac = 0, ext_mac = 0;
  472.           ULONGEST newmac;

  473.           status = regcache_cooked_read_unsigned (regcache, MT_MAC_REGNUM, &oldmac);
  474.           if (status != REG_VALID)
  475.             return status;

  476.           regcache_cooked_read_unsigned (regcache, MT_EXMAC_REGNUM, &ext_mac);
  477.           if (status != REG_VALID)
  478.             return status;

  479.           newmac =
  480.             (oldmac & 0xffffffff) | ((long long) (ext_mac & 0xff) << 32);
  481.           store_signed_integer (buf, 8, byte_order, newmac);

  482.           return REG_VALID;
  483.         }
  484.       else
  485.         return regcache_raw_read (regcache, MT_MAC_REGNUM, buf);
  486.       break;
  487.     default:
  488.       {
  489.         unsigned index = mt_select_coprocessor (gdbarch, regcache, regno);

  490.         if (index == MT_COPRO_PSEUDOREG_MAC_REGNUM)
  491.           return mt_pseudo_register_read (gdbarch, regcache,
  492.                                           MT_MAC_PSEUDOREG_REGNUM, buf);
  493.         else if (index < MT_NUM_REGS - MT_CPR0_REGNUM)
  494.           return regcache_raw_read (regcache, index + MT_CPR0_REGNUM, buf);
  495.         else
  496.           /* ??? */
  497.           return REG_VALID;
  498.       }
  499.       break;
  500.     }
  501. }

  502. /* Write the pseudo registers:

  503.    Mt pseudo-registers are stored directly to the target.  The
  504.    'coprocessor' register is special, because when it is modified, all
  505.    the other coprocessor regs must be flushed from the reg cache.  */

  506. static void
  507. mt_pseudo_register_write (struct gdbarch *gdbarch,
  508.                            struct regcache *regcache,
  509.                            int regno, const gdb_byte *buf)
  510. {
  511.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  512.   int i;

  513.   switch (regno)
  514.     {
  515.     case MT_COPRO_REGNUM:
  516.     case MT_COPRO_PSEUDOREG_REGNUM:
  517.       regcache_raw_write (regcache, MT_COPRO_REGNUM, buf);
  518.       for (i = MT_NUM_CPU_REGS; i < MT_NUM_REGS; i++)
  519.         regcache_invalidate (regcache, i);
  520.       break;
  521.     case MT_MAC_REGNUM:
  522.     case MT_MAC_PSEUDOREG_REGNUM:
  523.       if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_mrisc2
  524.           || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_ms2)
  525.         {
  526.           /* The 8-byte MAC pseudo-register must be broken down into two
  527.              32-byte registers.  */
  528.           unsigned int oldmac, ext_mac;
  529.           ULONGEST newmac;

  530.           newmac = extract_unsigned_integer (buf, 8, byte_order);
  531.           oldmac = newmac & 0xffffffff;
  532.           ext_mac = (newmac >> 32) & 0xff;
  533.           regcache_cooked_write_unsigned (regcache, MT_MAC_REGNUM, oldmac);
  534.           regcache_cooked_write_unsigned (regcache, MT_EXMAC_REGNUM, ext_mac);
  535.         }
  536.       else
  537.         regcache_raw_write (regcache, MT_MAC_REGNUM, buf);
  538.       break;
  539.     default:
  540.       {
  541.         unsigned index = mt_select_coprocessor (gdbarch, regcache, regno);

  542.         if (index == MT_COPRO_PSEUDOREG_MAC_REGNUM)
  543.           mt_pseudo_register_write (gdbarch, regcache,
  544.                                     MT_MAC_PSEUDOREG_REGNUM, buf);
  545.         else if (index < MT_NUM_REGS - MT_CPR0_REGNUM)
  546.           regcache_raw_write (regcache, index + MT_CPR0_REGNUM, buf);
  547.       }
  548.       break;
  549.     }
  550. }

  551. static CORE_ADDR
  552. mt_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
  553. {
  554.   /* Register size is 4 bytes.  */
  555.   return align_down (sp, 4);
  556. }

  557. /* Implements the "info registers" command.   When ``all'' is non-zero,
  558.    the coprocessor registers will be printed in addition to the rest
  559.    of the registers.  */

  560. static void
  561. mt_registers_info (struct gdbarch *gdbarch,
  562.                    struct ui_file *file,
  563.                    struct frame_info *frame, int regnum, int all)
  564. {
  565.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  566.   if (regnum == -1)
  567.     {
  568.       int lim;

  569.       lim = all ? MT_NUM_REGS : MT_NUM_CPU_REGS;

  570.       for (regnum = 0; regnum < lim; regnum++)
  571.         {
  572.           /* Don't display the Qchannel register since it will be displayed
  573.              along with Ichannel.  (See below.)  */
  574.           if (regnum == MT_QCHANNEL_REGNUM)
  575.             continue;

  576.           mt_registers_info (gdbarch, file, frame, regnum, all);

  577.           /* Display the Qchannel register immediately after Ichannel.  */
  578.           if (regnum == MT_ICHANNEL_REGNUM)
  579.             mt_registers_info (gdbarch, file, frame, MT_QCHANNEL_REGNUM, all);
  580.         }
  581.     }
  582.   else
  583.     {
  584.       if (regnum == MT_EXMAC_REGNUM)
  585.         return;
  586.       else if (regnum == MT_CONTEXT_REGNUM)
  587.         {
  588.           /* Special output handling for 38-bit context register.  */
  589.           unsigned char *buff;
  590.           unsigned int *bytes, i, regsize;

  591.           regsize = register_size (gdbarch, regnum);

  592.           buff = alloca (regsize);
  593.           bytes = alloca (regsize * sizeof (*bytes));

  594.           deprecated_frame_register_read (frame, regnum, buff);

  595.           fputs_filtered (gdbarch_register_name
  596.                           (gdbarch, regnum), file);
  597.           print_spaces_filtered (15 - strlen (gdbarch_register_name
  598.                                                 (gdbarch, regnum)),
  599.                                  file);
  600.           fputs_filtered ("0x", file);

  601.           for (i = 0; i < regsize; i++)
  602.             fprintf_filtered (file, "%02x", (unsigned int)
  603.                               extract_unsigned_integer (buff + i, 1, byte_order));
  604.           fputs_filtered ("\t", file);
  605.           print_longest (file, 'd', 0,
  606.                          extract_unsigned_integer (buff, regsize, byte_order));
  607.           fputs_filtered ("\n", file);
  608.         }
  609.       else if (regnum == MT_COPRO_REGNUM
  610.                || regnum == MT_COPRO_PSEUDOREG_REGNUM)
  611.         {
  612.           /* Special output handling for the 'coprocessor' register.  */
  613.           gdb_byte *buf;
  614.           struct value_print_options opts;

  615.           buf = alloca (register_size (gdbarch, MT_COPRO_REGNUM));
  616.           deprecated_frame_register_read (frame, MT_COPRO_REGNUM, buf);
  617.           /* And print.  */
  618.           regnum = MT_COPRO_PSEUDOREG_REGNUM;
  619.           fputs_filtered (gdbarch_register_name (gdbarch, regnum),
  620.                           file);
  621.           print_spaces_filtered (15 - strlen (gdbarch_register_name
  622.                                                 (gdbarch, regnum)),
  623.                                  file);
  624.           get_no_prettyformat_print_options (&opts);
  625.           opts.deref_ref = 1;
  626.           val_print (register_type (gdbarch, regnum), buf,
  627.                      0, 0, file, 0, NULL,
  628.                      &opts, current_language);
  629.           fputs_filtered ("\n", file);
  630.         }
  631.       else if (regnum == MT_MAC_REGNUM || regnum == MT_MAC_PSEUDOREG_REGNUM)
  632.         {
  633.           ULONGEST oldmac, ext_mac, newmac;
  634.           gdb_byte buf[3 * sizeof (LONGEST)];

  635.           /* Get the two "real" mac registers.  */
  636.           deprecated_frame_register_read (frame, MT_MAC_REGNUM, buf);
  637.           oldmac = extract_unsigned_integer
  638.             (buf, register_size (gdbarch, MT_MAC_REGNUM), byte_order);
  639.           if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_mrisc2
  640.               || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_ms2)
  641.             {
  642.               deprecated_frame_register_read (frame, MT_EXMAC_REGNUM, buf);
  643.               ext_mac = extract_unsigned_integer
  644.                 (buf, register_size (gdbarch, MT_EXMAC_REGNUM), byte_order);
  645.             }
  646.           else
  647.             ext_mac = 0;

  648.           /* Add them together.  */
  649.           newmac = (oldmac & 0xffffffff) + ((ext_mac & 0xff) << 32);

  650.           /* And print.  */
  651.           regnum = MT_MAC_PSEUDOREG_REGNUM;
  652.           fputs_filtered (gdbarch_register_name (gdbarch, regnum),
  653.                           file);
  654.           print_spaces_filtered (15 - strlen (gdbarch_register_name
  655.                                               (gdbarch, regnum)),
  656.                                  file);
  657.           fputs_filtered ("0x", file);
  658.           print_longest (file, 'x', 0, newmac);
  659.           fputs_filtered ("\t", file);
  660.           print_longest (file, 'u', 0, newmac);
  661.           fputs_filtered ("\n", file);
  662.         }
  663.       else
  664.         default_print_registers_info (gdbarch, file, frame, regnum, all);
  665.     }
  666. }

  667. /* Set up the callee's arguments for an inferior function call.  The
  668.    arguments are pushed on the stack or are placed in registers as
  669.    appropriate.  It also sets up the return address (which points to
  670.    the call dummy breakpoint).

  671.    Returns the updated (and aligned) stack pointer.  */

  672. static CORE_ADDR
  673. mt_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  674.                      struct regcache *regcache, CORE_ADDR bp_addr,
  675.                      int nargs, struct value **args, CORE_ADDR sp,
  676.                      int struct_return, CORE_ADDR struct_addr)
  677. {
  678. #define wordsize 4
  679.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  680.   gdb_byte buf[MT_MAX_STRUCT_SIZE];
  681.   int argreg = MT_1ST_ARGREG;
  682.   int split_param_len = 0;
  683.   int stack_dest = sp;
  684.   int slacklen;
  685.   int typelen;
  686.   int i, j;

  687.   /* First handle however many args we can fit into MT_1ST_ARGREG thru
  688.      MT_LAST_ARGREG.  */
  689.   for (i = 0; i < nargs && argreg <= MT_LAST_ARGREG; i++)
  690.     {
  691.       const gdb_byte *val;
  692.       typelen = TYPE_LENGTH (value_type (args[i]));
  693.       switch (typelen)
  694.         {
  695.         case 1:
  696.         case 2:
  697.         case 3:
  698.         case 4:
  699.           regcache_cooked_write_unsigned (regcache, argreg++,
  700.                                           extract_unsigned_integer
  701.                                           (value_contents (args[i]),
  702.                                            wordsize, byte_order));
  703.           break;
  704.         case 8:
  705.         case 12:
  706.         case 16:
  707.           val = value_contents (args[i]);
  708.           while (typelen > 0)
  709.             {
  710.               if (argreg <= MT_LAST_ARGREG)
  711.                 {
  712.                   /* This word of the argument is passed in a register.  */
  713.                   regcache_cooked_write_unsigned (regcache, argreg++,
  714.                                                   extract_unsigned_integer
  715.                                                   (val, wordsize, byte_order));
  716.                   typelen -= wordsize;
  717.                   val += wordsize;
  718.                 }
  719.               else
  720.                 {
  721.                   /* Remainder of this arg must be passed on the stack
  722.                      (deferred to do later).  */
  723.                   split_param_len = typelen;
  724.                   memcpy (buf, val, typelen);
  725.                   break;        /* No more args can be handled in regs.  */
  726.                 }
  727.             }
  728.           break;
  729.         default:
  730.           /* By reverse engineering of gcc output, args bigger than
  731.              16 bytes go on the stack, and their address is passed
  732.              in the argreg.  */
  733.           stack_dest -= typelen;
  734.           write_memory (stack_dest, value_contents (args[i]), typelen);
  735.           regcache_cooked_write_unsigned (regcache, argreg++, stack_dest);
  736.           break;
  737.         }
  738.     }

  739.   /* Next, the rest of the arguments go onto the stack, in reverse order.  */
  740.   for (j = nargs - 1; j >= i; j--)
  741.     {
  742.       gdb_byte *val;
  743.       struct cleanup *back_to;
  744.       const gdb_byte *contents = value_contents (args[j]);

  745.       /* Right-justify the value in an aligned-length buffer.  */
  746.       typelen = TYPE_LENGTH (value_type (args[j]));
  747.       slacklen = (wordsize - (typelen % wordsize)) % wordsize;
  748.       val = xmalloc (typelen + slacklen);
  749.       back_to = make_cleanup (xfree, val);
  750.       memcpy (val, contents, typelen);
  751.       memset (val + typelen, 0, slacklen);
  752.       /* Now write this data to the stack.  */
  753.       stack_dest -= typelen + slacklen;
  754.       write_memory (stack_dest, val, typelen + slacklen);
  755.       do_cleanups (back_to);
  756.     }

  757.   /* Finally, if a param needs to be split between registers and stack,
  758.      write the second half to the stack now.  */
  759.   if (split_param_len != 0)
  760.     {
  761.       stack_dest -= split_param_len;
  762.       write_memory (stack_dest, buf, split_param_len);
  763.     }

  764.   /* Set up return address (provided to us as bp_addr).  */
  765.   regcache_cooked_write_unsigned (regcache, MT_RA_REGNUM, bp_addr);

  766.   /* Store struct return address, if given.  */
  767.   if (struct_return && struct_addr != 0)
  768.     regcache_cooked_write_unsigned (regcache, MT_R11_REGNUM, struct_addr);

  769.   /* Set aside 16 bytes for the callee to save regs 1-4.  */
  770.   stack_dest -= 16;

  771.   /* Update the stack pointer.  */
  772.   regcache_cooked_write_unsigned (regcache, MT_SP_REGNUM, stack_dest);

  773.   /* And that should do it.  Return the new stack pointer.  */
  774.   return stack_dest;
  775. }


  776. /* The 'unwind_cache' data structure.  */

  777. struct mt_unwind_cache
  778. {
  779.   /* The previous frame's inner most stack address.
  780.      Used as this frame ID's stack_addr.  */
  781.   CORE_ADDR prev_sp;
  782.   CORE_ADDR frame_base;
  783.   int framesize;
  784.   int frameless_p;

  785.   /* Table indicating the location of each and every register.  */
  786.   struct trad_frame_saved_reg *saved_regs;
  787. };

  788. /* Initialize an unwind_cache.  Build up the saved_regs table etc. for
  789.    the frame.  */

  790. static struct mt_unwind_cache *
  791. mt_frame_unwind_cache (struct frame_info *this_frame,
  792.                         void **this_prologue_cache)
  793. {
  794.   struct gdbarch *gdbarch;
  795.   struct mt_unwind_cache *info;
  796.   CORE_ADDR next_addr, start_addr, end_addr, prologue_end_addr;
  797.   unsigned long instr, upper_half, delayed_store = 0;
  798.   int regnum, offset;
  799.   ULONGEST sp, fp;

  800.   if ((*this_prologue_cache))
  801.     return (*this_prologue_cache);

  802.   gdbarch = get_frame_arch (this_frame);
  803.   info = FRAME_OBSTACK_ZALLOC (struct mt_unwind_cache);
  804.   (*this_prologue_cache) = info;

  805.   info->prev_sp = 0;
  806.   info->framesize = 0;
  807.   info->frame_base = 0;
  808.   info->frameless_p = 1;
  809.   info->saved_regs = trad_frame_alloc_saved_regs (this_frame);

  810.   /* Grab the frame-relative values of SP and FP, needed below.
  811.      The frame_saved_register function will find them on the
  812.      stack or in the registers as appropriate.  */
  813.   sp = get_frame_register_unsigned (this_frame, MT_SP_REGNUM);
  814.   fp = get_frame_register_unsigned (this_frame, MT_FP_REGNUM);

  815.   start_addr = get_frame_func (this_frame);

  816.   /* Return early if GDB couldn't find the function.  */
  817.   if (start_addr == 0)
  818.     return info;

  819.   end_addr = get_frame_pc (this_frame);
  820.   prologue_end_addr = skip_prologue_using_sal (gdbarch, start_addr);
  821.   if (end_addr == 0)
  822.   for (next_addr = start_addr; next_addr < end_addr; next_addr += 4)
  823.     {
  824.       instr = get_frame_memory_unsigned (this_frame, next_addr, 4);
  825.       if (delayed_store)        /* Previous instr was a push.  */
  826.         {
  827.           upper_half = delayed_store >> 16;
  828.           regnum = upper_half & 0xf;
  829.           offset = delayed_store & 0xffff;
  830.           switch (upper_half & 0xfff0)
  831.             {
  832.             case 0x43c0:        /* push using frame pointer.  */
  833.               info->saved_regs[regnum].addr = offset;
  834.               break;
  835.             case 0x43d0:        /* push using stack pointer.  */
  836.               info->saved_regs[regnum].addr = offset;
  837.               break;
  838.             default:                /* lint */
  839.               break;
  840.             }
  841.           delayed_store = 0;
  842.         }

  843.       switch (instr)
  844.         {
  845.         case 0x12000000:        /* NO-OP */
  846.           continue;
  847.         case 0x12ddc000:        /* copy sp into fp */
  848.           info->frameless_p = 0;        /* Record that the frame
  849.                                            pointer is in use.  */
  850.           continue;
  851.         default:
  852.           upper_half = instr >> 16;
  853.           if (upper_half == 0x05dd ||        /* subi  sp, sp, imm */
  854.               upper_half == 0x07dd)        /* subui sp, sp, imm */
  855.             {
  856.               /* Record the frame size.  */
  857.               info->framesize = instr & 0xffff;
  858.               continue;
  859.             }
  860.           if ((upper_half & 0xfff0) == 0x43c0 ||        /* frame push */
  861.               (upper_half & 0xfff0) == 0x43d0)        /* stack push */
  862.             {
  863.               /* Save this instruction, but don't record the
  864.                  pushed register as 'saved' until we see the
  865.                  next instruction.  That's because of deferred stores
  866.                  on this target -- GDB won't be able to read the register
  867.                  from the stack until one instruction later.  */
  868.               delayed_store = instr;
  869.               continue;
  870.             }
  871.           /* Not a prologue instruction.  Is this the end of the prologue?
  872.              This is the most difficult decision; when to stop scanning.

  873.              If we have no line symbol, then the best thing we can do
  874.              is to stop scanning when we encounter an instruction that
  875.              is not likely to be a part of the prologue.

  876.              But if we do have a line symbol, then we should
  877.              keep scanning until we reach it (or we reach end_addr).  */

  878.           if (prologue_end_addr && (prologue_end_addr > (next_addr + 4)))
  879.             continue;        /* Keep scanning, recording saved_regs etc.  */
  880.           else
  881.             break;        /* Quit scanning: breakpoint can be set here.  */
  882.         }
  883.     }

  884.   /* Special handling for the "saved" address of the SP:
  885.      The SP is of course never saved on the stack at all, so
  886.      by convention what we put here is simply the previous
  887.      _value_ of the SP (as opposed to an address where the
  888.      previous value would have been pushed).  This will also
  889.      give us the frame base address.  */

  890.   if (info->frameless_p)
  891.     {
  892.       info->frame_base = sp + info->framesize;
  893.       info->prev_sp = sp + info->framesize;
  894.     }
  895.   else
  896.     {
  897.       info->frame_base = fp + info->framesize;
  898.       info->prev_sp = fp + info->framesize;
  899.     }
  900.   /* Save prev_sp in saved_regs as a value, not as an address.  */
  901.   trad_frame_set_value (info->saved_regs, MT_SP_REGNUM, info->prev_sp);

  902.   /* Now convert frame offsets to actual addresses (not offsets).  */
  903.   for (regnum = 0; regnum < MT_NUM_REGS; regnum++)
  904.     if (trad_frame_addr_p (info->saved_regs, regnum))
  905.       info->saved_regs[regnum].addr += info->frame_base - info->framesize;

  906.   /* The call instruction moves the caller's PC in the callee's RA reg.
  907.      Since this is an unwind, do the reverse.  Copy the location of RA
  908.      into PC (the address / regnum) so that a request for PC will be
  909.      converted into a request for the RA.  */
  910.   info->saved_regs[MT_PC_REGNUM] = info->saved_regs[MT_RA_REGNUM];

  911.   return info;
  912. }

  913. static CORE_ADDR
  914. mt_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  915. {
  916.   ULONGEST pc;

  917.   pc = frame_unwind_register_unsigned (next_frame, MT_PC_REGNUM);
  918.   return pc;
  919. }

  920. static CORE_ADDR
  921. mt_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
  922. {
  923.   ULONGEST sp;

  924.   sp = frame_unwind_register_unsigned (next_frame, MT_SP_REGNUM);
  925.   return sp;
  926. }

  927. /* Assuming THIS_FRAME is a dummy, return the frame ID of that dummy
  928.    frame.  The frame ID's base needs to match the TOS value saved by
  929.    save_dummy_frame_tos(), and the PC match the dummy frame's breakpoint.  */

  930. static struct frame_id
  931. mt_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  932. {
  933.   CORE_ADDR sp = get_frame_register_unsigned (this_frame, MT_SP_REGNUM);
  934.   return frame_id_build (sp, get_frame_pc (this_frame));
  935. }

  936. /* Given a GDB frame, determine the address of the calling function's
  937.    frame.  This will be used to create a new GDB frame struct.  */

  938. static void
  939. mt_frame_this_id (struct frame_info *this_frame,
  940.                    void **this_prologue_cache, struct frame_id *this_id)
  941. {
  942.   struct mt_unwind_cache *info =
  943.     mt_frame_unwind_cache (this_frame, this_prologue_cache);

  944.   if (!(info == NULL || info->prev_sp == 0))
  945.     (*this_id) = frame_id_build (info->prev_sp, get_frame_func (this_frame));

  946.   return;
  947. }

  948. static struct value *
  949. mt_frame_prev_register (struct frame_info *this_frame,
  950.                          void **this_prologue_cache, int regnum)
  951. {
  952.   struct mt_unwind_cache *info =
  953.     mt_frame_unwind_cache (this_frame, this_prologue_cache);

  954.   return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  955. }

  956. static CORE_ADDR
  957. mt_frame_base_address (struct frame_info *this_frame,
  958.                         void **this_prologue_cache)
  959. {
  960.   struct mt_unwind_cache *info =
  961.     mt_frame_unwind_cache (this_frame, this_prologue_cache);

  962.   return info->frame_base;
  963. }

  964. /* This is a shared interface:  the 'frame_unwind' object is what's
  965.    returned by the 'sniffer' function, and in turn specifies how to
  966.    get a frame's ID and prev_regs.

  967.    This exports the 'prev_register' and 'this_id' methods.  */

  968. static const struct frame_unwind mt_frame_unwind = {
  969.   NORMAL_FRAME,
  970.   default_frame_unwind_stop_reason,
  971.   mt_frame_this_id,
  972.   mt_frame_prev_register,
  973.   NULL,
  974.   default_frame_sniffer
  975. };

  976. /* Another shared interface:  the 'frame_base' object specifies how to
  977.    unwind a frame and secure the base addresses for frame objects
  978.    (locals, args).  */

  979. static struct frame_base mt_frame_base = {
  980.   &mt_frame_unwind,
  981.   mt_frame_base_address,
  982.   mt_frame_base_address,
  983.   mt_frame_base_address
  984. };

  985. static struct gdbarch *
  986. mt_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  987. {
  988.   struct gdbarch *gdbarch;
  989.   struct gdbarch_tdep *tdep;

  990.   /* Find a candidate among the list of pre-declared architectures.  */
  991.   arches = gdbarch_list_lookup_by_info (arches, &info);
  992.   if (arches != NULL)
  993.     return arches->gdbarch;

  994.   /* None found, create a new architecture from the information
  995.      provided.  */
  996.   tdep = XCNEW (struct gdbarch_tdep);
  997.   gdbarch = gdbarch_alloc (&info, tdep);

  998.   set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
  999.   set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
  1000.   set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);

  1001.   set_gdbarch_register_name (gdbarch, mt_register_name);
  1002.   set_gdbarch_num_regs (gdbarch, MT_NUM_REGS);
  1003.   set_gdbarch_num_pseudo_regs (gdbarch, MT_NUM_PSEUDO_REGS);
  1004.   set_gdbarch_pc_regnum (gdbarch, MT_PC_REGNUM);
  1005.   set_gdbarch_sp_regnum (gdbarch, MT_SP_REGNUM);
  1006.   set_gdbarch_pseudo_register_read (gdbarch, mt_pseudo_register_read);
  1007.   set_gdbarch_pseudo_register_write (gdbarch, mt_pseudo_register_write);
  1008.   set_gdbarch_skip_prologue (gdbarch, mt_skip_prologue);
  1009.   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  1010.   set_gdbarch_breakpoint_from_pc (gdbarch, mt_breakpoint_from_pc);
  1011.   set_gdbarch_decr_pc_after_break (gdbarch, 0);
  1012.   set_gdbarch_frame_args_skip (gdbarch, 0);
  1013.   set_gdbarch_print_insn (gdbarch, print_insn_mt);
  1014.   set_gdbarch_register_type (gdbarch, mt_register_type);
  1015.   set_gdbarch_register_reggroup_p (gdbarch, mt_register_reggroup_p);

  1016.   set_gdbarch_return_value (gdbarch, mt_return_value);
  1017.   set_gdbarch_sp_regnum (gdbarch, MT_SP_REGNUM);

  1018.   set_gdbarch_frame_align (gdbarch, mt_frame_align);

  1019.   set_gdbarch_print_registers_info (gdbarch, mt_registers_info);

  1020.   set_gdbarch_push_dummy_call (gdbarch, mt_push_dummy_call);

  1021.   /* Target builtin data types.  */
  1022.   set_gdbarch_short_bit (gdbarch, 16);
  1023.   set_gdbarch_int_bit (gdbarch, 32);
  1024.   set_gdbarch_long_bit (gdbarch, 32);
  1025.   set_gdbarch_long_long_bit (gdbarch, 64);
  1026.   set_gdbarch_float_bit (gdbarch, 32);
  1027.   set_gdbarch_double_bit (gdbarch, 64);
  1028.   set_gdbarch_long_double_bit (gdbarch, 64);
  1029.   set_gdbarch_ptr_bit (gdbarch, 32);

  1030.   /* Register the DWARF 2 sniffer first, and then the traditional prologue
  1031.      based sniffer.  */
  1032.   dwarf2_append_unwinders (gdbarch);
  1033.   frame_unwind_append_unwinder (gdbarch, &mt_frame_unwind);
  1034.   frame_base_set_default (gdbarch, &mt_frame_base);

  1035.   /* Register the 'unwind_pc' method.  */
  1036.   set_gdbarch_unwind_pc (gdbarch, mt_unwind_pc);
  1037.   set_gdbarch_unwind_sp (gdbarch, mt_unwind_sp);

  1038.   /* Methods for saving / extracting a dummy frame's ID.
  1039.      The ID's stack address must match the SP value returned by
  1040.      PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos.  */
  1041.   set_gdbarch_dummy_id (gdbarch, mt_dummy_id);

  1042.   return gdbarch;
  1043. }

  1044. /* Provide a prototype to silence -Wmissing-prototypes.  */
  1045. extern initialize_file_ftype _initialize_mt_tdep;

  1046. void
  1047. _initialize_mt_tdep (void)
  1048. {
  1049.   register_gdbarch_init (bfd_arch_mt, mt_gdbarch_init);
  1050. }