diff mbox

[4/8] AARCH64 SVE: Regcache compare methods

Message ID D46B0DD8.154F2%alan.hayward@arm.com
State New
Headers show

Commit Message

Alan Hayward Dec. 5, 2016, 12:28 p.m. UTC
This is part of a series adding AARCH64 SVE support to gdb and gdbserver.

This patch simply adds two methods for comparing a register value to a
buffer.
The function will ignore the first OFFSET bytes of the register value -
this
is used in a later patch where we check if the value of a Z register is
able
to fit into a V register.

Tested on x86 and aarch64.
Ok to commit?

Alan.



    set to or from a buffer.  This is the main worker function for
    regcache_supply_regset and regcache_collect_regset.  */
diff mbox

Patch

diff --git a/gdb/gdbserver/regcache.h b/gdb/gdbserver/regcache.h
index 
2209915ffea2737eaf166d697c9e122182792092..4535d23622090a460de81f8dbbf144844
48d3c83 100644
--- a/gdb/gdbserver/regcache.h
+++ b/gdb/gdbserver/regcache.h
@@ -120,4 +120,9 @@  void collect_register_as_string (struct regcache
*regcache, int n, char *buf);
 void collect_register_by_name (struct regcache *regcache,
 			       const char *name, void *buf);

+/* Compare the value of a register (ignoring the first OFFSET bytes) to a
+   value in a BUF.  Returns 0 if identical.  */
+
+int compare_register (struct regcache *regcache, int n, void *buf, int
offset);
+
 #endif /* REGCACHE_H */
diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index 
2af8e241d98db5a8795682aa203f1585a4820ddb..752148042f26e1a23c9d0b1b7fb5d14ca
b2bf538 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -489,3 +489,14 @@  regcache_write_pc (struct regcache *regcache,
CORE_ADDR pc)
 }

 #endif
+
+/* Compare the value of a register (ignoring the first OFFSET bytes) to a
+   value in a BUF.  Returns 0 if identical.  */
+
+int
+compare_register (struct regcache *regcache, int n, void *buf, int offset)
+{
+  gdb_assert (register_size (regcache->tdesc, n) > offset);
+  return memcmp (buf, register_data (regcache, n, 1) + offset,
+		 register_size (regcache->tdesc, n) - offset);
+}
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 
11a8bb98d69d0c32def1d3f5d2d68dd82900357f..20696415eb579774f6c0adb251b5e8be1
36cbcf1 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -144,6 +144,12 @@  extern void regcache_raw_supply (struct regcache
*regcache,
 extern void regcache_raw_collect (const struct regcache *regcache,
 				  int regnum, void *buf);

+/* Compare the value of a register (ignoring the first OFFSET bytes) to a
+   value in a BUF.  Returns 0 if identical.  */
+
+extern int regcache_raw_compare (const struct regcache *regcache, int
regnum,
+				 void *buf, int offset);
+
 /* Mapping between register numbers and offsets in a buffer, for use
    in the '*regset' functions below.  In an array of
    'regcache_map_entry' each element is interpreted like follows:
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 
1fcf93386f7d3d4180ab6dad4f228566563855b2..368463129f2e1ba7d0b90b7baf590f731
e5fe36e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1112,6 +1112,26 @@  regcache_raw_collect (const struct regcache
*regcache, int regnum, void *buf)
   memcpy (buf, regbuf, size);
 }

+/* Compare the value of a register (ignoring the first OFFSET bytes) to a
+   value in a BUF.  Returns 0 if identical.  */
+
+int
+regcache_raw_compare (const struct regcache *regcache, int regnum, void
*buf,
+		      int offset)
+{
+  const char *regbuf;
+  size_t size;
+
+  gdb_assert (regcache != NULL && buf != NULL);
+  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+
+  regbuf = (const char *) register_buffer (regcache, regnum);
+  size = regcache->descr->sizeof_register[regnum];
+  gdb_assert (size > offset);
+
+  return memcmp (buf, regbuf + offset, size - offset);
+}
+
 /* Transfer a single or all registers belonging to a certain register