From dd44e4a9d1bfd032ad8a623876cfc5b0ebcabe03 Mon Sep 17 00:00:00 2001 From: Hanhui Date: Mon, 14 Sep 2015 16:28:14 +0800 Subject: [PATCH] Add bLib support. --- Makefile | 1 + target/h/bLib.h | 39 +++++++ target/h/cpuset.h | 24 ++++ target/h/ffsLib.h | 85 ++++++++++++++ target/h/hashLib.h | 18 +++ target/h/loginLib.h | 23 ++++ target/h/version.h | 4 +- target/src/bLib.c | 269 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 target/h/bLib.h create mode 100644 target/h/cpuset.h create mode 100644 target/h/ffsLib.h create mode 100644 target/h/hashLib.h create mode 100644 target/h/loginLib.h create mode 100644 target/src/bLib.c diff --git a/Makefile b/Makefile index ea6238e..de0a6bd 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ LD = $(TOOLCHAIN_PREFIX)g++ # src(s) file #********************************************************************************************************* SRCS = \ +target/src/bLib.c \ target/src/errnoLib.c \ target/src/eventLib.c \ target/src/lstLib.c \ diff --git a/target/h/bLib.h b/target/h/bLib.h new file mode 100644 index 0000000..108df87 --- /dev/null +++ b/target/h/bLib.h @@ -0,0 +1,39 @@ +/** + * @file + * errno library. + * + * VxWork compatibility layer in SylixOS. + * + * Copyright (c) 2001-2014 SylixOS Group. + * All rights reserved. + * + * Author: Han.hui + */ + +#ifndef __VXWORKS_BLIB_H +#define __VXWORKS_BLIB_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int bcmp(char *buf1, char *buf2, size_t nbytes); +void binvert(char *buf, size_t nbytes); +void bswap(char *buf1, char *buf2, size_t nbytes); +void swab(char *source, char *destination, size_t nbytes); +void uswab(char *source, char *destination, size_t nbytes); +void bcopyBytes(char *source, char *destination, size_t nbytes); +void bcopyWords(char *source, char *destination, size_t nwords); +void bcopyLongs(char *source, char *destination, size_t nlongs); +void bcopyQuads(char *source, char *destination, size_t nquads); +void bfill(char *buf, size_t nbytes, int ch); +void bfillBytes(char *buf, size_t nbytes, int ch); + +#ifdef __cplusplus +} +#endif + +#endif /* __VXWORKS_BLIB_H */ diff --git a/target/h/cpuset.h b/target/h/cpuset.h new file mode 100644 index 0000000..2a6d93b --- /dev/null +++ b/target/h/cpuset.h @@ -0,0 +1,24 @@ +/** + * @file + * errno library. + * + * VxWork compatibility layer in SylixOS. + * + * Copyright (c) 2001-2014 SylixOS Group. + * All rights reserved. + * + * Author: Han.hui + */ + +#ifndef __VXWORKS_CPUSET_H +#define __VXWORKS_CPUSET_H + +#include "vxWorksCommon.h" +#include "vxCpuLib.h" + +#define CPUSET_SET(p, n) LW_CPU_SET(n, p) +#define CPUSET_CLR(p, n) LW_CPU_CLR(n, p) +#define CPUSET_ISSET(p, n) LW_CPU_ISSET(n, p) +#define CPUSET_ZERO(p) LW_CPU_ZERO(p) + +#endif /* __VXWORKS_CPUSET_H */ diff --git a/target/h/ffsLib.h b/target/h/ffsLib.h new file mode 100644 index 0000000..2ec5782 --- /dev/null +++ b/target/h/ffsLib.h @@ -0,0 +1,85 @@ +/** + * @file + * errno library. + * + * VxWork compatibility layer in SylixOS. + * + * Copyright (c) 2001-2014 SylixOS Group. + * All rights reserved. + * + * Author: Han.hui + */ + +#ifndef __VXWORKS_FFSLIB_H +#define __VXWORKS_FFSLIB_H + +#include "vxWorksCommon.h" + +#define ffsLsb archFindLsb +#define ffsMsb archFindMsb +#define ffs32Lsb archFindLsb +#define ffs32Msb archFindMsb + +#define ffsLsb_autosize(i) ((sizeof(i) == 8) ? ffs64Lsb(i) : ffs32Lsb(i)) +#define ffsMsb_autosize(i) ((sizeof(i) == 8) ? ffs64Msb(i) : ffs32Msb(i)) + +#ifdef __cplusplus +extern "C" { +#endif + +extern int archFindLsb(UINT32 ui32); +extern int archFindMsb(UINT32 ui32); + +static inline int ffs64Msb (UINT64 i) +{ + union { + UINT64 qword; + UINT32 dwords[2]; + } i_u; + + i_u.qword = i; + +#if _BYTE_ORDER == _BIG_ENDIAN + if (i_u.dwords[0]) { + return ffsMsb(i_u.dwords[0]) + 32; + } else { + return ffsMsb(i_u.dwords[1]); + } +#else + if (i_u.dwords[1]) { + return ffsMsb(i_u.dwords[1]) + 32; + } else { + return ffsMsb(i_u.dwords[0]); + } +#endif /* _BYTE_ORDER */ +} + +static inline int ffs64Lsb (UINT64 i) +{ + union { + UINT64 qword; + UINT32 dwords[2]; + } i_u; + + i_u.qword = i; + +#if _BYTE_ORDER == _BIG_ENDIAN + if (i_u.dwords[1]) { + return ffsLsb(i_u.dwords[1]); + } else { + return ffsLsb(i_u.dwords[0]) + (i ? 32 : 0); + } +#else + if (i_u.dwords[0]) { + return ffsLsb(i_u.dwords[0]); + } else { + return ffsLsb(i_u.dwords[1]) + (i ? 32 : 0); + } +#endif /* _BYTE_ORDER */ +} + +#ifdef __cplusplus +} +#endif + +#endif /* __VXWORKS_FFSLIB_H */ diff --git a/target/h/hashLib.h b/target/h/hashLib.h new file mode 100644 index 0000000..1ef755a --- /dev/null +++ b/target/h/hashLib.h @@ -0,0 +1,18 @@ +/** + * @file + * errno library. + * + * VxWork compatibility layer in SylixOS. + * + * Copyright (c) 2001-2014 SylixOS Group. + * All rights reserved. + * + * Author: Han.hui + */ + +#ifndef __VXWORKS_HASHLIB_H +#define __VXWORKS_HASHLIB_H + +#error "hashLib not support Now!" + +#endif /* __VXWORKS_HASHLIB_H */ diff --git a/target/h/loginLib.h b/target/h/loginLib.h new file mode 100644 index 0000000..1f07fed --- /dev/null +++ b/target/h/loginLib.h @@ -0,0 +1,23 @@ +/** + * @file + * errno library. + * + * VxWork compatibility layer in SylixOS. + * + * Copyright (c) 2001-2014 SylixOS Group. + * All rights reserved. + * + * Author: Han.hui + */ + +#ifndef __VXWORKS_LOGINLIB_H +#define __VXWORKS_LOGINLIB_H + +#include +#include "vxWorksCommon.h" + +#define loginUserVerify(n, p) userlogin(n, p, 1) + +#define + +#endif /* __VXWORKS_LOGINLIB_H */ diff --git a/target/h/version.h b/target/h/version.h index 0c6ebd1..0ec3711 100644 --- a/target/h/version.h +++ b/target/h/version.h @@ -35,7 +35,7 @@ #define _LIB_VXWORKS_MAJOR 0 #define _LIB_VXWORKS_MINOR 1 -#define _LIB_VXWORKS_MAINT 1 +#define _LIB_VXWORKS_MAINT 2 /* there is now a space between the runtime name, and the version */ @@ -45,7 +45,7 @@ /* VxWork compatibility layer */ /* 0.1.1 add cpu affinity */ -#define LIB_VXWORKS_VERSION "SylixOS Compatibility Pack 0.1.1" +#define LIB_VXWORKS_VERSION "SylixOS Compatibility Pack 0.1.2" char *creationDate; char *runtimeVersion; diff --git a/target/src/bLib.c b/target/src/bLib.c new file mode 100644 index 0000000..e0aaa7c --- /dev/null +++ b/target/src/bLib.c @@ -0,0 +1,269 @@ +/** + * @file + * errno library. + * + * VxWork compatibility layer in SylixOS. + * + * Copyright (c) 2001-2014 SylixOS Group. + * All rights reserved. + * + * Author: Han.hui + */ + +#include +#include + +/* + * bcmp - compare one buffer to another + */ +int bcmp (char *buf1, char *buf2, size_t nbytes) +{ + unsigned char *p1; + unsigned char *p2; + + if (nbytes == 0) { + return (0); + } + + p1 = (unsigned char *)buf1; + p2 = (unsigned char *)buf2; + + while (*p1++ == *p2++) { + if (--nbytes == 0) { + return (0); + } + } + + return ((*--p1) - (*--p2)); +} + +/* + * binvert - invert the order of bytes in a buffer + */ +void binvert (char *buf, size_t nbytes) +{ + char *buf_end = buf + nbytes - 1; + char temp; + + while (buf < buf_end) { + temp = *buf; + *buf = *buf_end; + *buf_end = temp; + + buf_end--; + buf++; + } +} + +/* + * bswap - swap buffers + */ +void bswap (char *buf1, char *buf2, size_t nbytes) +{ + char temp; + + while (nbytes >= 1) { + temp = *buf1; + *buf1++ = *buf2; + *buf2++ = temp; + nbytes--; + } +} + +/* + * swab - swap bytes + */ +void swab (char *source, char *destination, size_t nbytes) +{ + unsigned short *src = (unsigned short *)source; + unsigned short *dst = (unsigned short *)destination; + unsigned short *dst_end = (unsigned short *)(destination + nbytes); + + for (; dst < dst_end; dst++, src++) { + *dst = (short)(((*src & 0x00ff) << 8) | ((*src & 0xff00) >> 8)); + } +} + +/* + * uswab - swap bytes with buffers that are not necessarily aligned + */ +void uswab (char *source, char *destination, size_t nbytes) +{ + char *dst = (char *)destination; + char *dst_end = dst + nbytes; + char byte1; + char byte2; + + while (dst < dst_end) { + byte1 = *source++; + byte2 = *source++; + *dst++ = byte2; + *dst++ = byte1; + } +} + +/* + * bcopyBytes - copy one buffer to another one byte (8 bits) at a time + */ +void bcopyBytes (char *source, char *destination, size_t nbytes) +{ + char *dstend; + size_t offset = (size_t)(destination - source); + + if (offset == 0) { + return; + } + + if (offset >= nbytes) { /* true also when destination < source if no wrap */ + /* + * forward copy + */ + dstend = destination + nbytes; + while (destination != dstend) { + *destination++ = *source++; + } + } else { + /* + * backward copy + */ + dstend = destination; + destination += nbytes; + source += nbytes; + + while (destination != dstend) { + *--destination = *--source; + } + } +} + +/* + * bcopyWords - copy one buffer to another one word (16 bits) at a time + */ +void bcopyWords (char *source, char *destination, size_t nwords) +{ + short *dstend; + short *src = (short *)source; + short *dst = (short *)destination; + size_t nbytes = nwords << 1; /* convert to bytes */ + size_t offset = (size_t)(destination - source); + + if (offset == 0) { + return; + } + + if (offset >= nbytes) { /* true also when destination < source if no wrap */ + /* + * forward copy + */ + dstend = dst + nwords; + while (dst != dstend) { + *dst++ = *src++; + } + } else { + /* + * backward copy + */ + dstend = dst; + dst += nwords; + src += nwords; + while (dst != dstend) { + *--dst = *--src; + } + } +} + +/* + * bcopyLongs - copy one buffer to another one long word (32 bits) at a time + */ +void bcopyLongs (char *source, char *destination, size_t nlongs) +{ + UINT32 *dstend; + UINT32 *src = (UINT32 *)source; + UINT32 *dst = (UINT32 *)destination; + size_t nbytes = nlongs * sizeof(UINT32); /* convert to bytes */ + size_t offset = (size_t)(destination - source); + + if (offset == 0) { + return; + } + + if (offset >= nbytes) { /* true also when destination < source if no wrap */ + /* + * forward copy + */ + dstend = dst + nlongs; + while (dst != dstend) { + *dst++ = *src++; + } + } else { + /* + * backward copy + */ + dstend = dst; + dst += nlongs; + src += nlongs; + while (dst != dstend) { + *--dst = *--src; + } + } +} + +/* + * bcopyQuads - copy one buffer to another quad word (64 bits) at a time (64-bit) + */ +void bcopyQuads (char *source, char *destination, size_t nquads) +{ + UINT64 *dstend; + UINT64 *src = (UINT64 *)source; + UINT64 *dst = (UINT64 *)destination; + size_t nbytes = nquads * sizeof(UINT64); /* convert to bytes */ + size_t offset = (size_t)(destination - source); + + if (offset == 0) { + return; + } + + if (offset >= nbytes) { /* true also when destination < source if no wrap */ + /* + * forward copy + */ + dstend = dst + nquads; + while (dst != dstend) { + *dst++ = *src++; + } + } else { + /* + * backward copy + */ + dstend = dst; + dst += nquads; + src += nquads; + while (dst != dstend) { + *--dst = *--src; + } + } +} + +/* + * bfill - fill a buffer with a specified character + */ +void bfill (char *buf, size_t nbytes, int ch) +{ + lib_memset(buf, ch, nbytes); +} + +/* + * bfillBytes - fill buffer with a specified character one byte at a time + */ +void bfillBytes (char *buf, size_t nbytes, int ch) +{ + char *bufend = buf + nbytes; + + while (buf != bufend) { + *buf++ = (char)ch; + } +} + +/* + * end + */