0
|
1 /*
|
|
2
|
|
3 Package: dyncall
|
|
4 Library: dyncall
|
|
5 File: dyncall/dyncall_callvm_sparc64.c
|
|
6 Description: Call VM for sparc64 64-bit processor architecture.
|
|
7 License:
|
|
8
|
|
9 Copyright (c) 2011-2015 Daniel Adler <dadler@uni-goettingen.de>
|
|
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
|
|
26
|
|
27 #include "dyncall_callvm_sparc64.h"
|
|
28 #include "dyncall_call_sparc64.h"
|
|
29 #include "dyncall_alloc.h"
|
|
30
|
|
31 #define IREGS 6
|
|
32 #define FREGS 16
|
|
33 #define SREGS 16
|
|
34 #define DHEAD (IREGS+FREGS)*8+SREGS*4
|
|
35
|
|
36 /* Reset argument buffer. */
|
|
37 static void dc_callvm_reset_sparc64(DCCallVM* in_self)
|
|
38 {
|
|
39 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
84
|
40 dcVecResize(&self->mVecHead, DHEAD);
|
0
|
41 self->mIntRegs = 0;
|
|
42 self->mFloatRegs = 0;
|
|
43 self->mUseSingleFlags = 0;
|
|
44 }
|
|
45
|
|
46
|
|
47 /* Destructor. */
|
|
48 static void dc_callvm_free_sparc64(DCCallVM* in_self)
|
|
49 {
|
|
50 dcFreeMem(in_self);
|
|
51 }
|
|
52
|
|
53 /* all integers are promoted to 64-bit. */
|
|
54
|
|
55 static void dc_callvm_argLongLong_sparc64(DCCallVM* in_self, DClonglong x)
|
|
56 {
|
|
57 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
|
58 if (self->mIntRegs < IREGS) {
|
|
59 * ( (DClonglong*) ( dcVecAt(&self->mVecHead, (self->mIntRegs++)*8) ) ) = x;
|
|
60 } else {
|
|
61 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong));
|
|
62 }
|
|
63 if (self->mFloatRegs < FREGS) self->mFloatRegs++;
|
|
64 }
|
|
65
|
|
66 static void dc_callvm_argLong_sparc64 (DCCallVM* in_self, DClong x) { dc_callvm_argLongLong_sparc64(in_self, (DClonglong) x ); }
|
|
67 static void dc_callvm_argInt_sparc64 (DCCallVM* in_self, DCint x) { dc_callvm_argLongLong_sparc64(in_self, (DClonglong) x ); }
|
|
68 static void dc_callvm_argBool_sparc64 (DCCallVM* in_self, DCbool x) { dc_callvm_argLongLong_sparc64(in_self, (DClonglong) x ); }
|
|
69 static void dc_callvm_argChar_sparc64 (DCCallVM* in_self, DCchar x) { dc_callvm_argLongLong_sparc64(in_self, (DClonglong) x ); }
|
|
70 static void dc_callvm_argShort_sparc64 (DCCallVM* in_self, DCshort x) { dc_callvm_argLongLong_sparc64(in_self, (DClonglong) x ); }
|
|
71 static void dc_callvm_argPointer_sparc64(DCCallVM* in_self, DCpointer x) { dc_callvm_argLongLong_sparc64(in_self, (DClonglong) x ); }
|
|
72
|
|
73 static void dc_callvm_argDouble_sparc64(DCCallVM* in_self, DCdouble x)
|
|
74 {
|
|
75 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
|
76 if (self->mFloatRegs < FREGS) {
|
|
77 * ((double*)dcVecAt(&self->mVecHead,(IREGS+(self->mFloatRegs++))*8)) = x;
|
|
78 }
|
|
79 if (self->mIntRegs < IREGS) {
|
|
80 self->mIntRegs++;
|
|
81 } else {
|
|
82 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble));
|
|
83 }
|
|
84 }
|
|
85
|
|
86 static void dc_callvm_argDouble_sparc64_ellipsis(DCCallVM* in_self, DCdouble x)
|
|
87 {
|
|
88 union {
|
|
89 long long l;
|
|
90 double d;
|
|
91 } u;
|
|
92 u.d = x;
|
|
93 dc_callvm_argLongLong_sparc64(in_self, u.l);
|
|
94 }
|
|
95
|
|
96 static void dc_callvm_argFloat_sparc64_ellipsis(DCCallVM* in_self, DCfloat x)
|
|
97 {
|
|
98 dc_callvm_argDouble_sparc64_ellipsis(in_self, (DCdouble) x);
|
|
99 }
|
|
100
|
|
101 static void dc_callvm_argFloat_sparc64(DCCallVM* in_self, DCfloat x)
|
|
102 {
|
|
103 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
|
104 if (self->mFloatRegs < FREGS) {
|
|
105 self->mUseSingleFlags |= 1<<self->mFloatRegs;
|
|
106 * ((float*)dcVecAt(&self->mVecHead,(IREGS+FREGS)*8 + (self->mFloatRegs++)*4)) = x;
|
|
107 }
|
|
108
|
|
109 if (self->mIntRegs < IREGS) {
|
|
110 self->mIntRegs++;
|
|
111 } else {
|
|
112 union {
|
|
113 DCdouble d;
|
|
114 DClonglong l;
|
|
115 DCfloat f[2];
|
|
116 } u;
|
|
117 u.f[1] = x;
|
|
118 dcVecAppend(&self->mVecHead, &u.l, sizeof(DClonglong));
|
|
119 }
|
|
120 }
|
|
121
|
|
122 #if 0
|
|
123 /* call: delegate to default call kernel */
|
|
124 static void dc_callvm_call_sparc64(DCCallVM* in_self, DCpointer target)
|
|
125 {
|
|
126 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
|
127 dcCall_sparc64(target, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead));
|
|
128 }
|
|
129 #endif
|
|
130
|
84
|
131 #if 0
|
|
132 /* Load integer 32-bit. */
|
|
133 static void dc_callvm_argInt_sparc64(DCCallVM* in_self, DCint x)
|
|
134 {
|
|
135 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
|
136 dcVecAppend(&self->mVecHead, &x, sizeof(DCint));
|
|
137 }
|
|
138
|
|
139 /* we propagate Bool,Char,Short,Int to LongLong. */
|
|
140
|
|
141 static void dc_callvm_argBool_sparc64(DCCallVM* in_self, DCbool x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
|
|
142 static void dc_callvm_argChar_sparc64(DCCallVM* in_self, DCchar x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
|
|
143 static void dc_callvm_argShort_sparc64(DCCallVM* in_self, DCshort x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
|
|
144 #endif
|
|
145
|
0
|
146 static void dc_callvm_mode_sparc64(DCCallVM* in_self, DCint mode);
|
|
147
|
|
148 DCCallVM_vt gVT_sparc64_ellipsis =
|
|
149 {
|
|
150 &dc_callvm_free_sparc64,
|
|
151 &dc_callvm_reset_sparc64,
|
|
152 &dc_callvm_mode_sparc64,
|
|
153 &dc_callvm_argBool_sparc64,
|
|
154 &dc_callvm_argChar_sparc64,
|
|
155 &dc_callvm_argShort_sparc64,
|
|
156 &dc_callvm_argInt_sparc64,
|
|
157 &dc_callvm_argLong_sparc64,
|
|
158 &dc_callvm_argLongLong_sparc64,
|
|
159 &dc_callvm_argFloat_sparc64_ellipsis,
|
|
160 &dc_callvm_argDouble_sparc64_ellipsis,
|
|
161 &dc_callvm_argPointer_sparc64,
|
|
162 NULL /* argStruct */,
|
|
163 (DCvoidvmfunc*) &dcCall_sparc64,
|
|
164 (DCboolvmfunc*) &dcCall_sparc64,
|
|
165 (DCcharvmfunc*) &dcCall_sparc64,
|
|
166 (DCshortvmfunc*) &dcCall_sparc64,
|
|
167 (DCintvmfunc*) &dcCall_sparc64,
|
|
168 (DClongvmfunc*) &dcCall_sparc64,
|
|
169 (DClonglongvmfunc*) &dcCall_sparc64,
|
|
170 (DCfloatvmfunc*) &dcCall_sparc64,
|
|
171 (DCdoublevmfunc*) &dcCall_sparc64,
|
|
172 (DCpointervmfunc*) &dcCall_sparc64,
|
|
173 NULL /* callStruct */
|
|
174 };
|
|
175
|
|
176 /* CallVM virtual table. */
|
|
177 DCCallVM_vt gVT_sparc64 =
|
|
178 {
|
|
179 &dc_callvm_free_sparc64,
|
|
180 &dc_callvm_reset_sparc64,
|
|
181 &dc_callvm_mode_sparc64,
|
|
182 &dc_callvm_argBool_sparc64,
|
|
183 &dc_callvm_argChar_sparc64,
|
|
184 &dc_callvm_argShort_sparc64,
|
|
185 &dc_callvm_argInt_sparc64,
|
|
186 &dc_callvm_argLong_sparc64,
|
|
187 &dc_callvm_argLongLong_sparc64,
|
|
188 &dc_callvm_argFloat_sparc64,
|
|
189 &dc_callvm_argDouble_sparc64,
|
|
190 &dc_callvm_argPointer_sparc64,
|
|
191 NULL /* argStruct */,
|
|
192 (DCvoidvmfunc*) &dcCall_sparc64,
|
|
193 (DCboolvmfunc*) &dcCall_sparc64,
|
|
194 (DCcharvmfunc*) &dcCall_sparc64,
|
|
195 (DCshortvmfunc*) &dcCall_sparc64,
|
|
196 (DCintvmfunc*) &dcCall_sparc64,
|
|
197 (DClongvmfunc*) &dcCall_sparc64,
|
|
198 (DClonglongvmfunc*) &dcCall_sparc64,
|
|
199 (DCfloatvmfunc*) &dcCall_sparc64,
|
|
200 (DCdoublevmfunc*) &dcCall_sparc64,
|
|
201 (DCpointervmfunc*) &dcCall_sparc64,
|
|
202 NULL /* callStruct */
|
|
203 };
|
|
204
|
|
205 /* mode: only a single mode available currently. */
|
|
206 static void dc_callvm_mode_sparc64(DCCallVM* in_self, DCint mode)
|
|
207 {
|
84
|
208 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
|
|
209 DCCallVM_vt* vt;
|
|
210
|
0
|
211 switch(mode) {
|
|
212 case DC_CALL_C_DEFAULT:
|
84
|
213 case DC_CALL_C_SPARC64:
|
0
|
214 case DC_CALL_C_ELLIPSIS:
|
84
|
215 vt = &gVT_sparc64;
|
0
|
216 break;
|
|
217 case DC_CALL_C_ELLIPSIS_VARARGS:
|
84
|
218 vt = &gVT_sparc64_ellipsis;
|
0
|
219 break;
|
|
220 default:
|
84
|
221 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE;
|
|
222 return;
|
0
|
223 }
|
84
|
224 dc_callvm_base_init(&self->mInterface, vt);
|
0
|
225 }
|
|
226
|
|
227 /* Public API. */
|
|
228 DCCallVM* dcNewCallVM(DCsize size)
|
|
229 {
|
84
|
230 /* output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least DHEAD bytes. */
|
|
231 DCCallVM_sparc64* p = (DCCallVM_sparc64*)dcAllocMem(sizeof(DCCallVM_sparc64)+DHEAD+size);
|
|
232
|
|
233 dc_callvm_mode_sparc64((DCCallVM*)p, DC_CALL_C_DEFAULT);
|
|
234
|
|
235 dcVecInit(&p->mVecHead,DHEAD+size);
|
|
236 dc_callvm_reset_sparc64(&p->mInterface);
|
|
237
|
|
238 return (DCCallVM*)p;
|
0
|
239 }
|
|
240
|