reg_t -> struct reg
[openocd.git] / src / target / register.c
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, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "register.h"
28 #include "log.h"
29
30
31 struct reg_arch_type *reg_arch_types = NULL;
32
33 struct reg* register_get_by_name(struct reg_cache *first,
34 const char *name, bool search_all)
35 {
36 int i;
37 struct reg_cache *cache = first;
38
39 while (cache)
40 {
41 for (i = 0; i < cache->num_regs; i++)
42 {
43 if (strcmp(cache->reg_list[i].name, name) == 0)
44 return &(cache->reg_list[i]);
45 }
46
47 if (search_all)
48 cache = cache->next;
49 else
50 break;
51 }
52
53 return NULL;
54 }
55
56 struct reg_cache** register_get_last_cache_p(struct reg_cache **first)
57 {
58 struct reg_cache **cache_p = first;
59
60 if (*cache_p)
61 while (*cache_p)
62 cache_p = &((*cache_p)->next);
63 else
64 return first;
65
66 return cache_p;
67 }
68
69 int register_reg_arch_type(int (*get)(struct reg *reg), int (*set)(struct reg *reg, uint8_t *buf))
70 {
71 struct reg_arch_type** arch_type_p = &reg_arch_types;
72 int id = 0;
73
74 if (*arch_type_p)
75 {
76 while (*arch_type_p)
77 {
78 id = (*arch_type_p)->id;
79 arch_type_p = &((*arch_type_p)->next);
80 }
81 }
82
83 (*arch_type_p) = malloc(sizeof(struct reg_arch_type));
84 (*arch_type_p)->id = id + 1;
85 (*arch_type_p)->set = set;
86 (*arch_type_p)->get = get;
87 (*arch_type_p)->next = NULL;
88
89 return id + 1;
90 }
91
92 struct reg_arch_type* register_get_arch_type(int id)
93 {
94 struct reg_arch_type *arch_type = reg_arch_types;
95
96 while (arch_type)
97 {
98 if (arch_type->id == id)
99 return arch_type;
100 arch_type = arch_type->next;
101 }
102 LOG_ERROR("BUG: encountered unregistered arch type 0x%08x", id);
103 exit(-1);
104 return NULL;
105 }
106
107 static int register_get_dummy_core_reg(struct reg *reg)
108 {
109 return ERROR_OK;
110 }
111
112 static int register_set_dummy_core_reg(struct reg *reg, uint8_t *buf)
113 {
114 reg->dirty = 1;
115 reg->valid = 1;
116
117 return ERROR_OK;
118 }
119
120 void register_init_dummy(struct reg *reg)
121 {
122 static int dummy_arch_type = -1;
123 if (dummy_arch_type == -1)
124 dummy_arch_type = register_reg_arch_type(register_get_dummy_core_reg, register_set_dummy_core_reg);
125
126 reg->arch_type = dummy_arch_type;
127 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)