-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathcommon.inc
58 lines (54 loc) · 875 Bytes
/
common.inc
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
%macro save_syscall 0
push rax
push rdi
push rsi
push rdx
push r10
push r8
push r9
%endmacro
%macro load_syscall 0
pop rdx
pop rsi
pop rdi
pop rax
pop r9
pop r8
pop r10
%endmacro
; Write 64-bit register or address to stdtout in small endian.
;
; Registers are preserved.
;
; Sample calls:
;
; write64 rax
; write64 _start
;
; @param 1 the value to write
;
%macro write64 1
save_syscall
; Must store the value in case it was passed
; as one of the registers used in the syscall.
push rbx
mov rbx, %1
mov rax, 1
mov rdi, 1
mov rsi, rbx
bswap rsi
mov [rsp + 1], rsi
lea rsi, [rsp + 1]
mov rdx, 8
syscall
pop rbx
load_syscall
%endmacro
%macro sys_exit 1
mov rax, 60
mov rdi, %1
syscall
%endmacro
%macro sys_exit 0
sys_exit 0
%endmacro