ExitBootServicesWorksNow

This commit is contained in:
Jezura777 2025-04-12 21:36:18 +02:00
parent 951ee15924
commit 871845f7c1
2 changed files with 66 additions and 31 deletions

View file

@ -60,21 +60,21 @@ main:
mov rdx, BootMsg mov rdx, BootMsg
call print call print
;.GetGOP: .GetGOP:
; mov rcx, EFI_GRAPHICS_OUTPUT_UUID mov rcx, EFI_GRAPHICS_OUTPUT_UUID
; mov rdx, 3 mov rdx, 3
; mov r8, Video mov r8, Video
;
; mov rax, [BootSrvc]
; call_safe [rax + EFI_BOOT_SERVICES_TABLE.LocateProtocol]
;
; cmp rax, EFI_SUCCES
; jne .error
;
; mov rax, [Video]
; mov rbx, [rax + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
; jmp . mov rax, [BootSrvc]
call_safe [rax + EFI_BOOT_SERVICES_TABLE.LocateProtocol]
cmp rax, EFI_SUCCES
jne .error
mov rax, [Video]
mov rbx, [rax + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
jmp .
; TODO: Get and store framebuffer ; TODO: Get and store framebuffer
; Getting the memory map is kind of harder (not in this case), normally ; Getting the memory map is kind of harder (not in this case), normally
@ -92,13 +92,13 @@ main:
.GetMemMap: .GetMemMap:
mov rax, [BootSrvc] mov rax, [BootSrvc]
lea rcx, [MemMapSize] mov rcx, MemMapSize
mov rdx, [MemMapBuff] mov rdx, [MemMapBuff]
lea r8, [MemMapKey] mov r8, MemMapKey
lea r9, [MemMapDescSize] mov r9, MemMapDescSize
; notice the last argument is moved to r10 and then "pushed" to the stack ; notice the last argument is moved to r10 and then "pushed" to the stack
; with 32bit offset ; with 32bit offset
lea r10, [MemMapDescVer] mov r10, 0
mov [rsp+32], r10 mov [rsp+32], r10
call [rax + EFI_BOOT_SERVICES_TABLE.GetMemoryMap] call [rax + EFI_BOOT_SERVICES_TABLE.GetMemoryMap]
@ -106,16 +106,7 @@ main:
; if it returns buffer too small run the function again as it filled out ; if it returns buffer too small run the function again as it filled out
; the needed buffer length ; the needed buffer length
cmp al, EFI_BUFFER_TOO_SMALL cmp al, EFI_BUFFER_TOO_SMALL
je .GetMemMap pushf
; if it returned something else it maybe a problem possible TODO: proper
; error handling for now it just puts out error and exits with non-zero code
cmp rax, EFI_SUCCESS
jne .error
; print a message saying that we didn't f**k up yet...
mov rdx, OKMsg
call print
; preparing args and calling ; preparing args and calling
; BootServices.ExitBootServices(*ImegeHandle, *MemMapKey) ; BootServices.ExitBootServices(*ImegeHandle, *MemMapKey)
@ -126,11 +117,44 @@ main:
call_safe [rax + EFI_BOOT_SERVICES_TABLE.ExitBootServices] call_safe [rax + EFI_BOOT_SERVICES_TABLE.ExitBootServices]
cmp rax, EFI_SUCCESS cmp rax, EFI_SUCCESS
jne .error je .after
mov rdx, ErrMsg
call print
popf
je .GetMemMap
.after:
mov rdx, OKMsg
call print
mov eax, EFI_SUCCESS mov eax, EFI_SUCCESS
jmp .exit jmp .exit
; if it returned something else it maybe a problem possible TODO: proper
; error handling for now it just puts out error and exits with non-zero code
; cmp rax, EFI_SUCCESS
; jne .error
; print a message saying that we didn't f**k up yet...
;mov rdx, OKMsg
;call print
; preparing args and calling
; BootServices.ExitBootServices(*ImegeHandle, *MemMapKey)
; mov rcx, [ImgHdl]
; mov rdx, [MemMapKey]
; mov rax, [BootSrvc]
; call_safe [rax + EFI_BOOT_SERVICES_TABLE.ExitBootServices]
; cmp rax, EFI_SUCCESS
; jne .error
; mov eax, EFI_SUCCESS
; jmp .exit
.error: .error:
mov rdx, ErrMsg mov rdx, ErrMsg
call print call print

View file

@ -299,6 +299,17 @@ struc EFI_GRAPHICS_OUTPUT_MODE_INFORMATION {
.PixelsPerScanline int32 .PixelsPerScanline int32
} }
struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
struc EFI_MEMORY_DESCRIPTOR {
.Type int32
.Pad int32
.PhysicalStart int64
.VirtualStart int64
.NumberOfPages int64
.Attribute int64
}
struct EFI_MEMORY_DESCRIPTOR
;---macros to make life easier--- ;---macros to make life easier---
;call it early, after entry point is the best ;call it early, after entry point is the best
macro InitializeLib macro InitializeLib