1 /* Motorola m68k target-dependent support for GNU/Linux.
3 Copyright 1996, 1998, 2000, 2001, 2002, 2003 Free Software Foundation,
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
29 #include "m68k-tdep.h"
31 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
33 #define IS_SIGTRAMP(insn1, insn2) \
34 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
35 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
36 /* moveq #119,d0; trap #0 */ \
37 || insn1 == 0x70774e40)
39 #define IS_RT_SIGTRAMP(insn1, insn2) \
40 (/* movel #173,d0; trap #0 */ \
41 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
42 /* moveq #82,d0; notb d0; trap #0 */ \
43 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
45 /* Return non-zero if PC points into the signal trampoline. For the sake
46 of m68k_linux_frame_saved_pc we also distinguish between non-RT and RT
47 signal trampolines. */
50 m68k_linux_in_sigtramp (CORE_ADDR pc)
54 unsigned long insn0, insn1, insn2;
56 if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
58 insn1 = extract_unsigned_integer (buf + 4, 4);
59 insn2 = extract_unsigned_integer (buf + 8, 4);
60 if (IS_SIGTRAMP (insn1, insn2))
62 if (IS_RT_SIGTRAMP (insn1, insn2))
65 insn0 = extract_unsigned_integer (buf, 4);
66 if (IS_SIGTRAMP (insn0, insn1))
68 if (IS_RT_SIGTRAMP (insn0, insn1))
71 insn0 = (insn0 << 16) | (insn1 >> 16);
72 insn1 = (insn1 << 16) | (insn2 >> 16);
73 if (IS_SIGTRAMP (insn0, insn1))
75 if (IS_RT_SIGTRAMP (insn0, insn1))
81 /* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
82 #define SIGCONTEXT_PC_OFFSET 26
84 /* Offset to saved PC in ucontext, from <asm/ucontext.h>. */
85 #define UCONTEXT_PC_OFFSET 88
87 /* Get saved user PC for sigtramp from sigcontext or ucontext. */
90 m68k_linux_sigtramp_saved_pc (struct frame_info *frame)
92 CORE_ADDR sigcontext_addr;
93 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
94 int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
95 int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
97 /* Get sigcontext address, it is the third parameter on the stack. */
98 if (get_next_frame (frame))
100 = read_memory_unsigned_integer (get_frame_base (get_next_frame (frame))
106 = read_memory_unsigned_integer (read_register (SP_REGNUM)
110 /* Don't cause a memory_error when accessing sigcontext in case the
111 stack layout has changed or the stack is corrupt. */
112 if (m68k_linux_in_sigtramp (get_frame_pc (frame)) == 2)
113 target_read_memory (sigcontext_addr + UCONTEXT_PC_OFFSET, buf, ptrbytes);
115 target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
116 return extract_unsigned_integer (buf, ptrbytes);
119 /* Return the saved program counter for FRAME. */
122 m68k_linux_frame_saved_pc (struct frame_info *frame)
124 if (get_frame_type (frame) == SIGTRAMP_FRAME)
125 return m68k_linux_sigtramp_saved_pc (frame);
127 return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4);
131 m68k_linux_extract_return_value (struct type *type, char *regbuf, char *valbuf)
133 if (TYPE_CODE (type) == TYPE_CODE_FLT)
135 REGISTER_CONVERT_TO_VIRTUAL (FP0_REGNUM, type,
136 regbuf + REGISTER_BYTE (FP0_REGNUM),
139 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
140 memcpy (valbuf, regbuf + REGISTER_BYTE (M68K_A0_REGNUM),
144 regbuf + (TYPE_LENGTH (type) >= 4 ? 0 : 4 - TYPE_LENGTH (type)),
149 m68k_linux_store_return_value (struct type *type, char *valbuf)
151 if (TYPE_CODE (type) == TYPE_CODE_FLT)
153 char raw_buffer[REGISTER_RAW_SIZE (FP0_REGNUM)];
154 REGISTER_CONVERT_TO_RAW (type, FP0_REGNUM, valbuf, raw_buffer);
155 deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM),
156 raw_buffer, TYPE_LENGTH (type));
160 if (TYPE_CODE (type) == TYPE_CODE_PTR)
161 deprecated_write_register_bytes (REGISTER_BYTE (M68K_A0_REGNUM),
162 valbuf, TYPE_LENGTH (type));
163 deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
168 m68k_linux_extract_struct_value_address (char *regbuf)
170 return *(CORE_ADDR *) (regbuf + REGISTER_BYTE (M68K_A0_REGNUM));