1
/* ppc-sysv-asm.S -- PowerPC FFI trampoline for SVr4-like ABIs -*- asm -*-
3
* Author: Ian.Piumarta@INRIA.Fr
5
* Last edited: 2006-10-18 10:07:42 by piumarta on emilia.local
7
* Copyright (C) 1996-2004 by Ian Piumarta and other authors/contributors
8
* listed elsewhere in this file.
11
* This file is part of Unix Squeak.
13
* Permission is hereby granted, free of charge, to any person obtaining a copy
14
* of this software and associated documentation files (the "Software"), to deal
15
* in the Software without restriction, including without limitation the rights
16
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
* copies of the Software, and to permit persons to whom the Software is
18
* furnished to do so, subject to the following conditions:
20
* The above copyright notice and this permission notice shall be included in
21
* all copies or substantial portions of the Software.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
59
/* V.4 stack frames look like this (higher addresses first):
61
old SP--> | back chain to caller's caller |
62
| Save area for FP registers (F) | 8+P+A+V+L+X+C+G
63
| Save area for GP registers (G) | 8+P+A+V+L+X+C
64
| saved CR (C) | 8+P+A+V+L+X
65
| Float/int conversion temporary (X) | 8+P+A+V+L
66
| Local variable space (L) | 8+P+A+V
67
| Varargs save area (V) | 8+P+A
68
| Alloca space (A) | 8+P
69
| Parameter save area (P) | 8
70
| caller's saved LR | 4
71
SP--> | back chain to caller | 0
80
.globl ffiCallAddressOf
83
stwu sp, -16(sp) // push trampoline frame
87
stw r0, 12(sp) // saved ccr
88
mtlr fn // destination fn address
89
slwi r10, nparam, 2 // param save area size
90
addi r10, r10, 16+15 // round to quad word
91
rlwinm r10, r10, 0,0,27
93
stwux sp, sp, r10 // push ffi caller frame
94
cmpwi nparam, 0 // have params?
96
mtctr nparam // words to move
97
lis r10, (ffiStack-4)@ha
98
la r10, (ffiStack-4)@l(r10) // ffi param stack - 4
99
addi r11, sp, 4 // param save area - 4
100
1: lwzu r0, 4(r10) // copy param save area
104
beq+ 4f // no fp args
106
la r11, ffiFPRs@l(r11)
118
beq- 6f // no int args
120
la r11, ffiGPRs@l(r11)
132
lwz sp, 0(sp) // pop ffi caller frame
133
lis r5, ffiLongReturnValue@ha
134
la r5, ffiLongReturnValue@l(r5)
137
lis r5, ffiFloatReturnValue@ha
138
stfd f1, ffiFloatReturnValue@l(r5)
141
lwz r0, 12(sp) // saved ccr
143
addi sp, sp, 16 // pop trampoline frame