1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 Regents of the University of California
6 #include <asm/thread_info.h>
7 #include <asm/asm-offsets.h>
9 #include <linux/init.h>
10 #include <linux/linkage.h>
11 #include <asm/thread_info.h>
17 /* Mask all interrupts */
21 /* Load the global pointer */
24 la gp, __global_pointer$
28 * Disable FPU to detect illegal usage of
29 * floating point in kernel space
34 /* Pick one hart to run the main boot sequence */
38 bnez a3, .Lsecondary_start
40 /* Clear BSS for flat non-ELF images */
43 ble a4, a3, clear_bss_done
46 add a3, a3, RISCV_SZPTR
50 /* Save hart ID and DTB physical address */
53 la a2, boot_cpu_hartid
56 /* Initialize page tables and relocate to virtual addresses */
57 la sp, init_thread_union + THREAD_SIZE
61 /* Restore C environment */
63 sw zero, TASK_TI_CPU(tp)
64 la sp, init_thread_union + THREAD_SIZE
66 /* Start the kernel */
72 /* Relocate return address */
78 /* Point stvec to virtual address of intruction after satp write */
83 /* Compute satp for kernel page tables, but don't load it yet */
85 srl a2, a2, PAGE_SHIFT
90 * Load trampoline page directory, which will cause us to trap to
91 * stvec if VA != PA, or simply fall through if VA == PA. We need a
92 * full fence here because setup_vm() just wrote these PTEs and we need
93 * to ensure the new translations are in use.
95 la a0, trampoline_pg_dir
96 srl a0, a0, PAGE_SHIFT
102 /* Set trap vector to spin forever to help debug */
103 la a0, .Lsecondary_park
106 /* Reload the global pointer */
109 la gp, __global_pointer$
113 * Switch to kernel page tables. A full fence is necessary in order to
114 * avoid using the trampoline translations, which are only correct for
115 * the first superpage. Fetching the fence is guarnteed to work
116 * because that first superpage is translated the same way.
125 li a1, CONFIG_NR_CPUS
126 bgeu a0, a1, .Lsecondary_park
128 /* Set trap vector to spin forever to help debug */
129 la a3, .Lsecondary_park
133 la a1, __cpu_up_stack_pointer
134 la a2, __cpu_up_task_pointer
139 * This hart didn't win the lottery, so we wait for the winning hart to
140 * get far enough along the boot process that it should continue.
143 /* FIXME: We should WFI to save some energy here. */
146 beqz sp, .Lwait_for_cpu_up
147 beqz tp, .Lwait_for_cpu_up
150 /* Enable virtual memory and relocate to virtual address */
158 /* We lack SMP support or have too many harts, so park this hart */
164 /* Empty zero page */