Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / config / rs6000 / tramp.asm
blobcd61f1d7efd2d9a0f4857de743e6c009698dea4b
1 /* Special support for trampolines
3 * Copyright (C) 1996, 1997, 2000, 2007 Free Software Foundation, Inc.
4 * Written By Michael Meissner
5 *
6 * This file is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * In addition to the permissions in the GNU General Public License, the
12 * Free Software Foundation gives you unlimited permission to link the
13 * compiled version of this file with other programs, and to distribute
14 * those programs without any restriction coming from the use of this
15 * file. (The General Public License restrictions do apply in other
16 * respects; for example, they cover modification of the file, and
17 * distribution when not linked into another program.)
19 * This file is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; see the file COPYING. If not, write to
26 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27 * Boston, MA 02110-1301, USA.
29 * As a special exception, if you link this library with files
30 * compiled with GCC to produce an executable, this does not cause
31 * the resulting executable to be covered by the GNU General Public License.
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
34 */
36 /* Set up trampolines. */
38 .file "tramp.asm"
39 .section ".text"
40 #include "ppc-asm.h"
41 #include "config.h"
43 #ifndef __powerpc64__
44 .type trampoline_initial,@object
45 .align 2
46 trampoline_initial:
47 mflr r0
48 bcl 20,31,1f
49 .Lfunc = .-trampoline_initial
50 .long 0 /* will be replaced with function address */
51 .Lchain = .-trampoline_initial
52 .long 0 /* will be replaced with static chain */
53 1: mflr r11
54 mtlr r0
55 lwz r0,0(r11) /* function address */
56 lwz r11,4(r11) /* static chain */
57 mtctr r0
58 bctr
60 trampoline_size = .-trampoline_initial
61 .size trampoline_initial,trampoline_size
64 /* R3 = stack address to store trampoline */
65 /* R4 = length of trampoline area */
66 /* R5 = function address */
67 /* R6 = static chain */
69 FUNC_START(__trampoline_setup)
70 mflr r0 /* save return address */
71 bcl 20,31,.LCF0 /* load up __trampoline_initial into r7 */
72 .LCF0:
73 mflr r11
74 addi r7,r11,trampoline_initial-4-.LCF0 /* trampoline address -4 */
76 li r8,trampoline_size /* verify that the trampoline is big enough */
77 cmpw cr1,r8,r4
78 srwi r4,r4,2 /* # words to move */
79 addi r9,r3,-4 /* adjust pointer for lwzu */
80 mtctr r4
81 blt cr1,.Labort
83 mtlr r0
85 /* Copy the instructions to the stack */
86 .Lmove:
87 lwzu r10,4(r7)
88 stwu r10,4(r9)
89 bdnz .Lmove
91 /* Store correct function and static chain */
92 stw r5,.Lfunc(r3)
93 stw r6,.Lchain(r3)
95 /* Now flush both caches */
96 mtctr r4
97 .Lcache:
98 icbi 0,r3
99 dcbf 0,r3
100 addi r3,r3,4
101 bdnz .Lcache
103 /* Finally synchronize things & return */
104 sync
105 isync
108 .Labort:
109 #if (defined __PIC__ || defined __pic__) && defined HAVE_AS_REL16
110 bcl 20,31,1f
111 1: mflr r30
112 addis r30,r30,_GLOBAL_OFFSET_TABLE_-1b@ha
113 addi r30,r30,_GLOBAL_OFFSET_TABLE_-1b@l
114 #endif
115 bl JUMP_TARGET(abort)
116 FUNC_END(__trampoline_setup)
118 #endif