summaryrefslogtreecommitdiff
path: root/bsp/hpmicro/hpm6200evk/startup/HPM6280/startup.c
blob: 1928adaf5809446cf03ff79392e06c10ef91fc32 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (c) 2021-2025 HPMicro
 *
 *
 */

 #include "hpm_common.h"
 #include "hpm_soc.h"
 #include "hpm_l1c_drv.h"
 #include <rtthread.h>
 
 void system_init(void);
 
 extern int entry(void);
 
 extern void __libc_init_array(void);
 extern void __libc_fini_array(void);
 
 void system_init(void)
 {
     disable_global_irq(CSR_MSTATUS_MIE_MASK);
     disable_irq_from_intc();
     enable_irq_from_intc();
     enable_global_irq(CSR_MSTATUS_MIE_MASK);
 #ifndef CONFIG_NOT_ENABLE_ICACHE
     l1c_ic_enable();
 #endif
 #ifndef CONFIG_NOT_ENABLE_DCACHE
     l1c_dc_enable();
 #endif
 }
 
 __attribute__((weak)) void c_startup(void)
 {
 #ifndef __SES_RISCV
     uint32_t i, size;
 #ifdef FLASH_XIP
     extern uint8_t __vector_ram_start__[], __vector_ram_end__[], __vector_load_addr__[];
     size = __vector_ram_end__ - __vector_ram_start__;
     for (i = 0; i < size; i++) {
         *(__vector_ram_start__ + i) = *(__vector_load_addr__ + i);
     }
 #endif
 
     extern uint8_t __etext[];
     extern uint8_t __bss_start__[], __bss_end__[];
     extern uint8_t __tbss_start__[], __tbss_end__[];
     extern uint8_t __tdata_start__[], __tdata_end__[];
     extern uint8_t __fast_load_addr__[];
     extern uint8_t __noncacheable_init_load_addr__[];
     extern uint8_t __data_load_addr__[];
     extern uint8_t __tdata_load_addr__[];
     extern uint8_t __data_start__[], __data_end__[];
     extern uint8_t __noncacheable_bss_start__[], __noncacheable_bss_end__[];
     extern uint8_t __ramfunc_start__[], __ramfunc_end__[];
     extern uint8_t __noncacheable_init_start__[], __noncacheable_init_end__[];
 
     /* tbss section */
     size = __tbss_end__ - __tbss_start__;
     for (i = 0; i < size; i++) {
         *(__tbss_start__ + i) = 0;
     }
 
     /* bss section */
     size = __bss_end__ - __bss_start__;
     for (i = 0; i < size; i++) {
         *(__bss_start__ + i) = 0;
     }
 
     /* noncacheable bss section */
     size = __noncacheable_bss_end__ - __noncacheable_bss_start__;
     for (i = 0; i < size; i++) {
         *(__noncacheable_bss_start__ + i) = 0;
     }
 
     /* tdata section LMA: etext */
     size = __tdata_end__ - __tdata_start__;
     for (i = 0; i < size; i++) {
         *(__tdata_start__ + i) = *(__tdata_load_addr__ + i);
     }
 
     /* data section LMA: etext */
     size = __data_end__ - __data_start__;
     for (i = 0; i < size; i++) {
         *(__data_start__ + i) = *(__data_load_addr__ + i);
     }
 
     /* ramfunc section LMA: etext + data length */
     size = __ramfunc_end__ - __ramfunc_start__;
     for (i = 0; i < size; i++) {
         *(__ramfunc_start__ + i) = *(__fast_load_addr__ + i);
     }
 
     /* noncacheable init section LMA: etext + data length + ramfunc length */
     size = __noncacheable_init_end__ - __noncacheable_init_start__;
     for (i = 0; i < size; i++) {
         *(__noncacheable_init_start__ + i) = *(__noncacheable_init_load_addr__ + i);
     }
 #endif
 }
 
 __attribute__((weak)) int main(void)
 {
     while(1);
 }
 
 void reset_handler(void)
 {
     /**
      * Disable preemptive interrupt
      */
     HPM_PLIC->FEATURE = 0;
     /*
      * Initialize LMA/VMA sections.
      * Relocation for any sections that need to be copied from LMA to VMA.
      */
     c_startup();
 
     /* Call platform specific hardware initialization */
     system_init();
 
 #ifndef __SES_RISCV
     /* Do global constructors */
     __libc_init_array();
 #endif
 
     /* Entry function */
     entry();
 }
 
 
 __attribute__((weak)) void _init(void)
 {
 }