Usermode/libc - Look ma! setjmp
authorJohn Hodge <[email protected]>
Thu, 6 Oct 2011 15:18:26 +0000 (23:18 +0800)
committerJohn Hodge <[email protected]>
Thu, 6 Oct 2011 15:18:26 +0000 (23:18 +0800)
Usermode/Libraries/libc.so_src/Makefile
Usermode/Libraries/libc.so_src/arch/x86.asm [new file with mode: 0644]
Usermode/Libraries/libc.so_src/arch/x86_64.asm [new file with mode: 0644]
Usermode/Libraries/libc.so_src/select.c [new file with mode: 0644]
Usermode/include/setjmp.h [new file with mode: 0644]
Usermode/include/sys/types.h

index 2986301..8d9960c 100644 (file)
@@ -8,9 +8,10 @@ CFLAGS   +=
 ASFLAGS  +=\r
 LDFLAGS  += -soname libc.so -Map map.txt -lgcc\r
 \r
-OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o select.o\r
-DEPFILES := $(OBJ:%.o=%.d)\r
+OBJ  = stub.o heap.o stdlib.o env.o fileIO.o string.o select.o\r
+OBJ += arch/$(ARCHDIR).ao\r
 # signals.o\r
+DEPFILES := $(OBJ:%.o=%.d)\r
 BIN = libc.so\r
 \r
 include ../Makefile.tpl\r
diff --git a/Usermode/Libraries/libc.so_src/arch/x86.asm b/Usermode/Libraries/libc.so_src/arch/x86.asm
new file mode 100644 (file)
index 0000000..f95f28f
--- /dev/null
@@ -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 (file)
index 0000000..36d864c
--- /dev/null
@@ -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 (file)
index 0000000..c42848c
--- /dev/null
@@ -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 (file)
index 0000000..53f3fbf
--- /dev/null
@@ -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
+
index edcaa22..687457e 100644 (file)
@@ -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;
 

UCC git Repository :: git.ucc.asn.au