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