comparison dyncall/dyncall_callvm_sparc.c @ 0:3e629dc19168

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