comparison dyncallback/dyncall_thunk_mips64.c @ 116:c5cb02203df4

- mips n64 working thunks - todo update
author cslag
date Thu, 23 Jun 2016 12:38:51 +0200
parents
children 277f0eec3b29
comparison
equal deleted inserted replaced
115:b0d5b49bf418 116:c5cb02203df4
1 /*
2
3 Package: dyncall
4 Library: dyncallback
5 File: dyncallback/dyncall_thunk_mips64.c
6 Description: Thunk - Implementation for MIPS64
7 License:
8
9 Copyright (c) 2016 Tassilo Philipp <tphilipp@potion-studios.com>
10
11 Permission to use, copy, modify, and distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23 */
24
25 #include "dyncall_thunk.h"
26
27 static unsigned short b_48_63(x) { return ( (unsigned short) (((unsigned long long)x)>>48UL) ); }
28 static unsigned short b_32_47(x) { return ( (unsigned short) (((unsigned long long)x)>>32UL) ); }
29 static unsigned short b_16_31(x) { return ( (unsigned short) (((unsigned long long)x)>>16UL) ); }
30 static unsigned short b_00_16(x) { return ( (unsigned short) ((unsigned long long)x) ); }
31
32 void dcbInitThunk(DCThunk* p, void (*entry)())
33 {
34 /*
35
36 Thunk Register: $t8 ($24)
37 Call Address (sticking to t9 as for PIC calls on mips32): $t9 ($25)
38
39 mips64 thunk code:
40 lui $t8, p[48:63]
41 ori $t8, $t8, p[32:47]
42 sll $t8, 16
43 ori $t8, $t8, p[16:31]
44 sll $t8, 16
45 lui $t9, entry[48:63]
46 ori $t9, $t9, entry[32:47]
47 sll $t9, 16
48 ori $t9, $t9, entry[16:31]
49 sll $t9, 16
50 ori $t9, $t9, entry[0:15]
51 jr $t9
52 ori $t8, $t8, p[0:15] ; branch delay slot
53
54 Disassembly of section .text:
55
56 0000000000000000 <thunk>:
57 0: 3c180000 lui t8,0x0
58 4: 37180000 ori t8,t8,0x0
59 8: 0018c400 sll t8,t8,0x10
60 c: 37180000 ori t8,t8,0x0
61 10: 0018c400 sll t8,t8,0x10
62 14: 3c190000 lui t9,0x0
63 18: 37390000 ori t9,t9,0x0
64 1c: 0019cc00 sll t9,t9,0x10
65 20: 37390000 ori t9,t9,0x0
66 24: 0019cc00 sll t9,t9,0x10
67 28: 37390000 ori t9,t9,0x0
68 2c: 03200008 jr t9
69 30: 37180000 ori t8,t8,0x0
70
71 */
72
73 #if defined(DC__Endian_BIG)
74
75 p->text.s[ 0] = 0x3c18; p->text.s[ 1] = b_48_63(p); /* lui $t8, p[48:63] */
76 p->text.s[ 2] = 0x3718; p->text.s[ 3] = b_32_47(p); /* ori $t8, $t8, p[32:47] */
77 p->text.s[ 6] = 0x3718; p->text.s[ 7] = b_16_31(p); /* ori $t8, $t8, p[16:31] */
78 p->text.s[10] = 0x3c19; p->text.s[11] = b_48_63(entry); /* lui $t9, entry[48:63] */
79 p->text.s[12] = 0x3739; p->text.s[13] = b_32_47(entry); /* ori $t9, $t9, entry[32:47] */
80 p->text.s[16] = 0x3739; p->text.s[17] = b_16_31(entry); /* ori $t9, $t9, entry[16:31] */
81 p->text.s[20] = 0x3739; p->text.s[21] = b_00_16(entry); /* ori $t9, $t9, entry[0:15] */
82 p->text.s[24] = 0x3718; p->text.s[25] = b_00_16(p); /* ori $t8, $t8, p[0:15] - branch delay slot */
83
84 #else /* defined(DC__Endian_LITTLE) */
85
86 p->text.s[ 1] = 0x3c18; p->text.s[ 0] = b_48_63(p); /* lui $t8, p[48:63] */
87 p->text.s[ 3] = 0x3718; p->text.s[ 2] = b_32_47(p); /* ori $t8, $t8, p[32:47] */
88 p->text.s[ 7] = 0x3718; p->text.s[ 6] = b_16_31(p); /* ori $t8, $t8, p[16:31] */
89 p->text.s[11] = 0x3c19; p->text.s[10] = b_48_63(entry); /* lui $t9, entry[48:63] */
90 p->text.s[13] = 0x3739; p->text.s[12] = b_32_47(entry); /* ori $t9, $t9, entry[32:47] */
91 p->text.s[17] = 0x3739; p->text.s[16] = b_16_31(entry); /* ori $t9, $t9, entry[16:31] */
92 p->text.s[21] = 0x3739; p->text.s[20] = b_00_16(entry); /* ori $t9, $t9, entry[0:15] */
93 p->text.s[25] = 0x3718; p->text.s[24] = b_00_16(p); /* ori $t8, $t8, p[0:15] - branch delay slot */
94
95 #endif
96
97 p->text.i[ 2] = 0x0018c400; /* sll t8,t8,0x10 */
98 p->text.i[ 4] = 0x0018c400; /* sll t8,t8,0x10 */
99 p->text.i[ 7] = 0x0019cc00; /* sll t9,t9,0x10 */
100 p->text.i[ 9] = 0x0019cc00; /* sll t9,t9,0x10 */
101 p->text.i[11] = 0x03200008; /* jr $t9 */
102 }
103