Add basic 32-bit UEFI loader.

git-svn-id: svn://kolibrios.org@8150 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2020-11-06 17:52:10 +00:00
parent 7a4769e527
commit 2004300949
8 changed files with 1807 additions and 556 deletions

View File

@ -825,7 +825,7 @@ for i,v in ipairs(distr_extra_files) do
end end
end end
-- kolibri.raw -- build kolibri.raw
raw_mbr = "../programs/hd_load/usb_boot/mbr" raw_mbr = "../programs/hd_load/usb_boot/mbr"
raw_bootsector = "../kernel/trunk/bootloader/extended_primary_loader/fat32/bootsect.bin" raw_bootsector = "../kernel/trunk/bootloader/extended_primary_loader/fat32/bootsect.bin"
raw_files = { raw_files = {
@ -833,10 +833,11 @@ raw_files = {
{"KORDLDR.F32", "../kernel/trunk/bootloader/extended_primary_loader/fat32/kordldr.f32"}, {"KORDLDR.F32", "../kernel/trunk/bootloader/extended_primary_loader/fat32/kordldr.f32"},
{"KERNEL.MNT", "../kernel/trunk/kernel.mnt.ext_loader"}, {"KERNEL.MNT", "../kernel/trunk/kernel.mnt.ext_loader"},
{"CONFIG.INI", "../kernel/trunk/bootloader/extended_primary_loader/config.ini"}, {"CONFIG.INI", "../kernel/trunk/bootloader/extended_primary_loader/config.ini"},
{"EFI/BOOT/BOOTX64.EFI", "../kernel/trunk/bootloader/uefi4kos/kolibri.efi"}, {"EFI/BOOT/BOOTX64.EFI", "../kernel/trunk/bootloader/uefi4kos/bootx64.efi"},
{"EFI/BOOT/KOLIBRI.IMG", "kolibri.img"}, {"EFI/BOOT/BOOTIA32.EFI", "../kernel/trunk/bootloader/uefi4kos/bootia32.efi"},
{"EFI/BOOT/KOLIBRI.INI", "../kernel/trunk/bootloader/uefi4kos/kolibri.ini"}, {"EFI/KOLIBRIOS/KOLIBRI.IMG", "kolibri.img"},
{"EFI/BOOT/KOLIBRI.KRN", "../kernel/trunk/kolibri.krn"} {"EFI/KOLIBRIOS/KOLIBRI.INI", "../kernel/trunk/bootloader/uefi4kos/kolibri.ini"},
{"EFI/KOLIBRIOS/KOLIBRI.KRN", "../kernel/trunk/kolibri.krn"}
} }
for i,v in ipairs(img_files) do for i,v in ipairs(img_files) do

View File

@ -1,2 +1,3 @@
if tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("NO_FASM") ~= "" then return end
tup.rule("uefi4kos.asm", "fasm -dUEFI=1 -dextended_primary_loader=1 %f %o", "kolibri.efi") tup.rule("uefi64kos.asm", "fasm -dUEFI=1 -dextended_primary_loader=1 %f %o", "bootx64.efi")
tup.rule("uefi32kos.asm", "fasm -dUEFI=1 -dextended_primary_loader=1 %f %o", "bootia32.efi")

View File

@ -1,10 +1,8 @@
; Place this file to ESP:/EFI/BOOT/kolibri.ini, near kolibri.efi and kolibri.krn
; Screen resolution ; Screen resolution
resolution=1024x768 resolution=1024x768
; Duplicate debug output to the screen ; Duplicate debug output to the screen
debug_print=0 debug_print=1
; Start LAUNCHER app after kernel is loaded ; Start LAUNCHER app after kernel is loaded
launcher_start=1 launcher_start=1
@ -18,6 +16,3 @@ imgfrom=3
; Path to /sys directory ; Path to /sys directory
syspath=/rd/1 syspath=/rd/1
; Interrupt booting to ask the user for boot params
ask_params=0

View File

@ -1,8 +1,19 @@
;********************************************************************* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;* * ;; ;;
;* UEFI library for fasm by bzt, Public Domain * ;; 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. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Based on UEFI library for fasm by bzt, Public Domain. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EFI_LOCATE_SEARCH_TYPE:
.AllHandles = 0
.ByRegisterNotify = 1
.ByProtocol = 2
; EFI_MEMORY_TYPE ; EFI_MEMORY_TYPE
EFI_RESERVED_MEMORY_TYPE = 0 EFI_RESERVED_MEMORY_TYPE = 0
@ -27,20 +38,18 @@ EFI_ALLOCATE_ANY_PAGES = 0
EFI_ALLOCATE_MAX_ADDRESS = 1 EFI_ALLOCATE_MAX_ADDRESS = 1
EFI_ALLOCATE_ADDRESS = 2 EFI_ALLOCATE_ADDRESS = 2
EFI_MEMORY_UC = 0x0000000000000001 EFI_MEMORY_UC = 0x00000001
EFI_MEMORY_WC = 0x0000000000000002 EFI_MEMORY_WC = 0x00000002
EFI_MEMORY_WT = 0x0000000000000004 EFI_MEMORY_WT = 0x00000004
EFI_MEMORY_WB = 0x0000000000000008 EFI_MEMORY_WB = 0x00000008
EFI_MEMORY_UCE = 0x0000000000000010 EFI_MEMORY_UCE = 0x00000010
EFI_MEMORY_WP = 0x0000000000001000 EFI_MEMORY_WP = 0x00001000
EFI_MEMORY_RP = 0x0000000000002000 EFI_MEMORY_RP = 0x00002000
EFI_MEMORY_XP = 0x0000000000004000 EFI_MEMORY_XP = 0x00004000
EFI_MEMORY_NV = 0x0000000000008000 EFI_MEMORY_NV = 0x00008000
EFI_MEMORY_MORE_RELIABLE = 0x0000000000010000 EFI_MEMORY_MORE_RELIABLE = 0x00010000
EFI_MEMORY_RO = 0x0000000000020000 EFI_MEMORY_RO = 0x00020000
EFI_MEMORY_RUNTIME = 0x8000000000000000
EFIERR = 0x8000000000000000
EFI_SUCCESS = 0 EFI_SUCCESS = 0
EFI_LOAD_ERROR = EFIERR or 1 EFI_LOAD_ERROR = EFIERR or 1
EFI_INVALID_PARAMETER = EFIERR or 2 EFI_INVALID_PARAMETER = EFIERR or 2
@ -67,231 +76,190 @@ EFI_ICMP_ERROR = EFIERR or 22
EFI_TFTP_ERROR = EFIERR or 23 EFI_TFTP_ERROR = EFIERR or 23
EFI_PROTOCOL_ERROR = EFIERR or 24 EFI_PROTOCOL_ERROR = EFIERR or 24
struct EFI_FILE_SYSTEM_INFO
Size dq ?
ReadOnly db ?
rb 7
VolumeSize dq ?
FreeSpace dq ?
BlockSize dd ?
VolumeLabel rw 32
ends
EFI_FILE_SYSTEM_INFO_ID equ 0x93,0x6e,0x57,0x09,0x3f,0x6d,0xd2,0x11, \ EFI_FILE_SYSTEM_INFO_ID equ 0x93,0x6e,0x57,0x09,0x3f,0x6d,0xd2,0x11, \
0x39,0x8e,0x00,0xa0,0xc9,0x69,0x72,0x3b 0x39,0x8e,0x00,0xa0,0xc9,0x69,0x72,0x3b
EFI_SYSTEM_TABLE_SIGNATURE equ 0x49,0x42,0x49,0x20,0x53,0x59,0x53,0x54 EFI_SYSTEM_TABLE_SIGNATURE equ 0x49,0x42,0x49,0x20,0x53,0x59,0x53,0x54
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x22,0x5b,0x4e,0x96, \
0x59,0x64,0xd2,0x11, \
0x8e,0x39,0x00,0xa0, \
0xc9,0x69,0x72,0x3b
EFI_LOADED_IMAGE_PROTOCOL_GUID equ 0xA1,0x31,0x1b,0x5b,0x62,0x95,0xd2,0x11, \
0x8E,0x3F,0x00,0xA0,0xC9,0x69,0x72,0x3B
EFI_BLOCK_IO_PROTOCOL_GUID equ 0x21,0x5b,0x4e,0x96,0x59,0x64,0xd2,0x11, \
0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID equ 0xde,0xa9,0x42,0x90,0xdc,0x23,0x38,0x4a, \
0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a
EFI_FILE_MODE_READ = 1
EFI_FILE_MODE_WRITE = 2
EFI_FILE_MODE_CREATE = 0x8000000000000000
struct EFI_MEMORY_DESCRIPTOR
Type dd ?
dd ? ; align
PhysicalStart DQ ?
VirtualStart DQ ?
NumberOfPages DQ ?
Attribute DQ ?
ends
struct EFI_FILE_SYSTEM_INFO
Size DQ ?
ReadOnly db ?
rb 7
VolumeSize DQ ?
FreeSpace DQ ?
BlockSize dd ?
VolumeLabel rw 32
ends
struct EFI_TABLE_HEADER struct EFI_TABLE_HEADER
Signature dq ? Signature DQ ?
Revision dd ? Revision dd ?
HeaderSize dd ? HeaderSize dd ?
CRC32 dd ? CRC32 dd ?
Reserved dd ? Reserved dd ?
ends ends
struct EFI_SYSTEM_TABLE struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
Hdr EFI_TABLE_HEADER Reset DN ?
FirmwareVendor dq ? OutputString DN ?
FirmwareRevision dd ? TestString DN ?
dd ? QueryMode DN ?
ConsoleInHandle dq ? SetMode DN ?
ConIn dq ? SetAttribute DN ?
ConsoleOutHandle dq ? ClearScreen DN ?
ConOut dq ? SetCursorPosition DN ?
StandardErrorHandle dq ? EnableCursor DN ?
StdErr dq ? Mode DN ?
RuntimeServices dq ?
BootServices dq ?
NumberOfTableEntries dq ?
ConfigurationTable dq ?
ends
struct SIMPLE_TEXT_OUTPUT_INTERFACE
Reset dq ?
OutputString dq ?
TestString dq ?
QueryMode dq ?
SetMode dq ?
SetAttribute dq ?
ClearScreen dq ?
SetCursorPosition dq ?
EnableCursor dq ?
Mode dq ?
ends ends
struct SIMPLE_INPUT_INTERFACE struct SIMPLE_INPUT_INTERFACE
Reset dq ? Reset DN ?
ReadKeyStroke dq ? ReadKeyStroke DN ?
WaitForKey dq ? WaitForKey DN ?
ends ends
struct EFI_BOOT_SERVICES_TABLE struct EFI_BOOT_SERVICES
Hdr EFI_TABLE_HEADER Hdr EFI_TABLE_HEADER
RaisePriority dq ? RaisePriority DN ?
RestorePriority dq ? RestorePriority DN ?
AllocatePages dq ? AllocatePages DN ?
FreePages dq ? FreePages DN ?
GetMemoryMap dq ? GetMemoryMap DN ?
AllocatePool dq ? AllocatePool DN ?
FreePool dq ? FreePool DN ?
CreateEvent dq ? CreateEvent DN ?
SetTimer dq ? SetTimer DN ?
WaitForEvent dq ? WaitForEvent DN ?
SignalEvent dq ? SignalEvent DN ?
CloseEvent dq ? CloseEvent DN ?
CheckEvent dq ? CheckEvent DN ?
InstallProtocolInterface dq ? InstallProtocolInterface DN ?
ReInstallProtocolInterface dq ? ReInstallProtocolInterface DN ?
UnInstallProtocolInterface dq ? UnInstallProtocolInterface DN ?
HandleProtocol dq ? HandleProtocol DN ?
Void dq ? Reserved DN ?
RegisterProtocolNotify dq ? RegisterProtocolNotify DN ?
LocateHandle dq ? LocateHandle DN ?
LocateDevicePath dq ? LocateDevicePath DN ?
InstallConfigurationTable dq ? InstallConfigurationTable DN ?
ImageLoad dq ? ImageLoad DN ?
ImageStart dq ? ImageStart DN ?
Exit dq ? Exit DN ?
ImageUnLoad dq ? ImageUnLoad DN ?
ExitBootServices dq ? ExitBootServices DN ?
GetNextMonotonicCount dq ? GetNextMonotonicCount DN ?
Stall dq ? Stall DN ?
SetWatchdogTimer dq ? SetWatchdogTimer DN ?
ConnectController dq ? ConnectController DN ?
DisConnectController dq ? DisConnectController DN ?
OpenProtocol dq ? OpenProtocol DN ?
CloseProtocol dq ? CloseProtocol DN ?
OpenProtocolInformation dq ? OpenProtocolInformation DN ?
ProtocolsPerHandle dq ? ProtocolsPerHandle DN ?
LocateHandleBuffer dq ? LocateHandleBuffer DN ?
LocateProtocol dq ? LocateProtocol DN ?
InstallMultipleProtocolInterfaces dq ? InstallMultipleProtocolInterfaces DN ?
UnInstallMultipleProtocolInterfaces dq ? UnInstallMultipleProtocolInterfaces DN ?
CalculateCrc32 dq ? CalculateCrc32 DN ?
CopyMem dq ? CopyMem DN ?
SetMem dq ? SetMem DN ?
ends ends
struct EFI_RUNTIME_SERVICES_TABLE struct EFI_RUNTIME_SERVICES
Hdr EFI_TABLE_HEADER Hdr EFI_TABLE_HEADER
GetTime dq ? GetTime DN ?
SetTime dq ? SetTime DN ?
GetWakeUpTime dq ? GetWakeUpTime DN ?
SetWakeUpTime dq ? SetWakeUpTime DN ?
SetVirtualAddressMap dq ? SetVirtualAddressMap DN ?
ConvertPointer dq ? ConvertPointer DN ?
GetVariable dq ? GetVariable DN ?
GetNextVariableName dq ? GetNextVariableName DN ?
SetVariable dq ? SetVariable DN ?
GetNextHighMonoCount dq ? GetNextHighMonoCount DN ?
ResetSystem dq ? ResetSystem DN ?
ends ends
struct EFI_TIME
Year dw ?
Month db ?
Day db ?
Hour db ?
Minute db ?
Second db ?
Pad1 db ?
Nanosecond dd ?
TimeZone dw ?
Daylight db ?
Pad2 db ?
sizeof db ?
ends
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x22,0x5b,0x4e,0x96,0x59,0x64,0xd2,0x11, \
0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b
struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
Revision dq ? Revision DQ ?
OpenVolume dq ? OpenVolume DN ?
ends ends
EFI_FILE_MODE_READ = 1
EFI_FILE_MODE_WRITE = 2
EFI_FILE_MODE_CREATE = 0x8000000000000000
struct EFI_FILE_PROTOCOL struct EFI_FILE_PROTOCOL
Revision dq ? Revision DQ ?
Open dq ? Open DN ?
Close dq ? Close DN ?
Delete dq ? Delete DN ?
Read dq ? Read DN ?
Write dq ? Write DN ?
GetPosition dq ? GetPosition DN ?
SetPosition dq ? SetPosition DN ?
GetInfo dq ? GetInfo DN ?
SetInfo dq ? SetInfo DN ?
Flush dq ? Flush DN ?
OpenEx dq ? OpenEx DN ?
ReadEx dq ? ReadEx DN ?
WriteEx dq ? WriteEx DN ?
FlushEx dq ? FlushEx DN ?
ends ends
EFI_LOADED_IMAGE_PROTOCOL_GUID equ 0xA1,0x31,0x1b,0x5b,0x62,0x95,0xd2,0x11, \
0x8E,0x3F,0x00,0xA0,0xC9,0x69,0x72,0x3B
struct EFI_LOADED_IMAGE_PROTOCOL
Revision dd ?
dd ?
ParentHandle dq ?
SystemTable dq ?
DeviceHandle dq ?
FilePath dq ?
Reserved dq ?
LoadOptionsSize dd ?
dd ?
ImageBase dq ?
ImageSize dq ?
ImageCodeType dd ?
ImageDataType dd ?
UnLoad dq ?
ends
EFI_BLOCK_IO_PROTOCOL_GUID equ 0x21,0x5b,0x4e,0x96,0x59,0x64,0xd2,0x11, \
0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b
struct EFI_BLOCK_IO_PROTOCOL
Revision dq ?
Media dq ?
Reset dq ?
ReadBlocks dq ?
WriteBlocks dq ?
FlushBlocks dq ?
ends
struct EFI_BLOCK_IO_MEDIA
MediaId dd ?
RemovableMedia db ?
MediaPresent db ?
LogicalPartition db ?
ReadOnly db ?
WriteCaching db ?
rb 3
BlockSize dd ?
IoAlign dd ?
LastBlock dq ?
ends
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID equ 0xde,0xa9,0x42,0x90,0xdc,0x23,0x38,0x4a, \
0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a
struct EFI_GRAPHICS_OUTPUT_PROTOCOL struct EFI_GRAPHICS_OUTPUT_PROTOCOL
QueryMode dq ? QueryMode DN ?
SetMode dq ? SetMode DN ?
Blt dq ? Blt DN ?
Mode dq ? Mode DN ?
ends ends
struct EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE struct EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
MaxMode dd ? MaxMode dd ?
Mode dd ? Mode dd ?
nfo dq ? Info DN ?
SizeOfInfo dq ? SizeOfInfo DN ?
FrameBufferBase dq ? FrameBufferBase DQ ?
FrameBufferSize dq ? FrameBufferSize DN ?
ends
EFI_GRAPHICS_PIXEL_FORMAT:
.PixelRedGreenBlueReserved8BitPerColor = 0
.PixelBlueGreenRedReserved8BitPerColor = 1
.PixelBitMask = 2
.PixelBltOnly = 3
.PixelFormatMax = 4
struct EFI_PIXEL_BITMASK
RedMask dd ?
GreenMask dd ?
BlueMask dd ?
ReservedMask dd ?
ends ends
struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
@ -299,217 +267,6 @@ struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
HorizontalResolution dd ? HorizontalResolution dd ?
VerticalResolution dd ? VerticalResolution dd ?
PixelFormat dd ? PixelFormat dd ?
RedMask dd ? PixelInformation EFI_PIXEL_BITMASK
GreenMask dd ?
BlueMask dd ?
Reserved dd ?
PixelsPerScanLine dd ? PixelsPerScanLine dd ?
ends ends
;---macros to make life easier---
;call it early, after entry point is the best
macro InitializeLib
{
clc
test rdx, rdx
jz .badout
cmp dword[rdx], 'IBI ' ; 20494249h
jz @f
.badout:
xor ecx, ecx
xor edx, edx
stc
@@:
mov [efi_handler], rcx ; ImageHandle
mov [efi_ptr], rdx ; pointer to SystemTable
}
;invoke an UEFI function
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
if ~ arg1 in <ConsoleInHandle,ConIn,ConsoleOutHandle,ConOut,StandardErrorHandle,StdErr,RuntimeServices,BootServices>
mov rcx, arg1
end if
end if
end if
xor rax, rax
mov al, numarg
if interface in <ConsoleInHandle,ConIn,ConsoleOutHandle,ConOut,StandardErrorHandle,StdErr,RuntimeServices,BootServices>
mov rbx, [efi_ptr]
mov rbx, [rbx + EFI_SYSTEM_TABLE.#interface]
else
if ~ interface eq rbx
mov rbx, interface
end if
end if
if arg1 in <ConsoleInHandle,ConIn,ConsoleOutHandle,ConOut,StandardErrorHandle,StdErr,RuntimeServices,BootServices>
mov rcx, rbx
end if
if defined SIMPLE_INPUT_INTERFACE.#function
mov rbx, [rbx + SIMPLE_INPUT_INTERFACE.#function]
else
if defined SIMPLE_TEXT_OUTPUT_INTERFACE.#function
mov rbx, [rbx + SIMPLE_TEXT_OUTPUT_INTERFACE.#function]
else
if defined EFI_BOOT_SERVICES_TABLE.#function
mov rbx, [rbx + EFI_BOOT_SERVICES_TABLE.#function]
else
if defined EFI_RUNTIME_SERVICES_TABLE.#function
mov rbx, [rbx + EFI_RUNTIME_SERVICES_TABLE.#function]
else
if defined EFI_GRAPHICS_OUTPUT_PROTOCOL.#function
mov rbx, [rbx + EFI_GRAPHICS_OUTPUT_PROTOCOL.#function]
else
if defined EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.#function
mov rbx, [rbx + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.#function]
else
mov rbx, [rbx + function]
end if
end if
end if
end if
end if
end if
call uefifunc
}
;*********************************************************************
;* Library functions *
;*********************************************************************
section '.text' code executable readable
uefifunc:
;save stack pointer
mov qword [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, qword [uefi_rsptmp]
ret
section '.data' data readable writeable
efi_handler dq 0
efi_ptr dq 0
uefi_rsptmp dq 0

View File

@ -0,0 +1,58 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 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. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Based on UEFI library for fasm by bzt, Public Domain. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DN fix dd ; native
include "uefi.inc"
EFIERR = 0x80000000
struct EFI_SYSTEM_TABLE
Hdr EFI_TABLE_HEADER
FirmwareVendor dd ?
FirmwareRevision dd ?
ConsoleInHandle dd ?
ConIn dd ?
ConsoleOutHandle dd ?
ConOut dd ?
StandardErrorHandle dd ?
StdErr dd ?
RuntimeServices dd ?
BootServices dd ?
NumberOfTableEntries dd ?
ConfigurationTable dd ?
ends
struct EFI_CONFIGURATION_TABLE
VendorGUID rd 4
VendorTable dd ?
ends
struct EFI_LOADED_IMAGE_PROTOCOL
Revision dd ?
ParentHandle dd ?
SystemTable dd ?
DeviceHandle dd ?
FilePath dd ?
Reserved dd ?
LoadOptionsSize dd ?
ImageBase dd ?
ImageSize DQ ?
ImageCodeType dd ?
ImageDataType dd ?
UnLoad dd ?
ends
section '.text' code executable readable
uefifunc:
ret

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,196 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 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. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Based on UEFI library for fasm by bzt, Public Domain. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DN fix dq ; native
include "uefi.inc"
EFIERR = 0x8000000000000000
struct EFI_SYSTEM_TABLE
Hdr EFI_TABLE_HEADER
FirmwareVendor dq ?
FirmwareRevision dd ?
dd ?
ConsoleInHandle dq ?
ConIn dq ?
ConsoleOutHandle dq ?
ConOut dq ?
StandardErrorHandle dq ?
StdErr dq ?
RuntimeServices dq ?
BootServices dq ?
NumberOfTableEntries dq ?
ConfigurationTable dq ?
ends
struct EFI_LOADED_IMAGE_PROTOCOL
Revision dd ?
dd ?
ParentHandle dq ?
SystemTable dq ?
DeviceHandle dq ?
FilePath dq ?
Reserved dq ?
LoadOptionsSize dd ?
dd ?
ImageBase dq ?
ImageSize dq ?
ImageCodeType dd ?
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

View File

@ -1,4 +1,12 @@
format pe64 dll efi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 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. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format pe64 efi
entry main entry main
section '.text' code executable readable section '.text' code executable readable
@ -6,7 +14,9 @@ section '.text' code executable readable
include '../../struct.inc' include '../../struct.inc'
include '../../macros.inc' include '../../macros.inc'
include '../../const.inc' include '../../const.inc'
include 'uefi.inc'
purge DQ
include 'uefi64.inc'
MEMORY_MAP_SIZE = 0x4000 MEMORY_MAP_SIZE = 0x4000
GOP_BUFFER_SIZE = 0x100 GOP_BUFFER_SIZE = 0x100
@ -44,8 +54,14 @@ end virtual
xor eax, eax xor eax, eax
cmp [.fatal], 1 cmp [.fatal], 1
jnz .done jnz .done
eficall ConOut, OutputString, ConOut, msg_error_open_file mov rbx, [efi_table]
eficall ConOut, OutputString, ConOut, [.name] mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error_open_file
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
[.name]
jmp $ jmp $
@@: @@:
@ -101,7 +117,6 @@ skip_newline:
skip_line: skip_line:
call skip_until_newline call skip_until_newline
call skip_newline call skip_newline
.done:
ret ret
dec2bin: dec2bin:
@ -252,13 +267,17 @@ end virtual
ret 1*8 ret 1*8
read_options_from_config: read_options_from_config:
eficall BootServices, HandleProtocol, qword[efi_handler], lipuuid, \ mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [efi_handle], lipuuid, \
lip_interface lip_interface
cmp eax, EFI_SUCCESS cmp eax, EFI_SUCCESS
jnz .error jnz .error
mov rax, [lip_interface] mov rax, [lip_interface]
eficall BootServices, HandleProtocol, \ mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, \
[rax+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfspguid, \ [rax+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfspguid, \
sfsp_interface sfsp_interface
cmp rax, EFI_SUCCESS cmp rax, EFI_SUCCESS
@ -285,6 +304,30 @@ read_options_from_config:
.error: .error:
ret ret
print_vmode:
push rax rbx rcx rdx rsi rdi
mov rbx, rcx
call clearbuf
mov eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
mov rdi, msg
call num2dec
mov eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
mov rdi, msg+8*2
call num2dec
mov eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat]
mov rdi, msg+16*2
call num2dec
mov eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
mov rdi, msg+24*2
call num2dec
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
pop rdi rsi rdx rcx rbx rax
ret
find_vmode_index_by_resolution: find_vmode_index_by_resolution:
mov [cfg_opt_used_resolution], 1 mov [cfg_opt_used_resolution], 1
mov [cfg_opt_value_vmode], 0 mov [cfg_opt_value_vmode], 0
@ -295,6 +338,7 @@ find_vmode_index_by_resolution:
cmp rax, EFI_SUCCESS cmp rax, EFI_SUCCESS
jnz .error jnz .error
mov rcx, [gop_info] mov rcx, [gop_info]
call print_vmode
; PixelBlueGreenRedReserved8BitPerColor ; PixelBlueGreenRedReserved8BitPerColor
cmp [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1 cmp [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1
jnz .skip_mode jnz .skip_mode
@ -311,15 +355,31 @@ find_vmode_index_by_resolution:
movzx eax, [cfg_opt_value_vmode] movzx eax, [cfg_opt_value_vmode]
mov rcx, [gop_interface] mov rcx, [gop_interface]
mov rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode] mov rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
cmp eax, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode] cmp eax, 8;[rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
jnz .next_mode jnz .next_mode
mov [cfg_opt_used_resolution], 0 mov [cfg_opt_used_resolution], 0
mov [cfg_opt_value_ask_params], 1 mov [cfg_opt_value_ask_params], 1
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
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]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg_error
jmp $
.error: .error:
.done: .done:
ret ret
ask_for_params: 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 xor ebx, ebx
.next_mode: .next_mode:
call clearbuf call clearbuf
@ -346,7 +406,9 @@ ask_for_params:
; lea rdi, [msg+14*2] ; lea rdi, [msg+14*2]
; call num2dec ; call num2dec
.skip: .skip:
eficall ConOut, OutputString, ConOut, msg mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
cmp rax, EFI_SUCCESS cmp rax, EFI_SUCCESS
jnz .error jnz .error
@ -358,13 +420,17 @@ ask_for_params:
jnz .next_mode jnz .next_mode
eficall ConIn, Reset, ConIn, 1 mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
eficall rbx, SIMPLE_INPUT_INTERFACE.Reset, rbx, 1
cmp rax, EFI_SUCCESS cmp rax, EFI_SUCCESS
jnz .error jnz .error
xor ecx, ecx xor ecx, ecx
@@: @@:
push rcx push rcx
eficall ConIn, ReadKeyStroke, ConIn, msg mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
eficall rbx, SIMPLE_INPUT_INTERFACE.ReadKeyStroke, rbx, msg
pop rcx pop rcx
mov rdx, EFI_DEVICE_ERROR mov rdx, EFI_DEVICE_ERROR
cmp rax, rdx cmp rax, rdx
@ -388,23 +454,32 @@ ask_for_params:
ret ret
main: main:
sub rsp, 0x38 mov [efi_handle], rcx
mov [efi_table], rdx
; initialize UEFI library mov rbx, [efi_table]
InitializeLib mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
jc .error eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset, rbx, 1
test eax, eax
; eficall ConOut, Reset, ConOut, 1 jz @f
; cmp rax, EFI_SUCCESS jmp $ ; what can I do here?
; jnz .error @@:
mov rbx, [efi_table]
eficall ConOut, ClearScreen, ConOut mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
cmp rax, EFI_SUCCESS eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
jnz .error msg_u4k_loaded
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_read_options
call read_options_from_config call read_options_from_config
; read kernel file ; read kernel file
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_load_kernel
push 1 push 1
push -1 push -1
push KERNEL_BASE push KERNEL_BASE
@ -413,6 +488,10 @@ main:
call load_file call load_file
; read ramdisk image ; read ramdisk image
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_load_ramdisk
push 1 push 1
push -1 push -1
push RAMDISK_BASE push RAMDISK_BASE
@ -421,12 +500,24 @@ main:
call load_file call load_file
; alloc buffer for devices.dat ; alloc buffer for devices.dat
eficall BootServices, AllocatePages, EFI_ALLOCATE_MAX_ADDRESS, \ mov rbx, [efi_table]
EFI_RESERVED_MEMORY_TYPE, 1, devicesdat_data mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_alloc_devicesdat
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.AllocatePages, \
EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
devicesdat_data
cmp eax, EFI_SUCCESS cmp eax, EFI_SUCCESS
jnz .error jnz .error
; read devices.dat ; read devices.dat
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_load_devicesdat
push 0 ; not fatal push 0 ; not fatal
push [devicesdat_size] push [devicesdat_size]
push [devicesdat_data] push [devicesdat_data]
@ -435,19 +526,107 @@ main:
call load_file call load_file
mov [devicesdat_size], rax mov [devicesdat_size], rax
eficall BootServices, LocateHandle, 2, gopuuid, 0, gop_buffer_size, \ mov rbx, [efi_table]
gop_buffer mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
cmp eax, EFI_SUCCESS eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
jnz .error msg_locate_gop_handlers
mov rsi, gop_buffer
lodsq
mov [gop_handle], rax
eficall BootServices, HandleProtocol, qword[gop_handle], gopuuid, \
gop_interface
cmp eax, EFI_SUCCESS
jnz .error
mov rbx, [efi_ptr] 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
sub rax, gop_buffer
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
@@:
push rbx
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_look_for_rsdp
pop rbx
mov rbx, [efi_table]
mov rdi, [rbx+EFI_SYSTEM_TABLE.ConfigurationTable] mov rdi, [rbx+EFI_SYSTEM_TABLE.ConfigurationTable]
mov rcx, [rbx+EFI_SYSTEM_TABLE.NumberOfTableEntries] mov rcx, [rbx+EFI_SYSTEM_TABLE.NumberOfTableEntries]
mov rax, 0x11d3e4f18868e871 mov rax, 0x11d3e4f18868e871
@ -468,8 +647,29 @@ main:
jmp .next_table jmp .next_table
.all_tables_done: .all_tables_done:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_acpi_tables_done
cmp [cfg_opt_used_resolution], 0 cmp [cfg_opt_used_resolution], 0
jz .not_used_resolution jz .not_used_resolution
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_opt_resolution
call clearbuf
xor edx, edx
movzx eax, [rdx+BOOT_LO.x_res]
mov rdi, msg
call num2dec
xor edx, edx
movzx eax, [rdx+BOOT_LO.y_res]
mov rdi, msg+8*2
call num2dec
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
call find_vmode_index_by_resolution call find_vmode_index_by_resolution
.not_used_resolution: .not_used_resolution:
cmp [cfg_opt_used_debug_print], 0 cmp [cfg_opt_used_debug_print], 0
@ -487,8 +687,19 @@ main:
movzx ecx, [cfg_opt_value_vmode] movzx ecx, [cfg_opt_value_vmode]
eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode, \ eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode, \
[gop_interface], rcx [gop_interface], rcx
cmp eax, EFI_SUCCESS test eax, eax
jnz .error 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
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg_error
jmp $
@@:
mov rcx, [gop_interface] mov rcx, [gop_interface]
mov rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode] mov rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
@ -518,13 +729,17 @@ main:
mov dword[rdx+BOOT_LO.pci_data+4], 0xe3 mov dword[rdx+BOOT_LO.pci_data+4], 0xe3
eficall BootServices, AllocatePages, EFI_ALLOCATE_ANY_PAGES, \ mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.AllocatePages, EFI_ALLOCATE_ANY_PAGES, \
EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
cmp eax, EFI_SUCCESS cmp eax, EFI_SUCCESS
jnz .error jnz .error
eficall BootServices, GetMemoryMap, memory_map_size, [memory_map], \ mov rbx, [efi_table]
memory_map_key, descriptor_size, descriptor_ver mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.GetMemoryMap, memory_map_size, \
[memory_map], memory_map_key, descriptor_size, descriptor_ver
cmp eax, EFI_SUCCESS cmp eax, EFI_SUCCESS
jnz .error jnz .error
@ -553,7 +768,10 @@ main:
; eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \ ; eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
; 2880*512/0x1000, EFI_ALLOCATE_ADDRESS ; 2880*512/0x1000, EFI_ALLOCATE_ADDRESS
eficall BootServices, ExitBootServices, [efi_handler], [memory_map_key] mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
eficall rbx, EFI_BOOT_SERVICES.ExitBootServices, [efi_handle], \
[memory_map_key]
cmp eax, EFI_SUCCESS cmp eax, EFI_SUCCESS
jnz .error jnz .error
@ -612,7 +830,6 @@ main:
push CODE_32_SELECTOR push CODE_32_SELECTOR
lea rax, [.next] lea rax, [.next]
push rax push rax
; push .next
retf retf
use32 use32
align 16 align 16
@ -635,11 +852,11 @@ align 16
use64 use64
.error: .error:
eficall ConOut, OutputString, ConOut, msg_error mov rbx, [efi_table]
jmp .quit mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
.quit: eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
mov rcx, -1 msg_error
loop $ jmp $
; linux/arch/x86/platform/efi/efi.c ; linux/arch/x86/platform/efi/efi.c
@ -647,11 +864,10 @@ use64
add_uefi_memmap: add_uefi_memmap:
push rax rbx rcx rdx rsi rdi push rax rbx rcx rdx rsi rdi
mov r10d, [rsi+0] mov r10d, [rsi+EFI_MEMORY_DESCRIPTOR.Type]
mov r11, [rsi+8] mov r11, [rsi+EFI_MEMORY_DESCRIPTOR.PhysicalStart]
; mov r12, [rsi+16] mov r13, [rsi+EFI_MEMORY_DESCRIPTOR.NumberOfPages]
mov r13, [rsi+24] mov r14, [rsi+EFI_MEMORY_DESCRIPTOR.Attribute]
mov r14, [rsi+32]
mov [rdi+e820entry.addr], r11 mov [rdi+e820entry.addr], r11
mov rax, r13 mov rax, r13
@ -764,6 +980,9 @@ clearbuf:
ret ret
section '.data' data readable writeable section '.data' data readable writeable
efi_handle dq 0
efi_table dq 0
uefi_rsptmp dq 0
GDTR: GDTR:
dw 4*8-1 dw 4*8-1
@ -794,10 +1013,10 @@ sfsp_interface dq 0
esp_root dq ? esp_root dq ?
file_handle dq ? file_handle dq ?
file_name du '\EFI\BOOT\KOLIBRI.INI',0 file_name du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
kernel_name du '\EFI\BOOT\KOLIBRI.KRN',0 kernel_name du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
ramdisk_name du '\EFI\BOOT\KOLIBRI.IMG',0 ramdisk_name du '\EFI\KOLIBRIOS\KOLIBRI.IMG',0
devicesdat_name du '\EFI\BOOT\DEVICES.DAT',0 devicesdat_name du '\EFI\KOLIBRIOS\DEVICES.DAT',0
file_buffer_size dq FILE_BUFFER_SIZE-1 ; leave the last byte for \0 file_buffer_size dq FILE_BUFFER_SIZE-1 ; leave the last byte for \0
config_options dq cfg_opt_name_resolution, cfg_opt_func_resolution, \ config_options dq cfg_opt_name_resolution, cfg_opt_func_resolution, \
@ -816,14 +1035,14 @@ config_options dq cfg_opt_name_resolution, cfg_opt_func_resolution, \
cfg_opt_cmnt_syspath, \ cfg_opt_cmnt_syspath, \
0 0
cfg_opt_name_resolution db 'resolution',0 cfg_opt_name_resolution db "resolution",0
cfg_opt_name_acpi db 'acpi',0 cfg_opt_name_acpi db "acpi",0
cfg_opt_name_debug_print db 'debug_print',0 cfg_opt_name_debug_print db "debug_print",0
cfg_opt_name_launcher_start db 'launcher_start',0 cfg_opt_name_launcher_start db "launcher_start",0
cfg_opt_name_mtrr db 'mtrr',0 cfg_opt_name_mtrr db "mtrr",0
cfg_opt_name_ask_params db 'ask_params',0 cfg_opt_name_ask_params db "ask_params",0
cfg_opt_name_imgfrom db 'imgfrom',0 cfg_opt_name_imgfrom db "imgfrom",0
cfg_opt_name_syspath db 'syspath',0 cfg_opt_name_syspath db "syspath",0
cfg_opt_cmnt_resolution db "# Graphic mode",0 cfg_opt_cmnt_resolution db "# Graphic mode",0
cfg_opt_cmnt_acpi db "# ACPI settings",0xa, \ cfg_opt_cmnt_acpi db "# ACPI settings",0xa, \
@ -834,7 +1053,8 @@ cfg_opt_cmnt_acpi db "# ACPI settings",0xa, \
cfg_opt_cmnt_debug_print db "# Duplicate debug output to the screen",0 cfg_opt_cmnt_debug_print db "# Duplicate debug output to the screen",0
cfg_opt_cmnt_launcher_start db "# Start LAUNCHER app after kernel is loaded",0 cfg_opt_cmnt_launcher_start db "# Start LAUNCHER app after kernel is loaded",0
cfg_opt_cmnt_mtrr db "# Configure MTRR's",0 cfg_opt_cmnt_mtrr db "# Configure MTRR's",0
cfg_opt_cmnt_ask_params db "# Interrupt booting to ask the user for boot params",0 cfg_opt_cmnt_ask_params db "# Interrupt booting to ask the user for boot", \
" params",0
cfg_opt_cmnt_imgfrom db "# Where to load ramdisk image from",0 cfg_opt_cmnt_imgfrom db "# Where to load ramdisk image from",0
cfg_opt_cmnt_syspath db "# Path to /sys directory",0 cfg_opt_cmnt_syspath db "# Path to /sys directory",0
@ -852,9 +1072,9 @@ cfg_opt_value_acpi db 0
cfg_opt_value_debug_print db 0 cfg_opt_value_debug_print db 0
cfg_opt_value_launcher_start db 1 cfg_opt_value_launcher_start db 1
cfg_opt_value_mtrr db 0 cfg_opt_value_mtrr db 0
cfg_opt_value_ask_params db 1 cfg_opt_value_ask_params db 0
cfg_opt_value_imgfrom db RD_LOAD_FROM_MEMORY cfg_opt_value_imgfrom db RD_LOAD_FROM_MEMORY
cfg_opt_value_syspath db '/RD/1',0 cfg_opt_value_syspath db "/RD/1",0
rb 20 rb 20
memory_map_key dq 0 memory_map_key dq 0
@ -862,21 +1082,39 @@ descriptor_size dq 0
descriptor_ver dq 0 descriptor_ver dq 0
memory_map_size dq MEMORY_MAP_SIZE memory_map_size dq MEMORY_MAP_SIZE
msg_success du 'Success!',13,10,0 msg_u4k_loaded du "uefi64kos loaded",13,10,0
msg_error du 'Error!',13,10,0 msg_read_options du "Read options from config file",13,10,0
msg du 79 dup ' ',13,10,0 msg_load_kernel du "Load kernel",13,10,0
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_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
msg_look_for_rsdp du "Look for RSDP",13,10,0
msg_rsdp_found du "RSDP found",13,10,0
msg_acpi_tables_done du "ACPI tables done",13,10,0
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_gop_buffer_size du "GOP buffer size",13,10,0
msg_opt_resolution du "option resolution: ",0
msg_error du "Error!",13,10,0
msg_error_no_such_vmode du "No such vmode",13,10,0
msg_error_out_of_handlers du "Out of handlers",13,10,0
msg_error_open_file du "Error: can't open file ",0 msg_error_open_file du "Error: can't open file ",0
msg du 79 dup " ",13,10,0
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
efi_fs_info EFI_FILE_SYSTEM_INFO efi_fs_info EFI_FILE_SYSTEM_INFO
;section '.bss' data readable writeable
memory_map dq ? memory_map dq ?
gop_buffer rb GOP_BUFFER_SIZE gop_buffer rq GOP_BUFFER_SIZE/8
lip_buffer rb LIP_BUFFER_SIZE
devicesdat_data dq 0xffffffff devicesdat_data dq 0xffffffff
devicesdat_size dq 0x1000 devicesdat_size dq 0x1000
status dq ?
section '.reloc' fixups data discardable section '.reloc' fixups data discardable