X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Fregister.c;h=1c1717c8ff3b39342c12f5ba3e1f7f82546371eb;hp=d9ef53e31f0e43a2929bf8fd6aa22bffb57b51dd;hb=11b6ab90fb59bb2f794bbf7ca4cb89964ead6280;hpb=f4788652e45662d1e43933dc0620561bc4cddae0 diff --git a/src/target/register.c b/src/target/register.c index d9ef53e31f..1c1717c8ff 100644 --- a/src/target/register.c +++ b/src/target/register.c @@ -18,27 +18,34 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * ***************************************************************************/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "types.h" #include "register.h" -#include "log.h" +#include +/** + * @file + * Holds utilities to work with register caches. + * + * OpenOCD uses machine registers internally, and exposes them by name + * to Tcl scripts. Sets of related registers are grouped into caches. + * For example, a CPU core will expose a set of registers, and there + * may be separate registers associated with debug or trace modules. + */ -struct reg* register_get_by_name(struct reg_cache *first, +struct reg *register_get_by_name(struct reg_cache *first, const char *name, bool search_all) { - int i; + unsigned i; struct reg_cache *cache = first; - while (cache) - { - for (i = 0; i < cache->num_regs; i++) - { + while (cache) { + for (i = 0; i < cache->num_regs; i++) { if (strcmp(cache->reg_list[i].name, name) == 0) return &(cache->reg_list[i]); } @@ -52,7 +59,7 @@ struct reg* register_get_by_name(struct reg_cache *first, return NULL; } -struct reg_cache** register_get_last_cache_p(struct reg_cache **first) +struct reg_cache **register_get_last_cache_p(struct reg_cache **first) { struct reg_cache **cache_p = first; @@ -65,6 +72,25 @@ struct reg_cache** register_get_last_cache_p(struct reg_cache **first) return cache_p; } +void register_unlink_cache(struct reg_cache **cache_p, const struct reg_cache *cache) +{ + while (*cache_p && *cache_p != cache) + cache_p = &((*cache_p)->next); + if (*cache_p) + *cache_p = cache->next; +} + +/** Marks the contents of the register cache as invalid (and clean). */ +void register_cache_invalidate(struct reg_cache *cache) +{ + struct reg *reg = cache->reg_list; + + for (unsigned n = cache->num_regs; n != 0; n--, reg++) { + reg->valid = 0; + reg->dirty = 0; + } +} + static int register_get_dummy_core_reg(struct reg *reg) { return ERROR_OK;