changeset 116:c5cb02203df4

- mips n64 working thunks - todo update
author cslag
date Thu, 23 Jun 2016 12:38:51 +0200
parents b0d5b49bf418
children 4a64b733dc76
files ToDo dyncallback/dyncall_callback_mips_n32_gas.s dyncallback/dyncall_callback_mips_n64_gas.s dyncallback/dyncall_thunk.c dyncallback/dyncall_thunk.h dyncallback/dyncall_thunk_mips64.c dyncallback/dyncall_thunk_mips64.h
diffstat 7 files changed, 165 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ToDo	Thu Jun 23 12:21:07 2016 +0200
+++ b/ToDo	Thu Jun 23 12:38:51 2016 +0200
@@ -75,7 +75,8 @@
 - add MIPS callbacks for n32, n64
 - finish PPC32 callbacks (see bugs section, below, BSD not working)
 - MIPS32 softfloat support (-msoft-float)
-- test MIPS o32 big endian
+- test MIPS o32 big endian (current port works on netbsd/pmax, which is little endian, and gcc -EB doesn't work on there)
+- test MIPS n64 little endian (current port works on openbsd/octeon, which is big endian)
 
 bindings:
 ---------
--- a/dyncallback/dyncall_callback_mips_n32_gas.s	Thu Jun 23 12:21:07 2016 +0200
+++ b/dyncallback/dyncall_callback_mips_n32_gas.s	Thu Jun 23 12:38:51 2016 +0200
@@ -22,12 +22,14 @@
 
 */
 
-    .section .mdebug.abiN32
-    .previous
-    .abicalls
-    .text
-    .align  2
+	.section .mdebug.abiN32
+	.previous
+	.abicalls
+	.text
+	.align  2
 	.globl dcCallbackThunkEntry
-    .ent   dcCallbackThunkEntry
+	.ent   dcCallbackThunkEntry
 dcCallbackThunkEntry:
 
+	.end dcCallbackThunkEntry
+
--- a/dyncallback/dyncall_callback_mips_n64_gas.s	Thu Jun 23 12:21:07 2016 +0200
+++ b/dyncallback/dyncall_callback_mips_n64_gas.s	Thu Jun 23 12:38:51 2016 +0200
@@ -22,12 +22,14 @@
 
 */
 
-    .section .mdebug.abi64
-    .previous
-    .abicalls
-    .text
-    .align  2
+	.section .mdebug.abi64
+	.previous
+	.abicalls
+	.text
+	.align  2
 	.globl dcCallbackThunkEntry
-    .ent   dcCallbackThunkEntry
+	.ent   dcCallbackThunkEntry
 dcCallbackThunkEntry:
 
+	.end dcCallbackThunkEntry
+
--- a/dyncallback/dyncall_thunk.c	Thu Jun 23 12:21:07 2016 +0200
+++ b/dyncallback/dyncall_thunk.c	Thu Jun 23 12:38:51 2016 +0200
@@ -45,6 +45,8 @@
 #include "dyncall_thunk_arm32_thumb.c"
 #elif defined(DC__Arch_MIPS)
 #include "dyncall_thunk_mips.c"
+#elif defined(DC__Arch_MIPS64)
+#include "dyncall_thunk_mips64.c"
 #elif defined(DC__Arch_Sparc)
 #include "dyncall_thunk_sparc32.c"
 #elif defined(DC__Arch_Sparcv9)
--- a/dyncallback/dyncall_thunk.h	Thu Jun 23 12:21:07 2016 +0200
+++ b/dyncallback/dyncall_thunk.h	Thu Jun 23 12:38:51 2016 +0200
@@ -75,6 +75,8 @@
 #include "dyncall_thunk_arm32_thumb.h"
 #elif defined (DC__Arch_MIPS)
 #include "dyncall_thunk_mips.h"
+#elif defined (DC__Arch_MIPS64)
+#include "dyncall_thunk_mips64.h"
 #elif defined (DC__Arch_Sparc)
 #include "dyncall_thunk_sparc32.h"
 #elif defined (DC__Arch_Sparcv9)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dyncallback/dyncall_thunk_mips64.c	Thu Jun 23 12:38:51 2016 +0200
@@ -0,0 +1,103 @@
+/*
+
+ Package: dyncall
+ Library: dyncallback
+ File: dyncallback/dyncall_thunk_mips64.c
+ Description: Thunk - Implementation for MIPS64
+ License:
+
+   Copyright (c) 2016 Tassilo Philipp <tphilipp@potion-studios.com>
+
+   Permission to use, copy, modify, and distribute this software for any
+   purpose with or without fee is hereby granted, provided that the above
+   copyright notice and this permission notice appear in all copies.
+
+   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+*/
+
+#include "dyncall_thunk.h"
+
+static unsigned short b_48_63(x) { return ( (unsigned short) (((unsigned long long)x)>>48UL) ); }
+static unsigned short b_32_47(x) { return ( (unsigned short) (((unsigned long long)x)>>32UL) ); }
+static unsigned short b_16_31(x) { return ( (unsigned short) (((unsigned long long)x)>>16UL) ); }
+static unsigned short b_00_16(x) { return ( (unsigned short)  ((unsigned long long)x)        ); }
+
+void dcbInitThunk(DCThunk* p, void (*entry)())
+{
+/*
+
+Thunk Register: $t8 ($24)
+Call Address (sticking to t9 as for PIC calls on mips32): $t9 ($25)
+
+mips64 thunk code:
+        lui $t8, p[48:63]
+        ori $t8, $t8, p[32:47]
+        sll $t8, 16
+        ori $t8, $t8, p[16:31]
+        sll $t8, 16
+        lui $t9, entry[48:63]
+        ori $t9, $t9, entry[32:47]
+        sll $t9, 16
+        ori $t9, $t9, entry[16:31]
+        sll $t9, 16
+        ori $t9, $t9, entry[0:15]
+        jr  $t9
+        ori $t8, $t8, p[0:15]  ; branch delay slot
+
+Disassembly of section .text:
+
+0000000000000000 <thunk>:
+   0:   3c180000        lui     t8,0x0
+   4:   37180000        ori     t8,t8,0x0
+   8:   0018c400        sll     t8,t8,0x10
+   c:   37180000        ori     t8,t8,0x0
+  10:   0018c400        sll     t8,t8,0x10
+  14:   3c190000        lui     t9,0x0
+  18:   37390000        ori     t9,t9,0x0
+  1c:   0019cc00        sll     t9,t9,0x10
+  20:   37390000        ori     t9,t9,0x0
+  24:   0019cc00        sll     t9,t9,0x10
+  28:   37390000        ori     t9,t9,0x0
+  2c:   03200008        jr      t9
+  30:   37180000        ori     t8,t8,0x0
+
+*/
+
+#if defined(DC__Endian_BIG)
+
+  p->text.s[ 0] = 0x3c18; p->text.s[ 1] = b_48_63(p);     /* lui $t8, p[48:63] */
+  p->text.s[ 2] = 0x3718; p->text.s[ 3] = b_32_47(p);     /* ori $t8, $t8, p[32:47] */
+  p->text.s[ 6] = 0x3718; p->text.s[ 7] = b_16_31(p);     /* ori $t8, $t8, p[16:31] */
+  p->text.s[10] = 0x3c19; p->text.s[11] = b_48_63(entry); /* lui $t9, entry[48:63] */
+  p->text.s[12] = 0x3739; p->text.s[13] = b_32_47(entry); /* ori $t9, $t9, entry[32:47] */
+  p->text.s[16] = 0x3739; p->text.s[17] = b_16_31(entry); /* ori $t9, $t9, entry[16:31] */
+  p->text.s[20] = 0x3739; p->text.s[21] = b_00_16(entry); /* ori $t9, $t9, entry[0:15] */
+  p->text.s[24] = 0x3718; p->text.s[25] = b_00_16(p);     /* ori $t8, $t8, p[0:15] - branch delay slot */
+
+#else /* defined(DC__Endian_LITTLE) */
+  
+  p->text.s[ 1] = 0x3c18; p->text.s[ 0] = b_48_63(p);     /* lui $t8, p[48:63] */
+  p->text.s[ 3] = 0x3718; p->text.s[ 2] = b_32_47(p);     /* ori $t8, $t8, p[32:47] */
+  p->text.s[ 7] = 0x3718; p->text.s[ 6] = b_16_31(p);     /* ori $t8, $t8, p[16:31] */
+  p->text.s[11] = 0x3c19; p->text.s[10] = b_48_63(entry); /* lui $t9, entry[48:63] */
+  p->text.s[13] = 0x3739; p->text.s[12] = b_32_47(entry); /* ori $t9, $t9, entry[32:47] */
+  p->text.s[17] = 0x3739; p->text.s[16] = b_16_31(entry); /* ori $t9, $t9, entry[16:31] */
+  p->text.s[21] = 0x3739; p->text.s[20] = b_00_16(entry); /* ori $t9, $t9, entry[0:15] */
+  p->text.s[25] = 0x3718; p->text.s[24] = b_00_16(p);     /* ori $t8, $t8, p[0:15] - branch delay slot */
+  
+#endif
+
+  p->text.i[ 2] = 0x0018c400; /* sll t8,t8,0x10 */
+  p->text.i[ 4] = 0x0018c400; /* sll t8,t8,0x10 */
+  p->text.i[ 7] = 0x0019cc00; /* sll t9,t9,0x10 */
+  p->text.i[ 9] = 0x0019cc00; /* sll t9,t9,0x10 */
+  p->text.i[11] = 0x03200008; /* jr $t9 */
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dyncallback/dyncall_thunk_mips64.h	Thu Jun 23 12:38:51 2016 +0200
@@ -0,0 +1,40 @@
+/*
+
+ Package: dyncall
+ Library: dyncallback
+ File: dyncallback/dyncall_thunk_mips64.h
+ Description: Thunk - Header for MIPS64
+ License:
+
+   Copyright (c) 2016 Tassilo Philipp <tphilipp@potion-studios.com>
+
+   Permission to use, copy, modify, and distribute this software for any
+   purpose with or without fee is hereby granted, provided that the above
+   copyright notice and this permission notice appear in all copies.
+
+   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+*/
+
+
+#ifndef DYNCALL_THUNK_MIPS64_H
+#define DYNCALL_THUNK_MIPS64_H
+
+struct DCThunk_
+{
+  union {
+    unsigned short s[26];
+    unsigned int   i[13];
+  } text;
+};
+
+#define DCTHUNK_MIPS64_SIZE	52
+
+#endif /* DYNCALL_THUNK_MIPS64_H */
+