flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Fasm EFI

Author
Thread Post new topic Reply to topic
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello,
These days I started to do some experiments with efi,
but when I compile with the efi fasm format, it gives me 'error if I do not add ' use32 '.

Example:
Code:

format pe dll EFI at 10000000h
entry start


section '.text' code executable readable

; System Table   <==== ESP + 8
; Handle         <==== ESP + 4


use32
start:

    mov     eax,[esp+8]                     ; eax = Pointer to EFI_SYSTEM_TABLE
 mov     ecx,[eax+44]                    ; ecx = Pointer to SIMPLE_TEXT_OUTPUT_INTERFACE
     
    push    hello                           ; Pointer to String
 push    ecx                             ; Pointer to SIMPLE_TEXT_OUTPUT_INTERFACE
   call    Dword [ecx+4]                   ; SIMPLE_TEXT_OUTPUT_INTERFACE.OutputString

     xor     eax,eax

 ret


;-------------------------------------------
; Data
  section '.data' data readable writeable
;-------------------------------------------


hello           du 'Hello EFI',13,10,0

section '.reloc' fixups data discardable    


If you remove the word use32 fasm give me error with push ecx (Illegal instruction)
if you remove EFI , fasm compile ok also without use32.

Rolling Eyes

_________________
Nil Volentibus Arduum Razz
Post 22 Sep 2011, 08:19
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

I checked and I confirm
Code:
EFI use32
---------
 0 | 0   y
 0 | 1   y
 1 | 0   n   ;push ecx/illegal instruction/line 18
 1 | 1   y

y : does compile
n : does not compile    

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 22 Sep 2011, 09:16
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
Code:
format pe dll EFI at 10000000h
entry start 


section '.text' code executable readable 


start: 

        push    rcx    

For some reason fasm makes it "use64" instead of "use32". I will investigate further in the evening.
Post 22 Sep 2011, 10:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
fasm's PE formatter was always assuming that PE+ is always 64-bit code, while at the same time EFI requires PE+ format even for 32-bit case. I corrected it so that those two attributes (PE+ and x86-64 architecture) are distinguished and so it should now be possible to correctly generate 32-bit EFI PE. However, due to delicate nature of these changes, it is possible I introduced some new bugs. Can you test it thoroughly for me?
Post 23 Sep 2011, 17:30
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
With the code below i get:

Quote:

D:\Fasm>a hello_efi
flat assembler version 1.69.34 (1273648 kilobytes memory)
hello_efi.asm [18]:
push ecx ; Pointer to SIMPLE_TEXT_OUTPUT_INTERFACE
error: illegal instruction.



Code:
format pe dll EFI at 10000000h
entry start


section '.text' code executable readable

; System Table   <==== ESP + 8
; Handle         <==== ESP + 4


start:

  mov     eax,[esp+8]                     ; eax = Pointer to EFI_SYSTEM_TABLE
 mov     ecx,[eax+44]                    ; ecx = Pointer to SIMPLE_TEXT_OUTPUT_INTERFACE
     
    push    hello                           ; Pointer to String
 push    ecx                             ; Pointer to SIMPLE_TEXT_OUTPUT_INTERFACE
   call    Dword [ecx+4]                   ; SIMPLE_TEXT_OUTPUT_INTERFACE.OutputString
 add     esp,4*2

 xor     eax,eax

 ret


;-------------------------------------------
; Data
  section '.data' data readable writeable
;-------------------------------------------


hello           du 'Hello EFI',13,10,0

section '.reloc' fixups data discardable    

_________________
Nil Volentibus Arduum Razz
Post 24 Sep 2011, 06:59
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
Please try it now.
Post 24 Sep 2011, 10:30
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Yes Wink
Quote:

D:\Fasm>a hello_efi
flat assembler version 1.69.34 (1159800 kilobytes memory)
3 passes, 2048 bytes.

_________________
Nil Volentibus Arduum Razz
Post 24 Sep 2011, 11:14
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Does it run?
Post 24 Sep 2011, 17:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:

Does it run?


I don't know, i haven't EFI system on my PC Wink
I started to learn EFI because i want update my Os bootloader for the new EFI/BIOS PC...
I am writing all EFI API in asm, but without try it in real machine..Cool

_________________
Nil Volentibus Arduum Razz
Post 25 Sep 2011, 05:49
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello Tomasz,
I think that you must check your DLL EFI format in better way,
i get error when disassembly your PE in various disassembler tool, while
in the same tools the example compiled with microsoft C compiler and
linker work fine Crying or Very sad
Anyway i get no error when i test efi program compiled with fasm under the EFI shell Wink
Some Example:
Code:
IDA PRO show me 
PUSH ESI 
PUSH EBP
as
PUSH RSI
PUSH RBP
     

Another disassembly refuse to load your EFI DLL.... Question

_________________
Nil Volentibus Arduum Razz
Post 15 Oct 2011, 13:06
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello,
All the example precompiled under EFI toolkit (by intel) and EDK (efi development kit ) for 32bit use Classic Standard PE32 DLL EFI.
Why Fasm make DLL EFI PE32+ format as Default ?

_________________
Nil Volentibus Arduum Razz
Post 16 Oct 2011, 07:16
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
DJ Mauretto wrote:
Why Fasm make DLL EFI PE32+ format as Default ?
Because of what UEFI Specification states:
UEFI Specification Version 2.3.1, section 2.1.1 UEFI Images wrote:
UEFI uses a subset of the PE32+ image format with a modified header signature. The modification to the signature value in the PE32+ image is done to distinguish UEFI images from normal PE32 executables. The “+” addition to PE32 provides the 64-bit relocation fix-up extensions to standard PE32 format.
Post 16 Oct 2011, 22:16
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
Because of what UEFI Specification states:

Yes I know it, i'm learning EFI, but this is the theory, the reality is another.
EFI shell is a PE32 applpication, and all examples in EDK and EFI toolkit
are PE32 DLL... Crying or Very sad
Anyway can i select this option with fasm, without that fasm assume nothing ?
If i want Standard PE32 i write 'format pe dll EFI' , and if i want PE32+
i write 'format pe+ dll EFI'...

_________________
Nil Volentibus Arduum Razz
Post 17 Oct 2011, 08:55
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hey,
Are you There ? Razz
PE32+ is for 64 bit, please update fasm with PE32 dll efi.
Thanks
Wink

_________________
Nil Volentibus Arduum Razz
Post 18 Oct 2011, 13:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
No, PE32+ is for 32-bit EFI, specification says so. Of course, most disassembler don't support this unusual format, but that really has nothing to do with EFI.

Some specific implementation not obeying the standard completely, or your inability to use some disassembler for format it was not meant for are not good enough reasons for FASM to support a non-existent standard of plain-PE EFI files. If there was a EFI implementation unable to run 32-bit PE32+ executable, that would be a different story.
Post 19 Oct 2011, 00:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
No, PE32+ is for 32-bit EFI, specification says so. Of course, most disassembler don't support this unusual format, but that really has nothing to do with EFI.

Some specific implementation not obeying the standard completely, or your inability to use some disassembler for format it was not meant for are not good enough reasons for FASM to support a non-existent standard of plain-PE EFI files. If there was a EFI implementation unable to run 32-bit PE32+ executable, that would be a different story.


Look at the examples for efi 32 bit in the efi toolkit and edk.
They are all PE32 dll..
WHY Question
FASM make bad assumption about EFI..
The user must choose if he want PE32 or PE32+...
I guess it was you who suggested the platform for 64bit efi Razz

_________________
Nil Volentibus Arduum Razz
Post 19 Oct 2011, 08:11
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
or your inability to use some disassembler


between you and me there is only a small difference, I'm a genius
you are a 'HELLO world' programmer Wink

_________________
Nil Volentibus Arduum Razz
Post 19 Oct 2011, 09:59
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.