or1k-tdep.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. /* Target-dependent code for the 32-bit OpenRISC 1000, for the GDB.
  2. Copyright (C) 2008-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "inferior.h"
  17. #include "symtab.h"
  18. #include "value.h"
  19. #include "gdbcmd.h"
  20. #include "language.h"
  21. #include "gdbcore.h"
  22. #include "symfile.h"
  23. #include "objfiles.h"
  24. #include "gdbtypes.h"
  25. #include "target.h"
  26. #include "regcache.h"
  27. #include "safe-ctype.h"
  28. #include "block.h"
  29. #include "reggroups.h"
  30. #include "arch-utils.h"
  31. #include "frame-unwind.h"
  32. #include "frame-base.h"
  33. #include "dwarf2/frame.h"
  34. #include "trad-frame.h"
  35. #include "regset.h"
  36. #include "remote.h"
  37. #include "target-descriptions.h"
  38. #include <inttypes.h>
  39. #include "dis-asm.h"
  40. #include "gdbarch.h"
  41. /* OpenRISC specific includes. */
  42. #include "or1k-tdep.h"
  43. #include "features/or1k.c"
  44. /* Global debug flag. */
  45. static bool or1k_debug = false;
  46. static void
  47. show_or1k_debug (struct ui_file *file, int from_tty,
  48. struct cmd_list_element *c, const char *value)
  49. {
  50. gdb_printf (file, _("OpenRISC debugging is %s.\n"), value);
  51. }
  52. /* The target-dependent structure for gdbarch. */
  53. struct or1k_gdbarch_tdep : gdbarch_tdep
  54. {
  55. int bytes_per_word = 0;
  56. int bytes_per_address = 0;
  57. CGEN_CPU_DESC gdb_cgen_cpu_desc = nullptr;
  58. };
  59. /* Support functions for the architecture definition. */
  60. /* Get an instruction from memory. */
  61. static ULONGEST
  62. or1k_fetch_instruction (struct gdbarch *gdbarch, CORE_ADDR addr)
  63. {
  64. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  65. gdb_byte buf[OR1K_INSTLEN];
  66. if (target_read_code (addr, buf, OR1K_INSTLEN)) {
  67. memory_error (TARGET_XFER_E_IO, addr);
  68. }
  69. return extract_unsigned_integer (buf, OR1K_INSTLEN, byte_order);
  70. }
  71. /* Generic function to read bits from an instruction. */
  72. static bool
  73. or1k_analyse_inst (uint32_t inst, const char *format, ...)
  74. {
  75. /* Break out each field in turn, validating as we go. */
  76. va_list ap;
  77. int i;
  78. int iptr = 0; /* Instruction pointer */
  79. va_start (ap, format);
  80. for (i = 0; 0 != format[i];)
  81. {
  82. const char *start_ptr;
  83. char *end_ptr;
  84. uint32_t bits; /* Bit substring of interest */
  85. uint32_t width; /* Substring width */
  86. uint32_t *arg_ptr;
  87. switch (format[i])
  88. {
  89. case ' ':
  90. i++;
  91. break; /* Formatting: ignored */
  92. case '0':
  93. case '1': /* Constant bit field */
  94. bits = (inst >> (OR1K_INSTBITLEN - iptr - 1)) & 0x1;
  95. if ((format[i] - '0') != bits)
  96. return false;
  97. iptr++;
  98. i++;
  99. break;
  100. case '%': /* Bit field */
  101. i++;
  102. start_ptr = &(format[i]);
  103. width = strtoul (start_ptr, &end_ptr, 10);
  104. /* Check we got something, and if so skip on. */
  105. if (start_ptr == end_ptr)
  106. error (_("bitstring \"%s\" at offset %d has no length field."),
  107. format, i);
  108. i += end_ptr - start_ptr;
  109. /* Look for and skip the terminating 'b'. If it's not there, we
  110. still give a fatal error, because these are fixed strings that
  111. just should not be wrong. */
  112. if ('b' != format[i++])
  113. error (_("bitstring \"%s\" at offset %d has no terminating 'b'."),
  114. format, i);
  115. /* Break out the field. There is a special case with a bit width
  116. of 32. */
  117. if (32 == width)
  118. bits = inst;
  119. else
  120. bits =
  121. (inst >> (OR1K_INSTBITLEN - iptr - width)) & ((1 << width) - 1);
  122. arg_ptr = va_arg (ap, uint32_t *);
  123. *arg_ptr = bits;
  124. iptr += width;
  125. break;
  126. default:
  127. error (_("invalid character in bitstring \"%s\" at offset %d."),
  128. format, i);
  129. break;
  130. }
  131. }
  132. /* Is the length OK? */
  133. gdb_assert (OR1K_INSTBITLEN == iptr);
  134. return true; /* Success */
  135. }
  136. /* This is used to parse l.addi instructions during various prologue
  137. analysis routines. The l.addi instruction has semantics:
  138. assembly: l.addi rD,rA,I
  139. implementation: rD = rA + sign_extend(Immediate)
  140. The rd_ptr, ra_ptr and simm_ptr must be non NULL pointers and are used
  141. to store the parse results. Upon successful parsing true is returned,
  142. false on failure. */
  143. static bool
  144. or1k_analyse_l_addi (uint32_t inst, unsigned int *rd_ptr,
  145. unsigned int *ra_ptr, int *simm_ptr)
  146. {
  147. /* Instruction fields */
  148. uint32_t rd, ra, i;
  149. if (or1k_analyse_inst (inst, "10 0111 %5b %5b %16b", &rd, &ra, &i))
  150. {
  151. /* Found it. Construct the result fields. */
  152. *rd_ptr = (unsigned int) rd;
  153. *ra_ptr = (unsigned int) ra;
  154. *simm_ptr = (int) (((i & 0x8000) == 0x8000) ? 0xffff0000 | i : i);
  155. return true; /* Success */
  156. }
  157. else
  158. return false; /* Failure */
  159. }
  160. /* This is used to to parse store instructions during various prologue
  161. analysis routines. The l.sw instruction has semantics:
  162. assembly: l.sw I(rA),rB
  163. implementation: store rB contents to memory at effective address of
  164. rA + sign_extend(Immediate)
  165. The simm_ptr, ra_ptr and rb_ptr must be non NULL pointers and are used
  166. to store the parse results. Upon successful parsing true is returned,
  167. false on failure. */
  168. static bool
  169. or1k_analyse_l_sw (uint32_t inst, int *simm_ptr, unsigned int *ra_ptr,
  170. unsigned int *rb_ptr)
  171. {
  172. /* Instruction fields */
  173. uint32_t ihi, ilo, ra, rb;
  174. if (or1k_analyse_inst (inst, "11 0101 %5b %5b %5b %11b", &ihi, &ra, &rb,
  175. &ilo))
  176. {
  177. /* Found it. Construct the result fields. */
  178. *simm_ptr = (int) ((ihi << 11) | ilo);
  179. *simm_ptr |= ((ihi & 0x10) == 0x10) ? 0xffff0000 : 0;
  180. *ra_ptr = (unsigned int) ra;
  181. *rb_ptr = (unsigned int) rb;
  182. return true; /* Success */
  183. }
  184. else
  185. return false; /* Failure */
  186. }
  187. /* Functions defining the architecture. */
  188. /* Implement the return_value gdbarch method. */
  189. static enum return_value_convention
  190. or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
  191. struct type *valtype, struct regcache *regcache,
  192. gdb_byte *readbuf, const gdb_byte *writebuf)
  193. {
  194. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  195. enum type_code rv_type = valtype->code ();
  196. unsigned int rv_size = TYPE_LENGTH (valtype);
  197. or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  198. int bpw = tdep->bytes_per_word;
  199. /* Deal with struct/union as addresses. If an array won't fit in a
  200. single register it is returned as address. Anything larger than 2
  201. registers needs to also be passed as address (matches gcc
  202. default_return_in_memory). */
  203. if ((TYPE_CODE_STRUCT == rv_type) || (TYPE_CODE_UNION == rv_type)
  204. || ((TYPE_CODE_ARRAY == rv_type) && (rv_size > bpw))
  205. || (rv_size > 2 * bpw))
  206. {
  207. if (readbuf != NULL)
  208. {
  209. ULONGEST tmp;
  210. regcache_cooked_read_unsigned (regcache, OR1K_RV_REGNUM, &tmp);
  211. read_memory (tmp, readbuf, rv_size);
  212. }
  213. if (writebuf != NULL)
  214. {
  215. ULONGEST tmp;
  216. regcache_cooked_read_unsigned (regcache, OR1K_RV_REGNUM, &tmp);
  217. write_memory (tmp, writebuf, rv_size);
  218. }
  219. return RETURN_VALUE_ABI_RETURNS_ADDRESS;
  220. }
  221. if (rv_size <= bpw)
  222. {
  223. /* Up to one word scalars are returned in R11. */
  224. if (readbuf != NULL)
  225. {
  226. ULONGEST tmp;
  227. regcache_cooked_read_unsigned (regcache, OR1K_RV_REGNUM, &tmp);
  228. store_unsigned_integer (readbuf, rv_size, byte_order, tmp);
  229. }
  230. if (writebuf != NULL)
  231. {
  232. gdb_byte *buf = XCNEWVEC(gdb_byte, bpw);
  233. if (BFD_ENDIAN_BIG == byte_order)
  234. memcpy (buf + (sizeof (gdb_byte) * bpw) - rv_size, writebuf,
  235. rv_size);
  236. else
  237. memcpy (buf, writebuf, rv_size);
  238. regcache->cooked_write (OR1K_RV_REGNUM, buf);
  239. free (buf);
  240. }
  241. }
  242. else
  243. {
  244. /* 2 word scalars are returned in r11/r12 (with the MS word in r11). */
  245. if (readbuf != NULL)
  246. {
  247. ULONGEST tmp_lo;
  248. ULONGEST tmp_hi;
  249. ULONGEST tmp;
  250. regcache_cooked_read_unsigned (regcache, OR1K_RV_REGNUM,
  251. &tmp_hi);
  252. regcache_cooked_read_unsigned (regcache, OR1K_RV_REGNUM + 1,
  253. &tmp_lo);
  254. tmp = (tmp_hi << (bpw * 8)) | tmp_lo;
  255. store_unsigned_integer (readbuf, rv_size, byte_order, tmp);
  256. }
  257. if (writebuf != NULL)
  258. {
  259. gdb_byte *buf_lo = XCNEWVEC(gdb_byte, bpw);
  260. gdb_byte *buf_hi = XCNEWVEC(gdb_byte, bpw);
  261. /* This is cheating. We assume that we fit in 2 words exactly,
  262. which wouldn't work if we had (say) a 6-byte scalar type on a
  263. big endian architecture (with the OpenRISC 1000 usually is). */
  264. memcpy (buf_hi, writebuf, rv_size - bpw);
  265. memcpy (buf_lo, writebuf + bpw, bpw);
  266. regcache->cooked_write (OR1K_RV_REGNUM, buf_hi);
  267. regcache->cooked_write (OR1K_RV_REGNUM + 1, buf_lo);
  268. free (buf_lo);
  269. free (buf_hi);
  270. }
  271. }
  272. return RETURN_VALUE_REGISTER_CONVENTION;
  273. }
  274. /* OR1K always uses a l.trap instruction for breakpoints. */
  275. constexpr gdb_byte or1k_break_insn[] = {0x21, 0x00, 0x00, 0x01};
  276. typedef BP_MANIPULATION (or1k_break_insn) or1k_breakpoint;
  277. static int
  278. or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  279. {
  280. const CGEN_INSN *insn;
  281. CGEN_FIELDS tmp_fields;
  282. or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  283. insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
  284. NULL,
  285. or1k_fetch_instruction (gdbarch, pc),
  286. NULL, 32, &tmp_fields, 0);
  287. /* NULL here would mean the last instruction was not understood by cgen.
  288. This should not usually happen, but if does its not a delay slot. */
  289. if (insn == NULL)
  290. return 0;
  291. /* TODO: we should add a delay slot flag to the CGEN_INSN and remove
  292. this hard coded test. */
  293. return ((CGEN_INSN_NUM (insn) == OR1K_INSN_L_J)
  294. || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JAL)
  295. || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JR)
  296. || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_JALR)
  297. || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_BNF)
  298. || (CGEN_INSN_NUM (insn) == OR1K_INSN_L_BF));
  299. }
  300. /* Implement the single_step_through_delay gdbarch method. */
  301. static int
  302. or1k_single_step_through_delay (struct gdbarch *gdbarch,
  303. struct frame_info *this_frame)
  304. {
  305. ULONGEST val;
  306. CORE_ADDR ppc;
  307. CORE_ADDR npc;
  308. struct regcache *regcache = get_current_regcache ();
  309. /* Get the previous and current instruction addresses. If they are not
  310. adjacent, we cannot be in a delay slot. */
  311. regcache_cooked_read_unsigned (regcache, OR1K_PPC_REGNUM, &val);
  312. ppc = (CORE_ADDR) val;
  313. regcache_cooked_read_unsigned (regcache, OR1K_NPC_REGNUM, &val);
  314. npc = (CORE_ADDR) val;
  315. if (0x4 != (npc - ppc))
  316. return 0;
  317. return or1k_delay_slot_p (gdbarch, ppc);
  318. }
  319. /* or1k_software_single_step() is called just before we want to resume
  320. the inferior, if we want to single-step it but there is no hardware
  321. or kernel single-step support (OpenRISC on GNU/Linux for example). We
  322. find the target of the coming instruction skipping over delay slots
  323. and breakpoint it. */
  324. std::vector<CORE_ADDR>
  325. or1k_software_single_step (struct regcache *regcache)
  326. {
  327. struct gdbarch *gdbarch = regcache->arch ();
  328. CORE_ADDR pc, next_pc;
  329. pc = regcache_read_pc (regcache);
  330. next_pc = pc + 4;
  331. if (or1k_delay_slot_p (gdbarch, pc))
  332. next_pc += 4;
  333. return {next_pc};
  334. }
  335. /* Name for or1k general registers. */
  336. static const char *const or1k_reg_names[OR1K_NUM_REGS] = {
  337. /* general purpose registers */
  338. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  339. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  340. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  341. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
  342. /* previous program counter, next program counter and status register */
  343. "ppc", "npc", "sr"
  344. };
  345. static int
  346. or1k_is_arg_reg (unsigned int regnum)
  347. {
  348. return (OR1K_FIRST_ARG_REGNUM <= regnum)
  349. && (regnum <= OR1K_LAST_ARG_REGNUM);
  350. }
  351. static int
  352. or1k_is_callee_saved_reg (unsigned int regnum)
  353. {
  354. return (OR1K_FIRST_SAVED_REGNUM <= regnum) && (0 == regnum % 2);
  355. }
  356. /* Implement the skip_prologue gdbarch method. */
  357. static CORE_ADDR
  358. or1k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  359. {
  360. CORE_ADDR start_pc;
  361. CORE_ADDR addr;
  362. uint32_t inst;
  363. unsigned int ra, rb, rd; /* for instruction analysis */
  364. int simm;
  365. int frame_size = 0;
  366. /* Try using SAL first if we have symbolic information available. This
  367. only works for DWARF 2, not STABS. */
  368. if (find_pc_partial_function (pc, NULL, &start_pc, NULL))
  369. {
  370. CORE_ADDR prologue_end = skip_prologue_using_sal (gdbarch, pc);
  371. if (0 != prologue_end)
  372. {
  373. struct symtab_and_line prologue_sal = find_pc_line (start_pc, 0);
  374. struct compunit_symtab *compunit
  375. = prologue_sal.symtab->compunit ();
  376. const char *debug_format = compunit->debugformat ();
  377. if ((NULL != debug_format)
  378. && (strlen ("dwarf") <= strlen (debug_format))
  379. && (0 == strncasecmp ("dwarf", debug_format, strlen ("dwarf"))))
  380. return (prologue_end > pc) ? prologue_end : pc;
  381. }
  382. }
  383. /* Look to see if we can find any of the standard prologue sequence. All
  384. quite difficult, since any or all of it may be missing. So this is
  385. just a best guess! */
  386. addr = pc; /* Where we have got to */
  387. inst = or1k_fetch_instruction (gdbarch, addr);
  388. /* Look for the new stack pointer being set up. */
  389. if (or1k_analyse_l_addi (inst, &rd, &ra, &simm)
  390. && (OR1K_SP_REGNUM == rd) && (OR1K_SP_REGNUM == ra)
  391. && (simm < 0) && (0 == (simm % 4)))
  392. {
  393. frame_size = -simm;
  394. addr += OR1K_INSTLEN;
  395. inst = or1k_fetch_instruction (gdbarch, addr);
  396. }
  397. /* Look for the frame pointer being manipulated. */
  398. if (or1k_analyse_l_sw (inst, &simm, &ra, &rb)
  399. && (OR1K_SP_REGNUM == ra) && (OR1K_FP_REGNUM == rb)
  400. && (simm >= 0) && (0 == (simm % 4)))
  401. {
  402. addr += OR1K_INSTLEN;
  403. inst = or1k_fetch_instruction (gdbarch, addr);
  404. gdb_assert (or1k_analyse_l_addi (inst, &rd, &ra, &simm)
  405. && (OR1K_FP_REGNUM == rd) && (OR1K_SP_REGNUM == ra)
  406. && (simm == frame_size));
  407. addr += OR1K_INSTLEN;
  408. inst = or1k_fetch_instruction (gdbarch, addr);
  409. }
  410. /* Look for the link register being saved. */
  411. if (or1k_analyse_l_sw (inst, &simm, &ra, &rb)
  412. && (OR1K_SP_REGNUM == ra) && (OR1K_LR_REGNUM == rb)
  413. && (simm >= 0) && (0 == (simm % 4)))
  414. {
  415. addr += OR1K_INSTLEN;
  416. inst = or1k_fetch_instruction (gdbarch, addr);
  417. }
  418. /* Look for arguments or callee-saved register being saved. The register
  419. must be one of the arguments (r3-r8) or the 10 callee saved registers
  420. (r10, r12, r14, r16, r18, r20, r22, r24, r26, r28, r30). The base
  421. register must be the FP (for the args) or the SP (for the callee_saved
  422. registers). */
  423. while (1)
  424. {
  425. if (or1k_analyse_l_sw (inst, &simm, &ra, &rb)
  426. && (((OR1K_FP_REGNUM == ra) && or1k_is_arg_reg (rb))
  427. || ((OR1K_SP_REGNUM == ra) && or1k_is_callee_saved_reg (rb)))
  428. && (0 == (simm % 4)))
  429. {
  430. addr += OR1K_INSTLEN;
  431. inst = or1k_fetch_instruction (gdbarch, addr);
  432. }
  433. else
  434. {
  435. /* Nothing else to look for. We have found the end of the
  436. prologue. */
  437. break;
  438. }
  439. }
  440. return addr;
  441. }
  442. /* Implement the frame_align gdbarch method. */
  443. static CORE_ADDR
  444. or1k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
  445. {
  446. return align_down (sp, OR1K_STACK_ALIGN);
  447. }
  448. /* Implement the unwind_pc gdbarch method. */
  449. static CORE_ADDR
  450. or1k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  451. {
  452. CORE_ADDR pc;
  453. if (or1k_debug)
  454. gdb_printf (gdb_stdlog, "or1k_unwind_pc, next_frame=%d\n",
  455. frame_relative_level (next_frame));
  456. pc = frame_unwind_register_unsigned (next_frame, OR1K_NPC_REGNUM);
  457. if (or1k_debug)
  458. gdb_printf (gdb_stdlog, "or1k_unwind_pc, pc=%s\n",
  459. paddress (gdbarch, pc));
  460. return pc;
  461. }
  462. /* Implement the unwind_sp gdbarch method. */
  463. static CORE_ADDR
  464. or1k_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
  465. {
  466. CORE_ADDR sp;
  467. if (or1k_debug)
  468. gdb_printf (gdb_stdlog, "or1k_unwind_sp, next_frame=%d\n",
  469. frame_relative_level (next_frame));
  470. sp = frame_unwind_register_unsigned (next_frame, OR1K_SP_REGNUM);
  471. if (or1k_debug)
  472. gdb_printf (gdb_stdlog, "or1k_unwind_sp, sp=%s\n",
  473. paddress (gdbarch, sp));
  474. return sp;
  475. }
  476. /* Implement the push_dummy_code gdbarch method. */
  477. static CORE_ADDR
  478. or1k_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
  479. CORE_ADDR function, struct value **args, int nargs,
  480. struct type *value_type, CORE_ADDR * real_pc,
  481. CORE_ADDR * bp_addr, struct regcache *regcache)
  482. {
  483. CORE_ADDR bp_slot;
  484. /* Reserve enough room on the stack for our breakpoint instruction. */
  485. bp_slot = sp - 4;
  486. /* Store the address of that breakpoint. */
  487. *bp_addr = bp_slot;
  488. /* keeping the stack aligned. */
  489. sp = or1k_frame_align (gdbarch, bp_slot);
  490. /* The call starts at the callee's entry point. */
  491. *real_pc = function;
  492. return sp;
  493. }
  494. /* Implement the push_dummy_call gdbarch method. */
  495. static CORE_ADDR
  496. or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  497. struct regcache *regcache, CORE_ADDR bp_addr,
  498. int nargs, struct value **args, CORE_ADDR sp,
  499. function_call_return_method return_method,
  500. CORE_ADDR struct_addr)
  501. {
  502. int argreg;
  503. int argnum;
  504. int first_stack_arg;
  505. int stack_offset = 0;
  506. int heap_offset = 0;
  507. CORE_ADDR heap_sp = sp - 128;
  508. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  509. or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  510. int bpa = tdep->bytes_per_address;
  511. int bpw = tdep->bytes_per_word;
  512. struct type *func_type = value_type (function);
  513. /* Return address */
  514. regcache_cooked_write_unsigned (regcache, OR1K_LR_REGNUM, bp_addr);
  515. /* Register for the next argument. */
  516. argreg = OR1K_FIRST_ARG_REGNUM;
  517. /* Location for a returned structure. This is passed as a silent first
  518. argument. */
  519. if (return_method == return_method_struct)
  520. {
  521. regcache_cooked_write_unsigned (regcache, OR1K_FIRST_ARG_REGNUM,
  522. struct_addr);
  523. argreg++;
  524. }
  525. /* Put as many args as possible in registers. */
  526. for (argnum = 0; argnum < nargs; argnum++)
  527. {
  528. const gdb_byte *val;
  529. gdb_byte valbuf[sizeof (ULONGEST)];
  530. struct value *arg = args[argnum];
  531. struct type *arg_type = check_typedef (value_type (arg));
  532. int len = TYPE_LENGTH (arg_type);
  533. enum type_code typecode = arg_type->code ();
  534. if (func_type->has_varargs () && argnum >= func_type->num_fields ())
  535. break; /* end or regular args, varargs go to stack. */
  536. /* Extract the value, either a reference or the data. */
  537. if ((TYPE_CODE_STRUCT == typecode) || (TYPE_CODE_UNION == typecode)
  538. || (len > bpw * 2))
  539. {
  540. CORE_ADDR valaddr = value_address (arg);
  541. /* If the arg is fabricated (i.e. 3*i, instead of i) valaddr is
  542. undefined. */
  543. if (valaddr == 0)
  544. {
  545. /* The argument needs to be copied into the target space.
  546. Since the bottom of the stack is reserved for function
  547. arguments we store this at the these at the top growing
  548. down. */
  549. heap_offset += align_up (len, bpw);
  550. valaddr = heap_sp + heap_offset;
  551. write_memory (valaddr, value_contents (arg).data (), len);
  552. }
  553. /* The ABI passes all structures by reference, so get its
  554. address. */
  555. store_unsigned_integer (valbuf, bpa, byte_order, valaddr);
  556. len = bpa;
  557. val = valbuf;
  558. }
  559. else
  560. {
  561. /* Everything else, we just get the value. */
  562. val = value_contents (arg).data ();
  563. }
  564. /* Stick the value in a register. */
  565. if (len > bpw)
  566. {
  567. /* Big scalars use two registers, but need NOT be pair aligned. */
  568. if (argreg <= (OR1K_LAST_ARG_REGNUM - 1))
  569. {
  570. ULONGEST regval = extract_unsigned_integer (val, len,
  571. byte_order);
  572. unsigned int bits_per_word = bpw * 8;
  573. ULONGEST mask = (((ULONGEST) 1) << bits_per_word) - 1;
  574. ULONGEST lo = regval & mask;
  575. ULONGEST hi = regval >> bits_per_word;
  576. regcache_cooked_write_unsigned (regcache, argreg, hi);
  577. regcache_cooked_write_unsigned (regcache, argreg + 1, lo);
  578. argreg += 2;
  579. }
  580. else
  581. {
  582. /* Run out of regs */
  583. break;
  584. }
  585. }
  586. else if (argreg <= OR1K_LAST_ARG_REGNUM)
  587. {
  588. /* Smaller scalars fit in a single register. */
  589. regcache_cooked_write_unsigned
  590. (regcache, argreg, extract_unsigned_integer (val, len,
  591. byte_order));
  592. argreg++;
  593. }
  594. else
  595. {
  596. /* Ran out of regs. */
  597. break;
  598. }
  599. }
  600. first_stack_arg = argnum;
  601. /* If we get here with argnum < nargs, then arguments remain to be
  602. placed on the stack. This is tricky, since they must be pushed in
  603. reverse order and the stack in the end must be aligned. The only
  604. solution is to do it in two stages, the first to compute the stack
  605. size, the second to save the args. */
  606. for (argnum = first_stack_arg; argnum < nargs; argnum++)
  607. {
  608. struct value *arg = args[argnum];
  609. struct type *arg_type = check_typedef (value_type (arg));
  610. int len = TYPE_LENGTH (arg_type);
  611. enum type_code typecode = arg_type->code ();
  612. if ((TYPE_CODE_STRUCT == typecode) || (TYPE_CODE_UNION == typecode)
  613. || (len > bpw * 2))
  614. {
  615. /* Structures are passed as addresses. */
  616. sp -= bpa;
  617. }
  618. else
  619. {
  620. /* Big scalars use more than one word. Code here allows for
  621. future quad-word entities (e.g. long double.) */
  622. sp -= align_up (len, bpw);
  623. }
  624. /* Ensure our dummy heap doesn't touch the stack, this could only
  625. happen if we have many arguments including fabricated arguments. */
  626. gdb_assert (heap_offset == 0 || ((heap_sp + heap_offset) < sp));
  627. }
  628. sp = gdbarch_frame_align (gdbarch, sp);
  629. stack_offset = 0;
  630. /* Push the remaining args on the stack. */
  631. for (argnum = first_stack_arg; argnum < nargs; argnum++)
  632. {
  633. const gdb_byte *val;
  634. gdb_byte valbuf[sizeof (ULONGEST)];
  635. struct value *arg = args[argnum];
  636. struct type *arg_type = check_typedef (value_type (arg));
  637. int len = TYPE_LENGTH (arg_type);
  638. enum type_code typecode = arg_type->code ();
  639. /* The EABI passes structures that do not fit in a register by
  640. reference. In all other cases, pass the structure by value. */
  641. if ((TYPE_CODE_STRUCT == typecode) || (TYPE_CODE_UNION == typecode)
  642. || (len > bpw * 2))
  643. {
  644. store_unsigned_integer (valbuf, bpa, byte_order,
  645. value_address (arg));
  646. len = bpa;
  647. val = valbuf;
  648. }
  649. else
  650. val = value_contents (arg).data ();
  651. while (len > 0)
  652. {
  653. int partial_len = (len < bpw ? len : bpw);
  654. write_memory (sp + stack_offset, val, partial_len);
  655. stack_offset += align_up (partial_len, bpw);
  656. len -= partial_len;
  657. val += partial_len;
  658. }
  659. }
  660. /* Save the updated stack pointer. */
  661. regcache_cooked_write_unsigned (regcache, OR1K_SP_REGNUM, sp);
  662. if (heap_offset > 0)
  663. sp = heap_sp;
  664. return sp;
  665. }
  666. /* Support functions for frame handling. */
  667. /* Initialize a prologue cache
  668. We build a cache, saying where registers of the prev frame can be found
  669. from the data so far set up in this this.
  670. We also compute a unique ID for this frame, based on the function start
  671. address and the stack pointer (as it will be, even if it has yet to be
  672. computed.
  673. STACK FORMAT
  674. ============
  675. The OR1K has a falling stack frame and a simple prolog. The Stack
  676. pointer is R1 and the frame pointer R2. The frame base is therefore the
  677. address held in R2 and the stack pointer (R1) is the frame base of the
  678. next frame.
  679. l.addi r1,r1,-frame_size # SP now points to end of new stack frame
  680. The stack pointer may not be set up in a frameless function (e.g. a
  681. simple leaf function).
  682. l.sw fp_loc(r1),r2 # old FP saved in new stack frame
  683. l.addi r2,r1,frame_size # FP now points to base of new stack frame
  684. The frame pointer is not necessarily saved right at the end of the stack
  685. frame - OR1K saves enough space for any args to called functions right
  686. at the end (this is a difference from the Architecture Manual).
  687. l.sw lr_loc(r1),r9 # Link (return) address
  688. The link register is usually saved at fp_loc - 4. It may not be saved at
  689. all in a leaf function.
  690. l.sw reg_loc(r1),ry # Save any callee saved regs
  691. The offsets x for the callee saved registers generally (always?) rise in
  692. increments of 4, starting at fp_loc + 4. If the frame pointer is
  693. omitted (an option to GCC), then it may not be saved at all. There may
  694. be no callee saved registers.
  695. So in summary none of this may be present. However what is present
  696. seems always to follow this fixed order, and occur before any
  697. substantive code (it is possible for GCC to have more flexible
  698. scheduling of the prologue, but this does not seem to occur for OR1K).
  699. ANALYSIS
  700. ========
  701. This prolog is used, even for -O3 with GCC.
  702. All this analysis must allow for the possibility that the PC is in the
  703. middle of the prologue. Data in the cache should only be set up insofar
  704. as it has been computed.
  705. HOWEVER. The frame_id must be created with the SP *as it will be* at
  706. the end of the Prologue. Otherwise a recursive call, checking the frame
  707. with the PC at the start address will end up with the same frame_id as
  708. the caller.
  709. A suite of "helper" routines are used, allowing reuse for
  710. or1k_skip_prologue().
  711. Reportedly, this is only valid for frames less than 0x7fff in size. */
  712. static struct trad_frame_cache *
  713. or1k_frame_cache (struct frame_info *this_frame, void **prologue_cache)
  714. {
  715. struct gdbarch *gdbarch;
  716. struct trad_frame_cache *info;
  717. CORE_ADDR this_pc;
  718. CORE_ADDR this_sp;
  719. CORE_ADDR this_sp_for_id;
  720. int frame_size = 0;
  721. CORE_ADDR start_addr;
  722. CORE_ADDR end_addr;
  723. if (or1k_debug)
  724. gdb_printf (gdb_stdlog,
  725. "or1k_frame_cache, prologue_cache = %s\n",
  726. host_address_to_string (*prologue_cache));
  727. /* Nothing to do if we already have this info. */
  728. if (NULL != *prologue_cache)
  729. return (struct trad_frame_cache *) *prologue_cache;
  730. /* Get a new prologue cache and populate it with default values. */
  731. info = trad_frame_cache_zalloc (this_frame);
  732. *prologue_cache = info;
  733. /* Find the start address of this function (which is a normal frame, even
  734. if the next frame is the sentinel frame) and the end of its prologue. */
  735. this_pc = get_frame_pc (this_frame);
  736. find_pc_partial_function (this_pc, NULL, &start_addr, NULL);
  737. /* Get the stack pointer if we have one (if there's no process executing
  738. yet we won't have a frame. */
  739. this_sp = (NULL == this_frame) ? 0 :
  740. get_frame_register_unsigned (this_frame, OR1K_SP_REGNUM);
  741. /* Return early if GDB couldn't find the function. */
  742. if (start_addr == 0)
  743. {
  744. if (or1k_debug)
  745. gdb_printf (gdb_stdlog, " couldn't find function\n");
  746. /* JPB: 28-Apr-11. This is a temporary patch, to get round GDB
  747. crashing right at the beginning. Build the frame ID as best we
  748. can. */
  749. trad_frame_set_id (info, frame_id_build (this_sp, this_pc));
  750. return info;
  751. }
  752. /* The default frame base of this frame (for ID purposes only - frame
  753. base is an overloaded term) is its stack pointer. For now we use the
  754. value of the SP register in this frame. However if the PC is in the
  755. prologue of this frame, before the SP has been set up, then the value
  756. will actually be that of the prev frame, and we'll need to adjust it
  757. later. */
  758. trad_frame_set_this_base (info, this_sp);
  759. this_sp_for_id = this_sp;
  760. /* The default is to find the PC of the previous frame in the link
  761. register of this frame. This may be changed if we find the link
  762. register was saved on the stack. */
  763. trad_frame_set_reg_realreg (info, OR1K_NPC_REGNUM, OR1K_LR_REGNUM);
  764. /* We should only examine code that is in the prologue. This is all code
  765. up to (but not including) end_addr. We should only populate the cache
  766. while the address is up to (but not including) the PC or end_addr,
  767. whichever is first. */
  768. gdbarch = get_frame_arch (this_frame);
  769. end_addr = or1k_skip_prologue (gdbarch, start_addr);
  770. /* All the following analysis only occurs if we are in the prologue and
  771. have executed the code. Check we have a sane prologue size, and if
  772. zero we are frameless and can give up here. */
  773. if (end_addr < start_addr)
  774. error (_("end addr %s is less than start addr %s"),
  775. paddress (gdbarch, end_addr), paddress (gdbarch, start_addr));
  776. if (end_addr == start_addr)
  777. frame_size = 0;
  778. else
  779. {
  780. /* We have a frame. Look for the various components. */
  781. CORE_ADDR addr = start_addr; /* Where we have got to */
  782. uint32_t inst = or1k_fetch_instruction (gdbarch, addr);
  783. unsigned int ra, rb, rd; /* for instruction analysis */
  784. int simm;
  785. /* Look for the new stack pointer being set up. */
  786. if (or1k_analyse_l_addi (inst, &rd, &ra, &simm)
  787. && (OR1K_SP_REGNUM == rd) && (OR1K_SP_REGNUM == ra)
  788. && (simm < 0) && (0 == (simm % 4)))
  789. {
  790. frame_size = -simm;
  791. addr += OR1K_INSTLEN;
  792. inst = or1k_fetch_instruction (gdbarch, addr);
  793. /* If the PC has not actually got to this point, then the frame
  794. base will be wrong, and we adjust it.
  795. If we are past this point, then we need to populate the stack
  796. accordingly. */
  797. if (this_pc <= addr)
  798. {
  799. /* Only do if executing. */
  800. if (0 != this_sp)
  801. {
  802. this_sp_for_id = this_sp + frame_size;
  803. trad_frame_set_this_base (info, this_sp_for_id);
  804. }
  805. }
  806. else
  807. {
  808. /* We are past this point, so the stack pointer of the prev
  809. frame is frame_size greater than the stack pointer of this
  810. frame. */
  811. trad_frame_set_reg_value (info, OR1K_SP_REGNUM,
  812. this_sp + frame_size);
  813. }
  814. }
  815. /* From now on we are only populating the cache, so we stop once we
  816. get to either the end OR the current PC. */
  817. end_addr = (this_pc < end_addr) ? this_pc : end_addr;
  818. /* Look for the frame pointer being manipulated. */
  819. if ((addr < end_addr)
  820. && or1k_analyse_l_sw (inst, &simm, &ra, &rb)
  821. && (OR1K_SP_REGNUM == ra) && (OR1K_FP_REGNUM == rb)
  822. && (simm >= 0) && (0 == (simm % 4)))
  823. {
  824. addr += OR1K_INSTLEN;
  825. inst = or1k_fetch_instruction (gdbarch, addr);
  826. /* At this stage, we can find the frame pointer of the previous
  827. frame on the stack of the current frame. */
  828. trad_frame_set_reg_addr (info, OR1K_FP_REGNUM, this_sp + simm);
  829. /* Look for the new frame pointer being set up. */
  830. if ((addr < end_addr)
  831. && or1k_analyse_l_addi (inst, &rd, &ra, &simm)
  832. && (OR1K_FP_REGNUM == rd) && (OR1K_SP_REGNUM == ra)
  833. && (simm == frame_size))
  834. {
  835. addr += OR1K_INSTLEN;
  836. inst = or1k_fetch_instruction (gdbarch, addr);
  837. /* If we have got this far, the stack pointer of the previous
  838. frame is the frame pointer of this frame. */
  839. trad_frame_set_reg_realreg (info, OR1K_SP_REGNUM,
  840. OR1K_FP_REGNUM);
  841. }
  842. }
  843. /* Look for the link register being saved. */
  844. if ((addr < end_addr)
  845. && or1k_analyse_l_sw (inst, &simm, &ra, &rb)
  846. && (OR1K_SP_REGNUM == ra) && (OR1K_LR_REGNUM == rb)
  847. && (simm >= 0) && (0 == (simm % 4)))
  848. {
  849. addr += OR1K_INSTLEN;
  850. inst = or1k_fetch_instruction (gdbarch, addr);
  851. /* If the link register is saved in the this frame, it holds the
  852. value of the PC in the previous frame. This overwrites the
  853. previous information about finding the PC in the link
  854. register. */
  855. trad_frame_set_reg_addr (info, OR1K_NPC_REGNUM, this_sp + simm);
  856. }
  857. /* Look for arguments or callee-saved register being saved. The
  858. register must be one of the arguments (r3-r8) or the 10 callee
  859. saved registers (r10, r12, r14, r16, r18, r20, r22, r24, r26, r28,
  860. r30). The base register must be the FP (for the args) or the SP
  861. (for the callee_saved registers). */
  862. while (addr < end_addr)
  863. {
  864. if (or1k_analyse_l_sw (inst, &simm, &ra, &rb)
  865. && (((OR1K_FP_REGNUM == ra) && or1k_is_arg_reg (rb))
  866. || ((OR1K_SP_REGNUM == ra)
  867. && or1k_is_callee_saved_reg (rb)))
  868. && (0 == (simm % 4)))
  869. {
  870. addr += OR1K_INSTLEN;
  871. inst = or1k_fetch_instruction (gdbarch, addr);
  872. /* The register in the previous frame can be found at this
  873. location in this frame. */
  874. trad_frame_set_reg_addr (info, rb, this_sp + simm);
  875. }
  876. else
  877. break; /* Not a register save instruction. */
  878. }
  879. }
  880. /* Build the frame ID */
  881. trad_frame_set_id (info, frame_id_build (this_sp_for_id, start_addr));
  882. if (or1k_debug)
  883. {
  884. gdb_printf (gdb_stdlog, " this_sp_for_id = %s\n",
  885. paddress (gdbarch, this_sp_for_id));
  886. gdb_printf (gdb_stdlog, " start_addr = %s\n",
  887. paddress (gdbarch, start_addr));
  888. }
  889. return info;
  890. }
  891. /* Implement the this_id function for the stub unwinder. */
  892. static void
  893. or1k_frame_this_id (struct frame_info *this_frame,
  894. void **prologue_cache, struct frame_id *this_id)
  895. {
  896. struct trad_frame_cache *info = or1k_frame_cache (this_frame,
  897. prologue_cache);
  898. trad_frame_get_id (info, this_id);
  899. }
  900. /* Implement the prev_register function for the stub unwinder. */
  901. static struct value *
  902. or1k_frame_prev_register (struct frame_info *this_frame,
  903. void **prologue_cache, int regnum)
  904. {
  905. struct trad_frame_cache *info = or1k_frame_cache (this_frame,
  906. prologue_cache);
  907. return trad_frame_get_register (info, this_frame, regnum);
  908. }
  909. /* Data structures for the normal prologue-analysis-based unwinder. */
  910. static const struct frame_unwind or1k_frame_unwind = {
  911. "or1k prologue",
  912. NORMAL_FRAME,
  913. default_frame_unwind_stop_reason,
  914. or1k_frame_this_id,
  915. or1k_frame_prev_register,
  916. NULL,
  917. default_frame_sniffer,
  918. NULL,
  919. };
  920. /* Architecture initialization for OpenRISC 1000. */
  921. static struct gdbarch *
  922. or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  923. {
  924. struct gdbarch *gdbarch;
  925. const struct bfd_arch_info *binfo;
  926. tdesc_arch_data_up tdesc_data;
  927. const struct target_desc *tdesc = info.target_desc;
  928. /* Find a candidate among the list of pre-declared architectures. */
  929. arches = gdbarch_list_lookup_by_info (arches, &info);
  930. if (NULL != arches)
  931. return arches->gdbarch;
  932. /* None found, create a new architecture from the information
  933. provided. Can't initialize all the target dependencies until we
  934. actually know which target we are talking to, but put in some defaults
  935. for now. */
  936. binfo = info.bfd_arch_info;
  937. or1k_gdbarch_tdep *tdep = new or1k_gdbarch_tdep;
  938. tdep->bytes_per_word = binfo->bits_per_word / binfo->bits_per_byte;
  939. tdep->bytes_per_address = binfo->bits_per_address / binfo->bits_per_byte;
  940. gdbarch = gdbarch_alloc (&info, tdep);
  941. /* Target data types */
  942. set_gdbarch_short_bit (gdbarch, 16);
  943. set_gdbarch_int_bit (gdbarch, 32);
  944. set_gdbarch_long_bit (gdbarch, 32);
  945. set_gdbarch_long_long_bit (gdbarch, 64);
  946. set_gdbarch_float_bit (gdbarch, 32);
  947. set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
  948. set_gdbarch_double_bit (gdbarch, 64);
  949. set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
  950. set_gdbarch_long_double_bit (gdbarch, 64);
  951. set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
  952. set_gdbarch_ptr_bit (gdbarch, binfo->bits_per_address);
  953. set_gdbarch_addr_bit (gdbarch, binfo->bits_per_address);
  954. set_gdbarch_char_signed (gdbarch, 1);
  955. /* Information about the target architecture */
  956. set_gdbarch_return_value (gdbarch, or1k_return_value);
  957. set_gdbarch_breakpoint_kind_from_pc (gdbarch,
  958. or1k_breakpoint::kind_from_pc);
  959. set_gdbarch_sw_breakpoint_from_kind (gdbarch,
  960. or1k_breakpoint::bp_from_kind);
  961. set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
  962. /* Register architecture */
  963. set_gdbarch_num_regs (gdbarch, OR1K_NUM_REGS);
  964. set_gdbarch_num_pseudo_regs (gdbarch, OR1K_NUM_PSEUDO_REGS);
  965. set_gdbarch_sp_regnum (gdbarch, OR1K_SP_REGNUM);
  966. set_gdbarch_pc_regnum (gdbarch, OR1K_NPC_REGNUM);
  967. set_gdbarch_ps_regnum (gdbarch, OR1K_SR_REGNUM);
  968. set_gdbarch_deprecated_fp_regnum (gdbarch, OR1K_FP_REGNUM);
  969. /* Functions to analyse frames */
  970. set_gdbarch_skip_prologue (gdbarch, or1k_skip_prologue);
  971. set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  972. set_gdbarch_frame_align (gdbarch, or1k_frame_align);
  973. set_gdbarch_frame_red_zone_size (gdbarch, OR1K_FRAME_RED_ZONE_SIZE);
  974. /* Functions to access frame data */
  975. set_gdbarch_unwind_pc (gdbarch, or1k_unwind_pc);
  976. set_gdbarch_unwind_sp (gdbarch, or1k_unwind_sp);
  977. /* Functions handling dummy frames */
  978. set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
  979. set_gdbarch_push_dummy_code (gdbarch, or1k_push_dummy_code);
  980. set_gdbarch_push_dummy_call (gdbarch, or1k_push_dummy_call);
  981. /* Frame unwinders. Use DWARF debug info if available, otherwise use our
  982. own unwinder. */
  983. dwarf2_append_unwinders (gdbarch);
  984. frame_unwind_append_unwinder (gdbarch, &or1k_frame_unwind);
  985. /* Get a CGEN CPU descriptor for this architecture. */
  986. {
  987. const char *mach_name = binfo->printable_name;
  988. enum cgen_endian endian = (info.byte_order == BFD_ENDIAN_BIG
  989. ? CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE);
  990. tdep->gdb_cgen_cpu_desc =
  991. or1k_cgen_cpu_open (CGEN_CPU_OPEN_BFDMACH, mach_name,
  992. CGEN_CPU_OPEN_ENDIAN, endian, CGEN_CPU_OPEN_END);
  993. or1k_cgen_init_asm (tdep->gdb_cgen_cpu_desc);
  994. }
  995. /* If this mach has a delay slot. */
  996. if (binfo->mach == bfd_mach_or1k)
  997. set_gdbarch_single_step_through_delay (gdbarch,
  998. or1k_single_step_through_delay);
  999. if (!tdesc_has_registers (info.target_desc))
  1000. /* Pick a default target description. */
  1001. tdesc = tdesc_or1k;
  1002. /* Check any target description for validity. */
  1003. if (tdesc_has_registers (tdesc))
  1004. {
  1005. const struct tdesc_feature *feature;
  1006. int valid_p;
  1007. int i;
  1008. feature = tdesc_find_feature (tdesc, "org.gnu.gdb.or1k.group0");
  1009. if (feature == NULL)
  1010. return NULL;
  1011. tdesc_data = tdesc_data_alloc ();
  1012. valid_p = 1;
  1013. for (i = 0; i < OR1K_NUM_REGS; i++)
  1014. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
  1015. or1k_reg_names[i]);
  1016. if (!valid_p)
  1017. return NULL;
  1018. }
  1019. if (tdesc_data != NULL)
  1020. tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
  1021. /* Hook in ABI-specific overrides, if they have been registered. */
  1022. gdbarch_init_osabi (info, gdbarch);
  1023. return gdbarch;
  1024. }
  1025. /* Dump the target specific data for this architecture. */
  1026. static void
  1027. or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
  1028. {
  1029. or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1030. if (NULL == tdep)
  1031. return; /* Nothing to report */
  1032. gdb_printf (file, "or1k_dump_tdep: %d bytes per word\n",
  1033. tdep->bytes_per_word);
  1034. gdb_printf (file, "or1k_dump_tdep: %d bytes per address\n",
  1035. tdep->bytes_per_address);
  1036. }
  1037. void _initialize_or1k_tdep ();
  1038. void
  1039. _initialize_or1k_tdep ()
  1040. {
  1041. /* Register this architecture. */
  1042. gdbarch_register (bfd_arch_or1k, or1k_gdbarch_init, or1k_dump_tdep);
  1043. initialize_tdesc_or1k ();
  1044. /* Debugging flag. */
  1045. add_setshow_boolean_cmd ("or1k", class_maintenance, &or1k_debug,
  1046. _("Set OpenRISC debugging."),
  1047. _("Show OpenRISC debugging."),
  1048. _("When on, OpenRISC specific debugging is enabled."),
  1049. NULL,
  1050. show_or1k_debug,
  1051. &setdebuglist, &showdebuglist);
  1052. }