2002-04-20 Daniel Jacobowitz <drow@mvista.com>
[deliverable/binutils-gdb.git] / gdb / gdbserver / regcache.c
CommitLineData
0a30fbc4
DJ
1/* Register support routines for the remote server for GDB.
2 Copyright 2001, 2002
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 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22#include "server.h"
23#include "regdef.h"
24
25#include <stdlib.h>
26#include <string.h>
27
28static char *registers;
29static int register_bytes;
30
31static struct reg *reg_defs;
32static int num_registers;
33
34const char **gdbserver_expedite_regs;
35
36int
37registers_length (void)
38{
39 return 2 * register_bytes;
40}
41
42void
43set_register_cache (struct reg *regs, int n)
44{
45 int offset, i;
46
47 reg_defs = regs;
48 num_registers = n;
49
50 offset = 0;
51 for (i = 0; i < n; i++)
52 {
53 regs[i].offset = offset;
54 offset += regs[i].size;
55 }
56
57 register_bytes = offset / 8;
58 registers = malloc (offset / 8);
59 if (!registers)
60 fatal ("Could not allocate register cache.");
61}
62
63void
64registers_to_string (char *buf)
65{
66 convert_int_to_ascii (registers, buf, register_bytes);
67}
68
69void
70registers_from_string (char *buf)
71{
72 int len = strlen (buf);
73
74 if (len != register_bytes * 2)
75 {
76 warning ("Wrong sized register packet (expected %d bytes, got %d)", 2*register_bytes, len);
77 if (len > register_bytes * 2)
78 len = register_bytes * 2;
79 }
80 convert_ascii_to_int (buf, registers, len / 2);
81}
82
83struct reg *
84find_register_by_name (const char *name)
85{
86 int i;
87
88 for (i = 0; i < num_registers; i++)
89 if (!strcmp (name, reg_defs[i].name))
90 return &reg_defs[i];
91 fatal ("Unknown register %s requested", name);
92 return 0;
93}
94
95int
96find_regno (const char *name)
97{
98 int i;
99
100 for (i = 0; i < num_registers; i++)
101 if (!strcmp (name, reg_defs[i].name))
102 return i;
103 fatal ("Unknown register %s requested", name);
104 return -1;
105}
106
107struct reg *
108find_register_by_number (int n)
109{
110 return &reg_defs[n];
111}
112
113int
114register_size (int n)
115{
116 return reg_defs[n].size / 8;
117}
118
119char *
120register_data (int n)
121{
122 return registers + (reg_defs[n].offset / 8);
123}
124
58caa3dc 125void
0729219d 126supply_register (int n, const void *buf)
58caa3dc
DJ
127{
128 memcpy (register_data (n), buf, register_size (n));
129}
130
131void
0729219d 132supply_register_by_name (const char *name, const void *buf)
58caa3dc
DJ
133{
134 supply_register (find_regno (name), buf);
135}
136
137void
0729219d 138collect_register (int n, void *buf)
58caa3dc
DJ
139{
140 memcpy (buf, register_data (n), register_size (n));
141}
142
143void
0729219d 144collect_register_by_name (const char *name, void *buf)
58caa3dc
DJ
145{
146 collect_register (find_regno (name), buf);
147}
This page took 0.043974 seconds and 4 git commands to generate.