Update/correct copyright notices.
[external/binutils.git] / gdb / m68klinux-nat.c
1 /* Motorola m68k native support for Linux
2    Copyright 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
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.
10
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.
15
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.  */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "inferior.h"
24 #include "language.h"
25 #include "gdbcore.h"
26 #include "regcache.h"
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"
46 \f
47
48 /* This table must line up with REGISTER_NAMES in tm-m68k.h */
49 static const int regmap[] =
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
63 int
64 m68k_linux_register_u_addr (int blockend, int regnum)
65 {
66   return (blockend + 4 * regmap[regnum]);
67 }
68
69 /*  Given a pointer to a general register set in /proc format (gregset_t *),
70    unpack the register contents and supply them as gdb's idea of the current
71    register values. */
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 
80    depend on these definitions. */
81
82 #ifndef USE_PROC_FS
83
84 /* Prototypes for supply_gregset etc. */
85 #include "gregset.h"
86
87 void
88 supply_gregset (gregset_t *gregsetp)
89 {
90   int regi;
91
92   for (regi = D0_REGNUM; regi <= SP_REGNUM; regi++)
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
99    (fpregset_t *), unpack the register contents and supply them as gdb's
100    idea of the current floating point register values. */
101
102 void
103 supply_fpregset (fpregset_t *fpregsetp)
104 {
105   int regi;
106
107   for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
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
115 \f
116
117 int
118 kernel_u_size (void)
119 {
120   return (sizeof (struct user));
121 }
122 \f
123 /* Return non-zero if PC points into the signal trampoline.  */
124
125 int
126 in_sigtramp (CORE_ADDR pc)
127 {
128   CORE_ADDR sp;
129   char buf[TARGET_SHORT_BIT / TARGET_CHAR_BIT];
130   int insn;
131
132   sp = read_register (SP_REGNUM);
133   if (pc - 2 < sp)
134     return 0;
135
136   if (read_memory_nobpt (pc, buf, sizeof (buf)))
137     return 0;
138   insn = extract_unsigned_integer (buf, sizeof (buf));
139   if (insn == 0xdefc            /* addaw #,sp */
140       || insn == 0x7077         /* moveq #119,d0 */
141       || insn == 0x4e40         /* trap #0 */
142       || insn == 0x203c /* movel #,d0 */ )
143     return 1;
144
145   if (read_memory_nobpt (pc - 2, buf, sizeof (buf)))
146     return 0;
147   insn = extract_unsigned_integer (buf, sizeof (buf));
148   if (insn == 0xdefc            /* addaw #,sp */
149       || insn == 0x7077         /* moveq #119,d0 */
150       || insn == 0x4e40         /* trap #0 */
151       || insn == 0x203c /* movel #,d0 */ )
152     return 1;
153
154   return 0;
155 }