Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9227 → Rev 9226

/kernel/trunk/bootloader/uefi4kos/proc64.inc
File deleted
Property changes:
Deleted: svn:eol-style
-native
\ No newline at end of property
/kernel/trunk/bootloader/uefi4kos/uefi64kos.asm
1,11 → 1,9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
;; Written by Ivan Baravy ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
format pe64 efi
15,9 → 13,6
 
include '../../struct.inc'
include '../../macros.inc'
include '../../kglobals.inc'
fastcall fix fstcall
include 'proc64.inc'
include '../../const.inc'
 
purge DQ
24,7 → 19,8
include 'uefi64.inc'
 
MEMORY_MAP_SIZE = 0x10000
PROTOCOL_HANDLERS_BUFFER_SIZE = 0x100
GOP_BUFFER_SIZE = 0x100
LIP_BUFFER_SIZE = 0x100
FILE_BUFFER_SIZE = 0x1000
 
KERNEL_TRAMPOLINE = 0x8f80 ; just before BOOT_LO
52,10 → 48,8
.size dq ?
.fatal dq ?
end virtual
mov r10, [.root]
mov r11, [.name]
fstcall [r10+EFI_FILE_PROTOCOL.Open], r10, file_handle, \
r11, EFI_FILE_MODE_READ, 0
eficall [.root], EFI_FILE_PROTOCOL.Open, [.root], file_handle, \
[.name], EFI_FILE_MODE_READ, 0
test eax, eax
jz @f
xor eax, eax
63,21 → 57,19
jnz .done
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_open_file
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
mov r10, [.name]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, r10
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
[.name]
jmp $
@@:
 
lea rdx, [.size]
mov r8, [.buffer]
mov r10, [file_handle]
fstcall [r10+EFI_FILE_PROTOCOL.Read], [file_handle], rdx, r8
mov r10, [file_handle]
fstcall [r10+EFI_FILE_PROTOCOL.Close], [file_handle]
lea rax, [.size]
eficall [file_handle], EFI_FILE_PROTOCOL.Read, [file_handle], rax, \
[.buffer]
eficall [file_handle], EFI_FILE_PROTOCOL.Close, [file_handle]
mov rax, [.size]
.done:
push rax
87,13 → 79,13
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_file_size
pop rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
pop rbx
pop rax
ret 8*5
287,7 → 279,7
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_parsing_config
pop rbx
mov rsi, KERNEL_BASE
300,7 → 292,7
read_options_from_config:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], [efi_handle], lip_guid, \
eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [efi_handle], lipuuid, \
lip_interface
test eax, eax
jz @f
307,16 → 299,17
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_efi_lip_handle
pop rbx
jmp $
@@:
mov r10, [lip_interface]
mov rax, [lip_interface]
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], \
[r10+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfsp_guid, \
eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, \
[rax+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfspguid, \
sfsp_interface
test eax, eax
jz @f
323,13 → 316,12
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_lip_dev_sfsp
pop rbx
jmp $
@@:
mov r10, [sfsp_interface]
fstcall [r10+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume], \
eficall [sfsp_interface], EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume, \
[sfsp_interface], esp_root
test eax, eax
jz @f
336,7 → 328,7
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_sfsp_openvolume
pop rbx
jmp $
379,7 → 371,7
call num2dec
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
pop rdi rsi rdx rcx rbx rax
ret
 
387,10 → 379,9
mov [cfg_opt_used_resolution], 1
mov [cfg_opt_value_vmode], 0
.next_mode:
movzx edx, [cfg_opt_value_vmode]
mov r10, [gop_interface]
fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
rdx, gop_info_size, gop_info
movzx eax, [cfg_opt_value_vmode]
eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode, \
[gop_interface], rax, gop_info_size, gop_info
cmp rax, EFI_SUCCESS
jnz .error
mov rcx, [gop_info]
418,11 → 409,11
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_no_such_vmode
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error
jmp $
.error:
431,6 → 422,11
 
ask_for_params:
ret
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [rax], gopuuid, \
msg_ask_for_params
jmp $
 
xor ebx, ebx
.next_mode:
440,9 → 436,8
call num2dec
 
push rbx
mov r10, [gop_interface]
fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
rbx, gop_info_size, gop_info
eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode, \
[gop_interface], rbx, gop_info_size, gop_info
cmp rax, EFI_SUCCESS
jnz .error
mov rcx, [gop_info]
461,7 → 456,7
.skip:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
cmp rax, EFI_SUCCESS
jnz .error
 
475,7 → 470,7
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
fstcall [rbx+SIMPLE_INPUT_INTERFACE.Reset], rbx, 1
eficall rbx, SIMPLE_INPUT_INTERFACE.Reset, rbx, 1
cmp rax, EFI_SUCCESS
jnz .error
xor ecx, ecx
483,7 → 478,7
push rcx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
fstcall [rbx+SIMPLE_INPUT_INTERFACE.ReadKeyStroke], rbx, msg
eficall rbx, SIMPLE_INPUT_INTERFACE.ReadKeyStroke, rbx, msg
pop rcx
mov rdx, EFI_DEVICE_ERROR
cmp rax, rdx
506,57 → 501,13
.done:
ret
 
detect_pci_config:
fstcall get_protocol_interface, pcirbiop_guid
mov [pcirbiop_interface], rax
mov r10, rax
fstcall [r10+EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Configuration], r10, \
pcirbiop_resources
; fstcall dump_pci_resources
fstcall get_last_pci_bus
call clearbuf
movzx eax, [pci_last_bus]
mov rdi, msg
call num2hex
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_pci_last_bus
pop rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
pop rbx
ret
 
proc get_last_pci_bus
mov rsi, [pcirbiop_resources]
.next_resource:
cmp [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type], \
EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
jz .not_found
mov rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
cmp [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType], \
EFI_RESOURCE_TYPE.BUS
jz .found
movzx eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
lea rsi, [rsi+rax+3]
jmp .next_resource
.found:
mov [pci_last_bus], al
.not_found:
ret
endp
 
proc main _efi_handle, _efi_table
main:
mov [efi_handle], rcx
mov [efi_table], rdx
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset], rbx, 1
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset, rbx, 1
test eax, eax
jz @f
jmp $ ; what can I do here?
563,19 → 514,12
@@:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_u4k_loaded
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_detect_pci_config
 
call detect_pci_config
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_read_options
call read_options_from_config
 
582,7 → 526,7
; read kernel file
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_load_kernel
push 1 ; fatal
push MAX_FILE_SIZE
596,7 → 540,7
; read ramdisk image
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_load_ramdisk
push 1 ; fatal
push MAX_FILE_SIZE
610,11 → 554,11
; alloc buffer for devices.dat
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_alloc_devicesdat
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.AllocatePages], \
eficall rbx, EFI_BOOT_SERVICES.AllocatePages, \
EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
devicesdat_data
cmp eax, EFI_SUCCESS
623,7 → 567,7
; read devices.dat
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_load_devicesdat
 
push 0 ; not fatal
638,17 → 582,104
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_locate_gop_interface
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_locate_gop_handlers
 
fstcall get_protocol_interface, gop_guid
mov [gop_interface], rax
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.LocateHandle, \
EFI_LOCATE_SEARCH_TYPE.ByProtocol, gopuuid, 0, \
gop_buffer_size, gop_buffer
mov [status], rax
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_gop_buffer_size
call clearbuf
mov rax, [gop_buffer_size]
mov rdi, msg
call num2hex
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
 
mov rax, [status]
test eax, eax
jz @f
call clearbuf
mov rdi, msg
call num2hex
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
jmp $
@@:
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_look_for_gop_handler
 
mov rbx, gop_buffer
.next_gop_handle:
mov rax, rbx
mov rcx, gop_buffer
sub rax, rcx
cmp rax, [gop_buffer_size]
jb @f
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_out_of_handlers
pop rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg_error
pop rbx
jmp $
@@:
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_query_handler
pop rbx
 
mov rax, rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [rax], gopuuid, \
gop_interface
pop rbx
;mov rax, 0x8000_0000_0000_0003
test eax, eax
jz @f
call clearbuf
mov rdi, msg
call num2hex
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
pop rbx
 
add rbx, 8
jmp .next_gop_handle
@@:
 
call find_rsdp
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_acpi_tables_done
 
cmp [cfg_opt_used_resolution], 0
655,7 → 686,7
jz .not_used_resolution
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_opt_resolution
call clearbuf
xor edx, edx
668,7 → 699,7
call num2dec
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
call find_vmode_index_by_resolution
.not_used_resolution:
cmp [cfg_opt_used_debug_print], 0
683,9 → 714,9
call ask_for_params
@@:
 
movzx edx, [cfg_opt_value_vmode]
mov r10, [gop_interface]
fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode], [gop_interface], rdx
movzx ecx, [cfg_opt_value_vmode]
eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode, \
[gop_interface], rcx
test eax, eax
jz @f
call clearbuf
693,10 → 724,10
call num2hex
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error
jmp $
@@:
707,9 → 738,8
mov [fb_base], rdi
 
mov ebx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
mov rax, [gop_interface]
fstcall [rax+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
rbx, gop_info_size, gop_info
eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode, \
[gop_interface], rbx, gop_info_size, gop_info
test eax, eax
jz @f
jmp .error
724,26 → 754,26
shl eax, 2
mov [rdx+BOOT_LO.pitch], ax
 
mov [rdx+BOOT_LO.pci_data.access_mechanism], 1
movzx eax, [pci_last_bus]
mov [rdx+BOOT_LO.pci_data.last_bus], al
mov [rdx+BOOT_LO.pci_data.version], 0x0300 ; PCI 3.0
mov [rdx+BOOT_LO.pci_data.pm_entry], 0
mov byte[rdx+BOOT_LO.pci_data+0], 1 ; PCI access mechanism
mov byte[rdx+BOOT_LO.pci_data+1], 8 ; last bus, don't know how to count them
mov byte[rdx+BOOT_LO.pci_data+2], 0x10 ; PCI version
mov byte[rdx+BOOT_LO.pci_data+3], 0x02
mov dword[rdx+BOOT_LO.pci_data+4], 0xe3
 
; kernel
; fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
; eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
; 450000/0x1000, EFI_ALLOCATE_ADDRESS
 
; ramdisk
; fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
; eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
; 2880*512/0x1000, EFI_ALLOCATE_ADDRESS
 
call calc_memmap
; fstcall dump_memmap
; call dump_memmap
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.ExitBootServices], [efi_handle], \
eficall rbx, EFI_BOOT_SERVICES.ExitBootServices, [efi_handle], \
[memory_map_key]
call halt_on_error
 
813,11 → 843,11
.error:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error
jmp $
endp
 
 
halt_on_error:
test eax, eax
jz @f
826,118 → 856,20
call num2hex
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
jmp $
@@:
ret
 
proc get_protocol_interface uses rbx, _guid
mov [_guid], rcx
mov [prot_handlers_buffer_size], PROTOCOL_HANDLERS_BUFFER_SIZE
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.LocateHandle], \
EFI_LOCATE_SEARCH_TYPE.ByProtocol, [_guid], 0, \
prot_handlers_buffer_size, prot_handlers_buffer
mov [status], rax
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_protocol_buffer_size
call clearbuf
mov rax, [prot_handlers_buffer_size]
mov rdi, msg
call num2hex
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
 
mov rax, [status]
test eax, eax
jz @f
call clearbuf
mov rdi, msg
call num2hex
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_error
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
jmp $
@@:
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_look_for_handler
 
mov rbx, prot_handlers_buffer
.try_next_handle:
mov rax, rbx
mov rcx, prot_handlers_buffer
sub rax, rcx
cmp rax, [prot_handlers_buffer_size]
jb @f
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_error_out_of_handlers
pop rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_error
pop rbx
jmp $
@@:
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_query_handler
pop rbx
 
mov r10, rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], qword[r10], [_guid], \
prot_interface
pop rbx
;mov rax, 0x8000_0000_0000_0003
test eax, eax
jz @f
call clearbuf
mov rdi, msg
call num2hex
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
pop rbx
 
add rbx, 8
jmp .try_next_handle
@@:
mov rax, [prot_interface]
ret
endp
 
 
find_rsdp:
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_look_for_rsdp
pop rbx
 
963,66 → 895,16
.all_tables_done:
ret
 
proc dump_pci_resources
xor eax, eax
mov rsi, [pcirbiop_resources]
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
msg_dump_pci_resources
pop rbx
.next_resource:
call clearbuf
movzx eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type]
cmp eax, EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
jz .done
mov rdi, msg
call num2hex
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
pop rbx
call clearbuf
movzx eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType]
mov rdi, msg
call num2dec
mov rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMinimum]
mov rdi, msg+2*2
call num2hex
mov rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
mov rdi, msg+19*2
call num2hex
mov rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.TranslationOffset]
mov rdi, msg+36*2
call num2hex
mov rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.AddressLength]
mov rdi, msg+53*2
call num2hex
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
pop rbx
movzx eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
add eax, 3
add rsi, rax
jmp .next_resource
.done:
ret
endp
 
calc_memmap:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
eficall rbx, EFI_BOOT_SERVICES.AllocatePages, EFI_ALLOCATE_ANY_PAGES, \
EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
call halt_on_error
 
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
fstcall [rbx+EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
eficall rbx, EFI_BOOT_SERVICES.GetMemoryMap, memory_map_size, \
[memory_map], memory_map_key, descriptor_size, descriptor_ver
call halt_on_error
 
1038,7 → 920,7
jb .next_descr
ret
 
proc dump_memmap
dump_memmap:
xor eax, eax
mov rsi, BOOT_LO.memmap_blocks
mov ebx, [rax+BOOT_LO.memmap_block_cnt]
1050,13 → 932,13
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_memmap
pop rbx
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
pop rbx
call clearbuf
.next_mapping:
1079,14 → 961,14
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
pop rbx
add rsi, sizeof.e820entry
jmp .next_mapping
.done:
ret
endp
 
 
; linux/arch/x86/platform/efi/efi.c
; do_add_efi_memmap
add_uefi_memmap:
1226,10 → 1108,9
kernel_trampoline.size = $ - KERNEL_TRAMPOLINE
 
section '.rodata' data readable
gop_guid db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
lip_guid db EFI_LOADED_IMAGE_PROTOCOL_GUID
sfsp_guid db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
pcirbiop_guid db EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID
gopuuid db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
lipuuid db EFI_LOADED_IMAGE_PROTOCOL_GUID
sfspguid db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
 
file_name du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
kernel_name du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
1276,9 → 1157,6
cfg_opt_cmnt_syspath db "# Path to /sys directory",0
 
msg_u4k_loaded du "uefi64kos loaded",13,10,0
msg_detect_pci_config du "Detect PCI configuration",13,10,0
msg_dump_pci_resources du "Dump PCI resources",13,10,0
msg_pci_last_bus du "Last PCI bus",13,10,0
msg_read_options du "Read options from config file",13,10,0
msg_file_size du "File size:",13,10,0
msg_parsing_config du "Parsing config file",13,10,0
1286,8 → 1164,8
msg_load_ramdisk du "Load ramdisk",13,10,0
msg_load_devicesdat du "Load DEVICES.DAT",13,10,0
msg_alloc_devicesdat du "Allocate memory for DEVICES.DAT",13,10,0
msg_locate_gop_interface du "Locate GOP interface",13,10,0
msg_look_for_handler du "Look for protocol handler",13,10,0
msg_locate_gop_handlers du "Locate GOP handlers",13,10,0
msg_look_for_gop_handler du "Look for GOP handler",13,10,0
msg_query_handler du "Query handler",13,10,0
msg_query_vmode du "Query vmode",13,10,0
msg_vmode_found du "Video mode found",13,10,0
1297,7 → 1175,7
msg_ask_for_params du "Ask for params",13,10,0
msg_set_graphic_mode du "Set graphic mode",13,10,0
msg_success du "Success!",13,10,0
msg_protocol_buffer_size du "Protocol buffer size",13,10,0
msg_gop_buffer_size du "GOP buffer size",13,10,0
msg_opt_resolution du "Option resolution: ",0
msg_memmap du "Memmap",13,10,0
msg_error du "Error!",13,10,0
1310,19 → 1188,22
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
msg du 79 dup " ",13,10,0
 
 
section '.data' data readable writeable
efi_handle dq 0
efi_table dq 0
;uefi_rsptmp dq 0
uefi_rsptmp dq 0
 
fb_base dq 0
 
prot_handlers_buffer_size dq ?
prot_interface dq ?
gop_buffer_size dq GOP_BUFFER_SIZE
gop_handle dq 0
gop_interface dq 0
gop_info_size dq 0
gop_info dq 0
 
lip_buffer_size dq LIP_BUFFER_SIZE
lip_handle dq 0
lip_interface dq 0
 
sfsp_interface dq 0
1331,10 → 1212,6
file_handle dq ?
file_buffer_size dq FILE_BUFFER_SIZE-1 ; leave the last byte for \0
 
pcirbiop_interface dq ?
pcirbiop_resources dq ?
pci_last_bus db 254
 
cfg_opt_used_resolution db 0
cfg_opt_used_acpi db 0
cfg_opt_used_debug_print db 0
1364,9 → 1241,7
efi_fs_info EFI_FILE_SYSTEM_INFO
 
memory_map dq ?
prot_handlers_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
;gop_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
pcirbio_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
gop_buffer rq GOP_BUFFER_SIZE/8
devicesdat_data dq 0xffffffff
devicesdat_size dq 0x1000
status dq ?
/kernel/trunk/bootloader/uefi4kos/uefi32kos.asm
1,11 → 1,9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
;; Written by Ivan Baravy ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
format pe efi
562,11 → 560,11
shl eax, 2
mov [edx+BOOT_LO.pitch], ax
 
mov [edx+BOOT_LO.pci_data.access_mechanism], 1
movzx eax, [pci_last_bus]
mov [edx+BOOT_LO.pci_data.last_bus], al
mov [edx+BOOT_LO.pci_data.version], 0x0300 ; PCI 3.0
mov [edx+BOOT_LO.pci_data.pm_entry], 0
mov byte[edx+BOOT_LO.pci_data+0], 1 ; PCI access mechanism
mov byte[edx+BOOT_LO.pci_data+1], 8 ; last bus, don't know how to count them
mov byte[edx+BOOT_LO.pci_data+2], 0x10 ; PCI version
mov byte[edx+BOOT_LO.pci_data+3], 0x02
mov dword[edx+BOOT_LO.pci_data+4], 0xe3
 
; kernel
; eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
862,7 → 860,6
gopuuid db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
lipuuid db EFI_LOADED_IMAGE_PROTOCOL_GUID
sfspguid db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
pcirbguid db EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID
 
file_name du "\EFI\KOLIBRIOS\KOLIBRI.INI",0
kernel_name du "\EFI\KOLIBRIOS\KOLIBRI.KRN",0
952,8 → 949,6
 
sfsp_interface dd 0
 
pci_last_bus db 254
 
esp_root dd ?
file_handle dd ?
file_buffer_size dd FILE_BUFFER_SIZE-1 ; leave the last byte for \0
/kernel/trunk/bootloader/uefi4kos/uefi.inc
1,11 → 1,9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
;; Written by Ivan Baravy ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Based on UEFI library for fasm by bzt, Public Domain. ;;
98,11 → 96,6
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID equ 0xde,0xa9,0x42,0x90,0xdc,0x23,0x38,0x4a, \
0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a
 
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID equ 0xBB, 0x7E, 0x70, 0x2F, \
0x1A, 0x4A, 0xd4, 0x11, \
0x9A, 0x38, 0x00, 0x90, \
0x27, 0x3F, 0xC1, 0x4D
 
EFI_FILE_MODE_READ = 1
EFI_FILE_MODE_WRITE = 2
EFI_FILE_MODE_CREATE = 0x8000000000000000
277,47 → 270,3
PixelInformation EFI_PIXEL_BITMASK
PixelsPerScanLine dd ?
ends
 
struct PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS
Read DN ?
Write DN ?
ends
 
struct EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
ParentHandle DN ? ; EFI_HANDLE
PollMem DN ?
PollIo DN ?
Mem PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS
Io PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS
Pci PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS
CopyMem DN ?
Map DN ?
Unmap DN ?
AllocateBuffer DN ?
FreeBuffer DN ?
Flush DN ?
GetAttributes DN ?
SetAttributes DN ?
Configuration DN ?
SegmentNumber dd ?
ends
 
struct EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR ; described in acpi spec
Type db ?
Length dw ?
ResourceType db ?
GeneralFlags db ?
SpecificFlags db ?
Granularity dq ?
RangeMinimum dq ?
RangeMaximum dq ?
TranslationOffset dq ?
AddressLength dq ?
ends
 
EFI_RESOURCE_DESCRIPTOR_TYPE.QWORD_ADDRESS_SPACE = 0x8a
EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG = 0x79
 
EFI_RESOURCE_TYPE.MEMORY = 0
EFI_RESOURCE_TYPE.IO = 1
EFI_RESOURCE_TYPE.BUS = 2
/kernel/trunk/bootloader/uefi4kos/uefi32.inc
1,11 → 1,9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
;; Written by Ivan Baravy ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Based on UEFI library for fasm by bzt, Public Domain. ;;
53,3 → 51,8
ImageDataType dd ?
UnLoad dd ?
ends
 
section '.text' code executable readable
 
uefifunc:
ret
/kernel/trunk/bootloader/uefi4kos/uefi64.inc
1,11 → 1,9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
;; Written by Ivan Baravy ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Based on UEFI library for fasm by bzt, Public Domain. ;;
51,3 → 49,148
ImageDataType dd ?
UnLoad dq ?
ends
 
macro eficall interface,function,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11
{
numarg = 0
 
if ~ arg11 eq
numarg = numarg + 1
if ~ arg11 eq rdi
mov rdi, arg11
end if
end if
 
if ~ arg10 eq
numarg = numarg + 1
if ~ arg10 eq rsi
mov rsi, arg10
end if
end if
 
if ~ arg9 eq
numarg = numarg + 1
if ~ arg9 eq r14
mov r14, arg9
end if
end if
 
if ~ arg8 eq
numarg = numarg + 1
if ~ arg8 eq r13
mov r13, arg8
end if
end if
 
if ~ arg7 eq
numarg = numarg + 1
if ~ arg7 eq r12
mov r12, arg7
end if
end if
 
if ~ arg6 eq
numarg = numarg + 1
if ~ arg6 eq r11
mov r11, arg6
end if
end if
 
if ~ arg5 eq
numarg = numarg + 1
if ~ arg5 eq r10
mov r10, arg5
end if
end if
 
if ~ arg4 eq
numarg = numarg + 1
if ~ arg4 eq r9
mov r9, arg4
end if
end if
 
if ~ arg3 eq
numarg = numarg + 1
if ~ arg3 eq r8
mov r8, arg3
end if
end if
 
if ~ arg2 eq
numarg = numarg + 1
if ~ arg2 eq rdx
mov rdx, arg2
end if
end if
 
if ~ arg1 eq
numarg = numarg + 1
if ~ arg1 eq rcx
mov rcx, arg1
end if
end if
 
xor eax, eax
mov al, numarg
 
if ~ interface eq rbx
mov rbx, interface
end if
 
mov rbx, [rbx + function]
call uefifunc
}
 
section '.text' code executable readable
 
uefifunc:
;save stack pointer
mov [uefi_rsptmp], rsp
;set up new aligned stack
and esp, 0xFFFFFFF0
;alignment check on arguments
bt eax, 0
jnc @f
push rax
;arguments
@@:
cmp al, 11
jb @f
push rdi
@@:
cmp al, 10
jb @f
push rsi
@@:
cmp al, 9
jb @f
push r14
@@:
cmp al, 8
jb @f
push r13
@@:
cmp al, 7
jb @f
push r12
@@:
cmp al, 6
jb @f
push r11
@@:
cmp al, 5
jb @f
push r10
@@:
;space for
;r9
;r8
;rdx
;rcx
sub rsp, 4*8
;call function
call rbx
;restore old stack
mov rsp, [uefi_rsptmp]
ret