diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index 29863015e7ba10aa31fd53b685a422567840653c..8d9960c61edbc09a2124183d255a17ee974fb5d2 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -8,9 +8,10 @@ CFLAGS += ASFLAGS += LDFLAGS += -soname libc.so -Map map.txt -lgcc -OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o select.o -DEPFILES := $(OBJ:%.o=%.d) +OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o select.o +OBJ += arch/$(ARCHDIR).ao # signals.o +DEPFILES := $(OBJ:%.o=%.d) BIN = libc.so include ../Makefile.tpl diff --git a/Usermode/Libraries/libc.so_src/arch/x86.asm b/Usermode/Libraries/libc.so_src/arch/x86.asm new file mode 100644 index 0000000000000000000000000000000000000000..f95f28f1e70a2a658dbc92ffca6c5c7314f3114d --- /dev/null +++ b/Usermode/Libraries/libc.so_src/arch/x86.asm @@ -0,0 +1,49 @@ +; +; Acess2 C Library +; - By John Hodge (thePowersGang) +; +; arch/x86.asm +; - x86 specific code +[bits 32] +[section .text] + +[global setjmp] +setjmp: + mov eax, [esp+4] ; Get base of buffer + + mov [eax+0x00], eax + mov [eax+0x04], ecx + mov [eax+0x08], edx + mov [eax+0x0C], ebx + mov [eax+0x10], esi + mov [eax+0x14], edi + mov [eax+0x18], esp + mov [eax+0x1C], ebp + + xor eax, eax + ret +setjmp.restore: + ret + +[global longjmp] +longjmp: + mov ebp, [esp+4] ; jmp_buf + mov eax, [esp+8] ; value + + ;mov eax, [ebp+0x00] + mov ecx, [ebp+0x04] + mov edx, [ebp+0x08] + mov ebx, [ebp+0x0C] + mov esi, [ebp+0x10] + mov edi, [ebp+0x14] + mov esp, [ebp+0x18] + mov ebp, [ebp+0x1C] + + test eax, eax + jnz .ret + inc eax + + ; Return to where setjmp was called +.ret: + ret + diff --git a/Usermode/Libraries/libc.so_src/arch/x86_64.asm b/Usermode/Libraries/libc.so_src/arch/x86_64.asm new file mode 100644 index 0000000000000000000000000000000000000000..36d864c229b40837b749456a2bc5a931cbaad2dd --- /dev/null +++ b/Usermode/Libraries/libc.so_src/arch/x86_64.asm @@ -0,0 +1,62 @@ +; +; Acess2 C Library +; - By John Hodge (thePowersGang) +; +; arch/x86_64.asm +; - x86_64 specific code +[bits 64] +[section .text] + +[global setjmp] +setjmp: + ;mov [rdi+0x00], rax + mov [rdi+0x08], rcx + mov [rdi+0x10], rdx + mov [rdi+0x18], rbx + mov [rdi+0x20], rsi + mov [rdi+0x28], rdi + mov [rdi+0x30], rsp + mov [rdi+0x38], rbp + mov [rdi+0x40], r8 + mov [rdi+0x48], r9 + mov [rdi+0x50], r10 + mov [rdi+0x58], r11 + mov [rdi+0x60], r12 + mov [rdi+0x68], r13 + mov [rdi+0x70], r14 + mov [rdi+0x78], r15 + + xor eax, eax + ret +setjmp.restore: + ret + +[global longjmp] +longjmp: + mov rax, rsi + + ;mov rax, [rdi+0x00] + mov rcx, [rdi+0x08] + mov rdx, [rdi+0x10] + mov rbx, [rdi+0x18] + mov rsi, [rdi+0x20] + mov rdi, [rdi+0x28] + mov rsp, [rdi+0x30] + mov rbp, [rdi+0x38] + mov r8, [rdi+0x40] + mov r9, [rdi+0x48] + mov r10, [rdi+0x50] + mov r11, [rdi+0x58] + mov r12, [rdi+0x60] + mov r13, [rdi+0x68] + mov r14, [rdi+0x70] + mov r15, [rdi+0x78] + + test eax, eax + jnz .ret + inc eax + + ; Return to where setjmp was called +.ret: + ret + diff --git a/Usermode/Libraries/libc.so_src/select.c b/Usermode/Libraries/libc.so_src/select.c new file mode 100644 index 0000000000000000000000000000000000000000..c42848c4fb204ca765422f745b550c669134ec1d --- /dev/null +++ b/Usermode/Libraries/libc.so_src/select.c @@ -0,0 +1,35 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * select.c + */ + +//#include <sys/select.h> +#include <sys/types.h> + +void FD_ZERO(fd_set *fdsetp) +{ + int i = FD_SETSIZE/16; + while( i-- ) + fdsetp->flags[i]=0; +} + +void FD_CLR(int fd, fd_set *fdsetp) +{ + if(fd < 0 || fd > FD_SETSIZE) return; + fdsetp->flags[fd/16] &= (fd_set_ent_t) ((~1 << (fd%16))) & 0xFFFF; +} + +void FD_SET(int fd, fd_set *fdsetp) +{ + if(fd < 0 || fd > FD_SETSIZE) return; + fdsetp->flags[fd/16] |= (fd_set_ent_t) (1 << (fd%16)); +} + +int FD_ISSET(int fd, fd_set *fdsetp) +{ + if(fd < 0 || fd > FD_SETSIZE) return 0; + return !!( fdsetp->flags[fd/16] & (1<<(fd%16)) ); +} + diff --git a/Usermode/include/setjmp.h b/Usermode/include/setjmp.h new file mode 100644 index 0000000000000000000000000000000000000000..53f3fbf234a399aa456c0646c268e90b591bcd45 --- /dev/null +++ b/Usermode/include/setjmp.h @@ -0,0 +1,23 @@ +/* + * Acess2 LibC + * - By John Hodge (thePowersGang) + * + * setjmp.h + * - setjmp/longjmp support + */ +#ifndef _LIBC_SETJMP_H_ +#define _LIBC_SETJMP_H_ + +#if ARCHDIR_is_x86 +typedef uint32_t jmp_buf[8]; +#elif ARCHDIR_is_x86_64 +typedef uint64_t jmp_buf[16]; +#else +# error "Unknown Architecture" +#endif + +extern int setjmp(jmp_buf buf); +extern void longjmp(jmp_buf buf, int val); + +#endif + diff --git a/Usermode/include/sys/types.h b/Usermode/include/sys/types.h index edcaa2243e8729ad527777518425394fb37b0d5b..687457e4b3dd177482e9ba141d7b8102f88f2c55 100644 --- a/Usermode/include/sys/types.h +++ b/Usermode/include/sys/types.h @@ -12,7 +12,7 @@ typedef struct stat t_fstat; typedef unsigned long pid_t; typedef unsigned long tid_t; -typedef signed long long time_t; +typedef signed long long int time_t; typedef unsigned int uint;