1 /*
2  * Copyright (c) 2012-2015 Wind River Systems, Inc.
3  * Copyright (c) 2021 Synopsys, Inc.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 void __do_global_ctors_aux(void);
9 void __do_init_array_aux(void);
10 
z_init_static(void)11 void z_init_static(void)
12 {
13 #if defined(CONFIG_STATIC_INIT_GNU)
14 	__do_global_ctors_aux();
15 	__do_init_array_aux();
16 #elif defined(__CCAC__) /* ARC MWDT */
17 	__do_global_ctors_aux();
18 #endif
19 }
20 
21 /**
22  * @section - Constructor module
23  * @brief
24  * The ctors section contains a list of function pointers that execute both the C++ constructors of
25  * static global objects, as well as either C or C++ initializer functions (declared with the
26  * attribute constructor). These must be executed before the application's main() routine.
27  *
28  * NOTE: Not all compilers put those function pointers into the ctors section;
29  * some put them into the init_array section instead.
30  */
31 
32 #ifdef CONFIG_STATIC_INIT_GNU
33 
34 /* What a constructor function pointer looks like */
35 
36 typedef void (*CtorFuncPtr)(void);
37 
38 /* Constructor function pointer list is generated by the linker script. */
39 
40 extern CtorFuncPtr __ZEPHYR_CTOR_LIST__[];
41 extern CtorFuncPtr __ZEPHYR_CTOR_END__[];
42 
43 /**
44  *
45  * @brief Invoke all C++ style global object constructors
46  *
47  * This routine is invoked by the kernel prior to the execution of the
48  * application's main().
49  */
__do_global_ctors_aux(void)50 void __do_global_ctors_aux(void)
51 {
52 	unsigned int nCtors;
53 
54 	nCtors = (unsigned long)__ZEPHYR_CTOR_LIST__[0];
55 
56 	while (nCtors >= 1U) {
57 		__ZEPHYR_CTOR_LIST__[nCtors--]();
58 	}
59 }
60 
61 #endif
62 
63 /*
64  * @section
65  * @brief Execute initialization routines referenced in .init_array section
66  */
67 
68 #ifdef CONFIG_STATIC_INIT_GNU
69 
70 typedef void (*func_ptr)(void);
71 
72 extern func_ptr __zephyr_init_array_start[];
73 extern func_ptr __zephyr_init_array_end[];
74 
75 /**
76  * @brief Execute initialization routines referenced in .init_array section
77  */
__do_init_array_aux(void)78 void __do_init_array_aux(void)
79 {
80 	for (func_ptr *func = __zephyr_init_array_start;
81 		func < __zephyr_init_array_end;
82 		func++) {
83 		(*func)();
84 	}
85 }
86 
87 #endif
88