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 */
28 /* Load the global pointer */
31 la gp, __global_pointer$
35 * Disable FPU to detect illegal usage of
36 * floating point in kernel space
41 /* Pick one hart to run the main boot sequence */
45 bnez a3, .Lsecondary_start
47 /* Clear BSS for flat non-ELF images */
50 ble a4, a3, clear_bss_done
53 add a3, a3, RISCV_SZPTR
57 /* Save hart ID and DTB physical address */
60 la a2, boot_cpu_hartid
63 /* Initialize page tables and relocate to virtual addresses */
64 la sp, init_thread_union + THREAD_SIZE
68 /* Restore C environment */
70 sw zero, TASK_TI_CPU(tp)
72 la sp, init_thread_union
73 li a0, ASM_THREAD_SIZE
76 /* Start the kernel */
83 /* Relocate return address */
89 /* Point stvec to virtual address of intruction after satp write */
94 /* Compute satp for kernel page tables, but don't load it yet */
96 srl a2, a2, PAGE_SHIFT
101 * Load trampoline page directory, which will cause us to trap to
102 * stvec if VA != PA, or simply fall through if VA == PA
104 la a0, trampoline_pg_dir
105 srl a0, a0, PAGE_SHIFT
111 /* Set trap vector to spin forever to help debug */
112 la a0, .Lsecondary_park
115 /* Reload the global pointer */
118 la gp, __global_pointer$
121 /* Switch to kernel page tables */
128 li a1, CONFIG_NR_CPUS
129 bgeu a0, a1, .Lsecondary_park
131 /* Set trap vector to spin forever to help debug */
132 la a3, .Lsecondary_park
136 la a1, __cpu_up_stack_pointer
137 la a2, __cpu_up_task_pointer
142 * This hart didn't win the lottery, so we wait for the winning hart to
143 * get far enough along the boot process that it should continue.
146 /* FIXME: We should WFI to save some energy here. */
149 beqz sp, .Lwait_for_cpu_up
150 beqz tp, .Lwait_for_cpu_up
153 /* Enable virtual memory and relocate to virtual address */
161 /* We lack SMP support or have too many harts, so park this hart */
167 /* Empty zero page */