0
|
1 /*
|
|
2
|
|
3 Package: dyncall
|
|
4 Library: dyncall
|
|
5 File: dyncall/dyncall_callvm_mips_eabi.c
|
|
6 Description: Implementation of Call VM for mips "eabi" abi.
|
|
7 License:
|
|
8
|
|
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>,
|
|
10 Tassilo Philipp <tphilipp@potion-studios.com>
|
|
11
|
|
12 Permission to use, copy, modify, and distribute this software for any
|
|
13 purpose with or without fee is hereby granted, provided that the above
|
|
14 copyright notice and this permission notice appear in all copies.
|
|
15
|
|
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
|
24 */
|
|
25
|
|
26
|
|
27
|
|
28 #include "dyncall_callvm_mips_eabi.h"
|
|
29 #include "dyncall_alloc.h"
|
|
30
|
|
31 static void dc_callvm_reset_mips_eabi(DCCallVM* in_self)
|
|
32 {
|
|
33 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self;
|
|
34 dcVecReset(&self->mVecHead);
|
|
35 self->mIntRegs = 0;
|
|
36 self->mSingleRegs = 0;
|
|
37 }
|
|
38
|
|
39 static void dc_callvm_free_mips_eabi(DCCallVM* in_self)
|
|
40 {
|
|
41 dcFreeMem(in_self);
|
|
42 }
|
|
43
|
|
44 /* arg int -- fillup integer register file OR push on stack */
|
|
45
|
|
46 static void dc_callvm_argInt_mips_eabi(DCCallVM* in_self, DCint i)
|
|
47 {
|
|
48 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self;
|
|
49 /* fillup integer register file */
|
|
50 if (self->mIntRegs < 8)
|
|
51 self->mRegData.mIntData[self->mIntRegs++] = i;
|
|
52 else
|
|
53 dcVecAppend(&self->mVecHead, &i, sizeof(DCint));
|
|
54 }
|
|
55
|
|
56 static void dc_callvm_argPointer_mips_eabi(DCCallVM* in_self, DCpointer x)
|
|
57 {
|
|
58 dc_callvm_argInt_mips_eabi(in_self, * (DCint*) &x );
|
|
59 }
|
|
60
|
|
61 static void dc_callvm_argBool_mips_eabi(DCCallVM* in_self, DCbool x)
|
|
62 {
|
|
63 dc_callvm_argInt_mips_eabi(in_self, (DCint)x);
|
|
64 }
|
|
65
|
|
66 static void dc_callvm_argChar_mips_eabi(DCCallVM* in_self, DCchar x)
|
|
67 {
|
|
68 dc_callvm_argInt_mips_eabi(in_self, (DCint)x);
|
|
69 }
|
|
70
|
|
71 static void dc_callvm_argShort_mips_eabi(DCCallVM* in_self, DCshort x)
|
|
72 {
|
|
73 dc_callvm_argInt_mips_eabi(in_self, (DCint)x);
|
|
74 }
|
|
75
|
|
76 static void dc_callvm_argLong_mips_eabi(DCCallVM* in_self, DClong x)
|
|
77 {
|
|
78 dc_callvm_argInt_mips_eabi(in_self, (DCint)x);
|
|
79 }
|
|
80
|
|
81 static void dc_callvm_argLongLong_mips_eabi(DCCallVM* in_self, DClonglong Lv)
|
|
82 {
|
|
83 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self;
|
|
84
|
|
85 if (self->mIntRegs < 7) {
|
|
86 DCint* p = (DCint*) &Lv;
|
|
87 /* skip odd register (align 64 bit) */
|
|
88 self->mIntRegs += self->mIntRegs & 1;
|
|
89 self->mRegData.mIntData[self->mIntRegs++] = p[0];
|
|
90 self->mRegData.mIntData[self->mIntRegs++] = p[1];
|
|
91 } else {
|
|
92 self->mIntRegs = 8;
|
|
93 /* 64 bit values need to be aligned on 8 byte boundaries */
|
|
94 dcVecSkip(&self->mVecHead, dcVecSize(&self->mVecHead) & 4);
|
|
95 dcVecAppend(&self->mVecHead, &Lv, sizeof(DClonglong));
|
|
96 }
|
|
97 }
|
|
98
|
|
99 static void dc_callvm_argFloat_mips_eabi(DCCallVM* in_self, DCfloat x)
|
|
100 {
|
|
101 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self;
|
|
102 if (self->mSingleRegs < 8) {
|
|
103 self->mRegData.mSingleData[self->mSingleRegs++] = x;
|
|
104 } else {
|
|
105 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat) );
|
|
106 }
|
|
107 }
|
|
108
|
|
109 static void dc_callvm_argDouble_mips_eabi(DCCallVM* in_self, DCdouble x)
|
|
110 {
|
|
111 DClonglong* p = (DClonglong*) &x;
|
|
112 dc_callvm_argLongLong_mips_eabi(in_self, *p);
|
|
113 }
|
|
114
|
|
115 /* Call. */
|
|
116 void dc_callvm_call_mips_eabi(DCCallVM* in_self, DCpointer target)
|
|
117 {
|
|
118 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self;
|
|
119 dcCall_mips_eabi(target, &self->mRegData, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead));
|
|
120 }
|
|
121
|
84
|
122 static void dc_callvm_mode_mips_eabi(DCCallVM* in_self, DCint mode);
|
|
123
|
0
|
124 DCCallVM_vt gVT_mips_eabi =
|
|
125 {
|
|
126 &dc_callvm_free_mips_eabi
|
|
127 , &dc_callvm_reset_mips_eabi
|
|
128 , &dc_callvm_mode_mips_eabi
|
|
129 , &dc_callvm_argBool_mips_eabi
|
|
130 , &dc_callvm_argChar_mips_eabi
|
|
131 , &dc_callvm_argShort_mips_eabi
|
|
132 , &dc_callvm_argInt_mips_eabi
|
|
133 , &dc_callvm_argLong_mips_eabi
|
|
134 , &dc_callvm_argLongLong_mips_eabi
|
|
135 , &dc_callvm_argFloat_mips_eabi
|
|
136 , &dc_callvm_argDouble_mips_eabi
|
|
137 , &dc_callvm_argPointer_mips_eabi
|
|
138 , NULL /* argStruct */
|
|
139 , (DCvoidvmfunc*) &dc_callvm_call_mips_eabi
|
|
140 , (DCboolvmfunc*) &dc_callvm_call_mips_eabi
|
|
141 , (DCcharvmfunc*) &dc_callvm_call_mips_eabi
|
|
142 , (DCshortvmfunc*) &dc_callvm_call_mips_eabi
|
|
143 , (DCintvmfunc*) &dc_callvm_call_mips_eabi
|
|
144 , (DClongvmfunc*) &dc_callvm_call_mips_eabi
|
|
145 , (DClonglongvmfunc*) &dc_callvm_call_mips_eabi
|
|
146 , (DCfloatvmfunc*) &dc_callvm_call_mips_eabi
|
|
147 , (DCdoublevmfunc*) &dc_callvm_call_mips_eabi
|
|
148 , (DCpointervmfunc*) &dc_callvm_call_mips_eabi
|
|
149 , NULL /* callStruct */
|
|
150 };
|
|
151
|
84
|
152 /* mode: only a single mode available currently. */
|
|
153 static void dc_callvm_mode_mips_eabi(DCCallVM* in_self, DCint mode)
|
0
|
154 {
|
84
|
155 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self;
|
|
156 DCCallVM_vt* vt;
|
|
157
|
|
158 switch(mode) {
|
|
159 case DC_CALL_C_DEFAULT:
|
|
160 case DC_CALL_C_MIPS32_EABI:
|
|
161 case DC_CALL_C_ELLIPSIS:
|
|
162 case DC_CALL_C_ELLIPSIS_VARARGS:
|
|
163 vt = &gVT_mips_eabi;
|
|
164 break;
|
|
165 default:
|
|
166 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE;
|
|
167 return;
|
|
168 }
|
|
169 dc_callvm_base_init(&self->mInterface, vt);
|
0
|
170 }
|
|
171
|
84
|
172 /* Public API. */
|
0
|
173 DCCallVM* dcNewCallVM(DCsize size)
|
|
174 {
|
84
|
175 /* Store at least 16 bytes (4 words) for internal spill area. Assembly code depends on it. */
|
|
176 DCCallVM_mips_eabi* p = (DCCallVM_mips_eabi*)dcAllocMem(sizeof(DCCallVM_mips_eabi)+size+16);
|
|
177
|
|
178 dc_callvm_mode_mips_eabi((DCCallVM*)p, DC_CALL_C_DEFAULT);
|
|
179
|
|
180 dcVecInit(&p->mVecHead, size);
|
|
181 dc_callvm_reset_mips_eabi((DCCallVM*)p);
|
|
182
|
|
183 return (DCCallVM*)p;
|
0
|
184 }
|
|
185
|