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