1/*
2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3 * Copyright 2015, 2016 Hesham Almatary <heshamelmatary@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 */
7
8#include <config.h>
9#include <util.h>
10
11.section .boot.text, "ax"
12.global _start
13.extern init_kernel
14.extern kernel_stack_alloc
15.extern __global_pointer$
16.extern restore_user_context
17.extern trap_entry
18
19/*
20 * When SMP is enabled, the elfloader passes the hart ID in a4
21 * and logical core ID in a5.
22 */
23_start:
24  fence.i
25.option push
26.option norelax
271:auipc gp, %pcrel_hi(__global_pointer$)
28  addi  gp, gp, %pcrel_lo(1b)
29.option pop
30  la sp, (kernel_stack_alloc + BIT(CONFIG_KERNEL_STACK_BITS))
31  csrw sscratch, x0 /* zero sscratch for the init task */
32
33#if CONFIG_MAX_NUM_NODES > 1
34/* setup the per-core stack */
35  mv t0, a5
36  slli t0, t0, CONFIG_KERNEL_STACK_BITS
37  add  sp, sp, t0
38  /* put the stack in sscratch */
39  csrw sscratch, sp
40#endif
41
42  jal init_kernel
43
44  la ra, restore_user_context
45  jr ra
46