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