2 * Copyright (C) 2012 Regents of the University of California
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <asm/thread_info.h>
15 #include <asm/asm-offsets.h>
17 #include <linux/init.h>
18 #include <linux/linkage.h>
19 #include <asm/thread_info.h>
25 /* Mask all interrupts */
29 /* Load the global pointer */
32 la gp, __global_pointer$
36 * Disable FPU to detect illegal usage of
37 * floating point in kernel space
42 /* Pick one hart to run the main boot sequence */
46 bnez a3, .Lsecondary_start
48 /* Clear BSS for flat non-ELF images */
51 ble a4, a3, clear_bss_done
54 add a3, a3, RISCV_SZPTR
58 /* Save hart ID and DTB physical address */
61 la a2, boot_cpu_hartid
64 /* Initialize page tables and relocate to virtual addresses */
65 la sp, init_thread_union + THREAD_SIZE
69 /* Restore C environment */
71 sw zero, TASK_TI_CPU(tp)
72 la sp, init_thread_union + THREAD_SIZE
74 /* Start the kernel */
80 /* Relocate return address */
86 /* Point stvec to virtual address of intruction after satp write */
91 /* Compute satp for kernel page tables, but don't load it yet */
93 srl a2, a2, PAGE_SHIFT
98 * Load trampoline page directory, which will cause us to trap to
99 * stvec if VA != PA, or simply fall through if VA == PA. We need a
100 * full fence here because setup_vm() just wrote these PTEs and we need
101 * to ensure the new translations are in use.
103 la a0, trampoline_pg_dir
104 srl a0, a0, PAGE_SHIFT
110 /* Set trap vector to spin forever to help debug */
111 la a0, .Lsecondary_park
114 /* Reload the global pointer */
117 la gp, __global_pointer$
121 * Switch to kernel page tables. A full fence is necessary in order to
122 * avoid using the trampoline translations, which are only correct for
123 * the first superpage. Fetching the fence is guarnteed to work
124 * because that first superpage is translated the same way.
133 li a1, CONFIG_NR_CPUS
134 bgeu a0, a1, .Lsecondary_park
136 /* Set trap vector to spin forever to help debug */
137 la a3, .Lsecondary_park
141 la a1, __cpu_up_stack_pointer
142 la a2, __cpu_up_task_pointer
147 * This hart didn't win the lottery, so we wait for the winning hart to
148 * get far enough along the boot process that it should continue.
151 /* FIXME: We should WFI to save some energy here. */
154 beqz sp, .Lwait_for_cpu_up
155 beqz tp, .Lwait_for_cpu_up
158 /* Enable virtual memory and relocate to virtual address */
166 /* We lack SMP support or have too many harts, so park this hart */
172 /* Empty zero page */