]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/m68klinux-tdep.c
* c-exp.y (typebase): Remove duplicate occurence of
[thirdparty/binutils-gdb.git] / gdb / m68klinux-tdep.c
CommitLineData
0a595803
AS
1/* Motorola m68k target-dependent support for GNU/Linux.
2
3 Copyright 1996, 1998, 2000, 2001, 2002 Free Software Foundation,
4 Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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. */
22
23#include "defs.h"
24#include "gdbcore.h"
25#include "frame.h"
26#include "target.h"
27
28\f
29/* Check whether insn1 and insn2 are parts of a signal trampoline. */
30
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)
36
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))
42
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. */
46
47int
48m68k_linux_in_sigtramp (CORE_ADDR pc)
49{
50 CORE_ADDR sp;
51 char buf[12];
52 unsigned long insn0, insn1, insn2;
53
54 if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
55 return 0;
56 insn1 = extract_unsigned_integer (buf + 4, 4);
57 insn2 = extract_unsigned_integer (buf + 8, 4);
58 if (IS_SIGTRAMP (insn1, insn2))
59 return 1;
60 if (IS_RT_SIGTRAMP (insn1, insn2))
61 return 2;
62
63 insn0 = extract_unsigned_integer (buf, 4);
64 if (IS_SIGTRAMP (insn0, insn1))
65 return 1;
66 if (IS_RT_SIGTRAMP (insn0, insn1))
67 return 2;
68
69 insn0 = (insn0 << 16) | (insn1 >> 16);
70 insn1 = (insn1 << 16) | (insn2 >> 16);
71 if (IS_SIGTRAMP (insn0, insn1))
72 return 1;
73 if (IS_RT_SIGTRAMP (insn0, insn1))
74 return 2;
75
76 return 0;
77}
78
79/* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
80#define SIGCONTEXT_PC_OFFSET 26
81
82/* Offset to saved PC in ucontext, from <asm/ucontext.h>. */
83#define UCONTEXT_PC_OFFSET 88
84
85/* Get saved user PC for sigtramp from sigcontext or ucontext. */
86
87static CORE_ADDR
88m68k_linux_sigtramp_saved_pc (struct frame_info *frame)
89{
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;
94
95 /* Get sigcontext address, it is the third parameter on the stack. */
96 if (frame->next)
b5fc49aa
AS
97 sigcontext_addr
98 = read_memory_unsigned_integer (FRAME_ARGS_ADDRESS (frame->next)
99 + FRAME_ARGS_SKIP
100 + sigcontext_offs,
101 ptrbytes);
0a595803 102 else
b5fc49aa
AS
103 sigcontext_addr
104 = read_memory_unsigned_integer (read_register (SP_REGNUM)
105 + sigcontext_offs,
106 ptrbytes);
0a595803
AS
107
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);
112 else
113 target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
114 return extract_unsigned_integer (buf, ptrbytes);
115}
116
117/* Return the saved program counter for FRAME. */
118
119CORE_ADDR
120m68k_linux_frame_saved_pc (struct frame_info *frame)
121{
122 if (get_frame_type (frame) == SIGTRAMP_FRAME)
123 return m68k_linux_sigtramp_saved_pc (frame);
124
b5fc49aa 125 return read_memory_unsigned_integer (frame->frame + 4, 4);
0a595803 126}