a7705f76e089bed004be1ce7c3a704d30b28a0c8
[fw/openocd] / src / target / register.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
6  *   oyvind.harboe@zylin.com                                               *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
20  ***************************************************************************/
21
22 #ifndef OPENOCD_TARGET_REGISTER_H
23 #define OPENOCD_TARGET_REGISTER_H
24
25 #include "helper/replacements.h"
26 #include "helper/types.h"
27
28 struct target;
29
30 enum reg_type {
31         REG_TYPE_BOOL,
32         REG_TYPE_INT,
33         REG_TYPE_INT8,
34         REG_TYPE_INT16,
35         REG_TYPE_INT32,
36         REG_TYPE_INT64,
37         REG_TYPE_INT128,
38         REG_TYPE_UINT,
39         REG_TYPE_UINT8,
40         REG_TYPE_UINT16,
41         REG_TYPE_UINT32,
42         REG_TYPE_UINT64,
43         REG_TYPE_UINT128,
44         REG_TYPE_CODE_PTR,
45         REG_TYPE_DATA_PTR,
46         REG_TYPE_FLOAT,
47         REG_TYPE_IEEE_SINGLE,
48         REG_TYPE_IEEE_DOUBLE,
49         REG_TYPE_ARCH_DEFINED,
50 };
51
52 struct reg_feature {
53         const char *name;
54 };
55
56 struct reg_data_type_vector {
57         struct reg_data_type *type;
58         uint32_t count;
59 };
60
61 struct reg_data_type_union_field {
62         const char *name;
63         struct reg_data_type *type;
64         struct reg_data_type_union_field *next;
65 };
66
67 struct reg_data_type_union {
68         struct reg_data_type_union_field *fields;
69 };
70
71 struct reg_data_type_bitfield {
72         uint32_t start;
73         uint32_t end;
74         enum reg_type type;
75 };
76
77 struct reg_data_type_struct_field {
78         const char *name;
79         bool use_bitfields;
80         union {
81                 struct reg_data_type_bitfield *bitfield;
82                 struct reg_data_type *type;
83         };
84         struct reg_data_type_struct_field *next;
85 };
86
87 struct reg_data_type_struct {
88         uint32_t size;
89         struct reg_data_type_struct_field *fields;
90 };
91
92 struct reg_data_type_flags_field {
93         const char *name;
94         struct reg_data_type_bitfield *bitfield;
95         struct reg_data_type_flags_field *next;
96 };
97
98 struct reg_data_type_flags {
99         uint32_t size;
100         struct reg_data_type_flags_field *fields;
101 };
102
103 enum reg_data_type_class {
104         REG_TYPE_CLASS_VECTOR,
105         REG_TYPE_CLASS_UNION,
106         REG_TYPE_CLASS_STRUCT,
107         REG_TYPE_CLASS_FLAGS,
108 };
109
110 struct reg_data_type {
111         enum reg_type type;
112         const char *id;
113         enum reg_data_type_class type_class;
114         union {
115                 struct reg_data_type_vector *reg_type_vector;
116                 struct reg_data_type_union *reg_type_union;
117                 struct reg_data_type_struct *reg_type_struct;
118                 struct reg_data_type_flags *reg_type_flags;
119         };
120 };
121
122 struct reg {
123         /* Canonical name of the register. */
124         const char *name;
125         /* Number that gdb uses to access this register. */
126         uint32_t number;
127         /* TODO. This should probably be const. */
128         struct reg_feature *feature;
129         /* TODO: When true, the caller will save this register before running any algorithm. */
130         bool caller_save;
131         /* Pointer to place where the value is stored, in the format understood by
132          * the binarybuffer.h functions. */
133         uint8_t *value;
134         /* The stored value needs to be written to the target. */
135         bool dirty;
136         /* When true, value is valid. */
137         bool valid;
138         /* When false, the register doesn't actually exist in the target. */
139         bool exist;
140         /* Hide the register from gdb and omit it in 'reg' cmd output */
141         bool hidden;
142         /* Size of the register in bits. */
143         uint32_t size;
144         /* Used for generating XML description of registers. Can be set to NULL for
145          * targets that don't use that. */
146         struct reg_data_type *reg_data_type;
147         /* Used for generating XML description of registers. Can be set to NULL for
148          * targets that don't use that. */
149         const char *group;
150         /* Pointer to architecture-specific info for this register. */
151         void *arch_info;
152         const struct reg_arch_type *type;
153 };
154
155 struct reg_cache {
156         const char *name;
157         struct reg_cache *next;
158         struct reg *reg_list;
159         unsigned num_regs;
160 };
161
162 struct reg_arch_type {
163         int (*get)(struct reg *reg);
164         int (*set)(struct reg *reg, uint8_t *buf);
165 };
166
167 struct reg *register_get_by_number(struct reg_cache *first,
168                 uint32_t reg_num, bool search_all);
169 struct reg *register_get_by_name(struct reg_cache *first,
170                 const char *name, bool search_all);
171 struct reg_cache **register_get_last_cache_p(struct reg_cache **first);
172 void register_unlink_cache(struct reg_cache **cache_p, const struct reg_cache *cache);
173 void register_cache_invalidate(struct reg_cache *cache);
174
175 void register_init_dummy(struct reg *reg);
176
177 #endif /* OPENOCD_TARGET_REGISTER_H */