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 */
51 /* Initialize page tables and relocate to virtual addresses */
52 la sp, init_thread_union + THREAD_SIZE
56 /* Restore C environment */
58 sw s0, TASK_TI_CPU(tp)
60 la sp, init_thread_union
61 li a0, ASM_THREAD_SIZE
64 /* Start the kernel */
71 /* Relocate return address */
77 /* Point stvec to virtual address of intruction after satp write */
82 /* Compute satp for kernel page tables, but don't load it yet */
84 srl a2, a2, PAGE_SHIFT
89 * Load trampoline page directory, which will cause us to trap to
90 * stvec if VA != PA, or simply fall through if VA == PA
92 la a0, trampoline_pg_dir
93 srl a0, a0, PAGE_SHIFT
99 /* Set trap vector to spin forever to help debug */
100 la a0, .Lsecondary_park
103 /* Reload the global pointer */
106 la gp, __global_pointer$
109 /* Switch to kernel page tables */
116 li a1, CONFIG_NR_CPUS
117 bgeu a0, a1, .Lsecondary_park
119 /* Set trap vector to spin forever to help debug */
120 la a3, .Lsecondary_park
124 la a1, __cpu_up_stack_pointer
125 la a2, __cpu_up_task_pointer
130 * This hart didn't win the lottery, so we wait for the winning hart to
131 * get far enough along the boot process that it should continue.
134 /* FIXME: We should WFI to save some energy here. */
137 beqz sp, .Lwait_for_cpu_up
138 beqz tp, .Lwait_for_cpu_up
141 /* Enable virtual memory and relocate to virtual address */
149 /* We lack SMP support or have too many harts, so park this hart */
155 /* Empty zero page */