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 use core::arch::asm;
16 
17 /// Boots a Linux kernel with the given boot hart ID and FDT blob.
18 ///
19 /// # Safety
20 ///
21 /// Caller must ensure that `kernel` contains a valid Linux kernel.
jump_linux(kernel: &[u8], boot_hart_id: usize, fdt: &[u8]) -> !22 pub unsafe fn jump_linux(kernel: &[u8], boot_hart_id: usize, fdt: &[u8]) -> ! {
23     // No official documentation exists yet. This is equivalent to a C function call taking
24     // the hart ID and FDT address as parameters.
25     // SAFETY: By safety requirement of this function, `kernel` contains a valid linux kernel.
26     unsafe {
27         asm!(
28             "csrw satp, zero",
29             "jr {ep}",
30             in("a0") boot_hart_id,
31             in("a1") fdt.as_ptr() as usize,
32             ep = in(reg) kernel.as_ptr() as usize,
33         );
34     }
35 
36     unreachable!();
37 }
38