OSDN Git Service

2007-11-17 Andreas Tobler <a.tobler@schweiz.org>
[pf3gnuchains/gcc-fork.git] / libffi / src / powerpc / linux64.S
1 /* -----------------------------------------------------------------------
2    sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub@redhat.com>
3
4    PowerPC64 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
30 #ifdef __powerpc64__
31         .hidden ffi_call_LINUX64, .ffi_call_LINUX64
32         .globl  ffi_call_LINUX64, .ffi_call_LINUX64
33         .section        ".opd","aw"
34         .align  3
35 ffi_call_LINUX64:
36         .quad   .ffi_call_LINUX64,.TOC.@tocbase,0
37         .size   ffi_call_LINUX64,24
38         .type   .ffi_call_LINUX64,@function
39         .text
40 .ffi_call_LINUX64:
41 .LFB1:
42         mflr    %r0
43         std     %r28, -32(%r1)
44         std     %r29, -24(%r1)
45         std     %r30, -16(%r1)
46         std     %r31, -8(%r1)
47         std     %r0, 16(%r1)
48
49         mr      %r28, %r1       /* our AP.  */
50 .LCFI0:
51         stdux   %r1, %r1, %r4
52         mr      %r31, %r5       /* flags, */
53         mr      %r30, %r6       /* rvalue, */
54         mr      %r29, %r7       /* function address.  */
55         std     %r2, 40(%r1)
56
57         /* Call ffi_prep_args64.  */
58         mr      %r4, %r1
59         bl      .ffi_prep_args64
60
61         ld      %r0, 0(%r29)
62         ld      %r2, 8(%r29)
63         ld      %r11, 16(%r29)
64
65         /* Now do the call.  */
66         /* Set up cr1 with bits 4-7 of the flags.  */
67         mtcrf   0x40, %r31
68
69         /* Get the address to call into CTR.  */
70         mtctr   %r0
71         /* Load all those argument registers.  */
72         ld      %r3, -32-(8*8)(%r28)
73         ld      %r4, -32-(7*8)(%r28)
74         ld      %r5, -32-(6*8)(%r28)
75         ld      %r6, -32-(5*8)(%r28)
76         bf-     5, 1f
77         ld      %r7, -32-(4*8)(%r28)
78         ld      %r8, -32-(3*8)(%r28)
79         ld      %r9, -32-(2*8)(%r28)
80         ld      %r10, -32-(1*8)(%r28)
81 1:
82
83         /* Load all the FP registers.  */
84         bf-     6, 2f
85         lfd     %f1, -32-(21*8)(%r28)
86         lfd     %f2, -32-(20*8)(%r28)
87         lfd     %f3, -32-(19*8)(%r28)
88         lfd     %f4, -32-(18*8)(%r28)
89         lfd     %f5, -32-(17*8)(%r28)
90         lfd     %f6, -32-(16*8)(%r28)
91         lfd     %f7, -32-(15*8)(%r28)
92         lfd     %f8, -32-(14*8)(%r28)
93         lfd     %f9, -32-(13*8)(%r28)
94         lfd     %f10, -32-(12*8)(%r28)
95         lfd     %f11, -32-(11*8)(%r28)
96         lfd     %f12, -32-(10*8)(%r28)
97         lfd     %f13, -32-(9*8)(%r28)
98 2:
99
100         /* Make the call.  */
101         bctrl
102
103         /* This must follow the call immediately, the unwinder
104            uses this to find out if r2 has been saved or not.  */
105         ld      %r2, 40(%r1)
106
107         /* Now, deal with the return value.  */
108         mtcrf   0x01, %r31
109         bt-     30, .Ldone_return_value
110         bt-     29, .Lfp_return_value
111         std     %r3, 0(%r30)
112         /* Fall through...  */
113
114 .Ldone_return_value:
115         /* Restore the registers we used and return.  */
116         mr      %r1, %r28
117         ld      %r0, 16(%r28)
118         ld      %r28, -32(%r1)
119         mtlr    %r0
120         ld      %r29, -24(%r1)
121         ld      %r30, -16(%r1)
122         ld      %r31, -8(%r1)
123         blr
124
125 .Lfp_return_value:
126         bf      28, .Lfloat_return_value
127         stfd    %f1, 0(%r30)
128         mtcrf   0x02, %r31 /* cr6  */
129         bf      27, .Ldone_return_value
130         stfd    %f2, 8(%r30)
131         b       .Ldone_return_value
132 .Lfloat_return_value:
133         stfs    %f1, 0(%r30)
134         b       .Ldone_return_value
135 .LFE1:
136         .long   0
137         .byte   0,12,0,1,128,4,0,0
138         .size   .ffi_call_LINUX64,.-.ffi_call_LINUX64
139
140         .section        .eh_frame,EH_FRAME_FLAGS,@progbits
141 .Lframe1:
142         .4byte  .LECIE1-.LSCIE1  # Length of Common Information Entry
143 .LSCIE1:
144         .4byte  0x0      # CIE Identifier Tag
145         .byte   0x1      # CIE Version
146         .ascii "zR\0"    # CIE Augmentation
147         .uleb128 0x1     # CIE Code Alignment Factor
148         .sleb128 -8      # CIE Data Alignment Factor
149         .byte   0x41     # CIE RA Column
150         .uleb128 0x1     # Augmentation size
151         .byte   0x14     # FDE Encoding (pcrel udata8)
152         .byte   0xc      # DW_CFA_def_cfa
153         .uleb128 0x1
154         .uleb128 0x0
155         .align 3
156 .LECIE1:
157 .LSFDE1:
158         .4byte  .LEFDE1-.LASFDE1         # FDE Length
159 .LASFDE1:
160         .4byte  .LASFDE1-.Lframe1        # FDE CIE offset
161         .8byte  .LFB1-.  # FDE initial location
162         .8byte  .LFE1-.LFB1      # FDE address range
163         .uleb128 0x0     # Augmentation size
164         .byte   0x2      # DW_CFA_advance_loc1
165         .byte   .LCFI0-.LFB1
166         .byte   0xd      # DW_CFA_def_cfa_register
167         .uleb128 0x1c
168         .byte   0x11     # DW_CFA_offset_extended_sf
169         .uleb128 0x41
170         .sleb128 -2
171         .byte   0x9f     # DW_CFA_offset, column 0x1f
172         .uleb128 0x1
173         .byte   0x9e     # DW_CFA_offset, column 0x1e
174         .uleb128 0x2
175         .byte   0x9d     # DW_CFA_offset, column 0x1d
176         .uleb128 0x3
177         .byte   0x9c     # DW_CFA_offset, column 0x1c
178         .uleb128 0x4
179         .align 3
180 .LEFDE1:
181 #endif