Patrick Georgi | d1e50f9 | 2020-03-04 15:00:05 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Xiang Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 2 | |
| 3 | #include <arch/encoding.h> |
Philipp Hug | b09e500 | 2019-02-06 06:48:51 +0100 | [diff] [blame] | 4 | #include <bits.h> |
Xiang Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 5 | #include <mcall.h> |
| 6 | |
| 7 | .section ".text._start", "ax", %progbits |
| 8 | .globl _start |
| 9 | _start: |
Maximilian Brune | bd06a29 | 2023-11-09 17:53:34 +0100 | [diff] [blame^] | 10 | # 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 Heymans | 55069d1 | 2019-11-01 21:53:36 +0100 | [diff] [blame] | 15 | 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 Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 21 | # 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 Hug | b09e500 | 2019-02-06 06:48:51 +0100 | [diff] [blame] | 29 | STORE t1, 0(t0) |
Xiang Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 30 | li t1, RISCV_PGSIZE - HLS_SIZE |
| 31 | add sp, t0, t1 |
| 32 | |
| 33 | # initialize hart-local storage |
| 34 | csrr a0, mhartid |
Maximilian Brune | bd06a29 | 2023-11-09 17:53:34 +0100 | [diff] [blame^] | 35 | #NOTE a1 contains FDT and should not be cluttered above |
Xiang Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 36 | call hls_init |
| 37 | |
Xiang Wang | 26f725e | 2018-10-11 17:42:49 +0800 | [diff] [blame] | 38 | li a0, CONFIG_RISCV_WORKING_HARTID |
| 39 | call smp_pause |
| 40 | |
Xiang Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 41 | # 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äfer | 50b74b2 | 2018-10-01 09:45:49 +0200 | [diff] [blame] | 49 | # set up the mstatus register |
Xiang Wang | 21ed107 | 2018-08-29 17:21:19 +0800 | [diff] [blame] | 50 | call mstatus_init |
| 51 | tail main |
| 52 | |
| 53 | # These codes need to be implemented on a specific SoC |
| 54 | .weak exit_car |
| 55 | exit_car: |
| 56 | ret |