1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "arch-utils.h"
28 #include "gdb_string.h"
29 #include "gdb_assert.h"
30 #include "gdbcore.h" /* for write_memory_unsigned_integer */
34 #include "frame-unwind.h"
35 #include "frame-base.h"
36 #include "trad-frame.h"
38 #include "dwarf2-frame.h"
41 #include "mn10300-tdep.h"
44 extern struct trad_frame_cache
*mn10300_frame_unwind_cache (struct frame_info
*,
47 /* Compute the alignment required by a type. */
50 mn10300_type_align (struct type
*type
)
54 switch (TYPE_CODE (type
))
65 return TYPE_LENGTH (type
);
67 case TYPE_CODE_COMPLEX
:
68 return TYPE_LENGTH (type
) / 2;
70 case TYPE_CODE_STRUCT
:
72 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
74 int falign
= mn10300_type_align (TYPE_FIELD_TYPE (type
, i
));
75 while (align
< falign
)
81 /* HACK! Structures containing arrays, even small ones, are not
82 elligible for returning in registers. */
85 case TYPE_CODE_TYPEDEF
:
86 return mn10300_type_align (check_typedef (type
));
89 internal_error (__FILE__
, __LINE__
, _("bad switch"));
93 /* Should call_function allocate stack space for a struct return? */
95 mn10300_use_struct_convention (struct type
*type
)
97 /* Structures bigger than a pair of words can't be returned in
99 if (TYPE_LENGTH (type
) > 8)
102 switch (TYPE_CODE (type
))
104 case TYPE_CODE_STRUCT
:
105 case TYPE_CODE_UNION
:
106 /* Structures with a single field are handled as the field
108 if (TYPE_NFIELDS (type
) == 1)
109 return mn10300_use_struct_convention (TYPE_FIELD_TYPE (type
, 0));
111 /* Structures with word or double-word size are passed in memory, as
112 long as they require at least word alignment. */
113 if (mn10300_type_align (type
) >= 4)
118 /* Arrays are addressable, so they're never returned in
119 registers. This condition can only hold when the array is
120 the only field of a struct or union. */
121 case TYPE_CODE_ARRAY
:
124 case TYPE_CODE_TYPEDEF
:
125 return mn10300_use_struct_convention (check_typedef (type
));
133 mn10300_store_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
134 struct regcache
*regcache
, const void *valbuf
)
136 int len
= TYPE_LENGTH (type
);
139 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
144 regsz
= register_size (gdbarch
, reg
);
147 regcache_raw_write_part (regcache
, reg
, 0, len
, valbuf
);
148 else if (len
<= 2 * regsz
)
150 regcache_raw_write (regcache
, reg
, valbuf
);
151 gdb_assert (regsz
== register_size (gdbarch
, reg
+ 1));
152 regcache_raw_write_part (regcache
, reg
+1, 0,
153 len
- regsz
, (char *) valbuf
+ regsz
);
156 internal_error (__FILE__
, __LINE__
,
157 _("Cannot store return value %d bytes long."), len
);
161 mn10300_extract_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
162 struct regcache
*regcache
, void *valbuf
)
164 char buf
[MAX_REGISTER_SIZE
];
165 int len
= TYPE_LENGTH (type
);
168 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
173 regsz
= register_size (gdbarch
, reg
);
176 regcache_raw_read (regcache
, reg
, buf
);
177 memcpy (valbuf
, buf
, len
);
179 else if (len
<= 2 * regsz
)
181 regcache_raw_read (regcache
, reg
, buf
);
182 memcpy (valbuf
, buf
, regsz
);
183 gdb_assert (regsz
== register_size (gdbarch
, reg
+ 1));
184 regcache_raw_read (regcache
, reg
+ 1, buf
);
185 memcpy ((char *) valbuf
+ regsz
, buf
, len
- regsz
);
188 internal_error (__FILE__
, __LINE__
,
189 _("Cannot extract return value %d bytes long."), len
);
192 /* Determine, for architecture GDBARCH, how a return value of TYPE
193 should be returned. If it is supposed to be returned in registers,
194 and READBUF is non-zero, read the appropriate value from REGCACHE,
195 and copy it into READBUF. If WRITEBUF is non-zero, write the value
196 from WRITEBUF into REGCACHE. */
198 static enum return_value_convention
199 mn10300_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
200 struct regcache
*regcache
, gdb_byte
*readbuf
,
201 const gdb_byte
*writebuf
)
203 if (mn10300_use_struct_convention (type
))
204 return RETURN_VALUE_STRUCT_CONVENTION
;
207 mn10300_extract_return_value (gdbarch
, type
, regcache
, readbuf
);
209 mn10300_store_return_value (gdbarch
, type
, regcache
, writebuf
);
211 return RETURN_VALUE_REGISTER_CONVENTION
;
215 register_name (int reg
, char **regs
, long sizeof_regs
)
217 if (reg
< 0 || reg
>= sizeof_regs
/ sizeof (regs
[0]))
224 mn10300_generic_register_name (int reg
)
226 static char *regs
[] =
227 { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
228 "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
229 "", "", "", "", "", "", "", "",
230 "", "", "", "", "", "", "", "fp"
232 return register_name (reg
, regs
, sizeof regs
);
237 am33_register_name (int reg
)
239 static char *regs
[] =
240 { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
241 "sp", "pc", "mdr", "psw", "lir", "lar", "",
242 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
243 "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", ""
245 return register_name (reg
, regs
, sizeof regs
);
249 am33_2_register_name (int reg
)
251 static char *regs
[] =
253 "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
254 "sp", "pc", "mdr", "psw", "lir", "lar", "mdrq", "r0",
255 "r1", "r2", "r3", "r4", "r5", "r6", "r7", "ssp",
256 "msp", "usp", "mcrh", "mcrl", "mcvf", "fpcr", "", "",
257 "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
258 "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15",
259 "fs16", "fs17", "fs18", "fs19", "fs20", "fs21", "fs22", "fs23",
260 "fs24", "fs25", "fs26", "fs27", "fs28", "fs29", "fs30", "fs31"
262 return register_name (reg
, regs
, sizeof regs
);
266 mn10300_register_type (struct gdbarch
*gdbarch
, int reg
)
268 return builtin_type_int
;
272 mn10300_read_pc (ptid_t ptid
)
274 return read_register_pid (E_PC_REGNUM
, ptid
);
278 mn10300_write_pc (CORE_ADDR val
, ptid_t ptid
)
280 return write_register_pid (E_PC_REGNUM
, val
, ptid
);
283 /* The breakpoint instruction must be the same size as the smallest
284 instruction in the instruction set.
286 The Matsushita mn10x00 processors have single byte instructions
287 so we need a single byte breakpoint. Matsushita hasn't defined
288 one, so we defined it ourselves. */
290 const static unsigned char *
291 mn10300_breakpoint_from_pc (CORE_ADDR
*bp_addr
, int *bp_size
)
293 static char breakpoint
[] = {0xff};
298 /* Set offsets of saved registers.
299 This is a helper function for mn10300_analyze_prologue. */
302 set_reg_offsets (struct frame_info
*fi
,
306 int stack_extra_size
,
309 struct trad_frame_cache
*cache
;
313 if (fi
== NULL
|| this_cache
== NULL
)
316 cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
322 base
= frame_unwind_register_unsigned (fi
, E_A3_REGNUM
);
326 base
= frame_unwind_register_unsigned (fi
, E_SP_REGNUM
) + stack_extra_size
;
329 trad_frame_set_this_base (cache
, base
);
333 /* If bit N is set in fpregmask, fsN is saved on the stack.
334 The floating point registers are saved in ascending order.
335 For example: fs16 <- Frame Pointer
336 fs17 Frame Pointer + 4 */
340 for (i
= 0; i
< 32; i
++)
342 if (fpregmask
& (1 << i
))
344 trad_frame_set_reg_addr (cache
, E_FS0_REGNUM
+ i
, base
+ offset
);
352 if (movm_args
& movm_other_bit
)
354 /* The `other' bit leaves a blank area of four bytes at the
355 beginning of its block of saved registers, making it 32 bytes
357 trad_frame_set_reg_addr (cache
, E_LAR_REGNUM
, base
+ offset
+ 4);
358 trad_frame_set_reg_addr (cache
, E_LIR_REGNUM
, base
+ offset
+ 8);
359 trad_frame_set_reg_addr (cache
, E_MDR_REGNUM
, base
+ offset
+ 12);
360 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
+ 1, base
+ offset
+ 16);
361 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
, base
+ offset
+ 20);
362 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
+ 1, base
+ offset
+ 24);
363 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
, base
+ offset
+ 28);
367 if (movm_args
& movm_a3_bit
)
369 trad_frame_set_reg_addr (cache
, E_A3_REGNUM
, base
+ offset
);
372 if (movm_args
& movm_a2_bit
)
374 trad_frame_set_reg_addr (cache
, E_A2_REGNUM
, base
+ offset
);
377 if (movm_args
& movm_d3_bit
)
379 trad_frame_set_reg_addr (cache
, E_D3_REGNUM
, base
+ offset
);
382 if (movm_args
& movm_d2_bit
)
384 trad_frame_set_reg_addr (cache
, E_D2_REGNUM
, base
+ offset
);
389 if (movm_args
& movm_exother_bit
)
391 trad_frame_set_reg_addr (cache
, E_MCVF_REGNUM
, base
+ offset
);
392 trad_frame_set_reg_addr (cache
, E_MCRL_REGNUM
, base
+ offset
+ 4);
393 trad_frame_set_reg_addr (cache
, E_MCRH_REGNUM
, base
+ offset
+ 8);
394 trad_frame_set_reg_addr (cache
, E_MDRQ_REGNUM
, base
+ offset
+ 12);
395 trad_frame_set_reg_addr (cache
, E_E1_REGNUM
, base
+ offset
+ 16);
396 trad_frame_set_reg_addr (cache
, E_E0_REGNUM
, base
+ offset
+ 20);
399 if (movm_args
& movm_exreg1_bit
)
401 trad_frame_set_reg_addr (cache
, E_E7_REGNUM
, base
+ offset
);
402 trad_frame_set_reg_addr (cache
, E_E6_REGNUM
, base
+ offset
+ 4);
403 trad_frame_set_reg_addr (cache
, E_E5_REGNUM
, base
+ offset
+ 8);
404 trad_frame_set_reg_addr (cache
, E_E4_REGNUM
, base
+ offset
+ 12);
407 if (movm_args
& movm_exreg0_bit
)
409 trad_frame_set_reg_addr (cache
, E_E3_REGNUM
, base
+ offset
);
410 trad_frame_set_reg_addr (cache
, E_E2_REGNUM
, base
+ offset
+ 4);
414 /* The last (or first) thing on the stack will be the PC. */
415 trad_frame_set_reg_addr (cache
, E_PC_REGNUM
, base
+ offset
);
416 /* Save the SP in the 'traditional' way.
417 This will be the same location where the PC is saved. */
418 trad_frame_set_reg_value (cache
, E_SP_REGNUM
, base
+ offset
);
421 /* The main purpose of this file is dealing with prologues to extract
422 information about stack frames and saved registers.
424 In gcc/config/mn13000/mn10300.c, the expand_prologue prologue
425 function is pretty readable, and has a nice explanation of how the
426 prologue is generated. The prologues generated by that code will
427 have the following form (NOTE: the current code doesn't handle all
430 + If this is an old-style varargs function, then its arguments
431 need to be flushed back to the stack:
436 + If we use any of the callee-saved registers, save them now.
438 movm [some callee-saved registers],(sp)
440 + If we have any floating-point registers to save:
442 - Decrement the stack pointer to reserve space for the registers.
443 If the function doesn't need a frame pointer, we may combine
444 this with the adjustment that reserves space for the frame.
448 - Save the floating-point registers. We have two possible
451 . Save them at fixed offset from the SP:
453 fmov fsN,(OFFSETN,sp)
454 fmov fsM,(OFFSETM,sp)
457 Note that, if OFFSETN happens to be zero, you'll get the
458 different opcode: fmov fsN,(sp)
460 . Or, set a0 to the start of the save area, and then use
461 post-increment addressing to save the FP registers.
469 + If the function needs a frame pointer, we set it here.
473 + Now we reserve space for the stack frame proper. This could be
474 merged into the `add -SIZE, sp' instruction for FP saves up
475 above, unless we needed to set the frame pointer in the previous
476 step, or the frame is so large that allocating the whole thing at
477 once would put the FP register save slots out of reach of the
478 addressing mode (128 bytes).
482 One day we might keep the stack pointer constant, that won't
483 change the code for prologues, but it will make the frame
484 pointerless case much more common. */
486 /* Analyze the prologue to determine where registers are saved,
487 the end of the prologue, etc etc. Return the end of the prologue
490 We store into FI (if non-null) several tidbits of information:
492 * stack_size -- size of this stack frame. Note that if we stop in
493 certain parts of the prologue/epilogue we may claim the size of the
494 current frame is zero. This happens when the current frame has
495 not been allocated yet or has already been deallocated.
497 * fsr -- Addresses of registers saved in the stack by this frame.
499 * status -- A (relatively) generic status indicator. It's a bitmask
500 with the following bits:
502 MY_FRAME_IN_SP: The base of the current frame is actually in
503 the stack pointer. This can happen for frame pointerless
504 functions, or cases where we're stopped in the prologue/epilogue
505 itself. For these cases mn10300_analyze_prologue will need up
506 update fi->frame before returning or analyzing the register
509 MY_FRAME_IN_FP: The base of the current frame is in the
510 frame pointer register ($a3).
512 NO_MORE_FRAMES: Set this if the current frame is "start" or
513 if the first instruction looks like mov <imm>,sp. This tells
514 frame chain to not bother trying to unwind past this frame. */
517 mn10300_analyze_prologue (struct frame_info
*fi
,
521 CORE_ADDR func_addr
, func_end
, addr
, stop
;
522 long stack_extra_size
= 0;
524 unsigned char buf
[4];
531 /* Use the PC in the frame if it's provided to look up the
532 start of this function.
534 Note: kevinb/2003-07-16: We used to do the following here:
535 pc = (fi ? get_frame_pc (fi) : pc);
536 But this is (now) badly broken when called from analyze_dummy_frame().
540 pc
= (pc
? pc
: get_frame_pc (fi
));
543 /* Find the start of this function. */
544 status
= find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
);
546 /* Do nothing if we couldn't find the start of this function
548 MVS: comment went on to say "or if we're stopped at the first
549 instruction in the prologue" -- but code doesn't reflect that,
550 and I don't want to do that anyway. */
554 goto finish_prologue
;
557 /* If we're in start, then give up. */
558 if (strcmp (name
, "start") == 0)
561 goto finish_prologue
;
564 /* Figure out where to stop scanning. */
565 stop
= fi
? pc
: func_end
;
567 /* Don't walk off the end of the function. */
568 stop
= stop
> func_end
? func_end
: stop
;
570 /* Start scanning on the first instruction of this function. */
573 /* Suck in two bytes. */
574 if (addr
+ 2 > stop
|| !safe_frame_unwind_memory (fi
, addr
, buf
, 2))
575 goto finish_prologue
;
577 /* First see if this insn sets the stack pointer from a register; if
578 so, it's probably the initialization of the stack pointer in _start,
579 so mark this as the bottom-most frame. */
580 if (buf
[0] == 0xf2 && (buf
[1] & 0xf3) == 0xf0)
582 goto finish_prologue
;
585 /* Now look for movm [regs],sp, which saves the callee saved registers.
587 At this time we don't know if fi->frame is valid, so we only note
588 that we encountered a movm instruction. Later, we'll set the entries
589 in fsr.regs as needed. */
592 /* Extract the register list for the movm instruction. */
597 /* Quit now if we're beyond the stop point. */
599 goto finish_prologue
;
601 /* Get the next two bytes so the prologue scan can continue. */
602 if (!safe_frame_unwind_memory (fi
, addr
, buf
, 2))
603 goto finish_prologue
;
608 /* Determine if any floating point registers are to be saved.
609 Look for one of the following three prologue formats:
611 [movm [regs],(sp)] [movm [regs],(sp)] [movm [regs],(sp)]
613 add -SIZE,sp add -SIZE,sp add -SIZE,sp
614 fmov fs#,(sp) mov sp,a0/a1 mov sp,a0/a1
615 fmov fs#,(#,sp) fmov fs#,(a0/a1+) add SIZE2,a0/a1
616 ... ... fmov fs#,(a0/a1+)
618 fmov fs#,(#,sp) fmov fs#,(a0/a1+) fmov fs#,(a0/a1+)
620 [mov sp,a3] [mov sp,a3]
621 [add -SIZE2,sp] [add -SIZE2,sp] */
623 /* First, look for add -SIZE,sp (i.e. add imm8,sp (0xf8feXX)
624 or add imm16,sp (0xfafeXXXX)
625 or add imm32,sp (0xfcfeXXXXXXXX)) */
627 if (buf
[0] == 0xf8 && buf
[1] == 0xfe)
629 else if (buf
[0] == 0xfa && buf
[1] == 0xfe)
631 else if (buf
[0] == 0xfc && buf
[1] == 0xfe)
635 /* An "add -#,sp" instruction has been found. "addr + 2 + imm_size"
636 is the address of the next instruction. Don't modify "addr" until
637 the next "floating point prologue" instruction is found. If this
638 is not a prologue that saves floating point registers we need to
639 be able to back out of this bit of code and continue with the
640 prologue analysis. */
641 if (addr
+ 2 + imm_size
< stop
)
643 if (!safe_frame_unwind_memory (fi
, addr
+ 2 + imm_size
, buf
, 3))
644 goto finish_prologue
;
645 if ((buf
[0] & 0xfc) == 0x3c)
647 /* Occasionally, especially with C++ code, the "fmov"
648 instructions will be preceded by "mov sp,aN"
649 (aN => a0, a1, a2, or a3).
651 This is a one byte instruction: mov sp,aN = 0011 11XX
652 where XX is the register number.
654 Skip this instruction by incrementing addr. (We're
655 committed now.) The "fmov" instructions will have the
656 form "fmov fs#,(aN+)" in this case, but that will not
657 necessitate a change in the "fmov" parsing logic below. */
661 if ((buf
[1] & 0xfc) == 0x20)
663 /* Occasionally, especially with C++ code compiled with
664 the -fomit-frame-pointer or -O3 options, the
665 "mov sp,aN" instruction will be followed by an
666 "add #,aN" instruction. This indicates the
667 "stack_size", the size of the portion of the stack
668 containing the arguments. This instruction format is:
669 add #,aN = 0010 00XX YYYY YYYY
670 where XX is the register number
671 YYYY YYYY is the constant.
672 Note the size of the stack (as a negative number) in
673 the frame info structure. */
675 stack_extra_size
+= -buf
[2];
681 if ((buf
[0] & 0xfc) == 0x3c ||
682 buf
[0] == 0xf9 || buf
[0] == 0xfb)
684 /* An "fmov" instruction has been found indicating that this
685 prologue saves floating point registers (or, as described
686 above, a "mov sp,aN" and possible "add #,aN" have been
687 found and we will assume an "fmov" follows). Process the
688 consecutive "fmov" instructions. */
689 for (addr
+= 2 + imm_size
;;addr
+= imm_size
)
693 /* Read the "fmov" instruction. */
695 !safe_frame_unwind_memory (fi
, addr
, buf
, 4))
696 goto finish_prologue
;
698 if (buf
[0] != 0xf9 && buf
[0] != 0xfb)
701 /* Get the floating point register number from the
702 2nd and 3rd bytes of the "fmov" instruction:
703 Machine Code: 0000 00X0 YYYY 0000 =>
705 regnum
= (buf
[1] & 0x02) << 3;
706 regnum
|= ((buf
[2] & 0xf0) >> 4) & 0x0f;
708 /* Add this register number to the bit mask of floating
709 point registers that have been saved. */
710 fpregmask
|= 1 << regnum
;
712 /* Determine the length of this "fmov" instruction.
713 fmov fs#,(sp) => 3 byte instruction
714 fmov fs#,(#,sp) => 4 byte instruction */
715 imm_size
= (buf
[0] == 0xf9) ? 3 : 4;
720 /* No "fmov" was found. Reread the two bytes at the original
721 "addr" to reset the state. */
722 if (!safe_frame_unwind_memory (fi
, addr
, buf
, 2))
723 goto finish_prologue
;
726 /* else the prologue consists entirely of an "add -SIZE,sp"
727 instruction. Handle this below. */
729 /* else no "add -SIZE,sp" was found indicating no floating point
730 registers are saved in this prologue. Do not increment addr. Pretend
731 this bit of code never happened. */
734 /* Now see if we set up a frame pointer via "mov sp,a3" */
739 /* The frame pointer is now valid. */
745 /* Quit now if we're beyond the stop point. */
747 goto finish_prologue
;
749 /* Get two more bytes so scanning can continue. */
750 if (!safe_frame_unwind_memory (fi
, addr
, buf
, 2))
751 goto finish_prologue
;
754 /* Next we should allocate the local frame. No more prologue insns
755 are found after allocating the local frame.
757 Search for add imm8,sp (0xf8feXX)
758 or add imm16,sp (0xfafeXXXX)
759 or add imm32,sp (0xfcfeXXXXXXXX).
761 If none of the above was found, then this prologue has no
765 if (buf
[0] == 0xf8 && buf
[1] == 0xfe)
767 else if (buf
[0] == 0xfa && buf
[1] == 0xfe)
769 else if (buf
[0] == 0xfc && buf
[1] == 0xfe)
774 /* Suck in imm_size more bytes, they'll hold the size of the
776 if (!safe_frame_unwind_memory (fi
, addr
+ 2, buf
, imm_size
))
777 goto finish_prologue
;
779 /* Note the size of the stack. */
780 stack_extra_size
+= extract_signed_integer (buf
, imm_size
);
782 /* We just consumed 2 + imm_size bytes. */
783 addr
+= 2 + imm_size
;
785 /* No more prologue insns follow, so begin preparation to return. */
786 goto finish_prologue
;
788 /* Do the essentials and get out of here. */
790 /* Note if/where callee saved registers were saved. */
792 set_reg_offsets (fi
, this_cache
, movm_args
, fpregmask
, stack_extra_size
, frame_in_fp
);
796 /* Function: skip_prologue
797 Return the address of the first inst past the prologue of the function. */
800 mn10300_skip_prologue (CORE_ADDR pc
)
802 return mn10300_analyze_prologue (NULL
, NULL
, pc
);
805 /* Simple frame_unwind_cache.
806 This finds the "extra info" for the frame. */
807 struct trad_frame_cache
*
808 mn10300_frame_unwind_cache (struct frame_info
*next_frame
,
809 void **this_prologue_cache
)
811 struct trad_frame_cache
*cache
;
812 CORE_ADDR pc
, start
, end
;
814 if (*this_prologue_cache
)
815 return (*this_prologue_cache
);
817 cache
= trad_frame_cache_zalloc (next_frame
);
818 pc
= gdbarch_unwind_pc (current_gdbarch
, next_frame
);
819 mn10300_analyze_prologue (next_frame
, (void **) &cache
, pc
);
820 if (find_pc_partial_function (pc
, NULL
, &start
, &end
))
821 trad_frame_set_id (cache
,
822 frame_id_build (trad_frame_get_this_base (cache
),
825 trad_frame_set_id (cache
,
826 frame_id_build (trad_frame_get_this_base (cache
),
827 frame_func_unwind (next_frame
)));
829 (*this_prologue_cache
) = cache
;
833 /* Here is a dummy implementation. */
834 static struct frame_id
835 mn10300_unwind_dummy_id (struct gdbarch
*gdbarch
,
836 struct frame_info
*next_frame
)
838 return frame_id_build (frame_sp_unwind (next_frame
),
839 frame_pc_unwind (next_frame
));
842 /* Trad frame implementation. */
844 mn10300_frame_this_id (struct frame_info
*next_frame
,
845 void **this_prologue_cache
,
846 struct frame_id
*this_id
)
848 struct trad_frame_cache
*cache
=
849 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
851 trad_frame_get_id (cache
, this_id
);
855 mn10300_frame_prev_register (struct frame_info
*next_frame
,
856 void **this_prologue_cache
,
857 int regnum
, int *optimizedp
,
858 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
859 int *realnump
, gdb_byte
*bufferp
)
861 struct trad_frame_cache
*cache
=
862 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
864 trad_frame_get_register (cache
, next_frame
, regnum
, optimizedp
,
865 lvalp
, addrp
, realnump
, bufferp
);
867 trad_frame_get_prev_register (next_frame, cache->prev_regs, regnum,
868 optimizedp, lvalp, addrp, realnump, bufferp);
872 static const struct frame_unwind mn10300_frame_unwind
= {
874 mn10300_frame_this_id
,
875 mn10300_frame_prev_register
879 mn10300_frame_base_address (struct frame_info
*next_frame
,
880 void **this_prologue_cache
)
882 struct trad_frame_cache
*cache
=
883 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
885 return trad_frame_get_this_base (cache
);
888 static const struct frame_unwind
*
889 mn10300_frame_sniffer (struct frame_info
*next_frame
)
891 return &mn10300_frame_unwind
;
894 static const struct frame_base mn10300_frame_base
= {
895 &mn10300_frame_unwind
,
896 mn10300_frame_base_address
,
897 mn10300_frame_base_address
,
898 mn10300_frame_base_address
902 mn10300_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
906 frame_unwind_unsigned_register (next_frame
, E_PC_REGNUM
, &pc
);
911 mn10300_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
915 frame_unwind_unsigned_register (next_frame
, E_SP_REGNUM
, &sp
);
920 mn10300_frame_unwind_init (struct gdbarch
*gdbarch
)
922 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
923 frame_unwind_append_sniffer (gdbarch
, mn10300_frame_sniffer
);
924 frame_base_set_default (gdbarch
, &mn10300_frame_base
);
925 set_gdbarch_unwind_dummy_id (gdbarch
, mn10300_unwind_dummy_id
);
926 set_gdbarch_unwind_pc (gdbarch
, mn10300_unwind_pc
);
927 set_gdbarch_unwind_sp (gdbarch
, mn10300_unwind_sp
);
930 /* Function: push_dummy_call
932 * Set up machine state for a target call, including
933 * function arguments, stack, return address, etc.
938 mn10300_push_dummy_call (struct gdbarch
*gdbarch
,
939 struct value
*target_func
,
940 struct regcache
*regcache
,
942 int nargs
, struct value
**args
,
945 CORE_ADDR struct_addr
)
947 const int push_size
= register_size (gdbarch
, E_PC_REGNUM
);
950 int stack_offset
= 0;
952 char *val
, valbuf
[MAX_REGISTER_SIZE
];
954 /* This should be a nop, but align the stack just in case something
955 went wrong. Stacks are four byte aligned on the mn10300. */
958 /* Now make space on the stack for the args.
960 XXX This doesn't appear to handle pass-by-invisible reference
962 regs_used
= struct_return
? 1 : 0;
963 for (len
= 0, argnum
= 0; argnum
< nargs
; argnum
++)
965 arg_len
= (TYPE_LENGTH (value_type (args
[argnum
])) + 3) & ~3;
966 while (regs_used
< 2 && arg_len
> 0)
969 arg_len
-= push_size
;
974 /* Allocate stack space. */
980 write_register (E_D0_REGNUM
, struct_addr
);
985 /* Push all arguments onto the stack. */
986 for (argnum
= 0; argnum
< nargs
; argnum
++)
988 /* FIXME what about structs? Unions? */
989 if (TYPE_CODE (value_type (*args
)) == TYPE_CODE_STRUCT
990 && TYPE_LENGTH (value_type (*args
)) > 8)
992 /* Change to pointer-to-type. */
994 store_unsigned_integer (valbuf
, push_size
,
995 VALUE_ADDRESS (*args
));
1000 arg_len
= TYPE_LENGTH (value_type (*args
));
1001 val
= (char *) value_contents (*args
);
1004 while (regs_used
< 2 && arg_len
> 0)
1006 write_register (regs_used
,
1007 extract_unsigned_integer (val
, push_size
));
1009 arg_len
-= push_size
;
1015 write_memory (sp
+ stack_offset
, val
, push_size
);
1016 arg_len
-= push_size
;
1018 stack_offset
+= push_size
;
1024 /* Make space for the flushback area. */
1027 /* Push the return address that contains the magic breakpoint. */
1029 write_memory_unsigned_integer (sp
, push_size
, bp_addr
);
1031 regcache_cooked_write_unsigned (regcache
, E_SP_REGNUM
, sp
);
1035 /* If DWARF2 is a register number appearing in Dwarf2 debug info, then
1036 mn10300_dwarf2_reg_to_regnum (DWARF2) is the corresponding GDB
1037 register number. Why don't Dwarf2 and GDB use the same numbering?
1038 Who knows? But since people have object files lying around with
1039 the existing Dwarf2 numbering, and other people have written stubs
1040 to work with the existing GDB, neither of them can change. So we
1041 just have to cope. */
1043 mn10300_dwarf2_reg_to_regnum (int dwarf2
)
1045 /* This table is supposed to be shaped like the REGISTER_NAMES
1046 initializer in gcc/config/mn10300/mn10300.h. Registers which
1047 appear in GCC's numbering, but have no counterpart in GDB's
1048 world, are marked with a -1. */
1049 static int dwarf2_to_gdb
[] = {
1050 0, 1, 2, 3, 4, 5, 6, 7, -1, 8,
1051 15, 16, 17, 18, 19, 20, 21, 22,
1052 32, 33, 34, 35, 36, 37, 38, 39,
1053 40, 41, 42, 43, 44, 45, 46, 47,
1054 48, 49, 50, 51, 52, 53, 54, 55,
1055 56, 57, 58, 59, 60, 61, 62, 63
1059 || dwarf2
>= ARRAY_SIZE (dwarf2_to_gdb
)
1060 || dwarf2_to_gdb
[dwarf2
] == -1)
1062 warning (_("Bogus register number in debug info: %d"), dwarf2
);
1066 return dwarf2_to_gdb
[dwarf2
];
1069 static struct gdbarch
*
1070 mn10300_gdbarch_init (struct gdbarch_info info
,
1071 struct gdbarch_list
*arches
)
1073 struct gdbarch
*gdbarch
;
1074 struct gdbarch_tdep
*tdep
;
1077 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1079 return arches
->gdbarch
;
1081 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
1082 gdbarch
= gdbarch_alloc (&info
, tdep
);
1084 switch (info
.bfd_arch_info
->mach
)
1087 case bfd_mach_mn10300
:
1088 set_gdbarch_register_name (gdbarch
, mn10300_generic_register_name
);
1089 tdep
->am33_mode
= 0;
1093 set_gdbarch_register_name (gdbarch
, am33_register_name
);
1094 tdep
->am33_mode
= 1;
1097 case bfd_mach_am33_2
:
1098 set_gdbarch_register_name (gdbarch
, am33_2_register_name
);
1099 tdep
->am33_mode
= 2;
1101 set_gdbarch_fp0_regnum (gdbarch
, 32);
1104 internal_error (__FILE__
, __LINE__
,
1105 _("mn10300_gdbarch_init: Unknown mn10300 variant"));
1110 set_gdbarch_num_regs (gdbarch
, num_regs
);
1111 set_gdbarch_register_type (gdbarch
, mn10300_register_type
);
1112 set_gdbarch_skip_prologue (gdbarch
, mn10300_skip_prologue
);
1113 set_gdbarch_read_pc (gdbarch
, mn10300_read_pc
);
1114 set_gdbarch_write_pc (gdbarch
, mn10300_write_pc
);
1115 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
1116 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
1117 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, mn10300_dwarf2_reg_to_regnum
);
1119 /* Stack unwinding. */
1120 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1122 set_gdbarch_breakpoint_from_pc (gdbarch
, mn10300_breakpoint_from_pc
);
1123 /* decr_pc_after_break? */
1125 set_gdbarch_print_insn (gdbarch
, print_insn_mn10300
);
1128 set_gdbarch_return_value (gdbarch
, mn10300_return_value
);
1130 /* Stage 3 -- get target calls working. */
1131 set_gdbarch_push_dummy_call (gdbarch
, mn10300_push_dummy_call
);
1132 /* set_gdbarch_return_value (store, extract) */
1135 mn10300_frame_unwind_init (gdbarch
);
1137 /* Hook in ABI-specific overrides, if they have been registered. */
1138 gdbarch_init_osabi (info
, gdbarch
);
1143 /* Dump out the mn10300 specific architecture information. */
1146 mn10300_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
1148 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1149 fprintf_unfiltered (file
, "mn10300_dump_tdep: am33_mode = %d\n",
1154 _initialize_mn10300_tdep (void)
1156 gdbarch_register (bfd_arch_mn10300
, mn10300_gdbarch_init
, mn10300_dump_tdep
);