forked from openhwgroup/cva6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrt0.S
72 lines (62 loc) · 1.85 KB
/
crt0.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright (c) 2017 SiFive Inc. All rights reserved.
* Copyright (c) 2019 ETH Zürich and University of Bologna
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the FreeBSD License. This program is distributed in the hope that
* 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.
*/
/* Make sure the vector table gets linked into the binary. */
.global vector_table
/* Entry point for bare metal programs */
.section .text.start
.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
/* initialize stack pointer */
la sp, __stack_end
/* set vector table address */
la a0, __vector_start
ori a0, a0, 1 /*vector mode = vectored */
csrw mtvec, a0
/* clear the bss segment */
la a0, _edata
la a2, _end
sub a2, a2, a0
li a1, 0
call memset
/* new-style constructors and destructors */
la a0, __libc_fini_array
call atexit
call __libc_init_array
/* call main */
// lw a0, 0(sp) /* a0 = argc */
// addi a1, sp, __SIZEOF_POINTER__ /* a1 = argv */
// li a2, 0 /* a2 = envp = NULL */
// Initialize these variables to 0. Cannot use argc or argv
// since the stack is not initialized
li a0, 0
li a1, 0
li a2, 0
call main
tail exit
.size _start, .-_start
.global _init
.type _init, @function
.global _fini
.type _fini, @function
_init:
_fini:
/* These don't have to do anything since we use init_array/fini_array. Prevent
missing symbol error */
ret
.size _init, .-_init
.size _fini, .-_fini