1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
4 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. */
25 To get from 1.1 to 1.2, add:
29 extract_struct_value_address
31 Make sure to use regcache. */
35 Apparently cannot run without a stub placeholder for unwind_dummy_id.
40 To get from 1.2 to 1.3, add:
43 struct mn10300_unwind_cache
48 frame_sniffer (struct mn10300_frame_unwind)
52 #include "arch-utils.h"
56 #include "gdb_string.h"
57 #include "gdb_assert.h"
59 #include "frame-unwind.h"
60 #include "frame-base.h"
61 #include "trad-frame.h"
63 #include "dwarf2-frame.h"
66 #include "mn10300-tdep.h"
92 /* Compute the alignment required by a type. */
95 mn10300_type_align (struct type
*type
)
99 switch (TYPE_CODE (type
))
104 case TYPE_CODE_RANGE
:
110 return TYPE_LENGTH (type
);
112 case TYPE_CODE_COMPLEX
:
113 return TYPE_LENGTH (type
) / 2;
115 case TYPE_CODE_STRUCT
:
116 case TYPE_CODE_UNION
:
117 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
119 int falign
= mn10300_type_align (TYPE_FIELD_TYPE (type
, i
));
120 while (align
< falign
)
125 case TYPE_CODE_ARRAY
:
126 /* HACK! Structures containing arrays, even small ones, are not
127 elligible for returning in registers. */
130 case TYPE_CODE_TYPEDEF
:
131 return mn10300_type_align (check_typedef (type
));
134 internal_error (__FILE__
, __LINE__
, _("bad switch"));
138 /* MVS note this is deprecated. */
139 /* Should call_function allocate stack space for a struct return? */
142 mn10300_use_struct_convention (int gcc_p
, struct type
*type
)
144 /* Structures bigger than a pair of words can't be returned in
146 if (TYPE_LENGTH (type
) > 8)
149 switch (TYPE_CODE (type
))
151 case TYPE_CODE_STRUCT
:
152 case TYPE_CODE_UNION
:
153 /* Structures with a single field are handled as the field
155 if (TYPE_NFIELDS (type
) == 1)
156 return mn10300_use_struct_convention (gcc_p
,
157 TYPE_FIELD_TYPE (type
, 0));
159 /* Structures with word or double-word size are passed in memory, as
160 long as they require at least word alignment. */
161 if (mn10300_type_align (type
) >= 4)
166 /* Arrays are addressable, so they're never returned in
167 registers. This condition can only hold when the array is
168 the only field of a struct or union. */
169 case TYPE_CODE_ARRAY
:
172 case TYPE_CODE_TYPEDEF
:
173 return mn10300_use_struct_convention (gcc_p
, check_typedef (type
));
180 /* MVS note this is deprecated. */
182 mn10300_store_return_value (struct type
*type
,
183 struct regcache
*regcache
, const void *valbuf
)
185 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
186 int len
= TYPE_LENGTH (type
);
189 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
194 regsz
= register_size (gdbarch
, reg
);
197 regcache_raw_write_part (regcache
, reg
, 0, len
, valbuf
);
198 else if (len
<= 2 * regsz
)
200 regcache_raw_write (regcache
, reg
, valbuf
);
201 gdb_assert (regsz
== register_size (gdbarch
, reg
+ 1));
202 regcache_raw_write_part (regcache
, reg
+1, 0,
203 len
- regsz
, (char *) valbuf
+ regsz
);
206 internal_error (__FILE__
, __LINE__
,
207 _("Cannot store return value %d bytes long."), len
);
210 /* MVS note deprecated. */
212 mn10300_extract_return_value (struct type
*type
,
213 struct regcache
*regcache
, void *valbuf
)
215 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
216 char buf
[MAX_REGISTER_SIZE
];
217 int len
= TYPE_LENGTH (type
);
220 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
225 regsz
= register_size (gdbarch
, reg
);
228 regcache_raw_read (regcache
, reg
, buf
);
229 memcpy (valbuf
, buf
, len
);
231 else if (len
<= 2 * regsz
)
233 regcache_raw_read (regcache
, reg
, buf
);
234 memcpy (valbuf
, buf
, regsz
);
235 gdb_assert (regsz
== register_size (gdbarch
, reg
+ 1));
236 regcache_raw_read (regcache
, reg
+ 1, buf
);
237 memcpy ((char *) valbuf
+ regsz
, buf
, len
- regsz
);
240 internal_error (__FILE__
, __LINE__
,
241 _("Cannot extract return value %d bytes long."), len
);
245 register_name (int reg
, char **regs
, long sizeof_regs
)
247 if (reg
< 0 || reg
>= sizeof_regs
/ sizeof (regs
[0]))
254 mn10300_generic_register_name (int reg
)
256 static char *regs
[] =
257 { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
258 "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
259 "", "", "", "", "", "", "", "",
260 "", "", "", "", "", "", "", "fp"
262 return register_name (reg
, regs
, sizeof regs
);
267 am33_register_name (int reg
)
269 static char *regs
[] =
270 { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
271 "sp", "pc", "mdr", "psw", "lir", "lar", "",
272 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
273 "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", ""
275 return register_name (reg
, regs
, sizeof regs
);
280 mn10300_register_type (struct gdbarch
*gdbarch
, int reg
)
282 return builtin_type_int
;
286 mn10300_read_pc (ptid_t ptid
)
288 return read_register_pid (E_PC_REGNUM
, ptid
);
292 mn10300_write_pc (CORE_ADDR val
, ptid_t ptid
)
294 return write_register_pid (E_PC_REGNUM
, val
, ptid
);
297 /* The breakpoint instruction must be the same size as the smallest
298 instruction in the instruction set.
300 The Matsushita mn10x00 processors have single byte instructions
301 so we need a single byte breakpoint. Matsushita hasn't defined
302 one, so we defined it ourselves. */
304 const static unsigned char *
305 mn10300_breakpoint_from_pc (CORE_ADDR
*bp_addr
, int *bp_size
)
307 static char breakpoint
[] = {0xff};
312 /* Function: skip_prologue
313 Return the address of the first inst past the prologue of the function. */
316 mn10300_skip_prologue (CORE_ADDR pc
)
318 /* FIXME: not implemented. */
319 /* First approximation, try simply using skip_prologue_using_sal. */
320 return skip_prologue_using_sal (pc
);
323 /* Simple frame_unwind_cache.
324 This finds the "extra info" for the frame. */
325 struct trad_frame_cache
*
326 mn10300_frame_unwind_cache (struct frame_info
*next_frame
,
327 void **this_prologue_cache
)
329 struct trad_frame_cache
*cache
;
331 if (*this_prologue_cache
)
332 return (*this_prologue_cache
);
334 cache
= trad_frame_cache_zalloc (next_frame
);
335 trad_frame_set_id (cache
,
336 frame_id_build (gdbarch_unwind_sp (current_gdbarch
,
338 gdbarch_unwind_pc (current_gdbarch
,
341 /* FIXME: The SP isn't the frame base, so this is 0th approximation. */
342 /* FIXME: The A3 reg isn't always the frame register either, so this
343 is 1st approximation. */
344 trad_frame_set_this_base (cache
,
345 frame_unwind_register_signed (next_frame
,
347 (*this_prologue_cache
) = cache
;
351 /* Here is a dummy implementation. */
352 static struct frame_id
353 mn10300_dummy_unwind_dummy_id (struct gdbarch
*gdbarch
,
354 struct frame_info
*next_frame
)
356 return frame_id_build (0, 0);
359 /* Trad frame implementation. */
361 mn10300_frame_this_id (struct frame_info
*next_frame
,
362 void **this_prologue_cache
,
363 struct frame_id
*this_id
)
365 struct trad_frame_cache
*cache
=
366 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
368 trad_frame_get_id (cache
, this_id
);
372 mn10300_frame_prev_register (struct frame_info
*next_frame
,
373 void **this_prologue_cache
,
374 int regnum
, int *optimizedp
,
375 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
376 int *realnump
, void *bufferp
)
378 struct trad_frame_cache
*cache
=
379 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
381 trad_frame_get_register (cache
, next_frame
, regnum
, optimizedp
,
382 lvalp
, addrp
, realnump
, bufferp
);
384 trad_frame_get_prev_register (next_frame, cache->prev_regs, regnum,
385 optimizedp, lvalp, addrp, realnump, bufferp);
389 static const struct frame_unwind mn10300_frame_unwind
= {
391 mn10300_frame_this_id
,
392 mn10300_frame_prev_register
396 mn10300_frame_base_address (struct frame_info
*next_frame
,
397 void **this_prologue_cache
)
399 struct trad_frame_cache
*cache
=
400 mn10300_frame_unwind_cache (next_frame
, this_prologue_cache
);
402 return trad_frame_get_this_base (cache
);
405 static const struct frame_unwind
*
406 mn10300_frame_sniffer (struct frame_info
*next_frame
)
408 return &mn10300_frame_unwind
;
411 static const struct frame_base mn10300_frame_base
= {
412 &mn10300_frame_unwind
,
413 mn10300_frame_base_address
,
414 mn10300_frame_base_address
,
415 mn10300_frame_base_address
419 mn10300_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
423 frame_unwind_unsigned_register (next_frame
, E_PC_REGNUM
, &pc
);
428 mn10300_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
432 frame_unwind_unsigned_register (next_frame
, E_SP_REGNUM
, &sp
);
437 mn10300_frame_unwind_init (struct gdbarch
*gdbarch
)
439 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
440 frame_unwind_append_sniffer (gdbarch
, mn10300_frame_sniffer
);
441 frame_base_set_default (gdbarch
, &mn10300_frame_base
);
442 set_gdbarch_unwind_dummy_id (gdbarch
, mn10300_dummy_unwind_dummy_id
);
443 set_gdbarch_unwind_pc (gdbarch
, mn10300_unwind_pc
);
444 set_gdbarch_unwind_sp (gdbarch
, mn10300_unwind_sp
);
447 /* Dump out the mn10300 specific architecture information. */
450 mn10300_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
452 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
453 fprintf_unfiltered (file
, "mn10300_dump_tdep: am33_mode = %d\n",
457 static struct gdbarch
*
458 mn10300_gdbarch_init (struct gdbarch_info info
,
459 struct gdbarch_list
*arches
)
461 struct gdbarch
*gdbarch
;
462 struct gdbarch_tdep
*tdep
;
464 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
466 return arches
->gdbarch
;
468 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
469 gdbarch
= gdbarch_alloc (&info
, tdep
);
471 switch (info
.bfd_arch_info
->mach
)
474 case bfd_mach_mn10300
:
475 set_gdbarch_register_name (gdbarch
, mn10300_generic_register_name
);
479 set_gdbarch_register_name (gdbarch
, am33_register_name
);
483 internal_error (__FILE__
, __LINE__
,
484 _("mn10300_gdbarch_init: Unknown mn10300 variant"));
489 set_gdbarch_num_regs (gdbarch
, E_NUM_REGS
);
490 set_gdbarch_register_type (gdbarch
, mn10300_register_type
);
491 set_gdbarch_skip_prologue (gdbarch
, mn10300_skip_prologue
);
492 set_gdbarch_read_pc (gdbarch
, mn10300_read_pc
);
493 set_gdbarch_write_pc (gdbarch
, mn10300_write_pc
);
494 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
495 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
497 /* Stack unwinding. */
498 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
500 set_gdbarch_breakpoint_from_pc (gdbarch
, mn10300_breakpoint_from_pc
);
501 /* decr_pc_after_break? */
503 set_gdbarch_print_insn (gdbarch
, print_insn_mn10300
);
506 /* MVS Note: at least the first one is deprecated! */
507 set_gdbarch_deprecated_use_struct_convention (gdbarch
,
508 mn10300_use_struct_convention
);
509 set_gdbarch_store_return_value (gdbarch
, mn10300_store_return_value
);
510 set_gdbarch_extract_return_value (gdbarch
, mn10300_extract_return_value
);
512 mn10300_frame_unwind_init (gdbarch
);
518 _initialize_mn10300_tdep (void)
520 gdbarch_register (bfd_arch_mn10300
, mn10300_gdbarch_init
, mn10300_dump_tdep
);