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 * m88k Foreign Function Interface
29 #include <fficonfig.h>
35 * ffi_cacheflush_OBSD(unsigned int addr, %r2
36 * unsigned int size); %r3
39 .globl ffi_cacheflush_OBSD
40 .type ffi_cacheflush_OBSD,@function
45 .size ffi_cacheflush_OBSD, . - ffi_cacheflush_OBSD
48 * ffi_call_OBSD(unsigned bytes, %r2
49 * extended_cif *ecif, %r3
56 .type ffi_call_OBSD,@function
63 | Save the few arguments we'll need after ffi_prep_args()
67 | Allocate room for the image of r2-r9, and the stack space for
68 | the args (rounded to a 16-byte boundary)
69 addu %r2, %r2, (8 * 4) + 15
73 | Fill register and stack image
81 | Save pointer to return struct address, if any
84 | Get function pointer
88 | Fetch the register arguments
89 ld.d %r2, %r31, (0 * 4)
90 ld.d %r4, %r31, (2 * 4)
91 ld.d %r6, %r31, (4 * 4)
92 ld.d %r8, %r31, (6 * 4)
93 addu %r31, %r31, (8 * 4)
98 | Restore stack now that we don't need the args anymore
101 | Figure out what to return as the function's return value
102 ld %r5, %r31, 12 | rvalue
103 ld %r4, %r31, 8 | flags
107 bb0 0, %r4, 1f | CIF_FLAGS_INT
112 bb0 1, %r4, 1f | CIF_FLAGS_DINT
122 .size ffi_call_OBSD, . - ffi_call_OBSD
125 * ffi_closure_OBSD(ffi_closure *closure); %r13
128 .globl ffi_closure_OBSD
129 .type ffi_closure_OBSD, @function
136 | Make room on the stack for saved register arguments and return
138 subu %r31, %r31, (8 * 4) + (2 * 4)
139 st.d %r2, %r31, (0 * 4)
140 st.d %r4, %r31, (2 * 4)
141 st.d %r6, %r31, (4 * 4)
142 st.d %r8, %r31, (6 * 4)
144 | Invoke the closure function
145 or %r5, %r30, 0 | calling stack
146 addu %r4, %r31, 0 | saved registers
147 addu %r3, %r31, (8 * 4) | return value
148 or %r2, %r13, %r0 | closure
150 bsr ffi_closure_OBSD_inner#plt
152 bsr ffi_closure_OBSD_inner
155 | Figure out what to return as the function's return value
156 bb0 0, %r2, 1f | CIF_FLAGS_INT
157 ld %r2, %r31, (8 * 4)
161 bb0 1, %r2, 1f | CIF_FLAGS_DINT
162 ld.d %r2, %r31, (8 * 4)
172 .size ffi_closure_OBSD,.-ffi_closure_OBSD
175 * ffi_closure_struct_OBSD(ffi_closure *closure); %r13
178 .globl ffi_closure_struct_OBSD
179 .type ffi_closure_struct_OBSD, @function
180 ffi_closure_struct_OBSD:
186 | Make room on the stack for saved register arguments
187 subu %r31, %r31, (8 * 4)
188 st.d %r2, %r31, (0 * 4)
189 st.d %r4, %r31, (2 * 4)
190 st.d %r6, %r31, (4 * 4)
191 st.d %r8, %r31, (6 * 4)
193 | Invoke the closure function
194 or %r5, %r30, 0 | calling stack
195 addu %r4, %r31, 0 | saved registers
196 or %r3, %r12, 0 | return value
197 or %r2, %r13, %r0 | closure
199 bsr ffi_closure_OBSD_inner#plt
201 bsr ffi_closure_OBSD_inner
209 .size ffi_closure_struct_OBSD,.-ffi_closure_struct_OBSD