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_CFG_DEBUG_STREAM_TX) && (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
121
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 void * (*fn_vplt_link)(void *vplt, char *symname);
230};
231#endif
232
233#ifdef __VSF_APPLET__
234# if VSF_USE_APPLET == ENABLED && !defined(VSF_APPLET_VPLT)
235# define VSF_APPLET_VPLT ((vsf_vplt_t *)vsf_vplt((void *)0))
236# endif
237
238# ifdef __WIN__
239# if VSF_APPLET_CFG_ABI_PATCH == ENABLED
240# define applet_raw_entry \
241 void _dllstart(void) \
242 { \
243 _start(); \
244 }
245# else
246# define applet_raw_entry \
247 void _dllstart(vsf_applet_ctx_t *ctx) \
248 { \
249 _start(ctx); \
250 }
251# endif
252# else
253# define applet_raw_entry
254# endif
255
256# ifndef applet_entry_with_ctx
257# if VSF_APPLET_CFG_ABI_PATCH == ENABLED
258extern vsf_applet_ctx_t * vsf_applet_ctx(void);
259extern int vsf_vplt_init_array(void *target);
260extern void vsf_vplt_fini_array(void *target);
261# define applet_entry_with_ctx \
262 _start(void) { vsf_applet_ctx_t *ctx = vsf_applet_ctx();
263# define applet_init_array vsf_vplt_init_array
264# define applet_fini_array vsf_vplt_fini_array
265# else
266# define applet_entry_with_ctx \
267 _start(vsf_applet_ctx_t *ctx) {
268# define applet_init_array ctx->fn_init
269# define applet_fini_array ctx->fn_fini
270# endif
271# endif
272
273# ifndef VSF_APPLET_VPLT_ENTRY_DECORATOR
274# define VSF_APPLET_VPLT_ENTRY_DECORATOR
275# endif
276VSF_APPLET_VPLT_ENTRY_DECORATOR extern void * vsf_vplt(void *vplt);
277VSF_APPLET_VPLT_ENTRY_DECORATOR extern void * vsf_applet_remap(vsf_applet_ctx_t *applet_ctx, void *vaddr);
278# define main(...) \
279 applet_entry_with_ctx \
280 int result; \
281 vsf_applet_remap(ctx, (void *)0); \
282 vsf_vplt(ctx->vplt); \
283 if (applet_init_array != (void *)0) { \
284 result = applet_init_array(ctx->target); \
285 if (result) { \
286 return result; \
287 } \
288 } \
289 extern int main(__VA_ARGS__); \
290 result = ((int (*)(int, char **, char **))main)(ctx->argc, ctx->argv, ctx->envp);\
291 if (applet_fini_array != (void *)0) { \
292 applet_fini_array(ctx->target); \
293 } \
294 return result; \
295 } \
296 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_vplt(void *vplt) \
297 { \
298 static void *__vplt = (void *)0; \
299 if (vplt != (void *)0) { \
300 __vplt = vplt; \
301 VSF_APPLET_VPLT_ENTRY_FUNC_TRACE(); \
302 } \
303 return __vplt; \
304 } \
305 static vsf_applet_ctx_t *__vsf_applet_ctx = (vsf_applet_ctx_t *)0; \
306 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_applet_remap(vsf_applet_ctx_t *applet_ctx, void *vaddr)\
307 { \
308 void *realptr = (void *)0; \
309 if (applet_ctx != (vsf_applet_ctx_t *)0) { \
310 __vsf_applet_ctx = applet_ctx; \
311 } else if ( \
312 (__vsf_applet_ctx != (vsf_applet_ctx_t *)0) \
313 && (__vsf_applet_ctx->fn_remap != (void * (*)(vsf_applet_ctx_t *, void *))0)) {\
314 realptr = __vsf_applet_ctx->fn_remap(__vsf_applet_ctx, vaddr); \
315 } \
316 return realptr; \
317 } \
318 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_vplt_link(void *vplt, char *symname)\
319 { \
320 if ((__vsf_applet_ctx == (vsf_applet_ctx_t *)0) \
321 || (__vsf_applet_ctx->fn_vplt_link == (void * (*)(void *, char *))0)) {\
322 return (void *)0; \
323 } \
324 return __vsf_applet_ctx->fn_vplt_link(vplt, symname); \
325 } \
326 applet_raw_entry \
327 int main(__VA_ARGS__)
328#endif
329
330#if VSF_USE_APPLET == ENABLED || VSF_LINUX_USE_APPLET == ENABLED
331
345
346# if defined(__VSF_APPLET__) && defined(__VSF_APPLET_LIB__) && VSF_APPLET_CFG_DEBUG_VPLT == ENABLED
347# include <stdarg.h>
348# define VSF_APPLET_VPLT \
349 ((vsf_applet_vplt_t *)(((vsf_vplt_t *)vsf_vplt((void *)0))->applet_vplt))
350
351#define VSF_VPLT_APPLET_ENTRY(__NAME) \
352 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_APPLET_VPLT, __NAME)
353#define VSF_VPLT_APPLET_IMP(...) \
354 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_APPLET_VPLT, __VA_ARGS__)
355
356VSF_VPLT_APPLET_IMP(vsf_vplt_trace_arg, void, const char *fmt, va_list arg) {
357 VSF_VPLT_APPLET_ENTRY(vsf_vplt_trace_arg)(fmt, arg);
358}
359
360static void vsf_vplt_trace(const char *format, ...)
361{
362 va_list ap;
363
364 va_start(ap, format);
366 va_end(ap);
367}
368
369# endif
370
371# ifndef VSF_APPLET_USE_ARCH
372# define VSF_APPLET_USE_ARCH ENABLED
373# endif
374# ifndef VSF_APPLET_USE_KERNEL
375# define VSF_APPLET_USE_KERNEL ENABLED
376# endif
377# ifndef VSF_APPLET_USE_SERVICE
378# define VSF_APPLET_USE_SERVICE ENABLED
379# endif
380#endif
381
382/*============================ MACROFIED FUNCTIONS ===========================*/
383/*============================ TYPES =========================================*/
384/*============================ GLOBAL VARIABLES ==============================*/
385/*============================ LOCAL VARIABLES ===============================*/
386/*============================ PROTOTYPES ====================================*/
387
388#ifdef __cplusplus
389}
390#endif
391
392#endif
393/* 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:332
VSF_APPLET_VPLT_ENTRY_MOD_DEF(libapplet)
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:333
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:202
int vsf_vplt_init_array(void *target)
Definition vsf.c:197
void * vsf_applet_remap(vsf_applet_ctx_t *ctx, void *vaddr)
Definition vsf.c:208
void vsf_vplt_fini_array(void *target)
Definition vsf.c:199
void vsf_vplt_trace_arg(const char *fmt, va_list arg)
Definition vsf.c:214
__VSF_VPLT_DECORATOR__ vsf_applet_vplt_t vsf_applet_vplt
Definition vsf.c:221
vsf_dynamic_vplt_t vsf_dynamic_vplt
Definition vsf.c:83
struct vsf_vplt_entry_t vsf_vplt_entry_t
struct vsf_applet_vplt_t vsf_applet_vplt_t
struct vsf_vplt_t vsf_vplt_t
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
struct vsf_dynamic_vplt_t vsf_dynamic_vplt_t
union vsf_vplt_info_t vsf_vplt_info_t
__VSF_VPLT_DECORATOR__ vsf_vplt_t vsf_vplt
Definition vsf.c:55
void * vsf_vplt_link(void *vplt, char *symname)
Definition vsf.c:124
int vsf_vplt_load_dyn(vsf_vplt_info_t *info)
Definition vsf.c:136
SDL_PixelFormat format
Definition vsf_sdl2_pixelformat.c:32
Generated from commit: vsfteam/vsf@2a137b0