1 /* Special support for trampolines
3 * Copyright (C) 1996-2024 Free Software Foundation, Inc.
4 * Written By Michael Meissner
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 3, or (at your option) any
11 * This file is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * Under Section 7 of GPL version 3, you are granted additional
17 * permissions described in the GCC Runtime Library Exception, version
18 * 3.1, as published by the Free Software Foundation.
20 * You should have received a copy of the GNU General Public License and
21 * a copy of the GCC Runtime Library Exception along with this program;
22 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 * <http://www.gnu.org/licenses/>.
26 /* Set up trampolines. */
33 .type trampoline_initial,@object
38 .Lfunc = .-trampoline_initial
39 .long 0 /* will be replaced with function address */
40 .Lchain = .-trampoline_initial
41 .long 0 /* will be replaced with static chain */
44 lwz r0,0(r11) /* function address */
45 lwz r11,4(r11) /* static chain */
49 trampoline_size = .-trampoline_initial
50 .size trampoline_initial,trampoline_size
53 /* R3 = stack address to store trampoline */
54 /* R4 = length of trampoline area */
55 /* R5 = function address */
56 /* R6 = static chain */
58 FUNC_START(__trampoline_setup)
60 mflr r0 /* save return address */
61 bcl 20,31,.LCF0 /* load up __trampoline_initial into r7 */
65 addi r7,r11,trampoline_initial-4-.LCF0 /* trampoline address -4 */
67 cmpwi cr1,r4,trampoline_size /* verify that the trampoline is big enough */
68 srwi r4,r4,2 /* # words to move */
69 addi r9,r3,-4 /* adjust pointer for lwzu */
75 /* Copy the instructions to the stack */
81 /* Store correct function and static chain */
85 /* Now flush both caches */
93 /* Finally synchronize things & return */
99 /* Use a longcall sequence in the non PIC case on VxWorks, to prevent
100 possible relocation errors if this is module-loaded very far away from
101 the 'abort' entry point. */
102 #if defined (__VXWORKS__) && ! (defined __PIC__ || defined __pic__)
103 lis r11,JUMP_TARGET(abort)@ha
104 addic r11,r11,JUMP_TARGET(abort)@l
109 #if (defined __PIC__ || defined __pic__) && defined HAVE_AS_REL16
112 addis r30,r30,_GLOBAL_OFFSET_TABLE_-1b@ha
113 addi r30,r30,_GLOBAL_OFFSET_TABLE_-1b@l
115 bl JUMP_TARGET(abort)
118 FUNC_END(__trampoline_setup)
121 .type trampoline_initial,@object
128 .Lfunc = .-trampoline_initial
129 .quad 0 /* will be replaced with function address */
130 .Lchain = .-trampoline_initial
131 .quad 0 /* will be replaced with static chain */
133 trampoline_size = .-trampoline_initial
134 .size trampoline_initial,trampoline_size
137 /* R3 = stack address to store trampoline */
138 /* R4 = length of trampoline area */
139 /* R5 = function address */
140 /* R6 = static chain */
143 .pushsection ".toc","aw"
145 .quad trampoline_initial-8
149 FUNC_START(__trampoline_setup)
152 pla 7,(trampoline_initial-8)@pcrel
154 addis 7,2,.LC0@toc@ha
155 ld 7,.LC0@toc@l(7) /* trampoline address -8 */
158 cmpwi cr1,r4,trampoline_size /* verify that the trampoline is big enough */
159 srwi r4,r4,3 /* # doublewords to move */
160 addi r9,r3,-8 /* adjust pointer for stdu */
164 /* Copy the instructions to the stack */
170 /* Store correct function and static chain */
174 /* Now flush both caches */
182 /* Finally synchronize things & return */
188 bl JUMP_TARGET(abort)
191 FUNC_END(__trampoline_setup)