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 .ascii RISCV_IMAGE_MAGIC
44 .ascii RISCV_IMAGE_MAGIC2
49 /* Mask all interrupts */
53 #ifdef CONFIG_RISCV_M_MODE
55 * The hartid in a0 is expected later on, and we have no firmware
61 /* Load the global pointer */
64 la gp, __global_pointer$
68 * Disable FPU to detect illegal usage of
69 * floating point in kernel space
76 bgeu a0, t0, .Lsecondary_park
79 /* Pick one hart to run the main boot sequence */
83 bnez a3, .Lsecondary_start
85 /* Clear BSS for flat non-ELF images */
88 ble a4, a3, clear_bss_done
91 add a3, a3, RISCV_SZPTR
95 /* Save hart ID and DTB physical address */
98 la a2, boot_cpu_hartid
101 /* Initialize page tables and relocate to virtual addresses */
102 la sp, init_thread_union + THREAD_SIZE
108 /* Restore C environment */
110 sw zero, TASK_TI_CPU(tp)
111 la sp, init_thread_union + THREAD_SIZE
113 /* Start the kernel */
118 /* Relocate return address */
124 /* Point stvec to virtual address of intruction after satp write */
129 /* Compute satp for kernel page tables, but don't load it yet */
130 srl a2, a0, PAGE_SHIFT
135 * Load trampoline page directory, which will cause us to trap to
136 * stvec if VA != PA, or simply fall through if VA == PA. We need a
137 * full fence here because setup_vm() just wrote these PTEs and we need
138 * to ensure the new translations are in use.
140 la a0, trampoline_pg_dir
141 srl a0, a0, PAGE_SHIFT
147 /* Set trap vector to spin forever to help debug */
148 la a0, .Lsecondary_park
151 /* Reload the global pointer */
154 la gp, __global_pointer$
158 * Switch to kernel page tables. A full fence is necessary in order to
159 * avoid using the trampoline translations, which are only correct for
160 * the first superpage. Fetching the fence is guarnteed to work
161 * because that first superpage is translated the same way.
170 /* Set trap vector to spin forever to help debug */
171 la a3, .Lsecondary_park
175 la a1, __cpu_up_stack_pointer
176 la a2, __cpu_up_task_pointer
181 * This hart didn't win the lottery, so we wait for the winning hart to
182 * get far enough along the boot process that it should continue.
185 /* FIXME: We should WFI to save some energy here. */
188 beqz sp, .Lwait_for_cpu_up
189 beqz tp, .Lwait_for_cpu_up
192 /* Enable virtual memory and relocate to virtual address */
193 la a0, swapper_pg_dir
201 /* We lack SMP support or have too many harts, so park this hart */
207 /* Empty zero page */