forked from cirosantilli/linux-kernel-module-cheat
/
x86_64.h
79 lines (72 loc) · 1.59 KB
/
x86_64.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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) \
push %rdi; \
mov general2, %rdi; \
push %rdi; \
mov 8(%rsp), %rdi; \
mov general1, %rdi; \
pop %rsi; \
add $8, %rsp; \
mov $__LINE__, %edx; \
call lkmc_assert_eq_64; \
;
#define LKMC_ASSERT_EQ_32(general1, general2) \
push %rdi; \
mov general2, %edi; \
push %rdi; \
mov 8(%rsp), %rdi; \
mov general1, %edi; \
pop %rsi; \
add $8, %rsp; \
mov $__LINE__, %edx; \
call lkmc_assert_eq_32; \
;
#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://cirosantilli.com/linux-kernel-module-cheat#x86_64-calling-convention
*/
#define LKMC_EPILOGUE \
add $8, %rsp; \
pop %rbx; \
pop %r12; \
pop %r13; \
pop %r14; \
pop %r15; \
pop %rbp; \
mov $0, %rax; \
ret; \
;
/* Function prologue.
*
* https://cirosantilli.com/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; \
sub $8, %rsp; \
main_after_prologue: \
;
#endif