VSF Documented
vsf_cfg.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18
21#ifndef __VSF_CFG_H__
22#define __VSF_CFG_H__
23
24/*============================ MACROS ========================================*/
25
26#ifndef ENABLED
27# define ENABLED 1
28#endif
29
30#ifndef DISABLED
31# define DISABLED 0
32#endif
33
34/*============================ INCLUDES ======================================*/
35
36/* do not modify this */
37#include "vsf_usr_cfg.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*============================ MACROS ========================================*/
44
45#if !defined(__VSF_RELEASE__) && !defined(__VSF_DEBUG__)
46# define __VSF_DEBUG__ 1
47#elif defined(__VSF_RELEASE__) && defined(__VSF_DEBUG__)
48# error Both __VSF_RELEASE__ and __VSF_DEBUG__ are defined!!!! They should be\
49 mutually exclusive from each other, i.e. either define __VSF_RELEASE__ or\
50 __VSF_DEBUG__. If neither of them are defined, __VSF_DEBUG__ will be assumed.
51#endif
52
53
54#ifndef VSF_USE_KERNEL
55# define VSF_USE_KERNEL ENABLED
56#endif
57
58#ifndef Hz
59# define Hz ul
60#endif
61
62#ifndef VSF_USR_SWI_NUM
63# define VSF_USR_SWI_NUM 0
64#endif
65
66#if VSF_USE_KERNEL == ENABLED && defined(VSF_OS_CFG_PRIORITY_NUM)
67# if (VSF_OS_CFG_PRIORITY_NUM < 1)
68# error VSF_OS_CFG_PRIORITY_NUM MUST be defined to calculate \
69__VSF_HAL_SWI_NUM and its value must at least be 1.
70# endif
71
72# if VSF_OS_CFG_ADD_EVTQ_TO_IDLE == ENABLED
73# if VSF_OS_CFG_PRIORITY_NUM > 1
74# define __VSF_HAL_SWI_NUM (VSF_OS_CFG_PRIORITY_NUM - 1)
75# else
76# define __VSF_HAL_SWI_NUM 0
77# endif
78# else
79# define __VSF_HAL_SWI_NUM (VSF_OS_CFG_PRIORITY_NUM)
80# endif
81// priority configurations
82# define __VSF_OS_SWI_NUM __VSF_HAL_SWI_NUM
83#endif
84
85#if (defined(VSF_DEBUGGER_CFG_CONSOLE) && (defined(VSF_HAL_USE_DEBUG_STREAM) && VSF_HAL_USE_DEBUG_STREAM == ENABLED))\
86 || (defined(VSF_CFG_DEBUG_STREAM_TX_T) && (defined(VSF_HAL_USE_DEBUG_STREAM) && VSF_HAL_USE_DEBUG_STREAM == ENABLED))\
87 || (defined(VSF_DEBUGGER_CFG_CONSOLE) && defined(VSF_CFG_DEBUG_STREAM_TX_T))
88# error "please enable one of VSF_HAL_USE_DEBUG_STREAM/VSF_DEBUGGER_CFG_CONSOLE/VSF_CFG_DEBUG_STREAM_TX_T"
89#endif
90
91// for vplt
92#ifndef __VSF_VPLT_DECORATOR__
93# define __VSF_VPLT_DECORATOR__ const
94#endif
95typedef union vsf_vplt_info_t {
96 struct {
97 unsigned char major;
98 unsigned char minor;
99 unsigned short final : 1;
100 unsigned short entry_num : 15;
101 };
104
105typedef struct vsf_vplt_t {
107
111 void *hal_vplt;
118
121
122typedef struct vsf_dynamic_vplt_t {
124 void *ram_vplt;
126#ifndef __VSF_APPLET__
128extern int vsf_vplt_load_dyn(vsf_vplt_info_t *info);
129#endif
130
131#ifndef VSF_APPLET_CFG_LINKABLE
132# define VSF_APPLET_CFG_LINKABLE ENABLED
133#endif
134#if VSF_APPLET_CFG_LINKABLE == ENABLED && !defined(__VSF_APPLET__)
135extern void * vsf_vplt_link(void *vplt, char *symname);
137#endif
138typedef struct vsf_vplt_entry_t {
139#if VSF_APPLET_CFG_LINKABLE == ENABLED
140 // TODO: implement hash for link performance
141 const char *name;
142#endif
143 void *ptr;
145
146#define VSF_APPLET_VPLT_INFO(__TYPE, __MAJOR, __MINOR, __FINAL) \
147 .info = { \
148 .major = (__MAJOR), \
149 .minor = (__MINOR), \
150 .final = (__FINAL), \
151 .entry_num = (sizeof(__TYPE) - sizeof(vsf_vplt_info_t)) \
152 / ((__FINAL) ? sizeof(vsf_vplt_entry_t) : sizeof(void *)),\
153 }
154#define VSF_APPLET_VPLT_ENTRY_MOD_DEF(__NAME) \
155 vsf_vplt_entry_t mod_##__NAME
156#define VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__NAME) \
157 vsf_vplt_entry_t fn_##__NAME
158#define VSF_APPLET_VPLT_ENTRY_VAR_DEF(__NAME) \
159 vsf_vplt_entry_t var_##__NAME
160#define VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(__VPLT, __NAME) \
161 ((__##__NAME##_prototype_t)((__VPLT)->fn_##__NAME.ptr))
162#define VSF_APPLET_VPLT_ENTRY_VAR_ENTRY(__VPLT, __NAME) \
163 ((__VPLT)->var_##__NAME.ptr)
164#if VSF_APPLET_CFG_DEBUG_VPLT == ENABLED
165# define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE() \
166 vsf_vplt_trace("vplt invoke: %s\n", __FUNCTION__)
167#else
168# define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
169#endif
170#ifndef VSF_APPLET_VPLT_FUNC_DECORATOR
171# define VSF_APPLET_VPLT_FUNC_DECORATOR(__NAME) static inline
172#endif
173#define VSF_APPLET_VPLT_ENTRY_FUNC_IMP(__VPLT, __NAME, __RET, ...) \
174 typedef __RET (*__##__NAME##_prototype_t)(__VA_ARGS__); \
175 VSF_APPLET_VPLT_FUNC_DECORATOR(__NAME) __RET __NAME(__VA_ARGS__)
176#if VSF_APPLET_CFG_LINKABLE == ENABLED
177# define VSF_APPLET_VPLT_ENTRY_FUNC_EX(__ENTRY, __NAME, __PTR) \
178 .__ENTRY = { \
179 .name = (__NAME), \
180 .ptr = (void *)(__PTR), \
181 }
182# define VSF_APPLET_VPLT_ENTRY_FUNC(__NAME) \
183 .fn_##__NAME = { \
184 .name = VSF_STR(__NAME), \
185 .ptr = (void *)(__NAME), \
186 }
187# define VSF_APPLET_VPLT_ENTRY_VAR(__NAME) \
188 .var_##__NAME = { \
189 .name = VSF_STR(__NAME), \
190 .ptr = (void *)&(__NAME), \
191 }
192# define VSF_APPLET_VPLT_ENTRY_MOD(__NAME, __MOD) \
193 .mod_##__NAME = { \
194 .name = VSF_STR(__NAME), \
195 .ptr = (void *)&(__MOD), \
196 }
197#else
198# define VSF_APPLET_VPLT_ENTRY_FUNC_EX(__ENTRY, __NAME, __PTR) \
199 .__ENTRY = { \
200 .ptr = (void *)(__PTR), \
201 }
202# define VSF_APPLET_VPLT_ENTRY_FUNC(__NAME) \
203 .fn_##__NAME = { \
204 .ptr = (void *)(__NAME), \
205 }
206# define VSF_APPLET_VPLT_ENTRY_VAR(__NAME) \
207 .var_##__NAME = { \
208 .ptr = (void *)&(__NAME), \
209 }
210# define VSF_APPLET_VPLT_ENTRY_MOD(__NAME, __MOD) \
211 .mod_##__NAME = { \
212 .ptr = (void *)&(__MOD), \
213 }
214#endif
215
216#ifndef __VSF_APPLET_CTX_DEFINED__
217#define __VSF_APPLET_CTX_DEFINED__
220 void *target;
221 int (*fn_init)(void *);
222 void (*fn_fini)(void *);
223 void * (*fn_remap)(vsf_applet_ctx_t *ctx, void *vaddr);
224
225 int argc;
226 char **argv;
227 char **envp;
228 void *vplt;
229};
230#endif
231
232#ifdef __VSF_APPLET__
233# if VSF_USE_APPLET == ENABLED && !defined(VSF_APPLET_VPLT)
234# define VSF_APPLET_VPLT ((vsf_vplt_t *)vsf_vplt((void *)0))
235# endif
236
237# ifdef __WIN__
238# if VSF_APPLET_CFG_ABI_PATCH == ENABLED
239# define applet_raw_entry \
240 void _dllstart(void) \
241 { \
242 _start(); \
243 }
244# else
245# define applet_raw_entry \
246 void _dllstart(vsf_applet_ctx_t *ctx) \
247 { \
248 _start(ctx); \
249 }
250# endif
251# else
252# define applet_raw_entry
253# endif
254
255# ifndef applet_entry_with_ctx
256# if VSF_APPLET_CFG_ABI_PATCH == ENABLED
257extern vsf_applet_ctx_t * vsf_applet_ctx(void);
258extern int vsf_vplt_init_array(void *target);
259extern void vsf_vplt_fini_array(void *target);
260# define applet_entry_with_ctx \
261 _start(void) { vsf_applet_ctx_t *ctx = vsf_applet_ctx();
262# define applet_init_array vsf_vplt_init_array
263# define applet_fini_array vsf_vplt_fini_array
264# else
265# define applet_entry_with_ctx \
266 _start(vsf_applet_ctx_t *ctx) {
267# define applet_init_array ctx->fn_init
268# define applet_fini_array ctx->fn_fini
269# endif
270# endif
271
272# ifndef VSF_APPLET_VPLT_ENTRY_DECORATOR
273# define VSF_APPLET_VPLT_ENTRY_DECORATOR
274# endif
275VSF_APPLET_VPLT_ENTRY_DECORATOR extern void * vsf_vplt(void *vplt);
276VSF_APPLET_VPLT_ENTRY_DECORATOR extern void * vsf_applet_remap(vsf_applet_ctx_t *applet_ctx, void *vaddr);
277# define main(...) \
278 applet_entry_with_ctx \
279 int result; \
280 vsf_applet_remap(ctx, (void *)0); \
281 vsf_vplt(ctx->vplt); \
282 if (applet_init_array != (void *)0) { \
283 result = applet_init_array(ctx->target); \
284 if (result) { \
285 return result; \
286 } \
287 } \
288 extern int main(__VA_ARGS__); \
289 result = ((int (*)(int, char **, char **))main)(ctx->argc, ctx->argv, ctx->envp);\
290 if (applet_fini_array != (void *)0) { \
291 applet_fini_array(ctx->target); \
292 } \
293 return result; \
294 } \
295 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_vplt(void *vplt) \
296 { \
297 static void *__vplt = (void *)0; \
298 if (vplt != (void *)0) { \
299 __vplt = vplt; \
300 VSF_APPLET_VPLT_ENTRY_FUNC_TRACE(); \
301 } \
302 return __vplt; \
303 } \
304 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_applet_remap(vsf_applet_ctx_t *applet_ctx, void *vaddr)\
305 { \
306 static vsf_applet_ctx_t *__vsf_applet_ctx = (vsf_applet_ctx_t *)0; \
307 void *realptr = (void *)0; \
308 if (applet_ctx != (vsf_applet_ctx_t *)0) { \
309 __vsf_applet_ctx = applet_ctx; \
310 } else if ( \
311 (__vsf_applet_ctx != (vsf_applet_ctx_t *)0) \
312 && (__vsf_applet_ctx->fn_remap != (void * (*)(vsf_applet_ctx_t *, void *))0)) {\
313 realptr = __vsf_applet_ctx->fn_remap(__vsf_applet_ctx, vaddr); \
314 } \
315 return realptr; \
316 } \
317 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_vplt_link(void *vplt, char *symname)\
318 { \
319 vsf_vplt_t *root_vplt = vsf_vplt((void *)0); \
320 return ((void * (*)(void *vplt, char *symname)) \
321 (((vsf_applet_vplt_t *)root_vplt->applet_vplt)->fn_vsf_vplt_link.ptr))\
322 (vplt, symname); \
323 } \
324 applet_raw_entry \
325 int main(__VA_ARGS__)
326#endif
327
328#if VSF_USE_APPLET == ENABLED || VSF_LINUX_USE_APPLET == ENABLED
329
330typedef struct vsf_applet_vplt_t {
332
342
343# if defined(__VSF_APPLET__) && defined(__VSF_APPLET_LIB__) && VSF_APPLET_CFG_DEBUG_VPLT == ENABLED
344# include <stdarg.h>
345# define VSF_APPLET_VPLT \
346 ((vsf_applet_vplt_t *)(((vsf_vplt_t *)vsf_vplt((void *)0))->applet_vplt))
347
348#define VSF_VPLT_APPLET_ENTRY(__NAME) \
349 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_APPLET_VPLT, __NAME)
350#define VSF_VPLT_APPLET_IMP(...) \
351 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_APPLET_VPLT, __VA_ARGS__)
352
353VSF_VPLT_APPLET_IMP(vsf_vplt_trace_arg, void, const char *fmt, va_list arg) {
354 VSF_VPLT_APPLET_ENTRY(vsf_vplt_trace_arg)(fmt, arg);
355}
356
357static void vsf_vplt_trace(const char *format, ...)
358{
359 va_list ap;
360
361 va_start(ap, format);
363 va_end(ap);
364}
365
366# endif
367
368# ifndef VSF_APPLET_USE_ARCH
369# define VSF_APPLET_USE_ARCH ENABLED
370# endif
371# ifndef VSF_APPLET_USE_SERVICE
372# define VSF_APPLET_USE_SERVICE ENABLED
373# endif
374#endif
375
376/*============================ MACROFIED FUNCTIONS ===========================*/
377/*============================ TYPES =========================================*/
378/*============================ GLOBAL VARIABLES ==============================*/
379/*============================ LOCAL VARIABLES ===============================*/
380/*============================ PROTOTYPES ====================================*/
381
382#ifdef __cplusplus
383}
384#endif
385
386#endif
387/* EOF */
Definition vsf_cfg.h:219
char ** envp
Definition vsf_cfg.h:227
void(* fn_fini)(void *)
Definition vsf_cfg.h:222
int(* fn_init)(void *)
Definition vsf_cfg.h:221
void * vplt
Definition vsf_cfg.h:228
char ** argv
Definition vsf_cfg.h:226
void * target
Definition vsf_cfg.h:220
int argc
Definition vsf_cfg.h:225
Definition vsf_cfg.h:330
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_vplt_fini_array)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_vplt_load_dyn)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_applet_remap)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_vplt_trace_arg)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_vplt_link)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_vplt_init_array)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_applet_ctx)
vsf_vplt_info_t info
Definition vsf_cfg.h:331
Definition vsf_cfg.h:122
void * ram_vplt
Definition vsf_cfg.h:124
vsf_vplt_info_t info
Definition vsf_cfg.h:123
Definition vsf_cfg.h:138
const char * name
Definition vsf_cfg.h:141
void * ptr
Definition vsf_cfg.h:143
Definition vsf_cfg.h:105
void * dynamic_vplt
Definition vsf_cfg.h:116
void * utilities_vplt
Definition vsf_cfg.h:109
void * kernel_vplt
Definition vsf_cfg.h:113
void * service_vplt
Definition vsf_cfg.h:112
void * applet_vplt
Definition vsf_cfg.h:108
void * hal_vplt
Definition vsf_cfg.h:111
vsf_vplt_info_t info
Definition vsf_cfg.h:106
void * component_vplt
Definition vsf_cfg.h:114
void * compiler_vplt
Definition vsf_cfg.h:117
void * arch_abi_vplt
Definition vsf_cfg.h:115
void * arch_vplt
Definition vsf_cfg.h:110
void * linux_vplt
Definition vsf_cfg.h:119
Definition vsf_cfg.h:95
unsigned char minor
Definition vsf_cfg.h:98
unsigned short final
Definition vsf_cfg.h:99
unsigned char major
Definition vsf_cfg.h:97
void * __make_vplt_info_aligned
Definition vsf_cfg.h:102
unsigned short entry_num
Definition vsf_cfg.h:100
vsf_applet_ctx_t * vsf_applet_ctx(void)
Definition vsf.c:180
int vsf_vplt_init_array(void *target)
Definition vsf.c:175
void * vsf_applet_remap(vsf_applet_ctx_t *ctx, void *vaddr)
Definition vsf.c:186
void vsf_vplt_fini_array(void *target)
Definition vsf.c:177
void vsf_vplt_trace_arg(const char *fmt, va_list arg)
Definition vsf.c:192
__VSF_VPLT_DECORATOR__ vsf_applet_vplt_t vsf_applet_vplt
Definition vsf.c:199
vsf_dynamic_vplt_t vsf_dynamic_vplt
Definition vsf.c:61
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
__VSF_VPLT_DECORATOR__ vsf_vplt_t vsf_vplt
Definition vsf.c:36
void * vsf_vplt_link(void *vplt, char *symname)
Definition vsf.c:102
int vsf_vplt_load_dyn(vsf_vplt_info_t *info)
Definition vsf.c:114
SDL_PixelFormat format
Definition vsf_sdl2_pixelformat.c:32