forked from KolibriOS/kolibrios
Add UEFI stuff.
git-svn-id: svn://kolibrios.org@7130 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f208e0e454
commit
c14a80d34f
@ -733,6 +733,7 @@ end
|
||||
|
||||
-- generate tup rule for kolibri.img
|
||||
tup.definerule{inputs = input_deps, command = make_img_command, outputs = {"kolibri.img"}}
|
||||
tup.definerule{inputs = {"../kernel/trunk/boot/uefi4kos.asm"}, extra_inputs = {"kolibri.img", "../kernel/trunk/kernel.bin"}, command = "fasm %f %o", outputs = {"kolibri.efi"}}
|
||||
|
||||
-- generate command and dependencies for mkisofs
|
||||
input_deps = {"kolibri.img"}
|
||||
|
464
kernel/trunk/boot/uefi.inc
Normal file
464
kernel/trunk/boot/uefi.inc
Normal file
@ -0,0 +1,464 @@
|
||||
;*********************************************************************
|
||||
;* *
|
||||
;* UEFI library for fasm by bzt, Public Domain *
|
||||
;* *
|
||||
;*********************************************************************
|
||||
|
||||
; EFI_MEMORY_TYPE
|
||||
EFI_RESERVED_MEMORY_TYPE = 0
|
||||
EFI_LOADER_CODE = 1
|
||||
EFI_LOADER_DATA = 2
|
||||
EFI_BOOT_SERVICES_CODE = 3
|
||||
EFI_BOOT_SERVICES_DATA = 4
|
||||
EFI_RUNTIME_SERVICES_CODE = 5
|
||||
EFI_RUNTIME_SERVICES_DATA = 6
|
||||
EFI_CONVENTIONAL_MEMORY = 7
|
||||
EFI_UNUSABLE_MEMORY = 8
|
||||
EFI_ACPI_RECLAIM_MEMORY = 9
|
||||
EFI_ACPI_MEMORY_NVS = 10
|
||||
EFI_MEMORY_MAPPED_IO = 11
|
||||
EFI_MEMORY_MAPPED_IO_PORT_SPACE = 12
|
||||
EFI_PAL_CODE = 13
|
||||
EFI_PERSISTENT_MEMORY = 14
|
||||
EFI_MAX_MEMORY_TYPE = 15
|
||||
|
||||
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
|
||||
|
||||
EFIERR = 0x8000000000000000
|
||||
EFI_SUCCESS = 0
|
||||
EFI_LOAD_ERROR = EFIERR or 1
|
||||
EFI_INVALID_PARAMETER = EFIERR or 2
|
||||
EFI_UNSUPPORTED = EFIERR or 3
|
||||
EFI_BAD_BUFFER_SIZE = EFIERR or 4
|
||||
EFI_BUFFER_TOO_SMALL = EFIERR or 5
|
||||
EFI_NOT_READY = EFIERR or 6
|
||||
EFI_DEVICE_ERROR = EFIERR or 7
|
||||
EFI_WRITE_PROTECTED = EFIERR or 8
|
||||
EFI_OUT_OF_RESOURCES = EFIERR or 9
|
||||
EFI_VOLUME_CORRUPTED = EFIERR or 10
|
||||
EFI_VOLUME_FULL = EFIERR or 11
|
||||
EFI_NO_MEDIA = EFIERR or 12
|
||||
EFI_MEDIA_CHANGED = EFIERR or 13
|
||||
EFI_NOT_FOUND = EFIERR or 14
|
||||
EFI_ACCESS_DENIED = EFIERR or 15
|
||||
EFI_NO_RESPONSE = EFIERR or 16
|
||||
EFI_NO_MAPPING = EFIERR or 17
|
||||
EFI_TIMEOUT = EFIERR or 18
|
||||
EFI_NOT_STARTED = EFIERR or 19
|
||||
EFI_ALREADY_STARTED = EFIERR or 20
|
||||
EFI_ABORTED = EFIERR or 21
|
||||
EFI_ICMP_ERROR = EFIERR or 22
|
||||
EFI_TFTP_ERROR = EFIERR or 23
|
||||
EFI_PROTOCOL_ERROR = EFIERR or 24
|
||||
|
||||
EFI_SYSTEM_TABLE_SIGNATURE equ 0x49,0x42,0x49,0x20,0x53,0x59,0x53,0x54
|
||||
struct EFI_TABLE_HEADER
|
||||
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 ?
|
||||
ends
|
||||
|
||||
|
||||
struct SIMPLE_INPUT_INTERFACE
|
||||
Reset dq ?
|
||||
ReadKeyStroke dq ?
|
||||
WaitForKey dq ?
|
||||
ends
|
||||
|
||||
struct EFI_BOOT_SERVICES_TABLE
|
||||
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 ?
|
||||
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_LOADED_IMAGE_PROTOCOL_UUID 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_UUID 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_UUID 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 ?
|
||||
ends
|
||||
|
||||
struct EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
|
||||
MaxMode dd ?
|
||||
Mode dd ?
|
||||
nfo dq ?
|
||||
SizeOfInfo dq ?
|
||||
FrameBufferBase dq ?
|
||||
FrameBufferSize dq ?
|
||||
ends
|
||||
|
||||
struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
|
||||
Version dd ?
|
||||
HorizontalResolution dd ?
|
||||
VerticalResolution dd ?
|
||||
PixelFormat dd ?
|
||||
RedMask dd ?
|
||||
GreenMask dd ?
|
||||
BlueMask dd ?
|
||||
Reserved dd ?
|
||||
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 uefi_call_wrapper 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
|
445
kernel/trunk/boot/uefi4kos.asm
Normal file
445
kernel/trunk/boot/uefi4kos.asm
Normal file
@ -0,0 +1,445 @@
|
||||
format pe64 dll efi at 0
|
||||
entry main
|
||||
|
||||
|
||||
section '.text' code executable readable
|
||||
|
||||
include '../struct.inc'
|
||||
include '../macros.inc'
|
||||
include '../const.inc'
|
||||
include 'uefi.inc'
|
||||
|
||||
MEMORY_MAP_SIZE = 0x4000
|
||||
GOP_BUFFER_SIZE = 0x800
|
||||
|
||||
KERNEL_BASE = 0x10000
|
||||
RAMDISK_BASE = 0x100000
|
||||
|
||||
CODE_32_SELECTOR = 8
|
||||
DATA_32_SELECTOR = 16
|
||||
CODE_64_SELECTOR = 24
|
||||
|
||||
; linux/arch/x86/include/uapi/asm/e820.h
|
||||
E820_RAM = 1
|
||||
E820_RESERVED = 2
|
||||
E820_ACPI = 3
|
||||
E820_NVS = 4
|
||||
E820_UNUSABLE = 5
|
||||
E820_PMEM = 7
|
||||
;E820_MAX = 128
|
||||
|
||||
main:
|
||||
sub rsp, 0x38
|
||||
; initialize UEFI library
|
||||
InitializeLib
|
||||
jc .error
|
||||
|
||||
; uefi_call_wrapper ConOut, Reset, ConOut, 1
|
||||
; cmp rax, EFI_SUCCESS
|
||||
; jnz .error
|
||||
|
||||
uefi_call_wrapper ConOut, ClearScreen, ConOut
|
||||
cmp rax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
; uefi_call_wrapper ConOut, OutputString, ConOut, msg_hello
|
||||
; cmp eax, EFI_SUCCESS
|
||||
; jnz .error
|
||||
|
||||
uefi_call_wrapper 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
|
||||
uefi_call_wrapper BootServices, HandleProtocol, qword [gop_handle], gopuuid, gop_interface
|
||||
cmp eax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
mov rbx, [efi_ptr]
|
||||
mov rdi, [rbx + EFI_SYSTEM_TABLE.ConfigurationTable]
|
||||
mov rcx, [rbx + EFI_SYSTEM_TABLE.NumberOfTableEntries]
|
||||
mov rax, 0x11d3e4f18868e871
|
||||
mov rdx, 0x81883cc7800022bc
|
||||
.next_table:
|
||||
dec ecx
|
||||
js .all_tables_done
|
||||
cmp [rdi + 0], rax
|
||||
jnz .not_acpi20
|
||||
cmp [rdi + 8], rdx
|
||||
jnz .not_acpi20
|
||||
mov rax, [rdi + 16]
|
||||
mov rdx, BOOT_ACPI_RSDP
|
||||
mov [rdx], eax
|
||||
;jmp $
|
||||
jmp .all_tables_done
|
||||
.not_acpi20:
|
||||
add rdi, 24
|
||||
jmp .next_table
|
||||
.all_tables_done:
|
||||
|
||||
xor ebx, ebx
|
||||
.next_mode:
|
||||
call clearbuf
|
||||
mov eax, ebx
|
||||
lea rdi, [msg]
|
||||
call num2dec
|
||||
|
||||
push rbx
|
||||
uefi_call_wrapper [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]
|
||||
cmp [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1 ; PixelBlueGreenRedReserved8BitPerColor
|
||||
jnz .skip
|
||||
mov eax, [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
|
||||
lea rdi, [msg+4*2]
|
||||
call num2dec
|
||||
mov eax, [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
|
||||
lea rdi, [msg+9*2]
|
||||
call num2dec
|
||||
; mov eax, [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
|
||||
; lea rdi, [msg+14*2]
|
||||
; call num2dec
|
||||
.skip:
|
||||
uefi_call_wrapper ConOut, OutputString, ConOut, msg
|
||||
cmp rax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
pop rbx
|
||||
inc rbx
|
||||
mov rcx, [gop_interface]
|
||||
mov rdx, [rcx + EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
|
||||
cmp ebx, [rdx + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
|
||||
jnz .next_mode
|
||||
|
||||
|
||||
uefi_call_wrapper ConIn, Reset, ConIn, 1
|
||||
cmp rax, EFI_SUCCESS
|
||||
jnz .error
|
||||
xor ecx, ecx
|
||||
@@:
|
||||
push rcx
|
||||
uefi_call_wrapper ConIn, ReadKeyStroke, ConIn, msg
|
||||
pop rcx
|
||||
mov rdx, EFI_DEVICE_ERROR
|
||||
cmp rax, rdx
|
||||
jz .error
|
||||
mov rdx, EFI_NOT_READY
|
||||
cmp rax, rdx
|
||||
jz @b
|
||||
; cmp rax, EFI_SUCCESS
|
||||
movzx eax, word[msg+2]
|
||||
;jmp .key_done
|
||||
cmp al, 0x0D
|
||||
jz .key_done
|
||||
imul ecx, 10
|
||||
sub eax, '0'
|
||||
add ecx, eax
|
||||
jmp @b
|
||||
.key_done:
|
||||
|
||||
uefi_call_wrapper [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode, [gop_interface], rcx
|
||||
cmp eax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
mov rcx, [gop_interface]
|
||||
mov rdx, [rcx + EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
|
||||
mov rdi, [rdx + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
|
||||
mov [fb_base], rdi
|
||||
|
||||
|
||||
mov ebx, [rdx + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
|
||||
uefi_call_wrapper [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]
|
||||
mov eax, [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
|
||||
xor rdx, rdx
|
||||
mov word [rdx + BOOT_X_RES], ax
|
||||
mov eax, [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
|
||||
mov word [rdx + BOOT_Y_RES], ax
|
||||
mov eax, [rcx + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
|
||||
shl eax, 2
|
||||
mov word [rdx + BOOT_PITCH], ax
|
||||
|
||||
mov byte [rdx + BOOT_PCI_DATA + 0], 1
|
||||
mov byte [rdx + BOOT_PCI_DATA + 1], 0
|
||||
mov byte [rdx + BOOT_PCI_DATA + 2], 0x10
|
||||
mov byte [rdx + BOOT_PCI_DATA + 3], 0x02
|
||||
mov dword [rdx + BOOT_PCI_DATA + 4], 0xe3
|
||||
|
||||
|
||||
uefi_call_wrapper BootServices, GetMemoryMap, memory_map_size, memory_map, memory_map_key, descriptor_size, descriptor_ver
|
||||
cmp eax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
mov rdi, BOOT_MEMMAP_BLOCK_CNT
|
||||
mov dword[rdi], 0
|
||||
mov rdi, BOOT_MEMMAP_BLOCKS
|
||||
mov rax, [memory_map_size]
|
||||
xor edx, edx
|
||||
mov rcx, [descriptor_size]
|
||||
div ecx
|
||||
mov ecx, eax
|
||||
mov rsi, memory_map
|
||||
.next_descr:
|
||||
call add_uefi_memmap
|
||||
add rsi, [descriptor_size]
|
||||
add rdi, sizeof.e820entry
|
||||
dec rcx
|
||||
cmp rcx, 0
|
||||
jnz .next_descr
|
||||
|
||||
mov [memory_map_size], MEMORY_MAP_SIZE
|
||||
uefi_call_wrapper BootServices, GetMemoryMap, memory_map_size, memory_map, memory_map_key, descriptor_size, descriptor_ver
|
||||
cmp eax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
uefi_call_wrapper BootServices, ExitBootServices, [efi_handler], [memory_map_key]
|
||||
cmp eax, EFI_SUCCESS
|
||||
jnz .error
|
||||
|
||||
|
||||
cli
|
||||
|
||||
mov rsi, kernel_bin_data_begin
|
||||
mov rdi, KERNEL_BASE
|
||||
mov rcx, (kernel_bin_data_end - kernel_bin_data_begin + 7) / 8
|
||||
rep movsq
|
||||
|
||||
mov rsi, kolibri_img_data_begin
|
||||
mov rdi, RAMDISK_BASE
|
||||
mov rcx, (kolibri_img_data_end - kolibri_img_data_begin + 7 ) / 8
|
||||
rep movsq
|
||||
|
||||
xor esi, esi
|
||||
mov byte[esi + BOOT_BPP], 32
|
||||
mov word[esi + BOOT_VESA_MODE], 0
|
||||
mov dword[esi + BOOT_BANK_SW], 0
|
||||
mov rdi, [fb_base]
|
||||
mov dword[esi + BOOT_LFB], edi
|
||||
mov byte[esi + BOOT_MTRR], 1
|
||||
mov byte[esi + BOOT_LAUNCHER_START], 1
|
||||
mov byte[esi + BOOT_DEBUG_PRINT], 1
|
||||
mov byte[esi + BOOT_DMA], 0
|
||||
; mov qword[esi + BOOT_PCI_DATA], 0
|
||||
mov dword[esi + BOOT_APM_ENTRY], 0
|
||||
mov word[esi + BOOT_APM_VERSION], 0
|
||||
mov dword[esi + BOOT_APM_FLAGS], 0
|
||||
mov word[esi + BOOT_APM_CODE_32], 0
|
||||
mov word[esi + BOOT_APM_CODE_16], 0
|
||||
mov word[esi + BOOT_APM_DATA_16], 0
|
||||
mov byte[esi + BOOT_BIOS_HD_CNT], 0
|
||||
mov word[esi + BOOT_BX_FROM_LOAD], 'r1' ; boot from /rd/1
|
||||
|
||||
|
||||
lgdt [cs:GDTR]
|
||||
|
||||
mov ax, DATA_32_SELECTOR
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
|
||||
push CODE_32_SELECTOR
|
||||
lea rax, [.next]
|
||||
push rax
|
||||
; push .next
|
||||
retf
|
||||
use32
|
||||
align 16
|
||||
.next:
|
||||
mov eax, cr0
|
||||
and eax, not CR0_PG
|
||||
mov cr0, eax
|
||||
|
||||
mov ecx, MSR_AMD_EFER
|
||||
rdmsr
|
||||
btr eax, 8 ; LME
|
||||
wrmsr
|
||||
|
||||
mov eax, cr4
|
||||
and eax, not CR4_PAE
|
||||
mov cr4, eax
|
||||
|
||||
push KERNEL_BASE
|
||||
retn
|
||||
|
||||
use64
|
||||
.error:
|
||||
uefi_call_wrapper ConOut, OutputString, ConOut, msg_error
|
||||
jmp .quit
|
||||
.quit:
|
||||
mov rcx, -1
|
||||
loop $
|
||||
|
||||
|
||||
; linux/arch/x86/platform/efi/efi.c
|
||||
; do_add_efi_memmap
|
||||
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 [rdi + e820entry.addr], r11
|
||||
mov rax, r13
|
||||
shl rax, 12
|
||||
mov [rdi + e820entry.size], rax
|
||||
|
||||
|
||||
cmp r10d, EFI_LOADER_CODE
|
||||
jz .case0
|
||||
cmp r10d, EFI_LOADER_DATA
|
||||
jz .case0
|
||||
cmp r10d, EFI_BOOT_SERVICES_CODE
|
||||
jz .case0
|
||||
cmp r10d, EFI_BOOT_SERVICES_DATA
|
||||
jz .case0
|
||||
cmp r10d, EFI_CONVENTIONAL_MEMORY
|
||||
jz .case0
|
||||
cmp r10d, EFI_ACPI_RECLAIM_MEMORY
|
||||
jz .case1
|
||||
cmp r10d, EFI_ACPI_MEMORY_NVS
|
||||
jz .case2
|
||||
cmp r10d, EFI_UNUSABLE_MEMORY
|
||||
jz .case3
|
||||
cmp r10d, EFI_PERSISTENT_MEMORY
|
||||
jz .case4
|
||||
jmp .default
|
||||
|
||||
.case0:
|
||||
test r14, EFI_MEMORY_WB
|
||||
jz @f
|
||||
mov eax, E820_RAM
|
||||
jmp .done
|
||||
@@:
|
||||
mov eax, E820_RESERVED
|
||||
jmp .done
|
||||
.case1:
|
||||
mov eax, E820_ACPI
|
||||
jmp .done
|
||||
.case2:
|
||||
mov eax, E820_NVS
|
||||
jmp .done
|
||||
.case3:
|
||||
mov eax, E820_UNUSABLE
|
||||
jmp .done
|
||||
.case4:
|
||||
mov eax, E820_PMEM
|
||||
jmp .done
|
||||
.default:
|
||||
mov eax, E820_RESERVED
|
||||
jmp .done
|
||||
|
||||
.done:
|
||||
mov [rdi + e820entry.type], eax
|
||||
|
||||
mov rax, BOOT_MEMMAP_BLOCK_CNT
|
||||
inc word[rax]
|
||||
|
||||
pop rdi rsi rdx rcx rbx rax
|
||||
ret
|
||||
|
||||
|
||||
num2dec:
|
||||
push rax rbx rcx rdx rsi rdi
|
||||
|
||||
xor ecx, ecx
|
||||
mov ebx, 10
|
||||
.next_digit:
|
||||
xor edx, edx
|
||||
div ebx
|
||||
push rdx
|
||||
inc ecx
|
||||
test eax, eax
|
||||
jnz .next_digit
|
||||
|
||||
.next_char:
|
||||
pop rax
|
||||
add eax, '0'
|
||||
stosw
|
||||
loop .next_char
|
||||
|
||||
pop rdi rsi rdx rcx rbx rax
|
||||
ret
|
||||
|
||||
|
||||
num2hex:
|
||||
push rax rbx rcx rdx rsi rdi
|
||||
|
||||
xchg rdx, rax
|
||||
mov ecx, 16
|
||||
.next_tetra:
|
||||
rol rdx, 4
|
||||
movzx eax, dl
|
||||
and eax, 0x0f
|
||||
movzx eax, byte[hex+eax]
|
||||
stosw
|
||||
loop .next_tetra
|
||||
|
||||
pop rdi rsi rdx rcx rbx rax
|
||||
ret
|
||||
|
||||
hex db '0123456789ABCDEF'
|
||||
|
||||
clearbuf:
|
||||
push rax rbx rcx rdx rsi rdi
|
||||
mov eax, 0x0020
|
||||
mov ecx, 79
|
||||
mov rdi, msg
|
||||
rep stosw
|
||||
pop rdi rsi rdx rcx rbx rax
|
||||
ret
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
GDTR:
|
||||
dw 4*8-1
|
||||
dq GDT
|
||||
GDT:
|
||||
dw 0, 0, 0, 0
|
||||
dw 0FFFFh,0,9A00h,0CFh ; 32-bit code
|
||||
dw 0FFFFh,0,9200h,0CFh ; flat data
|
||||
dw 0FFFFh,0,9A00h,0AFh ; 64-bit code
|
||||
|
||||
|
||||
fb_base dq 0
|
||||
|
||||
gopuuid db EFI_GRAPHICS_OUTPUT_PROTOCOL_UUID
|
||||
gop_buffer_size dq GOP_BUFFER_SIZE
|
||||
gop_handle dq 0
|
||||
gop_interface dq 0
|
||||
gop_info_size dq 0
|
||||
gop_info dq 0
|
||||
|
||||
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
|
||||
|
||||
memory_map rb MEMORY_MAP_SIZE
|
||||
gop_buffer rb GOP_BUFFER_SIZE
|
||||
|
||||
|
||||
kernel_bin_data_begin:
|
||||
file '../kernel.bin'
|
||||
kernel_bin_data_end:
|
||||
|
||||
kolibri_img_data_begin:
|
||||
file '../../../data/kolibri.img'
|
||||
kolibri_img_data_end:
|
||||
|
||||
align 16
|
||||
data fixups
|
||||
end data
|
@ -363,6 +363,7 @@ BOOT_BX_FROM_LOAD equ 0x905A ; word
|
||||
; low byte: a,b,c,d -- hdX, r -- rdX
|
||||
; high byte: symbol 'X' as in the line above, e.g. '1', not 1
|
||||
; see loader_doc.txt for details
|
||||
BOOT_ACPI_RSDP equ 0x905C ; dword
|
||||
|
||||
BOOT_BIOS_HD_CNT equ 0x907F ; byte number of BIOS hard disks
|
||||
BOOT_BIOS_HD equ 0x9080 ; Nbytes BIOS hard disks
|
||||
|
@ -457,6 +457,13 @@ acpi_locate:
|
||||
push ebx
|
||||
push edi
|
||||
|
||||
if defined UEFI
|
||||
; UEFI loader knows where RSDP is
|
||||
mov ebx, [BOOT_ACPI_RSDP]
|
||||
test ebx, ebx
|
||||
jz .done
|
||||
call .check
|
||||
else
|
||||
movzx ebx, word [0x40E]
|
||||
shl ebx, 4
|
||||
lea ecx, [ebx+1024]
|
||||
@ -470,6 +477,7 @@ acpi_locate:
|
||||
mov ebx, ACPI_HI_RSDP_WINDOW_START
|
||||
mov edi, ACPI_HI_RSDP_WINDOW_END
|
||||
call .check
|
||||
end if
|
||||
.done:
|
||||
mov eax, ebx
|
||||
pop edi
|
||||
|
Loading…
Reference in New Issue
Block a user