flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Use UEFI Graphics Output Protocol Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next |
Author |
|
Fulgurance 11 Apr 2020, 19:42
Okay, but i don't understang the way to access to GOP.
Into default FASM efi.inc implementation, the programmer have this for GUID: Code: gopuuid: db EFI_GRAPHICS_OUTPUT_PROTOCOL_UUID When he call uefi_wrapper, guid is passed as arg2: Code: uefi_call_wrapper BootServices, LocateHandle, 2, gopuuid, 0, tmp, qword [tmpbuff] But arg2 is stored into rdx, 64 bits register: Code: if ~ arg2 eq numarg = numarg + 1 if ~ arg2 eq rdx mov rdx, arg2 end if end if But GUID for GOP is too larger: EFI_GRAPHICS_OUTPUT_PROTOCOL_UUID equ 0deh, 0a9h, 42h,90h,0dch,023h,38h,04ah,96h,0fbh,7ah,0deh,0d0h,80h,51h,6ah = 128 bits Why into rdx ??? And to call GOP, need i to use BootService.LocateHandle? He return address ? Where ? And why he call function with RBX ? EFI call function with RAX. There are many strange things into this UEFI official implementation. (source: https://wiki.osdev.org/Uefi.inc) |
|||
11 Apr 2020, 19:42 |
|
bitRAKE 11 Apr 2020, 22:48
The calling convention is:
https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_x64_calling_convention The other registers are used because they are preserved across the CALL. uefi_call_wrapper/uefifunc confuses things because people try to map Linux calling convention to Win64ABI -- to use existing Linux tools. Just ignore that craziness on OSDev! We want to read the spec and directly code the right thing. EFI_BOOT_SERVICES.HandleProtocol() is the easiest way to directly get the interface. Code: mov rcx,[ImageHandle] mov rdx,gop_guid ; pointer mov r8,gop ; pointer where to put interface mov rax,[SystemTable] mov rax,[rax+EFI_SYSTEM_TABLE.BootServices] call [rax+EFI_BOOT_SERVICES.HandleProtocol] Any time a function asks for the EFI_GUID, you'll see *Protocol - it wants an address. Note how the spec says/shows to use OpenProtocol. revolution caught me cut-n-pasting. (That parameter is ignored in reality for fills. So, hard to type code with Grammarly on.) Edit: fixed. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup Last edited by bitRAKE on 11 Apr 2020, 23:00; edited 2 times in total |
|||
11 Apr 2020, 22:48 |
|
revolution 11 Apr 2020, 22:54
Something doesn't look right:
Code: mov rax,[SystemTable] mov rax,[EFI_SYSTEM_TABLE.BootServices] |
|||
11 Apr 2020, 22:54 |
|
DimonSoft 12 Apr 2020, 09:14
I’m really sorry to post this but maybe… (maybe!) this link is going to be useful?
https://wiki.osdev.org/Required_Knowledge |
|||
12 Apr 2020, 09:14 |
|
Fulgurance 12 Apr 2020, 10:45
I have seen i have forgotten gop_uuid is pointer ... It's the explanation of how to pass GUID as argument ... i'm officialy tired lol
Thanks you bitRAKE and revolution for your example and help, i think now i have understand |
|||
12 Apr 2020, 10:45 |
|
Fulgurance 12 Apr 2020, 15:14
Okay ! I have coded test now. I think is missing little thing, but i think i'm in the good way.
My code: Code: format pe64 efi entry Main section '.text' code readable executable Main: mov [SystemTable],rdx mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.SetAttribute] mov rdx,0000010b sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString] mov rdx,SystemMessage sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.SetAttribute] mov rdx,0001111b sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[rdx+EFISystemTable.ConOut] mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString] mov rdx,Message sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[rdx+EFISystemTable.BootServices] mov rax,[rcx+EFIBootServices.HandleProtocol] mov rdx,GUID.EFIGraphicsOutputProtocol mov r8,Interface.EFIGraphicsOutputProtocol sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[Interface.EFIGraphicsOutputProtocol] mov rax,[rcx+EFIGraphicsOutputProtocol.Blt] mov rdx,RectangleColor mov r8,0x2;EFIGraphicsOutputBltOperation.BufferToVideo mov r9,0x0 mov r10,0x0 mov r11,0x64 mov r12,0x64 mov r13,0xF mov r14,0xF sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] jmp $ section '.data' data readable writable include "GUID.fasm" include "Interface.fasm" include "EFIDataTypes.fasm" include "EFITableHeader.fasm" include "EFISystemTable.fasm" include "EFIBootServices.fasm" include "EFISimpleTextOutputProtocol.fasm" include "EFIGraphicsOutputProtocol.fasm" include "EFIGraphicsOutputBltOperation.fasm" SystemTable: dq ? SystemMessage: du '* EFI Boot: ',0x0 Message: du 'Test OK',0xD,0xA,0x0 RectangleColor: db 0xFF,0xFF,0xFF,? Implementation: Code: GUID: .EFIGraphicsOutputProtocol: dq 0x9042A9DE23DC4A38,0x96FB7ADED080516A Interface: .EFIGraphicsOutputProtocol: dq ? Last edited by Fulgurance on 12 Apr 2020, 21:49; edited 3 times in total |
|||
12 Apr 2020, 15:14 |
|
bitRAKE 12 Apr 2020, 16:37
DimonSoft wrote: I’m really sorry to post this but maybe… (maybe!) this link is going to be useful? UNIX experience HA! (It's good to know one's own bias!) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
12 Apr 2020, 16:37 |
|
DimonSoft 12 Apr 2020, 21:48
bitRAKE wrote:
I wouldn’t call this item the most important but it makes some sense as well. In this particular case, I was more worried about #4 and #11: assembly and platform. Maybe. |
|||
12 Apr 2020, 21:48 |
|
Fulgurance 12 Apr 2020, 21:51
I read and read again, but i don't see the problem ...
|
|||
12 Apr 2020, 21:51 |
|
bitRAKE 12 Apr 2020, 22:26
I can get two handles in QEMU with the GUID I posted.
(Not sure where yours came from.) Nothing likes the handles for some reason though. (I'm trying to find my error rather than just reverse engineer something else.) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
12 Apr 2020, 22:26 |
|
bitRAKE 12 Apr 2020, 23:04
Success!
Code: FORMAT PE64 EFI AT 0 ON 'NUL' SECTION '.text' CODE EXECUTABLE READABLE WRITEABLE virtual at 0 EFI_SYSTEM_TABLE: .Hdr rb 24 .FirmwareVendor rq 1 .FirmwareRevision rd 1 rd 1 .ConsoleInHandle rq 1 .ConIn rq 1 .ConsoleOutHandle rq 1 .ConOut rq 1 .StandardErrorHandle rq 1 .StdErr rq 1 .RuntimeServices rq 1 .BootServices rq 1 .NumberOfTableEntries rd 2 .ConfigurationTable rq 1 end virtual virtual at 0 EFI_RUNTIME_SERVICES: .Hdr rb 24 .GetTime rq 1 .SetTime rq 1 .GetWakeupTime rq 1 .SetWakeupTime rq 1 .SetVirtualAddressMap rq 1 .ConvertPointer rq 1 .GetVariable rq 1 .GetNextVariableName rq 1 .SetVariable rq 1 .GetNextHighMonotonicCount rq 1 .ResetSystem rq 1 .UpdateCapsule rq 1 .QueryCapsuleCapabilities rq 1 .QueryVariableInfo rq 1 end virtual virtual at 0 EFI_BOOT_SERVICES: .Hdr rb 24 .RaiseTPL rq 1 .RestoreTPL rq 1 .AllocatePages rq 1 .FreePages rq 1 .GetMemoryMap rq 1 .AllocatePool rq 1 .FreePool rq 1 .CreateEvent rq 1 .SetTimer rq 1 .WaitForEvent rq 1 .SignalEvent rq 1 .CloseEvent rq 1 .CheckEvent rq 1 .InstallProtocolInterface rq 1 .ReinstallProtocolInterface rq 1 .UninstallProtocolInterface rq 1 .HandleProtocol rq 1 rq 1 .RegisterProtocolNotify rq 1 .LocateHandle rq 1 .LocateDevicePath rq 1 .InstallConfigurationTable rq 1 .LoadImage rq 1 .StartImage rq 1 .Exit rq 1 .UnloadImage rq 1 .ExitBootServices rq 1 .GetNextMonoticCount rq 1 .Stall rq 1 .SetWatchdogTimer rq 1 .ConnectController rq 1 .DisconnectController rq 1 .OpenProtocol rq 1 .CloseProtocol rq 1 .OpenProtocolInformation rq 1 .ProcotocolsPerHandle rq 1 .LocateHandleBuffer rq 1 .LocateProtocol rq 1 .InstallMultipleProtocolInterfaces rq 1 .UninstallMultipleProtocolInterfaces rq 1 .CalculateCrc32 rq 1 .CopyMem rq 1 .SetMem rq 1 .CreateEventEx rq 1 end virtual AllHandles = 0 ByRegisterNotify = 1 ByProtocol = 2 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL = 0x01 EFI_OPEN_PROTOCOL_GET_PROTOCOL = 0x02 EFI_OPEN_PROTOCOL_TEST_PROTOCOL = 0x04 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER = 0x08 EFI_OPEN_PROTOCOL_BY_DRIVER = 0x10 EFI_OPEN_PROTOCOL_EXCLUSIVE = 0x20 virtual at 0 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL: .Reset rq 1 .OutputString rq 1 .TestString rq 1 .QueryMode rq 1 .SetMode rq 1 .SetAttribute rq 1 .ClearScreen rq 1 .SetCursorPosition rq 1 .EnableCursor rq 1 .Mode rq 1 end virtual virtual at 0 EFI_GRAPHICS_OUTPUT_PROTOCOL: .QueryMode rq 1 .SetMode rq 1 .Blt rq 1 .Mode rq 1 end virtual align 64 ; cacheline friendly _hex: db "0123456789ABCDEF" _0F: db 16 dup (0xF) _REV: rept 16 i { db 16-i } align 16 gop_guid dq $4A3823DC9042A9DE,$6A5180D0DE7AFB96 ImageHandle rq 1 SystemTable rq 1 gop rq 1 Red_Pixel db 0,0,-1,0 ; EFI_GRAPHICS_OUTPUT_BLT_PIXEL array of one item ;############################################################################### entry $ mov rax,rsp enter 1024,0 mov [ImageHandle],rcx mov [SystemTable],rdx call Debug__ConOut du " RSP Address",13,10,0 mov ecx,ByProtocol mov rdx,gop_guid xor r8,r8 lea r9,[rsp+8*6] ; by reference, open to change lea rax,[rsp+8*7] ; buffer pointer put here mov [rsp+8*4],rax mov rax,[SystemTable] mov rax,[rax+EFI_SYSTEM_TABLE.BootServices] call [rax+EFI_BOOT_SERVICES.LocateHandleBuffer] call Debug__ConOut du " LocateHandleBuffer",13,10," ",0 mov rax,[rsp+8*7] call Debug__ConOut du " Buffer",13,10," ",0 mov rax,[rsp+8*6] call Debug__ConOut du " Handles",13,10,0 cmp qword[rsp+8*6],0 jz Shutdown mov rbx,[rsp+8*7] @@: mov rcx,[rbx] mov rdx,gop_guid ; pointer mov r8,gop ; pointer where to put interface mov r9,[ImageHandle] and qword[rsp+8*4],0 mov qword[rsp+8*5],EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL mov rax,[SystemTable] mov rax,[rax+EFI_SYSTEM_TABLE.BootServices] call [rax+EFI_BOOT_SERVICES.OpenProtocol] test rax,rax js not_okay mov qword [rsp+8*6],1 ; just to stop early not_okay: call Debug__ConOut du " OpenProtocol, for handle ",0 mov rax,[rbx] call Debug__ConOut du 13,10,0 add rbx,8 sub qword [rsp+8*6],1 ja @B mov rcx,[rsp+8*7] mov rax,[SystemTable] mov rax,[rax+EFI_SYSTEM_TABLE.BootServices] call [rax+EFI_BOOT_SERVICES.FreePool] call Debug__ConOut du " FreePool",13,10,0 mov rcx,[gop] ; EFI_GRAPHICS_OUTPUT_PROTOCOL mov rdx,Red_Pixel mov r8,0 ; EfiBltVideoFill mov r9,0 ; source X mov qword[rsp + 8*4],0 ; source Y mov qword[rsp + 8*5],0 ; destination X mov qword[rsp + 8*6],0 ; destination Y mov qword[rsp + 8*7],16 ; width mov qword[rsp + 8*8],16 ; height mov qword[rsp + 8*9],0 ; delta call [rcx + EFI_GRAPHICS_OUTPUT_PROTOCOL.Blt] call Debug__ConOut du " Blt",13,10,0 mov ecx,$FFFFFFF ; cheezy few second pause in QEMU loop $ Shutdown: push 2 pop rcx ; rcx = 2 = shutDown xor edx,edx ; rdx = status xor r8,r8 ; r8 = size of info buffer xor r9,r9 ; r9 = info buffer (none) mov rax,[SystemTable] mov rax,[rax+EFI_SYSTEM_TABLE.RuntimeServices] call [rax+EFI_RUNTIME_SERVICES.ResetSystem] jmp $ Debug__ConOut: ; output RAX in hex: push 0 0 0 0 0 mov rdx,rsp call QWORD__toWideChar call WideChar__ConOut add rsp,8*5 xchg [rsp],rdi mov rdx,rdi xor eax,eax or ecx,-1 repnz scasw xchg [rsp],rdi WideChar__ConOut: enter 32,0 and spl,$F0 ; mov rdx,string mov rcx,[SystemTable] mov rcx,[rcx + EFI_SYSTEM_TABLE.ConOut] call [rcx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] leave retn QWORD__toWideChar: movq xmm0,rax movdqa xmm1,xmm0 psrlw xmm0,4 punpcklbw xmm1,xmm0 movdqa xmm0,dqword [_hex] pand xmm1,dqword [_0F] pshufb xmm0,xmm1 pshufb xmm0,dqword [_REV] movdqa xmm1,xmm0 punpcklbw xmm0,[rdx] punpckhbw xmm1,[rdx] movdqu dqword [rdx],xmm0 movdqu dqword [rdx+16],xmm1 retn ; Disable watchdog timer: xor ecx,ecx xor edx,edx xor r8,r8 xor r9,r9 mov rax,[SystemTable] mov rax,[rax+EFI_SYSTEM_TABLE.BootServices] call [rax+EFI_BOOT_SERVICES.SetWatchdogTimer] ; a start address of zero forces relocation, ; which requires a relocation table section '.reloc' fixups data discardable _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
12 Apr 2020, 23:04 |
|
Fulgurance 13 Apr 2020, 10:21
Nice mdr. Very nice. I would like to understand why i haven't the same result
Edit: i have tested your code into USB bootable EFI with qemu with my laptop, but your code don't work lol |
|||
13 Apr 2020, 10:21 |
|
bitRAKE 13 Apr 2020, 10:37
Could you post the error codes displayed on the console? Do you have any working graphics applications for EFI? If not, try the BMP display utility here: https://github.com/fpmurphy/UEFI-Utilities-2019 - just to confirm your QEMU setup isn't the problem.
I should also note: on real hardware, it will flash for a fraction of a second and reset the machine. It's coded this way to make my debugging in QEMU easier. I have tested it on two different hardware setups here. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
13 Apr 2020, 10:37 |
|
Fulgurance 13 Apr 2020, 12:09
I have tested your code into VirtualBox, it work with uefi.
My code work with uefi. I have just problem with the part to call GOP. I think something is bad, but i don't see what. And just little question about your code. You don't put the same GUID number than in documentation, why ? Code: gop_guid dq $4A3823DC9042A9DE,$6A5180D0DE7AFB96 |
|||
13 Apr 2020, 12:09 |
|
bitRAKE 13 Apr 2020, 13:58
It is the same number. I'm moving to fasmg and will make a macro to convert the form in the documentation. So, I can just copy/paste.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
13 Apr 2020, 13:58 |
|
Fulgurance 13 Apr 2020, 14:14
Oh okay.
Do you know why my code don't work ? |
|||
13 Apr 2020, 14:14 |
|
bitRAKE 13 Apr 2020, 18:34
Code: mov rdx,[SystemTable] mov rcx,[rdx+EFISystemTable.BootServices] mov rax,[rcx+EFIBootServices.HandleProtocol] mov rdx,GUID.EFIGraphicsOutputProtocol mov r8,Interface.EFIGraphicsOutputProtocol sub rsp,0x20 call rax add rsp,0x20 |
|||
13 Apr 2020, 18:34 |
|
Fulgurance 13 Apr 2020, 19:33
If i understand good, i need before call HandleProtocol to call Locate Handle ?
|
|||
13 Apr 2020, 19:33 |
|
Fulgurance 13 Apr 2020, 21:23
Okay, i have updated my code.I'm not sure i have understand all. My code don't show red rectangle actually. If i have understand good, in first, i localize the handle (i use the ByProtocol option). In second, i call HandleProtocol service, and at the last, i can use GOP ?
This is my code: Code: ;-------------------------------------------------------- mov rcx,[rdx+EFISystemTable.BootServices] mov rax,[rcx+EFIBootServices.LocateHandle] mov rdx,EFILocateSearchType.ByProtocol mov r8,GUID.EFIGraphicsOutputProtocol xor r9,r9 mov r10,0x40 mov r11,Interface.EFIGraphicsOutputProtocol sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[rdx+EFISystemTable.BootServices] mov rax,[rcx+EFIBootServices.HandleProtocol] mov rdx,GUID.EFIGraphicsOutputProtocol mov r8,Interface.EFIGraphicsOutputProtocol sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] mov rcx,[Interface.EFIGraphicsOutputProtocol] mov rax,[rcx+EFIGraphicsOutputProtocol.Blt] mov rdx,RectangleColor mov r8,EFIGraphicsOutputBltOperation.BufferToVideo mov r9,0x0 mov r10,0x0 mov r11,0x64 mov r12,0x64 mov r13,0xF mov r14,0xF mov rsi,0x0 sub rsp,0x20 call rax add rsp,0x20 mov rdx,[SystemTable] jmp $ section '.data' data readable writable include "GUID.fasm" include "Interface.fasm" include "EFIDataTypes.fasm" include "EFITableHeader.fasm" include "EFISystemTable.fasm" include "EFIBootServices.fasm" include "EFILocateSearchType.fasm" include "EFISimpleTextOutputProtocol.fasm" include "EFIGraphicsOutputProtocol.fasm" include "EFIGraphicsOutputBltOperation.fasm" SystemTable: dq ? SystemMessage: du '* ',0x0 Message: du 'EFI Boot: Test OK',0xD,0xA,0x0 RectangleColor: db 0xFF,0xFF,0xFF,? |
|||
13 Apr 2020, 21:23 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.