-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinux_amd64_main.c
69 lines (62 loc) · 1.36 KB
/
linux_amd64_main.c
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
// libc-free platform layer for x86-64 Linux
// This is free and unencumbered software released into the public domain.
#include "u-config.c"
#define SYS_close 3
#define SYS_exit 60
#define SYS_mmap 9
#define SYS_open 2
#define SYS_read 0
#define SYS_write 1
#include "linux_noarch.c"
asm (
" .globl _start\n"
"_start: mov %rsp, %rdi\n"
" call entrypoint\n"
);
static long syscall1(long n, long a)
{
long r;
asm volatile (
"syscall"
: "=a"(r)
: "a"(n), "D"(a)
: "rcx", "r11", "memory"
);
return r;
}
static long syscall2(long n, long a, long b)
{
long r;
asm volatile (
"syscall"
: "=a"(r)
: "a"(n), "D"(a), "S"(b)
: "rcx", "r11", "memory"
);
return r;
}
static long syscall3(long n, long a, long b, long c)
{
long r;
asm volatile (
"syscall"
: "=a"(r)
: "a"(n), "D"(a), "S"(b), "d"(c)
: "rcx", "r11", "memory"
);
return r;
}
static long syscall6(long n, long a, long b, long c, long d, long e, long f)
{
long r;
register long r10 asm("r10") = d;
register long r8 asm("r8") = e;
register long r9 asm("r9") = f;
asm volatile (
"syscall"
: "=a"(r)
: "a"(n), "D"(a), "S"(b), "d"(c), "r"(r10), "r"(r8), "r"(r9)
: "rcx", "r11", "memory"
);
return r;
}