From fae0055eb723635fcb736052fd8682d85b42849f Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 6 May 2020 12:17:35 +0900 Subject: [PATCH] libc: Clean up syscall assembly stubs --- libc/posixcall.S | 99 ---------------- libc/syscall.S | 289 ++++++++++++++--------------------------------- 2 files changed, 87 insertions(+), 301 deletions(-) delete mode 100644 libc/posixcall.S diff --git a/libc/posixcall.S b/libc/posixcall.S deleted file mode 100644 index 278d5a1..0000000 --- a/libc/posixcall.S +++ /dev/null @@ -1,99 +0,0 @@ -#define __ASSEMBLY_SOURCE - -#include -#include - - /* 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 diff --git a/libc/syscall.S b/libc/syscall.S index 438e141..804527a 100644 --- a/libc/syscall.S +++ b/libc/syscall.S @@ -2,192 +2,25 @@ #include -.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 -- 2.47.3