1 /* Copyright (c) 2017 SiFive Inc. All rights reserved.
3 This copyrighted material is made available to anyone wishing to use,
4 modify, copy, or redistribute it subject to the terms and conditions
5 of the FreeBSD License. This program is distributed in the hope that
6 it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7 including the implied warranties of MERCHANTABILITY or FITNESS FOR
8 A PARTICULAR PURPOSE. A copy of this license is available at
9 http://www.opensource.org/licenses.
14 #=========================================================================
15 # crt0.S : Entry point for RISC-V user programs
16 #=========================================================================
20 .type _start, @function
22 # Initialize global pointer
25 1:auipc gp, %pcrel_hi(__global_pointer$)
26 addi gp, gp, %pcrel_lo(1b)
29 /* Initialize jvt CSR (reg addr: 0x0017) */
32 beqz a0, .Ljvt_init_end
40 # Clear the bss segment
47 # Make reference to atexit weak to avoid unconditionally pulling in
48 # support code. Refer to comments in __atexit.c for more details.
51 beqz a0, .Lweak_atexit
52 .weak __libc_fini_array
55 la a0, __libc_fini_array # Register global termination functions
56 call atexit # to be called upon exit
60 call __libc_init_array # Run global initialization functions
62 lw a0, 0(sp) # a0 = argc
63 addi a1, sp, __SIZEOF_POINTER__ # a1 = argv
64 slli a2, a0, 1 + __SIZEOF_POINTER__ >> 2
65 addi a2, a2, __SIZEOF_POINTER__
66 add a2, a2, a1 # a2 = envp
69 .size _start, .-_start