-
Notifications
You must be signed in to change notification settings - Fork 1
/
flash_crt.S
72 lines (62 loc) · 1.81 KB
/
flash_crt.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 lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
/**
* Flash executable runtime initialization code.
*/
// NOTE: The "ax" flag below is necessary to ensure that this section
// is allocated space in ROM by the linker.
.section .crt, "ax"
.extern main
/**
* Callable entry point for flash.
*
* This sets up the stack, zeroes |.bss|, and sets up |.data|.
* It then jumps into main.
*/
_start:
.globl _start
// Set up the stack. We have no expectation that the rom that
// jumps here will have the correct stack start linked in.
la sp, _stack_start
// Set up the new interrupt vector.
la t0, _vectors_start
csrw mtvec, t0
// Zero out the |.bss| segment.
//
// We use |t0| and |t1| to represent the start and end pointers
// of |.bss|.
la t0, _bss_start
la t1, _bss_end
bge t0, t1, bss_zero_loop_end
bss_zero_loop:
sw zero, 0(t0)
addi t0, t0, 0x4
ble t0, t1, bss_zero_loop
bss_zero_loop_end:
// Initialize the |.data| segment from the |.idata| segment.
//
// We use |t0| and |t1| to represent the start and end pointers
// of |.data|, |t2| to represent the start pointer of |.idata|
// (which has the same length as |.data|) and |t3| is a scratch
// register for the copy.
la t0, _data_start
la t1, _data_end
la t2, _data_init_start
bge t0, t1, data_copy_loop_end
data_copy_loop:
lw t3, 0(t2)
sw t3, 0(t0)
addi t0, t0, 0x4
addi t2, t2, 0x4
ble t0, t1, data_copy_loop
data_copy_loop_end:
// Jump into the C program entry point. This is your standard
// C |main()|, so we need to pass dummy values for |argc| and |argv|.
li a0, 0x0 // argc = 0
li a1, 0x0 // argv = NULL
call main
// Loop forever if main somehow returns.
1:
wfi
j 1b