]>
Commit | Line | Data |
---|---|---|
a0d66c8d | 1 | /* Special support for trampolines |
eaf1bcf1 | 2 | * |
9ebbca7d | 3 | * Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. |
eaf1bcf1 MM |
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. | |
10 | * | |
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.) | |
18 | * | |
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. | |
23 | * | |
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, 59 Temple Place - Suite 330, | |
27 | * Boston, MA 02111-1307, USA. | |
28 | * | |
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 | */ | |
35 | ||
9ebbca7d | 36 | /* Set up trampolines. */ |
eaf1bcf1 MM |
37 | |
38 | .file "tramp.asm" | |
39 | .section ".text" | |
40 | #include "ppc-asm.h" | |
41 | ||
9ebbca7d | 42 | .type trampoline_initial,@object |
eaf1bcf1 | 43 | .align 2 |
9ebbca7d | 44 | trampoline_initial: |
eaf1bcf1 MM |
45 | mflr r0 |
46 | bl 1f | |
9ebbca7d | 47 | .Lfunc = .-trampoline_initial |
eaf1bcf1 | 48 | .long 0 /* will be replaced with function address */ |
9ebbca7d | 49 | .Lchain = .-trampoline_initial |
eaf1bcf1 MM |
50 | .long 0 /* will be replaced with static chain */ |
51 | 1: mflr r11 | |
52 | mtlr r0 | |
53 | lwz r0,0(r11) /* function address */ | |
54 | lwz r11,4(r11) /* static chain */ | |
55 | mtctr r0 | |
56 | bctr | |
57 | ||
9ebbca7d GK |
58 | trampoline_size = .-trampoline_initial |
59 | .size trampoline_initial,trampoline_size | |
eaf1bcf1 | 60 | |
eaf1bcf1 MM |
61 | |
62 | /* R3 = stack address to store trampoline */ | |
63 | /* R4 = length of trampoline area */ | |
64 | /* R5 = function address */ | |
65 | /* R6 = static chain */ | |
66 | ||
67 | FUNC_START(__trampoline_setup) | |
9ebbca7d GK |
68 | mflr r0 /* save return address */ |
69 | bl .LCF0 /* load up __trampoline_initial into r7 */ | |
eaf1bcf1 MM |
70 | .LCF0: |
71 | mflr r11 | |
9ebbca7d | 72 | addi r7,r11,trampoline_initial-4-.LCF0 /* trampoline address -4 */ |
eaf1bcf1 | 73 | |
9ebbca7d | 74 | li r8,trampoline_size /* verify that the trampoline is big enough */ |
eaf1bcf1 | 75 | cmpw cr1,r8,r4 |
9ebbca7d GK |
76 | srwi r4,r4,2 /* # words to move */ |
77 | addi r9,r3,-4 /* adjust pointer for lwzu */ | |
eaf1bcf1 MM |
78 | mtctr r4 |
79 | blt cr1,.Labort | |
80 | ||
81 | mtlr r0 | |
82 | ||
83 | /* Copy the instructions to the stack */ | |
84 | .Lmove: | |
85 | lwzu r10,4(r7) | |
86 | stwu r10,4(r9) | |
87 | bdnz .Lmove | |
88 | ||
89 | /* Store correct function and static chain */ | |
90 | stw r5,.Lfunc(r3) | |
91 | stw r6,.Lchain(r3) | |
92 | ||
93 | /* Now flush both caches */ | |
94 | mtctr r4 | |
95 | .Lcache: | |
96 | icbi 0,r3 | |
97 | dcbf 0,r3 | |
98 | addi r3,r3,4 | |
99 | bdnz .Lcache | |
100 | ||
101 | /* Finally synchronize things & return */ | |
102 | sync | |
103 | isync | |
104 | blr | |
105 | ||
106 | .Labort: | |
9ebbca7d | 107 | bl FUNC_NAME(abort) |
eaf1bcf1 | 108 | FUNC_END(__trampoline_setup) |
9ebbca7d | 109 |