1 /* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
3 Copyright (C) 2008-2021 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
= {
635 default_frame_unwind_stop_reason
,
637 rx_frame_prev_register
,
642 /* Data structure for exception code using instruction-based prologue
645 static const struct frame_unwind rx_exception_unwind
= {
647 /* SIGTRAMP_FRAME could be used here, but backtraces are less informative. */
649 default_frame_unwind_stop_reason
,
651 rx_frame_prev_register
,
656 /* Implement the "push_dummy_call" gdbarch method. */
658 rx_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
659 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
660 struct value
**args
, CORE_ADDR sp
,
661 function_call_return_method return_method
,
662 CORE_ADDR struct_addr
)
664 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
668 int num_register_candidate_args
;
670 struct type
*func_type
= value_type (function
);
672 /* Dereference function pointer types. */
673 while (func_type
->code () == TYPE_CODE_PTR
)
674 func_type
= TYPE_TARGET_TYPE (func_type
);
676 /* The end result had better be a function or a method. */
677 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
678 || func_type
->code () == TYPE_CODE_METHOD
);
680 /* Functions with a variable number of arguments have all of their
681 variable arguments and the last non-variable argument passed
684 Otherwise, we can pass up to four arguments on the stack.
686 Once computed, we leave this value alone. I.e. we don't update
687 it in case of a struct return going in a register or an argument
688 requiring multiple registers, etc. We rely instead on the value
689 of the ``arg_reg'' variable to get these other details correct. */
691 if (func_type
->has_varargs ())
692 num_register_candidate_args
= func_type
->num_fields () - 1;
694 num_register_candidate_args
= 4;
696 /* We make two passes; the first does the stack allocation,
697 the second actually stores the arguments. */
698 for (write_pass
= 0; write_pass
<= 1; write_pass
++)
701 int arg_reg
= RX_R1_REGNUM
;
704 sp
= align_down (sp
- sp_off
, 4);
707 if (return_method
== return_method_struct
)
709 struct type
*return_type
= TYPE_TARGET_TYPE (func_type
);
711 gdb_assert (return_type
->code () == TYPE_CODE_STRUCT
712 || func_type
->code () == TYPE_CODE_UNION
);
714 if (TYPE_LENGTH (return_type
) > 16
715 || TYPE_LENGTH (return_type
) % 4 != 0)
718 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
723 /* Push the arguments. */
724 for (i
= 0; i
< nargs
; i
++)
726 struct value
*arg
= args
[i
];
727 const gdb_byte
*arg_bits
= value_contents_all (arg
);
728 struct type
*arg_type
= check_typedef (value_type (arg
));
729 ULONGEST arg_size
= TYPE_LENGTH (arg_type
);
731 if (i
== 0 && struct_addr
!= 0
732 && return_method
!= return_method_struct
733 && arg_type
->code () == TYPE_CODE_PTR
734 && extract_unsigned_integer (arg_bits
, 4,
735 byte_order
) == struct_addr
)
737 /* This argument represents the address at which C++ (and
738 possibly other languages) store their return value.
739 Put this value in R15. */
741 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
744 else if (arg_type
->code () != TYPE_CODE_STRUCT
745 && arg_type
->code () != TYPE_CODE_UNION
748 /* Argument is a scalar. */
751 if (i
< num_register_candidate_args
752 && arg_reg
<= RX_R4_REGNUM
- 1)
754 /* If argument registers are going to be used to pass
755 an 8 byte scalar, the ABI specifies that two registers
756 must be available. */
759 regcache_cooked_write_unsigned (regcache
, arg_reg
,
760 extract_unsigned_integer
763 regcache_cooked_write_unsigned (regcache
,
765 extract_unsigned_integer
773 sp_off
= align_up (sp_off
, 4);
774 /* Otherwise, pass the 8 byte scalar on the stack. */
776 write_memory (sp
+ sp_off
, arg_bits
, 8);
784 gdb_assert (arg_size
<= 4);
787 extract_unsigned_integer (arg_bits
, arg_size
, byte_order
);
789 if (i
< num_register_candidate_args
790 && arg_reg
<= RX_R4_REGNUM
)
793 regcache_cooked_write_unsigned (regcache
, arg_reg
, u
);
800 if (func_type
->is_prototyped ()
801 && i
< func_type
->num_fields ())
803 struct type
*p_arg_type
=
804 func_type
->field (i
).type ();
805 p_arg_size
= TYPE_LENGTH (p_arg_type
);
808 sp_off
= align_up (sp_off
, p_arg_size
);
811 write_memory_unsigned_integer (sp
+ sp_off
,
812 p_arg_size
, byte_order
,
814 sp_off
+= p_arg_size
;
820 /* Argument is a struct or union. Pass as much of the struct
821 in registers, if possible. Pass the rest on the stack. */
824 if (i
< num_register_candidate_args
825 && arg_reg
<= RX_R4_REGNUM
826 && arg_size
<= 4 * (RX_R4_REGNUM
- arg_reg
+ 1)
827 && arg_size
% 4 == 0)
829 int len
= std::min (arg_size
, (ULONGEST
) 4);
832 regcache_cooked_write_unsigned (regcache
, arg_reg
,
833 extract_unsigned_integer
842 sp_off
= align_up (sp_off
, 4);
844 write_memory (sp
+ sp_off
, arg_bits
, arg_size
);
845 sp_off
+= align_up (arg_size
, 4);
853 /* Keep track of the stack address prior to pushing the return address.
854 This is the value that we'll return. */
857 /* Push the return address. */
859 write_memory_unsigned_integer (sp
, 4, byte_order
, bp_addr
);
861 /* Update the stack pointer. */
862 regcache_cooked_write_unsigned (regcache
, RX_SP_REGNUM
, sp
);
867 /* Implement the "return_value" gdbarch method. */
868 static enum return_value_convention
869 rx_return_value (struct gdbarch
*gdbarch
,
870 struct value
*function
,
871 struct type
*valtype
,
872 struct regcache
*regcache
,
873 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
875 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
876 ULONGEST valtype_len
= TYPE_LENGTH (valtype
);
878 if (TYPE_LENGTH (valtype
) > 16
879 || ((valtype
->code () == TYPE_CODE_STRUCT
880 || valtype
->code () == TYPE_CODE_UNION
)
881 && TYPE_LENGTH (valtype
) % 4 != 0))
882 return RETURN_VALUE_STRUCT_CONVENTION
;
887 int argreg
= RX_R1_REGNUM
;
890 while (valtype_len
> 0)
892 int len
= std::min (valtype_len
, (ULONGEST
) 4);
894 regcache_cooked_read_unsigned (regcache
, argreg
, &u
);
895 store_unsigned_integer (readbuf
+ offset
, len
, byte_order
, u
);
905 int argreg
= RX_R1_REGNUM
;
908 while (valtype_len
> 0)
910 int len
= std::min (valtype_len
, (ULONGEST
) 4);
912 u
= extract_unsigned_integer (writebuf
+ offset
, len
, byte_order
);
913 regcache_cooked_write_unsigned (regcache
, argreg
, u
);
920 return RETURN_VALUE_REGISTER_CONVENTION
;
923 constexpr gdb_byte rx_break_insn
[] = { 0x00 };
925 typedef BP_MANIPULATION (rx_break_insn
) rx_breakpoint
;
927 /* Implement the dwarf_reg_to_regnum" gdbarch method. */
930 rx_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
932 if (0 <= reg
&& reg
<= 15)
935 return RX_PSW_REGNUM
;
942 /* Allocate and initialize a gdbarch object. */
943 static struct gdbarch
*
944 rx_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
946 struct gdbarch
*gdbarch
;
947 struct gdbarch_tdep
*tdep
;
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 if (gdbarch_tdep (arches
->gdbarch
)->elf_flags
!= elf_flags
)
969 return arches
->gdbarch
;
975 /* Check any target description for validity. */
976 if (tdesc_has_registers (tdesc
))
978 const struct tdesc_feature
*feature
;
981 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.rx.core");
985 tdesc_data
= tdesc_data_alloc ();
986 for (int i
= 0; i
< RX_NUM_REGS
; i
++)
987 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
988 rx_register_names
[i
]);
995 gdb_assert(tdesc_data
!= NULL
);
997 tdep
= XCNEW (struct gdbarch_tdep
);
998 gdbarch
= gdbarch_alloc (&info
, tdep
);
999 tdep
->elf_flags
= elf_flags
;
1001 set_gdbarch_num_regs (gdbarch
, RX_NUM_REGS
);
1002 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
1004 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1005 set_gdbarch_pc_regnum (gdbarch
, RX_PC_REGNUM
);
1006 set_gdbarch_sp_regnum (gdbarch
, RX_SP_REGNUM
);
1007 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1008 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
1009 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, rx_breakpoint::kind_from_pc
);
1010 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, rx_breakpoint::bp_from_kind
);
1011 set_gdbarch_skip_prologue (gdbarch
, rx_skip_prologue
);
1013 /* Target builtin data types. */
1014 set_gdbarch_char_signed (gdbarch
, 0);
1015 set_gdbarch_short_bit (gdbarch
, 16);
1016 set_gdbarch_int_bit (gdbarch
, 32);
1017 set_gdbarch_long_bit (gdbarch
, 32);
1018 set_gdbarch_long_long_bit (gdbarch
, 64);
1019 set_gdbarch_ptr_bit (gdbarch
, 32);
1020 set_gdbarch_float_bit (gdbarch
, 32);
1021 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
1023 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
1025 set_gdbarch_double_bit (gdbarch
, 64);
1026 set_gdbarch_long_double_bit (gdbarch
, 64);
1027 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
1028 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
1032 set_gdbarch_double_bit (gdbarch
, 32);
1033 set_gdbarch_long_double_bit (gdbarch
, 32);
1034 set_gdbarch_double_format (gdbarch
, floatformats_ieee_single
);
1035 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_single
);
1038 /* DWARF register mapping. */
1039 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, rx_dwarf_reg_to_regnum
);
1041 /* Frame unwinding. */
1042 frame_unwind_append_unwinder (gdbarch
, &rx_exception_unwind
);
1043 dwarf2_append_unwinders (gdbarch
);
1044 frame_unwind_append_unwinder (gdbarch
, &rx_frame_unwind
);
1046 /* Methods setting up a dummy call, and extracting the return value from
1048 set_gdbarch_push_dummy_call (gdbarch
, rx_push_dummy_call
);
1049 set_gdbarch_return_value (gdbarch
, rx_return_value
);
1051 /* Virtual tables. */
1052 set_gdbarch_vbit_in_delta (gdbarch
, 1);
1057 /* Register the above initialization routine. */
1059 void _initialize_rx_tdep ();
1061 _initialize_rx_tdep ()
1063 register_gdbarch_init (bfd_arch_rx
, rx_gdbarch_init
);
1064 initialize_tdesc_rx ();