x86 asm: move exchange instructions from x86-assembly-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-26 00:00:00 +00:00
parent 88a1c914c9
commit ce3d546ac8
5 changed files with 117 additions and 8 deletions

View File

@@ -0,0 +1,28 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#cmpxchg-instruction */
#include <lkmc.h>
LKMC_PROLOGUE
/* rax != r13 */
mov $0, %rax
mov $1, %r13
mov $2, %r14
cmpxchg %r14, %r13
mov %rax, %r12
LKMC_ASSERT(jnz)
LKMC_ASSERT_EQ(%rax, $1)
LKMC_ASSERT_EQ(%r13, $1)
LKMC_ASSERT_EQ(%r14, $2)
/* rax == r13 */
mov $0, %rax
mov $0, %r13
mov $2, %r14
cmpxchg %r14, %r13
mov %rax, %r12
LKMC_ASSERT(jz)
LKMC_ASSERT_EQ(%rax, $0)
LKMC_ASSERT_EQ(%r13, $2)
LKMC_ASSERT_EQ(%r14, $2)
LKMC_EPILOGUE

View File

@@ -0,0 +1,11 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-exchange-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
mov $1, %rax
mov $2, %rbx
xadd %rbx, %rax
LKMC_ASSERT_EQ(%rax, $3)
LKMC_ASSERT_EQ(%rbx, $1)
LKMC_EPILOGUE

View File

@@ -0,0 +1,16 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-exchange-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
mov $0, %rax
mov $1, %rbx
xchg %rbx, %rax
LKMC_ASSERT_EQ(%rax, $1)
LKMC_ASSERT_EQ(%rbx, $0)
xchg %rbx, %rax
LKMC_ASSERT_EQ(%rax, $0)
LKMC_ASSERT_EQ(%rbx, $1)
LKMC_EPILOGUE