* configure.in <64-bit configuration>: If using gcc, check and
[deliverable/binutils-gdb.git] / gdb / m68klinux-nat.c
CommitLineData
c906108c 1/* Motorola m68k native support for Linux
b6ba6518 2 Copyright 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
c906108c 10
c5aa993b
JM
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
c906108c 15
c5aa993b
JM
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
c906108c
SS
20
21#include "defs.h"
22#include "frame.h"
23#include "inferior.h"
24#include "language.h"
25#include "gdbcore.h"
4e052eda 26#include "regcache.h"
c906108c
SS
27
28#ifdef USG
29#include <sys/types.h>
30#endif
31
32#include <sys/param.h>
33#include <sys/dir.h>
34#include <signal.h>
35#include <sys/user.h>
36#include <sys/ioctl.h>
37#include <fcntl.h>
38#include <sys/procfs.h>
39
40#include <sys/file.h>
41#include "gdb_stat.h"
42
43#include "floatformat.h"
44
45#include "target.h"
c906108c 46\f
c5aa993b 47
c906108c 48/* This table must line up with REGISTER_NAMES in tm-m68k.h */
c5aa993b 49static const int regmap[] =
c906108c
SS
50{
51 PT_D0, PT_D1, PT_D2, PT_D3, PT_D4, PT_D5, PT_D6, PT_D7,
52 PT_A0, PT_A1, PT_A2, PT_A3, PT_A4, PT_A5, PT_A6, PT_USP,
53 PT_SR, PT_PC,
54 /* PT_FP0, ..., PT_FP7 */
55 21, 24, 27, 30, 33, 36, 39, 42,
56 /* PT_FPCR, PT_FPSR, PT_FPIAR */
57 45, 46, 47
58};
59
60/* BLOCKEND is the value of u.u_ar0, and points to the place where GS
61 is stored. */
62
63int
fba45db2 64m68k_linux_register_u_addr (int blockend, int regnum)
c906108c 65{
c5aa993b 66 return (blockend + 4 * regmap[regnum]);
c906108c
SS
67}
68
f175af98
DJ
69/* Given a pointer to a general register set in /proc format
70 (elf_gregset_t *), unpack the register contents and supply
71 them as gdb's idea of the current register values. */
c906108c
SS
72
73
74/* Note both m68k-tdep.c and m68klinux-nat.c contain definitions
75 for supply_gregset and supply_fpregset. The definitions
76 in m68k-tdep.c are valid if USE_PROC_FS is defined. Otherwise,
77 the definitions in m68klinux-nat.c will be used. This is a
78 bit of a hack. The supply_* routines do not belong in
79 *_tdep.c files. But, there are several lynx ports that currently
c5aa993b 80 depend on these definitions. */
c906108c
SS
81
82#ifndef USE_PROC_FS
83
c60c0f5f
MS
84/* Prototypes for supply_gregset etc. */
85#include "gregset.h"
86
c906108c 87void
f175af98 88supply_gregset (elf_gregset_t *gregsetp)
c906108c
SS
89{
90 int regi;
91
c5aa993b 92 for (regi = D0_REGNUM; regi <= SP_REGNUM; regi++)
c906108c
SS
93 supply_register (regi, (char *) (*gregsetp + regmap[regi]));
94 supply_register (PS_REGNUM, (char *) (*gregsetp + PT_SR));
95 supply_register (PC_REGNUM, (char *) (*gregsetp + PT_PC));
96}
97
98/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
99 (fpregset_t *), unpack the register contents and supply them as gdb's
100 idea of the current floating point register values. */
c906108c 101
c5aa993b 102void
f175af98 103supply_fpregset (elf_fpregset_t *fpregsetp)
c906108c
SS
104{
105 int regi;
106
c5aa993b 107 for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
c906108c
SS
108 supply_register (regi, (char *) &fpregsetp->fpregs[(regi - FP0_REGNUM) * 3]);
109 supply_register (FPC_REGNUM, (char *) &fpregsetp->fpcntl[0]);
110 supply_register (FPS_REGNUM, (char *) &fpregsetp->fpcntl[1]);
111 supply_register (FPI_REGNUM, (char *) &fpregsetp->fpcntl[2]);
112}
113
114#endif
f175af98
DJ
115
116\f
117/* Interpreting register set info found in core files. */
118
119/* Provide registers to GDB from a core file.
120
121 (We can't use the generic version of this function in
122 core-regset.c, because we need to use elf_gregset_t instead of
123 gregset_t.)
124
125 CORE_REG_SECT points to an array of bytes, which are the contents
126 of a `note' from a core file which BFD thinks might contain
127 register contents. CORE_REG_SIZE is its size.
128
129 WHICH says which register set corelow suspects this is:
130 0 --- the general-purpose register set, in elf_gregset_t format
131 2 --- the floating-point register set, in elf_fpregset_t format
132
133 REG_ADDR isn't used on Linux. */
134
135static void
136fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
137 int which, CORE_ADDR reg_addr)
138{
139 elf_gregset_t gregset;
140 elf_fpregset_t fpregset;
141
142 switch (which)
143 {
144 case 0:
145 if (core_reg_size != sizeof (gregset))
146 warning ("Wrong size gregset in core file.");
147 else
148 {
149 memcpy (&gregset, core_reg_sect, sizeof (gregset));
150 supply_gregset (&gregset);
151 }
152 break;
153
154 case 2:
155 if (core_reg_size != sizeof (fpregset))
156 warning ("Wrong size fpregset in core file.");
157 else
158 {
159 memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
160 supply_fpregset (&fpregset);
161 }
162 break;
163
164 default:
165 /* We've covered all the kinds of registers we know about here,
166 so this must be something we wouldn't know what to do with
167 anyway. Just ignore it. */
168 break;
169 }
170}
c906108c 171\f
c5aa993b 172
c906108c 173int
fba45db2 174kernel_u_size (void)
c906108c
SS
175{
176 return (sizeof (struct user));
177}
178\f
179/* Return non-zero if PC points into the signal trampoline. */
180
181int
fba45db2 182in_sigtramp (CORE_ADDR pc)
c906108c
SS
183{
184 CORE_ADDR sp;
185 char buf[TARGET_SHORT_BIT / TARGET_CHAR_BIT];
186 int insn;
187
188 sp = read_register (SP_REGNUM);
189 if (pc - 2 < sp)
190 return 0;
191
192 if (read_memory_nobpt (pc, buf, sizeof (buf)))
193 return 0;
194 insn = extract_unsigned_integer (buf, sizeof (buf));
c5aa993b
JM
195 if (insn == 0xdefc /* addaw #,sp */
196 || insn == 0x7077 /* moveq #119,d0 */
197 || insn == 0x4e40 /* trap #0 */
198 || insn == 0x203c /* movel #,d0 */ )
c906108c
SS
199 return 1;
200
201 if (read_memory_nobpt (pc - 2, buf, sizeof (buf)))
202 return 0;
203 insn = extract_unsigned_integer (buf, sizeof (buf));
c5aa993b
JM
204 if (insn == 0xdefc /* addaw #,sp */
205 || insn == 0x7077 /* moveq #119,d0 */
206 || insn == 0x4e40 /* trap #0 */
207 || insn == 0x203c /* movel #,d0 */ )
c906108c
SS
208 return 1;
209
210 return 0;
211}
f175af98
DJ
212
213\f
214/* Register that we are able to handle Linux ELF core file formats. */
215
216static struct core_fns linux_elf_core_fns =
217{
218 bfd_target_elf_flavour, /* core_flavour */
219 default_check_format, /* check_format */
220 default_core_sniffer, /* core_sniffer */
221 fetch_core_registers, /* core_read_registers */
222 NULL /* next */
223};
224
225void
226_initialize_m68k_linux_nat ()
227{
228 add_core_fns (&linux_elf_core_fns);
229}
This page took 0.16113 seconds and 4 git commands to generate.