kernel/arch/riscv64/boot/
entry.rs1use core::arch::naked_asm;
2
3use crate::{device::fdt::FdtManager, environment::STACK_SIZE, start_kernel};
4
5#[unsafe(link_section = ".init")]
7#[unsafe(export_name = "_entry")]
8#[unsafe(naked)]
9pub extern "C" fn _entry() {
10 unsafe {
11 naked_asm!("
12 .option norvc
13 .option norelax
14 .align 8
15 // a0 = hartid
16 li t0, {}
17 mv t1, a0
18 addi t1, t1, 1
19 mul t1, t1, a0
20 la sp, KERNEL_STACK
21 add sp, sp, t0
22
23 j arch_start_kernel
24 ", const STACK_SIZE
25 );
26 }
27}
28
29#[unsafe(link_section = ".init")]
31#[unsafe(export_name = "_entry_ap")]
32#[unsafe(naked)]
33pub extern "C" fn _entry_ap() {
34 unsafe {
35 naked_asm!("
36 .option norvc
37 .option norelax
38 .align 8
39 // a0 = hartid
40 li t0, {}
41 mv t1, a0
42 addi t1, t1, 1
43 mul t1, t1, a0
44 la sp, KERNEL_STACK
45 add sp, sp, t0
46
47 j start_ap
48 ", const STACK_SIZE
49 );
50 }
51}
52
53
54#[unsafe(no_mangle)]
55pub extern "C" fn arch_start_kernel(hartid: usize, fdt_ptr: usize) {
56 unsafe {
57 FdtManager::set_fdt_addr(fdt_ptr);
58 }
59 start_kernel(hartid);
60}