From d0e6bdb758d2424ff9efcc1d83a662a6f2b5fafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 11 Jul 2022 01:22:34 +0100 Subject: [PATCH] hex0.S: implement open_protocol function. --- amd64/Development/hex0.S | 41 ++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/amd64/Development/hex0.S b/amd64/Development/hex0.S index 4a73119..d6c9d27 100644 --- a/amd64/Development/hex0.S +++ b/amd64/Development/hex0.S @@ -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