s390-vregs.exp: Avoid compile errors with older GCCs and on 31-bit targets
[binutils-gdb.git] / gdb / rx-tdep.c
blobaa44f7adc54601a70322d3e89326023a42d2b24f
1 /* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
3 Copyright (C) 2008-2015 Free Software Foundation, Inc.
5 Contributed by Red Hat, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "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"
37 #include "elf/rx.h"
38 #include "elf-bfd.h"
40 /* Certain important register numbers. */
41 enum
43 RX_SP_REGNUM = 0,
44 RX_R1_REGNUM = 1,
45 RX_R4_REGNUM = 4,
46 RX_FP_REGNUM = 6,
47 RX_R15_REGNUM = 15,
48 RX_PC_REGNUM = 19,
49 RX_ACC_REGNUM = 25,
50 RX_NUM_REGS = 26
53 /* Architecture specific data. */
54 struct gdbarch_tdep
56 /* The ELF header flags specify the multilib used. */
57 int elf_flags;
60 /* This structure holds the results of a prologue analysis. */
61 struct rx_prologue
63 /* The offset from the frame base to the stack pointer --- always
64 zero or negative.
66 Calling this a "size" is a bit misleading, but given that the
67 stack grows downwards, using offsets for everything keeps one
68 from going completely sign-crazy: you never change anything's
69 sign for an ADD instruction; always change the second operand's
70 sign for a SUB instruction; and everything takes care of
71 itself. */
72 int frame_size;
74 /* Non-zero if this function has initialized the frame pointer from
75 the stack pointer, zero otherwise. */
76 int has_frame_ptr;
78 /* If has_frame_ptr is non-zero, this is the offset from the frame
79 base to where the frame pointer points. This is always zero or
80 negative. */
81 int frame_ptr_offset;
83 /* The address of the first instruction at which the frame has been
84 set up and the arguments are where the debug info says they are
85 --- as best as we can tell. */
86 CORE_ADDR prologue_end;
88 /* reg_offset[R] is the offset from the CFA at which register R is
89 saved, or 1 if register R has not been saved. (Real values are
90 always zero or negative.) */
91 int reg_offset[RX_NUM_REGS];
94 /* Implement the "register_name" gdbarch method. */
95 static const char *
96 rx_register_name (struct gdbarch *gdbarch, int regnr)
98 static const char *const reg_names[] = {
99 "r0",
100 "r1",
101 "r2",
102 "r3",
103 "r4",
104 "r5",
105 "r6",
106 "r7",
107 "r8",
108 "r9",
109 "r10",
110 "r11",
111 "r12",
112 "r13",
113 "r14",
114 "r15",
115 "usp",
116 "isp",
117 "psw",
118 "pc",
119 "intb",
120 "bpsw",
121 "bpc",
122 "fintv",
123 "fpsw",
124 "acc"
127 return reg_names[regnr];
130 /* Implement the "register_type" gdbarch method. */
131 static struct type *
132 rx_register_type (struct gdbarch *gdbarch, int reg_nr)
134 if (reg_nr == RX_PC_REGNUM)
135 return builtin_type (gdbarch)->builtin_func_ptr;
136 else if (reg_nr == RX_ACC_REGNUM)
137 return builtin_type (gdbarch)->builtin_unsigned_long_long;
138 else
139 return builtin_type (gdbarch)->builtin_unsigned_long;
143 /* Function for finding saved registers in a 'struct pv_area'; this
144 function is passed to pv_area_scan.
146 If VALUE is a saved register, ADDR says it was saved at a constant
147 offset from the frame base, and SIZE indicates that the whole
148 register was saved, record its offset. */
149 static void
150 check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value)
152 struct rx_prologue *result = (struct rx_prologue *) result_untyped;
154 if (value.kind == pvk_register
155 && value.k == 0
156 && pv_is_register (addr, RX_SP_REGNUM)
157 && size == register_size (target_gdbarch (), value.reg))
158 result->reg_offset[value.reg] = addr.k;
161 /* Define a "handle" struct for fetching the next opcode. */
162 struct rx_get_opcode_byte_handle
164 CORE_ADDR pc;
167 /* Fetch a byte on behalf of the opcode decoder. HANDLE contains
168 the memory address of the next byte to fetch. If successful,
169 the address in the handle is updated and the byte fetched is
170 returned as the value of the function. If not successful, -1
171 is returned. */
172 static int
173 rx_get_opcode_byte (void *handle)
175 struct rx_get_opcode_byte_handle *opcdata = handle;
176 int status;
177 gdb_byte byte;
179 status = target_read_memory (opcdata->pc, &byte, 1);
180 if (status == 0)
182 opcdata->pc += 1;
183 return byte;
185 else
186 return -1;
189 /* Analyze a prologue starting at START_PC, going no further than
190 LIMIT_PC. Fill in RESULT as appropriate. */
191 static void
192 rx_analyze_prologue (CORE_ADDR start_pc,
193 CORE_ADDR limit_pc, struct rx_prologue *result)
195 CORE_ADDR pc, next_pc;
196 int rn;
197 pv_t reg[RX_NUM_REGS];
198 struct pv_area *stack;
199 struct cleanup *back_to;
200 CORE_ADDR after_last_frame_setup_insn = start_pc;
202 memset (result, 0, sizeof (*result));
204 for (rn = 0; rn < RX_NUM_REGS; rn++)
206 reg[rn] = pv_register (rn, 0);
207 result->reg_offset[rn] = 1;
210 stack = make_pv_area (RX_SP_REGNUM, gdbarch_addr_bit (target_gdbarch ()));
211 back_to = make_cleanup_free_pv_area (stack);
213 /* The call instruction has saved the return address on the stack. */
214 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
215 pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[RX_PC_REGNUM]);
217 pc = start_pc;
218 while (pc < limit_pc)
220 int bytes_read;
221 struct rx_get_opcode_byte_handle opcode_handle;
222 RX_Opcode_Decoded opc;
224 opcode_handle.pc = pc;
225 bytes_read = rx_decode_opcode (pc, &opc, rx_get_opcode_byte,
226 &opcode_handle);
227 next_pc = pc + bytes_read;
229 if (opc.id == RXO_pushm /* pushm r1, r2 */
230 && opc.op[1].type == RX_Operand_Register
231 && opc.op[2].type == RX_Operand_Register)
233 int r1, r2;
234 int r;
236 r1 = opc.op[1].reg;
237 r2 = opc.op[2].reg;
238 for (r = r2; r >= r1; r--)
240 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
241 pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[r]);
243 after_last_frame_setup_insn = next_pc;
245 else if (opc.id == RXO_mov /* mov.l rdst, rsrc */
246 && opc.op[0].type == RX_Operand_Register
247 && opc.op[1].type == RX_Operand_Register
248 && opc.size == RX_Long)
250 int rdst, rsrc;
252 rdst = opc.op[0].reg;
253 rsrc = opc.op[1].reg;
254 reg[rdst] = reg[rsrc];
255 if (rdst == RX_FP_REGNUM && rsrc == RX_SP_REGNUM)
256 after_last_frame_setup_insn = next_pc;
258 else if (opc.id == RXO_mov /* mov.l rsrc, [-SP] */
259 && opc.op[0].type == RX_Operand_Predec
260 && opc.op[0].reg == RX_SP_REGNUM
261 && opc.op[1].type == RX_Operand_Register
262 && opc.size == RX_Long)
264 int rsrc;
266 rsrc = opc.op[1].reg;
267 reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
268 pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[rsrc]);
269 after_last_frame_setup_insn = next_pc;
271 else if (opc.id == RXO_add /* add #const, rsrc, rdst */
272 && opc.op[0].type == RX_Operand_Register
273 && opc.op[1].type == RX_Operand_Immediate
274 && opc.op[2].type == RX_Operand_Register)
276 int rdst = opc.op[0].reg;
277 int addend = opc.op[1].addend;
278 int rsrc = opc.op[2].reg;
279 reg[rdst] = pv_add_constant (reg[rsrc], addend);
280 /* Negative adjustments to the stack pointer or frame pointer
281 are (most likely) part of the prologue. */
282 if ((rdst == RX_SP_REGNUM || rdst == RX_FP_REGNUM) && addend < 0)
283 after_last_frame_setup_insn = next_pc;
285 else if (opc.id == RXO_mov
286 && opc.op[0].type == RX_Operand_Indirect
287 && opc.op[1].type == RX_Operand_Register
288 && opc.size == RX_Long
289 && (opc.op[0].reg == RX_SP_REGNUM
290 || opc.op[0].reg == RX_FP_REGNUM)
291 && (RX_R1_REGNUM <= opc.op[1].reg
292 && opc.op[1].reg <= RX_R4_REGNUM))
294 /* This moves an argument register to the stack. Don't
295 record it, but allow it to be a part of the prologue. */
297 else if (opc.id == RXO_branch
298 && opc.op[0].type == RX_Operand_Immediate
299 && next_pc < opc.op[0].addend)
301 /* When a loop appears as the first statement of a function
302 body, gcc 4.x will use a BRA instruction to branch to the
303 loop condition checking code. This BRA instruction is
304 marked as part of the prologue. We therefore set next_pc
305 to this branch target and also stop the prologue scan.
306 The instructions at and beyond the branch target should
307 no longer be associated with the prologue.
309 Note that we only consider forward branches here. We
310 presume that a forward branch is being used to skip over
311 a loop body.
313 A backwards branch is covered by the default case below.
314 If we were to encounter a backwards branch, that would
315 most likely mean that we've scanned through a loop body.
316 We definitely want to stop the prologue scan when this
317 happens and that is precisely what is done by the default
318 case below. */
320 after_last_frame_setup_insn = opc.op[0].addend;
321 break; /* Scan no further if we hit this case. */
323 else
325 /* Terminate the prologue scan. */
326 break;
329 pc = next_pc;
332 /* Is the frame size (offset, really) a known constant? */
333 if (pv_is_register (reg[RX_SP_REGNUM], RX_SP_REGNUM))
334 result->frame_size = reg[RX_SP_REGNUM].k;
336 /* Was the frame pointer initialized? */
337 if (pv_is_register (reg[RX_FP_REGNUM], RX_SP_REGNUM))
339 result->has_frame_ptr = 1;
340 result->frame_ptr_offset = reg[RX_FP_REGNUM].k;
343 /* Record where all the registers were saved. */
344 pv_area_scan (stack, check_for_saved, (void *) result);
346 result->prologue_end = after_last_frame_setup_insn;
348 do_cleanups (back_to);
352 /* Implement the "skip_prologue" gdbarch method. */
353 static CORE_ADDR
354 rx_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
356 const char *name;
357 CORE_ADDR func_addr, func_end;
358 struct rx_prologue p;
360 /* Try to find the extent of the function that contains PC. */
361 if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
362 return pc;
364 rx_analyze_prologue (pc, func_end, &p);
365 return p.prologue_end;
368 /* Given a frame described by THIS_FRAME, decode the prologue of its
369 associated function if there is not cache entry as specified by
370 THIS_PROLOGUE_CACHE. Save the decoded prologue in the cache and
371 return that struct as the value of this function. */
372 static struct rx_prologue *
373 rx_analyze_frame_prologue (struct frame_info *this_frame,
374 void **this_prologue_cache)
376 if (!*this_prologue_cache)
378 CORE_ADDR func_start, stop_addr;
380 *this_prologue_cache = FRAME_OBSTACK_ZALLOC (struct rx_prologue);
382 func_start = get_frame_func (this_frame);
383 stop_addr = get_frame_pc (this_frame);
385 /* If we couldn't find any function containing the PC, then
386 just initialize the prologue cache, but don't do anything. */
387 if (!func_start)
388 stop_addr = func_start;
390 rx_analyze_prologue (func_start, stop_addr, *this_prologue_cache);
393 return *this_prologue_cache;
396 /* Given the next frame and a prologue cache, return this frame's
397 base. */
398 static CORE_ADDR
399 rx_frame_base (struct frame_info *this_frame, void **this_prologue_cache)
401 struct rx_prologue *p
402 = rx_analyze_frame_prologue (this_frame, this_prologue_cache);
404 /* In functions that use alloca, the distance between the stack
405 pointer and the frame base varies dynamically, so we can't use
406 the SP plus static information like prologue analysis to find the
407 frame base. However, such functions must have a frame pointer,
408 to be able to restore the SP on exit. So whenever we do have a
409 frame pointer, use that to find the base. */
410 if (p->has_frame_ptr)
412 CORE_ADDR fp = get_frame_register_unsigned (this_frame, RX_FP_REGNUM);
413 return fp - p->frame_ptr_offset;
415 else
417 CORE_ADDR sp = get_frame_register_unsigned (this_frame, RX_SP_REGNUM);
418 return sp - p->frame_size;
422 /* Implement the "frame_this_id" method for unwinding frames. */
423 static void
424 rx_frame_this_id (struct frame_info *this_frame,
425 void **this_prologue_cache, struct frame_id *this_id)
427 *this_id = frame_id_build (rx_frame_base (this_frame, this_prologue_cache),
428 get_frame_func (this_frame));
431 /* Implement the "frame_prev_register" method for unwinding frames. */
432 static struct value *
433 rx_frame_prev_register (struct frame_info *this_frame,
434 void **this_prologue_cache, int regnum)
436 struct rx_prologue *p
437 = rx_analyze_frame_prologue (this_frame, this_prologue_cache);
438 CORE_ADDR frame_base = rx_frame_base (this_frame, this_prologue_cache);
439 int reg_size = register_size (get_frame_arch (this_frame), regnum);
441 if (regnum == RX_SP_REGNUM)
442 return frame_unwind_got_constant (this_frame, regnum, frame_base);
444 /* If prologue analysis says we saved this register somewhere,
445 return a description of the stack slot holding it. */
446 else if (p->reg_offset[regnum] != 1)
447 return frame_unwind_got_memory (this_frame, regnum,
448 frame_base + p->reg_offset[regnum]);
450 /* Otherwise, presume we haven't changed the value of this
451 register, and get it from the next frame. */
452 else
453 return frame_unwind_got_register (this_frame, regnum, regnum);
456 static const struct frame_unwind rx_frame_unwind = {
457 NORMAL_FRAME,
458 default_frame_unwind_stop_reason,
459 rx_frame_this_id,
460 rx_frame_prev_register,
461 NULL,
462 default_frame_sniffer
465 /* Implement the "unwind_pc" gdbarch method. */
466 static CORE_ADDR
467 rx_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame)
469 ULONGEST pc;
471 pc = frame_unwind_register_unsigned (this_frame, RX_PC_REGNUM);
472 return pc;
475 /* Implement the "unwind_sp" gdbarch method. */
476 static CORE_ADDR
477 rx_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
479 ULONGEST sp;
481 sp = frame_unwind_register_unsigned (this_frame, RX_SP_REGNUM);
482 return sp;
485 /* Implement the "dummy_id" gdbarch method. */
486 static struct frame_id
487 rx_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
489 return
490 frame_id_build (get_frame_register_unsigned (this_frame, RX_SP_REGNUM),
491 get_frame_pc (this_frame));
494 /* Implement the "push_dummy_call" gdbarch method. */
495 static CORE_ADDR
496 rx_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
497 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
498 struct value **args, CORE_ADDR sp, int struct_return,
499 CORE_ADDR struct_addr)
501 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
502 int write_pass;
503 int sp_off = 0;
504 CORE_ADDR cfa;
505 int num_register_candidate_args;
507 struct type *func_type = value_type (function);
509 /* Dereference function pointer types. */
510 while (TYPE_CODE (func_type) == TYPE_CODE_PTR)
511 func_type = TYPE_TARGET_TYPE (func_type);
513 /* The end result had better be a function or a method. */
514 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
515 || TYPE_CODE (func_type) == TYPE_CODE_METHOD);
517 /* Functions with a variable number of arguments have all of their
518 variable arguments and the last non-variable argument passed
519 on the stack.
521 Otherwise, we can pass up to four arguments on the stack.
523 Once computed, we leave this value alone. I.e. we don't update
524 it in case of a struct return going in a register or an argument
525 requiring multiple registers, etc. We rely instead on the value
526 of the ``arg_reg'' variable to get these other details correct. */
528 if (TYPE_VARARGS (func_type))
529 num_register_candidate_args = TYPE_NFIELDS (func_type) - 1;
530 else
531 num_register_candidate_args = 4;
533 /* We make two passes; the first does the stack allocation,
534 the second actually stores the arguments. */
535 for (write_pass = 0; write_pass <= 1; write_pass++)
537 int i;
538 int arg_reg = RX_R1_REGNUM;
540 if (write_pass)
541 sp = align_down (sp - sp_off, 4);
542 sp_off = 0;
544 if (struct_return)
546 struct type *return_type = TYPE_TARGET_TYPE (func_type);
548 gdb_assert (TYPE_CODE (return_type) == TYPE_CODE_STRUCT
549 || TYPE_CODE (func_type) == TYPE_CODE_UNION);
551 if (TYPE_LENGTH (return_type) > 16
552 || TYPE_LENGTH (return_type) % 4 != 0)
554 if (write_pass)
555 regcache_cooked_write_unsigned (regcache, RX_R15_REGNUM,
556 struct_addr);
560 /* Push the arguments. */
561 for (i = 0; i < nargs; i++)
563 struct value *arg = args[i];
564 const gdb_byte *arg_bits = value_contents_all (arg);
565 struct type *arg_type = check_typedef (value_type (arg));
566 ULONGEST arg_size = TYPE_LENGTH (arg_type);
568 if (i == 0 && struct_addr != 0 && !struct_return
569 && TYPE_CODE (arg_type) == TYPE_CODE_PTR
570 && extract_unsigned_integer (arg_bits, 4,
571 byte_order) == struct_addr)
573 /* This argument represents the address at which C++ (and
574 possibly other languages) store their return value.
575 Put this value in R15. */
576 if (write_pass)
577 regcache_cooked_write_unsigned (regcache, RX_R15_REGNUM,
578 struct_addr);
580 else if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT
581 && TYPE_CODE (arg_type) != TYPE_CODE_UNION)
583 /* Argument is a scalar. */
584 if (arg_size == 8)
586 if (i < num_register_candidate_args
587 && arg_reg <= RX_R4_REGNUM - 1)
589 /* If argument registers are going to be used to pass
590 an 8 byte scalar, the ABI specifies that two registers
591 must be available. */
592 if (write_pass)
594 regcache_cooked_write_unsigned (regcache, arg_reg,
595 extract_unsigned_integer
596 (arg_bits, 4,
597 byte_order));
598 regcache_cooked_write_unsigned (regcache,
599 arg_reg + 1,
600 extract_unsigned_integer
601 (arg_bits + 4, 4,
602 byte_order));
604 arg_reg += 2;
606 else
608 sp_off = align_up (sp_off, 4);
609 /* Otherwise, pass the 8 byte scalar on the stack. */
610 if (write_pass)
611 write_memory (sp + sp_off, arg_bits, 8);
612 sp_off += 8;
615 else
617 ULONGEST u;
619 gdb_assert (arg_size <= 4);
622 extract_unsigned_integer (arg_bits, arg_size, byte_order);
624 if (i < num_register_candidate_args
625 && arg_reg <= RX_R4_REGNUM)
627 if (write_pass)
628 regcache_cooked_write_unsigned (regcache, arg_reg, u);
629 arg_reg += 1;
631 else
633 int p_arg_size = 4;
635 if (TYPE_PROTOTYPED (func_type)
636 && i < TYPE_NFIELDS (func_type))
638 struct type *p_arg_type =
639 TYPE_FIELD_TYPE (func_type, i);
640 p_arg_size = TYPE_LENGTH (p_arg_type);
643 sp_off = align_up (sp_off, p_arg_size);
645 if (write_pass)
646 write_memory_unsigned_integer (sp + sp_off,
647 p_arg_size, byte_order,
649 sp_off += p_arg_size;
653 else
655 /* Argument is a struct or union. Pass as much of the struct
656 in registers, if possible. Pass the rest on the stack. */
657 while (arg_size > 0)
659 if (i < num_register_candidate_args
660 && arg_reg <= RX_R4_REGNUM
661 && arg_size <= 4 * (RX_R4_REGNUM - arg_reg + 1)
662 && arg_size % 4 == 0)
664 int len = min (arg_size, 4);
666 if (write_pass)
667 regcache_cooked_write_unsigned (regcache, arg_reg,
668 extract_unsigned_integer
669 (arg_bits, len,
670 byte_order));
671 arg_bits += len;
672 arg_size -= len;
673 arg_reg++;
675 else
677 sp_off = align_up (sp_off, 4);
678 if (write_pass)
679 write_memory (sp + sp_off, arg_bits, arg_size);
680 sp_off += align_up (arg_size, 4);
681 arg_size = 0;
688 /* Keep track of the stack address prior to pushing the return address.
689 This is the value that we'll return. */
690 cfa = sp;
692 /* Push the return address. */
693 sp = sp - 4;
694 write_memory_unsigned_integer (sp, 4, byte_order, bp_addr);
696 /* Update the stack pointer. */
697 regcache_cooked_write_unsigned (regcache, RX_SP_REGNUM, sp);
699 return cfa;
702 /* Implement the "return_value" gdbarch method. */
703 static enum return_value_convention
704 rx_return_value (struct gdbarch *gdbarch,
705 struct value *function,
706 struct type *valtype,
707 struct regcache *regcache,
708 gdb_byte *readbuf, const gdb_byte *writebuf)
710 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
711 ULONGEST valtype_len = TYPE_LENGTH (valtype);
713 if (TYPE_LENGTH (valtype) > 16
714 || ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
715 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
716 && TYPE_LENGTH (valtype) % 4 != 0))
717 return RETURN_VALUE_STRUCT_CONVENTION;
719 if (readbuf)
721 ULONGEST u;
722 int argreg = RX_R1_REGNUM;
723 int offset = 0;
725 while (valtype_len > 0)
727 int len = min (valtype_len, 4);
729 regcache_cooked_read_unsigned (regcache, argreg, &u);
730 store_unsigned_integer (readbuf + offset, len, byte_order, u);
731 valtype_len -= len;
732 offset += len;
733 argreg++;
737 if (writebuf)
739 ULONGEST u;
740 int argreg = RX_R1_REGNUM;
741 int offset = 0;
743 while (valtype_len > 0)
745 int len = min (valtype_len, 4);
747 u = extract_unsigned_integer (writebuf + offset, len, byte_order);
748 regcache_cooked_write_unsigned (regcache, argreg, u);
749 valtype_len -= len;
750 offset += len;
751 argreg++;
755 return RETURN_VALUE_REGISTER_CONVENTION;
758 /* Implement the "breakpoint_from_pc" gdbarch method. */
759 static const gdb_byte *
760 rx_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
762 static gdb_byte breakpoint[] = { 0x00 };
763 *lenptr = sizeof breakpoint;
764 return breakpoint;
767 /* Allocate and initialize a gdbarch object. */
768 static struct gdbarch *
769 rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
771 struct gdbarch *gdbarch;
772 struct gdbarch_tdep *tdep;
773 int elf_flags;
775 /* Extract the elf_flags if available. */
776 if (info.abfd != NULL
777 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
778 elf_flags = elf_elfheader (info.abfd)->e_flags;
779 else
780 elf_flags = 0;
783 /* Try to find the architecture in the list of already defined
784 architectures. */
785 for (arches = gdbarch_list_lookup_by_info (arches, &info);
786 arches != NULL;
787 arches = gdbarch_list_lookup_by_info (arches->next, &info))
789 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
790 continue;
792 return arches->gdbarch;
795 /* None found, create a new architecture from the information
796 provided. */
797 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
798 gdbarch = gdbarch_alloc (&info, tdep);
799 tdep->elf_flags = elf_flags;
801 set_gdbarch_num_regs (gdbarch, RX_NUM_REGS);
802 set_gdbarch_num_pseudo_regs (gdbarch, 0);
803 set_gdbarch_register_name (gdbarch, rx_register_name);
804 set_gdbarch_register_type (gdbarch, rx_register_type);
805 set_gdbarch_pc_regnum (gdbarch, RX_PC_REGNUM);
806 set_gdbarch_sp_regnum (gdbarch, RX_SP_REGNUM);
807 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
808 set_gdbarch_decr_pc_after_break (gdbarch, 1);
809 set_gdbarch_breakpoint_from_pc (gdbarch, rx_breakpoint_from_pc);
810 set_gdbarch_skip_prologue (gdbarch, rx_skip_prologue);
812 set_gdbarch_print_insn (gdbarch, print_insn_rx);
814 set_gdbarch_unwind_pc (gdbarch, rx_unwind_pc);
815 set_gdbarch_unwind_sp (gdbarch, rx_unwind_sp);
817 /* Target builtin data types. */
818 set_gdbarch_char_signed (gdbarch, 0);
819 set_gdbarch_short_bit (gdbarch, 16);
820 set_gdbarch_int_bit (gdbarch, 32);
821 set_gdbarch_long_bit (gdbarch, 32);
822 set_gdbarch_long_long_bit (gdbarch, 64);
823 set_gdbarch_ptr_bit (gdbarch, 32);
824 set_gdbarch_float_bit (gdbarch, 32);
825 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
826 if (elf_flags & E_FLAG_RX_64BIT_DOUBLES)
828 set_gdbarch_double_bit (gdbarch, 64);
829 set_gdbarch_long_double_bit (gdbarch, 64);
830 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
831 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
833 else
835 set_gdbarch_double_bit (gdbarch, 32);
836 set_gdbarch_long_double_bit (gdbarch, 32);
837 set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
838 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_single);
841 /* Frame unwinding. */
842 #if 0
843 /* Note: The test results are better with the dwarf2 unwinder disabled,
844 so it's turned off for now. */
845 dwarf2_append_unwinders (gdbarch);
846 #endif
847 frame_unwind_append_unwinder (gdbarch, &rx_frame_unwind);
849 /* Methods for saving / extracting a dummy frame's ID.
850 The ID's stack address must match the SP value returned by
851 PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
852 set_gdbarch_dummy_id (gdbarch, rx_dummy_id);
853 set_gdbarch_push_dummy_call (gdbarch, rx_push_dummy_call);
854 set_gdbarch_return_value (gdbarch, rx_return_value);
856 /* Virtual tables. */
857 set_gdbarch_vbit_in_delta (gdbarch, 1);
859 return gdbarch;
862 /* -Wmissing-prototypes */
863 extern initialize_file_ftype _initialize_rx_tdep;
865 /* Register the above initialization routine. */
867 void
868 _initialize_rx_tdep (void)
870 register_gdbarch_init (bfd_arch_rx, rx_gdbarch_init);