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