1 /* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
3 Copyright (C) 2008-2016 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"
41 /* Certain important register numbers. */
62 RX_FRAME_TYPE_EXCEPTION
,
63 RX_FRAME_TYPE_FAST_INTERRUPT
66 /* Architecture specific data. */
69 /* The ELF header flags specify the multilib used. */
72 /* Type of PSW and BPSW. */
73 struct type
*rx_psw_type
;
76 struct type
*rx_fpsw_type
;
79 /* This structure holds the results of a prologue analysis. */
82 /* Frame type, either a normal frame or one of two types of exception
84 enum rx_frame_type frame_type
;
86 /* The offset from the frame base to the stack pointer --- always
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
97 /* Non-zero if this function has initialized the frame pointer from
98 the stack pointer, zero otherwise. */
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
104 int frame_ptr_offset
;
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
;
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
];
117 /* Implement the "register_name" gdbarch method. */
119 rx_register_name (struct gdbarch
*gdbarch
, int regnr
)
121 static const char *const reg_names
[] = {
150 return reg_names
[regnr
];
153 /* Implement the "register_type" gdbarch method. */
155 rx_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
157 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
159 if (reg_nr
== RX_PC_REGNUM
)
160 return builtin_type (gdbarch
)->builtin_func_ptr
;
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
;
165 else if (reg_nr
== RX_ACC_REGNUM
)
166 return builtin_type (gdbarch
)->builtin_unsigned_long_long
;
168 return builtin_type (gdbarch
)->builtin_unsigned_long
;
172 /* Function for finding saved registers in a 'struct pv_area'; this
173 function is passed to pv_area_scan.
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. */
179 check_for_saved (void *result_untyped
, pv_t addr
, CORE_ADDR size
, pv_t value
)
181 struct rx_prologue
*result
= (struct rx_prologue
*) result_untyped
;
183 if (value
.kind
== pvk_register
185 && pv_is_register (addr
, RX_SP_REGNUM
)
186 && size
== register_size (target_gdbarch (), value
.reg
))
187 result
->reg_offset
[value
.reg
] = addr
.k
;
190 /* Define a "handle" struct for fetching the next opcode. */
191 struct rx_get_opcode_byte_handle
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
202 rx_get_opcode_byte (void *handle
)
204 struct rx_get_opcode_byte_handle
*opcdata
205 = (struct rx_get_opcode_byte_handle
*) handle
;
209 status
= target_read_code (opcdata
->pc
, &byte
, 1);
219 /* Analyze a prologue starting at START_PC, going no further than
220 LIMIT_PC. Fill in RESULT as appropriate. */
223 rx_analyze_prologue (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
224 enum rx_frame_type frame_type
,
225 struct rx_prologue
*result
)
227 CORE_ADDR pc
, next_pc
;
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
;
234 memset (result
, 0, sizeof (*result
));
236 result
->frame_type
= frame_type
;
238 for (rn
= 0; rn
< RX_NUM_REGS
; rn
++)
240 reg
[rn
] = pv_register (rn
, 0);
241 result
->reg_offset
[rn
] = 1;
244 stack
= make_pv_area (RX_SP_REGNUM
, gdbarch_addr_bit (target_gdbarch ()));
245 back_to
= make_cleanup_free_pv_area (stack
);
247 if (frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
)
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
];
256 /* When an exception occurs, the PSW is saved to the interrupt stack
258 if (frame_type
== RX_FRAME_TYPE_EXCEPTION
)
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
]);
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
]);
273 while (pc
< limit_pc
)
276 struct rx_get_opcode_byte_handle opcode_handle
;
277 RX_Opcode_Decoded opc
;
279 opcode_handle
.pc
= pc
;
280 bytes_read
= rx_decode_opcode (pc
, &opc
, rx_get_opcode_byte
,
282 next_pc
= pc
+ bytes_read
;
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
)
293 for (r
= r2
; r
>= r1
; r
--)
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
]);
298 after_last_frame_setup_insn
= next_pc
;
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
)
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
;
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
)
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
;
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
)
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
;
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
))
349 /* This moves an argument register to the stack. Don't
350 record it, but allow it to be a part of the prologue. */
352 else if (opc
.id
== RXO_branch
353 && opc
.op
[0].type
== RX_Operand_Immediate
354 && next_pc
< opc
.op
[0].addend
)
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.
364 Note that we only consider forward branches here. We
365 presume that a forward branch is being used to skip over
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
375 after_last_frame_setup_insn
= opc
.op
[0].addend
;
376 break; /* Scan no further if we hit this case. */
380 /* Terminate the prologue scan. */
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
;
391 /* Was the frame pointer initialized? */
392 if (pv_is_register (reg
[RX_FP_REGNUM
], RX_SP_REGNUM
))
394 result
->has_frame_ptr
= 1;
395 result
->frame_ptr_offset
= reg
[RX_FP_REGNUM
].k
;
398 /* Record where all the registers were saved. */
399 pv_area_scan (stack
, check_for_saved
, (void *) result
);
401 result
->prologue_end
= after_last_frame_setup_insn
;
403 do_cleanups (back_to
);
407 /* Implement the "skip_prologue" gdbarch method. */
409 rx_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
412 CORE_ADDR func_addr
, func_end
;
413 struct rx_prologue p
;
415 /* Try to find the extent of the function that contains PC. */
416 if (!find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
))
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
);
422 return p
.prologue_end
;
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. */
430 static struct rx_prologue
*
431 rx_analyze_frame_prologue (struct frame_info
*this_frame
,
432 enum rx_frame_type frame_type
,
433 void **this_prologue_cache
)
435 if (!*this_prologue_cache
)
437 CORE_ADDR func_start
, stop_addr
;
439 *this_prologue_cache
= FRAME_OBSTACK_ZALLOC (struct rx_prologue
);
441 func_start
= get_frame_func (this_frame
);
442 stop_addr
= get_frame_pc (this_frame
);
444 /* If we couldn't find any function containing the PC, then
445 just initialize the prologue cache, but don't do anything. */
447 stop_addr
= func_start
;
449 rx_analyze_prologue (func_start
, stop_addr
, frame_type
,
450 (struct rx_prologue
*) *this_prologue_cache
);
453 return (struct rx_prologue
*) *this_prologue_cache
;
456 /* Determine type of frame by scanning the function for a return
459 static enum rx_frame_type
460 rx_frame_type (struct frame_info
*this_frame
, void **this_cache
)
463 CORE_ADDR pc
, start_pc
, lim_pc
;
465 struct rx_get_opcode_byte_handle opcode_handle
;
466 RX_Opcode_Decoded opc
;
468 gdb_assert (this_cache
!= NULL
);
470 /* If we have a cached value, return it. */
472 if (*this_cache
!= NULL
)
474 struct rx_prologue
*p
= (struct rx_prologue
*) *this_cache
;
476 return p
->frame_type
;
479 /* No cached value; scan the function. The frame type is cached in
480 rx_analyze_prologue / rx_analyze_frame_prologue. */
482 pc
= get_frame_pc (this_frame
);
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
487 if (!find_pc_partial_function (pc
, &name
, &start_pc
, &lim_pc
))
492 opcode_handle
.pc
= pc
;
493 bytes_read
= rx_decode_opcode (pc
, &opc
, rx_get_opcode_byte
,
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
;
506 return RX_FRAME_TYPE_NORMAL
;
510 /* Given the next frame and a prologue cache, return this frame's
514 rx_frame_base (struct frame_info
*this_frame
, void **this_cache
)
516 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
517 struct rx_prologue
*p
518 = rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
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
)
528 CORE_ADDR fp
= get_frame_register_unsigned (this_frame
, RX_FP_REGNUM
);
529 return fp
- p
->frame_ptr_offset
;
533 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, RX_SP_REGNUM
);
534 return sp
- p
->frame_size
;
538 /* Implement the "frame_this_id" method for unwinding frames. */
541 rx_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
542 struct frame_id
*this_id
)
544 *this_id
= frame_id_build (rx_frame_base (this_frame
, this_cache
),
545 get_frame_func (this_frame
));
548 /* Implement the "frame_prev_register" method for unwinding frames. */
550 static struct value
*
551 rx_frame_prev_register (struct frame_info
*this_frame
, void **this_cache
,
554 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
555 struct rx_prologue
*p
556 = rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
557 CORE_ADDR frame_base
= rx_frame_base (this_frame
, this_cache
);
559 if (regnum
== RX_SP_REGNUM
)
561 if (frame_type
== RX_FRAME_TYPE_EXCEPTION
)
563 struct value
*psw_val
;
566 psw_val
= rx_frame_prev_register (this_frame
, this_cache
,
568 psw
= extract_unsigned_integer (value_contents_all (psw_val
), 4,
570 get_frame_arch (this_frame
)));
572 if ((psw
& 0x20000 /* U bit */) != 0)
573 return rx_frame_prev_register (this_frame
, this_cache
,
576 /* Fall through for the case where U bit is zero. */
579 return frame_unwind_got_constant (this_frame
, regnum
, frame_base
);
582 if (frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
)
584 if (regnum
== RX_PC_REGNUM
)
585 return rx_frame_prev_register (this_frame
, this_cache
,
587 if (regnum
== RX_PSW_REGNUM
)
588 return rx_frame_prev_register (this_frame
, this_cache
,
592 /* If prologue analysis says we saved this register somewhere,
593 return a description of the stack slot holding it. */
594 if (p
->reg_offset
[regnum
] != 1)
595 return frame_unwind_got_memory (this_frame
, regnum
,
596 frame_base
+ p
->reg_offset
[regnum
]);
598 /* Otherwise, presume we haven't changed the value of this
599 register, and get it from the next frame. */
600 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
603 /* Return TRUE if the frame indicated by FRAME_TYPE is a normal frame. */
606 normal_frame_p (enum rx_frame_type frame_type
)
608 return (frame_type
== RX_FRAME_TYPE_NORMAL
);
611 /* Return TRUE if the frame indicated by FRAME_TYPE is an exception
615 exception_frame_p (enum rx_frame_type frame_type
)
617 return (frame_type
== RX_FRAME_TYPE_EXCEPTION
618 || frame_type
== RX_FRAME_TYPE_FAST_INTERRUPT
);
621 /* Common code used by both normal and exception frame sniffers. */
624 rx_frame_sniffer_common (const struct frame_unwind
*self
,
625 struct frame_info
*this_frame
,
627 int (*sniff_p
)(enum rx_frame_type
) )
629 gdb_assert (this_cache
!= NULL
);
631 if (*this_cache
== NULL
)
633 enum rx_frame_type frame_type
= rx_frame_type (this_frame
, this_cache
);
635 if (sniff_p (frame_type
))
637 /* The call below will fill in the cache, including the frame
639 (void) rx_analyze_frame_prologue (this_frame
, frame_type
, this_cache
);
648 struct rx_prologue
*p
= (struct rx_prologue
*) *this_cache
;
650 return sniff_p (p
->frame_type
);
654 /* Frame sniffer for normal (non-exception) frames. */
657 rx_frame_sniffer (const struct frame_unwind
*self
,
658 struct frame_info
*this_frame
,
661 return rx_frame_sniffer_common (self
, this_frame
, this_cache
,
665 /* Frame sniffer for exception frames. */
668 rx_exception_sniffer (const struct frame_unwind
*self
,
669 struct frame_info
*this_frame
,
672 return rx_frame_sniffer_common (self
, this_frame
, this_cache
,
676 /* Data structure for normal code using instruction-based prologue
679 static const struct frame_unwind rx_frame_unwind
= {
681 default_frame_unwind_stop_reason
,
683 rx_frame_prev_register
,
688 /* Data structure for exception code using instruction-based prologue
691 static const struct frame_unwind rx_exception_unwind
= {
692 /* SIGTRAMP_FRAME could be used here, but backtraces are less informative. */
694 default_frame_unwind_stop_reason
,
696 rx_frame_prev_register
,
701 /* Implement the "unwind_pc" gdbarch method. */
703 rx_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
707 pc
= frame_unwind_register_unsigned (this_frame
, RX_PC_REGNUM
);
711 /* Implement the "unwind_sp" gdbarch method. */
713 rx_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
717 sp
= frame_unwind_register_unsigned (this_frame
, RX_SP_REGNUM
);
721 /* Implement the "dummy_id" gdbarch method. */
722 static struct frame_id
723 rx_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
726 frame_id_build (get_frame_register_unsigned (this_frame
, RX_SP_REGNUM
),
727 get_frame_pc (this_frame
));
730 /* Implement the "push_dummy_call" gdbarch method. */
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
)
737 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
741 int num_register_candidate_args
;
743 struct type
*func_type
= value_type (function
);
745 /* Dereference function pointer types. */
746 while (TYPE_CODE (func_type
) == TYPE_CODE_PTR
)
747 func_type
= TYPE_TARGET_TYPE (func_type
);
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
);
753 /* Functions with a variable number of arguments have all of their
754 variable arguments and the last non-variable argument passed
757 Otherwise, we can pass up to four arguments on the stack.
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. */
764 if (TYPE_VARARGS (func_type
))
765 num_register_candidate_args
= TYPE_NFIELDS (func_type
) - 1;
767 num_register_candidate_args
= 4;
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
++)
774 int arg_reg
= RX_R1_REGNUM
;
777 sp
= align_down (sp
- sp_off
, 4);
782 struct type
*return_type
= TYPE_TARGET_TYPE (func_type
);
784 gdb_assert (TYPE_CODE (return_type
) == TYPE_CODE_STRUCT
785 || TYPE_CODE (func_type
) == TYPE_CODE_UNION
);
787 if (TYPE_LENGTH (return_type
) > 16
788 || TYPE_LENGTH (return_type
) % 4 != 0)
791 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
796 /* Push the arguments. */
797 for (i
= 0; i
< nargs
; i
++)
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
);
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
)
809 /* This argument represents the address at which C++ (and
810 possibly other languages) store their return value.
811 Put this value in R15. */
813 regcache_cooked_write_unsigned (regcache
, RX_R15_REGNUM
,
816 else if (TYPE_CODE (arg_type
) != TYPE_CODE_STRUCT
817 && TYPE_CODE (arg_type
) != TYPE_CODE_UNION
820 /* Argument is a scalar. */
823 if (i
< num_register_candidate_args
824 && arg_reg
<= RX_R4_REGNUM
- 1)
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. */
831 regcache_cooked_write_unsigned (regcache
, arg_reg
,
832 extract_unsigned_integer
835 regcache_cooked_write_unsigned (regcache
,
837 extract_unsigned_integer
845 sp_off
= align_up (sp_off
, 4);
846 /* Otherwise, pass the 8 byte scalar on the stack. */
848 write_memory (sp
+ sp_off
, arg_bits
, 8);
856 gdb_assert (arg_size
<= 4);
859 extract_unsigned_integer (arg_bits
, arg_size
, byte_order
);
861 if (i
< num_register_candidate_args
862 && arg_reg
<= RX_R4_REGNUM
)
865 regcache_cooked_write_unsigned (regcache
, arg_reg
, u
);
872 if (TYPE_PROTOTYPED (func_type
)
873 && i
< TYPE_NFIELDS (func_type
))
875 struct type
*p_arg_type
=
876 TYPE_FIELD_TYPE (func_type
, i
);
877 p_arg_size
= TYPE_LENGTH (p_arg_type
);
880 sp_off
= align_up (sp_off
, p_arg_size
);
883 write_memory_unsigned_integer (sp
+ sp_off
,
884 p_arg_size
, byte_order
,
886 sp_off
+= p_arg_size
;
892 /* Argument is a struct or union. Pass as much of the struct
893 in registers, if possible. Pass the rest on the stack. */
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)
901 int len
= std::min (arg_size
, (ULONGEST
) 4);
904 regcache_cooked_write_unsigned (regcache
, arg_reg
,
905 extract_unsigned_integer
914 sp_off
= align_up (sp_off
, 4);
916 write_memory (sp
+ sp_off
, arg_bits
, arg_size
);
917 sp_off
+= align_up (arg_size
, 4);
925 /* Keep track of the stack address prior to pushing the return address.
926 This is the value that we'll return. */
929 /* Push the return address. */
931 write_memory_unsigned_integer (sp
, 4, byte_order
, bp_addr
);
933 /* Update the stack pointer. */
934 regcache_cooked_write_unsigned (regcache
, RX_SP_REGNUM
, sp
);
939 /* Implement the "return_value" gdbarch method. */
940 static enum return_value_convention
941 rx_return_value (struct gdbarch
*gdbarch
,
942 struct value
*function
,
943 struct type
*valtype
,
944 struct regcache
*regcache
,
945 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
947 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
948 ULONGEST valtype_len
= TYPE_LENGTH (valtype
);
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
;
959 int argreg
= RX_R1_REGNUM
;
962 while (valtype_len
> 0)
964 int len
= std::min (valtype_len
, (ULONGEST
) 4);
966 regcache_cooked_read_unsigned (regcache
, argreg
, &u
);
967 store_unsigned_integer (readbuf
+ offset
, len
, byte_order
, u
);
977 int argreg
= RX_R1_REGNUM
;
980 while (valtype_len
> 0)
982 int len
= std::min (valtype_len
, (ULONGEST
) 4);
984 u
= extract_unsigned_integer (writebuf
+ offset
, len
, byte_order
);
985 regcache_cooked_write_unsigned (regcache
, argreg
, u
);
992 return RETURN_VALUE_REGISTER_CONVENTION
;
995 /* Implement the "breakpoint_from_pc" gdbarch method. */
996 static const gdb_byte
*
997 rx_breakpoint_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
, int *lenptr
)
999 static gdb_byte breakpoint
[] = { 0x00 };
1000 *lenptr
= sizeof breakpoint
;
1004 /* Implement the dwarf_reg_to_regnum" gdbarch method. */
1007 rx_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
1009 if (0 <= reg
&& reg
<= 15)
1012 return RX_PSW_REGNUM
;
1014 return RX_PC_REGNUM
;
1019 /* Allocate and initialize a gdbarch object. */
1020 static struct gdbarch
*
1021 rx_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1023 struct gdbarch
*gdbarch
;
1024 struct gdbarch_tdep
*tdep
;
1027 /* Extract the elf_flags if available. */
1028 if (info
.abfd
!= NULL
1029 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
1030 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
1035 /* Try to find the architecture in the list of already defined
1037 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1039 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
1041 if (gdbarch_tdep (arches
->gdbarch
)->elf_flags
!= elf_flags
)
1044 return arches
->gdbarch
;
1047 /* None found, create a new architecture from the information
1049 tdep
= XNEW (struct gdbarch_tdep
);
1050 gdbarch
= gdbarch_alloc (&info
, tdep
);
1051 tdep
->elf_flags
= elf_flags
;
1053 /* Initialize the flags type for PSW and BPSW. */
1055 tdep
->rx_psw_type
= arch_flags_type (gdbarch
, "rx_psw_type", 4);
1056 append_flags_type_flag (tdep
->rx_psw_type
, 0, "C");
1057 append_flags_type_flag (tdep
->rx_psw_type
, 1, "Z");
1058 append_flags_type_flag (tdep
->rx_psw_type
, 2, "S");
1059 append_flags_type_flag (tdep
->rx_psw_type
, 3, "O");
1060 append_flags_type_flag (tdep
->rx_psw_type
, 16, "I");
1061 append_flags_type_flag (tdep
->rx_psw_type
, 17, "U");
1062 append_flags_type_flag (tdep
->rx_psw_type
, 20, "PM");
1063 append_flags_type_flag (tdep
->rx_psw_type
, 24, "IPL0");
1064 append_flags_type_flag (tdep
->rx_psw_type
, 25, "IPL1");
1065 append_flags_type_flag (tdep
->rx_psw_type
, 26, "IPL2");
1066 append_flags_type_flag (tdep
->rx_psw_type
, 27, "IPL3");
1068 /* Initialize flags type for FPSW. */
1070 tdep
->rx_fpsw_type
= arch_flags_type (gdbarch
, "rx_fpsw_type", 4);
1071 append_flags_type_flag (tdep
->rx_fpsw_type
, 0, "RM0");
1072 append_flags_type_flag (tdep
->rx_fpsw_type
, 1, "RM1");
1073 append_flags_type_flag (tdep
->rx_fpsw_type
, 2, "CV");
1074 append_flags_type_flag (tdep
->rx_fpsw_type
, 3, "CO");
1075 append_flags_type_flag (tdep
->rx_fpsw_type
, 4, "CZ");
1076 append_flags_type_flag (tdep
->rx_fpsw_type
, 5, "CU");
1077 append_flags_type_flag (tdep
->rx_fpsw_type
, 6, "CX");
1078 append_flags_type_flag (tdep
->rx_fpsw_type
, 7, "CE");
1079 append_flags_type_flag (tdep
->rx_fpsw_type
, 8, "DN");
1080 append_flags_type_flag (tdep
->rx_fpsw_type
, 10, "EV");
1081 append_flags_type_flag (tdep
->rx_fpsw_type
, 11, "EO");
1082 append_flags_type_flag (tdep
->rx_fpsw_type
, 12, "EZ");
1083 append_flags_type_flag (tdep
->rx_fpsw_type
, 13, "EU");
1084 append_flags_type_flag (tdep
->rx_fpsw_type
, 14, "EX");
1085 append_flags_type_flag (tdep
->rx_fpsw_type
, 26, "FV");
1086 append_flags_type_flag (tdep
->rx_fpsw_type
, 27, "FO");
1087 append_flags_type_flag (tdep
->rx_fpsw_type
, 28, "FZ");
1088 append_flags_type_flag (tdep
->rx_fpsw_type
, 29, "FU");
1089 append_flags_type_flag (tdep
->rx_fpsw_type
, 30, "FX");
1090 append_flags_type_flag (tdep
->rx_fpsw_type
, 31, "FS");
1092 set_gdbarch_num_regs (gdbarch
, RX_NUM_REGS
);
1093 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1094 set_gdbarch_register_name (gdbarch
, rx_register_name
);
1095 set_gdbarch_register_type (gdbarch
, rx_register_type
);
1096 set_gdbarch_pc_regnum (gdbarch
, RX_PC_REGNUM
);
1097 set_gdbarch_sp_regnum (gdbarch
, RX_SP_REGNUM
);
1098 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1099 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
1100 set_gdbarch_breakpoint_from_pc (gdbarch
, rx_breakpoint_from_pc
);
1101 set_gdbarch_skip_prologue (gdbarch
, rx_skip_prologue
);
1103 set_gdbarch_print_insn (gdbarch
, print_insn_rx
);
1105 set_gdbarch_unwind_pc (gdbarch
, rx_unwind_pc
);
1106 set_gdbarch_unwind_sp (gdbarch
, rx_unwind_sp
);
1108 /* Target builtin data types. */
1109 set_gdbarch_char_signed (gdbarch
, 0);
1110 set_gdbarch_short_bit (gdbarch
, 16);
1111 set_gdbarch_int_bit (gdbarch
, 32);
1112 set_gdbarch_long_bit (gdbarch
, 32);
1113 set_gdbarch_long_long_bit (gdbarch
, 64);
1114 set_gdbarch_ptr_bit (gdbarch
, 32);
1115 set_gdbarch_float_bit (gdbarch
, 32);
1116 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
1117 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
1119 set_gdbarch_double_bit (gdbarch
, 64);
1120 set_gdbarch_long_double_bit (gdbarch
, 64);
1121 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
1122 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
1126 set_gdbarch_double_bit (gdbarch
, 32);
1127 set_gdbarch_long_double_bit (gdbarch
, 32);
1128 set_gdbarch_double_format (gdbarch
, floatformats_ieee_single
);
1129 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_single
);
1132 /* DWARF register mapping. */
1133 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, rx_dwarf_reg_to_regnum
);
1135 /* Frame unwinding. */
1136 frame_unwind_append_unwinder (gdbarch
, &rx_exception_unwind
);
1137 dwarf2_append_unwinders (gdbarch
);
1138 frame_unwind_append_unwinder (gdbarch
, &rx_frame_unwind
);
1140 /* Methods for saving / extracting a dummy frame's ID.
1141 The ID's stack address must match the SP value returned by
1142 PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
1143 set_gdbarch_dummy_id (gdbarch
, rx_dummy_id
);
1144 set_gdbarch_push_dummy_call (gdbarch
, rx_push_dummy_call
);
1145 set_gdbarch_return_value (gdbarch
, rx_return_value
);
1147 /* Virtual tables. */
1148 set_gdbarch_vbit_in_delta (gdbarch
, 1);
1153 /* -Wmissing-prototypes */
1154 extern initialize_file_ftype _initialize_rx_tdep
;
1156 /* Register the above initialization routine. */
1159 _initialize_rx_tdep (void)
1161 register_gdbarch_init (bfd_arch_rx
, rx_gdbarch_init
);