Home | History | Annotate | Line # | Download | only in gdb
tic6x-tdep.c revision 1.7
      1  1.1  christos /* Target dependent code for GDB on TI C6x systems.
      2  1.1  christos 
      3  1.7  christos    Copyright (C) 2010-2017 Free Software Foundation, Inc.
      4  1.1  christos    Contributed by Andrew Jenner <andrew (at) codesourcery.com>
      5  1.1  christos    Contributed by Yao Qi <yao (at) codesourcery.com>
      6  1.1  christos 
      7  1.1  christos    This file is part of GDB.
      8  1.1  christos 
      9  1.1  christos    This program is free software; you can redistribute it and/or modify
     10  1.1  christos    it under the terms of the GNU General Public License as published by
     11  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12  1.1  christos    (at your option) any later version.
     13  1.1  christos 
     14  1.1  christos    This program is distributed in the hope that it will be useful,
     15  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  1.1  christos    GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos    You should have received a copy of the GNU General Public License
     20  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21  1.1  christos 
     22  1.1  christos #include "defs.h"
     23  1.1  christos #include "frame.h"
     24  1.1  christos #include "frame-unwind.h"
     25  1.1  christos #include "frame-base.h"
     26  1.1  christos #include "trad-frame.h"
     27  1.1  christos #include "dwarf2-frame.h"
     28  1.1  christos #include "symtab.h"
     29  1.1  christos #include "inferior.h"
     30  1.1  christos #include "gdbtypes.h"
     31  1.1  christos #include "gdbcore.h"
     32  1.1  christos #include "gdbcmd.h"
     33  1.1  christos #include "target.h"
     34  1.1  christos #include "dis-asm.h"
     35  1.1  christos #include "regcache.h"
     36  1.1  christos #include "value.h"
     37  1.1  christos #include "symfile.h"
     38  1.1  christos #include "arch-utils.h"
     39  1.1  christos #include "floatformat.h"
     40  1.1  christos #include "glibc-tdep.h"
     41  1.1  christos #include "infcall.h"
     42  1.1  christos #include "regset.h"
     43  1.1  christos #include "tramp-frame.h"
     44  1.1  christos #include "linux-tdep.h"
     45  1.1  christos #include "solib.h"
     46  1.1  christos #include "objfiles.h"
     47  1.1  christos #include "osabi.h"
     48  1.1  christos #include "tic6x-tdep.h"
     49  1.1  christos #include "language.h"
     50  1.1  christos #include "target-descriptions.h"
     51  1.7  christos #include <algorithm>
     52  1.1  christos 
     53  1.1  christos #include "features/tic6x-c64xp.c"
     54  1.1  christos #include "features/tic6x-c64x.c"
     55  1.1  christos #include "features/tic6x-c62x.c"
     56  1.1  christos 
     57  1.1  christos #define TIC6X_OPCODE_SIZE 4
     58  1.1  christos #define TIC6X_FETCH_PACKET_SIZE 32
     59  1.1  christos 
     60  1.1  christos #define INST_S_BIT(INST) ((INST >> 1) & 1)
     61  1.1  christos #define INST_X_BIT(INST) ((INST >> 12) & 1)
     62  1.1  christos 
     63  1.1  christos const gdb_byte tic6x_bkpt_illegal_opcode_be[] = { 0x56, 0x45, 0x43, 0x14 };
     64  1.1  christos const gdb_byte tic6x_bkpt_illegal_opcode_le[] = { 0x14, 0x43, 0x45, 0x56 };
     65  1.1  christos 
     66  1.1  christos struct tic6x_unwind_cache
     67  1.1  christos {
     68  1.1  christos   /* The frame's base, optionally used by the high-level debug info.  */
     69  1.1  christos   CORE_ADDR base;
     70  1.1  christos 
     71  1.1  christos   /* The previous frame's inner most stack address.  Used as this
     72  1.1  christos      frame ID's stack_addr.  */
     73  1.1  christos   CORE_ADDR cfa;
     74  1.1  christos 
     75  1.1  christos   /* The address of the first instruction in this function */
     76  1.1  christos   CORE_ADDR pc;
     77  1.1  christos 
     78  1.1  christos   /* Which register holds the return address for the frame.  */
     79  1.1  christos   int return_regnum;
     80  1.1  christos 
     81  1.1  christos   /* The offset of register saved on stack.  If register is not saved, the
     82  1.1  christos      corresponding element is -1.  */
     83  1.1  christos   CORE_ADDR reg_saved[TIC6X_NUM_CORE_REGS];
     84  1.1  christos };
     85  1.1  christos 
     86  1.1  christos 
     87  1.1  christos /* Name of TI C6x core registers.  */
     88  1.1  christos static const char *const tic6x_register_names[] =
     89  1.1  christos {
     90  1.1  christos   "A0",  "A1",  "A2",  "A3",  /*  0  1  2  3 */
     91  1.1  christos   "A4",  "A5",  "A6",  "A7",  /*  4  5  6  7 */
     92  1.1  christos   "A8",  "A9",  "A10", "A11", /*  8  9 10 11 */
     93  1.1  christos   "A12", "A13", "A14", "A15", /* 12 13 14 15 */
     94  1.1  christos   "B0",  "B1",  "B2",  "B3",  /* 16 17 18 19 */
     95  1.1  christos   "B4",  "B5",  "B6",  "B7",  /* 20 21 22 23 */
     96  1.1  christos   "B8",  "B9",  "B10", "B11", /* 24 25 26 27 */
     97  1.1  christos   "B12", "B13", "B14", "B15", /* 28 29 30 31 */
     98  1.1  christos   "CSR", "PC",                /* 32 33       */
     99  1.1  christos };
    100  1.1  christos 
    101  1.1  christos /* This array maps the arguments to the register number which passes argument
    102  1.1  christos    in function call according to C6000 ELF ABI.  */
    103  1.1  christos static const int arg_regs[] = { 4, 20, 6, 22, 8, 24, 10, 26, 12, 28 };
    104  1.1  christos 
    105  1.1  christos /* This is the implementation of gdbarch method register_name.  */
    106  1.1  christos 
    107  1.1  christos static const char *
    108  1.1  christos tic6x_register_name (struct gdbarch *gdbarch, int regno)
    109  1.1  christos {
    110  1.1  christos   if (regno < 0)
    111  1.1  christos     return NULL;
    112  1.1  christos 
    113  1.1  christos   if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
    114  1.1  christos     return tdesc_register_name (gdbarch, regno);
    115  1.1  christos   else if (regno >= ARRAY_SIZE (tic6x_register_names))
    116  1.1  christos     return "";
    117  1.1  christos   else
    118  1.1  christos     return tic6x_register_names[regno];
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos /* This is the implementation of gdbarch method register_type.  */
    122  1.1  christos 
    123  1.1  christos static struct type *
    124  1.1  christos tic6x_register_type (struct gdbarch *gdbarch, int regno)
    125  1.1  christos {
    126  1.1  christos 
    127  1.1  christos   if (regno == TIC6X_PC_REGNUM)
    128  1.1  christos     return builtin_type (gdbarch)->builtin_func_ptr;
    129  1.1  christos   else
    130  1.1  christos     return builtin_type (gdbarch)->builtin_uint32;
    131  1.1  christos }
    132  1.1  christos 
    133  1.1  christos static void
    134  1.1  christos tic6x_setup_default (struct tic6x_unwind_cache *cache)
    135  1.1  christos {
    136  1.1  christos   int i;
    137  1.1  christos 
    138  1.1  christos   for (i = 0; i < TIC6X_NUM_CORE_REGS; i++)
    139  1.1  christos     cache->reg_saved[i] = -1;
    140  1.1  christos }
    141  1.1  christos 
    142  1.1  christos static unsigned long tic6x_fetch_instruction (struct gdbarch *, CORE_ADDR);
    143  1.1  christos static int tic6x_register_number (int reg, int side, int crosspath);
    144  1.1  christos 
    145  1.1  christos /* Do a full analysis of the prologue at START_PC and update CACHE accordingly.
    146  1.1  christos    Bail out early if CURRENT_PC is reached.  Returns the address of the first
    147  1.1  christos    instruction after the prologue.  */
    148  1.1  christos 
    149  1.1  christos static CORE_ADDR
    150  1.1  christos tic6x_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR start_pc,
    151  1.1  christos 			const CORE_ADDR current_pc,
    152  1.1  christos 			struct tic6x_unwind_cache *cache,
    153  1.1  christos 			struct frame_info *this_frame)
    154  1.1  christos {
    155  1.1  christos   unsigned long inst;
    156  1.1  christos   unsigned int src_reg, base_reg, dst_reg;
    157  1.1  christos   int i;
    158  1.1  christos   CORE_ADDR pc = start_pc;
    159  1.1  christos   CORE_ADDR return_pc = start_pc;
    160  1.1  christos   int frame_base_offset_to_sp = 0;
    161  1.1  christos   /* Counter of non-stw instructions after first insn ` sub sp, xxx, sp'.  */
    162  1.1  christos   int non_stw_insn_counter = 0;
    163  1.1  christos 
    164  1.1  christos   if (start_pc >= current_pc)
    165  1.1  christos     return_pc = current_pc;
    166  1.1  christos 
    167  1.1  christos   cache->base = 0;
    168  1.1  christos 
    169  1.1  christos   /* The landmarks in prologue is one or two SUB instructions to SP.
    170  1.1  christos      Instructions on setting up dsbt are in the last part of prologue, if
    171  1.1  christos      needed.  In maxim, prologue can be divided to three parts by two
    172  1.1  christos      `sub sp, xx, sp' insns.  */
    173  1.1  christos 
    174  1.1  christos   /* Step 1: Look for the 1st and 2nd insn `sub sp, xx, sp',  in which, the
    175  1.1  christos      2nd one is optional.  */
    176  1.1  christos   while (pc < current_pc)
    177  1.1  christos     {
    178  1.1  christos       unsigned long inst = tic6x_fetch_instruction (gdbarch, pc);
    179  1.1  christos 
    180  1.1  christos       if ((inst & 0x1ffc) == 0x1dc0 || (inst & 0x1ffc) == 0x1bc0
    181  1.1  christos 	  || (inst & 0x0ffc) == 0x9c0)
    182  1.1  christos 	{
    183  1.1  christos 	  /* SUBAW/SUBAH/SUB, and src1 is ucst 5.  */
    184  1.1  christos 	  unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f,
    185  1.1  christos 						     INST_S_BIT (inst), 0);
    186  1.1  christos 	  unsigned int dst = tic6x_register_number ((inst >> 23) & 0x1f,
    187  1.1  christos 						    INST_S_BIT (inst), 0);
    188  1.1  christos 
    189  1.1  christos 	  if (src2 == TIC6X_SP_REGNUM && dst == TIC6X_SP_REGNUM)
    190  1.1  christos 	    {
    191  1.1  christos 	      /* Extract const from insn SUBAW/SUBAH/SUB, and translate it to
    192  1.1  christos 		 offset.  The constant offset is decoded in bit 13-17 in all
    193  1.1  christos 		 these three kinds of instructions.  */
    194  1.1  christos 	      unsigned int ucst5 = (inst >> 13) & 0x1f;
    195  1.1  christos 
    196  1.1  christos 	      if ((inst & 0x1ffc) == 0x1dc0)	/* SUBAW */
    197  1.1  christos 		frame_base_offset_to_sp += ucst5 << 2;
    198  1.1  christos 	      else if ((inst & 0x1ffc) == 0x1bc0)	/* SUBAH */
    199  1.1  christos 		frame_base_offset_to_sp += ucst5 << 1;
    200  1.1  christos 	      else if ((inst & 0x0ffc) == 0x9c0)	/* SUB */
    201  1.1  christos 		frame_base_offset_to_sp += ucst5;
    202  1.1  christos 	      else
    203  1.1  christos 		gdb_assert_not_reached ("unexpected instruction");
    204  1.1  christos 
    205  1.1  christos 	      return_pc = pc + 4;
    206  1.1  christos 	    }
    207  1.1  christos 	}
    208  1.1  christos       else if ((inst & 0x174) == 0x74)	/* stw SRC, *+b15(uconst) */
    209  1.1  christos 	{
    210  1.1  christos 	  /* The y bit determines which file base is read from.  */
    211  1.1  christos 	  base_reg = tic6x_register_number ((inst >> 18) & 0x1f,
    212  1.1  christos 					    (inst >> 7) & 1, 0);
    213  1.1  christos 
    214  1.1  christos 	  if (base_reg == TIC6X_SP_REGNUM)
    215  1.1  christos 	    {
    216  1.1  christos 	      src_reg = tic6x_register_number ((inst >> 23) & 0x1f,
    217  1.1  christos 					       INST_S_BIT (inst), 0);
    218  1.1  christos 
    219  1.1  christos 	      cache->reg_saved[src_reg] = ((inst >> 13) & 0x1f) << 2;
    220  1.1  christos 
    221  1.1  christos 	      return_pc = pc + 4;
    222  1.1  christos 	    }
    223  1.1  christos 	  non_stw_insn_counter = 0;
    224  1.1  christos 	}
    225  1.1  christos       else
    226  1.1  christos 	{
    227  1.1  christos 	  non_stw_insn_counter++;
    228  1.1  christos 	  /* Following instruction sequence may be emitted in prologue:
    229  1.1  christos 
    230  1.1  christos 	     <+0>: subah .D2 b15,28,b15
    231  1.1  christos 	     <+4>: or .L2X 0,a4,b0
    232  1.1  christos 	     <+8>: || stw .D2T2 b14,*+b15(56)
    233  1.1  christos 	     <+12>:[!b0] b .S1 0xe50e4c1c <sleep+220>
    234  1.1  christos 	     <+16>:|| stw .D2T1 a10,*+b15(48)
    235  1.1  christos 	     <+20>:stw .D2T2 b3,*+b15(52)
    236  1.1  christos 	     <+24>:stw .D2T1 a4,*+b15(40)
    237  1.1  christos 
    238  1.1  christos 	     we should look forward for next instruction instead of breaking loop
    239  1.1  christos 	     here.  So far, we allow almost two sequential non-stw instructions
    240  1.1  christos 	     in prologue.  */
    241  1.1  christos 	  if (non_stw_insn_counter >= 2)
    242  1.1  christos 	    break;
    243  1.1  christos 	}
    244  1.1  christos 
    245  1.1  christos 
    246  1.1  christos       pc += 4;
    247  1.1  christos     }
    248  1.1  christos   /* Step 2: Skip insn on setting up dsbt if it is.  Usually, it looks like,
    249  1.1  christos      ldw .D2T2 *+b14(0),b14 */
    250  1.1  christos   inst = tic6x_fetch_instruction (gdbarch, pc);
    251  1.1  christos   /* The s bit determines which file dst will be loaded into, same effect as
    252  1.1  christos      other places.  */
    253  1.1  christos   dst_reg = tic6x_register_number ((inst >> 23) & 0x1f, (inst >> 1) & 1, 0);
    254  1.1  christos   /* The y bit (bit 7), instead of s bit, determines which file base be
    255  1.1  christos      used.  */
    256  1.1  christos   base_reg = tic6x_register_number ((inst >> 18) & 0x1f, (inst >> 7) & 1, 0);
    257  1.1  christos 
    258  1.1  christos   if ((inst & 0x164) == 0x64	/* ldw */
    259  1.1  christos       && dst_reg == TIC6X_DP_REGNUM	/* dst is B14 */
    260  1.1  christos       && base_reg == TIC6X_DP_REGNUM)	/* baseR is B14 */
    261  1.1  christos     {
    262  1.1  christos       return_pc = pc + 4;
    263  1.1  christos     }
    264  1.1  christos 
    265  1.1  christos   if (this_frame)
    266  1.1  christos     {
    267  1.1  christos       cache->base = get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM);
    268  1.1  christos 
    269  1.1  christos       if (cache->reg_saved[TIC6X_FP_REGNUM] != -1)
    270  1.1  christos 	{
    271  1.1  christos 	  /* If the FP now holds an offset from the CFA then this is a frame
    272  1.1  christos 	     which uses the frame pointer.  */
    273  1.1  christos 
    274  1.1  christos 	  cache->cfa = get_frame_register_unsigned (this_frame,
    275  1.1  christos 						    TIC6X_FP_REGNUM);
    276  1.1  christos 	}
    277  1.1  christos       else
    278  1.1  christos 	{
    279  1.1  christos 	  /* FP doesn't hold an offset from the CFA.  If SP still holds an
    280  1.1  christos 	     offset from the CFA then we might be in a function which omits
    281  1.1  christos 	     the frame pointer.  */
    282  1.1  christos 
    283  1.1  christos 	  cache->cfa = cache->base + frame_base_offset_to_sp;
    284  1.1  christos 	}
    285  1.1  christos     }
    286  1.1  christos 
    287  1.1  christos   /* Adjust all the saved registers such that they contain addresses
    288  1.1  christos      instead of offsets.  */
    289  1.1  christos   for (i = 0; i < TIC6X_NUM_CORE_REGS; i++)
    290  1.1  christos     if (cache->reg_saved[i] != -1)
    291  1.1  christos       cache->reg_saved[i] = cache->base + cache->reg_saved[i];
    292  1.1  christos 
    293  1.1  christos   return return_pc;
    294  1.1  christos }
    295  1.1  christos 
    296  1.1  christos /* This is the implementation of gdbarch method skip_prologue.  */
    297  1.1  christos 
    298  1.1  christos static CORE_ADDR
    299  1.1  christos tic6x_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
    300  1.1  christos {
    301  1.1  christos   CORE_ADDR func_addr;
    302  1.1  christos   struct tic6x_unwind_cache cache;
    303  1.1  christos 
    304  1.1  christos   /* See if we can determine the end of the prologue via the symbol table.
    305  1.1  christos      If so, then return either PC, or the PC after the prologue, whichever is
    306  1.1  christos      greater.  */
    307  1.1  christos   if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
    308  1.1  christos     {
    309  1.1  christos       CORE_ADDR post_prologue_pc
    310  1.1  christos 	= skip_prologue_using_sal (gdbarch, func_addr);
    311  1.1  christos       if (post_prologue_pc != 0)
    312  1.7  christos 	return std::max (start_pc, post_prologue_pc);
    313  1.1  christos     }
    314  1.1  christos 
    315  1.1  christos   /* Can't determine prologue from the symbol table, need to examine
    316  1.1  christos      instructions.  */
    317  1.1  christos   return tic6x_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache,
    318  1.1  christos 				 NULL);
    319  1.1  christos }
    320  1.1  christos 
    321  1.7  christos /* Implement the breakpoint_kind_from_pc gdbarch method.  */
    322  1.7  christos 
    323  1.7  christos static int
    324  1.7  christos tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
    325  1.7  christos {
    326  1.7  christos   return 4;
    327  1.7  christos }
    328  1.7  christos 
    329  1.7  christos /* Implement the sw_breakpoint_from_kind gdbarch method.  */
    330  1.1  christos 
    331  1.1  christos static const gdb_byte *
    332  1.7  christos tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
    333  1.1  christos {
    334  1.1  christos   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
    335  1.1  christos 
    336  1.7  christos   *size = kind;
    337  1.1  christos 
    338  1.1  christos   if (tdep == NULL || tdep->breakpoint == NULL)
    339  1.1  christos     {
    340  1.1  christos       if (BFD_ENDIAN_BIG == gdbarch_byte_order_for_code (gdbarch))
    341  1.1  christos 	return tic6x_bkpt_illegal_opcode_be;
    342  1.1  christos       else
    343  1.1  christos 	return tic6x_bkpt_illegal_opcode_le;
    344  1.1  christos     }
    345  1.1  christos   else
    346  1.1  christos     return tdep->breakpoint;
    347  1.1  christos }
    348  1.1  christos 
    349  1.1  christos /* This is the implementation of gdbarch method print_insn.  */
    350  1.1  christos 
    351  1.1  christos static int
    352  1.1  christos tic6x_print_insn (bfd_vma memaddr, disassemble_info *info)
    353  1.1  christos {
    354  1.1  christos   return print_insn_tic6x (memaddr, info);
    355  1.1  christos }
    356  1.1  christos 
    357  1.1  christos static void
    358  1.1  christos tic6x_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
    359  1.1  christos 			     struct dwarf2_frame_state_reg *reg,
    360  1.1  christos 			     struct frame_info *this_frame)
    361  1.1  christos {
    362  1.1  christos   /* Mark the PC as the destination for the return address.  */
    363  1.1  christos   if (regnum == gdbarch_pc_regnum (gdbarch))
    364  1.1  christos     reg->how = DWARF2_FRAME_REG_RA;
    365  1.1  christos 
    366  1.1  christos   /* Mark the stack pointer as the call frame address.  */
    367  1.1  christos   else if (regnum == gdbarch_sp_regnum (gdbarch))
    368  1.1  christos     reg->how = DWARF2_FRAME_REG_CFA;
    369  1.1  christos 
    370  1.1  christos   /* The above was taken from the default init_reg in dwarf2-frame.c
    371  1.1  christos      while the below is c6x specific.  */
    372  1.1  christos 
    373  1.1  christos   /* Callee save registers.  The ABI designates A10-A15 and B10-B15 as
    374  1.1  christos      callee-save.  */
    375  1.1  christos   else if ((regnum >= 10 && regnum <= 15) || (regnum >= 26 && regnum <= 31))
    376  1.1  christos     reg->how = DWARF2_FRAME_REG_SAME_VALUE;
    377  1.1  christos   else
    378  1.1  christos     /* All other registers are caller-save.  */
    379  1.1  christos     reg->how = DWARF2_FRAME_REG_UNDEFINED;
    380  1.1  christos }
    381  1.1  christos 
    382  1.1  christos /* This is the implementation of gdbarch method unwind_pc.  */
    383  1.1  christos 
    384  1.1  christos static CORE_ADDR
    385  1.1  christos tic6x_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
    386  1.1  christos {
    387  1.1  christos   gdb_byte buf[8];
    388  1.1  christos 
    389  1.1  christos   frame_unwind_register (next_frame,  TIC6X_PC_REGNUM, buf);
    390  1.1  christos   return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
    391  1.1  christos }
    392  1.1  christos 
    393  1.1  christos /* This is the implementation of gdbarch method unwind_sp.  */
    394  1.1  christos 
    395  1.1  christos static CORE_ADDR
    396  1.1  christos tic6x_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
    397  1.1  christos {
    398  1.1  christos   return frame_unwind_register_unsigned (this_frame, TIC6X_SP_REGNUM);
    399  1.1  christos }
    400  1.1  christos 
    401  1.1  christos 
    402  1.1  christos /* Frame base handling.  */
    403  1.1  christos 
    404  1.1  christos static struct tic6x_unwind_cache*
    405  1.1  christos tic6x_frame_unwind_cache (struct frame_info *this_frame,
    406  1.1  christos 			  void **this_prologue_cache)
    407  1.1  christos {
    408  1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
    409  1.1  christos   CORE_ADDR current_pc;
    410  1.1  christos   struct tic6x_unwind_cache *cache;
    411  1.1  christos 
    412  1.1  christos   if (*this_prologue_cache)
    413  1.6  christos     return (struct tic6x_unwind_cache *) *this_prologue_cache;
    414  1.1  christos 
    415  1.1  christos   cache = FRAME_OBSTACK_ZALLOC (struct tic6x_unwind_cache);
    416  1.1  christos   (*this_prologue_cache) = cache;
    417  1.1  christos 
    418  1.1  christos   cache->return_regnum = TIC6X_RA_REGNUM;
    419  1.1  christos 
    420  1.1  christos   tic6x_setup_default (cache);
    421  1.1  christos 
    422  1.1  christos   cache->pc = get_frame_func (this_frame);
    423  1.1  christos   current_pc = get_frame_pc (this_frame);
    424  1.1  christos 
    425  1.1  christos   /* Prologue analysis does the rest...  */
    426  1.1  christos   if (cache->pc != 0)
    427  1.1  christos     tic6x_analyze_prologue (gdbarch, cache->pc, current_pc, cache, this_frame);
    428  1.1  christos 
    429  1.1  christos   return cache;
    430  1.1  christos }
    431  1.1  christos 
    432  1.1  christos static void
    433  1.1  christos tic6x_frame_this_id (struct frame_info *this_frame, void **this_cache,
    434  1.1  christos 		     struct frame_id *this_id)
    435  1.1  christos {
    436  1.1  christos   struct tic6x_unwind_cache *cache =
    437  1.1  christos     tic6x_frame_unwind_cache (this_frame, this_cache);
    438  1.1  christos 
    439  1.1  christos   /* This marks the outermost frame.  */
    440  1.1  christos   if (cache->base == 0)
    441  1.1  christos     return;
    442  1.1  christos 
    443  1.1  christos   (*this_id) = frame_id_build (cache->cfa, cache->pc);
    444  1.1  christos }
    445  1.1  christos 
    446  1.1  christos static struct value *
    447  1.1  christos tic6x_frame_prev_register (struct frame_info *this_frame, void **this_cache,
    448  1.1  christos 			   int regnum)
    449  1.1  christos {
    450  1.1  christos   struct tic6x_unwind_cache *cache =
    451  1.1  christos     tic6x_frame_unwind_cache (this_frame, this_cache);
    452  1.1  christos 
    453  1.1  christos   gdb_assert (regnum >= 0);
    454  1.1  christos 
    455  1.1  christos   /* The PC of the previous frame is stored in the RA register of
    456  1.1  christos      the current frame.  Frob regnum so that we pull the value from
    457  1.1  christos      the correct place.  */
    458  1.1  christos   if (regnum == TIC6X_PC_REGNUM)
    459  1.1  christos     regnum = cache->return_regnum;
    460  1.1  christos 
    461  1.1  christos   if (regnum == TIC6X_SP_REGNUM && cache->cfa)
    462  1.1  christos     return frame_unwind_got_constant (this_frame, regnum, cache->cfa);
    463  1.1  christos 
    464  1.1  christos   /* If we've worked out where a register is stored then load it from
    465  1.1  christos      there.  */
    466  1.1  christos   if (regnum < TIC6X_NUM_CORE_REGS && cache->reg_saved[regnum] != -1)
    467  1.1  christos     return frame_unwind_got_memory (this_frame, regnum,
    468  1.1  christos 				    cache->reg_saved[regnum]);
    469  1.1  christos 
    470  1.1  christos   return frame_unwind_got_register (this_frame, regnum, regnum);
    471  1.1  christos }
    472  1.1  christos 
    473  1.1  christos static CORE_ADDR
    474  1.1  christos tic6x_frame_base_address (struct frame_info *this_frame, void **this_cache)
    475  1.1  christos {
    476  1.1  christos   struct tic6x_unwind_cache *info
    477  1.1  christos     = tic6x_frame_unwind_cache (this_frame, this_cache);
    478  1.1  christos   return info->base;
    479  1.1  christos }
    480  1.1  christos 
    481  1.1  christos static const struct frame_unwind tic6x_frame_unwind =
    482  1.1  christos {
    483  1.1  christos   NORMAL_FRAME,
    484  1.1  christos   default_frame_unwind_stop_reason,
    485  1.1  christos   tic6x_frame_this_id,
    486  1.1  christos   tic6x_frame_prev_register,
    487  1.1  christos   NULL,
    488  1.1  christos   default_frame_sniffer
    489  1.1  christos };
    490  1.1  christos 
    491  1.1  christos static const struct frame_base tic6x_frame_base =
    492  1.1  christos {
    493  1.1  christos   &tic6x_frame_unwind,
    494  1.1  christos   tic6x_frame_base_address,
    495  1.1  christos   tic6x_frame_base_address,
    496  1.1  christos   tic6x_frame_base_address
    497  1.1  christos };
    498  1.1  christos 
    499  1.1  christos 
    500  1.1  christos static struct tic6x_unwind_cache *
    501  1.1  christos tic6x_make_stub_cache (struct frame_info *this_frame)
    502  1.1  christos {
    503  1.1  christos   struct tic6x_unwind_cache *cache;
    504  1.1  christos 
    505  1.1  christos   cache = FRAME_OBSTACK_ZALLOC (struct tic6x_unwind_cache);
    506  1.1  christos 
    507  1.1  christos   cache->return_regnum = TIC6X_RA_REGNUM;
    508  1.1  christos 
    509  1.1  christos   tic6x_setup_default (cache);
    510  1.1  christos 
    511  1.1  christos   cache->cfa = get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM);
    512  1.1  christos 
    513  1.1  christos   return cache;
    514  1.1  christos }
    515  1.1  christos 
    516  1.1  christos static void
    517  1.1  christos tic6x_stub_this_id (struct frame_info *this_frame, void **this_cache,
    518  1.1  christos 		    struct frame_id *this_id)
    519  1.1  christos {
    520  1.1  christos   struct tic6x_unwind_cache *cache;
    521  1.1  christos 
    522  1.1  christos   if (*this_cache == NULL)
    523  1.1  christos     *this_cache = tic6x_make_stub_cache (this_frame);
    524  1.6  christos   cache = (struct tic6x_unwind_cache *) *this_cache;
    525  1.1  christos 
    526  1.1  christos   *this_id = frame_id_build (cache->cfa, get_frame_pc (this_frame));
    527  1.1  christos }
    528  1.1  christos 
    529  1.1  christos static int
    530  1.1  christos tic6x_stub_unwind_sniffer (const struct frame_unwind *self,
    531  1.1  christos 			   struct frame_info *this_frame,
    532  1.1  christos 			   void **this_prologue_cache)
    533  1.1  christos {
    534  1.1  christos   CORE_ADDR addr_in_block;
    535  1.1  christos 
    536  1.1  christos   addr_in_block = get_frame_address_in_block (this_frame);
    537  1.1  christos   if (in_plt_section (addr_in_block))
    538  1.1  christos     return 1;
    539  1.1  christos 
    540  1.1  christos   return 0;
    541  1.1  christos }
    542  1.1  christos 
    543  1.1  christos static const struct frame_unwind tic6x_stub_unwind =
    544  1.1  christos {
    545  1.1  christos   NORMAL_FRAME,
    546  1.1  christos   default_frame_unwind_stop_reason,
    547  1.1  christos   tic6x_stub_this_id,
    548  1.1  christos   tic6x_frame_prev_register,
    549  1.1  christos   NULL,
    550  1.1  christos   tic6x_stub_unwind_sniffer
    551  1.1  christos };
    552  1.1  christos 
    553  1.1  christos /* Return the instruction on address PC.  */
    554  1.1  christos 
    555  1.1  christos static unsigned long
    556  1.1  christos tic6x_fetch_instruction (struct gdbarch *gdbarch, CORE_ADDR pc)
    557  1.1  christos {
    558  1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    559  1.1  christos   return read_memory_unsigned_integer (pc, TIC6X_OPCODE_SIZE, byte_order);
    560  1.1  christos }
    561  1.1  christos 
    562  1.1  christos /* Compute the condition of INST if it is a conditional instruction.  Always
    563  1.1  christos    return 1 if INST is not a conditional instruction.  */
    564  1.1  christos 
    565  1.1  christos static int
    566  1.7  christos tic6x_condition_true (struct regcache *regcache, unsigned long inst)
    567  1.1  christos {
    568  1.1  christos   int register_number;
    569  1.1  christos   int register_value;
    570  1.1  christos   static const int register_numbers[8] = { -1, 16, 17, 18, 1, 2, 0, -1 };
    571  1.1  christos 
    572  1.1  christos   register_number = register_numbers[(inst >> 29) & 7];
    573  1.1  christos   if (register_number == -1)
    574  1.1  christos     return 1;
    575  1.1  christos 
    576  1.7  christos   register_value = regcache_raw_get_signed (regcache, register_number);
    577  1.1  christos   if ((inst & 0x10000000) != 0)
    578  1.1  christos     return register_value == 0;
    579  1.1  christos   return register_value != 0;
    580  1.1  christos }
    581  1.1  christos 
    582  1.1  christos /* Get the register number by decoding raw bits REG, SIDE, and CROSSPATH in
    583  1.1  christos    instruction.  */
    584  1.1  christos 
    585  1.1  christos static int
    586  1.1  christos tic6x_register_number (int reg, int side, int crosspath)
    587  1.1  christos {
    588  1.1  christos   int r = (reg & 15) | ((crosspath ^ side) << 4);
    589  1.1  christos   if ((reg & 16) != 0) /* A16 - A31, B16 - B31 */
    590  1.1  christos     r += 37;
    591  1.1  christos   return r;
    592  1.1  christos }
    593  1.1  christos 
    594  1.1  christos static int
    595  1.1  christos tic6x_extract_signed_field (int value, int low_bit, int bits)
    596  1.1  christos {
    597  1.1  christos   int mask = (1 << bits) - 1;
    598  1.1  christos   int r = (value >> low_bit) & mask;
    599  1.1  christos   if ((r & (1 << (bits - 1))) != 0)
    600  1.1  christos     r -= mask + 1;
    601  1.1  christos   return r;
    602  1.1  christos }
    603  1.1  christos 
    604  1.1  christos /* Determine where to set a single step breakpoint.  */
    605  1.1  christos 
    606  1.1  christos static CORE_ADDR
    607  1.7  christos tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
    608  1.1  christos {
    609  1.7  christos   struct gdbarch *gdbarch = get_regcache_arch (regcache);
    610  1.1  christos   unsigned long inst;
    611  1.1  christos   int register_number;
    612  1.1  christos   int last = 0;
    613  1.1  christos 
    614  1.1  christos   do
    615  1.1  christos     {
    616  1.1  christos       inst = tic6x_fetch_instruction (gdbarch, pc);
    617  1.1  christos 
    618  1.1  christos       last = !(inst & 1);
    619  1.1  christos 
    620  1.1  christos       if (inst == TIC6X_INST_SWE)
    621  1.1  christos 	{
    622  1.1  christos 	  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
    623  1.1  christos 
    624  1.1  christos 	  if (tdep->syscall_next_pc != NULL)
    625  1.7  christos 	    return tdep->syscall_next_pc (get_current_frame ());
    626  1.1  christos 	}
    627  1.1  christos 
    628  1.7  christos       if (tic6x_condition_true (regcache, inst))
    629  1.1  christos 	{
    630  1.1  christos 	  if ((inst & 0x0000007c) == 0x00000010)
    631  1.1  christos 	    {
    632  1.1  christos 	      /* B with displacement */
    633  1.1  christos 	      pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
    634  1.1  christos 	      pc += tic6x_extract_signed_field (inst, 7, 21) << 2;
    635  1.1  christos 	      break;
    636  1.1  christos 	    }
    637  1.1  christos 	  if ((inst & 0x0f83effc) == 0x00000360)
    638  1.1  christos 	    {
    639  1.1  christos 	      /* B with register */
    640  1.1  christos 
    641  1.1  christos 	      register_number = tic6x_register_number ((inst >> 18) & 0x1f,
    642  1.1  christos 						       INST_S_BIT (inst),
    643  1.1  christos 						       INST_X_BIT (inst));
    644  1.7  christos 	      pc = regcache_raw_get_unsigned (regcache, register_number);
    645  1.1  christos 	      break;
    646  1.1  christos 	    }
    647  1.1  christos 	  if ((inst & 0x00001ffc) == 0x00001020)
    648  1.1  christos 	    {
    649  1.1  christos 	      /* BDEC */
    650  1.1  christos 	      register_number = tic6x_register_number ((inst >> 23) & 0x1f,
    651  1.1  christos 						       INST_S_BIT (inst), 0);
    652  1.7  christos 	      if (regcache_raw_get_signed (regcache, register_number) >= 0)
    653  1.1  christos 		{
    654  1.1  christos 		  pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
    655  1.1  christos 		  pc += tic6x_extract_signed_field (inst, 7, 10) << 2;
    656  1.1  christos 		}
    657  1.1  christos 	      break;
    658  1.1  christos 	    }
    659  1.1  christos 	  if ((inst & 0x00001ffc) == 0x00000120)
    660  1.1  christos 	    {
    661  1.1  christos 	      /* BNOP with displacement */
    662  1.1  christos 	      pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
    663  1.1  christos 	      pc += tic6x_extract_signed_field (inst, 16, 12) << 2;
    664  1.1  christos 	      break;
    665  1.1  christos 	    }
    666  1.1  christos 	  if ((inst & 0x0f830ffe) == 0x00800362)
    667  1.1  christos 	    {
    668  1.1  christos 	      /* BNOP with register */
    669  1.1  christos 	      register_number = tic6x_register_number ((inst >> 18) & 0x1f,
    670  1.1  christos 						       1, INST_X_BIT (inst));
    671  1.7  christos 	      pc = regcache_raw_get_unsigned (regcache, register_number);
    672  1.1  christos 	      break;
    673  1.1  christos 	    }
    674  1.1  christos 	  if ((inst & 0x00001ffc) == 0x00000020)
    675  1.1  christos 	    {
    676  1.1  christos 	      /* BPOS */
    677  1.1  christos 	      register_number = tic6x_register_number ((inst >> 23) & 0x1f,
    678  1.1  christos 						       INST_S_BIT (inst), 0);
    679  1.7  christos 	      if (regcache_raw_get_signed (regcache, register_number) >= 0)
    680  1.1  christos 		{
    681  1.1  christos 		  pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
    682  1.1  christos 		  pc += tic6x_extract_signed_field (inst, 13, 10) << 2;
    683  1.1  christos 		}
    684  1.1  christos 	      break;
    685  1.1  christos 	    }
    686  1.1  christos 	  if ((inst & 0xf000007c) == 0x10000010)
    687  1.1  christos 	    {
    688  1.1  christos 	      /* CALLP */
    689  1.1  christos 	      pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
    690  1.1  christos 	      pc += tic6x_extract_signed_field (inst, 7, 21) << 2;
    691  1.1  christos 	      break;
    692  1.1  christos 	    }
    693  1.1  christos 	}
    694  1.1  christos       pc += TIC6X_OPCODE_SIZE;
    695  1.1  christos     }
    696  1.1  christos   while (!last);
    697  1.1  christos   return pc;
    698  1.1  christos }
    699  1.1  christos 
    700  1.1  christos /* This is the implementation of gdbarch method software_single_step.  */
    701  1.1  christos 
    702  1.7  christos static VEC (CORE_ADDR) *
    703  1.7  christos tic6x_software_single_step (struct regcache *regcache)
    704  1.1  christos {
    705  1.7  christos   CORE_ADDR next_pc = tic6x_get_next_pc (regcache, regcache_read_pc (regcache));
    706  1.7  christos   VEC (CORE_ADDR) *next_pcs = NULL;
    707  1.1  christos 
    708  1.7  christos   VEC_safe_push (CORE_ADDR, next_pcs, next_pc);
    709  1.1  christos 
    710  1.7  christos   return next_pcs;
    711  1.1  christos }
    712  1.1  christos 
    713  1.1  christos /* This is the implementation of gdbarch method frame_align.  */
    714  1.1  christos 
    715  1.1  christos static CORE_ADDR
    716  1.1  christos tic6x_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
    717  1.1  christos {
    718  1.1  christos   return align_down (addr, 8);
    719  1.1  christos }
    720  1.1  christos 
    721  1.1  christos /* Given a return value in REGCACHE with a type VALTYPE, extract and copy its
    722  1.1  christos    value into VALBUF.  */
    723  1.1  christos 
    724  1.1  christos static void
    725  1.1  christos tic6x_extract_return_value (struct type *valtype, struct regcache *regcache,
    726  1.1  christos 			    enum bfd_endian byte_order, gdb_byte *valbuf)
    727  1.1  christos {
    728  1.1  christos   int len = TYPE_LENGTH (valtype);
    729  1.1  christos 
    730  1.1  christos   /* pointer types are returned in register A4,
    731  1.1  christos      up to 32-bit types in A4
    732  1.1  christos      up to 64-bit types in A5:A4  */
    733  1.1  christos   if (len <= 4)
    734  1.1  christos     {
    735  1.1  christos       /* In big-endian,
    736  1.1  christos 	 - one-byte structure or union occupies the LSB of single even register.
    737  1.1  christos 	 - for two-byte structure or union, the first byte occupies byte 1 of
    738  1.1  christos 	 register and the second byte occupies byte 0.
    739  1.1  christos 	 so, we read the contents in VAL from the LSBs of register.  */
    740  1.1  christos       if (len < 3 && byte_order == BFD_ENDIAN_BIG)
    741  1.1  christos 	regcache_cooked_read_part (regcache, TIC6X_A4_REGNUM, 4 - len, len,
    742  1.1  christos 				   valbuf);
    743  1.1  christos       else
    744  1.1  christos 	regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf);
    745  1.1  christos     }
    746  1.1  christos   else if (len <= 8)
    747  1.1  christos     {
    748  1.1  christos       /* For a 5-8 byte structure or union in big-endian, the first byte
    749  1.1  christos 	 occupies byte 3 (the MSB) of the upper (odd) register and the
    750  1.1  christos 	 remaining bytes fill the decreasingly significant bytes.  5-7
    751  1.1  christos 	 byte structures or unions have padding in the LSBs of the
    752  1.1  christos 	 lower (even) register.  */
    753  1.1  christos       if (byte_order == BFD_ENDIAN_BIG)
    754  1.1  christos 	{
    755  1.1  christos 	  regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf + 4);
    756  1.1  christos 	  regcache_cooked_read (regcache, TIC6X_A5_REGNUM, valbuf);
    757  1.1  christos 	}
    758  1.1  christos       else
    759  1.1  christos 	{
    760  1.1  christos 	  regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf);
    761  1.1  christos 	  regcache_cooked_read (regcache, TIC6X_A5_REGNUM, valbuf + 4);
    762  1.1  christos 	}
    763  1.1  christos     }
    764  1.1  christos }
    765  1.1  christos 
    766  1.1  christos /* Write into appropriate registers a function return value
    767  1.1  christos    of type TYPE, given in virtual format.  */
    768  1.1  christos 
    769  1.1  christos static void
    770  1.1  christos tic6x_store_return_value (struct type *valtype, struct regcache *regcache,
    771  1.1  christos 			  enum bfd_endian byte_order, const gdb_byte *valbuf)
    772  1.1  christos {
    773  1.1  christos   int len = TYPE_LENGTH (valtype);
    774  1.1  christos 
    775  1.1  christos   /* return values of up to 8 bytes are returned in A5:A4 */
    776  1.1  christos 
    777  1.1  christos   if (len <= 4)
    778  1.1  christos     {
    779  1.1  christos       if (len < 3 && byte_order == BFD_ENDIAN_BIG)
    780  1.1  christos 	regcache_cooked_write_part (regcache, TIC6X_A4_REGNUM, 4 - len, len,
    781  1.1  christos 				    valbuf);
    782  1.1  christos       else
    783  1.1  christos 	regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf);
    784  1.1  christos     }
    785  1.1  christos   else if (len <= 8)
    786  1.1  christos     {
    787  1.1  christos       if (byte_order == BFD_ENDIAN_BIG)
    788  1.1  christos 	{
    789  1.1  christos 	  regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf + 4);
    790  1.1  christos 	  regcache_cooked_write (regcache, TIC6X_A5_REGNUM, valbuf);
    791  1.1  christos 	}
    792  1.1  christos       else
    793  1.1  christos 	{
    794  1.1  christos 	  regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf);
    795  1.1  christos 	  regcache_cooked_write (regcache, TIC6X_A5_REGNUM, valbuf + 4);
    796  1.1  christos 	}
    797  1.1  christos     }
    798  1.1  christos }
    799  1.1  christos 
    800  1.1  christos /* This is the implementation of gdbarch method return_value.  */
    801  1.1  christos 
    802  1.1  christos static enum return_value_convention
    803  1.1  christos tic6x_return_value (struct gdbarch *gdbarch, struct value *function,
    804  1.1  christos 		    struct type *type, struct regcache *regcache,
    805  1.1  christos 		    gdb_byte *readbuf, const gdb_byte *writebuf)
    806  1.1  christos {
    807  1.1  christos   /* In C++, when function returns an object, even its size is small
    808  1.1  christos      enough, it stii has to be passed via reference, pointed by register
    809  1.1  christos      A3.  */
    810  1.1  christos   if (current_language->la_language == language_cplus)
    811  1.1  christos     {
    812  1.1  christos       if (type != NULL)
    813  1.1  christos 	{
    814  1.6  christos 	  type = check_typedef (type);
    815  1.1  christos 	  if (language_pass_by_reference (type))
    816  1.1  christos 	    return RETURN_VALUE_STRUCT_CONVENTION;
    817  1.1  christos 	}
    818  1.1  christos     }
    819  1.1  christos 
    820  1.1  christos   if (TYPE_LENGTH (type) > 8)
    821  1.1  christos     return RETURN_VALUE_STRUCT_CONVENTION;
    822  1.1  christos 
    823  1.1  christos   if (readbuf)
    824  1.1  christos     tic6x_extract_return_value (type, regcache,
    825  1.1  christos 				gdbarch_byte_order (gdbarch), readbuf);
    826  1.1  christos   if (writebuf)
    827  1.1  christos     tic6x_store_return_value (type, regcache,
    828  1.1  christos 			      gdbarch_byte_order (gdbarch), writebuf);
    829  1.1  christos 
    830  1.1  christos   return RETURN_VALUE_REGISTER_CONVENTION;
    831  1.1  christos }
    832  1.1  christos 
    833  1.1  christos /* This is the implementation of gdbarch method dummy_id.  */
    834  1.1  christos 
    835  1.1  christos static struct frame_id
    836  1.1  christos tic6x_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
    837  1.1  christos {
    838  1.1  christos   return frame_id_build
    839  1.1  christos     (get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM),
    840  1.1  christos      get_frame_pc (this_frame));
    841  1.1  christos }
    842  1.1  christos 
    843  1.1  christos /* Get the alignment requirement of TYPE.  */
    844  1.1  christos 
    845  1.1  christos static int
    846  1.1  christos tic6x_arg_type_alignment (struct type *type)
    847  1.1  christos {
    848  1.1  christos   int len = TYPE_LENGTH (check_typedef (type));
    849  1.1  christos   enum type_code typecode = TYPE_CODE (check_typedef (type));
    850  1.1  christos 
    851  1.1  christos   if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
    852  1.1  christos     {
    853  1.1  christos       /* The stack alignment of a structure (and union) passed by value is the
    854  1.1  christos 	 smallest power of two greater than or equal to its size.
    855  1.1  christos 	 This cannot exceed 8 bytes, which is the largest allowable size for
    856  1.1  christos 	 a structure passed by value.  */
    857  1.1  christos 
    858  1.1  christos       if (len <= 2)
    859  1.1  christos 	return len;
    860  1.1  christos       else if (len <= 4)
    861  1.1  christos 	return 4;
    862  1.1  christos       else if (len <= 8)
    863  1.1  christos 	return 8;
    864  1.1  christos       else
    865  1.1  christos 	gdb_assert_not_reached ("unexpected length of data");
    866  1.1  christos     }
    867  1.1  christos   else
    868  1.1  christos     {
    869  1.1  christos       if (len <= 4)
    870  1.1  christos 	return 4;
    871  1.1  christos       else if (len == 8)
    872  1.1  christos 	{
    873  1.1  christos 	  if (typecode == TYPE_CODE_COMPLEX)
    874  1.1  christos 	    return 4;
    875  1.1  christos 	  else
    876  1.1  christos 	    return 8;
    877  1.1  christos 	}
    878  1.1  christos       else if (len == 16)
    879  1.1  christos 	{
    880  1.1  christos 	  if (typecode == TYPE_CODE_COMPLEX)
    881  1.1  christos 	    return 8;
    882  1.1  christos 	  else
    883  1.1  christos 	    return 16;
    884  1.1  christos 	}
    885  1.1  christos       else
    886  1.1  christos 	internal_error (__FILE__, __LINE__, _("unexpected length %d of type"),
    887  1.1  christos 			len);
    888  1.1  christos     }
    889  1.1  christos }
    890  1.1  christos 
    891  1.1  christos /* This is the implementation of gdbarch method push_dummy_call.  */
    892  1.1  christos 
    893  1.1  christos static CORE_ADDR
    894  1.1  christos tic6x_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
    895  1.1  christos 		       struct regcache *regcache, CORE_ADDR bp_addr,
    896  1.1  christos 		       int nargs, struct value **args, CORE_ADDR sp,
    897  1.1  christos 		       int struct_return, CORE_ADDR struct_addr)
    898  1.1  christos {
    899  1.1  christos   int argreg = 0;
    900  1.1  christos   int argnum;
    901  1.1  christos   int stack_offset = 4;
    902  1.1  christos   int references_offset = 4;
    903  1.1  christos   CORE_ADDR func_addr = find_function_addr (function, NULL);
    904  1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    905  1.1  christos   struct type *func_type = value_type (function);
    906  1.1  christos   /* The first arg passed on stack.  Mostly the first 10 args are passed by
    907  1.1  christos      registers.  */
    908  1.1  christos   int first_arg_on_stack = 10;
    909  1.1  christos 
    910  1.1  christos   /* Set the return address register to point to the entry point of
    911  1.1  christos      the program, where a breakpoint lies in wait.  */
    912  1.1  christos   regcache_cooked_write_unsigned (regcache, TIC6X_RA_REGNUM, bp_addr);
    913  1.1  christos 
    914  1.1  christos   /* The caller must pass an argument in A3 containing a destination address
    915  1.1  christos      for the returned value.  The callee returns the object by copying it to
    916  1.1  christos      the address in A3.  */
    917  1.1  christos   if (struct_return)
    918  1.1  christos     regcache_cooked_write_unsigned (regcache, 3, struct_addr);
    919  1.1  christos 
    920  1.1  christos   /* Determine the type of this function.  */
    921  1.1  christos   func_type = check_typedef (func_type);
    922  1.1  christos   if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
    923  1.1  christos     func_type = check_typedef (TYPE_TARGET_TYPE (func_type));
    924  1.1  christos 
    925  1.1  christos   gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
    926  1.1  christos 	      || TYPE_CODE (func_type) == TYPE_CODE_METHOD);
    927  1.1  christos 
    928  1.1  christos   /* For a variadic C function, the last explicitly declared argument and all
    929  1.1  christos      remaining arguments are passed on the stack.  */
    930  1.1  christos   if (TYPE_VARARGS (func_type))
    931  1.1  christos     first_arg_on_stack = TYPE_NFIELDS (func_type) - 1;
    932  1.1  christos 
    933  1.1  christos   /* Now make space on the stack for the args.  */
    934  1.1  christos   for (argnum = 0; argnum < nargs; argnum++)
    935  1.1  christos     {
    936  1.1  christos       int len = align_up (TYPE_LENGTH (value_type (args[argnum])), 4);
    937  1.1  christos       if (argnum >= 10 - argreg)
    938  1.1  christos 	references_offset += len;
    939  1.1  christos       stack_offset += len;
    940  1.1  christos     }
    941  1.1  christos   sp -= stack_offset;
    942  1.1  christos   /* SP should be 8-byte aligned, see C6000 ABI section 4.4.1
    943  1.1  christos      Stack Alignment.  */
    944  1.1  christos   sp = align_down (sp, 8);
    945  1.1  christos   stack_offset = 4;
    946  1.1  christos 
    947  1.1  christos   /* Now load as many as possible of the first arguments into
    948  1.1  christos      registers, and push the rest onto the stack.  Loop through args
    949  1.1  christos      from first to last.  */
    950  1.1  christos   for (argnum = 0; argnum < nargs; argnum++)
    951  1.1  christos     {
    952  1.1  christos       const gdb_byte *val;
    953  1.1  christos       struct value *arg = args[argnum];
    954  1.1  christos       struct type *arg_type = check_typedef (value_type (arg));
    955  1.1  christos       int len = TYPE_LENGTH (arg_type);
    956  1.1  christos       enum type_code typecode = TYPE_CODE (arg_type);
    957  1.1  christos 
    958  1.1  christos       val = value_contents (arg);
    959  1.1  christos 
    960  1.1  christos       /* Copy the argument to general registers or the stack in
    961  1.1  christos          register-sized pieces.  */
    962  1.1  christos       if (argreg < first_arg_on_stack)
    963  1.1  christos 	{
    964  1.1  christos 	  if (len <= 4)
    965  1.1  christos 	    {
    966  1.1  christos 	      if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
    967  1.1  christos 		{
    968  1.1  christos 		  /* In big-endian,
    969  1.1  christos 		     - one-byte structure or union occupies the LSB of single
    970  1.1  christos 		     even register.
    971  1.1  christos 		     - for two-byte structure or union, the first byte
    972  1.1  christos 		     occupies byte 1 of register and the second byte occupies
    973  1.1  christos 		     byte 0.
    974  1.1  christos 		     so, we write the contents in VAL to the lsp of
    975  1.1  christos 		     register.  */
    976  1.1  christos 		  if (len < 3 && byte_order == BFD_ENDIAN_BIG)
    977  1.1  christos 		    regcache_cooked_write_part (regcache, arg_regs[argreg],
    978  1.1  christos 						4 - len, len, val);
    979  1.1  christos 		  else
    980  1.1  christos 		    regcache_cooked_write (regcache, arg_regs[argreg], val);
    981  1.1  christos 		}
    982  1.1  christos 	      else
    983  1.1  christos 		{
    984  1.1  christos 		  /* The argument is being passed by value in a single
    985  1.1  christos 		     register.  */
    986  1.1  christos 		  CORE_ADDR regval = extract_unsigned_integer (val, len,
    987  1.1  christos 							       byte_order);
    988  1.1  christos 
    989  1.1  christos 		  regcache_cooked_write_unsigned (regcache, arg_regs[argreg],
    990  1.1  christos 						  regval);
    991  1.1  christos 		}
    992  1.1  christos 	    }
    993  1.1  christos 	  else
    994  1.1  christos 	    {
    995  1.1  christos 	      if (len <= 8)
    996  1.1  christos 		{
    997  1.1  christos 		  if (typecode == TYPE_CODE_STRUCT
    998  1.1  christos 		      || typecode == TYPE_CODE_UNION)
    999  1.1  christos 		    {
   1000  1.1  christos 		      /* For a 5-8 byte structure or union in big-endian, the
   1001  1.1  christos 		         first byte occupies byte 3 (the MSB) of the upper (odd)
   1002  1.1  christos 		         register and the remaining bytes fill the decreasingly
   1003  1.1  christos 		         significant bytes.  5-7 byte structures or unions have
   1004  1.1  christos 		         padding in the LSBs of the lower (even) register.  */
   1005  1.1  christos 		      if (byte_order == BFD_ENDIAN_BIG)
   1006  1.1  christos 			{
   1007  1.1  christos 			  regcache_cooked_write (regcache,
   1008  1.1  christos 						 arg_regs[argreg] + 1, val);
   1009  1.1  christos 			  regcache_cooked_write_part (regcache,
   1010  1.1  christos 						      arg_regs[argreg], 0,
   1011  1.1  christos 						      len - 4, val + 4);
   1012  1.1  christos 			}
   1013  1.1  christos 		      else
   1014  1.1  christos 			{
   1015  1.1  christos 			  regcache_cooked_write (regcache, arg_regs[argreg],
   1016  1.1  christos 						 val);
   1017  1.1  christos 			  regcache_cooked_write_part (regcache,
   1018  1.1  christos 						      arg_regs[argreg] + 1, 0,
   1019  1.1  christos 						      len - 4, val + 4);
   1020  1.1  christos 			}
   1021  1.1  christos 		    }
   1022  1.1  christos 		  else
   1023  1.1  christos 		    {
   1024  1.1  christos 		      /* The argument is being passed by value in a pair of
   1025  1.1  christos 		         registers.  */
   1026  1.1  christos 		      ULONGEST regval = extract_unsigned_integer (val, len,
   1027  1.1  christos 								  byte_order);
   1028  1.1  christos 
   1029  1.1  christos 		      regcache_cooked_write_unsigned (regcache,
   1030  1.1  christos 						      arg_regs[argreg],
   1031  1.1  christos 						      regval);
   1032  1.1  christos 		      regcache_cooked_write_unsigned (regcache,
   1033  1.1  christos 						      arg_regs[argreg] + 1,
   1034  1.1  christos 						      regval >> 32);
   1035  1.1  christos 		    }
   1036  1.1  christos 		}
   1037  1.1  christos 	      else
   1038  1.1  christos 		{
   1039  1.1  christos 		  /* The argument is being passed by reference in a single
   1040  1.1  christos 		     register.  */
   1041  1.1  christos 		  CORE_ADDR addr;
   1042  1.1  christos 
   1043  1.1  christos 		  /* It is not necessary to adjust REFERENCES_OFFSET to
   1044  1.1  christos 		     8-byte aligned in some cases, in which 4-byte alignment
   1045  1.1  christos 		     is sufficient.  For simplicity, we adjust
   1046  1.1  christos 		     REFERENCES_OFFSET to 8-byte aligned.  */
   1047  1.1  christos 		  references_offset = align_up (references_offset, 8);
   1048  1.1  christos 
   1049  1.1  christos 		  addr = sp + references_offset;
   1050  1.1  christos 		  write_memory (addr, val, len);
   1051  1.1  christos 		  references_offset += align_up (len, 4);
   1052  1.1  christos 		  regcache_cooked_write_unsigned (regcache, arg_regs[argreg],
   1053  1.1  christos 						  addr);
   1054  1.1  christos 		}
   1055  1.1  christos 	    }
   1056  1.1  christos 	  argreg++;
   1057  1.1  christos 	}
   1058  1.1  christos       else
   1059  1.1  christos 	{
   1060  1.1  christos 	  /* The argument is being passed on the stack.  */
   1061  1.1  christos 	  CORE_ADDR addr;
   1062  1.1  christos 
   1063  1.1  christos 	  /* There are six different cases of alignment, and these rules can
   1064  1.1  christos 	     be found in tic6x_arg_type_alignment:
   1065  1.1  christos 
   1066  1.1  christos 	     1) 4-byte aligned if size is less than or equal to 4 byte, such
   1067  1.1  christos 	     as short, int, struct, union etc.
   1068  1.1  christos 	     2) 8-byte aligned if size is less than or equal to 8-byte, such
   1069  1.1  christos 	     as double, long long,
   1070  1.1  christos 	     3) 4-byte aligned if it is of type _Complex float, even its size
   1071  1.1  christos 	     is 8-byte.
   1072  1.1  christos 	     4) 8-byte aligned if it is of type _Complex double or _Complex
   1073  1.1  christos 	     long double, even its size is 16-byte.  Because, the address of
   1074  1.1  christos 	     variable is passed as reference.
   1075  1.1  christos 	     5) struct and union larger than 8-byte are passed by reference, so
   1076  1.1  christos 	     it is 4-byte aligned.
   1077  1.1  christos 	     6) struct and union of size between 4 byte and 8 byte varies.
   1078  1.1  christos 	     alignment of struct variable is the alignment of its first field,
   1079  1.1  christos 	     while alignment of union variable is the max of all its fields'
   1080  1.1  christos 	     alignment.  */
   1081  1.1  christos 
   1082  1.1  christos 	  if (len <= 4)
   1083  1.1  christos 	    ; /* Default is 4-byte aligned.  Nothing to be done.  */
   1084  1.1  christos 	  else if (len <= 8)
   1085  1.1  christos 	    stack_offset = align_up (stack_offset,
   1086  1.1  christos 				     tic6x_arg_type_alignment (arg_type));
   1087  1.1  christos 	  else if (len == 16)
   1088  1.1  christos 	    {
   1089  1.1  christos 	      /* _Complex double or _Complex long double */
   1090  1.1  christos 	      if (typecode == TYPE_CODE_COMPLEX)
   1091  1.1  christos 		{
   1092  1.1  christos 		  /* The argument is being passed by reference on stack.  */
   1093  1.1  christos 		  CORE_ADDR addr;
   1094  1.1  christos 		  references_offset = align_up (references_offset, 8);
   1095  1.1  christos 
   1096  1.1  christos 		  addr = sp + references_offset;
   1097  1.1  christos 		  /* Store variable on stack.  */
   1098  1.1  christos 		  write_memory (addr, val, len);
   1099  1.1  christos 
   1100  1.1  christos 		  references_offset += align_up (len, 4);
   1101  1.1  christos 
   1102  1.1  christos 		  /* Pass the address of variable on stack as reference.  */
   1103  1.1  christos 		  store_unsigned_integer ((gdb_byte *) val, 4, byte_order,
   1104  1.1  christos 					  addr);
   1105  1.1  christos 		  len = 4;
   1106  1.1  christos 
   1107  1.1  christos 		}
   1108  1.1  christos 	      else
   1109  1.1  christos 		internal_error (__FILE__, __LINE__,
   1110  1.1  christos 				_("unexpected type %d of arg %d"),
   1111  1.1  christos 				typecode, argnum);
   1112  1.1  christos 	    }
   1113  1.1  christos 	  else
   1114  1.1  christos 	    internal_error (__FILE__, __LINE__,
   1115  1.1  christos 			    _("unexpected length %d of arg %d"), len, argnum);
   1116  1.1  christos 
   1117  1.1  christos 	  addr = sp + stack_offset;
   1118  1.1  christos 	  write_memory (addr, val, len);
   1119  1.1  christos 	  stack_offset += align_up (len, 4);
   1120  1.1  christos 	}
   1121  1.1  christos     }
   1122  1.1  christos 
   1123  1.1  christos   regcache_cooked_write_signed (regcache, TIC6X_SP_REGNUM, sp);
   1124  1.1  christos 
   1125  1.1  christos   /* Return adjusted stack pointer.  */
   1126  1.1  christos   return sp;
   1127  1.1  christos }
   1128  1.1  christos 
   1129  1.5  christos /* This is the implementation of gdbarch method stack_frame_destroyed_p.  */
   1130  1.1  christos 
   1131  1.1  christos static int
   1132  1.5  christos tic6x_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
   1133  1.1  christos {
   1134  1.1  christos   unsigned long inst = tic6x_fetch_instruction (gdbarch, pc);
   1135  1.1  christos   /* Normally, the epilogue is composed by instruction `b .S2 b3'.  */
   1136  1.1  christos   if ((inst & 0x0f83effc) == 0x360)
   1137  1.1  christos     {
   1138  1.1  christos       unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f,
   1139  1.1  christos 						 INST_S_BIT (inst),
   1140  1.1  christos 						 INST_X_BIT (inst));
   1141  1.1  christos       if (src2 == TIC6X_RA_REGNUM)
   1142  1.1  christos 	return 1;
   1143  1.1  christos     }
   1144  1.1  christos 
   1145  1.1  christos   return 0;
   1146  1.1  christos }
   1147  1.1  christos 
   1148  1.1  christos /* This is the implementation of gdbarch method get_longjmp_target.  */
   1149  1.1  christos 
   1150  1.1  christos static int
   1151  1.1  christos tic6x_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   1152  1.1  christos {
   1153  1.1  christos   struct gdbarch *gdbarch = get_frame_arch (frame);
   1154  1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   1155  1.1  christos   CORE_ADDR jb_addr;
   1156  1.1  christos   gdb_byte buf[4];
   1157  1.1  christos 
   1158  1.1  christos   /* JMP_BUF is passed by reference in A4.  */
   1159  1.1  christos   jb_addr = get_frame_register_unsigned (frame, 4);
   1160  1.1  christos 
   1161  1.1  christos   /* JMP_BUF contains 13 elements of type int, and return address is stored
   1162  1.1  christos      in the last slot.  */
   1163  1.1  christos   if (target_read_memory (jb_addr + 12 * 4, buf, 4))
   1164  1.1  christos     return 0;
   1165  1.1  christos 
   1166  1.1  christos   *pc = extract_unsigned_integer (buf, 4, byte_order);
   1167  1.1  christos 
   1168  1.1  christos   return 1;
   1169  1.1  christos }
   1170  1.1  christos 
   1171  1.1  christos /* This is the implementation of gdbarch method
   1172  1.1  christos    return_in_first_hidden_param_p.  */
   1173  1.1  christos 
   1174  1.1  christos static int
   1175  1.1  christos tic6x_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
   1176  1.1  christos 				      struct type *type)
   1177  1.1  christos {
   1178  1.1  christos   return 0;
   1179  1.1  christos }
   1180  1.1  christos 
   1181  1.1  christos static struct gdbarch *
   1182  1.1  christos tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   1183  1.1  christos {
   1184  1.1  christos   struct gdbarch *gdbarch;
   1185  1.1  christos   struct gdbarch_tdep *tdep;
   1186  1.1  christos   struct tdesc_arch_data *tdesc_data = NULL;
   1187  1.1  christos   const struct target_desc *tdesc = info.target_desc;
   1188  1.1  christos   int has_gp = 0;
   1189  1.1  christos 
   1190  1.1  christos   /* Check any target description for validity.  */
   1191  1.1  christos   if (tdesc_has_registers (tdesc))
   1192  1.1  christos     {
   1193  1.1  christos       const struct tdesc_feature *feature;
   1194  1.1  christos       int valid_p, i;
   1195  1.1  christos 
   1196  1.1  christos       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.core");
   1197  1.1  christos 
   1198  1.1  christos       if (feature == NULL)
   1199  1.1  christos 	return NULL;
   1200  1.1  christos 
   1201  1.1  christos       tdesc_data = tdesc_data_alloc ();
   1202  1.1  christos 
   1203  1.1  christos       valid_p = 1;
   1204  1.1  christos       for (i = 0; i < 32; i++)	/* A0 - A15, B0 - B15 */
   1205  1.1  christos 	valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
   1206  1.1  christos 					    tic6x_register_names[i]);
   1207  1.1  christos 
   1208  1.1  christos       /* CSR */
   1209  1.1  christos       valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
   1210  1.1  christos 					  tic6x_register_names[TIC6X_CSR_REGNUM]);
   1211  1.1  christos       valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
   1212  1.1  christos 					  tic6x_register_names[TIC6X_PC_REGNUM]);
   1213  1.1  christos 
   1214  1.1  christos       if (!valid_p)
   1215  1.1  christos 	{
   1216  1.1  christos 	  tdesc_data_cleanup (tdesc_data);
   1217  1.1  christos 	  return NULL;
   1218  1.1  christos 	}
   1219  1.1  christos 
   1220  1.1  christos       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.gp");
   1221  1.1  christos       if (feature)
   1222  1.1  christos 	{
   1223  1.1  christos 	  int j = 0;
   1224  1.1  christos 	  static const char *const gp[] =
   1225  1.1  christos 	    {
   1226  1.1  christos 	      "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23",
   1227  1.1  christos 	      "A24", "A25", "A26", "A27", "A28", "A29", "A30", "A31",
   1228  1.1  christos 	      "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23",
   1229  1.1  christos 	      "B24", "B25", "B26", "B27", "B28", "B29", "B30", "B31",
   1230  1.1  christos 	    };
   1231  1.1  christos 
   1232  1.1  christos 	  has_gp = 1;
   1233  1.1  christos 	  valid_p = 1;
   1234  1.1  christos 	  for (j = 0; j < 32; j++)	/* A16 - A31, B16 - B31 */
   1235  1.1  christos 	    valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
   1236  1.1  christos 						gp[j]);
   1237  1.1  christos 
   1238  1.1  christos 	  if (!valid_p)
   1239  1.1  christos 	    {
   1240  1.1  christos 	      tdesc_data_cleanup (tdesc_data);
   1241  1.1  christos 	      return NULL;
   1242  1.1  christos 	    }
   1243  1.1  christos 	}
   1244  1.1  christos 
   1245  1.1  christos       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.c6xp");
   1246  1.1  christos       if (feature)
   1247  1.1  christos 	{
   1248  1.1  christos 	  valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "TSR");
   1249  1.1  christos 	  valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "ILC");
   1250  1.1  christos 	  valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "RILC");
   1251  1.1  christos 
   1252  1.1  christos 	  if (!valid_p)
   1253  1.1  christos 	    {
   1254  1.1  christos 	      tdesc_data_cleanup (tdesc_data);
   1255  1.1  christos 	      return NULL;
   1256  1.1  christos 	    }
   1257  1.1  christos 	}
   1258  1.1  christos 
   1259  1.1  christos     }
   1260  1.1  christos 
   1261  1.1  christos   /* Find a candidate among extant architectures.  */
   1262  1.1  christos   for (arches = gdbarch_list_lookup_by_info (arches, &info);
   1263  1.1  christos        arches != NULL;
   1264  1.1  christos        arches = gdbarch_list_lookup_by_info (arches->next, &info))
   1265  1.1  christos     {
   1266  1.1  christos       tdep = gdbarch_tdep (arches->gdbarch);
   1267  1.1  christos 
   1268  1.1  christos       if (has_gp != tdep->has_gp)
   1269  1.1  christos 	continue;
   1270  1.1  christos 
   1271  1.1  christos       if (tdep && tdep->breakpoint)
   1272  1.1  christos 	return arches->gdbarch;
   1273  1.1  christos     }
   1274  1.1  christos 
   1275  1.6  christos   tdep = XCNEW (struct gdbarch_tdep);
   1276  1.1  christos 
   1277  1.1  christos   tdep->has_gp = has_gp;
   1278  1.1  christos   gdbarch = gdbarch_alloc (&info, tdep);
   1279  1.1  christos 
   1280  1.1  christos   /* Data type sizes.  */
   1281  1.1  christos   set_gdbarch_ptr_bit (gdbarch, 32);
   1282  1.1  christos   set_gdbarch_addr_bit (gdbarch, 32);
   1283  1.1  christos   set_gdbarch_short_bit (gdbarch, 16);
   1284  1.1  christos   set_gdbarch_int_bit (gdbarch, 32);
   1285  1.1  christos   set_gdbarch_long_bit (gdbarch, 32);
   1286  1.1  christos   set_gdbarch_long_long_bit (gdbarch, 64);
   1287  1.1  christos   set_gdbarch_float_bit (gdbarch, 32);
   1288  1.1  christos   set_gdbarch_double_bit (gdbarch, 64);
   1289  1.1  christos 
   1290  1.1  christos   set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
   1291  1.1  christos   set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
   1292  1.1  christos 
   1293  1.1  christos   /* The register set.  */
   1294  1.1  christos   set_gdbarch_num_regs (gdbarch, TIC6X_NUM_REGS);
   1295  1.1  christos   set_gdbarch_sp_regnum (gdbarch, TIC6X_SP_REGNUM);
   1296  1.1  christos   set_gdbarch_pc_regnum (gdbarch, TIC6X_PC_REGNUM);
   1297  1.1  christos 
   1298  1.1  christos   set_gdbarch_register_name (gdbarch, tic6x_register_name);
   1299  1.1  christos   set_gdbarch_register_type (gdbarch, tic6x_register_type);
   1300  1.1  christos 
   1301  1.1  christos   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   1302  1.1  christos 
   1303  1.1  christos   set_gdbarch_skip_prologue (gdbarch, tic6x_skip_prologue);
   1304  1.7  christos   set_gdbarch_breakpoint_kind_from_pc (gdbarch,
   1305  1.7  christos 				       tic6x_breakpoint_kind_from_pc);
   1306  1.7  christos   set_gdbarch_sw_breakpoint_from_kind (gdbarch,
   1307  1.7  christos 				       tic6x_sw_breakpoint_from_kind);
   1308  1.1  christos 
   1309  1.1  christos   set_gdbarch_unwind_pc (gdbarch, tic6x_unwind_pc);
   1310  1.1  christos   set_gdbarch_unwind_sp (gdbarch, tic6x_unwind_sp);
   1311  1.1  christos 
   1312  1.1  christos   /* Unwinding.  */
   1313  1.1  christos   dwarf2_append_unwinders (gdbarch);
   1314  1.1  christos 
   1315  1.1  christos   frame_unwind_append_unwinder (gdbarch, &tic6x_stub_unwind);
   1316  1.1  christos   frame_unwind_append_unwinder (gdbarch, &tic6x_frame_unwind);
   1317  1.3  christos   frame_base_set_default (gdbarch, &tic6x_frame_base);
   1318  1.1  christos 
   1319  1.1  christos   dwarf2_frame_set_init_reg (gdbarch, tic6x_dwarf2_frame_init_reg);
   1320  1.1  christos 
   1321  1.1  christos   /* Single stepping.  */
   1322  1.1  christos   set_gdbarch_software_single_step (gdbarch, tic6x_software_single_step);
   1323  1.1  christos 
   1324  1.1  christos   set_gdbarch_print_insn (gdbarch, tic6x_print_insn);
   1325  1.1  christos 
   1326  1.1  christos   /* Call dummy code.  */
   1327  1.1  christos   set_gdbarch_frame_align (gdbarch, tic6x_frame_align);
   1328  1.1  christos 
   1329  1.1  christos   set_gdbarch_return_value (gdbarch, tic6x_return_value);
   1330  1.1  christos 
   1331  1.1  christos   set_gdbarch_dummy_id (gdbarch, tic6x_dummy_id);
   1332  1.1  christos 
   1333  1.1  christos   /* Enable inferior call support.  */
   1334  1.1  christos   set_gdbarch_push_dummy_call (gdbarch, tic6x_push_dummy_call);
   1335  1.1  christos 
   1336  1.1  christos   set_gdbarch_get_longjmp_target (gdbarch, tic6x_get_longjmp_target);
   1337  1.1  christos 
   1338  1.5  christos   set_gdbarch_stack_frame_destroyed_p (gdbarch, tic6x_stack_frame_destroyed_p);
   1339  1.1  christos 
   1340  1.1  christos   set_gdbarch_return_in_first_hidden_param_p (gdbarch,
   1341  1.1  christos 					      tic6x_return_in_first_hidden_param_p);
   1342  1.1  christos 
   1343  1.1  christos   /* Hook in ABI-specific overrides, if they have been registered.  */
   1344  1.1  christos   gdbarch_init_osabi (info, gdbarch);
   1345  1.1  christos 
   1346  1.1  christos   if (tdesc_data)
   1347  1.1  christos     tdesc_use_registers (gdbarch, tdesc, tdesc_data);
   1348  1.1  christos 
   1349  1.1  christos   return gdbarch;
   1350  1.1  christos }
   1351  1.1  christos 
   1352  1.1  christos /* -Wmissing-prototypes */
   1353  1.1  christos extern initialize_file_ftype _initialize_tic6x_tdep;
   1354  1.1  christos 
   1355  1.1  christos void
   1356  1.1  christos _initialize_tic6x_tdep (void)
   1357  1.1  christos {
   1358  1.1  christos   register_gdbarch_init (bfd_arch_tic6x, tic6x_gdbarch_init);
   1359  1.1  christos 
   1360  1.1  christos   initialize_tdesc_tic6x_c64xp ();
   1361  1.1  christos   initialize_tdesc_tic6x_c64x ();
   1362  1.1  christos   initialize_tdesc_tic6x_c62x ();
   1363  1.1  christos }
   1364