| 1 |
/* ----------------------------------------------------------------------- |
| 2 |
sysv.S - Copyright (c) 1998 Geoffrey Keating |
| 3 |
Copyright (C) 2007 Free Software Foundation, Inc |
| 4 |
|
| 5 |
PowerPC Assembly glue. |
| 6 |
|
| 7 |
Permission is hereby granted, free of charge, to any person obtaining |
| 8 |
a copy of this software and associated documentation files (the |
| 9 |
``Software''), to deal in the Software without restriction, including |
| 10 |
without limitation the rights to use, copy, modify, merge, publish, |
| 11 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 12 |
permit persons to whom the Software is furnished to do so, subject to |
| 13 |
the following conditions: |
| 14 |
|
| 15 |
The above copyright notice and this permission notice shall be included |
| 16 |
in all copies or substantial portions of the Software. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, |
| 19 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 22 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 23 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 25 |
DEALINGS IN THE SOFTWARE. |
| 26 |
----------------------------------------------------------------------- */ |
| 27 |
|
| 28 |
#define LIBFFI_ASM |
| 29 |
#include <fficonfig.h> |
| 30 |
#include <ffi.h> |
| 31 |
#include <powerpc/asm.h> |
| 32 |
|
| 33 |
#ifndef POWERPC64 |
| 34 |
FFI_HIDDEN(ffi_call_SYSV) |
| 35 |
ENTRY(ffi_call_SYSV) |
| 36 |
.cfi_startproc |
| 37 |
/* Save the old stack pointer as AP. */ |
| 38 |
mr %r10,%r1 |
| 39 |
.cfi_def_cfa_register 10 |
| 40 |
|
| 41 |
/* Allocate the stack space we need. */ |
| 42 |
stwux %r1,%r1,%r8 |
| 43 |
/* Save registers we use. */ |
| 44 |
mflr %r9 |
| 45 |
stw %r28,-16(%r10) |
| 46 |
stw %r29,-12(%r10) |
| 47 |
stw %r30, -8(%r10) |
| 48 |
stw %r31, -4(%r10) |
| 49 |
stw %r9, 4(%r10) |
| 50 |
.cfi_offset 65, 4 |
| 51 |
.cfi_offset 31, -4 |
| 52 |
.cfi_offset 30, -8 |
| 53 |
.cfi_offset 29, -12 |
| 54 |
.cfi_offset 28, -16 |
| 55 |
|
| 56 |
/* Save arguments over call... */ |
| 57 |
stw %r7, -20(%r10) /* closure, */ |
| 58 |
mr %r31,%r6 /* flags, */ |
| 59 |
mr %r30,%r5 /* rvalue, */ |
| 60 |
mr %r29,%r4 /* function address, */ |
| 61 |
mr %r28,%r10 /* our AP. */ |
| 62 |
.cfi_def_cfa_register 28 |
| 63 |
|
| 64 |
/* Call ffi_prep_args_SYSV. */ |
| 65 |
mr %r4,%r1 |
| 66 |
bl ffi_prep_args_SYSV@local |
| 67 |
|
| 68 |
/* Now do the call. */ |
| 69 |
/* Set up cr1 with bits 4-7 of the flags. */ |
| 70 |
mtcrf 0x40,%r31 |
| 71 |
/* Get the address to call into CTR. */ |
| 72 |
mtctr %r29 |
| 73 |
/* Load all those argument registers. */ |
| 74 |
lwz %r3,-24-(8*4)(%r28) |
| 75 |
lwz %r4,-24-(7*4)(%r28) |
| 76 |
lwz %r5,-24-(6*4)(%r28) |
| 77 |
lwz %r6,-24-(5*4)(%r28) |
| 78 |
bf- 5,1f |
| 79 |
nop |
| 80 |
lwz %r7,-24-(4*4)(%r28) |
| 81 |
lwz %r8,-24-(3*4)(%r28) |
| 82 |
lwz %r9,-24-(2*4)(%r28) |
| 83 |
lwz %r10,-24-(1*4)(%r28) |
| 84 |
nop |
| 85 |
1: |
| 86 |
|
| 87 |
#ifndef __NO_FPRS__ |
| 88 |
/* Load all the FP registers. */ |
| 89 |
bf- 6,2f |
| 90 |
lfd %f1,-24-(8*4)-(8*8)(%r28) |
| 91 |
lfd %f2,-24-(8*4)-(7*8)(%r28) |
| 92 |
lfd %f3,-24-(8*4)-(6*8)(%r28) |
| 93 |
lfd %f4,-24-(8*4)-(5*8)(%r28) |
| 94 |
nop |
| 95 |
lfd %f5,-24-(8*4)-(4*8)(%r28) |
| 96 |
lfd %f6,-24-(8*4)-(3*8)(%r28) |
| 97 |
lfd %f7,-24-(8*4)-(2*8)(%r28) |
| 98 |
lfd %f8,-24-(8*4)-(1*8)(%r28) |
| 99 |
#endif |
| 100 |
2: |
| 101 |
|
| 102 |
/* Make the call. */ |
| 103 |
lwz %r11, -20(%r28) |
| 104 |
bctrl |
| 105 |
|
| 106 |
/* Now, deal with the return value. */ |
| 107 |
mtcrf 0x03,%r31 /* cr6-cr7 */ |
| 108 |
bt- 31,L(small_struct_return_value) |
| 109 |
bt- 30,L(done_return_value) |
| 110 |
#ifndef __NO_FPRS__ |
| 111 |
bt- 29,L(fp_return_value) |
| 112 |
#endif |
| 113 |
stw %r3,0(%r30) |
| 114 |
bf+ 27,L(done_return_value) |
| 115 |
stw %r4,4(%r30) |
| 116 |
bf 26,L(done_return_value) |
| 117 |
stw %r5,8(%r30) |
| 118 |
stw %r6,12(%r30) |
| 119 |
/* Fall through... */ |
| 120 |
|
| 121 |
L(done_return_value): |
| 122 |
/* Restore the registers we used and return. */ |
| 123 |
lwz %r9, 4(%r28) |
| 124 |
lwz %r31, -4(%r28) |
| 125 |
mtlr %r9 |
| 126 |
lwz %r30, -8(%r28) |
| 127 |
lwz %r29,-12(%r28) |
| 128 |
lwz %r28,-16(%r28) |
| 129 |
.cfi_remember_state |
| 130 |
/* At this point we don't have a cfa register. Say all our |
| 131 |
saved regs have been restored. */ |
| 132 |
.cfi_same_value 65 |
| 133 |
.cfi_same_value 31 |
| 134 |
.cfi_same_value 30 |
| 135 |
.cfi_same_value 29 |
| 136 |
.cfi_same_value 28 |
| 137 |
/* Hopefully this works.. */ |
| 138 |
.cfi_def_cfa_register 1 |
| 139 |
.cfi_offset 1, 0 |
| 140 |
lwz %r1,0(%r1) |
| 141 |
.cfi_same_value 1 |
| 142 |
blr |
| 143 |
|
| 144 |
#ifndef __NO_FPRS__ |
| 145 |
L(fp_return_value): |
| 146 |
.cfi_restore_state |
| 147 |
bf 27,L(float_return_value) |
| 148 |
stfd %f1,0(%r30) |
| 149 |
bf 26,L(done_return_value) |
| 150 |
stfd %f2,8(%r30) |
| 151 |
b L(done_return_value) |
| 152 |
L(float_return_value): |
| 153 |
stfs %f1,0(%r30) |
| 154 |
b L(done_return_value) |
| 155 |
#endif |
| 156 |
|
| 157 |
L(small_struct_return_value): |
| 158 |
/* |
| 159 |
* The C code always allocates a properly-aligned 8-byte bounce |
| 160 |
* buffer to make this assembly code very simple. Just write out |
| 161 |
* r3 and r4 to the buffer to allow the C code to handle the rest. |
| 162 |
*/ |
| 163 |
stw %r3, 0(%r30) |
| 164 |
stw %r4, 4(%r30) |
| 165 |
b L(done_return_value) |
| 166 |
.cfi_endproc |
| 167 |
|
| 168 |
END(ffi_call_SYSV) |
| 169 |
|
| 170 |
#if defined __ELF__ && defined __linux__ |
| 171 |
.section .note.GNU-stack,"",@progbits |
| 172 |
#endif |
| 173 |
#endif |