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  Next
Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Okay.

In first, for me in french, i don't understand what do you mean "caller" ? The programmer ?
About 16n+8, is it just UEFI convention? I have many difficulties to understand this part. I need to see scheme i think. i understand the alignment reason, but i don't understand how it works.

What is the purpose of RBP return ?

I understand SystemTable term, but what is exactly Image Handle ? Address of original function caller.

It's what i thinking understand, but i think i need to be corrected (not physically please Laughing )
RAX must contain pointer to the called function
RCX first argument (always the origin called function) -> i think that is the image handle
RDX second,
...etc

But i think i do error, if RCX is the first argument,i always assign bad value at RCX no ?
Post 18 Apr 2020, 10:44
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
a caller is the code that's call a function.

a callee is the code called.

in french, l'appelant (caller), c'est le programme qui appele l'appelé (callee).
le callee, c'est la fonction appelléé par le caller.

Code:
caller:
  ;do stuff
  call callee
  ;do stuff
  ...


callee:
  ;do stuff
  ret

    


you clearlly miss the basics of asm programming, that's not really a problem cause you seems to understand what you talk about and coding in 64bits is not harder to get than in 16 or 32.

did you read the fasm manual?
it introduce the x86 architecture very well and you'll get every information you need about the function of registers like bp/ebp/rbp.
Post 18 Apr 2020, 15:12
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: 17665
Location: In your JS exploiting you and your system
revolution
Fulgurance: It is a common convention to use RBP to access the stack parameters. This is mostly a historical restriction from the original 8086 where BP would use SS by default and SP could not be used to directly access the stack with MOV. So you will often see {E|R}BP used for reading/writing the stack. Plus using RSP to directly access the stack parameters can be tricky if you intermix PUSH and POP because the RSP value changes.

The requirement to align to a multiple of 16 bytes is to allow callee functions to use the SSE aligned access instructions to access stack data. Callee functions are not required to use SSE, but they can if they wish to, so if you decide not to align the stack then the functions can fail when they use SSE to read/write the stack. This is why some functions still work with an unaligned stack because they don't use SSE. But don't rely on this, a future implementation might use SSE, or a different BIOS from yours might use SSE.

I don't see any requirement to have RAX point to the function you are calling. I think you can call it directly "call [R?? + EFI_table.function]". Try it. But get your print function working first, then start trying things and see when it breaks.


Last edited by revolution on 19 Apr 2020, 07:50; edited 1 time in total
Post 18 Apr 2020, 20:50
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
I know base about FASM, but when i look after many test i don't understand how to UEFI work, i think i miss some things. I have habits to code with BIOS mbr, without any PE convention, it's very difficult for me now.

I test again.I think after many times, i finally understand something....

Ask me if i make some errors. I have added comments to explain my reason of what i do
Code:
format pe64 efi
entry Main

section '.text' code readable executable

Main:
mov [Handle],rcx
mov [SystemTable],rdx

push rbp
sub rbp,0x20

mov rcx,GUID.EFIGraphicsOutputProtocol;It's address of 64 bits data with the GOP GUID
xor rdx,rdx;Not used for this test
mov r8,Interface.EFIGraphicsOutputProtocol;It's address where i store address of GOP protocol
mov rax,[SystemTable]
mov rax,[rax+EFISystemTable.BootServices+EFIBootServices.LocateProtocol]
call rax

add rsp,0x20
pop rbp

jmp $

include "EFIBase/GUID.fasm"
include "EFIBase/Interface.fasm"
include "EFIBase/EFIDataTypes.fasm"
include "EFITableHeader/EFITableHeader.fasm"
include "EFISystemTable/EFISystemTable.fasm"
include "EFIBootServices/EFIBootServices.fasm"
include "EFIBootServices/IndexTables/EFILocateSearchType.fasm"
include "EFISimpleTextOutputProtocol/EFISimpleTextOutputProtocol.fasm"
include "EFIGraphicsOutputProtocol/EFIGraphicsOutputProtocol.fasm"
include "EFIGraphicsOutputProtocol/IndexTables/EFIGraphicsOutputBltOperation.fasm"

section '.data' data readable writable executable

Handle:         dq ?
SystemTable:    dq ?    
Post 18 Apr 2020, 22:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
Start with a print output. Get your "hello world" working. Then move on to the GOP stuff.
Post 18 Apr 2020, 22:23
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Okay i start simple.I do that.
Post 18 Apr 2020, 22:30
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 821
Location: Belarus
DimonSoft
Actually, skipping layers of history is usually a bad idea. Modern stuff looks absolutely logical and goes without saying if you know what problems occured with its predecessors and which way they were solved. And knowing little to nothing about previous versions/platforms makes one just learn certain things by heart, and the things tend to look non-obvious.
Post 19 Apr 2020, 07:40
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Quote:
Actually, skipping layers of history is usually a bad idea. Modern stuff looks absolutely logical and goes without saying if you know what problems occured with its predecessors and which way they were solved. And knowing little to nothing about previous versions/platforms makes one just learn certain things by heart, and the things tend to look non-obvious.

I'm totally agree with you. I know many friend they have done informatic school, but i have seen many of them don't know very well the real working of computer.

The worst today, i think all is do to make this more worse. Today all people have habit to go to facility, and many programmer use programming language very far to the true working of computer.

Honestly, i'm sad when i seen programmer majority hate assembly and discourage any people to use it.

I think the only problem (for me), it's to found good tutorial. Many tutorial are not complete, have errors, and don't explain simple. I have project after i understand totally UEFI system to make assembly programming website

I think FASM is the best assembly language to learn and make progress. No any optimization or other features. Just understand what you doing
Post 19 Apr 2020, 11:09
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 821
Location: Belarus
DimonSoft
Fulgurance wrote:
The worst today, i think all is do to make this more worse. Today all people have habit to go to facility, and many programmer use programming language very far to the true working of computer.

This will happen until we get another well-paid profession where such people move leaving programming in a burnt-to-ashes state.
Post 19 Apr 2020, 12:24
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Well, now i have made simple code where i have success to show some text. I have already in past have success to do this with UEFI.

After this text, i have test to call LocateProtocol function, but, when my code run this part, this don't work. I think something is wrong, but i don't understand what... (text after LocateProtocol work)

Look:
Code:
format pe64 efi
entry Main

section '.text' code readable executable

Main:
mov [Handle],rcx
mov [SystemTable],rdx

push rbp
sub rbp,0x20

mov rcx,[rdx+EFISystemTable.ConOut]
mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString]
mov rdx,Text
call rax

add rsp,0x20
pop rbp
mov rdx,[SystemTable]

;-----------------------------------------------------

push rbp
sub rbp,0x20

mov rcx,GUID.EFIGraphicsOutputProtocol
mov rax,[rdx+EFISystemTable.BootServices]
xor rdx,rdx
mov r8,Interface.EFIGraphicsOutputProtocol
call [rax+EFIBootServices.LocateProtocol]

add rsp,0x20
pop rbp
mov rdx,[SystemTable]

;-----------------------------------------------------

cmp rax,0x0
jne .Exit

push rbp
sub rbp,0x20

mov rcx,[rdx+EFISystemTable.ConOut]
mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString]
mov rdx,Text
call rax

add rsp,0x20
pop rbp

.Exit:

jmp $

include "EFIBase/GUID.fasm"
include "EFIBase/Interface.fasm"
include "EFIBase/EFIDataTypes.fasm"
include "EFITableHeader/EFITableHeader.fasm"
include "EFISystemTable/EFISystemTable.fasm"
include "EFIBootServices/EFIBootServices.fasm"
include "EFIBootServices/IndexTables/EFILocateSearchType.fasm"
include "EFISimpleTextOutputProtocol/EFISimpleTextOutputProtocol.fasm"
include "EFIGraphicsOutputProtocol/EFIGraphicsOutputProtocol.fasm"
include "EFIGraphicsOutputProtocol/IndexTables/EFIGraphicsOutputBltOperation.fasm"

section '.data' data readable writable executable
Handle:         dq ?
SystemTable:    dq ?
Text:           du 'Texte',0x0
    
Post 19 Apr 2020, 15:23
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3044
Location: vpcmipstrm
bitRAKE
The next step would be to print the function result - to see what UEFI is saying to you. It's possible your UEFI firmware doesn't support the protocol - can't know without examining the return code.

I'm going to assume it returns: EFI_NOT_FOUND. This would be because a protocol instance isn't attached to your image. The display driver doesn't give every image its interface.

_________________
¯\(°_o)/¯ unlicense.org
Post 19 Apr 2020, 20:24
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: 17665
Location: In your JS exploiting you and your system
revolution
Fulgurance: This is good. We can now make progress to diagnose and follow what is happening.

But note that you only need the push rbp once at the code entry point. After that you don't need to do pop rbp or push rbp because the stack remains aligned for the entire procedure.
Post 19 Apr 2020, 21:40
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Quote:
But note that you only need the push rbp once at the code entry point. After that you don't need to do pop rbp or push rbp because the stack remains aligned for the entire procedure.

Okay.I have applied your advice.

Quote:
The next step would be to print the function result - to see what UEFI is saying to you. It's possible your UEFI firmware doesn't support the protocol - can't know without examining the return code.
I know he support him, because i have tested revolution code example.
But yes, i need to control the UEFI result.

Quote:
I'm going to assume it returns: EFI_NOT_FOUND. This would be because a protocol instance isn't attached to your image. The display driver doesn't give every image its interface.
?What ? Where and how can i attach my image ? Arguments are bad ?
Do you think i need to pass registration parameter ?


Last edited by Fulgurance on 19 Apr 2020, 23:00; edited 4 times in total
Post 19 Apr 2020, 22:37
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Look, i have removed useless push or pop rbp, but now, the last text call don't work:
Code:
format pe64 efi
entry Main

section '.text' code readable executable

Main:
mov [Handle],rcx
mov [SystemTable],rdx

push rbp
sub rbp,0x20

mov rcx,[rdx+EFISystemTable.ConOut]
mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString]
mov rdx,Text
call rax

add rsp,0x20
mov rdx,[SystemTable]

;-----------------------------------------------------

sub rbp,0x20

mov rcx,GUID.EFIGraphicsOutputProtocol
mov rax,[rdx+EFISystemTable.BootServices]
xor rdx,rdx
mov r8,Interface.EFIGraphicsOutputProtocol
call [rax+EFIBootServices.LocateProtocol]

add rsp,0x20
mov rdx,[SystemTable]

;-----------------------------------------------------

cmp rax,0x0
jne .Exit

sub rbp,0x20

mov rcx,[rdx+EFISystemTable.ConOut]
mov rax,[rcx+EFISimpleTextOutputProtocol.OutputString]
mov rdx,Text
call rax

add rsp,0x20

.Exit:

jmp $

include "EFIBase/GUID.fasm"
include "EFIBase/Interface.fasm"
include "EFIBase/EFIDataTypes.fasm"
include "EFITableHeader/EFITableHeader.fasm"
include "EFISystemTable/EFISystemTable.fasm"
include "EFIBootServices/EFIBootServices.fasm"
include "EFIBootServices/IndexTables/EFILocateSearchType.fasm"
include "EFISimpleTextOutputProtocol/EFISimpleTextOutputProtocol.fasm"
include "EFIGraphicsOutputProtocol/EFIGraphicsOutputProtocol.fasm"
include "EFIGraphicsOutputProtocol/IndexTables/EFIGraphicsOutputBltOperation.fasm"

section '.data' data readable writable executable
Handle:         dq ?
SystemTable:    dq ?
Text:           du 'Texte',0x0    
Post 19 Apr 2020, 22:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
If you remove "jne .Exit" does it print the text twice?
Post 19 Apr 2020, 22:51
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Oh yes ... i have forgotten that OMG. It's to test quickly the result...sorry.
I have corrected 2 errors into my code, i use add rbp, but it's rsp...
Just forgot my post about text problem, sorry

But about attached image problem, what do you mean ? (i have checked, when i try to call LocateProtocol, i haven't any good error code. I think i don't call good function. Something is bad
Post 19 Apr 2020, 22:56
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Just little question i ask me since many long. When i add value to memory, i do mov [memory],value.But when i add value to register, i do mov eax,value.

If i use [eax], what is this ???
Post 20 Apr 2020, 23:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17665
Location: In your JS exploiting you and your system
revolution
Code:
mov eax,0x12345678
mov byte[0x12345678],'A'; value = 'A', address = 0x12345678
mov byte[eax],'A' ; value = 'A', address = 0x12345678    
Post 21 Apr 2020, 00:22
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Code:
sub rsp,0x20

mov rax,[rdx+EFISystemTable.BootServices+EFIBootServices.HandleProtocol]
mov rcx,[Handle]
mov rdx,GUID.EFIGraphicsOutputProtocol
mov r8,Interface.EFIGraphicsOutputProtocol
call rax

add rsp,0x20
mov rdx,[SystemTable]    

I have tried with HandleProtocol function, but the same problem ...

What is the problem do you think ? Error return status code don't correspond to any error code...

Would you like i upload all of my code to test it?
Post 21 Apr 2020, 11:17
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 709
Location: Adelaide
sinsi
Untested
Code:
;assume the stack hasn't changed since program entry from RDX
sub rsp,28h ;change to 20h if you have aligned the stack to 16
mov rax,[SystemTable] ;assuming saved on program entry
mov rax,[rax+EFISystemTable.BootServices]
mov rcx,[Handle]
mov rdx,GUID.EFIGraphicsOutputProtocol ;RDX = address of GUID
mov r8,Interface.EFIGraphicsOutputProtocol ;R8 = address of QWORD
call [rax+EFIBootServices.HandleProtocol]
add rsp,xx
;Interface.EFIGraphicsOutputProtocol should now have a pointer to the protocol
    
Post 21 Apr 2020, 14:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  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.