-
Notifications
You must be signed in to change notification settings - Fork 1
/
sys-linux-x64.asm
78 lines (67 loc) · 1.32 KB
/
sys-linux-x64.asm
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
global _start
%define sys_read 0
%define sys_write 1
%define sys_open 2
%define sys_close 3
%define sys_exit 60
%define STDIN_FILENO 0
%define STDOUT_FILENO 1
[section .bss]
OldRSP: resq 1
__SECT__
_start:
mov [rel OldRSP], rsp
mov rdi, [rsp]
lea rsi, [rsp+8]
mov [rel ArgC], rdi
mov [rel ArgV], rsi
mov qword [rel StdinFile], STDIN_FILENO
mov qword [rel StdoutFile], STDOUT_FILENO
jmp StartInterpreter
NativeExit:
mov rdi, rax
mov rax, sys_exit
syscall
int3
NativeOpen:
push rsi
push rdi
mov rdi, rax
mov rsi, rcx
xor rdx, rdx
mov rax, sys_open
syscall
pop rdi
pop rsi
ret
NativeClose:
push rsi
push rdi
mov rdi, rax
mov rax, sys_close
syscall
pop rdi
pop rsi
ret
NativeReadFile:
push rsi
push rdi
mov rsi, rdi
mov rdi, rax
mov rdx, rcx
mov rax, sys_read
syscall
pop rdi
pop rsi
ret
NativeWriteFile:
push rsi
push rdi
mov rsi, rdi
mov rdi, rax
mov rdx, rcx
mov rax, sys_write
syscall
pop rdi
pop rsi
ret