Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / m68k-tdep.c
1 /* Target-dependent code for the Motorola 68000 series.
2
3 Copyright (C) 1990-2021 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 3 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, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "dwarf2/frame.h"
22 #include "frame.h"
23 #include "frame-base.h"
24 #include "frame-unwind.h"
25 #include "gdbtypes.h"
26 #include "symtab.h"
27 #include "gdbcore.h"
28 #include "value.h"
29 #include "inferior.h"
30 #include "regcache.h"
31 #include "arch-utils.h"
32 #include "osabi.h"
33 #include "dis-asm.h"
34 #include "target-descriptions.h"
35 #include "floatformat.h"
36 #include "target-float.h"
37 #include "elf-bfd.h"
38 #include "elf/m68k.h"
39
40 #include "m68k-tdep.h"
41 \f
42
43 #define P_LINKL_FP 0x480e
44 #define P_LINKW_FP 0x4e56
45 #define P_PEA_FP 0x4856
46 #define P_MOVEAL_SP_FP 0x2c4f
47 #define P_ADDAW_SP 0xdefc
48 #define P_ADDAL_SP 0xdffc
49 #define P_SUBQW_SP 0x514f
50 #define P_SUBQL_SP 0x518f
51 #define P_LEA_SP_SP 0x4fef
52 #define P_LEA_PC_A5 0x4bfb0170
53 #define P_FMOVEMX_SP 0xf227
54 #define P_MOVEL_SP 0x2f00
55 #define P_MOVEML_SP 0x48e7
56
57 /* Offset from SP to first arg on stack at first instruction of a function. */
58 #define SP_ARG0 (1 * 4)
59
60 #if !defined (BPT_VECTOR)
61 #define BPT_VECTOR 0xf
62 #endif
63
64 constexpr gdb_byte m68k_break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
65
66 typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
67 \f
68
69 /* Construct types for ISA-specific registers. */
70 static struct type *
71 m68k_ps_type (struct gdbarch *gdbarch)
72 {
73 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
74
75 if (!tdep->m68k_ps_type)
76 {
77 struct type *type;
78
79 type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 32);
80 append_flags_type_flag (type, 0, "C");
81 append_flags_type_flag (type, 1, "V");
82 append_flags_type_flag (type, 2, "Z");
83 append_flags_type_flag (type, 3, "N");
84 append_flags_type_flag (type, 4, "X");
85 append_flags_type_flag (type, 8, "I0");
86 append_flags_type_flag (type, 9, "I1");
87 append_flags_type_flag (type, 10, "I2");
88 append_flags_type_flag (type, 12, "M");
89 append_flags_type_flag (type, 13, "S");
90 append_flags_type_flag (type, 14, "T0");
91 append_flags_type_flag (type, 15, "T1");
92
93 tdep->m68k_ps_type = type;
94 }
95
96 return tdep->m68k_ps_type;
97 }
98
99 static struct type *
100 m68881_ext_type (struct gdbarch *gdbarch)
101 {
102 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
103
104 if (!tdep->m68881_ext_type)
105 tdep->m68881_ext_type
106 = arch_float_type (gdbarch, -1, "builtin_type_m68881_ext",
107 floatformats_m68881_ext);
108
109 return tdep->m68881_ext_type;
110 }
111
112 /* Return the GDB type object for the "standard" data type of data in
113 register N. This should be int for D0-D7, SR, FPCONTROL and
114 FPSTATUS, long double for FP0-FP7, and void pointer for all others
115 (A0-A7, PC, FPIADDR). Note, for registers which contain
116 addresses return pointer to void, not pointer to char, because we
117 don't want to attempt to print the string after printing the
118 address. */
119
120 static struct type *
121 m68k_register_type (struct gdbarch *gdbarch, int regnum)
122 {
123 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
124
125 if (tdep->fpregs_present)
126 {
127 if (regnum >= gdbarch_fp0_regnum (gdbarch)
128 && regnum <= gdbarch_fp0_regnum (gdbarch) + 7)
129 {
130 if (tdep->flavour == m68k_coldfire_flavour)
131 return builtin_type (gdbarch)->builtin_double;
132 else
133 return m68881_ext_type (gdbarch);
134 }
135
136 if (regnum == M68K_FPI_REGNUM)
137 return builtin_type (gdbarch)->builtin_func_ptr;
138
139 if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM)
140 return builtin_type (gdbarch)->builtin_int32;
141 }
142 else
143 {
144 if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM)
145 return builtin_type (gdbarch)->builtin_int0;
146 }
147
148 if (regnum == gdbarch_pc_regnum (gdbarch))
149 return builtin_type (gdbarch)->builtin_func_ptr;
150
151 if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
152 return builtin_type (gdbarch)->builtin_data_ptr;
153
154 if (regnum == M68K_PS_REGNUM)
155 return m68k_ps_type (gdbarch);
156
157 return builtin_type (gdbarch)->builtin_int32;
158 }
159
160 static const char * const m68k_register_names[] = {
161 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
162 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
163 "ps", "pc",
164 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
165 "fpcontrol", "fpstatus", "fpiaddr"
166 };
167
168 /* Function: m68k_register_name
169 Returns the name of the standard m68k register regnum. */
170
171 static const char *
172 m68k_register_name (struct gdbarch *gdbarch, int regnum)
173 {
174 if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
175 internal_error (__FILE__, __LINE__,
176 _("m68k_register_name: illegal register number %d"),
177 regnum);
178 else if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
179 && gdbarch_tdep (gdbarch)->fpregs_present == 0)
180 return "";
181 else
182 return m68k_register_names[regnum];
183 }
184 \f
185 /* Return nonzero if a value of type TYPE stored in register REGNUM
186 needs any special handling. */
187
188 static int
189 m68k_convert_register_p (struct gdbarch *gdbarch,
190 int regnum, struct type *type)
191 {
192 if (!gdbarch_tdep (gdbarch)->fpregs_present)
193 return 0;
194 return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
195 /* We only support floating-point values. */
196 && type->code () == TYPE_CODE_FLT
197 && type != register_type (gdbarch, M68K_FP0_REGNUM));
198 }
199
200 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
201 return its contents in TO. */
202
203 static int
204 m68k_register_to_value (struct frame_info *frame, int regnum,
205 struct type *type, gdb_byte *to,
206 int *optimizedp, int *unavailablep)
207 {
208 struct gdbarch *gdbarch = get_frame_arch (frame);
209 gdb_byte from[M68K_MAX_REGISTER_SIZE];
210 struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
211
212 gdb_assert (type->code () == TYPE_CODE_FLT);
213
214 /* Convert to TYPE. */
215 if (!get_frame_register_bytes (frame, regnum, 0,
216 gdb::make_array_view (from,
217 register_size (gdbarch,
218 regnum)),
219 optimizedp, unavailablep))
220 return 0;
221
222 target_float_convert (from, fpreg_type, to, type);
223 *optimizedp = *unavailablep = 0;
224 return 1;
225 }
226
227 /* Write the contents FROM of a value of type TYPE into register
228 REGNUM in frame FRAME. */
229
230 static void
231 m68k_value_to_register (struct frame_info *frame, int regnum,
232 struct type *type, const gdb_byte *from)
233 {
234 gdb_byte to[M68K_MAX_REGISTER_SIZE];
235 struct type *fpreg_type = register_type (get_frame_arch (frame),
236 M68K_FP0_REGNUM);
237
238 /* We only support floating-point values. */
239 if (type->code () != TYPE_CODE_FLT)
240 {
241 warning (_("Cannot convert non-floating-point type "
242 "to floating-point register value."));
243 return;
244 }
245
246 /* Convert from TYPE. */
247 target_float_convert (from, type, to, fpreg_type);
248 put_frame_register (frame, regnum, to);
249 }
250
251 \f
252 /* There is a fair number of calling conventions that are in somewhat
253 wide use. The 68000/08/10 don't support an FPU, not even as a
254 coprocessor. All function return values are stored in %d0/%d1.
255 Structures are returned in a static buffer, a pointer to which is
256 returned in %d0. This means that functions returning a structure
257 are not re-entrant. To avoid this problem some systems use a
258 convention where the caller passes a pointer to a buffer in %a1
259 where the return values is to be stored. This convention is the
260 default, and is implemented in the function m68k_return_value.
261
262 The 68020/030/040/060 do support an FPU, either as a coprocessor
263 (68881/2) or built-in (68040/68060). That's why System V release 4
264 (SVR4) introduces a new calling convention specified by the SVR4
265 psABI. Integer values are returned in %d0/%d1, pointer return
266 values in %a0 and floating values in %fp0. When calling functions
267 returning a structure the caller should pass a pointer to a buffer
268 for the return value in %a0. This convention is implemented in the
269 function m68k_svr4_return_value, and by appropriately setting the
270 struct_value_regnum member of `struct gdbarch_tdep'.
271
272 GNU/Linux returns values in the same way as SVR4 does, but uses %a1
273 for passing the structure return value buffer.
274
275 GCC can also generate code where small structures are returned in
276 %d0/%d1 instead of in memory by using -freg-struct-return. This is
277 the default on NetBSD a.out, OpenBSD and GNU/Linux and several
278 embedded systems. This convention is implemented by setting the
279 struct_return member of `struct gdbarch_tdep' to reg_struct_return.
280
281 GCC also has an "embedded" ABI. This works like the SVR4 ABI,
282 except that pointers are returned in %D0. This is implemented by
283 setting the pointer_result_regnum member of `struct gdbarch_tdep'
284 as appropriate. */
285
286 /* Read a function return value of TYPE from REGCACHE, and copy that
287 into VALBUF. */
288
289 static void
290 m68k_extract_return_value (struct type *type, struct regcache *regcache,
291 gdb_byte *valbuf)
292 {
293 int len = TYPE_LENGTH (type);
294 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
295
296 if (type->code () == TYPE_CODE_PTR && len == 4)
297 {
298 struct gdbarch *gdbarch = regcache->arch ();
299 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
300 regcache->raw_read (tdep->pointer_result_regnum, valbuf);
301 }
302 else if (len <= 4)
303 {
304 regcache->raw_read (M68K_D0_REGNUM, buf);
305 memcpy (valbuf, buf + (4 - len), len);
306 }
307 else if (len <= 8)
308 {
309 regcache->raw_read (M68K_D0_REGNUM, buf);
310 memcpy (valbuf, buf + (8 - len), len - 4);
311 regcache->raw_read (M68K_D1_REGNUM, valbuf + (len - 4));
312 }
313 else
314 internal_error (__FILE__, __LINE__,
315 _("Cannot extract return value of %d bytes long."), len);
316 }
317
318 static void
319 m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
320 gdb_byte *valbuf)
321 {
322 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
323 struct gdbarch *gdbarch = regcache->arch ();
324 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
325
326 if (tdep->float_return && type->code () == TYPE_CODE_FLT)
327 {
328 struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
329 regcache->raw_read (M68K_FP0_REGNUM, buf);
330 target_float_convert (buf, fpreg_type, valbuf, type);
331 }
332 else
333 m68k_extract_return_value (type, regcache, valbuf);
334 }
335
336 /* Write a function return value of TYPE from VALBUF into REGCACHE. */
337
338 static void
339 m68k_store_return_value (struct type *type, struct regcache *regcache,
340 const gdb_byte *valbuf)
341 {
342 int len = TYPE_LENGTH (type);
343
344 if (type->code () == TYPE_CODE_PTR && len == 4)
345 {
346 struct gdbarch *gdbarch = regcache->arch ();
347 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
348 regcache->raw_write (tdep->pointer_result_regnum, valbuf);
349 /* gdb historically also set D0 in the SVR4 case. */
350 if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
351 regcache->raw_write (M68K_D0_REGNUM, valbuf);
352 }
353 else if (len <= 4)
354 regcache->raw_write_part (M68K_D0_REGNUM, 4 - len, len, valbuf);
355 else if (len <= 8)
356 {
357 regcache->raw_write_part (M68K_D0_REGNUM, 8 - len, len - 4, valbuf);
358 regcache->raw_write (M68K_D1_REGNUM, valbuf + (len - 4));
359 }
360 else
361 internal_error (__FILE__, __LINE__,
362 _("Cannot store return value of %d bytes long."), len);
363 }
364
365 static void
366 m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
367 const gdb_byte *valbuf)
368 {
369 struct gdbarch *gdbarch = regcache->arch ();
370 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
371
372 if (tdep->float_return && type->code () == TYPE_CODE_FLT)
373 {
374 struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
375 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
376 target_float_convert (valbuf, type, buf, fpreg_type);
377 regcache->raw_write (M68K_FP0_REGNUM, buf);
378 }
379 else
380 m68k_store_return_value (type, regcache, valbuf);
381 }
382
383 /* Return non-zero if TYPE, which is assumed to be a structure, union or
384 complex type, should be returned in registers for architecture
385 GDBARCH. */
386
387 static int
388 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
389 {
390 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
391 enum type_code code = type->code ();
392 int len = TYPE_LENGTH (type);
393
394 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
395 || code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY);
396
397 if (tdep->struct_return == pcc_struct_return)
398 return 0;
399
400 const bool is_vector = code == TYPE_CODE_ARRAY && type->is_vector ();
401
402 if (is_vector
403 && check_typedef (TYPE_TARGET_TYPE (type))->code () == TYPE_CODE_FLT)
404 return 0;
405
406 /* According to m68k_return_in_memory in the m68k GCC back-end,
407 strange things happen for small aggregate types. Aggregate types
408 with only one component are always returned like the type of the
409 component. Aggregate types whose size is 2, 4, or 8 are returned
410 in registers if their natural alignment is at least 16 bits.
411
412 We reject vectors here, as experimentally this gives the correct
413 answer. */
414 if (!is_vector && (len == 2 || len == 4 || len == 8))
415 return type_align (type) >= 2;
416
417 return (len == 1 || len == 2 || len == 4 || len == 8);
418 }
419
420 /* Determine, for architecture GDBARCH, how a return value of TYPE
421 should be returned. If it is supposed to be returned in registers,
422 and READBUF is non-zero, read the appropriate value from REGCACHE,
423 and copy it into READBUF. If WRITEBUF is non-zero, write the value
424 from WRITEBUF into REGCACHE. */
425
426 static enum return_value_convention
427 m68k_return_value (struct gdbarch *gdbarch, struct value *function,
428 struct type *type, struct regcache *regcache,
429 gdb_byte *readbuf, const gdb_byte *writebuf)
430 {
431 enum type_code code = type->code ();
432
433 /* GCC returns a `long double' in memory too. */
434 if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
435 || code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
436 && !m68k_reg_struct_return_p (gdbarch, type))
437 || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12))
438 {
439 /* The default on m68k is to return structures in static memory.
440 Consequently a function must return the address where we can
441 find the return value. */
442
443 if (readbuf)
444 {
445 ULONGEST addr;
446
447 regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
448 read_memory (addr, readbuf, TYPE_LENGTH (type));
449 }
450
451 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
452 }
453
454 if (readbuf)
455 m68k_extract_return_value (type, regcache, readbuf);
456 if (writebuf)
457 m68k_store_return_value (type, regcache, writebuf);
458
459 return RETURN_VALUE_REGISTER_CONVENTION;
460 }
461
462 static enum return_value_convention
463 m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
464 struct type *type, struct regcache *regcache,
465 gdb_byte *readbuf, const gdb_byte *writebuf)
466 {
467 enum type_code code = type->code ();
468
469 /* Aggregates with a single member are always returned like their
470 sole element. */
471 if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
472 && type->num_fields () == 1)
473 {
474 type = check_typedef (type->field (0).type ());
475 return m68k_svr4_return_value (gdbarch, function, type, regcache,
476 readbuf, writebuf);
477 }
478
479 if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
480 || code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
481 && !m68k_reg_struct_return_p (gdbarch, type))
482 /* GCC may return a `long double' in memory too. */
483 || (!gdbarch_tdep (gdbarch)->float_return
484 && code == TYPE_CODE_FLT
485 && TYPE_LENGTH (type) == 12))
486 {
487 /* The System V ABI says that:
488
489 "A function returning a structure or union also sets %a0 to
490 the value it finds in %a0. Thus when the caller receives
491 control again, the address of the returned object resides in
492 register %a0."
493
494 So the ABI guarantees that we can always find the return
495 value just after the function has returned.
496
497 However, GCC also implements the "embedded" ABI. That ABI
498 does not preserve %a0 across calls, but does write the value
499 back to %d0. */
500
501 if (readbuf)
502 {
503 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
504 ULONGEST addr;
505
506 regcache_raw_read_unsigned (regcache, tdep->pointer_result_regnum,
507 &addr);
508 read_memory (addr, readbuf, TYPE_LENGTH (type));
509 }
510
511 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
512 }
513
514 if (readbuf)
515 m68k_svr4_extract_return_value (type, regcache, readbuf);
516 if (writebuf)
517 m68k_svr4_store_return_value (type, regcache, writebuf);
518
519 return RETURN_VALUE_REGISTER_CONVENTION;
520 }
521 \f
522
523 /* Always align the frame to a 4-byte boundary. This is required on
524 coldfire and harmless on the rest. */
525
526 static CORE_ADDR
527 m68k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
528 {
529 /* Align the stack to four bytes. */
530 return sp & ~3;
531 }
532
533 static CORE_ADDR
534 m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
535 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
536 struct value **args, CORE_ADDR sp,
537 function_call_return_method return_method,
538 CORE_ADDR struct_addr)
539 {
540 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
541 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
542 gdb_byte buf[4];
543 int i;
544
545 /* Push arguments in reverse order. */
546 for (i = nargs - 1; i >= 0; i--)
547 {
548 struct type *value_type = value_enclosing_type (args[i]);
549 int len = TYPE_LENGTH (value_type);
550 int container_len = (len + 3) & ~3;
551 int offset;
552
553 /* Non-scalars bigger than 4 bytes are left aligned, others are
554 right aligned. */
555 if ((value_type->code () == TYPE_CODE_STRUCT
556 || value_type->code () == TYPE_CODE_UNION
557 || value_type->code () == TYPE_CODE_ARRAY)
558 && len > 4)
559 offset = 0;
560 else
561 offset = container_len - len;
562 sp -= container_len;
563 write_memory (sp + offset, value_contents_all (args[i]), len);
564 }
565
566 /* Store struct value address. */
567 if (return_method == return_method_struct)
568 {
569 store_unsigned_integer (buf, 4, byte_order, struct_addr);
570 regcache->cooked_write (tdep->struct_value_regnum, buf);
571 }
572
573 /* Store return address. */
574 sp -= 4;
575 store_unsigned_integer (buf, 4, byte_order, bp_addr);
576 write_memory (sp, buf, 4);
577
578 /* Finally, update the stack pointer... */
579 store_unsigned_integer (buf, 4, byte_order, sp);
580 regcache->cooked_write (M68K_SP_REGNUM, buf);
581
582 /* ...and fake a frame pointer. */
583 regcache->cooked_write (M68K_FP_REGNUM, buf);
584
585 /* DWARF2/GCC uses the stack address *before* the function call as a
586 frame's CFA. */
587 return sp + 8;
588 }
589
590 /* Convert a dwarf or dwarf2 regnumber to a GDB regnum. */
591
592 static int
593 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
594 {
595 if (num < 8)
596 /* d0..7 */
597 return (num - 0) + M68K_D0_REGNUM;
598 else if (num < 16)
599 /* a0..7 */
600 return (num - 8) + M68K_A0_REGNUM;
601 else if (num < 24 && gdbarch_tdep (gdbarch)->fpregs_present)
602 /* fp0..7 */
603 return (num - 16) + M68K_FP0_REGNUM;
604 else if (num == 25)
605 /* pc */
606 return M68K_PC_REGNUM;
607 else
608 return -1;
609 }
610
611 \f
612 struct m68k_frame_cache
613 {
614 /* Base address. */
615 CORE_ADDR base;
616 CORE_ADDR sp_offset;
617 CORE_ADDR pc;
618
619 /* Saved registers. */
620 CORE_ADDR saved_regs[M68K_NUM_REGS];
621 CORE_ADDR saved_sp;
622
623 /* Stack space reserved for local variables. */
624 long locals;
625 };
626
627 /* Allocate and initialize a frame cache. */
628
629 static struct m68k_frame_cache *
630 m68k_alloc_frame_cache (void)
631 {
632 struct m68k_frame_cache *cache;
633 int i;
634
635 cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
636
637 /* Base address. */
638 cache->base = 0;
639 cache->sp_offset = -4;
640 cache->pc = 0;
641
642 /* Saved registers. We initialize these to -1 since zero is a valid
643 offset (that's where %fp is supposed to be stored). */
644 for (i = 0; i < M68K_NUM_REGS; i++)
645 cache->saved_regs[i] = -1;
646
647 /* Frameless until proven otherwise. */
648 cache->locals = -1;
649
650 return cache;
651 }
652
653 /* Check whether PC points at a code that sets up a new stack frame.
654 If so, it updates CACHE and returns the address of the first
655 instruction after the sequence that sets removes the "hidden"
656 argument from the stack or CURRENT_PC, whichever is smaller.
657 Otherwise, return PC. */
658
659 static CORE_ADDR
660 m68k_analyze_frame_setup (struct gdbarch *gdbarch,
661 CORE_ADDR pc, CORE_ADDR current_pc,
662 struct m68k_frame_cache *cache)
663 {
664 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
665 int op;
666
667 if (pc >= current_pc)
668 return current_pc;
669
670 op = read_memory_unsigned_integer (pc, 2, byte_order);
671
672 if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
673 {
674 cache->saved_regs[M68K_FP_REGNUM] = 0;
675 cache->sp_offset += 4;
676 if (op == P_LINKW_FP)
677 {
678 /* link.w %fp, #-N */
679 /* link.w %fp, #0; adda.l #-N, %sp */
680 cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
681
682 if (pc + 4 < current_pc && cache->locals == 0)
683 {
684 op = read_memory_unsigned_integer (pc + 4, 2, byte_order);
685 if (op == P_ADDAL_SP)
686 {
687 cache->locals = read_memory_integer (pc + 6, 4, byte_order);
688 return pc + 10;
689 }
690 }
691
692 return pc + 4;
693 }
694 else if (op == P_LINKL_FP)
695 {
696 /* link.l %fp, #-N */
697 cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
698 return pc + 6;
699 }
700 else
701 {
702 /* pea (%fp); movea.l %sp, %fp */
703 cache->locals = 0;
704
705 if (pc + 2 < current_pc)
706 {
707 op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
708
709 if (op == P_MOVEAL_SP_FP)
710 {
711 /* move.l %sp, %fp */
712 return pc + 4;
713 }
714 }
715
716 return pc + 2;
717 }
718 }
719 else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
720 {
721 /* subq.[wl] #N,%sp */
722 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
723 cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
724 if (pc + 2 < current_pc)
725 {
726 op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
727 if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
728 {
729 cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
730 return pc + 4;
731 }
732 }
733 return pc + 2;
734 }
735 else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
736 {
737 /* adda.w #-N,%sp */
738 /* lea (-N,%sp),%sp */
739 cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
740 return pc + 4;
741 }
742 else if (op == P_ADDAL_SP)
743 {
744 /* adda.l #-N,%sp */
745 cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
746 return pc + 6;
747 }
748
749 return pc;
750 }
751
752 /* Check whether PC points at code that saves registers on the stack.
753 If so, it updates CACHE and returns the address of the first
754 instruction after the register saves or CURRENT_PC, whichever is
755 smaller. Otherwise, return PC. */
756
757 static CORE_ADDR
758 m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
759 CORE_ADDR current_pc,
760 struct m68k_frame_cache *cache)
761 {
762 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
763
764 if (cache->locals >= 0)
765 {
766 CORE_ADDR offset;
767 int op;
768 int i, mask, regno;
769
770 offset = -4 - cache->locals;
771 while (pc < current_pc)
772 {
773 op = read_memory_unsigned_integer (pc, 2, byte_order);
774 if (op == P_FMOVEMX_SP
775 && gdbarch_tdep (gdbarch)->fpregs_present)
776 {
777 /* fmovem.x REGS,-(%sp) */
778 op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
779 if ((op & 0xff00) == 0xe000)
780 {
781 mask = op & 0xff;
782 for (i = 0; i < 16; i++, mask >>= 1)
783 {
784 if (mask & 1)
785 {
786 cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
787 offset -= 12;
788 }
789 }
790 pc += 4;
791 }
792 else
793 break;
794 }
795 else if ((op & 0177760) == P_MOVEL_SP)
796 {
797 /* move.l %R,-(%sp) */
798 regno = op & 017;
799 cache->saved_regs[regno] = offset;
800 offset -= 4;
801 pc += 2;
802 }
803 else if (op == P_MOVEML_SP)
804 {
805 /* movem.l REGS,-(%sp) */
806 mask = read_memory_unsigned_integer (pc + 2, 2, byte_order);
807 for (i = 0; i < 16; i++, mask >>= 1)
808 {
809 if (mask & 1)
810 {
811 cache->saved_regs[15 - i] = offset;
812 offset -= 4;
813 }
814 }
815 pc += 4;
816 }
817 else
818 break;
819 }
820 }
821
822 return pc;
823 }
824
825
826 /* Do a full analysis of the prologue at PC and update CACHE
827 accordingly. Bail out early if CURRENT_PC is reached. Return the
828 address where the analysis stopped.
829
830 We handle all cases that can be generated by gcc.
831
832 For allocating a stack frame:
833
834 link.w %a6,#-N
835 link.l %a6,#-N
836 pea (%fp); move.l %sp,%fp
837 link.w %a6,#0; add.l #-N,%sp
838 subq.l #N,%sp
839 subq.w #N,%sp
840 subq.w #8,%sp; subq.w #N-8,%sp
841 add.w #-N,%sp
842 lea (-N,%sp),%sp
843 add.l #-N,%sp
844
845 For saving registers:
846
847 fmovem.x REGS,-(%sp)
848 move.l R1,-(%sp)
849 move.l R1,-(%sp); move.l R2,-(%sp)
850 movem.l REGS,-(%sp)
851
852 For setting up the PIC register:
853
854 lea (%pc,N),%a5
855
856 */
857
858 static CORE_ADDR
859 m68k_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
860 CORE_ADDR current_pc, struct m68k_frame_cache *cache)
861 {
862 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
863 unsigned int op;
864
865 pc = m68k_analyze_frame_setup (gdbarch, pc, current_pc, cache);
866 pc = m68k_analyze_register_saves (gdbarch, pc, current_pc, cache);
867 if (pc >= current_pc)
868 return current_pc;
869
870 /* Check for GOT setup. */
871 op = read_memory_unsigned_integer (pc, 4, byte_order);
872 if (op == P_LEA_PC_A5)
873 {
874 /* lea (%pc,N),%a5 */
875 return pc + 8;
876 }
877
878 return pc;
879 }
880
881 /* Return PC of first real instruction. */
882
883 static CORE_ADDR
884 m68k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
885 {
886 struct m68k_frame_cache cache;
887 CORE_ADDR pc;
888
889 cache.locals = -1;
890 pc = m68k_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache);
891 if (cache.locals < 0)
892 return start_pc;
893 return pc;
894 }
895
896 static CORE_ADDR
897 m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
898 {
899 gdb_byte buf[8];
900
901 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
902 return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
903 }
904 \f
905 /* Normal frames. */
906
907 static struct m68k_frame_cache *
908 m68k_frame_cache (struct frame_info *this_frame, void **this_cache)
909 {
910 struct gdbarch *gdbarch = get_frame_arch (this_frame);
911 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
912 struct m68k_frame_cache *cache;
913 gdb_byte buf[4];
914 int i;
915
916 if (*this_cache)
917 return (struct m68k_frame_cache *) *this_cache;
918
919 cache = m68k_alloc_frame_cache ();
920 *this_cache = cache;
921
922 /* In principle, for normal frames, %fp holds the frame pointer,
923 which holds the base address for the current stack frame.
924 However, for functions that don't need it, the frame pointer is
925 optional. For these "frameless" functions the frame pointer is
926 actually the frame pointer of the calling frame. Signal
927 trampolines are just a special case of a "frameless" function.
928 They (usually) share their frame pointer with the frame that was
929 in progress when the signal occurred. */
930
931 get_frame_register (this_frame, M68K_FP_REGNUM, buf);
932 cache->base = extract_unsigned_integer (buf, 4, byte_order);
933 if (cache->base == 0)
934 return cache;
935
936 /* For normal frames, %pc is stored at 4(%fp). */
937 cache->saved_regs[M68K_PC_REGNUM] = 4;
938
939 cache->pc = get_frame_func (this_frame);
940 if (cache->pc != 0)
941 m68k_analyze_prologue (get_frame_arch (this_frame), cache->pc,
942 get_frame_pc (this_frame), cache);
943
944 if (cache->locals < 0)
945 {
946 /* We didn't find a valid frame, which means that CACHE->base
947 currently holds the frame pointer for our calling frame. If
948 we're at the start of a function, or somewhere half-way its
949 prologue, the function's frame probably hasn't been fully
950 setup yet. Try to reconstruct the base address for the stack
951 frame by looking at the stack pointer. For truly "frameless"
952 functions this might work too. */
953
954 get_frame_register (this_frame, M68K_SP_REGNUM, buf);
955 cache->base = extract_unsigned_integer (buf, 4, byte_order)
956 + cache->sp_offset;
957 }
958
959 /* Now that we have the base address for the stack frame we can
960 calculate the value of %sp in the calling frame. */
961 cache->saved_sp = cache->base + 8;
962
963 /* Adjust all the saved registers such that they contain addresses
964 instead of offsets. */
965 for (i = 0; i < M68K_NUM_REGS; i++)
966 if (cache->saved_regs[i] != -1)
967 cache->saved_regs[i] += cache->base;
968
969 return cache;
970 }
971
972 static void
973 m68k_frame_this_id (struct frame_info *this_frame, void **this_cache,
974 struct frame_id *this_id)
975 {
976 struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
977
978 /* This marks the outermost frame. */
979 if (cache->base == 0)
980 return;
981
982 /* See the end of m68k_push_dummy_call. */
983 *this_id = frame_id_build (cache->base + 8, cache->pc);
984 }
985
986 static struct value *
987 m68k_frame_prev_register (struct frame_info *this_frame, void **this_cache,
988 int regnum)
989 {
990 struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
991
992 gdb_assert (regnum >= 0);
993
994 if (regnum == M68K_SP_REGNUM && cache->saved_sp)
995 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
996
997 if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
998 return frame_unwind_got_memory (this_frame, regnum,
999 cache->saved_regs[regnum]);
1000
1001 return frame_unwind_got_register (this_frame, regnum, regnum);
1002 }
1003
1004 static const struct frame_unwind m68k_frame_unwind =
1005 {
1006 "m68k prologue",
1007 NORMAL_FRAME,
1008 default_frame_unwind_stop_reason,
1009 m68k_frame_this_id,
1010 m68k_frame_prev_register,
1011 NULL,
1012 default_frame_sniffer
1013 };
1014 \f
1015 static CORE_ADDR
1016 m68k_frame_base_address (struct frame_info *this_frame, void **this_cache)
1017 {
1018 struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
1019
1020 return cache->base;
1021 }
1022
1023 static const struct frame_base m68k_frame_base =
1024 {
1025 &m68k_frame_unwind,
1026 m68k_frame_base_address,
1027 m68k_frame_base_address,
1028 m68k_frame_base_address
1029 };
1030
1031 static struct frame_id
1032 m68k_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
1033 {
1034 CORE_ADDR fp;
1035
1036 fp = get_frame_register_unsigned (this_frame, M68K_FP_REGNUM);
1037
1038 /* See the end of m68k_push_dummy_call. */
1039 return frame_id_build (fp + 8, get_frame_pc (this_frame));
1040 }
1041 \f
1042
1043 /* Figure out where the longjmp will land. Slurp the args out of the stack.
1044 We expect the first arg to be a pointer to the jmp_buf structure from which
1045 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
1046 This routine returns true on success. */
1047
1048 static int
1049 m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
1050 {
1051 gdb_byte *buf;
1052 CORE_ADDR sp, jb_addr;
1053 struct gdbarch *gdbarch = get_frame_arch (frame);
1054 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1055 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1056
1057 if (tdep->jb_pc < 0)
1058 {
1059 internal_error (__FILE__, __LINE__,
1060 _("m68k_get_longjmp_target: not implemented"));
1061 return 0;
1062 }
1063
1064 buf = (gdb_byte *) alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
1065 sp = get_frame_register_unsigned (frame, gdbarch_sp_regnum (gdbarch));
1066
1067 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack. */
1068 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
1069 return 0;
1070
1071 jb_addr = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
1072 / TARGET_CHAR_BIT, byte_order);
1073
1074 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
1075 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT),
1076 byte_order)
1077 return 0;
1078
1079 *pc = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
1080 / TARGET_CHAR_BIT, byte_order);
1081 return 1;
1082 }
1083 \f
1084
1085 /* This is the implementation of gdbarch method
1086 return_in_first_hidden_param_p. */
1087
1088 static int
1089 m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
1090 struct type *type)
1091 {
1092 return 0;
1093 }
1094
1095 /* System V Release 4 (SVR4). */
1096
1097 void
1098 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1099 {
1100 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1101
1102 /* SVR4 uses a different calling convention. */
1103 set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
1104
1105 /* SVR4 uses %a0 instead of %a1. */
1106 tdep->struct_value_regnum = M68K_A0_REGNUM;
1107
1108 /* SVR4 returns pointers in %a0. */
1109 tdep->pointer_result_regnum = M68K_A0_REGNUM;
1110 }
1111
1112 /* GCC's m68k "embedded" ABI. This is like the SVR4 ABI, but pointer
1113 values are returned in %d0, not %a0. */
1114
1115 static void
1116 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1117 {
1118 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1119
1120 m68k_svr4_init_abi (info, gdbarch);
1121 tdep->pointer_result_regnum = M68K_D0_REGNUM;
1122 }
1123
1124 \f
1125
1126 /* Function: m68k_gdbarch_init
1127 Initializer function for the m68k gdbarch vector.
1128 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1129
1130 static struct gdbarch *
1131 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1132 {
1133 struct gdbarch_tdep *tdep = NULL;
1134 struct gdbarch *gdbarch;
1135 struct gdbarch_list *best_arch;
1136 tdesc_arch_data_up tdesc_data;
1137 int i;
1138 enum m68k_flavour flavour = m68k_no_flavour;
1139 int has_fp = 1;
1140 const struct floatformat **long_double_format = floatformats_m68881_ext;
1141
1142 /* Check any target description for validity. */
1143 if (tdesc_has_registers (info.target_desc))
1144 {
1145 const struct tdesc_feature *feature;
1146 int valid_p;
1147
1148 feature = tdesc_find_feature (info.target_desc,
1149 "org.gnu.gdb.m68k.core");
1150
1151 if (feature == NULL)
1152 {
1153 feature = tdesc_find_feature (info.target_desc,
1154 "org.gnu.gdb.coldfire.core");
1155 if (feature != NULL)
1156 flavour = m68k_coldfire_flavour;
1157 }
1158
1159 if (feature == NULL)
1160 {
1161 feature = tdesc_find_feature (info.target_desc,
1162 "org.gnu.gdb.fido.core");
1163 if (feature != NULL)
1164 flavour = m68k_fido_flavour;
1165 }
1166
1167 if (feature == NULL)
1168 return NULL;
1169
1170 tdesc_data = tdesc_data_alloc ();
1171
1172 valid_p = 1;
1173 for (i = 0; i <= M68K_PC_REGNUM; i++)
1174 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
1175 m68k_register_names[i]);
1176
1177 if (!valid_p)
1178 return NULL;
1179
1180 feature = tdesc_find_feature (info.target_desc,
1181 "org.gnu.gdb.coldfire.fp");
1182 if (feature != NULL)
1183 {
1184 valid_p = 1;
1185 for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++)
1186 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
1187 m68k_register_names[i]);
1188 if (!valid_p)
1189 return NULL;
1190 }
1191 else
1192 has_fp = 0;
1193 }
1194
1195 /* The mechanism for returning floating values from function
1196 and the type of long double depend on whether we're
1197 on ColdFire or standard m68k. */
1198
1199 if (info.bfd_arch_info && info.bfd_arch_info->mach != 0)
1200 {
1201 const bfd_arch_info_type *coldfire_arch =
1202 bfd_lookup_arch (bfd_arch_m68k, bfd_mach_mcf_isa_a_nodiv);
1203
1204 if (coldfire_arch
1205 && ((*info.bfd_arch_info->compatible)
1206 (info.bfd_arch_info, coldfire_arch)))
1207 flavour = m68k_coldfire_flavour;
1208 }
1209
1210 /* Try to figure out if the arch uses floating registers to return
1211 floating point values from functions. On ColdFire, floating
1212 point values are returned in D0. */
1213 int float_return = 0;
1214 if (has_fp && flavour != m68k_coldfire_flavour)
1215 float_return = 1;
1216 #ifdef HAVE_ELF
1217 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
1218 {
1219 int fp_abi = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
1220 Tag_GNU_M68K_ABI_FP);
1221 if (fp_abi == 1)
1222 float_return = 1;
1223 else if (fp_abi == 2)
1224 float_return = 0;
1225 }
1226 #endif /* HAVE_ELF */
1227
1228 /* If there is already a candidate, use it. */
1229 for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
1230 best_arch != NULL;
1231 best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
1232 {
1233 if (flavour != gdbarch_tdep (best_arch->gdbarch)->flavour)
1234 continue;
1235
1236 if (has_fp != gdbarch_tdep (best_arch->gdbarch)->fpregs_present)
1237 continue;
1238
1239 if (float_return != gdbarch_tdep (best_arch->gdbarch)->float_return)
1240 continue;
1241
1242 break;
1243 }
1244
1245 if (best_arch != NULL)
1246 return best_arch->gdbarch;
1247
1248 tdep = XCNEW (struct gdbarch_tdep);
1249 gdbarch = gdbarch_alloc (&info, tdep);
1250 tdep->fpregs_present = has_fp;
1251 tdep->float_return = float_return;
1252 tdep->flavour = flavour;
1253
1254 if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
1255 long_double_format = floatformats_ieee_double;
1256 set_gdbarch_long_double_format (gdbarch, long_double_format);
1257 set_gdbarch_long_double_bit (gdbarch, long_double_format[0]->totalsize);
1258
1259 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
1260 set_gdbarch_breakpoint_kind_from_pc (gdbarch, m68k_breakpoint::kind_from_pc);
1261 set_gdbarch_sw_breakpoint_from_kind (gdbarch, m68k_breakpoint::bp_from_kind);
1262
1263 /* Stack grows down. */
1264 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1265 set_gdbarch_frame_align (gdbarch, m68k_frame_align);
1266
1267 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
1268 if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
1269 set_gdbarch_decr_pc_after_break (gdbarch, 2);
1270
1271 set_gdbarch_frame_args_skip (gdbarch, 8);
1272 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
1273
1274 set_gdbarch_register_type (gdbarch, m68k_register_type);
1275 set_gdbarch_register_name (gdbarch, m68k_register_name);
1276 set_gdbarch_num_regs (gdbarch, M68K_NUM_REGS);
1277 set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
1278 set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
1279 set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
1280 set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
1281 set_gdbarch_register_to_value (gdbarch, m68k_register_to_value);
1282 set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);
1283
1284 if (has_fp)
1285 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
1286
1287 /* Function call & return. */
1288 set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
1289 set_gdbarch_return_value (gdbarch, m68k_return_value);
1290 set_gdbarch_return_in_first_hidden_param_p (gdbarch,
1291 m68k_return_in_first_hidden_param_p);
1292
1293 #if defined JB_PC && defined JB_ELEMENT_SIZE
1294 tdep->jb_pc = JB_PC;
1295 tdep->jb_elt_size = JB_ELEMENT_SIZE;
1296 #else
1297 tdep->jb_pc = -1;
1298 #endif
1299 tdep->pointer_result_regnum = M68K_D0_REGNUM;
1300 tdep->struct_value_regnum = M68K_A1_REGNUM;
1301 tdep->struct_return = reg_struct_return;
1302
1303 /* Frame unwinder. */
1304 set_gdbarch_dummy_id (gdbarch, m68k_dummy_id);
1305 set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
1306
1307 /* Hook in the DWARF CFI frame unwinder. */
1308 dwarf2_append_unwinders (gdbarch);
1309
1310 frame_base_set_default (gdbarch, &m68k_frame_base);
1311
1312 /* Hook in ABI-specific overrides, if they have been registered. */
1313 gdbarch_init_osabi (info, gdbarch);
1314
1315 /* Now we have tuned the configuration, set a few final things,
1316 based on what the OS ABI has told us. */
1317
1318 if (tdep->jb_pc >= 0)
1319 set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
1320
1321 frame_unwind_append_unwinder (gdbarch, &m68k_frame_unwind);
1322
1323 if (tdesc_data != nullptr)
1324 tdesc_use_registers (gdbarch, info.target_desc, std::move (tdesc_data));
1325
1326 return gdbarch;
1327 }
1328
1329
1330 static void
1331 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
1332 {
1333 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1334
1335 if (tdep == NULL)
1336 return;
1337 }
1338
1339 /* OSABI sniffer for m68k. */
1340
1341 static enum gdb_osabi
1342 m68k_osabi_sniffer (bfd *abfd)
1343 {
1344 unsigned int elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
1345
1346 if (elfosabi == ELFOSABI_NONE)
1347 return GDB_OSABI_SVR4;
1348
1349 return GDB_OSABI_UNKNOWN;
1350 }
1351
1352 void _initialize_m68k_tdep ();
1353 void
1354 _initialize_m68k_tdep ()
1355 {
1356 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
1357
1358 gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_elf_flavour,
1359 m68k_osabi_sniffer);
1360 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_SVR4,
1361 m68k_embedded_init_abi);
1362 }
This page took 0.057255 seconds and 4 git commands to generate.