1 /* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
3 Copyright (C) 2008-2020 Free Software Foundation, Inc.
5 Contributed by Red Hat, Inc.
7 This file is part of GDB.
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.
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.
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/>. */
23 #include "arch-utils.h"
24 #include "prologue-value.h"
27 #include "opcode/rx.h"
31 #include "frame-unwind.h"
32 #include "frame-base.h"
35 #include "dwarf2/frame.h"
37 #include "target-descriptions.h"
43 #include "features/rx.c"
45 /* Certain important register numbers. */
66 RX_FRAME_TYPE_EXCEPTION
,
67 RX_FRAME_TYPE_FAST_INTERRUPT
70 /* Architecture specific data. */
73 /* The ELF header flags specify the multilib used. */
76 /* Type of PSW and BPSW. */
77 struct type
*rx_psw_type
;
80 struct type
*rx_fpsw_type
;
83 /* This structure holds the results of a prologue analysis. */
86 /* Frame type, either a normal frame or one of two types of exception
88 enum rx_frame_type frame_type
;
90 /* The offset from the frame base to the stack pointer --- always
93 Calling this a "size" is a bit misleading, but given that the
94 stack grows downwards, using offsets for everything keeps one
95 from going completely sign-crazy: you never change anything's
96 sign for an ADD instruction; always change the second operand's
97 sign for a SUB instruction; and everything takes care of
101 /* Non-zero if this function has initialized the frame pointer from
102 the stack pointer, zero otherwise. */
105 /* If has_frame_ptr is non-zero, this is the offset from the frame
106 base to where the frame pointer points. This is always zero or
108 int frame_ptr_offset
;
110 /* The address of the first instruction at which the frame has been
111 set up and the arguments are where the debug info says they are
112 --- as best as we can tell. */
113 CORE_ADDR prologue_end
;
115 /* reg_offset[R] is the offset from the CFA at which register R is
116 saved, or 1 if register R has not been saved. (Real values are
117 always zero or negative.) */
118 int reg_offset
[RX_NUM_REGS
];
121 /* RX register names */
122 static const char *const rx_register_names
[] = {
123 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
124 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
125 "usp", "isp", "psw", "pc", "intb", "bpsw","bpc","fintv",
130 /* Function for finding saved registers in a 'struct pv_area'; this
131 function is passed to pv_area::scan.
133 If VALUE is a saved register, ADDR says it was saved at a constant
134 offset from the frame base, and SIZE indicates that the whole
135 register was saved, record its offset. */
137 check_for_saved (void *result_untyped
, pv_t addr
, CORE_ADDR size
, pv_t value
)
139 struct rx_prologue
*result
= (struct rx_prologue
*) result_untyped
;
141 if (value
.kind
== pvk_register
143 && pv_is_register (addr
, RX_SP_REGNUM
)
144 && size
== register_size (target_gdbarch (), value
.reg
))
145 result
->reg_offset
[value
.reg
] = addr
.k
;
148 /* Define a "handle" struct for fetching the next opcode. */
149 struct rx_get_opcode_byte_handle
154 /* Fetch a byte on behalf of the opcode decoder. HANDLE contains
155 the memory address of the next byte to fetch. If successful,
156 the address in the handle is updated and the byte fetched is
157 returned as the value of the function. If not successful, -1
160 rx_get_opcode_byte (void *handle
)
162 struct rx_get_opcode_byte_handle
*opcdata
163 = (struct rx_get_opcode_byte_handle
*) handle
;
167 status
= target_read_code (opcdata
->pc
, &byte
, 1);
177 /* Analyze a prologue starting at START_PC, going no further than
178 LIMIT_PC. Fill in RESULT as appropriate. */
181 rx_analyze_prologue (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
182 enum rx_frame_type frame_type
,
183 struct rx_prologue
*result
)
185 CORE_ADDR pc
, next_pc
;
187 pv_t reg
[RX_NUM_REGS
];
188 CORE_ADDR after_last_frame_setup_insn
= start_pc
;
190 memset (result
, 0, sizeof (*result
));
192 result
->frame_type
= frame_type
;
194 for (rn
= 0; rn
< RX_NUM_REGS
; rn
++)
196 reg
[rn
] = pv_register (rn
, 0);
197 result
->reg_offset
[rn
] = 1;
200 pv_area
stack (RX_SP_REGNUM
, gdbarch_addr_bit (target_gdbarch ()));
202 if (frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
)
204 /* This code won't do anything useful at present, but this is
205 what happens for fast interrupts. */
206 reg
[RX_BPSW_REGNUM
] = reg
[RX_PSW_REGNUM
];
207 reg
[RX_BPC_REGNUM
] = reg
[RX_PC_REGNUM
];
211 /* When an exception occurs, the PSW is saved to the interrupt stack
213 if (frame_type
== RX_FRAME_TYPE_EXCEPTION
)
215 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
216 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[RX_PSW_REGNUM
]);
219 /* The call instruction (or an exception/interrupt) has saved the return
220 address on the stack. */
221 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
222 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[RX_PC_REGNUM
]);
228 while (pc
< limit_pc
)
231 struct rx_get_opcode_byte_handle opcode_handle
;
232 RX_Opcode_Decoded opc
;
234 opcode_handle
.pc
= pc
;
235 bytes_read
= rx_decode_opcode (pc
, &opc
, rx_get_opcode_byte
,
237 next_pc
= pc
+ bytes_read
;
239 if (opc
.id
== RXO_pushm
/* pushm r1, r2 */
240 && opc
.op
[1].type
== RX_Operand_Register
241 && opc
.op
[2].type
== RX_Operand_Register
)
248 for (r
= r2
; r
>= r1
; r
--)
250 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
251 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[r
]);
253 after_last_frame_setup_insn
= next_pc
;
255 else if (opc
.id
== RXO_mov
/* mov.l rdst, rsrc */
256 && opc
.op
[0].type
== RX_Operand_Register
257 && opc
.op
[1].type
== RX_Operand_Register
258 && opc
.size
== RX_Long
)
262 rdst
= opc
.op
[0].reg
;
263 rsrc
= opc
.op
[1].reg
;
264 reg
[rdst
] = reg
[rsrc
];
265 if (rdst
== RX_FP_REGNUM
&& rsrc
== RX_SP_REGNUM
)
266 after_last_frame_setup_insn
= next_pc
;
268 else if (opc
.id
== RXO_mov
/* mov.l rsrc, [-SP] */
269 && opc
.op
[0].type
== RX_Operand_Predec
270 && opc
.op
[0].reg
== RX_SP_REGNUM
271 && opc
.op
[1].type
== RX_Operand_Register
272 && opc
.size
== RX_Long
)
276 rsrc
= opc
.op
[1].reg
;
277 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
278 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[rsrc
]);
279 after_last_frame_setup_insn
= next_pc
;
281 else if (opc
.id
== RXO_add
/* add #const, rsrc, rdst */
282 && opc
.op
[0].type
== RX_Operand_Register
283 && opc
.op
[1].type
== RX_Operand_Immediate
284 && opc
.op
[2].type
== RX_Operand_Register
)
286 int rdst
= opc
.op
[0].reg
;
287 int addend
= opc
.op
[1].addend
;
288 int rsrc
= opc
.op
[2].reg
;
289 reg
[rdst
] = pv_add_constant (reg
[rsrc
], addend
);
290 /* Negative adjustments to the stack pointer or frame pointer
291 are (most likely) part of the prologue. */
292 if ((rdst
== RX_SP_REGNUM
|| rdst
== RX_FP_REGNUM
) && addend
< 0)
293 after_last_frame_setup_insn
= next_pc
;
295 else if (opc
.id
== RXO_mov
296 && opc
.op
[0].type
== RX_Operand_Indirect
297 && opc
.op
[1].type
== RX_Operand_Register
298 && opc
.size
== RX_Long
299 && (opc
.op
[0].reg
== RX_SP_REGNUM
300 || opc
.op
[0].reg
== RX_FP_REGNUM
)
301 && (RX_R1_REGNUM
<= opc
.op
[1].reg
302 && opc
.op
[1].reg
<= RX_R4_REGNUM
))
304 /* This moves an argument register to the stack. Don't
305 record it, but allow it to be a part of the prologue. */
307 else if (opc
.id
== RXO_branch
308 && opc
.op
[0].type
== RX_Operand_Immediate
309 && next_pc
< opc
.op
[0].addend
)
311 /* When a loop appears as the first statement of a function
312 body, gcc 4.x will use a BRA instruction to branch to the
313 loop condition checking code. This BRA instruction is
314 marked as part of the prologue. We therefore set next_pc
315 to this branch target and also stop the prologue scan.
316 The instructions at and beyond the branch target should
317 no longer be associated with the prologue.
319 Note that we only consider forward branches here. We
320 presume that a forward branch is being used to skip over
323 A backwards branch is covered by the default case below.
324 If we were to encounter a backwards branch, that would
325 most likely mean that we've scanned through a loop body.
326 We definitely want to stop the prologue scan when this
327 happens and that is precisely what is done by the default
330 after_last_frame_setup_insn
= opc
.op
[0].addend
;
331 break; /* Scan no further if we hit this case. */
335 /* Terminate the prologue scan. */
342 /* Is the frame size (offset, really) a known constant? */
343 if (pv_is_register (reg
[RX_SP_REGNUM
], RX_SP_REGNUM
))
344 result
->frame_size
= reg
[RX_SP_REGNUM
].k
;
346 /* Was the frame pointer initialized? */
347 if (pv_is_register (reg
[RX_FP_REGNUM
], RX_SP_REGNUM
))
349 result
->has_frame_ptr
= 1;
350 result
->frame_ptr_offset
= reg
[RX_FP_REGNUM
].k
;
353 /* Record where all the registers were saved. */
354 stack
.scan (check_for_saved
, (void *) result
);
356 result
->prologue_end
= after_last_frame_setup_insn
;
360 /* Implement the "skip_prologue" gdbarch method. */
362 rx_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
365 CORE_ADDR func_addr
, func_end
;
366 struct rx_prologue p
;
368 /* Try to find the extent of the function that contains PC. */
369 if (!find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
))
372 /* The frame type doesn't matter here, since we only care about
373 where the prologue ends. We'll use RX_FRAME_TYPE_NORMAL. */
374 rx_analyze_prologue (pc
, func_end
, RX_FRAME_TYPE_NORMAL
, &p
);
375 return p
.prologue_end
;
378 /* Given a frame described by THIS_FRAME, decode the prologue of its
379 associated function if there is not cache entry as specified by
380 THIS_PROLOGUE_CACHE. Save the decoded prologue in the cache and
381 return that struct as the value of this function. */
383 static struct rx_prologue
*
384 rx_analyze_frame_prologue (struct frame_info
*this_frame
,
385 enum rx_frame_type frame_type
,
386 void **this_prologue_cache
)
388 if (!*this_prologue_cache
)
390 CORE_ADDR func_start
, stop_addr
;
392 *this_prologue_cache
= FRAME_OBSTACK_ZALLOC (struct rx_prologue
);
394 func_start
= get_frame_func (this_frame
);
395 stop_addr
= get_frame_pc (this_frame
);
397 /* If we couldn't find any function containing the PC, then
398 just initialize the prologue cache, but don't do anything. */
400 stop_addr
= func_start
;
402 rx_analyze_prologue (func_start
, stop_addr
, frame_type
,
403 (struct rx_prologue
*) *this_prologue_cache
);
406 return (struct rx_prologue
*) *this_prologue_cache
;
409 /* Determine type of frame by scanning the function for a return
412 static enum rx_frame_type
413 rx_frame_type (struct frame_info
*this_frame
, void **this_cache
)
416 CORE_ADDR pc
, start_pc
, lim_pc
;
418 struct rx_get_opcode_byte_handle opcode_handle
;
419 RX_Opcode_Decoded opc
;
421 gdb_assert (this_cache
!= NULL
);
423 /* If we have a cached value, return it. */
425 if (*this_cache
!= NULL
)
427 struct rx_prologue
*p
= (struct rx_prologue
*) *this_cache
;
429 return p
->frame_type
;
432 /* No cached value; scan the function. The frame type is cached in
433 rx_analyze_prologue / rx_analyze_frame_prologue. */
435 pc
= get_frame_pc (this_frame
);
437 /* Attempt to find the last address in the function. If it cannot
438 be determined, set the limit to be a short ways past the frame's
440 if (!find_pc_partial_function (pc
, &name
, &start_pc
, &lim_pc
))
445 opcode_handle
.pc
= pc
;
446 bytes_read
= rx_decode_opcode (pc
, &opc
, rx_get_opcode_byte
,
449 if (bytes_read
<= 0 || opc
.id
== RXO_rts
)
450 return RX_FRAME_TYPE_NORMAL
;
451 else if (opc
.id
== RXO_rtfi
)
452 return RX_FRAME_TYPE_FAST_INTERRUPT
;
453 else if (opc
.id
== RXO_rte
)
454 return RX_FRAME_TYPE_EXCEPTION
;
459 return RX_FRAME_TYPE_NORMAL
;
463 /* Given the next frame and a prologue cache, return this frame's
467 rx_frame_base (struct frame_info
*this_frame
, void **this_cache
)
469 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
470 struct rx_prologue
*p
471 = rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
473 /* In functions that use alloca, the distance between the stack
474 pointer and the frame base varies dynamically, so we can't use
475 the SP plus static information like prologue analysis to find the
476 frame base. However, such functions must have a frame pointer,
477 to be able to restore the SP on exit. So whenever we do have a
478 frame pointer, use that to find the base. */
479 if (p
->has_frame_ptr
)
481 CORE_ADDR fp
= get_frame_register_unsigned (this_frame
, RX_FP_REGNUM
);
482 return fp
- p
->frame_ptr_offset
;
486 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, RX_SP_REGNUM
);
487 return sp
- p
->frame_size
;
491 /* Implement the "frame_this_id" method for unwinding frames. */
494 rx_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
495 struct frame_id
*this_id
)
497 *this_id
= frame_id_build (rx_frame_base (this_frame
, this_cache
),
498 get_frame_func (this_frame
));
501 /* Implement the "frame_prev_register" method for unwinding frames. */
503 static struct value
*
504 rx_frame_prev_register (struct frame_info
*this_frame
, void **this_cache
,
507 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
508 struct rx_prologue
*p
509 = rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
510 CORE_ADDR frame_base
= rx_frame_base (this_frame
, this_cache
);
512 if (regnum
== RX_SP_REGNUM
)
514 if (frame_type
== RX_FRAME_TYPE_EXCEPTION
)
516 struct value
*psw_val
;
519 psw_val
= rx_frame_prev_register (this_frame
, this_cache
,
521 psw
= extract_unsigned_integer (value_contents_all (psw_val
), 4,
523 get_frame_arch (this_frame
)));
525 if ((psw
& 0x20000 /* U bit */) != 0)
526 return rx_frame_prev_register (this_frame
, this_cache
,
529 /* Fall through for the case where U bit is zero. */
532 return frame_unwind_got_constant (this_frame
, regnum
, frame_base
);
535 if (frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
)
537 if (regnum
== RX_PC_REGNUM
)
538 return rx_frame_prev_register (this_frame
, this_cache
,
540 if (regnum
== RX_PSW_REGNUM
)
541 return rx_frame_prev_register (this_frame
, this_cache
,
545 /* If prologue analysis says we saved this register somewhere,
546 return a description of the stack slot holding it. */
547 if (p
->reg_offset
[regnum
] != 1)
548 return frame_unwind_got_memory (this_frame
, regnum
,
549 frame_base
+ p
->reg_offset
[regnum
]);
551 /* Otherwise, presume we haven't changed the value of this
552 register, and get it from the next frame. */
553 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
556 /* Return TRUE if the frame indicated by FRAME_TYPE is a normal frame. */
559 normal_frame_p (enum rx_frame_type frame_type
)
561 return (frame_type
== RX_FRAME_TYPE_NORMAL
);
564 /* Return TRUE if the frame indicated by FRAME_TYPE is an exception
568 exception_frame_p (enum rx_frame_type frame_type
)
570 return (frame_type
== RX_FRAME_TYPE_EXCEPTION
571 || frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
);
574 /* Common code used by both normal and exception frame sniffers. */
577 rx_frame_sniffer_common (const struct frame_unwind
*self
,
578 struct frame_info
*this_frame
,
580 int (*sniff_p
)(enum rx_frame_type
) )
582 gdb_assert (this_cache
!= NULL
);
584 if (*this_cache
== NULL
)
586 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
588 if (sniff_p (frame_type
))
590 /* The call below will fill in the cache, including the frame
592 (void) rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
601 struct rx_prologue
*p
= (struct rx_prologue
*) *this_cache
;
603 return sniff_p (p
->frame_type
);
607 /* Frame sniffer for normal (non-exception) frames. */
610 rx_frame_sniffer (const struct frame_unwind
*self
,
611 struct frame_info
*this_frame
,
614 return rx_frame_sniffer_common (self
, this_frame
, this_cache
,
618 /* Frame sniffer for exception frames. */
621 rx_exception_sniffer (const struct frame_unwind
*self
,
622 struct frame_info
*this_frame
,
625 return rx_frame_sniffer_common (self
, this_frame
, this_cache
,
629 /* Data structure for normal code using instruction-based prologue
632 static const struct frame_unwind rx_frame_unwind
= {
634 default_frame_unwind_stop_reason
,
636 rx_frame_prev_register
,
641 /* Data structure for exception code using instruction-based prologue
644 static const struct frame_unwind rx_exception_unwind
= {
645 /* SIGTRAMP_FRAME could be used here, but backtraces are less informative. */
647 default_frame_unwind_stop_reason
,
649 rx_frame_prev_register
,
654 /* Implement the "push_dummy_call" gdbarch method. */
656 rx_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
657 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
658 struct value
**args
, CORE_ADDR sp
,
659 function_call_return_method return_method
,
660 CORE_ADDR struct_addr
)
662 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
666 int num_register_candidate_args
;
668 struct type
*func_type
= value_type (function
);
670 /* Dereference function pointer types. */
671 while (func_type
->code () == TYPE_CODE_PTR
)
672 func_type
= TYPE_TARGET_TYPE (func_type
);
674 /* The end result had better be a function or a method. */
675 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
676 || func_type
->code () == TYPE_CODE_METHOD
);
678 /* Functions with a variable number of arguments have all of their
679 variable arguments and the last non-variable argument passed
682 Otherwise, we can pass up to four arguments on the stack.
684 Once computed, we leave this value alone. I.e. we don't update
685 it in case of a struct return going in a register or an argument
686 requiring multiple registers, etc. We rely instead on the value
687 of the ``arg_reg'' variable to get these other details correct. */
689 if (TYPE_VARARGS (func_type
))
690 num_register_candidate_args
= func_type
->num_fields () - 1;
692 num_register_candidate_args
= 4;
694 /* We make two passes; the first does the stack allocation,
695 the second actually stores the arguments. */
696 for (write_pass
= 0; write_pass
<= 1; write_pass
++)
699 int arg_reg
= RX_R1_REGNUM
;
702 sp
= align_down (sp
- sp_off
, 4);
705 if (return_method
== return_method_struct
)
707 struct type
*return_type
= TYPE_TARGET_TYPE (func_type
);
709 gdb_assert (return_type
->code () == TYPE_CODE_STRUCT
710 || func_type
->code () == TYPE_CODE_UNION
);
712 if (TYPE_LENGTH (return_type
) > 16
713 || TYPE_LENGTH (return_type
) % 4 != 0)
716 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
721 /* Push the arguments. */
722 for (i
= 0; i
< nargs
; i
++)
724 struct value
*arg
= args
[i
];
725 const gdb_byte
*arg_bits
= value_contents_all (arg
);
726 struct type
*arg_type
= check_typedef (value_type (arg
));
727 ULONGEST arg_size
= TYPE_LENGTH (arg_type
);
729 if (i
== 0 && struct_addr
!= 0
730 && return_method
!= return_method_struct
731 && arg_type
->code () == TYPE_CODE_PTR
732 && extract_unsigned_integer (arg_bits
, 4,
733 byte_order
) == struct_addr
)
735 /* This argument represents the address at which C++ (and
736 possibly other languages) store their return value.
737 Put this value in R15. */
739 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
742 else if (arg_type
->code () != TYPE_CODE_STRUCT
743 && arg_type
->code () != TYPE_CODE_UNION
746 /* Argument is a scalar. */
749 if (i
< num_register_candidate_args
750 && arg_reg
<= RX_R4_REGNUM
- 1)
752 /* If argument registers are going to be used to pass
753 an 8 byte scalar, the ABI specifies that two registers
754 must be available. */
757 regcache_cooked_write_unsigned (regcache
, arg_reg
,
758 extract_unsigned_integer
761 regcache_cooked_write_unsigned (regcache
,
763 extract_unsigned_integer
771 sp_off
= align_up (sp_off
, 4);
772 /* Otherwise, pass the 8 byte scalar on the stack. */
774 write_memory (sp
+ sp_off
, arg_bits
, 8);
782 gdb_assert (arg_size
<= 4);
785 extract_unsigned_integer (arg_bits
, arg_size
, byte_order
);
787 if (i
< num_register_candidate_args
788 && arg_reg
<= RX_R4_REGNUM
)
791 regcache_cooked_write_unsigned (regcache
, arg_reg
, u
);
798 if (TYPE_PROTOTYPED (func_type
)
799 && i
< func_type
->num_fields ())
801 struct type
*p_arg_type
=
802 func_type
->field (i
).type ();
803 p_arg_size
= TYPE_LENGTH (p_arg_type
);
806 sp_off
= align_up (sp_off
, p_arg_size
);
809 write_memory_unsigned_integer (sp
+ sp_off
,
810 p_arg_size
, byte_order
,
812 sp_off
+= p_arg_size
;
818 /* Argument is a struct or union. Pass as much of the struct
819 in registers, if possible. Pass the rest on the stack. */
822 if (i
< num_register_candidate_args
823 && arg_reg
<= RX_R4_REGNUM
824 && arg_size
<= 4 * (RX_R4_REGNUM
- arg_reg
+ 1)
825 && arg_size
% 4 == 0)
827 int len
= std::min (arg_size
, (ULONGEST
) 4);
830 regcache_cooked_write_unsigned (regcache
, arg_reg
,
831 extract_unsigned_integer
840 sp_off
= align_up (sp_off
, 4);
842 write_memory (sp
+ sp_off
, arg_bits
, arg_size
);
843 sp_off
+= align_up (arg_size
, 4);
851 /* Keep track of the stack address prior to pushing the return address.
852 This is the value that we'll return. */
855 /* Push the return address. */
857 write_memory_unsigned_integer (sp
, 4, byte_order
, bp_addr
);
859 /* Update the stack pointer. */
860 regcache_cooked_write_unsigned (regcache
, RX_SP_REGNUM
, sp
);
865 /* Implement the "return_value" gdbarch method. */
866 static enum return_value_convention
867 rx_return_value (struct gdbarch
*gdbarch
,
868 struct value
*function
,
869 struct type
*valtype
,
870 struct regcache
*regcache
,
871 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
873 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
874 ULONGEST valtype_len
= TYPE_LENGTH (valtype
);
876 if (TYPE_LENGTH (valtype
) > 16
877 || ((valtype
->code () == TYPE_CODE_STRUCT
878 || valtype
->code () == TYPE_CODE_UNION
)
879 && TYPE_LENGTH (valtype
) % 4 != 0))
880 return RETURN_VALUE_STRUCT_CONVENTION
;
885 int argreg
= RX_R1_REGNUM
;
888 while (valtype_len
> 0)
890 int len
= std::min (valtype_len
, (ULONGEST
) 4);
892 regcache_cooked_read_unsigned (regcache
, argreg
, &u
);
893 store_unsigned_integer (readbuf
+ offset
, len
, byte_order
, u
);
903 int argreg
= RX_R1_REGNUM
;
906 while (valtype_len
> 0)
908 int len
= std::min (valtype_len
, (ULONGEST
) 4);
910 u
= extract_unsigned_integer (writebuf
+ offset
, len
, byte_order
);
911 regcache_cooked_write_unsigned (regcache
, argreg
, u
);
918 return RETURN_VALUE_REGISTER_CONVENTION
;
921 constexpr gdb_byte rx_break_insn
[] = { 0x00 };
923 typedef BP_MANIPULATION (rx_break_insn
) rx_breakpoint
;
925 /* Implement the dwarf_reg_to_regnum" gdbarch method. */
928 rx_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
930 if (0 <= reg
&& reg
<= 15)
933 return RX_PSW_REGNUM
;
940 /* Allocate and initialize a gdbarch object. */
941 static struct gdbarch
*
942 rx_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
944 struct gdbarch
*gdbarch
;
945 struct gdbarch_tdep
*tdep
;
947 struct tdesc_arch_data
*tdesc_data
= NULL
;
948 const struct target_desc
*tdesc
= info
.target_desc
;
950 /* Extract the elf_flags if available. */
951 if (info
.abfd
!= NULL
952 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
953 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
958 /* Try to find the architecture in the list of already defined
960 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
962 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
964 if (gdbarch_tdep (arches
->gdbarch
)->elf_flags
!= elf_flags
)
967 return arches
->gdbarch
;
973 /* Check any target description for validity. */
974 if (tdesc_has_registers (tdesc
))
976 const struct tdesc_feature
*feature
;
979 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.rx.core");
983 tdesc_data
= tdesc_data_alloc ();
984 for (int i
= 0; i
< RX_NUM_REGS
; i
++)
985 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
, i
,
986 rx_register_names
[i
]);
991 tdesc_data_cleanup (tdesc_data
);
996 gdb_assert(tdesc_data
!= NULL
);
998 tdep
= XCNEW (struct gdbarch_tdep
);
999 gdbarch
= gdbarch_alloc (&info
, tdep
);
1000 tdep
->elf_flags
= elf_flags
;
1002 set_gdbarch_num_regs (gdbarch
, RX_NUM_REGS
);
1003 tdesc_use_registers (gdbarch
, tdesc
, tdesc_data
);
1005 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1006 set_gdbarch_pc_regnum (gdbarch
, RX_PC_REGNUM
);
1007 set_gdbarch_sp_regnum (gdbarch
, RX_SP_REGNUM
);
1008 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1009 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
1010 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, rx_breakpoint::kind_from_pc
);
1011 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, rx_breakpoint::bp_from_kind
);
1012 set_gdbarch_skip_prologue (gdbarch
, rx_skip_prologue
);
1014 /* Target builtin data types. */
1015 set_gdbarch_char_signed (gdbarch
, 0);
1016 set_gdbarch_short_bit (gdbarch
, 16);
1017 set_gdbarch_int_bit (gdbarch
, 32);
1018 set_gdbarch_long_bit (gdbarch
, 32);
1019 set_gdbarch_long_long_bit (gdbarch
, 64);
1020 set_gdbarch_ptr_bit (gdbarch
, 32);
1021 set_gdbarch_float_bit (gdbarch
, 32);
1022 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
1024 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
1026 set_gdbarch_double_bit (gdbarch
, 64);
1027 set_gdbarch_long_double_bit (gdbarch
, 64);
1028 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
1029 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
1033 set_gdbarch_double_bit (gdbarch
, 32);
1034 set_gdbarch_long_double_bit (gdbarch
, 32);
1035 set_gdbarch_double_format (gdbarch
, floatformats_ieee_single
);
1036 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_single
);
1039 /* DWARF register mapping. */
1040 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, rx_dwarf_reg_to_regnum
);
1042 /* Frame unwinding. */
1043 frame_unwind_append_unwinder (gdbarch
, &rx_exception_unwind
);
1044 dwarf2_append_unwinders (gdbarch
);
1045 frame_unwind_append_unwinder (gdbarch
, &rx_frame_unwind
);
1047 /* Methods setting up a dummy call, and extracting the return value from
1049 set_gdbarch_push_dummy_call (gdbarch
, rx_push_dummy_call
);
1050 set_gdbarch_return_value (gdbarch
, rx_return_value
);
1052 /* Virtual tables. */
1053 set_gdbarch_vbit_in_delta (gdbarch
, 1);
1058 /* Register the above initialization routine. */
1060 void _initialize_rx_tdep ();
1062 _initialize_rx_tdep ()
1064 register_gdbarch_init (bfd_arch_rx
, rx_gdbarch_init
);
1065 initialize_tdesc_rx ();