From b67975a820d481577f8ea7515858b2f35450b0d0 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 3 Dec 2023 18:26:11 +0100 Subject: [ARM64_DYNAREC] More work on LOCK prefixed opcodes (Atomic still disabled) --- tests/ref29.txt | 2 ++ tests/test29 | Bin 0 -> 16024 bytes tests/test29.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/ref29.txt create mode 100755 tests/test29 create mode 100644 tests/test29.c (limited to 'tests') diff --git a/tests/ref29.txt b/tests/ref29.txt new file mode 100644 index 00000000..6b25f7de --- /dev/null +++ b/tests/ref29.txt @@ -0,0 +1,2 @@ +Lock XADD: Res = 0x456, Ed = 0x579 +Lock XCHG: Res = 0x579, Ed = 0x123 diff --git a/tests/test29 b/tests/test29 new file mode 100755 index 00000000..0c4a63da Binary files /dev/null and b/tests/test29 differ diff --git a/tests/test29.c b/tests/test29.c new file mode 100644 index 00000000..96384251 --- /dev/null +++ b/tests/test29.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +// Build with `gcc -march=core2 -O0 test29.c -o test29` + +uint64_t lock_xadd(uint64_t Gd, uint64_t volatile* Ed) { +uint64_t Res; +asm( +"lock xadd %[_Gd], (%[_Ed])\n" +"movq %[_Gd], %[_Res]\n" +: [_Res] "+r"(Res) +: [_Gd] "r"(Gd) +, [_Ed] "r"(Ed) +); +return Res; +} + +uint64_t lock_xchg(uint64_t Gd, uint64_t volatile* Ed) { +uint64_t Res; +asm( +"lock xchg %[_Gd], (%[_Ed])\n" +"movq %[_Gd], %[_Res]\n" +: [_Res] "+r"(Res) +: [_Gd] "r"(Gd) +, [_Ed] "r"(Ed) +); +return Res; +} + +int main() { +uint64_t Gd = 0x123; +uint64_t volatile Ed = 0x456; +uint64_t Res = lock_xadd(Gd, &Ed); +printf("Lock XADD: Res = 0x%lx, Ed = 0x%lx\n", Res, Ed); +Gd = 0x123; +Res = lock_xchg(Gd, &Ed); +printf("Lock XCHG: Res = 0x%lx, Ed = 0x%lx\n", Res, Ed); +return 0; +} -- cgit 1.4.1