xref: /aosp_15_r20/bootable/libbootloader/gbl/efi/app/riscv64.rs (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1*5225e6b1SAndroid Build Coastguard Worker // Copyright 2023, 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 compiler looks for this function. It is normally provided by libstd.
16*5225e6b1SAndroid Build Coastguard Worker // But for baremetal we don't use std and implementation doesn't matter
17*5225e6b1SAndroid Build Coastguard Worker // anyway. We put a empty place holder here to get compilation pass.
18*5225e6b1SAndroid Build Coastguard Worker #[no_mangle]
rust_eh_personality()19*5225e6b1SAndroid Build Coastguard Worker pub extern "C" fn rust_eh_personality() {}
20*5225e6b1SAndroid Build Coastguard Worker 
21*5225e6b1SAndroid Build Coastguard Worker // Provide a few dependencies such as memcpy, memset not provided by RISC-V toolchain
22*5225e6b1SAndroid Build Coastguard Worker // in the GBL setting
23*5225e6b1SAndroid Build Coastguard Worker #[link(name = "efi_arch_deps_riscv64", kind = "static")]
24*5225e6b1SAndroid Build Coastguard Worker extern "C" {
25*5225e6b1SAndroid Build Coastguard Worker     // Pointer to the EFI header.
26*5225e6b1SAndroid Build Coastguard Worker     static dos_header: *const core::ffi::c_void;
27*5225e6b1SAndroid Build Coastguard Worker }
28*5225e6b1SAndroid Build Coastguard Worker 
29*5225e6b1SAndroid Build Coastguard Worker // LLVM doesn't yet have native PE/COFF support for RISC-V target. Thus we have to
30*5225e6b1SAndroid Build Coastguard Worker // manually add the PE/COFF header to the binary via arch/riscv64/riscv64_efi_header.S.
31*5225e6b1SAndroid Build Coastguard Worker // Since the source is compiled as a static library, we need to have a public rust
32*5225e6b1SAndroid Build Coastguard Worker // function that refers to some symbol from it so that the linker doesn't discard it
33*5225e6b1SAndroid Build Coastguard Worker // from the binary.
34*5225e6b1SAndroid Build Coastguard Worker #[no_mangle]
get_efi_header() -> *const core::ffi::c_void35*5225e6b1SAndroid Build Coastguard Worker pub extern "C" fn get_efi_header() -> *const core::ffi::c_void {
36*5225e6b1SAndroid Build Coastguard Worker     unsafe { dos_header }
37*5225e6b1SAndroid Build Coastguard Worker }
38*5225e6b1SAndroid Build Coastguard Worker 
39*5225e6b1SAndroid Build Coastguard Worker // The function is related to stack unwinding and called by liballoc. However we don't expect
40*5225e6b1SAndroid Build Coastguard Worker // exception handling in UEFI application. If it ever reaches here, panics.
41*5225e6b1SAndroid Build Coastguard Worker #[no_mangle]
_Unwind_Resume(_: *mut core::ffi::c_void)42*5225e6b1SAndroid Build Coastguard Worker pub extern "C" fn _Unwind_Resume(_: *mut core::ffi::c_void) {
43*5225e6b1SAndroid Build Coastguard Worker     panic!();
44*5225e6b1SAndroid Build Coastguard Worker }
45