Subversion Repositories Kolibri OS

Rev

Rev 9227 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2020. All rights reserved.      ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;; Version 2, or (at your option) any later version.            ;;
  6. ;;                                                              ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;                                                              ;;
  9. ;; Based on UEFI library for fasm by bzt, Public Domain.        ;;
  10. ;;                                                              ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. DN fix dq       ; native
  14.  
  15. include "uefi.inc"
  16.  
  17. EFIERR = 0x8000000000000000
  18.  
  19. struct EFI_SYSTEM_TABLE
  20.   Hdr                   EFI_TABLE_HEADER
  21.   FirmwareVendor        dq ?
  22.   FirmwareRevision      dd ?
  23.                         dd ?
  24.   ConsoleInHandle       dq ?
  25.   ConIn                 dq ?
  26.   ConsoleOutHandle      dq ?
  27.   ConOut                dq ?
  28.   StandardErrorHandle   dq ?
  29.   StdErr                dq ?
  30.   RuntimeServices       dq ?
  31.   BootServices          dq ?
  32.   NumberOfTableEntries  dq ?
  33.   ConfigurationTable    dq ?
  34. ends
  35.  
  36. struct EFI_LOADED_IMAGE_PROTOCOL
  37.   Revision              dd ?
  38.                         dd ?
  39.   ParentHandle          dq ?
  40.   SystemTable           dq ?
  41.   DeviceHandle          dq ?
  42.   FilePath              dq ?
  43.   Reserved              dq ?
  44.   LoadOptionsSize       dd ?
  45.                         dd ?
  46.   ImageBase             dq ?
  47.   ImageSize             dq ?
  48.   ImageCodeType         dd ?
  49.   ImageDataType         dd ?
  50.   UnLoad                dq ?
  51. ends
  52.  
  53. macro eficall interface,function,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11
  54. {
  55. numarg = 0
  56.  
  57. if ~ arg11 eq
  58.   numarg = numarg + 1
  59.   if ~ arg11 eq rdi
  60.         mov     rdi, arg11
  61.   end if
  62. end if
  63.  
  64. if ~ arg10 eq
  65.   numarg = numarg + 1
  66.   if ~ arg10 eq rsi
  67.         mov     rsi, arg10
  68.   end if
  69. end if
  70.  
  71. if ~ arg9 eq
  72.   numarg = numarg + 1
  73.   if ~ arg9 eq r14
  74.         mov     r14, arg9
  75.   end if
  76. end if
  77.  
  78. if ~ arg8 eq
  79.   numarg = numarg + 1
  80.   if ~ arg8 eq r13
  81.         mov     r13, arg8
  82.   end if
  83. end if
  84.  
  85. if ~ arg7 eq
  86.   numarg = numarg + 1
  87.   if ~ arg7 eq r12
  88.         mov     r12, arg7
  89.   end if
  90. end if
  91.  
  92. if ~ arg6 eq
  93.   numarg = numarg + 1
  94.   if ~ arg6 eq r11
  95.         mov     r11, arg6
  96.   end if
  97. end if
  98.  
  99. if ~ arg5 eq
  100.   numarg = numarg + 1
  101.   if ~ arg5 eq r10
  102.         mov     r10, arg5
  103.   end if
  104. end if
  105.  
  106. if ~ arg4 eq
  107.   numarg = numarg + 1
  108.   if ~ arg4 eq r9
  109.         mov     r9, arg4
  110.   end if
  111. end if
  112.  
  113. if ~ arg3 eq
  114.   numarg = numarg + 1
  115.   if ~ arg3 eq r8
  116.         mov     r8, arg3
  117.   end if
  118. end if
  119.  
  120. if ~ arg2 eq
  121.   numarg = numarg + 1
  122.   if ~ arg2 eq rdx
  123.         mov     rdx, arg2
  124.   end if
  125. end if
  126.  
  127. if ~ arg1 eq
  128.   numarg = numarg + 1
  129.   if ~ arg1 eq rcx
  130.         mov     rcx, arg1
  131.   end if
  132. end if
  133.  
  134.         xor     eax, eax
  135.         mov     al, numarg
  136.  
  137. if ~ interface eq rbx
  138.         mov     rbx, interface
  139. end if
  140.  
  141.         mov     rbx, [rbx + function]
  142.         call    uefifunc
  143. }
  144.  
  145. section '.text' code executable readable
  146.  
  147. uefifunc:
  148.         ;save stack pointer
  149.         mov     [uefi_rsptmp], rsp
  150.         ;set up new aligned stack
  151.         and     esp, 0xFFFFFFF0
  152.         ;alignment check on arguments
  153.         bt      eax, 0
  154.         jnc     @f
  155.         push    rax
  156.         ;arguments
  157. @@:
  158.         cmp     al, 11
  159.         jb      @f
  160.         push    rdi
  161. @@:
  162.         cmp     al, 10
  163.         jb      @f
  164.         push    rsi
  165. @@:
  166.         cmp     al, 9
  167.         jb      @f
  168.         push    r14
  169. @@:
  170.         cmp     al, 8
  171.         jb      @f
  172.         push    r13
  173. @@:
  174.         cmp     al, 7
  175.         jb      @f
  176.         push    r12
  177. @@:
  178.         cmp     al, 6
  179.         jb      @f
  180.         push    r11
  181. @@:
  182.         cmp     al, 5
  183.         jb      @f
  184.         push    r10
  185. @@:
  186.         ;space for
  187.         ;r9
  188.         ;r8
  189.         ;rdx
  190.         ;rcx
  191.         sub     rsp, 4*8
  192.         ;call function
  193.         call    rbx
  194.         ;restore old stack
  195.         mov     rsp, [uefi_rsptmp]
  196.         ret
  197.