diff options
author | Anton Kling <anton@kling.gg> | 2023-11-23 16:10:34 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-23 16:10:34 +0100 |
commit | b8da260dd01175529feb57d5a73570f469decb08 (patch) | |
tree | 733941b61531f1685e4d6b546a9325d7868ec9e4 /userland | |
parent | 81819f711e6d1f9216f688da8ecbbc682d106d9c (diff) |
LibC: Move assembly to its own file to avoid using inline
This was a ugly hack and in this case it caused undefined behavior.
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libc/Makefile | 6 | ||||
-rw-r--r-- | userland/libc/libc.c | 38 |
2 files changed, 6 insertions, 38 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index 4c784fe..146492b 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -1,12 +1,12 @@ CC="i686-sb-gcc" AR="i686-sb-ar" AS="i686-sb-as" -CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -Werror -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o math/min.o math/max.o +CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o math/min.o math/max.o systemcall.o all: libc.a %.o: %.c - $(CC) $(CFLAGS) -O0 -I. -o $@ -c $< -lgcc + $(CC) $(CFLAGS) -I. -o $@ -c $< -lgcc %.o: %.s $(AS) $< -o $@ diff --git a/userland/libc/libc.c b/userland/libc/libc.c index 7320d29..3597fe2 100644 --- a/userland/libc/libc.c +++ b/userland/libc/libc.c @@ -141,22 +141,7 @@ void _libc_setup(void) { // Syscall: eax ebx ecx edx esi edi int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, - uint32_t esi, uint32_t edi) { - asm volatile( - "push %edi\n" - "push %esi\n" - "push %ebx\n" - "mov 0x1C(%ebp), %edi\n" - "mov 0x18(%ebp), %esi\n" - "mov 0x14(%ebp), %edx\n" - "mov 0x10(%ebp), %ecx\n" - "mov 0xc(%ebp), %ebx\n" - "mov 0x8(%ebp), %eax\n" - "int $0x80\n" - "pop %ebx\n" - "pop %esi\n" - "pop %edi\n"); -} + uint32_t esi, uint32_t edi); int pipe(int fd[2]) { return syscall(SYS_PIPE, (u32)fd, 0, 0, 0, 0); } @@ -210,27 +195,10 @@ int execv(char *path, char **argv) { struct SYS_EXEC_PARAMS args = {.path = path, .argv = argv}; return syscall(SYS_EXEC, (u32)&args, 0, 0, 0, 0); } -/* -int syscall(int sys, void *args) { - asm volatile("push %ebx\n" - "mov 0xc(%ebp), %ebx\n" - "mov 0x8(%ebp), %eax\n" - "int $0x80\n" - "pop %ebx\n"); -}*/ - -int s_syscall(int sys) { - asm volatile("movl %0, %%eax\n" - "int $0x80\n" ::"r"((uint32_t)sys)); -} + +int s_syscall(int sys); int write(int fd, const char *buf, size_t count) { - /* -struct SYS_WRITE_PARAMS args = { -.fd = fd, -.buf = buf, -.count = count, -};*/ return syscall(SYS_WRITE, fd, buf, count, 0, 0); } |