summaryrefslogtreecommitdiff
path: root/libffi/src/alpha/osf.S
blob: 9ed37cbb00e18d405f4a497ae4ee0144a0955b60 (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* -----------------------------------------------------------------------
   osf.S - Copyright (c) 1998 Cygnus Solutions
   
   Alpha/OSF Foreign Function Interface 

   $Id: osf.S,v 1.1.1.1 1998/11/29 16:48:16 green Exp $

   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 CYGNUS SOLUTIONS 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.
   ----------------------------------------------------------------------- */

#define LIBFFI_ASM	
#include <ffi.h>

	.text

/* ffi_call_osf (void *args, unsigned long bytes, unsigned flags,
		 void *raddr, void (*fnaddr)());

   Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
   for this function.  This has been allocated by ffi_call.  We also
   deallocate some of the stack that has been alloca'd.  */

	.align	3
	.globl	ffi_call_osf
	.ent	ffi_call_osf
ffi_call_osf:
	.frame	$15, 32, $26, 0
	.mask   0x4008000, -32
	addq	$16,$17,$1
	mov	$16, $30
	stq	$26, 0($1)
	stq	$15, 8($1)
	stq	$18, 16($1)
	mov	$1, $15
	.prologue 0

	stq	$19, 24($1)
	mov	$20, $27

	# Load up all of the (potential) argument registers.
	ldq	$16, 0($30)
	ldt	$f16, 0($30)
	ldt	$f17, 8($30)
	ldq	$17, 8($30)
	ldt	$f18, 16($30)
	ldq	$18, 16($30)
	ldt	$f19, 24($30)
	ldq	$19, 24($30)
	ldt	$f20, 32($30)
	ldq	$20, 32($30)
	ldt	$f21, 40($30)
	ldq	$21, 40($30)

	# Deallocate the register argument area.
	lda	$30, 48($30)

	jsr	$26, ($27), 0
	ldgp	$29, 0($26)

	# If the return value pointer is NULL, assume no return value.
	ldq	$19, 24($15)
	ldq	$18, 16($15)
	ldq	$26, 0($15)
	beq	$19, $noretval

	# Store the return value out in the proper type.
	cmpeq	$18, FFI_TYPE_INT, $1
	bne	$1, $retint
	cmpeq	$18, FFI_TYPE_FLOAT, $2
	bne	$2, $retfloat
	cmpeq	$18, FFI_TYPE_DOUBLE, $3
	bne	$3, $retdouble

$noretval:
	ldq	$15, 8($15)
	ret

$retint:
	stq	$0, 0($19)
	nop
	ldq	$15, 8($15)
	ret

$retfloat:
	sts	$f0, 0($19)
	nop
	ldq	$15, 8($15)
	ret

$retdouble:
	stt	$f0, 0($19)
	nop
	ldq	$15, 8($15)
	ret

	.end	ffi_call_osf

/* ffi_closure_osf(...)

   Receives the closure argument in $1.   */

	.align	3
	.globl	ffi_closure_osf
	.ent	ffi_closure_osf
ffi_closure_osf:
	.frame	$30, 16*8, $26, 0
	.mask	0x4000000, -14*8
	ldgp	$29, 0($27)
	subq	$30, 14*8, $30
	stq	$26, 0($30)
	.prologue 1

	# Store all of the potential argument registers in va_list format.
	stt	$f16, 4*8($30)
	stt	$f17, 5*8($30)
	stt	$f18, 6*8($30)
	stt	$f19, 7*8($30)
	stt	$f20, 8*8($30)
	stt	$f21, 9*8($30)
	stq	$16, 10*8($30)
	stq	$17, 11*8($30)
	stq	$18, 12*8($30)
	stq	$19, 13*8($30)
	stq	$20, 14*8($30)
	stq	$21, 15*8($30)

	# Call ffi_closure_osf_inner to do the bulk of the work.
	mov	$1, $16
	lda	$17, 2*8($30)
	lda	$18, 10*8($30)
	jsr	$26, ffi_closure_osf_inner
	ldgp	$29, 0($26)
	ldq	$26, 0($30)

	# Load up the return value in the proper type.
	cmpeq	$0, FFI_TYPE_INT, $1
	bne	$1, $loadint
	cmpeq	$0, FFI_TYPE_FLOAT, $2
	bne	$2, $loadfloat
	cmpeq	$18, FFI_TYPE_DOUBLE, $3
	bne	$3, $loaddouble

	addq	$30, 16*8, $30
	ret

	.align 3
$loadint:
	ldq	$0, 16($30)
	nop
	addq	$30, 16*8, $30
	ret

$loadfloat:
	lds	$f0, 16($30)
	nop
	addq	$30, 16*8, $30
	ret

$loaddouble:
	ldt	$f0, 16($30)
	nop
	addq	$30, 16*8, $30
	ret

	.end	ffi_closure_osf