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
);
250 mn10300_register_type (struct gdbarch
*gdbarch
, int reg
)
252 return builtin_type_int
;
256 mn10300_read_pc (ptid_t ptid
)
258 return read_register_pid (E_PC_REGNUM
, ptid
);
262 mn10300_write_pc (CORE_ADDR val
, ptid_t ptid
)
264 return write_register_pid (E_PC_REGNUM
, val
, ptid
);
267 /* The breakpoint instruction must be the same size as the smallest
268 instruction in the instruction set.
270 The Matsushita mn10x00 processors have single byte instructions
271 so we need a single byte breakpoint. Matsushita hasn't defined
272 one, so we defined it ourselves. */
274 const static unsigned char *
275 mn10300_breakpoint_from_pc (CORE_ADDR
*bp_addr
, int *bp_size
)
277 static char breakpoint
[] = {0xff};
285 * status -- actually frame type (SP, FP, or last frame)
286 * stack size -- offset to the next frame
288 * The former might ultimately be stored in the frame_base.
289 * Seems like there'd be a way to store the later too.
291 * Temporarily supply empty stub functions as place holders.
295 my_frame_is_in_sp (struct frame_info
*fi
, void **this_cache
)
297 struct trad_frame_cache
*cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
298 trad_frame_set_this_base (cache
,
299 frame_unwind_register_unsigned (fi
,
304 my_frame_is_in_fp (struct frame_info
*fi
, void **this_cache
)
306 struct trad_frame_cache
*cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
307 trad_frame_set_this_base (cache
,
308 frame_unwind_register_unsigned (fi
,
313 my_frame_is_last (struct frame_info
*fi
)
318 set_my_stack_size (struct frame_info
*fi
, CORE_ADDR size
)
323 /* Set offsets of registers saved by movm instruction.
324 This is a helper function for mn10300_analyze_prologue. */
327 set_movm_offsets (struct frame_info
*fi
,
331 struct trad_frame_cache
*cache
;
335 if (fi
== NULL
|| this_cache
== NULL
)
338 cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
342 base
= trad_frame_get_this_base (cache
);
343 if (movm_args
& movm_other_bit
)
345 /* The `other' bit leaves a blank area of four bytes at the
346 beginning of its block of saved registers, making it 32 bytes
348 trad_frame_set_reg_addr (cache
, E_LAR_REGNUM
, base
+ offset
+ 4);
349 trad_frame_set_reg_addr (cache
, E_LIR_REGNUM
, base
+ offset
+ 8);
350 trad_frame_set_reg_addr (cache
, E_MDR_REGNUM
, base
+ offset
+ 12);
351 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
+ 1, base
+ offset
+ 16);
352 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
, base
+ offset
+ 20);
353 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
+ 1, base
+ offset
+ 24);
354 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
, base
+ offset
+ 28);
358 if (movm_args
& movm_a3_bit
)
360 trad_frame_set_reg_addr (cache
, E_A3_REGNUM
, base
+ offset
);
363 if (movm_args
& movm_a2_bit
)
365 trad_frame_set_reg_addr (cache
, E_A2_REGNUM
, base
+ offset
);
368 if (movm_args
& movm_d3_bit
)
370 trad_frame_set_reg_addr (cache
, E_D3_REGNUM
, base
+ offset
);
373 if (movm_args
& movm_d2_bit
)
375 trad_frame_set_reg_addr (cache
, E_D2_REGNUM
, base
+ offset
);
380 if (movm_args
& movm_exother_bit
)
382 trad_frame_set_reg_addr (cache
, E_MCVF_REGNUM
, base
+ offset
);
383 trad_frame_set_reg_addr (cache
, E_MCRL_REGNUM
, base
+ offset
+ 4);
384 trad_frame_set_reg_addr (cache
, E_MCRH_REGNUM
, base
+ offset
+ 8);
385 trad_frame_set_reg_addr (cache
, E_MDRQ_REGNUM
, base
+ offset
+ 12);
386 trad_frame_set_reg_addr (cache
, E_E1_REGNUM
, base
+ offset
+ 16);
387 trad_frame_set_reg_addr (cache
, E_E0_REGNUM
, base
+ offset
+ 20);
390 if (movm_args
& movm_exreg1_bit
)
392 trad_frame_set_reg_addr (cache
, E_E7_REGNUM
, base
+ offset
);
393 trad_frame_set_reg_addr (cache
, E_E6_REGNUM
, base
+ offset
+ 4);
394 trad_frame_set_reg_addr (cache
, E_E5_REGNUM
, base
+ offset
+ 8);
395 trad_frame_set_reg_addr (cache
, E_E4_REGNUM
, base
+ offset
+ 12);
398 if (movm_args
& movm_exreg0_bit
)
400 trad_frame_set_reg_addr (cache
, E_E3_REGNUM
, base
+ offset
);
401 trad_frame_set_reg_addr (cache
, E_E2_REGNUM
, base
+ offset
+ 4);
405 /* The last (or first) thing on the stack will be the PC. */
406 trad_frame_set_reg_addr (cache
, E_PC_REGNUM
, base
+ offset
);
407 /* Save the SP in the 'traditional' way.
408 This will be the same location where the PC is saved. */
409 trad_frame_set_reg_value (cache
, E_SP_REGNUM
, base
+ offset
);
412 /* The main purpose of this file is dealing with prologues to extract
413 information about stack frames and saved registers.
415 In gcc/config/mn13000/mn10300.c, the expand_prologue prologue
416 function is pretty readable, and has a nice explanation of how the
417 prologue is generated. The prologues generated by that code will
418 have the following form (NOTE: the current code doesn't handle all
421 + If this is an old-style varargs function, then its arguments
422 need to be flushed back to the stack:
427 + If we use any of the callee-saved registers, save them now.
429 movm [some callee-saved registers],(sp)
431 + If we have any floating-point registers to save:
433 - Decrement the stack pointer to reserve space for the registers.
434 If the function doesn't need a frame pointer, we may combine
435 this with the adjustment that reserves space for the frame.
439 - Save the floating-point registers. We have two possible
442 . Save them at fixed offset from the SP:
444 fmov fsN,(OFFSETN,sp)
445 fmov fsM,(OFFSETM,sp)
448 Note that, if OFFSETN happens to be zero, you'll get the
449 different opcode: fmov fsN,(sp)
451 . Or, set a0 to the start of the save area, and then use
452 post-increment addressing to save the FP registers.
460 + If the function needs a frame pointer, we set it here.
464 + Now we reserve space for the stack frame proper. This could be
465 merged into the `add -SIZE, sp' instruction for FP saves up
466 above, unless we needed to set the frame pointer in the previous
467 step, or the frame is so large that allocating the whole thing at
468 once would put the FP register save slots out of reach of the
469 addressing mode (128 bytes).
473 One day we might keep the stack pointer constant, that won't
474 change the code for prologues, but it will make the frame
475 pointerless case much more common. */
477 /* Analyze the prologue to determine where registers are saved,
478 the end of the prologue, etc etc. Return the end of the prologue
481 We store into FI (if non-null) several tidbits of information:
483 * stack_size -- size of this stack frame. Note that if we stop in
484 certain parts of the prologue/epilogue we may claim the size of the
485 current frame is zero. This happens when the current frame has
486 not been allocated yet or has already been deallocated.
488 * fsr -- Addresses of registers saved in the stack by this frame.
490 * status -- A (relatively) generic status indicator. It's a bitmask
491 with the following bits:
493 MY_FRAME_IN_SP: The base of the current frame is actually in
494 the stack pointer. This can happen for frame pointerless
495 functions, or cases where we're stopped in the prologue/epilogue
496 itself. For these cases mn10300_analyze_prologue will need up
497 update fi->frame before returning or analyzing the register
500 MY_FRAME_IN_FP: The base of the current frame is in the
501 frame pointer register ($a3).
503 NO_MORE_FRAMES: Set this if the current frame is "start" or
504 if the first instruction looks like mov <imm>,sp. This tells
505 frame chain to not bother trying to unwind past this frame. */
508 mn10300_analyze_prologue (struct frame_info
*fi
,
512 CORE_ADDR func_addr
, func_end
, addr
, stop
;
515 unsigned char buf
[4];
516 int status
, movm_args
= 0;
519 /* Use the PC in the frame if it's provided to look up the
520 start of this function.
522 Note: kevinb/2003-07-16: We used to do the following here:
523 pc = (fi ? get_frame_pc (fi) : pc);
524 But this is (now) badly broken when called from analyze_dummy_frame().
528 pc
= (pc
? pc
: get_frame_pc (fi
));
529 /* At the start of a function our frame is in the stack pointer. */
530 my_frame_is_in_sp (fi
, this_cache
);
533 /* Find the start of this function. */
534 status
= find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
);
536 /* Do nothing if we couldn't find the start of this function
538 MVS: comment went on to say "or if we're stopped at the first
539 instruction in the prologue" -- but code doesn't reflect that,
540 and I don't want to do that anyway. */
546 /* If we're in start, then give up. */
547 if (strcmp (name
, "start") == 0)
550 my_frame_is_last (fi
);
555 /* Get the next two bytes into buf, we need two because rets is a two
556 byte insn and the first isn't enough to uniquely identify it. */
557 status
= deprecated_read_memory_nobpt (pc
, buf
, 2);
561 /* Note: kevinb/2003-07-16: We shouldn't be making these sorts of
562 changes to the frame in prologue examination code. */
563 /* If we're physically on an "rets" instruction, then our frame has
564 already been deallocated. Note this can also be true for retf
565 and ret if they specify a size of zero.
567 In this case fi->frame is bogus, we need to fix it. */
568 if (fi
&& buf
[0] == 0xf0 && buf
[1] == 0xfc)
570 if (get_next_frame (fi
) == NULL
)
571 deprecated_update_frame_base_hack (fi
, read_sp ());
572 return get_frame_pc (fi
);
575 /* Similarly if we're stopped on the first insn of a prologue as our
576 frame hasn't been allocated yet. */
577 if (fi
&& get_frame_pc (fi
) == func_addr
)
579 if (get_next_frame (fi
) == NULL
)
580 deprecated_update_frame_base_hack (fi
, read_sp ());
581 return get_frame_pc (fi
);
585 /* NOTE: from here on, we don't want to return without jumping to
589 /* Figure out where to stop scanning. */
590 stop
= fi
? pc
: func_end
;
592 /* Don't walk off the end of the function. */
593 stop
= stop
> func_end
? func_end
: stop
;
595 /* Start scanning on the first instruction of this function. */
598 /* Suck in two bytes. */
600 || (status
= deprecated_read_memory_nobpt (addr
, buf
, 2)) != 0)
601 goto finish_prologue
;
603 /* First see if this insn sets the stack pointer from a register; if
604 so, it's probably the initialization of the stack pointer in _start,
605 so mark this as the bottom-most frame. */
606 if (buf
[0] == 0xf2 && (buf
[1] & 0xf3) == 0xf0)
609 my_frame_is_last (fi
);
610 goto finish_prologue
;
613 /* Now look for movm [regs],sp, which saves the callee saved registers.
615 At this time we don't know if fi->frame is valid, so we only note
616 that we encountered a movm instruction. Later, we'll set the entries
617 in fsr.regs as needed. */
620 /* Extract the register list for the movm instruction. */
625 /* Quit now if we're beyond the stop point. */
627 goto finish_prologue
;
629 /* Get the next two bytes so the prologue scan can continue. */
630 status
= deprecated_read_memory_nobpt (addr
, buf
, 2);
632 goto finish_prologue
;
635 /* Now see if we set up a frame pointer via "mov sp,a3" */
640 /* The frame pointer is now valid. */
643 my_frame_is_in_fp (fi
, this_cache
);
646 /* Quit now if we're beyond the stop point. */
648 goto finish_prologue
;
650 /* Get two more bytes so scanning can continue. */
651 status
= deprecated_read_memory_nobpt (addr
, buf
, 2);
653 goto finish_prologue
;
656 /* Next we should allocate the local frame. No more prologue insns
657 are found after allocating the local frame.
659 Search for add imm8,sp (0xf8feXX)
660 or add imm16,sp (0xfafeXXXX)
661 or add imm32,sp (0xfcfeXXXXXXXX).
663 If none of the above was found, then this prologue has no
667 if (buf
[0] == 0xf8 && buf
[1] == 0xfe)
669 else if (buf
[0] == 0xfa && buf
[1] == 0xfe)
671 else if (buf
[0] == 0xfc && buf
[1] == 0xfe)
676 /* Suck in imm_size more bytes, they'll hold the size of the
678 status
= deprecated_read_memory_nobpt (addr
+ 2, buf
, imm_size
);
680 goto finish_prologue
;
682 /* Note the size of the stack in the frame info structure. */
683 stack_size
= extract_signed_integer (buf
, imm_size
);
685 set_my_stack_size (fi
, stack_size
);
687 /* We just consumed 2 + imm_size bytes. */
688 addr
+= 2 + imm_size
;
690 /* No more prologue insns follow, so begin preparation to return. */
691 goto finish_prologue
;
693 /* Do the essentials and get out of here. */
695 /* Note if/where callee saved registers were saved. */
697 set_movm_offsets (fi
, this_cache
, movm_args
);
701 /* Function: skip_prologue
702 Return the address of the first inst past the prologue of the function. */
705 mn10300_skip_prologue (CORE_ADDR pc
)
707 return mn10300_analyze_prologue (NULL
, NULL
, pc
);
710 /* Simple frame_unwind_cache.
711 This finds the "extra info" for the frame. */
712 struct trad_frame_cache
*
713 mn10300_frame_unwind_cache (struct frame_info
*next_frame
,
714 void **this_prologue_cache
)
716 struct trad_frame_cache
*cache
;
717 CORE_ADDR pc
, start
, end
;
719 if (*this_prologue_cache
)
720 return (*this_prologue_cache
);
722 cache
= trad_frame_cache_zalloc (next_frame
);
723 pc
= gdbarch_unwind_pc (current_gdbarch
, next_frame
);
724 mn10300_analyze_prologue (next_frame
, (void **) &cache
, pc
);
725 if (find_pc_partial_function (pc
, NULL
, &start
, &end
))
726 trad_frame_set_id (cache
,
727 frame_id_build (trad_frame_get_this_base (cache
),
730 trad_frame_set_id (cache
,
731 frame_id_build (trad_frame_get_this_base (cache
),
732 frame_func_unwind (next_frame
)));
734 (*this_prologue_cache
) = cache
;
738 /* Here is a dummy implementation. */
739 static struct frame_id
740 mn10300_unwind_dummy_id (struct gdbarch
*gdbarch
,
741 struct frame_info
*next_frame
)
743 return frame_id_build (frame_sp_unwind (next_frame
),
744 frame_pc_unwind (next_frame
));
747 /* Trad frame implementation. */
749 mn10300_frame_this_id (struct frame_info
*next_frame
,
750 void **this_prologue_cache
,
751 struct frame_id
*this_id
)
753 struct trad_frame_cache
*cache
=
754 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
756 trad_frame_get_id (cache
, this_id
);
760 mn10300_frame_prev_register (struct frame_info
*next_frame
,
761 void **this_prologue_cache
,
762 int regnum
, int *optimizedp
,
763 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
764 int *realnump
, gdb_byte
*bufferp
)
766 struct trad_frame_cache
*cache
=
767 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
769 trad_frame_get_register (cache
, next_frame
, regnum
, optimizedp
,
770 lvalp
, addrp
, realnump
, bufferp
);
772 trad_frame_get_prev_register (next_frame, cache->prev_regs, regnum,
773 optimizedp, lvalp, addrp, realnump, bufferp);
777 static const struct frame_unwind mn10300_frame_unwind
= {
779 mn10300_frame_this_id
,
780 mn10300_frame_prev_register
784 mn10300_frame_base_address (struct frame_info
*next_frame
,
785 void **this_prologue_cache
)
787 struct trad_frame_cache
*cache
=
788 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
790 return trad_frame_get_this_base (cache
);
793 static const struct frame_unwind
*
794 mn10300_frame_sniffer (struct frame_info
*next_frame
)
796 return &mn10300_frame_unwind
;
799 static const struct frame_base mn10300_frame_base
= {
800 &mn10300_frame_unwind
,
801 mn10300_frame_base_address
,
802 mn10300_frame_base_address
,
803 mn10300_frame_base_address
807 mn10300_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
811 frame_unwind_unsigned_register (next_frame
, E_PC_REGNUM
, &pc
);
816 mn10300_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
820 frame_unwind_unsigned_register (next_frame
, E_SP_REGNUM
, &sp
);
825 mn10300_frame_unwind_init (struct gdbarch
*gdbarch
)
827 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
828 frame_unwind_append_sniffer (gdbarch
, mn10300_frame_sniffer
);
829 frame_base_set_default (gdbarch
, &mn10300_frame_base
);
830 set_gdbarch_unwind_dummy_id (gdbarch
, mn10300_unwind_dummy_id
);
831 set_gdbarch_unwind_pc (gdbarch
, mn10300_unwind_pc
);
832 set_gdbarch_unwind_sp (gdbarch
, mn10300_unwind_sp
);
835 /* Function: push_dummy_call
837 * Set up machine state for a target call, including
838 * function arguments, stack, return address, etc.
843 mn10300_push_dummy_call (struct gdbarch
*gdbarch
,
844 struct value
*target_func
,
845 struct regcache
*regcache
,
847 int nargs
, struct value
**args
,
850 CORE_ADDR struct_addr
)
852 const int push_size
= register_size (gdbarch
, E_PC_REGNUM
);
855 int stack_offset
= 0;
857 char *val
, valbuf
[MAX_REGISTER_SIZE
];
859 /* This should be a nop, but align the stack just in case something
860 went wrong. Stacks are four byte aligned on the mn10300. */
863 /* Now make space on the stack for the args.
865 XXX This doesn't appear to handle pass-by-invisible reference
867 regs_used
= struct_return
? 1 : 0;
868 for (len
= 0, argnum
= 0; argnum
< nargs
; argnum
++)
870 arg_len
= (TYPE_LENGTH (value_type (args
[argnum
])) + 3) & ~3;
871 while (regs_used
< 2 && arg_len
> 0)
874 arg_len
-= push_size
;
879 /* Allocate stack space. */
885 write_register (E_D0_REGNUM
, struct_addr
);
890 /* Push all arguments onto the stack. */
891 for (argnum
= 0; argnum
< nargs
; argnum
++)
893 /* FIXME what about structs? Unions? */
894 if (TYPE_CODE (value_type (*args
)) == TYPE_CODE_STRUCT
895 && TYPE_LENGTH (value_type (*args
)) > 8)
897 /* Change to pointer-to-type. */
899 store_unsigned_integer (valbuf
, push_size
,
900 VALUE_ADDRESS (*args
));
905 arg_len
= TYPE_LENGTH (value_type (*args
));
906 val
= (char *) value_contents (*args
);
909 while (regs_used
< 2 && arg_len
> 0)
911 write_register (regs_used
,
912 extract_unsigned_integer (val
, push_size
));
914 arg_len
-= push_size
;
920 write_memory (sp
+ stack_offset
, val
, push_size
);
921 arg_len
-= push_size
;
923 stack_offset
+= push_size
;
929 /* Make space for the flushback area. */
932 /* Push the return address that contains the magic breakpoint. */
934 write_memory_unsigned_integer (sp
, push_size
, bp_addr
);
936 regcache_cooked_write_unsigned (regcache
, E_SP_REGNUM
, sp
);
940 /* If DWARF2 is a register number appearing in Dwarf2 debug info, then
941 mn10300_dwarf2_reg_to_regnum (DWARF2) is the corresponding GDB
942 register number. Why don't Dwarf2 and GDB use the same numbering?
943 Who knows? But since people have object files lying around with
944 the existing Dwarf2 numbering, and other people have written stubs
945 to work with the existing GDB, neither of them can change. So we
946 just have to cope. */
948 mn10300_dwarf2_reg_to_regnum (int dwarf2
)
950 /* This table is supposed to be shaped like the REGISTER_NAMES
951 initializer in gcc/config/mn10300/mn10300.h. Registers which
952 appear in GCC's numbering, but have no counterpart in GDB's
953 world, are marked with a -1. */
954 static int dwarf2_to_gdb
[] = {
955 0, 1, 2, 3, 4, 5, 6, 7, -1, 8,
956 15, 16, 17, 18, 19, 20, 21, 22,
957 32, 33, 34, 35, 36, 37, 38, 39,
958 40, 41, 42, 43, 44, 45, 46, 47,
959 48, 49, 50, 51, 52, 53, 54, 55,
960 56, 57, 58, 59, 60, 61, 62, 63
964 || dwarf2
>= (sizeof (dwarf2_to_gdb
) / sizeof (dwarf2_to_gdb
[0]))
965 || dwarf2_to_gdb
[dwarf2
] == -1)
966 internal_error (__FILE__
, __LINE__
,
967 "bogus register number in debug info: %d", dwarf2
);
969 return dwarf2_to_gdb
[dwarf2
];
972 static struct gdbarch
*
973 mn10300_gdbarch_init (struct gdbarch_info info
,
974 struct gdbarch_list
*arches
)
976 struct gdbarch
*gdbarch
;
977 struct gdbarch_tdep
*tdep
;
979 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
981 return arches
->gdbarch
;
983 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
984 gdbarch
= gdbarch_alloc (&info
, tdep
);
986 switch (info
.bfd_arch_info
->mach
)
989 case bfd_mach_mn10300
:
990 set_gdbarch_register_name (gdbarch
, mn10300_generic_register_name
);
994 set_gdbarch_register_name (gdbarch
, am33_register_name
);
998 internal_error (__FILE__
, __LINE__
,
999 _("mn10300_gdbarch_init: Unknown mn10300 variant"));
1004 set_gdbarch_num_regs (gdbarch
, E_NUM_REGS
);
1005 set_gdbarch_register_type (gdbarch
, mn10300_register_type
);
1006 set_gdbarch_skip_prologue (gdbarch
, mn10300_skip_prologue
);
1007 set_gdbarch_read_pc (gdbarch
, mn10300_read_pc
);
1008 set_gdbarch_write_pc (gdbarch
, mn10300_write_pc
);
1009 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
1010 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
1011 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, mn10300_dwarf2_reg_to_regnum
);
1013 /* Stack unwinding. */
1014 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1016 set_gdbarch_breakpoint_from_pc (gdbarch
, mn10300_breakpoint_from_pc
);
1017 /* decr_pc_after_break? */
1019 set_gdbarch_print_insn (gdbarch
, print_insn_mn10300
);
1022 set_gdbarch_return_value (gdbarch
, mn10300_return_value
);
1024 /* Stage 3 -- get target calls working. */
1025 set_gdbarch_push_dummy_call (gdbarch
, mn10300_push_dummy_call
);
1026 /* set_gdbarch_return_value (store, extract) */
1029 mn10300_frame_unwind_init (gdbarch
);
1031 /* Hook in ABI-specific overrides, if they have been registered. */
1032 gdbarch_init_osabi (info
, gdbarch
);
1037 /* Dump out the mn10300 specific architecture information. */
1040 mn10300_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
1042 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1043 fprintf_unfiltered (file
, "mn10300_dump_tdep: am33_mode = %d\n",
1048 _initialize_mn10300_tdep (void)
1050 gdbarch_register (bfd_arch_mn10300
, mn10300_gdbarch_init
, mn10300_dump_tdep
);