sal_cint_data.c (12462B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 7 * 8 * sal_cint_data.c 9 * 10 * Hand-coded support for a few SAL core routines. 11 */ 12 13 int sal_core_cint_data_not_empty; 14 #include <sdk_config.h> 15 16 #if defined(INCLUDE_LIB_CINT) 17 18 #include <cint_config.h> 19 #include <cint_types.h> 20 #include <cint_porting.h> 21 #include <cint_logger.h> 22 #include <sal/core/libc.h> 23 #include <sal/core/alloc.h> 24 #include <sal/core/thread.h> 25 #include <sal/appl/config.h> 26 27 #include <sal/appl/sal.h> 28 29 30 31 /* 32 * Explicit wrappers as these may be macros instead of functions 33 */ 34 static void* __memset(void* p, int c, int sz) 35 { 36 return sal_memset(p, c, sz); 37 } 38 static void* __memcpy(void* dst, void* src, int sz) 39 { 40 return sal_memcpy(dst, src, sz); 41 } 42 static int __memcmp(void* dst, void* src, int sz) 43 { 44 return sal_memcmp(dst, src, sz); 45 } 46 static int __strcmp(char* p, char* c) 47 { 48 return sal_strcmp(p, c); 49 } 50 static int __strncmp(char* p, char* c, int sz) 51 { 52 return sal_strncmp(p, c, sz); 53 } 54 static char* __strcpy(char* dst, char* src) 55 { 56 return sal_strcpy(dst, src); 57 } 58 static char* __strncpy(char* dst, char* src, int sz) 59 { 60 return sal_strncpy(dst, src, sz); 61 } 62 static char* __strncpy_s(char* dst, char* src, int sz) 63 { 64 return sal_strncpy_s(dst, src, sz); 65 } 66 static char* __strstr(char* p, char* c) 67 { 68 return sal_strstr(p, c); 69 } 70 static int __strlen(char* c) 71 { 72 return sal_strlen(c); 73 } 74 static int __strnlen(char* c, int sz) 75 { 76 return sal_strnlen(c, sz); 77 } 78 static int __rand(void) 79 { 80 return sal_rand(); 81 } 82 static int __srand(int p) 83 { 84 sal_srand(p); 85 return p; 86 } 87 static double __sal_time(void) 88 { 89 return sal_time(); 90 } 91 static unsigned int __sal_time_usecs(void) 92 { 93 return sal_time_usecs(); 94 } 95 static void __sleep(int sec) 96 { 97 sal_sleep(sec); 98 } 99 static void __usleep(unsigned int usec) 100 { 101 sal_usleep(usec); 102 } 103 static void __udelay(unsigned int usec) 104 { 105 sal_udelay(usec); 106 } 107 108 void *cint_sal_alloc(unsigned int size, char *name) 109 { 110 return sal_alloc(size, name); 111 } 112 void cint_sal_free(void *ptr) 113 { 114 sal_free(ptr); 115 } 116 117 CINT_FWRAPPER_CREATE_RP2(void*, void, 1, 0, 118 cint_sal_alloc, 119 int,int,size,0,0, 120 void*,void,name,1,0); 121 122 CINT_FWRAPPER_CREATE_VP1(cint_sal_free, 123 void*,void,p,1,0); 124 125 CINT_FWRAPPER_CREATE_RP3(void*,void,1,0, 126 __memset, 127 void*,void,p,1,0, 128 int,int,c,0,0, 129 int,int,sz,0,0); 130 131 CINT_FWRAPPER_CREATE_RP3(void*,void,1,0, 132 __memcpy, 133 void*,void,dst,1,0, 134 void*,void,src,1,0, 135 int,int,sz,0,0); 136 CINT_FWRAPPER_CREATE_RP3(int,int,0,0, 137 __memcmp, 138 void*,void,dst,1,0, 139 void*,void,src,1,0, 140 int,int,sz,0,0); 141 CINT_FWRAPPER_CREATE_RP2(int,int,1,0, 142 __strcmp, 143 char*,char,p,1,0, 144 char*,char,c,1,0); 145 CINT_FWRAPPER_CREATE_RP3(int,int,1,0, 146 __strncmp, 147 char*,char,p,1,0, 148 char*,char,c,1,0, 149 int,int,sz,0,0); 150 151 CINT_FWRAPPER_CREATE_RP2(char*,char,1,0, 152 __strcpy, 153 char*,char,dst,1,0, 154 char*,char,src,1,0); 155 CINT_FWRAPPER_CREATE_RP3(char*,char,1,0, 156 __strncpy, 157 char*,char,dst,1,0, 158 char*,char,src,1,0, 159 int,int,sz,0,0); 160 CINT_FWRAPPER_CREATE_RP3(char*,char,1,0, 161 __strncpy_s, 162 char*,char,dst,1,0, 163 char*,char,src,1,0, 164 int,int,sz,0,0); 165 CINT_FWRAPPER_CREATE_RP2(char*,char,1,0, 166 __strstr, 167 char*,char,p,1,0, 168 char*,char,c,1,0); 169 CINT_FWRAPPER_CREATE_RP1(int,int,0,0, 170 __strlen, 171 char*,char,c,1,0); 172 CINT_FWRAPPER_CREATE_RP2(int,int,0,0, 173 __strnlen, 174 char*,char,c,1,0, 175 int,int,sz,0,0); 176 CINT_FWRAPPER_CREATE_RP0(int,int,0,0, 177 __rand); 178 CINT_FWRAPPER_CREATE_RP0(int,int,0,0, 179 __sal_time); 180 CINT_FWRAPPER_CREATE_RP0(unsigned int,unsigned int,0,0, 181 __sal_time_usecs); 182 CINT_FWRAPPER_CREATE_RP1(int,int,0,0, 183 __srand, 184 int,int,p,0,0); 185 CINT_FWRAPPER_CREATE_VP1(__sleep, 186 int,int,sec,0,0); 187 CINT_FWRAPPER_CREATE_VP1(__usleep, 188 unsigned int,unsigned int,usec,0,0); 189 CINT_FWRAPPER_CREATE_VP1(__udelay, 190 unsigned int,unsigned int,usec,0,0); 191 CINT_FWRAPPER_CREATE_RP2(int,int,1,0, 192 sal_config_set, 193 char*,char,name,1,0, 194 char*,char,value,1,0); 195 196 /* cmicx diag additions */ 197 198 CINT_FWRAPPER_CREATE_RP1(char*,char,1,0, 199 sal_config_get, 200 char*,char,name,1,0); 201 202 /* end cmicx diag additions */ 203 204 205 /* 206 * COMPILER_64 macros 207 */ 208 static void __COMPILER_64_TO_32_LO(int* dst, uint64 src) { COMPILER_64_TO_32_LO(*dst, src); } 209 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_TO_32_LO, int*,int,dst,1,0,uint64,uint64,src,0,0); 210 211 static void __COMPILER_64_TO_32_HI(int* dst, uint64 src) { COMPILER_64_TO_32_HI(*dst, src); } 212 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_TO_32_HI, int*,int,dst,1,0,uint64,uint64,src,0,0); 213 214 static int __COMPILER_64_HI(uint64* src) { return COMPILER_64_HI(*src); } 215 CINT_FWRAPPER_CREATE_RP1(int,int,0,0,__COMPILER_64_HI,uint64*,uint64,src,1,0); 216 217 static unsigned int __COMPILER_64_LO(uint64* src) { return COMPILER_64_LO(*src); } 218 CINT_FWRAPPER_CREATE_RP1(unsigned int,unsigned int,0,0,__COMPILER_64_LO,uint64*,uint64,src,1,0); 219 220 static void __COMPILER_64_ZERO(uint64* dst) { COMPILER_64_ZERO(*dst); } 221 CINT_FWRAPPER_CREATE_VP1(__COMPILER_64_ZERO, uint64*, uint64, dst, 1, 0); 222 223 static int __COMPILER_64_IS_ZERO(uint64* src) { return COMPILER_64_IS_ZERO(*src); } 224 CINT_FWRAPPER_CREATE_RP1(int,int,0,0,__COMPILER_64_IS_ZERO,uint64*,uint64,src,1,0); 225 226 static void __COMPILER_64_SET(uint64* dst, uint32 hi, uint32 lo) { COMPILER_64_SET(*dst, hi, lo); } 227 CINT_FWRAPPER_CREATE_VP3(__COMPILER_64_SET, 228 uint64*, uint64, dst, 1, 0, 229 uint32, uint32, hi, 0, 0, 230 uint32, uint32, lo, 0, 0); 231 232 static void __COMPILER_64_UDIV_64(uint64* dst, uint64 src) { COMPILER_64_UDIV_64(*dst, src); } 233 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_UDIV_64, uint64*,uint64,dst,1,0,uint64,uint64,src,0,0); 234 235 static void __COMPILER_64_UDIV_32(uint64* dst, uint32 src) { COMPILER_64_UDIV_32(*dst, src); } 236 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_UDIV_32, uint64*,uint64,dst,1,0,uint32,uint32,src,0,0); 237 238 static void __COMPILER_64_UMUL_32(uint64* dst, uint32 src) { COMPILER_64_UMUL_32(*dst, src); } 239 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_UMUL_32, uint64*,uint64,dst,1,0,uint32,uint32,src,0,0); 240 241 static void __COMPILER_64_ADD_64(uint64* dst, uint64 src) { COMPILER_64_ADD_64(*dst, src); } 242 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_ADD_64, uint64*,uint64,dst,1,0,uint64,uint64,src,0,0); 243 244 static void __COMPILER_64_ADD_32(uint64* dst, uint32 src) { COMPILER_64_ADD_32(*dst, src); } 245 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_ADD_32, uint64*,uint64,dst,1,0,uint32,uint32,src,0,0); 246 247 static void __COMPILER_64_SUB_64(uint64* dst, uint64 src) { COMPILER_64_SUB_64(*dst, src); } 248 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_SUB_64, uint64*,uint64,dst,1,0,uint64,uint64,src,0,0); 249 250 static void __COMPILER_64_SUB_32(uint64* dst, uint32 src) { COMPILER_64_SUB_32(*dst, src); } 251 CINT_FWRAPPER_CREATE_VP2(__COMPILER_64_SUB_32, uint64*,uint64,dst,1,0,uint32,uint32,src,0,0); 252 253 static cint_function_t __cint_sal_functions[] = 254 { 255 CINT_FWRAPPER_NENTRY("sal_alloc", cint_sal_alloc), 256 CINT_FWRAPPER_NENTRY("sal_free", cint_sal_free), 257 CINT_FWRAPPER_NENTRY("sal_memset", __memset), 258 CINT_FWRAPPER_NENTRY("sal_memcpy", __memcpy), 259 CINT_FWRAPPER_NENTRY("sal_memcmp", __memcmp), 260 CINT_FWRAPPER_NENTRY("sal_strcpy", __strcpy), 261 CINT_FWRAPPER_NENTRY("sal_strncpy", __strncpy), 262 CINT_FWRAPPER_NENTRY("sal_strncpy_s", __strncpy_s), 263 CINT_FWRAPPER_NENTRY("sal_strcmp", __strcmp), 264 CINT_FWRAPPER_NENTRY("sal_strncmp", __strncmp), 265 CINT_FWRAPPER_NENTRY("sal_strstr", __strstr), 266 CINT_FWRAPPER_NENTRY("sal_strlen", __strlen), 267 CINT_FWRAPPER_NENTRY("sal_strnlen", __strnlen), 268 CINT_FWRAPPER_NENTRY("sal_rand", __rand), 269 CINT_FWRAPPER_NENTRY("sal_time", __sal_time), 270 CINT_FWRAPPER_NENTRY("sal_time_usecs", __sal_time_usecs), 271 CINT_FWRAPPER_NENTRY("sal_srand", __srand), 272 CINT_FWRAPPER_NENTRY("sal_sleep", __sleep), 273 CINT_FWRAPPER_NENTRY("sal_usleep", __usleep), 274 CINT_FWRAPPER_NENTRY("sal_udelay", __udelay), 275 CINT_FWRAPPER_NENTRY("COMPILER_64_TO_32_LO", __COMPILER_64_TO_32_LO), 276 CINT_FWRAPPER_NENTRY("COMPILER_64_TO_32_HI", __COMPILER_64_TO_32_HI), 277 CINT_FWRAPPER_NENTRY("COMPILER_64_HI", __COMPILER_64_HI), 278 CINT_FWRAPPER_NENTRY("COMPILER_64_LO", __COMPILER_64_LO), 279 CINT_FWRAPPER_NENTRY("COMPILER_64_ZERO", __COMPILER_64_ZERO), 280 CINT_FWRAPPER_NENTRY("COMPILER_64_IS_ZERO", __COMPILER_64_IS_ZERO), 281 CINT_FWRAPPER_NENTRY("COMPILER_64_SET", __COMPILER_64_SET), 282 CINT_FWRAPPER_NENTRY("COMPILER_64_UDIV_64", __COMPILER_64_UDIV_64), 283 CINT_FWRAPPER_NENTRY("COMPILER_64_UDIV_32", __COMPILER_64_UDIV_32), 284 CINT_FWRAPPER_NENTRY("COMPILER_64_UMUL_32", __COMPILER_64_UMUL_32), 285 CINT_FWRAPPER_NENTRY("COMPILER_64_ADD_32", __COMPILER_64_ADD_32), 286 CINT_FWRAPPER_NENTRY("COMPILER_64_ADD_64", __COMPILER_64_ADD_64), 287 CINT_FWRAPPER_NENTRY("COMPILER_64_SUB_32", __COMPILER_64_SUB_32), 288 CINT_FWRAPPER_NENTRY("COMPILER_64_SUB_64", __COMPILER_64_SUB_64), 289 CINT_FWRAPPER_ENTRY(sal_config_set), 290 291 /* cmicx diag additions */ 292 293 CINT_FWRAPPER_ENTRY(sal_config_get), 294 295 /* end cmicx diag additions */ 296 297 CINT_ENTRY_LAST 298 }; 299 300 301 /* Typedefs section */ 302 static cint_parameter_desc_t __cint_typedefs[] = 303 { 304 {"uint8", "sal_mac_addr_t" , 0 , 6}, 305 { NULL } 306 }; 307 308 cint_data_t sal_cint_data = 309 { 310 NULL, 311 __cint_sal_functions, 312 NULL, 313 NULL, 314 __cint_typedefs, 315 NULL, 316 NULL, 317 NULL, 318 NULL 319 }; 320 321 /* 322 * This is the print function used by CINT. 323 * 324 * The purpose of this function is to set the SAL main thread to avoid background thread prefixes during output. 325 */ 326 327 int cint_printk(const char* fmt, ...) 328 { 329 int rv; 330 va_list args; 331 sal_thread_t t; 332 #if CINT_CONFIG_INCLUDE_CINT_LOGGER == 1 333 va_list args2; 334 int ototal, obuf_size = 1024; 335 char obuf[obuf_size], *obuf2; 336 cint_logger_thread_data_t *tdata = cint_logger_thread_specific(); 337 unsigned int bsl_ls; 338 #endif 339 340 t = sal_thread_main_get(); 341 sal_thread_main_set(sal_thread_self()); 342 343 va_start(args, fmt); 344 345 #if CINT_CONFIG_INCLUDE_CINT_LOGGER == 1 346 if ((*tdata).logger_is_active) { 347 348 bsl_ls = BSL_LAYER_ENC(cint_logger_cfg.logLayer) | BSL_SOURCE_ENC(cint_logger_cfg.logSource); 349 350 va_copy(args2, args); 351 352 ototal = vsnprintf(obuf, obuf_size, fmt, args2); 353 354 if (ototal >= obuf_size) { 355 356 obuf_size = ototal + 1; 357 358 obuf2 = sal_alloc(obuf_size, "cint_printk output buffer - 2nd attempt"); 359 360 ototal = vsnprintf(obuf2, obuf_size, fmt, args); 361 362 if (ototal >= obuf_size) { 363 /* assert(); -- This shouldn't happen */ 364 } 365 366 rv = bsl_printf("<c=%u>%s", bsl_ls | BSL_VERBOSE, obuf2); 367 368 sal_free(obuf2); 369 370 } else { 371 372 rv = bsl_printf("<c=%u>%s", bsl_ls | BSL_VERBOSE, obuf); 373 374 } 375 376 va_end(args2); 377 378 } else 379 #endif 380 { 381 rv = sal_vprintf(fmt, args); 382 } 383 384 va_end(args); 385 386 sal_thread_main_set(t); 387 return rv; 388 } 389 390 #endif /* INCLUDE_LIB_CINT */ 391 392 393