1 /* -----------------------------------------------------------------------
2 linux.S - (c) 2003-2004 Randolph Chung <tausq@debian.org>
5 HPPA Foreign Function Interface
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 ``Software''), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL RENESAS TECHNOLOGY BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
28 #include <fficonfig.h>
35 /* void ffi_call_pa32(void (*)(char *, extended_cif *),
43 .export ffi_call_pa32,code
44 .import ffi_prep_args_pa32,code
46 .type ffi_call_pa32, @function
50 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
59 /* Setup the stack for calling prep_args...
60 We want the stack to look like this:
62 [ Previous stack ] <- %r3
64 [ 64-bytes register save area ] <- %r4
66 [ Stack space for actual call, passed as ] <- %arg0
67 [ arg0 to ffi_prep_args_pa32 ]
69 [ Stack for calling prep_args ] <- %sp
77 addl %arg2, %r4, %arg0 /* arg stack */
78 stw %arg3, -48(%r3) /* save flags; we need it later */
81 %arg0(stack) -- set up above
82 %arg1(ecif) -- same as incoming param
83 %arg2(bytes) -- same as incoming param */
84 bl ffi_prep_args_pa32,%r2
88 /* now %sp should point where %arg0 was pointing. */
90 /* Load the arguments that should be passed in registers
91 The fp args were loaded by the prep_args function. */
97 /* in case the function is going to return a structure
98 we need to give it a place to put the result. */
99 ldw -52(%r3), %ret0 /* %ret0 <- rvalue */
100 ldw -56(%r3), %r22 /* %r22 <- function to call */
101 bl $$dyncall, %r31 /* Call the user function */
104 /* Prepare to store the result; we need to recover flags and rvalue. */
105 ldw -48(%r3), %r21 /* r21 <- flags */
106 ldw -52(%r3), %r20 /* r20 <- rvalue */
108 /* Store the result according to the return type. */
111 comib,<>,n FFI_TYPE_INT, %r21, .Lcheckint8
116 comib,<>,n FFI_TYPE_UINT8, %r21, .Lcheckint16
121 comib,<>,n FFI_TYPE_UINT16, %r21, .Lcheckdbl
126 comib,<>,n FFI_TYPE_DOUBLE, %r21, .Lcheckfloat
131 comib,<>,n FFI_TYPE_FLOAT, %r21, .Lcheckll
136 comib,<>,n FFI_TYPE_UINT64, %r21, .Lchecksmst2
142 comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, .Lchecksmst3
143 /* 2-byte structs are returned in ret0 as ????xxyy. */
144 extru %ret0, 23, 8, %r22
145 stbs,ma %r22, 1(%r20)
150 comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, .Lchecksmst4
151 /* 3-byte structs are returned in ret0 as ??xxyyzz. */
152 extru %ret0, 15, 8, %r22
153 stbs,ma %r22, 1(%r20)
154 extru %ret0, 23, 8, %r22
155 stbs,ma %r22, 1(%r20)
160 comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, .Lchecksmst5
161 /* 4-byte structs are returned in ret0 as wwxxyyzz. */
162 extru %ret0, 7, 8, %r22
163 stbs,ma %r22, 1(%r20)
164 extru %ret0, 15, 8, %r22
165 stbs,ma %r22, 1(%r20)
166 extru %ret0, 23, 8, %r22
167 stbs,ma %r22, 1(%r20)
172 comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, .Lchecksmst6
173 /* 5 byte values are returned right justified:
175 5: ??????aa bbccddee */
176 stbs,ma %ret0, 1(%r20)
177 extru %ret1, 7, 8, %r22
178 stbs,ma %r22, 1(%r20)
179 extru %ret1, 15, 8, %r22
180 stbs,ma %r22, 1(%r20)
181 extru %ret1, 23, 8, %r22
182 stbs,ma %r22, 1(%r20)
187 comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, .Lchecksmst7
188 /* 6 byte values are returned right justified:
190 6: ????aabb ccddeeff */
191 extru %ret0, 23, 8, %r22
192 stbs,ma %r22, 1(%r20)
193 stbs,ma %ret0, 1(%r20)
194 extru %ret1, 7, 8, %r22
195 stbs,ma %r22, 1(%r20)
196 extru %ret1, 15, 8, %r22
197 stbs,ma %r22, 1(%r20)
198 extru %ret1, 23, 8, %r22
199 stbs,ma %r22, 1(%r20)
204 comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, .Lchecksmst8
205 /* 7 byte values are returned right justified:
207 7: ??aabbcc ddeeffgg */
208 extru %ret0, 15, 8, %r22
209 stbs,ma %r22, 1(%r20)
210 extru %ret0, 23, 8, %r22
211 stbs,ma %r22, 1(%r20)
212 stbs,ma %ret0, 1(%r20)
213 extru %ret1, 7, 8, %r22
214 stbs,ma %r22, 1(%r20)
215 extru %ret1, 15, 8, %r22
216 stbs,ma %r22, 1(%r20)
217 extru %ret1, 23, 8, %r22
218 stbs,ma %r22, 1(%r20)
223 comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, .Ldone
224 /* 8 byte values are returned right justified:
226 8: aabbccdd eeffgghh */
227 extru %ret0, 7, 8, %r22
228 stbs,ma %r22, 1(%r20)
229 extru %ret0, 15, 8, %r22
230 stbs,ma %r22, 1(%r20)
231 extru %ret0, 23, 8, %r22
232 stbs,ma %r22, 1(%r20)
233 stbs,ma %ret0, 1(%r20)
234 extru %ret1, 7, 8, %r22
235 stbs,ma %r22, 1(%r20)
236 extru %ret1, 15, 8, %r22
237 stbs,ma %r22, 1(%r20)
238 extru %ret1, 23, 8, %r22
239 stbs,ma %r22, 1(%r20)
243 /* all done, return */
244 copy %r4, %sp /* pop arg stack */
246 ldwm -64(%sp), %r3 /* .. and pop stack */
254 /* void ffi_closure_pa32(void);
255 Called with closure argument in %r21 */
256 .export ffi_closure_pa32,code
257 .import ffi_closure_inner_pa32,code
259 .type ffi_closure_pa32, @function
263 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
274 /* Put arguments onto the stack and call ffi_closure_inner. */
281 bl ffi_closure_inner_pa32, %r2
294 .section ".eh_frame",EH_FRAME_FLAGS,@progbits
296 .word .LECIE1-.LSCIE1 ;# Length of Common Information Entry
298 .word 0x0 ;# CIE Identifier Tag
299 .byte 0x1 ;# CIE Version
300 .ascii "\0" ;# CIE Augmentation
301 .uleb128 0x1 ;# CIE Code Alignment Factor
302 .sleb128 4 ;# CIE Data Alignment Factor
303 .byte 0x2 ;# CIE RA Column
304 .byte 0xc ;# DW_CFA_def_cfa
310 .word .LEFDE1-.LASFDE1 ;# FDE Length
312 .word .LASFDE1-.Lframe1 ;# FDE CIE offset
313 .word .LFB1 ;# FDE initial location
314 .word .LFE1-.LFB1 ;# FDE address range
316 .byte 0x4 ;# DW_CFA_advance_loc4
318 .byte 0x83 ;# DW_CFA_offset, column 0x3
320 .byte 0x11 ;# DW_CFA_offset_extended_sf; save r2 at [r30-20]
324 .byte 0x4 ;# DW_CFA_advance_loc4
325 .word .LCFI12-.LCFI11
326 .byte 0xd ;# DW_CFA_def_cfa_register = r3
329 .byte 0x4 ;# DW_CFA_advance_loc4
330 .word .LCFI13-.LCFI12
331 .byte 0x84 ;# DW_CFA_offset, column 0x4
338 .word .LEFDE2-.LASFDE2 ;# FDE Length
340 .word .LASFDE2-.Lframe1 ;# FDE CIE offset
341 .word .LFB2 ;# FDE initial location
342 .word .LFE2-.LFB2 ;# FDE address range
343 .byte 0x4 ;# DW_CFA_advance_loc4
345 .byte 0x83 ;# DW_CFA_offset, column 0x3
347 .byte 0x11 ;# DW_CFA_offset_extended_sf
351 .byte 0x4 ;# DW_CFA_advance_loc4
352 .word .LCFI22-.LCFI21
353 .byte 0xd ;# DW_CFA_def_cfa_register = r3