1 /* -----------------------------------------------------------------------
2 linux.S - (c) 2003-2004 Randolph Chung <tausq@debian.org>
4 (c) 2016 John David Anglin
6 HPPA Foreign Function Interface
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 ``Software''), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice shall be included
17 in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL RENESAS TECHNOLOGY BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
26 ----------------------------------------------------------------------- */
29 #include <fficonfig.h>
36 /* void ffi_call_pa32(void (*)(char *, extended_cif *),
42 ffi_go_closure *closure);
45 .export ffi_call_pa32,code
46 .import ffi_prep_args_pa32,code
48 .type ffi_call_pa32, @function
52 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
60 .cfi_def_cfa_register 3
62 /* Setup the stack for calling prep_args...
63 We want the stack to look like this:
65 [ Previous stack ] <- %r3
67 [ 64-bytes register save area ] <- %r4
69 [ Stack space for actual call, passed as ] <- %arg0
70 [ arg0 to ffi_prep_args_pa32 ]
72 [ Stack for calling prep_args ] <- %sp
80 addl %arg2, %r4, %arg0 /* arg stack */
81 stw %arg3, -48(%r3) /* save flags; we need it later */
84 %arg0(stack) -- set up above
85 %arg1(ecif) -- same as incoming param
86 %arg2(bytes) -- same as incoming param */
87 bl ffi_prep_args_pa32,%r2
91 /* now %sp should point where %arg0 was pointing. */
93 /* Load the arguments that should be passed in registers
94 The fp args were loaded by the prep_args function. */
100 /* in case the function is going to return a structure
101 we need to give it a place to put the result. */
102 ldw -52(%r3), %ret0 /* %ret0 <- rvalue */
103 ldw -56(%r3), %r22 /* %r22 <- function to call */
104 ldw -60(%r3), %ret1 /* %ret1 <- closure */
105 bl $$dyncall, %r31 /* Call the user function */
108 /* Prepare to store the result; we need to recover flags and rvalue. */
109 ldw -48(%r3), %r21 /* r21 <- flags */
110 ldw -52(%r3), %r20 /* r20 <- rvalue */
112 /* Store the result according to the return type. */
115 comib,<>,n FFI_TYPE_INT, %r21, .Lcheckint8
120 comib,<>,n FFI_TYPE_UINT8, %r21, .Lcheckint16
125 comib,<>,n FFI_TYPE_UINT16, %r21, .Lcheckdbl
130 comib,<>,n FFI_TYPE_DOUBLE, %r21, .Lcheckfloat
135 comib,<>,n FFI_TYPE_FLOAT, %r21, .Lcheckll
140 comib,<>,n FFI_TYPE_UINT64, %r21, .Lchecksmst2
146 comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, .Lchecksmst3
147 /* 2-byte structs are returned in ret0 as ????xxyy. */
148 extru %ret0, 23, 8, %r22
149 stbs,ma %r22, 1(%r20)
154 comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, .Lchecksmst4
155 /* 3-byte structs are returned in ret0 as ??xxyyzz. */
156 extru %ret0, 15, 8, %r22
157 stbs,ma %r22, 1(%r20)
158 extru %ret0, 23, 8, %r22
159 stbs,ma %r22, 1(%r20)
164 comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, .Lchecksmst5
165 /* 4-byte structs are returned in ret0 as wwxxyyzz. */
166 extru %ret0, 7, 8, %r22
167 stbs,ma %r22, 1(%r20)
168 extru %ret0, 15, 8, %r22
169 stbs,ma %r22, 1(%r20)
170 extru %ret0, 23, 8, %r22
171 stbs,ma %r22, 1(%r20)
176 comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, .Lchecksmst6
177 /* 5 byte values are returned right justified:
179 5: ??????aa bbccddee */
180 stbs,ma %ret0, 1(%r20)
181 extru %ret1, 7, 8, %r22
182 stbs,ma %r22, 1(%r20)
183 extru %ret1, 15, 8, %r22
184 stbs,ma %r22, 1(%r20)
185 extru %ret1, 23, 8, %r22
186 stbs,ma %r22, 1(%r20)
191 comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, .Lchecksmst7
192 /* 6 byte values are returned right justified:
194 6: ????aabb ccddeeff */
195 extru %ret0, 23, 8, %r22
196 stbs,ma %r22, 1(%r20)
197 stbs,ma %ret0, 1(%r20)
198 extru %ret1, 7, 8, %r22
199 stbs,ma %r22, 1(%r20)
200 extru %ret1, 15, 8, %r22
201 stbs,ma %r22, 1(%r20)
202 extru %ret1, 23, 8, %r22
203 stbs,ma %r22, 1(%r20)
208 comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, .Lchecksmst8
209 /* 7 byte values are returned right justified:
211 7: ??aabbcc ddeeffgg */
212 extru %ret0, 15, 8, %r22
213 stbs,ma %r22, 1(%r20)
214 extru %ret0, 23, 8, %r22
215 stbs,ma %r22, 1(%r20)
216 stbs,ma %ret0, 1(%r20)
217 extru %ret1, 7, 8, %r22
218 stbs,ma %r22, 1(%r20)
219 extru %ret1, 15, 8, %r22
220 stbs,ma %r22, 1(%r20)
221 extru %ret1, 23, 8, %r22
222 stbs,ma %r22, 1(%r20)
227 comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, .Ldone
228 /* 8 byte values are returned right justified:
230 8: aabbccdd eeffgghh */
231 extru %ret0, 7, 8, %r22
232 stbs,ma %r22, 1(%r20)
233 extru %ret0, 15, 8, %r22
234 stbs,ma %r22, 1(%r20)
235 extru %ret0, 23, 8, %r22
236 stbs,ma %r22, 1(%r20)
237 stbs,ma %ret0, 1(%r20)
238 extru %ret1, 7, 8, %r22
239 stbs,ma %r22, 1(%r20)
240 extru %ret1, 15, 8, %r22
241 stbs,ma %r22, 1(%r20)
242 extru %ret1, 23, 8, %r22
243 stbs,ma %r22, 1(%r20)
247 /* all done, return */
248 copy %r4, %sp /* pop arg stack */
250 ldwm -64(%sp), %r3 /* .. and pop stack */
258 /* void ffi_closure_pa32(void);
259 Called with ffi_closure argument in %r21. */
260 .export ffi_closure_pa32,code
261 .import ffi_closure_inner_pa32,code
262 .type ffi_closure_pa32, @function
266 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
274 .cfi_def_cfa_register 3
278 /* Put arguments onto the stack and call ffi_closure_inner. */
284 /* Closure type 0. */
287 bl ffi_closure_inner_pa32, %r2
300 /* void ffi_go_closure_pa32(void);
301 Called with ffi_go_closure argument in %ret1. */
302 .export ffi_go_closure_pa32,code
303 .import ffi_closure_inner_pa32,code
304 .type ffi_go_closure_pa32, @function
308 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
316 .cfi_def_cfa_register 3
320 /* Put arguments onto the stack and call ffi_closure_inner. */
326 /* Closure type 1. */
329 bl ffi_closure_inner_pa32, %r2