OSDN Git Service

2007-12-01 Andreas Tobler <a.tobler@schweiz.org>
[pf3gnuchains/gcc-fork.git] / libffi / src / powerpc / sysv.S
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, EXPRESS
19    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
22    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24    OTHER DEALINGS IN THE SOFTWARE.
25    ----------------------------------------------------------------------- */
26
27 #define LIBFFI_ASM
28 #include <fficonfig.h>
29 #include <ffi.h>
30 #include <powerpc/asm.h>
31
32 #ifndef __powerpc64__
33         .globl ffi_prep_args_SYSV
34 ENTRY(ffi_call_SYSV)
35 .LFB1:
36         /* Save the old stack pointer as AP.  */
37         mr      %r8,%r1
38
39 .LCFI0:
40         /* Allocate the stack space we need.  */
41         stwux   %r1,%r1,%r4
42         /* Save registers we use.  */
43         mflr    %r9
44         stw     %r28,-16(%r8)
45 .LCFI1:
46         stw     %r29,-12(%r8)
47 .LCFI2:
48         stw     %r30, -8(%r8)
49 .LCFI3:
50         stw     %r31, -4(%r8)
51 .LCFI4:
52         stw     %r9,   4(%r8)
53 .LCFI5:
54
55         /* Save arguments over call...  */
56         mr      %r31,%r5        /* flags, */
57         mr      %r30,%r6        /* rvalue, */
58         mr      %r29,%r7        /* function address, */
59         mr      %r28,%r8        /* our AP. */
60 .LCFI6:
61
62         /* Call ffi_prep_args_SYSV.  */
63         mr      %r4,%r1
64         bl      ffi_prep_args_SYSV@local
65
66         /* Now do the call.  */
67         /* Set up cr1 with bits 4-7 of the flags.  */
68         mtcrf   0x40,%r31
69         /* Get the address to call into CTR.  */
70         mtctr   %r29
71         /* Load all those argument registers.  */
72         lwz     %r3,-16-(8*4)(%r28)
73         lwz     %r4,-16-(7*4)(%r28)
74         lwz     %r5,-16-(6*4)(%r28)
75         lwz     %r6,-16-(5*4)(%r28)
76         bf-     5,1f
77         nop
78         lwz     %r7,-16-(4*4)(%r28)
79         lwz     %r8,-16-(3*4)(%r28)
80         lwz     %r9,-16-(2*4)(%r28)
81         lwz     %r10,-16-(1*4)(%r28)
82         nop
83 1:
84
85         /* Load all the FP registers.  */
86         bf-     6,2f
87         lfd     %f1,-16-(8*4)-(8*8)(%r28)
88         lfd     %f2,-16-(8*4)-(7*8)(%r28)
89         lfd     %f3,-16-(8*4)-(6*8)(%r28)
90         lfd     %f4,-16-(8*4)-(5*8)(%r28)
91         nop
92         lfd     %f5,-16-(8*4)-(4*8)(%r28)
93         lfd     %f6,-16-(8*4)-(3*8)(%r28)
94         lfd     %f7,-16-(8*4)-(2*8)(%r28)
95         lfd     %f8,-16-(8*4)-(1*8)(%r28)
96 2:
97
98         /* Make the call.  */
99         bctrl
100
101         /* Now, deal with the return value.  */
102         mtcrf   0x01,%r31 /* cr7  */
103         bt-     31,L(small_struct_return_value)
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         mtcrf   0x02,%r31 /* cr6  */
110         bf      27,L(done_return_value)
111         stw     %r5,8(%r30)
112         stw     %r6,12(%r30)
113         /* Fall through...  */
114
115 L(done_return_value):
116         /* Restore the registers we used and return.  */
117         lwz     %r9,   4(%r28)
118         lwz     %r31, -4(%r28)
119         mtlr    %r9
120         lwz     %r30, -8(%r28)
121         lwz     %r29,-12(%r28)
122         lwz     %r28,-16(%r28)
123         lwz     %r1,0(%r1)
124         blr
125
126 L(fp_return_value):
127         bf      28,L(float_return_value)
128         stfd    %f1,0(%r30)
129         mtcrf   0x02,%r31 /* cr6  */
130         bf      27,L(done_return_value)
131         stfd    %f2,8(%r30)
132         b       L(done_return_value)
133 L(float_return_value):
134         stfs    %f1,0(%r30)
135         b       L(done_return_value)
136
137 L(small_struct_return_value):
138         mtcrf   0x10,%r31       /* cr3  */
139         bt-     15,L(smst_one_register)
140         mtcrf   0x08,%r31       /* cr4  */
141         bt-     16,L(smst_two_register)
142         b       L(done_return_value)
143
144 L(smst_one_register):
145         rlwinm  %r5,%r31,5+23,32-5,31 /* Extract the value to shift.  */
146         slw     %r3,%r3,%r5
147         stw     %r3,0(%r30)
148         b       L(done_return_value)
149 L(smst_two_register):
150         rlwinm  %r5,%r31,5+23,32-5,31 /* Extract the value to shift.  */
151         cmpwi   %r5,0
152         subfic  %r9,%r5,32
153         slw     %r29,%r3,%r5
154         srw     %r9,%r4,%r9
155         beq-    L(smst_8byte)
156         or      %r3,%r9,%r29
157         slw     %r4,%r4,%r5
158 L(smst_8byte):
159         stw     %r3,0(%r30)
160         stw     %r4,4(%r30)
161         b       L(done_return_value)
162
163 .LFE1:
164 END(ffi_call_SYSV)
165
166       .section  ".eh_frame",EH_FRAME_FLAGS,@progbits
167 .Lframe1:
168       .4byte    .LECIE1-.LSCIE1  /*  Length of Common Information Entry */
169 .LSCIE1:
170       .4byte    0x0      /*  CIE Identifier Tag */
171       .byte     0x1      /*  CIE Version */
172 #if defined _RELOCATABLE || defined __PIC__
173       .ascii    "zR\0"   /*  CIE Augmentation */
174 #else
175       .ascii    "\0"     /*  CIE Augmentation */
176 #endif
177       .uleb128  0x1      /*  CIE Code Alignment Factor */
178       .sleb128  -4       /*  CIE Data Alignment Factor */
179       .byte     0x41     /*  CIE RA Column */
180 #if defined _RELOCATABLE || defined __PIC__
181       .uleb128  0x1      /*  Augmentation size */
182       .byte     0x1b     /*  FDE Encoding (pcrel sdata4) */
183 #endif
184       .byte     0xc      /*  DW_CFA_def_cfa */
185       .uleb128  0x1
186       .uleb128  0x0
187       .align 2
188 .LECIE1:
189 .LSFDE1:
190       .4byte    .LEFDE1-.LASFDE1         /*  FDE Length */
191 .LASFDE1:
192       .4byte    .LASFDE1-.Lframe1         /*  FDE CIE offset */
193 #if defined _RELOCATABLE || defined __PIC__
194       .4byte    .LFB1-.  /*  FDE initial location */
195 #else
196       .4byte    .LFB1    /*  FDE initial location */
197 #endif
198       .4byte    .LFE1-.LFB1      /*  FDE address range */
199 #if defined _RELOCATABLE || defined __PIC__
200       .uleb128  0x0      /*  Augmentation size */
201 #endif
202       .byte     0x4      /*  DW_CFA_advance_loc4 */
203       .4byte    .LCFI0-.LFB1
204       .byte     0xd      /*  DW_CFA_def_cfa_register */
205       .uleb128  0x08
206       .byte     0x4      /*  DW_CFA_advance_loc4 */
207       .4byte    .LCFI5-.LCFI0
208       .byte     0x11     /*  DW_CFA_offset_extended_sf */
209       .uleb128  0x41
210       .sleb128  -1
211       .byte     0x9f     /*  DW_CFA_offset, column 0x1f */
212       .uleb128  0x1
213       .byte     0x9e     /*  DW_CFA_offset, column 0x1e */
214       .uleb128  0x2
215       .byte     0x9d     /*  DW_CFA_offset, column 0x1d */
216       .uleb128  0x3
217       .byte     0x9c     /*  DW_CFA_offset, column 0x1c */
218       .uleb128  0x4
219       .byte     0x4      /*  DW_CFA_advance_loc4 */
220       .4byte    .LCFI6-.LCFI5
221       .byte     0xd      /*  DW_CFA_def_cfa_register */
222       .uleb128  0x1c
223       .align 2
224 .LEFDE1:
225 #endif