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