1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2005 by Dominic Rath *
5 * Dominic.Rath@gmx.de *
7 * Copyright (C) 2007,2008 Øyvind Harboe *
8 * oyvind.harboe@zylin.com *
9 ***************************************************************************/
16 #include <helper/log.h>
20 * Holds utilities to work with register caches.
22 * OpenOCD uses machine registers internally, and exposes them by name
23 * to Tcl scripts. Sets of related registers are grouped into caches.
24 * For example, a CPU core will expose a set of registers, and there
25 * may be separate registers associated with debug or trace modules.
28 struct reg *register_get_by_number(struct reg_cache *first,
29 uint32_t reg_num, bool search_all)
31 struct reg_cache *cache = first;
34 for (unsigned int i = 0; i < cache->num_regs; i++) {
35 if (!cache->reg_list[i].exist)
37 if (cache->reg_list[i].number == reg_num)
38 return &(cache->reg_list[i]);
50 struct reg *register_get_by_name(struct reg_cache *first,
51 const char *name, bool search_all)
53 struct reg_cache *cache = first;
56 for (unsigned int i = 0; i < cache->num_regs; i++) {
57 if (!cache->reg_list[i].exist)
59 if (strcmp(cache->reg_list[i].name, name) == 0)
60 return &(cache->reg_list[i]);
72 struct reg_cache **register_get_last_cache_p(struct reg_cache **first)
74 struct reg_cache **cache_p = first;
78 cache_p = &((*cache_p)->next);
85 void register_unlink_cache(struct reg_cache **cache_p, const struct reg_cache *cache)
87 while (*cache_p && *cache_p != cache)
88 cache_p = &((*cache_p)->next);
90 *cache_p = cache->next;
93 /** Marks the contents of the register cache as invalid (and clean). */
94 void register_cache_invalidate(struct reg_cache *cache)
96 struct reg *reg = cache->reg_list;
98 for (unsigned int n = cache->num_regs; n != 0; n--, reg++) {
106 static int register_get_dummy_core_reg(struct reg *reg)
111 static int register_set_dummy_core_reg(struct reg *reg, uint8_t *buf)
119 static const struct reg_arch_type dummy_type = {
120 .get = register_get_dummy_core_reg,
121 .set = register_set_dummy_core_reg,
124 void register_init_dummy(struct reg *reg)
126 reg->type = &dummy_type;