NASM Forum > Using NASM
Compiling EFI file from ASM code
JD9999:
I have written (what I believe to be) a very simple UEFI implementation is asm. It does nothing fancy.
I can compile this to an object file (.o file), but I don't know how to turn a .asm into a .efi that I can use to boot off a USB stick.
Please tell me if you know how to convert this into an EFI file.
I am using Windows 10, NASM 2.15.05, administrator privileges.
My code is attached below in case that helps.
--- Code: ---BITS 64
global start
start:
;Start moving handoff variables
mov [EFI_HANDLE], rcx
mov [EFI_SYSTEM_TABLE], rdx
mov [UEFI_RETURN], rsp
;Do more here in the future
;Done!
mov rax, EFI_SUCCESS
ret
; Declare constants and variables here
EFI_HANDLE dq 0
EFI_SYSTEM_TABLE dq 0
UEFI_RETURN dq 0
EFI_SUCCESS db 0
--- End code ---
Thanks,
JD9999
Frank Kotler:
Hi JD9999.
Welcome to the Forum!
I have no idea. :(
Does this give you any help?
https://wiki.osdev.org/UEFI
What have you tried? ...and what happened?
I'm ASSuming:
--- Code: ---nasm -f win64 myprog.asm
--- End code ---
?
or?
What linker do you normally use? Any help in its documentation?
Hope for help from Windows users! Good luck!
Best.
Frank
Frank Kotler:
further thoughts...
I would expect a bootable file to be assembled as:
--- Code: ---nasm -f bin -o myfile.bin myfile.asm
--- End code ---
The form of your code suggests that it is to be called and is to return. This would not be thecase with a binary file. So I'm confused...
Best,
Frank
JD9999:
Thanks Frank for your response!
I have been reading OSDev's articles of UEFI, as well as the bare bones article (but that's with C, not asm).
The main thing I've been looking at is https://github.com/BrianOtto/nasm-uefi, which is a successful implementation.
For the moment, I have copied a bit of his code, but I would like to not just copy it so that I understand what is happening.
I don't use linkers, because it's only one file, and I believe I don't need a header file (though I could be wrong).
I have managed to make a .o file, a .obj file, and a .bin file from this code, so I know that it definitely compiles. And in theory it should work, because all it does is retrieve the variables from the UEFI, and then return back to the UEFI. (Not like traditional BIOS, where the application can't give control back to the BIOS)
There is a script on Brian Otto's Github (in link above) that copies the file onto an emulated VHS and runs it off that, but that doesn't give me an EFI file. The other thing I've been looking at is https://forum.nasm.us/index.php?topic=2191.0. However, I don't understand the code in the OP's (of that thread) solution at all, and according to another user on the thread, it doesn't work (though that may be 32 bit vs 64 bit, or the other error the user points out).
My issue is how to compile the code so that it becomes an EFI file.
I hope this helps!
Frank Kotler:
Wow.
I am so far over my head I can't even see daylight.
I just came across this in nntp:alt/os/development
https://wiki.osdev.org/UEFI#UEFI_vs._legacy_BIOS
If anything, I'm even more confused than before.
They seem to say we need a PE executable. Okay, we can do that... with a linker or in -f bin mode. A header like UNIXMAN shows? Maybe "not quite"?
Fasm supposedly knows how to do this. If all else fails, we can copy Fasm. As you say. it would be nice to understand it...
I don't even know where to start. You show some code that uses symbols. These symbols must be defined somewhere or Nasm would barf, no? You must have used -f bin for the bin file. -f win64 for the .o or .obj files? Or did you just change the name? Are you shooting for real hardware or an emulation?
I just read that IDE drives are recommended. I had IDE drives in my old computer... but it crashed and the new one won't take 'em. I would love to have my IDE drives back, so I may be doubly "blessed"... I don't know whether I have UEFI... or what sort... I probably am not going to be able to help you much. We can discuss it...
Best,
Frank
Navigation
[0] Message Index
[#] Next page
Go to full version