1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef NSI_COMMON_SRC_INCL_NSI_CPU_IF_INTERNAL_H 8 #define NSI_COMMON_SRC_INCL_NSI_CPU_IF_INTERNAL_H 9 10 #include "nsi_utils.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define FUNCT(i, pre, post) \ 17 pre##i##post 18 19 #define FUNCT_LIST(pre, post, sep) \ 20 FUNCT(0, pre, post) NSI_DEBRACKET sep \ 21 FUNCT(1, pre, post) NSI_DEBRACKET sep \ 22 FUNCT(2, pre, post) NSI_DEBRACKET sep \ 23 FUNCT(3, pre, post) NSI_DEBRACKET sep \ 24 FUNCT(4, pre, post) NSI_DEBRACKET sep \ 25 FUNCT(5, pre, post) NSI_DEBRACKET sep \ 26 FUNCT(6, pre, post) NSI_DEBRACKET sep \ 27 FUNCT(7, pre, post) NSI_DEBRACKET sep \ 28 FUNCT(8, pre, post) NSI_DEBRACKET sep \ 29 FUNCT(9, pre, post) NSI_DEBRACKET sep \ 30 FUNCT(10, pre, post) NSI_DEBRACKET sep \ 31 FUNCT(11, pre, post) NSI_DEBRACKET sep \ 32 FUNCT(12, pre, post) NSI_DEBRACKET sep \ 33 FUNCT(13, pre, post) NSI_DEBRACKET sep \ 34 FUNCT(14, pre, post) NSI_DEBRACKET sep \ 35 FUNCT(15, pre, post) NSI_DEBRACKET sep \ 36 37 #define F_TRAMP_TABLE(pre, post) FUNCT_LIST(pre, post, (,)) 38 39 #define F_TRAMP_LIST(pre, post) FUNCT_LIST(pre, post, (;)) 40 41 #define F_TRAMP_BODY_LIST(pre, post) FUNCT_LIST(pre, post, ()) 42 43 #define TRAMPOLINES(pre, post) \ 44 void pre ## n ## post(int n) \ 45 { \ 46 void(*fptrs[])(void) = { \ 47 F_TRAMP_TABLE(pre, post) \ 48 }; \ 49 fptrs[n](); \ 50 } 51 52 #define TRAMPOLINES_i_vp(pre, post) \ 53 int pre ## n ## post(int n, void *p) \ 54 { \ 55 int(*fptrs[])(void *p) = { \ 56 F_TRAMP_TABLE(pre, post) \ 57 }; \ 58 return fptrs[n](p); \ 59 } 60 61 #define TRAMPOLINES_i_(pre, post) \ 62 int pre ## n ## post(int n) \ 63 { \ 64 int(*fptrs[])(void) = { \ 65 F_TRAMP_TABLE(pre, post) \ 66 }; \ 67 return fptrs[n](); \ 68 } 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #endif /* NSI_COMMON_SRC_INCL_NSI_CPU_IF_INTERNAL_H */ 75