Commit | Line | Data |
---|---|---|
baa835b4 KB |
1 | /* Target-dependent code for the Renesas RX for GDB, the GNU debugger. |
2 | ||
618f726f | 3 | Copyright (C) 2008-2016 Free Software Foundation, Inc. |
baa835b4 KB |
4 | |
5 | Contributed by Red Hat, Inc. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 3 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "arch-utils.h" | |
24 | #include "prologue-value.h" | |
25 | #include "target.h" | |
26 | #include "regcache.h" | |
27 | #include "opcode/rx.h" | |
28 | #include "dis-asm.h" | |
29 | #include "gdbtypes.h" | |
30 | #include "frame.h" | |
31 | #include "frame-unwind.h" | |
32 | #include "frame-base.h" | |
33 | #include "value.h" | |
34 | #include "gdbcore.h" | |
35 | #include "dwarf2-frame.h" | |
36 | ||
37 | #include "elf/rx.h" | |
38 | #include "elf-bfd.h" | |
325fac50 | 39 | #include <algorithm> |
baa835b4 KB |
40 | |
41 | /* Certain important register numbers. */ | |
42 | enum | |
43 | { | |
44 | RX_SP_REGNUM = 0, | |
45 | RX_R1_REGNUM = 1, | |
46 | RX_R4_REGNUM = 4, | |
47 | RX_FP_REGNUM = 6, | |
48 | RX_R15_REGNUM = 15, | |
1b485e67 | 49 | RX_USP_REGNUM = 16, |
fd6e021d | 50 | RX_PSW_REGNUM = 18, |
baa835b4 | 51 | RX_PC_REGNUM = 19, |
0561fea4 | 52 | RX_BPSW_REGNUM = 21, |
1b485e67 | 53 | RX_BPC_REGNUM = 22, |
0561fea4 | 54 | RX_FPSW_REGNUM = 24, |
fd60dc69 KB |
55 | RX_ACC_REGNUM = 25, |
56 | RX_NUM_REGS = 26 | |
baa835b4 KB |
57 | }; |
58 | ||
1b485e67 KB |
59 | /* RX frame types. */ |
60 | enum rx_frame_type { | |
61 | RX_FRAME_TYPE_NORMAL, | |
62 | RX_FRAME_TYPE_EXCEPTION, | |
63 | RX_FRAME_TYPE_FAST_INTERRUPT | |
64 | }; | |
65 | ||
baa835b4 KB |
66 | /* Architecture specific data. */ |
67 | struct gdbarch_tdep | |
68 | { | |
69 | /* The ELF header flags specify the multilib used. */ | |
70 | int elf_flags; | |
0561fea4 KB |
71 | |
72 | /* Type of PSW and BPSW. */ | |
73 | struct type *rx_psw_type; | |
74 | ||
75 | /* Type of FPSW. */ | |
76 | struct type *rx_fpsw_type; | |
baa835b4 KB |
77 | }; |
78 | ||
79 | /* This structure holds the results of a prologue analysis. */ | |
80 | struct rx_prologue | |
81 | { | |
1b485e67 KB |
82 | /* Frame type, either a normal frame or one of two types of exception |
83 | frames. */ | |
84 | enum rx_frame_type frame_type; | |
85 | ||
baa835b4 KB |
86 | /* The offset from the frame base to the stack pointer --- always |
87 | zero or negative. | |
88 | ||
89 | Calling this a "size" is a bit misleading, but given that the | |
90 | stack grows downwards, using offsets for everything keeps one | |
91 | from going completely sign-crazy: you never change anything's | |
92 | sign for an ADD instruction; always change the second operand's | |
93 | sign for a SUB instruction; and everything takes care of | |
94 | itself. */ | |
95 | int frame_size; | |
96 | ||
97 | /* Non-zero if this function has initialized the frame pointer from | |
98 | the stack pointer, zero otherwise. */ | |
99 | int has_frame_ptr; | |
100 | ||
101 | /* If has_frame_ptr is non-zero, this is the offset from the frame | |
102 | base to where the frame pointer points. This is always zero or | |
103 | negative. */ | |
104 | int frame_ptr_offset; | |
105 | ||
106 | /* The address of the first instruction at which the frame has been | |
107 | set up and the arguments are where the debug info says they are | |
108 | --- as best as we can tell. */ | |
109 | CORE_ADDR prologue_end; | |
110 | ||
111 | /* reg_offset[R] is the offset from the CFA at which register R is | |
112 | saved, or 1 if register R has not been saved. (Real values are | |
113 | always zero or negative.) */ | |
114 | int reg_offset[RX_NUM_REGS]; | |
115 | }; | |
116 | ||
117 | /* Implement the "register_name" gdbarch method. */ | |
118 | static const char * | |
119 | rx_register_name (struct gdbarch *gdbarch, int regnr) | |
120 | { | |
121 | static const char *const reg_names[] = { | |
122 | "r0", | |
123 | "r1", | |
124 | "r2", | |
125 | "r3", | |
126 | "r4", | |
127 | "r5", | |
128 | "r6", | |
129 | "r7", | |
130 | "r8", | |
131 | "r9", | |
132 | "r10", | |
133 | "r11", | |
134 | "r12", | |
135 | "r13", | |
136 | "r14", | |
137 | "r15", | |
baa835b4 | 138 | "usp", |
fd60dc69 | 139 | "isp", |
baa835b4 | 140 | "psw", |
fd60dc69 KB |
141 | "pc", |
142 | "intb", | |
baa835b4 | 143 | "bpsw", |
fd60dc69 KB |
144 | "bpc", |
145 | "fintv", | |
146 | "fpsw", | |
147 | "acc" | |
baa835b4 KB |
148 | }; |
149 | ||
150 | return reg_names[regnr]; | |
151 | } | |
152 | ||
153 | /* Implement the "register_type" gdbarch method. */ | |
154 | static struct type * | |
155 | rx_register_type (struct gdbarch *gdbarch, int reg_nr) | |
156 | { | |
0561fea4 KB |
157 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
158 | ||
baa835b4 KB |
159 | if (reg_nr == RX_PC_REGNUM) |
160 | return builtin_type (gdbarch)->builtin_func_ptr; | |
0561fea4 KB |
161 | else if (reg_nr == RX_PSW_REGNUM || reg_nr == RX_BPSW_REGNUM) |
162 | return tdep->rx_psw_type; | |
163 | else if (reg_nr == RX_FPSW_REGNUM) | |
164 | return tdep->rx_fpsw_type; | |
fd60dc69 KB |
165 | else if (reg_nr == RX_ACC_REGNUM) |
166 | return builtin_type (gdbarch)->builtin_unsigned_long_long; | |
baa835b4 KB |
167 | else |
168 | return builtin_type (gdbarch)->builtin_unsigned_long; | |
169 | } | |
170 | ||
171 | ||
172 | /* Function for finding saved registers in a 'struct pv_area'; this | |
173 | function is passed to pv_area_scan. | |
174 | ||
175 | If VALUE is a saved register, ADDR says it was saved at a constant | |
176 | offset from the frame base, and SIZE indicates that the whole | |
177 | register was saved, record its offset. */ | |
178 | static void | |
179 | check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value) | |
180 | { | |
181 | struct rx_prologue *result = (struct rx_prologue *) result_untyped; | |
182 | ||
183 | if (value.kind == pvk_register | |
184 | && value.k == 0 | |
185 | && pv_is_register (addr, RX_SP_REGNUM) | |
f5656ead | 186 | && size == register_size (target_gdbarch (), value.reg)) |
baa835b4 KB |
187 | result->reg_offset[value.reg] = addr.k; |
188 | } | |
189 | ||
190 | /* Define a "handle" struct for fetching the next opcode. */ | |
191 | struct rx_get_opcode_byte_handle | |
192 | { | |
193 | CORE_ADDR pc; | |
194 | }; | |
195 | ||
196 | /* Fetch a byte on behalf of the opcode decoder. HANDLE contains | |
197 | the memory address of the next byte to fetch. If successful, | |
198 | the address in the handle is updated and the byte fetched is | |
199 | returned as the value of the function. If not successful, -1 | |
200 | is returned. */ | |
201 | static int | |
202 | rx_get_opcode_byte (void *handle) | |
203 | { | |
19ba03f4 SM |
204 | struct rx_get_opcode_byte_handle *opcdata |
205 | = (struct rx_get_opcode_byte_handle *) handle; | |
baa835b4 KB |
206 | int status; |
207 | gdb_byte byte; | |
208 | ||
a0e28e54 | 209 | status = target_read_code (opcdata->pc, &byte, 1); |
baa835b4 KB |
210 | if (status == 0) |
211 | { | |
212 | opcdata->pc += 1; | |
213 | return byte; | |
214 | } | |
215 | else | |
216 | return -1; | |
217 | } | |
218 | ||
219 | /* Analyze a prologue starting at START_PC, going no further than | |
220 | LIMIT_PC. Fill in RESULT as appropriate. */ | |
1b485e67 | 221 | |
baa835b4 | 222 | static void |
1b485e67 KB |
223 | rx_analyze_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
224 | enum rx_frame_type frame_type, | |
225 | struct rx_prologue *result) | |
baa835b4 KB |
226 | { |
227 | CORE_ADDR pc, next_pc; | |
228 | int rn; | |
229 | pv_t reg[RX_NUM_REGS]; | |
230 | struct pv_area *stack; | |
231 | struct cleanup *back_to; | |
232 | CORE_ADDR after_last_frame_setup_insn = start_pc; | |
233 | ||
234 | memset (result, 0, sizeof (*result)); | |
235 | ||
1b485e67 KB |
236 | result->frame_type = frame_type; |
237 | ||
baa835b4 KB |
238 | for (rn = 0; rn < RX_NUM_REGS; rn++) |
239 | { | |
240 | reg[rn] = pv_register (rn, 0); | |
241 | result->reg_offset[rn] = 1; | |
242 | } | |
243 | ||
f5656ead | 244 | stack = make_pv_area (RX_SP_REGNUM, gdbarch_addr_bit (target_gdbarch ())); |
baa835b4 KB |
245 | back_to = make_cleanup_free_pv_area (stack); |
246 | ||
1b485e67 KB |
247 | if (frame_type == RX_FRAME_TYPE_FAST_INTERRUPT) |
248 | { | |
249 | /* This code won't do anything useful at present, but this is | |
250 | what happens for fast interrupts. */ | |
251 | reg[RX_BPSW_REGNUM] = reg[RX_PSW_REGNUM]; | |
252 | reg[RX_BPC_REGNUM] = reg[RX_PC_REGNUM]; | |
253 | } | |
254 | else | |
255 | { | |
256 | /* When an exception occurs, the PSW is saved to the interrupt stack | |
257 | first. */ | |
258 | if (frame_type == RX_FRAME_TYPE_EXCEPTION) | |
259 | { | |
260 | reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4); | |
261 | pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[RX_PSW_REGNUM]); | |
262 | } | |
263 | ||
264 | /* The call instruction (or an exception/interrupt) has saved the return | |
265 | address on the stack. */ | |
266 | reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4); | |
267 | pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[RX_PC_REGNUM]); | |
268 | ||
269 | } | |
270 | ||
baa835b4 KB |
271 | |
272 | pc = start_pc; | |
273 | while (pc < limit_pc) | |
274 | { | |
275 | int bytes_read; | |
276 | struct rx_get_opcode_byte_handle opcode_handle; | |
277 | RX_Opcode_Decoded opc; | |
278 | ||
279 | opcode_handle.pc = pc; | |
280 | bytes_read = rx_decode_opcode (pc, &opc, rx_get_opcode_byte, | |
281 | &opcode_handle); | |
282 | next_pc = pc + bytes_read; | |
283 | ||
284 | if (opc.id == RXO_pushm /* pushm r1, r2 */ | |
285 | && opc.op[1].type == RX_Operand_Register | |
286 | && opc.op[2].type == RX_Operand_Register) | |
287 | { | |
288 | int r1, r2; | |
289 | int r; | |
290 | ||
291 | r1 = opc.op[1].reg; | |
292 | r2 = opc.op[2].reg; | |
293 | for (r = r2; r >= r1; r--) | |
294 | { | |
295 | reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4); | |
296 | pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[r]); | |
297 | } | |
298 | after_last_frame_setup_insn = next_pc; | |
299 | } | |
300 | else if (opc.id == RXO_mov /* mov.l rdst, rsrc */ | |
301 | && opc.op[0].type == RX_Operand_Register | |
302 | && opc.op[1].type == RX_Operand_Register | |
303 | && opc.size == RX_Long) | |
304 | { | |
305 | int rdst, rsrc; | |
306 | ||
307 | rdst = opc.op[0].reg; | |
308 | rsrc = opc.op[1].reg; | |
309 | reg[rdst] = reg[rsrc]; | |
310 | if (rdst == RX_FP_REGNUM && rsrc == RX_SP_REGNUM) | |
311 | after_last_frame_setup_insn = next_pc; | |
312 | } | |
313 | else if (opc.id == RXO_mov /* mov.l rsrc, [-SP] */ | |
314 | && opc.op[0].type == RX_Operand_Predec | |
315 | && opc.op[0].reg == RX_SP_REGNUM | |
316 | && opc.op[1].type == RX_Operand_Register | |
317 | && opc.size == RX_Long) | |
318 | { | |
319 | int rsrc; | |
320 | ||
321 | rsrc = opc.op[1].reg; | |
322 | reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4); | |
323 | pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[rsrc]); | |
324 | after_last_frame_setup_insn = next_pc; | |
325 | } | |
326 | else if (opc.id == RXO_add /* add #const, rsrc, rdst */ | |
327 | && opc.op[0].type == RX_Operand_Register | |
328 | && opc.op[1].type == RX_Operand_Immediate | |
329 | && opc.op[2].type == RX_Operand_Register) | |
330 | { | |
331 | int rdst = opc.op[0].reg; | |
332 | int addend = opc.op[1].addend; | |
333 | int rsrc = opc.op[2].reg; | |
334 | reg[rdst] = pv_add_constant (reg[rsrc], addend); | |
335 | /* Negative adjustments to the stack pointer or frame pointer | |
336 | are (most likely) part of the prologue. */ | |
337 | if ((rdst == RX_SP_REGNUM || rdst == RX_FP_REGNUM) && addend < 0) | |
338 | after_last_frame_setup_insn = next_pc; | |
339 | } | |
340 | else if (opc.id == RXO_mov | |
341 | && opc.op[0].type == RX_Operand_Indirect | |
342 | && opc.op[1].type == RX_Operand_Register | |
343 | && opc.size == RX_Long | |
344 | && (opc.op[0].reg == RX_SP_REGNUM | |
345 | || opc.op[0].reg == RX_FP_REGNUM) | |
346 | && (RX_R1_REGNUM <= opc.op[1].reg | |
347 | && opc.op[1].reg <= RX_R4_REGNUM)) | |
348 | { | |
349 | /* This moves an argument register to the stack. Don't | |
350 | record it, but allow it to be a part of the prologue. */ | |
351 | } | |
352 | else if (opc.id == RXO_branch | |
353 | && opc.op[0].type == RX_Operand_Immediate | |
baa835b4 KB |
354 | && next_pc < opc.op[0].addend) |
355 | { | |
356 | /* When a loop appears as the first statement of a function | |
357 | body, gcc 4.x will use a BRA instruction to branch to the | |
358 | loop condition checking code. This BRA instruction is | |
359 | marked as part of the prologue. We therefore set next_pc | |
360 | to this branch target and also stop the prologue scan. | |
361 | The instructions at and beyond the branch target should | |
362 | no longer be associated with the prologue. | |
363 | ||
364 | Note that we only consider forward branches here. We | |
365 | presume that a forward branch is being used to skip over | |
366 | a loop body. | |
367 | ||
368 | A backwards branch is covered by the default case below. | |
369 | If we were to encounter a backwards branch, that would | |
370 | most likely mean that we've scanned through a loop body. | |
371 | We definitely want to stop the prologue scan when this | |
372 | happens and that is precisely what is done by the default | |
373 | case below. */ | |
374 | ||
375 | after_last_frame_setup_insn = opc.op[0].addend; | |
376 | break; /* Scan no further if we hit this case. */ | |
377 | } | |
378 | else | |
379 | { | |
380 | /* Terminate the prologue scan. */ | |
381 | break; | |
382 | } | |
383 | ||
384 | pc = next_pc; | |
385 | } | |
386 | ||
387 | /* Is the frame size (offset, really) a known constant? */ | |
388 | if (pv_is_register (reg[RX_SP_REGNUM], RX_SP_REGNUM)) | |
389 | result->frame_size = reg[RX_SP_REGNUM].k; | |
390 | ||
391 | /* Was the frame pointer initialized? */ | |
392 | if (pv_is_register (reg[RX_FP_REGNUM], RX_SP_REGNUM)) | |
393 | { | |
394 | result->has_frame_ptr = 1; | |
395 | result->frame_ptr_offset = reg[RX_FP_REGNUM].k; | |
396 | } | |
397 | ||
398 | /* Record where all the registers were saved. */ | |
399 | pv_area_scan (stack, check_for_saved, (void *) result); | |
400 | ||
401 | result->prologue_end = after_last_frame_setup_insn; | |
402 | ||
403 | do_cleanups (back_to); | |
404 | } | |
405 | ||
406 | ||
407 | /* Implement the "skip_prologue" gdbarch method. */ | |
408 | static CORE_ADDR | |
409 | rx_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) | |
410 | { | |
2c02bd72 | 411 | const char *name; |
baa835b4 KB |
412 | CORE_ADDR func_addr, func_end; |
413 | struct rx_prologue p; | |
414 | ||
415 | /* Try to find the extent of the function that contains PC. */ | |
416 | if (!find_pc_partial_function (pc, &name, &func_addr, &func_end)) | |
417 | return pc; | |
418 | ||
1b485e67 KB |
419 | /* The frame type doesn't matter here, since we only care about |
420 | where the prologue ends. We'll use RX_FRAME_TYPE_NORMAL. */ | |
421 | rx_analyze_prologue (pc, func_end, RX_FRAME_TYPE_NORMAL, &p); | |
baa835b4 KB |
422 | return p.prologue_end; |
423 | } | |
424 | ||
425 | /* Given a frame described by THIS_FRAME, decode the prologue of its | |
426 | associated function if there is not cache entry as specified by | |
427 | THIS_PROLOGUE_CACHE. Save the decoded prologue in the cache and | |
428 | return that struct as the value of this function. */ | |
1b485e67 | 429 | |
baa835b4 KB |
430 | static struct rx_prologue * |
431 | rx_analyze_frame_prologue (struct frame_info *this_frame, | |
1b485e67 | 432 | enum rx_frame_type frame_type, |
baa835b4 KB |
433 | void **this_prologue_cache) |
434 | { | |
435 | if (!*this_prologue_cache) | |
436 | { | |
437 | CORE_ADDR func_start, stop_addr; | |
438 | ||
439 | *this_prologue_cache = FRAME_OBSTACK_ZALLOC (struct rx_prologue); | |
440 | ||
441 | func_start = get_frame_func (this_frame); | |
442 | stop_addr = get_frame_pc (this_frame); | |
443 | ||
444 | /* If we couldn't find any function containing the PC, then | |
445 | just initialize the prologue cache, but don't do anything. */ | |
446 | if (!func_start) | |
447 | stop_addr = func_start; | |
448 | ||
1b485e67 | 449 | rx_analyze_prologue (func_start, stop_addr, frame_type, |
19ba03f4 | 450 | (struct rx_prologue *) *this_prologue_cache); |
baa835b4 KB |
451 | } |
452 | ||
19ba03f4 | 453 | return (struct rx_prologue *) *this_prologue_cache; |
baa835b4 KB |
454 | } |
455 | ||
1b485e67 KB |
456 | /* Determine type of frame by scanning the function for a return |
457 | instruction. */ | |
458 | ||
459 | static enum rx_frame_type | |
460 | rx_frame_type (struct frame_info *this_frame, void **this_cache) | |
461 | { | |
462 | const char *name; | |
463 | CORE_ADDR pc, start_pc, lim_pc; | |
464 | int bytes_read; | |
465 | struct rx_get_opcode_byte_handle opcode_handle; | |
466 | RX_Opcode_Decoded opc; | |
467 | ||
468 | gdb_assert (this_cache != NULL); | |
469 | ||
470 | /* If we have a cached value, return it. */ | |
471 | ||
472 | if (*this_cache != NULL) | |
473 | { | |
19ba03f4 | 474 | struct rx_prologue *p = (struct rx_prologue *) *this_cache; |
1b485e67 KB |
475 | |
476 | return p->frame_type; | |
477 | } | |
478 | ||
479 | /* No cached value; scan the function. The frame type is cached in | |
480 | rx_analyze_prologue / rx_analyze_frame_prologue. */ | |
481 | ||
482 | pc = get_frame_pc (this_frame); | |
483 | ||
484 | /* Attempt to find the last address in the function. If it cannot | |
485 | be determined, set the limit to be a short ways past the frame's | |
486 | pc. */ | |
487 | if (!find_pc_partial_function (pc, &name, &start_pc, &lim_pc)) | |
488 | lim_pc = pc + 20; | |
489 | ||
490 | while (pc < lim_pc) | |
491 | { | |
492 | opcode_handle.pc = pc; | |
493 | bytes_read = rx_decode_opcode (pc, &opc, rx_get_opcode_byte, | |
494 | &opcode_handle); | |
495 | ||
496 | if (bytes_read <= 0 || opc.id == RXO_rts) | |
497 | return RX_FRAME_TYPE_NORMAL; | |
498 | else if (opc.id == RXO_rtfi) | |
499 | return RX_FRAME_TYPE_FAST_INTERRUPT; | |
500 | else if (opc.id == RXO_rte) | |
501 | return RX_FRAME_TYPE_EXCEPTION; | |
502 | ||
503 | pc += bytes_read; | |
504 | } | |
505 | ||
506 | return RX_FRAME_TYPE_NORMAL; | |
507 | } | |
508 | ||
509 | ||
baa835b4 KB |
510 | /* Given the next frame and a prologue cache, return this frame's |
511 | base. */ | |
1b485e67 | 512 | |
baa835b4 | 513 | static CORE_ADDR |
1b485e67 | 514 | rx_frame_base (struct frame_info *this_frame, void **this_cache) |
baa835b4 | 515 | { |
1b485e67 | 516 | enum rx_frame_type frame_type = rx_frame_type (this_frame, this_cache); |
baa835b4 | 517 | struct rx_prologue *p |
1b485e67 | 518 | = rx_analyze_frame_prologue (this_frame, frame_type, this_cache); |
baa835b4 KB |
519 | |
520 | /* In functions that use alloca, the distance between the stack | |
521 | pointer and the frame base varies dynamically, so we can't use | |
522 | the SP plus static information like prologue analysis to find the | |
523 | frame base. However, such functions must have a frame pointer, | |
524 | to be able to restore the SP on exit. So whenever we do have a | |
525 | frame pointer, use that to find the base. */ | |
526 | if (p->has_frame_ptr) | |
527 | { | |
528 | CORE_ADDR fp = get_frame_register_unsigned (this_frame, RX_FP_REGNUM); | |
529 | return fp - p->frame_ptr_offset; | |
530 | } | |
531 | else | |
532 | { | |
533 | CORE_ADDR sp = get_frame_register_unsigned (this_frame, RX_SP_REGNUM); | |
534 | return sp - p->frame_size; | |
535 | } | |
536 | } | |
537 | ||
538 | /* Implement the "frame_this_id" method for unwinding frames. */ | |
1b485e67 | 539 | |
baa835b4 | 540 | static void |
1b485e67 KB |
541 | rx_frame_this_id (struct frame_info *this_frame, void **this_cache, |
542 | struct frame_id *this_id) | |
baa835b4 | 543 | { |
1b485e67 | 544 | *this_id = frame_id_build (rx_frame_base (this_frame, this_cache), |
baa835b4 KB |
545 | get_frame_func (this_frame)); |
546 | } | |
547 | ||
548 | /* Implement the "frame_prev_register" method for unwinding frames. */ | |
1b485e67 | 549 | |
baa835b4 | 550 | static struct value * |
1b485e67 KB |
551 | rx_frame_prev_register (struct frame_info *this_frame, void **this_cache, |
552 | int regnum) | |
baa835b4 | 553 | { |
1b485e67 | 554 | enum rx_frame_type frame_type = rx_frame_type (this_frame, this_cache); |
baa835b4 | 555 | struct rx_prologue *p |
1b485e67 KB |
556 | = rx_analyze_frame_prologue (this_frame, frame_type, this_cache); |
557 | CORE_ADDR frame_base = rx_frame_base (this_frame, this_cache); | |
baa835b4 KB |
558 | |
559 | if (regnum == RX_SP_REGNUM) | |
1b485e67 KB |
560 | { |
561 | if (frame_type == RX_FRAME_TYPE_EXCEPTION) | |
562 | { | |
563 | struct value *psw_val; | |
564 | CORE_ADDR psw; | |
565 | ||
566 | psw_val = rx_frame_prev_register (this_frame, this_cache, | |
567 | RX_PSW_REGNUM); | |
568 | psw = extract_unsigned_integer (value_contents_all (psw_val), 4, | |
569 | gdbarch_byte_order ( | |
570 | get_frame_arch (this_frame))); | |
571 | ||
572 | if ((psw & 0x20000 /* U bit */) != 0) | |
573 | return rx_frame_prev_register (this_frame, this_cache, | |
574 | RX_USP_REGNUM); | |
575 | ||
576 | /* Fall through for the case where U bit is zero. */ | |
577 | } | |
578 | ||
579 | return frame_unwind_got_constant (this_frame, regnum, frame_base); | |
580 | } | |
581 | ||
582 | if (frame_type == RX_FRAME_TYPE_FAST_INTERRUPT) | |
583 | { | |
584 | if (regnum == RX_PC_REGNUM) | |
585 | return rx_frame_prev_register (this_frame, this_cache, | |
586 | RX_BPC_REGNUM); | |
587 | if (regnum == RX_PSW_REGNUM) | |
588 | return rx_frame_prev_register (this_frame, this_cache, | |
589 | RX_BPSW_REGNUM); | |
590 | } | |
baa835b4 KB |
591 | |
592 | /* If prologue analysis says we saved this register somewhere, | |
593 | return a description of the stack slot holding it. */ | |
1b485e67 | 594 | if (p->reg_offset[regnum] != 1) |
baa835b4 KB |
595 | return frame_unwind_got_memory (this_frame, regnum, |
596 | frame_base + p->reg_offset[regnum]); | |
597 | ||
598 | /* Otherwise, presume we haven't changed the value of this | |
599 | register, and get it from the next frame. */ | |
1b485e67 KB |
600 | return frame_unwind_got_register (this_frame, regnum, regnum); |
601 | } | |
602 | ||
603 | /* Return TRUE if the frame indicated by FRAME_TYPE is a normal frame. */ | |
604 | ||
605 | static int | |
606 | normal_frame_p (enum rx_frame_type frame_type) | |
607 | { | |
608 | return (frame_type == RX_FRAME_TYPE_NORMAL); | |
609 | } | |
610 | ||
611 | /* Return TRUE if the frame indicated by FRAME_TYPE is an exception | |
612 | frame. */ | |
613 | ||
614 | static int | |
615 | exception_frame_p (enum rx_frame_type frame_type) | |
616 | { | |
617 | return (frame_type == RX_FRAME_TYPE_EXCEPTION | |
618 | || frame_type == RX_FRAME_TYPE_FAST_INTERRUPT); | |
619 | } | |
620 | ||
621 | /* Common code used by both normal and exception frame sniffers. */ | |
622 | ||
623 | static int | |
624 | rx_frame_sniffer_common (const struct frame_unwind *self, | |
625 | struct frame_info *this_frame, | |
626 | void **this_cache, | |
627 | int (*sniff_p)(enum rx_frame_type) ) | |
628 | { | |
629 | gdb_assert (this_cache != NULL); | |
630 | ||
631 | if (*this_cache == NULL) | |
632 | { | |
633 | enum rx_frame_type frame_type = rx_frame_type (this_frame, this_cache); | |
634 | ||
635 | if (sniff_p (frame_type)) | |
636 | { | |
637 | /* The call below will fill in the cache, including the frame | |
638 | type. */ | |
639 | (void) rx_analyze_frame_prologue (this_frame, frame_type, this_cache); | |
640 | ||
641 | return 1; | |
642 | } | |
643 | else | |
644 | return 0; | |
645 | } | |
baa835b4 | 646 | else |
1b485e67 | 647 | { |
19ba03f4 | 648 | struct rx_prologue *p = (struct rx_prologue *) *this_cache; |
1b485e67 KB |
649 | |
650 | return sniff_p (p->frame_type); | |
651 | } | |
652 | } | |
653 | ||
654 | /* Frame sniffer for normal (non-exception) frames. */ | |
655 | ||
656 | static int | |
657 | rx_frame_sniffer (const struct frame_unwind *self, | |
658 | struct frame_info *this_frame, | |
659 | void **this_cache) | |
660 | { | |
661 | return rx_frame_sniffer_common (self, this_frame, this_cache, | |
662 | normal_frame_p); | |
663 | } | |
664 | ||
665 | /* Frame sniffer for exception frames. */ | |
666 | ||
667 | static int | |
668 | rx_exception_sniffer (const struct frame_unwind *self, | |
669 | struct frame_info *this_frame, | |
670 | void **this_cache) | |
671 | { | |
672 | return rx_frame_sniffer_common (self, this_frame, this_cache, | |
673 | exception_frame_p); | |
baa835b4 KB |
674 | } |
675 | ||
1b485e67 KB |
676 | /* Data structure for normal code using instruction-based prologue |
677 | analyzer. */ | |
678 | ||
baa835b4 KB |
679 | static const struct frame_unwind rx_frame_unwind = { |
680 | NORMAL_FRAME, | |
e0f68161 | 681 | default_frame_unwind_stop_reason, |
baa835b4 KB |
682 | rx_frame_this_id, |
683 | rx_frame_prev_register, | |
684 | NULL, | |
1b485e67 KB |
685 | rx_frame_sniffer |
686 | }; | |
687 | ||
688 | /* Data structure for exception code using instruction-based prologue | |
689 | analyzer. */ | |
690 | ||
691 | static const struct frame_unwind rx_exception_unwind = { | |
692 | /* SIGTRAMP_FRAME could be used here, but backtraces are less informative. */ | |
693 | NORMAL_FRAME, | |
694 | default_frame_unwind_stop_reason, | |
695 | rx_frame_this_id, | |
696 | rx_frame_prev_register, | |
697 | NULL, | |
698 | rx_exception_sniffer | |
baa835b4 KB |
699 | }; |
700 | ||
701 | /* Implement the "unwind_pc" gdbarch method. */ | |
702 | static CORE_ADDR | |
703 | rx_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame) | |
704 | { | |
705 | ULONGEST pc; | |
706 | ||
707 | pc = frame_unwind_register_unsigned (this_frame, RX_PC_REGNUM); | |
708 | return pc; | |
709 | } | |
710 | ||
711 | /* Implement the "unwind_sp" gdbarch method. */ | |
712 | static CORE_ADDR | |
713 | rx_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame) | |
714 | { | |
715 | ULONGEST sp; | |
716 | ||
717 | sp = frame_unwind_register_unsigned (this_frame, RX_SP_REGNUM); | |
718 | return sp; | |
719 | } | |
720 | ||
721 | /* Implement the "dummy_id" gdbarch method. */ | |
722 | static struct frame_id | |
723 | rx_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) | |
724 | { | |
725 | return | |
726 | frame_id_build (get_frame_register_unsigned (this_frame, RX_SP_REGNUM), | |
727 | get_frame_pc (this_frame)); | |
728 | } | |
729 | ||
730 | /* Implement the "push_dummy_call" gdbarch method. */ | |
731 | static CORE_ADDR | |
732 | rx_push_dummy_call (struct gdbarch *gdbarch, struct value *function, | |
733 | struct regcache *regcache, CORE_ADDR bp_addr, int nargs, | |
734 | struct value **args, CORE_ADDR sp, int struct_return, | |
735 | CORE_ADDR struct_addr) | |
736 | { | |
737 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
738 | int write_pass; | |
739 | int sp_off = 0; | |
740 | CORE_ADDR cfa; | |
741 | int num_register_candidate_args; | |
742 | ||
743 | struct type *func_type = value_type (function); | |
744 | ||
745 | /* Dereference function pointer types. */ | |
746 | while (TYPE_CODE (func_type) == TYPE_CODE_PTR) | |
747 | func_type = TYPE_TARGET_TYPE (func_type); | |
748 | ||
749 | /* The end result had better be a function or a method. */ | |
750 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC | |
751 | || TYPE_CODE (func_type) == TYPE_CODE_METHOD); | |
752 | ||
753 | /* Functions with a variable number of arguments have all of their | |
754 | variable arguments and the last non-variable argument passed | |
755 | on the stack. | |
756 | ||
757 | Otherwise, we can pass up to four arguments on the stack. | |
758 | ||
759 | Once computed, we leave this value alone. I.e. we don't update | |
760 | it in case of a struct return going in a register or an argument | |
761 | requiring multiple registers, etc. We rely instead on the value | |
762 | of the ``arg_reg'' variable to get these other details correct. */ | |
763 | ||
764 | if (TYPE_VARARGS (func_type)) | |
765 | num_register_candidate_args = TYPE_NFIELDS (func_type) - 1; | |
766 | else | |
767 | num_register_candidate_args = 4; | |
768 | ||
769 | /* We make two passes; the first does the stack allocation, | |
770 | the second actually stores the arguments. */ | |
771 | for (write_pass = 0; write_pass <= 1; write_pass++) | |
772 | { | |
773 | int i; | |
774 | int arg_reg = RX_R1_REGNUM; | |
775 | ||
776 | if (write_pass) | |
777 | sp = align_down (sp - sp_off, 4); | |
778 | sp_off = 0; | |
779 | ||
780 | if (struct_return) | |
781 | { | |
782 | struct type *return_type = TYPE_TARGET_TYPE (func_type); | |
783 | ||
784 | gdb_assert (TYPE_CODE (return_type) == TYPE_CODE_STRUCT | |
785 | || TYPE_CODE (func_type) == TYPE_CODE_UNION); | |
786 | ||
787 | if (TYPE_LENGTH (return_type) > 16 | |
788 | || TYPE_LENGTH (return_type) % 4 != 0) | |
789 | { | |
790 | if (write_pass) | |
791 | regcache_cooked_write_unsigned (regcache, RX_R15_REGNUM, | |
792 | struct_addr); | |
793 | } | |
794 | } | |
795 | ||
796 | /* Push the arguments. */ | |
797 | for (i = 0; i < nargs; i++) | |
798 | { | |
799 | struct value *arg = args[i]; | |
800 | const gdb_byte *arg_bits = value_contents_all (arg); | |
801 | struct type *arg_type = check_typedef (value_type (arg)); | |
802 | ULONGEST arg_size = TYPE_LENGTH (arg_type); | |
803 | ||
804 | if (i == 0 && struct_addr != 0 && !struct_return | |
805 | && TYPE_CODE (arg_type) == TYPE_CODE_PTR | |
806 | && extract_unsigned_integer (arg_bits, 4, | |
807 | byte_order) == struct_addr) | |
808 | { | |
809 | /* This argument represents the address at which C++ (and | |
810 | possibly other languages) store their return value. | |
811 | Put this value in R15. */ | |
812 | if (write_pass) | |
813 | regcache_cooked_write_unsigned (regcache, RX_R15_REGNUM, | |
814 | struct_addr); | |
815 | } | |
816 | else if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT | |
94715c17 KB |
817 | && TYPE_CODE (arg_type) != TYPE_CODE_UNION |
818 | && arg_size <= 8) | |
baa835b4 KB |
819 | { |
820 | /* Argument is a scalar. */ | |
821 | if (arg_size == 8) | |
822 | { | |
823 | if (i < num_register_candidate_args | |
824 | && arg_reg <= RX_R4_REGNUM - 1) | |
825 | { | |
826 | /* If argument registers are going to be used to pass | |
827 | an 8 byte scalar, the ABI specifies that two registers | |
828 | must be available. */ | |
829 | if (write_pass) | |
830 | { | |
831 | regcache_cooked_write_unsigned (regcache, arg_reg, | |
832 | extract_unsigned_integer | |
833 | (arg_bits, 4, | |
834 | byte_order)); | |
835 | regcache_cooked_write_unsigned (regcache, | |
836 | arg_reg + 1, | |
837 | extract_unsigned_integer | |
838 | (arg_bits + 4, 4, | |
839 | byte_order)); | |
840 | } | |
841 | arg_reg += 2; | |
842 | } | |
843 | else | |
844 | { | |
845 | sp_off = align_up (sp_off, 4); | |
846 | /* Otherwise, pass the 8 byte scalar on the stack. */ | |
847 | if (write_pass) | |
848 | write_memory (sp + sp_off, arg_bits, 8); | |
849 | sp_off += 8; | |
850 | } | |
851 | } | |
852 | else | |
853 | { | |
854 | ULONGEST u; | |
855 | ||
856 | gdb_assert (arg_size <= 4); | |
857 | ||
858 | u = | |
859 | extract_unsigned_integer (arg_bits, arg_size, byte_order); | |
860 | ||
861 | if (i < num_register_candidate_args | |
862 | && arg_reg <= RX_R4_REGNUM) | |
863 | { | |
864 | if (write_pass) | |
865 | regcache_cooked_write_unsigned (regcache, arg_reg, u); | |
866 | arg_reg += 1; | |
867 | } | |
868 | else | |
869 | { | |
870 | int p_arg_size = 4; | |
871 | ||
872 | if (TYPE_PROTOTYPED (func_type) | |
873 | && i < TYPE_NFIELDS (func_type)) | |
874 | { | |
875 | struct type *p_arg_type = | |
876 | TYPE_FIELD_TYPE (func_type, i); | |
877 | p_arg_size = TYPE_LENGTH (p_arg_type); | |
878 | } | |
879 | ||
880 | sp_off = align_up (sp_off, p_arg_size); | |
881 | ||
882 | if (write_pass) | |
883 | write_memory_unsigned_integer (sp + sp_off, | |
884 | p_arg_size, byte_order, | |
885 | u); | |
886 | sp_off += p_arg_size; | |
887 | } | |
888 | } | |
889 | } | |
890 | else | |
891 | { | |
892 | /* Argument is a struct or union. Pass as much of the struct | |
893 | in registers, if possible. Pass the rest on the stack. */ | |
894 | while (arg_size > 0) | |
895 | { | |
896 | if (i < num_register_candidate_args | |
897 | && arg_reg <= RX_R4_REGNUM | |
898 | && arg_size <= 4 * (RX_R4_REGNUM - arg_reg + 1) | |
899 | && arg_size % 4 == 0) | |
900 | { | |
325fac50 | 901 | int len = std::min (arg_size, (ULONGEST) 4); |
baa835b4 KB |
902 | |
903 | if (write_pass) | |
904 | regcache_cooked_write_unsigned (regcache, arg_reg, | |
905 | extract_unsigned_integer | |
906 | (arg_bits, len, | |
907 | byte_order)); | |
908 | arg_bits += len; | |
909 | arg_size -= len; | |
910 | arg_reg++; | |
911 | } | |
912 | else | |
913 | { | |
914 | sp_off = align_up (sp_off, 4); | |
915 | if (write_pass) | |
916 | write_memory (sp + sp_off, arg_bits, arg_size); | |
917 | sp_off += align_up (arg_size, 4); | |
918 | arg_size = 0; | |
919 | } | |
920 | } | |
921 | } | |
922 | } | |
923 | } | |
924 | ||
925 | /* Keep track of the stack address prior to pushing the return address. | |
926 | This is the value that we'll return. */ | |
927 | cfa = sp; | |
928 | ||
929 | /* Push the return address. */ | |
930 | sp = sp - 4; | |
931 | write_memory_unsigned_integer (sp, 4, byte_order, bp_addr); | |
932 | ||
933 | /* Update the stack pointer. */ | |
934 | regcache_cooked_write_unsigned (regcache, RX_SP_REGNUM, sp); | |
935 | ||
936 | return cfa; | |
937 | } | |
938 | ||
939 | /* Implement the "return_value" gdbarch method. */ | |
940 | static enum return_value_convention | |
941 | rx_return_value (struct gdbarch *gdbarch, | |
6a3a010b | 942 | struct value *function, |
baa835b4 KB |
943 | struct type *valtype, |
944 | struct regcache *regcache, | |
945 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
946 | { | |
947 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
948 | ULONGEST valtype_len = TYPE_LENGTH (valtype); | |
949 | ||
950 | if (TYPE_LENGTH (valtype) > 16 | |
951 | || ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT | |
952 | || TYPE_CODE (valtype) == TYPE_CODE_UNION) | |
953 | && TYPE_LENGTH (valtype) % 4 != 0)) | |
954 | return RETURN_VALUE_STRUCT_CONVENTION; | |
955 | ||
956 | if (readbuf) | |
957 | { | |
958 | ULONGEST u; | |
959 | int argreg = RX_R1_REGNUM; | |
960 | int offset = 0; | |
961 | ||
962 | while (valtype_len > 0) | |
963 | { | |
325fac50 | 964 | int len = std::min (valtype_len, (ULONGEST) 4); |
baa835b4 KB |
965 | |
966 | regcache_cooked_read_unsigned (regcache, argreg, &u); | |
967 | store_unsigned_integer (readbuf + offset, len, byte_order, u); | |
968 | valtype_len -= len; | |
969 | offset += len; | |
970 | argreg++; | |
971 | } | |
972 | } | |
973 | ||
974 | if (writebuf) | |
975 | { | |
976 | ULONGEST u; | |
977 | int argreg = RX_R1_REGNUM; | |
978 | int offset = 0; | |
979 | ||
980 | while (valtype_len > 0) | |
981 | { | |
325fac50 | 982 | int len = std::min (valtype_len, (ULONGEST) 4); |
baa835b4 KB |
983 | |
984 | u = extract_unsigned_integer (writebuf + offset, len, byte_order); | |
985 | regcache_cooked_write_unsigned (regcache, argreg, u); | |
986 | valtype_len -= len; | |
987 | offset += len; | |
988 | argreg++; | |
989 | } | |
990 | } | |
991 | ||
992 | return RETURN_VALUE_REGISTER_CONVENTION; | |
993 | } | |
994 | ||
04180708 | 995 | constexpr gdb_byte rx_break_insn[] = { 0x00 }; |
598cc9dc | 996 | |
04180708 | 997 | typedef BP_MANIPULATION (rx_break_insn) rx_breakpoint; |
baa835b4 | 998 | |
fd6e021d KB |
999 | /* Implement the dwarf_reg_to_regnum" gdbarch method. */ |
1000 | ||
1001 | static int | |
1002 | rx_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg) | |
1003 | { | |
1004 | if (0 <= reg && reg <= 15) | |
1005 | return reg; | |
1006 | else if (reg == 16) | |
1007 | return RX_PSW_REGNUM; | |
1008 | else if (reg == 17) | |
1009 | return RX_PC_REGNUM; | |
1010 | else | |
0fde2c53 | 1011 | return -1; |
fd6e021d KB |
1012 | } |
1013 | ||
baa835b4 KB |
1014 | /* Allocate and initialize a gdbarch object. */ |
1015 | static struct gdbarch * | |
1016 | rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1017 | { | |
1018 | struct gdbarch *gdbarch; | |
1019 | struct gdbarch_tdep *tdep; | |
1020 | int elf_flags; | |
1021 | ||
1022 | /* Extract the elf_flags if available. */ | |
1023 | if (info.abfd != NULL | |
1024 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
1025 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
1026 | else | |
1027 | elf_flags = 0; | |
1028 | ||
1029 | ||
1030 | /* Try to find the architecture in the list of already defined | |
1031 | architectures. */ | |
1032 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
1033 | arches != NULL; | |
1034 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
1035 | { | |
1036 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) | |
1037 | continue; | |
1038 | ||
1039 | return arches->gdbarch; | |
1040 | } | |
1041 | ||
1042 | /* None found, create a new architecture from the information | |
1043 | provided. */ | |
8d749320 | 1044 | tdep = XNEW (struct gdbarch_tdep); |
baa835b4 KB |
1045 | gdbarch = gdbarch_alloc (&info, tdep); |
1046 | tdep->elf_flags = elf_flags; | |
1047 | ||
0561fea4 KB |
1048 | /* Initialize the flags type for PSW and BPSW. */ |
1049 | ||
1050 | tdep->rx_psw_type = arch_flags_type (gdbarch, "rx_psw_type", 4); | |
1051 | append_flags_type_flag (tdep->rx_psw_type, 0, "C"); | |
1052 | append_flags_type_flag (tdep->rx_psw_type, 1, "Z"); | |
1053 | append_flags_type_flag (tdep->rx_psw_type, 2, "S"); | |
1054 | append_flags_type_flag (tdep->rx_psw_type, 3, "O"); | |
1055 | append_flags_type_flag (tdep->rx_psw_type, 16, "I"); | |
1056 | append_flags_type_flag (tdep->rx_psw_type, 17, "U"); | |
1057 | append_flags_type_flag (tdep->rx_psw_type, 20, "PM"); | |
1058 | append_flags_type_flag (tdep->rx_psw_type, 24, "IPL0"); | |
1059 | append_flags_type_flag (tdep->rx_psw_type, 25, "IPL1"); | |
1060 | append_flags_type_flag (tdep->rx_psw_type, 26, "IPL2"); | |
1061 | append_flags_type_flag (tdep->rx_psw_type, 27, "IPL3"); | |
1062 | ||
1063 | /* Initialize flags type for FPSW. */ | |
1064 | ||
1065 | tdep->rx_fpsw_type = arch_flags_type (gdbarch, "rx_fpsw_type", 4); | |
1066 | append_flags_type_flag (tdep->rx_fpsw_type, 0, "RM0"); | |
1067 | append_flags_type_flag (tdep->rx_fpsw_type, 1, "RM1"); | |
1068 | append_flags_type_flag (tdep->rx_fpsw_type, 2, "CV"); | |
1069 | append_flags_type_flag (tdep->rx_fpsw_type, 3, "CO"); | |
1070 | append_flags_type_flag (tdep->rx_fpsw_type, 4, "CZ"); | |
1071 | append_flags_type_flag (tdep->rx_fpsw_type, 5, "CU"); | |
1072 | append_flags_type_flag (tdep->rx_fpsw_type, 6, "CX"); | |
1073 | append_flags_type_flag (tdep->rx_fpsw_type, 7, "CE"); | |
1074 | append_flags_type_flag (tdep->rx_fpsw_type, 8, "DN"); | |
1075 | append_flags_type_flag (tdep->rx_fpsw_type, 10, "EV"); | |
1076 | append_flags_type_flag (tdep->rx_fpsw_type, 11, "EO"); | |
1077 | append_flags_type_flag (tdep->rx_fpsw_type, 12, "EZ"); | |
1078 | append_flags_type_flag (tdep->rx_fpsw_type, 13, "EU"); | |
1079 | append_flags_type_flag (tdep->rx_fpsw_type, 14, "EX"); | |
1080 | append_flags_type_flag (tdep->rx_fpsw_type, 26, "FV"); | |
1081 | append_flags_type_flag (tdep->rx_fpsw_type, 27, "FO"); | |
1082 | append_flags_type_flag (tdep->rx_fpsw_type, 28, "FZ"); | |
1083 | append_flags_type_flag (tdep->rx_fpsw_type, 29, "FU"); | |
1084 | append_flags_type_flag (tdep->rx_fpsw_type, 30, "FX"); | |
1085 | append_flags_type_flag (tdep->rx_fpsw_type, 31, "FS"); | |
1086 | ||
baa835b4 KB |
1087 | set_gdbarch_num_regs (gdbarch, RX_NUM_REGS); |
1088 | set_gdbarch_num_pseudo_regs (gdbarch, 0); | |
1089 | set_gdbarch_register_name (gdbarch, rx_register_name); | |
1090 | set_gdbarch_register_type (gdbarch, rx_register_type); | |
1091 | set_gdbarch_pc_regnum (gdbarch, RX_PC_REGNUM); | |
1092 | set_gdbarch_sp_regnum (gdbarch, RX_SP_REGNUM); | |
1093 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1094 | set_gdbarch_decr_pc_after_break (gdbarch, 1); | |
04180708 YQ |
1095 | set_gdbarch_breakpoint_kind_from_pc (gdbarch, rx_breakpoint::kind_from_pc); |
1096 | set_gdbarch_sw_breakpoint_from_kind (gdbarch, rx_breakpoint::bp_from_kind); | |
baa835b4 KB |
1097 | set_gdbarch_skip_prologue (gdbarch, rx_skip_prologue); |
1098 | ||
1099 | set_gdbarch_print_insn (gdbarch, print_insn_rx); | |
1100 | ||
1101 | set_gdbarch_unwind_pc (gdbarch, rx_unwind_pc); | |
1102 | set_gdbarch_unwind_sp (gdbarch, rx_unwind_sp); | |
1103 | ||
1104 | /* Target builtin data types. */ | |
1105 | set_gdbarch_char_signed (gdbarch, 0); | |
1106 | set_gdbarch_short_bit (gdbarch, 16); | |
1107 | set_gdbarch_int_bit (gdbarch, 32); | |
1108 | set_gdbarch_long_bit (gdbarch, 32); | |
1109 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1110 | set_gdbarch_ptr_bit (gdbarch, 32); | |
1111 | set_gdbarch_float_bit (gdbarch, 32); | |
1112 | set_gdbarch_float_format (gdbarch, floatformats_ieee_single); | |
1113 | if (elf_flags & E_FLAG_RX_64BIT_DOUBLES) | |
1114 | { | |
1115 | set_gdbarch_double_bit (gdbarch, 64); | |
1116 | set_gdbarch_long_double_bit (gdbarch, 64); | |
1117 | set_gdbarch_double_format (gdbarch, floatformats_ieee_double); | |
1118 | set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double); | |
1119 | } | |
1120 | else | |
1121 | { | |
1122 | set_gdbarch_double_bit (gdbarch, 32); | |
1123 | set_gdbarch_long_double_bit (gdbarch, 32); | |
1124 | set_gdbarch_double_format (gdbarch, floatformats_ieee_single); | |
1125 | set_gdbarch_long_double_format (gdbarch, floatformats_ieee_single); | |
1126 | } | |
1127 | ||
fd6e021d KB |
1128 | /* DWARF register mapping. */ |
1129 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rx_dwarf_reg_to_regnum); | |
1130 | ||
baa835b4 | 1131 | /* Frame unwinding. */ |
1b485e67 | 1132 | frame_unwind_append_unwinder (gdbarch, &rx_exception_unwind); |
baa835b4 | 1133 | dwarf2_append_unwinders (gdbarch); |
baa835b4 KB |
1134 | frame_unwind_append_unwinder (gdbarch, &rx_frame_unwind); |
1135 | ||
1136 | /* Methods for saving / extracting a dummy frame's ID. | |
1137 | The ID's stack address must match the SP value returned by | |
1138 | PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */ | |
1139 | set_gdbarch_dummy_id (gdbarch, rx_dummy_id); | |
1140 | set_gdbarch_push_dummy_call (gdbarch, rx_push_dummy_call); | |
1141 | set_gdbarch_return_value (gdbarch, rx_return_value); | |
1142 | ||
1143 | /* Virtual tables. */ | |
1144 | set_gdbarch_vbit_in_delta (gdbarch, 1); | |
1145 | ||
1146 | return gdbarch; | |
1147 | } | |
1148 | ||
693be288 JK |
1149 | /* -Wmissing-prototypes */ |
1150 | extern initialize_file_ftype _initialize_rx_tdep; | |
1151 | ||
baa835b4 | 1152 | /* Register the above initialization routine. */ |
693be288 | 1153 | |
baa835b4 KB |
1154 | void |
1155 | _initialize_rx_tdep (void) | |
1156 | { | |
1157 | register_gdbarch_init (bfd_arch_rx, rx_gdbarch_init); | |
1158 | } |