summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/env/nt64/__environ.s11
-rw-r--r--src/fcntl/nt64/posix_fadvise.c14
-rw-r--r--src/internal/nt64/libc.c7
-rw-r--r--src/internal/nt64/syscall.s5
-rw-r--r--src/ldso/nt64/dl_iterate_phdr.c10
-rw-r--r--src/ldso/nt64/dynlink.c58
-rw-r--r--src/ldso/nt64/start.s2
-rw-r--r--src/ldso/nt64/tlsdesc.c8
-rw-r--r--src/setjmp/nt64/longjmp.s28
-rw-r--r--src/setjmp/nt64/setjmp.s23
-rw-r--r--src/thread/nt64/__set_thread_area.c13
-rw-r--r--src/thread/nt64/__tls_get_addr.c2
-rw-r--r--src/thread/nt64/clone.c62
-rw-r--r--src/thread/nt64/pthread_detach.c6
-rw-r--r--src/thread/nt64/pthread_equal.c6
-rw-r--r--src/thread/nt64/pthread_self.c10
-rw-r--r--src/thread/nt64/syscall_cp.s29
17 files changed, 294 insertions, 0 deletions
diff --git a/src/env/nt64/__environ.s b/src/env/nt64/__environ.s
new file mode 100644
index 0000000..28ac875
--- /dev/null
+++ b/src/env/nt64/__environ.s
@@ -0,0 +1,11 @@
+.globl ___environ
+.globl __environ
+.globl _environ
+.globl environ
+
+.data
+___environ:
+__environ:
+_environ:
+environ:
+ .quad 0
diff --git a/src/fcntl/nt64/posix_fadvise.c b/src/fcntl/nt64/posix_fadvise.c
new file mode 100644
index 0000000..c95d7f4
--- /dev/null
+++ b/src/fcntl/nt64/posix_fadvise.c
@@ -0,0 +1,14 @@
+#include "fcntl.h"
+#include "syscall_arch.h"
+
+int posix_fadvise (int fd, off_t base, off_t len, int advice)
+{
+ /**
+ * __syscall is needed here due to the odd semantics
+ * of posix_fadvise(), which for us means calling
+ * __sys_fadvise() directly.
+ **/
+
+ return 0; /* __sys_fadvise (fd, base, len, advice); */
+}
+
diff --git a/src/internal/nt64/libc.c b/src/internal/nt64/libc.c
new file mode 100644
index 0000000..43face8
--- /dev/null
+++ b/src/internal/nt64/libc.c
@@ -0,0 +1,7 @@
+#include "../libc.h"
+
+/* todo: teach the linker to export weak symbols */
+#undef weak_alias
+#define weak_alias(old,new) extern __typeof(old) new __attribute__((alias(#old)))
+
+#include "../libc.c"
diff --git a/src/internal/nt64/syscall.s b/src/internal/nt64/syscall.s
new file mode 100644
index 0000000..ce3827b
--- /dev/null
+++ b/src/internal/nt64/syscall.s
@@ -0,0 +1,5 @@
+.text
+.global __syscall
+
+__syscall:
+ jmp __syscall_disp
diff --git a/src/ldso/nt64/dl_iterate_phdr.c b/src/ldso/nt64/dl_iterate_phdr.c
new file mode 100644
index 0000000..f98a509
--- /dev/null
+++ b/src/ldso/nt64/dl_iterate_phdr.c
@@ -0,0 +1,10 @@
+#include <stddef.h>
+#include <dlfcn.h>
+#include <link.h>
+
+typedef int __ldso_phdr_callback(struct dl_phdr_info * info, size_t size, void * data);
+
+int dl_iterate_phdr(__ldso_phdr_callback * callback, void * data)
+{
+ return -1;
+}
diff --git a/src/ldso/nt64/dynlink.c b/src/ldso/nt64/dynlink.c
new file mode 100644
index 0000000..e5329e6
--- /dev/null
+++ b/src/ldso/nt64/dynlink.c
@@ -0,0 +1,58 @@
+#define _BSD_SOURCE
+
+#include <dlfcn.h>
+#include "pthread_impl.h"
+
+int __dladdr(const void * addr, Dl_info * info)
+{
+ return 0;
+}
+
+int __dlinfo(void * dso, int req, void * res)
+{
+ return 0;
+}
+
+void *__dlsym(void * restrict p, const char * restrict s, void * restrict ra)
+{
+ return 0;
+}
+
+void * dlopen(const char * file, int mode)
+{
+ return 0;
+}
+
+int dlclose(void *p)
+{
+ return 0;
+}
+
+char * dlerror(void)
+{
+ return 0;
+}
+
+void __reset_tls(void)
+{
+}
+
+void *__copy_tls(unsigned char * mem)
+{
+ /**
+ * this is always the simple case, since:
+ * emutls is based on PE named sections; and
+ * tls allocation and initialization are handled by clone(2)
+ **/
+
+ pthread_t td;
+ void ** dtv;
+
+ dtv = (void **)mem;
+ dtv[0] = 0;
+
+ td = (void *)(dtv + 1);
+ td->dtv = dtv;
+
+ return td;
+}
diff --git a/src/ldso/nt64/start.s b/src/ldso/nt64/start.s
new file mode 100644
index 0000000..32dc52f
--- /dev/null
+++ b/src/ldso/nt64/start.s
@@ -0,0 +1,2 @@
+# standard dynamic loader is not required
+# optional dynamic loader [to be] provided by libldso/libpsxscl
diff --git a/src/ldso/nt64/tlsdesc.c b/src/ldso/nt64/tlsdesc.c
new file mode 100644
index 0000000..7015e30
--- /dev/null
+++ b/src/ldso/nt64/tlsdesc.c
@@ -0,0 +1,8 @@
+#include <stddef.h>
+
+ptrdiff_t __tlsdesc_static(void)
+{
+ return 0;
+}
+
+ptrdiff_t __tlsdesc_dynamic(void) __attribute__((alias("__tlsdesc_static")));
diff --git a/src/setjmp/nt64/longjmp.s b/src/setjmp/nt64/longjmp.s
new file mode 100644
index 0000000..0fcf52e
--- /dev/null
+++ b/src/setjmp/nt64/longjmp.s
@@ -0,0 +1,28 @@
+.text
+.globl __longjmp
+.globl _longjmp
+.globl longjmp
+
+__longjmp:
+_longjmp:
+longjmp:
+ test %edx, %edx # is val zero?
+ jne 1f # no: return val
+ xor $1, %edx # yes: return one
+
+1:
+ mov %edx, %eax # return value
+
+2:
+ mov 0x10(%rcx), %rbx # restore regs
+ mov 0x18(%rcx), %rbp
+ mov 0x20(%rcx), %rdi
+ mov 0x28(%rcx), %rsi
+ mov 0x30(%rcx), %r12
+ mov 0x38(%rcx), %r13
+ mov 0x40(%rcx), %r14
+ mov 0x48(%rcx), %r15
+
+ mov 0x08(%rcx), %rsp # saved stack pointer
+ mov (%rcx), %rdx # return address
+ jmp *%rdx # return
diff --git a/src/setjmp/nt64/setjmp.s b/src/setjmp/nt64/setjmp.s
new file mode 100644
index 0000000..3e8a1ea
--- /dev/null
+++ b/src/setjmp/nt64/setjmp.s
@@ -0,0 +1,23 @@
+.text
+.globl __setjmp
+.globl _setjmp
+.globl setjmp
+
+__setjmp:
+_setjmp:
+setjmp:
+ pop (%rcx) # return address
+ mov %rsp, 0x08(%rcx) # caller's stack pointer
+ push (%rcx) # restore own stack pointer
+
+ mov %rbx, 0x10(%rcx)
+ mov %rbp, 0x18(%rcx)
+ mov %rdi, 0x20(%rcx)
+ mov %rsi, 0x28(%rcx)
+ mov %r12, 0x30(%rcx)
+ mov %r13, 0x38(%rcx)
+ mov %r14, 0x40(%rcx)
+ mov %r15, 0x48(%rcx)
+
+ xor %eax, %eax
+ ret
diff --git a/src/thread/nt64/__set_thread_area.c b/src/thread/nt64/__set_thread_area.c
new file mode 100644
index 0000000..c50f6c6
--- /dev/null
+++ b/src/thread/nt64/__set_thread_area.c
@@ -0,0 +1,13 @@
+#include <errno.h>
+#include "pthread_impl.h"
+
+int __set_thread_area(void * p)
+{
+ struct pthread ** ptlca;
+
+ ptlca = __psx_tlca();
+ if (!ptlca) return -ESRCH;
+
+ *ptlca = p;
+ return 0;
+}
diff --git a/src/thread/nt64/__tls_get_addr.c b/src/thread/nt64/__tls_get_addr.c
new file mode 100644
index 0000000..ad8d845
--- /dev/null
+++ b/src/thread/nt64/__tls_get_addr.c
@@ -0,0 +1,2 @@
+/* using a custom, register-based __emutls_get_address */
+typedef int dummy;
diff --git a/src/thread/nt64/clone.c b/src/thread/nt64/clone.c
new file mode 100644
index 0000000..d460855
--- /dev/null
+++ b/src/thread/nt64/clone.c
@@ -0,0 +1,62 @@
+#include <syscall.h>
+
+struct pt_regs {
+ unsigned long r15;
+ unsigned long r14;
+ unsigned long r13;
+ unsigned long r12;
+ unsigned long rbp;
+ unsigned long rbx;
+ unsigned long r11;
+ unsigned long r10;
+ unsigned long r9;
+ unsigned long r8;
+ unsigned long rax;
+ unsigned long rcx;
+ unsigned long rdx;
+ unsigned long rsi;
+ unsigned long rdi;
+ unsigned long orig_rax;
+ unsigned long rip;
+ unsigned long cs;
+ unsigned long eflags;
+ unsigned long rsp;
+ unsigned long ss;
+};
+
+typedef long __sys_clone(
+ unsigned long flags,
+ void * child_stack,
+ void * ptid,
+ void * ctid,
+ struct pt_regs *regs);
+
+typedef int __entry_point(void *);
+
+extern unsigned long ** __syscall_vtbl;
+
+int __clone(
+ __entry_point * fn,
+ void * child_stack,
+ int flags,
+ void * arg,
+ int * ptid,
+ void * pthread_self_addr,
+ int * ctid)
+{
+ struct pt_regs regs;
+ __sys_clone * pfn_clone;
+
+ regs.rip = (unsigned long)fn;
+ regs.rcx = (unsigned long)arg;
+ regs.rdx = (unsigned long)pthread_self_addr;
+
+ pfn_clone = (__sys_clone *)(__syscall_vtbl[SYS_clone]);
+
+ return (int)pfn_clone(
+ flags,
+ child_stack,
+ ptid,
+ ctid,
+ &regs);
+}
diff --git a/src/thread/nt64/pthread_detach.c b/src/thread/nt64/pthread_detach.c
new file mode 100644
index 0000000..85db4cb
--- /dev/null
+++ b/src/thread/nt64/pthread_detach.c
@@ -0,0 +1,6 @@
+#include "../pthread_detach.c"
+
+int __pthread_detach_impl(pthread_t t)
+{
+ return thrd_detach(t);
+}
diff --git a/src/thread/nt64/pthread_equal.c b/src/thread/nt64/pthread_equal.c
new file mode 100644
index 0000000..a8fcd79
--- /dev/null
+++ b/src/thread/nt64/pthread_equal.c
@@ -0,0 +1,6 @@
+#include "../pthread_equal.c"
+
+int __pthread_equal_impl(pthread_t a, pthread_t b)
+{
+ return thrd_equal(a,b);
+}
diff --git a/src/thread/nt64/pthread_self.c b/src/thread/nt64/pthread_self.c
new file mode 100644
index 0000000..23fbc53
--- /dev/null
+++ b/src/thread/nt64/pthread_self.c
@@ -0,0 +1,10 @@
+#include "pthread_impl.h"
+#include <threads.h>
+#include "libc.h"
+
+pthread_t pthread_self()
+{
+ return __pthread_self();
+}
+
+weak_alias(pthread_self, thrd_current);
diff --git a/src/thread/nt64/syscall_cp.s b/src/thread/nt64/syscall_cp.s
new file mode 100644
index 0000000..b8b7039
--- /dev/null
+++ b/src/thread/nt64/syscall_cp.s
@@ -0,0 +1,29 @@
+.text
+.globl __syscall_cp_asm
+.globl __cp_begin
+.globl __cp_end
+
+__syscall_cp_asm:
+__cp_begin:
+ movq (%rcx), %rcx /* check content of ptr */
+ test %ecx, %ecx
+ jnz __cancel /* thread is pending cancellation */
+
+ movq %rdx, %rcx/* move water */
+ movq %r8, %rdx/* from one glass */
+ movq %r9, %r8 /* to another */
+ movq 0x28(%rsp), %r9
+
+ movq 0x30(%rsp),%rax
+ movq %rax, 0x28(%rsp)
+
+ movq 0x38(%rsp),%r10
+ movq %r10, 0x30(%rsp)
+
+ movq 0x40(%rsp),%r10
+ movq %r10, 0x38(%rsp)
+
+ jmp __syscall
+
+__cp_end:
+ ret