* Makefile.in (mips-tdep.o, target-descriptions.o): Update.
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-arm-low.c
CommitLineData
0a30fbc4 1/* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
9308fc88
DJ
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006
0a30fbc4
DJ
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
6f0f660e
EZ
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
0a30fbc4
DJ
22
23#include "server.h"
58caa3dc 24#include "linux-low.h"
0a30fbc4 25
9308fc88
DJ
26#include <sys/ptrace.h>
27
28#include "gdb_proc_service.h"
29
30#ifndef PTRACE_GET_THREAD_AREA
31#define PTRACE_GET_THREAD_AREA 22
32#endif
33
0a30fbc4
DJ
34#ifdef HAVE_SYS_REG_H
35#include <sys/reg.h>
36#endif
37
23ce3b1c 38#define arm_num_regs 26
0a30fbc4 39
2ec06d2e 40static int arm_regmap[] = {
0a30fbc4
DJ
41 0, 4, 8, 12, 16, 20, 24, 28,
42 32, 36, 40, 44, 48, 52, 56, 60,
23ce3b1c
DJ
43 -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 64
0a30fbc4
DJ
45};
46
2ec06d2e
DJ
47static int
48arm_cannot_store_register (int regno)
0a30fbc4 49{
2ec06d2e 50 return (regno >= arm_num_regs);
0a30fbc4
DJ
51}
52
2ec06d2e
DJ
53static int
54arm_cannot_fetch_register (int regno)
0a30fbc4 55{
2ec06d2e 56 return (regno >= arm_num_regs);
0a30fbc4
DJ
57}
58
d677d77d
DJ
59extern int debug_threads;
60
0d62e5e8
DJ
61static CORE_ADDR
62arm_get_pc ()
63{
64 unsigned long pc;
65 collect_register_by_name ("pc", &pc);
d677d77d
DJ
66 if (debug_threads)
67 fprintf (stderr, "stop pc is %08lx\n", pc);
0d62e5e8
DJ
68 return pc;
69}
70
71static void
72arm_set_pc (CORE_ADDR pc)
73{
74 unsigned long newpc = pc;
75 supply_register_by_name ("pc", &newpc);
76}
77
78/* Correct in either endianness. We do not support Thumb yet. */
79static const unsigned long arm_breakpoint = 0xef9f0001;
80#define arm_breakpoint_len 4
81
9d1fb177
DJ
82/* For new EABI binaries. We recognize it regardless of which ABI
83 is used for gdbserver, so single threaded debugging should work
84 OK, but for multi-threaded debugging we only insert the current
85 ABI's breakpoint instruction. For now at least. */
86static const unsigned long arm_eabi_breakpoint = 0xe7f001f0;
87
0d62e5e8
DJ
88static int
89arm_breakpoint_at (CORE_ADDR where)
90{
91 unsigned long insn;
92
f450004a 93 (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
0d62e5e8
DJ
94 if (insn == arm_breakpoint)
95 return 1;
96
9d1fb177
DJ
97 if (insn == arm_eabi_breakpoint)
98 return 1;
99
0d62e5e8 100 /* If necessary, recognize more trap instructions here. GDB only uses the
9d1fb177
DJ
101 two. */
102
0d62e5e8
DJ
103 return 0;
104}
105
3b2fc2ea
DJ
106/* We only place breakpoints in empty marker functions, and thread locking
107 is outside of the function. So rather than importing software single-step,
108 we can just run until exit. */
109static CORE_ADDR
110arm_reinsert_addr ()
111{
112 unsigned long pc;
113 collect_register_by_name ("lr", &pc);
114 return pc;
115}
116
9308fc88
DJ
117/* Fetch the thread-local storage pointer for libthread_db. */
118
119ps_err_e
120ps_get_thread_area (const struct ps_prochandle *ph,
121 lwpid_t lwpid, int idx, void **base)
122{
123 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
124 return PS_ERR;
125
126 /* IDX is the bias from the thread pointer to the beginning of the
127 thread descriptor. It has to be subtracted due to implementation
128 quirks in libthread_db. */
129 *base = (void *) ((char *)*base - idx);
130
131 return PS_OK;
132}
133
2ec06d2e
DJ
134struct linux_target_ops the_low_target = {
135 arm_num_regs,
136 arm_regmap,
137 arm_cannot_fetch_register,
138 arm_cannot_store_register,
0d62e5e8
DJ
139 arm_get_pc,
140 arm_set_pc,
9d1fb177 141#ifndef __ARM_EABI__
f450004a 142 (const unsigned char *) &arm_breakpoint,
9d1fb177
DJ
143#else
144 (const unsigned char *) &arm_eabi_breakpoint,
145#endif
0d62e5e8 146 arm_breakpoint_len,
3b2fc2ea 147 arm_reinsert_addr,
0d62e5e8
DJ
148 0,
149 arm_breakpoint_at,
2ec06d2e 150};
This page took 0.358878 seconds and 4 git commands to generate.