OSDN Git Service

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