tic6x-tdep.c 38 KB

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