1 /* -----------------------------------------------------------------------
2 hpux32.S - Copyright (c) 2006 Free Software Foundation, Inc.
3 based on src/pa/linux.S
5 HP-UX PA 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 THE AUTHOR 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>
34 .IMPORT $$dyncall,MILLICODE
38 /* void ffi_call_pa32(void (*)(char *, extended_cif *),
46 .export ffi_call_pa32,ENTRY,PRIV_LEV=3
47 .import ffi_prep_args_pa32,CODE
56 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
64 /* Setup the stack for calling prep_args...
65 We want the stack to look like this:
67 [ Previous stack ] <- %r3
69 [ 64-bytes register save area ] <- %r4
71 [ Stack space for actual call, passed as ] <- %arg0
72 [ arg0 to ffi_prep_args_pa32 ]
74 [ Stack for calling prep_args ] <- %sp
82 addl %arg2, %r4, %arg0 ; arg stack
83 stw %arg3, -48(%r3) ; save flags we need it later
86 %arg0(stack) -- set up above
87 %arg1(ecif) -- same as incoming param
88 %arg2(bytes) -- same as incoming param */
89 bl ffi_prep_args_pa32,%r2
93 /* now %sp should point where %arg0 was pointing. */
95 /* Load the arguments that should be passed in registers
96 The fp args are loaded by the prep_args function. */
102 /* in case the function is going to return a structure
103 we need to give it a place to put the result. */
104 ldw -52(%r3), %ret0 ; %ret0 <- rvalue
105 ldw -56(%r3), %r22 ; %r22 <- function to call
106 bl $$dyncall, %r31 ; Call the user function
109 /* Prepare to store the result; we need to recover flags and rvalue. */
110 ldw -48(%r3), %r21 ; r21 <- flags
111 ldw -52(%r3), %r20 ; r20 <- rvalue
113 /* Store the result according to the return type. The most
114 likely types should come first. */
117 comib,<>,n FFI_TYPE_INT, %r21, L$checkint8
122 comib,<>,n FFI_TYPE_UINT8, %r21, L$checkint16
127 comib,<>,n FFI_TYPE_UINT16, %r21, L$checkdbl
132 comib,<>,n FFI_TYPE_DOUBLE, %r21, L$checkfloat
137 comib,<>,n FFI_TYPE_FLOAT, %r21, L$checkll
142 comib,<>,n FFI_TYPE_UINT64, %r21, L$checksmst2
148 comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, L$checksmst3
149 /* 2-byte structs are returned in ret0 as ????xxyy. */
150 extru %ret0, 23, 8, %r22
151 stbs,ma %r22, 1(%r20)
156 comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, L$checksmst4
157 /* 3-byte structs are returned in ret0 as ??xxyyzz. */
158 extru %ret0, 15, 8, %r22
159 stbs,ma %r22, 1(%r20)
160 extru %ret0, 23, 8, %r22
161 stbs,ma %r22, 1(%r20)
166 comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, L$checksmst5
167 /* 4-byte structs are returned in ret0 as wwxxyyzz. */
168 extru %ret0, 7, 8, %r22
169 stbs,ma %r22, 1(%r20)
170 extru %ret0, 15, 8, %r22
171 stbs,ma %r22, 1(%r20)
172 extru %ret0, 23, 8, %r22
173 stbs,ma %r22, 1(%r20)
178 comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, L$checksmst6
179 /* 5 byte values are returned right justified:
181 5: ??????aa bbccddee */
182 stbs,ma %ret0, 1(%r20)
183 extru %ret1, 7, 8, %r22
184 stbs,ma %r22, 1(%r20)
185 extru %ret1, 15, 8, %r22
186 stbs,ma %r22, 1(%r20)
187 extru %ret1, 23, 8, %r22
188 stbs,ma %r22, 1(%r20)
193 comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, L$checksmst7
194 /* 6 byte values are returned right justified:
196 6: ????aabb ccddeeff */
197 extru %ret0, 23, 8, %r22
198 stbs,ma %r22, 1(%r20)
199 stbs,ma %ret0, 1(%r20)
200 extru %ret1, 7, 8, %r22
201 stbs,ma %r22, 1(%r20)
202 extru %ret1, 15, 8, %r22
203 stbs,ma %r22, 1(%r20)
204 extru %ret1, 23, 8, %r22
205 stbs,ma %r22, 1(%r20)
210 comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, L$checksmst8
211 /* 7 byte values are returned right justified:
213 7: ??aabbcc ddeeffgg */
214 extru %ret0, 15, 8, %r22
215 stbs,ma %r22, 1(%r20)
216 extru %ret0, 23, 8, %r22
217 stbs,ma %r22, 1(%r20)
218 stbs,ma %ret0, 1(%r20)
219 extru %ret1, 7, 8, %r22
220 stbs,ma %r22, 1(%r20)
221 extru %ret1, 15, 8, %r22
222 stbs,ma %r22, 1(%r20)
223 extru %ret1, 23, 8, %r22
224 stbs,ma %r22, 1(%r20)
229 comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, L$done
230 /* 8 byte values are returned right justified:
232 8: aabbccdd eeffgghh */
233 extru %ret0, 7, 8, %r22
234 stbs,ma %r22, 1(%r20)
235 extru %ret0, 15, 8, %r22
236 stbs,ma %r22, 1(%r20)
237 extru %ret0, 23, 8, %r22
238 stbs,ma %r22, 1(%r20)
239 stbs,ma %ret0, 1(%r20)
240 extru %ret1, 7, 8, %r22
241 stbs,ma %r22, 1(%r20)
242 extru %ret1, 15, 8, %r22
243 stbs,ma %r22, 1(%r20)
244 extru %ret1, 23, 8, %r22
245 stbs,ma %r22, 1(%r20)
249 /* all done, return */
250 copy %r4, %sp ; pop arg stack
252 ldwm -64(%sp), %r3 ; .. and pop stack
260 /* void ffi_closure_pa32(void);
261 Called with closure argument in %r21 */
265 .export ffi_closure_pa32,ENTRY,PRIV_LEV=3,RTNVAL=GR
266 .import ffi_closure_inner_pa32,CODE
271 .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
281 /* Put arguments onto the stack and call ffi_closure_inner. */
288 bl ffi_closure_inner_pa32, %r2
303 .EXPORT _GLOBAL__F_ffi_call_pa32,DATA
304 _GLOBAL__F_ffi_call_pa32
306 .word L$ECIE1-L$SCIE1 ;# Length of Common Information Entry
308 .word 0x0 ;# CIE Identifier Tag
309 .byte 0x1 ;# CIE Version
310 .ascii "\0" ;# CIE Augmentation
311 .uleb128 0x1 ;# CIE Code Alignment Factor
312 .sleb128 4 ;# CIE Data Alignment Factor
313 .byte 0x2 ;# CIE RA Column
314 .byte 0xc ;# DW_CFA_def_cfa
320 .word L$EFDE1-L$ASFDE1 ;# FDE Length
322 .word L$ASFDE1-L$frame1 ;# FDE CIE offset
323 .word L$FB1 ;# FDE initial location
324 .word L$FE1-L$FB1 ;# FDE address range
326 .byte 0x4 ;# DW_CFA_advance_loc4
328 .byte 0x83 ;# DW_CFA_offset, column 0x3
330 .byte 0x11 ;# DW_CFA_offset_extended_sf; save r2 at [r30-20]
334 .byte 0x4 ;# DW_CFA_advance_loc4
335 .word L$CFI12-L$CFI11
336 .byte 0xd ;# DW_CFA_def_cfa_register = r3
339 .byte 0x4 ;# DW_CFA_advance_loc4
340 .word L$CFI13-L$CFI12
341 .byte 0x84 ;# DW_CFA_offset, column 0x4
348 .word L$EFDE2-L$ASFDE2 ;# FDE Length
350 .word L$ASFDE2-L$frame1 ;# FDE CIE offset
351 .word L$FB2 ;# FDE initial location
352 .word L$FE2-L$FB2 ;# FDE address range
353 .byte 0x4 ;# DW_CFA_advance_loc4
355 .byte 0x83 ;# DW_CFA_offset, column 0x3
357 .byte 0x11 ;# DW_CFA_offset_extended_sf
361 .byte 0x4 ;# DW_CFA_advance_loc4
362 .word L$CFI22-L$CFI21
363 .byte 0xd ;# DW_CFA_def_cfa_register = r3