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>
14 #include <asm/image.h>
19 * Image header expected by Linux boot-loaders. The image header data
20 * structure is described in asm/image.h.
21 * Do not modify it without modifying the structure and all bootloaders
22 * that expects this header format!!
24 /* jump to start kernel */
29 #if __riscv_xlen == 64
30 /* Image load offset(2MB) from start of RAM */
33 /* Image load offset(4MB) from start of RAM */
36 /* Effective size of kernel image */
39 .word RISCV_HEADER_VERSION
42 .asciz RISCV_IMAGE_MAGIC
49 /* Mask all interrupts */
53 /* Load the global pointer */
56 la gp, __global_pointer$
60 * Disable FPU to detect illegal usage of
61 * floating point in kernel space
66 /* Pick one hart to run the main boot sequence */
70 bnez a3, .Lsecondary_start
72 /* Clear BSS for flat non-ELF images */
75 ble a4, a3, clear_bss_done
78 add a3, a3, RISCV_SZPTR
82 /* Save hart ID and DTB physical address */
85 la a2, boot_cpu_hartid
88 /* Initialize page tables and relocate to virtual addresses */
89 la sp, init_thread_union + THREAD_SIZE
95 /* Restore C environment */
97 sw zero, TASK_TI_CPU(tp)
98 la sp, init_thread_union + THREAD_SIZE
100 /* Start the kernel */
105 /* Relocate return address */
111 /* Point stvec to virtual address of intruction after satp write */
116 /* Compute satp for kernel page tables, but don't load it yet */
117 srl a2, a0, PAGE_SHIFT
122 * Load trampoline page directory, which will cause us to trap to
123 * stvec if VA != PA, or simply fall through if VA == PA. We need a
124 * full fence here because setup_vm() just wrote these PTEs and we need
125 * to ensure the new translations are in use.
127 la a0, trampoline_pg_dir
128 srl a0, a0, PAGE_SHIFT
134 /* Set trap vector to spin forever to help debug */
135 la a0, .Lsecondary_park
138 /* Reload the global pointer */
141 la gp, __global_pointer$
145 * Switch to kernel page tables. A full fence is necessary in order to
146 * avoid using the trampoline translations, which are only correct for
147 * the first superpage. Fetching the fence is guarnteed to work
148 * because that first superpage is translated the same way.
157 li a1, CONFIG_NR_CPUS
158 bgeu a0, a1, .Lsecondary_park
160 /* Set trap vector to spin forever to help debug */
161 la a3, .Lsecondary_park
165 la a1, __cpu_up_stack_pointer
166 la a2, __cpu_up_task_pointer
171 * This hart didn't win the lottery, so we wait for the winning hart to
172 * get far enough along the boot process that it should continue.
175 /* FIXME: We should WFI to save some energy here. */
178 beqz sp, .Lwait_for_cpu_up
179 beqz tp, .Lwait_for_cpu_up
182 /* Enable virtual memory and relocate to virtual address */
183 la a0, swapper_pg_dir
191 /* We lack SMP support or have too many harts, so park this hart */
197 /* Empty zero page */