1 #------------------------------------------------------------------------------
3 # Manage differenced between UNIX ABI and EFI/Windows ABI
5 # EFI Arg passing: RCX, RDX, R8, R9
6 # Callee allocates 32 bytes on stack to spill registers
7 # UNIX Arg passing: RDI, RSI, RDX, RCX, R8, R9
8 # RSI, RDI calle-save on EFI, scatch on UNIX callign
10 # Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
11 # This program and the accompanying materials
12 # are licensed and made available under the terms and conditions of the BSD License
13 # which accompanies this distribution. The full text of the license may be found at
14 # http://opensource.org/licenses/bsd-license.php
16 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #------------------------------------------------------------------------------
22 // Gaskets are EFI ABI to UNIX ABI calls
23 // EFI ABI code will sub 40 (0x28) from %rsp before calling a function
24 // This is the 32 (0x20) byte to spill registers and 8 bytes to align stack on 16 byte boundry.
28 // 32 byte shadow to spill rcx-r9, 8 bytes to align stack on 16 byte boundry
29 // Any call with 0 - 4 arguments allocates 40 bytes on the stack.
30 // For more than 4 args you always have to increase in quanta of 16 so 5 or 6 args is 56,
31 // 7 or 8 args is 72, and 9 or 10 args is 88
38 // EMU_THUNK_PROTOCOL gaskets (EFIAPI to UNIX ABI)
44 ASM_GLOBAL ASM_PFX(GasketSecWriteStdErr)
45 ASM_PFX(GasketSecWriteStdErr):
46 pushq %rbp // stack frame is for the debugger
49 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
52 movq %rcx, %rdi // Swizzle args
55 call ASM_PFX(SecWriteStdErr)
57 popq %rdi // restore state
63 ASM_GLOBAL ASM_PFX(GasketSecSetTimer)
64 ASM_PFX(GasketSecSetTimer):
65 pushq %rbp // stack frame is for the debugger
68 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
71 movq %rcx, %rdi // Swizzle args
74 call ASM_PFX(SecSetTimer)
76 popq %rdi // restore state
82 ASM_GLOBAL ASM_PFX(GasketSecEnableInterrupt)
83 ASM_PFX(GasketSecEnableInterrupt):
84 pushq %rbp // stack frame is for the debugger
87 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
90 call ASM_PFX(SecEnableInterrupt)
92 popq %rdi // restore state
98 ASM_GLOBAL ASM_PFX(GasketSecDisableInterrupt)
99 ASM_PFX(GasketSecDisableInterrupt):
100 pushq %rbp // stack frame is for the debugger
103 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
106 call ASM_PFX(SecDisableInterrupt)
108 popq %rdi // restore state
113 ASM_GLOBAL ASM_PFX(GasketQueryPerformanceFrequency)
114 ASM_PFX(GasketQueryPerformanceFrequency):
115 pushq %rbp // stack frame is for the debugger
118 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
121 call ASM_PFX(QueryPerformanceFrequency)
123 popq %rdi // restore state
129 ASM_GLOBAL ASM_PFX(GasketQueryPerformanceCounter)
130 ASM_PFX(GasketQueryPerformanceCounter):
131 pushq %rbp // stack frame is for the debugger
134 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
137 call ASM_PFX(QueryPerformanceCounter)
139 popq %rdi // restore state
145 ASM_GLOBAL ASM_PFX(GasketSecSleep)
146 ASM_PFX(GasketSecSleep):
147 pushq %rbp // stack frame is for the debugger
150 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
153 movq %rcx, %rdi // Swizzle args
155 call ASM_PFX(SecSleep)
157 popq %rdi // restore state
163 ASM_GLOBAL ASM_PFX(GasketSecExit)
164 ASM_PFX(GasketSecExit):
165 pushq %rbp // stack frame is for the debugger
168 movq %rcx, %rdi // Swizzle args
169 call ASM_PFX(SecExit) // Less to do as we will never return to EFI ABI world
171 jmp LDEAD_LOOP // _exit should never return
174 ASM_GLOBAL ASM_PFX(GasketSecGetTime)
175 ASM_PFX(GasketSecGetTime):
176 pushq %rbp // stack frame is for the debugger
179 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
182 movq %rcx, %rdi // Swizzle args
185 call ASM_PFX(SecGetTime)
187 popq %rdi // restore state
192 ASM_GLOBAL ASM_PFX(GasketSecSetTime)
193 ASM_PFX(GasketSecSetTime):
194 pushq %rbp // stack frame is for the debugger
197 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
200 movq %rcx, %rdi // Swizzle args
203 call ASM_PFX(SecSetTime)
205 popq %rdi // restore state
211 ASM_GLOBAL ASM_PFX(GasketSecGetNextProtocol)
212 ASM_PFX(GasketSecGetNextProtocol):
213 pushq %rbp // stack frame is for the debugger
216 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
219 movq %rcx, %rdi // Swizzle args
224 call ASM_PFX(SecGetNextProtocol)
226 popq %rdi // restore state
231 // PPIs produced by SEC
233 ASM_GLOBAL ASM_PFX(GasketSecPeCoffGetEntryPoint)
234 ASM_PFX(GasketSecPeCoffGetEntryPoint):
235 pushq %rbp // stack frame is for the debugger
238 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
241 movq %rcx, %rdi // Swizzle args
244 call ASM_PFX(SecPeCoffGetEntryPoint)
246 popq %rdi // restore state
251 ASM_GLOBAL ASM_PFX(GasketSecPeCoffRelocateImageExtraAction)
252 ASM_PFX(GasketSecPeCoffRelocateImageExtraAction):
253 pushq %rbp // stack frame is for the debugger
256 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
259 movq %rcx, %rdi // Swizzle args
261 call ASM_PFX(SecPeCoffRelocateImageExtraAction)
263 popq %rdi // restore state
268 ASM_GLOBAL ASM_PFX(GasketSecPeCoffUnloadImageExtraAction)
269 ASM_PFX(GasketSecPeCoffUnloadImageExtraAction):
270 pushq %rbp // stack frame is for the debugger
273 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
276 movq %rcx, %rdi // Swizzle args
278 call ASM_PFX(SecPeCoffUnloadImageExtraAction)
280 popq %rdi // restore state
286 ASM_GLOBAL ASM_PFX(GasketSecEmuThunkAddress)
287 ASM_PFX(GasketSecEmuThunkAddress):
288 pushq %rbp // stack frame is for the debugger
291 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
294 call ASM_PFX(SecEmuThunkAddress)
296 popq %rdi // restore state
302 // Gasket functions for EFI_EMU_UGA_IO_PROTOCOL
305 ASM_GLOBAL ASM_PFX(GasketX11Size)
306 ASM_PFX(GasketX11Size):
307 pushq %rbp // stack frame is for the debugger
310 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
313 movq %rcx, %rdi // Swizzle args
318 call ASM_PFX(X11Size)
320 popq %rdi // restore state
326 ASM_GLOBAL ASM_PFX(GasketX11CheckKey)
327 ASM_PFX(GasketX11CheckKey):
328 pushq %rbp // stack frame is for the debugger
331 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
334 movq %rcx, %rdi // Swizzle args
336 call ASM_PFX(X11CheckKey)
338 popq %rdi // restore state
343 ASM_GLOBAL ASM_PFX(GasketX11GetKey)
344 ASM_PFX(GasketX11GetKey):
345 pushq %rbp // stack frame is for the debugger
348 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
351 movq %rcx, %rdi // Swizzle args
354 call ASM_PFX(X11GetKey)
356 popq %rdi // restore state
362 ASM_GLOBAL ASM_PFX(GasketX11KeySetState)
363 ASM_PFX(GasketX11KeySetState):
364 pushq %rbp // stack frame is for the debugger
367 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
370 movq %rcx, %rdi // Swizzle args
373 call ASM_PFX(X11KeySetState)
375 popq %rdi // restore state
381 ASM_GLOBAL ASM_PFX(GasketX11RegisterKeyNotify)
382 ASM_PFX(GasketX11RegisterKeyNotify):
383 pushq %rbp // stack frame is for the debugger
386 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
389 movq %rcx, %rdi // Swizzle args
394 call ASM_PFX(X11RegisterKeyNotify)
396 popq %rdi // restore state
402 ASM_GLOBAL ASM_PFX(GasketX11Blt)
403 ASM_PFX(GasketX11Blt):
404 pushq %rbp // stack frame is for the debugger
407 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
410 movq %rcx, %rdi // Swizzle args
417 popq %rdi // restore state
423 ASM_GLOBAL ASM_PFX(GasketX11CheckPointer)
424 ASM_PFX(GasketX11CheckPointer):
425 pushq %rbp // stack frame is for the debugger
428 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
431 movq %rcx, %rdi // Swizzle args
433 call ASM_PFX(X11CheckPointer)
435 popq %rdi // restore state
441 ASM_GLOBAL ASM_PFX(GasketX11GetPointerState)
442 ASM_PFX(GasketX11GetPointerState):
443 pushq %rbp // stack frame is for the debugger
446 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
449 movq %rcx, %rdi // Swizzle args
452 call ASM_PFX(X11GetPointerState)
454 popq %rdi // restore state
460 ASM_GLOBAL ASM_PFX(GasketX11GraphicsWindowOpen)
461 ASM_PFX(GasketX11GraphicsWindowOpen):
462 pushq %rbp // stack frame is for the debugger
465 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
468 movq %rcx, %rdi // Swizzle args
470 call ASM_PFX(X11GraphicsWindowOpen)
472 popq %rdi // restore state
478 ASM_GLOBAL ASM_PFX(GasketX11GraphicsWindowClose)
479 ASM_PFX(GasketX11GraphicsWindowClose):
480 pushq %rbp // stack frame is for the debugger
483 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
486 movq %rcx, %rdi // Swizzle args
489 call ASM_PFX(X11GraphicsWindowClose)
491 popq %rdi // restore state
499 ASM_GLOBAL ASM_PFX(GasketPthreadMutexLock)
500 ASM_PFX(GasketPthreadMutexLock):
501 pushq %rbp // stack frame is for the debugger
504 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
507 movq %rcx, %rdi // Swizzle args
509 call ASM_PFX(PthreadMutexLock)
511 popq %rdi // restore state
517 ASM_GLOBAL ASM_PFX(GasketPthreadMutexUnLock)
518 ASM_PFX(GasketPthreadMutexUnLock):
519 pushq %rbp // stack frame is for the debugger
522 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
525 movq %rcx, %rdi // Swizzle args
527 call ASM_PFX(PthreadMutexUnLock)
529 popq %rdi // restore state
534 ASM_GLOBAL ASM_PFX(GasketPthreadMutexTryLock)
535 ASM_PFX(GasketPthreadMutexTryLock):
536 pushq %rbp // stack frame is for the debugger
539 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
542 movq %rcx, %rdi // Swizzle args
544 call ASM_PFX(PthreadMutexTryLock)
546 popq %rdi // restore state
551 ASM_GLOBAL ASM_PFX(GasketPthreadMutexInit)
552 ASM_PFX(GasketPthreadMutexInit):
553 pushq %rbp // stack frame is for the debugger
556 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
560 call ASM_PFX(PthreadMutexInit)
562 popq %rdi // restore state
569 ASM_GLOBAL ASM_PFX(GasketPthreadMutexDestroy)
570 ASM_PFX(GasketPthreadMutexDestroy):
571 pushq %rbp // stack frame is for the debugger
574 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
577 movq %rcx, %rdi // Swizzle args
579 call ASM_PFX(PthreadMutexDestroy)
581 popq %rdi // restore state
587 ASM_GLOBAL ASM_PFX(GasketPthreadCreate)
588 ASM_PFX(GasketPthreadCreate):
589 pushq %rbp // stack frame is for the debugger
592 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
595 movq %rcx, %rdi // Swizzle args
600 call ASM_PFX(PthreadCreate)
602 popq %rdi // restore state
608 ASM_GLOBAL ASM_PFX(GasketPthreadExit)
609 ASM_PFX(GasketPthreadExit):
610 pushq %rbp // stack frame is for the debugger
613 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
616 movq %rcx, %rdi // Swizzle args
618 call ASM_PFX(PthreadExit)
620 popq %rdi // restore state
627 ASM_GLOBAL ASM_PFX(GasketPthreadSelf)
628 ASM_PFX(GasketPthreadSelf):
629 pushq %rbp // stack frame is for the debugger
632 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
636 call ASM_PFX(PthreadSelf)
638 popq %rdi // restore state
644 ASM_GLOBAL ASM_PFX(GasketPthreadOpen)
645 ASM_PFX(GasketPthreadOpen):
646 pushq %rbp // stack frame is for the debugger
649 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
652 movq %rcx, %rdi // Swizzle args
654 call ASM_PFX(PthreadOpen)
656 popq %rdi // restore state
662 ASM_GLOBAL ASM_PFX(GasketPthreadClose)
663 ASM_PFX(GasketPthreadClose):
664 pushq %rbp // stack frame is for the debugger
667 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
670 movq %rcx, %rdi // Swizzle args
672 call ASM_PFX(PthreadClose)
674 popq %rdi // restore state
683 // UNIX ABI to EFI ABI call
686 // ReverseGasketUint64 (
690 ASM_GLOBAL ASM_PFX(ReverseGasketUint64)
691 ASM_PFX(ReverseGasketUint64):
692 pushq %rbp // stack frame is for the debugger
695 movq %rdi, %rax // Swizzle args
698 subq $32, %rsp // 32-byte shadow space
706 // UNIX ABI to EFI ABI call
709 // ReverseGasketUint64Uint64 (
714 ASM_GLOBAL ASM_PFX(ReverseGasketUint64Uint64)
715 ASM_PFX(ReverseGasketUint64Uint64):
716 pushq %rbp // stack frame is for the debugger
719 movq %rdi, %rax // Swizzle args
722 subq $32, %rsp // 32-byte shadow space
730 // Sec PPI Callbacks - Check Me
732 ASM_GLOBAL ASM_PFX(GasketSecUnixPeiLoadFile)
733 ASM_PFX(GasketSecUnixPeiLoadFile):
734 pushq %rbp // stack frame is for the debugger
737 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
740 movq %rcx, %rdi // Swizzle args
745 call ASM_PFX(SecUnixPeiLoadFile)
747 popq %rdi // restore state
754 ASM_GLOBAL ASM_PFX(GasketSecUnixPeiAutoScan)
755 ASM_PFX(GasketSecUnixPeiAutoScan):
756 pushq %rbp // stack frame is for the debugger
759 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
762 movq %rcx, %rdi // Swizzle args
766 call ASM_PFX(SecUnixPeiAutoScan)
768 popq %rdi // restore state
774 ASM_GLOBAL ASM_PFX(GasketSecUnixFdAddress)
775 ASM_PFX(GasketSecUnixFdAddress):
776 pushq %rbp // stack frame is for the debugger
779 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
782 movq %rcx, %rdi // Swizzle args
787 call ASM_PFX(SecUnixFdAddress)
789 popq %rdi // restore state
795 // EmuIoThunk SimpleFileSystem
797 ASM_GLOBAL ASM_PFX(GasketPosixOpenVolume)
798 ASM_PFX(GasketPosixOpenVolume):
799 pushq %rbp // stack frame is for the debugger
802 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
805 movq %rcx, %rdi // Swizzle args
810 call ASM_PFX(PosixOpenVolume)
812 popq %rdi // restore state
818 ASM_GLOBAL ASM_PFX(GasketPosixFileOpen)
819 ASM_PFX(GasketPosixFileOpen):
820 pushq %rbp // stack frame is for the debugger
823 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
826 movq %rcx, %rdi // Swizzle args
832 call ASM_PFX(PosixFileOpen)
834 popq %rdi // restore state
840 ASM_GLOBAL ASM_PFX(GasketPosixFileCLose)
841 ASM_PFX(GasketPosixFileCLose):
842 pushq %rbp // stack frame is for the debugger
845 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
848 movq %rcx, %rdi // Swizzle args
850 call ASM_PFX(PosixFileCLose)
852 popq %rdi // restore state
858 ASM_GLOBAL ASM_PFX(GasketPosixFileDelete)
859 ASM_PFX(GasketPosixFileDelete):
860 pushq %rbp // stack frame is for the debugger
863 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
866 movq %rcx, %rdi // Swizzle args
868 call ASM_PFX(PosixFileDelete)
870 popq %rdi // restore state
876 ASM_GLOBAL ASM_PFX(GasketPosixFileRead)
877 ASM_PFX(GasketPosixFileRead):
878 pushq %rbp // stack frame is for the debugger
881 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
884 movq %rcx, %rdi // Swizzle args
888 call ASM_PFX(PosixFileRead)
890 popq %rdi // restore state
896 ASM_GLOBAL ASM_PFX(GasketPosixFileWrite)
897 ASM_PFX(GasketPosixFileWrite):
898 pushq %rbp // stack frame is for the debugger
901 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
904 movq %rcx, %rdi // Swizzle args
908 call ASM_PFX(PosixFileWrite)
910 popq %rdi // restore state
916 ASM_GLOBAL ASM_PFX(GasketPosixFileSetPossition)
917 ASM_PFX(GasketPosixFileSetPossition):
918 pushq %rbp // stack frame is for the debugger
921 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
924 movq %rcx, %rdi // Swizzle args
927 call ASM_PFX(PosixFileSetPossition)
929 popq %rdi // restore state
935 ASM_GLOBAL ASM_PFX(GasketPosixFileGetPossition)
936 ASM_PFX(GasketPosixFileGetPossition):
937 pushq %rbp // stack frame is for the debugger
940 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
943 movq %rcx, %rdi // Swizzle args
946 call ASM_PFX(PosixFileGetPossition)
948 popq %rdi // restore state
954 ASM_GLOBAL ASM_PFX(GasketPosixFileGetInfo)
955 ASM_PFX(GasketPosixFileGetInfo):
956 pushq %rbp // stack frame is for the debugger
959 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
962 movq %rcx, %rdi // Swizzle args
967 call ASM_PFX(PosixFileGetInfo)
969 popq %rdi // restore state
975 ASM_GLOBAL ASM_PFX(GasketPosixFileSetInfo)
976 ASM_PFX(GasketPosixFileSetInfo):
977 pushq %rbp // stack frame is for the debugger
980 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
983 movq %rcx, %rdi // Swizzle args
988 call ASM_PFX(PosixFileSetInfo)
990 popq %rdi // restore state
996 ASM_GLOBAL ASM_PFX(GasketPosixFileFlush)
997 ASM_PFX(GasketPosixFileFlush):
998 pushq %rbp // stack frame is for the debugger
1001 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
1004 movq %rcx, %rdi // Swizzle args
1006 call ASM_PFX(PosixFileFlush)
1008 popq %rdi // restore state
1014 ASM_GLOBAL ASM_PFX(GasketPosixFileSystmeThunkOpen)
1015 ASM_PFX(GasketPosixFileSystmeThunkOpen):
1016 pushq %rbp // stack frame is for the debugger
1019 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
1022 movq %rcx, %rdi // Swizzle args
1024 call ASM_PFX(PosixFileSystmeThunkOpen)
1026 popq %rdi // restore state
1032 ASM_GLOBAL ASM_PFX(GasketPosixFileSystmeThunkClose)
1033 ASM_PFX(GasketPosixFileSystmeThunkClose):
1034 pushq %rbp // stack frame is for the debugger
1037 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
1040 movq %rcx, %rdi // Swizzle args
1042 call ASM_PFX(PosixFileSystmeThunkClose)
1044 popq %rdi // restore state