blob: 954b1555b3e6cd092c93fbb1b030161987d63e12 [file] [log] [blame]
Patrick Georgid1e50f92020-03-04 15:00:05 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Xiang Wang21ed1072018-08-29 17:21:19 +08002
3#include <arch/encoding.h>
Philipp Hugb09e5002019-02-06 06:48:51 +01004#include <bits.h>
Xiang Wang21ed1072018-08-29 17:21:19 +08005#include <mcall.h>
6
7.section ".text._start", "ax", %progbits
8.globl _start
9_start:
Maximilian Brunebd06a292023-11-09 17:53:34 +010010 # The romstage may pass the following arguments:
11 # a0: the value of mhartid
12 # a1: a pointer to the flattened devicetree
13 # a2: cbmem_top
14
Arthur Heymans55069d12019-11-01 21:53:36 +010015 la t0, _cbmem_top_ptr
16#if __riscv_xlen == 32
17 sw a2, (t0)
18#elif __riscv_xlen == 64
19 sd a2, (t0)
20#endif
Xiang Wang21ed1072018-08-29 17:21:19 +080021 # initialize stack point for each hart
22 # and the stack must be page-aligned.
23 # 0xDEADBEEF used to check stack overflow
24 csrr a0, mhartid
25 la t0, _stack
26 slli t1, a0, RISCV_PGSHIFT
27 add t0, t0, t1
28 li t1, 0xDEADBEEF
Philipp Hugb09e5002019-02-06 06:48:51 +010029 STORE t1, 0(t0)
Xiang Wang21ed1072018-08-29 17:21:19 +080030 li t1, RISCV_PGSIZE - HLS_SIZE
31 add sp, t0, t1
32
33 # initialize hart-local storage
34 csrr a0, mhartid
Maximilian Brunebd06a292023-11-09 17:53:34 +010035 #NOTE a1 contains FDT and should not be cluttered above
Xiang Wang21ed1072018-08-29 17:21:19 +080036 call hls_init
37
Xiang Wang26f725e2018-10-11 17:42:49 +080038 li a0, CONFIG_RISCV_WORKING_HARTID
39 call smp_pause
40
Xiang Wang21ed1072018-08-29 17:21:19 +080041 # initialize entry of interrupt/exception
42 la t0, trap_entry
43 csrw mtvec, t0
44
45 # clear any pending interrupts
46 csrwi mip, 0
47
48 call exit_car
Jonathan Neuschäfer50b74b22018-10-01 09:45:49 +020049 # set up the mstatus register
Xiang Wang21ed1072018-08-29 17:21:19 +080050 call mstatus_init
51 tail main
52
53 # These codes need to be implemented on a specific SoC
54 .weak exit_car
55exit_car:
56 ret