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 struct target;
26 
27 enum reg_type {
28 	REG_TYPE_BOOL,
29 	REG_TYPE_INT,
30 	REG_TYPE_INT8,
31 	REG_TYPE_INT16,
32 	REG_TYPE_INT32,
33 	REG_TYPE_INT64,
34 	REG_TYPE_INT128,
35 	REG_TYPE_UINT,
36 	REG_TYPE_UINT8,
37 	REG_TYPE_UINT16,
38 	REG_TYPE_UINT32,
39 	REG_TYPE_UINT64,
40 	REG_TYPE_UINT128,
41 	REG_TYPE_CODE_PTR,
42 	REG_TYPE_DATA_PTR,
43 	REG_TYPE_FLOAT,
44 	REG_TYPE_IEEE_SINGLE,
45 	REG_TYPE_IEEE_DOUBLE,
46 	REG_TYPE_ARCH_DEFINED,
47 };
48 
49 struct reg_feature {
50 	const char *name;
51 };
52 
53 struct reg_data_type_vector {
54 	struct reg_data_type *type;
55 	uint32_t count;
56 };
57 
58 struct reg_data_type_union_field {
59 	const char *name;
60 	struct reg_data_type *type;
61 	struct reg_data_type_union_field *next;
62 };
63 
64 struct reg_data_type_union {
65 	struct reg_data_type_union_field *fields;
66 };
67 
68 struct reg_data_type_bitfield {
69 	uint32_t start;
70 	uint32_t end;
71 	enum reg_type type;
72 };
73 
74 struct reg_data_type_struct_field {
75 	const char *name;
76 	bool use_bitfields;
77 	union {
78 		struct reg_data_type_bitfield *bitfield;
79 		struct reg_data_type *type;
80 	};
81 	struct reg_data_type_struct_field *next;
82 };
83 
84 struct reg_data_type_struct {
85 	uint32_t size;
86 	struct reg_data_type_struct_field *fields;
87 };
88 
89 struct reg_data_type_flags_field {
90 	const char *name;
91 	struct reg_data_type_bitfield *bitfield;
92 	struct reg_data_type_flags_field *next;
93 };
94 
95 struct reg_data_type_flags {
96 	uint32_t size;
97 	struct reg_data_type_flags_field *fields;
98 };
99 
100 enum reg_data_type_class {
101 	REG_TYPE_CLASS_VECTOR,
102 	REG_TYPE_CLASS_UNION,
103 	REG_TYPE_CLASS_STRUCT,
104 	REG_TYPE_CLASS_FLAGS,
105 };
106 
107 struct reg_data_type {
108 	enum reg_type type;
109 	const char *id;
110 	enum reg_data_type_class type_class;
111 	union {
112 		struct reg_data_type_vector *reg_type_vector;
113 		struct reg_data_type_union *reg_type_union;
114 		struct reg_data_type_struct *reg_type_struct;
115 		struct reg_data_type_flags *reg_type_flags;
116 	};
117 };
118 
119 struct reg {
120 	/* Canonical name of the register. */
121 	const char *name;
122 	/* Number that gdb uses to access this register. */
123 	uint32_t number;
124 	/* TODO. This should probably be const. */
125 	struct reg_feature *feature;
126 	/* TODO: When true, the caller will save this register before running any algorithm. */
127 	bool caller_save;
128 	/* Pointer to place where the value is stored, in the format understood by
129 	 * the binarybuffer.h functions. */
130 	uint8_t *value;
131 	/* The stored value needs to be written to the target. */
132 	bool dirty;
133 	/* When true, value is valid. */
134 	bool valid;
135 	/* When false, the register doesn't actually exist in the target. */
136 	bool exist;
137 	/* Hide the register from gdb and omit it in 'reg' cmd output */
138 	bool hidden;
139 	/* Size of the register in bits. */
140 	uint32_t size;
141 	/* Used for generating XML description of registers. Can be set to NULL for
142 	 * targets that don't use that. */
143 	struct reg_data_type *reg_data_type;
144 	/* Used for generating XML description of registers. Can be set to NULL for
145 	 * targets that don't use that. */
146 	const char *group;
147 	/* Pointer to architecture-specific info for this register. */
148 	void *arch_info;
149 	const struct reg_arch_type *type;
150 };
151 
152 struct reg_cache {
153 	const char *name;
154 	struct reg_cache *next;
155 	struct reg *reg_list;
156 	unsigned num_regs;
157 };
158 
159 struct reg_arch_type {
160 	int (*get)(struct reg *reg);
161 	int (*set)(struct reg *reg, uint8_t *buf);
162 };
163 
164 struct reg *register_get_by_number(struct reg_cache *first,
165 		uint32_t reg_num, bool search_all);
166 struct reg *register_get_by_name(struct reg_cache *first,
167 		const char *name, bool search_all);
168 struct reg_cache **register_get_last_cache_p(struct reg_cache **first);
169 void register_unlink_cache(struct reg_cache **cache_p, const struct reg_cache *cache);
170 void register_cache_invalidate(struct reg_cache *cache);
171 
172 void register_init_dummy(struct reg *reg);
173 
174 #endif /* OPENOCD_TARGET_REGISTER_H */
175