]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_IGLOO2_Creative_SoftConsole/riscv_hal/init.c
Backup checkin of MiFive demo running in ReNode emulator.
[freertos] / FreeRTOS / Demo / RISC-V_IGLOO2_Creative_SoftConsole / riscv_hal / init.c
1 /*******************************************************************************\r
2  * (c) Copyright 2016-2018 Microsemi SoC Products Group.  All rights reserved.\r
3  *\r
4  * @file init.c\r
5  * @author Microsemi SoC Products Group\r
6  * @brief Mi-V soft processor memory section initializations and start-up code.\r
7  *\r
8  * SVN $Revision: 9661 $\r
9  * SVN $Date: 2018-01-15 16:13:33 +0530 (Mon, 15 Jan 2018) $\r
10  */\r
11 \r
12 #include <stdlib.h>\r
13 #include <stdint.h>\r
14 #include <unistd.h>\r
15 \r
16 #include "encoding.h"\r
17 \r
18 #ifdef __cplusplus\r
19 extern "C" {\r
20 #endif\r
21 \r
22 extern uint32_t     __sdata_load;\r
23 extern uint32_t     __sdata_start;\r
24 extern uint32_t     __sdata_end;\r
25 \r
26 extern uint32_t     __data_load;\r
27 extern uint32_t     __data_start;\r
28 extern uint32_t     __data_end;\r
29 \r
30 extern uint32_t     __sbss_start;\r
31 extern uint32_t     __sbss_end;\r
32 extern uint32_t     __bss_start;\r
33 extern uint32_t     __bss_end;\r
34 \r
35 \r
36 static void copy_section(uint32_t * p_load, uint32_t * p_vma, uint32_t * p_vma_end)\r
37 {\r
38     while(p_vma <= p_vma_end)\r
39     {\r
40         *p_vma = *p_load;\r
41         ++p_load;\r
42         ++p_vma;\r
43     }\r
44 }\r
45 \r
46 static void zero_section(uint32_t * start, uint32_t * end)\r
47 {\r
48     uint32_t * p_zero = start;\r
49     \r
50     while(p_zero <= end)\r
51     {\r
52         *p_zero = 0;\r
53         ++p_zero;\r
54     }\r
55 }\r
56 \r
57 void _init(void)\r
58 {\r
59     extern int main(int, char**);\r
60     const char *argv0 = "hello";\r
61     char *argv[] = {(char *)argv0, NULL, NULL};\r
62 \r
63     copy_section(&__sdata_load, &__sdata_start, &__sdata_end);\r
64     copy_section(&__data_load, &__data_start, &__data_end);\r
65     zero_section(&__sbss_start, &__sbss_end);\r
66     zero_section(&__bss_start, &__bss_end);\r
67     \r
68     main(1, argv);\r
69 }\r
70 \r
71 /* Function called after main() finishes */\r
72 void\r
73 _fini()\r
74 {\r
75 }\r
76 \r
77 #ifdef __cplusplus\r
78 }\r
79 #endif\r
80 \r