]> git.corax.cc Git - corax/commitdiff
libc: Clean up syscall assembly stubs
authorMatthias Kruk <m@m10k.eu>
Wed, 6 May 2020 03:17:35 +0000 (12:17 +0900)
committerMatthias Kruk <m@m10k.eu>
Wed, 6 May 2020 03:48:11 +0000 (12:48 +0900)
libc/posixcall.S [deleted file]
libc/syscall.S

diff --git a/libc/posixcall.S b/libc/posixcall.S
deleted file mode 100644 (file)
index 278d5a1..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-#define __ASSEMBLY_SOURCE
-
-#include <config.h>
-#include <corax/syscall.h>
-
-       /* FIXME: Add syscall stubs for amd64/Intel64 */
-
-.global fork
-fork:
-       pushl   %ebx
-
-       movl    $SYS_FORK, %eax
-       int     $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-.global vfork
-vfork:
-       pushl   %ebx
-
-       movl    $SYS_VFORK, %eax
-       int     $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-.global _exit
-_exit:
-       pushl   %ebx
-
-       movl    $SYS_EXIT, %eax
-       movl    8(%esp), %ebx
-       int     $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-.global execeve
-execeve:
-       pushl   %ebx
-
-       movl    $SYS_EXECEVE, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       movl    20(%esp), %esi
-       int     $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-       .global wait
-       wait:
-       pushl   %ebx
-
-       movl    $SYS_WAIT, %eax
-       movl    8(%esp), %ebx
-       int             $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-       .global waitpid
-       waitpid:
-       pushl   %ebx
-
-       movl    $SYS_WAITPID, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-       .global waitid
-       waitid:
-       pushl   %ebx
-
-       movl    $SYS_WAITID, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       movl    20(%esp), %esi
-       int             $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
-
-       .global setsid
-       setsid:
-       pushl   %ebx
-
-       movl    $SYS_SETSID, %eax
-       int             $SYSCALL_POSIX
-
-       popl    %ebx
-       ret
index 438e141098ded3c839f20128a4b3e28f56780487..804527aa33e19e36a155f195e611165d5bad673e 100644 (file)
 
 #include <corax/syscall.h>
 
-.global socket
-socket:
-       pushl   %ebx
-
-       movl    $SYS_SOCKET, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global close
-close:
-       pushl   %ebx
-
-       movl    $SYS_CLOSE, %eax
-       movl    8(%esp), %ebx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global sendto
-sendto:
-       /*
-        * sendto() and recvfrom() have 6 arguments, so we also have
-        * to preserve the ebp register in order to repurpose it
-        */
-       pushl   %ebx
-       pushl   %ebp
-
-       movl    $SYS_SENDTO, %eax
-       movl    12(%esp), %ebx
-       movl    16(%esp), %ecx
-       movl    20(%esp), %edx
-       movl    24(%esp), %esi
-       movl    28(%esp), %edi
-       movl    32(%esp), %ebp
-       int             $SYSCALL_CXNET
-
-       popl    %ebp
-       popl    %ebx
-       ret
-
-.global recvfrom
-recvfrom:
-       pushl   %ebx
-       pushl   %ebp
-
-       movl    $SYS_RECVFROM, %eax
-       movl    12(%esp), %ebx
-       movl    16(%esp), %ecx
-       movl    20(%esp), %edx
-       movl    24(%esp), %esi
-       movl    28(%esp), %edi
-       movl    32(%esp), %ebp
-       int             $SYSCALL_CXNET
-
-       popl    %ebp
-       popl    %ebx
-       ret
-
-.global connect
-connect:
-       pushl   %ebx
-
-       movl    $SYS_CONNECT, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global listen
-listen:
-       pushl   %ebx
+       .section .text
+
+       /* Corax sycalls */
+       .global cxsend
+       .global cxrecv
+       .global cxsendrecv
+       .global debug
+
+       /* POSIX syscalls */
+       .global fork
+       .global vfork
+       .global _exit
+       .global execeve
+       .global brk
+       .global sbrk
+       .global mmap
+       .global munmap
+       .global sigaction
 
-       movl    $SYS_LISTEN, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global accept
-accept:
-       pushl   %ebx
-
-       movl    $SYS_ACCEPT, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global setsockopt
-setsockopt:
-       pushl   %ebx
-
-       movl    $SYS_SETSOCKOPT, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       movl    20(%esp), %esi
-       movl    24(%esp), %edi
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global getsockopt
-getsockopt:
-       pushl   %ebx
-
-       movl    $SYS_GETSOCKOPT, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       movl    20(%esp), %esi
-       movl    24(%esp), %edi
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global shutdown
-shutdown:
-       pushl   %ebx
-
-       movl    $SYS_SHUTDOWN, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global select
-select:
-       pushl   %ebx
-
-       movl    $SYS_SELECT, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       movl    20(%esp), %esi
-       movl    24(%esp), %edi
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global poll
-poll:
-       pushl   %ebx
-
-       movl    $SYS_POLL, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global bind
-bind:
-       pushl   %ebx
-
-       movl    $SYS_BIND, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_CXNET
-
-       popl    %ebx
-       ret
-
-.global cxsend
 cxsend:
        pushl   %ebx
 
@@ -199,7 +32,6 @@ cxsend:
        popl    %ebx
        ret
 
-.global cxrecv
 cxrecv:
        pushl   %ebx
 
@@ -211,7 +43,6 @@ cxrecv:
        popl    %ebx
        ret
 
-.global cxsendrecv
 cxsendrecv:
        pushl   %ebx
 
@@ -223,42 +54,96 @@ cxsendrecv:
        popl    %ebx
        ret
 
-.global fork
-fork:
+       /* FIXME: Remove debug syscall once VGA+IO is implemented */
+debug:
        pushl   %ebx
 
-       movl    $SYS_FORK, %eax
-       int             $SYSCALL_POSIX
+       movl    $SYS_DEBUG, %eax
+       movl    8(%esp), %ebx
+       movl    12(%esp), %ecx
+       int     $SYSCALL_POSIX
 
        popl    %ebx
        ret
 
-.global execfve
-execfve:
+fork:
        pushl   %ebx
 
-       movl    $SYS_EXECFVE, %eax
-       movl    8(%esp), %ebx
-       movl    12(%esp), %ecx
-       movl    16(%esp), %edx
-       int             $SYSCALL_POSIX
+       movl    $SYS_FORK, %eax
+       int     $SYSCALL_POSIX
 
        popl    %ebx
        ret
 
-.global debug
-debug:
+execeve:
        pushl   %ebx
 
-       movl    $SYS_DEBUG, %eax
+       movl    $SYS_EXECEVE, %eax
        movl    8(%esp), %ebx
        movl    12(%esp), %ecx
+       movl    16(%esp), %edx
+       movl    20(%esp), %esi
        int     $SYSCALL_POSIX
 
        popl    %ebx
        ret
 
-.global sigaction
+brk:
+        pushl   $0
+        call    sbrk
+
+        /*
+         * The eax register contains the current sbrk, 8(%esp) the desired sbrk.
+         * We have to pass the difference to sbrk() to increase or decrease it.
+         */
+        movl    8(%esp), %edx
+        subl    %eax, %edx
+
+        /* sbrk(8(%esp) - sbrk(0)) */
+        movl    %edx, (%esp)
+        call    sbrk
+
+        addl    $4, %esp
+        ret
+
+sbrk:
+        pushl   %ebx
+
+        movl    $SYS_SBRK, %eax
+        movl    8(%esp), %ebx
+        int    $SYSCALL_POSIX
+
+        popl    %ebx
+        ret
+
+mmap:
+        pushl   %ebx
+        pushl   %ebp
+
+        movl    $SYS_MMAP, %eax
+        movl    12(%esp), %ebx
+        movl    16(%esp), %ecx
+        movl    20(%esp), %edx
+        movl    24(%esp), %esi
+        movl    28(%esp), %edi
+        movl    32(%esp), %ebp
+        int    $SYSCALL_POSIX
+
+        popl    %ebp
+        popl    %ebx
+        ret
+
+munmap:
+        pushl   %ebx
+
+        movl    $SYS_MUNMAP, %eax
+        movl    8(%esp), %ebx
+        movl    12(%esp), %ecx
+        int    $SYSCALL_POSIX
+
+        popl    %ebx
+        ret
+
 sigaction:
        pushl   %ebx