]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add test for address size override prefixes for REP prefixed string
authorTom Hughes <tom@compton.nu>
Fri, 12 Aug 2011 15:43:31 +0000 (15:43 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 12 Aug 2011 15:43:31 +0000 (15:43 +0000)
instructions on amd64. Fixes remaining issues from #211371.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11969

none/tests/amd64/Makefile.am
none/tests/amd64/asorep.c [new file with mode: 0644]
none/tests/amd64/asorep.stderr.exp [new file with mode: 0644]
none/tests/amd64/asorep.stdout.exp [new file with mode: 0644]
none/tests/amd64/asorep.vgtest [new file with mode: 0644]

index 215cc3f7f07579de6fda94e22c2a0aa5f508f727..5f1b08e86ab75a386b13e46e1126fa133267a9a1 100644 (file)
@@ -22,6 +22,7 @@ endif
 
 EXTRA_DIST = \
        amd64locked.vgtest amd64locked.stdout.exp amd64locked.stderr.exp \
+       asorep.stderr.exp asorep.stdout.exp asorep.vgtest \
        bug127521-64.vgtest bug127521-64.stdout.exp bug127521-64.stderr.exp \
        bug132813-amd64.vgtest bug132813-amd64.stdout.exp \
        bug132813-amd64.stderr.exp \
@@ -66,6 +67,7 @@ EXTRA_DIST = \
 
 check_PROGRAMS = \
        amd64locked \
+       asorep \
        bug127521-64 bug132813-amd64 bug132918 \
        clc \
        cmpxchg \
diff --git a/none/tests/amd64/asorep.c b/none/tests/amd64/asorep.c
new file mode 100644 (file)
index 0000000..e6af8ce
--- /dev/null
@@ -0,0 +1,77 @@
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+char buf1[64], buf2[64];
+
+int
+main (void)
+{
+  unsigned long rdi, rsi, rcx, rax;
+  uintptr_t b1 = (uintptr_t) buf1, b2 = (uintptr_t) buf2;
+
+  if (b1 > 0xffffffffULL || b2 > 0xffffffffULL)
+    return 0;
+
+  b1 += 0x100000000ULL;
+  b2 += 0xfff00000000ULL;
+  memcpy (buf1, "abcde", 4);
+  asm volatile ("addr32 rep movsb"
+               : "=D" (rdi), "=S" (rsi), "=c" (rcx)
+               : "D" (b2), "S" (b1), "c" (0x100000004ULL)
+               : "memory");
+  if (memcmp (buf2, "abcd", 5) != 0
+      || rdi != (uintptr_t) buf2 + 4
+      || rsi != (uintptr_t) buf1 + 4
+      || rcx)
+    fprintf (stderr, "addr32 rep movsb wrong\n");
+
+  rax = 0x751234560000ULL + (' ' << 8) + '0';
+  asm volatile ("addr32 rep stosw"
+               : "=D" (rdi), "=c" (rcx), "+a" (rax)
+               : "D" (b2), "c" (0x100000003ULL)
+               : "memory");
+  if (memcmp (buf2, "0 0 0 ", 7) != 0
+      || rdi != (uintptr_t) buf2 + 6
+      || rcx
+      || rax != 0x751234560000ULL + (' ' << 8) + '0')
+    fprintf (stderr, "addr32 rep stosw wrong\n");
+
+  asm volatile ("addr32 lodsl"
+                : "=S" (rsi), "=a" (rax)
+               : "S" (b2), "a" (2ULL));
+  if (rsi != (uintptr_t) buf2 + 4
+      || rax != 0x20302030ULL)
+    fprintf (stderr, "addr32 lodsl wrong\n");
+
+  memcpy (buf1, "abcdefghijklmno", 16);
+  memcpy (buf2, "abcdefghijklmnO", 16);
+  asm volatile ("addr32 repe cmpsb"
+               : "=D" (rdi), "=S" (rsi), "=c" (rcx)
+               : "D" (b2), "S" (b1), "c" (0x100000020ULL));
+  if (rdi != (uintptr_t) buf2 + 15
+      || rsi != (uintptr_t) buf1 + 15
+      || rcx != 17ULL)
+    fprintf (stderr, "addr32 repe cmpsb wrong\n");
+
+  memcpy (buf2, "ababababababababcdab", 20);
+  rax = 0x123450000ULL + ('d' << 8) + 'c';
+  asm volatile ("addr32 repne scasw"
+               : "=D" (rdi), "=c" (rcx), "+a" (rax)
+               : "D" (b2), "c" (0x100000020ULL));
+  if (rdi != (uintptr_t) buf2 + 18
+      || rcx != 23ULL
+      || rax != 0x123450000ULL + ('d' << 8) + 'c')
+    fprintf (stderr, "addr32 repne scasw wrong\n");
+
+  rax = 0x543210000ULL + ('b' << 8) + 'a';
+  asm volatile ("addr32 repe scasw"
+               : "=D" (rdi), "=c" (rcx), "+a" (rax)
+               : "D" (b2), "c" (0x100000020ULL));
+  if (rdi != (uintptr_t) buf2 + 18
+      || rcx != 23ULL
+      || rax != 0x543210000ULL + ('b' << 8) + 'a')
+    fprintf (stderr, "addr32 repe scasw wrong\n");
+
+  return 0;
+}
diff --git a/none/tests/amd64/asorep.stderr.exp b/none/tests/amd64/asorep.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/amd64/asorep.stdout.exp b/none/tests/amd64/asorep.stdout.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/amd64/asorep.vgtest b/none/tests/amd64/asorep.vgtest
new file mode 100644 (file)
index 0000000..71f3d9d
--- /dev/null
@@ -0,0 +1 @@
+prog: asorep