1 #------------------------------------------------------------------------------
3 # Copyright (c) 2008 - 2009 Apple Inc. All rights reserved.
4 # All rights reserved. This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 # OS X Application requires 16 byte stack alignment. The problem is these
15 # APIs are exposed to code that does not have this requirement via
16 # EFI_UNIX_THUNK_PROTOCOL. So these are wrapper functions that make sure
17 # the stack is aligned. This code should also work if the stack is already
18 # aligned. Extra stack padding is really the same as local varaibles so
19 # it gets freed by the leave instruction
21 # I basically used the compiler, added extra 16 bytes to the local stack and
22 # made sure %esp ended in 0 before the call (16 byte algined)
26 ##include <sys/stat.h>
28 #int chmod (int fd, mode_t len){
32 #int Gasketchmod (int fd, mode_t len){
33 # return chmod (fd, len);
38 # this gives you the starting point....
41 #------------------------------------------------------------------------------
43 #include <ProcessorBind.h>
49 # EFI_UNIX_THUNK_PROTOCOL that gets exported
53 #------------------------------------------------------------------------------
54 # VOID GasketmsSleep (unsigned long Milliseconds);
55 #------------------------------------------------------------------------------
60 subl $40, %esp # sub extra 0x10 from the stack for the AND
61 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
69 #------------------------------------------------------------------------------
70 # void Gasketexit (int status);
71 #------------------------------------------------------------------------------
76 subl $40, %esp # sub extra 0x10 from the stack for the AND
77 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
85 #------------------------------------------------------------------------------
86 # void GasketSetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
87 #------------------------------------------------------------------------------
88 .globl _GasketSetTimer
92 subl $56, %esp # sub extra 0x10 from the stack for the AND
93 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
110 #------------------------------------------------------------------------------
111 # void GasketGetLocalTime (EFI_TIME *Time);
112 #------------------------------------------------------------------------------
113 .globl _GasketGetLocalTime
117 subl $40, %esp # sub extra 0x10 from the stack for the AND
118 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
127 #------------------------------------------------------------------------------
128 # struct tm *Gasketgmtime (const time_t *clock);
129 #------------------------------------------------------------------------------
134 subl $40, %esp # sub extra 0x10 from the stack for the AND
135 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
145 #------------------------------------------------------------------------------
146 # long GasketGetTimeZone(void);
147 #------------------------------------------------------------------------------
148 .globl _GasketGetTimeZone
152 subl $24, %esp # sub extra 0x10 from the stack for the AND
153 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
159 #------------------------------------------------------------------------------
160 # int GasketGetDayLight (void);
161 #------------------------------------------------------------------------------
162 .globl _GasketGetDayLight
166 subl $24, %esp # sub extra 0x10 from the stack for the AND
167 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
174 #------------------------------------------------------------------------------
175 # int Gasketpoll (struct pollfd *pfd, int nfds, int timeout);
176 #------------------------------------------------------------------------------
181 subl $56, %esp # sub extra 0x10 from the stack for the AND
182 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
195 #------------------------------------------------------------------------------
196 # int Gasketread (int fd, void *buf, int count);
197 #------------------------------------------------------------------------------
202 subl $56, %esp # sub extra 0x10 from the stack for the AND
203 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
215 #------------------------------------------------------------------------------
216 # int Gasketwrite (int fd, const void *buf, int count);
217 #------------------------------------------------------------------------------
222 subl $56, %esp # sub extra 0x10 from the stack for the AND
223 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
236 #------------------------------------------------------------------------------
237 # char *Gasketgetenv (const char *name);
238 #------------------------------------------------------------------------------
243 subl $40, %esp # sub extra 0x10 from the stack for the AND
244 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
253 #------------------------------------------------------------------------------
254 # int Gasketopen (const char *name, int flags, int mode);
255 #------------------------------------------------------------------------------
260 subl $56, %esp # sub extra 0x10 from the stack for the AND
261 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
274 #------------------------------------------------------------------------------
275 # off_t Gasketlseek (int fd, off_t off, int whence);
276 #------------------------------------------------------------------------------
281 subl $56, %esp # sub extra 0x10 from the stack for the AND
282 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
301 #------------------------------------------------------------------------------
302 # int Gasketftruncate (int fd, long int len);
303 #------------------------------------------------------------------------------
304 .globl _Gasketftruncate
308 subl $40, %esp # sub extra 0x10 from the stack for the AND
309 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
320 #------------------------------------------------------------------------------
321 # int Gasketclose (int fd);
322 #------------------------------------------------------------------------------
327 subl $40, %esp # sub extra 0x10 from the stack for the AND
328 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
337 #------------------------------------------------------------------------------
338 # int Gasketmkdir (const char *pathname, mode_t mode);
339 #------------------------------------------------------------------------------
344 subl $40, %esp # sub extra 0x10 from the stack for the AND
345 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
356 #------------------------------------------------------------------------------
357 # int Gasketrmdir (const char *pathname);
358 #------------------------------------------------------------------------------
363 subl $40, %esp # sub extra 0x10 from the stack for the AND
364 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
373 #------------------------------------------------------------------------------
374 # int Gasketunlink (const char *pathname);
375 #------------------------------------------------------------------------------
380 subl $40, %esp # sub extra 0x10 from the stack for the AND
381 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
390 #------------------------------------------------------------------------------
391 # int GasketGetErrno (void);
392 #------------------------------------------------------------------------------
393 .globl _GasketGetErrno
397 subl $24, %esp # sub extra 0x10 from the stack for the AND
398 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
405 #------------------------------------------------------------------------------
406 # DIR *Gasketopendir (const char *pathname);
407 #------------------------------------------------------------------------------
408 .globl _Gasketopendir
412 subl $40, %esp # sub extra 0x10 from the stack for the AND
413 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
422 #------------------------------------------------------------------------------
423 # void *Gasketrewinddir (DIR *dir);
424 #------------------------------------------------------------------------------
425 .globl _Gasketrewinddir
429 subl $40, %esp # sub extra 0x10 from the stack for the AND
430 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
439 #------------------------------------------------------------------------------
440 # struct dirent *Gasketreaddir (DIR *dir);
441 #------------------------------------------------------------------------------
442 .globl _Gasketreaddir
446 subl $40, %esp # sub extra 0x10 from the stack for the AND
447 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
456 #------------------------------------------------------------------------------
457 # int Gasketclosedir (DIR *dir);
458 #------------------------------------------------------------------------------
459 .globl _Gasketclosedir
463 subl $40, %esp # sub extra 0x10 from the stack for the AND
464 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
473 #------------------------------------------------------------------------------
474 # int Gasketstat (const char *path, struct stat *buf);
475 #------------------------------------------------------------------------------
480 subl $40, %esp # sub extra 0x10 from the stack for the AND
481 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
492 #------------------------------------------------------------------------------
493 # int Gasketstatfs (const char *path, struct statfs *buf);
494 #------------------------------------------------------------------------------
499 subl $40, %esp # sub extra 0x10 from the stack for the AND
500 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
512 #------------------------------------------------------------------------------
513 # int Gasketrename (const char *oldpath, const char *newpath);
514 #------------------------------------------------------------------------------
519 subl $40, %esp # sub extra 0x10 from the stack for the AND
520 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
532 #------------------------------------------------------------------------------
533 # time_t Gasketmktime (struct tm *tm);
534 #------------------------------------------------------------------------------
539 subl $40, %esp # sub extra 0x10 from the stack for the AND
540 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
549 #------------------------------------------------------------------------------
550 # int Gasketfsync (int fd);
551 #------------------------------------------------------------------------------
556 subl $40, %esp # sub extra 0x10 from the stack for the AND
557 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
566 #------------------------------------------------------------------------------
567 # int Gasketchmod (const char *path, mode_t mode);
568 #------------------------------------------------------------------------------
573 subl $56, %esp # sub extra 0x10 from the stack for the AND
574 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
577 movzwl -12(%ebp), %eax
585 #------------------------------------------------------------------------------
586 # int Gasketutime (const char *filename, const struct utimbuf *buf);
587 #------------------------------------------------------------------------------
592 subl $40, %esp # sub extra 0x10 from the stack for the AND
593 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
604 #------------------------------------------------------------------------------
605 # int Gaskettcflush (int fildes, int queue_selector);
606 #------------------------------------------------------------------------------
607 .globl _Gaskettcflush
611 subl $40, %esp # sub extra 0x10 from the stack for the AND
612 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
622 #------------------------------------------------------------------------------
623 # EFI_STATUS UgaCreate (struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title);
624 #------------------------------------------------------------------------------
625 .globl _GasketUgaCreate
629 subl $40, %esp #sub extra 0x10 from the stack for the AND
630 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
640 #------------------------------------------------------------------------------
641 # void Gasketperror (__const char *__s);
642 #------------------------------------------------------------------------------
647 subl $40, %esp # sub extra 0x10 from the stack for the AND
648 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
657 #------------------------------------------------------------------------------
658 # int Gasketioctl (int fd, unsigned long int __request, ...);
660 # ... is really int or pointer to structure, so we can treat like an int
662 #------------------------------------------------------------------------------
667 subl $40, %esp # sub extra 0x10 from the stack for the AND
668 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
681 #------------------------------------------------------------------------------
682 # int Gasketfcntl (int __fd, int __cmd, ...);
684 # ... is really int or pointer to structure, so we can treat like an int
686 #------------------------------------------------------------------------------
691 subl $40, %esp # sub extra 0x10 from the stack for the AND
692 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
705 #------------------------------------------------------------------------------
706 # int Gasketcfsetispeed (struct termios *__termios_p, speed_t __speed);
707 #------------------------------------------------------------------------------
708 .globl _Gasketcfsetispeed
712 subl $40, %esp # sub extra 0x10 from the stack for the AND
713 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
724 #------------------------------------------------------------------------------
725 # int Gasketcfsetospeed (struct termios *__termios_p, speed_t __speed);
726 #------------------------------------------------------------------------------
727 .globl _Gasketcfsetospeed
731 subl $40, %esp # sub extra 0x10 from the stack for the AND
732 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
743 #------------------------------------------------------------------------------
744 # int Gaskettcgetattr (int __fd, struct termios *__termios_p);
745 #------------------------------------------------------------------------------
746 .globl _Gaskettcgetattr
750 subl $40, %esp # sub extra 0x10 from the stack for the AND
751 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
762 #------------------------------------------------------------------------------
763 # int Gaskettcsetattr (int __fd, int __optional_actions, __const struct termios *__termios_p);
764 #------------------------------------------------------------------------------
765 .globl _Gaskettcsetattr
769 subl $40, %esp # sub extra 0x10 from the stack for the AND
770 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
781 #------------------------------------------------------------------------------
782 # int Gasketsigaction (int sig, const struct sigaction *act, struct sigaction *oact);
783 #------------------------------------------------------------------------------
784 .globl _Gasketsigaction
788 subl $40, %esp # sub extra 0x10 from the stack for the AND
789 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
801 #------------------------------------------------------------------------------
802 # int Gasketsetcontext (const ucontext_t *ucp);
803 #------------------------------------------------------------------------------
804 .globl _Gasketsetcontext
808 subl $40, %esp # sub extra 0x10 from the stack for the AND
809 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
816 #------------------------------------------------------------------------------
817 # int Gasketgetcontext (ucontext_t *ucp);
818 #------------------------------------------------------------------------------
819 .globl _Gasketgetcontext
823 subl $40, %esp # sub extra 0x10 from the stack for the AND
824 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
831 #------------------------------------------------------------------------------
832 # int Gasketsigemptyset (sigset_t *set);
833 #------------------------------------------------------------------------------
834 .globl _Gasketsigemptyset
838 subl $40, %esp # sub extra 0x10 from the stack for the AND
839 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
847 #------------------------------------------------------------------------------
848 # int Gasketsigaltstack (const stack_t *ss, stack_t *oss);
849 #------------------------------------------------------------------------------
850 .globl _Gasketsigaltstack
854 subl $40, %esp # sub extra 0x10 from the stack for the AND
855 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
866 # UGA Functions that get exported
870 #------------------------------------------------------------------------------
871 # EFI_STATUS GasketUgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo);
872 #------------------------------------------------------------------------------
873 .globl _GasketUgaClose
877 subl $40, %esp # sub extra 0x10 from the stack for the AND
878 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
885 #------------------------------------------------------------------------------
886 # EFI_STATUS GasketUgaSize (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height);
887 #------------------------------------------------------------------------------
888 .globl _GasketUgaSize
893 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
905 #------------------------------------------------------------------------------
906 # EFI_STATUS GasketUgaCheckKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo);
907 #------------------------------------------------------------------------------
908 .globl _GasketUgaCheckKey
912 subl $40, %esp # sub extra 0x10 from the stack for the AND
913 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
920 #------------------------------------------------------------------------------
921 # EFI_STATUS GasketUgaGetKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key);
922 #------------------------------------------------------------------------------
923 .globl _GasketUgaGetKey
927 subl $40, %esp #sub extra 0x10 from the stack for the AND
928 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
938 #------------------------------------------------------------------------------
941 # EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
942 # IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
943 # IN EFI_UGA_BLT_OPERATION BltOperation,
946 # IN UINTN DestinationX,
947 # IN UINTN DestinationY,
950 # IN UINTN Delta OPTIONAL
952 #------------------------------------------------------------------------------
957 subl $88, %esp #sub extra 0x10 from the stack for the AND
958 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call