1/* ----------------------------------------------------------------------- 2 sysv.h - Copyright (c) 1998 Geoffrey Keating 3 4 PowerPC Assembly glue. 5 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: 13 14 The above copyright notice and this permission notice shall be included 15 in all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 OTHER DEALINGS IN THE SOFTWARE. 24 ----------------------------------------------------------------------- */ 25 26#define LIBFFI_ASM 27#include <fficonfig.h> 28#include <ffi.h> 29#include <powerpc/asm.h> 30 31#ifndef __powerpc64__ 32 .globl ffi_prep_args_SYSV 33ENTRY(ffi_call_SYSV) 34.LFB1: 35 /* Save the old stack pointer as AP. */ 36 mr %r8,%r1 37 38.LCFI0: 39 /* Allocate the stack space we need. */ 40 stwux %r1,%r1,%r4 41 /* Save registers we use. */ 42 mflr %r9 43 stw %r28,-16(%r8) 44.LCFI1: 45 stw %r29,-12(%r8) 46.LCFI2: 47 stw %r30, -8(%r8) 48.LCFI3: 49 stw %r31, -4(%r8) 50.LCFI4: 51 stw %r9, 4(%r8) 52.LCFI5: 53 54 /* Save arguments over call... */ 55 mr %r31,%r5 /* flags, */ 56 mr %r30,%r6 /* rvalue, */ 57 mr %r29,%r7 /* function address, */ 58 mr %r28,%r8 /* our AP. */ 59.LCFI6: 60 61 /* Call ffi_prep_args_SYSV. */ 62 mr %r4,%r1 63 bl JUMPTARGET(ffi_prep_args_SYSV) 64 65 /* Now do the call. */ 66 /* Set up cr1 with bits 4-7 of the flags. */ 67 mtcrf 0x40,%r31 68 /* Get the address to call into CTR. */ 69 mtctr %r29 70 /* Load all those argument registers. */ 71 lwz %r3,-16-(8*4)(%r28) 72 lwz %r4,-16-(7*4)(%r28) 73 lwz %r5,-16-(6*4)(%r28) 74 lwz %r6,-16-(5*4)(%r28) 75 bf- 5,1f 76 nop 77 lwz %r7,-16-(4*4)(%r28) 78 lwz %r8,-16-(3*4)(%r28) 79 lwz %r9,-16-(2*4)(%r28) 80 lwz %r10,-16-(1*4)(%r28) 81 nop 821: 83 84 /* Load all the FP registers. */ 85 bf- 6,2f 86 lfd %f1,-16-(8*4)-(8*8)(%r28) 87 lfd %f2,-16-(8*4)-(7*8)(%r28) 88 lfd %f3,-16-(8*4)-(6*8)(%r28) 89 lfd %f4,-16-(8*4)-(5*8)(%r28) 90 nop 91 lfd %f5,-16-(8*4)-(4*8)(%r28) 92 lfd %f6,-16-(8*4)-(3*8)(%r28) 93 lfd %f7,-16-(8*4)-(2*8)(%r28) 94 lfd %f8,-16-(8*4)-(1*8)(%r28) 952: 96 97 /* Make the call. */ 98 bctrl 99 100 /* Now, deal with the return value. */ 101 mtcrf 0x01,%r31 102 bt- 30,L(done_return_value) 103 bt- 29,L(fp_return_value) 104 stw %r3,0(%r30) 105 bf+ 28,L(done_return_value) 106 stw %r4,4(%r30) 107 /* Fall through... */ 108 109L(done_return_value): 110 /* Restore the registers we used and return. */ 111 lwz %r9, 4(%r28) 112 lwz %r31, -4(%r28) 113 mtlr %r9 114 lwz %r30, -8(%r28) 115 lwz %r29,-12(%r28) 116 lwz %r28,-16(%r28) 117 lwz %r1,0(%r1) 118 blr 119 120L(fp_return_value): 121 bf 28,L(float_return_value) 122 stfd %f1,0(%r30) 123 b L(done_return_value) 124L(float_return_value): 125 stfs %f1,0(%r30) 126 b L(done_return_value) 127.LFE1: 128END(ffi_call_SYSV) 129 130 .section ".eh_frame",EH_FRAME_FLAGS,@progbits 131.Lframe1: 132 .4byte .LECIE1-.LSCIE1 /* Length of Common Information Entry */ 133.LSCIE1: 134 .4byte 0x0 /* CIE Identifier Tag */ 135 .byte 0x1 /* CIE Version */ 136#if defined _RELOCATABLE || defined __PIC__ 137 .ascii "zR\0" /* CIE Augmentation */ 138#else 139 .ascii "\0" /* CIE Augmentation */ 140#endif 141 .uleb128 0x1 /* CIE Code Alignment Factor */ 142 .sleb128 -4 /* CIE Data Alignment Factor */ 143 .byte 0x41 /* CIE RA Column */ 144#if defined _RELOCATABLE || defined __PIC__ 145 .uleb128 0x1 /* Augmentation size */ 146 .byte 0x1b /* FDE Encoding (pcrel sdata4) */ 147#endif 148 .byte 0xc /* DW_CFA_def_cfa */ 149 .uleb128 0x1 150 .uleb128 0x0 151 .align 2 152.LECIE1: 153.LSFDE1: 154 .4byte .LEFDE1-.LASFDE1 /* FDE Length */ 155.LASFDE1: 156 .4byte .LASFDE1-.Lframe1 /* FDE CIE offset */ 157#if defined _RELOCATABLE || defined __PIC__ 158 .4byte .LFB1-. /* FDE initial location */ 159#else 160 .4byte .LFB1 /* FDE initial location */ 161#endif 162 .4byte .LFE1-.LFB1 /* FDE address range */ 163#if defined _RELOCATABLE || defined __PIC__ 164 .uleb128 0x0 /* Augmentation size */ 165#endif 166 .byte 0x4 /* DW_CFA_advance_loc4 */ 167 .4byte .LCFI0-.LFB1 168 .byte 0xd /* DW_CFA_def_cfa_register */ 169 .uleb128 0x08 170 .byte 0x4 /* DW_CFA_advance_loc4 */ 171 .4byte .LCFI5-.LCFI0 172 .byte 0x2f /* DW_CFA_GNU_negative_offset_extended */ 173 .uleb128 0x41 174 .uleb128 0x1 175 .byte 0x9f /* DW_CFA_offset, column 0x1f */ 176 .uleb128 0x1 177 .byte 0x9e /* DW_CFA_offset, column 0x1e */ 178 .uleb128 0x2 179 .byte 0x9d /* DW_CFA_offset, column 0x1d */ 180 .uleb128 0x3 181 .byte 0x9c /* DW_CFA_offset, column 0x1c */ 182 .uleb128 0x4 183 .byte 0x4 /* DW_CFA_advance_loc4 */ 184 .4byte .LCFI6-.LCFI5 185 .byte 0xd /* DW_CFA_def_cfa_register */ 186 .uleb128 0x1c 187 .align 2 188.LEFDE1: 189#endif 190