Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_sparc.c @ 520:bb4933eab7d6
- call_suite_aggrs: makefile fix
author | Tassilo Philipp |
---|---|
date | Mon, 11 Apr 2022 22:49:04 +0200 |
parents | ddfb9577a00e |
children | 71c884e610f0 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callvm_sparc.c | |
6 Description: Call VM for sparc processor architecture. | |
7 License: | |
8 | |
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
|
9 Copyright (c) 2011-2020 Daniel Adler <dadler@uni-goettingen.de> |
0 | 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_sparc.h" | |
28 #include "dyncall_utils.h" | |
29 #include "dyncall_alloc.h" | |
30 #define DEFAULT_STACK_ALIGN 16 | |
31 | |
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
|
32 |
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 void dcCall_sparc(DCpointer target, DCsize size, DCpointer data); |
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 |
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
|
35 |
0 | 36 /* Destructor. */ |
37 static void dc_callvm_free_sparc(DCCallVM* in_self) | |
38 { | |
39 dcFreeMem(in_self); | |
40 } | |
41 | |
42 /* Reset argument buffer. */ | |
43 static void dc_callvm_reset_sparc(DCCallVM* in_self) | |
44 { | |
45 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
46 dcVecReset(&self->mVecHead); | |
47 } | |
48 | |
49 /* Load integer 32-bit. */ | |
50 static void dc_callvm_argInt_sparc(DCCallVM* in_self, DCint x) | |
51 { | |
52 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
53 dcVecAppend(&self->mVecHead, &x, sizeof(DCint)); | |
54 } | |
55 | |
56 /* we propagate Bool,Char,Short to Int. */ | |
57 | |
58 static void dc_callvm_argBool_sparc(DCCallVM* in_self, DCbool x) { dc_callvm_argInt_sparc(in_self, (DCint)x); } | |
59 static void dc_callvm_argChar_sparc(DCCallVM* in_self, DCchar x) { dc_callvm_argInt_sparc(in_self, (DCint)x); } | |
60 static void dc_callvm_argShort_sparc(DCCallVM* in_self, DCshort x) { dc_callvm_argInt_sparc(in_self, (DCint)x); } | |
61 | |
62 /* handle others Pointer, Long, LongLong, Float and Double as-is. */ | |
63 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
64 static void dc_callvm_argPointer_sparc(DCCallVM* in_self, DCpointer x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
65 { |
0 | 66 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; |
67 dcVecAppend(&self->mVecHead, &x, sizeof(DCpointer)); | |
68 } | |
69 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
70 static void dc_callvm_argLong_sparc(DCCallVM* in_self, DClong x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
71 { |
0 | 72 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; |
73 dcVecAppend(&self->mVecHead, &x, sizeof(DClong)); | |
74 } | |
75 static void dc_callvm_argLongLong_sparc(DCCallVM* in_self, DClonglong x) | |
76 { | |
77 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
78 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong)); | |
79 } | |
80 static void dc_callvm_argFloat_sparc(DCCallVM* in_self, DCfloat x) | |
81 { | |
82 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
83 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat)); | |
84 } | |
85 static void dc_callvm_argDouble_sparc(DCCallVM* in_self, DCdouble x) | |
86 { | |
87 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
88 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble)); | |
89 } | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
90 |
0 | 91 /* we call directly with 'RTYPE dcCall(DCCallVM* in_self, DCpointer target)' */ |
92 #if 0 | |
93 /* call: delegate to default call kernel */ | |
94 static void dc_callvm_call_sparc(DCCallVM* in_self, DCpointer target) | |
95 { | |
96 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
97 dcCall_sparc(target, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead)); | |
98 } | |
99 #endif | |
100 | |
84 | 101 static void dc_callvm_mode_sparc(DCCallVM* in_self, DCint mode); |
102 | |
0 | 103 /* CallVM virtual table. */ |
104 DCCallVM_vt gVT_sparc = | |
105 { | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
106 &dc_callvm_free_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
107 &dc_callvm_reset_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
108 &dc_callvm_mode_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
109 &dc_callvm_argBool_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
110 &dc_callvm_argChar_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
111 &dc_callvm_argShort_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
112 &dc_callvm_argInt_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
113 &dc_callvm_argLong_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
114 &dc_callvm_argLongLong_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
115 &dc_callvm_argFloat_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
116 &dc_callvm_argDouble_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
117 &dc_callvm_argPointer_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
118 NULL /* argStruct */, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
119 (DCvoidvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
120 (DCboolvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
121 (DCcharvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
122 (DCshortvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
123 (DCintvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
124 (DClongvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
125 (DClonglongvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
126 (DCfloatvmfunc*) &dcCall_sparc, |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
127 (DCdoublevmfunc*) &dcCall_sparc, |
0 | 128 (DCpointervmfunc*) &dcCall_sparc, |
129 NULL /* callStruct */ | |
130 }; | |
131 | |
84 | 132 /* mode: only a single mode available currently. */ |
133 static void dc_callvm_mode_sparc(DCCallVM* in_self, DCint mode) | |
134 { | |
135 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
136 DCCallVM_vt* vt; | |
137 | |
138 switch(mode) { | |
139 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
|
140 case DC_CALL_C_DEFAULT_THIS: |
84 | 141 case DC_CALL_C_SPARC32: |
142 case DC_CALL_C_ELLIPSIS: | |
143 case DC_CALL_C_ELLIPSIS_VARARGS: | |
144 vt = &gVT_sparc; | |
145 break; | |
146 default: | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
147 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 148 return; |
149 } | |
150 dc_callvm_base_init(&self->mInterface, vt); | |
151 } | |
152 | |
0 | 153 /* Public API. */ |
154 DCCallVM* dcNewCallVM(DCsize size) | |
155 { | |
163 | 156 DCCallVM_sparc* p; |
157 | |
84 | 158 /* the six output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least 24 bytes. */ |
159 size = DC_MAX(size, sizeof(void*)*(6+1)); | |
163 | 160 p = (DCCallVM_sparc*)dcAllocMem(sizeof(DCCallVM_sparc)+size); |
84 | 161 |
162 dc_callvm_mode_sparc((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
163 | |
164 dcVecInit(&p->mVecHead, size); | |
165 | |
166 return (DCCallVM*)p; | |
0 | 167 } |
168 |