diff --git a/porting/liteos_m/kernel/BUILD.gn b/porting/liteos_m/kernel/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c946f3de7474c6bd45a0e06ddba5cb1e47592621 --- /dev/null +++ b/porting/liteos_m/kernel/BUILD.gn @@ -0,0 +1,167 @@ +# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +libc = "musl-c" +libm = "musl-m" + +config("include") { + include_dirs = [ + "include", + ] +} + +static_library(libc) { + sources = [ + #"src/errno/strerror.c", + "src/internal/shgetc.c", + "src/internal/intscan.c", + "src/stdlib/atoi.c", + #"src/stdlib/strtol.c", + "src/stdlib/atol.c", + "src/stdlib/atoll.c", + "src/stdlib/abs.c", + "src/network/h_errno.c", + "src/network/htonl.c", + "src/network/htons.c", + "src/network/ntohl.c", + "src/network/ntohs.c", + "src/exit/abort.c", + "src/exit/assert.c", + "src/ctype/isascii.c", + "src/ctype/isxdigit.c", + "src/ctype/isdigit.c", + "src/ctype/isupper.c", + "src/ctype/isspace.c", + "src/ctype/isalnum.c", + "src/ctype/islower.c", + "src/ctype/tolower.c", + "src/ctype/toupper.c", + "src/ctype/isprint.c", + "src/misc/dirname.c", + "src/locale/__lctrans.c", + "src/locale/langinfo.c", + "src/locale/c_locale.c", + "src/stdio/fputs.c", + "src/stdio/__stdio_close.c", + "src/stdio/fflush.c", + "src/stdio/__toread.c", + "src/stdio/ofl_add.c", + "src/stdio/__stdio_seek.c", + "src/stdio/__uflow.c", + "src/stdio/ftell.c", + "src/stdio/__stdio_read.c", + "src/stdio/fwrite.c", + "src/stdio/fread.c", + "src/stdio/fclose.c", + "src/stdio/stderr.c", + "src/stdio/fileno.c", + "src/stdio/perror.c", + "src/stdio/__lockfile.c", + "src/stdio/fgets.c", + "src/stdio/clearerr.c", + "src/stdio/__stdio_write.c", + "src/stdio/__fmodeflags.c", + "src/stdio/__fdopen.c", + "src/stdio/ofl.c", + "src/stdio/fseek.c", + "src/stdio/__stdout_write.c", + "src/stdio/rewind.c", + "src/stdio/__towrite.c", + "src/stdio/feof.c", + "src/stdio/fopen.c", + "src/stdio/stdout.c", + "src/time/strptime.c", + "src/time/strftime.c", + "src/time/__year_to_secs.c", + "src/time/__month_to_secs.c", + "src/time/__tz.c", + "src/time/__tm_to_secs.c", + "src/prng/random.c", + "src/regex/regexec.c", + "src/regex/regcomp.c", + "src/regex/tre-mem.c", + "src/string/strrchr.c", + "src/string/memcmp.c", + "src/string/strcspn.c", + "src/string/strstr.c", + "src/string/strchrnul.c", + "src/string/strchr.c", + "src/string/memcpy.c", + "src/string/strncmp.c", + "src/string/strcasecmp.c", + "src/string/strcmp.c", + "src/string/strncasecmp.c", + "src/string/memchr.c", + "src/string/memrchr.c", + "src/string/strdup.c", + "src/string/wcslen.c", + "src/string/memset.c", + "src/string/strlen.c", + "src/string/wcschr.c", + ] + + include_dirs = [ + "src/include", + "src/internal", + ] + + include_dirs += [ + "//kernel/liteos_m/kernel/arch/include", + "//kernel/liteos_m/kernel/include", + "//kernel/liteos_m/utils", + ] + + public_configs = [ ":include" ] +} + +static_library(libm) { + sources = [ + "src/math/pow.c", + "src/math/log.c", + "src/math/sqrt.c", + "src/math/pow_data.c", + "src/math/log_data.c", + "src/math/exp_data.c", + "src/math/round.c", + ] + + include_dirs = [ + "src/include", + "src/internal", + ] + + public_configs = [ ":include" ] +} + +group("kernel") { + public_deps = [ + ":$libc", + ":$libm", + ] +} diff --git a/porting/liteos_m/kernel/src/network/htonl.c b/porting/liteos_m/kernel/src/network/htonl.c new file mode 100644 index 0000000000000000000000000000000000000000..6622d16cc5351749d1b76c5f24aa71009b018ff0 --- /dev/null +++ b/porting/liteos_m/kernel/src/network/htonl.c @@ -0,0 +1,8 @@ +#include +#include + +uint32_t htonl(uint32_t n) +{ + union { int i; char c; } u = { 1 }; + return u.c ? bswap_32(n) : n; +} diff --git a/porting/liteos_m/kernel/src/network/htons.c b/porting/liteos_m/kernel/src/network/htons.c new file mode 100644 index 0000000000000000000000000000000000000000..03a3a1d59ed4d5d10272d2751920ce3f8bec080b --- /dev/null +++ b/porting/liteos_m/kernel/src/network/htons.c @@ -0,0 +1,8 @@ +#include +#include + +uint16_t htons(uint16_t n) +{ + union { int i; char c; } u = { 1 }; + return u.c ? bswap_16(n) : n; +} diff --git a/porting/liteos_m/kernel/src/network/ntohl.c b/porting/liteos_m/kernel/src/network/ntohl.c new file mode 100644 index 0000000000000000000000000000000000000000..d6fce4590d43a3ee868d7cd807c89c0b6599ee3e --- /dev/null +++ b/porting/liteos_m/kernel/src/network/ntohl.c @@ -0,0 +1,8 @@ +#include +#include + +uint32_t ntohl(uint32_t n) +{ + union { int i; char c; } u = { 1 }; + return u.c ? bswap_32(n) : n; +} diff --git a/porting/liteos_m/kernel/src/network/ntohs.c b/porting/liteos_m/kernel/src/network/ntohs.c new file mode 100644 index 0000000000000000000000000000000000000000..745cef425a1947f119880d499e7829146e049470 --- /dev/null +++ b/porting/liteos_m/kernel/src/network/ntohs.c @@ -0,0 +1,8 @@ +#include +#include + +uint16_t ntohs(uint16_t n) +{ + union { int i; char c; } u = { 1 }; + return u.c ? bswap_16(n) : n; +} diff --git a/porting/liteos_m/kernel/src/stdio/fclose.c b/porting/liteos_m/kernel/src/stdio/fclose.c index eeba0ffbb5eab880379c49e304284e73fcfa6014..46c2cdb32e02cac01bf056d519313093ac47e8ab 100644 --- a/porting/liteos_m/kernel/src/stdio/fclose.c +++ b/porting/liteos_m/kernel/src/stdio/fclose.c @@ -34,4 +34,10 @@ int __fclose(FILE *f) return r; } -weak_alias(__fclose, fclose); \ No newline at end of file +weak_alias(__fclose, fclose); + +int __wrap_fclose(FILE *f) +{ + return __fclose(f); +} + diff --git a/porting/liteos_m/kernel/src/stdio/fflush.c b/porting/liteos_m/kernel/src/stdio/fflush.c index d755f8f1e206a2226180a8a6372ce2e08b834718..f2164eec033a9c132b9c603a111c1b9952b6cf14 100644 --- a/porting/liteos_m/kernel/src/stdio/fflush.c +++ b/porting/liteos_m/kernel/src/stdio/fflush.c @@ -46,3 +46,9 @@ int __fflush(FILE *f) weak_alias(fflush, fflush_unlocked); weak_alias(__fflush, fflush); + +int __wrap_fflush(FILE *f) +{ + return __fflush(f); +} +