1 /* Motorola m68k target-dependent support for GNU/Linux.
3 Copyright 1996, 1998, 2000, 2001, 2002 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. */
29 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
31 #define IS_SIGTRAMP(insn1, insn2) \
32 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
33 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
34 /* moveq #119,d0; trap #0 */ \
35 || insn1 == 0x70774e40)
37 #define IS_RT_SIGTRAMP(insn1, insn2) \
38 (/* movel #173,d0; trap #0 */ \
39 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
40 /* moveq #82,d0; notb d0; trap #0 */ \
41 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
43 /* Return non-zero if PC points into the signal trampoline. For the sake
44 of m68k_linux_frame_saved_pc we also distinguish between non-RT and RT
45 signal trampolines. */
48 m68k_linux_in_sigtramp (CORE_ADDR pc
)
52 unsigned long insn0
, insn1
, insn2
;
54 if (read_memory_nobpt (pc
- 4, buf
, sizeof (buf
)))
56 insn1
= extract_unsigned_integer (buf
+ 4, 4);
57 insn2
= extract_unsigned_integer (buf
+ 8, 4);
58 if (IS_SIGTRAMP (insn1
, insn2
))
60 if (IS_RT_SIGTRAMP (insn1
, insn2
))
63 insn0
= extract_unsigned_integer (buf
, 4);
64 if (IS_SIGTRAMP (insn0
, insn1
))
66 if (IS_RT_SIGTRAMP (insn0
, insn1
))
69 insn0
= (insn0
<< 16) | (insn1
>> 16);
70 insn1
= (insn1
<< 16) | (insn2
>> 16);
71 if (IS_SIGTRAMP (insn0
, insn1
))
73 if (IS_RT_SIGTRAMP (insn0
, insn1
))
79 /* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
80 #define SIGCONTEXT_PC_OFFSET 26
82 /* Offset to saved PC in ucontext, from <asm/ucontext.h>. */
83 #define UCONTEXT_PC_OFFSET 88
85 /* Get saved user PC for sigtramp from sigcontext or ucontext. */
88 m68k_linux_sigtramp_saved_pc (struct frame_info
*frame
)
90 CORE_ADDR sigcontext_addr
;
91 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
92 int ptrbytes
= TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
93 int sigcontext_offs
= (2 * TARGET_INT_BIT
) / TARGET_CHAR_BIT
;
95 /* Get sigcontext address, it is the third parameter on the stack. */
98 = read_memory_unsigned_integer (FRAME_ARGS_ADDRESS (frame
->next
)
104 = read_memory_unsigned_integer (read_register (SP_REGNUM
)
108 /* Don't cause a memory_error when accessing sigcontext in case the
109 stack layout has changed or the stack is corrupt. */
110 if (m68k_linux_in_sigtramp (frame
->pc
) == 2)
111 target_read_memory (sigcontext_addr
+ UCONTEXT_PC_OFFSET
, buf
, ptrbytes
);
113 target_read_memory (sigcontext_addr
+ SIGCONTEXT_PC_OFFSET
, buf
, ptrbytes
);
114 return extract_unsigned_integer (buf
, ptrbytes
);
117 /* Return the saved program counter for FRAME. */
120 m68k_linux_frame_saved_pc (struct frame_info
*frame
)
122 if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
123 return m68k_linux_sigtramp_saved_pc (frame
);
125 return read_memory_unsigned_integer (frame
->frame
+ 4, 4);