1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 2014 Sebastian Macke <sebastian@macke.de>
4 OpenRISC Foreign Function Interface
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 ``Software''), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
28 #include <fficonfig.h>
33 .type ffi_call_SYSV, @function
35 r3: size to allocate on stack
36 r4: extended cif structure
37 r5: function pointer ffi_prep_args
40 r8: flag for return type
44 /* Store registers used on stack */
45 l.sw -4(r1), r9 /* return address */
46 l.sw -8(r1), r1 /* stack address */
47 l.sw -12(r1), r14 /* callee saved registers */
52 l.ori r14, r1, 0x0 /* save stack pointer */
55 l.ori r16, r7, 0x0 /* save function address */
56 l.ori r18, r6, 0x0 /* save ret address */
57 l.ori r20, r8, 0x0 /* save flag */
59 l.sub r1, r1, r3 /* reserve space on stack */
61 /* Call ffi_prep_args */
62 l.ori r3, r1, 0x0 /* first argument stack address, second already ecif */
66 /* Load register arguments and call*/
74 l.ori r1, r11, 0x0 /* new stack pointer */
78 /* handle return values */
80 l.sfeqi r20, FFI_TYPE_STRUCT
81 l.bf ret /* structs don't return an rvalue */
84 /* copy ret address */
86 l.sfeqi r20, FFI_TYPE_UINT64
87 l.bnf four_byte_ret /* 8 byte value is returned */
97 l.ori r1, r14, 0x0 /* reset stack pointer */
107 .size ffi_call_SYSV, .-ffi_call_SYSV