sys_stubs.S (1790B)
1 /* Linux x86_64 syscall stubs matching the sys_* labels libp1pp 2 * provides (see P1/P1pp.P1pp). boot2-syscall.c declares them as 3 * extern long sys_<name>(...) and the mes-libc layers (read/write/ 4 * open/close/lseek/sbrk/unlink/_exit) call them. The cc.scm + libp1pp 5 * pipeline resolves these labels against P1pp.P1pp's wrappers; the 6 * tcc-libc suite links against this object instead since tcc-built 7 * binaries don't catm libp1pp. 8 * 9 * Linux x86_64 syscall ABI: nr in rax, args in rdi/rsi/rdx/r10/r8/r9 10 * (note: r10, not rcx, for the 4th arg — the syscall instruction 11 * clobbers rcx); return in rax. 12 * 13 * sys_open/sys_unlink shuffle args because Linux's openat/unlinkat 14 * take an AT_FDCWD prefix that the libp1pp-compatible wrappers 15 * don't surface to callers. 16 */ 17 18 .globl sys_read, sys_write, sys_close, sys_open 19 .globl sys_lseek, sys_brk, sys_unlink, sys_exit 20 21 sys_read: 22 movq $0, %rax 23 syscall 24 ret 25 26 sys_write: 27 movq $1, %rax 28 syscall 29 ret 30 31 sys_close: 32 movq $3, %rax 33 syscall 34 ret 35 36 sys_open: 37 /* (path, flags, mode) -> openat(AT_FDCWD, path, flags, mode) */ 38 movq %rdx, %r10 /* mode */ 39 movq %rsi, %rdx /* flags */ 40 movq %rdi, %rsi /* path */ 41 movq $-100, %rdi /* AT_FDCWD */ 42 movq $257, %rax /* NR_openat */ 43 syscall 44 ret 45 46 sys_lseek: 47 movq $8, %rax 48 syscall 49 ret 50 51 sys_brk: 52 movq $12, %rax 53 syscall 54 ret 55 56 sys_unlink: 57 /* (path) -> unlinkat(AT_FDCWD, path, 0) */ 58 movq %rdi, %rsi /* path */ 59 movq $-100, %rdi /* AT_FDCWD */ 60 movq $0, %rdx /* flags */ 61 movq $263, %rax /* NR_unlinkat */ 62 syscall 63 ret 64 65 sys_exit: 66 movq $60, %rax 67 syscall 68 /* unreachable */ 69 1: jmp 1b