| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/** |
| 3 |
****************************************************************************** |
| 4 |
* @file start.S |
| 5 |
* @author StarFive Technology |
| 6 |
* @version V1.0 |
| 7 |
* @date 07/29/2020 |
| 8 |
* @brief |
| 9 |
****************************************************************************** |
| 10 |
* @copy |
| 11 |
* |
| 12 |
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
| 13 |
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
| 14 |
* TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY |
| 15 |
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
| 16 |
* FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
| 17 |
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
| 18 |
* |
| 19 |
* COPYRIGHT 2020 Shanghai StarFive Technology Co., Ltd. |
| 20 |
*/ |
| 21 |
#include "encoding.h" |
| 22 |
|
| 23 |
/* This is defined in sifive/platform.h, but that can't be included from |
| 24 |
* assembly. */ |
| 25 |
.section .init |
| 26 |
.globl _start |
| 27 |
.type _start,@function |
| 28 |
|
| 29 |
_start: |
| 30 |
.cfi_startproc |
| 31 |
.cfi_undefined ra |
| 32 |
.option push |
| 33 |
.option norelax |
| 34 |
la gp, __global_pointer$ |
| 35 |
.option pop |
| 36 |
la sp, _sp |
| 37 |
|
| 38 |
csrr a0, mhartid |
| 39 |
li a1, 0 |
| 40 |
li a2, 0 |
| 41 |
/* Increment by hartid number of stack sizes */ |
| 42 |
li t0, 0 |
| 43 |
la t1, __stack_size |
| 44 |
1: |
| 45 |
beq t0, a0, 1f |
| 46 |
add sp, sp, t1 |
| 47 |
addi t0, t0, 1 |
| 48 |
j 1b |
| 49 |
1: |
| 50 |
andi sp, sp, -16 |
| 51 |
|
| 52 |
csrr a0, mhartid |
| 53 |
bnez a0, hart1_loop |
| 54 |
j start_boot_main |
| 55 |
|
| 56 |
hart1_loop: |
| 57 |
/* j hart1_loop */ |
| 58 |
li a2, MIP_MSIP |
| 59 |
csrw mie, a2 |
| 60 |
wfi |
| 61 |
/*call second_main */ |
| 62 |
|
| 63 |
start_boot_main: |
| 64 |
#if 0 |
| 65 |
/* Load data section */ |
| 66 |
la t0, _data_lma |
| 67 |
la t1, _data |
| 68 |
la t2, _edata |
| 69 |
bgeu t1, t2, 2f |
| 70 |
1: |
| 71 |
ld a0, 0(t0) |
| 72 |
addi t0, t0, 8 |
| 73 |
sd a0, 0(t1) |
| 74 |
addi t1, t1, 8 |
| 75 |
blt t1, t2, 1b |
| 76 |
2: |
| 77 |
#endif |
| 78 |
/* Clear bss section */ |
| 79 |
la t1, __bss_start |
| 80 |
la t2, _end |
| 81 |
bgeu t1, t2, 2f |
| 82 |
1: |
| 83 |
sd x0, 0(t1) |
| 84 |
addi t1, t1, 8 |
| 85 |
blt t1, t2, 1b |
| 86 |
2: |
| 87 |
|
| 88 |
/* Call global constructors */ |
| 89 |
//la a0, __libc_fini_array |
| 90 |
//call atexit |
| 91 |
//call __libc_init_array |
| 92 |
|
| 93 |
#ifndef __riscv_float_abi_soft |
| 94 |
/* Enable FPU */ |
| 95 |
li t0, MSTATUS_FS |
| 96 |
csrs mstatus, t0 |
| 97 |
csrr t1, mstatus |
| 98 |
and t1, t1, t0 |
| 99 |
beqz t1, 1f |
| 100 |
fssr x0 |
| 101 |
1: |
| 102 |
#endif |
| 103 |
|
| 104 |
#if defined(ENABLE_SMP) |
| 105 |
smp_resume(t0, t1) |
| 106 |
|
| 107 |
csrr a0, mhartid |
| 108 |
bnez a0, 2f |
| 109 |
#endif |
| 110 |
|
| 111 |
auipc ra, 0 |
| 112 |
addi sp, sp, -16 |
| 113 |
#if __riscv_xlen == 32 |
| 114 |
sw ra, 8(sp) |
| 115 |
#else |
| 116 |
sd ra, 8(sp) |
| 117 |
#endif |
| 118 |
|
| 119 |
/* argc = argv = 0 */ |
| 120 |
li a0, 0 |
| 121 |
li a1, 0 |
| 122 |
call BootMain |
| 123 |
//tail exit |
| 124 |
1: |
| 125 |
j 1b |
| 126 |
|
| 127 |
.cfi_endproc |