GDB (xrefs)
Loading...
Searching...
No Matches
rx-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
2
3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4
5 Contributed by Red Hat, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22#include "defs.h"
23#include "arch-utils.h"
24#include "prologue-value.h"
25#include "target.h"
26#include "regcache.h"
27#include "opcode/rx.h"
28#include "dis-asm.h"
29#include "gdbtypes.h"
30#include "frame.h"
31#include "frame-unwind.h"
32#include "frame-base.h"
33#include "value.h"
34#include "gdbcore.h"
35#include "dwarf2/frame.h"
36#include "remote.h"
37#include "target-descriptions.h"
38#include "gdbarch.h"
39
40#include "elf/rx.h"
41#include "elf-bfd.h"
42#include <algorithm>
43
44#include "features/rx.c"
45
46/* Certain important register numbers. */
47enum
48{
61 RX_NUM_REGS = 26
62};
63
64/* RX frame types. */
70
71/* Architecture specific data. */
73{
74 /* The ELF header flags specify the multilib used. */
75 int elf_flags = 0;
76
77 /* Type of PSW and BPSW. */
78 struct type *rx_psw_type = nullptr;
79
80 /* Type of FPSW. */
81 struct type *rx_fpsw_type = nullptr;
82};
83
84/* This structure holds the results of a prologue analysis. */
86{
87 /* Frame type, either a normal frame or one of two types of exception
88 frames. */
90
91 /* The offset from the frame base to the stack pointer --- always
92 zero or negative.
93
94 Calling this a "size" is a bit misleading, but given that the
95 stack grows downwards, using offsets for everything keeps one
96 from going completely sign-crazy: you never change anything's
97 sign for an ADD instruction; always change the second operand's
98 sign for a SUB instruction; and everything takes care of
99 itself. */
101
102 /* Non-zero if this function has initialized the frame pointer from
103 the stack pointer, zero otherwise. */
105
106 /* If has_frame_ptr is non-zero, this is the offset from the frame
107 base to where the frame pointer points. This is always zero or
108 negative. */
110
111 /* The address of the first instruction at which the frame has been
112 set up and the arguments are where the debug info says they are
113 --- as best as we can tell. */
114 CORE_ADDR prologue_end;
115
116 /* reg_offset[R] is the offset from the CFA at which register R is
117 saved, or 1 if register R has not been saved. (Real values are
118 always zero or negative.) */
120};
121
122/* RX register names */
123static const char *const rx_register_names[] = {
124 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
125 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
126 "usp", "isp", "psw", "pc", "intb", "bpsw","bpc","fintv",
127 "fpsw", "acc",
128};
129
130
131/* Function for finding saved registers in a 'struct pv_area'; this
132 function is passed to pv_area::scan.
133
134 If VALUE is a saved register, ADDR says it was saved at a constant
135 offset from the frame base, and SIZE indicates that the whole
136 register was saved, record its offset. */
137static void
138check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value)
139{
140 struct rx_prologue *result = (struct rx_prologue *) result_untyped;
141
142 if (value.kind == pvk_register
143 && value.k == 0
146 result->reg_offset[value.reg] = addr.k;
147}
148
149/* Define a "handle" struct for fetching the next opcode. */
151{
152 CORE_ADDR pc;
153};
154
155/* Fetch a byte on behalf of the opcode decoder. HANDLE contains
156 the memory address of the next byte to fetch. If successful,
157 the address in the handle is updated and the byte fetched is
158 returned as the value of the function. If not successful, -1
159 is returned. */
160static int
161rx_get_opcode_byte (void *handle)
162{
163 struct rx_get_opcode_byte_handle *opcdata
164 = (struct rx_get_opcode_byte_handle *) handle;
165 int status;
166 gdb_byte byte;
167
168 status = target_read_code (opcdata->pc, &byte, 1);
169 if (status == 0)
170 {
171 opcdata->pc += 1;
172 return byte;
173 }
174 else
175 return -1;
176}
177
178/* Analyze a prologue starting at START_PC, going no further than
179 LIMIT_PC. Fill in RESULT as appropriate. */
180
181static void
182rx_analyze_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc,
184 struct rx_prologue *result)
185{
186 CORE_ADDR pc, next_pc;
187 int rn;
188 pv_t reg[RX_NUM_REGS];
189 CORE_ADDR after_last_frame_setup_insn = start_pc;
190
191 memset (result, 0, sizeof (*result));
192
193 result->frame_type = frame_type;
194
195 for (rn = 0; rn < RX_NUM_REGS; rn++)
196 {
197 reg[rn] = pv_register (rn, 0);
198 result->reg_offset[rn] = 1;
199 }
200
202
204 {
205 /* This code won't do anything useful at present, but this is
206 what happens for fast interrupts. */
207 reg[RX_BPSW_REGNUM] = reg[RX_PSW_REGNUM];
208 reg[RX_BPC_REGNUM] = reg[RX_PC_REGNUM];
209 }
210 else
211 {
212 /* When an exception occurs, the PSW is saved to the interrupt stack
213 first. */
215 {
216 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
217 stack.store (reg[RX_SP_REGNUM], 4, reg[RX_PSW_REGNUM]);
218 }
219
220 /* The call instruction (or an exception/interrupt) has saved the return
221 address on the stack. */
222 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
223 stack.store (reg[RX_SP_REGNUM], 4, reg[RX_PC_REGNUM]);
224
225 }
226
227
228 pc = start_pc;
229 while (pc < limit_pc)
230 {
231 int bytes_read;
232 struct rx_get_opcode_byte_handle opcode_handle;
233 RX_Opcode_Decoded opc;
234
235 opcode_handle.pc = pc;
236 bytes_read = rx_decode_opcode (pc, &opc, rx_get_opcode_byte,
237 &opcode_handle);
238 next_pc = pc + bytes_read;
239
240 if (opc.id == RXO_pushm /* pushm r1, r2 */
241 && opc.op[1].type == RX_Operand_Register
242 && opc.op[2].type == RX_Operand_Register)
243 {
244 int r1, r2;
245 int r;
246
247 r1 = opc.op[1].reg;
248 r2 = opc.op[2].reg;
249 for (r = r2; r >= r1; r--)
250 {
251 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
252 stack.store (reg[RX_SP_REGNUM], 4, reg[r]);
253 }
254 after_last_frame_setup_insn = next_pc;
255 }
256 else if (opc.id == RXO_mov /* mov.l rdst, rsrc */
257 && opc.op[0].type == RX_Operand_Register
258 && opc.op[1].type == RX_Operand_Register
259 && opc.size == RX_Long)
260 {
261 int rdst, rsrc;
262
263 rdst = opc.op[0].reg;
264 rsrc = opc.op[1].reg;
265 reg[rdst] = reg[rsrc];
266 if (rdst == RX_FP_REGNUM && rsrc == RX_SP_REGNUM)
267 after_last_frame_setup_insn = next_pc;
268 }
269 else if (opc.id == RXO_mov /* mov.l rsrc, [-SP] */
270 && opc.op[0].type == RX_Operand_Predec
271 && opc.op[0].reg == RX_SP_REGNUM
272 && opc.op[1].type == RX_Operand_Register
273 && opc.size == RX_Long)
274 {
275 int rsrc;
276
277 rsrc = opc.op[1].reg;
278 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
279 stack.store (reg[RX_SP_REGNUM], 4, reg[rsrc]);
280 after_last_frame_setup_insn = next_pc;
281 }
282 else if (opc.id == RXO_add /* add #const, rsrc, rdst */
283 && opc.op[0].type == RX_Operand_Register
284 && opc.op[1].type == RX_Operand_Immediate
285 && opc.op[2].type == RX_Operand_Register)
286 {
287 int rdst = opc.op[0].reg;
288 int addend = opc.op[1].addend;
289 int rsrc = opc.op[2].reg;
290 reg[rdst] = pv_add_constant (reg[rsrc], addend);
291 /* Negative adjustments to the stack pointer or frame pointer
292 are (most likely) part of the prologue. */
293 if ((rdst == RX_SP_REGNUM || rdst == RX_FP_REGNUM) && addend < 0)
294 after_last_frame_setup_insn = next_pc;
295 }
296 else if (opc.id == RXO_mov
297 && opc.op[0].type == RX_Operand_Indirect
298 && opc.op[1].type == RX_Operand_Register
299 && opc.size == RX_Long
300 && (opc.op[0].reg == RX_SP_REGNUM
301 || opc.op[0].reg == RX_FP_REGNUM)
302 && (RX_R1_REGNUM <= opc.op[1].reg
303 && opc.op[1].reg <= RX_R4_REGNUM))
304 {
305 /* This moves an argument register to the stack. Don't
306 record it, but allow it to be a part of the prologue. */
307 }
308 else if (opc.id == RXO_branch
309 && opc.op[0].type == RX_Operand_Immediate
310 && next_pc < opc.op[0].addend)
311 {
312 /* When a loop appears as the first statement of a function
313 body, gcc 4.x will use a BRA instruction to branch to the
314 loop condition checking code. This BRA instruction is
315 marked as part of the prologue. We therefore set next_pc
316 to this branch target and also stop the prologue scan.
317 The instructions at and beyond the branch target should
318 no longer be associated with the prologue.
319
320 Note that we only consider forward branches here. We
321 presume that a forward branch is being used to skip over
322 a loop body.
323
324 A backwards branch is covered by the default case below.
325 If we were to encounter a backwards branch, that would
326 most likely mean that we've scanned through a loop body.
327 We definitely want to stop the prologue scan when this
328 happens and that is precisely what is done by the default
329 case below. */
330
331 after_last_frame_setup_insn = opc.op[0].addend;
332 break; /* Scan no further if we hit this case. */
333 }
334 else
335 {
336 /* Terminate the prologue scan. */
337 break;
338 }
339
340 pc = next_pc;
341 }
342
343 /* Is the frame size (offset, really) a known constant? */
345 result->frame_size = reg[RX_SP_REGNUM].k;
346
347 /* Was the frame pointer initialized? */
349 {
350 result->has_frame_ptr = 1;
351 result->frame_ptr_offset = reg[RX_FP_REGNUM].k;
352 }
353
354 /* Record where all the registers were saved. */
355 stack.scan (check_for_saved, (void *) result);
356
357 result->prologue_end = after_last_frame_setup_insn;
358}
359
360
361/* Implement the "skip_prologue" gdbarch method. */
362static CORE_ADDR
363rx_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
364{
365 const char *name;
366 CORE_ADDR func_addr, func_end;
367 struct rx_prologue p;
368
369 /* Try to find the extent of the function that contains PC. */
370 if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
371 return pc;
372
373 /* The frame type doesn't matter here, since we only care about
374 where the prologue ends. We'll use RX_FRAME_TYPE_NORMAL. */
375 rx_analyze_prologue (pc, func_end, RX_FRAME_TYPE_NORMAL, &p);
376 return p.prologue_end;
377}
378
379/* Given a frame described by THIS_FRAME, decode the prologue of its
380 associated function if there is not cache entry as specified by
381 THIS_PROLOGUE_CACHE. Save the decoded prologue in the cache and
382 return that struct as the value of this function. */
383
384static struct rx_prologue *
387 void **this_prologue_cache)
388{
389 if (!*this_prologue_cache)
390 {
391 CORE_ADDR func_start, stop_addr;
392
393 *this_prologue_cache = FRAME_OBSTACK_ZALLOC (struct rx_prologue);
394
395 func_start = get_frame_func (this_frame);
396 stop_addr = get_frame_pc (this_frame);
397
398 /* If we couldn't find any function containing the PC, then
399 just initialize the prologue cache, but don't do anything. */
400 if (!func_start)
401 stop_addr = func_start;
402
403 rx_analyze_prologue (func_start, stop_addr, frame_type,
404 (struct rx_prologue *) *this_prologue_cache);
405 }
406
407 return (struct rx_prologue *) *this_prologue_cache;
408}
409
410/* Determine type of frame by scanning the function for a return
411 instruction. */
412
413static enum rx_frame_type
414rx_frame_type (frame_info_ptr this_frame, void **this_cache)
415{
416 const char *name;
417 CORE_ADDR pc, start_pc, lim_pc;
418 int bytes_read;
419 struct rx_get_opcode_byte_handle opcode_handle;
420 RX_Opcode_Decoded opc;
421
422 gdb_assert (this_cache != NULL);
423
424 /* If we have a cached value, return it. */
425
426 if (*this_cache != NULL)
427 {
428 struct rx_prologue *p = (struct rx_prologue *) *this_cache;
429
430 return p->frame_type;
431 }
432
433 /* No cached value; scan the function. The frame type is cached in
434 rx_analyze_prologue / rx_analyze_frame_prologue. */
435
436 pc = get_frame_pc (this_frame);
437
438 /* Attempt to find the last address in the function. If it cannot
439 be determined, set the limit to be a short ways past the frame's
440 pc. */
441 if (!find_pc_partial_function (pc, &name, &start_pc, &lim_pc))
442 lim_pc = pc + 20;
443
444 while (pc < lim_pc)
445 {
446 opcode_handle.pc = pc;
447 bytes_read = rx_decode_opcode (pc, &opc, rx_get_opcode_byte,
448 &opcode_handle);
449
450 if (bytes_read <= 0 || opc.id == RXO_rts)
452 else if (opc.id == RXO_rtfi)
454 else if (opc.id == RXO_rte)
456
457 pc += bytes_read;
458 }
459
461}
462
463
464/* Given the next frame and a prologue cache, return this frame's
465 base. */
466
467static CORE_ADDR
468rx_frame_base (frame_info_ptr this_frame, void **this_cache)
469{
470 enum rx_frame_type frame_type = rx_frame_type (this_frame, this_cache);
471 struct rx_prologue *p
472 = rx_analyze_frame_prologue (this_frame, frame_type, this_cache);
473
474 /* In functions that use alloca, the distance between the stack
475 pointer and the frame base varies dynamically, so we can't use
476 the SP plus static information like prologue analysis to find the
477 frame base. However, such functions must have a frame pointer,
478 to be able to restore the SP on exit. So whenever we do have a
479 frame pointer, use that to find the base. */
480 if (p->has_frame_ptr)
481 {
482 CORE_ADDR fp = get_frame_register_unsigned (this_frame, RX_FP_REGNUM);
483 return fp - p->frame_ptr_offset;
484 }
485 else
486 {
487 CORE_ADDR sp = get_frame_register_unsigned (this_frame, RX_SP_REGNUM);
488 return sp - p->frame_size;
489 }
490}
491
492/* Implement the "frame_this_id" method for unwinding frames. */
493
494static void
495rx_frame_this_id (frame_info_ptr this_frame, void **this_cache,
496 struct frame_id *this_id)
497{
498 *this_id = frame_id_build (rx_frame_base (this_frame, this_cache),
499 get_frame_func (this_frame));
500}
501
502/* Implement the "frame_prev_register" method for unwinding frames. */
503
504static struct value *
505rx_frame_prev_register (frame_info_ptr this_frame, void **this_cache,
506 int regnum)
507{
508 enum rx_frame_type frame_type = rx_frame_type (this_frame, this_cache);
509 struct rx_prologue *p
510 = rx_analyze_frame_prologue (this_frame, frame_type, this_cache);
511 CORE_ADDR frame_base = rx_frame_base (this_frame, this_cache);
512
513 if (regnum == RX_SP_REGNUM)
514 {
516 {
517 struct value *psw_val;
518 CORE_ADDR psw;
519
520 psw_val = rx_frame_prev_register (this_frame, this_cache,
523 (psw_val->contents_all ().data (), 4,
524 gdbarch_byte_order (get_frame_arch (this_frame)));
525
526 if ((psw & 0x20000 /* U bit */) != 0)
527 return rx_frame_prev_register (this_frame, this_cache,
529
530 /* Fall through for the case where U bit is zero. */
531 }
532
533 return frame_unwind_got_constant (this_frame, regnum, frame_base);
534 }
535
537 {
538 if (regnum == RX_PC_REGNUM)
539 return rx_frame_prev_register (this_frame, this_cache,
541 if (regnum == RX_PSW_REGNUM)
542 return rx_frame_prev_register (this_frame, this_cache,
544 }
545
546 /* If prologue analysis says we saved this register somewhere,
547 return a description of the stack slot holding it. */
548 if (p->reg_offset[regnum] != 1)
549 return frame_unwind_got_memory (this_frame, regnum,
551
552 /* Otherwise, presume we haven't changed the value of this
553 register, and get it from the next frame. */
554 return frame_unwind_got_register (this_frame, regnum, regnum);
555}
556
557/* Return TRUE if the frame indicated by FRAME_TYPE is a normal frame. */
558
559static int
564
565/* Return TRUE if the frame indicated by FRAME_TYPE is an exception
566 frame. */
567
568static int
574
575/* Common code used by both normal and exception frame sniffers. */
576
577static int
579 frame_info_ptr this_frame,
580 void **this_cache,
581 int (*sniff_p)(enum rx_frame_type) )
582{
583 gdb_assert (this_cache != NULL);
584
585 if (*this_cache == NULL)
586 {
587 enum rx_frame_type frame_type = rx_frame_type (this_frame, this_cache);
588
589 if (sniff_p (frame_type))
590 {
591 /* The call below will fill in the cache, including the frame
592 type. */
593 (void) rx_analyze_frame_prologue (this_frame, frame_type, this_cache);
594
595 return 1;
596 }
597 else
598 return 0;
599 }
600 else
601 {
602 struct rx_prologue *p = (struct rx_prologue *) *this_cache;
603
604 return sniff_p (p->frame_type);
605 }
606}
607
608/* Frame sniffer for normal (non-exception) frames. */
609
610static int
611rx_frame_sniffer (const struct frame_unwind *self,
612 frame_info_ptr this_frame,
613 void **this_cache)
614{
615 return rx_frame_sniffer_common (self, this_frame, this_cache,
617}
618
619/* Frame sniffer for exception frames. */
620
621static int
623 frame_info_ptr this_frame,
624 void **this_cache)
625{
626 return rx_frame_sniffer_common (self, this_frame, this_cache,
628}
629
630/* Data structure for normal code using instruction-based prologue
631 analyzer. */
632
633static const struct frame_unwind rx_frame_unwind = {
634 "rx prologue",
639 NULL,
641};
642
643/* Data structure for exception code using instruction-based prologue
644 analyzer. */
645
646static const struct frame_unwind rx_exception_unwind = {
647 "rx exception",
648 /* SIGTRAMP_FRAME could be used here, but backtraces are less informative. */
653 NULL,
655};
656
657/* Implement the "push_dummy_call" gdbarch method. */
658static CORE_ADDR
659rx_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
660 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
661 struct value **args, CORE_ADDR sp,
662 function_call_return_method return_method,
663 CORE_ADDR struct_addr)
664{
665 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
666 int write_pass;
667 int sp_off = 0;
668 CORE_ADDR cfa;
669 int num_register_candidate_args;
670
671 struct type *func_type = function->type ();
672
673 /* Dereference function pointer types. */
674 while (func_type->code () == TYPE_CODE_PTR)
675 func_type = func_type->target_type ();
676
677 /* The end result had better be a function or a method. */
678 gdb_assert (func_type->code () == TYPE_CODE_FUNC
679 || func_type->code () == TYPE_CODE_METHOD);
680
681 /* Functions with a variable number of arguments have all of their
682 variable arguments and the last non-variable argument passed
683 on the stack.
684
685 Otherwise, we can pass up to four arguments on the stack.
686
687 Once computed, we leave this value alone. I.e. we don't update
688 it in case of a struct return going in a register or an argument
689 requiring multiple registers, etc. We rely instead on the value
690 of the ``arg_reg'' variable to get these other details correct. */
691
692 if (func_type->has_varargs ())
693 num_register_candidate_args = func_type->num_fields () - 1;
694 else
695 num_register_candidate_args = 4;
696
697 /* We make two passes; the first does the stack allocation,
698 the second actually stores the arguments. */
699 for (write_pass = 0; write_pass <= 1; write_pass++)
700 {
701 int i;
702 int arg_reg = RX_R1_REGNUM;
703
704 if (write_pass)
705 sp = align_down (sp - sp_off, 4);
706 sp_off = 0;
707
708 if (return_method == return_method_struct)
709 {
710 struct type *return_type = func_type->target_type ();
711
712 gdb_assert (return_type->code () == TYPE_CODE_STRUCT
713 || func_type->code () == TYPE_CODE_UNION);
714
715 if (return_type->length () > 16
716 || return_type->length () % 4 != 0)
717 {
718 if (write_pass)
720 struct_addr);
721 }
722 }
723
724 /* Push the arguments. */
725 for (i = 0; i < nargs; i++)
726 {
727 struct value *arg = args[i];
728 const gdb_byte *arg_bits = arg->contents_all ().data ();
729 struct type *arg_type = check_typedef (arg->type ());
730 ULONGEST arg_size = arg_type->length ();
731
732 if (i == 0 && struct_addr != 0
733 && return_method != return_method_struct
734 && arg_type->code () == TYPE_CODE_PTR
735 && extract_unsigned_integer (arg_bits, 4,
736 byte_order) == struct_addr)
737 {
738 /* This argument represents the address at which C++ (and
739 possibly other languages) store their return value.
740 Put this value in R15. */
741 if (write_pass)
743 struct_addr);
744 }
745 else if (arg_type->code () != TYPE_CODE_STRUCT
746 && arg_type->code () != TYPE_CODE_UNION
747 && arg_size <= 8)
748 {
749 /* Argument is a scalar. */
750 if (arg_size == 8)
751 {
752 if (i < num_register_candidate_args
753 && arg_reg <= RX_R4_REGNUM - 1)
754 {
755 /* If argument registers are going to be used to pass
756 an 8 byte scalar, the ABI specifies that two registers
757 must be available. */
758 if (write_pass)
759 {
762 (arg_bits, 4,
763 byte_order));
765 arg_reg + 1,
767 (arg_bits + 4, 4,
768 byte_order));
769 }
770 arg_reg += 2;
771 }
772 else
773 {
774 sp_off = align_up (sp_off, 4);
775 /* Otherwise, pass the 8 byte scalar on the stack. */
776 if (write_pass)
777 write_memory (sp + sp_off, arg_bits, 8);
778 sp_off += 8;
779 }
780 }
781 else
782 {
783 ULONGEST u;
784
785 gdb_assert (arg_size <= 4);
786
787 u =
788 extract_unsigned_integer (arg_bits, arg_size, byte_order);
789
790 if (i < num_register_candidate_args
791 && arg_reg <= RX_R4_REGNUM)
792 {
793 if (write_pass)
795 arg_reg += 1;
796 }
797 else
798 {
799 int p_arg_size = 4;
800
801 if (func_type->is_prototyped ()
802 && i < func_type->num_fields ())
803 {
804 struct type *p_arg_type =
805 func_type->field (i).type ();
806 p_arg_size = p_arg_type->length ();
807 }
808
809 sp_off = align_up (sp_off, p_arg_size);
810
811 if (write_pass)
813 p_arg_size, byte_order,
814 u);
815 sp_off += p_arg_size;
816 }
817 }
818 }
819 else
820 {
821 /* Argument is a struct or union. Pass as much of the struct
822 in registers, if possible. Pass the rest on the stack. */
823 while (arg_size > 0)
824 {
825 if (i < num_register_candidate_args
826 && arg_reg <= RX_R4_REGNUM
827 && arg_size <= 4 * (RX_R4_REGNUM - arg_reg + 1)
828 && arg_size % 4 == 0)
829 {
830 int len = std::min (arg_size, (ULONGEST) 4);
831
832 if (write_pass)
835 (arg_bits, len,
836 byte_order));
837 arg_bits += len;
838 arg_size -= len;
839 arg_reg++;
840 }
841 else
842 {
843 sp_off = align_up (sp_off, 4);
844 if (write_pass)
845 write_memory (sp + sp_off, arg_bits, arg_size);
846 sp_off += align_up (arg_size, 4);
847 arg_size = 0;
848 }
849 }
850 }
851 }
852 }
853
854 /* Keep track of the stack address prior to pushing the return address.
855 This is the value that we'll return. */
856 cfa = sp;
857
858 /* Push the return address. */
859 sp = sp - 4;
860 write_memory_unsigned_integer (sp, 4, byte_order, bp_addr);
861
862 /* Update the stack pointer. */
864
865 return cfa;
866}
867
868/* Implement the "return_value" gdbarch method. */
869static enum return_value_convention
871 struct value *function,
872 struct type *valtype,
873 struct regcache *regcache,
874 gdb_byte *readbuf, const gdb_byte *writebuf)
875{
876 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
877 ULONGEST valtype_len = valtype->length ();
878
879 if (valtype->length () > 16
880 || ((valtype->code () == TYPE_CODE_STRUCT
881 || valtype->code () == TYPE_CODE_UNION)
882 && valtype->length () % 4 != 0))
884
885 if (readbuf)
886 {
887 ULONGEST u;
888 int argreg = RX_R1_REGNUM;
889 int offset = 0;
890
891 while (valtype_len > 0)
892 {
893 int len = std::min (valtype_len, (ULONGEST) 4);
894
896 store_unsigned_integer (readbuf + offset, len, byte_order, u);
897 valtype_len -= len;
898 offset += len;
899 argreg++;
900 }
901 }
902
903 if (writebuf)
904 {
905 ULONGEST u;
906 int argreg = RX_R1_REGNUM;
907 int offset = 0;
908
909 while (valtype_len > 0)
910 {
911 int len = std::min (valtype_len, (ULONGEST) 4);
912
913 u = extract_unsigned_integer (writebuf + offset, len, byte_order);
915 valtype_len -= len;
916 offset += len;
917 argreg++;
918 }
919 }
920
922}
923
924constexpr gdb_byte rx_break_insn[] = { 0x00 };
925
926typedef BP_MANIPULATION (rx_break_insn) rx_breakpoint;
927
928/* Implement the dwarf_reg_to_regnum" gdbarch method. */
929
930static int
931rx_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
932{
933 if (0 <= reg && reg <= 15)
934 return reg;
935 else if (reg == 16)
936 return RX_PSW_REGNUM;
937 else if (reg == 17)
938 return RX_PC_REGNUM;
939 else
940 return -1;
941}
942
943/* Allocate and initialize a gdbarch object. */
944static struct gdbarch *
946{
947 int elf_flags;
949 const struct target_desc *tdesc = info.target_desc;
950
951 /* Extract the elf_flags if available. */
952 if (info.abfd != NULL
953 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
954 elf_flags = elf_elfheader (info.abfd)->e_flags;
955 else
956 elf_flags = 0;
957
958
959 /* Try to find the architecture in the list of already defined
960 architectures. */
962 arches != NULL;
964 {
965 rx_gdbarch_tdep *tdep
966 = gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
967
968 if (tdep->elf_flags != elf_flags)
969 continue;
970
971 return arches->gdbarch;
972 }
973
974 if (tdesc == NULL)
975 tdesc = tdesc_rx;
976
977 /* Check any target description for validity. */
978 if (tdesc_has_registers (tdesc))
979 {
980 const struct tdesc_feature *feature;
981 bool valid_p = true;
982
983 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.rx.core");
984
985 if (feature != NULL)
986 {
988 for (int i = 0; i < RX_NUM_REGS; i++)
989 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
991 }
992
993 if (!valid_p)
994 return NULL;
995 }
996
997 gdb_assert(tdesc_data != NULL);
998
1001 rx_gdbarch_tdep *tdep = gdbarch_tdep<rx_gdbarch_tdep> (gdbarch);
1002
1003 tdep->elf_flags = elf_flags;
1004
1006 tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
1007
1013 set_gdbarch_breakpoint_kind_from_pc (gdbarch, rx_breakpoint::kind_from_pc);
1014 set_gdbarch_sw_breakpoint_from_kind (gdbarch, rx_breakpoint::bp_from_kind);
1016
1017 /* Target builtin data types. */
1026
1027 if (elf_flags & E_FLAG_RX_64BIT_DOUBLES)
1028 {
1033 }
1034 else
1035 {
1040 }
1041
1042 /* DWARF register mapping. */
1043 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rx_dwarf_reg_to_regnum);
1044
1045 /* Frame unwinding. */
1049
1050 /* Methods setting up a dummy call, and extracting the return value from
1051 a call. */
1054
1055 /* Virtual tables. */
1057
1058 return gdbarch;
1059}
1060
1061/* Register the above initialization routine. */
1062
1063void _initialize_rx_tdep ();
1064void
int regnum
const char *const name
void gdbarch_register(enum bfd_architecture bfd_architecture, gdbarch_init_ftype *init, gdbarch_dump_tdep_ftype *dump_tdep, gdbarch_supports_arch_info_ftype *supports_arch_info)
struct gdbarch * target_gdbarch(void)
static std::vector< const char * > arches
Definition arch-utils.c:685
int core_addr_lessthan(CORE_ADDR lhs, CORE_ADDR rhs)
Definition arch-utils.c:177
struct gdbarch_list * gdbarch_list_lookup_by_info(struct gdbarch_list *arches, const struct gdbarch_info *info)
#define BP_MANIPULATION(BREAK_INSN)
Definition arch-utils.h:70
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
void scan(void(*func)(void *closure, pv_t addr, CORE_ADDR size, pv_t value), void *closure)
void store(pv_t addr, CORE_ADDR size, pv_t value)
void * get(unsigned key)
Definition registry.h:211
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition corefile.c:347
void write_memory_unsigned_integer(CORE_ADDR addr, int len, enum bfd_endian byte_order, ULONGEST value)
Definition corefile.c:380
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
return_value_convention
Definition defs.h:257
@ RETURN_VALUE_REGISTER_CONVENTION
Definition defs.h:260
@ RETURN_VALUE_STRUCT_CONVENTION
Definition defs.h:267
void dwarf2_append_unwinders(struct gdbarch *gdbarch)
Definition frame.c:1369
struct value * frame_unwind_got_memory(frame_info_ptr frame, int regnum, CORE_ADDR addr)
struct value * frame_unwind_got_register(frame_info_ptr frame, int regnum, int new_regnum)
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
struct value * frame_unwind_got_constant(frame_info_ptr frame, int regnum, ULONGEST val)
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition frame.c:736
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
CORE_ADDR get_frame_func(frame_info_ptr this_frame)
Definition frame.c:1098
frame_type
Definition frame.h:184
@ NORMAL_FRAME
Definition frame.h:187
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition frame.h:825
void set_gdbarch_long_long_bit(struct gdbarch *gdbarch, int long_long_bit)
Definition gdbarch.c:1493
void set_gdbarch_char_signed(struct gdbarch *gdbarch, int char_signed)
Definition gdbarch.c:1786
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_breakpoint_kind_from_pc(struct gdbarch *gdbarch, gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc)
void set_gdbarch_skip_prologue(struct gdbarch *gdbarch, gdbarch_skip_prologue_ftype *skip_prologue)
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1739
void set_gdbarch_int_bit(struct gdbarch *gdbarch, int int_bit)
Definition gdbarch.c:1459
void set_gdbarch_return_value(struct gdbarch *gdbarch, gdbarch_return_value_ftype *return_value)
void set_gdbarch_decr_pc_after_break(struct gdbarch *gdbarch, CORE_ADDR decr_pc_after_break)
Definition gdbarch.c:2913
void set_gdbarch_double_bit(struct gdbarch *gdbarch, int double_bit)
Definition gdbarch.c:1612
void set_gdbarch_inner_than(struct gdbarch *gdbarch, gdbarch_inner_than_ftype *inner_than)
void set_gdbarch_sp_regnum(struct gdbarch *gdbarch, int sp_regnum)
Definition gdbarch.c:2047
void set_gdbarch_long_double_format(struct gdbarch *gdbarch, const struct floatformat **long_double_format)
Definition gdbarch.c:1663
void set_gdbarch_pc_regnum(struct gdbarch *gdbarch, int pc_regnum)
Definition gdbarch.c:2064
void set_gdbarch_float_bit(struct gdbarch *gdbarch, int float_bit)
Definition gdbarch.c:1578
void set_gdbarch_short_bit(struct gdbarch *gdbarch, int short_bit)
Definition gdbarch.c:1442
void set_gdbarch_num_pseudo_regs(struct gdbarch *gdbarch, int num_pseudo_regs)
Definition gdbarch.c:1958
void set_gdbarch_dwarf2_reg_to_regnum(struct gdbarch *gdbarch, gdbarch_dwarf2_reg_to_regnum_ftype *dwarf2_reg_to_regnum)
void set_gdbarch_long_bit(struct gdbarch *gdbarch, int long_bit)
Definition gdbarch.c:1476
void set_gdbarch_ptr_bit(struct gdbarch *gdbarch, int ptr_bit)
Definition gdbarch.c:1732
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition gdbarch.c:1941
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition gdbarch.c:1646
void set_gdbarch_sw_breakpoint_from_kind(struct gdbarch *gdbarch, gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind)
void set_gdbarch_double_format(struct gdbarch *gdbarch, const struct floatformat **double_format)
Definition gdbarch.c:1629
void set_gdbarch_float_format(struct gdbarch *gdbarch, const struct floatformat **float_format)
Definition gdbarch.c:1595
void set_gdbarch_push_dummy_call(struct gdbarch *gdbarch, gdbarch_push_dummy_call_ftype *push_dummy_call)
void set_gdbarch_vbit_in_delta(struct gdbarch *gdbarch, int vbit_in_delta)
Definition gdbarch.c:4051
struct gdbarch * gdbarch_alloc(const struct gdbarch_info *info, gdbarch_tdep_up tdep)
Definition gdbarch.c:266
std::unique_ptr< gdbarch_tdep_base > gdbarch_tdep_up
Definition gdbarch.h:73
function_call_return_method
Definition gdbarch.h:114
@ return_method_struct
Definition gdbarch.h:126
const struct floatformat * floatformats_ieee_single[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:85
const struct floatformat * floatformats_ieee_double[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:89
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
size_t size
Definition go32-nat.c:239
info(Component c)
Definition gdbarch.py:41
pv_t pv_register(int reg, CORE_ADDR k)
pv_t pv_add_constant(pv_t v, CORE_ADDR k)
int pv_is_register(pv_t a, int r)
@ pvk_register
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition regcache.c:796
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition regcache.c:825
static void check_for_saved(void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value)
Definition rx-tdep.c:138
static struct rx_prologue * rx_analyze_frame_prologue(frame_info_ptr this_frame, enum rx_frame_type frame_type, void **this_prologue_cache)
Definition rx-tdep.c:385
static void rx_frame_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
Definition rx-tdep.c:495
static CORE_ADDR rx_frame_base(frame_info_ptr this_frame, void **this_cache)
Definition rx-tdep.c:468
constexpr gdb_byte rx_break_insn[]
Definition rx-tdep.c:924
static enum return_value_convention rx_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
Definition rx-tdep.c:870
static int exception_frame_p(enum rx_frame_type frame_type)
Definition rx-tdep.c:569
static const struct frame_unwind rx_exception_unwind
Definition rx-tdep.c:646
static void rx_analyze_prologue(CORE_ADDR start_pc, CORE_ADDR limit_pc, enum rx_frame_type frame_type, struct rx_prologue *result)
Definition rx-tdep.c:182
static struct value * rx_frame_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
Definition rx-tdep.c:505
static int rx_frame_sniffer_common(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache, int(*sniff_p)(enum rx_frame_type))
Definition rx-tdep.c:578
static const char *const rx_register_names[]
Definition rx-tdep.c:123
rx_frame_type
Definition rx-tdep.c:65
@ RX_FRAME_TYPE_EXCEPTION
Definition rx-tdep.c:67
@ RX_FRAME_TYPE_FAST_INTERRUPT
Definition rx-tdep.c:68
@ RX_FRAME_TYPE_NORMAL
Definition rx-tdep.c:66
void _initialize_rx_tdep()
Definition rx-tdep.c:1065
static int normal_frame_p(enum rx_frame_type frame_type)
Definition rx-tdep.c:560
static const struct frame_unwind rx_frame_unwind
Definition rx-tdep.c:633
static struct gdbarch * rx_gdbarch_init(struct gdbarch_info info, struct gdbarch_list *arches)
Definition rx-tdep.c:945
@ RX_R15_REGNUM
Definition rx-tdep.c:53
@ RX_BPC_REGNUM
Definition rx-tdep.c:58
@ RX_BPSW_REGNUM
Definition rx-tdep.c:57
@ RX_ACC_REGNUM
Definition rx-tdep.c:60
@ RX_NUM_REGS
Definition rx-tdep.c:61
@ RX_R1_REGNUM
Definition rx-tdep.c:50
@ RX_SP_REGNUM
Definition rx-tdep.c:49
@ RX_PSW_REGNUM
Definition rx-tdep.c:55
@ RX_PC_REGNUM
Definition rx-tdep.c:56
@ RX_USP_REGNUM
Definition rx-tdep.c:54
@ RX_FP_REGNUM
Definition rx-tdep.c:52
@ RX_R4_REGNUM
Definition rx-tdep.c:51
@ RX_FPSW_REGNUM
Definition rx-tdep.c:59
static CORE_ADDR rx_push_dummy_call(struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, function_call_return_method return_method, CORE_ADDR struct_addr)
Definition rx-tdep.c:659
static int rx_get_opcode_byte(void *handle)
Definition rx-tdep.c:161
static int rx_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
Definition rx-tdep.c:611
static int rx_exception_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
Definition rx-tdep.c:622
static CORE_ADDR rx_skip_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition rx-tdep.c:363
static void initialize_tdesc_rx(void)
Definition rx.c:10
const struct target_desc * tdesc_rx
Definition rx.c:8
struct type * rx_fpsw_type
Definition rx-tdep.c:81
struct type * rx_psw_type
Definition rx-tdep.c:78
int frame_size
Definition rx-tdep.c:100
CORE_ADDR prologue_end
Definition rx-tdep.c:114
int reg_offset[RX_NUM_REGS]
Definition rx-tdep.c:119
int has_frame_ptr
Definition rx-tdep.c:104
int frame_ptr_offset
Definition rx-tdep.c:109
enum rx_frame_type frame_type
Definition rx-tdep.c:89
type_code code() const
Definition gdbtypes.h:956
ULONGEST length() const
Definition gdbtypes.h:983
unsigned int num_fields() const
Definition gdbtypes.h:994
Definition value.h:130
gdb::array_view< const gdb_byte > contents_all()
Definition value.c:1119
struct type * type() const
Definition value.h:180
struct value::@203::@204 reg
tdesc_arch_data_up tdesc_data_alloc(void)
const struct tdesc_feature * tdesc_find_feature(const struct target_desc *target_desc, const char *name)
int tdesc_numbered_register(const struct tdesc_feature *feature, struct tdesc_arch_data *data, int regno, const char *name)
static const registry< gdbarch >::key< tdesc_arch_data > tdesc_data
void tdesc_use_registers(struct gdbarch *gdbarch, const struct target_desc *target_desc, tdesc_arch_data_up &&early_data, tdesc_unknown_register_ftype unk_reg_cb)
int tdesc_has_registers(const struct target_desc *target_desc)
std::unique_ptr< tdesc_arch_data, tdesc_arch_data_deleter > tdesc_arch_data_up
int target_read_code(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1844