Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
// Should be self-explanatory. #![no_std] // Like most no_std targets, UEFI executables don't use the typical main function. // Most UEFI executables have the following entry point signature (C, taken from EDK2): // // EFI_STATUS // EFIAPI // UefiMain ( // IN EFI_HANDLE ImageHandle, // IN EFI_SYSTEM_TABLE *SystemTable // ); #![no_main] // The EFIAPI ABI, used by UEFI executables, has not been stabilized in Rust yet: // https://github.com/rust-lang/rust/issues/65815 #![feature(abi_efiapi)] use core::fmt::Write; use core::panic::PanicInfo; use uefi::prelude::*; // We need to manually define a panic handler. // You could also use the implementation in the uefi-services crate, but we'll keep things // simple for now. #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {} } // Our custom entry point. #[entry] fn efi_main(_handle: Handle, system_table: SystemTable) -> Status { match system_table.stdout().write_str("Hello, world!\n") { Ok(_) => Status::SUCCESS, Err(_) => Status::DEVICE_ERROR } }
The entry point takes two parameters, a Handle and a SystemTable. Section 4.1: UEFI Image Entry Point in the UEFI Specification covers this, but I'll give a brief explanation here. The Handle is an opaque handle (allocated by the firmware implementation) used to identify the currently running image/executable. You can use it with the EFI Loaded Image Protocol (more on that later) to get some more info about the current image/executable. Next is the SystemTable. The EFI System Table contains some fields such as the revision of the UEFI specification that the firmware implementation complies to, the name of the firmware vendor, and pointers to instances of the EFI Simple Text Input/Output Protocols for standard input/output/error. It also has pointers to the EFI Boot Services Table and the EFI Runtime Services Table. Section 4.3: EFI System Table has the C structure definition of the EFI System Table; you can also find its definition in the EDK2 (EFI Development Kit 2) headers. system_table.stdout() is how uefi-rs wrapped the StdOut member of the EFI System Table.