Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger. |
cda5a58a | 2 | |
464e0365 AC |
3 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free |
4 | Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
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. | |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b JM |
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. */ | |
c906108c | 22 | |
81c0587e MS |
23 | /* MVS Notes: |
24 | ||
25 | To get from 1.1 to 1.2, add: | |
26 | use_struct_convention | |
27 | store_return_value | |
28 | extract_return_value | |
29 | extract_struct_value_address | |
30 | ||
31 | Make sure to use regcache. */ | |
32 | ||
33 | /* MVS Notes: | |
34 | ||
35 | Apparently cannot run without a stub placeholder for unwind_dummy_id. | |
36 | */ | |
37 | ||
38 | /* MVS Notes: | |
39 | ||
40 | To get from 1.2 to 1.3, add: | |
41 | read_pc, write_pc | |
42 | frame_unwind_init | |
43 | struct mn10300_unwind_cache | |
44 | unwind_pc | |
45 | unwind_dummy_id | |
46 | frame_this_id | |
47 | frame_prev_register | |
48 | frame_sniffer (struct mn10300_frame_unwind) | |
49 | */ | |
50 | ||
c906108c | 51 | #include "defs.h" |
ad8fe2ce | 52 | #include "arch-utils.h" |
a89aa300 | 53 | #include "dis-asm.h" |
81c0587e MS |
54 | #include "gdbtypes.h" |
55 | #include "regcache.h" | |
56 | #include "gdb_string.h" | |
57 | #include "gdb_assert.h" | |
58 | #include "frame.h" | |
59 | #include "frame-unwind.h" | |
60 | #include "frame-base.h" | |
61 | #include "trad-frame.h" | |
62 | #include "symtab.h" | |
63 | #include "dwarf2-frame.h" | |
64 | #include "regcache.h" | |
c906108c | 65 | |
81c0587e MS |
66 | enum { |
67 | E_D0_REGNUM = 0, | |
68 | E_D1_REGNUM = 1, | |
69 | E_D2_REGNUM = 2, | |
70 | E_D3_REGNUM = 3, | |
71 | E_A0_REGNUM = 4, | |
72 | E_A1_REGNUM = 5, | |
73 | E_A2_REGNUM = 6, | |
74 | E_A3_REGNUM = 7, | |
75 | E_SP_REGNUM = 8, | |
76 | E_PC_REGNUM = 9, | |
77 | E_MDR_REGNUM = 10, | |
78 | E_PSW_REGNUM = 11, | |
79 | E_LIR_REGNUM = 12, | |
80 | E_LAR_REGNUM = 13, | |
81 | E_MDRQ_REGNUM = 14, | |
82 | E_E0_REGNUM = 15, | |
83 | E_MCRH_REGNUM = 26, | |
84 | E_MCRL_REGNUM = 27, | |
85 | E_MCVF_REGNUM = 28, | |
86 | E_NUM_REGS = 32 | |
91225883 AC |
87 | }; |
88 | ||
c906108c | 89 | |
d560a54b AO |
90 | /* Compute the alignment required by a type. */ |
91 | ||
92 | static int | |
93 | mn10300_type_align (struct type *type) | |
94 | { | |
95 | int i, align = 1; | |
96 | ||
97 | switch (TYPE_CODE (type)) | |
98 | { | |
99 | case TYPE_CODE_INT: | |
100 | case TYPE_CODE_ENUM: | |
101 | case TYPE_CODE_SET: | |
102 | case TYPE_CODE_RANGE: | |
103 | case TYPE_CODE_CHAR: | |
104 | case TYPE_CODE_BOOL: | |
105 | case TYPE_CODE_FLT: | |
106 | case TYPE_CODE_PTR: | |
107 | case TYPE_CODE_REF: | |
108 | return TYPE_LENGTH (type); | |
109 | ||
110 | case TYPE_CODE_COMPLEX: | |
111 | return TYPE_LENGTH (type) / 2; | |
112 | ||
113 | case TYPE_CODE_STRUCT: | |
114 | case TYPE_CODE_UNION: | |
115 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
116 | { | |
117 | int falign = mn10300_type_align (TYPE_FIELD_TYPE (type, i)); | |
118 | while (align < falign) | |
119 | align <<= 1; | |
120 | } | |
121 | return align; | |
122 | ||
123 | case TYPE_CODE_ARRAY: | |
124 | /* HACK! Structures containing arrays, even small ones, are not | |
125 | elligible for returning in registers. */ | |
126 | return 256; | |
127 | ||
128 | case TYPE_CODE_TYPEDEF: | |
129 | return mn10300_type_align (check_typedef (type)); | |
130 | ||
131 | default: | |
fc720350 | 132 | internal_error (__FILE__, __LINE__, "bad switch"); |
d560a54b AO |
133 | } |
134 | } | |
c906108c | 135 | |
81c0587e | 136 | /* MVS note this is deprecated. */ |
c906108c | 137 | /* Should call_function allocate stack space for a struct return? */ |
81c0587e | 138 | /* gcc_p unused */ |
2ac51b36 | 139 | static int |
81c0587e | 140 | mn10300_use_struct_convention (int gcc_p, struct type *type) |
d560a54b AO |
141 | { |
142 | /* Structures bigger than a pair of words can't be returned in | |
143 | registers. */ | |
144 | if (TYPE_LENGTH (type) > 8) | |
145 | return 1; | |
146 | ||
147 | switch (TYPE_CODE (type)) | |
148 | { | |
149 | case TYPE_CODE_STRUCT: | |
150 | case TYPE_CODE_UNION: | |
151 | /* Structures with a single field are handled as the field | |
152 | itself. */ | |
153 | if (TYPE_NFIELDS (type) == 1) | |
81c0587e MS |
154 | return mn10300_use_struct_convention (gcc_p, |
155 | TYPE_FIELD_TYPE (type, 0)); | |
d560a54b AO |
156 | |
157 | /* Structures with word or double-word size are passed in memory, as | |
158 | long as they require at least word alignment. */ | |
159 | if (mn10300_type_align (type) >= 4) | |
160 | return 0; | |
161 | ||
162 | return 1; | |
163 | ||
164 | /* Arrays are addressable, so they're never returned in | |
165 | registers. This condition can only hold when the array is | |
166 | the only field of a struct or union. */ | |
167 | case TYPE_CODE_ARRAY: | |
168 | return 1; | |
169 | ||
170 | case TYPE_CODE_TYPEDEF: | |
81c0587e | 171 | return mn10300_use_struct_convention (gcc_p, check_typedef (type)); |
d560a54b AO |
172 | |
173 | default: | |
174 | return 0; | |
175 | } | |
176 | } | |
177 | ||
81c0587e MS |
178 | /* MVS note this is deprecated. */ |
179 | static void | |
180 | mn10300_store_return_value (struct type *type, | |
181 | struct regcache *regcache, const void *valbuf) | |
c906108c | 182 | { |
81c0587e MS |
183 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
184 | int len = TYPE_LENGTH (type); | |
185 | int reg, regsz; | |
186 | ||
187 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
188 | reg = 4; | |
189 | else | |
190 | reg = 0; | |
c906108c | 191 | |
81c0587e | 192 | regsz = register_size (gdbarch, reg); |
c906108c | 193 | |
81c0587e MS |
194 | if (len <= regsz) |
195 | regcache_raw_write_part (regcache, reg, 0, len, valbuf); | |
196 | else if (len <= 2 * regsz) | |
c906108c | 197 | { |
81c0587e MS |
198 | regcache_raw_write (regcache, reg, valbuf); |
199 | gdb_assert (regsz == register_size (gdbarch, reg + 1)); | |
200 | regcache_raw_write_part (regcache, reg+1, 0, | |
201 | len - regsz, (char *) valbuf + regsz); | |
c906108c | 202 | } |
81c0587e MS |
203 | else |
204 | internal_error (__FILE__, __LINE__, | |
205 | "Cannot store return value %d bytes long.", len); | |
c906108c SS |
206 | } |
207 | ||
81c0587e | 208 | /* MVS note deprecated. */ |
c906108c | 209 | static void |
81c0587e MS |
210 | mn10300_extract_return_value (struct type *type, |
211 | struct regcache *regcache, void *valbuf) | |
c906108c | 212 | { |
81c0587e MS |
213 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
214 | char buf[MAX_REGISTER_SIZE]; | |
215 | int len = TYPE_LENGTH (type); | |
216 | int reg, regsz; | |
c906108c | 217 | |
81c0587e MS |
218 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
219 | reg = 4; | |
220 | else | |
221 | reg = 0; | |
c906108c | 222 | |
81c0587e MS |
223 | regsz = register_size (gdbarch, reg); |
224 | if (len <= regsz) | |
c906108c | 225 | { |
81c0587e MS |
226 | regcache_raw_read (regcache, reg, buf); |
227 | memcpy (valbuf, buf, len); | |
c906108c | 228 | } |
81c0587e | 229 | else if (len <= 2 * regsz) |
c2d11a7d | 230 | { |
81c0587e MS |
231 | regcache_raw_read (regcache, reg, buf); |
232 | memcpy (valbuf, buf, regsz); | |
233 | gdb_assert (regsz == register_size (gdbarch, reg + 1)); | |
234 | regcache_raw_read (regcache, reg + 1, buf); | |
235 | memcpy ((char *) valbuf + regsz, buf, len - regsz); | |
c2d11a7d | 236 | } |
81c0587e MS |
237 | else |
238 | internal_error (__FILE__, __LINE__, | |
239 | "Cannot extract return value %d bytes long.", len); | |
c906108c SS |
240 | } |
241 | ||
81c0587e MS |
242 | static char * |
243 | register_name (int reg, char **regs, long sizeof_regs) | |
c906108c | 244 | { |
81c0587e MS |
245 | if (reg < 0 || reg >= sizeof_regs / sizeof (regs[0])) |
246 | return NULL; | |
247 | else | |
248 | return regs[reg]; | |
c906108c | 249 | } |
c5aa993b | 250 | |
81c0587e MS |
251 | static const char * |
252 | mn10300_generic_register_name (int reg) | |
ae83b20d | 253 | { |
81c0587e MS |
254 | static char *regs[] = |
255 | { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3", | |
256 | "sp", "pc", "mdr", "psw", "lir", "lar", "", "", | |
257 | "", "", "", "", "", "", "", "", | |
258 | "", "", "", "", "", "", "", "fp" | |
259 | }; | |
260 | return register_name (reg, regs, sizeof regs); | |
ae83b20d JB |
261 | } |
262 | ||
263 | ||
81c0587e MS |
264 | static const char * |
265 | am33_register_name (int reg) | |
c906108c | 266 | { |
81c0587e MS |
267 | static char *regs[] = |
268 | { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3", | |
269 | "sp", "pc", "mdr", "psw", "lir", "lar", "", | |
270 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
271 | "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", "" | |
272 | }; | |
273 | return register_name (reg, regs, sizeof regs); | |
c906108c SS |
274 | } |
275 | ||
c906108c | 276 | |
81c0587e MS |
277 | static struct type * |
278 | mn10300_register_type (struct gdbarch *gdbarch, int reg) | |
c906108c | 279 | { |
81c0587e | 280 | return builtin_type_int; |
c906108c SS |
281 | } |
282 | ||
81c0587e MS |
283 | static CORE_ADDR |
284 | mn10300_read_pc (ptid_t ptid) | |
c906108c | 285 | { |
81c0587e | 286 | return read_register_pid (E_PC_REGNUM, ptid); |
ee9f9641 JB |
287 | } |
288 | ||
ee9f9641 | 289 | static void |
81c0587e | 290 | mn10300_write_pc (CORE_ADDR val, ptid_t ptid) |
ee9f9641 | 291 | { |
81c0587e | 292 | return write_register_pid (E_PC_REGNUM, val, ptid); |
c906108c SS |
293 | } |
294 | ||
81c0587e MS |
295 | /* The breakpoint instruction must be the same size as the smallest |
296 | instruction in the instruction set. | |
c906108c | 297 | |
81c0587e MS |
298 | The Matsushita mn10x00 processors have single byte instructions |
299 | so we need a single byte breakpoint. Matsushita hasn't defined | |
300 | one, so we defined it ourselves. */ | |
c5aa993b | 301 | |
81c0587e MS |
302 | const static unsigned char * |
303 | mn10300_breakpoint_from_pc (CORE_ADDR *bp_addr, int *bp_size) | |
c906108c | 304 | { |
81c0587e MS |
305 | static char breakpoint[] = {0xff}; |
306 | *bp_size = 1; | |
307 | return breakpoint; | |
c906108c | 308 | } |
c5aa993b | 309 | |
81c0587e MS |
310 | /* Function: skip_prologue |
311 | Return the address of the first inst past the prologue of the function. */ | |
c906108c | 312 | |
2ac51b36 | 313 | static CORE_ADDR |
81c0587e | 314 | mn10300_skip_prologue (CORE_ADDR pc) |
c906108c | 315 | { |
81c0587e MS |
316 | /* FIXME: not implemented. */ |
317 | /* First approximation, try simply using scan_prologue_using_sal. */ | |
318 | return skip_prologue_using_sal (pc); | |
c906108c SS |
319 | } |
320 | ||
81c0587e MS |
321 | /* Simple frame_unwind_cache. |
322 | This finds the "extra info" for the frame. */ | |
323 | static struct trad_frame_cache * | |
324 | mn10300_frame_unwind_cache (struct frame_info *next_frame, | |
325 | void **this_prologue_cache) | |
c906108c | 326 | { |
81c0587e | 327 | struct trad_frame_cache *cache; |
c906108c | 328 | |
81c0587e MS |
329 | if (*this_prologue_cache) |
330 | return (*this_prologue_cache); | |
c906108c | 331 | |
81c0587e MS |
332 | cache = trad_frame_cache_zalloc (next_frame); |
333 | trad_frame_set_id (cache, | |
334 | frame_id_build (gdbarch_unwind_sp (current_gdbarch, | |
335 | next_frame), | |
336 | gdbarch_unwind_pc (current_gdbarch, | |
337 | next_frame))); | |
c906108c | 338 | |
81c0587e MS |
339 | /* FIXME: The SP isn't the frame base, so this is 0th approximation. */ |
340 | /* FIXME: The A3 reg isn't always the frame register either, so this | |
341 | is 1st approximation. */ | |
342 | trad_frame_set_this_base (cache, | |
343 | frame_unwind_register_signed (next_frame, | |
344 | E_A3_REGNUM)); | |
345 | (*this_prologue_cache) = cache; | |
346 | return cache; | |
c906108c SS |
347 | } |
348 | ||
81c0587e MS |
349 | /* Here is a dummy implementation. */ |
350 | static struct frame_id | |
351 | mn10300_dummy_unwind_dummy_id (struct gdbarch *gdbarch, | |
352 | struct frame_info *next_frame) | |
ad8fe2ce | 353 | { |
81c0587e | 354 | return frame_id_build (0, 0); |
ad8fe2ce JB |
355 | } |
356 | ||
81c0587e | 357 | /* Trad frame implementation. */ |
39d4ef09 | 358 | static void |
81c0587e MS |
359 | mn10300_frame_this_id (struct frame_info *next_frame, |
360 | void **this_prologue_cache, | |
361 | struct frame_id *this_id) | |
c906108c | 362 | { |
81c0587e MS |
363 | struct trad_frame_cache *cache = |
364 | mn10300_frame_unwind_cache (next_frame, this_prologue_cache); | |
c5aa993b | 365 | |
81c0587e | 366 | trad_frame_get_id (cache, this_id); |
91225883 | 367 | } |
c906108c | 368 | |
81c0587e MS |
369 | static void |
370 | mn10300_frame_prev_register (struct frame_info *next_frame, | |
371 | void **this_prologue_cache, | |
372 | int regnum, int *optimizedp, | |
373 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
374 | int *realnump, void *bufferp) | |
375 | { | |
376 | struct trad_frame_cache *cache = | |
377 | mn10300_frame_unwind_cache (next_frame, this_prologue_cache); | |
378 | ||
379 | trad_frame_get_register (cache, next_frame, regnum, optimizedp, | |
380 | lvalp, addrp, realnump, bufferp); | |
381 | /* Or... | |
382 | trad_frame_get_prev_register (next_frame, cache->prev_regs, regnum, | |
383 | optimizedp, lvalp, addrp, realnump, bufferp); | |
384 | */ | |
f6df245f AC |
385 | } |
386 | ||
81c0587e MS |
387 | static const struct frame_unwind mn10300_frame_unwind = { |
388 | NORMAL_FRAME, | |
389 | mn10300_frame_this_id, | |
390 | mn10300_frame_prev_register | |
391 | }; | |
f6df245f | 392 | |
81c0587e MS |
393 | static CORE_ADDR |
394 | mn10300_frame_base_address (struct frame_info *next_frame, | |
395 | void **this_prologue_cache) | |
f6df245f | 396 | { |
81c0587e MS |
397 | struct trad_frame_cache *cache = |
398 | mn10300_frame_unwind_cache (next_frame, this_prologue_cache); | |
f6df245f | 399 | |
81c0587e | 400 | return trad_frame_get_this_base (cache); |
f6df245f AC |
401 | } |
402 | ||
81c0587e MS |
403 | static const struct frame_unwind * |
404 | mn10300_frame_sniffer (struct frame_info *next_frame) | |
23436510 | 405 | { |
81c0587e | 406 | return &mn10300_frame_unwind; |
23436510 JB |
407 | } |
408 | ||
81c0587e MS |
409 | static const struct frame_base mn10300_frame_base = { |
410 | &mn10300_frame_unwind, | |
411 | mn10300_frame_base_address, | |
412 | mn10300_frame_base_address, | |
413 | mn10300_frame_base_address | |
414 | }; | |
f6df245f | 415 | |
81c0587e MS |
416 | static CORE_ADDR |
417 | mn10300_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
f6df245f | 418 | { |
81c0587e MS |
419 | ULONGEST pc; |
420 | ||
421 | frame_unwind_unsigned_register (next_frame, E_PC_REGNUM, &pc); | |
422 | return pc; | |
f6df245f AC |
423 | } |
424 | ||
bd1ce8ba | 425 | static CORE_ADDR |
81c0587e | 426 | mn10300_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) |
bd1ce8ba | 427 | { |
81c0587e | 428 | ULONGEST sp; |
bd1ce8ba | 429 | |
81c0587e MS |
430 | frame_unwind_unsigned_register (next_frame, E_SP_REGNUM, &sp); |
431 | return sp; | |
432 | } | |
c906108c | 433 | |
91225883 | 434 | static void |
81c0587e | 435 | mn10300_frame_unwind_init (struct gdbarch *gdbarch) |
91225883 | 436 | { |
81c0587e MS |
437 | frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer); |
438 | frame_unwind_append_sniffer (gdbarch, mn10300_frame_sniffer); | |
439 | frame_base_set_default (gdbarch, &mn10300_frame_base); | |
440 | set_gdbarch_unwind_dummy_id (gdbarch, mn10300_dummy_unwind_dummy_id); | |
441 | set_gdbarch_unwind_pc (gdbarch, mn10300_unwind_pc); | |
442 | set_gdbarch_unwind_sp (gdbarch, mn10300_unwind_sp); | |
91225883 | 443 | } |
c2d11a7d | 444 | |
91225883 AC |
445 | static struct gdbarch * |
446 | mn10300_gdbarch_init (struct gdbarch_info info, | |
447 | struct gdbarch_list *arches) | |
448 | { | |
449 | struct gdbarch *gdbarch; | |
91225883 AC |
450 | |
451 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
452 | if (arches != NULL) | |
453 | return arches->gdbarch; | |
81c0587e | 454 | gdbarch = gdbarch_alloc (&info, NULL); |
91225883 | 455 | |
81c0587e | 456 | switch (info.bfd_arch_info->mach) |
91225883 AC |
457 | { |
458 | case 0: | |
f6df245f | 459 | case bfd_mach_mn10300: |
81c0587e | 460 | set_gdbarch_register_name (gdbarch, mn10300_generic_register_name); |
91225883 AC |
461 | break; |
462 | case bfd_mach_am33: | |
81c0587e | 463 | set_gdbarch_register_name (gdbarch, am33_register_name); |
91225883 AC |
464 | break; |
465 | default: | |
8e65ff28 AC |
466 | internal_error (__FILE__, __LINE__, |
467 | "mn10300_gdbarch_init: Unknown mn10300 variant"); | |
81c0587e | 468 | break; |
c2d11a7d | 469 | } |
c906108c | 470 | |
584f96a8 | 471 | /* Registers. */ |
81c0587e MS |
472 | set_gdbarch_num_regs (gdbarch, E_NUM_REGS); |
473 | set_gdbarch_register_type (gdbarch, mn10300_register_type); | |
474 | set_gdbarch_skip_prologue (gdbarch, mn10300_skip_prologue); | |
475 | set_gdbarch_read_pc (gdbarch, mn10300_read_pc); | |
476 | set_gdbarch_write_pc (gdbarch, mn10300_write_pc); | |
477 | set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM); | |
478 | set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM); | |
584f96a8 JB |
479 | |
480 | /* Stack unwinding. */ | |
ad8fe2ce | 481 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
81c0587e MS |
482 | /* Breakpoints. */ |
483 | set_gdbarch_breakpoint_from_pc (gdbarch, mn10300_breakpoint_from_pc); | |
484 | /* decr_pc_after_break? */ | |
485 | /* Disassembly. */ | |
486 | set_gdbarch_print_insn (gdbarch, print_insn_mn10300); | |
91225883 | 487 | |
81c0587e MS |
488 | /* Stage 2 */ |
489 | /* MVS Note: at least the first one is deprecated! */ | |
490 | set_gdbarch_deprecated_use_struct_convention (gdbarch, | |
491 | mn10300_use_struct_convention); | |
492 | set_gdbarch_store_return_value (gdbarch, mn10300_store_return_value); | |
493 | set_gdbarch_extract_return_value (gdbarch, mn10300_extract_return_value); | |
6c0e89ed | 494 | |
81c0587e | 495 | mn10300_frame_unwind_init (gdbarch); |
36482093 | 496 | |
91225883 AC |
497 | return gdbarch; |
498 | } | |
499 | ||
c906108c | 500 | void |
fba45db2 | 501 | _initialize_mn10300_tdep (void) |
c906108c | 502 | { |
81c0587e | 503 | register_gdbarch_init (bfd_arch_mn10300, mn10300_gdbarch_init); |
c906108c | 504 | } |
81c0587e | 505 |