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
-- kolibri.raw
-- build kolibri.raw
raw_mbr = "../programs/hd_load/usb_boot/mbr"
raw_bootsector = "../kernel/trunk/bootloader/extended_primary_loader/fat32/bootsect.bin"
raw_files = {
@ -833,10 +833,11 @@ raw_files = {
{"KORDLDR.F32", "../kernel/trunk/bootloader/extended_primary_loader/fat32/kordldr.f32"},
{"KERNEL.MNT", "../kernel/trunk/kernel.mnt.ext_loader"},
{"CONFIG.INI", "../kernel/trunk/bootloader/extended_primary_loader/config.ini"},
{"EFI/BOOT/BOOTX64.EFI", "../kernel/trunk/bootloader/uefi4kos/kolibri.efi"},
{"EFI/BOOT/KOLIBRI.IMG", "kolibri.img"},
{"EFI/BOOT/KOLIBRI.INI", "../kernel/trunk/bootloader/uefi4kos/kolibri.ini"},
{"EFI/BOOT/KOLIBRI.KRN", "../kernel/trunk/kolibri.krn"}
{"EFI/BOOT/BOOTX64.EFI", "../kernel/trunk/bootloader/uefi4kos/bootx64.efi"},
{"EFI/BOOT/BOOTIA32.EFI", "../kernel/trunk/bootloader/uefi4kos/bootia32.efi"},
{"EFI/KOLIBRIOS/KOLIBRI.IMG", "kolibri.img"},
{"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

View File

@ -1,2 +1,3 @@
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
resolution=1024x768
; Duplicate debug output to the screen
debug_print=0
debug_print=1
; Start LAUNCHER app after kernel is loaded
launcher_start=1
@ -18,6 +16,3 @@ imgfrom=3
; Path to /sys directory
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_RESERVED_MEMORY_TYPE = 0
@ -27,20 +38,18 @@ EFI_ALLOCATE_ANY_PAGES = 0
EFI_ALLOCATE_MAX_ADDRESS = 1
EFI_ALLOCATE_ADDRESS = 2
EFI_MEMORY_UC = 0x0000000000000001
EFI_MEMORY_WC = 0x0000000000000002
EFI_MEMORY_WT = 0x0000000000000004
EFI_MEMORY_WB = 0x0000000000000008
EFI_MEMORY_UCE = 0x0000000000000010
EFI_MEMORY_WP = 0x0000000000001000
EFI_MEMORY_RP = 0x0000000000002000
EFI_MEMORY_XP = 0x0000000000004000
EFI_MEMORY_NV = 0x0000000000008000
EFI_MEMORY_MORE_RELIABLE = 0x0000000000010000
EFI_MEMORY_RO = 0x0000000000020000
EFI_MEMORY_RUNTIME = 0x8000000000000000
EFI_MEMORY_UC = 0x00000001
EFI_MEMORY_WC = 0x00000002
EFI_MEMORY_WT = 0x00000004
EFI_MEMORY_WB = 0x00000008
EFI_MEMORY_UCE = 0x00000010
EFI_MEMORY_WP = 0x00001000
EFI_MEMORY_RP = 0x00002000
EFI_MEMORY_XP = 0x00004000
EFI_MEMORY_NV = 0x00008000
EFI_MEMORY_MORE_RELIABLE = 0x00010000
EFI_MEMORY_RO = 0x00020000
EFIERR = 0x8000000000000000
EFI_SUCCESS = 0
EFI_LOAD_ERROR = EFIERR or 1
EFI_INVALID_PARAMETER = EFIERR or 2
@ -67,231 +76,190 @@ EFI_ICMP_ERROR = EFIERR or 22
EFI_TFTP_ERROR = EFIERR or 23
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, \
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
Signature dq ?
Signature DQ ?
Revision dd ?
HeaderSize dd ?
CRC32 dd ?
Reserved dd ?
ends
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 SIMPLE_TEXT_OUTPUT_INTERFACE
Reset dq ?
OutputString dq ?
TestString dq ?
QueryMode dq ?
SetMode dq ?
SetAttribute dq ?
ClearScreen dq ?
SetCursorPosition dq ?
EnableCursor dq ?
Mode dq ?
struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
Reset DN ?
OutputString DN ?
TestString DN ?
QueryMode DN ?
SetMode DN ?
SetAttribute DN ?
ClearScreen DN ?
SetCursorPosition DN ?
EnableCursor DN ?
Mode DN ?
ends
struct SIMPLE_INPUT_INTERFACE
Reset dq ?
ReadKeyStroke dq ?
WaitForKey dq ?
Reset DN ?
ReadKeyStroke DN ?
WaitForKey DN ?
ends
struct EFI_BOOT_SERVICES_TABLE
struct EFI_BOOT_SERVICES
Hdr EFI_TABLE_HEADER
RaisePriority DN ?
RestorePriority DN ?
AllocatePages DN ?
FreePages DN ?
GetMemoryMap DN ?
AllocatePool DN ?
FreePool DN ?
CreateEvent DN ?
SetTimer DN ?
WaitForEvent DN ?
SignalEvent DN ?
CloseEvent DN ?
CheckEvent DN ?
InstallProtocolInterface DN ?
ReInstallProtocolInterface DN ?
UnInstallProtocolInterface DN ?
HandleProtocol DN ?
Reserved DN ?
RegisterProtocolNotify DN ?
LocateHandle DN ?
LocateDevicePath DN ?
InstallConfigurationTable DN ?
ImageLoad DN ?
ImageStart DN ?
Exit DN ?
ImageUnLoad DN ?
ExitBootServices DN ?
GetNextMonotonicCount DN ?
Stall DN ?
SetWatchdogTimer DN ?
ConnectController DN ?
DisConnectController DN ?
OpenProtocol DN ?
CloseProtocol DN ?
OpenProtocolInformation DN ?
ProtocolsPerHandle DN ?
LocateHandleBuffer DN ?
LocateProtocol DN ?
InstallMultipleProtocolInterfaces DN ?
UnInstallMultipleProtocolInterfaces DN ?
CalculateCrc32 DN ?
CopyMem DN ?
SetMem DN ?
ends
struct EFI_RUNTIME_SERVICES
Hdr EFI_TABLE_HEADER
RaisePriority dq ?
RestorePriority dq ?
AllocatePages dq ?
FreePages dq ?
GetMemoryMap dq ?
AllocatePool dq ?
FreePool dq ?
CreateEvent dq ?
SetTimer dq ?
WaitForEvent dq ?
SignalEvent dq ?
CloseEvent dq ?
CheckEvent dq ?
InstallProtocolInterface dq ?
ReInstallProtocolInterface dq ?
UnInstallProtocolInterface dq ?
HandleProtocol dq ?
Void dq ?
RegisterProtocolNotify dq ?
LocateHandle dq ?
LocateDevicePath dq ?
InstallConfigurationTable dq ?
ImageLoad dq ?
ImageStart dq ?
Exit dq ?
ImageUnLoad dq ?
ExitBootServices dq ?
GetNextMonotonicCount dq ?
Stall dq ?
SetWatchdogTimer dq ?
ConnectController dq ?
DisConnectController dq ?
OpenProtocol dq ?
CloseProtocol dq ?
OpenProtocolInformation dq ?
ProtocolsPerHandle dq ?
LocateHandleBuffer dq ?
LocateProtocol dq ?
InstallMultipleProtocolInterfaces dq ?
UnInstallMultipleProtocolInterfaces dq ?
CalculateCrc32 dq ?
CopyMem dq ?
SetMem dq ?
GetTime DN ?
SetTime DN ?
GetWakeUpTime DN ?
SetWakeUpTime DN ?
SetVirtualAddressMap DN ?
ConvertPointer DN ?
GetVariable DN ?
GetNextVariableName DN ?
SetVariable DN ?
GetNextHighMonoCount DN ?
ResetSystem DN ?
ends
struct EFI_RUNTIME_SERVICES_TABLE
Hdr EFI_TABLE_HEADER
GetTime dq ?
SetTime dq ?
GetWakeUpTime dq ?
SetWakeUpTime dq ?
SetVirtualAddressMap dq ?
ConvertPointer dq ?
GetVariable dq ?
GetNextVariableName dq ?
SetVariable dq ?
GetNextHighMonoCount dq ?
ResetSystem dq ?
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
Revision dq ?
OpenVolume dq ?
Revision DQ ?
OpenVolume DN ?
ends
EFI_FILE_MODE_READ = 1
EFI_FILE_MODE_WRITE = 2
EFI_FILE_MODE_CREATE = 0x8000000000000000
struct EFI_FILE_PROTOCOL
Revision dq ?
Open dq ?
Close dq ?
Delete dq ?
Read dq ?
Write dq ?
GetPosition dq ?
SetPosition dq ?
GetInfo dq ?
SetInfo dq ?
Flush dq ?
OpenEx dq ?
ReadEx dq ?
WriteEx dq ?
FlushEx dq ?
Revision DQ ?
Open DN ?
Close DN ?
Delete DN ?
Read DN ?
Write DN ?
GetPosition DN ?
SetPosition DN ?
GetInfo DN ?
SetInfo DN ?
Flush DN ?
OpenEx DN ?
ReadEx DN ?
WriteEx DN ?
FlushEx DN ?
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
QueryMode dq ?
SetMode dq ?
Blt dq ?
Mode dq ?
QueryMode DN ?
SetMode DN ?
Blt DN ?
Mode DN ?
ends
struct EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
MaxMode dd ?
Mode dd ?
nfo dq ?
SizeOfInfo dq ?
FrameBufferBase dq ?
FrameBufferSize dq ?
Info DN ?
SizeOfInfo DN ?
FrameBufferBase 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
struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
@ -299,217 +267,6 @@ struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
HorizontalResolution dd ?
VerticalResolution dd ?
PixelFormat dd ?
RedMask dd ?
GreenMask dd ?
BlueMask dd ?
Reserved dd ?
PixelInformation EFI_PIXEL_BITMASK
PixelsPerScanLine dd ?
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
section '.text' code executable readable
@ -6,7 +14,9 @@ section '.text' code executable readable
include '../../struct.inc'
include '../../macros.inc'
include '../../const.inc'
include 'uefi.inc'
purge DQ
include 'uefi64.inc'
MEMORY_MAP_SIZE = 0x4000
GOP_BUFFER_SIZE = 0x100
@ -44,8 +54,14 @@ end virtual
xor eax, eax
cmp [.fatal], 1
jnz .done
eficall ConOut, OutputString, ConOut, msg_error_open_file
eficall ConOut, OutputString, ConOut, [.name]
mov rbx, [efi_table]
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 $
@@:
@ -101,7 +117,6 @@ skip_newline:
skip_line:
call skip_until_newline
call skip_newline
.done:
ret
dec2bin:
@ -252,13 +267,17 @@ end virtual
ret 1*8
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
cmp eax, EFI_SUCCESS
jnz .error
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, \
sfsp_interface
cmp rax, EFI_SUCCESS
@ -285,16 +304,41 @@ read_options_from_config:
.error:
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:
mov [cfg_opt_used_resolution], 1
mov [cfg_opt_value_vmode], 0
.next_mode:
.next_mode:
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]
call print_vmode
; PixelBlueGreenRedReserved8BitPerColor
cmp [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1
jnz .skip_mode
@ -306,22 +350,38 @@ find_vmode_index_by_resolution:
cmp ax, [rdx+BOOT_LO.y_res]
jnz .skip_mode
jmp .done
.skip_mode:
.skip_mode:
inc [cfg_opt_value_vmode]
movzx eax, [cfg_opt_value_vmode]
mov rcx, [gop_interface]
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
mov [cfg_opt_used_resolution], 0
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:
.done:
ret
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:
.next_mode:
call clearbuf
mov eax, ebx
lea rdi, [msg]
@ -345,8 +405,10 @@ ask_for_params:
; mov eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
; lea rdi, [msg+14*2]
; call num2dec
.skip:
eficall ConOut, OutputString, ConOut, msg
.skip:
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
jnz .error
@ -358,13 +420,17 @@ ask_for_params:
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
jnz .error
xor ecx, ecx
@@:
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
mov rdx, EFI_DEVICE_ERROR
cmp rax, rdx
@ -381,30 +447,39 @@ ask_for_params:
sub eax, '0'
add ecx, eax
jmp @b
.key_done:
.key_done:
mov [cfg_opt_value_vmode], cl
.error:
.done:
ret
main:
sub rsp, 0x38
mov [efi_handle], rcx
mov [efi_table], rdx
; initialize UEFI library
InitializeLib
jc .error
; eficall ConOut, Reset, ConOut, 1
; cmp rax, EFI_SUCCESS
; jnz .error
eficall ConOut, ClearScreen, ConOut
cmp rax, EFI_SUCCESS
jnz .error
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset, rbx, 1
test eax, eax
jz @f
jmp $ ; what can I do here?
@@:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
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
; 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 KERNEL_BASE
@ -413,6 +488,10 @@ main:
call load_file
; 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 RAMDISK_BASE
@ -421,12 +500,24 @@ main:
call load_file
; alloc buffer for devices.dat
eficall BootServices, AllocatePages, EFI_ALLOCATE_MAX_ADDRESS, \
EFI_RESERVED_MEMORY_TYPE, 1, devicesdat_data
mov rbx, [efi_table]
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
jnz .error
; 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 [devicesdat_size]
push [devicesdat_data]
@ -435,24 +526,112 @@ main:
call load_file
mov [devicesdat_size], rax
eficall BootServices, LocateHandle, 2, gopuuid, 0, gop_buffer_size, \
gop_buffer
cmp eax, EFI_SUCCESS
jnz .error
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_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_locate_gop_handlers
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 rcx, [rbx+EFI_SYSTEM_TABLE.NumberOfTableEntries]
mov rax, 0x11d3e4f18868e871
mov rdx, 0x81883cc7800022bc
.next_table:
.next_table:
dec ecx
js .all_tables_done
cmp [rdi+0], rax
@ -463,13 +642,34 @@ main:
mov rdx, BOOT_LO.acpi_rsdp
mov [rdx], eax
jmp .all_tables_done
.not_acpi20:
.not_acpi20:
add rdi, 24
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
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
.not_used_resolution:
cmp [cfg_opt_used_debug_print], 0
@ -487,8 +687,19 @@ main:
movzx ecx, [cfg_opt_value_vmode]
eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode, \
[gop_interface], rcx
cmp eax, EFI_SUCCESS
jnz .error
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
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 rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
@ -518,13 +729,17 @@ main:
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
cmp eax, EFI_SUCCESS
jnz .error
eficall BootServices, GetMemoryMap, memory_map_size, [memory_map], \
memory_map_key, descriptor_size, descriptor_ver
mov rbx, [efi_table]
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
jnz .error
@ -537,7 +752,7 @@ main:
div ecx
mov ecx, eax
mov rsi, [memory_map]
.next_descr:
.next_descr:
call add_uefi_memmap
add rsi, [descriptor_size]
add rdi, sizeof.e820entry
@ -553,7 +768,10 @@ main:
; eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
; 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
jnz .error
@ -612,11 +830,10 @@ main:
push CODE_32_SELECTOR
lea rax, [.next]
push rax
; push .next
retf
use32
align 16
.next:
.next:
mov eax, cr0
and eax, not CR0_PG
mov cr0, eax
@ -634,12 +851,12 @@ align 16
retn
use64
.error:
eficall ConOut, OutputString, ConOut, msg_error
jmp .quit
.quit:
mov rcx, -1
loop $
.error:
mov rbx, [efi_table]
mov rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
msg_error
jmp $
; linux/arch/x86/platform/efi/efi.c
@ -647,11 +864,10 @@ use64
add_uefi_memmap:
push rax rbx rcx rdx rsi rdi
mov r10d, [rsi+0]
mov r11, [rsi+8]
; mov r12, [rsi+16]
mov r13, [rsi+24]
mov r14, [rsi+32]
mov r10d, [rsi+EFI_MEMORY_DESCRIPTOR.Type]
mov r11, [rsi+EFI_MEMORY_DESCRIPTOR.PhysicalStart]
mov r13, [rsi+EFI_MEMORY_DESCRIPTOR.NumberOfPages]
mov r14, [rsi+EFI_MEMORY_DESCRIPTOR.Attribute]
mov [rdi+e820entry.addr], r11
mov rax, r13
@ -679,7 +895,7 @@ add_uefi_memmap:
jz .case4
jmp .default
.case0:
.case0:
test r14, EFI_MEMORY_WB
jz @f
mov eax, E820_RAM
@ -687,23 +903,23 @@ add_uefi_memmap:
@@:
mov eax, E820_RESERVED
jmp .done
.case1:
.case1:
mov eax, E820_ACPI
jmp .done
.case2:
.case2:
mov eax, E820_NVS
jmp .done
.case3:
.case3:
mov eax, E820_UNUSABLE
jmp .done
.case4:
.case4:
mov eax, E820_PMEM
jmp .done
.default:
.default:
mov eax, E820_RESERVED
jmp .done
.done:
.done:
mov [rdi+e820entry.type], eax
mov rax, BOOT_LO.memmap_block_cnt
@ -718,7 +934,7 @@ num2dec:
xor ecx, ecx
mov ebx, 10
.next_digit:
.next_digit:
xor edx, edx
div ebx
push rdx
@ -726,7 +942,7 @@ num2dec:
test eax, eax
jnz .next_digit
.next_char:
.next_char:
pop rax
add eax, '0'
stosw
@ -741,7 +957,7 @@ num2hex:
xchg rdx, rax
mov ecx, 16
.next_tetra:
.next_tetra:
rol rdx, 4
movzx eax, dl
and eax, 0x0f
@ -764,6 +980,9 @@ clearbuf:
ret
section '.data' data readable writeable
efi_handle dq 0
efi_table dq 0
uefi_rsptmp dq 0
GDTR:
dw 4*8-1
@ -794,10 +1013,10 @@ sfsp_interface dq 0
esp_root dq ?
file_handle dq ?
file_name du '\EFI\BOOT\KOLIBRI.INI',0
kernel_name du '\EFI\BOOT\KOLIBRI.KRN',0
ramdisk_name du '\EFI\BOOT\KOLIBRI.IMG',0
devicesdat_name du '\EFI\BOOT\DEVICES.DAT',0
file_name du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
kernel_name du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
ramdisk_name du '\EFI\KOLIBRIOS\KOLIBRI.IMG',0
devicesdat_name du '\EFI\KOLIBRIOS\DEVICES.DAT',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, \
@ -816,67 +1035,86 @@ config_options dq cfg_opt_name_resolution, cfg_opt_func_resolution, \
cfg_opt_cmnt_syspath, \
0
cfg_opt_name_resolution db 'resolution',0
cfg_opt_name_acpi db 'acpi',0
cfg_opt_name_debug_print db 'debug_print',0
cfg_opt_name_launcher_start db 'launcher_start',0
cfg_opt_name_mtrr db 'mtrr',0
cfg_opt_name_ask_params db 'ask_params',0
cfg_opt_name_imgfrom db 'imgfrom',0
cfg_opt_name_syspath db 'syspath',0
cfg_opt_name_resolution db "resolution",0
cfg_opt_name_acpi db "acpi",0
cfg_opt_name_debug_print db "debug_print",0
cfg_opt_name_launcher_start db "launcher_start",0
cfg_opt_name_mtrr db "mtrr",0
cfg_opt_name_ask_params db "ask_params",0
cfg_opt_name_imgfrom db "imgfrom",0
cfg_opt_name_syspath db "syspath",0
cfg_opt_cmnt_resolution db "# Graphic mode",0
cfg_opt_cmnt_acpi db "# ACPI settings",0xa, \
"# 0: don't use",0xa, \
"# 1: parse ACPI tables",0xa, \
"# 2: + call _PIC method",0xa, \
"# 3: + get APIC interrupts",0xa,0
cfg_opt_cmnt_debug_print db "# Duplicate debug output to the screen",0
cfg_opt_cmnt_resolution db "# Graphic mode",0
cfg_opt_cmnt_acpi db "# ACPI settings",0xa, \
"# 0: don't use",0xa, \
"# 1: parse ACPI tables",0xa, \
"# 2: + call _PIC method",0xa, \
"# 3: + get APIC interrupts",0xa,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_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_imgfrom db "# Where to load ramdisk image from",0
cfg_opt_cmnt_syspath db "# Path to /sys directory",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_imgfrom db "# Where to load ramdisk image from",0
cfg_opt_cmnt_syspath db "# Path to /sys directory",0
cfg_opt_used_resolution db 0
cfg_opt_used_acpi db 0
cfg_opt_used_debug_print db 0
cfg_opt_used_resolution db 0
cfg_opt_used_acpi db 0
cfg_opt_used_debug_print db 0
cfg_opt_used_launcher_start db 0
cfg_opt_used_mtrr db 0
cfg_opt_used_ask_params db 0
cfg_opt_used_imgfrom db 0
cfg_opt_used_syspath db 0
cfg_opt_used_mtrr db 0
cfg_opt_used_ask_params db 0
cfg_opt_used_imgfrom db 0
cfg_opt_used_syspath db 0
cfg_opt_value_vmode db 0
cfg_opt_value_acpi db 0
cfg_opt_value_debug_print db 0
cfg_opt_value_vmode db 0
cfg_opt_value_acpi db 0
cfg_opt_value_debug_print db 0
cfg_opt_value_launcher_start db 1
cfg_opt_value_mtrr db 0
cfg_opt_value_ask_params db 1
cfg_opt_value_imgfrom db RD_LOAD_FROM_MEMORY
cfg_opt_value_syspath db '/RD/1',0
rb 20
cfg_opt_value_mtrr db 0
cfg_opt_value_ask_params db 0
cfg_opt_value_imgfrom db RD_LOAD_FROM_MEMORY
cfg_opt_value_syspath db "/RD/1",0
rb 20
memory_map_key dq 0
descriptor_size dq 0
descriptor_ver dq 0
memory_map_size dq MEMORY_MAP_SIZE
msg_success du 'Success!',13,10,0
msg_error du 'Error!',13,10,0
msg du 79 dup ' ',13,10,0
msg_error_open_file du "Error: can't open file ",0
msg_u4k_loaded du "uefi64kos loaded",13,10,0
msg_read_options du "Read options from config file",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 du 79 dup " ",13,10,0
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
efi_fs_info EFI_FILE_SYSTEM_INFO
;section '.bss' data readable writeable
memory_map dq ?
gop_buffer rb GOP_BUFFER_SIZE
lip_buffer rb LIP_BUFFER_SIZE
gop_buffer rq GOP_BUFFER_SIZE/8
devicesdat_data dq 0xffffffff
devicesdat_size dq 0x1000
status dq ?
section '.reloc' fixups data discardable