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