OSDN Git Service

2007-04-02 Dave Korn <dave.korn@artimi.com>
[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         bf      27,L(done_return_value)
125         stfd    %f2,8(%r30)
126         b       L(done_return_value)
127 L(float_return_value):
128         stfs    %f1,0(%r30)
129         b       L(done_return_value)
130
131 L(small_struct_return_value):
132         mtcrf   0x10,%r31       /* cr3  */
133         bt-     15,L(smst_one_register)
134         mtcrf   0x08,%r31       /* cr4  */
135         bt-     16,L(smst_two_register)
136         b       L(done_return_value)
137
138 L(smst_one_register):
139         rlwinm  %r5,%r31,5+23,32-5,31 /* Extract the value to shift.  */
140         slw     %r3,%r3,%r5
141         stw     %r3,0(%r30)
142         b       L(done_return_value)
143 L(smst_two_register):
144         rlwinm  %r5,%r31,5+23,32-5,31 /* Extract the value to shift.  */
145         cmpwi   %r5,0
146         subfic  %r9,%r5,32
147         slw     %r29,%r3,%r5
148         srw     %r9,%r4,%r9
149         beq-    L(smst_8byte)
150         or      %r3,%r9,%r29
151         slw     %r4,%r4,%r5
152 L(smst_8byte):
153         stw     %r3,0(%r30)
154         stw     %r4,4(%r30)
155         b       L(done_return_value)
156
157 .LFE1:
158 END(ffi_call_SYSV)
159
160       .section  ".eh_frame",EH_FRAME_FLAGS,@progbits
161 .Lframe1:
162       .4byte    .LECIE1-.LSCIE1  /*  Length of Common Information Entry */
163 .LSCIE1:
164       .4byte    0x0      /*  CIE Identifier Tag */
165       .byte     0x1      /*  CIE Version */
166 #if defined _RELOCATABLE || defined __PIC__
167       .ascii    "zR\0"   /*  CIE Augmentation */
168 #else
169       .ascii    "\0"     /*  CIE Augmentation */
170 #endif
171       .uleb128  0x1      /*  CIE Code Alignment Factor */
172       .sleb128  -4       /*  CIE Data Alignment Factor */
173       .byte     0x41     /*  CIE RA Column */
174 #if defined _RELOCATABLE || defined __PIC__
175       .uleb128  0x1      /*  Augmentation size */
176       .byte     0x1b     /*  FDE Encoding (pcrel sdata4) */
177 #endif
178       .byte     0xc      /*  DW_CFA_def_cfa */
179       .uleb128  0x1
180       .uleb128  0x0
181       .align 2
182 .LECIE1:
183 .LSFDE1:
184       .4byte    .LEFDE1-.LASFDE1         /*  FDE Length */
185 .LASFDE1:
186       .4byte    .LASFDE1-.Lframe1         /*  FDE CIE offset */
187 #if defined _RELOCATABLE || defined __PIC__
188       .4byte    .LFB1-.  /*  FDE initial location */
189 #else
190       .4byte    .LFB1    /*  FDE initial location */
191 #endif
192       .4byte    .LFE1-.LFB1      /*  FDE address range */
193 #if defined _RELOCATABLE || defined __PIC__
194       .uleb128  0x0      /*  Augmentation size */
195 #endif
196       .byte     0x4      /*  DW_CFA_advance_loc4 */
197       .4byte    .LCFI0-.LFB1
198       .byte     0xd      /*  DW_CFA_def_cfa_register */
199       .uleb128  0x08
200       .byte     0x4      /*  DW_CFA_advance_loc4 */
201       .4byte    .LCFI5-.LCFI0
202       .byte     0x11     /*  DW_CFA_offset_extended_sf */
203       .uleb128  0x41
204       .sleb128  -1
205       .byte     0x9f     /*  DW_CFA_offset, column 0x1f */
206       .uleb128  0x1
207       .byte     0x9e     /*  DW_CFA_offset, column 0x1e */
208       .uleb128  0x2
209       .byte     0x9d     /*  DW_CFA_offset, column 0x1d */
210       .uleb128  0x3
211       .byte     0x9c     /*  DW_CFA_offset, column 0x1c */
212       .uleb128  0x4
213       .byte     0x4      /*  DW_CFA_advance_loc4 */
214       .4byte    .LCFI6-.LCFI5
215       .byte     0xd      /*  DW_CFA_def_cfa_register */
216       .uleb128  0x1c
217       .align 2
218 .LEFDE1:
219 #endif