annotate dyncallback/dyncall_thunk_mips64.c @ 542:a73a5cd50c19

- fix passing aggregate-by-val on x64/sysv: subaggr classification for aggr *arrays* was wrong (was problematic when there ware exactly 2 8bytes to be classified, potentially be passed via registers)
author Tassilo Philipp
date Mon, 02 May 2022 15:32:41 +0200
parents f5577f6bf97a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
1 /*
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
2
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
3 Package: dyncall
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
4 Library: dyncallback
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
5 File: dyncallback/dyncall_thunk_mips64.c
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
6 Description: Thunk - Implementation for MIPS64
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
7 License:
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
8
281
f5577f6bf97a - file header cleanups for release
Tassilo Philipp
parents: 137
diff changeset
9 Copyright (c) 2016-2018 Tassilo Philipp <tphilipp@potion-studios.com>
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
10
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
11 Permission to use, copy, modify, and distribute this software for any
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
12 purpose with or without fee is hereby granted, provided that the above
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
13 copyright notice and this permission notice appear in all copies.
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
14
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
22
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
23 */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
24
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
25 #include "dyncall_thunk.h"
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
26
136
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
27 #define b_48_63(x) ((unsigned short)(((unsigned long long)x)>>48UL))
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
28 #define b_32_47(x) ((unsigned short)(((unsigned long long)x)>>32UL))
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
29 #define b_16_31(x) ((unsigned short)(((unsigned long long)x)>>16UL))
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
30 #define b_00_15(x) ((unsigned short) ((unsigned long long)x) )
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
31
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
32 void dcbInitThunk(DCThunk* p, void (*entry)())
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
33 {
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
34 /*
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
35
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
36 Thunk Register: $t8 ($24)
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
37 Call Address (sticking to t9 as for PIC calls on mips32): $t9 ($25)
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
38
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
39 mips64 thunk code:
137
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
40 lui $t8, p[48:63]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
41 ori $t8, $t8, p[32:47]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
42 dsll $t8, 16
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
43 ori $t8, $t8, p[16:31]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
44 dsll $t8, 16
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
45 lui $t9, entry[48:63]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
46 ori $t9, $t9, entry[32:47]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
47 dsll $t9, 16
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
48 ori $t9, $t9, entry[16:31]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
49 dsll $t9, 16
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
50 ori $t9, $t9, entry[0:15]
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
51 jr $t9
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
52 ori $t8, $t8, p[0:15] ; branch delay slot
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
53
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
54 Disassembly of section .text:
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
55
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
56 0000000000000000 <thunk>:
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
57 0: 3c180000 lui t8,0x0
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
58 4: 37180000 ori t8,t8,0x0
137
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
59 8: 0018c438 dsll t8,t8,0x10
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
60 c: 37180000 ori t8,t8,0x0
137
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
61 10: 0018c438 dsll t8,t8,0x10
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
62 14: 3c190000 lui t9,0x0
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
63 18: 37390000 ori t9,t9,0x0
137
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
64 1c: 0019cc38 dsll t9,t9,0x10
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
65 20: 37390000 ori t9,t9,0x0
137
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
66 24: 0019cc38 dsll t9,t9,0x10
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
67 28: 37390000 ori t9,t9,0x0
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
68 2c: 03200008 jr t9
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
69 30: 37180000 ori t8,t8,0x0
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
70
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
71 */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
72
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
73 #if defined(DC__Endian_BIG)
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
74
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
75 p->text.s[ 0] = 0x3c18; p->text.s[ 1] = b_48_63(p); /* lui $t8, p[48:63] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
76 p->text.s[ 2] = 0x3718; p->text.s[ 3] = b_32_47(p); /* ori $t8, $t8, p[32:47] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
77 p->text.s[ 6] = 0x3718; p->text.s[ 7] = b_16_31(p); /* ori $t8, $t8, p[16:31] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
78 p->text.s[10] = 0x3c19; p->text.s[11] = b_48_63(entry); /* lui $t9, entry[48:63] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
79 p->text.s[12] = 0x3739; p->text.s[13] = b_32_47(entry); /* ori $t9, $t9, entry[32:47] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
80 p->text.s[16] = 0x3739; p->text.s[17] = b_16_31(entry); /* ori $t9, $t9, entry[16:31] */
136
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
81 p->text.s[20] = 0x3739; p->text.s[21] = b_00_15(entry); /* ori $t9, $t9, entry[0:15] */
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
82 p->text.s[24] = 0x3718; p->text.s[25] = b_00_15(p); /* ori $t8, $t8, p[0:15] - branch delay slot */
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
83
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
84 #else /* defined(DC__Endian_LITTLE) */
136
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
85
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
86 p->text.s[ 1] = 0x3c18; p->text.s[ 0] = b_48_63(p); /* lui $t8, p[48:63] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
87 p->text.s[ 3] = 0x3718; p->text.s[ 2] = b_32_47(p); /* ori $t8, $t8, p[32:47] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
88 p->text.s[ 7] = 0x3718; p->text.s[ 6] = b_16_31(p); /* ori $t8, $t8, p[16:31] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
89 p->text.s[11] = 0x3c19; p->text.s[10] = b_48_63(entry); /* lui $t9, entry[48:63] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
90 p->text.s[13] = 0x3739; p->text.s[12] = b_32_47(entry); /* ori $t9, $t9, entry[32:47] */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
91 p->text.s[17] = 0x3739; p->text.s[16] = b_16_31(entry); /* ori $t9, $t9, entry[16:31] */
136
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
92 p->text.s[21] = 0x3739; p->text.s[20] = b_00_15(entry); /* ori $t9, $t9, entry[0:15] */
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
93 p->text.s[25] = 0x3718; p->text.s[24] = b_00_15(p); /* ori $t8, $t8, p[0:15] - branch delay slot */
277f0eec3b29 - mips64 thunk fix
cslag
parents: 116
diff changeset
94
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
95 #endif
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
96
137
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
97 p->text.i[ 2] = 0x0018c438; /* dsll t8,t8,0x10 */
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
98 p->text.i[ 4] = 0x0018c438; /* dsll t8,t8,0x10 */
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
99 p->text.i[ 7] = 0x0019cc38; /* dsll t9,t9,0x10 */
4b5ae110848c - mips64 callback fixes for addresses using high word bits
cslag
parents: 136
diff changeset
100 p->text.i[ 9] = 0x0019cc38; /* dsll t9,t9,0x10 */
116
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
101 p->text.i[11] = 0x03200008; /* jr $t9 */
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
102 }
c5cb02203df4 - mips n64 working thunks
cslag
parents:
diff changeset
103