* infrun.c (adjust_pc_after_break): Do not assume software single-step
[deliverable/binutils-gdb.git] / gdb / m68k-tdep.c
CommitLineData
748894bf 1/* Target-dependent code for the Motorola 68000 series.
c6f0559b 2
6aba47ca
DJ
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007 Free 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
197e01b6
EZ
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
c906108c
SS
22
23#include "defs.h"
3f244638 24#include "dwarf2-frame.h"
c906108c 25#include "frame.h"
8de307e0
AS
26#include "frame-base.h"
27#include "frame-unwind.h"
e6bb342a 28#include "gdbtypes.h"
c906108c
SS
29#include "symtab.h"
30#include "gdbcore.h"
31#include "value.h"
32#include "gdb_string.h"
8de307e0 33#include "gdb_assert.h"
7a292a7a 34#include "inferior.h"
4e052eda 35#include "regcache.h"
5d3ed2e3 36#include "arch-utils.h"
55809acb 37#include "osabi.h"
a89aa300 38#include "dis-asm.h"
8ed86d01 39#include "target-descriptions.h"
32eeb91a
AS
40
41#include "m68k-tdep.h"
c906108c 42\f
c5aa993b 43
89c3b6d3
PDM
44#define P_LINKL_FP 0x480e
45#define P_LINKW_FP 0x4e56
46#define P_PEA_FP 0x4856
8de307e0
AS
47#define P_MOVEAL_SP_FP 0x2c4f
48#define P_ADDAW_SP 0xdefc
49#define P_ADDAL_SP 0xdffc
50#define P_SUBQW_SP 0x514f
51#define P_SUBQL_SP 0x518f
52#define P_LEA_SP_SP 0x4fef
53#define P_LEA_PC_A5 0x4bfb0170
54#define P_FMOVEMX_SP 0xf227
55#define P_MOVEL_SP 0x2f00
56#define P_MOVEML_SP 0x48e7
89c3b6d3 57
103a1597 58/* Offset from SP to first arg on stack at first instruction of a function */
103a1597
GS
59#define SP_ARG0 (1 * 4)
60
103a1597
GS
61#if !defined (BPT_VECTOR)
62#define BPT_VECTOR 0xf
63#endif
64
f5cf7aa1 65static const gdb_byte *
103a1597
GS
66m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
67{
f5cf7aa1 68 static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
103a1597
GS
69 *lenptr = sizeof (break_insn);
70 return break_insn;
71}
72
d85fe7f7
AS
73/* Return the GDB type object for the "standard" data type of data in
74 register N. This should be int for D0-D7, SR, FPCONTROL and
75 FPSTATUS, long double for FP0-FP7, and void pointer for all others
76 (A0-A7, PC, FPIADDR). Note, for registers which contain
77 addresses return pointer to void, not pointer to char, because we
78 don't want to attempt to print the string after printing the
79 address. */
5d3ed2e3
GS
80
81static struct type *
8de307e0 82m68k_register_type (struct gdbarch *gdbarch, int regnum)
5d3ed2e3 83{
8ed86d01 84 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
03dac896 85
8ed86d01
VP
86 if (tdep->fpregs_present)
87 {
3e8c568d
UW
88 if (regnum >= gdbarch_fp0_regnum (current_gdbarch)
89 && regnum <= gdbarch_fp0_regnum (current_gdbarch) + 7)
8ed86d01
VP
90 {
91 if (tdep->flavour == m68k_coldfire_flavour)
92 return builtin_type (gdbarch)->builtin_double;
93 else
94 return builtin_type_m68881_ext;
95 }
96
97 if (regnum == M68K_FPI_REGNUM)
98 return builtin_type_void_func_ptr;
99
100 if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM)
101 return builtin_type_int32;
102 }
103 else
104 {
105 if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM)
106 return builtin_type_int0;
107 }
03dac896 108
3e8c568d 109 if (regnum == gdbarch_pc_regnum (current_gdbarch))
8ed86d01 110 return builtin_type_void_func_ptr;
03dac896 111
32eeb91a 112 if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
03dac896
AS
113 return builtin_type_void_data_ptr;
114
115 return builtin_type_int32;
5d3ed2e3
GS
116}
117
8ed86d01 118static const char *m68k_register_names[] = {
5d3ed2e3
GS
119 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
120 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
121 "ps", "pc",
122 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
8ed86d01 123 "fpcontrol", "fpstatus", "fpiaddr"
5d3ed2e3
GS
124 };
125
8ed86d01
VP
126/* Function: m68k_register_name
127 Returns the name of the standard m68k register regnum. */
128
129static const char *
130m68k_register_name (int regnum)
131{
132 if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
5d3ed2e3 133 internal_error (__FILE__, __LINE__,
e2e0b3e5 134 _("m68k_register_name: illegal register number %d"), regnum);
5d3ed2e3 135 else
8ed86d01 136 return m68k_register_names[regnum];
5d3ed2e3 137}
e47577ab
MK
138\f
139/* Return nonzero if a value of type TYPE stored in register REGNUM
140 needs any special handling. */
141
142static int
143m68k_convert_register_p (int regnum, struct type *type)
144{
8ed86d01
VP
145 if (!gdbarch_tdep (current_gdbarch)->fpregs_present)
146 return 0;
e47577ab
MK
147 return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7);
148}
149
150/* Read a value of type TYPE from register REGNUM in frame FRAME, and
151 return its contents in TO. */
152
153static void
154m68k_register_to_value (struct frame_info *frame, int regnum,
f5cf7aa1 155 struct type *type, gdb_byte *to)
e47577ab 156{
f5cf7aa1 157 gdb_byte from[M68K_MAX_REGISTER_SIZE];
8ed86d01 158 struct type *fpreg_type = register_type (current_gdbarch, M68K_FP0_REGNUM);
e47577ab
MK
159
160 /* We only support floating-point values. */
161 if (TYPE_CODE (type) != TYPE_CODE_FLT)
162 {
8a3fe4f8
AC
163 warning (_("Cannot convert floating-point register value "
164 "to non-floating-point type."));
e47577ab
MK
165 return;
166 }
167
168 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
169 the extended floating-point format used by the FPU. */
170 get_frame_register (frame, regnum, from);
8ed86d01 171 convert_typed_floating (from, fpreg_type, to, type);
e47577ab
MK
172}
173
174/* Write the contents FROM of a value of type TYPE into register
175 REGNUM in frame FRAME. */
176
177static void
178m68k_value_to_register (struct frame_info *frame, int regnum,
f5cf7aa1 179 struct type *type, const gdb_byte *from)
e47577ab 180{
f5cf7aa1 181 gdb_byte to[M68K_MAX_REGISTER_SIZE];
8ed86d01 182 struct type *fpreg_type = register_type (current_gdbarch, M68K_FP0_REGNUM);
e47577ab
MK
183
184 /* We only support floating-point values. */
185 if (TYPE_CODE (type) != TYPE_CODE_FLT)
186 {
8a3fe4f8
AC
187 warning (_("Cannot convert non-floating-point type "
188 "to floating-point register value."));
e47577ab
MK
189 return;
190 }
191
192 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
193 to the extended floating-point format used by the FPU. */
8ed86d01 194 convert_typed_floating (from, type, to, fpreg_type);
e47577ab
MK
195 put_frame_register (frame, regnum, to);
196}
197
8de307e0 198\f
f595cb19
MK
199/* There is a fair number of calling conventions that are in somewhat
200 wide use. The 68000/08/10 don't support an FPU, not even as a
201 coprocessor. All function return values are stored in %d0/%d1.
202 Structures are returned in a static buffer, a pointer to which is
203 returned in %d0. This means that functions returning a structure
204 are not re-entrant. To avoid this problem some systems use a
205 convention where the caller passes a pointer to a buffer in %a1
206 where the return values is to be stored. This convention is the
207 default, and is implemented in the function m68k_return_value.
208
209 The 68020/030/040/060 do support an FPU, either as a coprocessor
210 (68881/2) or built-in (68040/68060). That's why System V release 4
211 (SVR4) instroduces a new calling convention specified by the SVR4
212 psABI. Integer values are returned in %d0/%d1, pointer return
213 values in %a0 and floating values in %fp0. When calling functions
214 returning a structure the caller should pass a pointer to a buffer
215 for the return value in %a0. This convention is implemented in the
216 function m68k_svr4_return_value, and by appropriately setting the
217 struct_value_regnum member of `struct gdbarch_tdep'.
218
219 GNU/Linux returns values in the same way as SVR4 does, but uses %a1
220 for passing the structure return value buffer.
221
222 GCC can also generate code where small structures are returned in
223 %d0/%d1 instead of in memory by using -freg-struct-return. This is
224 the default on NetBSD a.out, OpenBSD and GNU/Linux and several
225 embedded systems. This convention is implemented by setting the
226 struct_return member of `struct gdbarch_tdep' to reg_struct_return. */
227
228/* Read a function return value of TYPE from REGCACHE, and copy that
8de307e0 229 into VALBUF. */
942dc0e9
GS
230
231static void
8de307e0 232m68k_extract_return_value (struct type *type, struct regcache *regcache,
f5cf7aa1 233 gdb_byte *valbuf)
942dc0e9 234{
8de307e0 235 int len = TYPE_LENGTH (type);
f5cf7aa1 236 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
942dc0e9 237
8de307e0
AS
238 if (len <= 4)
239 {
240 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
241 memcpy (valbuf, buf + (4 - len), len);
242 }
243 else if (len <= 8)
244 {
245 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
246 memcpy (valbuf, buf + (8 - len), len - 4);
f5cf7aa1 247 regcache_raw_read (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
8de307e0
AS
248 }
249 else
250 internal_error (__FILE__, __LINE__,
e2e0b3e5 251 _("Cannot extract return value of %d bytes long."), len);
942dc0e9
GS
252}
253
942dc0e9 254static void
f595cb19 255m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
f5cf7aa1 256 gdb_byte *valbuf)
942dc0e9 257{
8de307e0 258 int len = TYPE_LENGTH (type);
f5cf7aa1 259 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
8ed86d01 260 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
942dc0e9 261
8ed86d01 262 if (tdep->float_return && TYPE_CODE (type) == TYPE_CODE_FLT)
8de307e0 263 {
8ed86d01
VP
264 struct type *fpreg_type = register_type
265 (current_gdbarch, M68K_FP0_REGNUM);
f595cb19 266 regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
8ed86d01 267 convert_typed_floating (buf, fpreg_type, valbuf, type);
8de307e0 268 }
f595cb19
MK
269 else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4)
270 regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
271 else
272 m68k_extract_return_value (type, regcache, valbuf);
273}
274
275/* Write a function return value of TYPE from VALBUF into REGCACHE. */
276
277static void
278m68k_store_return_value (struct type *type, struct regcache *regcache,
f5cf7aa1 279 const gdb_byte *valbuf)
f595cb19
MK
280{
281 int len = TYPE_LENGTH (type);
942dc0e9 282
8de307e0
AS
283 if (len <= 4)
284 regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf);
285 else if (len <= 8)
286 {
f595cb19 287 regcache_raw_write_part (regcache, M68K_D0_REGNUM, 8 - len,
8de307e0 288 len - 4, valbuf);
f5cf7aa1 289 regcache_raw_write (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
8de307e0
AS
290 }
291 else
292 internal_error (__FILE__, __LINE__,
e2e0b3e5 293 _("Cannot store return value of %d bytes long."), len);
8de307e0 294}
942dc0e9 295
f595cb19
MK
296static void
297m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
f5cf7aa1 298 const gdb_byte *valbuf)
942dc0e9 299{
f595cb19 300 int len = TYPE_LENGTH (type);
8ed86d01 301 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
8de307e0 302
8ed86d01 303 if (tdep->float_return && TYPE_CODE (type) == TYPE_CODE_FLT)
f595cb19 304 {
8ed86d01
VP
305 struct type *fpreg_type = register_type
306 (current_gdbarch, M68K_FP0_REGNUM);
f5cf7aa1 307 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
8ed86d01 308 convert_typed_floating (valbuf, type, buf, fpreg_type);
f595cb19
MK
309 regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
310 }
311 else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4)
312 {
313 regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
314 regcache_raw_write (regcache, M68K_D0_REGNUM, valbuf);
315 }
316 else
317 m68k_store_return_value (type, regcache, valbuf);
942dc0e9
GS
318}
319
f595cb19
MK
320/* Return non-zero if TYPE, which is assumed to be a structure or
321 union type, should be returned in registers for architecture
322 GDBARCH. */
323
c481dac7 324static int
f595cb19 325m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
c481dac7 326{
f595cb19
MK
327 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
328 enum type_code code = TYPE_CODE (type);
329 int len = TYPE_LENGTH (type);
c481dac7 330
f595cb19
MK
331 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
332
333 if (tdep->struct_return == pcc_struct_return)
334 return 0;
335
336 return (len == 1 || len == 2 || len == 4 || len == 8);
c481dac7
AS
337}
338
f595cb19
MK
339/* Determine, for architecture GDBARCH, how a return value of TYPE
340 should be returned. If it is supposed to be returned in registers,
341 and READBUF is non-zero, read the appropriate value from REGCACHE,
342 and copy it into READBUF. If WRITEBUF is non-zero, write the value
343 from WRITEBUF into REGCACHE. */
344
345static enum return_value_convention
346m68k_return_value (struct gdbarch *gdbarch, struct type *type,
f5cf7aa1
MK
347 struct regcache *regcache, gdb_byte *readbuf,
348 const gdb_byte *writebuf)
f595cb19
MK
349{
350 enum type_code code = TYPE_CODE (type);
351
1c845060
MK
352 /* GCC returns a `long double' in memory too. */
353 if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
354 && !m68k_reg_struct_return_p (gdbarch, type))
355 || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12))
356 {
357 /* The default on m68k is to return structures in static memory.
358 Consequently a function must return the address where we can
359 find the return value. */
f595cb19 360
1c845060
MK
361 if (readbuf)
362 {
363 ULONGEST addr;
364
365 regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
366 read_memory (addr, readbuf, TYPE_LENGTH (type));
367 }
368
369 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
370 }
f595cb19
MK
371
372 if (readbuf)
373 m68k_extract_return_value (type, regcache, readbuf);
374 if (writebuf)
375 m68k_store_return_value (type, regcache, writebuf);
376
377 return RETURN_VALUE_REGISTER_CONVENTION;
378}
379
380static enum return_value_convention
381m68k_svr4_return_value (struct gdbarch *gdbarch, struct type *type,
f5cf7aa1
MK
382 struct regcache *regcache, gdb_byte *readbuf,
383 const gdb_byte *writebuf)
f595cb19
MK
384{
385 enum type_code code = TYPE_CODE (type);
386
387 if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
388 && !m68k_reg_struct_return_p (gdbarch, type))
51da707a
MK
389 {
390 /* The System V ABI says that:
391
392 "A function returning a structure or union also sets %a0 to
393 the value it finds in %a0. Thus when the caller receives
394 control again, the address of the returned object resides in
395 register %a0."
396
397 So the ABI guarantees that we can always find the return
398 value just after the function has returned. */
399
400 if (readbuf)
401 {
402 ULONGEST addr;
403
404 regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr);
405 read_memory (addr, readbuf, TYPE_LENGTH (type));
406 }
407
408 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
409 }
f595cb19
MK
410
411 /* This special case is for structures consisting of a single
412 `float' or `double' member. These structures are returned in
413 %fp0. For these structures, we call ourselves recursively,
414 changing TYPE into the type of the first member of the structure.
415 Since that should work for all structures that have only one
416 member, we don't bother to check the member's type here. */
417 if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
418 {
419 type = check_typedef (TYPE_FIELD_TYPE (type, 0));
420 return m68k_svr4_return_value (gdbarch, type, regcache,
421 readbuf, writebuf);
422 }
423
424 if (readbuf)
425 m68k_svr4_extract_return_value (type, regcache, readbuf);
426 if (writebuf)
427 m68k_svr4_store_return_value (type, regcache, writebuf);
428
429 return RETURN_VALUE_REGISTER_CONVENTION;
430}
431\f
392a587b 432
9bb47d95
NS
433/* Always align the frame to a 4-byte boundary. This is required on
434 coldfire and harmless on the rest. */
435
436static CORE_ADDR
437m68k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
438{
439 /* Align the stack to four bytes. */
440 return sp & ~3;
441}
442
8de307e0 443static CORE_ADDR
7d9b040b 444m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
8de307e0
AS
445 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
446 struct value **args, CORE_ADDR sp, int struct_return,
447 CORE_ADDR struct_addr)
7f8e7424 448{
f595cb19 449 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
f5cf7aa1 450 gdb_byte buf[4];
8de307e0
AS
451 int i;
452
453 /* Push arguments in reverse order. */
454 for (i = nargs - 1; i >= 0; i--)
455 {
4754a64e 456 struct type *value_type = value_enclosing_type (args[i]);
c481dac7 457 int len = TYPE_LENGTH (value_type);
8de307e0 458 int container_len = (len + 3) & ~3;
c481dac7
AS
459 int offset;
460
461 /* Non-scalars bigger than 4 bytes are left aligned, others are
462 right aligned. */
463 if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT
464 || TYPE_CODE (value_type) == TYPE_CODE_UNION
465 || TYPE_CODE (value_type) == TYPE_CODE_ARRAY)
466 && len > 4)
467 offset = 0;
468 else
469 offset = container_len - len;
8de307e0 470 sp -= container_len;
46615f07 471 write_memory (sp + offset, value_contents_all (args[i]), len);
8de307e0
AS
472 }
473
c481dac7 474 /* Store struct value address. */
8de307e0
AS
475 if (struct_return)
476 {
8de307e0 477 store_unsigned_integer (buf, 4, struct_addr);
f595cb19 478 regcache_cooked_write (regcache, tdep->struct_value_regnum, buf);
8de307e0
AS
479 }
480
481 /* Store return address. */
482 sp -= 4;
483 store_unsigned_integer (buf, 4, bp_addr);
484 write_memory (sp, buf, 4);
485
486 /* Finally, update the stack pointer... */
487 store_unsigned_integer (buf, 4, sp);
488 regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);
489
490 /* ...and fake a frame pointer. */
491 regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);
492
493 /* DWARF2/GCC uses the stack address *before* the function call as a
494 frame's CFA. */
495 return sp + 8;
7f8e7424 496}
6dd0fba6
NS
497
498/* Convert a dwarf or dwarf2 regnumber to a GDB regnum. */
499
500static int
501m68k_dwarf_reg_to_regnum (int num)
502{
503 if (num < 8)
504 /* d0..7 */
505 return (num - 0) + M68K_D0_REGNUM;
506 else if (num < 16)
507 /* a0..7 */
508 return (num - 8) + M68K_A0_REGNUM;
8ed86d01 509 else if (num < 24 && gdbarch_tdep (current_gdbarch)->fpregs_present)
6dd0fba6
NS
510 /* fp0..7 */
511 return (num - 16) + M68K_FP0_REGNUM;
512 else if (num == 25)
513 /* pc */
514 return M68K_PC_REGNUM;
515 else
f57d151a
UW
516 return gdbarch_num_regs (current_gdbarch)
517 + gdbarch_num_pseudo_regs (current_gdbarch);
6dd0fba6
NS
518}
519
8de307e0
AS
520\f
521struct m68k_frame_cache
522{
523 /* Base address. */
524 CORE_ADDR base;
525 CORE_ADDR sp_offset;
526 CORE_ADDR pc;
7f8e7424 527
8de307e0
AS
528 /* Saved registers. */
529 CORE_ADDR saved_regs[M68K_NUM_REGS];
530 CORE_ADDR saved_sp;
7f8e7424 531
8de307e0
AS
532 /* Stack space reserved for local variables. */
533 long locals;
534};
c906108c 535
8de307e0
AS
536/* Allocate and initialize a frame cache. */
537
538static struct m68k_frame_cache *
539m68k_alloc_frame_cache (void)
c906108c 540{
8de307e0
AS
541 struct m68k_frame_cache *cache;
542 int i;
c906108c 543
8de307e0 544 cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
c906108c 545
8de307e0
AS
546 /* Base address. */
547 cache->base = 0;
548 cache->sp_offset = -4;
549 cache->pc = 0;
c906108c 550
8de307e0
AS
551 /* Saved registers. We initialize these to -1 since zero is a valid
552 offset (that's where %fp is supposed to be stored). */
553 for (i = 0; i < M68K_NUM_REGS; i++)
554 cache->saved_regs[i] = -1;
555
556 /* Frameless until proven otherwise. */
557 cache->locals = -1;
558
559 return cache;
c906108c
SS
560}
561
8de307e0
AS
562/* Check whether PC points at a code that sets up a new stack frame.
563 If so, it updates CACHE and returns the address of the first
564 instruction after the sequence that sets removes the "hidden"
565 argument from the stack or CURRENT_PC, whichever is smaller.
566 Otherwise, return PC. */
c906108c 567
8de307e0
AS
568static CORE_ADDR
569m68k_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc,
570 struct m68k_frame_cache *cache)
c906108c 571{
8de307e0
AS
572 int op;
573
574 if (pc >= current_pc)
575 return current_pc;
c906108c 576
8de307e0
AS
577 op = read_memory_unsigned_integer (pc, 2);
578
579 if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
c906108c 580 {
8de307e0
AS
581 cache->saved_regs[M68K_FP_REGNUM] = 0;
582 cache->sp_offset += 4;
583 if (op == P_LINKW_FP)
584 {
585 /* link.w %fp, #-N */
586 /* link.w %fp, #0; adda.l #-N, %sp */
587 cache->locals = -read_memory_integer (pc + 2, 2);
588
589 if (pc + 4 < current_pc && cache->locals == 0)
590 {
591 op = read_memory_unsigned_integer (pc + 4, 2);
592 if (op == P_ADDAL_SP)
593 {
594 cache->locals = read_memory_integer (pc + 6, 4);
595 return pc + 10;
596 }
597 }
598
599 return pc + 4;
600 }
601 else if (op == P_LINKL_FP)
c906108c 602 {
8de307e0
AS
603 /* link.l %fp, #-N */
604 cache->locals = -read_memory_integer (pc + 2, 4);
605 return pc + 6;
606 }
607 else
608 {
609 /* pea (%fp); movea.l %sp, %fp */
610 cache->locals = 0;
611
612 if (pc + 2 < current_pc)
613 {
614 op = read_memory_unsigned_integer (pc + 2, 2);
615
616 if (op == P_MOVEAL_SP_FP)
617 {
618 /* move.l %sp, %fp */
619 return pc + 4;
620 }
621 }
622
623 return pc + 2;
c906108c
SS
624 }
625 }
8de307e0 626 else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
c906108c 627 {
8de307e0
AS
628 /* subq.[wl] #N,%sp */
629 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
630 cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
631 if (pc + 2 < current_pc)
c906108c 632 {
8de307e0
AS
633 op = read_memory_unsigned_integer (pc + 2, 2);
634 if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
635 {
636 cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
637 return pc + 4;
638 }
c906108c 639 }
8de307e0
AS
640 return pc + 2;
641 }
642 else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
643 {
644 /* adda.w #-N,%sp */
645 /* lea (-N,%sp),%sp */
646 cache->locals = -read_memory_integer (pc + 2, 2);
647 return pc + 4;
c906108c 648 }
8de307e0 649 else if (op == P_ADDAL_SP)
c906108c 650 {
8de307e0
AS
651 /* adda.l #-N,%sp */
652 cache->locals = -read_memory_integer (pc + 2, 4);
653 return pc + 6;
c906108c 654 }
8de307e0
AS
655
656 return pc;
c906108c 657}
c5aa993b 658
8de307e0
AS
659/* Check whether PC points at code that saves registers on the stack.
660 If so, it updates CACHE and returns the address of the first
661 instruction after the register saves or CURRENT_PC, whichever is
662 smaller. Otherwise, return PC. */
c906108c 663
8de307e0
AS
664static CORE_ADDR
665m68k_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
666 struct m68k_frame_cache *cache)
667{
668 if (cache->locals >= 0)
669 {
670 CORE_ADDR offset;
671 int op;
672 int i, mask, regno;
c906108c 673
8de307e0
AS
674 offset = -4 - cache->locals;
675 while (pc < current_pc)
676 {
677 op = read_memory_unsigned_integer (pc, 2);
8ed86d01
VP
678 if (op == P_FMOVEMX_SP
679 && gdbarch_tdep (current_gdbarch)->fpregs_present)
8de307e0
AS
680 {
681 /* fmovem.x REGS,-(%sp) */
682 op = read_memory_unsigned_integer (pc + 2, 2);
683 if ((op & 0xff00) == 0xe000)
684 {
685 mask = op & 0xff;
686 for (i = 0; i < 16; i++, mask >>= 1)
687 {
688 if (mask & 1)
689 {
690 cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
691 offset -= 12;
692 }
693 }
694 pc += 4;
695 }
696 else
697 break;
698 }
0ba5a932 699 else if ((op & 0177760) == P_MOVEL_SP)
8de307e0
AS
700 {
701 /* move.l %R,-(%sp) */
0ba5a932 702 regno = op & 017;
8de307e0
AS
703 cache->saved_regs[regno] = offset;
704 offset -= 4;
705 pc += 2;
706 }
707 else if (op == P_MOVEML_SP)
708 {
709 /* movem.l REGS,-(%sp) */
710 mask = read_memory_unsigned_integer (pc + 2, 2);
711 for (i = 0; i < 16; i++, mask >>= 1)
712 {
713 if (mask & 1)
714 {
715 cache->saved_regs[15 - i] = offset;
716 offset -= 4;
717 }
718 }
719 pc += 4;
720 }
721 else
722 break;
723 }
724 }
725
726 return pc;
727}
c906108c 728
c906108c 729
8de307e0
AS
730/* Do a full analysis of the prologue at PC and update CACHE
731 accordingly. Bail out early if CURRENT_PC is reached. Return the
732 address where the analysis stopped.
c906108c 733
8de307e0 734 We handle all cases that can be generated by gcc.
c906108c 735
8de307e0 736 For allocating a stack frame:
c906108c 737
8de307e0
AS
738 link.w %a6,#-N
739 link.l %a6,#-N
740 pea (%fp); move.l %sp,%fp
741 link.w %a6,#0; add.l #-N,%sp
742 subq.l #N,%sp
743 subq.w #N,%sp
744 subq.w #8,%sp; subq.w #N-8,%sp
745 add.w #-N,%sp
746 lea (-N,%sp),%sp
747 add.l #-N,%sp
c906108c 748
8de307e0 749 For saving registers:
c906108c 750
8de307e0
AS
751 fmovem.x REGS,-(%sp)
752 move.l R1,-(%sp)
753 move.l R1,-(%sp); move.l R2,-(%sp)
754 movem.l REGS,-(%sp)
c906108c 755
8de307e0 756 For setting up the PIC register:
c906108c 757
8de307e0 758 lea (%pc,N),%a5
c906108c 759
8de307e0 760 */
c906108c 761
eb2e12d7 762static CORE_ADDR
8de307e0
AS
763m68k_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
764 struct m68k_frame_cache *cache)
c906108c 765{
8de307e0 766 unsigned int op;
c906108c 767
8de307e0
AS
768 pc = m68k_analyze_frame_setup (pc, current_pc, cache);
769 pc = m68k_analyze_register_saves (pc, current_pc, cache);
770 if (pc >= current_pc)
771 return current_pc;
c906108c 772
8de307e0
AS
773 /* Check for GOT setup. */
774 op = read_memory_unsigned_integer (pc, 4);
775 if (op == P_LEA_PC_A5)
c906108c 776 {
8de307e0
AS
777 /* lea (%pc,N),%a5 */
778 return pc + 6;
c906108c 779 }
8de307e0
AS
780
781 return pc;
c906108c
SS
782}
783
8de307e0 784/* Return PC of first real instruction. */
7f8e7424 785
8de307e0
AS
786static CORE_ADDR
787m68k_skip_prologue (CORE_ADDR start_pc)
c906108c 788{
8de307e0
AS
789 struct m68k_frame_cache cache;
790 CORE_ADDR pc;
791 int op;
c906108c 792
8de307e0
AS
793 cache.locals = -1;
794 pc = m68k_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache);
795 if (cache.locals < 0)
796 return start_pc;
797 return pc;
798}
c906108c 799
8de307e0
AS
800static CORE_ADDR
801m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
802{
f5cf7aa1 803 gdb_byte buf[8];
7f8e7424 804
3e8c568d 805 frame_unwind_register (next_frame, gdbarch_pc_regnum (current_gdbarch), buf);
8de307e0
AS
806 return extract_typed_address (buf, builtin_type_void_func_ptr);
807}
808\f
809/* Normal frames. */
7f8e7424 810
8de307e0
AS
811static struct m68k_frame_cache *
812m68k_frame_cache (struct frame_info *next_frame, void **this_cache)
813{
814 struct m68k_frame_cache *cache;
f5cf7aa1 815 gdb_byte buf[4];
8de307e0
AS
816 int i;
817
818 if (*this_cache)
819 return *this_cache;
820
821 cache = m68k_alloc_frame_cache ();
822 *this_cache = cache;
823
824 /* In principle, for normal frames, %fp holds the frame pointer,
825 which holds the base address for the current stack frame.
826 However, for functions that don't need it, the frame pointer is
827 optional. For these "frameless" functions the frame pointer is
828 actually the frame pointer of the calling frame. Signal
829 trampolines are just a special case of a "frameless" function.
830 They (usually) share their frame pointer with the frame that was
831 in progress when the signal occurred. */
832
833 frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
834 cache->base = extract_unsigned_integer (buf, 4);
835 if (cache->base == 0)
836 return cache;
837
838 /* For normal frames, %pc is stored at 4(%fp). */
839 cache->saved_regs[M68K_PC_REGNUM] = 4;
840
93d42b30 841 cache->pc = frame_func_unwind (next_frame, NORMAL_FRAME);
8de307e0
AS
842 if (cache->pc != 0)
843 m68k_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache);
844
845 if (cache->locals < 0)
846 {
847 /* We didn't find a valid frame, which means that CACHE->base
848 currently holds the frame pointer for our calling frame. If
849 we're at the start of a function, or somewhere half-way its
850 prologue, the function's frame probably hasn't been fully
851 setup yet. Try to reconstruct the base address for the stack
852 frame by looking at the stack pointer. For truly "frameless"
853 functions this might work too. */
854
855 frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
856 cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset;
857 }
7f8e7424 858
8de307e0
AS
859 /* Now that we have the base address for the stack frame we can
860 calculate the value of %sp in the calling frame. */
861 cache->saved_sp = cache->base + 8;
7f8e7424 862
8de307e0
AS
863 /* Adjust all the saved registers such that they contain addresses
864 instead of offsets. */
865 for (i = 0; i < M68K_NUM_REGS; i++)
866 if (cache->saved_regs[i] != -1)
867 cache->saved_regs[i] += cache->base;
c906108c 868
8de307e0
AS
869 return cache;
870}
c906108c 871
8de307e0
AS
872static void
873m68k_frame_this_id (struct frame_info *next_frame, void **this_cache,
874 struct frame_id *this_id)
875{
876 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
c906108c 877
8de307e0
AS
878 /* This marks the outermost frame. */
879 if (cache->base == 0)
880 return;
c5aa993b 881
8de307e0
AS
882 /* See the end of m68k_push_dummy_call. */
883 *this_id = frame_id_build (cache->base + 8, cache->pc);
884}
c5aa993b 885
8de307e0
AS
886static void
887m68k_frame_prev_register (struct frame_info *next_frame, void **this_cache,
888 int regnum, int *optimizedp,
889 enum lval_type *lvalp, CORE_ADDR *addrp,
60b04da5 890 int *realnump, gdb_byte *valuep)
8de307e0
AS
891{
892 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
893
894 gdb_assert (regnum >= 0);
895
896 if (regnum == M68K_SP_REGNUM && cache->saved_sp)
c5aa993b 897 {
8de307e0
AS
898 *optimizedp = 0;
899 *lvalp = not_lval;
900 *addrp = 0;
901 *realnump = -1;
902 if (valuep)
c906108c 903 {
8de307e0
AS
904 /* Store the value. */
905 store_unsigned_integer (valuep, 4, cache->saved_sp);
89c3b6d3 906 }
8de307e0
AS
907 return;
908 }
909
910 if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
911 {
912 *optimizedp = 0;
913 *lvalp = lval_memory;
914 *addrp = cache->saved_regs[regnum];
915 *realnump = -1;
916 if (valuep)
89c3b6d3 917 {
8de307e0
AS
918 /* Read the value in from memory. */
919 read_memory (*addrp, valuep,
920 register_size (current_gdbarch, regnum));
89c3b6d3 921 }
8de307e0 922 return;
c906108c 923 }
8de307e0 924
00b25ff3
AC
925 *optimizedp = 0;
926 *lvalp = lval_register;
927 *addrp = 0;
928 *realnump = regnum;
929 if (valuep)
930 frame_unwind_register (next_frame, (*realnump), valuep);
8de307e0
AS
931}
932
933static const struct frame_unwind m68k_frame_unwind =
934{
935 NORMAL_FRAME,
936 m68k_frame_this_id,
937 m68k_frame_prev_register
938};
939
940static const struct frame_unwind *
336d1bba 941m68k_frame_sniffer (struct frame_info *next_frame)
8de307e0
AS
942{
943 return &m68k_frame_unwind;
944}
945\f
8de307e0
AS
946static CORE_ADDR
947m68k_frame_base_address (struct frame_info *next_frame, void **this_cache)
948{
949 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
950
951 return cache->base;
952}
953
954static const struct frame_base m68k_frame_base =
955{
956 &m68k_frame_unwind,
957 m68k_frame_base_address,
958 m68k_frame_base_address,
959 m68k_frame_base_address
960};
961
962static struct frame_id
963m68k_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
964{
f5cf7aa1 965 gdb_byte buf[4];
8de307e0 966 CORE_ADDR fp;
c906108c 967
8de307e0
AS
968 frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
969 fp = extract_unsigned_integer (buf, 4);
c906108c 970
8de307e0
AS
971 /* See the end of m68k_push_dummy_call. */
972 return frame_id_build (fp + 8, frame_pc_unwind (next_frame));
973}
974\f
c906108c 975
c906108c
SS
976/* Figure out where the longjmp will land. Slurp the args out of the stack.
977 We expect the first arg to be a pointer to the jmp_buf structure from which
978 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
979 This routine returns true on success. */
980
c34d127c 981static int
60ade65d 982m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
c906108c 983{
f5cf7aa1 984 gdb_byte *buf;
c906108c 985 CORE_ADDR sp, jb_addr;
60ade65d 986 struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (frame));
eb2e12d7
AS
987
988 if (tdep->jb_pc < 0)
989 {
990 internal_error (__FILE__, __LINE__,
e2e0b3e5 991 _("m68k_get_longjmp_target: not implemented"));
eb2e12d7
AS
992 return 0;
993 }
c906108c 994
819844ad 995 buf = alloca (gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT);
3e8c568d 996 sp = get_frame_register_unsigned (frame, gdbarch_sp_regnum (current_gdbarch));
c906108c 997
b5d78d39 998 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
819844ad
UW
999 buf,
1000 gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT))
c906108c
SS
1001 return 0;
1002
819844ad
UW
1003 jb_addr = extract_unsigned_integer (buf, gdbarch_ptr_bit (current_gdbarch)
1004 / TARGET_CHAR_BIT);
c906108c 1005
eb2e12d7 1006 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
819844ad 1007 gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT))
c906108c
SS
1008 return 0;
1009
819844ad
UW
1010 *pc = extract_unsigned_integer (buf, gdbarch_ptr_bit (current_gdbarch)
1011 / TARGET_CHAR_BIT);
c906108c
SS
1012 return 1;
1013}
f595cb19
MK
1014\f
1015
1016/* System V Release 4 (SVR4). */
1017
1018void
1019m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1020{
1021 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1022
1023 /* SVR4 uses a different calling convention. */
1024 set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
1025
1026 /* SVR4 uses %a0 instead of %a1. */
1027 tdep->struct_value_regnum = M68K_A0_REGNUM;
1028}
1029\f
c906108c 1030
152d9db6
GS
1031/* Function: m68k_gdbarch_init
1032 Initializer function for the m68k gdbarch vector.
1033 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1034
1035static struct gdbarch *
1036m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1037{
1038 struct gdbarch_tdep *tdep = NULL;
1039 struct gdbarch *gdbarch;
8ed86d01
VP
1040 struct gdbarch_list *best_arch;
1041 struct tdesc_arch_data *tdesc_data = NULL;
1042 int i;
1043 enum m68k_flavour flavour = m68k_no_flavour;
1044 int has_fp = 1;
1045 const struct floatformat **long_double_format = floatformats_m68881_ext;
1046
1047 /* Check any target description for validity. */
1048 if (tdesc_has_registers (info.target_desc))
1049 {
1050 const struct tdesc_feature *feature;
1051 int valid_p;
152d9db6 1052
8ed86d01
VP
1053 feature = tdesc_find_feature (info.target_desc,
1054 "org.gnu.gdb.m68k.core");
1055 if (feature != NULL)
1056 /* Do nothing. */
1057 ;
1058
1059 if (feature == NULL)
1060 {
1061 feature = tdesc_find_feature (info.target_desc,
1062 "org.gnu.gdb.coldfire.core");
1063 if (feature != NULL)
1064 flavour = m68k_coldfire_flavour;
1065 }
1066
1067 if (feature == NULL)
1068 {
1069 feature = tdesc_find_feature (info.target_desc,
1070 "org.gnu.gdb.fido.core");
1071 if (feature != NULL)
1072 flavour = m68k_fido_flavour;
1073 }
1074
1075 if (feature == NULL)
1076 return NULL;
1077
1078 tdesc_data = tdesc_data_alloc ();
1079
1080 valid_p = 1;
1081 for (i = 0; i <= M68K_PC_REGNUM; i++)
1082 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
1083 m68k_register_names[i]);
1084
1085 if (!valid_p)
1086 {
1087 tdesc_data_cleanup (tdesc_data);
1088 return NULL;
1089 }
1090
1091 feature = tdesc_find_feature (info.target_desc,
1092 "org.gnu.gdb.coldfire.fp");
1093 if (feature != NULL)
1094 {
1095 valid_p = 1;
1096 for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++)
1097 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
1098 m68k_register_names[i]);
1099 if (!valid_p)
1100 {
1101 tdesc_data_cleanup (tdesc_data);
1102 return NULL;
1103 }
1104 }
1105 else
1106 has_fp = 0;
1107 }
1108
1109 /* The mechanism for returning floating values from function
1110 and the type of long double depend on whether we're
1111 on ColdFire or standard m68k. */
1112
1113 if (info.bfd_arch_info)
1114 {
1115 const bfd_arch_info_type *coldfire_arch =
1116 bfd_lookup_arch (bfd_arch_m68k, bfd_mach_mcf_isa_a_nodiv);
1117
1118 if (coldfire_arch
1119 && (*info.bfd_arch_info->compatible)
1120 (info.bfd_arch_info, coldfire_arch))
1121 flavour = m68k_coldfire_flavour;
1122 }
1123
1124 /* If there is already a candidate, use it. */
1125 for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
1126 best_arch != NULL;
1127 best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
1128 {
1129 if (flavour != gdbarch_tdep (best_arch->gdbarch)->flavour)
1130 continue;
1131
1132 if (has_fp != gdbarch_tdep (best_arch->gdbarch)->fpregs_present)
1133 continue;
1134
1135 break;
1136 }
152d9db6 1137
eb2e12d7
AS
1138 tdep = xmalloc (sizeof (struct gdbarch_tdep));
1139 gdbarch = gdbarch_alloc (&info, tdep);
8ed86d01
VP
1140 tdep->fpregs_present = has_fp;
1141 tdep->flavour = flavour;
152d9db6 1142
8ed86d01
VP
1143 if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
1144 long_double_format = floatformats_ieee_double;
1145 set_gdbarch_long_double_format (gdbarch, long_double_format);
1146 set_gdbarch_long_double_bit (gdbarch, long_double_format[0]->totalsize);
5d3ed2e3 1147
5d3ed2e3 1148 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
103a1597 1149 set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
5d3ed2e3
GS
1150
1151 /* Stack grows down. */
1152 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
9bb47d95 1153 set_gdbarch_frame_align (gdbarch, m68k_frame_align);
6300c360
GS
1154
1155 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
8ed86d01
VP
1156 if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
1157 set_gdbarch_decr_pc_after_break (gdbarch, 2);
942dc0e9 1158
6300c360 1159 set_gdbarch_frame_args_skip (gdbarch, 8);
6dd0fba6
NS
1160 set_gdbarch_dwarf_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
1161 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
942dc0e9 1162
8de307e0 1163 set_gdbarch_register_type (gdbarch, m68k_register_type);
5d3ed2e3 1164 set_gdbarch_register_name (gdbarch, m68k_register_name);
6dd0fba6 1165 set_gdbarch_num_regs (gdbarch, M68K_NUM_REGS);
32eeb91a 1166 set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
32eeb91a
AS
1167 set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
1168 set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
1169 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
e47577ab
MK
1170 set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
1171 set_gdbarch_register_to_value (gdbarch, m68k_register_to_value);
1172 set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);
a2c6a6d5 1173
8ed86d01
VP
1174 if (has_fp)
1175 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
1176
1177 /* Try to figure out if the arch uses floating registers to return
1178 floating point values from functions. */
1179 if (has_fp)
1180 {
1181 /* On ColdFire, floating point values are returned in D0. */
1182 if (flavour == m68k_coldfire_flavour)
1183 tdep->float_return = 0;
1184 else
1185 tdep->float_return = 1;
1186 }
1187 else
1188 {
1189 /* No floating registers, so can't use them for returning values. */
1190 tdep->float_return = 0;
1191 }
1192
1193 /* Function call & return */
8de307e0 1194 set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
f595cb19 1195 set_gdbarch_return_value (gdbarch, m68k_return_value);
6c0e89ed 1196
8ed86d01 1197
650fcc91
AS
1198 /* Disassembler. */
1199 set_gdbarch_print_insn (gdbarch, print_insn_m68k);
1200
eb2e12d7
AS
1201#if defined JB_PC && defined JB_ELEMENT_SIZE
1202 tdep->jb_pc = JB_PC;
1203 tdep->jb_elt_size = JB_ELEMENT_SIZE;
1204#else
1205 tdep->jb_pc = -1;
1206#endif
f595cb19 1207 tdep->struct_value_regnum = M68K_A1_REGNUM;
66894781 1208 tdep->struct_return = reg_struct_return;
8de307e0
AS
1209
1210 /* Frame unwinder. */
1211 set_gdbarch_unwind_dummy_id (gdbarch, m68k_unwind_dummy_id);
1212 set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
3f244638
AS
1213
1214 /* Hook in the DWARF CFI frame unwinder. */
1215 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
1216
8de307e0 1217 frame_base_set_default (gdbarch, &m68k_frame_base);
eb2e12d7 1218
55809acb
AS
1219 /* Hook in ABI-specific overrides, if they have been registered. */
1220 gdbarch_init_osabi (info, gdbarch);
1221
eb2e12d7
AS
1222 /* Now we have tuned the configuration, set a few final things,
1223 based on what the OS ABI has told us. */
1224
1225 if (tdep->jb_pc >= 0)
1226 set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
1227
336d1bba 1228 frame_unwind_append_sniffer (gdbarch, m68k_frame_sniffer);
8de307e0 1229
8ed86d01
VP
1230 if (tdesc_data)
1231 tdesc_use_registers (gdbarch, tdesc_data);
1232
152d9db6
GS
1233 return gdbarch;
1234}
1235
1236
1237static void
1238m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1239{
eb2e12d7 1240 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
152d9db6 1241
eb2e12d7
AS
1242 if (tdep == NULL)
1243 return;
152d9db6 1244}
2acceee2 1245
a78f21af
AC
1246extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */
1247
c906108c 1248void
fba45db2 1249_initialize_m68k_tdep (void)
c906108c 1250{
152d9db6 1251 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
c906108c 1252}
This page took 0.633586 seconds and 4 git commands to generate.