xref: /aosp_15_r20/bootable/libbootloader/gbl/efi/app/main.rs (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! The GBL UEFI application.
16 //!
17 //! This just contains the minimal entry point and global hook declarations
18 //! needed for a full application build; all the logic should go in the
19 //! `gbl_efi` library instead.
20 
21 #![no_std]
22 #![no_main]
23 
24 #[cfg(target_arch = "riscv64")]
25 mod riscv64;
26 
27 use core::{ffi::c_void, panic::PanicInfo};
28 use efi::{initialize, panic, EfiAllocator};
29 use efi_types::EfiSystemTable;
30 use gbl_efi::app_main;
31 
32 #[panic_handler]
handle_panic(p_info: &PanicInfo) -> !33 fn handle_panic(p_info: &PanicInfo) -> ! {
34     panic(p_info)
35 }
36 
37 #[no_mangle]
38 #[global_allocator]
39 static mut EFI_GLOBAL_ALLOCATOR: EfiAllocator = EfiAllocator::new();
40 
41 /// Pull in the sysdeps required by libavb so the linker can find them.
42 extern crate avb_sysdeps;
43 
44 /// EFI application entry point. Does not return.
45 ///
46 /// # Safety
47 /// `image_handle` and `systab_ptr` must be valid objects that adhere to the UEFI specification.
48 #[no_mangle]
efi_main(image_handle: *mut c_void, systab_ptr: *mut EfiSystemTable)49 pub unsafe extern "C" fn efi_main(image_handle: *mut c_void, systab_ptr: *mut EfiSystemTable) {
50     // SAFETY:
51     // * caller provides valid `image_handle` and `systab_ptr` objects
52     // * we only call `initialize()` once
53     let entry = unsafe { initialize(image_handle, systab_ptr) }.unwrap();
54     app_main(entry).unwrap();
55     loop {}
56 }
57