1 |
1181 |
sfurman |
/* Target dependent code for the Motorola 68000 series.
|
2 |
|
|
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001
|
3 |
|
|
Free Software Foundation, Inc.
|
4 |
|
|
|
5 |
|
|
This file is part of GDB.
|
6 |
|
|
|
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.
|
11 |
|
|
|
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.
|
16 |
|
|
|
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. */
|
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"
|
28 |
|
|
#include "inferior.h"
|
29 |
|
|
#include "regcache.h"
|
30 |
|
|
#include "arch-utils.h"
|
31 |
|
|
|
32 |
|
|
|
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 |
|
|
|
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 |
|
|
|
56 |
|
|
enum
|
57 |
|
|
{
|
58 |
|
|
E_A1_REGNUM = 9,
|
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 */
|
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
|
67 |
|
|
};
|
68 |
|
|
|
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 |
|
|
|
99 |
|
|
void m68k_frame_init_saved_regs (struct frame_info *frame_info);
|
100 |
|
|
|
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 |
|
|
|
105 |
|
|
const static unsigned char *
|
106 |
|
|
m68k_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 |
|
|
|
113 |
|
|
const static unsigned char *
|
114 |
|
|
m68k_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 |
|
|
|
122 |
|
|
static int
|
123 |
|
|
m68k_register_bytes_ok (long numbytes)
|
124 |
|
|
{
|
125 |
|
|
return ((numbytes == REGISTER_BYTES_FP)
|
126 |
|
|
|| (numbytes == REGISTER_BYTES_NOFP));
|
127 |
|
|
}
|
128 |
|
|
|
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 |
|
|
|
135 |
|
|
static int
|
136 |
|
|
m68k_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 |
|
|
|
145 |
|
|
static int
|
146 |
|
|
m68k_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 |
|
|
|
158 |
|
|
static struct type *
|
159 |
|
|
m68k_register_virtual_type (int regnum)
|
160 |
|
|
{
|
161 |
|
|
if ((unsigned) regnum >= E_FPC_REGNUM)
|
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 |
|
|
|
174 |
|
|
static const char *
|
175 |
|
|
m68k_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 |
|
|
|
195 |
|
|
static CORE_ADDR
|
196 |
|
|
m68k_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 |
|
|
|
204 |
|
|
static int
|
205 |
|
|
m68k_register_byte (int regnum)
|
206 |
|
|
{
|
207 |
|
|
if (regnum >= E_FPC_REGNUM)
|
208 |
|
|
return (((regnum - E_FPC_REGNUM) * 4) + 168);
|
209 |
|
|
else if (regnum >= FP0_REGNUM)
|
210 |
|
|
return (((regnum - FP0_REGNUM) * 12) + 72);
|
211 |
|
|
else
|
212 |
|
|
return (regnum * 4);
|
213 |
|
|
}
|
214 |
|
|
|
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 |
|
|
|
218 |
|
|
static void
|
219 |
|
|
m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
|
220 |
|
|
{
|
221 |
|
|
write_register (E_A1_REGNUM, addr);
|
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 |
|
|
|
229 |
|
|
static void
|
230 |
|
|
m68k_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 |
|
|
|
242 |
|
|
static CORE_ADDR
|
243 |
|
|
m68k_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 |
|
|
|
252 |
|
|
static void
|
253 |
|
|
m68k_store_return_value (struct type *type, char *valbuf)
|
254 |
|
|
{
|
255 |
|
|
write_register_bytes (0, valbuf, TYPE_LENGTH (type));
|
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 |
|
|
|
270 |
|
|
static CORE_ADDR
|
271 |
|
|
m68k_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 |
|
|
|
285 |
|
|
static int
|
286 |
|
|
m68k_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 |
|
|
|
294 |
|
|
static CORE_ADDR
|
295 |
|
|
m68k_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 |
|
|
|
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 |
|
|
|
313 |
|
|
extern CORE_ADDR
|
314 |
|
|
altos_skip_prologue (CORE_ADDR pc)
|
315 |
|
|
{
|
316 |
|
|
register int op = read_memory_integer (pc, 2);
|
317 |
|
|
if (op == P_LINKW_FP)
|
318 |
|
|
pc += 4; /* Skip link #word */
|
319 |
|
|
else if (op == P_LINKL_FP)
|
320 |
|
|
pc += 6; /* Skip link #long */
|
321 |
|
|
/* Not sure why branches are here. */
|
322 |
|
|
/* From tm-altos.h */
|
323 |
|
|
else if (op == 0060000)
|
324 |
|
|
pc += 4; /* Skip bra #word */
|
325 |
|
|
else if (op == 00600377)
|
326 |
|
|
pc += 6; /* skip bra #long */
|
327 |
|
|
else if ((op & 0177400) == 0060000)
|
328 |
|
|
pc += 2; /* skip bra #char */
|
329 |
|
|
return pc;
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
int
|
333 |
|
|
delta68_in_sigtramp (CORE_ADDR pc, char *name)
|
334 |
|
|
{
|
335 |
|
|
if (name != NULL)
|
336 |
|
|
return strcmp (name, "_sigcode") == 0;
|
337 |
|
|
else
|
338 |
|
|
return 0;
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
CORE_ADDR
|
342 |
|
|
delta68_frame_args_address (struct frame_info *frame_info)
|
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 |
|
|
{
|
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;
|
355 |
|
|
}
|
356 |
|
|
else
|
357 |
|
|
return frame_info->frame;
|
358 |
|
|
}
|
359 |
|
|
|
360 |
|
|
CORE_ADDR
|
361 |
|
|
delta68_frame_saved_pc (struct frame_info *frame_info)
|
362 |
|
|
{
|
363 |
|
|
return read_memory_integer (delta68_frame_args_address (frame_info) + 4, 4);
|
364 |
|
|
}
|
365 |
|
|
|
366 |
|
|
/* Return number of args passed to a frame.
|
367 |
|
|
Can return -1, meaning no way to tell. */
|
368 |
|
|
|
369 |
|
|
int
|
370 |
|
|
isi_frame_num_args (struct frame_info *fi)
|
371 |
|
|
{
|
372 |
|
|
int val;
|
373 |
|
|
CORE_ADDR pc = FRAME_SAVED_PC (fi);
|
374 |
|
|
int insn = 0177777 & read_memory_integer (pc, 2);
|
375 |
|
|
val = 0;
|
376 |
|
|
if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
|
377 |
|
|
val = read_memory_integer (pc + 2, 2);
|
378 |
|
|
else if ((insn & 0170777) == 0050217 /* addql #N, sp */
|
379 |
|
|
|| (insn & 0170777) == 0050117) /* addqw */
|
380 |
|
|
{
|
381 |
|
|
val = (insn >> 9) & 7;
|
382 |
|
|
if (val == 0)
|
383 |
|
|
val = 8;
|
384 |
|
|
}
|
385 |
|
|
else if (insn == 0157774) /* addal #WW, sp */
|
386 |
|
|
val = read_memory_integer (pc + 2, 4);
|
387 |
|
|
val >>= 2;
|
388 |
|
|
return val;
|
389 |
|
|
}
|
390 |
|
|
|
391 |
|
|
int
|
392 |
|
|
delta68_frame_num_args (struct frame_info *fi)
|
393 |
|
|
{
|
394 |
|
|
int val;
|
395 |
|
|
CORE_ADDR pc = FRAME_SAVED_PC (fi);
|
396 |
|
|
int insn = 0177777 & read_memory_integer (pc, 2);
|
397 |
|
|
val = 0;
|
398 |
|
|
if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
|
399 |
|
|
val = read_memory_integer (pc + 2, 2);
|
400 |
|
|
else if ((insn & 0170777) == 0050217 /* addql #N, sp */
|
401 |
|
|
|| (insn & 0170777) == 0050117) /* addqw */
|
402 |
|
|
{
|
403 |
|
|
val = (insn >> 9) & 7;
|
404 |
|
|
if (val == 0)
|
405 |
|
|
val = 8;
|
406 |
|
|
}
|
407 |
|
|
else if (insn == 0157774) /* addal #WW, sp */
|
408 |
|
|
val = read_memory_integer (pc + 2, 4);
|
409 |
|
|
val >>= 2;
|
410 |
|
|
return val;
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
int
|
414 |
|
|
news_frame_num_args (struct frame_info *fi)
|
415 |
|
|
{
|
416 |
|
|
int val;
|
417 |
|
|
CORE_ADDR pc = FRAME_SAVED_PC (fi);
|
418 |
|
|
int insn = 0177777 & read_memory_integer (pc, 2);
|
419 |
|
|
val = 0;
|
420 |
|
|
if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
|
421 |
|
|
val = read_memory_integer (pc + 2, 2);
|
422 |
|
|
else if ((insn & 0170777) == 0050217 /* addql #N, sp */
|
423 |
|
|
|| (insn & 0170777) == 0050117) /* addqw */
|
424 |
|
|
{
|
425 |
|
|
val = (insn >> 9) & 7;
|
426 |
|
|
if (val == 0)
|
427 |
|
|
val = 8;
|
428 |
|
|
}
|
429 |
|
|
else if (insn == 0157774) /* addal #WW, sp */
|
430 |
|
|
val = read_memory_integer (pc + 2, 4);
|
431 |
|
|
val >>= 2;
|
432 |
|
|
return val;
|
433 |
|
|
}
|
434 |
|
|
|
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 |
|
|
|
439 |
|
|
void
|
440 |
|
|
m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
|
441 |
|
|
struct value **args, struct type *type, int gcc_p)
|
442 |
|
|
{
|
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);
|
446 |
|
|
}
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
/* Push an empty stack frame, to record the current PC, etc. */
|
450 |
|
|
|
451 |
|
|
void
|
452 |
|
|
m68k_push_dummy_frame (void)
|
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 |
|
|
{
|
466 |
|
|
read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
|
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 |
|
|
|
481 |
|
|
void
|
482 |
|
|
m68k_pop_frame (void)
|
483 |
|
|
{
|
484 |
|
|
register struct frame_info *frame = get_current_frame ();
|
485 |
|
|
register CORE_ADDR fp;
|
486 |
|
|
register int regnum;
|
487 |
|
|
char raw_buffer[12];
|
488 |
|
|
|
489 |
|
|
fp = FRAME_FP (frame);
|
490 |
|
|
m68k_frame_init_saved_regs (frame);
|
491 |
|
|
for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
|
492 |
|
|
{
|
493 |
|
|
if (frame->saved_regs[regnum])
|
494 |
|
|
{
|
495 |
|
|
read_memory (frame->saved_regs[regnum], raw_buffer, 12);
|
496 |
|
|
write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
|
497 |
|
|
}
|
498 |
|
|
}
|
499 |
|
|
for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
|
500 |
|
|
{
|
501 |
|
|
if (frame->saved_regs[regnum])
|
502 |
|
|
{
|
503 |
|
|
write_register (regnum,
|
504 |
|
|
read_memory_integer (frame->saved_regs[regnum], 4));
|
505 |
|
|
}
|
506 |
|
|
}
|
507 |
|
|
if (frame->saved_regs[PS_REGNUM])
|
508 |
|
|
{
|
509 |
|
|
write_register (PS_REGNUM,
|
510 |
|
|
read_memory_integer (frame->saved_regs[PS_REGNUM], 4));
|
511 |
|
|
}
|
512 |
|
|
write_register (FP_REGNUM, read_memory_integer (fp, 4));
|
513 |
|
|
write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
|
514 |
|
|
write_register (SP_REGNUM, fp + 8);
|
515 |
|
|
flush_cached_frames ();
|
516 |
|
|
}
|
517 |
|
|
|
518 |
|
|
|
519 |
|
|
/* Given an ip value corresponding to the start of a function,
|
520 |
|
|
return the ip of the first instruction after the function
|
521 |
|
|
prologue. This is the generic m68k support. Machines which
|
522 |
|
|
require something different can override the SKIP_PROLOGUE
|
523 |
|
|
macro to point elsewhere.
|
524 |
|
|
|
525 |
|
|
Some instructions which typically may appear in a function
|
526 |
|
|
prologue include:
|
527 |
|
|
|
528 |
|
|
A link instruction, word form:
|
529 |
|
|
|
530 |
|
|
link.w %a6,&0 4e56 XXXX
|
531 |
|
|
|
532 |
|
|
A link instruction, long form:
|
533 |
|
|
|
534 |
|
|
link.l %fp,&F%1 480e XXXX XXXX
|
535 |
|
|
|
536 |
|
|
A movm instruction to preserve integer regs:
|
537 |
|
|
|
538 |
|
|
movm.l &M%1,(4,%sp) 48ef XXXX XXXX
|
539 |
|
|
|
540 |
|
|
A fmovm instruction to preserve float regs:
|
541 |
|
|
|
542 |
|
|
fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX
|
543 |
|
|
|
544 |
|
|
Some profiling setup code (FIXME, not recognized yet):
|
545 |
|
|
|
546 |
|
|
lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX
|
547 |
|
|
bsr _mcount 61ff XXXX XXXX
|
548 |
|
|
|
549 |
|
|
*/
|
550 |
|
|
|
551 |
|
|
CORE_ADDR
|
552 |
|
|
m68k_skip_prologue (CORE_ADDR ip)
|
553 |
|
|
{
|
554 |
|
|
register CORE_ADDR limit;
|
555 |
|
|
struct symtab_and_line sal;
|
556 |
|
|
register int op;
|
557 |
|
|
|
558 |
|
|
/* Find out if there is a known limit for the extent of the prologue.
|
559 |
|
|
If so, ensure we don't go past it. If not, assume "infinity". */
|
560 |
|
|
|
561 |
|
|
sal = find_pc_line (ip, 0);
|
562 |
|
|
limit = (sal.end) ? sal.end : (CORE_ADDR) ~0;
|
563 |
|
|
|
564 |
|
|
while (ip < limit)
|
565 |
|
|
{
|
566 |
|
|
op = read_memory_integer (ip, 2);
|
567 |
|
|
op &= 0xFFFF;
|
568 |
|
|
|
569 |
|
|
if (op == P_LINKW_FP)
|
570 |
|
|
ip += 4; /* Skip link.w */
|
571 |
|
|
else if (op == P_PEA_FP)
|
572 |
|
|
ip += 2; /* Skip pea %fp */
|
573 |
|
|
else if (op == P_MOVL_SP_FP)
|
574 |
|
|
ip += 2; /* Skip move.l %sp, %fp */
|
575 |
|
|
else if (op == P_LINKL_FP)
|
576 |
|
|
ip += 6; /* Skip link.l */
|
577 |
|
|
else if (op == P_MOVML)
|
578 |
|
|
ip += 6; /* Skip movm.l */
|
579 |
|
|
else if (op == P_FMOVM)
|
580 |
|
|
ip += 10; /* Skip fmovm */
|
581 |
|
|
else
|
582 |
|
|
break; /* Found unknown code, bail out. */
|
583 |
|
|
}
|
584 |
|
|
return (ip);
|
585 |
|
|
}
|
586 |
|
|
|
587 |
|
|
/* Store the addresses of the saved registers of the frame described by
|
588 |
|
|
FRAME_INFO in its saved_regs field.
|
589 |
|
|
This includes special registers such as pc and fp saved in special
|
590 |
|
|
ways in the stack frame. sp is even more special:
|
591 |
|
|
the address we return for it IS the sp for the next frame. */
|
592 |
|
|
|
593 |
|
|
void
|
594 |
|
|
m68k_frame_init_saved_regs (struct frame_info *frame_info)
|
595 |
|
|
{
|
596 |
|
|
register int regnum;
|
597 |
|
|
register int regmask;
|
598 |
|
|
register CORE_ADDR next_addr;
|
599 |
|
|
register CORE_ADDR pc;
|
600 |
|
|
|
601 |
|
|
/* First possible address for a pc in a call dummy for this frame. */
|
602 |
|
|
CORE_ADDR possible_call_dummy_start =
|
603 |
|
|
(frame_info)->frame - 28 - FP_REGNUM * 4 - 4 - 8 * 12;
|
604 |
|
|
|
605 |
|
|
int nextinsn;
|
606 |
|
|
|
607 |
|
|
if (frame_info->saved_regs)
|
608 |
|
|
return;
|
609 |
|
|
|
610 |
|
|
frame_saved_regs_zalloc (frame_info);
|
611 |
|
|
|
612 |
|
|
memset (frame_info->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
|
613 |
|
|
|
614 |
|
|
if ((frame_info)->pc >= possible_call_dummy_start
|
615 |
|
|
&& (frame_info)->pc <= (frame_info)->frame)
|
616 |
|
|
{
|
617 |
|
|
|
618 |
|
|
/* It is a call dummy. We could just stop now, since we know
|
619 |
|
|
what the call dummy saves and where. But this code proceeds
|
620 |
|
|
to parse the "prologue" which is part of the call dummy.
|
621 |
|
|
This is needlessly complex and confusing. FIXME. */
|
622 |
|
|
|
623 |
|
|
next_addr = (frame_info)->frame;
|
624 |
|
|
pc = possible_call_dummy_start;
|
625 |
|
|
}
|
626 |
|
|
else
|
627 |
|
|
{
|
628 |
|
|
pc = get_pc_function_start ((frame_info)->pc);
|
629 |
|
|
|
630 |
|
|
nextinsn = read_memory_integer (pc, 2);
|
631 |
|
|
if (P_PEA_FP == nextinsn
|
632 |
|
|
&& P_MOVL_SP_FP == read_memory_integer (pc + 2, 2))
|
633 |
|
|
{
|
634 |
|
|
/* pea %fp
|
635 |
|
|
move.l %sp, %fp */
|
636 |
|
|
next_addr = frame_info->frame;
|
637 |
|
|
pc += 4;
|
638 |
|
|
}
|
639 |
|
|
else if (P_LINKL_FP == nextinsn)
|
640 |
|
|
/* link.l %fp */
|
641 |
|
|
/* Find the address above the saved
|
642 |
|
|
regs using the amount of storage from the link instruction. */
|
643 |
|
|
{
|
644 |
|
|
next_addr = (frame_info)->frame + read_memory_integer (pc + 2, 4);
|
645 |
|
|
pc += 6;
|
646 |
|
|
}
|
647 |
|
|
else if (P_LINKW_FP == nextinsn)
|
648 |
|
|
/* link.w %fp */
|
649 |
|
|
/* Find the address above the saved
|
650 |
|
|
regs using the amount of storage from the link instruction. */
|
651 |
|
|
{
|
652 |
|
|
next_addr = (frame_info)->frame + read_memory_integer (pc + 2, 2);
|
653 |
|
|
pc += 4;
|
654 |
|
|
}
|
655 |
|
|
else
|
656 |
|
|
goto lose;
|
657 |
|
|
|
658 |
|
|
/* If have an addal #-n, sp next, adjust next_addr. */
|
659 |
|
|
if ((0177777 & read_memory_integer (pc, 2)) == 0157774)
|
660 |
|
|
next_addr += read_memory_integer (pc += 2, 4), pc += 4;
|
661 |
|
|
}
|
662 |
|
|
|
663 |
|
|
for (;;)
|
664 |
|
|
{
|
665 |
|
|
nextinsn = 0xffff & read_memory_integer (pc, 2);
|
666 |
|
|
regmask = read_memory_integer (pc + 2, 2);
|
667 |
|
|
/* fmovemx to -(sp) */
|
668 |
|
|
if (0xf227 == nextinsn && (regmask & 0xff00) == 0xe000)
|
669 |
|
|
{
|
670 |
|
|
/* Regmask's low bit is for register fp7, the first pushed */
|
671 |
|
|
for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
|
672 |
|
|
if (regmask & 1)
|
673 |
|
|
frame_info->saved_regs[regnum] = (next_addr -= 12);
|
674 |
|
|
pc += 4;
|
675 |
|
|
}
|
676 |
|
|
/* fmovemx to (fp + displacement) */
|
677 |
|
|
else if (0171056 == nextinsn && (regmask & 0xff00) == 0xf000)
|
678 |
|
|
{
|
679 |
|
|
register CORE_ADDR addr;
|
680 |
|
|
|
681 |
|
|
addr = (frame_info)->frame + read_memory_integer (pc + 4, 2);
|
682 |
|
|
/* Regmask's low bit is for register fp7, the first pushed */
|
683 |
|
|
for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
|
684 |
|
|
if (regmask & 1)
|
685 |
|
|
{
|
686 |
|
|
frame_info->saved_regs[regnum] = addr;
|
687 |
|
|
addr += 12;
|
688 |
|
|
}
|
689 |
|
|
pc += 6;
|
690 |
|
|
}
|
691 |
|
|
/* moveml to (sp) */
|
692 |
|
|
else if (0044327 == nextinsn)
|
693 |
|
|
{
|
694 |
|
|
/* Regmask's low bit is for register 0, the first written */
|
695 |
|
|
for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
|
696 |
|
|
if (regmask & 1)
|
697 |
|
|
{
|
698 |
|
|
frame_info->saved_regs[regnum] = next_addr;
|
699 |
|
|
next_addr += 4;
|
700 |
|
|
}
|
701 |
|
|
pc += 4;
|
702 |
|
|
}
|
703 |
|
|
/* moveml to (fp + displacement) */
|
704 |
|
|
else if (0044356 == nextinsn)
|
705 |
|
|
{
|
706 |
|
|
register CORE_ADDR addr;
|
707 |
|
|
|
708 |
|
|
addr = (frame_info)->frame + read_memory_integer (pc + 4, 2);
|
709 |
|
|
/* Regmask's low bit is for register 0, the first written */
|
710 |
|
|
for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
|
711 |
|
|
if (regmask & 1)
|
712 |
|
|
{
|
713 |
|
|
frame_info->saved_regs[regnum] = addr;
|
714 |
|
|
addr += 4;
|
715 |
|
|
}
|
716 |
|
|
pc += 6;
|
717 |
|
|
}
|
718 |
|
|
/* moveml to -(sp) */
|
719 |
|
|
else if (0044347 == nextinsn)
|
720 |
|
|
{
|
721 |
|
|
/* Regmask's low bit is for register 15, the first pushed */
|
722 |
|
|
for (regnum = 16; --regnum >= 0; regmask >>= 1)
|
723 |
|
|
if (regmask & 1)
|
724 |
|
|
frame_info->saved_regs[regnum] = (next_addr -= 4);
|
725 |
|
|
pc += 4;
|
726 |
|
|
}
|
727 |
|
|
/* movl r,-(sp) */
|
728 |
|
|
else if (0x2f00 == (0xfff0 & nextinsn))
|
729 |
|
|
{
|
730 |
|
|
regnum = 0xf & nextinsn;
|
731 |
|
|
frame_info->saved_regs[regnum] = (next_addr -= 4);
|
732 |
|
|
pc += 2;
|
733 |
|
|
}
|
734 |
|
|
/* fmovemx to index of sp */
|
735 |
|
|
else if (0xf236 == nextinsn && (regmask & 0xff00) == 0xf000)
|
736 |
|
|
{
|
737 |
|
|
/* Regmask's low bit is for register fp0, the first written */
|
738 |
|
|
for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
|
739 |
|
|
if (regmask & 1)
|
740 |
|
|
{
|
741 |
|
|
frame_info->saved_regs[regnum] = next_addr;
|
742 |
|
|
next_addr += 12;
|
743 |
|
|
}
|
744 |
|
|
pc += 10;
|
745 |
|
|
}
|
746 |
|
|
/* clrw -(sp); movw ccr,-(sp) */
|
747 |
|
|
else if (0x4267 == nextinsn && 0x42e7 == regmask)
|
748 |
|
|
{
|
749 |
|
|
frame_info->saved_regs[PS_REGNUM] = (next_addr -= 4);
|
750 |
|
|
pc += 4;
|
751 |
|
|
}
|
752 |
|
|
else
|
753 |
|
|
break;
|
754 |
|
|
}
|
755 |
|
|
lose:;
|
756 |
|
|
frame_info->saved_regs[SP_REGNUM] = (frame_info)->frame + 8;
|
757 |
|
|
frame_info->saved_regs[FP_REGNUM] = (frame_info)->frame;
|
758 |
|
|
frame_info->saved_regs[PC_REGNUM] = (frame_info)->frame + 4;
|
759 |
|
|
#ifdef SIG_SP_FP_OFFSET
|
760 |
|
|
/* Adjust saved SP_REGNUM for fake _sigtramp frames. */
|
761 |
|
|
if (frame_info->signal_handler_caller && frame_info->next)
|
762 |
|
|
frame_info->saved_regs[SP_REGNUM] =
|
763 |
|
|
frame_info->next->frame + SIG_SP_FP_OFFSET;
|
764 |
|
|
#endif
|
765 |
|
|
}
|
766 |
|
|
|
767 |
|
|
|
768 |
|
|
#ifdef USE_PROC_FS /* Target dependent support for /proc */
|
769 |
|
|
|
770 |
|
|
#include <sys/procfs.h>
|
771 |
|
|
|
772 |
|
|
/* Prototypes for supply_gregset etc. */
|
773 |
|
|
#include "gregset.h"
|
774 |
|
|
|
775 |
|
|
/* The /proc interface divides the target machine's register set up into
|
776 |
|
|
two different sets, the general register set (gregset) and the floating
|
777 |
|
|
point register set (fpregset). For each set, there is an ioctl to get
|
778 |
|
|
the current register set and another ioctl to set the current values.
|
779 |
|
|
|
780 |
|
|
The actual structure passed through the ioctl interface is, of course,
|
781 |
|
|
naturally machine dependent, and is different for each set of registers.
|
782 |
|
|
For the m68k for example, the general register set is typically defined
|
783 |
|
|
by:
|
784 |
|
|
|
785 |
|
|
typedef int gregset_t[18];
|
786 |
|
|
|
787 |
|
|
#define R_D0 0
|
788 |
|
|
...
|
789 |
|
|
#define R_PS 17
|
790 |
|
|
|
791 |
|
|
and the floating point set by:
|
792 |
|
|
|
793 |
|
|
typedef struct fpregset {
|
794 |
|
|
int f_pcr;
|
795 |
|
|
int f_psr;
|
796 |
|
|
int f_fpiaddr;
|
797 |
|
|
int f_fpregs[8][3]; (8 regs, 96 bits each)
|
798 |
|
|
} fpregset_t;
|
799 |
|
|
|
800 |
|
|
These routines provide the packing and unpacking of gregset_t and
|
801 |
|
|
fpregset_t formatted data.
|
802 |
|
|
|
803 |
|
|
*/
|
804 |
|
|
|
805 |
|
|
/* Atari SVR4 has R_SR but not R_PS */
|
806 |
|
|
|
807 |
|
|
#if !defined (R_PS) && defined (R_SR)
|
808 |
|
|
#define R_PS R_SR
|
809 |
|
|
#endif
|
810 |
|
|
|
811 |
|
|
/* Given a pointer to a general register set in /proc format (gregset_t *),
|
812 |
|
|
unpack the register contents and supply them as gdb's idea of the current
|
813 |
|
|
register values. */
|
814 |
|
|
|
815 |
|
|
void
|
816 |
|
|
supply_gregset (gregset_t *gregsetp)
|
817 |
|
|
{
|
818 |
|
|
register int regi;
|
819 |
|
|
register greg_t *regp = (greg_t *) gregsetp;
|
820 |
|
|
|
821 |
|
|
for (regi = 0; regi < R_PC; regi++)
|
822 |
|
|
{
|
823 |
|
|
supply_register (regi, (char *) (regp + regi));
|
824 |
|
|
}
|
825 |
|
|
supply_register (PS_REGNUM, (char *) (regp + R_PS));
|
826 |
|
|
supply_register (PC_REGNUM, (char *) (regp + R_PC));
|
827 |
|
|
}
|
828 |
|
|
|
829 |
|
|
void
|
830 |
|
|
fill_gregset (gregset_t *gregsetp, int regno)
|
831 |
|
|
{
|
832 |
|
|
register int regi;
|
833 |
|
|
register greg_t *regp = (greg_t *) gregsetp;
|
834 |
|
|
|
835 |
|
|
for (regi = 0; regi < R_PC; regi++)
|
836 |
|
|
{
|
837 |
|
|
if ((regno == -1) || (regno == regi))
|
838 |
|
|
{
|
839 |
|
|
*(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];
|
840 |
|
|
}
|
841 |
|
|
}
|
842 |
|
|
if ((regno == -1) || (regno == PS_REGNUM))
|
843 |
|
|
{
|
844 |
|
|
*(regp + R_PS) = *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)];
|
845 |
|
|
}
|
846 |
|
|
if ((regno == -1) || (regno == PC_REGNUM))
|
847 |
|
|
{
|
848 |
|
|
*(regp + R_PC) = *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)];
|
849 |
|
|
}
|
850 |
|
|
}
|
851 |
|
|
|
852 |
|
|
#if defined (FP0_REGNUM)
|
853 |
|
|
|
854 |
|
|
/* Given a pointer to a floating point register set in /proc format
|
855 |
|
|
(fpregset_t *), unpack the register contents and supply them as gdb's
|
856 |
|
|
idea of the current floating point register values. */
|
857 |
|
|
|
858 |
|
|
void
|
859 |
|
|
supply_fpregset (fpregset_t *fpregsetp)
|
860 |
|
|
{
|
861 |
|
|
register int regi;
|
862 |
|
|
char *from;
|
863 |
|
|
|
864 |
|
|
for (regi = FP0_REGNUM; regi < E_FPC_REGNUM; regi++)
|
865 |
|
|
{
|
866 |
|
|
from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
|
867 |
|
|
supply_register (regi, from);
|
868 |
|
|
}
|
869 |
|
|
supply_register (E_FPC_REGNUM, (char *) &(fpregsetp->f_pcr));
|
870 |
|
|
supply_register (E_FPS_REGNUM, (char *) &(fpregsetp->f_psr));
|
871 |
|
|
supply_register (E_FPI_REGNUM, (char *) &(fpregsetp->f_fpiaddr));
|
872 |
|
|
}
|
873 |
|
|
|
874 |
|
|
/* Given a pointer to a floating point register set in /proc format
|
875 |
|
|
(fpregset_t *), update the register specified by REGNO from gdb's idea
|
876 |
|
|
of the current floating point register set. If REGNO is -1, update
|
877 |
|
|
them all. */
|
878 |
|
|
|
879 |
|
|
void
|
880 |
|
|
fill_fpregset (fpregset_t *fpregsetp, int regno)
|
881 |
|
|
{
|
882 |
|
|
int regi;
|
883 |
|
|
char *to;
|
884 |
|
|
char *from;
|
885 |
|
|
|
886 |
|
|
for (regi = FP0_REGNUM; regi < E_FPC_REGNUM; regi++)
|
887 |
|
|
{
|
888 |
|
|
if ((regno == -1) || (regno == regi))
|
889 |
|
|
{
|
890 |
|
|
from = (char *) ®isters[REGISTER_BYTE (regi)];
|
891 |
|
|
to = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
|
892 |
|
|
memcpy (to, from, REGISTER_RAW_SIZE (regi));
|
893 |
|
|
}
|
894 |
|
|
}
|
895 |
|
|
if ((regno == -1) || (regno == E_FPC_REGNUM))
|
896 |
|
|
{
|
897 |
|
|
fpregsetp->f_pcr = *(int *) ®isters[REGISTER_BYTE (E_FPC_REGNUM)];
|
898 |
|
|
}
|
899 |
|
|
if ((regno == -1) || (regno == E_FPS_REGNUM))
|
900 |
|
|
{
|
901 |
|
|
fpregsetp->f_psr = *(int *) ®isters[REGISTER_BYTE (E_FPS_REGNUM)];
|
902 |
|
|
}
|
903 |
|
|
if ((regno == -1) || (regno == E_FPI_REGNUM))
|
904 |
|
|
{
|
905 |
|
|
fpregsetp->f_fpiaddr = *(int *) ®isters[REGISTER_BYTE (E_FPI_REGNUM)];
|
906 |
|
|
}
|
907 |
|
|
}
|
908 |
|
|
|
909 |
|
|
#endif /* defined (FP0_REGNUM) */
|
910 |
|
|
|
911 |
|
|
#endif /* USE_PROC_FS */
|
912 |
|
|
|
913 |
|
|
/* Figure out where the longjmp will land. Slurp the args out of the stack.
|
914 |
|
|
We expect the first arg to be a pointer to the jmp_buf structure from which
|
915 |
|
|
we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
|
916 |
|
|
This routine returns true on success. */
|
917 |
|
|
|
918 |
|
|
/* NOTE: cagney/2000-11-08: For this function to be fully multi-arched
|
919 |
|
|
the macro's JB_PC and JB_ELEMENT_SIZE would need to be moved into
|
920 |
|
|
the ``struct gdbarch_tdep'' object and then set on a target ISA/ABI
|
921 |
|
|
dependant basis. */
|
922 |
|
|
|
923 |
|
|
int
|
924 |
|
|
m68k_get_longjmp_target (CORE_ADDR *pc)
|
925 |
|
|
{
|
926 |
|
|
#if defined (JB_PC) && defined (JB_ELEMENT_SIZE)
|
927 |
|
|
char *buf;
|
928 |
|
|
CORE_ADDR sp, jb_addr;
|
929 |
|
|
|
930 |
|
|
buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
|
931 |
|
|
sp = read_register (SP_REGNUM);
|
932 |
|
|
|
933 |
|
|
if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
|
934 |
|
|
buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
|
935 |
|
|
return 0;
|
936 |
|
|
|
937 |
|
|
jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
|
938 |
|
|
|
939 |
|
|
if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
|
940 |
|
|
TARGET_PTR_BIT / TARGET_CHAR_BIT))
|
941 |
|
|
return 0;
|
942 |
|
|
|
943 |
|
|
*pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
|
944 |
|
|
|
945 |
|
|
return 1;
|
946 |
|
|
#else
|
947 |
|
|
internal_error (__FILE__, __LINE__,
|
948 |
|
|
"m68k_get_longjmp_target: not implemented");
|
949 |
|
|
return 0;
|
950 |
|
|
#endif
|
951 |
|
|
}
|
952 |
|
|
|
953 |
|
|
/* Immediately after a function call, return the saved pc before the frame
|
954 |
|
|
is setup. For sun3's, we check for the common case of being inside of a
|
955 |
|
|
system call, and if so, we know that Sun pushes the call # on the stack
|
956 |
|
|
prior to doing the trap. */
|
957 |
|
|
|
958 |
|
|
CORE_ADDR
|
959 |
|
|
m68k_saved_pc_after_call (struct frame_info *frame)
|
960 |
|
|
{
|
961 |
|
|
#ifdef SYSCALL_TRAP
|
962 |
|
|
int op;
|
963 |
|
|
|
964 |
|
|
op = read_memory_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2);
|
965 |
|
|
|
966 |
|
|
if (op == SYSCALL_TRAP)
|
967 |
|
|
return read_memory_integer (read_register (SP_REGNUM) + 4, 4);
|
968 |
|
|
else
|
969 |
|
|
#endif /* SYSCALL_TRAP */
|
970 |
|
|
return read_memory_integer (read_register (SP_REGNUM), 4);
|
971 |
|
|
}
|
972 |
|
|
|
973 |
|
|
/* Function: m68k_gdbarch_init
|
974 |
|
|
Initializer function for the m68k gdbarch vector.
|
975 |
|
|
Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
|
976 |
|
|
|
977 |
|
|
static struct gdbarch *
|
978 |
|
|
m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
|
979 |
|
|
{
|
980 |
|
|
static LONGEST call_dummy_words[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7,
|
981 |
|
|
0x4eb93232, 0x3232dffc, 0x69696969,
|
982 |
|
|
(0x4e404e71 | (BPT_VECTOR << 16))
|
983 |
|
|
};
|
984 |
|
|
struct gdbarch_tdep *tdep = NULL;
|
985 |
|
|
struct gdbarch *gdbarch;
|
986 |
|
|
|
987 |
|
|
/* find a candidate among the list of pre-declared architectures. */
|
988 |
|
|
arches = gdbarch_list_lookup_by_info (arches, &info);
|
989 |
|
|
if (arches != NULL)
|
990 |
|
|
return (arches->gdbarch);
|
991 |
|
|
|
992 |
|
|
#if 0
|
993 |
|
|
tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
|
994 |
|
|
#endif
|
995 |
|
|
|
996 |
|
|
gdbarch = gdbarch_alloc (&info, 0);
|
997 |
|
|
|
998 |
|
|
set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext);
|
999 |
|
|
set_gdbarch_long_double_bit (gdbarch, 96);
|
1000 |
|
|
|
1001 |
|
|
set_gdbarch_function_start_offset (gdbarch, 0);
|
1002 |
|
|
|
1003 |
|
|
set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
|
1004 |
|
|
set_gdbarch_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call);
|
1005 |
|
|
set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
|
1006 |
|
|
|
1007 |
|
|
/* Stack grows down. */
|
1008 |
|
|
set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
|
1009 |
|
|
set_gdbarch_stack_align (gdbarch, m68k_stack_align);
|
1010 |
|
|
|
1011 |
|
|
|
1012 |
|
|
set_gdbarch_believe_pcc_promotion (gdbarch, 1);
|
1013 |
|
|
set_gdbarch_decr_pc_after_break (gdbarch, 2);
|
1014 |
|
|
|
1015 |
|
|
set_gdbarch_store_struct_return (gdbarch, m68k_store_struct_return);
|
1016 |
|
|
set_gdbarch_deprecated_extract_return_value (gdbarch,
|
1017 |
|
|
m68k_deprecated_extract_return_value);
|
1018 |
|
|
set_gdbarch_deprecated_store_return_value (gdbarch, m68k_store_return_value);
|
1019 |
|
|
|
1020 |
|
|
set_gdbarch_frame_chain (gdbarch, m68k_frame_chain);
|
1021 |
|
|
set_gdbarch_frame_chain_valid (gdbarch, generic_func_frame_chain_valid);
|
1022 |
|
|
set_gdbarch_frame_saved_pc (gdbarch, m68k_frame_saved_pc);
|
1023 |
|
|
set_gdbarch_frame_init_saved_regs (gdbarch, m68k_frame_init_saved_regs);
|
1024 |
|
|
set_gdbarch_frameless_function_invocation (gdbarch,
|
1025 |
|
|
m68k_frameless_function_invocation);
|
1026 |
|
|
/* OK to default this value to 'unknown'. */
|
1027 |
|
|
set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
|
1028 |
|
|
set_gdbarch_frame_args_skip (gdbarch, 8);
|
1029 |
|
|
set_gdbarch_frame_args_address (gdbarch, default_frame_address);
|
1030 |
|
|
set_gdbarch_frame_locals_address (gdbarch, default_frame_address);
|
1031 |
|
|
|
1032 |
|
|
set_gdbarch_register_raw_size (gdbarch, m68k_register_raw_size);
|
1033 |
|
|
set_gdbarch_register_virtual_size (gdbarch, m68k_register_virtual_size);
|
1034 |
|
|
set_gdbarch_max_register_raw_size (gdbarch, 12);
|
1035 |
|
|
set_gdbarch_max_register_virtual_size (gdbarch, 12);
|
1036 |
|
|
set_gdbarch_register_virtual_type (gdbarch, m68k_register_virtual_type);
|
1037 |
|
|
set_gdbarch_register_name (gdbarch, m68k_register_name);
|
1038 |
|
|
set_gdbarch_register_size (gdbarch, 4);
|
1039 |
|
|
set_gdbarch_register_byte (gdbarch, m68k_register_byte);
|
1040 |
|
|
set_gdbarch_num_regs (gdbarch, 29);
|
1041 |
|
|
set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
|
1042 |
|
|
set_gdbarch_register_bytes (gdbarch, (16 * 4 + 8 + 8 * 12 + 3 * 4));
|
1043 |
|
|
set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
|
1044 |
|
|
set_gdbarch_fp_regnum (gdbarch, E_FP_REGNUM);
|
1045 |
|
|
set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
|
1046 |
|
|
set_gdbarch_ps_regnum (gdbarch, E_PS_REGNUM);
|
1047 |
|
|
set_gdbarch_fp0_regnum (gdbarch, E_FP0_REGNUM);
|
1048 |
|
|
|
1049 |
|
|
set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
|
1050 |
|
|
set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
|
1051 |
|
|
set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
|
1052 |
|
|
set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 24);
|
1053 |
|
|
set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack);
|
1054 |
|
|
set_gdbarch_call_dummy_p (gdbarch, 1);
|
1055 |
|
|
set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
|
1056 |
|
|
set_gdbarch_call_dummy_length (gdbarch, 28);
|
1057 |
|
|
set_gdbarch_call_dummy_start_offset (gdbarch, 12);
|
1058 |
|
|
|
1059 |
|
|
set_gdbarch_call_dummy_words (gdbarch, call_dummy_words);
|
1060 |
|
|
set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (call_dummy_words));
|
1061 |
|
|
set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
|
1062 |
|
|
set_gdbarch_fix_call_dummy (gdbarch, m68k_fix_call_dummy);
|
1063 |
|
|
set_gdbarch_push_dummy_frame (gdbarch, m68k_push_dummy_frame);
|
1064 |
|
|
set_gdbarch_pop_frame (gdbarch, m68k_pop_frame);
|
1065 |
|
|
|
1066 |
|
|
return gdbarch;
|
1067 |
|
|
}
|
1068 |
|
|
|
1069 |
|
|
|
1070 |
|
|
static void
|
1071 |
|
|
m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
|
1072 |
|
|
{
|
1073 |
|
|
|
1074 |
|
|
}
|
1075 |
|
|
|
1076 |
|
|
void
|
1077 |
|
|
_initialize_m68k_tdep (void)
|
1078 |
|
|
{
|
1079 |
|
|
gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
|
1080 |
|
|
tm_print_insn = print_insn_m68k;
|
1081 |
|
|
}
|