summaryrefslogtreecommitdiff
path: root/UnixPkg/Sec/Ia32/Gasket.S
blob: 93d92b50deb14ba02ae362494198093af19b9957 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#------------------------------------------------------------------------------
#
# OS X Application requires 16 byte stack alignment. The problem is these
# APIs are exposed to code that does not have this requirement via 
# EFI_UNIX_THUNK_PROTOCOL. So these are wrapper functions that make sure
# the stack is aligned. This code should also work if the stack is already
# aligned. Extra stack padding is really the same as local varaibles so 
# it gets freed by the leave instruction
#
# I basically used the compiler, added extra 16 bytes to the local stack and
# made sure %esp ended in 0 before the call (16 byte algined)
#
# The EFI_UNIX_THUNK_PROTOCOL member functions call a C API that then calls 
# one of these generic assembly routines.  We do it that way to work around 
# some magic name changing that happens in C. For example stat() is _stat() 
# on Leopard and _stat$INDOE64 on Snow Leopard. That is why we pass stat()
# into one of these gaskets from C code.
#
# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution.  The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------

#ifdef __APPLE__

  .text

#------------------------------------------------------------------------------
# int GasketVoid (void *api)
#------------------------------------------------------------------------------    
.globl _GasketVoid
_GasketVoid:
  pushl %ebp
  movl  %esp, %ebp
  subl  $34, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintn
_GasketUintn:
  pushl %ebp
  movl  %esp, %ebp
  subl  $50, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintnUintn
_GasketUintnUintn:
  pushl %ebp
  movl  %esp, %ebp
  subl  $50, %esp           # sub extra 0x10 from the stack for the AND 
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  16(%ebp), %eax
  movl  %eax, 4(%esp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintnUintnUintn
_GasketUintnUintnUintn:
  pushl %ebp
  movl  %esp, %ebp
  subl  $50, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  20(%ebp), %eax
  movl  %eax, 8(%esp)
  movl  16(%ebp), %eax
  movl  %eax, 4(%esp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintnUintnUintnUintn
_GasketUintnUintnUintnUintn:
  pushl %ebp
  movl  %esp, %ebp
  subl  $50, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  24(%ebp), %eax
  movl  %eax, 12(%esp)
  movl  20(%ebp), %eax
  movl  %eax, 8(%esp)
  movl  16(%ebp), %eax
  movl  %eax, 4(%esp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintn10Args
_GasketUintn10Args:
  pushl %ebp
  movl  %esp, %ebp
  subl  $82, %esp         # sub extra 0x10 from the stack for the AND
  and   $-16, %esp        # stack needs to end in 0xFFFFFFF0 before call
  movl  8(%ebp), %eax     
  movl  %eax, -12(%ebp)
  movl  48(%ebp), %eax
  movl  %eax, 36(%esp)
  movl  44(%ebp), %eax
  movl  %eax, 32(%esp)
  movl  40(%ebp), %eax
  movl  %eax, 28(%esp)
  movl  36(%ebp), %eax
  movl  %eax, 24(%esp)
  movl  32(%ebp), %eax
  movl  %eax, 20(%esp)
  movl  28(%ebp), %eax
  movl  %eax, 16(%esp)
  movl  24(%ebp), %eax
  movl  %eax, 12(%esp)
  movl  20(%ebp), %eax
  movl  %eax, 8(%esp)
  movl  16(%ebp), %eax
  movl  %eax, 4(%esp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret


#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUint64Uintn
_GasketUint64Uintn:
  pushl %ebp
  movl  %esp, %ebp
  subl  $66, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  12(%ebp), %eax
  movl  %eax, -32(%ebp)
  movl  16(%ebp), %eax
  movl  %eax, -28(%ebp)
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  20(%ebp), %eax
  movl  %eax, 8(%esp)
  movl  -32(%ebp), %eax
  movl  -28(%ebp), %edx
  movl  %eax, (%esp)
  movl  %edx, 4(%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintnUint64Uintn
_GasketUintnUint64Uintn:
  pushl %ebp
  movl  %esp, %ebp
  subl  $66, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  16(%ebp), %eax
  movl  %eax, -32(%ebp)
  movl  20(%ebp), %eax
  movl  %eax, -28(%ebp)
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movl  24(%ebp), %eax
  movl  %eax, 12(%esp)
  movl  -32(%ebp), %eax
  movl  -28(%ebp), %edx
  movl  %eax, 4(%esp)
  movl  %edx, 8(%esp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
.globl _GasketUintnUint16
_GasketUintnUint16:
  pushl %ebp
  movl  %esp, %ebp
  subl  $66, %esp           # sub extra 0x10 from the stack for the AND
  and   $-16, %esp          # stack needs to end in 0xFFFFFFF0 before call
  movl  16(%ebp), %eax
  movw  %ax, -28(%ebp)
  movl  8(%ebp), %eax
  movl  %eax, -12(%ebp)
  movzwl  -28(%ebp), %eax
  movl  %eax, 4(%esp)
  movl  12(%ebp), %eax
  movl  %eax, (%esp)
  movl  -12(%ebp), %eax
  call  *%eax
  leave
  ret
  
  
.globl _ReverseGasketUint64
_ReverseGasketUint64:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$40, %esp
	movl	12(%ebp), %eax
	movl	%eax, -16(%ebp)
	movl	16(%ebp), %eax
	movl	%eax, -12(%ebp)
	movl	-16(%ebp), %eax
	movl	-12(%ebp), %edx
	movl	%eax, (%esp)
	movl	%edx, 4(%esp)
	movl	8(%ebp), %eax
	call	*%eax
	leave
	ret
  
  
// Sec PPI Callbacks

.globl _GasketSecUnixPeiLoadFile
_GasketSecUnixPeiLoadFile:
	jmp	  _SecUnixPeiLoadFile


.globl _GasketSecUnixPeiAutoScan
_GasketSecUnixPeiAutoScan:
	jmp	  _SecUnixPeiAutoScan


.globl _GasketSecUnixUnixThunkAddress
_GasketSecUnixUnixThunkAddress:
	jmp	  _SecUnixUnixThunkAddress


.globl _GasketSecPeiReportStatusCode
_GasketSecPeiReportStatusCode:
	jmp	  _SecPeiReportStatusCode


.globl _GasketSecUnixFdAddress
_GasketSecUnixFdAddress:
	jmp	  _SecUnixFdAddress


.globl _GasketSecTemporaryRamSupport
_GasketSecTemporaryRamSupport:
	jmp	  _SecTemporaryRamSupport
  
  #endif