先来看一个具体的嵌入式工程的start.S文件:
#include "hpm_csr_regs.h"
.section .start, "ax"
.global _start
.type _start,@function
_start:
/* Initialize global pointer */
.option push
.option norelax
la gp, __global_pointer$
la tp, __thread_pointer$
.option pop
/* reset mstatus to 0*/
csrrw x0, mstatus, x0
#ifdef __riscv_flen
/* Enable FPU */
li t0, CSR_MSTATUS_FS_MASK
csrrs t0, mstatus, t0
/* Initialize FCSR */
fscsr zero
#endif
/* Enable LMM1 clock */
la t0, 0xF4000800
lw t1, 0(t0)
ori t1, t1, 0x80
sw t1, 0(t0)
#ifdef INIT_EXT_RAM_FOR_DATA
la t0, _stack_safe
mv sp, t0
call _init_ext_ram
#endif
/* Initialize stack pointer */
la t0, _stack
mv sp, t0
/*
* Initialize LMA/VMA sections.
* Relocation for any sections that need to be copied from LMA to VMA.
*/
call c_startup
#if defined(__SES_RISCV)
/* Initialize the hea