summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-04-05 17:05:57 -0400
committermidipix <writeonce@midipix.org>2015-04-05 17:05:57 -0400
commit296178913c5dfbc2b35842fc16ed680ef51fd402 (patch)
tree6720928dbc03c3d656229d2509eda38f6eb0628b /src
parent20a5ca45ef2f5716e8f2dea42c7e8a6b3367619f (diff)
downloadmmglue-296178913c5dfbc2b35842fc16ed680ef51fd402.tar.bz2
mmglue-296178913c5dfbc2b35842fc16ed680ef51fd402.tar.xz
nt32: initial commit of core port files.
signed-off by Z. Gilboa; see copying.midipix (9cd0746c) for additional information.
Diffstat (limited to 'src')
-rw-r--r--src/env/nt32/__environ.s11
-rw-r--r--src/fcntl/nt32/posix_fadvise.c14
-rw-r--r--src/internal/nt32/libc.c7
-rw-r--r--src/internal/nt32/syscall.s5
-rw-r--r--src/ldso/nt32/dl_iterate_phdr.c10
-rw-r--r--src/ldso/nt32/dynlink.c62
-rw-r--r--src/ldso/nt32/start.s2
-rw-r--r--src/ldso/nt32/tlsdesc.c8
-rw-r--r--src/setjmp/nt32/longjmp.s9
-rw-r--r--src/setjmp/nt32/setjmp.s14
-rw-r--r--src/stdio/nt32/fflush.c6
-rw-r--r--src/thread/nt32/__set_thread_area.c13
-rw-r--r--src/thread/nt32/__tls_get_addr.c2
-rw-r--r--src/thread/nt32/clone.c54
-rw-r--r--src/thread/nt32/pthread_detach.c6
-rw-r--r--src/thread/nt32/pthread_equal.c6
-rw-r--r--src/thread/nt32/pthread_self.c10
-rw-r--r--src/thread/nt32/syscall_cp.s15
18 files changed, 254 insertions, 0 deletions
diff --git a/src/env/nt32/__environ.s b/src/env/nt32/__environ.s
new file mode 100644
index 0000000..62b9ee6
--- /dev/null
+++ b/src/env/nt32/__environ.s
@@ -0,0 +1,11 @@
+.globl ____environ
+.globl ___environ
+.globl __environ
+.globl _environ
+
+.data
+____environ:
+___environ:
+__environ:
+_environ:
+ .long 0
diff --git a/src/fcntl/nt32/posix_fadvise.c b/src/fcntl/nt32/posix_fadvise.c
new file mode 100644
index 0000000..c95d7f4
--- /dev/null
+++ b/src/fcntl/nt32/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/nt32/libc.c b/src/internal/nt32/libc.c
new file mode 100644
index 0000000..43face8
--- /dev/null
+++ b/src/internal/nt32/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/nt32/syscall.s b/src/internal/nt32/syscall.s
new file mode 100644
index 0000000..3fcd5bb
--- /dev/null
+++ b/src/internal/nt32/syscall.s
@@ -0,0 +1,5 @@
+.text
+.global ___syscall
+
+___syscall:
+ jmp ___syscall_disp
diff --git a/src/ldso/nt32/dl_iterate_phdr.c b/src/ldso/nt32/dl_iterate_phdr.c
new file mode 100644
index 0000000..f98a509
--- /dev/null
+++ b/src/ldso/nt32/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/nt32/dynlink.c b/src/ldso/nt32/dynlink.c
new file mode 100644
index 0000000..c3cb23e
--- /dev/null
+++ b/src/ldso/nt32/dynlink.c
@@ -0,0 +1,62 @@
+#define _BSD_SOURCE
+
+#include <dlfcn.h>
+#include "psxglue.h"
+#include "pthread_impl.h"
+
+extern struct __ldso_vtbl * __ldso_vtbl;
+
+int __dladdr(const void * addr, Dl_info * info)
+{
+ return __ldso_vtbl->dladdr(addr,info);
+}
+
+int __dlinfo(void * dso, int req, void * res)
+{
+ return __ldso_vtbl->dlinfo(dso,req,res);
+}
+
+void *__dlsym(void * restrict p, const char * restrict s, void * restrict ra)
+{
+ return __ldso_vtbl->dlsym(p,s,ra);
+}
+
+void * dlopen(const char * file, int mode)
+{
+ return __ldso_vtbl->dlopen(file,mode);
+}
+
+int dlclose(void *p)
+{
+ return __ldso_vtbl->dlclose(p);
+}
+
+char * dlerror(void)
+{
+ return __ldso_vtbl->dlerror();
+}
+
+void __reset_tls(void)
+{
+ __ldso_vtbl->reset_tls();
+}
+
+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/nt32/start.s b/src/ldso/nt32/start.s
new file mode 100644
index 0000000..32dc52f
--- /dev/null
+++ b/src/ldso/nt32/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/nt32/tlsdesc.c b/src/ldso/nt32/tlsdesc.c
new file mode 100644
index 0000000..7015e30
--- /dev/null
+++ b/src/ldso/nt32/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/nt32/longjmp.s b/src/setjmp/nt32/longjmp.s
new file mode 100644
index 0000000..095a47f
--- /dev/null
+++ b/src/setjmp/nt32/longjmp.s
@@ -0,0 +1,9 @@
+.text
+.globl ___longjmp
+.globl __longjmp
+.globl _longjmp
+
+___longjmp:
+__longjmp:
+_longjmp:
+ test %edx, %edx # is val zero?
diff --git a/src/setjmp/nt32/setjmp.s b/src/setjmp/nt32/setjmp.s
new file mode 100644
index 0000000..1865f0c
--- /dev/null
+++ b/src/setjmp/nt32/setjmp.s
@@ -0,0 +1,14 @@
+.text
+.globl ___setjmp
+.globl __setjmp
+.globl _setjmp
+
+___setjmp:
+__setjmp:
+_setjmp:
+ pop (%ecx) # return address
+ mov %esp, 0x04(%ecx) # caller's stack pointer
+ push (%ecx) # restore own stack pointer
+
+ xor %eax, %eax
+ ret
diff --git a/src/stdio/nt32/fflush.c b/src/stdio/nt32/fflush.c
new file mode 100644
index 0000000..4c88f20
--- /dev/null
+++ b/src/stdio/nt32/fflush.c
@@ -0,0 +1,6 @@
+#include "../fflush.c"
+
+int __fflush_unlocked_impl(FILE *f)
+{
+ return __fflush_unlocked(f);
+}
diff --git a/src/thread/nt32/__set_thread_area.c b/src/thread/nt32/__set_thread_area.c
new file mode 100644
index 0000000..c50f6c6
--- /dev/null
+++ b/src/thread/nt32/__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/nt32/__tls_get_addr.c b/src/thread/nt32/__tls_get_addr.c
new file mode 100644
index 0000000..ad8d845
--- /dev/null
+++ b/src/thread/nt32/__tls_get_addr.c
@@ -0,0 +1,2 @@
+/* using a custom, register-based __emutls_get_address */
+typedef int dummy;
diff --git a/src/thread/nt32/clone.c b/src/thread/nt32/clone.c
new file mode 100644
index 0000000..fb53501
--- /dev/null
+++ b/src/thread/nt32/clone.c
@@ -0,0 +1,54 @@
+#include <syscall.h>
+
+struct pt_regs {
+ unsigned long ebp;
+ unsigned long ebx;
+ unsigned long eax;
+ unsigned long ecx;
+ unsigned long edx;
+ unsigned long esi;
+ unsigned long edi;
+ unsigned long orig_eax;
+ unsigned long eip;
+ unsigned long cs;
+ unsigned long eflags;
+ unsigned long esp;
+ 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.eip = (unsigned long)fn;
+ regs.ecx = (unsigned long)arg;
+ regs.edx = (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/nt32/pthread_detach.c b/src/thread/nt32/pthread_detach.c
new file mode 100644
index 0000000..85db4cb
--- /dev/null
+++ b/src/thread/nt32/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/nt32/pthread_equal.c b/src/thread/nt32/pthread_equal.c
new file mode 100644
index 0000000..a8fcd79
--- /dev/null
+++ b/src/thread/nt32/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/nt32/pthread_self.c b/src/thread/nt32/pthread_self.c
new file mode 100644
index 0000000..23fbc53
--- /dev/null
+++ b/src/thread/nt32/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/nt32/syscall_cp.s b/src/thread/nt32/syscall_cp.s
new file mode 100644
index 0000000..c52731f
--- /dev/null
+++ b/src/thread/nt32/syscall_cp.s
@@ -0,0 +1,15 @@
+.text
+.globl ___syscall_cp_asm
+.globl ___cp_begin
+.globl ___cp_end
+
+___syscall_cp_asm:
+___cp_begin:
+ mov (%ecx), %ecx /* check content of ptr */
+ test %ecx, %ecx
+ jnz ___cancel /* thread is pending cancellation */
+
+ jmp ___syscall
+
+___cp_end:
+ ret