File: ppc-darwin-asm.S

package info (click to toggle)
squeak-vm 1%3A4.10.2.2614-4.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,284 kB
  • ctags: 15,344
  • sloc: ansic: 75,096; cs: 11,191; objc: 5,494; sh: 3,170; asm: 1,533; cpp: 449; pascal: 372; makefile: 366; awk: 103
file content (130 lines) | stat: -rw-r--r-- 3,773 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ppc-sysv-asm.S -- PowerPC FFI trampoline for Mach-O			-*- asm -*-
 *
 * Author: Ian.Piumarta@INRIA.Fr
 *
 * Last edited:	2006-10-18 10:08:10 by piumarta on emilia.local
 *
 *   Copyright (C) 1996-2004 by Ian Piumarta and other authors/contributors
 *                              listed elsewhere in this file.
 *   All rights reserved.
 *   
 *   This file is part of Unix Squeak.
 * 
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 * 
 *   The above copyright notice and this permission notice shall be included in
 *   all copies or substantial portions of the Software.
 * 
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *   SOFTWARE.
 */

/* Mach-O PPC stack frames look like this (higher addresses first):
 *
 * 		| caller's lr		|
 * 		| caller's cr		|
 * caller's sp->| caller's caller's sp	|
 *		| fpr save area		|
 *		| gpr save area		|
 *		|     [alignment pad]	|
 *		| local variables	|
 * sp + 24  ->	| param save area	|
 * sp + 20  ->	| caller's toc		|
 * sp + 16  ->	| reserved		|
 * sp + 12  ->	| reserved		|
 * sp +  8  ->	| (callee-save) lr	|
 * sp +  4  ->	| (callee-save) cr	|
 * sp +  0  ->	| caller's sp		|
 */

#define GPR_MAX   8
#define FPR_MAX  13
#define ARG_MAX 512
#define FRAMESZ	 32

#include "ppc-global.h"

#define sp r1

	.text
	.globl	_ffiCallAddressOf

_ffiCallAddressOf:
	stwu	sp, -FRAMESZ(sp)		// push trampoline frame
	mflr	r0
	stw	r0, (FRAMESZ+8)(sp)
        mfcr	r0
        stw	r0, (FRAMESZ+4)(sp)		// saved ccr
	mtlr	r3				// destination fn address
	stw	r4, (FRAMESZ-4)(sp)		// globals
	lwz	r5, stackIndex(r4)
	slwi	r10, r5, 2			// param save area size
	addi	r10, r10, 32+15			// round to quad word
	rlwinm	r10, r10, 0,0,27
	neg	r10, r10
	stwux	sp, sp, r10			// push ffi caller frame
	cmpwi	r5, 0				// have params?
	beq+	2f
	mtctr	r5				// words to move
	la	r10, (stack-4)(r4)		// ffi param stack - 4
	addi	r11, sp, 24-4			// param save area - 4
1:	lwzu	r0, 4(r10)			// copy param save area
	stwu	r0, 4(r11)
	bdnz	1b
2:	lwz	r5, fprCount(r4)
	cmpwi	r5, 0
	beq+	4f				// no fp args
	la	r11, fprs(r4)
	cmpwi	r5, 4
	ble+	3f
	lfd	f5,  32(r11)
	lfd	f6,  40(r11)
	lfd	f7,  48(r11)
	lfd	f8,  56(r11)
#	if (FPR_MAX > 8)
	lfd	f9,  64(r11)
	lfd	f10, 72(r11)
	lfd	f11, 80(r11)
	lfd	f12, 88(r11)
	lfd	f13, 96(r11)
#	endif
3:	lfd	f1,   0(r11)
	lfd	f2,   8(r11)
	lfd	f3,  16(r11)
	lfd	f4,  24(r11)
4:	lwz	r5, gprCount(r4)
	cmpwi	r5, 0
	beq-	6f				// no int args
	la	r11, gprs(r4)
	cmpwi	r5, 4
	ble+	5f
	lwz	r7,  16(r11)
	lwz	r8,  20(r11)
	lwz	r9,  24(r11)
	lwz	r10, 28(r11)
5:	lwz	r3,   0(r11)
	lwz	r4,   4(r11)
	lwz	r5,   8(r11)
	lwz	r6,  12(r11)
6:	blrl					// callout
	lwz	sp, 0(sp)			// pop ffi caller frame
	lwz	r5, (FRAMESZ-4)(sp)		// globals
	stw	r3, longReturnValue+0(r5)
	stw	r4, longReturnValue+4(r5)
	stfd	f1, floatReturnValue(r5)
	lwz	r0, (FRAMESZ+8)(sp)
 	mtlr	r0
        lwz	r0, (FRAMESZ+4)(sp)		// saved ccr
        mtcr	r0
	addi	sp, sp, FRAMESZ			// pop trampoline frame
	blr