1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 2009 Bradley Smith <brad@brad-smith.co.uk>
AVR32 Foreign Function Interface
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------- */
#define LIBFFI_ASM
#include <fficonfig.h>
#include <ffi.h>
/* r12: ffi_prep_args
* r11: &ecif
* r10: size
* r9: cif->flags
* r8: ecif.rvalue
* sp+0: cif->rstruct_flag
* sp+4: fn */
.text
.align 1
.globl ffi_call_SYSV
.type ffi_call_SYSV, @function
ffi_call_SYSV:
stm --sp, r0,r1,lr
stm --sp, r8-r12
mov r0, sp
/* Make room for all of the new args. */
sub sp, r10
/* Pad to make way for potential skipped registers */
sub sp, 20
/* Call ffi_prep_args(stack, &ecif). */
/* r11 already set */
mov r1, r12
mov r12, sp
icall r1
/* Save new argument size */
mov r1, r12
/* Move first 5 parameters in registers. */
ldm sp++, r8-r12
/* call (fn) (...). */
ld.w r1, r0[36]
icall r1
/* Remove the space we pushed for the args. */
mov sp, r0
/* Load r1 with the rstruct flag. */
ld.w r1, sp[32]
/* Load r9 with the return type code. */
ld.w r9, sp[12]
/* Load r8 with the return value pointer. */
ld.w r8, sp[16]
/* If the return value pointer is NULL, assume no return value. */
cp.w r8, 0
breq .Lend
/* Check if return type is actually a struct */
cp.w r1, 0
breq 1f
/* Return 8bit */
cp.w r9, FFI_TYPE_UINT8
breq .Lstore8
/* Return 16bit */
cp.w r9, FFI_TYPE_UINT16
breq .Lstore16
1:
/* Return 32bit */
cp.w r9, FFI_TYPE_UINT32
breq .Lstore32
cp.w r9, FFI_TYPE_UINT16
breq .Lstore32
cp.w r9, FFI_TYPE_UINT8
breq .Lstore32
/* Return 64bit */
cp.w r9, FFI_TYPE_UINT64
breq .Lstore64
/* Didn't match anything */
bral .Lend
.Lstore64:
st.w r8[0], r11
st.w r8[4], r10
bral .Lend
.Lstore32:
st.w r8[0], r12
bral .Lend
.Lstore16:
st.h r8[0], r12
bral .Lend
.Lstore8:
st.b r8[0], r12
bral .Lend
.Lend:
sub sp, -20
ldm sp++, r0,r1,pc
.size ffi_call_SYSV, . - ffi_call_SYSV
/* r12: __ctx
* r11: __rstruct_flag
* r10: __inner */
.align 1
.globl ffi_closure_SYSV
.type ffi_closure_SYSV, @function
ffi_closure_SYSV:
stm --sp, r0,lr
mov r0, r11
mov r8, r10
sub r10, sp, -8
sub sp, 12
st.w sp[8], sp
sub r11, sp, -8
icall r8
/* Check if return type is actually a struct */
cp.w r0, 0
breq 1f
/* Return 8bit */
cp.w r12, FFI_TYPE_UINT8
breq .Lget8
/* Return 16bit */
cp.w r12, FFI_TYPE_UINT16
breq .Lget16
1:
/* Return 32bit */
cp.w r12, FFI_TYPE_UINT32
breq .Lget32
cp.w r12, FFI_TYPE_UINT16
breq .Lget32
cp.w r12, FFI_TYPE_UINT8
breq .Lget32
/* Return 64bit */
cp.w r12, FFI_TYPE_UINT64
breq .Lget64
/* Didn't match anything */
bral .Lclend
.Lget64:
ld.w r11, sp[0]
ld.w r10, sp[4]
bral .Lclend
.Lget32:
ld.w r12, sp[0]
bral .Lclend
.Lget16:
ld.uh r12, sp[0]
bral .Lclend
.Lget8:
ld.ub r12, sp[0]
bral .Lclend
.Lclend:
sub sp, -12
ldm sp++, r0,lr
sub sp, -20
mov pc, lr
.size ffi_closure_SYSV, . - ffi_closure_SYSV
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif
|