2017-07-27 16:45:47 +08:00
|
|
|
/* Copyright (c) 2017 SiFive Inc. All rights reserved.
|
|
|
|
|
|
|
|
This copyrighted material is made available to anyone wishing to use,
|
|
|
|
modify, copy, or redistribute it subject to the terms and conditions
|
2017-08-21 10:30:30 +08:00
|
|
|
of the FreeBSD License. This program is distributed in the hope that
|
2017-07-27 16:45:47 +08:00
|
|
|
it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
|
|
|
|
including the implied warranties of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. A copy of this license is available at
|
|
|
|
http://www.opensource.org/licenses.
|
|
|
|
*/
|
|
|
|
|
2019-05-23 08:41:25 +08:00
|
|
|
#include "newlib.h"
|
|
|
|
|
2017-07-27 16:45:47 +08:00
|
|
|
#=========================================================================
|
|
|
|
# crt0.S : Entry point for RISC-V user programs
|
|
|
|
#=========================================================================
|
|
|
|
|
|
|
|
.text
|
|
|
|
.global _start
|
|
|
|
.type _start, @function
|
|
|
|
_start:
|
|
|
|
# Initialize global pointer
|
|
|
|
.option push
|
|
|
|
.option norelax
|
|
|
|
1:auipc gp, %pcrel_hi(__global_pointer$)
|
|
|
|
addi gp, gp, %pcrel_lo(1b)
|
|
|
|
.option pop
|
|
|
|
|
2024-01-05 15:06:39 +08:00
|
|
|
/* Initialize jvt CSR (reg addr: 0x0017) */
|
|
|
|
.weak __jvt_base$
|
|
|
|
lla a0, __jvt_base$
|
|
|
|
beqz a0, .Ljvt_init_end
|
|
|
|
.option push
|
|
|
|
.option norelax
|
|
|
|
.option arch, +zicsr
|
|
|
|
csrw 0x17, a0
|
|
|
|
.option pop
|
|
|
|
.Ljvt_init_end:
|
|
|
|
|
2017-07-27 16:45:47 +08:00
|
|
|
# Clear the bss segment
|
2021-02-04 15:34:00 +08:00
|
|
|
la a0, __bss_start
|
2017-07-27 16:45:47 +08:00
|
|
|
la a2, _end
|
|
|
|
sub a2, a2, a0
|
|
|
|
li a1, 0
|
|
|
|
call memset
|
2019-05-23 08:41:25 +08:00
|
|
|
#ifdef _LITE_EXIT
|
|
|
|
# Make reference to atexit weak to avoid unconditionally pulling in
|
|
|
|
# support code. Refer to comments in __atexit.c for more details.
|
|
|
|
.weak atexit
|
|
|
|
la a0, atexit
|
|
|
|
beqz a0, .Lweak_atexit
|
|
|
|
.weak __libc_fini_array
|
|
|
|
#endif
|
2017-07-27 16:45:47 +08:00
|
|
|
|
|
|
|
la a0, __libc_fini_array # Register global termination functions
|
|
|
|
call atexit # to be called upon exit
|
2019-05-23 08:41:25 +08:00
|
|
|
#ifdef _LITE_EXIT
|
|
|
|
.Lweak_atexit:
|
|
|
|
#endif
|
2017-07-27 16:45:47 +08:00
|
|
|
call __libc_init_array # Run global initialization functions
|
|
|
|
|
|
|
|
lw a0, 0(sp) # a0 = argc
|
|
|
|
addi a1, sp, __SIZEOF_POINTER__ # a1 = argv
|
|
|
|
li a2, 0 # a2 = envp = NULL
|
|
|
|
call main
|
|
|
|
tail exit
|
|
|
|
.size _start, .-_start
|