From: John Hodge Date: Thu, 6 Oct 2011 15:18:26 +0000 (+0800) Subject: Usermode/libc - Look ma! setjmp X-Git-Tag: rel0.11~23 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=edf4c879ac931092da63389e186f06f08e324680;p=tpg%2Facess2.git Usermode/libc - Look ma! setjmp --- diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index 29863015..8d9960c6 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 00000000..f95f28f1 --- /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 00000000..36d864c2 --- /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 00000000..c42848c4 --- /dev/null +++ b/Usermode/Libraries/libc.so_src/select.c @@ -0,0 +1,35 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * select.c + */ + +//#include +#include + +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 00000000..53f3fbf2 --- /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 edcaa224..687457e4 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;