Home | History | Annotate | Line # | Download | only in gdb
      1   1.1  christos /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
      2   1.1  christos 
      3  1.11  christos    Copyright (C) 1996-2024 Free Software Foundation, Inc.
      4   1.1  christos 
      5   1.1  christos    This file is part of GDB.
      6   1.1  christos 
      7   1.1  christos    This program is free software; you can redistribute it and/or modify
      8   1.1  christos    it under the terms of the GNU General Public License as published by
      9   1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10   1.1  christos    (at your option) any later version.
     11   1.1  christos 
     12   1.1  christos    This program is distributed in the hope that it will be useful,
     13   1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15   1.1  christos    GNU General Public License for more details.
     16   1.1  christos 
     17   1.1  christos    You should have received a copy of the GNU General Public License
     18   1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19   1.1  christos 
     20   1.1  christos #include "arch-utils.h"
     21   1.1  christos #include "dis-asm.h"
     22  1.11  christos #include "extract-store-integer.h"
     23   1.1  christos #include "gdbtypes.h"
     24   1.1  christos #include "regcache.h"
     25  1.11  christos #include "gdbcore.h"
     26   1.1  christos #include "value.h"
     27   1.1  christos #include "frame.h"
     28   1.1  christos #include "frame-unwind.h"
     29   1.1  christos #include "frame-base.h"
     30   1.1  christos #include "symtab.h"
     31   1.9  christos #include "dwarf2/frame.h"
     32   1.1  christos #include "osabi.h"
     33   1.1  christos #include "infcall.h"
     34   1.1  christos #include "prologue-value.h"
     35   1.1  christos #include "target.h"
     36   1.1  christos 
     37   1.1  christos #include "mn10300-tdep.h"
     38   1.1  christos 
     39   1.1  christos 
     40   1.1  christos /* The am33-2 has 64 registers.  */
     41   1.1  christos #define MN10300_MAX_NUM_REGS 64
     42   1.1  christos 
     43   1.8  christos /* Big enough to hold the size of the largest register in bytes.  */
     44   1.8  christos #define MN10300_MAX_REGISTER_SIZE      64
     45   1.8  christos 
     46   1.1  christos /* This structure holds the results of a prologue analysis.  */
     47   1.1  christos struct mn10300_prologue
     48   1.1  christos {
     49   1.1  christos   /* The architecture for which we generated this prologue info.  */
     50   1.1  christos   struct gdbarch *gdbarch;
     51   1.1  christos 
     52   1.1  christos   /* The offset from the frame base to the stack pointer --- always
     53   1.1  christos      zero or negative.
     54   1.1  christos 
     55   1.1  christos      Calling this a "size" is a bit misleading, but given that the
     56   1.1  christos      stack grows downwards, using offsets for everything keeps one
     57   1.1  christos      from going completely sign-crazy: you never change anything's
     58   1.1  christos      sign for an ADD instruction; always change the second operand's
     59   1.1  christos      sign for a SUB instruction; and everything takes care of
     60   1.1  christos      itself.  */
     61   1.1  christos   int frame_size;
     62   1.1  christos 
     63   1.1  christos   /* Non-zero if this function has initialized the frame pointer from
     64   1.1  christos      the stack pointer, zero otherwise.  */
     65   1.1  christos   int has_frame_ptr;
     66   1.1  christos 
     67   1.1  christos   /* If has_frame_ptr is non-zero, this is the offset from the frame
     68   1.1  christos      base to where the frame pointer points.  This is always zero or
     69   1.1  christos      negative.  */
     70   1.1  christos   int frame_ptr_offset;
     71   1.1  christos 
     72   1.1  christos   /* The address of the first instruction at which the frame has been
     73   1.1  christos      set up and the arguments are where the debug info says they are
     74   1.1  christos      --- as best as we can tell.  */
     75   1.1  christos   CORE_ADDR prologue_end;
     76   1.1  christos 
     77   1.1  christos   /* reg_offset[R] is the offset from the CFA at which register R is
     78   1.1  christos      saved, or 1 if register R has not been saved.  (Real values are
     79   1.1  christos      always zero or negative.)  */
     80   1.1  christos   int reg_offset[MN10300_MAX_NUM_REGS];
     81   1.1  christos };
     82   1.1  christos 
     83   1.1  christos 
     84   1.1  christos /* Compute the alignment required by a type.  */
     85   1.1  christos 
     86   1.1  christos static int
     87   1.1  christos mn10300_type_align (struct type *type)
     88   1.1  christos {
     89   1.1  christos   int i, align = 1;
     90   1.1  christos 
     91   1.9  christos   switch (type->code ())
     92   1.1  christos     {
     93   1.1  christos     case TYPE_CODE_INT:
     94   1.1  christos     case TYPE_CODE_ENUM:
     95   1.1  christos     case TYPE_CODE_SET:
     96   1.1  christos     case TYPE_CODE_RANGE:
     97   1.1  christos     case TYPE_CODE_CHAR:
     98   1.1  christos     case TYPE_CODE_BOOL:
     99   1.1  christos     case TYPE_CODE_FLT:
    100   1.1  christos     case TYPE_CODE_PTR:
    101   1.1  christos     case TYPE_CODE_REF:
    102   1.7  christos     case TYPE_CODE_RVALUE_REF:
    103  1.10  christos       return type->length ();
    104   1.1  christos 
    105   1.1  christos     case TYPE_CODE_COMPLEX:
    106  1.10  christos       return type->length () / 2;
    107   1.1  christos 
    108   1.1  christos     case TYPE_CODE_STRUCT:
    109   1.1  christos     case TYPE_CODE_UNION:
    110   1.9  christos       for (i = 0; i < type->num_fields (); i++)
    111   1.1  christos 	{
    112   1.9  christos 	  int falign = mn10300_type_align (type->field (i).type ());
    113   1.1  christos 	  while (align < falign)
    114   1.1  christos 	    align <<= 1;
    115   1.1  christos 	}
    116   1.1  christos       return align;
    117   1.1  christos 
    118   1.1  christos     case TYPE_CODE_ARRAY:
    119   1.1  christos       /* HACK!  Structures containing arrays, even small ones, are not
    120   1.9  christos 	 eligible for returning in registers.  */
    121   1.1  christos       return 256;
    122   1.1  christos 
    123   1.1  christos     case TYPE_CODE_TYPEDEF:
    124   1.1  christos       return mn10300_type_align (check_typedef (type));
    125   1.1  christos 
    126   1.1  christos     default:
    127  1.10  christos       internal_error (_("bad switch"));
    128   1.1  christos     }
    129   1.1  christos }
    130   1.1  christos 
    131   1.1  christos /* Should call_function allocate stack space for a struct return?  */
    132   1.1  christos static int
    133   1.1  christos mn10300_use_struct_convention (struct type *type)
    134   1.1  christos {
    135   1.1  christos   /* Structures bigger than a pair of words can't be returned in
    136   1.1  christos      registers.  */
    137  1.10  christos   if (type->length () > 8)
    138   1.1  christos     return 1;
    139   1.1  christos 
    140   1.9  christos   switch (type->code ())
    141   1.1  christos     {
    142   1.1  christos     case TYPE_CODE_STRUCT:
    143   1.1  christos     case TYPE_CODE_UNION:
    144   1.1  christos       /* Structures with a single field are handled as the field
    145   1.1  christos 	 itself.  */
    146   1.9  christos       if (type->num_fields () == 1)
    147   1.9  christos 	return mn10300_use_struct_convention (type->field (0).type ());
    148   1.1  christos 
    149   1.1  christos       /* Structures with word or double-word size are passed in memory, as
    150   1.1  christos 	 long as they require at least word alignment.  */
    151   1.1  christos       if (mn10300_type_align (type) >= 4)
    152   1.1  christos 	return 0;
    153   1.1  christos 
    154   1.1  christos       return 1;
    155   1.1  christos 
    156   1.1  christos       /* Arrays are addressable, so they're never returned in
    157   1.1  christos 	 registers.  This condition can only hold when the array is
    158   1.1  christos 	 the only field of a struct or union.  */
    159   1.1  christos     case TYPE_CODE_ARRAY:
    160   1.1  christos       return 1;
    161   1.1  christos 
    162   1.1  christos     case TYPE_CODE_TYPEDEF:
    163   1.1  christos       return mn10300_use_struct_convention (check_typedef (type));
    164   1.1  christos 
    165   1.1  christos     default:
    166   1.1  christos       return 0;
    167   1.1  christos     }
    168   1.1  christos }
    169   1.1  christos 
    170   1.1  christos static void
    171   1.1  christos mn10300_store_return_value (struct gdbarch *gdbarch, struct type *type,
    172   1.1  christos 			    struct regcache *regcache, const gdb_byte *valbuf)
    173   1.1  christos {
    174  1.10  christos   int len = type->length ();
    175   1.1  christos   int reg, regsz;
    176   1.1  christos 
    177   1.9  christos   if (type->code () == TYPE_CODE_PTR)
    178   1.1  christos     reg = 4;
    179   1.1  christos   else
    180   1.1  christos     reg = 0;
    181   1.1  christos 
    182   1.1  christos   regsz = register_size (gdbarch, reg);
    183   1.1  christos 
    184   1.1  christos   if (len <= regsz)
    185   1.8  christos     regcache->raw_write_part (reg, 0, len, valbuf);
    186   1.1  christos   else if (len <= 2 * regsz)
    187   1.1  christos     {
    188   1.8  christos       regcache->raw_write (reg, valbuf);
    189   1.1  christos       gdb_assert (regsz == register_size (gdbarch, reg + 1));
    190   1.8  christos       regcache->raw_write_part (reg + 1, 0, len - regsz, valbuf + regsz);
    191   1.1  christos     }
    192   1.1  christos   else
    193  1.10  christos     internal_error (_("Cannot store return value %d bytes long."), len);
    194   1.1  christos }
    195   1.1  christos 
    196   1.1  christos static void
    197   1.1  christos mn10300_extract_return_value (struct gdbarch *gdbarch, struct type *type,
    198   1.1  christos 			      struct regcache *regcache, void *valbuf)
    199   1.1  christos {
    200   1.8  christos   gdb_byte buf[MN10300_MAX_REGISTER_SIZE];
    201  1.10  christos   int len = type->length ();
    202   1.1  christos   int reg, regsz;
    203   1.1  christos 
    204   1.9  christos   if (type->code () == TYPE_CODE_PTR)
    205   1.1  christos     reg = 4;
    206   1.1  christos   else
    207   1.1  christos     reg = 0;
    208   1.1  christos 
    209   1.1  christos   regsz = register_size (gdbarch, reg);
    210   1.8  christos   gdb_assert (regsz <= MN10300_MAX_REGISTER_SIZE);
    211   1.1  christos   if (len <= regsz)
    212   1.1  christos     {
    213   1.8  christos       regcache->raw_read (reg, buf);
    214   1.1  christos       memcpy (valbuf, buf, len);
    215   1.1  christos     }
    216   1.1  christos   else if (len <= 2 * regsz)
    217   1.1  christos     {
    218   1.8  christos       regcache->raw_read (reg, buf);
    219   1.1  christos       memcpy (valbuf, buf, regsz);
    220   1.1  christos       gdb_assert (regsz == register_size (gdbarch, reg + 1));
    221   1.8  christos       regcache->raw_read (reg + 1, buf);
    222   1.1  christos       memcpy ((char *) valbuf + regsz, buf, len - regsz);
    223   1.1  christos     }
    224   1.1  christos   else
    225  1.10  christos     internal_error (_("Cannot extract return value %d bytes long."), len);
    226   1.1  christos }
    227   1.1  christos 
    228   1.1  christos /* Determine, for architecture GDBARCH, how a return value of TYPE
    229   1.1  christos    should be returned.  If it is supposed to be returned in registers,
    230   1.1  christos    and READBUF is non-zero, read the appropriate value from REGCACHE,
    231   1.1  christos    and copy it into READBUF.  If WRITEBUF is non-zero, write the value
    232   1.1  christos    from WRITEBUF into REGCACHE.  */
    233   1.1  christos 
    234   1.1  christos static enum return_value_convention
    235   1.1  christos mn10300_return_value (struct gdbarch *gdbarch, struct value *function,
    236   1.1  christos 		      struct type *type, struct regcache *regcache,
    237   1.1  christos 		      gdb_byte *readbuf, const gdb_byte *writebuf)
    238   1.1  christos {
    239   1.1  christos   if (mn10300_use_struct_convention (type))
    240   1.1  christos     return RETURN_VALUE_STRUCT_CONVENTION;
    241   1.1  christos 
    242   1.1  christos   if (readbuf)
    243   1.1  christos     mn10300_extract_return_value (gdbarch, type, regcache, readbuf);
    244   1.1  christos   if (writebuf)
    245   1.1  christos     mn10300_store_return_value (gdbarch, type, regcache, writebuf);
    246   1.1  christos 
    247   1.1  christos   return RETURN_VALUE_REGISTER_CONVENTION;
    248   1.1  christos }
    249   1.1  christos 
    250   1.7  christos static const char *
    251  1.10  christos register_name (int reg, const char **regs, long num_regs)
    252   1.1  christos {
    253  1.10  christos   gdb_assert (reg < num_regs);
    254  1.10  christos   return regs[reg];
    255   1.1  christos }
    256   1.1  christos 
    257   1.1  christos static const char *
    258   1.1  christos mn10300_generic_register_name (struct gdbarch *gdbarch, int reg)
    259   1.1  christos {
    260   1.7  christos   static const char *regs[] =
    261   1.1  christos   { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
    262   1.1  christos     "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
    263   1.1  christos     "", "", "", "", "", "", "", "",
    264   1.1  christos     "", "", "", "", "", "", "", "fp"
    265   1.1  christos   };
    266  1.10  christos   return register_name (reg, regs, ARRAY_SIZE (regs));
    267   1.1  christos }
    268   1.1  christos 
    269   1.1  christos 
    270   1.1  christos static const char *
    271   1.1  christos am33_register_name (struct gdbarch *gdbarch, int reg)
    272   1.1  christos {
    273   1.7  christos   static const char *regs[] =
    274   1.1  christos   { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
    275   1.1  christos     "sp", "pc", "mdr", "psw", "lir", "lar", "",
    276   1.1  christos     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
    277   1.1  christos     "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", ""
    278   1.1  christos   };
    279  1.10  christos   return register_name (reg, regs, ARRAY_SIZE (regs));
    280   1.1  christos }
    281   1.1  christos 
    282   1.1  christos static const char *
    283   1.1  christos am33_2_register_name (struct gdbarch *gdbarch, int reg)
    284   1.1  christos {
    285   1.7  christos   static const char *regs[] =
    286   1.1  christos   {
    287   1.1  christos     "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
    288   1.1  christos     "sp", "pc", "mdr", "psw", "lir", "lar", "mdrq", "r0",
    289   1.1  christos     "r1", "r2", "r3", "r4", "r5", "r6", "r7", "ssp",
    290   1.1  christos     "msp", "usp", "mcrh", "mcrl", "mcvf", "fpcr", "", "",
    291   1.1  christos     "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
    292   1.1  christos     "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15",
    293   1.1  christos     "fs16", "fs17", "fs18", "fs19", "fs20", "fs21", "fs22", "fs23",
    294   1.1  christos     "fs24", "fs25", "fs26", "fs27", "fs28", "fs29", "fs30", "fs31"
    295   1.1  christos   };
    296  1.10  christos   return register_name (reg, regs, ARRAY_SIZE (regs));
    297   1.1  christos }
    298   1.1  christos 
    299   1.1  christos static struct type *
    300   1.1  christos mn10300_register_type (struct gdbarch *gdbarch, int reg)
    301   1.1  christos {
    302   1.1  christos   return builtin_type (gdbarch)->builtin_int;
    303   1.1  christos }
    304   1.1  christos 
    305   1.1  christos /* The breakpoint instruction must be the same size as the smallest
    306   1.1  christos    instruction in the instruction set.
    307   1.1  christos 
    308   1.1  christos    The Matsushita mn10x00 processors have single byte instructions
    309   1.1  christos    so we need a single byte breakpoint.  Matsushita hasn't defined
    310   1.1  christos    one, so we defined it ourselves.  */
    311   1.7  christos constexpr gdb_byte mn10300_break_insn[] = {0xff};
    312   1.1  christos 
    313   1.7  christos typedef BP_MANIPULATION (mn10300_break_insn) mn10300_breakpoint;
    314   1.1  christos 
    315   1.1  christos /* Model the semantics of pushing a register onto the stack.  This
    316   1.1  christos    is a helper function for mn10300_analyze_prologue, below.  */
    317   1.1  christos static void
    318   1.1  christos push_reg (pv_t *regs, struct pv_area *stack, int regnum)
    319   1.1  christos {
    320   1.1  christos   regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], -4);
    321   1.8  christos   stack->store (regs[E_SP_REGNUM], 4, regs[regnum]);
    322   1.1  christos }
    323   1.1  christos 
    324   1.1  christos /* Translate an "r" register number extracted from an instruction encoding
    325   1.1  christos    into a GDB register number.  Adapted from a simulator function
    326   1.1  christos    of the same name; see am33.igen.  */
    327   1.1  christos static int
    328   1.1  christos translate_rreg (int rreg)
    329   1.1  christos {
    330   1.1  christos  /* The higher register numbers actually correspond to the
    331   1.1  christos      basic machine's address and data registers.  */
    332   1.1  christos   if (rreg > 7 && rreg < 12)
    333   1.1  christos     return E_A0_REGNUM + rreg - 8;
    334   1.1  christos   else if (rreg > 11 && rreg < 16)
    335   1.1  christos     return E_D0_REGNUM + rreg - 12;
    336   1.1  christos   else
    337   1.1  christos     return E_E0_REGNUM + rreg;
    338   1.1  christos }
    339   1.1  christos 
    340   1.8  christos /* Find saved registers in a 'struct pv_area'; we pass this to pv_area::scan.
    341   1.1  christos 
    342   1.1  christos    If VALUE is a saved register, ADDR says it was saved at a constant
    343   1.1  christos    offset from the frame base, and SIZE indicates that the whole
    344   1.1  christos    register was saved, record its offset in RESULT_UNTYPED.  */
    345   1.1  christos static void
    346   1.1  christos check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value)
    347   1.1  christos {
    348   1.1  christos   struct mn10300_prologue *result = (struct mn10300_prologue *) result_untyped;
    349   1.1  christos 
    350   1.1  christos   if (value.kind == pvk_register
    351   1.1  christos       && value.k == 0
    352   1.1  christos       && pv_is_register (addr, E_SP_REGNUM)
    353   1.1  christos       && size == register_size (result->gdbarch, value.reg))
    354   1.1  christos     result->reg_offset[value.reg] = addr.k;
    355   1.1  christos }
    356   1.1  christos 
    357   1.1  christos /* Analyze the prologue to determine where registers are saved,
    358   1.1  christos    the end of the prologue, etc.  The result of this analysis is
    359   1.1  christos    returned in RESULT.  See struct mn10300_prologue above for more
    360   1.1  christos    information.  */
    361   1.1  christos static void
    362   1.1  christos mn10300_analyze_prologue (struct gdbarch *gdbarch,
    363  1.10  christos 			  CORE_ADDR start_pc, CORE_ADDR limit_pc,
    364  1.10  christos 			  struct mn10300_prologue *result)
    365   1.1  christos {
    366   1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    367   1.1  christos   CORE_ADDR pc;
    368   1.1  christos   int rn;
    369   1.1  christos   pv_t regs[MN10300_MAX_NUM_REGS];
    370   1.1  christos   CORE_ADDR after_last_frame_setup_insn = start_pc;
    371  1.10  christos   int am33_mode = get_am33_mode (gdbarch);
    372   1.1  christos 
    373   1.1  christos   memset (result, 0, sizeof (*result));
    374   1.1  christos   result->gdbarch = gdbarch;
    375   1.1  christos 
    376   1.1  christos   for (rn = 0; rn < MN10300_MAX_NUM_REGS; rn++)
    377   1.1  christos     {
    378   1.1  christos       regs[rn] = pv_register (rn, 0);
    379   1.1  christos       result->reg_offset[rn] = 1;
    380   1.1  christos     }
    381   1.8  christos   pv_area stack (E_SP_REGNUM, gdbarch_addr_bit (gdbarch));
    382   1.1  christos 
    383   1.8  christos   /* The typical call instruction will have saved the return address on the
    384   1.8  christos      stack.  Space for the return address has already been preallocated in
    385   1.8  christos      the caller's frame.  It's possible, such as when using -mrelax with gcc
    386   1.8  christos      that other registers were saved as well.  If this happens, we really
    387   1.8  christos      have no chance of deciphering the frame.  DWARF info can save the day
    388   1.8  christos      when this happens.  */
    389   1.8  christos   stack.store (regs[E_SP_REGNUM], 4, regs[E_PC_REGNUM]);
    390   1.1  christos 
    391   1.1  christos   pc = start_pc;
    392   1.1  christos   while (pc < limit_pc)
    393   1.1  christos     {
    394   1.1  christos       int status;
    395   1.1  christos       gdb_byte instr[2];
    396   1.1  christos 
    397   1.1  christos       /* Instructions can be as small as one byte; however, we usually
    398  1.10  christos 	 need at least two bytes to do the decoding, so fetch that many
    399   1.1  christos 	 to begin with.  */
    400   1.1  christos       status = target_read_memory (pc, instr, 2);
    401   1.1  christos       if (status != 0)
    402   1.1  christos 	break;
    403   1.1  christos 
    404   1.1  christos       /* movm [regs], sp  */
    405   1.1  christos       if (instr[0] == 0xcf)
    406   1.1  christos 	{
    407   1.1  christos 	  gdb_byte save_mask;
    408   1.1  christos 
    409   1.1  christos 	  save_mask = instr[1];
    410   1.1  christos 
    411   1.1  christos 	  if ((save_mask & movm_exreg0_bit) && am33_mode)
    412   1.1  christos 	    {
    413   1.8  christos 	      push_reg (regs, &stack, E_E2_REGNUM);
    414   1.8  christos 	      push_reg (regs, &stack, E_E3_REGNUM);
    415   1.1  christos 	    }
    416   1.1  christos 	  if ((save_mask & movm_exreg1_bit) && am33_mode)
    417   1.1  christos 	    {
    418   1.8  christos 	      push_reg (regs, &stack, E_E4_REGNUM);
    419   1.8  christos 	      push_reg (regs, &stack, E_E5_REGNUM);
    420   1.8  christos 	      push_reg (regs, &stack, E_E6_REGNUM);
    421   1.8  christos 	      push_reg (regs, &stack, E_E7_REGNUM);
    422   1.1  christos 	    }
    423   1.1  christos 	  if ((save_mask & movm_exother_bit) && am33_mode)
    424   1.1  christos 	    {
    425   1.8  christos 	      push_reg (regs, &stack, E_E0_REGNUM);
    426   1.8  christos 	      push_reg (regs, &stack, E_E1_REGNUM);
    427   1.8  christos 	      push_reg (regs, &stack, E_MDRQ_REGNUM);
    428   1.8  christos 	      push_reg (regs, &stack, E_MCRH_REGNUM);
    429   1.8  christos 	      push_reg (regs, &stack, E_MCRL_REGNUM);
    430   1.8  christos 	      push_reg (regs, &stack, E_MCVF_REGNUM);
    431   1.1  christos 	    }
    432   1.1  christos 	  if (save_mask & movm_d2_bit)
    433   1.8  christos 	    push_reg (regs, &stack, E_D2_REGNUM);
    434   1.1  christos 	  if (save_mask & movm_d3_bit)
    435   1.8  christos 	    push_reg (regs, &stack, E_D3_REGNUM);
    436   1.1  christos 	  if (save_mask & movm_a2_bit)
    437   1.8  christos 	    push_reg (regs, &stack, E_A2_REGNUM);
    438   1.1  christos 	  if (save_mask & movm_a3_bit)
    439   1.8  christos 	    push_reg (regs, &stack, E_A3_REGNUM);
    440   1.1  christos 	  if (save_mask & movm_other_bit)
    441   1.1  christos 	    {
    442   1.8  christos 	      push_reg (regs, &stack, E_D0_REGNUM);
    443   1.8  christos 	      push_reg (regs, &stack, E_D1_REGNUM);
    444   1.8  christos 	      push_reg (regs, &stack, E_A0_REGNUM);
    445   1.8  christos 	      push_reg (regs, &stack, E_A1_REGNUM);
    446   1.8  christos 	      push_reg (regs, &stack, E_MDR_REGNUM);
    447   1.8  christos 	      push_reg (regs, &stack, E_LIR_REGNUM);
    448   1.8  christos 	      push_reg (regs, &stack, E_LAR_REGNUM);
    449   1.1  christos 	      /* The `other' bit leaves a blank area of four bytes at
    450   1.1  christos 		 the beginning of its block of saved registers, making
    451   1.1  christos 		 it 32 bytes long in total.  */
    452   1.1  christos 	      regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], -4);
    453   1.1  christos 	    }
    454   1.1  christos 
    455   1.1  christos 	  pc += 2;
    456   1.1  christos 	  after_last_frame_setup_insn = pc;
    457   1.1  christos 	}
    458   1.1  christos       /* mov sp, aN */
    459   1.1  christos       else if ((instr[0] & 0xfc) == 0x3c)
    460   1.1  christos 	{
    461   1.1  christos 	  int aN = instr[0] & 0x03;
    462   1.1  christos 
    463   1.1  christos 	  regs[E_A0_REGNUM + aN] = regs[E_SP_REGNUM];
    464   1.1  christos 
    465   1.1  christos 	  pc += 1;
    466   1.1  christos 	  if (aN == 3)
    467   1.1  christos 	    after_last_frame_setup_insn = pc;
    468   1.1  christos 	}
    469   1.1  christos       /* mov aM, aN */
    470   1.1  christos       else if ((instr[0] & 0xf0) == 0x90
    471  1.10  christos 	       && (instr[0] & 0x03) != ((instr[0] & 0x0c) >> 2))
    472   1.1  christos 	{
    473   1.1  christos 	  int aN = instr[0] & 0x03;
    474   1.1  christos 	  int aM = (instr[0] & 0x0c) >> 2;
    475   1.1  christos 
    476   1.1  christos 	  regs[E_A0_REGNUM + aN] = regs[E_A0_REGNUM + aM];
    477   1.1  christos 
    478   1.1  christos 	  pc += 1;
    479   1.1  christos 	}
    480   1.1  christos       /* mov dM, dN */
    481   1.1  christos       else if ((instr[0] & 0xf0) == 0x80
    482  1.10  christos 	       && (instr[0] & 0x03) != ((instr[0] & 0x0c) >> 2))
    483   1.1  christos 	{
    484   1.1  christos 	  int dN = instr[0] & 0x03;
    485   1.1  christos 	  int dM = (instr[0] & 0x0c) >> 2;
    486   1.1  christos 
    487   1.1  christos 	  regs[E_D0_REGNUM + dN] = regs[E_D0_REGNUM + dM];
    488   1.1  christos 
    489   1.1  christos 	  pc += 1;
    490   1.1  christos 	}
    491   1.1  christos       /* mov aM, dN */
    492   1.1  christos       else if (instr[0] == 0xf1 && (instr[1] & 0xf0) == 0xd0)
    493   1.1  christos 	{
    494   1.1  christos 	  int dN = instr[1] & 0x03;
    495   1.1  christos 	  int aM = (instr[1] & 0x0c) >> 2;
    496   1.1  christos 
    497   1.1  christos 	  regs[E_D0_REGNUM + dN] = regs[E_A0_REGNUM + aM];
    498   1.1  christos 
    499   1.1  christos 	  pc += 2;
    500   1.1  christos 	}
    501   1.1  christos       /* mov dM, aN */
    502   1.1  christos       else if (instr[0] == 0xf1 && (instr[1] & 0xf0) == 0xe0)
    503   1.1  christos 	{
    504   1.1  christos 	  int aN = instr[1] & 0x03;
    505   1.1  christos 	  int dM = (instr[1] & 0x0c) >> 2;
    506   1.1  christos 
    507   1.1  christos 	  regs[E_A0_REGNUM + aN] = regs[E_D0_REGNUM + dM];
    508   1.1  christos 
    509   1.1  christos 	  pc += 2;
    510   1.1  christos 	}
    511   1.1  christos       /* add imm8, SP */
    512   1.1  christos       else if (instr[0] == 0xf8 && instr[1] == 0xfe)
    513   1.1  christos 	{
    514   1.1  christos 	  gdb_byte buf[1];
    515   1.1  christos 	  LONGEST imm8;
    516   1.1  christos 
    517   1.1  christos 
    518   1.1  christos 	  status = target_read_memory (pc + 2, buf, 1);
    519   1.1  christos 	  if (status != 0)
    520   1.1  christos 	    break;
    521   1.1  christos 
    522   1.1  christos 	  imm8 = extract_signed_integer (buf, 1, byte_order);
    523   1.1  christos 	  regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], imm8);
    524   1.1  christos 
    525   1.1  christos 	  pc += 3;
    526   1.1  christos 	  /* Stack pointer adjustments are frame related.  */
    527   1.1  christos 	  after_last_frame_setup_insn = pc;
    528   1.1  christos 	}
    529   1.1  christos       /* add imm16, SP */
    530   1.1  christos       else if (instr[0] == 0xfa && instr[1] == 0xfe)
    531   1.1  christos 	{
    532   1.1  christos 	  gdb_byte buf[2];
    533   1.1  christos 	  LONGEST imm16;
    534   1.1  christos 
    535   1.1  christos 	  status = target_read_memory (pc + 2, buf, 2);
    536   1.1  christos 	  if (status != 0)
    537   1.1  christos 	    break;
    538   1.1  christos 
    539   1.1  christos 	  imm16 = extract_signed_integer (buf, 2, byte_order);
    540   1.1  christos 	  regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], imm16);
    541   1.1  christos 
    542   1.1  christos 	  pc += 4;
    543   1.1  christos 	  /* Stack pointer adjustments are frame related.  */
    544   1.1  christos 	  after_last_frame_setup_insn = pc;
    545   1.1  christos 	}
    546   1.1  christos       /* add imm32, SP */
    547   1.1  christos       else if (instr[0] == 0xfc && instr[1] == 0xfe)
    548   1.1  christos 	{
    549   1.1  christos 	  gdb_byte buf[4];
    550   1.1  christos 	  LONGEST imm32;
    551   1.1  christos 
    552   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    553   1.1  christos 	  if (status != 0)
    554   1.1  christos 	    break;
    555   1.1  christos 
    556   1.1  christos 
    557   1.1  christos 	  imm32 = extract_signed_integer (buf, 4, byte_order);
    558   1.1  christos 	  regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], imm32);
    559   1.1  christos 
    560   1.1  christos 	  pc += 6;
    561   1.1  christos 	  /* Stack pointer adjustments are frame related.  */
    562   1.1  christos 	  after_last_frame_setup_insn = pc;
    563   1.1  christos 	}
    564   1.1  christos       /* add imm8, aN  */
    565   1.1  christos       else if ((instr[0] & 0xfc) == 0x20)
    566   1.1  christos 	{
    567   1.1  christos 	  int aN;
    568   1.1  christos 	  LONGEST imm8;
    569   1.1  christos 
    570   1.1  christos 	  aN = instr[0] & 0x03;
    571   1.1  christos 	  imm8 = extract_signed_integer (&instr[1], 1, byte_order);
    572   1.1  christos 
    573   1.1  christos 	  regs[E_A0_REGNUM + aN] = pv_add_constant (regs[E_A0_REGNUM + aN],
    574  1.10  christos 						    imm8);
    575   1.1  christos 
    576   1.1  christos 	  pc += 2;
    577   1.1  christos 	}
    578   1.1  christos       /* add imm16, aN  */
    579   1.1  christos       else if (instr[0] == 0xfa && (instr[1] & 0xfc) == 0xd0)
    580   1.1  christos 	{
    581   1.1  christos 	  int aN;
    582   1.1  christos 	  LONGEST imm16;
    583   1.1  christos 	  gdb_byte buf[2];
    584   1.1  christos 
    585   1.1  christos 	  aN = instr[1] & 0x03;
    586   1.1  christos 
    587   1.1  christos 	  status = target_read_memory (pc + 2, buf, 2);
    588   1.1  christos 	  if (status != 0)
    589   1.1  christos 	    break;
    590   1.1  christos 
    591   1.1  christos 
    592   1.1  christos 	  imm16 = extract_signed_integer (buf, 2, byte_order);
    593   1.1  christos 
    594   1.1  christos 	  regs[E_A0_REGNUM + aN] = pv_add_constant (regs[E_A0_REGNUM + aN],
    595  1.10  christos 						    imm16);
    596   1.1  christos 
    597   1.1  christos 	  pc += 4;
    598   1.1  christos 	}
    599   1.1  christos       /* add imm32, aN  */
    600   1.1  christos       else if (instr[0] == 0xfc && (instr[1] & 0xfc) == 0xd0)
    601   1.1  christos 	{
    602   1.1  christos 	  int aN;
    603   1.1  christos 	  LONGEST imm32;
    604   1.1  christos 	  gdb_byte buf[4];
    605   1.1  christos 
    606   1.1  christos 	  aN = instr[1] & 0x03;
    607   1.1  christos 
    608   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    609   1.1  christos 	  if (status != 0)
    610   1.1  christos 	    break;
    611   1.1  christos 
    612   1.1  christos 	  imm32 = extract_signed_integer (buf, 2, byte_order);
    613   1.1  christos 
    614   1.1  christos 	  regs[E_A0_REGNUM + aN] = pv_add_constant (regs[E_A0_REGNUM + aN],
    615  1.10  christos 						    imm32);
    616   1.1  christos 	  pc += 6;
    617   1.1  christos 	}
    618   1.1  christos       /* fmov fsM, (rN) */
    619   1.1  christos       else if (instr[0] == 0xf9 && (instr[1] & 0xfd) == 0x30)
    620   1.1  christos 	{
    621   1.1  christos 	  int fsM, sM, Y, rN;
    622   1.1  christos 	  gdb_byte buf[1];
    623   1.1  christos 
    624   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    625   1.1  christos 
    626   1.1  christos 	  status = target_read_memory (pc + 2, buf, 1);
    627   1.1  christos 	  if (status != 0)
    628   1.1  christos 	    break;
    629   1.1  christos 
    630   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    631   1.1  christos 	  rN = buf[0] & 0x0f;
    632   1.1  christos 	  fsM = (Y << 4) | sM;
    633   1.1  christos 
    634   1.8  christos 	  stack.store (regs[translate_rreg (rN)], 4,
    635   1.8  christos 		       regs[E_FS0_REGNUM + fsM]);
    636   1.1  christos 
    637   1.1  christos 	  pc += 3;
    638   1.1  christos 	}
    639   1.1  christos       /* fmov fsM, (sp) */
    640   1.1  christos       else if (instr[0] == 0xf9 && (instr[1] & 0xfd) == 0x34)
    641   1.1  christos 	{
    642   1.1  christos 	  int fsM, sM, Y;
    643   1.1  christos 	  gdb_byte buf[1];
    644   1.1  christos 
    645   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    646   1.1  christos 
    647   1.1  christos 	  status = target_read_memory (pc + 2, buf, 1);
    648   1.1  christos 	  if (status != 0)
    649   1.1  christos 	    break;
    650   1.1  christos 
    651   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    652   1.1  christos 	  fsM = (Y << 4) | sM;
    653   1.1  christos 
    654   1.8  christos 	  stack.store (regs[E_SP_REGNUM], 4,
    655   1.8  christos 		       regs[E_FS0_REGNUM + fsM]);
    656   1.1  christos 
    657   1.1  christos 	  pc += 3;
    658   1.1  christos 	}
    659   1.1  christos       /* fmov fsM, (rN, rI) */
    660   1.1  christos       else if (instr[0] == 0xfb && instr[1] == 0x37)
    661   1.1  christos 	{
    662   1.1  christos 	  int fsM, sM, Z, rN, rI;
    663   1.1  christos 	  gdb_byte buf[2];
    664   1.1  christos 
    665   1.1  christos 
    666   1.1  christos 	  status = target_read_memory (pc + 2, buf, 2);
    667   1.1  christos 	  if (status != 0)
    668   1.1  christos 	    break;
    669   1.1  christos 
    670   1.1  christos 	  rI = (buf[0] & 0xf0) >> 4;
    671   1.1  christos 	  rN = buf[0] & 0x0f;
    672   1.1  christos 	  sM = (buf[1] & 0xf0) >> 4;
    673   1.1  christos 	  Z = (buf[1] & 0x02) >> 1;
    674   1.1  christos 	  fsM = (Z << 4) | sM;
    675   1.1  christos 
    676   1.8  christos 	  stack.store (pv_add (regs[translate_rreg (rN)],
    677   1.8  christos 			       regs[translate_rreg (rI)]),
    678   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    679   1.1  christos 
    680   1.1  christos 	  pc += 4;
    681   1.1  christos 	}
    682   1.1  christos       /* fmov fsM, (d8, rN) */
    683   1.1  christos       else if (instr[0] == 0xfb && (instr[1] & 0xfd) == 0x30)
    684   1.1  christos 	{
    685   1.1  christos 	  int fsM, sM, Y, rN;
    686   1.1  christos 	  LONGEST d8;
    687   1.1  christos 	  gdb_byte buf[2];
    688   1.1  christos 
    689   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    690   1.1  christos 
    691   1.1  christos 	  status = target_read_memory (pc + 2, buf, 2);
    692   1.1  christos 	  if (status != 0)
    693   1.1  christos 	    break;
    694   1.1  christos 
    695   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    696   1.1  christos 	  rN = buf[0] & 0x0f;
    697   1.1  christos 	  fsM = (Y << 4) | sM;
    698   1.1  christos 	  d8 = extract_signed_integer (&buf[1], 1, byte_order);
    699   1.1  christos 
    700   1.8  christos 	  stack.store (pv_add_constant (regs[translate_rreg (rN)], d8),
    701   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    702   1.1  christos 
    703   1.1  christos 	  pc += 4;
    704   1.1  christos 	}
    705   1.1  christos       /* fmov fsM, (d24, rN) */
    706   1.1  christos       else if (instr[0] == 0xfd && (instr[1] & 0xfd) == 0x30)
    707   1.1  christos 	{
    708   1.1  christos 	  int fsM, sM, Y, rN;
    709   1.1  christos 	  LONGEST d24;
    710   1.1  christos 	  gdb_byte buf[4];
    711   1.1  christos 
    712   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    713   1.1  christos 
    714   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    715   1.1  christos 	  if (status != 0)
    716   1.1  christos 	    break;
    717   1.1  christos 
    718   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    719   1.1  christos 	  rN = buf[0] & 0x0f;
    720   1.1  christos 	  fsM = (Y << 4) | sM;
    721   1.1  christos 	  d24 = extract_signed_integer (&buf[1], 3, byte_order);
    722   1.1  christos 
    723   1.8  christos 	  stack.store (pv_add_constant (regs[translate_rreg (rN)], d24),
    724   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    725   1.1  christos 
    726   1.1  christos 	  pc += 6;
    727   1.1  christos 	}
    728   1.1  christos       /* fmov fsM, (d32, rN) */
    729   1.1  christos       else if (instr[0] == 0xfe && (instr[1] & 0xfd) == 0x30)
    730   1.1  christos 	{
    731   1.1  christos 	  int fsM, sM, Y, rN;
    732   1.1  christos 	  LONGEST d32;
    733   1.1  christos 	  gdb_byte buf[5];
    734   1.1  christos 
    735   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    736   1.1  christos 
    737   1.1  christos 	  status = target_read_memory (pc + 2, buf, 5);
    738   1.1  christos 	  if (status != 0)
    739   1.1  christos 	    break;
    740   1.1  christos 
    741   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    742   1.1  christos 	  rN = buf[0] & 0x0f;
    743   1.1  christos 	  fsM = (Y << 4) | sM;
    744   1.1  christos 	  d32 = extract_signed_integer (&buf[1], 4, byte_order);
    745   1.1  christos 
    746   1.8  christos 	  stack.store (pv_add_constant (regs[translate_rreg (rN)], d32),
    747   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    748   1.1  christos 
    749   1.1  christos 	  pc += 7;
    750   1.1  christos 	}
    751   1.1  christos       /* fmov fsM, (d8, SP) */
    752   1.1  christos       else if (instr[0] == 0xfb && (instr[1] & 0xfd) == 0x34)
    753   1.1  christos 	{
    754   1.1  christos 	  int fsM, sM, Y;
    755   1.1  christos 	  LONGEST d8;
    756   1.1  christos 	  gdb_byte buf[2];
    757   1.1  christos 
    758   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    759   1.1  christos 
    760   1.1  christos 	  status = target_read_memory (pc + 2, buf, 2);
    761   1.1  christos 	  if (status != 0)
    762   1.1  christos 	    break;
    763   1.1  christos 
    764   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    765   1.1  christos 	  fsM = (Y << 4) | sM;
    766   1.1  christos 	  d8 = extract_signed_integer (&buf[1], 1, byte_order);
    767   1.1  christos 
    768   1.8  christos 	  stack.store (pv_add_constant (regs[E_SP_REGNUM], d8),
    769   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    770   1.1  christos 
    771   1.1  christos 	  pc += 4;
    772   1.1  christos 	}
    773   1.1  christos       /* fmov fsM, (d24, SP) */
    774   1.1  christos       else if (instr[0] == 0xfd && (instr[1] & 0xfd) == 0x34)
    775   1.1  christos 	{
    776   1.1  christos 	  int fsM, sM, Y;
    777   1.1  christos 	  LONGEST d24;
    778   1.1  christos 	  gdb_byte buf[4];
    779   1.1  christos 
    780   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    781   1.1  christos 
    782   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    783   1.1  christos 	  if (status != 0)
    784   1.1  christos 	    break;
    785   1.1  christos 
    786   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    787   1.1  christos 	  fsM = (Y << 4) | sM;
    788   1.1  christos 	  d24 = extract_signed_integer (&buf[1], 3, byte_order);
    789   1.1  christos 
    790   1.8  christos 	  stack.store (pv_add_constant (regs[E_SP_REGNUM], d24),
    791   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    792   1.1  christos 
    793   1.1  christos 	  pc += 6;
    794   1.1  christos 	}
    795   1.1  christos       /* fmov fsM, (d32, SP) */
    796   1.1  christos       else if (instr[0] == 0xfe && (instr[1] & 0xfd) == 0x34)
    797   1.1  christos 	{
    798   1.1  christos 	  int fsM, sM, Y;
    799   1.1  christos 	  LONGEST d32;
    800   1.1  christos 	  gdb_byte buf[5];
    801   1.1  christos 
    802   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    803   1.1  christos 
    804   1.1  christos 	  status = target_read_memory (pc + 2, buf, 5);
    805   1.1  christos 	  if (status != 0)
    806   1.1  christos 	    break;
    807   1.1  christos 
    808   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    809   1.1  christos 	  fsM = (Y << 4) | sM;
    810   1.1  christos 	  d32 = extract_signed_integer (&buf[1], 4, byte_order);
    811   1.1  christos 
    812   1.8  christos 	  stack.store (pv_add_constant (regs[E_SP_REGNUM], d32),
    813   1.8  christos 		       4, regs[E_FS0_REGNUM + fsM]);
    814   1.1  christos 
    815   1.1  christos 	  pc += 7;
    816   1.1  christos 	}
    817   1.1  christos       /* fmov fsM, (rN+) */
    818   1.1  christos       else if (instr[0] == 0xf9 && (instr[1] & 0xfd) == 0x31)
    819   1.1  christos 	{
    820   1.1  christos 	  int fsM, sM, Y, rN, rN_regnum;
    821   1.1  christos 	  gdb_byte buf[1];
    822   1.1  christos 
    823   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    824   1.1  christos 
    825   1.1  christos 	  status = target_read_memory (pc + 2, buf, 1);
    826   1.1  christos 	  if (status != 0)
    827   1.1  christos 	    break;
    828   1.1  christos 
    829   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    830   1.1  christos 	  rN = buf[0] & 0x0f;
    831   1.1  christos 	  fsM = (Y << 4) | sM;
    832   1.1  christos 
    833   1.1  christos 	  rN_regnum = translate_rreg (rN);
    834   1.1  christos 
    835   1.8  christos 	  stack.store (regs[rN_regnum], 4,
    836   1.8  christos 		       regs[E_FS0_REGNUM + fsM]);
    837   1.1  christos 	  regs[rN_regnum] = pv_add_constant (regs[rN_regnum], 4);
    838   1.1  christos 
    839   1.1  christos 	  pc += 3;
    840   1.1  christos 	}
    841   1.1  christos       /* fmov fsM, (rN+, imm8) */
    842   1.1  christos       else if (instr[0] == 0xfb && (instr[1] & 0xfd) == 0x31)
    843   1.1  christos 	{
    844   1.1  christos 	  int fsM, sM, Y, rN, rN_regnum;
    845   1.1  christos 	  LONGEST imm8;
    846   1.1  christos 	  gdb_byte buf[2];
    847   1.1  christos 
    848   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    849   1.1  christos 
    850   1.1  christos 	  status = target_read_memory (pc + 2, buf, 2);
    851   1.1  christos 	  if (status != 0)
    852   1.1  christos 	    break;
    853   1.1  christos 
    854   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    855   1.1  christos 	  rN = buf[0] & 0x0f;
    856   1.1  christos 	  fsM = (Y << 4) | sM;
    857   1.1  christos 	  imm8 = extract_signed_integer (&buf[1], 1, byte_order);
    858   1.1  christos 
    859   1.1  christos 	  rN_regnum = translate_rreg (rN);
    860   1.1  christos 
    861   1.8  christos 	  stack.store (regs[rN_regnum], 4, regs[E_FS0_REGNUM + fsM]);
    862   1.1  christos 	  regs[rN_regnum] = pv_add_constant (regs[rN_regnum], imm8);
    863   1.1  christos 
    864   1.1  christos 	  pc += 4;
    865   1.1  christos 	}
    866   1.1  christos       /* fmov fsM, (rN+, imm24) */
    867   1.1  christos       else if (instr[0] == 0xfd && (instr[1] & 0xfd) == 0x31)
    868   1.1  christos 	{
    869   1.1  christos 	  int fsM, sM, Y, rN, rN_regnum;
    870   1.1  christos 	  LONGEST imm24;
    871   1.1  christos 	  gdb_byte buf[4];
    872   1.1  christos 
    873   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    874   1.1  christos 
    875   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    876   1.1  christos 	  if (status != 0)
    877   1.1  christos 	    break;
    878   1.1  christos 
    879   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    880   1.1  christos 	  rN = buf[0] & 0x0f;
    881   1.1  christos 	  fsM = (Y << 4) | sM;
    882   1.1  christos 	  imm24 = extract_signed_integer (&buf[1], 3, byte_order);
    883   1.1  christos 
    884   1.1  christos 	  rN_regnum = translate_rreg (rN);
    885   1.1  christos 
    886   1.8  christos 	  stack.store (regs[rN_regnum], 4, regs[E_FS0_REGNUM + fsM]);
    887   1.1  christos 	  regs[rN_regnum] = pv_add_constant (regs[rN_regnum], imm24);
    888   1.1  christos 
    889   1.1  christos 	  pc += 6;
    890   1.1  christos 	}
    891   1.1  christos       /* fmov fsM, (rN+, imm32) */
    892   1.1  christos       else if (instr[0] == 0xfe && (instr[1] & 0xfd) == 0x31)
    893   1.1  christos 	{
    894   1.1  christos 	  int fsM, sM, Y, rN, rN_regnum;
    895   1.1  christos 	  LONGEST imm32;
    896   1.1  christos 	  gdb_byte buf[5];
    897   1.1  christos 
    898   1.1  christos 	  Y = (instr[1] & 0x02) >> 1;
    899   1.1  christos 
    900   1.1  christos 	  status = target_read_memory (pc + 2, buf, 5);
    901   1.1  christos 	  if (status != 0)
    902   1.1  christos 	    break;
    903   1.1  christos 
    904   1.1  christos 	  sM = (buf[0] & 0xf0) >> 4;
    905   1.1  christos 	  rN = buf[0] & 0x0f;
    906   1.1  christos 	  fsM = (Y << 4) | sM;
    907   1.1  christos 	  imm32 = extract_signed_integer (&buf[1], 4, byte_order);
    908   1.1  christos 
    909   1.1  christos 	  rN_regnum = translate_rreg (rN);
    910   1.1  christos 
    911   1.8  christos 	  stack.store (regs[rN_regnum], 4, regs[E_FS0_REGNUM + fsM]);
    912   1.1  christos 	  regs[rN_regnum] = pv_add_constant (regs[rN_regnum], imm32);
    913   1.1  christos 
    914   1.1  christos 	  pc += 7;
    915   1.1  christos 	}
    916   1.1  christos       /* mov imm8, aN */
    917   1.1  christos       else if ((instr[0] & 0xf0) == 0x90)
    918  1.10  christos 	{
    919   1.1  christos 	  int aN = instr[0] & 0x03;
    920   1.1  christos 	  LONGEST imm8;
    921   1.1  christos 
    922   1.1  christos 	  imm8 = extract_signed_integer (&instr[1], 1, byte_order);
    923   1.1  christos 
    924   1.1  christos 	  regs[E_A0_REGNUM + aN] = pv_constant (imm8);
    925   1.1  christos 	  pc += 2;
    926   1.1  christos 	}
    927   1.1  christos       /* mov imm16, aN */
    928   1.1  christos       else if ((instr[0] & 0xfc) == 0x24)
    929  1.10  christos 	{
    930   1.1  christos 	  int aN = instr[0] & 0x03;
    931   1.1  christos 	  gdb_byte buf[2];
    932   1.1  christos 	  LONGEST imm16;
    933   1.1  christos 
    934   1.1  christos 	  status = target_read_memory (pc + 1, buf, 2);
    935   1.1  christos 	  if (status != 0)
    936   1.1  christos 	    break;
    937   1.1  christos 
    938   1.1  christos 	  imm16 = extract_signed_integer (buf, 2, byte_order);
    939   1.1  christos 	  regs[E_A0_REGNUM + aN] = pv_constant (imm16);
    940   1.1  christos 	  pc += 3;
    941   1.1  christos 	}
    942   1.1  christos       /* mov imm32, aN */
    943   1.1  christos       else if (instr[0] == 0xfc && ((instr[1] & 0xfc) == 0xdc))
    944  1.10  christos 	{
    945   1.1  christos 	  int aN = instr[1] & 0x03;
    946   1.1  christos 	  gdb_byte buf[4];
    947   1.1  christos 	  LONGEST imm32;
    948   1.1  christos 
    949   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    950   1.1  christos 	  if (status != 0)
    951   1.1  christos 	    break;
    952   1.1  christos 
    953   1.1  christos 	  imm32 = extract_signed_integer (buf, 4, byte_order);
    954   1.1  christos 	  regs[E_A0_REGNUM + aN] = pv_constant (imm32);
    955   1.1  christos 	  pc += 6;
    956   1.1  christos 	}
    957   1.1  christos       /* mov imm8, dN */
    958   1.1  christos       else if ((instr[0] & 0xf0) == 0x80)
    959  1.10  christos 	{
    960   1.1  christos 	  int dN = instr[0] & 0x03;
    961   1.1  christos 	  LONGEST imm8;
    962   1.1  christos 
    963   1.1  christos 	  imm8 = extract_signed_integer (&instr[1], 1, byte_order);
    964   1.1  christos 
    965   1.1  christos 	  regs[E_D0_REGNUM + dN] = pv_constant (imm8);
    966   1.1  christos 	  pc += 2;
    967   1.1  christos 	}
    968   1.1  christos       /* mov imm16, dN */
    969   1.1  christos       else if ((instr[0] & 0xfc) == 0x2c)
    970  1.10  christos 	{
    971   1.1  christos 	  int dN = instr[0] & 0x03;
    972   1.1  christos 	  gdb_byte buf[2];
    973   1.1  christos 	  LONGEST imm16;
    974   1.1  christos 
    975   1.1  christos 	  status = target_read_memory (pc + 1, buf, 2);
    976   1.1  christos 	  if (status != 0)
    977   1.1  christos 	    break;
    978   1.1  christos 
    979   1.1  christos 	  imm16 = extract_signed_integer (buf, 2, byte_order);
    980   1.1  christos 	  regs[E_D0_REGNUM + dN] = pv_constant (imm16);
    981   1.1  christos 	  pc += 3;
    982   1.1  christos 	}
    983   1.1  christos       /* mov imm32, dN */
    984   1.1  christos       else if (instr[0] == 0xfc && ((instr[1] & 0xfc) == 0xcc))
    985  1.10  christos 	{
    986   1.1  christos 	  int dN = instr[1] & 0x03;
    987   1.1  christos 	  gdb_byte buf[4];
    988   1.1  christos 	  LONGEST imm32;
    989   1.1  christos 
    990   1.1  christos 	  status = target_read_memory (pc + 2, buf, 4);
    991   1.1  christos 	  if (status != 0)
    992   1.1  christos 	    break;
    993   1.1  christos 
    994   1.1  christos 	  imm32 = extract_signed_integer (buf, 4, byte_order);
    995   1.1  christos 	  regs[E_D0_REGNUM + dN] = pv_constant (imm32);
    996   1.1  christos 	  pc += 6;
    997   1.1  christos 	}
    998   1.1  christos       else
    999   1.1  christos 	{
   1000   1.1  christos 	  /* We've hit some instruction that we don't recognize.  Hopefully,
   1001   1.1  christos 	     we have enough to do prologue analysis.  */
   1002   1.1  christos 	  break;
   1003   1.1  christos 	}
   1004   1.1  christos     }
   1005   1.1  christos 
   1006   1.1  christos   /* Is the frame size (offset, really) a known constant?  */
   1007   1.1  christos   if (pv_is_register (regs[E_SP_REGNUM], E_SP_REGNUM))
   1008   1.1  christos     result->frame_size = regs[E_SP_REGNUM].k;
   1009   1.1  christos 
   1010   1.1  christos   /* Was the frame pointer initialized?  */
   1011   1.1  christos   if (pv_is_register (regs[E_A3_REGNUM], E_SP_REGNUM))
   1012   1.1  christos     {
   1013   1.1  christos       result->has_frame_ptr = 1;
   1014   1.1  christos       result->frame_ptr_offset = regs[E_A3_REGNUM].k;
   1015   1.1  christos     }
   1016   1.1  christos 
   1017   1.1  christos   /* Record where all the registers were saved.  */
   1018   1.8  christos   stack.scan (check_for_saved, (void *) result);
   1019   1.1  christos 
   1020   1.1  christos   result->prologue_end = after_last_frame_setup_insn;
   1021   1.1  christos }
   1022   1.1  christos 
   1023   1.1  christos /* Function: skip_prologue
   1024   1.1  christos    Return the address of the first inst past the prologue of the function.  */
   1025   1.1  christos 
   1026   1.1  christos static CORE_ADDR
   1027   1.1  christos mn10300_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   1028   1.1  christos {
   1029   1.1  christos   const char *name;
   1030   1.1  christos   CORE_ADDR func_addr, func_end;
   1031   1.1  christos   struct mn10300_prologue p;
   1032   1.1  christos 
   1033   1.1  christos   /* Try to find the extent of the function that contains PC.  */
   1034   1.1  christos   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
   1035   1.1  christos     return pc;
   1036   1.1  christos 
   1037   1.1  christos   mn10300_analyze_prologue (gdbarch, pc, func_end, &p);
   1038   1.1  christos   return p.prologue_end;
   1039   1.1  christos }
   1040   1.1  christos 
   1041   1.1  christos /* Wrapper for mn10300_analyze_prologue: find the function start;
   1042   1.1  christos    use the current frame PC as the limit, then
   1043   1.1  christos    invoke mn10300_analyze_prologue and return its result.  */
   1044   1.1  christos static struct mn10300_prologue *
   1045  1.11  christos mn10300_analyze_frame_prologue (const frame_info_ptr &this_frame,
   1046   1.1  christos 			   void **this_prologue_cache)
   1047   1.1  christos {
   1048   1.1  christos   if (!*this_prologue_cache)
   1049   1.1  christos     {
   1050   1.1  christos       CORE_ADDR func_start, stop_addr;
   1051   1.1  christos 
   1052   1.1  christos       *this_prologue_cache = FRAME_OBSTACK_ZALLOC (struct mn10300_prologue);
   1053   1.1  christos 
   1054   1.1  christos       func_start = get_frame_func (this_frame);
   1055   1.1  christos       stop_addr = get_frame_pc (this_frame);
   1056   1.1  christos 
   1057   1.1  christos       /* If we couldn't find any function containing the PC, then
   1058  1.10  christos 	 just initialize the prologue cache, but don't do anything.  */
   1059   1.1  christos       if (!func_start)
   1060  1.10  christos 	stop_addr = func_start;
   1061   1.1  christos 
   1062   1.1  christos       mn10300_analyze_prologue (get_frame_arch (this_frame),
   1063   1.6  christos 				func_start, stop_addr,
   1064   1.6  christos 				((struct mn10300_prologue *)
   1065   1.6  christos 				 *this_prologue_cache));
   1066   1.1  christos     }
   1067   1.1  christos 
   1068   1.6  christos   return (struct mn10300_prologue *) *this_prologue_cache;
   1069   1.1  christos }
   1070   1.1  christos 
   1071   1.1  christos /* Given the next frame and a prologue cache, return this frame's
   1072   1.1  christos    base.  */
   1073   1.1  christos static CORE_ADDR
   1074  1.11  christos mn10300_frame_base (const frame_info_ptr &this_frame, void **this_prologue_cache)
   1075   1.1  christos {
   1076   1.1  christos   struct mn10300_prologue *p
   1077   1.1  christos     = mn10300_analyze_frame_prologue (this_frame, this_prologue_cache);
   1078   1.1  christos 
   1079   1.1  christos   /* In functions that use alloca, the distance between the stack
   1080   1.1  christos      pointer and the frame base varies dynamically, so we can't use
   1081   1.1  christos      the SP plus static information like prologue analysis to find the
   1082   1.1  christos      frame base.  However, such functions must have a frame pointer,
   1083   1.1  christos      to be able to restore the SP on exit.  So whenever we do have a
   1084   1.1  christos      frame pointer, use that to find the base.  */
   1085   1.1  christos   if (p->has_frame_ptr)
   1086   1.1  christos     {
   1087   1.1  christos       CORE_ADDR fp = get_frame_register_unsigned (this_frame, E_A3_REGNUM);
   1088   1.1  christos       return fp - p->frame_ptr_offset;
   1089   1.1  christos     }
   1090   1.1  christos   else
   1091   1.1  christos     {
   1092   1.1  christos       CORE_ADDR sp = get_frame_register_unsigned (this_frame, E_SP_REGNUM);
   1093   1.1  christos       return sp - p->frame_size;
   1094   1.1  christos     }
   1095   1.1  christos }
   1096   1.1  christos 
   1097   1.1  christos static void
   1098  1.11  christos mn10300_frame_this_id (const frame_info_ptr &this_frame,
   1099   1.1  christos 		       void **this_prologue_cache,
   1100   1.1  christos 		       struct frame_id *this_id)
   1101   1.1  christos {
   1102   1.1  christos   *this_id = frame_id_build (mn10300_frame_base (this_frame,
   1103   1.1  christos 						 this_prologue_cache),
   1104   1.1  christos 			     get_frame_func (this_frame));
   1105   1.1  christos 
   1106   1.1  christos }
   1107   1.1  christos 
   1108   1.1  christos static struct value *
   1109  1.11  christos mn10300_frame_prev_register (const frame_info_ptr &this_frame,
   1110  1.10  christos 			     void **this_prologue_cache, int regnum)
   1111   1.1  christos {
   1112   1.1  christos   struct mn10300_prologue *p
   1113   1.1  christos     = mn10300_analyze_frame_prologue (this_frame, this_prologue_cache);
   1114   1.1  christos   CORE_ADDR frame_base = mn10300_frame_base (this_frame, this_prologue_cache);
   1115   1.1  christos 
   1116   1.1  christos   if (regnum == E_SP_REGNUM)
   1117   1.1  christos     return frame_unwind_got_constant (this_frame, regnum, frame_base);
   1118   1.1  christos 
   1119   1.1  christos   /* If prologue analysis says we saved this register somewhere,
   1120   1.1  christos      return a description of the stack slot holding it.  */
   1121   1.1  christos   if (p->reg_offset[regnum] != 1)
   1122   1.1  christos     return frame_unwind_got_memory (this_frame, regnum,
   1123  1.10  christos 				    frame_base + p->reg_offset[regnum]);
   1124   1.1  christos 
   1125   1.1  christos   /* Otherwise, presume we haven't changed the value of this
   1126   1.1  christos      register, and get it from the next frame.  */
   1127   1.1  christos   return frame_unwind_got_register (this_frame, regnum, regnum);
   1128   1.1  christos }
   1129   1.1  christos 
   1130   1.1  christos static const struct frame_unwind mn10300_frame_unwind = {
   1131  1.10  christos   "mn10300 prologue",
   1132   1.1  christos   NORMAL_FRAME,
   1133   1.1  christos   default_frame_unwind_stop_reason,
   1134   1.1  christos   mn10300_frame_this_id,
   1135   1.1  christos   mn10300_frame_prev_register,
   1136   1.1  christos   NULL,
   1137   1.1  christos   default_frame_sniffer
   1138   1.1  christos };
   1139   1.1  christos 
   1140   1.1  christos static void
   1141   1.1  christos mn10300_frame_unwind_init (struct gdbarch *gdbarch)
   1142   1.1  christos {
   1143   1.1  christos   dwarf2_append_unwinders (gdbarch);
   1144   1.1  christos   frame_unwind_append_unwinder (gdbarch, &mn10300_frame_unwind);
   1145   1.1  christos }
   1146   1.1  christos 
   1147   1.1  christos /* Function: push_dummy_call
   1148   1.1  christos  *
   1149   1.1  christos  * Set up machine state for a target call, including
   1150   1.1  christos  * function arguments, stack, return address, etc.
   1151   1.1  christos  *
   1152   1.1  christos  */
   1153   1.1  christos 
   1154   1.1  christos static CORE_ADDR
   1155   1.1  christos mn10300_push_dummy_call (struct gdbarch *gdbarch,
   1156   1.1  christos 			 struct value *target_func,
   1157   1.1  christos 			 struct regcache *regcache,
   1158   1.1  christos 			 CORE_ADDR bp_addr,
   1159   1.1  christos 			 int nargs, struct value **args,
   1160   1.1  christos 			 CORE_ADDR sp,
   1161   1.8  christos 			 function_call_return_method return_method,
   1162   1.1  christos 			 CORE_ADDR struct_addr)
   1163   1.1  christos {
   1164   1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   1165   1.1  christos   const int push_size = register_size (gdbarch, E_PC_REGNUM);
   1166   1.1  christos   int regs_used;
   1167   1.1  christos   int len, arg_len;
   1168   1.1  christos   int stack_offset = 0;
   1169   1.1  christos   int argnum;
   1170   1.1  christos   const gdb_byte *val;
   1171   1.8  christos   gdb_byte valbuf[MN10300_MAX_REGISTER_SIZE];
   1172   1.1  christos 
   1173   1.1  christos   /* This should be a nop, but align the stack just in case something
   1174   1.1  christos      went wrong.  Stacks are four byte aligned on the mn10300.  */
   1175   1.1  christos   sp &= ~3;
   1176   1.1  christos 
   1177   1.1  christos   /* Now make space on the stack for the args.
   1178   1.1  christos 
   1179   1.1  christos      XXX This doesn't appear to handle pass-by-invisible reference
   1180   1.1  christos      arguments.  */
   1181   1.8  christos   regs_used = (return_method == return_method_struct) ? 1 : 0;
   1182   1.1  christos   for (len = 0, argnum = 0; argnum < nargs; argnum++)
   1183   1.1  christos     {
   1184  1.11  christos       arg_len = (args[argnum]->type ()->length () + 3) & ~3;
   1185   1.1  christos       while (regs_used < 2 && arg_len > 0)
   1186   1.1  christos 	{
   1187   1.1  christos 	  regs_used++;
   1188   1.1  christos 	  arg_len -= push_size;
   1189   1.1  christos 	}
   1190   1.1  christos       len += arg_len;
   1191   1.1  christos     }
   1192   1.1  christos 
   1193   1.1  christos   /* Allocate stack space.  */
   1194   1.1  christos   sp -= len;
   1195   1.1  christos 
   1196   1.8  christos   if (return_method == return_method_struct)
   1197   1.1  christos     {
   1198   1.1  christos       regs_used = 1;
   1199   1.1  christos       regcache_cooked_write_unsigned (regcache, E_D0_REGNUM, struct_addr);
   1200   1.1  christos     }
   1201   1.1  christos   else
   1202   1.1  christos     regs_used = 0;
   1203   1.1  christos 
   1204   1.1  christos   /* Push all arguments onto the stack.  */
   1205   1.1  christos   for (argnum = 0; argnum < nargs; argnum++)
   1206   1.1  christos     {
   1207   1.1  christos       /* FIXME what about structs?  Unions?  */
   1208  1.11  christos       if ((*args)->type ()->code () == TYPE_CODE_STRUCT
   1209  1.11  christos 	  && (*args)->type ()->length () > 8)
   1210   1.1  christos 	{
   1211   1.1  christos 	  /* Change to pointer-to-type.  */
   1212   1.1  christos 	  arg_len = push_size;
   1213   1.8  christos 	  gdb_assert (push_size <= MN10300_MAX_REGISTER_SIZE);
   1214   1.1  christos 	  store_unsigned_integer (valbuf, push_size, byte_order,
   1215  1.11  christos 				  (*args)->address ());
   1216   1.1  christos 	  val = &valbuf[0];
   1217   1.1  christos 	}
   1218   1.1  christos       else
   1219   1.1  christos 	{
   1220  1.11  christos 	  arg_len = (*args)->type ()->length ();
   1221  1.11  christos 	  val = (*args)->contents ().data ();
   1222   1.1  christos 	}
   1223   1.1  christos 
   1224   1.1  christos       while (regs_used < 2 && arg_len > 0)
   1225   1.1  christos 	{
   1226   1.1  christos 	  regcache_cooked_write_unsigned (regcache, regs_used,
   1227   1.1  christos 		  extract_unsigned_integer (val, push_size, byte_order));
   1228   1.1  christos 	  val += push_size;
   1229   1.1  christos 	  arg_len -= push_size;
   1230   1.1  christos 	  regs_used++;
   1231   1.1  christos 	}
   1232   1.1  christos 
   1233   1.1  christos       while (arg_len > 0)
   1234   1.1  christos 	{
   1235   1.1  christos 	  write_memory (sp + stack_offset, val, push_size);
   1236   1.1  christos 	  arg_len -= push_size;
   1237   1.1  christos 	  val += push_size;
   1238   1.1  christos 	  stack_offset += push_size;
   1239   1.1  christos 	}
   1240   1.1  christos 
   1241   1.1  christos       args++;
   1242   1.1  christos     }
   1243   1.1  christos 
   1244   1.1  christos   /* Make space for the flushback area.  */
   1245   1.1  christos   sp -= 8;
   1246   1.1  christos 
   1247   1.1  christos   /* Push the return address that contains the magic breakpoint.  */
   1248   1.1  christos   sp -= 4;
   1249   1.1  christos   write_memory_unsigned_integer (sp, push_size, byte_order, bp_addr);
   1250   1.1  christos 
   1251   1.1  christos   /* The CPU also writes the return address always into the
   1252   1.1  christos      MDR register on "call".  */
   1253   1.1  christos   regcache_cooked_write_unsigned (regcache, E_MDR_REGNUM, bp_addr);
   1254   1.1  christos 
   1255   1.1  christos   /* Update $sp.  */
   1256   1.1  christos   regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp);
   1257   1.1  christos 
   1258   1.1  christos   /* On the mn10300, it's possible to move some of the stack adjustment
   1259   1.1  christos      and saving of the caller-save registers out of the prologue and
   1260   1.1  christos      into the call sites.  (When using gcc, this optimization can
   1261   1.1  christos      occur when using the -mrelax switch.) If this occurs, the dwarf2
   1262   1.1  christos      info will reflect this fact.  We can test to see if this is the
   1263   1.1  christos      case by creating a new frame using the current stack pointer and
   1264   1.1  christos      the address of the function that we're about to call.  We then
   1265   1.1  christos      unwind SP and see if it's different than the SP of our newly
   1266   1.1  christos      created frame.  If the SP values are the same, the caller is not
   1267   1.1  christos      expected to allocate any additional stack.  On the other hand, if
   1268   1.1  christos      the SP values are different, the difference determines the
   1269   1.1  christos      additional stack that must be allocated.
   1270   1.1  christos 
   1271   1.1  christos      Note that we don't update the return value though because that's
   1272   1.1  christos      the value of the stack just after pushing the arguments, but prior
   1273   1.1  christos      to performing the call.  This value is needed in order to
   1274   1.1  christos      construct the frame ID of the dummy call.  */
   1275   1.1  christos   {
   1276   1.1  christos     CORE_ADDR func_addr = find_function_addr (target_func, NULL);
   1277   1.1  christos     CORE_ADDR unwound_sp
   1278   1.9  christos       = gdbarch_unwind_sp (gdbarch, create_new_frame (sp, func_addr));
   1279   1.1  christos     if (sp != unwound_sp)
   1280   1.1  christos       regcache_cooked_write_unsigned (regcache, E_SP_REGNUM,
   1281  1.10  christos 				      sp - (unwound_sp - sp));
   1282   1.1  christos   }
   1283   1.1  christos 
   1284   1.1  christos   return sp;
   1285   1.1  christos }
   1286   1.1  christos 
   1287   1.1  christos /* If DWARF2 is a register number appearing in Dwarf2 debug info, then
   1288   1.1  christos    mn10300_dwarf2_reg_to_regnum (DWARF2) is the corresponding GDB
   1289   1.1  christos    register number.  Why don't Dwarf2 and GDB use the same numbering?
   1290   1.1  christos    Who knows?  But since people have object files lying around with
   1291   1.1  christos    the existing Dwarf2 numbering, and other people have written stubs
   1292   1.1  christos    to work with the existing GDB, neither of them can change.  So we
   1293   1.1  christos    just have to cope.  */
   1294   1.1  christos static int
   1295   1.1  christos mn10300_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int dwarf2)
   1296   1.1  christos {
   1297   1.1  christos   /* This table is supposed to be shaped like the gdbarch_register_name
   1298   1.1  christos      initializer in gcc/config/mn10300/mn10300.h.  Registers which
   1299   1.1  christos      appear in GCC's numbering, but have no counterpart in GDB's
   1300   1.1  christos      world, are marked with a -1.  */
   1301   1.1  christos   static int dwarf2_to_gdb[] = {
   1302   1.3  christos     E_D0_REGNUM, E_D1_REGNUM, E_D2_REGNUM, E_D3_REGNUM,
   1303   1.3  christos     E_A0_REGNUM, E_A1_REGNUM, E_A2_REGNUM, E_A3_REGNUM,
   1304   1.3  christos     -1, E_SP_REGNUM,
   1305   1.3  christos 
   1306   1.3  christos     E_E0_REGNUM, E_E1_REGNUM, E_E2_REGNUM, E_E3_REGNUM,
   1307   1.3  christos     E_E4_REGNUM, E_E5_REGNUM, E_E6_REGNUM, E_E7_REGNUM,
   1308   1.3  christos 
   1309   1.3  christos     E_FS0_REGNUM + 0, E_FS0_REGNUM + 1, E_FS0_REGNUM + 2, E_FS0_REGNUM + 3,
   1310   1.3  christos     E_FS0_REGNUM + 4, E_FS0_REGNUM + 5, E_FS0_REGNUM + 6, E_FS0_REGNUM + 7,
   1311   1.3  christos 
   1312   1.3  christos     E_FS0_REGNUM + 8, E_FS0_REGNUM + 9, E_FS0_REGNUM + 10, E_FS0_REGNUM + 11,
   1313   1.3  christos     E_FS0_REGNUM + 12, E_FS0_REGNUM + 13, E_FS0_REGNUM + 14, E_FS0_REGNUM + 15,
   1314   1.3  christos 
   1315   1.3  christos     E_FS0_REGNUM + 16, E_FS0_REGNUM + 17, E_FS0_REGNUM + 18, E_FS0_REGNUM + 19,
   1316   1.3  christos     E_FS0_REGNUM + 20, E_FS0_REGNUM + 21, E_FS0_REGNUM + 22, E_FS0_REGNUM + 23,
   1317   1.3  christos 
   1318   1.3  christos     E_FS0_REGNUM + 24, E_FS0_REGNUM + 25, E_FS0_REGNUM + 26, E_FS0_REGNUM + 27,
   1319   1.3  christos     E_FS0_REGNUM + 28, E_FS0_REGNUM + 29, E_FS0_REGNUM + 30, E_FS0_REGNUM + 31,
   1320   1.3  christos 
   1321   1.3  christos     E_MDR_REGNUM, E_PSW_REGNUM, E_PC_REGNUM
   1322   1.1  christos   };
   1323   1.1  christos 
   1324   1.1  christos   if (dwarf2 < 0
   1325   1.1  christos       || dwarf2 >= ARRAY_SIZE (dwarf2_to_gdb))
   1326   1.6  christos     return -1;
   1327   1.1  christos 
   1328   1.1  christos   return dwarf2_to_gdb[dwarf2];
   1329   1.1  christos }
   1330   1.1  christos 
   1331   1.1  christos static struct gdbarch *
   1332   1.1  christos mn10300_gdbarch_init (struct gdbarch_info info,
   1333   1.1  christos 		      struct gdbarch_list *arches)
   1334   1.1  christos {
   1335   1.1  christos   int num_regs;
   1336   1.1  christos 
   1337   1.1  christos   arches = gdbarch_list_lookup_by_info (arches, &info);
   1338   1.1  christos   if (arches != NULL)
   1339   1.1  christos     return arches->gdbarch;
   1340   1.1  christos 
   1341  1.11  christos   gdbarch *gdbarch
   1342  1.11  christos     = gdbarch_alloc (&info, gdbarch_tdep_up (new mn10300_gdbarch_tdep));
   1343  1.11  christos   mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
   1344   1.1  christos 
   1345   1.1  christos   switch (info.bfd_arch_info->mach)
   1346   1.1  christos     {
   1347   1.1  christos     case 0:
   1348   1.1  christos     case bfd_mach_mn10300:
   1349   1.1  christos       set_gdbarch_register_name (gdbarch, mn10300_generic_register_name);
   1350   1.1  christos       tdep->am33_mode = 0;
   1351   1.1  christos       num_regs = 32;
   1352   1.1  christos       break;
   1353   1.1  christos     case bfd_mach_am33:
   1354   1.1  christos       set_gdbarch_register_name (gdbarch, am33_register_name);
   1355   1.1  christos       tdep->am33_mode = 1;
   1356   1.1  christos       num_regs = 32;
   1357   1.1  christos       break;
   1358   1.1  christos     case bfd_mach_am33_2:
   1359   1.1  christos       set_gdbarch_register_name (gdbarch, am33_2_register_name);
   1360   1.1  christos       tdep->am33_mode = 2;
   1361   1.1  christos       num_regs = 64;
   1362   1.1  christos       set_gdbarch_fp0_regnum (gdbarch, 32);
   1363   1.1  christos       break;
   1364   1.1  christos     default:
   1365  1.10  christos       internal_error (_("mn10300_gdbarch_init: Unknown mn10300 variant"));
   1366   1.1  christos       break;
   1367   1.1  christos     }
   1368   1.1  christos 
   1369   1.1  christos   /* By default, chars are unsigned.  */
   1370   1.1  christos   set_gdbarch_char_signed (gdbarch, 0);
   1371   1.1  christos 
   1372   1.1  christos   /* Registers.  */
   1373   1.1  christos   set_gdbarch_num_regs (gdbarch, num_regs);
   1374   1.1  christos   set_gdbarch_register_type (gdbarch, mn10300_register_type);
   1375   1.1  christos   set_gdbarch_skip_prologue (gdbarch, mn10300_skip_prologue);
   1376   1.1  christos   set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
   1377   1.1  christos   set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
   1378   1.1  christos   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mn10300_dwarf2_reg_to_regnum);
   1379   1.1  christos 
   1380   1.1  christos   /* Stack unwinding.  */
   1381   1.1  christos   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   1382   1.1  christos   /* Breakpoints.  */
   1383   1.7  christos   set_gdbarch_breakpoint_kind_from_pc (gdbarch,
   1384   1.7  christos 				       mn10300_breakpoint::kind_from_pc);
   1385   1.7  christos   set_gdbarch_sw_breakpoint_from_kind (gdbarch,
   1386   1.7  christos 				       mn10300_breakpoint::bp_from_kind);
   1387   1.1  christos   /* decr_pc_after_break?  */
   1388   1.1  christos 
   1389   1.1  christos   /* Stage 2 */
   1390   1.1  christos   set_gdbarch_return_value (gdbarch, mn10300_return_value);
   1391   1.1  christos 
   1392   1.1  christos   /* Stage 3 -- get target calls working.  */
   1393   1.1  christos   set_gdbarch_push_dummy_call (gdbarch, mn10300_push_dummy_call);
   1394   1.1  christos   /* set_gdbarch_return_value (store, extract) */
   1395   1.1  christos 
   1396   1.1  christos 
   1397   1.1  christos   mn10300_frame_unwind_init (gdbarch);
   1398   1.1  christos 
   1399   1.1  christos   /* Hook in ABI-specific overrides, if they have been registered.  */
   1400   1.1  christos   gdbarch_init_osabi (info, gdbarch);
   1401   1.1  christos 
   1402   1.1  christos   return gdbarch;
   1403   1.1  christos }
   1404   1.1  christos 
   1405   1.1  christos /* Dump out the mn10300 specific architecture information.  */
   1406   1.1  christos 
   1407   1.1  christos static void
   1408   1.1  christos mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
   1409   1.1  christos {
   1410  1.10  christos   mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
   1411  1.10  christos   gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
   1412  1.10  christos 	      tdep->am33_mode);
   1413   1.1  christos }
   1414   1.1  christos 
   1415   1.9  christos void _initialize_mn10300_tdep ();
   1416   1.1  christos void
   1417   1.9  christos _initialize_mn10300_tdep ()
   1418   1.1  christos {
   1419   1.1  christos   gdbarch_register (bfd_arch_mn10300, mn10300_gdbarch_init, mn10300_dump_tdep);
   1420   1.1  christos }
   1421   1.1  christos 
   1422