forked from wolfSSL/wolfBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup_riscv.c
84 lines (71 loc) · 2.18 KB
/
startup_riscv.c
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
73
74
75
76
77
78
79
80
81
82
83
84
/* startup_riscv.c
*
* Copyright (C) 2021 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdint.h>
extern void trap_entry(void);
extern void trap_exit(void);
extern uint32_t _start_vector;
extern uint32_t _stored_data;
extern uint32_t _start_data;
extern uint32_t _end_data;
extern uint32_t _start_bss;
extern uint32_t _end_bss;
extern uint32_t _end_stack;
extern uint32_t _start_heap;
extern uint32_t _global_pointer;
extern void (* const IV[])(void);
extern void main(void);
void __attribute__((naked,section(".init"))) _reset(void) {
register uint32_t *src, *dst;
asm volatile("la gp, _global_pointer");
asm volatile("la sp, _end_stack");
/* Set up vectored interrupt, with IV starting at offset 0x100 */
asm volatile("csrw mtvec, %0":: "r"((uint8_t *)(&_start_vector) + 1));
src = (uint32_t *) &_stored_data;
dst = (uint32_t *) &_start_data;
/* Copy the .data section from flash to RAM. */
while (dst < (uint32_t *)&_end_data) {
*dst = *src;
dst++;
src++;
}
/* Initialize the BSS section to 0 */
dst = &_start_bss;
while (dst < (uint32_t *)&_end_bss) {
*dst = 0U;
dst++;
}
/* Run wolfboot */
main();
while(1)
;
}
void do_boot(const uint32_t *app_offset)
{
}
static uint32_t synctrap_cause = 0;
void __attribute__((naked)) isr_synctrap(void)
{
asm volatile("csrr %0,mcause" : "=r"(synctrap_cause));
//asm volatile("ebreak");
}
void isr_empty(void)
{
}