1 |
441 |
jeremybenn |
/* GNU/Linux/or32 specific low level interface, for the remote server for GDB.
|
2 |
|
|
Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
3 |
|
|
Copyright (C) 2010 Embecosm Limited
|
4 |
|
|
|
5 |
|
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
6 |
|
|
|
7 |
|
|
This file is part of GDB.
|
8 |
|
|
|
9 |
|
|
This program is free software; you can redistribute it and/or modify
|
10 |
|
|
it under the terms of the GNU General Public License as published by
|
11 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
12 |
|
|
(at your option) any later version.
|
13 |
|
|
|
14 |
|
|
This program is distributed in the hope that it will be useful,
|
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
GNU General Public License for more details.
|
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU General Public License
|
20 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
21 |
|
|
|
22 |
|
|
/* -------------------------------------------------------------------------- */
|
23 |
|
|
/* OpenRISC 1000 specific low level Linux interface for GDB server.
|
24 |
|
|
|
25 |
|
|
This implementation includes full Doxygen compatible documentation */
|
26 |
|
|
/* -------------------------------------------------------------------------- */
|
27 |
|
|
|
28 |
|
|
#ifdef HAVE_STRINGS_H
|
29 |
|
|
#include <strings.h>
|
30 |
|
|
#endif
|
31 |
|
|
|
32 |
|
|
#include "server.h"
|
33 |
|
|
#include "regdef.h"
|
34 |
|
|
#include "linux-low.h"
|
35 |
|
|
|
36 |
445 |
julius |
#include <asm/ptrace.h> /* For openrisc kernel ptrace register offsets */
|
37 |
|
|
|
38 |
441 |
jeremybenn |
#ifdef HAVE_SYS_REG_H
|
39 |
|
|
#include <sys/reg.h>
|
40 |
|
|
#endif
|
41 |
|
|
|
42 |
446 |
julius |
struct reg regs_or32[] = {
|
43 |
445 |
julius |
{ "npc", PC * 8, 32 },
|
44 |
|
|
{ "sr", SR * 8, 32 },
|
45 |
|
|
{ "sp", SP * 8, 32 },
|
46 |
|
|
{ "fp", GPR2 * 8, 32 },
|
47 |
|
|
{ "r3", GPR3 * 8, 32 },
|
48 |
|
|
{ "r4", GPR4 * 8, 32 },
|
49 |
|
|
{ "r5", GPR5 * 8, 32 },
|
50 |
|
|
{ "r6", GPR6 * 8, 32 },
|
51 |
|
|
{ "r7", GPR7 * 8, 32 },
|
52 |
|
|
{ "r8", GPR8 * 8, 32 },
|
53 |
|
|
{ "lr", GPR9 * 8, 32 },
|
54 |
|
|
{ "r10", GPR10 * 8, 32 },
|
55 |
|
|
{ "r11", GPR11 * 8, 32 },
|
56 |
|
|
{ "r12", GPR12 * 8, 32 },
|
57 |
|
|
{ "r13", GPR13 * 8, 32 },
|
58 |
|
|
{ "r14", GPR14 * 8, 32 },
|
59 |
|
|
{ "r15", GPR15 * 8, 32 },
|
60 |
|
|
{ "r16", GPR16 * 8, 32 },
|
61 |
|
|
{ "r17", GPR17 * 8, 32 },
|
62 |
|
|
{ "r18", GPR18 * 8, 32 },
|
63 |
|
|
{ "r19", GPR19 * 8, 32 },
|
64 |
|
|
{ "r20", GPR20 * 8, 32 },
|
65 |
|
|
{ "r21", GPR21 * 8, 32 },
|
66 |
|
|
{ "r22", GPR22 * 8, 32 },
|
67 |
|
|
{ "r23", GPR23 * 8, 32 },
|
68 |
|
|
{ "r24", GPR24 * 8, 32 },
|
69 |
|
|
{ "r25", GPR25 * 8, 32 },
|
70 |
|
|
{ "r26", GPR26 * 8, 32 },
|
71 |
|
|
{ "r27", GPR27 * 8, 32 },
|
72 |
|
|
{ "r28", GPR28 * 8, 32 },
|
73 |
|
|
{ "r29", GPR29 * 8, 32 },
|
74 |
|
|
{ "r30", GPR30 * 8, 32 },
|
75 |
|
|
{ "r31", GPR31 * 8, 32 },
|
76 |
441 |
jeremybenn |
};
|
77 |
446 |
julius |
|
78 |
|
|
/* -------------------------------------------------------------------------- */
|
79 |
|
|
/*!Initialize the register data.
|
80 |
|
|
|
81 |
|
|
Should be automagically created from a data file in gdb/regformats, but for
|
82 |
|
|
now we do it manually. */
|
83 |
|
|
/* -------------------------------------------------------------------------- */
|
84 |
|
|
static void
|
85 |
|
|
init_registers_or32 ()
|
86 |
|
|
{
|
87 |
|
|
|
88 |
441 |
jeremybenn |
static const char *expedite_regs_or32[] = { "sp", "lr", "npc", 0 };
|
89 |
|
|
|
90 |
|
|
set_register_cache (regs_or32, sizeof (regs_or32) / sizeof (regs_or32[0]));
|
91 |
|
|
gdbserver_expedite_regs = expedite_regs_or32;
|
92 |
|
|
gdbserver_xmltarget = NULL;
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
|
96 |
445 |
julius |
/*! OpenRISC Linux ptrace provides NPC, SR, then GPRS 1 to 31 */
|
97 |
|
|
#define or32_num_regs (2 + 31)
|
98 |
441 |
jeremybenn |
|
99 |
|
|
|
100 |
|
|
/* -------------------------------------------------------------------------- */
|
101 |
|
|
/*!Provide the ptrace "address" of a register.
|
102 |
445 |
julius |
*/
|
103 |
441 |
jeremybenn |
/* -------------------------------------------------------------------------- */
|
104 |
|
|
static int or32_regmap[] = {
|
105 |
445 |
julius |
#ifdef PC
|
106 |
|
|
PC , SR , SP , GPR2 , GPR3 , GPR4 , GPR5 , GPR6 ,
|
107 |
|
|
GPR7 , GPR8 , GPR9 , GPR10, GPR11, GPR12, GPR13, GPR14,
|
108 |
|
|
GPR15, GPR16, GPR17, GPR18, GPR19, GPR20, GPR21, GPR22,
|
109 |
|
|
GPR23, GPR24, GPR25, GPR26, GPR27, GPR28, GPR29, GPR30,
|
110 |
|
|
GPR31
|
111 |
441 |
jeremybenn |
#else
|
112 |
|
|
4 * 0, 4 * 1, 4 * 2, 4 * 3, 4 * 4, 4 * 5, 4 * 6, 4 * 7,
|
113 |
|
|
4 * 8, 4 * 9, 4 * 10, 4 * 11, 4 * 12, 4 * 13, 4 * 14, 4 * 15,
|
114 |
|
|
4 * 16, 4 * 17, 4 * 18, 4 * 19, 4 * 20, 4 * 21, 4 * 22, 4 * 23,
|
115 |
|
|
4 * 24, 4 * 25, 4 * 26, 4 * 27, 4 * 28, 4 * 29, 4 * 30, 4 * 31,
|
116 |
|
|
4 * 32, 4 * 33, 4 * 34
|
117 |
|
|
#endif
|
118 |
|
|
};
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
/* -------------------------------------------------------------------------- */
|
122 |
|
|
/*!Predicate to indicate if a register can be read.
|
123 |
|
|
|
124 |
|
|
For now, we believe all OR32 registers are readable.
|
125 |
|
|
|
126 |
|
|
@param[in] regno Register to read.
|
127 |
|
|
|
128 |
|
|
@return Non-zero (TRUE) if the register can be read, zero (FALSE)
|
129 |
|
|
otherwise. */
|
130 |
|
|
/* -------------------------------------------------------------------------- */
|
131 |
|
|
static int
|
132 |
|
|
or32_cannot_fetch_register (int regno)
|
133 |
|
|
{
|
134 |
|
|
return (regno >= or32_num_regs);
|
135 |
|
|
|
136 |
|
|
} /* or32_cannot_fetch_register () */
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
/* -------------------------------------------------------------------------- */
|
140 |
|
|
/*!Predicate to indicate if a register can be written.
|
141 |
|
|
|
142 |
|
|
For now, we believe all OR32 registers are writable.
|
143 |
|
|
|
144 |
|
|
@param[in] regno Register to write.
|
145 |
|
|
|
146 |
|
|
@return Non-zero (TRUE) if the register can be written, zero (FALSE)
|
147 |
|
|
otherwise. */
|
148 |
|
|
/* -------------------------------------------------------------------------- */
|
149 |
|
|
static int
|
150 |
|
|
or32_cannot_store_register (int regno)
|
151 |
|
|
{
|
152 |
|
|
return (regno >= or32_num_regs);
|
153 |
|
|
|
154 |
|
|
} /* or32_cannot_store_register () */
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
/* -------------------------------------------------------------------------- */
|
158 |
|
|
/*!Get the current program counter.
|
159 |
|
|
|
160 |
|
|
On the OR32, this is NPC, the *next* program counter.
|
161 |
|
|
|
162 |
|
|
@param[in] regcache Current register cache.
|
163 |
|
|
|
164 |
|
|
@return The value of the NPC. */
|
165 |
|
|
/* -------------------------------------------------------------------------- */
|
166 |
|
|
static CORE_ADDR
|
167 |
|
|
or32_get_pc (struct regcache *regcache)
|
168 |
|
|
{
|
169 |
|
|
unsigned long int npc;
|
170 |
445 |
julius |
collect_register_by_name (regcache, "npc", &npc);
|
171 |
441 |
jeremybenn |
|
172 |
445 |
julius |
if (debug_threads)
|
173 |
441 |
jeremybenn |
{
|
174 |
|
|
fprintf (stderr, "stop pc is %08lx\n", npc);
|
175 |
|
|
}
|
176 |
445 |
julius |
|
177 |
441 |
jeremybenn |
return npc;
|
178 |
|
|
|
179 |
|
|
} /* or32_get_pc () */
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
/* -------------------------------------------------------------------------- */
|
183 |
|
|
/*!Set the current program counter.
|
184 |
|
|
|
185 |
|
|
On the OR32, this is NPC, the *next* program counter.
|
186 |
|
|
|
187 |
|
|
@param[in] regcache Current register cache.
|
188 |
|
|
@param[in] pc The value of the program counter to set. */
|
189 |
|
|
/* -------------------------------------------------------------------------- */
|
190 |
|
|
static void
|
191 |
|
|
or32_set_pc (struct regcache *regcache,
|
192 |
|
|
CORE_ADDR pc)
|
193 |
|
|
{
|
194 |
|
|
unsigned long int npc = pc;
|
195 |
445 |
julius |
supply_register_by_name (regcache, "npc", &npc);
|
196 |
441 |
jeremybenn |
|
197 |
|
|
} /* or32_set_pc () */
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
/*! The value of a breakpoint instruction (l.trap 1). */
|
201 |
|
|
static const unsigned char or32_breakpoint [] = {0x21, 0x00, 0x00, 0x01};
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
/*! The length of a breakpoint instruction. */
|
205 |
|
|
#define OR32_BREAKPOINT_LEN 4
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
/* -------------------------------------------------------------------------- */
|
209 |
|
|
/*!Predicate to indicate if there is a breakpoint at the current address.
|
210 |
|
|
|
211 |
|
|
For the OR32 we, just look for the l.trap 1 instruction.
|
212 |
|
|
|
213 |
|
|
@param[in] where The address to look for a breakpoint at.
|
214 |
|
|
|
215 |
|
|
@return Non-zero (TRUE) if there is a breakpoint, zero (FALSE) otherwise. */
|
216 |
|
|
/* -------------------------------------------------------------------------- */
|
217 |
|
|
static int
|
218 |
|
|
or32_breakpoint_at (CORE_ADDR where)
|
219 |
|
|
{
|
220 |
|
|
unsigned char insn[OR32_BREAKPOINT_LEN];
|
221 |
|
|
|
222 |
|
|
(*the_target->read_memory) (where, insn, OR32_BREAKPOINT_LEN);
|
223 |
|
|
|
224 |
|
|
return (0 == bcmp (insn, or32_breakpoint, OR32_BREAKPOINT_LEN));
|
225 |
|
|
|
226 |
|
|
} /* or32_breakpoint_at () */
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
/* -------------------------------------------------------------------------- */
|
230 |
|
|
/*!Data structure giving all the target specific functions.
|
231 |
|
|
|
232 |
|
|
Details are in struct linux_target_ops in linux-low.h. */
|
233 |
|
|
/* -------------------------------------------------------------------------- */
|
234 |
|
|
struct linux_target_ops the_low_target = {
|
235 |
|
|
init_registers_or32, /* Arch initialization */
|
236 |
|
|
or32_num_regs, /* Num regs in arch */
|
237 |
|
|
or32_regmap, /* Reg offsets for ptrace */
|
238 |
|
|
or32_cannot_fetch_register, /* Predicate for reg reading */
|
239 |
|
|
or32_cannot_store_register, /* Predicate for reg writing */
|
240 |
|
|
or32_get_pc, /* Read the PC */
|
241 |
|
|
or32_set_pc, /* Write the PC */
|
242 |
|
|
or32_breakpoint, /* Breakpoint instruction bytes */
|
243 |
|
|
OR32_BREAKPOINT_LEN, /* Breakpoint length */
|
244 |
|
|
NULL, /* Breakpoint reinsertion (unused) */
|
245 |
|
|
0, /* Decrement PC after break (FALSE) */
|
246 |
|
|
or32_breakpoint_at, /* Predicate to check for breakpoint */
|
247 |
|
|
NULL, /* Insert matchpoint (unused) */
|
248 |
|
|
NULL, /* Remove matchpoint (unused) */
|
249 |
|
|
NULL, /* Predicate if stopped by watchpoint */
|
250 |
|
|
NULL, /* Data address for watchpoint stop */
|
251 |
|
|
NULL, /* ptrace PEEKUSR hook */
|
252 |
|
|
NULL, /* ptrace POKEUSR hook */
|
253 |
|
|
NULL, /* ptrace conversion predicate */
|
254 |
|
|
NULL, /* New process hook */
|
255 |
|
|
NULL, /* New thread hook */
|
256 |
|
|
NULL, /* Prepare to resume thread */
|
257 |
|
|
NULL, /* Target specific qSupported */
|
258 |
|
|
NULL, /* Tracepoint supported predicate */
|
259 |
|
|
NULL, /* Get thread area address */
|
260 |
|
|
NULL, /* Fast tracepoint jump pad */
|
261 |
|
|
NULL, /* Get bytecode operations vector */
|
262 |
|
|
};
|