From c6bcfe6c5b766b0c73910996bb7fc3e2f9b79758 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Mon, 28 Oct 2019 01:20:19 +0900 Subject: [PATCH] Temporarily add assembly stubs for syscalls, to avoid having to link against the C library --- kernel/core/Makefile | 2 +- kernel/core/syscall.S | 227 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 kernel/core/syscall.S diff --git a/kernel/core/Makefile b/kernel/core/Makefile index 2839bfc..e1c8b78 100644 --- a/kernel/core/Makefile +++ b/kernel/core/Makefile @@ -1,4 +1,4 @@ -OBJECTS = main.o process.o sched.o cxnet.o socket.o cxipc.o +OBJECTS = main.o process.o sched.o cxnet.o socket.o cxipc.o syscall.o OUTPUT = core.o INCLUDES = -I../include -I../../include -I../.. CFLAGS += $(INCLUDES) diff --git a/kernel/core/syscall.S b/kernel/core/syscall.S new file mode 100644 index 0000000..8226ea6 --- /dev/null +++ b/kernel/core/syscall.S @@ -0,0 +1,227 @@ +#define __ASSEMBLY_SOURCE + +#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 + + 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 + +/* int cxsend(pid_t dst, struct ipc_msg *buf) */ + +.global cxsend +cxsend: + pushl %ebx + + movl $IPC_SEND, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + int $SYSCALL_CXIPC + + popl %ebx + ret + +/* int cxrecv(pid_t src, struct ipc_msg *buf) */ +.global cxrecv +cxrecv: + pushl %ebx + + movl $IPC_RECV, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + int $SYSCALL_CXIPC + + popl %ebx + ret + +.global cxsendrecv +cxsendrecv: + pushl %ebx + + movl $IPC_SENDRECV, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + int $SYSCALL_CXIPC + + popl %ebx + ret -- 2.47.3