annotate libffi/src/nios2/sysv.S @ 155:da32f4b04d38

fix __code name conflict
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 17:51:46 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Low-level libffi support for Altera Nios II.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 Copyright (c) 2013 Mentor Graphics.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 Permission is hereby granted, free of charge, to any person obtaining
kono
parents:
diff changeset
6 a copy of this software and associated documentation files (the
kono
parents:
diff changeset
7 ``Software''), to deal in the Software without restriction, including
kono
parents:
diff changeset
8 without limitation the rights to use, copy, modify, merge, publish,
kono
parents:
diff changeset
9 distribute, sublicense, and/or sell copies of the Software, and to
kono
parents:
diff changeset
10 permit persons to whom the Software is furnished to do so, subject to
kono
parents:
diff changeset
11 the following conditions:
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 The above copyright notice and this permission notice shall be
kono
parents:
diff changeset
14 included in all copies or substantial portions of the Software.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
kono
parents:
diff changeset
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
kono
parents:
diff changeset
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
kono
parents:
diff changeset
19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
kono
parents:
diff changeset
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
kono
parents:
diff changeset
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
kono
parents:
diff changeset
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 /* This function is declared on the C side as
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 extern UINT64 ffi_call_sysv (void (*arghook) (char *, extended_cif *),
kono
parents:
diff changeset
27 extended_cif *ecif,
kono
parents:
diff changeset
28 unsigned nbytes,
kono
parents:
diff changeset
29 void (*fn) (void));
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 On input, the arguments appear as
kono
parents:
diff changeset
32 r4 = arghook
kono
parents:
diff changeset
33 r5 = ecif
kono
parents:
diff changeset
34 r6 = nbytes
kono
parents:
diff changeset
35 r7 = fn
kono
parents:
diff changeset
36 */
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 .section .text
kono
parents:
diff changeset
39 .align 2
kono
parents:
diff changeset
40 .global ffi_call_sysv
kono
parents:
diff changeset
41 .type ffi_call_sysv, @function
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 ffi_call_sysv:
kono
parents:
diff changeset
44 .cfi_startproc
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 /* Create the stack frame, saving r16 so we can use it locally. */
kono
parents:
diff changeset
47 addi sp, sp, -12
kono
parents:
diff changeset
48 .cfi_def_cfa_offset 12
kono
parents:
diff changeset
49 stw ra, 8(sp)
kono
parents:
diff changeset
50 stw fp, 4(sp)
kono
parents:
diff changeset
51 stw r16, 0(sp)
kono
parents:
diff changeset
52 .cfi_offset 31, -4
kono
parents:
diff changeset
53 .cfi_offset 28, -8
kono
parents:
diff changeset
54 .cfi_offset 16, -12
kono
parents:
diff changeset
55 mov fp, sp
kono
parents:
diff changeset
56 .cfi_def_cfa_register 28
kono
parents:
diff changeset
57 mov r16, r7
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* Adjust the stack pointer to create the argument buffer
kono
parents:
diff changeset
60 nbytes long. */
kono
parents:
diff changeset
61 sub sp, sp, r6
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 /* Call the arghook function. */
kono
parents:
diff changeset
64 mov r2, r4 /* fn */
kono
parents:
diff changeset
65 mov r4, sp /* argbuffer */
kono
parents:
diff changeset
66 callr r2 /* r5 already contains ecif */
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Pop off the first 16 bytes of the argument buffer on the stack,
kono
parents:
diff changeset
69 transferring the contents to the argument registers. */
kono
parents:
diff changeset
70 ldw r4, 0(sp)
kono
parents:
diff changeset
71 ldw r5, 4(sp)
kono
parents:
diff changeset
72 ldw r6, 8(sp)
kono
parents:
diff changeset
73 ldw r7, 12(sp)
kono
parents:
diff changeset
74 addi sp, sp, 16
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 /* Call the user function, which leaves its result in r2 and r3. */
kono
parents:
diff changeset
77 callr r16
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* Pop off the stack frame. */
kono
parents:
diff changeset
80 mov sp, fp
kono
parents:
diff changeset
81 ldw ra, 8(sp)
kono
parents:
diff changeset
82 ldw fp, 4(sp)
kono
parents:
diff changeset
83 ldw r16, 0(sp)
kono
parents:
diff changeset
84 addi sp, sp, 12
kono
parents:
diff changeset
85 ret
kono
parents:
diff changeset
86 .cfi_endproc
kono
parents:
diff changeset
87 .size ffi_call_sysv, .-ffi_call_sysv
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* Closure trampolines jump here after putting the C helper address
kono
parents:
diff changeset
91 in r9 and the closure pointer in r10. The user-supplied arguments
kono
parents:
diff changeset
92 to the closure are in the normal places, in r4-r7 and on the
kono
parents:
diff changeset
93 stack. Push the register arguments on the stack too and then call the
kono
parents:
diff changeset
94 C helper function to deal with them. */
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 .section .text
kono
parents:
diff changeset
97 .align 2
kono
parents:
diff changeset
98 .global ffi_closure_sysv
kono
parents:
diff changeset
99 .type ffi_closure_sysv, @function
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 ffi_closure_sysv:
kono
parents:
diff changeset
102 .cfi_startproc
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 /* Create the stack frame, pushing the register args on the stack
kono
parents:
diff changeset
105 just below the stack args. This is the same trick illustrated
kono
parents:
diff changeset
106 in Figure 7-3 in the Nios II Processor Reference Handbook, used
kono
parents:
diff changeset
107 for variable arguments and structures passed by value. */
kono
parents:
diff changeset
108 addi sp, sp, -20
kono
parents:
diff changeset
109 .cfi_def_cfa_offset 20
kono
parents:
diff changeset
110 stw ra, 0(sp)
kono
parents:
diff changeset
111 .cfi_offset 31, -20
kono
parents:
diff changeset
112 stw r4, 4(sp)
kono
parents:
diff changeset
113 .cfi_offset 4, -16
kono
parents:
diff changeset
114 stw r5, 8(sp)
kono
parents:
diff changeset
115 .cfi_offset 5, -12
kono
parents:
diff changeset
116 stw r6, 12(sp)
kono
parents:
diff changeset
117 .cfi_offset 6, -8
kono
parents:
diff changeset
118 stw r7, 16(sp)
kono
parents:
diff changeset
119 .cfi_offset 7, -4
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 /* Call the helper.
kono
parents:
diff changeset
122 r4 = pointer to arguments on stack
kono
parents:
diff changeset
123 r5 = closure pointer (loaded in r10 by the trampoline)
kono
parents:
diff changeset
124 r9 = address of helper function (loaded by trampoline) */
kono
parents:
diff changeset
125 addi r4, sp, 4
kono
parents:
diff changeset
126 mov r5, r10
kono
parents:
diff changeset
127 callr r9
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 /* Pop the stack and return. */
kono
parents:
diff changeset
130 ldw ra, 0(sp)
kono
parents:
diff changeset
131 addi sp, sp, 20
kono
parents:
diff changeset
132 .cfi_def_cfa_offset -20
kono
parents:
diff changeset
133 ret
kono
parents:
diff changeset
134 .cfi_endproc
kono
parents:
diff changeset
135 .size ffi_closure_sysv, .-ffi_closure_sysv
kono
parents:
diff changeset
136