gdb/tic6x-tdep.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Target dependent code for GDB on TI C6x systems.

  2.    Copyright (C) 2010-2015 Free Software Foundation, Inc.
  3.    Contributed by Andrew Jenner <andrew@codesourcery.com>
  4.    Contributed by Yao Qi <yao@codesourcery.com>

  5.    This file is part of GDB.

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

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

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

  16. #include "defs.h"
  17. #include "frame.h"
  18. #include "frame-unwind.h"
  19. #include "frame-base.h"
  20. #include "trad-frame.h"
  21. #include "dwarf2-frame.h"
  22. #include "symtab.h"
  23. #include "inferior.h"
  24. #include "gdbtypes.h"
  25. #include "gdbcore.h"
  26. #include "gdbcmd.h"
  27. #include "target.h"
  28. #include "dis-asm.h"
  29. #include "regcache.h"
  30. #include "value.h"
  31. #include "symfile.h"
  32. #include "arch-utils.h"
  33. #include "floatformat.h"
  34. #include "glibc-tdep.h"
  35. #include "infcall.h"
  36. #include "regset.h"
  37. #include "tramp-frame.h"
  38. #include "linux-tdep.h"
  39. #include "solib.h"
  40. #include "objfiles.h"
  41. #include "osabi.h"
  42. #include "tic6x-tdep.h"
  43. #include "language.h"
  44. #include "target-descriptions.h"

  45. #include "features/tic6x-c64xp.c"
  46. #include "features/tic6x-c64x.c"
  47. #include "features/tic6x-c62x.c"

  48. #define TIC6X_OPCODE_SIZE 4
  49. #define TIC6X_FETCH_PACKET_SIZE 32

  50. #define INST_S_BIT(INST) ((INST >> 1) & 1)
  51. #define INST_X_BIT(INST) ((INST >> 12) & 1)

  52. const gdb_byte tic6x_bkpt_illegal_opcode_be[] = { 0x56, 0x45, 0x43, 0x14 };
  53. const gdb_byte tic6x_bkpt_illegal_opcode_le[] = { 0x14, 0x43, 0x45, 0x56 };

  54. struct tic6x_unwind_cache
  55. {
  56.   /* The frame's base, optionally used by the high-level debug info.  */
  57.   CORE_ADDR base;

  58.   /* The previous frame's inner most stack address.  Used as this
  59.      frame ID's stack_addr.  */
  60.   CORE_ADDR cfa;

  61.   /* The address of the first instruction in this function */
  62.   CORE_ADDR pc;

  63.   /* Which register holds the return address for the frame.  */
  64.   int return_regnum;

  65.   /* The offset of register saved on stack.  If register is not saved, the
  66.      corresponding element is -1.  */
  67.   CORE_ADDR reg_saved[TIC6X_NUM_CORE_REGS];
  68. };


  69. /* Name of TI C6x core registers.  */
  70. static const char *const tic6x_register_names[] =
  71. {
  72.   "A0""A1""A2""A3"/*  0  1  2  3 */
  73.   "A4""A5""A6""A7"/*  4  5  6  7 */
  74.   "A8""A9""A10", "A11", /*  8  9 10 11 */
  75.   "A12", "A13", "A14", "A15", /* 12 13 14 15 */
  76.   "B0""B1""B2""B3"/* 16 17 18 19 */
  77.   "B4""B5""B6""B7"/* 20 21 22 23 */
  78.   "B8""B9""B10", "B11", /* 24 25 26 27 */
  79.   "B12", "B13", "B14", "B15", /* 28 29 30 31 */
  80.   "CSR", "PC",                /* 32 33       */
  81. };

  82. /* This array maps the arguments to the register number which passes argument
  83.    in function call according to C6000 ELF ABI.  */
  84. static const int arg_regs[] = { 4, 20, 6, 22, 8, 24, 10, 26, 12, 28 };

  85. /* This is the implementation of gdbarch method register_name.  */

  86. static const char *
  87. tic6x_register_name (struct gdbarch *gdbarch, int regno)
  88. {
  89.   if (regno < 0)
  90.     return NULL;

  91.   if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
  92.     return tdesc_register_name (gdbarch, regno);
  93.   else if (regno >= ARRAY_SIZE (tic6x_register_names))
  94.     return "";
  95.   else
  96.     return tic6x_register_names[regno];
  97. }

  98. /* This is the implementation of gdbarch method register_type.  */

  99. static struct type *
  100. tic6x_register_type (struct gdbarch *gdbarch, int regno)
  101. {

  102.   if (regno == TIC6X_PC_REGNUM)
  103.     return builtin_type (gdbarch)->builtin_func_ptr;
  104.   else
  105.     return builtin_type (gdbarch)->builtin_uint32;
  106. }

  107. static void
  108. tic6x_setup_default (struct tic6x_unwind_cache *cache)
  109. {
  110.   int i;

  111.   for (i = 0; i < TIC6X_NUM_CORE_REGS; i++)
  112.     cache->reg_saved[i] = -1;
  113. }

  114. static unsigned long tic6x_fetch_instruction (struct gdbarch *, CORE_ADDR);
  115. static int tic6x_register_number (int reg, int side, int crosspath);

  116. /* Do a full analysis of the prologue at START_PC and update CACHE accordingly.
  117.    Bail out early if CURRENT_PC is reached.  Returns the address of the first
  118.    instruction after the prologue.  */

  119. static CORE_ADDR
  120. tic6x_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR start_pc,
  121.                         const CORE_ADDR current_pc,
  122.                         struct tic6x_unwind_cache *cache,
  123.                         struct frame_info *this_frame)
  124. {
  125.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  126.   unsigned long inst;
  127.   unsigned int src_reg, base_reg, dst_reg;
  128.   int i;
  129.   CORE_ADDR pc = start_pc;
  130.   CORE_ADDR return_pc = start_pc;
  131.   int frame_base_offset_to_sp = 0;
  132.   /* Counter of non-stw instructions after first insn ` sub sp, xxx, sp'.  */
  133.   int non_stw_insn_counter = 0;

  134.   if (start_pc >= current_pc)
  135.     return_pc = current_pc;

  136.   cache->base = 0;

  137.   /* The landmarks in prologue is one or two SUB instructions to SP.
  138.      Instructions on setting up dsbt are in the last part of prologue, if
  139.      needed.  In maxim, prologue can be divided to three parts by two
  140.      `sub sp, xx, sp' insns.  */

  141.   /* Step 1: Look for the 1st and 2nd insn `sub sp, xx, sp',  in which, the
  142.      2nd one is optional.  */
  143.   while (pc < current_pc)
  144.     {
  145.       int offset = 0;

  146.       unsigned long inst = tic6x_fetch_instruction (gdbarch, pc);

  147.       if ((inst & 0x1ffc) == 0x1dc0 || (inst & 0x1ffc) == 0x1bc0
  148.           || (inst & 0x0ffc) == 0x9c0)
  149.         {
  150.           /* SUBAW/SUBAH/SUB, and src1 is ucst 5.  */
  151.           unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f,
  152.                                                      INST_S_BIT (inst), 0);
  153.           unsigned int dst = tic6x_register_number ((inst >> 23) & 0x1f,
  154.                                                     INST_S_BIT (inst), 0);

  155.           if (src2 == TIC6X_SP_REGNUM && dst == TIC6X_SP_REGNUM)
  156.             {
  157.               /* Extract const from insn SUBAW/SUBAH/SUB, and translate it to
  158.                  offset.  The constant offset is decoded in bit 13-17 in all
  159.                  these three kinds of instructions.  */
  160.               unsigned int ucst5 = (inst >> 13) & 0x1f;

  161.               if ((inst & 0x1ffc) == 0x1dc0)        /* SUBAW */
  162.                 frame_base_offset_to_sp += ucst5 << 2;
  163.               else if ((inst & 0x1ffc) == 0x1bc0)        /* SUBAH */
  164.                 frame_base_offset_to_sp += ucst5 << 1;
  165.               else if ((inst & 0x0ffc) == 0x9c0)        /* SUB */
  166.                 frame_base_offset_to_sp += ucst5;
  167.               else
  168.                 gdb_assert_not_reached ("unexpected instruction");

  169.               return_pc = pc + 4;
  170.             }
  171.         }
  172.       else if ((inst & 0x174) == 0x74)        /* stw SRC, *+b15(uconst) */
  173.         {
  174.           /* The y bit determines which file base is read from.  */
  175.           base_reg = tic6x_register_number ((inst >> 18) & 0x1f,
  176.                                             (inst >> 7) & 1, 0);

  177.           if (base_reg == TIC6X_SP_REGNUM)
  178.             {
  179.               src_reg = tic6x_register_number ((inst >> 23) & 0x1f,
  180.                                                INST_S_BIT (inst), 0);

  181.               cache->reg_saved[src_reg] = ((inst >> 13) & 0x1f) << 2;

  182.               return_pc = pc + 4;
  183.             }
  184.           non_stw_insn_counter = 0;
  185.         }
  186.       else
  187.         {
  188.           non_stw_insn_counter++;
  189.           /* Following instruction sequence may be emitted in prologue:

  190.              <+0>: subah .D2 b15,28,b15
  191.              <+4>: or .L2X 0,a4,b0
  192.              <+8>: || stw .D2T2 b14,*+b15(56)
  193.              <+12>:[!b0] b .S1 0xe50e4c1c <sleep+220>
  194.              <+16>:|| stw .D2T1 a10,*+b15(48)
  195.              <+20>:stw .D2T2 b3,*+b15(52)
  196.              <+24>:stw .D2T1 a4,*+b15(40)

  197.              we should look forward for next instruction instead of breaking loop
  198.              here.  So far, we allow almost two sequential non-stw instructions
  199.              in prologue.  */
  200.           if (non_stw_insn_counter >= 2)
  201.             break;
  202.         }


  203.       pc += 4;
  204.     }
  205.   /* Step 2: Skip insn on setting up dsbt if it is.  Usually, it looks like,
  206.      ldw .D2T2 *+b14(0),b14 */
  207.   inst = tic6x_fetch_instruction (gdbarch, pc);
  208.   /* The s bit determines which file dst will be loaded into, same effect as
  209.      other places.  */
  210.   dst_reg = tic6x_register_number ((inst >> 23) & 0x1f, (inst >> 1) & 1, 0);
  211.   /* The y bit (bit 7), instead of s bit, determines which file base be
  212.      used.  */
  213.   base_reg = tic6x_register_number ((inst >> 18) & 0x1f, (inst >> 7) & 1, 0);

  214.   if ((inst & 0x164) == 0x64        /* ldw */
  215.       && dst_reg == TIC6X_DP_REGNUM        /* dst is B14 */
  216.       && base_reg == TIC6X_DP_REGNUM)        /* baseR is B14 */
  217.     {
  218.       return_pc = pc + 4;
  219.     }

  220.   if (this_frame)
  221.     {
  222.       cache->base = get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM);

  223.       if (cache->reg_saved[TIC6X_FP_REGNUM] != -1)
  224.         {
  225.           /* If the FP now holds an offset from the CFA then this is a frame
  226.              which uses the frame pointer.  */

  227.           cache->cfa = get_frame_register_unsigned (this_frame,
  228.                                                     TIC6X_FP_REGNUM);
  229.         }
  230.       else
  231.         {
  232.           /* FP doesn't hold an offset from the CFA.  If SP still holds an
  233.              offset from the CFA then we might be in a function which omits
  234.              the frame pointer.  */

  235.           cache->cfa = cache->base + frame_base_offset_to_sp;
  236.         }
  237.     }

  238.   /* Adjust all the saved registers such that they contain addresses
  239.      instead of offsets.  */
  240.   for (i = 0; i < TIC6X_NUM_CORE_REGS; i++)
  241.     if (cache->reg_saved[i] != -1)
  242.       cache->reg_saved[i] = cache->base + cache->reg_saved[i];

  243.   return return_pc;
  244. }

  245. /* This is the implementation of gdbarch method skip_prologue.  */

  246. static CORE_ADDR
  247. tic6x_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
  248. {
  249.   CORE_ADDR func_addr;
  250.   struct tic6x_unwind_cache cache;

  251.   /* See if we can determine the end of the prologue via the symbol table.
  252.      If so, then return either PC, or the PC after the prologue, whichever is
  253.      greater.  */
  254.   if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
  255.     {
  256.       CORE_ADDR post_prologue_pc
  257.         = skip_prologue_using_sal (gdbarch, func_addr);
  258.       if (post_prologue_pc != 0)
  259.         return max (start_pc, post_prologue_pc);
  260.     }

  261.   /* Can't determine prologue from the symbol table, need to examine
  262.      instructions.  */
  263.   return tic6x_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache,
  264.                                  NULL);
  265. }

  266. /* This is the implementation of gdbarch method breakpiont_from_pc.  */

  267. static const gdb_byte *
  268. tic6x_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
  269.                           int *bp_size)
  270. {
  271.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  272.   *bp_size = 4;

  273.   if (tdep == NULL || tdep->breakpoint == NULL)
  274.     {
  275.       if (BFD_ENDIAN_BIG == gdbarch_byte_order_for_code (gdbarch))
  276.         return tic6x_bkpt_illegal_opcode_be;
  277.       else
  278.         return tic6x_bkpt_illegal_opcode_le;
  279.     }
  280.   else
  281.     return tdep->breakpoint;
  282. }

  283. /* This is the implementation of gdbarch method print_insn.  */

  284. static int
  285. tic6x_print_insn (bfd_vma memaddr, disassemble_info *info)
  286. {
  287.   return print_insn_tic6x (memaddr, info);
  288. }

  289. static void
  290. tic6x_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
  291.                              struct dwarf2_frame_state_reg *reg,
  292.                              struct frame_info *this_frame)
  293. {
  294.   /* Mark the PC as the destination for the return address.  */
  295.   if (regnum == gdbarch_pc_regnum (gdbarch))
  296.     reg->how = DWARF2_FRAME_REG_RA;

  297.   /* Mark the stack pointer as the call frame address.  */
  298.   else if (regnum == gdbarch_sp_regnum (gdbarch))
  299.     reg->how = DWARF2_FRAME_REG_CFA;

  300.   /* The above was taken from the default init_reg in dwarf2-frame.c
  301.      while the below is c6x specific.  */

  302.   /* Callee save registers.  The ABI designates A10-A15 and B10-B15 as
  303.      callee-save.  */
  304.   else if ((regnum >= 10 && regnum <= 15) || (regnum >= 26 && regnum <= 31))
  305.     reg->how = DWARF2_FRAME_REG_SAME_VALUE;
  306.   else
  307.     /* All other registers are caller-save.  */
  308.     reg->how = DWARF2_FRAME_REG_UNDEFINED;
  309. }

  310. /* This is the implementation of gdbarch method unwind_pc.  */

  311. static CORE_ADDR
  312. tic6x_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  313. {
  314.   gdb_byte buf[8];

  315.   frame_unwind_register (next_frame,  TIC6X_PC_REGNUM, buf);
  316.   return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
  317. }

  318. /* This is the implementation of gdbarch method unwind_sp.  */

  319. static CORE_ADDR
  320. tic6x_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
  321. {
  322.   return frame_unwind_register_unsigned (this_frame, TIC6X_SP_REGNUM);
  323. }


  324. /* Frame base handling.  */

  325. static struct tic6x_unwind_cache*
  326. tic6x_frame_unwind_cache (struct frame_info *this_frame,
  327.                           void **this_prologue_cache)
  328. {
  329.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  330.   CORE_ADDR current_pc;
  331.   struct tic6x_unwind_cache *cache;

  332.   if (*this_prologue_cache)
  333.     return *this_prologue_cache;

  334.   cache = FRAME_OBSTACK_ZALLOC (struct tic6x_unwind_cache);
  335.   (*this_prologue_cache) = cache;

  336.   cache->return_regnum = TIC6X_RA_REGNUM;

  337.   tic6x_setup_default (cache);

  338.   cache->pc = get_frame_func (this_frame);
  339.   current_pc = get_frame_pc (this_frame);

  340.   /* Prologue analysis does the rest...  */
  341.   if (cache->pc != 0)
  342.     tic6x_analyze_prologue (gdbarch, cache->pc, current_pc, cache, this_frame);

  343.   return cache;
  344. }

  345. static void
  346. tic6x_frame_this_id (struct frame_info *this_frame, void **this_cache,
  347.                      struct frame_id *this_id)
  348. {
  349.   struct tic6x_unwind_cache *cache =
  350.     tic6x_frame_unwind_cache (this_frame, this_cache);

  351.   /* This marks the outermost frame.  */
  352.   if (cache->base == 0)
  353.     return;

  354.   (*this_id) = frame_id_build (cache->cfa, cache->pc);
  355. }

  356. static struct value *
  357. tic6x_frame_prev_register (struct frame_info *this_frame, void **this_cache,
  358.                            int regnum)
  359. {
  360.   struct tic6x_unwind_cache *cache =
  361.     tic6x_frame_unwind_cache (this_frame, this_cache);

  362.   gdb_assert (regnum >= 0);

  363.   /* The PC of the previous frame is stored in the RA register of
  364.      the current frame.  Frob regnum so that we pull the value from
  365.      the correct place.  */
  366.   if (regnum == TIC6X_PC_REGNUM)
  367.     regnum = cache->return_regnum;

  368.   if (regnum == TIC6X_SP_REGNUM && cache->cfa)
  369.     return frame_unwind_got_constant (this_frame, regnum, cache->cfa);

  370.   /* If we've worked out where a register is stored then load it from
  371.      there.  */
  372.   if (regnum < TIC6X_NUM_CORE_REGS && cache->reg_saved[regnum] != -1)
  373.     return frame_unwind_got_memory (this_frame, regnum,
  374.                                     cache->reg_saved[regnum]);

  375.   return frame_unwind_got_register (this_frame, regnum, regnum);
  376. }

  377. static CORE_ADDR
  378. tic6x_frame_base_address (struct frame_info *this_frame, void **this_cache)
  379. {
  380.   struct tic6x_unwind_cache *info
  381.     = tic6x_frame_unwind_cache (this_frame, this_cache);
  382.   return info->base;
  383. }

  384. static const struct frame_unwind tic6x_frame_unwind =
  385. {
  386.   NORMAL_FRAME,
  387.   default_frame_unwind_stop_reason,
  388.   tic6x_frame_this_id,
  389.   tic6x_frame_prev_register,
  390.   NULL,
  391.   default_frame_sniffer
  392. };

  393. static const struct frame_base tic6x_frame_base =
  394. {
  395.   &tic6x_frame_unwind,
  396.   tic6x_frame_base_address,
  397.   tic6x_frame_base_address,
  398.   tic6x_frame_base_address
  399. };


  400. static struct tic6x_unwind_cache *
  401. tic6x_make_stub_cache (struct frame_info *this_frame)
  402. {
  403.   struct tic6x_unwind_cache *cache;

  404.   cache = FRAME_OBSTACK_ZALLOC (struct tic6x_unwind_cache);

  405.   cache->return_regnum = TIC6X_RA_REGNUM;

  406.   tic6x_setup_default (cache);

  407.   cache->cfa = get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM);

  408.   return cache;
  409. }

  410. static void
  411. tic6x_stub_this_id (struct frame_info *this_frame, void **this_cache,
  412.                     struct frame_id *this_id)
  413. {
  414.   struct tic6x_unwind_cache *cache;

  415.   if (*this_cache == NULL)
  416.     *this_cache = tic6x_make_stub_cache (this_frame);
  417.   cache = *this_cache;

  418.   *this_id = frame_id_build (cache->cfa, get_frame_pc (this_frame));
  419. }

  420. static int
  421. tic6x_stub_unwind_sniffer (const struct frame_unwind *self,
  422.                            struct frame_info *this_frame,
  423.                            void **this_prologue_cache)
  424. {
  425.   CORE_ADDR addr_in_block;

  426.   addr_in_block = get_frame_address_in_block (this_frame);
  427.   if (in_plt_section (addr_in_block))
  428.     return 1;

  429.   return 0;
  430. }

  431. static const struct frame_unwind tic6x_stub_unwind =
  432. {
  433.   NORMAL_FRAME,
  434.   default_frame_unwind_stop_reason,
  435.   tic6x_stub_this_id,
  436.   tic6x_frame_prev_register,
  437.   NULL,
  438.   tic6x_stub_unwind_sniffer
  439. };

  440. /* Return the instruction on address PC.  */

  441. static unsigned long
  442. tic6x_fetch_instruction (struct gdbarch *gdbarch, CORE_ADDR pc)
  443. {
  444.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  445.   return read_memory_unsigned_integer (pc, TIC6X_OPCODE_SIZE, byte_order);
  446. }

  447. /* Compute the condition of INST if it is a conditional instruction.  Always
  448.    return 1 if INST is not a conditional instruction.  */

  449. static int
  450. tic6x_condition_true (struct frame_info *frame, unsigned long inst)
  451. {
  452.   int register_number;
  453.   int register_value;
  454.   static const int register_numbers[8] = { -1, 16, 17, 18, 1, 2, 0, -1 };

  455.   register_number = register_numbers[(inst >> 29) & 7];
  456.   if (register_number == -1)
  457.     return 1;

  458.   register_value = get_frame_register_signed (frame, register_number);
  459.   if ((inst & 0x10000000) != 0)
  460.     return register_value == 0;
  461.   return register_value != 0;
  462. }

  463. /* Get the register number by decoding raw bits REG, SIDE, and CROSSPATH in
  464.    instruction.  */

  465. static int
  466. tic6x_register_number (int reg, int side, int crosspath)
  467. {
  468.   int r = (reg & 15) | ((crosspath ^ side) << 4);
  469.   if ((reg & 16) != 0) /* A16 - A31, B16 - B31 */
  470.     r += 37;
  471.   return r;
  472. }

  473. static int
  474. tic6x_extract_signed_field (int value, int low_bit, int bits)
  475. {
  476.   int mask = (1 << bits) - 1;
  477.   int r = (value >> low_bit) & mask;
  478.   if ((r & (1 << (bits - 1))) != 0)
  479.     r -= mask + 1;
  480.   return r;
  481. }

  482. /* Determine where to set a single step breakpoint.  */

  483. static CORE_ADDR
  484. tic6x_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
  485. {
  486.   struct gdbarch *gdbarch = get_frame_arch (frame);
  487.   unsigned long inst;
  488.   int register_number;
  489.   int last = 0;

  490.   do
  491.     {
  492.       inst = tic6x_fetch_instruction (gdbarch, pc);

  493.       last = !(inst & 1);

  494.       if (inst == TIC6X_INST_SWE)
  495.         {
  496.           struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  497.           if (tdep->syscall_next_pc != NULL)
  498.             return tdep->syscall_next_pc (frame);
  499.         }

  500.       if (tic6x_condition_true (frame, inst))
  501.         {
  502.           if ((inst & 0x0000007c) == 0x00000010)
  503.             {
  504.               /* B with displacement */
  505.               pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
  506.               pc += tic6x_extract_signed_field (inst, 7, 21) << 2;
  507.               break;
  508.             }
  509.           if ((inst & 0x0f83effc) == 0x00000360)
  510.             {
  511.               /* B with register */

  512.               register_number = tic6x_register_number ((inst >> 18) & 0x1f,
  513.                                                        INST_S_BIT (inst),
  514.                                                        INST_X_BIT (inst));
  515.               pc = get_frame_register_unsigned (frame, register_number);
  516.               break;
  517.             }
  518.           if ((inst & 0x00001ffc) == 0x00001020)
  519.             {
  520.               /* BDEC */
  521.               register_number = tic6x_register_number ((inst >> 23) & 0x1f,
  522.                                                        INST_S_BIT (inst), 0);
  523.               if (get_frame_register_signed (frame, register_number) >= 0)
  524.                 {
  525.                   pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
  526.                   pc += tic6x_extract_signed_field (inst, 7, 10) << 2;
  527.                 }
  528.               break;
  529.             }
  530.           if ((inst & 0x00001ffc) == 0x00000120)
  531.             {
  532.               /* BNOP with displacement */
  533.               pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
  534.               pc += tic6x_extract_signed_field (inst, 16, 12) << 2;
  535.               break;
  536.             }
  537.           if ((inst & 0x0f830ffe) == 0x00800362)
  538.             {
  539.               /* BNOP with register */
  540.               register_number = tic6x_register_number ((inst >> 18) & 0x1f,
  541.                                                        1, INST_X_BIT (inst));
  542.               pc = get_frame_register_unsigned (frame, register_number);
  543.               break;
  544.             }
  545.           if ((inst & 0x00001ffc) == 0x00000020)
  546.             {
  547.               /* BPOS */
  548.               register_number = tic6x_register_number ((inst >> 23) & 0x1f,
  549.                                                        INST_S_BIT (inst), 0);
  550.               if (get_frame_register_signed (frame, register_number) >= 0)
  551.                 {
  552.                   pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
  553.                   pc += tic6x_extract_signed_field (inst, 13, 10) << 2;
  554.                 }
  555.               break;
  556.             }
  557.           if ((inst & 0xf000007c) == 0x10000010)
  558.             {
  559.               /* CALLP */
  560.               pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
  561.               pc += tic6x_extract_signed_field (inst, 7, 21) << 2;
  562.               break;
  563.             }
  564.         }
  565.       pc += TIC6X_OPCODE_SIZE;
  566.     }
  567.   while (!last);
  568.   return pc;
  569. }

  570. /* This is the implementation of gdbarch method software_single_step.  */

  571. static int
  572. tic6x_software_single_step (struct frame_info *frame)
  573. {
  574.   struct gdbarch *gdbarch = get_frame_arch (frame);
  575.   struct address_space *aspace = get_frame_address_space (frame);
  576.   CORE_ADDR next_pc = tic6x_get_next_pc (frame, get_frame_pc (frame));

  577.   insert_single_step_breakpoint (gdbarch, aspace, next_pc);

  578.   return 1;
  579. }

  580. /* This is the implementation of gdbarch method frame_align.  */

  581. static CORE_ADDR
  582. tic6x_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
  583. {
  584.   return align_down (addr, 8);
  585. }

  586. /* Given a return value in REGCACHE with a type VALTYPE, extract and copy its
  587.    value into VALBUF.  */

  588. static void
  589. tic6x_extract_return_value (struct type *valtype, struct regcache *regcache,
  590.                             enum bfd_endian byte_order, gdb_byte *valbuf)
  591. {
  592.   int len = TYPE_LENGTH (valtype);

  593.   /* pointer types are returned in register A4,
  594.      up to 32-bit types in A4
  595.      up to 64-bit types in A5:A4  */
  596.   if (len <= 4)
  597.     {
  598.       /* In big-endian,
  599.          - one-byte structure or union occupies the LSB of single even register.
  600.          - for two-byte structure or union, the first byte occupies byte 1 of
  601.          register and the second byte occupies byte 0.
  602.          so, we read the contents in VAL from the LSBs of register.  */
  603.       if (len < 3 && byte_order == BFD_ENDIAN_BIG)
  604.         regcache_cooked_read_part (regcache, TIC6X_A4_REGNUM, 4 - len, len,
  605.                                    valbuf);
  606.       else
  607.         regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf);
  608.     }
  609.   else if (len <= 8)
  610.     {
  611.       /* For a 5-8 byte structure or union in big-endian, the first byte
  612.          occupies byte 3 (the MSB) of the upper (odd) register and the
  613.          remaining bytes fill the decreasingly significant bytes.  5-7
  614.          byte structures or unions have padding in the LSBs of the
  615.          lower (even) register.  */
  616.       if (byte_order == BFD_ENDIAN_BIG)
  617.         {
  618.           regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf + 4);
  619.           regcache_cooked_read (regcache, TIC6X_A5_REGNUM, valbuf);
  620.         }
  621.       else
  622.         {
  623.           regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf);
  624.           regcache_cooked_read (regcache, TIC6X_A5_REGNUM, valbuf + 4);
  625.         }
  626.     }
  627. }

  628. /* Write into appropriate registers a function return value
  629.    of type TYPE, given in virtual format.  */

  630. static void
  631. tic6x_store_return_value (struct type *valtype, struct regcache *regcache,
  632.                           enum bfd_endian byte_order, const gdb_byte *valbuf)
  633. {
  634.   int len = TYPE_LENGTH (valtype);

  635.   /* return values of up to 8 bytes are returned in A5:A4 */

  636.   if (len <= 4)
  637.     {
  638.       if (len < 3 && byte_order == BFD_ENDIAN_BIG)
  639.         regcache_cooked_write_part (regcache, TIC6X_A4_REGNUM, 4 - len, len,
  640.                                     valbuf);
  641.       else
  642.         regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf);
  643.     }
  644.   else if (len <= 8)
  645.     {
  646.       if (byte_order == BFD_ENDIAN_BIG)
  647.         {
  648.           regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf + 4);
  649.           regcache_cooked_write (regcache, TIC6X_A5_REGNUM, valbuf);
  650.         }
  651.       else
  652.         {
  653.           regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf);
  654.           regcache_cooked_write (regcache, TIC6X_A5_REGNUM, valbuf + 4);
  655.         }
  656.     }
  657. }

  658. /* This is the implementation of gdbarch method return_value.  */

  659. static enum return_value_convention
  660. tic6x_return_value (struct gdbarch *gdbarch, struct value *function,
  661.                     struct type *type, struct regcache *regcache,
  662.                     gdb_byte *readbuf, const gdb_byte *writebuf)
  663. {
  664.   /* In C++, when function returns an object, even its size is small
  665.      enough, it stii has to be passed via reference, pointed by register
  666.      A3.  */
  667.   if (current_language->la_language == language_cplus)
  668.     {
  669.       if (type != NULL)
  670.         {
  671.           CHECK_TYPEDEF (type);
  672.           if (language_pass_by_reference (type))
  673.             return RETURN_VALUE_STRUCT_CONVENTION;
  674.         }
  675.     }

  676.   if (TYPE_LENGTH (type) > 8)
  677.     return RETURN_VALUE_STRUCT_CONVENTION;

  678.   if (readbuf)
  679.     tic6x_extract_return_value (type, regcache,
  680.                                 gdbarch_byte_order (gdbarch), readbuf);
  681.   if (writebuf)
  682.     tic6x_store_return_value (type, regcache,
  683.                               gdbarch_byte_order (gdbarch), writebuf);

  684.   return RETURN_VALUE_REGISTER_CONVENTION;
  685. }

  686. /* This is the implementation of gdbarch method dummy_id.  */

  687. static struct frame_id
  688. tic6x_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  689. {
  690.   return frame_id_build
  691.     (get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM),
  692.      get_frame_pc (this_frame));
  693. }

  694. /* Get the alignment requirement of TYPE.  */

  695. static int
  696. tic6x_arg_type_alignment (struct type *type)
  697. {
  698.   int len = TYPE_LENGTH (check_typedef (type));
  699.   enum type_code typecode = TYPE_CODE (check_typedef (type));

  700.   if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
  701.     {
  702.       /* The stack alignment of a structure (and union) passed by value is the
  703.          smallest power of two greater than or equal to its size.
  704.          This cannot exceed 8 bytes, which is the largest allowable size for
  705.          a structure passed by value.  */

  706.       if (len <= 2)
  707.         return len;
  708.       else if (len <= 4)
  709.         return 4;
  710.       else if (len <= 8)
  711.         return 8;
  712.       else
  713.         gdb_assert_not_reached ("unexpected length of data");
  714.     }
  715.   else
  716.     {
  717.       if (len <= 4)
  718.         return 4;
  719.       else if (len == 8)
  720.         {
  721.           if (typecode == TYPE_CODE_COMPLEX)
  722.             return 4;
  723.           else
  724.             return 8;
  725.         }
  726.       else if (len == 16)
  727.         {
  728.           if (typecode == TYPE_CODE_COMPLEX)
  729.             return 8;
  730.           else
  731.             return 16;
  732.         }
  733.       else
  734.         internal_error (__FILE__, __LINE__, _("unexpected length %d of type"),
  735.                         len);
  736.     }
  737. }

  738. /* This is the implementation of gdbarch method push_dummy_call.  */

  739. static CORE_ADDR
  740. tic6x_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  741.                        struct regcache *regcache, CORE_ADDR bp_addr,
  742.                        int nargs, struct value **args, CORE_ADDR sp,
  743.                        int struct_return, CORE_ADDR struct_addr)
  744. {
  745.   int argreg = 0;
  746.   int argnum;
  747.   int stack_offset = 4;
  748.   int references_offset = 4;
  749.   CORE_ADDR func_addr = find_function_addr (function, NULL);
  750.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  751.   struct type *func_type = value_type (function);
  752.   /* The first arg passed on stack.  Mostly the first 10 args are passed by
  753.      registers.  */
  754.   int first_arg_on_stack = 10;

  755.   /* Set the return address register to point to the entry point of
  756.      the program, where a breakpoint lies in wait.  */
  757.   regcache_cooked_write_unsigned (regcache, TIC6X_RA_REGNUM, bp_addr);

  758.   /* The caller must pass an argument in A3 containing a destination address
  759.      for the returned value.  The callee returns the object by copying it to
  760.      the address in A3.  */
  761.   if (struct_return)
  762.     regcache_cooked_write_unsigned (regcache, 3, struct_addr);

  763.   /* Determine the type of this function.  */
  764.   func_type = check_typedef (func_type);
  765.   if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
  766.     func_type = check_typedef (TYPE_TARGET_TYPE (func_type));

  767.   gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
  768.               || TYPE_CODE (func_type) == TYPE_CODE_METHOD);

  769.   /* For a variadic C function, the last explicitly declared argument and all
  770.      remaining arguments are passed on the stack.  */
  771.   if (TYPE_VARARGS (func_type))
  772.     first_arg_on_stack = TYPE_NFIELDS (func_type) - 1;

  773.   /* Now make space on the stack for the args.  */
  774.   for (argnum = 0; argnum < nargs; argnum++)
  775.     {
  776.       int len = align_up (TYPE_LENGTH (value_type (args[argnum])), 4);
  777.       if (argnum >= 10 - argreg)
  778.         references_offset += len;
  779.       stack_offset += len;
  780.     }
  781.   sp -= stack_offset;
  782.   /* SP should be 8-byte aligned, see C6000 ABI section 4.4.1
  783.      Stack Alignment.  */
  784.   sp = align_down (sp, 8);
  785.   stack_offset = 4;

  786.   /* Now load as many as possible of the first arguments into
  787.      registers, and push the rest onto the stack.  Loop through args
  788.      from first to last.  */
  789.   for (argnum = 0; argnum < nargs; argnum++)
  790.     {
  791.       const gdb_byte *val;
  792.       struct value *arg = args[argnum];
  793.       struct type *arg_type = check_typedef (value_type (arg));
  794.       int len = TYPE_LENGTH (arg_type);
  795.       enum type_code typecode = TYPE_CODE (arg_type);

  796.       val = value_contents (arg);

  797.       /* Copy the argument to general registers or the stack in
  798.          register-sized pieces.  */
  799.       if (argreg < first_arg_on_stack)
  800.         {
  801.           if (len <= 4)
  802.             {
  803.               if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
  804.                 {
  805.                   /* In big-endian,
  806.                      - one-byte structure or union occupies the LSB of single
  807.                      even register.
  808.                      - for two-byte structure or union, the first byte
  809.                      occupies byte 1 of register and the second byte occupies
  810.                      byte 0.
  811.                      so, we write the contents in VAL to the lsp of
  812.                      register.  */
  813.                   if (len < 3 && byte_order == BFD_ENDIAN_BIG)
  814.                     regcache_cooked_write_part (regcache, arg_regs[argreg],
  815.                                                 4 - len, len, val);
  816.                   else
  817.                     regcache_cooked_write (regcache, arg_regs[argreg], val);
  818.                 }
  819.               else
  820.                 {
  821.                   /* The argument is being passed by value in a single
  822.                      register.  */
  823.                   CORE_ADDR regval = extract_unsigned_integer (val, len,
  824.                                                                byte_order);

  825.                   regcache_cooked_write_unsigned (regcache, arg_regs[argreg],
  826.                                                   regval);
  827.                 }
  828.             }
  829.           else
  830.             {
  831.               if (len <= 8)
  832.                 {
  833.                   if (typecode == TYPE_CODE_STRUCT
  834.                       || typecode == TYPE_CODE_UNION)
  835.                     {
  836.                       /* For a 5-8 byte structure or union in big-endian, the
  837.                          first byte occupies byte 3 (the MSB) of the upper (odd)
  838.                          register and the remaining bytes fill the decreasingly
  839.                          significant bytes.  5-7 byte structures or unions have
  840.                          padding in the LSBs of the lower (even) register.  */
  841.                       if (byte_order == BFD_ENDIAN_BIG)
  842.                         {
  843.                           regcache_cooked_write (regcache,
  844.                                                  arg_regs[argreg] + 1, val);
  845.                           regcache_cooked_write_part (regcache,
  846.                                                       arg_regs[argreg], 0,
  847.                                                       len - 4, val + 4);
  848.                         }
  849.                       else
  850.                         {
  851.                           regcache_cooked_write (regcache, arg_regs[argreg],
  852.                                                  val);
  853.                           regcache_cooked_write_part (regcache,
  854.                                                       arg_regs[argreg] + 1, 0,
  855.                                                       len - 4, val + 4);
  856.                         }
  857.                     }
  858.                   else
  859.                     {
  860.                       /* The argument is being passed by value in a pair of
  861.                          registers.  */
  862.                       ULONGEST regval = extract_unsigned_integer (val, len,
  863.                                                                   byte_order);

  864.                       regcache_cooked_write_unsigned (regcache,
  865.                                                       arg_regs[argreg],
  866.                                                       regval);
  867.                       regcache_cooked_write_unsigned (regcache,
  868.                                                       arg_regs[argreg] + 1,
  869.                                                       regval >> 32);
  870.                     }
  871.                 }
  872.               else
  873.                 {
  874.                   /* The argument is being passed by reference in a single
  875.                      register.  */
  876.                   CORE_ADDR addr;

  877.                   /* It is not necessary to adjust REFERENCES_OFFSET to
  878.                      8-byte aligned in some cases, in which 4-byte alignment
  879.                      is sufficient.  For simplicity, we adjust
  880.                      REFERENCES_OFFSET to 8-byte aligned.  */
  881.                   references_offset = align_up (references_offset, 8);

  882.                   addr = sp + references_offset;
  883.                   write_memory (addr, val, len);
  884.                   references_offset += align_up (len, 4);
  885.                   regcache_cooked_write_unsigned (regcache, arg_regs[argreg],
  886.                                                   addr);
  887.                 }
  888.             }
  889.           argreg++;
  890.         }
  891.       else
  892.         {
  893.           /* The argument is being passed on the stack.  */
  894.           CORE_ADDR addr;

  895.           /* There are six different cases of alignment, and these rules can
  896.              be found in tic6x_arg_type_alignment:

  897.              1) 4-byte aligned if size is less than or equal to 4 byte, such
  898.              as short, int, struct, union etc.
  899.              2) 8-byte aligned if size is less than or equal to 8-byte, such
  900.              as double, long long,
  901.              3) 4-byte aligned if it is of type _Complex float, even its size
  902.              is 8-byte.
  903.              4) 8-byte aligned if it is of type _Complex double or _Complex
  904.              long double, even its size is 16-byte.  Because, the address of
  905.              variable is passed as reference.
  906.              5) struct and union larger than 8-byte are passed by reference, so
  907.              it is 4-byte aligned.
  908.              6) struct and union of size between 4 byte and 8 byte varies.
  909.              alignment of struct variable is the alignment of its first field,
  910.              while alignment of union variable is the max of all its fields'
  911.              alignment.  */

  912.           if (len <= 4)
  913.             ; /* Default is 4-byte aligned.  Nothing to be done.  */
  914.           else if (len <= 8)
  915.             stack_offset = align_up (stack_offset,
  916.                                      tic6x_arg_type_alignment (arg_type));
  917.           else if (len == 16)
  918.             {
  919.               /* _Complex double or _Complex long double */
  920.               if (typecode == TYPE_CODE_COMPLEX)
  921.                 {
  922.                   /* The argument is being passed by reference on stack.  */
  923.                   CORE_ADDR addr;
  924.                   references_offset = align_up (references_offset, 8);

  925.                   addr = sp + references_offset;
  926.                   /* Store variable on stack.  */
  927.                   write_memory (addr, val, len);

  928.                   references_offset += align_up (len, 4);

  929.                   /* Pass the address of variable on stack as reference.  */
  930.                   store_unsigned_integer ((gdb_byte *) val, 4, byte_order,
  931.                                           addr);
  932.                   len = 4;

  933.                 }
  934.               else
  935.                 internal_error (__FILE__, __LINE__,
  936.                                 _("unexpected type %d of arg %d"),
  937.                                 typecode, argnum);
  938.             }
  939.           else
  940.             internal_error (__FILE__, __LINE__,
  941.                             _("unexpected length %d of arg %d"), len, argnum);

  942.           addr = sp + stack_offset;
  943.           write_memory (addr, val, len);
  944.           stack_offset += align_up (len, 4);
  945.         }
  946.     }

  947.   regcache_cooked_write_signed (regcache, TIC6X_SP_REGNUM, sp);

  948.   /* Return adjusted stack pointer.  */
  949.   return sp;
  950. }

  951. /* This is the implementation of gdbarch method in_function_epilogue_p.  */

  952. static int
  953. tic6x_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  954. {
  955.   unsigned long inst = tic6x_fetch_instruction (gdbarch, pc);
  956.   /* Normally, the epilogue is composed by instruction `b .S2 b3'.  */
  957.   if ((inst & 0x0f83effc) == 0x360)
  958.     {
  959.       unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f,
  960.                                                  INST_S_BIT (inst),
  961.                                                  INST_X_BIT (inst));
  962.       if (src2 == TIC6X_RA_REGNUM)
  963.         return 1;
  964.     }

  965.   return 0;
  966. }

  967. /* This is the implementation of gdbarch method get_longjmp_target.  */

  968. static int
  969. tic6x_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  970. {
  971.   struct gdbarch *gdbarch = get_frame_arch (frame);
  972.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  973.   CORE_ADDR jb_addr;
  974.   gdb_byte buf[4];

  975.   /* JMP_BUF is passed by reference in A4.  */
  976.   jb_addr = get_frame_register_unsigned (frame, 4);

  977.   /* JMP_BUF contains 13 elements of type int, and return address is stored
  978.      in the last slot.  */
  979.   if (target_read_memory (jb_addr + 12 * 4, buf, 4))
  980.     return 0;

  981.   *pc = extract_unsigned_integer (buf, 4, byte_order);

  982.   return 1;
  983. }

  984. /* This is the implementation of gdbarch method
  985.    return_in_first_hidden_param_p.  */

  986. static int
  987. tic6x_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
  988.                                       struct type *type)
  989. {
  990.   return 0;
  991. }

  992. static struct gdbarch *
  993. tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  994. {
  995.   struct gdbarch *gdbarch;
  996.   struct gdbarch_tdep *tdep;
  997.   struct tdesc_arch_data *tdesc_data = NULL;
  998.   const struct target_desc *tdesc = info.target_desc;
  999.   int has_gp = 0;

  1000.   /* Check any target description for validity.  */
  1001.   if (tdesc_has_registers (tdesc))
  1002.     {
  1003.       const struct tdesc_feature *feature;
  1004.       int valid_p, i;

  1005.       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.core");

  1006.       if (feature == NULL)
  1007.         return NULL;

  1008.       tdesc_data = tdesc_data_alloc ();

  1009.       valid_p = 1;
  1010.       for (i = 0; i < 32; i++)        /* A0 - A15, B0 - B15 */
  1011.         valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
  1012.                                             tic6x_register_names[i]);

  1013.       /* CSR */
  1014.       valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
  1015.                                           tic6x_register_names[TIC6X_CSR_REGNUM]);
  1016.       valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
  1017.                                           tic6x_register_names[TIC6X_PC_REGNUM]);

  1018.       if (!valid_p)
  1019.         {
  1020.           tdesc_data_cleanup (tdesc_data);
  1021.           return NULL;
  1022.         }

  1023.       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.gp");
  1024.       if (feature)
  1025.         {
  1026.           int j = 0;
  1027.           static const char *const gp[] =
  1028.             {
  1029.               "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23",
  1030.               "A24", "A25", "A26", "A27", "A28", "A29", "A30", "A31",
  1031.               "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23",
  1032.               "B24", "B25", "B26", "B27", "B28", "B29", "B30", "B31",
  1033.             };

  1034.           has_gp = 1;
  1035.           valid_p = 1;
  1036.           for (j = 0; j < 32; j++)        /* A16 - A31, B16 - B31 */
  1037.             valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
  1038.                                                 gp[j]);

  1039.           if (!valid_p)
  1040.             {
  1041.               tdesc_data_cleanup (tdesc_data);
  1042.               return NULL;
  1043.             }
  1044.         }

  1045.       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.c6xp");
  1046.       if (feature)
  1047.         {
  1048.           valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "TSR");
  1049.           valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "ILC");
  1050.           valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "RILC");

  1051.           if (!valid_p)
  1052.             {
  1053.               tdesc_data_cleanup (tdesc_data);
  1054.               return NULL;
  1055.             }
  1056.         }

  1057.     }

  1058.   /* Find a candidate among extant architectures.  */
  1059.   for (arches = gdbarch_list_lookup_by_info (arches, &info);
  1060.        arches != NULL;
  1061.        arches = gdbarch_list_lookup_by_info (arches->next, &info))
  1062.     {
  1063.       tdep = gdbarch_tdep (arches->gdbarch);

  1064.       if (has_gp != tdep->has_gp)
  1065.         continue;

  1066.       if (tdep && tdep->breakpoint)
  1067.         return arches->gdbarch;
  1068.     }

  1069.   tdep = xcalloc (1, sizeof (struct gdbarch_tdep));

  1070.   tdep->has_gp = has_gp;
  1071.   gdbarch = gdbarch_alloc (&info, tdep);

  1072.   /* Data type sizes.  */
  1073.   set_gdbarch_ptr_bit (gdbarch, 32);
  1074.   set_gdbarch_addr_bit (gdbarch, 32);
  1075.   set_gdbarch_short_bit (gdbarch, 16);
  1076.   set_gdbarch_int_bit (gdbarch, 32);
  1077.   set_gdbarch_long_bit (gdbarch, 32);
  1078.   set_gdbarch_long_long_bit (gdbarch, 64);
  1079.   set_gdbarch_float_bit (gdbarch, 32);
  1080.   set_gdbarch_double_bit (gdbarch, 64);

  1081.   set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
  1082.   set_gdbarch_double_format (gdbarch, floatformats_ieee_double);

  1083.   /* The register set.  */
  1084.   set_gdbarch_num_regs (gdbarch, TIC6X_NUM_REGS);
  1085.   set_gdbarch_sp_regnum (gdbarch, TIC6X_SP_REGNUM);
  1086.   set_gdbarch_pc_regnum (gdbarch, TIC6X_PC_REGNUM);

  1087.   set_gdbarch_register_name (gdbarch, tic6x_register_name);
  1088.   set_gdbarch_register_type (gdbarch, tic6x_register_type);

  1089.   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);

  1090.   set_gdbarch_skip_prologue (gdbarch, tic6x_skip_prologue);
  1091.   set_gdbarch_breakpoint_from_pc (gdbarch, tic6x_breakpoint_from_pc);

  1092.   set_gdbarch_unwind_pc (gdbarch, tic6x_unwind_pc);
  1093.   set_gdbarch_unwind_sp (gdbarch, tic6x_unwind_sp);

  1094.   /* Unwinding.  */
  1095.   dwarf2_append_unwinders (gdbarch);

  1096.   frame_unwind_append_unwinder (gdbarch, &tic6x_stub_unwind);
  1097.   frame_unwind_append_unwinder (gdbarch, &tic6x_frame_unwind);
  1098.   frame_base_set_default (gdbarch, &tic6x_frame_base);

  1099.   dwarf2_frame_set_init_reg (gdbarch, tic6x_dwarf2_frame_init_reg);

  1100.   /* Single stepping.  */
  1101.   set_gdbarch_software_single_step (gdbarch, tic6x_software_single_step);

  1102.   set_gdbarch_print_insn (gdbarch, tic6x_print_insn);

  1103.   /* Call dummy code.  */
  1104.   set_gdbarch_frame_align (gdbarch, tic6x_frame_align);

  1105.   set_gdbarch_return_value (gdbarch, tic6x_return_value);

  1106.   set_gdbarch_dummy_id (gdbarch, tic6x_dummy_id);

  1107.   /* Enable inferior call support.  */
  1108.   set_gdbarch_push_dummy_call (gdbarch, tic6x_push_dummy_call);

  1109.   set_gdbarch_get_longjmp_target (gdbarch, tic6x_get_longjmp_target);

  1110.   set_gdbarch_in_function_epilogue_p (gdbarch, tic6x_in_function_epilogue_p);

  1111.   set_gdbarch_return_in_first_hidden_param_p (gdbarch,
  1112.                                               tic6x_return_in_first_hidden_param_p);

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

  1115.   if (tdesc_data)
  1116.     tdesc_use_registers (gdbarch, tdesc, tdesc_data);

  1117.   return gdbarch;
  1118. }

  1119. /* -Wmissing-prototypes */
  1120. extern initialize_file_ftype _initialize_tic6x_tdep;

  1121. void
  1122. _initialize_tic6x_tdep (void)
  1123. {
  1124.   register_gdbarch_init (bfd_arch_tic6x, tic6x_gdbarch_init);

  1125.   initialize_tdesc_tic6x_c64xp ();
  1126.   initialize_tdesc_tic6x_c64x ();
  1127.   initialize_tdesc_tic6x_c62x ();
  1128. }