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