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 # EFI uses a simplified version of the MSFT calling convention, and every one else,
15 # Mac OS X, BSD, Linux, uses a different one. We can skip dealing with floating point
16 # other than making sure non volatile registers are preserved.
18 # Register for arguments
28 # Callee saved registers
40 ##include <sys/stat.h>
42 #int chmod (int fd, mode_t len){
46 #int Gasketchmod (int fd, mode_t len){
47 # return chmod (fd, len);
50 # gcc -arch x86_64 -S t.c
52 # this gives you the starting point....
55 #------------------------------------------------------------------------------
57 #include <ProcessorBind.h>
63 # EFI_UNIX_THUNK_PROTOCOL that gets exported
67 #------------------------------------------------------------------------------
68 # VOID GasketmsSleep (unsigned long Milliseconds);
69 #------------------------------------------------------------------------------
73 movq %rsp, %rbp # does leave use rbp or rsp???
76 # save registers the OS X will think are volatile
77 movaps %xmm6, -8(%rbp)
78 movaps %xmm7, -24(%rbp)
79 movaps %xmm8, -40(%rbp)
80 movaps %xmm9, -56(%rbp)
81 movaps %xmm10, -72(%rbp)
82 movaps %xmm11, -88(%rbp)
83 movaps %xmm12, -104(%rbp)
84 movaps %xmm13, -120(%rbp)
85 movaps %xmm14, -136(%rbp)
86 movaps %xmm15, -152(%rbp)
93 movaps -8(%rbp), %xmm6,
94 movaps -24(%rbp), %xmm7
95 movaps -40(%rbp), %xmm8
96 movaps -56(%rbp), %xmm9
97 movaps -72(%rbp), %xmm10
98 movaps -88(%rbp), %xmm11
99 movaps -104(%rbp), %xmm12
100 movaps -120(%rbp), %xmm13
101 movaps -136(%rbp), %xmm14
102 movaps -152(%rbp), %xmm15
103 movq -160(%rbp), %rsi
104 movq -168(%rbp), %rdi
110 #------------------------------------------------------------------------------
111 # void Gasketexit (int status);
112 #------------------------------------------------------------------------------
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
126 #------------------------------------------------------------------------------
127 # void GasketSetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
128 #------------------------------------------------------------------------------
129 .globl _GasketSetTimer
133 subl $56, %esp # sub extra 0x10 from the stack for the AND
134 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
151 #------------------------------------------------------------------------------
152 # void GasketGetLocalTime (EFI_TIME *Time);
153 #------------------------------------------------------------------------------
154 .globl _GasketGetLocalTime
158 subl $40, %esp # sub extra 0x10 from the stack for the AND
159 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
168 #------------------------------------------------------------------------------
169 # struct tm *Gasketgmtime (const time_t *clock);
170 #------------------------------------------------------------------------------
175 subl $40, %esp # sub extra 0x10 from the stack for the AND
176 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
186 #------------------------------------------------------------------------------
187 # long GasketGetTimeZone(void);
188 #------------------------------------------------------------------------------
189 .globl _GasketGetTimeZone
193 subl $24, %esp # sub extra 0x10 from the stack for the AND
194 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
200 #------------------------------------------------------------------------------
201 # int GasketGetDayLight (void);
202 #------------------------------------------------------------------------------
203 .globl _GasketGetDayLight
207 subl $24, %esp # sub extra 0x10 from the stack for the AND
208 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
215 #------------------------------------------------------------------------------
216 # int Gasketpoll (struct pollfd *pfd, int nfds, int timeout);
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 # int Gasketread (int fd, void *buf, int count);
238 #------------------------------------------------------------------------------
243 subl $56, %esp # sub extra 0x10 from the stack for the AND
244 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
256 #------------------------------------------------------------------------------
257 # int Gasketwrite (int fd, const void *buf, int count);
258 #------------------------------------------------------------------------------
263 subl $56, %esp # sub extra 0x10 from the stack for the AND
264 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
277 #------------------------------------------------------------------------------
278 # char *Gasketgetenv (const char *name);
279 #------------------------------------------------------------------------------
284 subl $40, %esp # sub extra 0x10 from the stack for the AND
285 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
294 #------------------------------------------------------------------------------
295 # int Gasketopen (const char *name, int flags, int mode);
296 #------------------------------------------------------------------------------
301 subl $56, %esp # sub extra 0x10 from the stack for the AND
302 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
315 #------------------------------------------------------------------------------
316 # off_t Gasketlseek (int fd, off_t off, int whence);
317 #------------------------------------------------------------------------------
322 subl $56, %esp # sub extra 0x10 from the stack for the AND
323 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
342 #------------------------------------------------------------------------------
343 # int Gasketftruncate (int fd, long int len);
344 #------------------------------------------------------------------------------
345 .globl _Gasketftruncate
349 subl $40, %esp # sub extra 0x10 from the stack for the AND
350 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
361 #------------------------------------------------------------------------------
362 # int Gasketclose (int fd);
363 #------------------------------------------------------------------------------
368 subl $40, %esp # sub extra 0x10 from the stack for the AND
369 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
378 #------------------------------------------------------------------------------
379 # int Gasketmkdir (const char *pathname, mode_t mode);
380 #------------------------------------------------------------------------------
385 subl $40, %esp # sub extra 0x10 from the stack for the AND
386 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
397 #------------------------------------------------------------------------------
398 # int Gasketrmdir (const char *pathname);
399 #------------------------------------------------------------------------------
404 subl $40, %esp # sub extra 0x10 from the stack for the AND
405 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
414 #------------------------------------------------------------------------------
415 # int Gasketunlink (const char *pathname);
416 #------------------------------------------------------------------------------
421 subl $40, %esp # sub extra 0x10 from the stack for the AND
422 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
431 #------------------------------------------------------------------------------
432 # int GasketGetErrno (void);
433 #------------------------------------------------------------------------------
434 .globl _GasketGetErrno
438 subl $24, %esp # sub extra 0x10 from the stack for the AND
439 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
446 #------------------------------------------------------------------------------
447 # DIR *Gasketopendir (const char *pathname);
448 #------------------------------------------------------------------------------
449 .globl _Gasketopendir
453 subl $40, %esp # sub extra 0x10 from the stack for the AND
454 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
463 #------------------------------------------------------------------------------
464 # void *Gasketrewinddir (DIR *dir);
465 #------------------------------------------------------------------------------
466 .globl _Gasketrewinddir
470 subl $40, %esp # sub extra 0x10 from the stack for the AND
471 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
480 #------------------------------------------------------------------------------
481 # struct dirent *Gasketreaddir (DIR *dir);
482 #------------------------------------------------------------------------------
483 .globl _Gasketreaddir
487 subl $40, %esp # sub extra 0x10 from the stack for the AND
488 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
497 #------------------------------------------------------------------------------
498 # int Gasketclosedir (DIR *dir);
499 #------------------------------------------------------------------------------
500 .globl _Gasketclosedir
504 subl $40, %esp # sub extra 0x10 from the stack for the AND
505 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
514 #------------------------------------------------------------------------------
515 # int Gasketstat (const char *path, struct stat *buf);
516 #------------------------------------------------------------------------------
521 subl $40, %esp # sub extra 0x10 from the stack for the AND
522 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
533 #------------------------------------------------------------------------------
534 # int Gasketstatfs (const char *path, struct statfs *buf);
535 #------------------------------------------------------------------------------
540 subl $40, %esp # sub extra 0x10 from the stack for the AND
541 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
553 #------------------------------------------------------------------------------
554 # int Gasketrename (const char *oldpath, const char *newpath);
555 #------------------------------------------------------------------------------
560 subl $40, %esp # sub extra 0x10 from the stack for the AND
561 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
573 #------------------------------------------------------------------------------
574 # time_t Gasketmktime (struct tm *tm);
575 #------------------------------------------------------------------------------
580 subl $40, %esp # sub extra 0x10 from the stack for the AND
581 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
590 #------------------------------------------------------------------------------
591 # int Gasketfsync (int fd);
592 #------------------------------------------------------------------------------
597 subl $40, %esp # sub extra 0x10 from the stack for the AND
598 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
607 #------------------------------------------------------------------------------
608 # int Gasketchmod (const char *path, mode_t mode);
609 #------------------------------------------------------------------------------
614 subl $56, %esp # sub extra 0x10 from the stack for the AND
615 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
618 movzwl -12(%ebp), %eax
626 #------------------------------------------------------------------------------
627 # int Gasketutime (const char *filename, const struct utimbuf *buf);
628 #------------------------------------------------------------------------------
633 subl $40, %esp # sub extra 0x10 from the stack for the AND
634 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
645 #------------------------------------------------------------------------------
646 # int Gaskettcflush (int fildes, int queue_selector);
647 #------------------------------------------------------------------------------
648 .globl _Gaskettcflush
652 subl $40, %esp # sub extra 0x10 from the stack for the AND
653 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
663 #------------------------------------------------------------------------------
664 # EFI_STATUS UgaCreate (struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title);
665 #------------------------------------------------------------------------------
666 .globl _GasketUgaCreate
670 subl $40, %esp #sub extra 0x10 from the stack for the AND
671 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
681 #------------------------------------------------------------------------------
682 # void Gasketperror (__const char *__s);
683 #------------------------------------------------------------------------------
688 subl $40, %esp # sub extra 0x10 from the stack for the AND
689 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
698 #------------------------------------------------------------------------------
699 # int Gasketioctl (int fd, unsigned long int __request, ...);
701 # ... is really int or pointer to structure, so we can treat like an int
703 #------------------------------------------------------------------------------
708 subl $40, %esp # sub extra 0x10 from the stack for the AND
709 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
722 #------------------------------------------------------------------------------
723 # int Gasketfcntl (int __fd, int __cmd, ...);
725 # ... is really int or pointer to structure, so we can treat like an int
727 #------------------------------------------------------------------------------
732 subl $40, %esp # sub extra 0x10 from the stack for the AND
733 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
746 #------------------------------------------------------------------------------
747 # int Gasketcfsetispeed (struct termios *__termios_p, speed_t __speed);
748 #------------------------------------------------------------------------------
749 .globl _Gasketcfsetispeed
753 subl $40, %esp # sub extra 0x10 from the stack for the AND
754 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
765 #------------------------------------------------------------------------------
766 # int Gasketcfsetospeed (struct termios *__termios_p, speed_t __speed);
767 #------------------------------------------------------------------------------
768 .globl _Gasketcfsetospeed
772 subl $40, %esp # sub extra 0x10 from the stack for the AND
773 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
784 #------------------------------------------------------------------------------
785 # int Gaskettcgetattr (int __fd, struct termios *__termios_p);
786 #------------------------------------------------------------------------------
787 .globl _Gaskettcgetattr
791 subl $40, %esp # sub extra 0x10 from the stack for the AND
792 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
803 #------------------------------------------------------------------------------
804 # int Gaskettcsetattr (int __fd, int __optional_actions, __const struct termios *__termios_p);
805 #------------------------------------------------------------------------------
806 .globl _Gaskettcsetattr
810 subl $40, %esp # sub extra 0x10 from the stack for the AND
811 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
822 #------------------------------------------------------------------------------
823 # int Gasketsigaction (int sig, const struct sigaction *act, struct sigaction *oact);
824 #------------------------------------------------------------------------------
825 .globl _Gasketsigaction
829 subl $40, %esp # sub extra 0x10 from the stack for the AND
830 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
842 #------------------------------------------------------------------------------
843 # int Gasketsetcontext (const ucontext_t *ucp);
844 #------------------------------------------------------------------------------
845 .globl _Gasketsetcontext
849 subl $40, %esp # sub extra 0x10 from the stack for the AND
850 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
857 #------------------------------------------------------------------------------
858 # int Gasketgetcontext (ucontext_t *ucp);
859 #------------------------------------------------------------------------------
860 .globl _Gasketgetcontext
864 subl $40, %esp # sub extra 0x10 from the stack for the AND
865 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
872 #------------------------------------------------------------------------------
873 # int Gasketsigemptyset (sigset_t *set);
874 #------------------------------------------------------------------------------
875 .globl _Gasketsigemptyset
879 subl $40, %esp # sub extra 0x10 from the stack for the AND
880 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
888 #------------------------------------------------------------------------------
889 # int Gasketsigaltstack (const stack_t *ss, stack_t *oss);
890 #------------------------------------------------------------------------------
891 .globl _Gasketsigaltstack
895 subl $40, %esp # sub extra 0x10 from the stack for the AND
896 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
907 # UGA Functions that get exported
911 #------------------------------------------------------------------------------
912 # EFI_STATUS GasketUgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo);
913 #------------------------------------------------------------------------------
914 .globl _GasketUgaClose
918 subl $40, %esp # sub extra 0x10 from the stack for the AND
919 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
926 #------------------------------------------------------------------------------
927 # EFI_STATUS GasketUgaSize (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height);
928 #------------------------------------------------------------------------------
929 .globl _GasketUgaSize
934 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
946 #------------------------------------------------------------------------------
947 # EFI_STATUS GasketUgaCheckKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo);
948 #------------------------------------------------------------------------------
949 .globl _GasketUgaCheckKey
953 subl $40, %esp # sub extra 0x10 from the stack for the AND
954 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
961 #------------------------------------------------------------------------------
962 # EFI_STATUS GasketUgaGetKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key);
963 #------------------------------------------------------------------------------
964 .globl _GasketUgaGetKey
968 subl $40, %esp #sub extra 0x10 from the stack for the AND
969 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
979 #------------------------------------------------------------------------------
982 # EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
983 # IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
984 # IN EFI_UGA_BLT_OPERATION BltOperation,
987 # IN UINTN DestinationX,
988 # IN UINTN DestinationY,
991 # IN UINTN Delta OPTIONAL
993 #------------------------------------------------------------------------------
998 subl $88, %esp #sub extra 0x10 from the stack for the AND
999 and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call