OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [gdb/] [gdbserver/] [linux-or32-low.c] - Blame information for rev 453

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 447 jeremybenn
 
43
/* -------------------------------------------------------------------------- */
44
/*!Global register map
45
 
46
   This should be in GDB order (r0-r1, ppc, npc, sr) to ptrace offset.
47
 
48
   ptrace does not support r0 (so we use r31 for now), nor ppc (so we use npc
49
   for now).
50
 
51
   @note This must be a global variable.
52
 
53
   @todo Fix r0 and ppc (needs ptrace changes).                               */
54
/* -------------------------------------------------------------------------- */
55 446 julius
struct reg regs_or32[] = {
56 447 jeremybenn
  { "r0",  GPR31 * 8, 32 },
57
  { "sp",  SP    * 8, 32 },
58
  { "fp",  GPR2  * 8, 32 },
59
  { "r3",  GPR3  * 8, 32 },
60
  { "r4",  GPR4  * 8, 32 },
61
  { "r5",  GPR5  * 8, 32 },
62
  { "r6",  GPR6  * 8, 32 },
63
  { "r7",  GPR7  * 8, 32 },
64
  { "r8",  GPR8  * 8, 32 },
65
  { "lr",  GPR9  * 8, 32 },
66
  { "r10", GPR10 * 8, 32 },
67
  { "r11", GPR11 * 8, 32 },
68
  { "r12", GPR12 * 8, 32 },
69
  { "r13", GPR13 * 8, 32 },
70
  { "r14", GPR14 * 8, 32 },
71
  { "r15", GPR15 * 8, 32 },
72
  { "r16", GPR16 * 8, 32 },
73
  { "r17", GPR17 * 8, 32 },
74
  { "r18", GPR18 * 8, 32 },
75
  { "r19", GPR19 * 8, 32 },
76
  { "r20", GPR20 * 8, 32 },
77
  { "r21", GPR21 * 8, 32 },
78
  { "r22", GPR22 * 8, 32 },
79
  { "r23", GPR23 * 8, 32 },
80
  { "r24", GPR24 * 8, 32 },
81
  { "r25", GPR25 * 8, 32 },
82
  { "r26", GPR26 * 8, 32 },
83
  { "r27", GPR27 * 8, 32 },
84
  { "r28", GPR28 * 8, 32 },
85
  { "r29", GPR29 * 8, 32 },
86
  { "r30", GPR30 * 8, 32 },
87
  { "r31", GPR31 * 8, 32 },
88
  { "ppc", PC    * 8, 32 },
89
  { "npc", PC    * 8, 32 },
90
  { "sr",  SR    * 8, 32 }
91
};
92 446 julius
 
93
/* -------------------------------------------------------------------------- */
94
/*!Initialize the register data.
95
 
96
  Should be automagically created from a data file in gdb/regformats, but for
97
  now we do it manually.                                                      */
98
/* -------------------------------------------------------------------------- */
99
static void
100
init_registers_or32 ()
101
{
102
 
103 441 jeremybenn
  static const char *expedite_regs_or32[] = { "sp", "lr", "npc", 0 };
104
 
105
  set_register_cache (regs_or32, sizeof (regs_or32) / sizeof (regs_or32[0]));
106
  gdbserver_expedite_regs = expedite_regs_or32;
107
  gdbserver_xmltarget     = NULL;
108
}
109
 
110
 
111 453 jeremybenn
/*! Some useful GDB register numbers. */
112
#define GDB_REGNUM_R0    0
113
#define GDB_REGNUM_R31  31
114
#define GDB_REGNUM_PPC  32
115
#define GDB_REGNUM_NPC  33
116
#define GDB_REGNUM_SR   34
117
 
118 447 jeremybenn
/*! This is the number of *GDB* registers. I.e. r0-r31, PPC, NPC and SR. */
119 453 jeremybenn
#define or32_num_regs  (GDB_REGNUM_SR + 1)
120 441 jeremybenn
 
121
 
122
/* -------------------------------------------------------------------------- */
123
/*!Provide the ptrace "address" of a register.
124 447 jeremybenn
 
125
   This must be in GDB order (r0-r1, ppc, npc, sr) to ptrace offset. As with
126
   regs_or32, we substitute r31 for r0 and NPC for PPC.                       */
127 441 jeremybenn
/* -------------------------------------------------------------------------- */
128
static int or32_regmap[] = {
129 447 jeremybenn
  GPR31, SP,    GPR2,  GPR3,  GPR4,  GPR5,  GPR6,  GPR7,
130
  GPR8,  GPR9,  GPR10, GPR11, GPR12, GPR13, GPR14, GPR15,
131
  GPR16, GPR17, GPR18, GPR19, GPR20, GPR21, GPR22, GPR23,
132
  GPR24, GPR25, GPR26, GPR27, GPR28, GPR29, GPR30, GPR31,
133
  PC,    PC,    SR
134 441 jeremybenn
};
135
 
136
 
137
/* -------------------------------------------------------------------------- */
138
/*!Predicate to indicate if a register can be read.
139
 
140 453 jeremybenn
   We mark r0 as not readable.
141 441 jeremybenn
 
142
   @param[in] regno  Register to read.
143
 
144
   @return  Non-zero (TRUE) if the register can be read, zero (FALSE)
145
            otherwise.                                                        */
146
/* -------------------------------------------------------------------------- */
147
static int
148
or32_cannot_fetch_register (int  regno)
149
{
150 453 jeremybenn
  return (GDB_REGNUM_R0 == regno) || (regno >= or32_num_regs);
151 441 jeremybenn
 
152
}       /* or32_cannot_fetch_register () */
153
 
154
 
155
/* -------------------------------------------------------------------------- */
156
/*!Predicate to indicate if a register can be written.
157
 
158 453 jeremybenn
   We mark r0 and the SR as not writeable.
159 441 jeremybenn
 
160
   @param[in] regno  Register to write.
161
 
162
   @return  Non-zero (TRUE) if the register can be written, zero (FALSE)
163
            otherwise.                                                        */
164
/* -------------------------------------------------------------------------- */
165
static int
166
or32_cannot_store_register (int  regno)
167
{
168 453 jeremybenn
  return (GDB_REGNUM_R0 == regno) || (GDB_REGNUM_SR == regno) ||
169
         (regno >= or32_num_regs);
170 441 jeremybenn
 
171
}       /* or32_cannot_store_register () */
172
 
173
 
174
/* -------------------------------------------------------------------------- */
175
/*!Get the current program counter.
176
 
177
   On the OR32, this is NPC, the *next* program counter.
178
 
179
   @param[in] regcache  Current register cache.
180
 
181
   @return  The value of the NPC.                                             */
182
/* -------------------------------------------------------------------------- */
183
static CORE_ADDR
184
or32_get_pc (struct regcache *regcache)
185
{
186
  unsigned long int  npc;
187 445 julius
  collect_register_by_name (regcache, "npc", &npc);
188 441 jeremybenn
 
189 445 julius
    if (debug_threads)
190 441 jeremybenn
    {
191
      fprintf (stderr, "stop pc is %08lx\n", npc);
192
    }
193 445 julius
 
194 441 jeremybenn
  return  npc;
195
 
196
}       /* or32_get_pc () */
197
 
198
 
199
/* -------------------------------------------------------------------------- */
200
/*!Set the current program counter.
201
 
202
   On the OR32, this is NPC, the *next* program counter.
203
 
204
   @param[in] regcache  Current register cache.
205
   @param[in] pc        The value of the program counter to set.              */
206
/* -------------------------------------------------------------------------- */
207
static void
208
or32_set_pc (struct regcache *regcache,
209
             CORE_ADDR        pc)
210
{
211
  unsigned long int  npc = pc;
212 445 julius
  supply_register_by_name (regcache, "npc", &npc);
213 441 jeremybenn
 
214
}       /* or32_set_pc () */
215
 
216
 
217
/*! The value of a breakpoint instruction (l.trap  1). */
218
static const unsigned char or32_breakpoint [] = {0x21, 0x00, 0x00, 0x01};
219
 
220
 
221
/*! The length of a breakpoint instruction. */
222
#define OR32_BREAKPOINT_LEN  4
223
 
224
 
225
/* -------------------------------------------------------------------------- */
226
/*!Predicate to indicate if there is a breakpoint at the current address.
227
 
228
   For the OR32 we, just look for the l.trap 1 instruction.
229
 
230
   @param[in] where  The address to look for a breakpoint at.
231
 
232
   @return  Non-zero (TRUE) if there is a breakpoint, zero (FALSE) otherwise. */
233
/* -------------------------------------------------------------------------- */
234
static int
235
or32_breakpoint_at (CORE_ADDR where)
236
{
237
  unsigned char  insn[OR32_BREAKPOINT_LEN];
238
 
239
  (*the_target->read_memory) (where, insn, OR32_BREAKPOINT_LEN);
240
 
241
  return  (0 ==  bcmp (insn, or32_breakpoint, OR32_BREAKPOINT_LEN));
242
 
243
}       /* or32_breakpoint_at () */
244
 
245
 
246
/* -------------------------------------------------------------------------- */
247
/*!Data structure giving all the target specific functions.
248
 
249
   Details are in struct linux_target_ops in linux-low.h.                     */
250
/* -------------------------------------------------------------------------- */
251
struct linux_target_ops the_low_target = {
252
  init_registers_or32,                  /* Arch initialization */
253
  or32_num_regs,                        /* Num regs in arch */
254
  or32_regmap,                          /* Reg offsets for ptrace */
255
  or32_cannot_fetch_register,           /* Predicate for reg reading */
256
  or32_cannot_store_register,           /* Predicate for reg writing */
257
  or32_get_pc,                          /* Read the PC */
258
  or32_set_pc,                          /* Write the PC */
259
  or32_breakpoint,                      /* Breakpoint instruction bytes */
260
  OR32_BREAKPOINT_LEN,                  /* Breakpoint length */
261
  NULL,                                 /* Breakpoint reinsertion (unused) */
262
  0,                                     /* Decrement PC after break (FALSE) */
263
  or32_breakpoint_at,                   /* Predicate to check for breakpoint */
264
  NULL,                                 /* Insert matchpoint (unused) */
265
  NULL,                                 /* Remove matchpoint (unused) */
266
  NULL,                                 /* Predicate if stopped by watchpoint */
267
  NULL,                                 /* Data address for watchpoint stop */
268
  NULL,                                 /* ptrace PEEKUSR hook */
269
  NULL,                                 /* ptrace POKEUSR hook */
270
  NULL,                                 /* ptrace conversion predicate */
271
  NULL,                                 /* New process hook */
272
  NULL,                                 /* New thread hook */
273
  NULL,                                 /* Prepare to resume thread */
274
  NULL,                                 /* Target specific qSupported */
275
  NULL,                                 /* Tracepoint supported predicate */
276
  NULL,                                 /* Get thread area address */
277
  NULL,                                 /* Fast tracepoint jump pad */
278
  NULL,                                 /* Get bytecode operations vector */
279
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.