OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [gdb/] [gdbserver/] [regcache.c] - Blame information for rev 157

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* Register support routines for the remote server for GDB.
2
   Copyright (C) 2001, 2002, 2004, 2005, 2007, 2008
3
   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 3 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, see <http://www.gnu.org/licenses/>.  */
19
 
20
#include "server.h"
21
#include "regdef.h"
22
 
23
#include <stdlib.h>
24
#include <string.h>
25
 
26
/* The private data for the register cache.  Note that we have one
27
   per inferior; this is primarily for simplicity, as the performance
28
   benefit is minimal.  */
29
 
30
struct inferior_regcache_data
31
{
32
  int registers_valid;
33
  unsigned char *registers;
34
};
35
 
36
static int register_bytes;
37
 
38
static struct reg *reg_defs;
39
static int num_registers;
40
 
41
const char **gdbserver_expedite_regs;
42
 
43
static struct inferior_regcache_data *
44
get_regcache (struct thread_info *inf, int fetch)
45
{
46
  struct inferior_regcache_data *regcache;
47
 
48
  regcache = (struct inferior_regcache_data *) inferior_regcache_data (inf);
49
 
50
  if (regcache == NULL)
51
    fatal ("no register cache");
52
 
53
  /* FIXME - fetch registers for INF */
54
  if (fetch && regcache->registers_valid == 0)
55
    {
56
      fetch_inferior_registers (0);
57
      regcache->registers_valid = 1;
58
    }
59
 
60
  return regcache;
61
}
62
 
63
void
64
regcache_invalidate_one (struct inferior_list_entry *entry)
65
{
66
  struct thread_info *thread = (struct thread_info *) entry;
67
  struct inferior_regcache_data *regcache;
68
 
69
  regcache = (struct inferior_regcache_data *) inferior_regcache_data (thread);
70
 
71
  if (regcache->registers_valid)
72
    {
73
      struct thread_info *saved_inferior = current_inferior;
74
 
75
      current_inferior = thread;
76
      store_inferior_registers (-1);
77
      current_inferior = saved_inferior;
78
    }
79
 
80
  regcache->registers_valid = 0;
81
}
82
 
83
void
84
regcache_invalidate ()
85
{
86
  for_each_inferior (&all_threads, regcache_invalidate_one);
87
}
88
 
89
int
90
registers_length (void)
91
{
92
  return 2 * register_bytes;
93
}
94
 
95
void *
96
new_register_cache (void)
97
{
98
  struct inferior_regcache_data *regcache;
99
 
100
  regcache = malloc (sizeof (*regcache));
101
 
102
  /* Make sure to zero-initialize the register cache when it is created,
103
     in case there are registers the target never fetches.  This way they'll
104
     read as zero instead of garbage.  */
105
  regcache->registers = calloc (1, register_bytes);
106
  if (regcache->registers == NULL)
107
    fatal ("Could not allocate register cache.");
108
 
109
  regcache->registers_valid = 0;
110
 
111
  return regcache;
112
}
113
 
114
void
115
free_register_cache (void *regcache_p)
116
{
117
  struct inferior_regcache_data *regcache
118
    = (struct inferior_regcache_data *) regcache_p;
119
 
120
  free (regcache->registers);
121
  free (regcache);
122
}
123
 
124
void
125
set_register_cache (struct reg *regs, int n)
126
{
127
  int offset, i;
128
 
129
  reg_defs = regs;
130
  num_registers = n;
131
 
132
  offset = 0;
133
  for (i = 0; i < n; i++)
134
    {
135
      regs[i].offset = offset;
136
      offset += regs[i].size;
137
    }
138
 
139
  register_bytes = offset / 8;
140
}
141
 
142
void
143
registers_to_string (char *buf)
144
{
145
  unsigned char *registers = get_regcache (current_inferior, 1)->registers;
146
 
147
  convert_int_to_ascii (registers, buf, register_bytes);
148
}
149
 
150
void
151
registers_from_string (char *buf)
152
{
153
  int len = strlen (buf);
154
  unsigned char *registers = get_regcache (current_inferior, 1)->registers;
155
 
156
  if (len != register_bytes * 2)
157
    {
158
      warning ("Wrong sized register packet (expected %d bytes, got %d)", 2*register_bytes, len);
159
      if (len > register_bytes * 2)
160
        len = register_bytes * 2;
161
    }
162
  convert_ascii_to_int (buf, registers, len / 2);
163
}
164
 
165
struct reg *
166
find_register_by_name (const char *name)
167
{
168
  int i;
169
 
170
  for (i = 0; i < num_registers; i++)
171
    if (!strcmp (name, reg_defs[i].name))
172
      return &reg_defs[i];
173
  fatal ("Unknown register %s requested", name);
174
  return 0;
175
}
176
 
177
int
178
find_regno (const char *name)
179
{
180
  int i;
181
 
182
  for (i = 0; i < num_registers; i++)
183
    if (!strcmp (name, reg_defs[i].name))
184
      return i;
185
  fatal ("Unknown register %s requested", name);
186
  return -1;
187
}
188
 
189
struct reg *
190
find_register_by_number (int n)
191
{
192
  return &reg_defs[n];
193
}
194
 
195
int
196
register_size (int n)
197
{
198
  return reg_defs[n].size / 8;
199
}
200
 
201
static unsigned char *
202
register_data (int n, int fetch)
203
{
204
  unsigned char *registers
205
    = get_regcache (current_inferior, fetch)->registers;
206
 
207
  return registers + (reg_defs[n].offset / 8);
208
}
209
 
210
void
211
supply_register (int n, const void *buf)
212
{
213
  memcpy (register_data (n, 0), buf, register_size (n));
214
}
215
 
216
void
217
supply_register_by_name (const char *name, const void *buf)
218
{
219
  supply_register (find_regno (name), buf);
220
}
221
 
222
void
223
collect_register (int n, void *buf)
224
{
225
  memcpy (buf, register_data (n, 1), register_size (n));
226
}
227
 
228
void
229
collect_register_as_string (int n, char *buf)
230
{
231
  convert_int_to_ascii (register_data (n, 1), buf, register_size (n));
232
}
233
 
234
void
235
collect_register_by_name (const char *name, void *buf)
236
{
237
  collect_register (find_regno (name), buf);
238
}

powered by: WebSVN 2.1.0

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