summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/fiddle/libffi-3.2.1/src/m88k/obsd.S
blob: 1944a23de424594a92cb39b4258357f6a4a1e789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright (c) 2013 Miodrag Vallat.  <miod@openbsd.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * ``Software''), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/*
 * m88k Foreign Function Interface
 */

#define LIBFFI_ASM      
#include <fficonfig.h>
#include <ffi.h>

        .text

/*
 * ffi_cacheflush_OBSD(unsigned int addr,       %r2
 *                     unsigned int size);      %r3
 */
        .align  4
        .globl  ffi_cacheflush_OBSD
        .type   ffi_cacheflush_OBSD,@function
ffi_cacheflush_OBSD:
        tb0     0,   %r0, 451
        or      %r0, %r0, %r0
        jmp     %r1
        .size   ffi_cacheflush_OBSD, . - ffi_cacheflush_OBSD

/*
 * ffi_call_OBSD(unsigned bytes,                %r2
 *               extended_cif *ecif,            %r3
 *               unsigned flags,                %r4
 *               void *rvalue,                  %r5
 *               void (*fn)());                 %r6
 */
        .align  4
        .globl  ffi_call_OBSD
        .type   ffi_call_OBSD,@function
ffi_call_OBSD:
        subu    %r31, %r31, 32
        st      %r30, %r31, 4
        st      %r1,  %r31, 0
        addu    %r30, %r31, 32

        | Save the few arguments we'll need after ffi_prep_args()
        st.d    %r4, %r31, 8
        st      %r6, %r31, 16

        | Allocate room for the image of r2-r9, and the stack space for
        | the args (rounded to a 16-byte boundary)
        addu    %r2,  %r2,  (8 * 4) + 15
        clr     %r2,  %r2,  4<0>
        subu    %r31, %r31, %r2

        | Fill register and stack image
        or      %r2, %r31, %r0
#ifdef PIC
        bsr     ffi_prep_args#plt
#else
        bsr     ffi_prep_args
#endif

        | Save pointer to return struct address, if any
        or      %r12, %r2, %r0

        | Get function pointer
        subu    %r4,  %r30, 32
        ld      %r1,  %r4,  16

        | Fetch the register arguments
        ld.d    %r2, %r31, (0 * 4)
        ld.d    %r4, %r31, (2 * 4)
        ld.d    %r6, %r31, (4 * 4)
        ld.d    %r8, %r31, (6 * 4)
        addu    %r31, %r31, (8 * 4)

        | Invoke the function
        jsr     %r1

        | Restore stack now that we don't need the args anymore
        subu    %r31, %r30, 32

        | Figure out what to return as the function's return value
        ld      %r5, %r31, 12           | rvalue
        ld      %r4, %r31, 8            | flags

        bcnd    eq0, %r5, 9f

        bb0     0, %r4, 1f              | CIF_FLAGS_INT
        st      %r2, %r5, 0
        br      9f

1:
        bb0     1, %r4, 1f              | CIF_FLAGS_DINT
        st.d    %r2, %r5, 0
        br      9f

1:
9:
        ld      %r1,  %r31, 0
        ld      %r30, %r31, 4
        jmp.n   %r1
         addu   %r31, %r31, 32
        .size   ffi_call_OBSD, . - ffi_call_OBSD

/*
 * ffi_closure_OBSD(ffi_closure *closure);      %r13
 */
        .align  4
        .globl  ffi_closure_OBSD
        .type   ffi_closure_OBSD, @function
ffi_closure_OBSD:
        subu    %r31, %r31, 16
        st      %r30, %r31, 4
        st      %r1,  %r31, 0
        addu    %r30, %r31, 16

        | Make room on the stack for saved register arguments and return
        | value
        subu    %r31, %r31, (8 * 4) + (2 * 4)
        st.d    %r2,  %r31, (0 * 4)
        st.d    %r4,  %r31, (2 * 4)
        st.d    %r6,  %r31, (4 * 4)
        st.d    %r8,  %r31, (6 * 4)

        | Invoke the closure function
        or      %r5,  %r30, 0                   | calling stack
        addu    %r4,  %r31, 0                   | saved registers
        addu    %r3,  %r31, (8 * 4)             | return value
        or      %r2,  %r13, %r0                 | closure
#ifdef PIC
        bsr     ffi_closure_OBSD_inner#plt
#else
        bsr     ffi_closure_OBSD_inner
#endif

        | Figure out what to return as the function's return value
        bb0     0, %r2, 1f              | CIF_FLAGS_INT
        ld      %r2, %r31, (8 * 4)
        br      9f

1:
        bb0     1, %r2, 1f              | CIF_FLAGS_DINT
        ld.d    %r2, %r31, (8 * 4)
        br      9f

1:
9:
        subu    %r31, %r30, 16
        ld      %r1,  %r31, 0
        ld      %r30, %r31, 4
        jmp.n   %r1
         addu   %r31, %r31, 16
        .size   ffi_closure_OBSD,.-ffi_closure_OBSD

/*
 * ffi_closure_struct_OBSD(ffi_closure *closure);       %r13
 */
        .align  4
        .globl  ffi_closure_struct_OBSD
        .type   ffi_closure_struct_OBSD, @function
ffi_closure_struct_OBSD:
        subu    %r31, %r31, 16
        st      %r30, %r31, 4
        st      %r1,  %r31, 0
        addu    %r30, %r31, 16

        | Make room on the stack for saved register arguments
        subu    %r31, %r31, (8 * 4)
        st.d    %r2,  %r31, (0 * 4)
        st.d    %r4,  %r31, (2 * 4)
        st.d    %r6,  %r31, (4 * 4)
        st.d    %r8,  %r31, (6 * 4)

        | Invoke the closure function
        or      %r5,  %r30, 0                   | calling stack
        addu    %r4,  %r31, 0                   | saved registers
        or      %r3,  %r12, 0                   | return value
        or      %r2,  %r13, %r0                 | closure
#ifdef PIC
        bsr     ffi_closure_OBSD_inner#plt
#else
        bsr     ffi_closure_OBSD_inner
#endif

        subu    %r31, %r30, 16
        ld      %r1,  %r31, 0
        ld      %r30, %r31, 4
        jmp.n   %r1
         addu   %r31, %r31, 16
        .size   ffi_closure_struct_OBSD,.-ffi_closure_struct_OBSD