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



Joined: 27 Nov 2017
Posts: 276
Fulgurance 21 Apr 2020, 14:13
Thanks you Smile

But no, don't work ... Crying or Very sad
..It's terrible ...
Post 21 Apr 2020, 14:13
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 22 Apr 2020, 14:41
Please if somebody can help me. I'm desperate ...

I have uploaded all of my code to test UEFI fonction: https://www.mediafire.com/file/4l9ado1e39813p2/UEFITest.tar.gz/file
Post 22 Apr 2020, 14:41
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 22 Apr 2020, 21:50
you can upload your code here, then no need to use this shitty mediafire site.

i suggest you to first feel comfortable with legacy bootloading, then, you'll see better what you miss for uefi.

i'll have a look at your code, bur please use the add attachement form below the post editor.


Description: for example, you can upload anything here
Download
Filename: hexchars3x5.inc
Filesize: 1.58 KB
Downloaded: 775 Time(s)

Post 22 Apr 2020, 21:50
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 23 Apr 2020, 04:56
There is an error in EFIBootServices
Code:
    .HandleProtocol                         EFIInteger64
    .void                                   EFIInteger64 ;<<<<<missing
    .RegisterProtocolNotify                 EFIInteger64
    

This code snippet returns RAX=0 (no error)
Code:
        mov     rax,[SystemTable]
        mov     rax,[rax+EFISystemTable.BootServices]
        lea     rcx,[GUID.EFIGraphicsOutputProtocol]
        sub     edx,edx
        lea     r8,[Interface.EFIGraphicsOutputProtocol]
        call    [rax+EFIBootServices.LocateProtocol]
    
Post 23 Apr 2020, 04:56
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 09:47
No Surprised Omg, finally it's very simple error omg ...
I understand better what nothing work xD

Just question, what is exactly LEA instruction ?

And why with this function, when i do CALL RAX, this don't work? I think i need understand something...
Post 23 Apr 2020, 09:47
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 716
Ali.Z 23 Apr 2020, 10:42
Fulgurance wrote:
Just question, what is exactly LEA instruction ?


Load Effective Address, computes a complex address and store it in a register.
example:
- lea eax,[eax+edi*8+86868686h]

read it this way:
86868686h + (8*edi) + eax = result stored in eax.

you can refer to intel's/amd's manual to learn new instructions or learn what is X instruction or how it work.

_________________
Asm For Wise Humans
Post 23 Apr 2020, 10:42
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 11:47
In one word, thanks ! End of desesperate Surprised

FInally work !

Code:
format pe64 efi
entry Main

section '.text' code readable writeable executable

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

push rbp
sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x50

mov rcx,[Interface.EFIGraphicsOutputProtocol]
mov rdx,RectangleColor
mov r8,[EFIGraphicsOutputBltOperation.BufferToVideo]
mov r9,0x0
mov qword[rsp + 8*4],0x0
mov qword[rsp + 8*5],0x64
mov qword[rsp + 8*6],0x64
mov qword[rsp + 8*7],0xF
mov qword[rsp + 8*8],0xF
mov qword[rsp + 8*9],0x0
call [rcx+EFIGraphicsOutputProtocol.Blt]

add rsp,0x50
mov rdx,[SystemTable]

cmp rax,0x0
jne .Exit

sub rsp,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"

Handle:         dq ?
SystemTable:    dq ?
Text:           du 'Texte',0x0
RectangleColor: db 0xFF,0xFF,0xFF,?
    
Post 23 Apr 2020, 11:47
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 11:52
Just little question. Is it normal when i do ClearScreen before my rect drawing, my rect isn't visible. It's only visible if i don't do clear screen
Post 23 Apr 2020, 11:52
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 11:59
I have doing that (look comments)

Code:
format pe64 efi
entry Main

section '.text' code readable writeable executable

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

push rbp
;sub rsp,0x20

;mov rcx,[rdx+EFISystemTable.ConOut]
;mov rax,[rcx+EFISimpleTextOutputProtocol.ClearScreen]
;call rax

;add rsp,0x20
;mov rdx,[SystemTable]

sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x50

mov rcx,[Interface.EFIGraphicsOutputProtocol]
mov rdx,RectangleColor
mov r8,[EFIGraphicsOutputBltOperation.BufferToVideo]
mov r9,0x0
mov qword[rsp + 8*4],0x0
mov qword[rsp + 8*5],0x64
mov qword[rsp + 8*6],0x64
mov qword[rsp + 8*7],0xF
mov qword[rsp + 8*8],0xF
mov qword[rsp + 8*9],0x0
call [rcx+EFIGraphicsOutputProtocol.Blt]

add rsp,0x50
mov rdx,[SystemTable]

cmp rax,0x0
jne .Exit

sub rsp,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"

Handle:         dq ?
SystemTable:    dq ?
Text:           du 'Texte',0x0
RectangleColor: db 0xFF,0xFF,0xFF,?
    
Post 23 Apr 2020, 11:59
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 12:08
I have found the problem. I need to do mov rdx,[SystemTable]. But why ...
Post 23 Apr 2020, 12:08
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 12:56
It's very strange, because, when i put comment into the part when i test result of EFIGraphicsOutputSource.Blt, Blt function don't work ... why ???

Code:
format pe64 efi
entry Main

section '.text' code readable writeable executable

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

mov rdx,[SystemTable]

push rbp
sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x20

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

add rsp,0x20
mov rdx,[SystemTable]

sub rsp,0x50

mov rcx,[Interface.EFIGraphicsOutputProtocol]
mov rdx,RectangleColor
mov r8,[EFIGraphicsOutputBltOperation.BufferToVideo]
mov r9,0x0
mov qword[rsp + 8*4],0x0
mov qword[rsp + 8*5],0x64
mov qword[rsp + 8*6],0x64
mov qword[rsp + 8*7],0xF
mov qword[rsp + 8*8],0xF
mov qword[rsp + 8*9],0x0
call [rcx+EFIGraphicsOutputProtocol.Blt]

add rsp,0x50
mov rdx,[SystemTable]

;cmp rax,0x0
;jne .Exit

;sub rsp,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"

Handle:         dq ?
SystemTable:    dq ?
Text:           du 'Texte',0x0
RectangleColor: db 0xFF,0xFF,0xFF,?
SystemMessage:  du '* ',0x0
Message:        du 'EFI Boot: Test OK',0xD,0xA,0x0
    
Post 23 Apr 2020, 12:56
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 23 Apr 2020, 13:20
I have understand something ! It's always needed to restore rcx and rdx ???
Post 23 Apr 2020, 13:20
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 23 Apr 2020, 16:49
Let me insist again that general-purpose instructions, addressing, calling conventions and stuff like that are things to be learnt far before one gets to writing something for UEFI or legacy BIOS (though real mode world is a lot easier to deal with). There’re six pages for now but the questions are still basic. Writing an OS requires one to know even much more stuff than that.

Nothing personal, I just feel you’re wasting your time relying on other people’s help all the way along instead of developing your own skills by learning things in order.
Post 23 Apr 2020, 16:49
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 716
Ali.Z 23 Apr 2020, 17:55
I agree with DimonSoft on that one should learn all the basics before even attempting to write a kernel mode OS or even a simple bootloader.

many (if not most) assembly programmers made their tiny OS for fun, including me; and yes what DimonSoft said is true one need to know a lot more than basic stuff.

when programming at hardware level, assembly instructions are very thin layer or lets say its level 1; there are a lot of things one need to consider and understand, in other words assembly is the key to the hardware level by mean it removes many abstractions.

but I dont agree on the part he (DimonSoft) said that you are relying on other people's help; because I believe we humans must co-op and help each other, and not helping others is wrong and no good; however this is off-topic.

refer to your processor manual for the complete instruction set and their uses, its good to learn intel's efi and do some uefi programming if you have an intel chip and you want your software to run on future processors; as intel stated there is no CSM.

but if you are on amd's side, then its okay AFAIK amd wont drop the CSM.

good luck with your project.

_________________
Asm For Wise Humans
Post 23 Apr 2020, 17:55
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 24 Apr 2020, 18:04
c'est pas faux (ce qu'ils disent plus haut), il faut d'abord bien maitriser et connaitre les bases. je ne sais pas quel est ton background en developpement, mais l'asm est un domaine bien different des autres langages. il est plus proche de la logique et de la mecanique que de l'informatique. ça demande de comprendre les fonctions de base de n'importe quel processeur.

les processeurs x86 sont relativement simples a utiliser, mais très complexes à comprendre.

le fonctionnement du mode uefi des pc est un fragment de ce que tu dois comprendre pour coder ce que tu veux coder.

un os, ou une appli embarquée, ça demande de maitriser l'outil.

n'hesite pas à tester les codes des autres, et à les lire pour les comprendre. ça va rentrer.
Post 24 Apr 2020, 18:04
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 24 Apr 2020, 19:50
Fulgurance wrote:
I have understand something ! It's always needed to restore rcx and rdx ???

Et la réponse à cette question est liée à les conventions d’appel des fonctions utilisé par UEFI, l’une des conventions. Mais ayant de l’expérience dans la programmation pour Windows tout ça serait assez évident. C’est pour ça que je dis qu’il ne faut pas se plonger dans UEFI sans avoir assez d’expérience plus basique: beaucoup des choses assez simples va prendre trop de temps.
Post 24 Apr 2020, 19:50
View user's profile Send private message Visit poster's website Reply with quote
HSE



Joined: 13 Jan 2019
Posts: 15
HSE 02 Apr 2022, 00:22
Apparently is so trivial that I can't find any description:

How you test *.efi files in QEMU?

Thanks in advance, HSE
Post 02 Apr 2022, 00:22
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4022
Location: vpcmpistri
bitRAKE 02 Apr 2022, 02:38
Check out this repo, https://github.com/bitRAKE/UEFI_playground
,.. it has premade EFI firmware for a few scenarios, and the command files outline what QEMU wants, configuration wise.

It was difficult to figure this stuff out as most people use a shell program of some sort to configure QEMU. The examples worked on my hardware and in QEMU.

I like to map the working directory as a drive when using QEMU - makes roundtrip debugging really fast:
Code:
"C:\Program Files\qemu\qemu-system-x86_64w.exe" ^
 -nodefaults ^
 -cpu qemu64 -vga std -machine q35,smm=on ^
 -device qemu-xhci -device usb-mouse -device usb-kbd ^
 -L . -drive file=fat:rw:image,index=1,media=disk,if=virtio,format=raw ^
 -drive file=firmware\OVMF_amd64\OVMF_CODE_4M.ms.fd,if=pflash,format=raw,unit=0,readonly=on ^
 -drive file=firmware\OVMF_amd64\OVMF_VARS_4M.ms.fd,if=pflash,format=raw,unit=1    
... that's what the fifth line does.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 02 Apr 2022, 02:38
View user's profile Send private message Visit poster's website Reply with quote
HSE



Joined: 13 Jan 2019
Posts: 15
HSE 02 Apr 2022, 17:48
Nice package!

With yours settings I have "command error status : access denied"

But taking one of your lines I maked (is an older UEFI version):
Code:
qemu-system-x86_64w -bios OVMF.fd -drive file=fat:rw:e:\image,index=1,media=disk,if=virtio,format=raw -net none -serial stdio     

That allow me to test your efi files.

Trying to boot inside qemu is going nowhere, some kind of loop.

No problem at all with hardware, red square (bitRAKE1 version) work perfectly.

Thanks.
Post 02 Apr 2022, 17:48
View user's profile Send private message Reply with quote
HSE



Joined: 13 Jan 2019
Posts: 15
HSE 04 Apr 2022, 17:46
Still no success with booting in qemu.

But there is a trick (https://www.howtogeek.com/187721/how-to-boot-from-a-usb-drive-in-virtualbox/) to boot the example from USB in VirtualBox.
Post 04 Apr 2022, 17:46
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, 7  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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.