37#include "vsf_usr_cfg.h"
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.
55# define VSF_USE_KERNEL ENABLED
62#ifndef VSF_USR_SWI_NUM
63# define VSF_USR_SWI_NUM 0
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.
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)
76# define __VSF_HAL_SWI_NUM 0
79# define __VSF_HAL_SWI_NUM (VSF_OS_CFG_PRIORITY_NUM)
82# define __VSF_OS_SWI_NUM __VSF_HAL_SWI_NUM
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"
92#ifndef __VSF_VPLT_DECORATOR__
93# define __VSF_VPLT_DECORATOR__ const
126#ifndef __VSF_APPLET__
131#ifndef VSF_APPLET_CFG_LINKABLE
132# define VSF_APPLET_CFG_LINKABLE ENABLED
134#if VSF_APPLET_CFG_LINKABLE == ENABLED && !defined(__VSF_APPLET__)
139#if VSF_APPLET_CFG_LINKABLE == ENABLED
146#define VSF_APPLET_VPLT_INFO(__TYPE, __MAJOR, __MINOR, __FINAL) \
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 *)),\
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__)
168# define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
170#ifndef VSF_APPLET_VPLT_FUNC_DECORATOR
171# define VSF_APPLET_VPLT_FUNC_DECORATOR(__NAME) static inline
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) \
180 .ptr = (void *)(__PTR), \
182# define VSF_APPLET_VPLT_ENTRY_FUNC(__NAME) \
184 .name = VSF_STR(__NAME), \
185 .ptr = (void *)(__NAME), \
187# define VSF_APPLET_VPLT_ENTRY_VAR(__NAME) \
189 .name = VSF_STR(__NAME), \
190 .ptr = (void *)&(__NAME), \
192# define VSF_APPLET_VPLT_ENTRY_MOD(__NAME, __MOD) \
194 .name = VSF_STR(__NAME), \
195 .ptr = (void *)&(__MOD), \
198# define VSF_APPLET_VPLT_ENTRY_FUNC_EX(__ENTRY, __NAME, __PTR) \
200 .ptr = (void *)(__PTR), \
202# define VSF_APPLET_VPLT_ENTRY_FUNC(__NAME) \
204 .ptr = (void *)(__NAME), \
206# define VSF_APPLET_VPLT_ENTRY_VAR(__NAME) \
208 .ptr = (void *)&(__NAME), \
210# define VSF_APPLET_VPLT_ENTRY_MOD(__NAME, __MOD) \
212 .ptr = (void *)&(__MOD), \
216#ifndef __VSF_APPLET_CTX_DEFINED__
217#define __VSF_APPLET_CTX_DEFINED__
233# if VSF_USE_APPLET == ENABLED && !defined(VSF_APPLET_VPLT)
234# define VSF_APPLET_VPLT ((vsf_vplt_t *)vsf_vplt((void *)0))
238# if VSF_APPLET_CFG_ABI_PATCH == ENABLED
239# define applet_raw_entry \
240 void _dllstart(void) \
245# define applet_raw_entry \
246 void _dllstart(vsf_applet_ctx_t *ctx) \
252# define applet_raw_entry
255# ifndef applet_entry_with_ctx
256# if VSF_APPLET_CFG_ABI_PATCH == ENABLED
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
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
272# ifndef VSF_APPLET_VPLT_ENTRY_DECORATOR
273# define VSF_APPLET_VPLT_ENTRY_DECORATOR
275VSF_APPLET_VPLT_ENTRY_DECORATOR
extern void *
vsf_vplt(
void *vplt);
278 applet_entry_with_ctx \
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); \
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); \
295 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_vplt(void *vplt) \
297 static void *__vplt = (void *)0; \
298 if (vplt != (void *)0) { \
300 VSF_APPLET_VPLT_ENTRY_FUNC_TRACE(); \
304 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_applet_remap(vsf_applet_ctx_t *applet_ctx, void *vaddr)\
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; \
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); \
317 VSF_APPLET_VPLT_ENTRY_DECORATOR void * vsf_vplt_link(void *vplt, char *symname)\
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))\
325 int main(__VA_ARGS__)
328#if VSF_USE_APPLET == ENABLED || VSF_LINUX_USE_APPLET == ENABLED
343# if defined(__VSF_APPLET__) && defined(__VSF_APPLET_LIB__) && VSF_APPLET_CFG_DEBUG_VPLT == ENABLED
345# define VSF_APPLET_VPLT \
346 ((vsf_applet_vplt_t *)(((vsf_vplt_t *)vsf_vplt((void *)0))->applet_vplt))
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__)
357static void vsf_vplt_trace(
const char *
format, ...)
368# ifndef VSF_APPLET_USE_ARCH
369# define VSF_APPLET_USE_ARCH ENABLED
371# ifndef VSF_APPLET_USE_SERVICE
372# define VSF_APPLET_USE_SERVICE ENABLED
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
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
void * ram_vplt
Definition vsf_cfg.h:124
vsf_vplt_info_t info
Definition vsf_cfg.h:123
const char * name
Definition vsf_cfg.h:141
void * ptr
Definition vsf_cfg.h:143
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
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