/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <xos/syscall.h> .text #define end_syscall() \ cmpl $-4096, %eax; \ ja __syscall_error; \ ret #define syscall0(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ movl $nr, %eax; \ int $0x80; \ end_syscall() #define syscall1(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ xchgl 4(%esp), %ebx; \ movl $nr, %eax; \ int $0x80; \ movl 4(%esp), %ebx; \ end_syscall() #define syscall2(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ xchgl 4(%esp), %ebx; \ xchgl 8(%esp), %ecx; \ movl $nr, %eax; \ int $0x80; \ movl 4(%esp), %ebx; \ movl 8(%esp), %ecx; \ end_syscall() #define syscall3(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ xchgl 4(%esp), %ebx; \ xchgl 8(%esp), %ecx; \ xchgl 12(%esp), %edx; \ movl $nr, %eax; \ int $0x80; \ movl 4(%esp), %ebx; \ movl 8(%esp), %ecx; \ movl 12(%esp), %edx; \ end_syscall() #define syscall4(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ xchgl 4(%esp), %ebx; \ xchgl 8(%esp), %ecx; \ xchgl 12(%esp), %edx; \ xchgl 16(%esp), %esi; \ movl $nr, %eax; \ int $0x80; \ movl 4(%esp), %ebx; \ movl 8(%esp), %ecx; \ movl 12(%esp), %edx; \ movl 16(%esp), %esi; \ end_syscall() #define syscall5(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ xchgl 4(%esp), %ebx; \ xchgl 8(%esp), %ecx; \ xchgl 12(%esp), %edx; \ xchgl 16(%esp), %esi; \ xchgl 20(%esp), %edi; \ movl $nr, %eax; \ int $0x80; \ movl 4(%esp), %ebx; \ movl 8(%esp), %ecx; \ movl 12(%esp), %edx; \ movl 16(%esp), %esi; \ movl 20(%esp), %edi; \ end_syscall() #define syscall6(name, nr) \ .globl name; \ .type name,@function; \ .hidden name; \ .align 4; \ name: \ xchgl 4(%esp), %ebx; \ xchgl 8(%esp), %ecx; \ xchgl 12(%esp), %edx; \ xchgl 16(%esp), %esi; \ xchgl 20(%esp), %edi; \ xchgl 24(%esp), %ebp; \ movl $nr, %eax; \ int $0x80; \ movl 4(%esp), %ebx; \ movl 8(%esp), %ecx; \ movl 12(%esp), %edx; \ movl 16(%esp), %esi; \ movl 20(%esp), %edi; \ movl 24(%esp), %ebp; \ end_syscall() syscall0(__syscall_fork, SC_FORK) syscall1(__syscall_exit, SC_EXIT) syscall3(__syscall_exec, SC_EXEC) syscall0(__syscall_getpid, SC_GETPID) syscall0(__syscall_getpgid, SC_GETPGID) syscall2(__syscall_setpgid, SC_SETPGID) syscall1(__syscall_chdir, SC_CHDIR) syscall2(__syscall_sbrk, SC_SBRK) syscall1(__syscall_sleep, SC_SLEEP) syscall3(__syscall_wait, SC_WAIT) syscall2(__syscall_kill, SC_KILL) syscall1(__syscall_uname, SC_UNAME) syscall2(__syscall_open, SC_OPEN) syscall1(__syscall_close, SC_CLOSE) syscall1(__syscall_dup, SC_DUP) syscall2(__syscall_dup2, SC_DUP2) syscall2(__syscall_pipe, SC_PIPE) syscall3(__syscall_fcntl, SC_FCNTL) syscall3(__syscall_read, SC_READ) syscall3(__syscall_write, SC_WRITE) syscall3(__syscall_seek, SC_SEEK) syscall2(__syscall_stat, SC_STAT) syscall3(__syscall_ioctl, SC_IOCTL) syscall1(__syscall_create, SC_CREATE) syscall1(__syscall_remove, SC_REMOVE) syscall1(__syscall_mkdir, SC_MKDIR) syscall1(__syscall_rmdir, SC_RMDIR) syscall2(__syscall_rename, SC_RENAME) syscall3(__syscall_mount, SC_MOUNT) syscall1(__syscall_umount, SC_UMOUNT) syscall1(__syscall_reboot, SC_REBOOT) syscall1(__syscall_gettime, SC_GETTIME) syscall5(__syscall_mmap, SC_MMAP) syscall2(__syscall_munmap, SC_MUNMAP) syscall3(__syscall_mprotect, SC_MPROTECT) __syscall_error: negl %eax pushl %eax call __set_errno@PLT addl $4, %esp movl $-1, %eax ret .section .note.GNU-stack,"",%progbits