summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/fiddle/libffi-3.2.1/src/vax/elfbsd.S
blob: 01ca313402b20e2f5b7aff45d2c08995b78da2d6 (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
/*
 * 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.
 */

/*
 * vax Foreign Function Interface
 */

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

        .text

/*
 * void *                                       %r0
 * ffi_call_elfbsd(extended_cif *ecif,          4(%ap)
 *                 unsigned bytes,              8(%ap)
 *                 unsigned flags,              12(%ap)
 *                 void *rvalue,                16(%ap)
 *                 void (*fn)());               20(%ap)
 */
        .globl  ffi_call_elfbsd
        .type   ffi_call_elfbsd,@function
        .align  2
ffi_call_elfbsd:
        .word   0x00c           # save R2 and R3

        # Allocate stack space for the args
        subl2   8(%ap), %sp

        # Call ffi_prep_args
        pushl   %sp
        pushl   4(%ap)
        calls   $2, ffi_prep_args

        # Get function pointer
        movl    20(%ap), %r1

        # Build a CALLS frame
        ashl    $-2, 8(%ap), %r0
        pushl   %r0             # argument stack usage
        movl    %sp, %r0        # future %ap
        # saved registers
        bbc     $11, 0(%r1), 1f
        pushl   %r11
1:      bbc     $10, 0(%r1), 1f
        pushl   %r10
1:      bbc     $9, 0(%r1), 1f
        pushl   %r9
1:      bbc     $8, 0(%r1), 1f
        pushl   %r8
1:      bbc     $7, 0(%r1), 1f
        pushl   %r7
1:      bbc     $6, 0(%r1), 1f
        pushl   %r6
1:      bbc     $5, 0(%r1), 1f
        pushl   %r5
1:      bbc     $4, 0(%r1), 1f
        pushl   %r4
1:      bbc     $3, 0(%r1), 1f
        pushl   %r3
1:      bbc     $2, 0(%r1), 1f
        pushl   %r2
1:      
        pushal  9f
        pushl   %fp
        pushl   %ap
        movl    16(%ap), %r3    # struct return address, if needed
        movl    %r0, %ap
        movzwl  4(%fp), %r0     # previous PSW, without the saved registers mask
        bisl2   $0x20000000, %r0 # calls frame
        movzwl  0(%r1), %r2
        bicw2   $0xf003, %r2    # only keep R11-R2
        ashl    $16, %r2, %r2
        bisl2   %r2, %r0        # saved register mask of the called function
        pushl   %r0     
        pushl   $0
        movl    %sp, %fp

        # Invoke the function
        pushal  2(%r1)          # skip procedure entry mask
        movl    %r3, %r1
        bicpsw  $0x000f
        rsb

9:
        # Copy return value if necessary
        tstl    16(%ap)
        jeql    9f
        movl    16(%ap), %r2

        bbc     $0, 12(%ap), 1f # CIF_FLAGS_CHAR
        movb    %r0, 0(%r2)
        brb     9f
1:
        bbc     $1, 12(%ap), 1f # CIF_FLAGS_SHORT
        movw    %r0, 0(%r2)
        brb     9f
1:
        bbc     $2, 12(%ap), 1f # CIF_FLAGS_INT
        movl    %r0, 0(%r2)
        brb     9f
1:
        bbc     $3, 12(%ap), 1f # CIF_FLAGS_DINT
        movq    %r0, 0(%r2)
        brb     9f
1:
        movl    %r1, %r0        # might have been a struct
        #brb    9f

9:
        ret

/*
 * ffi_closure_elfbsd(void);
 * invoked with %r0: ffi_closure *closure
 */
        .globl  ffi_closure_elfbsd
        .type   ffi_closure_elfbsd, @function
        .align  2
ffi_closure_elfbsd:
        .word   0

        # Allocate room on stack for return value
        subl2   $8, %sp

        # Invoke the closure function
        pushal  4(%ap)          # calling stack
        pushal  4(%sp)          # return value
        pushl   %r0             # closure
        calls   $3, ffi_closure_elfbsd_inner

        # Copy return value if necessary
        bitb    $1, %r0         # CIF_FLAGS_CHAR
        beql    1f
        movb    0(%sp), %r0
        brb     9f
1:
        bitb    $2, %r0         # CIF_FLAGS_SHORT
        beql    1f
        movw    0(%sp), %r0
        brb     9f
1:
        bitb    $4, %r0         # CIF_FLAGS_INT
        beql    1f
        movl    0(%sp), %r0
        brb     9f
1:
        bitb    $8, %r0         # CIF_FLAGS_DINT
        beql    1f
        movq    0(%sp), %r0
        #brb    9f
1:

9:
        ret

/*
 * ffi_closure_struct_elfbsd(void);
 * invoked with %r0: ffi_closure *closure
 *              %r1: struct return address
 */
        .globl  ffi_closure_struct_elfbsd
        .type   ffi_closure_struct_elfbsd, @function
        .align  2
ffi_closure_struct_elfbsd:
        .word   0

        # Invoke the closure function
        pushal  4(%ap)          # calling stack
        pushl   %r1             # return value
        pushl   %r0             # closure
        calls   $3, ffi_closure_elfbsd_inner

        ret