ioutil: make the file compile on MacOS
[fw/openocd] / src / target / register.c
index d9ef53e31f0e43a2929bf8fd6aa22bffb57b51dd..ab1e40b17a10d63cf89f2fdb4edfd7e9ccf5c6f4 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include "types.h"
 #include "register.h"
-#include "log.h"
+#include <helper/log.h>
 
+/**
+ * @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 regregister_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,17 @@ struct reg_cache** register_get_last_cache_p(struct reg_cache **first)
        return cache_p;
 }
 
+/** 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;