• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef LITE_BOOTSTRAP_SERVICE_H
16 #define LITE_BOOTSTRAP_SERVICE_H
17 #ifdef __cplusplus
18 #if __cplusplus
19 extern "C" {
20 #endif
21 #endif
22 
23 #define APP_NAME(name, step) ".zinitcall.app." #name #step ".init"
24 #define MODULE_NAME(name, step) ".zinitcall." #name #step ".init"
25 
26 #define APP_CALL(name, step)                                      \
27     do {                                                          \
28         InitCall *initcall = (InitCall *)(APP_BEGIN(name, step)); \
29         InitCall *initend = (InitCall *)(APP_END(name, step));    \
30         for (; initcall < initend; initcall++) {                  \
31             (*initcall)();                                        \
32         }                                                         \
33     } while (0)
34 
35 #define MODULE_CALL(name, step)                                      \
36     do {                                                             \
37         InitCall *initcall = (InitCall *)(MODULE_BEGIN(name, step)); \
38         InitCall *initend = (InitCall *)(MODULE_END(name, step));    \
39         for (; initcall < initend; initcall++) {                     \
40             (*initcall)();                                           \
41         }                                                            \
42     } while (0)
43 
44 #if (defined(__GNUC__) || defined(__clang__))
45 #define APP_BEGIN(name, step)                                 \
46     ({  extern InitCall __zinitcall_app_##name##_start;       \
47         InitCall *initCall = &__zinitcall_app_##name##_start; \
48         (initCall);                                           \
49     })
50 
51 #define APP_END(name, step)                                 \
52     ({  extern InitCall __zinitcall_app_##name##_end;       \
53         InitCall *initCall = &__zinitcall_app_##name##_end; \
54         (initCall);                                         \
55     })
56 
57 #define MODULE_BEGIN(name, step)                          \
58     ({  extern InitCall __zinitcall_##name##_start;       \
59         InitCall *initCall = &__zinitcall_##name##_start; \
60         (initCall);                                       \
61     })
62 #define MODULE_END(name, step)                          \
63     ({  extern InitCall __zinitcall_##name##_end;       \
64         InitCall *initCall = &__zinitcall_##name##_end; \
65         (initCall);                                     \
66     })
67 
68 #define INIT_APP_CALL(name) APP_CALL(name, 0);
69 
70 #define INIT_TEST_CALL()    MODULE_CALL(test, 0);
71 #elif (defined(__ICCARM__))
72 #define APP_BEGIN(name, step) __section_begin(APP_NAME(name, step))
73 #define APP_END(name, step) __section_end(APP_NAME(name, step))
74 #define MODULE_BEGIN(name, step) __section_begin(MODULE_NAME(name, step))
75 #define MODULE_END(name, step) __section_end(MODULE_NAME(name, step))
76 
77 #pragma section = APP_NAME(service, 0)
78 #pragma section = APP_NAME(service, 1)
79 #pragma section = APP_NAME(service, 2)
80 #pragma section = APP_NAME(service, 3)
81 #pragma section = APP_NAME(service, 4)
82 #pragma section = APP_NAME(feature, 0)
83 #pragma section = APP_NAME(feature, 1)
84 #pragma section = APP_NAME(feature, 2)
85 #pragma section = APP_NAME(feature, 3)
86 #pragma section = APP_NAME(feature, 4)
87 #pragma section = MODULE_NAME(test, 0)
88 #pragma section = MODULE_NAME(test, 1)
89 #pragma section = MODULE_NAME(test, 2)
90 #pragma section = MODULE_NAME(test, 3)
91 #pragma section = MODULE_NAME(test, 4)
92 
93 #define INIT_APP_CALL(name) \
94     do {                    \
95         APP_CALL(name, 0);  \
96         APP_CALL(name, 1);  \
97         APP_CALL(name, 2);  \
98         APP_CALL(name, 3);  \
99         APP_CALL(name, 4);  \
100     } while (0)
101 
102 #define INIT_TEST_CALL()      \
103     do {                      \
104         MODULE_CALL(test, 0); \
105         MODULE_CALL(test, 1); \
106         MODULE_CALL(test, 2); \
107         MODULE_CALL(test, 3); \
108         MODULE_CALL(test, 4); \
109     } while (0)
110 #else
111 #error Not support current compiler!
112 #endif
113 
114 #ifdef __cplusplus
115 #if __cplusplus
116 }
117 #endif
118 #endif
119 #endif // LITE_BOOTSTRAP_SERVICE_H
120