-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path_startc.c
61 lines (46 loc) · 1.44 KB
/
_startc.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
/*
* Phoenix-RTOS
*
* Entrypoint
*
* Copyright 2021-2022 Phoenix Systems
* Author: Hubert Buczynski, Gerard Swiderski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#include <hal/hal.h>
extern char __bss_start[], __bss_end[];
extern char __data_load[], __data_start[], __data_end[];
extern char __rodata_load[], __rodata_start[], __rodata_end[];
extern char __ramtext_load[], __ramtext_start[], __ramtext_end[];
extern void (*__init_array_start[])(void);
extern void (*__init_array_end[])(void);
extern void (*__fini_array_start[])(void);
extern void (*__fini_array_end[])(void);
extern int main(void);
void _startc(int argc, char **argv, char **env)
{
size_t i, size;
/* Load .fastram.text, .data and .rodata sections */
if (__ramtext_start != __ramtext_load) {
/* hal_memcpy may reside in fastram. */
for (i = 0; i <= __ramtext_end - __ramtext_start; i++) {
__ramtext_start[i] = __ramtext_load[i];
}
}
if (__data_start != __data_load)
hal_memcpy(__data_start, __data_load, __data_end - __data_start);
if (__rodata_start != __rodata_load)
hal_memcpy(__rodata_start, __rodata_load, __rodata_end - __rodata_start);
/* Clear the .bss section */
hal_memset(__bss_start, 0, __bss_end - __bss_start);
size = __init_array_end - __init_array_start;
for (i = 0; i < size; i++)
(*__init_array_start[i])();
main();
size = __fini_array_end - __fini_array_start;
for (i = size; i > 0; i--)
(*__fini_array_start[i - 1])();
}