From Lazarus wiki
Revision as of 00:46, 30 April 2017 by Oco (talk | contribs) (Current state)

Motivations behind this target

The Unified Extensible Firmware Interface (UEFI) now replaces BIOS in most current PCs.

Currently, there are two main options to develop UEFI applications:

Both solutions require a tedious setup process.

Thank to its internal linker, Free Pascal can become the easiest option to develop UEFI applications, as no external tools would be required to start hacking.

Technical requirements

UEFI applications are PE binaries like the Windows target, which Free Pascal already supports. The only difference is the subsystem in the PE header.

Calling conventions under UEFI are identical to the ones under Windows on the same architecture, which Free Pascal already supports, too.

Current state

My current patch against trunk is here : http://nan.tf/download/uefi_all_03_01_2016.diff. It is not yet a clean patch : lots of debug output inside.

I have resume my work on this target. Here is my updated patch against trunk : http://nan.tf/download/fpc_uefi_28_04_2017.diff

Currently, i am focusing on UEFI32 because i have a few cheap atom machines with that version (see https://software.intel.com/en-us/blogs/2015/07/22/why-cheap-systems-run-32-bit-uefi-on-x64-systems) and because i use Haiku as my main development platform, without a 64 bits freepascal yet.

But UEFI64 support should be easy to had with careful API declarations.

Build instructions

For UEFI 32 target, the build command line is :

make all OS_TARGET=uefi CPU_TARGET=i386

Known problems

Affectation of string constant to string variable does not work. It is currently necessary to create strings through an array of WideChar.

  s : string;
  s := 'Hello world !';

Maybe it is related to Position Independent Code generation in the case of PE executables ?

Any hints in this area are welcome ;-)

With current trunk (3.1.1), this bug has been fixed. It helps a lot to be be able to use WriteLn('Something to write') instead of constructing an array of WideChar and call UEFI functions as before ;-).

Other known problem :

  list := TStringList.Create;

While constructing other kind of object works as expected, this one currently crash the program... I will have to investigate.

Testing UEFI applications with qemu

See OSDev UEFI Emulation with QEMU and OVMF

To avoid creating an image, i use FAT emulation to a local directory where my UEFI application is located :

qemu-system-i386-x86 -pflash /path/to/OVMF.fd -hda fat:local_directory -net none

"-net none" avoid net booting to save a few seconds in the boot process.

From UEFI shell, then write :


to switch to the directory where are located your application then you can launch it :



Everything has started after reading this article : http://blog.theincredibleholk.org/blog/2013/11/18/booting-to-rust/

What about doing that in Freepascal as well ?

It appears that Freepascal is even a better target for such a project because of its internal linker for PE targets : no need to install and configure an external one.

August 2014

Proof of concept : Freepascal is able to output a PE binary that can run in an UEFI environment. It can output a static text and the version of the firmware to the screen using an UEFI method.

April 2017

After observing that an annoying bug about string constant was fixed, i have resumed my work on this target.

Currently, here are the features that are implemented :

- WriteLn support (no more awkward array of WideChar allocation required)
- Memory allocation

External resources

Some interesting development resources around UEFI :