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 /* Save hart ID and DTB physical address */
50 la a2, boot_cpu_hartid
53 /* Initialize page tables and relocate to virtual addresses */
54 la sp, init_thread_union + THREAD_SIZE
58 /* Restore C environment */
60 sw zero, TASK_TI_CPU(tp)
62 la sp, init_thread_union
63 li a0, ASM_THREAD_SIZE
66 /* Start the kernel */
73 /* Relocate return address */
79 /* Point stvec to virtual address of intruction after satp write */
84 /* Compute satp for kernel page tables, but don't load it yet */
86 srl a2, a2, PAGE_SHIFT
91 * Load trampoline page directory, which will cause us to trap to
92 * stvec if VA != PA, or simply fall through if VA == PA
94 la a0, trampoline_pg_dir
95 srl a0, a0, PAGE_SHIFT
101 /* Set trap vector to spin forever to help debug */
102 la a0, .Lsecondary_park
105 /* Reload the global pointer */
108 la gp, __global_pointer$
111 /* Switch to kernel page tables */
118 li a1, CONFIG_NR_CPUS
119 bgeu a0, a1, .Lsecondary_park
121 /* Set trap vector to spin forever to help debug */
122 la a3, .Lsecondary_park
126 la a1, __cpu_up_stack_pointer
127 la a2, __cpu_up_task_pointer
132 * This hart didn't win the lottery, so we wait for the winning hart to
133 * get far enough along the boot process that it should continue.
136 /* FIXME: We should WFI to save some energy here. */
139 beqz sp, .Lwait_for_cpu_up
140 beqz tp, .Lwait_for_cpu_up
143 /* Enable virtual memory and relocate to virtual address */
151 /* We lack SMP support or have too many harts, so park this hart */
157 /* Empty zero page */