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 #ifdef CONFIG_RISCV_M_MODE
30 /* Image load offset (0MB) from start of RAM for M-mode */
33 #if __riscv_xlen == 64
34 /* Image load offset(2MB) from start of RAM */
37 /* Image load offset(4MB) from start of RAM */
41 /* Effective size of kernel image */
44 .word RISCV_HEADER_VERSION
47 .ascii RISCV_IMAGE_MAGIC
49 .ascii RISCV_IMAGE_MAGIC2
54 /* Mask all interrupts */
58 /* Load the global pointer */
61 la gp, __global_pointer$
65 * Disable FPU to detect illegal usage of
66 * floating point in kernel space
73 bgeu a0, t0, .Lsecondary_park
76 /* Pick one hart to run the main boot sequence */
80 bnez a3, .Lsecondary_start
82 /* Clear BSS for flat non-ELF images */
85 ble a4, a3, clear_bss_done
88 add a3, a3, RISCV_SZPTR
92 /* Save hart ID and DTB physical address */
95 la a2, boot_cpu_hartid
98 /* Initialize page tables and relocate to virtual addresses */
99 la sp, init_thread_union + THREAD_SIZE
105 /* Restore C environment */
107 sw zero, TASK_TI_CPU(tp)
108 la sp, init_thread_union + THREAD_SIZE
110 /* Start the kernel */
115 /* Relocate return address */
121 /* Point stvec to virtual address of intruction after satp write */
126 /* Compute satp for kernel page tables, but don't load it yet */
127 srl a2, a0, PAGE_SHIFT
132 * Load trampoline page directory, which will cause us to trap to
133 * stvec if VA != PA, or simply fall through if VA == PA. We need a
134 * full fence here because setup_vm() just wrote these PTEs and we need
135 * to ensure the new translations are in use.
137 la a0, trampoline_pg_dir
138 srl a0, a0, PAGE_SHIFT
144 /* Set trap vector to spin forever to help debug */
145 la a0, .Lsecondary_park
148 /* Reload the global pointer */
151 la gp, __global_pointer$
155 * Switch to kernel page tables. A full fence is necessary in order to
156 * avoid using the trampoline translations, which are only correct for
157 * the first superpage. Fetching the fence is guarnteed to work
158 * because that first superpage is translated the same way.
167 /* Set trap vector to spin forever to help debug */
168 la a3, .Lsecondary_park
172 la a1, __cpu_up_stack_pointer
173 la a2, __cpu_up_task_pointer
178 * This hart didn't win the lottery, so we wait for the winning hart to
179 * get far enough along the boot process that it should continue.
182 /* FIXME: We should WFI to save some energy here. */
185 beqz sp, .Lwait_for_cpu_up
186 beqz tp, .Lwait_for_cpu_up
189 /* Enable virtual memory and relocate to virtual address */
190 la a0, swapper_pg_dir
198 /* We lack SMP support or have too many harts, so park this hart */
204 /* Empty zero page */