* tui-out.c (tui_out_data): Fix typedef.
[deliverable/binutils-gdb.git] / gdb / m68k-tdep.c
CommitLineData
c906108c 1/* Target dependent code for the Motorola 68000 series.
51603483
DJ
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
3 2002, 2003
a1de33a8 4 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
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "frame.h"
25#include "symtab.h"
26#include "gdbcore.h"
27#include "value.h"
28#include "gdb_string.h"
7a292a7a 29#include "inferior.h"
4e052eda 30#include "regcache.h"
5d3ed2e3 31#include "arch-utils.h"
32eeb91a
AS
32
33#include "m68k-tdep.h"
c906108c 34\f
c5aa993b 35
89c3b6d3
PDM
36#define P_LINKL_FP 0x480e
37#define P_LINKW_FP 0x4e56
38#define P_PEA_FP 0x4856
39#define P_MOVL_SP_FP 0x2c4f
40#define P_MOVL 0x207c
41#define P_JSR 0x4eb9
42#define P_BSR 0x61ff
43#define P_LEAL 0x43fb
44#define P_MOVML 0x48ef
45#define P_FMOVM 0xf237
46#define P_TRAP 0x4e40
47
103a1597 48
103a1597
GS
49#define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
50#define REGISTER_BYTES_NOFP (16*4 + 8)
51
52#define NUM_FREGS (NUM_REGS-24)
53
54/* Offset from SP to first arg on stack at first instruction of a function */
55
56#define SP_ARG0 (1 * 4)
57
58/* This was determined by experimentation on hp300 BSD 4.3. Perhaps
59 it corresponds to some offset in /usr/include/sys/user.h or
60 something like that. Using some system include file would
61 have the advantage of probably being more robust in the face
62 of OS upgrades, but the disadvantage of being wrong for
63 cross-debugging. */
64
65#define SIG_PC_FP_OFFSET 530
66
67#define TARGET_M68K
68
69
70#if !defined (BPT_VECTOR)
71#define BPT_VECTOR 0xf
72#endif
73
74#if !defined (REMOTE_BPT_VECTOR)
75#define REMOTE_BPT_VECTOR 1
76#endif
77
78
7f8e7424
GS
79void m68k_frame_init_saved_regs (struct frame_info *frame_info);
80
103a1597
GS
81
82/* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc
83 so m68k_remote_breakpoint_from_pc is currently not used. */
84
85const static unsigned char *
86m68k_remote_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
87{
88 static unsigned char break_insn[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR)};
89 *lenptr = sizeof (break_insn);
90 return break_insn;
91}
92
93const static unsigned char *
94m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
95{
96 static unsigned char break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
97 *lenptr = sizeof (break_insn);
98 return break_insn;
99}
100
101
942dc0e9 102static int
5ae5f592 103m68k_register_bytes_ok (long numbytes)
942dc0e9
GS
104{
105 return ((numbytes == REGISTER_BYTES_FP)
106 || (numbytes == REGISTER_BYTES_NOFP));
107}
108
5d3ed2e3
GS
109/* Number of bytes of storage in the actual machine representation
110 for register regnum. On the 68000, all regs are 4 bytes
111 except the floating point regs which are 12 bytes. */
112/* Note that the unsigned cast here forces the result of the
113 subtraction to very high positive values if regnum < FP0_REGNUM */
114
115static int
116m68k_register_raw_size (int regnum)
117{
118 return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
119}
120
121/* Number of bytes of storage in the program's representation
122 for register regnum. On the 68000, all regs are 4 bytes
123 except the floating point regs which are 12-byte long doubles. */
124
125static int
126m68k_register_virtual_size (int regnum)
127{
128 return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
129}
130
d85fe7f7
AS
131/* Return the GDB type object for the "standard" data type of data in
132 register N. This should be int for D0-D7, SR, FPCONTROL and
133 FPSTATUS, long double for FP0-FP7, and void pointer for all others
134 (A0-A7, PC, FPIADDR). Note, for registers which contain
135 addresses return pointer to void, not pointer to char, because we
136 don't want to attempt to print the string after printing the
137 address. */
5d3ed2e3
GS
138
139static struct type *
140m68k_register_virtual_type (int regnum)
141{
03dac896
AS
142 if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7)
143 return builtin_type_m68881_ext;
144
32eeb91a 145 if (regnum == M68K_FPI_REGNUM || regnum == PC_REGNUM)
03dac896
AS
146 return builtin_type_void_func_ptr;
147
32eeb91a
AS
148 if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM
149 || regnum == PS_REGNUM)
03dac896
AS
150 return builtin_type_int32;
151
32eeb91a 152 if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
03dac896
AS
153 return builtin_type_void_data_ptr;
154
155 return builtin_type_int32;
5d3ed2e3
GS
156}
157
158/* Function: m68k_register_name
159 Returns the name of the standard m68k register regnum. */
160
161static const char *
162m68k_register_name (int regnum)
163{
164 static char *register_names[] = {
165 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
166 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
167 "ps", "pc",
168 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
169 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
170 };
171
172 if (regnum < 0 ||
173 regnum >= sizeof (register_names) / sizeof (register_names[0]))
174 internal_error (__FILE__, __LINE__,
175 "m68k_register_name: illegal register number %d", regnum);
176 else
177 return register_names[regnum];
178}
179
180/* Stack must be kept short aligned when doing function calls. */
181
182static CORE_ADDR
183m68k_stack_align (CORE_ADDR addr)
184{
185 return ((addr + 1) & ~1);
186}
187
188/* Index within `registers' of the first byte of the space for
189 register regnum. */
190
191static int
192m68k_register_byte (int regnum)
193{
32eeb91a
AS
194 if (regnum >= M68K_FPC_REGNUM)
195 return (((regnum - M68K_FPC_REGNUM) * 4) + 168);
5d3ed2e3
GS
196 else if (regnum >= FP0_REGNUM)
197 return (((regnum - FP0_REGNUM) * 12) + 72);
198 else
199 return (regnum * 4);
200}
201
942dc0e9
GS
202/* Store the address of the place in which to copy the structure the
203 subroutine will return. This is called from call_function. */
204
205static void
206m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
207{
32eeb91a 208 write_register (M68K_A1_REGNUM, addr);
942dc0e9
GS
209}
210
211/* Extract from an array regbuf containing the (raw) register state
212 a function return value of type type, and copy that, in virtual format,
213 into valbuf. This is assuming that floating point values are returned
214 as doubles in d0/d1. */
215
216static void
217m68k_deprecated_extract_return_value (struct type *type, char *regbuf,
218 char *valbuf)
219{
220 int offset = 0;
221 int typeLength = TYPE_LENGTH (type);
222
223 if (typeLength < 4)
224 offset = 4 - typeLength;
225
226 memcpy (valbuf, regbuf + offset, typeLength);
227}
228
229static CORE_ADDR
230m68k_deprecated_extract_struct_value_address (char *regbuf)
231{
232 return (*(CORE_ADDR *) (regbuf));
233}
234
235/* Write into appropriate registers a function return value
236 of type TYPE, given in virtual format. Assumes floats are passed
237 in d0/d1. */
238
239static void
240m68k_store_return_value (struct type *type, char *valbuf)
241{
73937e03 242 deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
942dc0e9
GS
243}
244
245/* Describe the pointer in each stack frame to the previous stack frame
246 (its caller). */
247
248/* FRAME_CHAIN takes a frame's nominal address and produces the frame's
249 chain-pointer.
250 In the case of the 68000, the frame's nominal address
251 is the address of a 4-byte word containing the calling frame's address. */
252
253/* If we are chaining from sigtramp, then manufacture a sigtramp frame
254 (which isn't really on the stack. I'm not sure this is right for anything
255 but BSD4.3 on an hp300. */
256
257static CORE_ADDR
258m68k_frame_chain (struct frame_info *thisframe)
259{
32eeb91a 260 if (get_frame_type (thisframe) == SIGTRAMP_FRAME)
1e2330ba 261 return get_frame_base (thisframe);
50abf9e5 262 else if (!inside_entry_file (get_frame_pc (thisframe)))
1e2330ba 263 return read_memory_unsigned_integer (get_frame_base (thisframe), 4);
942dc0e9
GS
264 else
265 return 0;
266}
267
268/* A function that tells us whether the function invocation represented
269 by fi does not have a frame on the stack associated with it. If it
270 does not, FRAMELESS is set to 1, else 0. */
271
272static int
273m68k_frameless_function_invocation (struct frame_info *fi)
274{
32eeb91a 275 if (get_frame_type (fi) == SIGTRAMP_FRAME)
942dc0e9
GS
276 return 0;
277 else
278 return frameless_look_for_prologue (fi);
279}
280
281static CORE_ADDR
282m68k_frame_saved_pc (struct frame_info *frame)
283{
32eeb91a 284 if (get_frame_type (frame) == SIGTRAMP_FRAME)
942dc0e9 285 {
11c02a10
AC
286 if (get_next_frame (frame))
287 return read_memory_unsigned_integer (get_frame_base (get_next_frame (frame))
b5fc49aa 288 + SIG_PC_FP_OFFSET, 4);
942dc0e9 289 else
b5fc49aa
AS
290 return read_memory_unsigned_integer (read_register (SP_REGNUM)
291 + SIG_PC_FP_OFFSET - 8, 4);
942dc0e9
GS
292 }
293 else
1e2330ba 294 return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4);
942dc0e9
GS
295}
296
297
b83266a0
SS
298/* The only reason this is here is the tm-altos.h reference below. It
299 was moved back here from tm-m68k.h. FIXME? */
300
301extern CORE_ADDR
fba45db2 302altos_skip_prologue (CORE_ADDR pc)
b83266a0 303{
b5fc49aa 304 register int op = read_memory_unsigned_integer (pc, 2);
89c3b6d3 305 if (op == P_LINKW_FP)
c5aa993b 306 pc += 4; /* Skip link #word */
89c3b6d3 307 else if (op == P_LINKL_FP)
c5aa993b 308 pc += 6; /* Skip link #long */
b83266a0 309 /* Not sure why branches are here. */
514e603d 310 /* From tm-altos.h */
b83266a0 311 else if (op == 0060000)
c5aa993b 312 pc += 4; /* Skip bra #word */
b83266a0 313 else if (op == 00600377)
c5aa993b 314 pc += 6; /* skip bra #long */
b83266a0 315 else if ((op & 0177400) == 0060000)
c5aa993b 316 pc += 2; /* skip bra #char */
b83266a0
SS
317 return pc;
318}
319
89c3b6d3 320int
fba45db2 321delta68_in_sigtramp (CORE_ADDR pc, char *name)
89c3b6d3 322{
1bd54964
AC
323 if (name != NULL)
324 return strcmp (name, "_sigcode") == 0;
325 else
326 return 0;
89c3b6d3
PDM
327}
328
329CORE_ADDR
fba45db2 330delta68_frame_args_address (struct frame_info *frame_info)
89c3b6d3
PDM
331{
332 /* we assume here that the only frameless functions are the system calls
333 or other functions who do not put anything on the stack. */
32eeb91a 334 if (get_frame_type (frame_info) == SIGTRAMP_FRAME)
1e2330ba 335 return get_frame_base (frame_info) + 12;
89c3b6d3
PDM
336 else if (frameless_look_for_prologue (frame_info))
337 {
b5d78d39 338 /* Check for an interrupted system call */
11c02a10
AC
339 if (get_next_frame (frame_info) && (get_frame_type (get_next_frame (frame_info)) == SIGTRAMP_FRAME))
340 return get_frame_base (get_next_frame (frame_info)) + 16;
b5d78d39 341 else
1e2330ba 342 return get_frame_base (frame_info) + 4;
89c3b6d3
PDM
343 }
344 else
1e2330ba 345 return get_frame_base (frame_info);
89c3b6d3
PDM
346}
347
348CORE_ADDR
fba45db2 349delta68_frame_saved_pc (struct frame_info *frame_info)
89c3b6d3 350{
b5fc49aa
AS
351 return read_memory_unsigned_integer (delta68_frame_args_address (frame_info)
352 + 4, 4);
89c3b6d3
PDM
353}
354
392a587b
JM
355/* Return number of args passed to a frame.
356 Can return -1, meaning no way to tell. */
357
358int
fba45db2 359isi_frame_num_args (struct frame_info *fi)
392a587b
JM
360{
361 int val;
8bedc050 362 CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi);
b5fc49aa 363 int insn = read_memory_unsigned_integer (pc, 2);
392a587b 364 val = 0;
c5aa993b 365 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
392a587b 366 val = read_memory_integer (pc + 2, 2);
c5aa993b
JM
367 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
368 || (insn & 0170777) == 0050117) /* addqw */
392a587b
JM
369 {
370 val = (insn >> 9) & 7;
371 if (val == 0)
372 val = 8;
373 }
c5aa993b 374 else if (insn == 0157774) /* addal #WW, sp */
392a587b
JM
375 val = read_memory_integer (pc + 2, 4);
376 val >>= 2;
377 return val;
378}
379
380int
fba45db2 381delta68_frame_num_args (struct frame_info *fi)
392a587b
JM
382{
383 int val;
8bedc050 384 CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi);
b5fc49aa 385 int insn = read_memory_unsigned_integer (pc, 2);
392a587b 386 val = 0;
c5aa993b 387 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
392a587b 388 val = read_memory_integer (pc + 2, 2);
c5aa993b
JM
389 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
390 || (insn & 0170777) == 0050117) /* addqw */
392a587b
JM
391 {
392 val = (insn >> 9) & 7;
393 if (val == 0)
394 val = 8;
395 }
c5aa993b 396 else if (insn == 0157774) /* addal #WW, sp */
392a587b
JM
397 val = read_memory_integer (pc + 2, 4);
398 val >>= 2;
399 return val;
400}
401
402int
fba45db2 403news_frame_num_args (struct frame_info *fi)
392a587b
JM
404{
405 int val;
8bedc050 406 CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi);
b5fc49aa 407 int insn = read_memory_unsigned_integer (pc, 2);
392a587b 408 val = 0;
c5aa993b 409 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
392a587b 410 val = read_memory_integer (pc + 2, 2);
c5aa993b
JM
411 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
412 || (insn & 0170777) == 0050117) /* addqw */
392a587b
JM
413 {
414 val = (insn >> 9) & 7;
415 if (val == 0)
416 val = 8;
417 }
c5aa993b 418 else if (insn == 0157774) /* addal #WW, sp */
392a587b
JM
419 val = read_memory_integer (pc + 2, 4);
420 val >>= 2;
421 return val;
422}
b83266a0 423
7f8e7424
GS
424/* Insert the specified number of args and function address
425 into a call sequence of the above form stored at DUMMYNAME.
426 We use the BFD routines to store a big-endian value of known size. */
427
428void
a2c6a6d5
GS
429m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
430 struct value **args, struct type *type, int gcc_p)
7f8e7424 431{
a2c6a6d5
GS
432 bfd_putb32 (fun, (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 2);
433 bfd_putb32 (nargs * 4,
434 (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 8);
7f8e7424
GS
435}
436
437
c906108c
SS
438/* Push an empty stack frame, to record the current PC, etc. */
439
440void
fba45db2 441m68k_push_dummy_frame (void)
c906108c
SS
442{
443 register CORE_ADDR sp = read_register (SP_REGNUM);
444 register int regnum;
445 char raw_buffer[12];
446
447 sp = push_word (sp, read_register (PC_REGNUM));
448 sp = push_word (sp, read_register (FP_REGNUM));
449 write_register (FP_REGNUM, sp);
450
451 /* Always save the floating-point registers, whether they exist on
452 this target or not. */
453 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
454 {
73937e03 455 deprecated_read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
c906108c
SS
456 sp = push_bytes (sp, raw_buffer, 12);
457 }
458
459 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
460 {
461 sp = push_word (sp, read_register (regnum));
462 }
463 sp = push_word (sp, read_register (PS_REGNUM));
464 write_register (SP_REGNUM, sp);
465}
466
467/* Discard from the stack the innermost frame,
468 restoring all saved registers. */
469
470void
fba45db2 471m68k_pop_frame (void)
c906108c
SS
472{
473 register struct frame_info *frame = get_current_frame ();
474 register CORE_ADDR fp;
475 register int regnum;
c906108c
SS
476 char raw_buffer[12];
477
c193f6ac 478 fp = get_frame_base (frame);
7f8e7424 479 m68k_frame_init_saved_regs (frame);
c5aa993b 480 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
c906108c 481 {
b2fb4676 482 if (get_frame_saved_regs (frame)[regnum])
c906108c 483 {
b2fb4676 484 read_memory (get_frame_saved_regs (frame)[regnum], raw_buffer, 12);
73937e03
AC
485 deprecated_write_register_bytes (REGISTER_BYTE (regnum), raw_buffer,
486 12);
c906108c
SS
487 }
488 }
c5aa993b 489 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
c906108c 490 {
b2fb4676 491 if (get_frame_saved_regs (frame)[regnum])
c906108c 492 {
a2c6a6d5 493 write_register (regnum,
b2fb4676 494 read_memory_integer (get_frame_saved_regs (frame)[regnum], 4));
c906108c
SS
495 }
496 }
b2fb4676 497 if (get_frame_saved_regs (frame)[PS_REGNUM])
c906108c 498 {
b5d78d39 499 write_register (PS_REGNUM,
b2fb4676 500 read_memory_integer (get_frame_saved_regs (frame)[PS_REGNUM], 4));
c906108c
SS
501 }
502 write_register (FP_REGNUM, read_memory_integer (fp, 4));
503 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
504 write_register (SP_REGNUM, fp + 8);
505 flush_cached_frames ();
506}
c906108c 507\f
c5aa993b 508
c906108c
SS
509/* Given an ip value corresponding to the start of a function,
510 return the ip of the first instruction after the function
511 prologue. This is the generic m68k support. Machines which
512 require something different can override the SKIP_PROLOGUE
513 macro to point elsewhere.
514
515 Some instructions which typically may appear in a function
516 prologue include:
517
518 A link instruction, word form:
519
c5aa993b 520 link.w %a6,&0 4e56 XXXX
c906108c
SS
521
522 A link instruction, long form:
523
c5aa993b 524 link.l %fp,&F%1 480e XXXX XXXX
c906108c
SS
525
526 A movm instruction to preserve integer regs:
527
c5aa993b 528 movm.l &M%1,(4,%sp) 48ef XXXX XXXX
c906108c
SS
529
530 A fmovm instruction to preserve float regs:
531
c5aa993b 532 fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX
c906108c
SS
533
534 Some profiling setup code (FIXME, not recognized yet):
535
c5aa993b
JM
536 lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX
537 bsr _mcount 61ff XXXX XXXX
c906108c 538
c5aa993b 539 */
c906108c 540
c906108c 541CORE_ADDR
fba45db2 542m68k_skip_prologue (CORE_ADDR ip)
c906108c
SS
543{
544 register CORE_ADDR limit;
545 struct symtab_and_line sal;
546 register int op;
547
548 /* Find out if there is a known limit for the extent of the prologue.
549 If so, ensure we don't go past it. If not, assume "infinity". */
550
551 sal = find_pc_line (ip, 0);
b5d78d39 552 limit = (sal.end) ? sal.end : (CORE_ADDR) ~0;
c906108c
SS
553
554 while (ip < limit)
555 {
b5fc49aa 556 op = read_memory_unsigned_integer (ip, 2);
c5aa993b 557
89c3b6d3
PDM
558 if (op == P_LINKW_FP)
559 ip += 4; /* Skip link.w */
560 else if (op == P_PEA_FP)
c5aa993b 561 ip += 2; /* Skip pea %fp */
89c3b6d3 562 else if (op == P_MOVL_SP_FP)
c5aa993b 563 ip += 2; /* Skip move.l %sp, %fp */
89c3b6d3
PDM
564 else if (op == P_LINKL_FP)
565 ip += 6; /* Skip link.l */
566 else if (op == P_MOVML)
567 ip += 6; /* Skip movm.l */
c906108c 568 else if (op == P_FMOVM)
89c3b6d3 569 ip += 10; /* Skip fmovm */
c906108c 570 else
b5d78d39 571 break; /* Found unknown code, bail out. */
c906108c
SS
572 }
573 return (ip);
574}
575
7f8e7424
GS
576/* Store the addresses of the saved registers of the frame described by
577 FRAME_INFO in its saved_regs field.
578 This includes special registers such as pc and fp saved in special
579 ways in the stack frame. sp is even more special:
580 the address we return for it IS the sp for the next frame. */
581
c906108c 582void
7f8e7424 583m68k_frame_init_saved_regs (struct frame_info *frame_info)
c906108c 584{
c5aa993b
JM
585 register int regnum;
586 register int regmask;
587 register CORE_ADDR next_addr;
c906108c
SS
588 register CORE_ADDR pc;
589
590 /* First possible address for a pc in a call dummy for this frame. */
591 CORE_ADDR possible_call_dummy_start =
1e2330ba 592 get_frame_base (frame_info) - 28 - FP_REGNUM * 4 - 4 - 8 * 12;
c906108c
SS
593
594 int nextinsn;
7f8e7424 595
b2fb4676 596 if (get_frame_saved_regs (frame_info))
7f8e7424
GS
597 return;
598
599 frame_saved_regs_zalloc (frame_info);
600
b2fb4676 601 memset (get_frame_saved_regs (frame_info), 0, SIZEOF_FRAME_SAVED_REGS);
7f8e7424 602
50abf9e5 603 if (get_frame_pc (frame_info) >= possible_call_dummy_start
1e2330ba 604 && get_frame_pc (frame_info) <= get_frame_base (frame_info))
c906108c
SS
605 {
606
607 /* It is a call dummy. We could just stop now, since we know
c5aa993b
JM
608 what the call dummy saves and where. But this code proceeds
609 to parse the "prologue" which is part of the call dummy.
610 This is needlessly complex and confusing. FIXME. */
c906108c 611
1e2330ba 612 next_addr = get_frame_base (frame_info);
c906108c
SS
613 pc = possible_call_dummy_start;
614 }
c5aa993b 615 else
c906108c 616 {
50abf9e5 617 pc = get_pc_function_start (get_frame_pc (frame_info));
c906108c 618
b5fc49aa 619 nextinsn = read_memory_unsigned_integer (pc, 2);
89c3b6d3 620 if (P_PEA_FP == nextinsn
b5fc49aa 621 && P_MOVL_SP_FP == read_memory_unsigned_integer (pc + 2, 2))
c906108c 622 {
89c3b6d3 623 /* pea %fp
c5aa993b 624 move.l %sp, %fp */
1e2330ba 625 next_addr = get_frame_base (frame_info);
89c3b6d3 626 pc += 4;
c906108c 627 }
89c3b6d3 628 else if (P_LINKL_FP == nextinsn)
c906108c
SS
629 /* link.l %fp */
630 /* Find the address above the saved
631 regs using the amount of storage from the link instruction. */
89c3b6d3 632 {
1e2330ba 633 next_addr = get_frame_base (frame_info) + read_memory_integer (pc + 2, 4);
89c3b6d3
PDM
634 pc += 6;
635 }
636 else if (P_LINKW_FP == nextinsn)
c906108c
SS
637 /* link.w %fp */
638 /* Find the address above the saved
639 regs using the amount of storage from the link instruction. */
89c3b6d3 640 {
1e2330ba 641 next_addr = get_frame_base (frame_info) + read_memory_integer (pc + 2, 2);
89c3b6d3
PDM
642 pc += 4;
643 }
c5aa993b
JM
644 else
645 goto lose;
646
647 /* If have an addal #-n, sp next, adjust next_addr. */
b5fc49aa 648 if (read_memory_unsigned_integer (pc, 2) == 0157774)
c5aa993b
JM
649 next_addr += read_memory_integer (pc += 2, 4), pc += 4;
650 }
c5aa993b 651
b5d78d39 652 for (;;)
c5aa993b 653 {
b5fc49aa
AS
654 nextinsn = read_memory_unsigned_integer (pc, 2);
655 regmask = read_memory_unsigned_integer (pc + 2, 2);
89c3b6d3
PDM
656 /* fmovemx to -(sp) */
657 if (0xf227 == nextinsn && (regmask & 0xff00) == 0xe000)
c906108c 658 {
89c3b6d3
PDM
659 /* Regmask's low bit is for register fp7, the first pushed */
660 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
661 if (regmask & 1)
b2fb4676 662 get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 12);
89c3b6d3
PDM
663 pc += 4;
664 }
665 /* fmovemx to (fp + displacement) */
666 else if (0171056 == nextinsn && (regmask & 0xff00) == 0xf000)
667 {
668 register CORE_ADDR addr;
669
1e2330ba 670 addr = get_frame_base (frame_info) + read_memory_integer (pc + 4, 2);
89c3b6d3
PDM
671 /* Regmask's low bit is for register fp7, the first pushed */
672 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
673 if (regmask & 1)
674 {
b2fb4676 675 get_frame_saved_regs (frame_info)[regnum] = addr;
89c3b6d3
PDM
676 addr += 12;
677 }
678 pc += 6;
679 }
680 /* moveml to (sp) */
681 else if (0044327 == nextinsn)
682 {
683 /* Regmask's low bit is for register 0, the first written */
684 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
685 if (regmask & 1)
686 {
b2fb4676 687 get_frame_saved_regs (frame_info)[regnum] = next_addr;
89c3b6d3
PDM
688 next_addr += 4;
689 }
690 pc += 4;
691 }
692 /* moveml to (fp + displacement) */
693 else if (0044356 == nextinsn)
694 {
695 register CORE_ADDR addr;
696
1e2330ba 697 addr = get_frame_base (frame_info) + read_memory_integer (pc + 4, 2);
89c3b6d3
PDM
698 /* Regmask's low bit is for register 0, the first written */
699 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
700 if (regmask & 1)
701 {
b2fb4676 702 get_frame_saved_regs (frame_info)[regnum] = addr;
89c3b6d3
PDM
703 addr += 4;
704 }
705 pc += 6;
706 }
707 /* moveml to -(sp) */
708 else if (0044347 == nextinsn)
709 {
710 /* Regmask's low bit is for register 15, the first pushed */
711 for (regnum = 16; --regnum >= 0; regmask >>= 1)
712 if (regmask & 1)
b2fb4676 713 get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 4);
89c3b6d3
PDM
714 pc += 4;
715 }
716 /* movl r,-(sp) */
717 else if (0x2f00 == (0xfff0 & nextinsn))
718 {
719 regnum = 0xf & nextinsn;
b2fb4676 720 get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 4);
89c3b6d3 721 pc += 2;
c906108c 722 }
89c3b6d3
PDM
723 /* fmovemx to index of sp */
724 else if (0xf236 == nextinsn && (regmask & 0xff00) == 0xf000)
725 {
726 /* Regmask's low bit is for register fp0, the first written */
727 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
728 if (regmask & 1)
729 {
b2fb4676 730 get_frame_saved_regs (frame_info)[regnum] = next_addr;
89c3b6d3
PDM
731 next_addr += 12;
732 }
733 pc += 10;
734 }
735 /* clrw -(sp); movw ccr,-(sp) */
736 else if (0x4267 == nextinsn && 0x42e7 == regmask)
737 {
b2fb4676 738 get_frame_saved_regs (frame_info)[PS_REGNUM] = (next_addr -= 4);
89c3b6d3
PDM
739 pc += 4;
740 }
741 else
742 break;
c906108c 743 }
c5aa993b 744lose:;
1e2330ba
AC
745 get_frame_saved_regs (frame_info)[SP_REGNUM] = get_frame_base (frame_info) + 8;
746 get_frame_saved_regs (frame_info)[FP_REGNUM] = get_frame_base (frame_info);
747 get_frame_saved_regs (frame_info)[PC_REGNUM] = get_frame_base (frame_info) + 4;
c906108c
SS
748#ifdef SIG_SP_FP_OFFSET
749 /* Adjust saved SP_REGNUM for fake _sigtramp frames. */
5a203e44 750 if ((get_frame_type (frame_info) == SIGTRAMP_FRAME) && frame_info->next)
7f8e7424
GS
751 frame_info->saved_regs[SP_REGNUM] =
752 frame_info->next->frame + SIG_SP_FP_OFFSET;
c906108c
SS
753#endif
754}
755
756
c5aa993b 757#ifdef USE_PROC_FS /* Target dependent support for /proc */
c906108c
SS
758
759#include <sys/procfs.h>
760
c60c0f5f
MS
761/* Prototypes for supply_gregset etc. */
762#include "gregset.h"
763
c906108c 764/* The /proc interface divides the target machine's register set up into
c5aa993b
JM
765 two different sets, the general register set (gregset) and the floating
766 point register set (fpregset). For each set, there is an ioctl to get
767 the current register set and another ioctl to set the current values.
c906108c 768
c5aa993b
JM
769 The actual structure passed through the ioctl interface is, of course,
770 naturally machine dependent, and is different for each set of registers.
771 For the m68k for example, the general register set is typically defined
772 by:
c906108c 773
c5aa993b 774 typedef int gregset_t[18];
c906108c 775
c5aa993b
JM
776 #define R_D0 0
777 ...
778 #define R_PS 17
c906108c 779
c5aa993b 780 and the floating point set by:
c906108c 781
c5aa993b
JM
782 typedef struct fpregset {
783 int f_pcr;
784 int f_psr;
785 int f_fpiaddr;
786 int f_fpregs[8][3]; (8 regs, 96 bits each)
787 } fpregset_t;
c906108c 788
c5aa993b
JM
789 These routines provide the packing and unpacking of gregset_t and
790 fpregset_t formatted data.
c906108c
SS
791
792 */
793
794/* Atari SVR4 has R_SR but not R_PS */
795
796#if !defined (R_PS) && defined (R_SR)
797#define R_PS R_SR
798#endif
799
800/* Given a pointer to a general register set in /proc format (gregset_t *),
c5aa993b
JM
801 unpack the register contents and supply them as gdb's idea of the current
802 register values. */
c906108c
SS
803
804void
fba45db2 805supply_gregset (gregset_t *gregsetp)
c906108c
SS
806{
807 register int regi;
808 register greg_t *regp = (greg_t *) gregsetp;
809
c5aa993b 810 for (regi = 0; regi < R_PC; regi++)
c906108c
SS
811 {
812 supply_register (regi, (char *) (regp + regi));
813 }
814 supply_register (PS_REGNUM, (char *) (regp + R_PS));
815 supply_register (PC_REGNUM, (char *) (regp + R_PC));
816}
817
818void
fba45db2 819fill_gregset (gregset_t *gregsetp, int regno)
c906108c
SS
820{
821 register int regi;
822 register greg_t *regp = (greg_t *) gregsetp;
c906108c 823
c5aa993b 824 for (regi = 0; regi < R_PC; regi++)
c906108c
SS
825 {
826 if ((regno == -1) || (regno == regi))
827 {
524d7c18 828 *(regp + regi) = *(int *) &deprecated_registers[REGISTER_BYTE (regi)];
c906108c
SS
829 }
830 }
831 if ((regno == -1) || (regno == PS_REGNUM))
832 {
524d7c18 833 *(regp + R_PS) = *(int *) &deprecated_registers[REGISTER_BYTE (PS_REGNUM)];
c906108c
SS
834 }
835 if ((regno == -1) || (regno == PC_REGNUM))
836 {
524d7c18 837 *(regp + R_PC) = *(int *) &deprecated_registers[REGISTER_BYTE (PC_REGNUM)];
c906108c
SS
838 }
839}
840
841#if defined (FP0_REGNUM)
842
843/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
844 (fpregset_t *), unpack the register contents and supply them as gdb's
845 idea of the current floating point register values. */
c906108c 846
c5aa993b 847void
fba45db2 848supply_fpregset (fpregset_t *fpregsetp)
c906108c
SS
849{
850 register int regi;
851 char *from;
c5aa993b 852
32eeb91a 853 for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
c906108c 854 {
c5aa993b 855 from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
c906108c
SS
856 supply_register (regi, from);
857 }
32eeb91a
AS
858 supply_register (M68K_FPC_REGNUM, (char *) &(fpregsetp->f_pcr));
859 supply_register (M68K_FPS_REGNUM, (char *) &(fpregsetp->f_psr));
860 supply_register (M68K_FPI_REGNUM, (char *) &(fpregsetp->f_fpiaddr));
c906108c
SS
861}
862
863/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
864 (fpregset_t *), update the register specified by REGNO from gdb's idea
865 of the current floating point register set. If REGNO is -1, update
866 them all. */
c906108c
SS
867
868void
fba45db2 869fill_fpregset (fpregset_t *fpregsetp, int regno)
c906108c
SS
870{
871 int regi;
872 char *to;
873 char *from;
c906108c 874
32eeb91a 875 for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
c906108c
SS
876 {
877 if ((regno == -1) || (regno == regi))
878 {
524d7c18 879 from = (char *) &deprecated_registers[REGISTER_BYTE (regi)];
c5aa993b 880 to = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
c906108c
SS
881 memcpy (to, from, REGISTER_RAW_SIZE (regi));
882 }
883 }
32eeb91a 884 if ((regno == -1) || (regno == M68K_FPC_REGNUM))
c906108c 885 {
32eeb91a 886 fpregsetp->f_pcr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPC_REGNUM)];
c906108c 887 }
32eeb91a 888 if ((regno == -1) || (regno == M68K_FPS_REGNUM))
c906108c 889 {
32eeb91a 890 fpregsetp->f_psr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPS_REGNUM)];
c906108c 891 }
32eeb91a 892 if ((regno == -1) || (regno == M68K_FPI_REGNUM))
c906108c 893 {
32eeb91a 894 fpregsetp->f_fpiaddr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPI_REGNUM)];
c906108c
SS
895 }
896}
897
c5aa993b 898#endif /* defined (FP0_REGNUM) */
c906108c 899
c5aa993b 900#endif /* USE_PROC_FS */
c906108c 901
c906108c
SS
902/* Figure out where the longjmp will land. Slurp the args out of the stack.
903 We expect the first arg to be a pointer to the jmp_buf structure from which
904 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
905 This routine returns true on success. */
906
2765b798
AC
907/* NOTE: cagney/2000-11-08: For this function to be fully multi-arched
908 the macro's JB_PC and JB_ELEMENT_SIZE would need to be moved into
909 the ``struct gdbarch_tdep'' object and then set on a target ISA/ABI
910 dependant basis. */
911
c906108c 912int
f4281f55 913m68k_get_longjmp_target (CORE_ADDR *pc)
c906108c 914{
2765b798 915#if defined (JB_PC) && defined (JB_ELEMENT_SIZE)
35fc8285 916 char *buf;
c906108c
SS
917 CORE_ADDR sp, jb_addr;
918
35fc8285 919 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
c5aa993b 920 sp = read_register (SP_REGNUM);
c906108c 921
b5d78d39
GS
922 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
923 buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
c906108c
SS
924 return 0;
925
926 jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
927
928 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
929 TARGET_PTR_BIT / TARGET_CHAR_BIT))
930 return 0;
931
932 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
933
934 return 1;
2765b798 935#else
8e65ff28
AC
936 internal_error (__FILE__, __LINE__,
937 "m68k_get_longjmp_target: not implemented");
2765b798
AC
938 return 0;
939#endif
c906108c 940}
c906108c
SS
941
942/* Immediately after a function call, return the saved pc before the frame
943 is setup. For sun3's, we check for the common case of being inside of a
944 system call, and if so, we know that Sun pushes the call # on the stack
945 prior to doing the trap. */
946
947CORE_ADDR
fba45db2 948m68k_saved_pc_after_call (struct frame_info *frame)
c906108c
SS
949{
950#ifdef SYSCALL_TRAP
951 int op;
952
b5fc49aa 953 op = read_memory_unsigned_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2);
c906108c
SS
954
955 if (op == SYSCALL_TRAP)
b5fc49aa 956 return read_memory_unsigned_integer (read_register (SP_REGNUM) + 4, 4);
c906108c
SS
957 else
958#endif /* SYSCALL_TRAP */
b5fc49aa 959 return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
c906108c
SS
960}
961
152d9db6
GS
962/* Function: m68k_gdbarch_init
963 Initializer function for the m68k gdbarch vector.
964 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
965
966static struct gdbarch *
967m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
968{
a2c6a6d5
GS
969 static LONGEST call_dummy_words[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7,
970 0x4eb93232, 0x3232dffc, 0x69696969,
971 (0x4e404e71 | (BPT_VECTOR << 16))
972 };
152d9db6
GS
973 struct gdbarch_tdep *tdep = NULL;
974 struct gdbarch *gdbarch;
975
976 /* find a candidate among the list of pre-declared architectures. */
977 arches = gdbarch_list_lookup_by_info (arches, &info);
978 if (arches != NULL)
979 return (arches->gdbarch);
980
981#if 0
982 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
983#endif
6300c360 984
152d9db6
GS
985 gdbarch = gdbarch_alloc (&info, 0);
986
a5afb99f
AC
987 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
988 ready to unwind the PC first (see frame.c:get_prev_frame()). */
989 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
990
5d3ed2e3
GS
991 set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext);
992 set_gdbarch_long_double_bit (gdbarch, 96);
993
994 set_gdbarch_function_start_offset (gdbarch, 0);
995
996 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
997 set_gdbarch_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call);
103a1597 998 set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
5d3ed2e3
GS
999
1000 /* Stack grows down. */
1001 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1002 set_gdbarch_stack_align (gdbarch, m68k_stack_align);
1003
6300c360
GS
1004
1005 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
942dc0e9
GS
1006 set_gdbarch_decr_pc_after_break (gdbarch, 2);
1007
1008 set_gdbarch_store_struct_return (gdbarch, m68k_store_struct_return);
1009 set_gdbarch_deprecated_extract_return_value (gdbarch,
1010 m68k_deprecated_extract_return_value);
ebba8386 1011 set_gdbarch_deprecated_store_return_value (gdbarch, m68k_store_return_value);
942dc0e9
GS
1012
1013 set_gdbarch_frame_chain (gdbarch, m68k_frame_chain);
8bedc050 1014 set_gdbarch_deprecated_frame_saved_pc (gdbarch, m68k_frame_saved_pc);
f30ee0bc 1015 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, m68k_frame_init_saved_regs);
942dc0e9
GS
1016 set_gdbarch_frameless_function_invocation (gdbarch,
1017 m68k_frameless_function_invocation);
6300c360
GS
1018 /* OK to default this value to 'unknown'. */
1019 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
1020 set_gdbarch_frame_args_skip (gdbarch, 8);
942dc0e9 1021
5d3ed2e3
GS
1022 set_gdbarch_register_raw_size (gdbarch, m68k_register_raw_size);
1023 set_gdbarch_register_virtual_size (gdbarch, m68k_register_virtual_size);
a0ed5532
AC
1024 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 12);
1025 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 12);
5d3ed2e3
GS
1026 set_gdbarch_register_virtual_type (gdbarch, m68k_register_virtual_type);
1027 set_gdbarch_register_name (gdbarch, m68k_register_name);
1028 set_gdbarch_register_size (gdbarch, 4);
1029 set_gdbarch_register_byte (gdbarch, m68k_register_byte);
942dc0e9
GS
1030 set_gdbarch_num_regs (gdbarch, 29);
1031 set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
1032 set_gdbarch_register_bytes (gdbarch, (16 * 4 + 8 + 8 * 12 + 3 * 4));
32eeb91a
AS
1033 set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
1034 set_gdbarch_fp_regnum (gdbarch, M68K_FP_REGNUM);
1035 set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
1036 set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
1037 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
a2c6a6d5 1038
07555a72 1039 set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0);
7f8e7424
GS
1040 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
1041 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
a2c6a6d5 1042 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 24);
ae45cd16 1043 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_on_stack);
7f8e7424
GS
1044 set_gdbarch_call_dummy_p (gdbarch, 1);
1045 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1046 set_gdbarch_call_dummy_length (gdbarch, 28);
1047 set_gdbarch_call_dummy_start_offset (gdbarch, 12);
a2c6a6d5 1048
7f8e7424
GS
1049 set_gdbarch_call_dummy_words (gdbarch, call_dummy_words);
1050 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (call_dummy_words));
1051 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1052 set_gdbarch_fix_call_dummy (gdbarch, m68k_fix_call_dummy);
f3824013 1053 set_gdbarch_deprecated_push_dummy_frame (gdbarch, m68k_push_dummy_frame);
7f8e7424 1054 set_gdbarch_pop_frame (gdbarch, m68k_pop_frame);
a2c6a6d5 1055
152d9db6
GS
1056 return gdbarch;
1057}
1058
1059
1060static void
1061m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1062{
1063
1064}
2acceee2 1065
c906108c 1066void
fba45db2 1067_initialize_m68k_tdep (void)
c906108c 1068{
152d9db6 1069 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
c906108c
SS
1070 tm_print_insn = print_insn_m68k;
1071}
This page took 0.339208 seconds and 4 git commands to generate.