flat assembler
Message board for the users of flat assembler.

Index > OS Construction > My first UEFI app...

Author
Thread Post new topic Reply to topic
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 07 May 2024, 17:39
I posted in Discord before but not here.
Anyway, here it is: The shortest "Hello, world" UEFI app, bypassing various structure.

EDIT: Thank you @revolution for the suggestion of "du" instead of "dw".

Code:
format PE64 EFI DLL on 'nul'

section '.code' code readable executable

entry $

       sub     rsp, 40
       mov     rcx, qword [rdx + 0x40]
       lea     rdx, [_message]
       call    qword [rcx + 0x08]
       add     rsp, 40
       retn

_message du 'Hello World',13,10,0         


Description:
Filesize: 21.55 KB
Viewed: 3688 Time(s)

GMXqL8_a4AAetXu.jpeg




Last edited by MatQuasar on 08 May 2024, 01:52; edited 1 time in total
Post 07 May 2024, 17:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20739
Location: In your JS exploiting you and your system
revolution 07 May 2024, 22:11
You can use du instead of dw.
Code:
_message du 'Hello World',13,10,0    
Post 07 May 2024, 22:11
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4288
Location: vpcmpistri
bitRAKE 08 May 2024, 00:29

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 08 May 2024, 00:29
View user's profile Send private message Visit poster's website Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 08 May 2024, 01:53
revolution wrote:
You can use du instead of dw.
Code:
_message du 'Hello World',13,10,0    


Nice, I thought it required include file from "encodings". Just now I tested, it doesn't need one. Thank you for the suggestion.
Post 08 May 2024, 01:53
View user's profile Send private message Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 08 May 2024, 01:55


Yes! Actually I referred to your this particular example before doing my own similar one. I use the offset in EFI_SYSTEM_TABLE and EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL directly, skipping the need of include files.

Very Happy
Post 08 May 2024, 01:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20739
Location: In your JS exploiting you and your system
revolution 08 May 2024, 02:03
By declaring constants, and expanding the rsp value, this code can be made more reader friendly.
Code:
format PE64 EFI DLL on 'nul'

section '.code' code readable executable

EFI_SYSTEM_TABLE.ConOut                         = 0x40
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString    = 0x08

entry $

        sub     rsp, 8 * 5
        mov     rcx, qword[rdx + EFI_SYSTEM_TABLE.ConOut]
        lea     rdx, [_message]
        call    qword[rcx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
        add     rsp, 8 * 5
        ret

_message du 'Hello World',13,10,0    
Post 08 May 2024, 02:03
View user's profile Send private message Visit poster's website Reply with quote
buyerninety



Joined: 04 Mar 2014
Posts: 2
buyerninety 04 Oct 2025, 19:36
Posted merely as some members may find this video as minor interesting.

Youtube Video may be better described as,
'using the UEFI spec to build a game', i.e., 'seems like we wrote Assembly
using an OS, that we compiled using an OS, that we executed in EFI as a game
without an OS. An impressive result for sure, just not quite the (Video) title.'
https://www.youtube.com/watch?v=ZFHnbozz7b4

Seen random Youtube comments;
"This is not really bare metal programming. You're not banging hardware
registers directly but using the UEFI services. Still cool, though."
----
"What I appreciate about this is the proof of concept - actually interfacing
directly with the UEFI to initiate a boot."..."almost all of this is done with UEFI
commands, not 'actual x86 instructions' - but as an example of how to read
instruction references and develop them into a working solution, it covers all
the main bases - timing and a for-while loop, input and output, and parallelization."
..."Basically anything you would need to initiate on boot is covered here or at
least the door to it pointed out."
----
"Only one CPU (core) is active at boot (power up) time. The application
activated the rest on start up as needed. This should make sense. The only
reason why all CPU's are active here is the author of this atrocity decided to abuse
them I assume. Cores can easily be put into an idle state by executing the halt
instruction which will make them 'sleep' until a hardware interrupt occurs or some
other conditions these days."
----
"The fans kick in cause there is no code to put the cores to sleep, resulting in
the entire CPU being 100% busy at all times."
----
"Pretty sure they just used the easiest way to render to the screen within UEFI
and it just so happens to be horrifically inefficient"
----
"also calling the UEFI blit service for every pixel you want to upscale is insanely
inefficient. Do the upscaling in a memory buffer manually and blit the whole
screen once. This game with upscaling does not need more than a single core
to run at hundreds to thousands fps on a modern processor."
----
"They can get the framebuffer address and do the integer upscale in their own
blit routine. The upscale is a blit after all."

----
"When the game says: 'Loading...', it means: counting tics for 1 full second to
calculate how long a tic is. Definitely one of the stranger reasons for a load screen."
----
"(Timestamp)5:06 Caveat: C structs are padded so that 64-bit pointers are
qword aligned. If you neglect that you'll end up with wrong field offsets."
----
"You have to preserve (if you overwrite them) rbx, rsi, rdi, rbp, r12, r13, r14, r15,
xmm4-xmm7 in your efimain, and restore them before returning. The stack pointer
must be aligned to 16 byte boundary before you call any function. You have almost
no ABI comformance in your code at all."
----
"(timestamp)6:20 You can create an image file containing your EFI partition
and add it to QEMU with `-drive format=raw,file=/path/to/image.img`, no
need for a physical USB drive to forward to the VM."
----
"You don’t actually need a real flash drive to test your app in qemu! The
drive option can also accept a folder path, which it will then treat as a drive
image. So all you have to do is create the EFI folder structure, pass -drive
argument, obviously also pass in paths to ovmf, and voila! It’s very helpful
to run this in qemu since you get integrated gdb support meaning you can
very easily step through the code and figure out what’s happening when
something goes wrong"
---
REPLY youtube comment to above comment,
"I recommend creating a disk image rather than executing an EFI application
directly, because it seems to make some of the image (as in, the loaded
executable image) not work properly. I don't remember what didn't work, but
something did.
Also, gdb cannot read symbols in EFI or PDB files, so you need to compile an
ELF file as well to get the symbols. But I guess that doesn't matter much if
you're already writing in assembly."
Post 04 Oct 2025, 19:36
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4288
Location: vpcmpistri
bitRAKE 04 Oct 2025, 21:23
lol'd when he said, "... the C language - much too rich for my blood." The way he communicates his progress of understanding is very relatable. Very basic use of MASM - the syntax is mostly generic/plain x64, imho. The Zaxxon clone looks really good. Thanks for sharing. (btw, two replies over 10 years apart might be a record - see you in another ten, lol.)

_________________
¯\(°_o)/¯ AI may [not] have aided with the above reply.
Post 04 Oct 2025, 21:23
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:  


< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.