GDB (API)
/home/stan/gdb/src/gdb/tic6x-tdep.c
Go to the documentation of this file.
00001 /* Target dependent code for GDB on TI C6x systems.
00002 
00003    Copyright (C) 2010-2013 Free Software Foundation, Inc.
00004    Contributed by Andrew Jenner <andrew@codesourcery.com>
00005    Contributed by Yao Qi <yao@codesourcery.com>
00006 
00007    This file is part of GDB.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 3 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00021 
00022 #include "defs.h"
00023 #include "frame.h"
00024 #include "frame-unwind.h"
00025 #include "frame-base.h"
00026 #include "trad-frame.h"
00027 #include "dwarf2-frame.h"
00028 #include "symtab.h"
00029 #include "inferior.h"
00030 #include "gdbtypes.h"
00031 #include "gdbcore.h"
00032 #include "gdbcmd.h"
00033 #include "target.h"
00034 #include "dis-asm.h"
00035 #include "regcache.h"
00036 #include "value.h"
00037 #include "symfile.h"
00038 #include "arch-utils.h"
00039 #include "floatformat.h"
00040 #include "glibc-tdep.h"
00041 #include "infcall.h"
00042 #include "regset.h"
00043 #include "tramp-frame.h"
00044 #include "linux-tdep.h"
00045 #include "solib.h"
00046 #include "objfiles.h"
00047 #include "gdb_assert.h"
00048 #include "osabi.h"
00049 #include "tic6x-tdep.h"
00050 #include "language.h"
00051 #include "target-descriptions.h"
00052 
00053 #include "features/tic6x-c64xp.c"
00054 #include "features/tic6x-c64x.c"
00055 #include "features/tic6x-c62x.c"
00056 
00057 #define TIC6X_OPCODE_SIZE 4
00058 #define TIC6X_FETCH_PACKET_SIZE 32
00059 
00060 #define INST_S_BIT(INST) ((INST >> 1) & 1)
00061 #define INST_X_BIT(INST) ((INST >> 12) & 1)
00062 
00063 const gdb_byte tic6x_bkpt_illegal_opcode_be[] = { 0x56, 0x45, 0x43, 0x14 };
00064 const gdb_byte tic6x_bkpt_illegal_opcode_le[] = { 0x14, 0x43, 0x45, 0x56 };
00065 
00066 struct tic6x_unwind_cache
00067 {
00068   /* The frame's base, optionally used by the high-level debug info.  */
00069   CORE_ADDR base;
00070 
00071   /* The previous frame's inner most stack address.  Used as this
00072      frame ID's stack_addr.  */
00073   CORE_ADDR cfa;
00074 
00075   /* The address of the first instruction in this function */
00076   CORE_ADDR pc;
00077 
00078   /* Which register holds the return address for the frame.  */
00079   int return_regnum;
00080 
00081   /* The offset of register saved on stack.  If register is not saved, the
00082      corresponding element is -1.  */
00083   CORE_ADDR reg_saved[TIC6X_NUM_CORE_REGS];
00084 };
00085 
00086 
00087 /* Name of TI C6x core registers.  */
00088 static const char *const tic6x_register_names[] =
00089 {
00090   "A0",  "A1",  "A2",  "A3",  /*  0  1  2  3 */
00091   "A4",  "A5",  "A6",  "A7",  /*  4  5  6  7 */
00092   "A8",  "A9",  "A10", "A11", /*  8  9 10 11 */
00093   "A12", "A13", "A14", "A15", /* 12 13 14 15 */
00094   "B0",  "B1",  "B2",  "B3",  /* 16 17 18 19 */
00095   "B4",  "B5",  "B6",  "B7",  /* 20 21 22 23 */
00096   "B8",  "B9",  "B10", "B11", /* 24 25 26 27 */
00097   "B12", "B13", "B14", "B15", /* 28 29 30 31 */
00098   "CSR", "PC",                /* 32 33       */
00099 };
00100 
00101 /* This array maps the arguments to the register number which passes argument
00102    in function call according to C6000 ELF ABI.  */
00103 static const int arg_regs[] = { 4, 20, 6, 22, 8, 24, 10, 26, 12, 28 };
00104 
00105 /* This is the implementation of gdbarch method register_name.  */
00106 
00107 static const char *
00108 tic6x_register_name (struct gdbarch *gdbarch, int regno)
00109 {
00110   if (regno < 0)
00111     return NULL;
00112 
00113   if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
00114     return tdesc_register_name (gdbarch, regno);
00115   else if (regno >= ARRAY_SIZE (tic6x_register_names))
00116     return "";
00117   else
00118     return tic6x_register_names[regno];
00119 }
00120 
00121 /* This is the implementation of gdbarch method register_type.  */
00122 
00123 static struct type *
00124 tic6x_register_type (struct gdbarch *gdbarch, int regno)
00125 {
00126 
00127   if (regno == TIC6X_PC_REGNUM)
00128     return builtin_type (gdbarch)->builtin_func_ptr;
00129   else
00130     return builtin_type (gdbarch)->builtin_uint32;
00131 }
00132 
00133 static void
00134 tic6x_setup_default (struct tic6x_unwind_cache *cache)
00135 {
00136   int i;
00137 
00138   for (i = 0; i < TIC6X_NUM_CORE_REGS; i++)
00139     cache->reg_saved[i] = -1;
00140 }
00141 
00142 static unsigned long tic6x_fetch_instruction (struct gdbarch *, CORE_ADDR);
00143 static int tic6x_register_number (int reg, int side, int crosspath);
00144 
00145 /* Do a full analysis of the prologue at START_PC and update CACHE accordingly.
00146    Bail out early if CURRENT_PC is reached.  Returns the address of the first
00147    instruction after the prologue.  */
00148 
00149 static CORE_ADDR
00150 tic6x_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR start_pc,
00151                         const CORE_ADDR current_pc,
00152                         struct tic6x_unwind_cache *cache,
00153                         struct frame_info *this_frame)
00154 {
00155   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00156   unsigned long inst;
00157   unsigned int src_reg, base_reg, dst_reg;
00158   int i;
00159   CORE_ADDR pc = start_pc;
00160   CORE_ADDR return_pc = start_pc;
00161   int frame_base_offset_to_sp = 0;
00162   /* Counter of non-stw instructions after first insn ` sub sp, xxx, sp'.  */
00163   int non_stw_insn_counter = 0;
00164 
00165   if (start_pc >= current_pc)
00166     return_pc = current_pc;
00167 
00168   cache->base = 0;
00169 
00170   /* The landmarks in prologue is one or two SUB instructions to SP.
00171      Instructions on setting up dsbt are in the last part of prologue, if
00172      needed.  In maxim, prologue can be divided to three parts by two
00173      `sub sp, xx, sp' insns.  */
00174 
00175   /* Step 1: Look for the 1st and 2nd insn `sub sp, xx, sp',  in which, the
00176      2nd one is optional.  */
00177   while (pc < current_pc)
00178     {
00179       int offset = 0;
00180 
00181       unsigned long inst = tic6x_fetch_instruction (gdbarch, pc);
00182 
00183       if ((inst & 0x1ffc) == 0x1dc0 || (inst & 0x1ffc) == 0x1bc0
00184           || (inst & 0x0ffc) == 0x9c0)
00185         {
00186           /* SUBAW/SUBAH/SUB, and src1 is ucst 5.  */
00187           unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f,
00188                                                      INST_S_BIT (inst), 0);
00189           unsigned int dst = tic6x_register_number ((inst >> 23) & 0x1f,
00190                                                     INST_S_BIT (inst), 0);
00191 
00192           if (src2 == TIC6X_SP_REGNUM && dst == TIC6X_SP_REGNUM)
00193             {
00194               /* Extract const from insn SUBAW/SUBAH/SUB, and translate it to
00195                  offset.  The constant offset is decoded in bit 13-17 in all
00196                  these three kinds of instructions.  */
00197               unsigned int ucst5 = (inst >> 13) & 0x1f;
00198 
00199               if ((inst & 0x1ffc) == 0x1dc0)    /* SUBAW */
00200                 frame_base_offset_to_sp += ucst5 << 2;
00201               else if ((inst & 0x1ffc) == 0x1bc0)       /* SUBAH */
00202                 frame_base_offset_to_sp += ucst5 << 1;
00203               else if ((inst & 0x0ffc) == 0x9c0)        /* SUB */
00204                 frame_base_offset_to_sp += ucst5;
00205               else
00206                 gdb_assert_not_reached ("unexpected instruction");
00207 
00208               return_pc = pc + 4;
00209             }
00210         }
00211       else if ((inst & 0x174) == 0x74)  /* stw SRC, *+b15(uconst) */
00212         {
00213           /* The y bit determines which file base is read from.  */
00214           base_reg = tic6x_register_number ((inst >> 18) & 0x1f,
00215                                             (inst >> 7) & 1, 0);
00216 
00217           if (base_reg == TIC6X_SP_REGNUM)
00218             {
00219               src_reg = tic6x_register_number ((inst >> 23) & 0x1f,
00220                                                INST_S_BIT (inst), 0);
00221 
00222               cache->reg_saved[src_reg] = ((inst >> 13) & 0x1f) << 2;
00223 
00224               return_pc = pc + 4;
00225             }
00226           non_stw_insn_counter = 0;
00227         }
00228       else
00229         {
00230           non_stw_insn_counter++;
00231           /* Following instruction sequence may be emitted in prologue:
00232 
00233              <+0>: subah .D2 b15,28,b15
00234              <+4>: or .L2X 0,a4,b0
00235              <+8>: || stw .D2T2 b14,*+b15(56)
00236              <+12>:[!b0] b .S1 0xe50e4c1c <sleep+220>
00237              <+16>:|| stw .D2T1 a10,*+b15(48)
00238              <+20>:stw .D2T2 b3,*+b15(52)
00239              <+24>:stw .D2T1 a4,*+b15(40)
00240 
00241              we should look forward for next instruction instead of breaking loop
00242              here.  So far, we allow almost two sequential non-stw instructions
00243              in prologue.  */
00244           if (non_stw_insn_counter >= 2)
00245             break;
00246         }
00247 
00248 
00249       pc += 4;
00250     }
00251   /* Step 2: Skip insn on setting up dsbt if it is.  Usually, it looks like,
00252      ldw .D2T2 *+b14(0),b14 */
00253   inst = tic6x_fetch_instruction (gdbarch, pc);
00254   /* The s bit determines which file dst will be loaded into, same effect as
00255      other places.  */
00256   dst_reg = tic6x_register_number ((inst >> 23) & 0x1f, (inst >> 1) & 1, 0);
00257   /* The y bit (bit 7), instead of s bit, determines which file base be
00258      used.  */
00259   base_reg = tic6x_register_number ((inst >> 18) & 0x1f, (inst >> 7) & 1, 0);
00260 
00261   if ((inst & 0x164) == 0x64    /* ldw */
00262       && dst_reg == TIC6X_DP_REGNUM     /* dst is B14 */
00263       && base_reg == TIC6X_DP_REGNUM)   /* baseR is B14 */
00264     {
00265       return_pc = pc + 4;
00266     }
00267 
00268   if (this_frame)
00269     {
00270       cache->base = get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM);
00271 
00272       if (cache->reg_saved[TIC6X_FP_REGNUM] != -1)
00273         {
00274           /* If the FP now holds an offset from the CFA then this is a frame
00275              which uses the frame pointer.  */
00276 
00277           cache->cfa = get_frame_register_unsigned (this_frame,
00278                                                     TIC6X_FP_REGNUM);
00279         }
00280       else
00281         {
00282           /* FP doesn't hold an offset from the CFA.  If SP still holds an
00283              offset from the CFA then we might be in a function which omits
00284              the frame pointer.  */
00285 
00286           cache->cfa = cache->base + frame_base_offset_to_sp;
00287         }
00288     }
00289 
00290   /* Adjust all the saved registers such that they contain addresses
00291      instead of offsets.  */
00292   for (i = 0; i < TIC6X_NUM_CORE_REGS; i++)
00293     if (cache->reg_saved[i] != -1)
00294       cache->reg_saved[i] = cache->base + cache->reg_saved[i];
00295 
00296   return return_pc;
00297 }
00298 
00299 /* This is the implementation of gdbarch method skip_prologue.  */
00300 
00301 static CORE_ADDR
00302 tic6x_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
00303 {
00304   CORE_ADDR func_addr;
00305   struct tic6x_unwind_cache cache;
00306 
00307   /* See if we can determine the end of the prologue via the symbol table.
00308      If so, then return either PC, or the PC after the prologue, whichever is
00309      greater.  */
00310   if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
00311     {
00312       CORE_ADDR post_prologue_pc
00313         = skip_prologue_using_sal (gdbarch, func_addr);
00314       if (post_prologue_pc != 0)
00315         return max (start_pc, post_prologue_pc);
00316     }
00317 
00318   /* Can't determine prologue from the symbol table, need to examine
00319      instructions.  */
00320   return tic6x_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache,
00321                                  NULL);
00322 }
00323 
00324 /* This is the implementation of gdbarch method breakpiont_from_pc.  */
00325 
00326 static const gdb_byte *
00327 tic6x_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
00328                           int *bp_size)
00329 {
00330   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00331 
00332   *bp_size = 4;
00333 
00334   if (tdep == NULL || tdep->breakpoint == NULL)
00335     {
00336       if (BFD_ENDIAN_BIG == gdbarch_byte_order_for_code (gdbarch))
00337         return tic6x_bkpt_illegal_opcode_be;
00338       else
00339         return tic6x_bkpt_illegal_opcode_le;
00340     }
00341   else
00342     return tdep->breakpoint;
00343 }
00344 
00345 /* This is the implementation of gdbarch method print_insn.  */
00346 
00347 static int
00348 tic6x_print_insn (bfd_vma memaddr, disassemble_info *info)
00349 {
00350   return print_insn_tic6x (memaddr, info);
00351 }
00352 
00353 static void
00354 tic6x_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
00355                              struct dwarf2_frame_state_reg *reg,
00356                              struct frame_info *this_frame)
00357 {
00358   /* Mark the PC as the destination for the return address.  */
00359   if (regnum == gdbarch_pc_regnum (gdbarch))
00360     reg->how = DWARF2_FRAME_REG_RA;
00361 
00362   /* Mark the stack pointer as the call frame address.  */
00363   else if (regnum == gdbarch_sp_regnum (gdbarch))
00364     reg->how = DWARF2_FRAME_REG_CFA;
00365 
00366   /* The above was taken from the default init_reg in dwarf2-frame.c
00367      while the below is c6x specific.  */
00368 
00369   /* Callee save registers.  The ABI designates A10-A15 and B10-B15 as
00370      callee-save.  */
00371   else if ((regnum >= 10 && regnum <= 15) || (regnum >= 26 && regnum <= 31))
00372     reg->how = DWARF2_FRAME_REG_SAME_VALUE;
00373   else
00374     /* All other registers are caller-save.  */
00375     reg->how = DWARF2_FRAME_REG_UNDEFINED;
00376 }
00377 
00378 /* This is the implementation of gdbarch method unwind_pc.  */
00379 
00380 static CORE_ADDR
00381 tic6x_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
00382 {
00383   gdb_byte buf[8];
00384 
00385   frame_unwind_register (next_frame,  TIC6X_PC_REGNUM, buf);
00386   return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
00387 }
00388 
00389 /* This is the implementation of gdbarch method unwind_sp.  */
00390 
00391 static CORE_ADDR
00392 tic6x_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
00393 {
00394   return frame_unwind_register_unsigned (this_frame, TIC6X_SP_REGNUM);
00395 }
00396 
00397 
00398 /* Frame base handling.  */
00399 
00400 static struct tic6x_unwind_cache*
00401 tic6x_frame_unwind_cache (struct frame_info *this_frame,
00402                           void **this_prologue_cache)
00403 {
00404   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00405   CORE_ADDR current_pc;
00406   struct tic6x_unwind_cache *cache;
00407 
00408   if (*this_prologue_cache)
00409     return *this_prologue_cache;
00410 
00411   cache = FRAME_OBSTACK_ZALLOC (struct tic6x_unwind_cache);
00412   (*this_prologue_cache) = cache;
00413 
00414   cache->return_regnum = TIC6X_RA_REGNUM;
00415 
00416   tic6x_setup_default (cache);
00417 
00418   cache->pc = get_frame_func (this_frame);
00419   current_pc = get_frame_pc (this_frame);
00420 
00421   /* Prologue analysis does the rest...  */
00422   if (cache->pc != 0)
00423     tic6x_analyze_prologue (gdbarch, cache->pc, current_pc, cache, this_frame);
00424 
00425   return cache;
00426 }
00427 
00428 static void
00429 tic6x_frame_this_id (struct frame_info *this_frame, void **this_cache,
00430                      struct frame_id *this_id)
00431 {
00432   struct tic6x_unwind_cache *cache =
00433     tic6x_frame_unwind_cache (this_frame, this_cache);
00434 
00435   /* This marks the outermost frame.  */
00436   if (cache->base == 0)
00437     return;
00438 
00439   (*this_id) = frame_id_build (cache->cfa, cache->pc);
00440 }
00441 
00442 static struct value *
00443 tic6x_frame_prev_register (struct frame_info *this_frame, void **this_cache,
00444                            int regnum)
00445 {
00446   struct tic6x_unwind_cache *cache =
00447     tic6x_frame_unwind_cache (this_frame, this_cache);
00448 
00449   gdb_assert (regnum >= 0);
00450 
00451   /* The PC of the previous frame is stored in the RA register of
00452      the current frame.  Frob regnum so that we pull the value from
00453      the correct place.  */
00454   if (regnum == TIC6X_PC_REGNUM)
00455     regnum = cache->return_regnum;
00456 
00457   if (regnum == TIC6X_SP_REGNUM && cache->cfa)
00458     return frame_unwind_got_constant (this_frame, regnum, cache->cfa);
00459 
00460   /* If we've worked out where a register is stored then load it from
00461      there.  */
00462   if (regnum < TIC6X_NUM_CORE_REGS && cache->reg_saved[regnum] != -1)
00463     return frame_unwind_got_memory (this_frame, regnum,
00464                                     cache->reg_saved[regnum]);
00465 
00466   return frame_unwind_got_register (this_frame, regnum, regnum);
00467 }
00468 
00469 static CORE_ADDR
00470 tic6x_frame_base_address (struct frame_info *this_frame, void **this_cache)
00471 {
00472   struct tic6x_unwind_cache *info
00473     = tic6x_frame_unwind_cache (this_frame, this_cache);
00474   return info->base;
00475 }
00476 
00477 static const struct frame_unwind tic6x_frame_unwind =
00478 {
00479   NORMAL_FRAME,
00480   default_frame_unwind_stop_reason,
00481   tic6x_frame_this_id,
00482   tic6x_frame_prev_register,
00483   NULL,
00484   default_frame_sniffer
00485 };
00486 
00487 static const struct frame_base tic6x_frame_base =
00488 {
00489   &tic6x_frame_unwind,
00490   tic6x_frame_base_address,
00491   tic6x_frame_base_address,
00492   tic6x_frame_base_address
00493 };
00494 
00495 
00496 static struct tic6x_unwind_cache *
00497 tic6x_make_stub_cache (struct frame_info *this_frame)
00498 {
00499   struct tic6x_unwind_cache *cache;
00500 
00501   cache = FRAME_OBSTACK_ZALLOC (struct tic6x_unwind_cache);
00502 
00503   cache->return_regnum = TIC6X_RA_REGNUM;
00504 
00505   tic6x_setup_default (cache);
00506 
00507   cache->cfa = get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM);
00508 
00509   return cache;
00510 }
00511 
00512 static void
00513 tic6x_stub_this_id (struct frame_info *this_frame, void **this_cache,
00514                     struct frame_id *this_id)
00515 {
00516   struct tic6x_unwind_cache *cache;
00517 
00518   if (*this_cache == NULL)
00519     *this_cache = tic6x_make_stub_cache (this_frame);
00520   cache = *this_cache;
00521 
00522   *this_id = frame_id_build (cache->cfa, get_frame_pc (this_frame));
00523 }
00524 
00525 static int
00526 tic6x_stub_unwind_sniffer (const struct frame_unwind *self,
00527                            struct frame_info *this_frame,
00528                            void **this_prologue_cache)
00529 {
00530   CORE_ADDR addr_in_block;
00531 
00532   addr_in_block = get_frame_address_in_block (this_frame);
00533   if (in_plt_section (addr_in_block))
00534     return 1;
00535 
00536   return 0;
00537 }
00538 
00539 static const struct frame_unwind tic6x_stub_unwind =
00540 {
00541   NORMAL_FRAME,
00542   default_frame_unwind_stop_reason,
00543   tic6x_stub_this_id,
00544   tic6x_frame_prev_register,
00545   NULL,
00546   tic6x_stub_unwind_sniffer
00547 };
00548 
00549 /* Return the instruction on address PC.  */
00550 
00551 static unsigned long
00552 tic6x_fetch_instruction (struct gdbarch *gdbarch, CORE_ADDR pc)
00553 {
00554   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00555   return read_memory_unsigned_integer (pc, TIC6X_OPCODE_SIZE, byte_order);
00556 }
00557 
00558 /* Compute the condition of INST if it is a conditional instruction.  Always
00559    return 1 if INST is not a conditional instruction.  */
00560 
00561 static int
00562 tic6x_condition_true (struct frame_info *frame, unsigned long inst)
00563 {
00564   int register_number;
00565   int register_value;
00566   static const int register_numbers[8] = { -1, 16, 17, 18, 1, 2, 0, -1 };
00567 
00568   register_number = register_numbers[(inst >> 29) & 7];
00569   if (register_number == -1)
00570     return 1;
00571 
00572   register_value = get_frame_register_signed (frame, register_number);
00573   if ((inst & 0x10000000) != 0)
00574     return register_value == 0;
00575   return register_value != 0;
00576 }
00577 
00578 /* Get the register number by decoding raw bits REG, SIDE, and CROSSPATH in
00579    instruction.  */
00580 
00581 static int
00582 tic6x_register_number (int reg, int side, int crosspath)
00583 {
00584   int r = (reg & 15) | ((crosspath ^ side) << 4);
00585   if ((reg & 16) != 0) /* A16 - A31, B16 - B31 */
00586     r += 37;
00587   return r;
00588 }
00589 
00590 static int
00591 tic6x_extract_signed_field (int value, int low_bit, int bits)
00592 {
00593   int mask = (1 << bits) - 1;
00594   int r = (value >> low_bit) & mask;
00595   if ((r & (1 << (bits - 1))) != 0)
00596     r -= mask + 1;
00597   return r;
00598 }
00599 
00600 /* Determine where to set a single step breakpoint.  */
00601 
00602 static CORE_ADDR
00603 tic6x_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
00604 {
00605   struct gdbarch *gdbarch = get_frame_arch (frame);
00606   unsigned long inst;
00607   int register_number;
00608   int last = 0;
00609 
00610   do
00611     {
00612       inst = tic6x_fetch_instruction (gdbarch, pc);
00613 
00614       last = !(inst & 1);
00615 
00616       if (inst == TIC6X_INST_SWE)
00617         {
00618           struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00619 
00620           if (tdep->syscall_next_pc != NULL)
00621             return tdep->syscall_next_pc (frame);
00622         }
00623 
00624       if (tic6x_condition_true (frame, inst))
00625         {
00626           if ((inst & 0x0000007c) == 0x00000010)
00627             {
00628               /* B with displacement */
00629               pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
00630               pc += tic6x_extract_signed_field (inst, 7, 21) << 2;
00631               break;
00632             }
00633           if ((inst & 0x0f83effc) == 0x00000360)
00634             {
00635               /* B with register */
00636 
00637               register_number = tic6x_register_number ((inst >> 18) & 0x1f,
00638                                                        INST_S_BIT (inst),
00639                                                        INST_X_BIT (inst));
00640               pc = get_frame_register_unsigned (frame, register_number);
00641               break;
00642             }
00643           if ((inst & 0x00001ffc) == 0x00001020)
00644             {
00645               /* BDEC */
00646               register_number = tic6x_register_number ((inst >> 23) & 0x1f,
00647                                                        INST_S_BIT (inst), 0);
00648               if (get_frame_register_signed (frame, register_number) >= 0)
00649                 {
00650                   pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
00651                   pc += tic6x_extract_signed_field (inst, 7, 10) << 2;
00652                 }
00653               break;
00654             }
00655           if ((inst & 0x00001ffc) == 0x00000120)
00656             {
00657               /* BNOP with displacement */
00658               pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
00659               pc += tic6x_extract_signed_field (inst, 16, 12) << 2;
00660               break;
00661             }
00662           if ((inst & 0x0f830ffe) == 0x00800362)
00663             {
00664               /* BNOP with register */
00665               register_number = tic6x_register_number ((inst >> 18) & 0x1f,
00666                                                        1, INST_X_BIT (inst));
00667               pc = get_frame_register_unsigned (frame, register_number);
00668               break;
00669             }
00670           if ((inst & 0x00001ffc) == 0x00000020)
00671             {
00672               /* BPOS */
00673               register_number = tic6x_register_number ((inst >> 23) & 0x1f,
00674                                                        INST_S_BIT (inst), 0);
00675               if (get_frame_register_signed (frame, register_number) >= 0)
00676                 {
00677                   pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
00678                   pc += tic6x_extract_signed_field (inst, 13, 10) << 2;
00679                 }
00680               break;
00681             }
00682           if ((inst & 0xf000007c) == 0x10000010)
00683             {
00684               /* CALLP */
00685               pc &= ~(TIC6X_FETCH_PACKET_SIZE - 1);
00686               pc += tic6x_extract_signed_field (inst, 7, 21) << 2;
00687               break;
00688             }
00689         }
00690       pc += TIC6X_OPCODE_SIZE;
00691     }
00692   while (!last);
00693   return pc;
00694 }
00695 
00696 /* This is the implementation of gdbarch method software_single_step.  */
00697 
00698 static int
00699 tic6x_software_single_step (struct frame_info *frame)
00700 {
00701   struct gdbarch *gdbarch = get_frame_arch (frame);
00702   struct address_space *aspace = get_frame_address_space (frame);
00703   CORE_ADDR next_pc = tic6x_get_next_pc (frame, get_frame_pc (frame));
00704 
00705   insert_single_step_breakpoint (gdbarch, aspace, next_pc);
00706 
00707   return 1;
00708 }
00709 
00710 /* This is the implementation of gdbarch method frame_align.  */
00711 
00712 static CORE_ADDR
00713 tic6x_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
00714 {
00715   return align_down (addr, 8);
00716 }
00717 
00718 /* Given a return value in REGCACHE with a type VALTYPE, extract and copy its
00719    value into VALBUF.  */
00720 
00721 static void
00722 tic6x_extract_return_value (struct type *valtype, struct regcache *regcache,
00723                             enum bfd_endian byte_order, gdb_byte *valbuf)
00724 {
00725   int len = TYPE_LENGTH (valtype);
00726 
00727   /* pointer types are returned in register A4,
00728      up to 32-bit types in A4
00729      up to 64-bit types in A5:A4  */
00730   if (len <= 4)
00731     {
00732       /* In big-endian,
00733          - one-byte structure or union occupies the LSB of single even register.
00734          - for two-byte structure or union, the first byte occupies byte 1 of
00735          register and the second byte occupies byte 0.
00736          so, we read the contents in VAL from the LSBs of register.  */
00737       if (len < 3 && byte_order == BFD_ENDIAN_BIG)
00738         regcache_cooked_read_part (regcache, TIC6X_A4_REGNUM, 4 - len, len,
00739                                    valbuf);
00740       else
00741         regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf);
00742     }
00743   else if (len <= 8)
00744     {
00745       /* For a 5-8 byte structure or union in big-endian, the first byte
00746          occupies byte 3 (the MSB) of the upper (odd) register and the
00747          remaining bytes fill the decreasingly significant bytes.  5-7
00748          byte structures or unions have padding in the LSBs of the
00749          lower (even) register.  */
00750       if (byte_order == BFD_ENDIAN_BIG)
00751         {
00752           regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf + 4);
00753           regcache_cooked_read (regcache, TIC6X_A5_REGNUM, valbuf);
00754         }
00755       else
00756         {
00757           regcache_cooked_read (regcache, TIC6X_A4_REGNUM, valbuf);
00758           regcache_cooked_read (regcache, TIC6X_A5_REGNUM, valbuf + 4);
00759         }
00760     }
00761 }
00762 
00763 /* Write into appropriate registers a function return value
00764    of type TYPE, given in virtual format.  */
00765 
00766 static void
00767 tic6x_store_return_value (struct type *valtype, struct regcache *regcache,
00768                           enum bfd_endian byte_order, const gdb_byte *valbuf)
00769 {
00770   int len = TYPE_LENGTH (valtype);
00771 
00772   /* return values of up to 8 bytes are returned in A5:A4 */
00773 
00774   if (len <= 4)
00775     {
00776       if (len < 3 && byte_order == BFD_ENDIAN_BIG)
00777         regcache_cooked_write_part (regcache, TIC6X_A4_REGNUM, 4 - len, len,
00778                                     valbuf);
00779       else
00780         regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf);
00781     }
00782   else if (len <= 8)
00783     {
00784       if (byte_order == BFD_ENDIAN_BIG)
00785         {
00786           regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf + 4);
00787           regcache_cooked_write (regcache, TIC6X_A5_REGNUM, valbuf);
00788         }
00789       else
00790         {
00791           regcache_cooked_write (regcache, TIC6X_A4_REGNUM, valbuf);
00792           regcache_cooked_write (regcache, TIC6X_A5_REGNUM, valbuf + 4);
00793         }
00794     }
00795 }
00796 
00797 /* This is the implementation of gdbarch method return_value.  */
00798 
00799 static enum return_value_convention
00800 tic6x_return_value (struct gdbarch *gdbarch, struct value *function,
00801                     struct type *type, struct regcache *regcache,
00802                     gdb_byte *readbuf, const gdb_byte *writebuf)
00803 {
00804   /* In C++, when function returns an object, even its size is small
00805      enough, it stii has to be passed via reference, pointed by register
00806      A3.  */
00807   if (current_language->la_language == language_cplus)
00808     {
00809       if (type != NULL)
00810         {
00811           CHECK_TYPEDEF (type);
00812           if (language_pass_by_reference (type))
00813             return RETURN_VALUE_STRUCT_CONVENTION;
00814         }
00815     }
00816 
00817   if (TYPE_LENGTH (type) > 8)
00818     return RETURN_VALUE_STRUCT_CONVENTION;
00819 
00820   if (readbuf)
00821     tic6x_extract_return_value (type, regcache,
00822                                 gdbarch_byte_order (gdbarch), readbuf);
00823   if (writebuf)
00824     tic6x_store_return_value (type, regcache,
00825                               gdbarch_byte_order (gdbarch), writebuf);
00826 
00827   return RETURN_VALUE_REGISTER_CONVENTION;
00828 }
00829 
00830 /* This is the implementation of gdbarch method dummy_id.  */
00831 
00832 static struct frame_id
00833 tic6x_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
00834 {
00835   return frame_id_build
00836     (get_frame_register_unsigned (this_frame, TIC6X_SP_REGNUM),
00837      get_frame_pc (this_frame));
00838 }
00839 
00840 /* Get the alignment requirement of TYPE.  */
00841 
00842 static int
00843 tic6x_arg_type_alignment (struct type *type)
00844 {
00845   int len = TYPE_LENGTH (check_typedef (type));
00846   enum type_code typecode = TYPE_CODE (check_typedef (type));
00847 
00848   if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
00849     {
00850       /* The stack alignment of a structure (and union) passed by value is the
00851          smallest power of two greater than or equal to its size.
00852          This cannot exceed 8 bytes, which is the largest allowable size for
00853          a structure passed by value.  */
00854 
00855       if (len <= 2)
00856         return len;
00857       else if (len <= 4)
00858         return 4;
00859       else if (len <= 8)
00860         return 8;
00861       else
00862         gdb_assert_not_reached ("unexpected length of data");
00863     }
00864   else
00865     {
00866       if (len <= 4)
00867         return 4;
00868       else if (len == 8)
00869         {
00870           if (typecode == TYPE_CODE_COMPLEX)
00871             return 4;
00872           else
00873             return 8;
00874         }
00875       else if (len == 16)
00876         {
00877           if (typecode == TYPE_CODE_COMPLEX)
00878             return 8;
00879           else
00880             return 16;
00881         }
00882       else
00883         internal_error (__FILE__, __LINE__, _("unexpected length %d of type"),
00884                         len);
00885     }
00886 }
00887 
00888 /* This is the implementation of gdbarch method push_dummy_call.  */
00889 
00890 static CORE_ADDR
00891 tic6x_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00892                        struct regcache *regcache, CORE_ADDR bp_addr,
00893                        int nargs, struct value **args, CORE_ADDR sp,
00894                        int struct_return, CORE_ADDR struct_addr)
00895 {
00896   int argreg = 0;
00897   int argnum;
00898   int stack_offset = 4;
00899   int references_offset = 4;
00900   CORE_ADDR func_addr = find_function_addr (function, NULL);
00901   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00902   struct type *func_type = value_type (function);
00903   /* The first arg passed on stack.  Mostly the first 10 args are passed by
00904      registers.  */
00905   int first_arg_on_stack = 10;
00906 
00907   /* Set the return address register to point to the entry point of
00908      the program, where a breakpoint lies in wait.  */
00909   regcache_cooked_write_unsigned (regcache, TIC6X_RA_REGNUM, bp_addr);
00910 
00911   /* The caller must pass an argument in A3 containing a destination address
00912      for the returned value.  The callee returns the object by copying it to
00913      the address in A3.  */
00914   if (struct_return)
00915     regcache_cooked_write_unsigned (regcache, 3, struct_addr);
00916 
00917   /* Determine the type of this function.  */
00918   func_type = check_typedef (func_type);
00919   if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
00920     func_type = check_typedef (TYPE_TARGET_TYPE (func_type));
00921 
00922   gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
00923               || TYPE_CODE (func_type) == TYPE_CODE_METHOD);
00924 
00925   /* For a variadic C function, the last explicitly declared argument and all
00926      remaining arguments are passed on the stack.  */
00927   if (TYPE_VARARGS (func_type))
00928     first_arg_on_stack = TYPE_NFIELDS (func_type) - 1;
00929 
00930   /* Now make space on the stack for the args.  */
00931   for (argnum = 0; argnum < nargs; argnum++)
00932     {
00933       int len = align_up (TYPE_LENGTH (value_type (args[argnum])), 4);
00934       if (argnum >= 10 - argreg)
00935         references_offset += len;
00936       stack_offset += len;
00937     }
00938   sp -= stack_offset;
00939   /* SP should be 8-byte aligned, see C6000 ABI section 4.4.1
00940      Stack Alignment.  */
00941   sp = align_down (sp, 8);
00942   stack_offset = 4;
00943 
00944   /* Now load as many as possible of the first arguments into
00945      registers, and push the rest onto the stack.  Loop through args
00946      from first to last.  */
00947   for (argnum = 0; argnum < nargs; argnum++)
00948     {
00949       const gdb_byte *val;
00950       struct value *arg = args[argnum];
00951       struct type *arg_type = check_typedef (value_type (arg));
00952       int len = TYPE_LENGTH (arg_type);
00953       enum type_code typecode = TYPE_CODE (arg_type);
00954 
00955       val = value_contents (arg);
00956 
00957       /* Copy the argument to general registers or the stack in
00958          register-sized pieces.  */
00959       if (argreg < first_arg_on_stack)
00960         {
00961           if (len <= 4)
00962             {
00963               if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
00964                 {
00965                   /* In big-endian,
00966                      - one-byte structure or union occupies the LSB of single
00967                      even register.
00968                      - for two-byte structure or union, the first byte
00969                      occupies byte 1 of register and the second byte occupies
00970                      byte 0.
00971                      so, we write the contents in VAL to the lsp of
00972                      register.  */
00973                   if (len < 3 && byte_order == BFD_ENDIAN_BIG)
00974                     regcache_cooked_write_part (regcache, arg_regs[argreg],
00975                                                 4 - len, len, val);
00976                   else
00977                     regcache_cooked_write (regcache, arg_regs[argreg], val);
00978                 }
00979               else
00980                 {
00981                   /* The argument is being passed by value in a single
00982                      register.  */
00983                   CORE_ADDR regval = extract_unsigned_integer (val, len,
00984                                                                byte_order);
00985 
00986                   regcache_cooked_write_unsigned (regcache, arg_regs[argreg],
00987                                                   regval);
00988                 }
00989             }
00990           else
00991             {
00992               if (len <= 8)
00993                 {
00994                   if (typecode == TYPE_CODE_STRUCT
00995                       || typecode == TYPE_CODE_UNION)
00996                     {
00997                       /* For a 5-8 byte structure or union in big-endian, the
00998                          first byte occupies byte 3 (the MSB) of the upper (odd)
00999                          register and the remaining bytes fill the decreasingly
01000                          significant bytes.  5-7 byte structures or unions have
01001                          padding in the LSBs of the lower (even) register.  */
01002                       if (byte_order == BFD_ENDIAN_BIG)
01003                         {
01004                           regcache_cooked_write (regcache,
01005                                                  arg_regs[argreg] + 1, val);
01006                           regcache_cooked_write_part (regcache,
01007                                                       arg_regs[argreg], 0,
01008                                                       len - 4, val + 4);
01009                         }
01010                       else
01011                         {
01012                           regcache_cooked_write (regcache, arg_regs[argreg],
01013                                                  val);
01014                           regcache_cooked_write_part (regcache,
01015                                                       arg_regs[argreg] + 1, 0,
01016                                                       len - 4, val + 4);
01017                         }
01018                     }
01019                   else
01020                     {
01021                       /* The argument is being passed by value in a pair of
01022                          registers.  */
01023                       ULONGEST regval = extract_unsigned_integer (val, len,
01024                                                                   byte_order);
01025 
01026                       regcache_cooked_write_unsigned (regcache,
01027                                                       arg_regs[argreg],
01028                                                       regval);
01029                       regcache_cooked_write_unsigned (regcache,
01030                                                       arg_regs[argreg] + 1,
01031                                                       regval >> 32);
01032                     }
01033                 }
01034               else
01035                 {
01036                   /* The argument is being passed by reference in a single
01037                      register.  */
01038                   CORE_ADDR addr;
01039 
01040                   /* It is not necessary to adjust REFERENCES_OFFSET to
01041                      8-byte aligned in some cases, in which 4-byte alignment
01042                      is sufficient.  For simplicity, we adjust
01043                      REFERENCES_OFFSET to 8-byte aligned.  */
01044                   references_offset = align_up (references_offset, 8);
01045 
01046                   addr = sp + references_offset;
01047                   write_memory (addr, val, len);
01048                   references_offset += align_up (len, 4);
01049                   regcache_cooked_write_unsigned (regcache, arg_regs[argreg],
01050                                                   addr);
01051                 }
01052             }
01053           argreg++;
01054         }
01055       else
01056         {
01057           /* The argument is being passed on the stack.  */
01058           CORE_ADDR addr;
01059 
01060           /* There are six different cases of alignment, and these rules can
01061              be found in tic6x_arg_type_alignment:
01062 
01063              1) 4-byte aligned if size is less than or equal to 4 byte, such
01064              as short, int, struct, union etc.
01065              2) 8-byte aligned if size is less than or equal to 8-byte, such
01066              as double, long long,
01067              3) 4-byte aligned if it is of type _Complex float, even its size
01068              is 8-byte.
01069              4) 8-byte aligned if it is of type _Complex double or _Complex
01070              long double, even its size is 16-byte.  Because, the address of
01071              variable is passed as reference.
01072              5) struct and union larger than 8-byte are passed by reference, so
01073              it is 4-byte aligned.
01074              6) struct and union of size between 4 byte and 8 byte varies.
01075              alignment of struct variable is the alignment of its first field,
01076              while alignment of union variable is the max of all its fields'
01077              alignment.  */
01078 
01079           if (len <= 4)
01080             ; /* Default is 4-byte aligned.  Nothing to be done.  */
01081           else if (len <= 8)
01082             stack_offset = align_up (stack_offset,
01083                                      tic6x_arg_type_alignment (arg_type));
01084           else if (len == 16)
01085             {
01086               /* _Complex double or _Complex long double */
01087               if (typecode == TYPE_CODE_COMPLEX)
01088                 {
01089                   /* The argument is being passed by reference on stack.  */
01090                   CORE_ADDR addr;
01091                   references_offset = align_up (references_offset, 8);
01092 
01093                   addr = sp + references_offset;
01094                   /* Store variable on stack.  */
01095                   write_memory (addr, val, len);
01096 
01097                   references_offset += align_up (len, 4);
01098 
01099                   /* Pass the address of variable on stack as reference.  */
01100                   store_unsigned_integer ((gdb_byte *) val, 4, byte_order,
01101                                           addr);
01102                   len = 4;
01103 
01104                 }
01105               else
01106                 internal_error (__FILE__, __LINE__,
01107                                 _("unexpected type %d of arg %d"),
01108                                 typecode, argnum);
01109             }
01110           else
01111             internal_error (__FILE__, __LINE__,
01112                             _("unexpected length %d of arg %d"), len, argnum);
01113 
01114           addr = sp + stack_offset;
01115           write_memory (addr, val, len);
01116           stack_offset += align_up (len, 4);
01117         }
01118     }
01119 
01120   regcache_cooked_write_signed (regcache, TIC6X_SP_REGNUM, sp);
01121 
01122   /* Return adjusted stack pointer.  */
01123   return sp;
01124 }
01125 
01126 /* This is the implementation of gdbarch method in_function_epilogue_p.  */
01127 
01128 static int
01129 tic6x_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
01130 {
01131   unsigned long inst = tic6x_fetch_instruction (gdbarch, pc);
01132   /* Normally, the epilogue is composed by instruction `b .S2 b3'.  */
01133   if ((inst & 0x0f83effc) == 0x360)
01134     {
01135       unsigned int src2 = tic6x_register_number ((inst >> 18) & 0x1f,
01136                                                  INST_S_BIT (inst),
01137                                                  INST_X_BIT (inst));
01138       if (src2 == TIC6X_RA_REGNUM)
01139         return 1;
01140     }
01141 
01142   return 0;
01143 }
01144 
01145 /* This is the implementation of gdbarch method get_longjmp_target.  */
01146 
01147 static int
01148 tic6x_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
01149 {
01150   struct gdbarch *gdbarch = get_frame_arch (frame);
01151   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01152   CORE_ADDR jb_addr;
01153   gdb_byte buf[4];
01154 
01155   /* JMP_BUF is passed by reference in A4.  */
01156   jb_addr = get_frame_register_unsigned (frame, 4);
01157 
01158   /* JMP_BUF contains 13 elements of type int, and return address is stored
01159      in the last slot.  */
01160   if (target_read_memory (jb_addr + 12 * 4, buf, 4))
01161     return 0;
01162 
01163   *pc = extract_unsigned_integer (buf, 4, byte_order);
01164 
01165   return 1;
01166 }
01167 
01168 /* This is the implementation of gdbarch method
01169    return_in_first_hidden_param_p.  */
01170 
01171 static int
01172 tic6x_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
01173                                       struct type *type)
01174 {
01175   return 0;
01176 }
01177 
01178 static struct gdbarch *
01179 tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
01180 {
01181   struct gdbarch *gdbarch;
01182   struct gdbarch_tdep *tdep;
01183   struct tdesc_arch_data *tdesc_data = NULL;
01184   const struct target_desc *tdesc = info.target_desc;
01185   int has_gp = 0;
01186 
01187   /* Check any target description for validity.  */
01188   if (tdesc_has_registers (tdesc))
01189     {
01190       const struct tdesc_feature *feature;
01191       int valid_p, i;
01192 
01193       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.core");
01194 
01195       if (feature == NULL)
01196         return NULL;
01197 
01198       tdesc_data = tdesc_data_alloc ();
01199 
01200       valid_p = 1;
01201       for (i = 0; i < 32; i++)  /* A0 - A15, B0 - B15 */
01202         valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
01203                                             tic6x_register_names[i]);
01204 
01205       /* CSR */
01206       valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
01207                                           tic6x_register_names[TIC6X_CSR_REGNUM]);
01208       valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
01209                                           tic6x_register_names[TIC6X_PC_REGNUM]);
01210 
01211       if (!valid_p)
01212         {
01213           tdesc_data_cleanup (tdesc_data);
01214           return NULL;
01215         }
01216 
01217       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.gp");
01218       if (feature)
01219         {
01220           int j = 0;
01221           static const char *const gp[] =
01222             {
01223               "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23",
01224               "A24", "A25", "A26", "A27", "A28", "A29", "A30", "A31",
01225               "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23",
01226               "B24", "B25", "B26", "B27", "B28", "B29", "B30", "B31",
01227             };
01228 
01229           has_gp = 1;
01230           valid_p = 1;
01231           for (j = 0; j < 32; j++)      /* A16 - A31, B16 - B31 */
01232             valid_p &= tdesc_numbered_register (feature, tdesc_data, i++,
01233                                                 gp[j]);
01234 
01235           if (!valid_p)
01236             {
01237               tdesc_data_cleanup (tdesc_data);
01238               return NULL;
01239             }
01240         }
01241 
01242       feature = tdesc_find_feature (tdesc, "org.gnu.gdb.tic6x.c6xp");
01243       if (feature)
01244         {
01245           valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "TSR");
01246           valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "ILC");
01247           valid_p &= tdesc_numbered_register (feature, tdesc_data, i++, "RILC");
01248 
01249           if (!valid_p)
01250             {
01251               tdesc_data_cleanup (tdesc_data);
01252               return NULL;
01253             }
01254         }
01255 
01256     }
01257 
01258   /* Find a candidate among extant architectures.  */
01259   for (arches = gdbarch_list_lookup_by_info (arches, &info);
01260        arches != NULL;
01261        arches = gdbarch_list_lookup_by_info (arches->next, &info))
01262     {
01263       tdep = gdbarch_tdep (arches->gdbarch);
01264 
01265       if (has_gp != tdep->has_gp)
01266         continue;
01267 
01268       if (tdep && tdep->breakpoint)
01269         return arches->gdbarch;
01270     }
01271 
01272   tdep = xcalloc (1, sizeof (struct gdbarch_tdep));
01273 
01274   tdep->has_gp = has_gp;
01275   gdbarch = gdbarch_alloc (&info, tdep);
01276 
01277   /* Data type sizes.  */
01278   set_gdbarch_ptr_bit (gdbarch, 32);
01279   set_gdbarch_addr_bit (gdbarch, 32);
01280   set_gdbarch_short_bit (gdbarch, 16);
01281   set_gdbarch_int_bit (gdbarch, 32);
01282   set_gdbarch_long_bit (gdbarch, 32);
01283   set_gdbarch_long_long_bit (gdbarch, 64);
01284   set_gdbarch_float_bit (gdbarch, 32);
01285   set_gdbarch_double_bit (gdbarch, 64);
01286 
01287   set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
01288   set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
01289 
01290   /* The register set.  */
01291   set_gdbarch_num_regs (gdbarch, TIC6X_NUM_REGS);
01292   set_gdbarch_sp_regnum (gdbarch, TIC6X_SP_REGNUM);
01293   set_gdbarch_pc_regnum (gdbarch, TIC6X_PC_REGNUM);
01294 
01295   set_gdbarch_register_name (gdbarch, tic6x_register_name);
01296   set_gdbarch_register_type (gdbarch, tic6x_register_type);
01297 
01298   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
01299 
01300   set_gdbarch_skip_prologue (gdbarch, tic6x_skip_prologue);
01301   set_gdbarch_breakpoint_from_pc (gdbarch, tic6x_breakpoint_from_pc);
01302 
01303   set_gdbarch_unwind_pc (gdbarch, tic6x_unwind_pc);
01304   set_gdbarch_unwind_sp (gdbarch, tic6x_unwind_sp);
01305 
01306   /* Unwinding.  */
01307   dwarf2_append_unwinders (gdbarch);
01308 
01309   frame_unwind_append_unwinder (gdbarch, &tic6x_stub_unwind);
01310   frame_unwind_append_unwinder (gdbarch, &tic6x_frame_unwind);
01311 
01312   dwarf2_frame_set_init_reg (gdbarch, tic6x_dwarf2_frame_init_reg);
01313 
01314   /* Single stepping.  */
01315   set_gdbarch_software_single_step (gdbarch, tic6x_software_single_step);
01316 
01317   set_gdbarch_print_insn (gdbarch, tic6x_print_insn);
01318 
01319   /* Call dummy code.  */
01320   set_gdbarch_frame_align (gdbarch, tic6x_frame_align);
01321 
01322   set_gdbarch_return_value (gdbarch, tic6x_return_value);
01323 
01324   set_gdbarch_dummy_id (gdbarch, tic6x_dummy_id);
01325 
01326   /* Enable inferior call support.  */
01327   set_gdbarch_push_dummy_call (gdbarch, tic6x_push_dummy_call);
01328 
01329   set_gdbarch_get_longjmp_target (gdbarch, tic6x_get_longjmp_target);
01330 
01331   set_gdbarch_in_function_epilogue_p (gdbarch, tic6x_in_function_epilogue_p);
01332 
01333   set_gdbarch_return_in_first_hidden_param_p (gdbarch,
01334                                               tic6x_return_in_first_hidden_param_p);
01335 
01336   /* Hook in ABI-specific overrides, if they have been registered.  */
01337   gdbarch_init_osabi (info, gdbarch);
01338 
01339   if (tdesc_data)
01340     tdesc_use_registers (gdbarch, tdesc, tdesc_data);
01341 
01342   return gdbarch;
01343 }
01344 
01345 /* -Wmissing-prototypes */
01346 extern initialize_file_ftype _initialize_tic6x_tdep;
01347 
01348 void
01349 _initialize_tic6x_tdep (void)
01350 {
01351   register_gdbarch_init (bfd_arch_tic6x, tic6x_gdbarch_init);
01352 
01353   initialize_tdesc_tic6x_c64xp ();
01354   initialize_tdesc_tic6x_c64x ();
01355   initialize_tdesc_tic6x_c62x ();
01356 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines