hex0.S: implement open_protocol function.

This commit is contained in:
Andrius Štikonas 2022-07-11 01:22:34 +01:00
parent 9cb1d5b7f0
commit d0e6bdb758
1 changed files with 31 additions and 10 deletions

View File

@ -2,25 +2,46 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Calling convention:
# First four arguments are passed via registers but we need to leave stack space
.global _start
.text
_start:
mov [ImageHandle], rcx # ImageHandle *image
mov [SystemTable], rdx # SystemTable *system
sub rsp, 64
mov [ImageHandle], rcx # ImageHandle *image_handle
mov rax, [rdx+96] # system->boot
mov [SystemBoot], rax # save system->boot
lea rdx, [hello] # arg2 = "Hello World"
mov rcx, [SystemTable] # system
mov rcx, [rcx+64] # arg1 = system->out
call [rcx+8]
# Open Loaded Image protocol
# arg1 = ImageHandle
mov rdx, [LOADED_IMAGE_PROTOCOL] # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
mov [rsp+48], rdx # save onto stack
mov rdx, [LOADED_IMAGE_PROTOCOL+8]# EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
mov [rsp+56], rdx # save onto stack
lea rdx, [rsp+48] # arg2 = &EFI_LOADED_IMAGE_PROTOCOL_GUID
# arg3 = &image
mov r9, rcx # arg4 = image_handle
mov qword ptr [rsp+32], 0 # arg5 = NULL
mov qword ptr [rsp+40], 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
call [rax+280] # system->boot->open_protocol();
add rsp, 64
# Command line args
Done:
mov rax, 0 # rax = 0
ret
.data
hello: .asciz "H\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d\0!\0\n\0\r\0\0"
ImageHandle: .quad 0
SystemTable: .quad 0
SystemBoot: .quad 0
# Protocol GUIDs
LOADED_IMAGE_PROTOCOL:
.long 0x5b1b31a1
.short 0x9562
.short 0x11d2
.byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b