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