platform_linux_amd64.c (1953B)
1 /* See LICENSE for license details. */ 2 typedef unsigned char u8; 3 typedef signed long i64; 4 typedef unsigned long u64; 5 typedef signed int i32; 6 typedef unsigned int u32; 7 typedef unsigned int b32; 8 typedef unsigned short u16; 9 typedef signed long size; 10 typedef unsigned long usize; 11 typedef signed long iptr; 12 13 #define SYS_read 0 14 #define SYS_write 1 15 #define SYS_close 3 16 #define SYS_fstat 5 17 #define SYS_mmap 9 18 #define SYS_exit 60 19 #define SYS_getdents64 217 20 #define SYS_openat 257 21 22 #define PAGESIZE 4096 23 24 #define O_DIRECTORY 0x10000 25 26 #include "platform_linux.c" 27 28 static i64 29 syscall1(i64 n, i64 a1) 30 { 31 i64 result; 32 asm volatile ("syscall" 33 : "=a"(result) 34 : "a"(n), "D"(a1) 35 : "rcx", "r11", "memory" 36 ); 37 return result; 38 } 39 40 static i64 41 syscall2(i64 n, i64 a1, i64 a2) 42 { 43 i64 result; 44 asm volatile ("syscall" 45 : "=a"(result) 46 : "a"(n), "D"(a1), "S"(a2) 47 : "rcx", "r11", "memory" 48 ); 49 return result; 50 } 51 52 static i64 53 syscall3(i64 n, i64 a1, i64 a2, i64 a3) 54 { 55 i64 result; 56 asm volatile ("syscall" 57 : "=a"(result) 58 : "a"(n), "D"(a1), "S"(a2), "d"(a3) 59 : "rcx", "r11", "memory" 60 ); 61 return result; 62 } 63 64 static i64 65 syscall4(i64 n, i64 a1, i64 a2, i64 a3, i64 a4) 66 { 67 i64 result; 68 register i64 r10 asm("r10") = a4; 69 asm volatile ("syscall" 70 : "=a"(result) 71 : "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10) 72 : "rcx", "r11", "memory" 73 ); 74 return result; 75 } 76 77 static i64 78 syscall6(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5, i64 a6) 79 { 80 i64 result; 81 register i64 r10 asm("r10") = a4; 82 register i64 r8 asm("r8") = a5; 83 register i64 r9 asm("r9") = a6; 84 asm volatile ("syscall" 85 : "=a"(result) 86 : "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10), "r"(r8), "r"(r9) 87 : "rcx", "r11", "memory" 88 ); 89 return result; 90 } 91 92 asm ( 93 ".intel_syntax noprefix\n" 94 ".global _start\n" 95 "_start:\n" 96 " mov edi, DWORD PTR [rsp]\n" 97 " lea rsi, [rsp+8]\n" 98 " lea rdx, [rsi+rdi*8+8]\n" 99 " call linux_main\n" 100 " ud2\n" 101 ".att_syntax\n" 102 );