diff --git a/Makefile b/Makefile index f8cbae5..a65a53c 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,13 @@ C_HEADERS = $(wildcard kernel/*.h kernel/cpu/$(PLAT)/*.h kernel/cpu/*.h kernel/t ASM = $(wildcard kernel/cpu/$(PLAT)/*.asm) S_ASM = $(wildcard kernel/cpu/$(PLAT)/*.s) LIBC_SOURCES = $(wildcard libc/*.c libc/*/*.c) +LIBC_ASM_SOURCES = $(wildcard libc/*.asm libc/*/*.asm) LIBC_HEADERS = $(wildcard libc/*.h libc/*/*.h) OBJ = $(C_SOURCES:.c=.o kernel/cpu/$(PLAT)/boot.o) ASM_OBJ = $(S_ASM:.s=.o) S_ASM_OBJ = $(ASM:.asm=.o) LIBC_OBJ = $(LIBC_SOURCES:.c=.o) +LIBC_ASM_OBJ = $(LIBC_ASM_SOURCES:.asm=.o) CC = $(shell cat psinfo/$(PLAT)/cc.txt) AS = $(shell cat psinfo/$(PLAT)/as.txt) AR = $(shell cat psinfo/$(PLAT)/ar.txt) @@ -75,7 +77,7 @@ kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) sysroot/usr/lib/libc.a libc: sysroot/usr/lib/libc.a -sysroot/usr/lib/libc.a: $(LIBC_OBJ) +sysroot/usr/lib/libc.a: $(LIBC_OBJ) $(LIBC_ASM_OBJ) @$(AR) rcs $@ $^ sysroot/usr/share/man: doc diff --git a/libc/__helpers.asm b/libc/__helpers.asm new file mode 100644 index 0000000..37f4a90 --- /dev/null +++ b/libc/__helpers.asm @@ -0,0 +1,9 @@ +global __pthread_spin_lock_helper + +__pthread_spin_lock_helper: + mov ebx,[esp+4] + mov eax,1 + xchg eax,[ebx] + test eax, eax + jnz __pthread_spin_lock_helper + ret diff --git a/libc/__helpers.h b/libc/__helpers.h new file mode 100644 index 0000000..d2f48cd --- /dev/null +++ b/libc/__helpers.h @@ -0,0 +1,7 @@ +#ifndef __HELPERS_H +#define __HELPERS_H +#include + +void __pthread_spin_lock_helper(pthread_spinlock_t* lock); + +#endif diff --git a/libc/pthread.c b/libc/pthread.c index 5db20b0..47f4df1 100644 --- a/libc/pthread.c +++ b/libc/pthread.c @@ -1,6 +1,7 @@ #include #include #include +#include <__helpers.h> #define QUAUX(X) #X #define QU(X) QUAUX(X) @@ -21,3 +22,22 @@ void pthread_exit(void *value_ptr) { mov $" QU(SYSCALL_THREAD_EXIT) ", %eax; \ int $80;"); } + +int pthread_spin_init(pthread_spinlock_t *lock, int pshared) { + *lock=0; + return 0; +} + +int pthread_spin_lock(pthread_spinlock_t *lock) { + __pthread_spin_lock_helper(lock); + return 0; +} + +int pthread_spin_unlock(pthread_spinlock_t *lock) { + *lock=0; + return 0; +} + +int pthread_spin_destroy(pthread_spinlock_t *lock) { + return 0; +} diff --git a/libc/pthread.h b/libc/pthread.h index ee40417..61732a0 100644 --- a/libc/pthread.h +++ b/libc/pthread.h @@ -9,6 +9,7 @@ typedef pid_t pthread_t; //!< Represents a thread typedef int pthread_attr_t; //!< Created as dummy +typedef int pthread_spinlock_t; //!< Represents a spinlock /** * Create a thread in the current process @@ -28,4 +29,35 @@ int pthread_create(pthread_t *restrict thread, */ void pthread_exit(void *value_ptr); +/** + * Initializes a spin lock + * \param lock The spinlock to initialize + * \param pshared Unused + * \returns 0 on success, 1 on failure +*/ +int pthread_spin_init(pthread_spinlock_t *lock, int pshared); + +/** + * Locks a spin lock + * \param lock The spinlock to lock + * \returns 0 on success, 1 on failure +*/ +int pthread_spin_lock(pthread_spinlock_t *lock); + +/** + * Unlocks a spin lock + * \param lock The spinlock to unlock + * \returns 0 on success, 1 on failure +*/ +int pthread_spin_unlock(pthread_spinlock_t *lock); + +/** + * Destroys a spin lock + * \param lock The spinlock to destroy + * \returns 0 on success, 1 on failure +*/ +int pthread_spin_destroy(pthread_spinlock_t *lock); + + + #endif