-
Notifications
You must be signed in to change notification settings - Fork 1
/
platform_linux_amd64.c
102 lines (91 loc) · 1.85 KB
/
platform_linux_amd64.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* See LICENSE for license details. */
typedef unsigned char u8;
typedef signed long i64;
typedef unsigned long u64;
typedef signed int i32;
typedef unsigned int u32;
typedef unsigned int b32;
typedef unsigned short u16;
typedef signed long size;
typedef unsigned long usize;
typedef signed long iptr;
#ifndef asm
#ifdef __asm
#define asm __asm
#else
#define asm __asm__
#endif
#endif
#define SYS_read 0
#define SYS_write 1
#define SYS_open 2
#define SYS_close 3
#define SYS_stat 4
#define SYS_mmap 9
#define SYS_exit 60
#define SYS_getdents64 217
#define PAGESIZE 4096
#define STAT_BUF_SIZE 144
#define STAT_SIZE_OFF 48
#define DIRENT_RECLEN_OFF 16
#define DIRENT_TYPE_OFF 18
#define DIRENT_NAME_OFF 19
#include "platform_linux.c"
static i64
syscall1(i64 n, i64 a1)
{
i64 result;
asm volatile ("syscall"
: "=a"(result)
: "a"(n), "D"(a1)
: "rcx", "r11", "memory"
);
return result;
}
static i64
syscall2(i64 n, i64 a1, i64 a2)
{
i64 result;
asm volatile ("syscall"
: "=a"(result)
: "a"(n), "D"(a1), "S"(a2)
: "rcx", "r11", "memory"
);
return result;
}
static i64
syscall3(i64 n, i64 a1, i64 a2, i64 a3)
{
i64 result;
asm volatile ("syscall"
: "=a"(result)
: "a"(n), "D"(a1), "S"(a2), "d"(a3)
: "rcx", "r11", "memory"
);
return result;
}
static i64
syscall6(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5, i64 a6)
{
i64 result;
register i64 r10 asm("r10") = a4;
register i64 r8 asm("r8") = a5;
register i64 r9 asm("r9") = a6;
asm volatile ("syscall"
: "=a"(result)
: "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10), "r"(r8), "r"(r9)
: "rcx", "r11", "memory"
);
return result;
}
asm (
".intel_syntax noprefix\n"
".global _start\n"
"_start:\n"
" mov edi, DWORD PTR [rsp]\n"
" lea rsi, [rsp+8]\n"
" lea rdx, [rsi+rdi*8+8]\n"
" call linux_main\n"
" ud2\n"
".att_syntax\n"
);