Files
linux-kernel-module-cheat/lkmc/x86_64.h
Ciro Santilli 六四事件 法轮功 c8c4f89854 asm: make use regular asserts that will just work on baremetal
Previously had wonky line pointer in asm_main. New interface simpler and more portable.

Add tests for ASSERT_EQ_ and family in arm and aarch64, previously on x86_64.

ASSERT_EQ_ and family in ARM can now either take =123, =addr or var, before this
the = was added on macros so var was not possible.

Define the main function directly in assembly, the C driver was useless.
2019-05-23 00:00:00 +00:00

63 lines
1.3 KiB
C

#ifndef LKMC_X86_64_H
#define LKMC_X86_64_H
/* This and other macros may make C function calls, and therefore can destroy
* non-callee saved registers. */
#define LKMC_ASSERT_EQ(general1, general2) \
mov general2, %rdi; \
push %rdi; \
mov general1, %rdi; \
pop %rsi; \
mov $__LINE__, %edx; \
call lkmc_assert_eq_64; \
;
#define LKMC_ASSERT_FAIL \
mov $__LINE__, %edi; \
call lkmc_assert_fail; \
;
/* Assert that two memory arrays are the same. */
#define LKMC_ASSERT_MEMCMP(label1, label2, const_size) \
lea label1(%rip), %rdi; \
lea label2(%rip), %rsi; \
mov const_size, %rdx; \
mov $__LINE__, %ecx; \
call lkmc_assert_memcmp; \
;
/* Function epilogue.
*
* https://github.com/cirosantilli/linux-kernel-module-cheat#x86_64-calling-convention
*/
#define LKMC_EPILOGUE \
pop %rbx; \
pop %r12; \
pop %r13; \
pop %r14; \
pop %r15; \
pop %rbp; \
mov $0, %rax; \
ret; \
;
/* Function prologue.
*
* https://github.com/cirosantilli/linux-kernel-module-cheat#x86_64-calling-convention
*/
#define LKMC_PROLOGUE \
.text; \
.global main; \
main: \
push %rbp; \
mov %rsp, %rbp; \
push %r15; \
push %r14; \
push %r13; \
push %r12; \
push %rbx; \
main_after_prologue: \
;
#endif