Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_eabi.c @ 553:a93bb23fca8c
win build fix
author | Tassilo Philipp |
---|---|
date | Mon, 20 Jun 2022 15:25:01 +0200 |
parents | 71c884e610f0 |
children |
rev | line source |
---|---|
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 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
9 Copyright (c) 2007-2020 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 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 | |
366
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
31 |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
32 void dcCall_mips_eabi(DCpointer target, DCRegData_mips_eabi* regdata, DCsize stksize, DCpointer stkdata); |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
33 |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
34 |
0 | 35 static void dc_callvm_reset_mips_eabi(DCCallVM* in_self) |
36 { | |
37 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self; | |
38 dcVecReset(&self->mVecHead); | |
39 self->mIntRegs = 0; | |
40 self->mSingleRegs = 0; | |
41 } | |
42 | |
43 static void dc_callvm_free_mips_eabi(DCCallVM* in_self) | |
44 { | |
45 dcFreeMem(in_self); | |
46 } | |
47 | |
48 /* arg int -- fillup integer register file OR push on stack */ | |
49 | |
50 static void dc_callvm_argInt_mips_eabi(DCCallVM* in_self, DCint i) | |
51 { | |
52 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self; | |
53 /* fillup integer register file */ | |
54 if (self->mIntRegs < 8) | |
55 self->mRegData.mIntData[self->mIntRegs++] = i; | |
56 else | |
57 dcVecAppend(&self->mVecHead, &i, sizeof(DCint)); | |
58 } | |
59 | |
60 static void dc_callvm_argPointer_mips_eabi(DCCallVM* in_self, DCpointer x) | |
61 { | |
62 dc_callvm_argInt_mips_eabi(in_self, * (DCint*) &x ); | |
63 } | |
64 | |
65 static void dc_callvm_argBool_mips_eabi(DCCallVM* in_self, DCbool x) | |
66 { | |
67 dc_callvm_argInt_mips_eabi(in_self, (DCint)x); | |
68 } | |
69 | |
70 static void dc_callvm_argChar_mips_eabi(DCCallVM* in_self, DCchar x) | |
71 { | |
72 dc_callvm_argInt_mips_eabi(in_self, (DCint)x); | |
73 } | |
74 | |
75 static void dc_callvm_argShort_mips_eabi(DCCallVM* in_self, DCshort x) | |
76 { | |
77 dc_callvm_argInt_mips_eabi(in_self, (DCint)x); | |
78 } | |
79 | |
80 static void dc_callvm_argLong_mips_eabi(DCCallVM* in_self, DClong x) | |
81 { | |
82 dc_callvm_argInt_mips_eabi(in_self, (DCint)x); | |
83 } | |
84 | |
85 static void dc_callvm_argLongLong_mips_eabi(DCCallVM* in_self, DClonglong Lv) | |
86 { | |
87 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self; | |
88 | |
89 if (self->mIntRegs < 7) { | |
90 DCint* p = (DCint*) &Lv; | |
91 /* skip odd register (align 64 bit) */ | |
92 self->mIntRegs += self->mIntRegs & 1; | |
93 self->mRegData.mIntData[self->mIntRegs++] = p[0]; | |
94 self->mRegData.mIntData[self->mIntRegs++] = p[1]; | |
95 } else { | |
96 self->mIntRegs = 8; | |
97 /* 64 bit values need to be aligned on 8 byte boundaries */ | |
98 dcVecSkip(&self->mVecHead, dcVecSize(&self->mVecHead) & 4); | |
99 dcVecAppend(&self->mVecHead, &Lv, sizeof(DClonglong)); | |
100 } | |
101 } | |
102 | |
103 static void dc_callvm_argFloat_mips_eabi(DCCallVM* in_self, DCfloat x) | |
104 { | |
105 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self; | |
106 if (self->mSingleRegs < 8) { | |
107 self->mRegData.mSingleData[self->mSingleRegs++] = x; | |
108 } else { | |
109 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat) ); | |
110 } | |
111 } | |
112 | |
113 static void dc_callvm_argDouble_mips_eabi(DCCallVM* in_self, DCdouble x) | |
114 { | |
115 DClonglong* p = (DClonglong*) &x; | |
116 dc_callvm_argLongLong_mips_eabi(in_self, *p); | |
117 } | |
118 | |
119 /* Call. */ | |
120 void dc_callvm_call_mips_eabi(DCCallVM* in_self, DCpointer target) | |
121 { | |
122 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self; | |
123 dcCall_mips_eabi(target, &self->mRegData, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead)); | |
124 } | |
125 | |
84 | 126 static void dc_callvm_mode_mips_eabi(DCCallVM* in_self, DCint mode); |
127 | |
0 | 128 DCCallVM_vt gVT_mips_eabi = |
129 { | |
130 &dc_callvm_free_mips_eabi | |
131 , &dc_callvm_reset_mips_eabi | |
132 , &dc_callvm_mode_mips_eabi | |
133 , &dc_callvm_argBool_mips_eabi | |
134 , &dc_callvm_argChar_mips_eabi | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
135 , &dc_callvm_argShort_mips_eabi |
0 | 136 , &dc_callvm_argInt_mips_eabi |
137 , &dc_callvm_argLong_mips_eabi | |
138 , &dc_callvm_argLongLong_mips_eabi | |
139 , &dc_callvm_argFloat_mips_eabi | |
140 , &dc_callvm_argDouble_mips_eabi | |
141 , &dc_callvm_argPointer_mips_eabi | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
142 , NULL /* argAggr */ |
0 | 143 , (DCvoidvmfunc*) &dc_callvm_call_mips_eabi |
144 , (DCboolvmfunc*) &dc_callvm_call_mips_eabi | |
145 , (DCcharvmfunc*) &dc_callvm_call_mips_eabi | |
146 , (DCshortvmfunc*) &dc_callvm_call_mips_eabi | |
147 , (DCintvmfunc*) &dc_callvm_call_mips_eabi | |
148 , (DClongvmfunc*) &dc_callvm_call_mips_eabi | |
149 , (DClonglongvmfunc*) &dc_callvm_call_mips_eabi | |
150 , (DCfloatvmfunc*) &dc_callvm_call_mips_eabi | |
151 , (DCdoublevmfunc*) &dc_callvm_call_mips_eabi | |
152 , (DCpointervmfunc*) &dc_callvm_call_mips_eabi | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
153 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
154 , NULL /* beginAggr */ |
0 | 155 }; |
156 | |
84 | 157 /* mode: only a single mode available currently. */ |
158 static void dc_callvm_mode_mips_eabi(DCCallVM* in_self, DCint mode) | |
0 | 159 { |
84 | 160 DCCallVM_mips_eabi* self = (DCCallVM_mips_eabi*)in_self; |
161 DCCallVM_vt* vt; | |
162 | |
163 switch(mode) { | |
164 case DC_CALL_C_DEFAULT: | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
165 case DC_CALL_C_DEFAULT_THIS: |
84 | 166 case DC_CALL_C_MIPS32_EABI: |
167 case DC_CALL_C_ELLIPSIS: | |
168 case DC_CALL_C_ELLIPSIS_VARARGS: | |
169 vt = &gVT_mips_eabi; | |
170 break; | |
171 default: | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
172 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 173 return; |
174 } | |
175 dc_callvm_base_init(&self->mInterface, vt); | |
0 | 176 } |
177 | |
84 | 178 /* Public API. */ |
0 | 179 DCCallVM* dcNewCallVM(DCsize size) |
180 { | |
84 | 181 /* Store at least 16 bytes (4 words) for internal spill area. Assembly code depends on it. */ |
182 DCCallVM_mips_eabi* p = (DCCallVM_mips_eabi*)dcAllocMem(sizeof(DCCallVM_mips_eabi)+size+16); | |
183 | |
184 dc_callvm_mode_mips_eabi((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
185 | |
186 dcVecInit(&p->mVecHead, size); | |
187 dc_callvm_reset_mips_eabi((DCCallVM*)p); | |
188 | |
189 return (DCCallVM*)p; | |
0 | 190 } |
191 |