* mips-linux-nat.c: Include "gdb_proc_service.h".
[external/binutils.git] / gdb / mips-linux-nat.c
1 /* Native-dependent code for GNU/Linux on MIPS processors.
2
3    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
4    Free Software Foundation, 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., 51 Franklin Street, Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22
23 #include "defs.h"
24 #include "mips-tdep.h"
25 #include "target.h"
26 #include "linux-nat.h"
27
28 #include "gdb_proc_service.h"
29
30 #ifndef PTRACE_GET_THREAD_AREA
31 #define PTRACE_GET_THREAD_AREA 25
32 #endif
33
34 /* Pseudo registers can not be read.  ptrace does not provide a way to
35    read (or set) MIPS_PS_REGNUM, and there's no point in reading or
36    setting MIPS_ZERO_REGNUM.  We also can not set BADVADDR, CAUSE, or
37    FCRIR via ptrace().  */
38
39 int
40 mips_linux_cannot_fetch_register (int regno)
41 {
42   if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32)
43     return 0;
44   else if (regno >= mips_regnum (current_gdbarch)->fp0
45            && regno <= mips_regnum (current_gdbarch)->fp0 + 32)
46     return 0;
47   else if (regno == mips_regnum (current_gdbarch)->lo
48            || regno == mips_regnum (current_gdbarch)->hi
49            || regno == mips_regnum (current_gdbarch)->badvaddr
50            || regno == mips_regnum (current_gdbarch)->cause
51            || regno == mips_regnum (current_gdbarch)->pc
52            || regno == mips_regnum (current_gdbarch)->fp_control_status
53            || regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
54     return 0;
55   else
56     return 1;
57 }
58
59 int
60 mips_linux_cannot_store_register (int regno)
61 {
62   if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32)
63     return 0;
64   else if (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 32)
65     return 0;
66   else if (regno == mips_regnum (current_gdbarch)->lo
67            || regno == mips_regnum (current_gdbarch)->hi
68            || regno == mips_regnum (current_gdbarch)->pc
69            || regno == mips_regnum (current_gdbarch)->fp_control_status)
70     return 0;
71   else
72     return 1;
73 }
74
75 /* Fetch the thread-local storage pointer for libthread_db.  */
76
77 ps_err_e
78 ps_get_thread_area (const struct ps_prochandle *ph,
79                     lwpid_t lwpid, int idx, void **base)
80 {
81   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
82     return PS_ERR;
83
84   /* IDX is the bias from the thread pointer to the beginning of the
85      thread descriptor.  It has to be subtracted due to implementation
86      quirks in libthread_db.  */
87   *base = (void *) ((char *)*base - idx);
88
89   return PS_OK;
90 }
91
92 void _initialize_mips_linux_nat (void);
93
94 void
95 _initialize_mips_linux_nat (void)
96 {
97   add_target (linux_target ());
98 }