Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_sparc.c @ 533:71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
* integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv)
* windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.)
* see Changelog for details
- new calling convention modes for thiscalls (platform agnostic, was specific before)
* new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL)
- dcCallF(), dcVCallF(), dcArgF() and dcVArgF():
* added support for aggregates-by-value (wasn't part of patch)
* change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change)
- added macros to feature test implementation for aggregate-by-value and syscall support
- changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order
- doc:
* man page updates to describe aggregate interface
* manual overview changes to highlight platforms with aggregate-by-value support
- test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author | Tassilo Philipp |
---|---|
date | Thu, 21 Apr 2022 13:35:47 +0200 |
parents | ddfb9577a00e |
children |
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, |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
118 NULL /* argAggr */, |
466
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, |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
129 NULL /* callAggr */, |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
130 NULL /* beginAggr */ |
0 | 131 }; |
132 | |
84 | 133 /* mode: only a single mode available currently. */ |
134 static void dc_callvm_mode_sparc(DCCallVM* in_self, DCint mode) | |
135 { | |
136 DCCallVM_sparc* self = (DCCallVM_sparc*)in_self; | |
137 DCCallVM_vt* vt; | |
138 | |
139 switch(mode) { | |
140 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
|
141 case DC_CALL_C_DEFAULT_THIS: |
84 | 142 case DC_CALL_C_SPARC32: |
143 case DC_CALL_C_ELLIPSIS: | |
144 case DC_CALL_C_ELLIPSIS_VARARGS: | |
145 vt = &gVT_sparc; | |
146 break; | |
147 default: | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
148 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 149 return; |
150 } | |
151 dc_callvm_base_init(&self->mInterface, vt); | |
152 } | |
153 | |
0 | 154 /* Public API. */ |
155 DCCallVM* dcNewCallVM(DCsize size) | |
156 { | |
163 | 157 DCCallVM_sparc* p; |
158 | |
84 | 159 /* the six output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least 24 bytes. */ |
160 size = DC_MAX(size, sizeof(void*)*(6+1)); | |
163 | 161 p = (DCCallVM_sparc*)dcAllocMem(sizeof(DCCallVM_sparc)+size); |
84 | 162 |
163 dc_callvm_mode_sparc((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
164 | |
165 dcVecInit(&p->mVecHead, size); | |
166 | |
167 return (DCCallVM*)p; | |
0 | 168 } |
169 |