#include "encoding.h" // See LICENSE for license details. .section .init .globl _start .type _start,@function _start: .option push .option norelax .option norvc #ifdef WITH_SIGNATURE j 1f .2byte 0x4e4d .2byte 0x5352 .4byte 0x669 1: #endif la gp, __global_pointer$ .option pop csrr t0, mhartid // Get hart ID la t1, __stack_size // stack size la sp, _sp // Base stack address /* this loop is to avoid multiplication which is not available on all ISAs */ 1: beqz t0, 2f sub sp, sp, t1 // Subtract __stack_size to get per-hart stack base addi t0, t0, -1 j 1b 2: la t0, trap_entry csrw mtvec, t0 #ifdef HARTX_WAIT4WFI /* block other cores until hart 0 has finished initialization */ csrr t0, mhartid beqz t0, hart0_init wfi j hartx_start hart0_init: #endif /* Load data section */ la a0, _data_lma la a1, _data la a2, _edata bgeu a1, a2, 2f 1: lw t0, (a0) addi a0, a0, 4 sw t0, (a1) addi a1, a1, 4 bltu a1, a2, 1b 2: /* Clear bss section */ la a0, __bss_start la a1, _end bgeu a0, a1, 2f 1: sw zero, (a0) addi a0, a0, 4 bltu a0, a1, 1b 2: /* Call global constructors */ #ifndef HAVE_NO_INIT_FINI la a0, __libc_fini_array call atexit call __libc_init_array #endif la a0, mtx li t0, 1 sw t0, 0(a0) hartx_start: #ifndef __riscv_float_abi_soft /* Enable FPU */ li t0, MSTATUS_FS csrs mstatus, t0 csrr t1, mstatus and t1, t1, t0 beqz t1, 1f fssr x0 1: #endif call _init /* argc = argv = 0 */ li a0, 0 li a1, 0 call main tail _exit .data mtx: .word 0 # 32-bit value