newlib: Regenerate autotools files
[newlib-cygwin.git] / libgloss / riscv / crt0.S
blob54443e4129dc4889ea56107c2b6b413d5767012f
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.
12 #include "newlib.h"
14 #=========================================================================
15 # crt0.S : Entry point for RISC-V user programs
16 #=========================================================================
18   .text
19   .global _start
20   .type   _start, @function
21 _start:
22   # Initialize global pointer
23 .option push
24 .option norelax
25 1:auipc gp, %pcrel_hi(__global_pointer$)
26   addi  gp, gp, %pcrel_lo(1b)
27 .option pop
29   /* Initialize jvt CSR (reg addr: 0x0017) */
30   .weak __jvt_base$
31   lla a0, __jvt_base$
32   beqz a0, .Ljvt_init_end
33 .option push
34 .option norelax
35 .option arch, +zicsr
36   csrw 0x17, a0
37 .option pop
38 .Ljvt_init_end:
40   # Clear the bss segment
41   la      a0, __bss_start
42   la      a2, _end
43   sub     a2, a2, a0
44   li      a1, 0
45   call    memset
46 #ifdef _LITE_EXIT
47   # Make reference to atexit weak to avoid unconditionally pulling in
48   # support code.  Refer to comments in __atexit.c for more details.
49   .weak   atexit
50   la      a0, atexit
51   beqz    a0, .Lweak_atexit
52   .weak   __libc_fini_array
53 #endif
55   la      a0, __libc_fini_array   # Register global termination functions
56   call    atexit                  #  to be called upon exit
57 #ifdef _LITE_EXIT
58 .Lweak_atexit:
59 #endif
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
67   call    main
68   tail    exit
69   .size  _start, .-_start