summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/fiddle/libffi-3.2.1/src/arc/arcompact.S
blob: 03715fde49f7a1ff02c82be3b09362cf0b871e17 (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
/* -----------------------------------------------------------------------
   arcompact.S - Copyright (c) 2013 Synposys, Inc. (www.synopsys.com)
   
   ARCompact Foreign Function Interface 

   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 RENESAS TECHNOLOGY 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.
   ----------------------------------------------------------------------- */

#define LIBFFI_ASM
#include <fficonfig.h>
#include <ffi.h>
#ifdef HAVE_MACHINE_ASM_H
#include <machine/asm.h>
#else
#define CNAME(x) x
#define ENTRY(x) .globl CNAME(x)` .type CNAME(x),%function` CNAME(x):
#endif

.text

        /* R0:   ffi_prep_args */
        /* R1:   &ecif */
        /* R2:   cif->bytes */
        /* R3:   fig->flags */
        /* R4:   ecif.rvalue */
        /* R5:   fn */
ENTRY(ffi_call_ARCompact)
        /* Save registers.  */
        st.a       fp, [sp, -4]        /* fp + 20, fp */
        push_s     blink               /* fp + 16, blink */
        st.a       r4, [sp, -4]        /* fp + 12, ecif.rvalue */
        push_s     r3                  /* fp +  8, fig->flags */
        st.a       r5, [sp, -4]        /* fp +  4, fn */
        push_s     r2                  /* fp +  0, cif->bytes */
        mov        fp, sp

        /* Make room for all of the new args.  */
        sub        sp, sp, r2

        /* Place all of the ffi_prep_args in position.  */
        /* ffi_prep_args(char *stack, extended_cif *ecif) */
        /* R1 already set.  */

        /* And call.  */
        jl_s.d     [r0]
        mov_s      r0, sp

        ld.ab      r12, [fp, 4]        /* cif->bytes */
        ld.ab      r11, [fp, 4]        /* fn */

        /* Move first 8 parameters in registers...  */
        ld_s       r0, [sp]
        ld_s       r1, [sp, 4]
        ld_s       r2, [sp, 8]
        ld_s       r3, [sp, 12]
        ld         r4, [sp, 16]
        ld         r5, [sp, 20]
        ld         r6, [sp, 24]
        ld         r7, [sp, 28]

        /* ...and adjust the stack.  */
        min        r12, r12, 32

        /* Call the function.  */
        jl.d       [r11]
        add        sp, sp, r12 

        mov        sp, fp        
        pop_s      r3        /* fig->flags, return type */
        pop_s      r2        /* ecif.rvalue, pointer for return value */

        /* If the return value pointer is NULL, assume no return value.  */
        breq.d     r2, 0, epilogue
        pop_s      blink

        /* Return INT.  */
        brne       r3, FFI_TYPE_INT, return_double
        b.d        epilogue
        st_s       r0, [r2]        

return_double:
        brne       r3, FFI_TYPE_DOUBLE, epilogue
        st_s       r0, [r2]        
        st_s       r1, [r2,4]

epilogue:
        j_s.d      [blink]
        ld.ab      fp, [sp, 4]

ENTRY(ffi_closure_ARCompact)
        st.a       r0, [sp, -32]
        st_s       r1, [sp, 4]
        st_s       r2, [sp, 8]
        st_s       r3, [sp, 12]
        st         r4, [sp, 16]
        st         r5, [sp, 20]
        st         r6, [sp, 24]
        st         r7, [sp, 28]

        /* pointer to arguments */
        mov_s      r2, sp

        /* return value goes here */
        sub        sp, sp, 8
        mov_s      r1, sp

        push_s     blink
        
        bl.d       ffi_closure_inner_ARCompact
        mov_s      r0, r8                /* codeloc, set by trampoline */

        pop_s      blink

        /* set return value to r1:r0 */
        pop_s      r0
        pop_s      r1
        j_s.d      [blink]
        add_s      sp, sp, 32