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