1 /* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
3 Copyright (C) 2008-2024 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/>. */
22 #include "arch-utils.h"
23 #include "extract-store-integer.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"
45 #include "features/rx.c"
47 /* Certain important register numbers. */
68 RX_FRAME_TYPE_EXCEPTION
,
69 RX_FRAME_TYPE_FAST_INTERRUPT
72 /* Architecture specific data. */
73 struct rx_gdbarch_tdep
: gdbarch_tdep_base
75 /* The ELF header flags specify the multilib used. */
78 /* Type of PSW and BPSW. */
79 struct type
*rx_psw_type
= nullptr;
82 struct type
*rx_fpsw_type
= nullptr;
85 /* This structure holds the results of a prologue analysis. */
88 /* Frame type, either a normal frame or one of two types of exception
90 enum rx_frame_type frame_type
;
92 /* The offset from the frame base to the stack pointer --- always
95 Calling this a "size" is a bit misleading, but given that the
96 stack grows downwards, using offsets for everything keeps one
97 from going completely sign-crazy: you never change anything's
98 sign for an ADD instruction; always change the second operand's
99 sign for a SUB instruction; and everything takes care of
103 /* Non-zero if this function has initialized the frame pointer from
104 the stack pointer, zero otherwise. */
107 /* If has_frame_ptr is non-zero, this is the offset from the frame
108 base to where the frame pointer points. This is always zero or
110 int frame_ptr_offset
;
112 /* The address of the first instruction at which the frame has been
113 set up and the arguments are where the debug info says they are
114 --- as best as we can tell. */
115 CORE_ADDR prologue_end
;
117 /* reg_offset[R] is the offset from the CFA at which register R is
118 saved, or 1 if register R has not been saved. (Real values are
119 always zero or negative.) */
120 int reg_offset
[RX_NUM_REGS
];
123 /* RX register names */
124 static const char *const rx_register_names
[] = {
125 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
126 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
127 "usp", "isp", "psw", "pc", "intb", "bpsw","bpc","fintv",
132 /* Function for finding saved registers in a 'struct pv_area'; this
133 function is passed to pv_area::scan.
135 If VALUE is a saved register, ADDR says it was saved at a constant
136 offset from the frame base, and SIZE indicates that the whole
137 register was saved, record its offset. */
139 check_for_saved (void *result_untyped
, pv_t addr
, CORE_ADDR size
, pv_t value
)
141 struct rx_prologue
*result
= (struct rx_prologue
*) result_untyped
;
143 if (value
.kind
== pvk_register
145 && pv_is_register (addr
, RX_SP_REGNUM
)
146 && size
== register_size (current_inferior ()->arch (), value
.reg
))
147 result
->reg_offset
[value
.reg
] = addr
.k
;
150 /* Define a "handle" struct for fetching the next opcode. */
151 struct rx_get_opcode_byte_handle
156 /* Fetch a byte on behalf of the opcode decoder. HANDLE contains
157 the memory address of the next byte to fetch. If successful,
158 the address in the handle is updated and the byte fetched is
159 returned as the value of the function. If not successful, -1
162 rx_get_opcode_byte (void *handle
)
164 struct rx_get_opcode_byte_handle
*opcdata
165 = (struct rx_get_opcode_byte_handle
*) handle
;
169 status
= target_read_code (opcdata
->pc
, &byte
, 1);
179 /* Analyze a prologue starting at START_PC, going no further than
180 LIMIT_PC. Fill in RESULT as appropriate. */
183 rx_analyze_prologue (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
184 enum rx_frame_type frame_type
,
185 struct rx_prologue
*result
)
187 CORE_ADDR pc
, next_pc
;
189 pv_t reg
[RX_NUM_REGS
];
190 CORE_ADDR after_last_frame_setup_insn
= start_pc
;
192 memset (result
, 0, sizeof (*result
));
194 result
->frame_type
= frame_type
;
196 for (rn
= 0; rn
< RX_NUM_REGS
; rn
++)
198 reg
[rn
] = pv_register (rn
, 0);
199 result
->reg_offset
[rn
] = 1;
202 pv_area
stack (RX_SP_REGNUM
, gdbarch_addr_bit (current_inferior ()->arch ()));
204 if (frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
)
206 /* This code won't do anything useful at present, but this is
207 what happens for fast interrupts. */
208 reg
[RX_BPSW_REGNUM
] = reg
[RX_PSW_REGNUM
];
209 reg
[RX_BPC_REGNUM
] = reg
[RX_PC_REGNUM
];
213 /* When an exception occurs, the PSW is saved to the interrupt stack
215 if (frame_type
== RX_FRAME_TYPE_EXCEPTION
)
217 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
218 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[RX_PSW_REGNUM
]);
221 /* The call instruction (or an exception/interrupt) has saved the return
222 address on the stack. */
223 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
224 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[RX_PC_REGNUM
]);
230 while (pc
< limit_pc
)
233 struct rx_get_opcode_byte_handle opcode_handle
;
234 RX_Opcode_Decoded opc
;
236 opcode_handle
.pc
= pc
;
237 bytes_read
= rx_decode_opcode (pc
, &opc
, rx_get_opcode_byte
,
239 next_pc
= pc
+ bytes_read
;
241 if (opc
.id
== RXO_pushm
/* pushm r1, r2 */
242 && opc
.op
[1].type
== RX_Operand_Register
243 && opc
.op
[2].type
== RX_Operand_Register
)
250 for (r
= r2
; r
>= r1
; r
--)
252 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
253 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[r
]);
255 after_last_frame_setup_insn
= next_pc
;
257 else if (opc
.id
== RXO_mov
/* mov.l rdst, rsrc */
258 && opc
.op
[0].type
== RX_Operand_Register
259 && opc
.op
[1].type
== RX_Operand_Register
260 && opc
.size
== RX_Long
)
264 rdst
= opc
.op
[0].reg
;
265 rsrc
= opc
.op
[1].reg
;
266 reg
[rdst
] = reg
[rsrc
];
267 if (rdst
== RX_FP_REGNUM
&& rsrc
== RX_SP_REGNUM
)
268 after_last_frame_setup_insn
= next_pc
;
270 else if (opc
.id
== RXO_mov
/* mov.l rsrc, [-SP] */
271 && opc
.op
[0].type
== RX_Operand_Predec
272 && opc
.op
[0].reg
== RX_SP_REGNUM
273 && opc
.op
[1].type
== RX_Operand_Register
274 && opc
.size
== RX_Long
)
278 rsrc
= opc
.op
[1].reg
;
279 reg
[RX_SP_REGNUM
] = pv_add_constant (reg
[RX_SP_REGNUM
], -4);
280 stack
.store (reg
[RX_SP_REGNUM
], 4, reg
[rsrc
]);
281 after_last_frame_setup_insn
= next_pc
;
283 else if (opc
.id
== RXO_add
/* add #const, rsrc, rdst */
284 && opc
.op
[0].type
== RX_Operand_Register
285 && opc
.op
[1].type
== RX_Operand_Immediate
286 && opc
.op
[2].type
== RX_Operand_Register
)
288 int rdst
= opc
.op
[0].reg
;
289 int addend
= opc
.op
[1].addend
;
290 int rsrc
= opc
.op
[2].reg
;
291 reg
[rdst
] = pv_add_constant (reg
[rsrc
], addend
);
292 /* Negative adjustments to the stack pointer or frame pointer
293 are (most likely) part of the prologue. */
294 if ((rdst
== RX_SP_REGNUM
|| rdst
== RX_FP_REGNUM
) && addend
< 0)
295 after_last_frame_setup_insn
= next_pc
;
297 else if (opc
.id
== RXO_mov
298 && opc
.op
[0].type
== RX_Operand_Indirect
299 && opc
.op
[1].type
== RX_Operand_Register
300 && opc
.size
== RX_Long
301 && (opc
.op
[0].reg
== RX_SP_REGNUM
302 || opc
.op
[0].reg
== RX_FP_REGNUM
)
303 && (RX_R1_REGNUM
<= opc
.op
[1].reg
304 && opc
.op
[1].reg
<= RX_R4_REGNUM
))
306 /* This moves an argument register to the stack. Don't
307 record it, but allow it to be a part of the prologue. */
309 else if (opc
.id
== RXO_branch
310 && opc
.op
[0].type
== RX_Operand_Immediate
311 && next_pc
< opc
.op
[0].addend
)
313 /* When a loop appears as the first statement of a function
314 body, gcc 4.x will use a BRA instruction to branch to the
315 loop condition checking code. This BRA instruction is
316 marked as part of the prologue. We therefore set next_pc
317 to this branch target and also stop the prologue scan.
318 The instructions at and beyond the branch target should
319 no longer be associated with the prologue.
321 Note that we only consider forward branches here. We
322 presume that a forward branch is being used to skip over
325 A backwards branch is covered by the default case below.
326 If we were to encounter a backwards branch, that would
327 most likely mean that we've scanned through a loop body.
328 We definitely want to stop the prologue scan when this
329 happens and that is precisely what is done by the default
332 after_last_frame_setup_insn
= opc
.op
[0].addend
;
333 break; /* Scan no further if we hit this case. */
337 /* Terminate the prologue scan. */
344 /* Is the frame size (offset, really) a known constant? */
345 if (pv_is_register (reg
[RX_SP_REGNUM
], RX_SP_REGNUM
))
346 result
->frame_size
= reg
[RX_SP_REGNUM
].k
;
348 /* Was the frame pointer initialized? */
349 if (pv_is_register (reg
[RX_FP_REGNUM
], RX_SP_REGNUM
))
351 result
->has_frame_ptr
= 1;
352 result
->frame_ptr_offset
= reg
[RX_FP_REGNUM
].k
;
355 /* Record where all the registers were saved. */
356 stack
.scan (check_for_saved
, (void *) result
);
358 result
->prologue_end
= after_last_frame_setup_insn
;
362 /* Implement the "skip_prologue" gdbarch method. */
364 rx_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
367 CORE_ADDR func_addr
, func_end
;
368 struct rx_prologue p
;
370 /* Try to find the extent of the function that contains PC. */
371 if (!find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
))
374 /* The frame type doesn't matter here, since we only care about
375 where the prologue ends. We'll use RX_FRAME_TYPE_NORMAL. */
376 rx_analyze_prologue (pc
, func_end
, RX_FRAME_TYPE_NORMAL
, &p
);
377 return p
.prologue_end
;
380 /* Given a frame described by THIS_FRAME, decode the prologue of its
381 associated function if there is not cache entry as specified by
382 THIS_PROLOGUE_CACHE. Save the decoded prologue in the cache and
383 return that struct as the value of this function. */
385 static struct rx_prologue
*
386 rx_analyze_frame_prologue (const frame_info_ptr
&this_frame
,
387 enum rx_frame_type frame_type
,
388 void **this_prologue_cache
)
390 if (!*this_prologue_cache
)
392 CORE_ADDR func_start
, stop_addr
;
394 *this_prologue_cache
= FRAME_OBSTACK_ZALLOC (struct rx_prologue
);
396 func_start
= get_frame_func (this_frame
);
397 stop_addr
= get_frame_pc (this_frame
);
399 /* If we couldn't find any function containing the PC, then
400 just initialize the prologue cache, but don't do anything. */
402 stop_addr
= func_start
;
404 rx_analyze_prologue (func_start
, stop_addr
, frame_type
,
405 (struct rx_prologue
*) *this_prologue_cache
);
408 return (struct rx_prologue
*) *this_prologue_cache
;
411 /* Determine type of frame by scanning the function for a return
414 static enum rx_frame_type
415 rx_frame_type (const frame_info_ptr
&this_frame
, void **this_cache
)
418 CORE_ADDR pc
, start_pc
, lim_pc
;
420 struct rx_get_opcode_byte_handle opcode_handle
;
421 RX_Opcode_Decoded opc
;
423 gdb_assert (this_cache
!= NULL
);
425 /* If we have a cached value, return it. */
427 if (*this_cache
!= NULL
)
429 struct rx_prologue
*p
= (struct rx_prologue
*) *this_cache
;
431 return p
->frame_type
;
434 /* No cached value; scan the function. The frame type is cached in
435 rx_analyze_prologue / rx_analyze_frame_prologue. */
437 pc
= get_frame_pc (this_frame
);
439 /* Attempt to find the last address in the function. If it cannot
440 be determined, set the limit to be a short ways past the frame's
442 if (!find_pc_partial_function (pc
, &name
, &start_pc
, &lim_pc
))
447 opcode_handle
.pc
= pc
;
448 bytes_read
= rx_decode_opcode (pc
, &opc
, rx_get_opcode_byte
,
451 if (bytes_read
<= 0 || opc
.id
== RXO_rts
)
452 return RX_FRAME_TYPE_NORMAL
;
453 else if (opc
.id
== RXO_rtfi
)
454 return RX_FRAME_TYPE_FAST_INTERRUPT
;
455 else if (opc
.id
== RXO_rte
)
456 return RX_FRAME_TYPE_EXCEPTION
;
461 return RX_FRAME_TYPE_NORMAL
;
465 /* Given the next frame and a prologue cache, return this frame's
469 rx_frame_base (const frame_info_ptr
&this_frame
, void **this_cache
)
471 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
472 struct rx_prologue
*p
473 = rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
475 /* In functions that use alloca, the distance between the stack
476 pointer and the frame base varies dynamically, so we can't use
477 the SP plus static information like prologue analysis to find the
478 frame base. However, such functions must have a frame pointer,
479 to be able to restore the SP on exit. So whenever we do have a
480 frame pointer, use that to find the base. */
481 if (p
->has_frame_ptr
)
483 CORE_ADDR fp
= get_frame_register_unsigned (this_frame
, RX_FP_REGNUM
);
484 return fp
- p
->frame_ptr_offset
;
488 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, RX_SP_REGNUM
);
489 return sp
- p
->frame_size
;
493 /* Implement the "frame_this_id" method for unwinding frames. */
496 rx_frame_this_id (const frame_info_ptr
&this_frame
, void **this_cache
,
497 struct frame_id
*this_id
)
499 *this_id
= frame_id_build (rx_frame_base (this_frame
, this_cache
),
500 get_frame_func (this_frame
));
503 /* Implement the "frame_prev_register" method for unwinding frames. */
505 static struct value
*
506 rx_frame_prev_register (const frame_info_ptr
&this_frame
, void **this_cache
,
509 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
510 struct rx_prologue
*p
511 = rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
512 CORE_ADDR frame_base
= rx_frame_base (this_frame
, this_cache
);
514 if (regnum
== RX_SP_REGNUM
)
516 if (frame_type
== RX_FRAME_TYPE_EXCEPTION
)
518 struct value
*psw_val
;
521 psw_val
= rx_frame_prev_register (this_frame
, this_cache
,
523 psw
= extract_unsigned_integer
524 (psw_val
->contents_all ().data (), 4,
525 gdbarch_byte_order (get_frame_arch (this_frame
)));
527 if ((psw
& 0x20000 /* U bit */) != 0)
528 return rx_frame_prev_register (this_frame
, this_cache
,
531 /* Fall through for the case where U bit is zero. */
534 return frame_unwind_got_constant (this_frame
, regnum
, frame_base
);
537 if (frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
)
539 if (regnum
== RX_PC_REGNUM
)
540 return rx_frame_prev_register (this_frame
, this_cache
,
542 if (regnum
== RX_PSW_REGNUM
)
543 return rx_frame_prev_register (this_frame
, this_cache
,
547 /* If prologue analysis says we saved this register somewhere,
548 return a description of the stack slot holding it. */
549 if (p
->reg_offset
[regnum
] != 1)
550 return frame_unwind_got_memory (this_frame
, regnum
,
551 frame_base
+ p
->reg_offset
[regnum
]);
553 /* Otherwise, presume we haven't changed the value of this
554 register, and get it from the next frame. */
555 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
558 /* Return TRUE if the frame indicated by FRAME_TYPE is a normal frame. */
561 normal_frame_p (enum rx_frame_type frame_type
)
563 return (frame_type
== RX_FRAME_TYPE_NORMAL
);
566 /* Return TRUE if the frame indicated by FRAME_TYPE is an exception
570 exception_frame_p (enum rx_frame_type frame_type
)
572 return (frame_type
== RX_FRAME_TYPE_EXCEPTION
573 || frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
);
576 /* Common code used by both normal and exception frame sniffers. */
579 rx_frame_sniffer_common (const struct frame_unwind
*self
,
580 const frame_info_ptr
&this_frame
,
582 int (*sniff_p
)(enum rx_frame_type
) )
584 gdb_assert (this_cache
!= NULL
);
586 if (*this_cache
== NULL
)
588 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
590 if (sniff_p (frame_type
))
592 /* The call below will fill in the cache, including the frame
594 (void) rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
603 struct rx_prologue
*p
= (struct rx_prologue
*) *this_cache
;
605 return sniff_p (p
->frame_type
);
609 /* Frame sniffer for normal (non-exception) frames. */
612 rx_frame_sniffer (const struct frame_unwind
*self
,
613 const frame_info_ptr
&this_frame
,
616 return rx_frame_sniffer_common (self
, this_frame
, this_cache
,
620 /* Frame sniffer for exception frames. */
623 rx_exception_sniffer (const struct frame_unwind
*self
,
624 const frame_info_ptr
&this_frame
,
627 return rx_frame_sniffer_common (self
, this_frame
, this_cache
,
631 /* Data structure for normal code using instruction-based prologue
634 static const struct frame_unwind rx_frame_unwind
= {
637 default_frame_unwind_stop_reason
,
639 rx_frame_prev_register
,
644 /* Data structure for exception code using instruction-based prologue
647 static const struct frame_unwind rx_exception_unwind
= {
649 /* SIGTRAMP_FRAME could be used here, but backtraces are less informative. */
651 default_frame_unwind_stop_reason
,
653 rx_frame_prev_register
,
658 /* Implement the "push_dummy_call" gdbarch method. */
660 rx_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
661 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
662 struct value
**args
, CORE_ADDR sp
,
663 function_call_return_method return_method
,
664 CORE_ADDR struct_addr
)
666 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
670 int num_register_candidate_args
;
672 struct type
*func_type
= function
->type ();
674 /* Dereference function pointer types. */
675 while (func_type
->code () == TYPE_CODE_PTR
)
676 func_type
= func_type
->target_type ();
678 /* The end result had better be a function or a method. */
679 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
680 || func_type
->code () == TYPE_CODE_METHOD
);
682 /* Functions with a variable number of arguments have all of their
683 variable arguments and the last non-variable argument passed
686 Otherwise, we can pass up to four arguments on the stack.
688 Once computed, we leave this value alone. I.e. we don't update
689 it in case of a struct return going in a register or an argument
690 requiring multiple registers, etc. We rely instead on the value
691 of the ``arg_reg'' variable to get these other details correct. */
693 if (func_type
->has_varargs ())
694 num_register_candidate_args
= func_type
->num_fields () - 1;
696 num_register_candidate_args
= 4;
698 /* We make two passes; the first does the stack allocation,
699 the second actually stores the arguments. */
700 for (write_pass
= 0; write_pass
<= 1; write_pass
++)
703 int arg_reg
= RX_R1_REGNUM
;
706 sp
= align_down (sp
- sp_off
, 4);
709 if (return_method
== return_method_struct
)
711 struct type
*return_type
= func_type
->target_type ();
713 gdb_assert (return_type
->code () == TYPE_CODE_STRUCT
714 || func_type
->code () == TYPE_CODE_UNION
);
716 if (return_type
->length () > 16
717 || return_type
->length () % 4 != 0)
720 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
725 /* Push the arguments. */
726 for (i
= 0; i
< nargs
; i
++)
728 struct value
*arg
= args
[i
];
729 const gdb_byte
*arg_bits
= arg
->contents_all ().data ();
730 struct type
*arg_type
= check_typedef (arg
->type ());
731 ULONGEST arg_size
= arg_type
->length ();
733 if (i
== 0 && struct_addr
!= 0
734 && return_method
!= return_method_struct
735 && arg_type
->code () == TYPE_CODE_PTR
736 && extract_unsigned_integer (arg_bits
, 4,
737 byte_order
) == struct_addr
)
739 /* This argument represents the address at which C++ (and
740 possibly other languages) store their return value.
741 Put this value in R15. */
743 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
746 else if (arg_type
->code () != TYPE_CODE_STRUCT
747 && arg_type
->code () != TYPE_CODE_UNION
750 /* Argument is a scalar. */
753 if (i
< num_register_candidate_args
754 && arg_reg
<= RX_R4_REGNUM
- 1)
756 /* If argument registers are going to be used to pass
757 an 8 byte scalar, the ABI specifies that two registers
758 must be available. */
761 regcache_cooked_write_unsigned (regcache
, arg_reg
,
762 extract_unsigned_integer
765 regcache_cooked_write_unsigned (regcache
,
767 extract_unsigned_integer
775 sp_off
= align_up (sp_off
, 4);
776 /* Otherwise, pass the 8 byte scalar on the stack. */
778 write_memory (sp
+ sp_off
, arg_bits
, 8);
786 gdb_assert (arg_size
<= 4);
789 extract_unsigned_integer (arg_bits
, arg_size
, byte_order
);
791 if (i
< num_register_candidate_args
792 && arg_reg
<= RX_R4_REGNUM
)
795 regcache_cooked_write_unsigned (regcache
, arg_reg
, u
);
802 if (func_type
->is_prototyped ()
803 && i
< func_type
->num_fields ())
805 struct type
*p_arg_type
=
806 func_type
->field (i
).type ();
807 p_arg_size
= p_arg_type
->length ();
810 sp_off
= align_up (sp_off
, p_arg_size
);
813 write_memory_unsigned_integer (sp
+ sp_off
,
814 p_arg_size
, byte_order
,
816 sp_off
+= p_arg_size
;
822 /* Argument is a struct or union. Pass as much of the struct
823 in registers, if possible. Pass the rest on the stack. */
826 if (i
< num_register_candidate_args
827 && arg_reg
<= RX_R4_REGNUM
828 && arg_size
<= 4 * (RX_R4_REGNUM
- arg_reg
+ 1)
829 && arg_size
% 4 == 0)
831 int len
= std::min (arg_size
, (ULONGEST
) 4);
834 regcache_cooked_write_unsigned (regcache
, arg_reg
,
835 extract_unsigned_integer
844 sp_off
= align_up (sp_off
, 4);
846 write_memory (sp
+ sp_off
, arg_bits
, arg_size
);
847 sp_off
+= align_up (arg_size
, 4);
855 /* Keep track of the stack address prior to pushing the return address.
856 This is the value that we'll return. */
859 /* Push the return address. */
861 write_memory_unsigned_integer (sp
, 4, byte_order
, bp_addr
);
863 /* Update the stack pointer. */
864 regcache_cooked_write_unsigned (regcache
, RX_SP_REGNUM
, sp
);
869 /* Implement the "return_value" gdbarch method. */
870 static enum return_value_convention
871 rx_return_value (struct gdbarch
*gdbarch
,
872 struct value
*function
,
873 struct type
*valtype
,
874 struct regcache
*regcache
,
875 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
877 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
878 ULONGEST valtype_len
= valtype
->length ();
880 if (valtype
->length () > 16
881 || ((valtype
->code () == TYPE_CODE_STRUCT
882 || valtype
->code () == TYPE_CODE_UNION
)
883 && valtype
->length () % 4 != 0))
884 return RETURN_VALUE_STRUCT_CONVENTION
;
889 int argreg
= RX_R1_REGNUM
;
892 while (valtype_len
> 0)
894 int len
= std::min (valtype_len
, (ULONGEST
) 4);
896 regcache_cooked_read_unsigned (regcache
, argreg
, &u
);
897 store_unsigned_integer (readbuf
+ offset
, len
, byte_order
, u
);
907 int argreg
= RX_R1_REGNUM
;
910 while (valtype_len
> 0)
912 int len
= std::min (valtype_len
, (ULONGEST
) 4);
914 u
= extract_unsigned_integer (writebuf
+ offset
, len
, byte_order
);
915 regcache_cooked_write_unsigned (regcache
, argreg
, u
);
922 return RETURN_VALUE_REGISTER_CONVENTION
;
925 constexpr gdb_byte rx_break_insn
[] = { 0x00 };
927 typedef BP_MANIPULATION (rx_break_insn
) rx_breakpoint
;
929 /* Implement the dwarf_reg_to_regnum" gdbarch method. */
932 rx_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
934 if (0 <= reg
&& reg
<= 15)
937 return RX_PSW_REGNUM
;
944 /* Allocate and initialize a gdbarch object. */
945 static struct gdbarch
*
946 rx_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
949 tdesc_arch_data_up tdesc_data
;
950 const struct target_desc
*tdesc
= info
.target_desc
;
952 /* Extract the elf_flags if available. */
953 if (info
.abfd
!= NULL
954 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
955 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
960 /* Try to find the architecture in the list of already defined
962 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
964 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
966 rx_gdbarch_tdep
*tdep
967 = gdbarch_tdep
<rx_gdbarch_tdep
> (arches
->gdbarch
);
969 if (tdep
->elf_flags
!= elf_flags
)
972 return arches
->gdbarch
;
978 /* Check any target description for validity. */
979 if (tdesc_has_registers (tdesc
))
981 const struct tdesc_feature
*feature
;
984 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.rx.core");
988 tdesc_data
= tdesc_data_alloc ();
989 for (int i
= 0; i
< RX_NUM_REGS
; i
++)
990 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
991 rx_register_names
[i
]);
998 gdb_assert(tdesc_data
!= NULL
);
1001 = gdbarch_alloc (&info
, gdbarch_tdep_up (new rx_gdbarch_tdep
));
1002 rx_gdbarch_tdep
*tdep
= gdbarch_tdep
<rx_gdbarch_tdep
> (gdbarch
);
1004 tdep
->elf_flags
= elf_flags
;
1006 set_gdbarch_num_regs (gdbarch
, RX_NUM_REGS
);
1007 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
1009 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1010 set_gdbarch_pc_regnum (gdbarch
, RX_PC_REGNUM
);
1011 set_gdbarch_sp_regnum (gdbarch
, RX_SP_REGNUM
);
1012 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1013 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
1014 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, rx_breakpoint::kind_from_pc
);
1015 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, rx_breakpoint::bp_from_kind
);
1016 set_gdbarch_skip_prologue (gdbarch
, rx_skip_prologue
);
1018 /* Target builtin data types. */
1019 set_gdbarch_char_signed (gdbarch
, 0);
1020 set_gdbarch_short_bit (gdbarch
, 16);
1021 set_gdbarch_int_bit (gdbarch
, 32);
1022 set_gdbarch_long_bit (gdbarch
, 32);
1023 set_gdbarch_long_long_bit (gdbarch
, 64);
1024 set_gdbarch_ptr_bit (gdbarch
, 32);
1025 set_gdbarch_float_bit (gdbarch
, 32);
1026 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
1028 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
1030 set_gdbarch_double_bit (gdbarch
, 64);
1031 set_gdbarch_long_double_bit (gdbarch
, 64);
1032 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
1033 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
1037 set_gdbarch_double_bit (gdbarch
, 32);
1038 set_gdbarch_long_double_bit (gdbarch
, 32);
1039 set_gdbarch_double_format (gdbarch
, floatformats_ieee_single
);
1040 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_single
);
1043 /* DWARF register mapping. */
1044 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, rx_dwarf_reg_to_regnum
);
1046 /* Frame unwinding. */
1047 frame_unwind_append_unwinder (gdbarch
, &rx_exception_unwind
);
1048 dwarf2_append_unwinders (gdbarch
);
1049 frame_unwind_append_unwinder (gdbarch
, &rx_frame_unwind
);
1051 /* Methods setting up a dummy call, and extracting the return value from
1053 set_gdbarch_push_dummy_call (gdbarch
, rx_push_dummy_call
);
1054 set_gdbarch_return_value (gdbarch
, rx_return_value
);
1056 /* Virtual tables. */
1057 set_gdbarch_vbit_in_delta (gdbarch
, 1);
1062 /* Register the above initialization routine. */
1064 void _initialize_rx_tdep ();
1066 _initialize_rx_tdep ()
1068 gdbarch_register (bfd_arch_rx
, rx_gdbarch_init
);
1069 initialize_tdesc_rx ();