]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gdbserver/linux-arm-low.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / gdbserver / linux-arm-low.c
1 /* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include "server.h"
23 #include "linux-low.h"
24
25 #include <sys/ptrace.h>
26
27 #include "gdb_proc_service.h"
28
29 #ifndef PTRACE_GET_THREAD_AREA
30 #define PTRACE_GET_THREAD_AREA 22
31 #endif
32
33 #ifdef HAVE_SYS_REG_H
34 #include <sys/reg.h>
35 #endif
36
37 #define arm_num_regs 26
38
39 static int arm_regmap[] = {
40 0, 4, 8, 12, 16, 20, 24, 28,
41 32, 36, 40, 44, 48, 52, 56, 60,
42 -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 64
44 };
45
46 static int
47 arm_cannot_store_register (int regno)
48 {
49 return (regno >= arm_num_regs);
50 }
51
52 static int
53 arm_cannot_fetch_register (int regno)
54 {
55 return (regno >= arm_num_regs);
56 }
57
58 extern int debug_threads;
59
60 static CORE_ADDR
61 arm_get_pc ()
62 {
63 unsigned long pc;
64 collect_register_by_name ("pc", &pc);
65 if (debug_threads)
66 fprintf (stderr, "stop pc is %08lx\n", pc);
67 return pc;
68 }
69
70 static void
71 arm_set_pc (CORE_ADDR pc)
72 {
73 unsigned long newpc = pc;
74 supply_register_by_name ("pc", &newpc);
75 }
76
77 /* Correct in either endianness. We do not support Thumb yet. */
78 static const unsigned long arm_breakpoint = 0xef9f0001;
79 #define arm_breakpoint_len 4
80
81 /* For new EABI binaries. We recognize it regardless of which ABI
82 is used for gdbserver, so single threaded debugging should work
83 OK, but for multi-threaded debugging we only insert the current
84 ABI's breakpoint instruction. For now at least. */
85 static const unsigned long arm_eabi_breakpoint = 0xe7f001f0;
86
87 static int
88 arm_breakpoint_at (CORE_ADDR where)
89 {
90 unsigned long insn;
91
92 (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
93 if (insn == arm_breakpoint)
94 return 1;
95
96 if (insn == arm_eabi_breakpoint)
97 return 1;
98
99 /* If necessary, recognize more trap instructions here. GDB only uses the
100 two. */
101
102 return 0;
103 }
104
105 /* We only place breakpoints in empty marker functions, and thread locking
106 is outside of the function. So rather than importing software single-step,
107 we can just run until exit. */
108 static CORE_ADDR
109 arm_reinsert_addr ()
110 {
111 unsigned long pc;
112 collect_register_by_name ("lr", &pc);
113 return pc;
114 }
115
116 /* Fetch the thread-local storage pointer for libthread_db. */
117
118 ps_err_e
119 ps_get_thread_area (const struct ps_prochandle *ph,
120 lwpid_t lwpid, int idx, void **base)
121 {
122 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
123 return PS_ERR;
124
125 /* IDX is the bias from the thread pointer to the beginning of the
126 thread descriptor. It has to be subtracted due to implementation
127 quirks in libthread_db. */
128 *base = (void *) ((char *)*base - idx);
129
130 return PS_OK;
131 }
132
133 struct linux_target_ops the_low_target = {
134 arm_num_regs,
135 arm_regmap,
136 arm_cannot_fetch_register,
137 arm_cannot_store_register,
138 arm_get_pc,
139 arm_set_pc,
140 #ifndef __ARM_EABI__
141 (const unsigned char *) &arm_breakpoint,
142 #else
143 (const unsigned char *) &arm_eabi_breakpoint,
144 #endif
145 arm_breakpoint_len,
146 arm_reinsert_addr,
147 0,
148 arm_breakpoint_at,
149 };