2 * Copyright (c) 2013 Miodrag Vallat. <miod@openbsd.org>
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * ``Software''), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * vax Foreign Function Interface
29 #include <fficonfig.h>
36 * ffi_call_elfbsd(extended_cif *ecif, 4(%ap)
37 * unsigned bytes, 8(%ap)
38 * unsigned flags, 12(%ap)
39 * void *rvalue, 16(%ap)
40 * void (*fn)()); 20(%ap)
42 .globl ffi_call_elfbsd
43 .type ffi_call_elfbsd,@function
46 .word 0x00c # save R2 and R3
48 # Allocate stack space for the args
54 calls $2, ffi_prep_args
56 # Get function pointer
61 pushl %r0 # argument stack usage
62 movl %sp, %r0 # future %ap
66 1: bbc $10, 0(%r1), 1f
88 movl 16(%ap), %r3 # struct return address, if needed
90 movzwl 4(%fp), %r0 # previous PSW, without the saved registers mask
91 bisl2 $0x20000000, %r0 # calls frame
93 bicw2 $0xf003, %r2 # only keep R11-R2
95 bisl2 %r2, %r0 # saved register mask of the called function
100 # Invoke the function
101 pushal 2(%r1) # skip procedure entry mask
107 # Copy return value if necessary
112 bbc $0, 12(%ap), 1f # CIF_FLAGS_CHAR
116 bbc $1, 12(%ap), 1f # CIF_FLAGS_SHORT
120 bbc $2, 12(%ap), 1f # CIF_FLAGS_INT
124 bbc $3, 12(%ap), 1f # CIF_FLAGS_DINT
128 movl %r1, %r0 # might have been a struct
135 * ffi_closure_elfbsd(void);
136 * invoked with %r0: ffi_closure *closure
138 .globl ffi_closure_elfbsd
139 .type ffi_closure_elfbsd, @function
144 # Allocate room on stack for return value
147 # Invoke the closure function
148 pushal 4(%ap) # calling stack
149 pushal 4(%sp) # return value
151 calls $3, ffi_closure_elfbsd_inner
153 # Copy return value if necessary
154 bitb $1, %r0 # CIF_FLAGS_CHAR
159 bitb $2, %r0 # CIF_FLAGS_SHORT
164 bitb $4, %r0 # CIF_FLAGS_INT
169 bitb $8, %r0 # CIF_FLAGS_DINT
179 * ffi_closure_struct_elfbsd(void);
180 * invoked with %r0: ffi_closure *closure
181 * %r1: struct return address
183 .globl ffi_closure_struct_elfbsd
184 .type ffi_closure_struct_elfbsd, @function
186 ffi_closure_struct_elfbsd:
189 # Invoke the closure function
190 pushal 4(%ap) # calling stack
191 pushl %r1 # return value
193 calls $3, ffi_closure_elfbsd_inner