diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3c1a5acf431e4bc1430578fc2fbb6f08330089b0 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +NASM = nasm +CPPFLAGS = -nostdinc -Iinclude +CFLAGS = -Wall -Wextra -fno-PIC -fno-stack-protector -fno-builtin +# Remove the line below to disable debugging support. +CFLAGS += -g -O0 + +.PHONY: all clean pack + +SRCS = syscall.c \ + process/exit.c \ + mm/malloc.c mm/mmap.c mm/mem_list.c \ + string/string.c \ + stat/fstatat.c stat/fstat.c stat/stat.c \ + io/open.c io/close.c io/read_write.c \ + io/lseek.c io/truncate.c io/ftruncate.c \ + errno.c \ + crt/__libc_start_main.c \ + io/puts.c \ + process/nanosleep.c \ + process/sleep.c \ + +# TODO: Add sleep.c and puts.c dependency. + +OBJS = $(patsubst %.c,%.o,$(SRCS)) + +all: libc.a + +libc.a: $(OBJS) crt/start.o + $(AR) -rc $@ $^ + +$(OBJS): %.o:%.c + +crt/start.o: crt/start.asm + $(NASM) -f elf64 -o $@ $< + +pack: clean + zip -r ../src.zip * + +clean: + -rm -f *~ + -rm -f $(OBJS) crt/start.o + -rm -f libc.a diff --git a/errno.c b/errno.c new file mode 100644 index 0000000000000000000000000000000000000000..01a7d85a522de21ce94e80a3fb6a4807f6700aaf --- /dev/null +++ b/errno.c @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#include <errno.h> + +int errno; diff --git a/src.zip b/src.zip index 3ea3cf69720df006513da40c5cedb6857e9ad181..e9e7228bf0a86eb101fb736a3174d679a03d1c41 100644 Binary files a/src.zip and b/src.zip differ diff --git a/syscall.c b/syscall.c new file mode 100644 index 0000000000000000000000000000000000000000..23ab562450ef70a9d8818f71e1982fc2841e2456 --- /dev/null +++ b/syscall.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#include <internal/arch/x86_64/syscall_arch.h> +#include <stdarg.h> + +long syscall(long num, ...) +{ + va_list valist; + long a, b, c, d, e, f; + + va_start(valist, num); + a = va_arg(valist, long); + b = va_arg(valist, long); + c = va_arg(valist, long); + d = va_arg(valist, long); + e = va_arg(valist, long); + f = va_arg(valist, long); + va_end(valist); + + return __syscall(num, a, b, c, d, e, f); +} diff --git a/tests/test_string.c b/tests/test_string.c old mode 100644 new mode 100755 index d0ea0401faa41f168c51c09b4180ae3f996bd99a..12d052c8340b581a9ede032675e7250530a4adc7 --- a/tests/test_string.c +++ b/tests/test_string.c @@ -2,8 +2,8 @@ #include <string.h> -#include "./graded_test.h" +#include "./graded_test.h" static int test_strcpy(void) { char src[] = "sticksandstones"; @@ -59,7 +59,6 @@ static int test_strncpy_cut(void) dst[10] = 'Z'; strncpy(dst, src, 10); len = strlen(dst); - return len == 11; }