flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Use UEFI Graphics Output Protocol

Goto page 1, 2, 3, 4, 5, 6  Next
Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Hello, i have question about GOP. I have seen this UEFI protocol can using to draw something into screen. But i don't understand how to access to this function.

It's not into EFI_SYSTEM_TABLE...
Post 10 Apr 2020, 12:38
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3018
Location: vpcmipstrm
bitRAKE
If the handle (ImageHandle for an application) can access the protocol, it's GUID can be used to return a pointer to the interface through EFI_BOOT_SERVICES.OpenProtocol. This is slightly analogous to the way COM works.
Post 10 Apr 2020, 15:39
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Hum, okay. But there aren't any information how can i use this fonction into UEFI documentation. Can you give me an example please. I don't understand how can i do that. What is GUID ?

And sorry, but i have never coding COM files...
Post 10 Apr 2020, 16:40
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 807
Location: Belarus
DimonSoft
It’s not about COM files, it’s about COM interfaces, a completely unrelated thing.
Post 10 Apr 2020, 18:18
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Ohokay. I don't know COM interface.Have you got some example please ?
Post 10 Apr 2020, 19:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17624
Location: In your JS exploiting you and your system
revolution
Post 10 Apr 2020, 19:26
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3018
Location: vpcmipstrm
bitRAKE
If you don't know what a GUID is then you've hardly read enough of the spec, IMHO. I'm sorry that the learning curve is so steep. There are examples:

https://github.com/fabianishere/boot2flappy - cool graphic game for UEFI (see https://github.com/fabianishere/boot2flappy/blob/9b1aced88a33e31f95c1a61614f4b53dc2147458/src/efi-x86_64/graphics.s#L51)

Ferno has converted his debugger FDBG to work on EFI, but it's not gfx, but is a larger example of EFI use. It's on the board if you search.

Some other references:
https://en.wikipedia.org/wiki/Component_Object_Model
https://docs.microsoft.com/en-us/windows/win32/com/com-objects-and-interfaces

UEFI differs from COM in that interfaces do not inherit from IUnknown, and the firmware restricts interface use by handle. But a lot of cool additional features exist as well. Creating your own protocols for the hardware you have. These can stay resident after the OS takes over. Replacing firmware UEFI protocols with your own implementations, etc.

_________________
¯\(°_o)/¯ unlicense.org
Post 10 Apr 2020, 19:27
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
https://yadi.sk/d/HTs1wxZvp6BmYw see subfolder "\DEMOS\EXECS\WINDOWS\WIN32\COM_TECH" there 2 folders "CLIENTS" & "SERVERS" (COM is client-server technology).
sources are compilable with includes path like in file fasmw.ini in subfolder "\BIN".

example of using COM(as client) in EasyCode package (package is crossassembler IDE) of forum member EasyCode.

all rest about COM exist only in HLL.

[EDITED]because UEFI differs from COM, beter read what suggested bitRAKE.
Post 10 Apr 2020, 19:36
View user's profile Send private message Send e-mail Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3018
Location: vpcmipstrm
bitRAKE
If you are on windows, this example works well:
https://github.com/nebulaeonline/nebulae

This is a project to keep an eye on.

_________________
¯\(°_o)/¯ unlicense.org
Post 10 Apr 2020, 22:59
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
bitRAKE wrote:
If you are on windows, this example works well:
https://github.com/nebulaeonline/nebulae

This is a project to keep an eye on.


I'm Gentoo Linux user
Post 11 Apr 2020, 09:48
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Oh yes, i'm stupid, GUID ... simply GUID partition table (GPT) Yes i see.
But i don't understand how GUID can help me to call Graphical function. I'm going to read yours links, and i come again if i have some questions

But... hey ! Now i think i have understand something.

First install protocol with boot service and pass Graphics Output Protocol at argument with him GUID ?

And after call it ? Is it something else ?
Post 11 Apr 2020, 09:53
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Okay, i have read all, and i have coded that. But i'm not sure about my way to pass GUID arguments.Is it two 64 bits parameters ? i'm not sure about BltOperation, is it bolean or the same as efi offset ?

And how can i pass the last arguments ? With stack ?

Look:

Code:
format pe64 efi
entry Main

section '.text' code readable executable

Main:
mov [SystemTable],rdx
mov rcx,[rdx+EFISystemTable.BootServices]
mov rax,[rcx+EFIBootServices.OpenProtocol]
mov rdx,0x9042a9de23dc4a38
mov r8,0x96fb7aded080516a
mov r9,[rax+EFIGraphicsOutputProtocol.Blt]
mov r10,RectangleColor
mov r11,EFIGraphicsOutputBltOperation.BufferToVideo
mov r12,0x0
mov r13,0x0
mov r14,0x64
mov rsi,0x64
mov rdi,0xF

sub rsp,0x20
call rax
add rsp,0x20

mov rdx,[SystemTable]

jmp $

section '.data' data readable writable

include "UEFIDataTypes.fasm"
include "EFITableHeader.fasm"
include "EFISystemTable.fasm"
include "EFIBootServices.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,?
    
[/code]


Last edited by Fulgurance on 11 Apr 2020, 13:26; edited 2 times in total
Post 11 Apr 2020, 13:20
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
struc EFIInteger8
{
    . db ?
}

struc EFIInteger16
{
    align 2
    . dw ?
}

struc EFIInteger32
{
    align 4
    . dd ?
}

struc EFIInteger64
{
    align 8
    . dq ?
}

macro EFITable name
{
    virtual at 0
    name name
    end virtual
}
    
Post 11 Apr 2020, 13:21
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
struc EFITableHeader
{
    .Signature     EFIInteger64
    .Revision      EFIInteger32
    .HeaderSize    EFIInteger32
    .CRC32         EFIInteger32
    .Reserved      EFIInteger32
}

EFITable EFITableHeader
    
Post 11 Apr 2020, 13:21
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
struc EFISystemTable
{
    .Hdr                   EFITableHeader
    .FirmwareVendor        EFIInteger64
    .FirmwareRevision      EFIInteger32
    .ConsoleInHandle       EFIInteger64
    .ConIn                 EFIInteger64
    .ConsoleOutHandle      EFIInteger64
    .ConOut                EFIInteger64
    .StandardErrorHandle   EFIInteger64
    .StdErr                EFIInteger64
    .RuntimeServices       EFIInteger64
    .BootServices          EFIInteger64
    .NumberOfTableEntries  EFIInteger64
    .ConfigurationTable    EFIInteger64
}

EFITable EFISystemTable
    
Post 11 Apr 2020, 13:22
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
struc EFIBootServices
{
    .Hdr                                    EFITableHeader
    .RaiseTPL                               EFIInteger64
    .RestoreTPL                             EFIInteger64
    .AllocatePages                          EFIInteger64
    .FreePages                              EFIInteger64
    .GetMemoryMap                           EFIInteger64
    .AllocatePool                           EFIInteger64
    .FreePool                               EFIInteger64
    .CreateEvent                            EFIInteger64
    .SetTimer                               EFIInteger64
    .WaitForEvent                           EFIInteger64
    .SignalEvent                            EFIInteger64
    .CloseEvent                             EFIInteger64
    .CheckEvent                             EFIInteger64
    .InstallProtocolInterface               EFIInteger64
    .ReinstallProtocolInterface             EFIInteger64
    .UninstallProtocolInterface             EFIInteger64
    .HandleProtocol                         EFIInteger64
    .RegisterProtocolNotify                 EFIInteger64
    .LocateHandle                           EFIInteger64
    .LocateDevicePath                       EFIInteger64
    .InstallConfigurationTable              EFIInteger64
    .LoadImage                              EFIInteger64
    .StartImage                             EFIInteger64
    .Exit                                   EFIInteger64
    .UnloadImage                            EFIInteger64
    .ExitBootServices                       EFIInteger64
    .GetNextMonoticCount                    EFIInteger64
    .Stall                                  EFIInteger64
    .SetWatchdogTimer                       EFIInteger64
    .ConnectController                      EFIInteger64
    .DisconnectController                   EFIInteger64
    .OpenProtocol                           EFIInteger64
    .CloseProtocol                          EFIInteger64
    .OpenProtocolInformation                EFIInteger64
    .ProcotocolsPerHandle                   EFIInteger64
    .LocateHandleBuffer                     EFIInteger64
    .LocateProtocol                         EFIInteger64
    .InstallMultipleProtocolInterfaces      EFIInteger64
    .UninstallMultipleProtocolInterfaces    EFIInteger64
    .CalculateCrc32                         EFIInteger64
    .CopyMem                                EFIInteger64
    .SetMem                                 EFIInteger64
    .CreateEventEx                          EFIInteger64
}

EFITable EFIBootServices
    
Post 11 Apr 2020, 13:22
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
struc EFIGraphicsOutputProtocol
{
    .QueryMode  EFIInteger64
    .SetMode    EFIInteger64
    .Blt        EFIInteger64
    .Mode       EFIInteger64
}

EFITable EFIGraphicsOutputProtocol
    
Post 11 Apr 2020, 13:22
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
struc EFIGraphicsOutputBltOperation
{
    .VideoFill          EFIInteger64
    .VideoToBltBuffer   EFIInteger64
    .BufferToVideo      EFIInteger64
    .VideoToVideo       EFIInteger64
    .OperationMax       EFIInteger64
}

EFITable EFIGraphicsOutputBltOperation
    
Post 11 Apr 2020, 13:23
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3018
Location: vpcmipstrm
bitRAKE
Each protocol is a pointer to an interface. Get pointer to EFI_GRAPHICS_OUTPUT_PROTCOL and then the third pointer is Blt function. There are many separate function calls - each with their own parameters.

Okay, so let us work backward, assuming we are going to fill a 16x16 area with the color red:
Code:
; our pixel (somewhere in a data section)
Red_Pixel db 0,0,-1,0 ; EFI_GRAPHICS_OUTPUT_BLT_PIXEL array of one item


; ... after other setup ...

        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*8],0 ; delta
        call [rcx + EFI_GRAPHICS_OUTPUT_PROTOCOL.Blt]    
(Assuming you are looking at the UEFI spec ...)
*BltBuffer - the asterisks means a pointer to the data is needed.
enum are just integer constants, so EfiBltVideoFill = 0.

_________________
¯\(°_o)/¯ unlicense.org
Post 11 Apr 2020, 18:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17624
Location: In your JS exploiting you and your system
revolution
Something doesn't look right:
Code:
        mov qword[rsp + 8*8],16 ; height
        mov qword[rsp + 8*8],0 ; delta    
I assume that delta is rsp + 8*9.
Post 11 Apr 2020, 18:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4, 5, 6  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.