summaryrefslogtreecommitdiffhomepage
path: root/src/thread
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-03-08 13:23:20 -0400
committermidipix <writeonce@midipix.org>2015-03-08 13:23:20 -0400
commit86062740f1e8eeb4c554055cf304dc1e0e87ea43 (patch)
tree35d8309221f4fd2050fefbc1b3b3957a1099ce8a /src/thread
parent41058bd82ed2ae880c463d61e5702aef07681bf0 (diff)
downloadmmglue-86062740f1e8eeb4c554055cf304dc1e0e87ea43.tar.bz2
mmglue-86062740f1e8eeb4c554055cf304dc1e0e87ea43.tar.xz
initial commit of core port files.
signed-off by Z. Gilboa; see copying.midipix (9cd0746c) for additional information.
Diffstat (limited to 'src/thread')
-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
7 files changed, 128 insertions, 0 deletions
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