| 1 |
// Example: Hello World! |
| 2 |
// |
| 3 |
// This is an example UEFI application that prints "Hello World!", then waits |
| 4 |
// for key input before it exits. It serves as base example how to write UEFI |
| 5 |
// applications without any helper modules other than the UEFI protocol |
| 6 |
// definitions. |
| 7 |
// |
| 8 |
// This example builds upon the `freestanding.rs` example, using the same setup |
| 9 |
// and rust integration. See there for details on the panic-handler and entry |
| 10 |
// point configuration. |
| 11 |
// |
| 12 |
// Note that UEFI uses UTF-16 strings. Since rust literals are UTF-8, we have |
| 13 |
// to use an open-coded, zero-terminated, UTF-16 array as argument to |
| 14 |
// `output_string()`. Similarly to the panic handler, real applications should |
| 15 |
// rather use UTF-16 modules. |
| 16 |
|
| 17 |
#![no_main] |
| 18 |
#![no_std] |
| 19 |
|
| 20 |
use r_efi::efi; |
| 21 |
|
| 22 |
#[panic_handler] |
| 23 |
fn panic_handler(_info: &core::panic::PanicInfo) -> ! { |
| 24 |
loop {} |
| 25 |
} |
| 26 |
|
| 27 |
#[export_name = "efi_main"] |
| 28 |
pub extern "C" fn main(_h: efi::Handle, st: *mut efi::SystemTable) -> efi::Status { |
| 29 |
let s = [ |
| 30 |
0x0048u16, 0x0065u16, 0x006cu16, 0x006cu16, 0x006fu16, // "Hello" |
| 31 |
0x0020u16, // " " |
| 32 |
0x0057u16, 0x006fu16, 0x0072u16, 0x006cu16, 0x0064u16, // "World" |
| 33 |
0x0021u16, // "!" |
| 34 |
0x000au16, // "\n" |
| 35 |
0x0000u16, // NUL |
| 36 |
]; |
| 37 |
|
| 38 |
// Print "Hello World!". |
| 39 |
let r = |
| 40 |
unsafe { ((*(*st).con_out).output_string)((*st).con_out, s.as_ptr() as *mut efi::Char16) }; |
| 41 |
if r.is_error() { |
| 42 |
return r; |
| 43 |
} |
| 44 |
|
| 45 |
// Wait for key input, by waiting on the `wait_for_key` event hook. |
| 46 |
let r = unsafe { |
| 47 |
let mut x: usize = 0; |
| 48 |
((*(*st).boot_services).wait_for_event)(1, &mut (*(*st).con_in).wait_for_key, &mut x) |
| 49 |
}; |
| 50 |
if r.is_error() { |
| 51 |
return r; |
| 52 |
} |
| 53 |
|
| 54 |
efi::Status::SUCCESS |
| 55 |
} |