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"
42 #include "mn10300-tdep.h"
45 extern struct trad_frame_cache
*mn10300_frame_unwind_cache (struct frame_info
*,
48 /* Compute the alignment required by a type. */
51 mn10300_type_align (struct type
*type
)
55 switch (TYPE_CODE (type
))
66 return TYPE_LENGTH (type
);
68 case TYPE_CODE_COMPLEX
:
69 return TYPE_LENGTH (type
) / 2;
71 case TYPE_CODE_STRUCT
:
73 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
75 int falign
= mn10300_type_align (TYPE_FIELD_TYPE (type
, i
));
76 while (align
< falign
)
82 /* HACK! Structures containing arrays, even small ones, are not
83 elligible for returning in registers. */
86 case TYPE_CODE_TYPEDEF
:
87 return mn10300_type_align (check_typedef (type
));
90 internal_error (__FILE__
, __LINE__
, _("bad switch"));
94 /* MVS note this is deprecated. */
95 /* Should call_function allocate stack space for a struct return? */
98 mn10300_use_struct_convention (int gcc_p
, struct type
*type
)
100 /* Structures bigger than a pair of words can't be returned in
102 if (TYPE_LENGTH (type
) > 8)
105 switch (TYPE_CODE (type
))
107 case TYPE_CODE_STRUCT
:
108 case TYPE_CODE_UNION
:
109 /* Structures with a single field are handled as the field
111 if (TYPE_NFIELDS (type
) == 1)
112 return mn10300_use_struct_convention (gcc_p
,
113 TYPE_FIELD_TYPE (type
, 0));
115 /* Structures with word or double-word size are passed in memory, as
116 long as they require at least word alignment. */
117 if (mn10300_type_align (type
) >= 4)
122 /* Arrays are addressable, so they're never returned in
123 registers. This condition can only hold when the array is
124 the only field of a struct or union. */
125 case TYPE_CODE_ARRAY
:
128 case TYPE_CODE_TYPEDEF
:
129 return mn10300_use_struct_convention (gcc_p
, check_typedef (type
));
136 /* MVS note this is deprecated. */
138 mn10300_store_return_value (struct type
*type
,
139 struct regcache
*regcache
, const void *valbuf
)
141 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
142 int len
= TYPE_LENGTH (type
);
145 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
150 regsz
= register_size (gdbarch
, reg
);
153 regcache_raw_write_part (regcache
, reg
, 0, len
, valbuf
);
154 else if (len
<= 2 * regsz
)
156 regcache_raw_write (regcache
, reg
, valbuf
);
157 gdb_assert (regsz
== register_size (gdbarch
, reg
+ 1));
158 regcache_raw_write_part (regcache
, reg
+1, 0,
159 len
- regsz
, (char *) valbuf
+ regsz
);
162 internal_error (__FILE__
, __LINE__
,
163 _("Cannot store return value %d bytes long."), len
);
166 /* MVS note deprecated. */
168 mn10300_extract_return_value (struct type
*type
,
169 struct regcache
*regcache
, void *valbuf
)
171 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
172 char buf
[MAX_REGISTER_SIZE
];
173 int len
= TYPE_LENGTH (type
);
176 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
181 regsz
= register_size (gdbarch
, reg
);
184 regcache_raw_read (regcache
, reg
, buf
);
185 memcpy (valbuf
, buf
, len
);
187 else if (len
<= 2 * regsz
)
189 regcache_raw_read (regcache
, reg
, buf
);
190 memcpy (valbuf
, buf
, regsz
);
191 gdb_assert (regsz
== register_size (gdbarch
, reg
+ 1));
192 regcache_raw_read (regcache
, reg
+ 1, buf
);
193 memcpy ((char *) valbuf
+ regsz
, buf
, len
- regsz
);
196 internal_error (__FILE__
, __LINE__
,
197 _("Cannot extract return value %d bytes long."), len
);
201 register_name (int reg
, char **regs
, long sizeof_regs
)
203 if (reg
< 0 || reg
>= sizeof_regs
/ sizeof (regs
[0]))
210 mn10300_generic_register_name (int reg
)
212 static char *regs
[] =
213 { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
214 "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
215 "", "", "", "", "", "", "", "",
216 "", "", "", "", "", "", "", "fp"
218 return register_name (reg
, regs
, sizeof regs
);
223 am33_register_name (int reg
)
225 static char *regs
[] =
226 { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
227 "sp", "pc", "mdr", "psw", "lir", "lar", "",
228 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
229 "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", ""
231 return register_name (reg
, regs
, sizeof regs
);
236 mn10300_register_type (struct gdbarch
*gdbarch
, int reg
)
238 return builtin_type_int
;
242 mn10300_read_pc (ptid_t ptid
)
244 return read_register_pid (E_PC_REGNUM
, ptid
);
248 mn10300_write_pc (CORE_ADDR val
, ptid_t ptid
)
250 return write_register_pid (E_PC_REGNUM
, val
, ptid
);
253 /* The breakpoint instruction must be the same size as the smallest
254 instruction in the instruction set.
256 The Matsushita mn10x00 processors have single byte instructions
257 so we need a single byte breakpoint. Matsushita hasn't defined
258 one, so we defined it ourselves. */
260 const static unsigned char *
261 mn10300_breakpoint_from_pc (CORE_ADDR
*bp_addr
, int *bp_size
)
263 static char breakpoint
[] = {0xff};
271 * status -- actually frame type (SP, FP, or last frame)
272 * stack size -- offset to the next frame
274 * The former might ultimately be stored in the frame_base.
275 * Seems like there'd be a way to store the later too.
277 * Temporarily supply empty stub functions as place holders.
281 my_frame_is_in_sp (struct frame_info
*fi
, void **this_cache
)
283 struct trad_frame_cache
*cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
284 trad_frame_set_this_base (cache
,
285 frame_unwind_register_unsigned (fi
,
290 my_frame_is_in_fp (struct frame_info
*fi
, void **this_cache
)
292 struct trad_frame_cache
*cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
293 trad_frame_set_this_base (cache
,
294 frame_unwind_register_unsigned (fi
,
299 my_frame_is_last (struct frame_info
*fi
)
304 is_my_frame_in_sp (struct frame_info
*fi
)
310 is_my_frame_in_fp (struct frame_info
*fi
)
316 is_my_frame_last (struct frame_info
*fi
)
322 set_my_stack_size (struct frame_info
*fi
, CORE_ADDR size
)
327 /* Set offsets of registers saved by movm instruction.
328 This is a helper function for mn10300_analyze_prologue. */
331 set_movm_offsets (struct frame_info
*fi
,
335 struct trad_frame_cache
*cache
;
339 if (fi
== NULL
|| this_cache
== NULL
)
342 cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
346 base
= trad_frame_get_this_base (cache
);
347 if (movm_args
& movm_other_bit
)
349 /* The `other' bit leaves a blank area of four bytes at the
350 beginning of its block of saved registers, making it 32 bytes
352 trad_frame_set_reg_addr (cache
, E_LAR_REGNUM
, base
+ offset
+ 4);
353 trad_frame_set_reg_addr (cache
, E_LIR_REGNUM
, base
+ offset
+ 8);
354 trad_frame_set_reg_addr (cache
, E_MDR_REGNUM
, base
+ offset
+ 12);
355 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
+ 1, base
+ offset
+ 16);
356 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
, base
+ offset
+ 20);
357 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
+ 1, base
+ offset
+ 24);
358 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
, base
+ offset
+ 28);
362 if (movm_args
& movm_a3_bit
)
364 trad_frame_set_reg_addr (cache
, E_A3_REGNUM
, base
+ offset
);
367 if (movm_args
& movm_a2_bit
)
369 trad_frame_set_reg_addr (cache
, E_A2_REGNUM
, base
+ offset
);
372 if (movm_args
& movm_d3_bit
)
374 trad_frame_set_reg_addr (cache
, E_D3_REGNUM
, base
+ offset
);
377 if (movm_args
& movm_d2_bit
)
379 trad_frame_set_reg_addr (cache
, E_D2_REGNUM
, base
+ offset
);
384 if (movm_args
& movm_exother_bit
)
386 trad_frame_set_reg_addr (cache
, E_MCVF_REGNUM
, base
+ offset
);
387 trad_frame_set_reg_addr (cache
, E_MCRL_REGNUM
, base
+ offset
+ 4);
388 trad_frame_set_reg_addr (cache
, E_MCRH_REGNUM
, base
+ offset
+ 8);
389 trad_frame_set_reg_addr (cache
, E_MDRQ_REGNUM
, base
+ offset
+ 12);
390 trad_frame_set_reg_addr (cache
, E_E1_REGNUM
, base
+ offset
+ 16);
391 trad_frame_set_reg_addr (cache
, E_E0_REGNUM
, base
+ offset
+ 20);
394 if (movm_args
& movm_exreg1_bit
)
396 trad_frame_set_reg_addr (cache
, E_E7_REGNUM
, base
+ offset
);
397 trad_frame_set_reg_addr (cache
, E_E6_REGNUM
, base
+ offset
+ 4);
398 trad_frame_set_reg_addr (cache
, E_E5_REGNUM
, base
+ offset
+ 8);
399 trad_frame_set_reg_addr (cache
, E_E4_REGNUM
, base
+ offset
+ 12);
402 if (movm_args
& movm_exreg0_bit
)
404 trad_frame_set_reg_addr (cache
, E_E3_REGNUM
, base
+ offset
);
405 trad_frame_set_reg_addr (cache
, E_E2_REGNUM
, base
+ offset
+ 4);
409 /* The last (or first) thing on the stack will be the PC. */
410 trad_frame_set_reg_addr (cache
, E_PC_REGNUM
, base
+ offset
);
411 /* Save the SP in the 'traditional' way.
412 This will be the same location where the PC is saved. */
413 trad_frame_set_reg_value (cache
, E_SP_REGNUM
, base
+ offset
);
416 /* The main purpose of this file is dealing with prologues to extract
417 information about stack frames and saved registers.
419 In gcc/config/mn13000/mn10300.c, the expand_prologue prologue
420 function is pretty readable, and has a nice explanation of how the
421 prologue is generated. The prologues generated by that code will
422 have the following form (NOTE: the current code doesn't handle all
425 + If this is an old-style varargs function, then its arguments
426 need to be flushed back to the stack:
431 + If we use any of the callee-saved registers, save them now.
433 movm [some callee-saved registers],(sp)
435 + If we have any floating-point registers to save:
437 - Decrement the stack pointer to reserve space for the registers.
438 If the function doesn't need a frame pointer, we may combine
439 this with the adjustment that reserves space for the frame.
443 - Save the floating-point registers. We have two possible
446 . Save them at fixed offset from the SP:
448 fmov fsN,(OFFSETN,sp)
449 fmov fsM,(OFFSETM,sp)
452 Note that, if OFFSETN happens to be zero, you'll get the
453 different opcode: fmov fsN,(sp)
455 . Or, set a0 to the start of the save area, and then use
456 post-increment addressing to save the FP registers.
464 + If the function needs a frame pointer, we set it here.
468 + Now we reserve space for the stack frame proper. This could be
469 merged into the `add -SIZE, sp' instruction for FP saves up
470 above, unless we needed to set the frame pointer in the previous
471 step, or the frame is so large that allocating the whole thing at
472 once would put the FP register save slots out of reach of the
473 addressing mode (128 bytes).
477 One day we might keep the stack pointer constant, that won't
478 change the code for prologues, but it will make the frame
479 pointerless case much more common. */
481 /* Analyze the prologue to determine where registers are saved,
482 the end of the prologue, etc etc. Return the end of the prologue
485 We store into FI (if non-null) several tidbits of information:
487 * stack_size -- size of this stack frame. Note that if we stop in
488 certain parts of the prologue/epilogue we may claim the size of the
489 current frame is zero. This happens when the current frame has
490 not been allocated yet or has already been deallocated.
492 * fsr -- Addresses of registers saved in the stack by this frame.
494 * status -- A (relatively) generic status indicator. It's a bitmask
495 with the following bits:
497 MY_FRAME_IN_SP: The base of the current frame is actually in
498 the stack pointer. This can happen for frame pointerless
499 functions, or cases where we're stopped in the prologue/epilogue
500 itself. For these cases mn10300_analyze_prologue will need up
501 update fi->frame before returning or analyzing the register
504 MY_FRAME_IN_FP: The base of the current frame is in the
505 frame pointer register ($a3).
507 NO_MORE_FRAMES: Set this if the current frame is "start" or
508 if the first instruction looks like mov <imm>,sp. This tells
509 frame chain to not bother trying to unwind past this frame. */
512 mn10300_analyze_prologue (struct frame_info
*fi
,
516 CORE_ADDR func_addr
, func_end
, addr
, stop
;
519 unsigned char buf
[4];
520 int status
, movm_args
= 0;
523 /* Use the PC in the frame if it's provided to look up the
524 start of this function.
526 Note: kevinb/2003-07-16: We used to do the following here:
527 pc = (fi ? get_frame_pc (fi) : pc);
528 But this is (now) badly broken when called from analyze_dummy_frame().
532 pc
= (pc
? pc
: get_frame_pc (fi
));
533 /* At the start of a function our frame is in the stack pointer. */
534 my_frame_is_in_sp (fi
, this_cache
);
537 /* Find the start of this function. */
538 status
= find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
);
540 /* Do nothing if we couldn't find the start of this function
542 MVS: comment went on to say "or if we're stopped at the first
543 instruction in the prologue" -- but code doesn't reflect that,
544 and I don't want to do that anyway. */
550 /* If we're in start, then give up. */
551 if (strcmp (name
, "start") == 0)
554 my_frame_is_last (fi
);
559 /* Get the next two bytes into buf, we need two because rets is a two
560 byte insn and the first isn't enough to uniquely identify it. */
561 status
= deprecated_read_memory_nobpt (pc
, buf
, 2);
565 /* Note: kevinb/2003-07-16: We shouldn't be making these sorts of
566 changes to the frame in prologue examination code. */
567 /* If we're physically on an "rets" instruction, then our frame has
568 already been deallocated. Note this can also be true for retf
569 and ret if they specify a size of zero.
571 In this case fi->frame is bogus, we need to fix it. */
572 if (fi
&& buf
[0] == 0xf0 && buf
[1] == 0xfc)
574 if (get_next_frame (fi
) == NULL
)
575 deprecated_update_frame_base_hack (fi
, read_sp ());
576 return get_frame_pc (fi
);
579 /* Similarly if we're stopped on the first insn of a prologue as our
580 frame hasn't been allocated yet. */
581 if (fi
&& get_frame_pc (fi
) == func_addr
)
583 if (get_next_frame (fi
) == NULL
)
584 deprecated_update_frame_base_hack (fi
, read_sp ());
585 return get_frame_pc (fi
);
589 /* NOTE: from here on, we don't want to return without jumping to
593 /* Figure out where to stop scanning. */
594 stop
= fi
? pc
: func_end
;
596 /* Don't walk off the end of the function. */
597 stop
= stop
> func_end
? func_end
: stop
;
599 /* Start scanning on the first instruction of this function. */
602 /* Suck in two bytes. */
604 || (status
= deprecated_read_memory_nobpt (addr
, buf
, 2)) != 0)
605 goto finish_prologue
;
607 /* First see if this insn sets the stack pointer from a register; if
608 so, it's probably the initialization of the stack pointer in _start,
609 so mark this as the bottom-most frame. */
610 if (buf
[0] == 0xf2 && (buf
[1] & 0xf3) == 0xf0)
613 my_frame_is_last (fi
);
614 goto finish_prologue
;
617 /* Now look for movm [regs],sp, which saves the callee saved registers.
619 At this time we don't know if fi->frame is valid, so we only note
620 that we encountered a movm instruction. Later, we'll set the entries
621 in fsr.regs as needed. */
624 /* Extract the register list for the movm instruction. */
629 /* Quit now if we're beyond the stop point. */
631 goto finish_prologue
;
633 /* Get the next two bytes so the prologue scan can continue. */
634 status
= deprecated_read_memory_nobpt (addr
, buf
, 2);
636 goto finish_prologue
;
639 /* Now see if we set up a frame pointer via "mov sp,a3" */
644 /* The frame pointer is now valid. */
647 my_frame_is_in_fp (fi
, this_cache
);
650 /* Quit now if we're beyond the stop point. */
652 goto finish_prologue
;
654 /* Get two more bytes so scanning can continue. */
655 status
= deprecated_read_memory_nobpt (addr
, buf
, 2);
657 goto finish_prologue
;
660 /* Next we should allocate the local frame. No more prologue insns
661 are found after allocating the local frame.
663 Search for add imm8,sp (0xf8feXX)
664 or add imm16,sp (0xfafeXXXX)
665 or add imm32,sp (0xfcfeXXXXXXXX).
667 If none of the above was found, then this prologue has no
671 if (buf
[0] == 0xf8 && buf
[1] == 0xfe)
673 else if (buf
[0] == 0xfa && buf
[1] == 0xfe)
675 else if (buf
[0] == 0xfc && buf
[1] == 0xfe)
680 /* Suck in imm_size more bytes, they'll hold the size of the
682 status
= deprecated_read_memory_nobpt (addr
+ 2, buf
, imm_size
);
684 goto finish_prologue
;
686 /* Note the size of the stack in the frame info structure. */
687 stack_size
= extract_signed_integer (buf
, imm_size
);
689 set_my_stack_size (fi
, stack_size
);
691 /* We just consumed 2 + imm_size bytes. */
692 addr
+= 2 + imm_size
;
694 /* No more prologue insns follow, so begin preparation to return. */
695 goto finish_prologue
;
697 /* Do the essentials and get out of here. */
699 /* Note if/where callee saved registers were saved. */
701 set_movm_offsets (fi
, this_cache
, movm_args
);
705 /* Function: skip_prologue
706 Return the address of the first inst past the prologue of the function. */
709 mn10300_skip_prologue (CORE_ADDR pc
)
711 return mn10300_analyze_prologue (NULL
, NULL
, pc
);
714 /* Simple frame_unwind_cache.
715 This finds the "extra info" for the frame. */
716 struct trad_frame_cache
*
717 mn10300_frame_unwind_cache (struct frame_info
*next_frame
,
718 void **this_prologue_cache
)
720 struct trad_frame_cache
*cache
;
721 CORE_ADDR pc
, start
, end
;
723 if (*this_prologue_cache
)
724 return (*this_prologue_cache
);
726 cache
= trad_frame_cache_zalloc (next_frame
);
727 pc
= gdbarch_unwind_pc (current_gdbarch
, next_frame
);
728 mn10300_analyze_prologue (next_frame
, (void **) &cache
, pc
);
729 if (find_pc_partial_function (pc
, NULL
, &start
, &end
))
730 trad_frame_set_id (cache
,
731 frame_id_build (trad_frame_get_this_base (cache
),
734 trad_frame_set_id (cache
,
735 frame_id_build (trad_frame_get_this_base (cache
),
736 frame_func_unwind (next_frame
)));
738 (*this_prologue_cache
) = cache
;
742 /* Here is a dummy implementation. */
743 static struct frame_id
744 mn10300_unwind_dummy_id (struct gdbarch
*gdbarch
,
745 struct frame_info
*next_frame
)
747 return frame_id_build (frame_sp_unwind (next_frame
),
748 frame_pc_unwind (next_frame
));
751 /* Trad frame implementation. */
753 mn10300_frame_this_id (struct frame_info
*next_frame
,
754 void **this_prologue_cache
,
755 struct frame_id
*this_id
)
757 struct trad_frame_cache
*cache
=
758 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
760 trad_frame_get_id (cache
, this_id
);
764 mn10300_frame_prev_register (struct frame_info
*next_frame
,
765 void **this_prologue_cache
,
766 int regnum
, int *optimizedp
,
767 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
768 int *realnump
, void *bufferp
)
770 struct trad_frame_cache
*cache
=
771 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
773 trad_frame_get_register (cache
, next_frame
, regnum
, optimizedp
,
774 lvalp
, addrp
, realnump
, bufferp
);
776 trad_frame_get_prev_register (next_frame, cache->prev_regs, regnum,
777 optimizedp, lvalp, addrp, realnump, bufferp);
781 static const struct frame_unwind mn10300_frame_unwind
= {
783 mn10300_frame_this_id
,
784 mn10300_frame_prev_register
788 mn10300_frame_base_address (struct frame_info
*next_frame
,
789 void **this_prologue_cache
)
791 struct trad_frame_cache
*cache
=
792 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
794 return trad_frame_get_this_base (cache
);
797 static const struct frame_unwind
*
798 mn10300_frame_sniffer (struct frame_info
*next_frame
)
800 return &mn10300_frame_unwind
;
803 static const struct frame_base mn10300_frame_base
= {
804 &mn10300_frame_unwind
,
805 mn10300_frame_base_address
,
806 mn10300_frame_base_address
,
807 mn10300_frame_base_address
811 mn10300_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
815 frame_unwind_unsigned_register (next_frame
, E_PC_REGNUM
, &pc
);
820 mn10300_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
824 frame_unwind_unsigned_register (next_frame
, E_SP_REGNUM
, &sp
);
829 mn10300_frame_unwind_init (struct gdbarch
*gdbarch
)
831 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
832 frame_unwind_append_sniffer (gdbarch
, mn10300_frame_sniffer
);
833 frame_base_set_default (gdbarch
, &mn10300_frame_base
);
834 set_gdbarch_unwind_dummy_id (gdbarch
, mn10300_unwind_dummy_id
);
835 set_gdbarch_unwind_pc (gdbarch
, mn10300_unwind_pc
);
836 set_gdbarch_unwind_sp (gdbarch
, mn10300_unwind_sp
);
839 /* Function: push_dummy_call
841 * Set up machine state for a target call, including
842 * function arguments, stack, return address, etc.
847 mn10300_push_dummy_call (struct gdbarch
*gdbarch
,
848 struct value
*target_func
,
849 struct regcache
*regcache
,
851 int nargs
, struct value
**args
,
854 CORE_ADDR struct_addr
)
856 const int push_size
= register_size (gdbarch
, E_PC_REGNUM
);
859 int stack_offset
= 0;
861 char *val
, valbuf
[MAX_REGISTER_SIZE
];
863 /* This should be a nop, but align the stack just in case something
864 went wrong. Stacks are four byte aligned on the mn10300. */
867 /* Now make space on the stack for the args.
869 XXX This doesn't appear to handle pass-by-invisible reference
871 regs_used
= struct_return
? 1 : 0;
872 for (len
= 0, argnum
= 0; argnum
< nargs
; argnum
++)
874 arg_len
= (TYPE_LENGTH (value_type (args
[argnum
])) + 3) & ~3;
875 while (regs_used
< 2 && arg_len
> 0)
878 arg_len
-= push_size
;
883 /* Allocate stack space. */
889 write_register (E_D0_REGNUM
, struct_addr
);
894 /* Push all arguments onto the stack. */
895 for (argnum
= 0; argnum
< nargs
; argnum
++)
897 /* FIXME what about structs? Unions? */
898 if (TYPE_CODE (value_type (*args
)) == TYPE_CODE_STRUCT
899 && TYPE_LENGTH (value_type (*args
)) > 8)
901 /* Change to pointer-to-type. */
903 store_unsigned_integer (valbuf
, push_size
,
904 VALUE_ADDRESS (*args
));
909 arg_len
= TYPE_LENGTH (value_type (*args
));
910 val
= (char *) value_contents (*args
);
913 while (regs_used
< 2 && arg_len
> 0)
915 write_register (regs_used
,
916 extract_unsigned_integer (val
, push_size
));
918 arg_len
-= push_size
;
924 write_memory (sp
+ stack_offset
, val
, push_size
);
925 arg_len
-= push_size
;
927 stack_offset
+= push_size
;
933 /* Make space for the flushback area. */
936 /* Push the return address that contains the magic breakpoint. */
938 write_memory_unsigned_integer (sp
, push_size
, bp_addr
);
940 regcache_cooked_write_unsigned (regcache
, E_SP_REGNUM
, sp
);
945 static struct gdbarch
*
946 mn10300_gdbarch_init (struct gdbarch_info info
,
947 struct gdbarch_list
*arches
)
949 struct gdbarch
*gdbarch
;
950 struct gdbarch_tdep
*tdep
;
952 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
954 return arches
->gdbarch
;
956 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
957 gdbarch
= gdbarch_alloc (&info
, tdep
);
959 switch (info
.bfd_arch_info
->mach
)
962 case bfd_mach_mn10300
:
963 set_gdbarch_register_name (gdbarch
, mn10300_generic_register_name
);
967 set_gdbarch_register_name (gdbarch
, am33_register_name
);
971 internal_error (__FILE__
, __LINE__
,
972 _("mn10300_gdbarch_init: Unknown mn10300 variant"));
977 set_gdbarch_num_regs (gdbarch
, E_NUM_REGS
);
978 set_gdbarch_register_type (gdbarch
, mn10300_register_type
);
979 set_gdbarch_skip_prologue (gdbarch
, mn10300_skip_prologue
);
980 set_gdbarch_read_pc (gdbarch
, mn10300_read_pc
);
981 set_gdbarch_write_pc (gdbarch
, mn10300_write_pc
);
982 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
983 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
985 /* Stack unwinding. */
986 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
988 set_gdbarch_breakpoint_from_pc (gdbarch
, mn10300_breakpoint_from_pc
);
989 /* decr_pc_after_break? */
991 set_gdbarch_print_insn (gdbarch
, print_insn_mn10300
);
994 /* MVS Note: at least the first one is deprecated! */
995 set_gdbarch_deprecated_use_struct_convention (gdbarch
,
996 mn10300_use_struct_convention
);
997 set_gdbarch_store_return_value (gdbarch
, mn10300_store_return_value
);
998 set_gdbarch_extract_return_value (gdbarch
, mn10300_extract_return_value
);
1000 /* Stage 3 -- get target calls working. */
1001 set_gdbarch_push_dummy_call (gdbarch
, mn10300_push_dummy_call
);
1002 /* set_gdbarch_return_value (store, extract) */
1005 mn10300_frame_unwind_init (gdbarch
);
1007 /* Hook in ABI-specific overrides, if they have been registered. */
1008 gdbarch_init_osabi (info
, gdbarch
);
1013 /* Dump out the mn10300 specific architecture information. */
1016 mn10300_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
1018 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1019 fprintf_unfiltered (file
, "mn10300_dump_tdep: am33_mode = %d\n",
1024 _initialize_mn10300_tdep (void)
1026 gdbarch_register (bfd_arch_mn10300
, mn10300_gdbarch_init
, mn10300_dump_tdep
);