sys_stubs.c (2728B)
1 /* aarch64 syscall stubs matching P1pp.P1pp's sys_* entry points. 2 * Same C ABI as P1pp's labelled entries — our libc.flat.c calls these 3 * with argument shapes copied straight from boot2-syscall.c. 4 * 5 * Linux aarch64 syscall ABI: nr in x8, args in x0..x5, return in x0. 6 */ 7 8 static inline long _syscall0(long nr) { 9 register long x8 __asm__("x8") = nr; 10 register long x0 __asm__("x0"); 11 __asm__ volatile ("svc #0" : "=r"(x0) : "r"(x8) : "memory"); 12 return x0; 13 } 14 static inline long _syscall1(long nr, long a) { 15 register long x8 __asm__("x8") = nr; 16 register long x0 __asm__("x0") = a; 17 __asm__ volatile ("svc #0" : "+r"(x0) : "r"(x8) : "memory"); 18 return x0; 19 } 20 static inline long _syscall2(long nr, long a, long b) { 21 register long x8 __asm__("x8") = nr; 22 register long x0 __asm__("x0") = a; 23 register long x1 __asm__("x1") = b; 24 __asm__ volatile ("svc #0" : "+r"(x0) : "r"(x8), "r"(x1) : "memory"); 25 return x0; 26 } 27 static inline long _syscall3(long nr, long a, long b, long c) { 28 register long x8 __asm__("x8") = nr; 29 register long x0 __asm__("x0") = a; 30 register long x1 __asm__("x1") = b; 31 register long x2 __asm__("x2") = c; 32 __asm__ volatile ("svc #0" : "+r"(x0) : "r"(x8), "r"(x1), "r"(x2) : "memory"); 33 return x0; 34 } 35 static inline long _syscall4(long nr, long a, long b, long c, long d) { 36 register long x8 __asm__("x8") = nr; 37 register long x0 __asm__("x0") = a; 38 register long x1 __asm__("x1") = b; 39 register long x2 __asm__("x2") = c; 40 register long x3 __asm__("x3") = d; 41 __asm__ volatile ("svc #0" : "+r"(x0) 42 : "r"(x8), "r"(x1), "r"(x2), "r"(x3) : "memory"); 43 return x0; 44 } 45 46 #define NR_read 63 47 #define NR_write 64 48 #define NR_close 57 49 #define NR_openat 56 50 #define NR_lseek 62 51 #define NR_brk 214 52 #define NR_unlinkat 35 53 #define NR_exit 93 54 #define AT_FDCWD (-100) 55 56 long sys_read (long fd, long buf, long n) { return _syscall3(NR_read, fd, buf, n); } 57 long sys_write (long fd, long buf, long n) { return _syscall3(NR_write, fd, buf, n); } 58 long sys_close (long fd) { return _syscall1(NR_close, fd); } 59 long sys_open (long path, long flags, long mode) { return _syscall4(NR_openat, AT_FDCWD, path, flags, mode); } 60 long sys_lseek (long fd, long off, long whence) { return _syscall3(NR_lseek, fd, off, whence); } 61 long sys_brk (long addr) { return _syscall1(NR_brk, addr); } 62 long sys_unlink(long path) { return _syscall3(NR_unlinkat, AT_FDCWD, path, 0); } 63 long sys_exit (long code) { _syscall1(NR_exit, code); for(;;); }