OSDN Git Service

9682016d2fa3628a4425a22dd1fe4ffa09381f30
[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    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
33 ENTRY(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      ffi_prep_args_SYSV@local
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
82 1:
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)
95 2:
96
97         /* Make the call.  */
98         bctrl
99
100         /* Now, deal with the return value.  */
101         mtcrf   0x01,%r31
102         bt-     31,L(small_struct_return_value)
103         bt-     30,L(done_return_value)
104         bt-     29,L(fp_return_value)
105         stw     %r3,0(%r30)
106         bf+     28,L(done_return_value)
107         stw     %r4,4(%r30)
108         /* Fall through...  */
109
110 L(done_return_value):
111         /* Restore the registers we used and return.  */
112         lwz     %r9,   4(%r28)
113         lwz     %r31, -4(%r28)
114         mtlr    %r9
115         lwz     %r30, -8(%r28)
116         lwz     %r29,-12(%r28)
117         lwz     %r28,-16(%r28)
118         lwz     %r1,0(%r1)
119         blr
120
121 L(fp_return_value):
122         bf      28,L(float_return_value)
123         stfd    %f1,0(%r30)
124         mtcrf   0x02,%r31 /* cr6  */
125         bf      27,L(done_return_value)
126         stfd    %f2,8(%r30)
127         b       L(done_return_value)
128 L(float_return_value):
129         stfs    %f1,0(%r30)
130         b       L(done_return_value)
131
132 L(small_struct_return_value):
133         mtcrf   0x10,%r31       /* cr3  */
134         bt-     15,L(smst_one_register)
135         mtcrf   0x08,%r31       /* cr4  */
136         bt-     16,L(smst_two_register)
137         b       L(done_return_value)
138
139 L(smst_one_register):
140         rlwinm  %r5,%r31,5+23,32-5,31 /* Extract the value to shift.  */
141         slw     %r3,%r3,%r5
142         stw     %r3,0(%r30)
143         b       L(done_return_value)
144 L(smst_two_register):
145         rlwinm  %r5,%r31,5+23,32-5,31 /* Extract the value to shift.  */
146         cmpwi   %r5,0
147         subfic  %r9,%r5,32
148         slw     %r29,%r3,%r5
149         srw     %r9,%r4,%r9
150         beq-    L(smst_8byte)
151         or      %r3,%r9,%r29
152         slw     %r4,%r4,%r5
153 L(smst_8byte):
154         stw     %r3,0(%r30)
155         stw     %r4,4(%r30)
156         b       L(done_return_value)
157
158 .LFE1:
159 END(ffi_call_SYSV)
160
161       .section  ".eh_frame",EH_FRAME_FLAGS,@progbits
162 .Lframe1:
163       .4byte    .LECIE1-.LSCIE1  /*  Length of Common Information Entry */
164 .LSCIE1:
165       .4byte    0x0      /*  CIE Identifier Tag */
166       .byte     0x1      /*  CIE Version */
167 #if defined _RELOCATABLE || defined __PIC__
168       .ascii    "zR\0"   /*  CIE Augmentation */
169 #else
170       .ascii    "\0"     /*  CIE Augmentation */
171 #endif
172       .uleb128  0x1      /*  CIE Code Alignment Factor */
173       .sleb128  -4       /*  CIE Data Alignment Factor */
174       .byte     0x41     /*  CIE RA Column */
175 #if defined _RELOCATABLE || defined __PIC__
176       .uleb128  0x1      /*  Augmentation size */
177       .byte     0x1b     /*  FDE Encoding (pcrel sdata4) */
178 #endif
179       .byte     0xc      /*  DW_CFA_def_cfa */
180       .uleb128  0x1
181       .uleb128  0x0
182       .align 2
183 .LECIE1:
184 .LSFDE1:
185       .4byte    .LEFDE1-.LASFDE1         /*  FDE Length */
186 .LASFDE1:
187       .4byte    .LASFDE1-.Lframe1         /*  FDE CIE offset */
188 #if defined _RELOCATABLE || defined __PIC__
189       .4byte    .LFB1-.  /*  FDE initial location */
190 #else
191       .4byte    .LFB1    /*  FDE initial location */
192 #endif
193       .4byte    .LFE1-.LFB1      /*  FDE address range */
194 #if defined _RELOCATABLE || defined __PIC__
195       .uleb128  0x0      /*  Augmentation size */
196 #endif
197       .byte     0x4      /*  DW_CFA_advance_loc4 */
198       .4byte    .LCFI0-.LFB1
199       .byte     0xd      /*  DW_CFA_def_cfa_register */
200       .uleb128  0x08
201       .byte     0x4      /*  DW_CFA_advance_loc4 */
202       .4byte    .LCFI5-.LCFI0
203       .byte     0x11     /*  DW_CFA_offset_extended_sf */
204       .uleb128  0x41
205       .sleb128  -1
206       .byte     0x9f     /*  DW_CFA_offset, column 0x1f */
207       .uleb128  0x1
208       .byte     0x9e     /*  DW_CFA_offset, column 0x1e */
209       .uleb128  0x2
210       .byte     0x9d     /*  DW_CFA_offset, column 0x1d */
211       .uleb128  0x3
212       .byte     0x9c     /*  DW_CFA_offset, column 0x1c */
213       .uleb128  0x4
214       .byte     0x4      /*  DW_CFA_advance_loc4 */
215       .4byte    .LCFI6-.LCFI5
216       .byte     0xd      /*  DW_CFA_def_cfa_register */
217       .uleb128  0x1c
218       .align 2
219 .LEFDE1:
220 #endif