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