Debian Codegraph @

src/kvx/sysv.S

raw
1 /* Copyright (c) 2020 Kalray
2
3 Permission is hereby granted, free of charge, to any person obtaining
4 a copy of this software and associated documentation files (the
5 ``Software''), to deal in the Software without restriction, including
6 without limitation the rights to use, copy, modify, merge, publish,
7 distribute, sublicense, and/or sell copies of the Software, and to
8 permit persons to whom the Software is furnished to do so, subject to
9 the following conditions:
10
11 The above copyright notice and this permission notice shall be
12 included in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
15 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
21
22 #if defined(__kvx__)
23 #define LIBFFI_ASM
24 #include <fficonfig.h>
25 #include <ffi.h>
26 #include <ffi_cfi.h>
27 #include <kvx/asm.h>
28
29 .text
30 .global ffi_call_SYSV
31 .type ffi_call_SYSV, @function
32 .type ffi_prep_args, @function
33 .align 8
34
35 /* ffi_call_SYSV
36
37 r0: total size to allocate on stack
38 r1: size of arg slots
39 r2: extended cif structure, DO NOT REMOVE: it is used by ffi_prep_args()
40 r3: return value address
41 r4: function to call
42 r5: integer sign extension method to be used
43 */
44 ffi_call_SYSV:
45 addd $r12 = $r12, -64
46 so (-32)[$r12] = $r20r21r22r23
47 ;;
48 sd (0)[$r12] = $r24
49 ;;
50 get $r23 = $ra
51 copyd $r20 = $r12
52 sbfd $r12 = $r0, $r12
53 ;;
54 copyd $r0 = $r12
55 copyd $r21 = $r3
56 copyd $r22 = $r4
57 copyd $r24 = $r5
58 call ffi_prep_args
59 ;;
60 lo $r8r9r10r11 = (64)[$r12]
61 ;;
62 lo $r4r5r6r7 = (32)[$r12]
63 ;;
64 lo $r0r1r2r3 = (0)[$r12]
65 copyd $r12 = $r0
66 /* $r15 is the register used by the ABI to return big (>32 bytes)
67 * structs by value.
68 * It is also referred to as the "struct register" in the ABI.
69 */
70 copyd $r15 = $r21
71 icall $r22
72 ;;
73 pcrel $r4 = @pcrel(.Ltable)
74 cb.deqz $r24 ? .Lend
75 ;;
76 addx8d $r24 = $r24, $r4
77 ;;
78 igoto $r24
79 ;;
80 .Ltable:
81 0: /* we should never arrive here */
82 goto .Lerror
83 nop
84 ;;
85 1: /* Sign extend byte to double */
86 sxbd $r0 = $r0
87 goto .Lend
88 ;;
89 2: /* Sign extend half to double */
90 sxhd $r0 = $r0
91 goto .Lend
92 ;;
93 3: /* Sign extend word to double */
94 sxwd $r0 = $r0
95 goto .Lend
96 ;;
97 4: /* Zero extend byte to double */
98 zxbd $r0 = $r0
99 goto .Lend
100 ;;
101 5: /* Zero extend half to double */
102 zxhd $r0 = $r0
103 goto .Lend
104 ;;
105 6: /* Zero extend word to double */
106 zxwd $r0 = $r0
107 /* Fallthrough to .Lend */
108 ;;
109 .Lend:
110 ld $r24 = (0)[$r12]
111 ;;
112 set $ra = $r23
113 lo $r20r21r22r23 = (32)[$r20]
114 addd $r12 = $r20, 64
115 ;;
116 ret
117 ;;
118 .Lerror:
119 errop
120 ;;
121
122 #endif /* __kvx__ */
123
124 #if defined __ELF__ && defined __linux__
125 .section .note.GNU-stack,"",%progbits
126 #endif
127