chen
2024-11-08 cc432b761c884a0bd8e9d83db0a4e26109fc08b1
keil/include/components/libc/libc.c
对比新文件
@@ -0,0 +1,1068 @@
/*
 * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and
 * its subsidiaries and affiliates (collectly called MKSEMI).
 *
 * 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, except as embedded into an MKSEMI
 *    integrated circuit in a product or a software update for such product,
 *    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 MKSEMI nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    MKSEMI integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be
 *    reverse engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY MKSEMI "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL MKSEMI 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.
 */
#include "libc_rom.h"
#ifndef STD_LIBC
#if defined(__ARMCC_VERSION)
static const struct LIBC_ROM_T *libc_rom __attribute__((section(".bss.noinit")));
#elif defined(__ICCARM__)
__no_init static const struct LIBC_ROM_T *libc_rom;
#elif defined(__GNUC__)
static const struct LIBC_ROM_T *libc_rom __attribute__((section(".noinit")));
#else
#warning "Confirm compiler version"
#endif
void update_libc_rom_table(void)
{
    // A4
    if (*(const volatile uint32_t *)(0x4000000C) == 0x00000020)
    {
        libc_rom = (const struct LIBC_ROM_T *)0x0301d624;
    }
    else
    {
        libc_rom = (const struct LIBC_ROM_T *)0x0301cf30;
    }
}
#if !defined(__ICCARM__)
void *memcpy(void *s1, const void *s2, size_t n)
{
    return libc_rom->memcpy(s1, s2, n);
}
void *memmove(void *s1, const void *s2, size_t n)
{
    return libc_rom->memmove(s1, s2, n);
}
#endif
char *strcpy(char *s1, const char *s2)
{
    return libc_rom->strcpy(s1, s2);
}
char *strncpy(char *s1, const char *s2, size_t n)
{
    return libc_rom->strncpy(s1, s2, n);
}
char *strcat(char *s1, const char *s2)
{
    return libc_rom->strcat(s1, s2);
}
char *strncat(char *s1, const char *s2, size_t n)
{
    return libc_rom->strncat(s1, s2, n);
}
int memcmp(const void *s1, const void *s2, size_t n)
{
    return libc_rom->memcmp(s1, s2, n);
}
int strcmp(const char *s1, const char *s2)
{
    return libc_rom->strcmp(s1, s2);
}
int strncmp(const char *s1, const char *s2, size_t n)
{
    return libc_rom->strncmp(s1, s2, n);
}
int strcasecmp(const char *s1, const char *s2)
{
    return libc_rom->strcasecmp(s1, s2);
}
int strncasecmp(const char *s1, const char *s2, size_t n)
{
    return libc_rom->strncasecmp(s1, s2, n);
}
int strcoll(const char *s1, const char *s2)
{
    return libc_rom->strcoll(s1, s2);
}
size_t strxfrm(char *s1, const char *s2, size_t n)
{
    return libc_rom->strxfrm(s1, s2, n);
}
void *memchr(const void *s, int c, size_t n)
{
    return libc_rom->memchr(s, c, n);
}
char *strchr(const char *s, int c)
{
    return libc_rom->strchr(s, c);
}
size_t strcspn(const char *s1, const char *s2)
{
    return libc_rom->strcspn(s1, s2);
}
char *strpbrk(const char *s1, const char *s2)
{
    return libc_rom->strpbrk(s1, s2);
}
char *strrchr(const char *s, int c)
{
    return libc_rom->strrchr(s, c);
}
size_t strspn(const char *s1, const char *s2)
{
    return libc_rom->strspn(s1, s2);
}
char *strstr(const char *s1, const char *s2)
{
    return libc_rom->strstr(s1, s2);
}
char *strtok(char *s1, const char *s2)
{
    return libc_rom->strtok(s1, s2);
}
#if !defined(__ICCARM__)
void *memset(void *s, int c, size_t n)
{
    return libc_rom->memset(s, c, n);
}
#endif
char *strerror(int errnum)
{
    return libc_rom->strerror(errnum);
}
size_t strlen(const char *s)
{
    return libc_rom->strlen(s);
}
size_t strlcpy(char *dst, const char *src, size_t len)
{
    return libc_rom->strlcpy(dst, src, len);
}
size_t strlcat(char *dst, const char *src, size_t len)
{
    return libc_rom->strlcat(dst, src, len);
}
int sprintf(char *s, const char *format, ...)
{
    va_list ap;
    int len;
    va_start(ap, format);
    len = libc_rom->vsnprintf(s, -(size_t)s, format, ap);
    va_end(ap);
    return (len);
}
int snprintf(char *s, size_t n, const char *format, ...)
{
    va_list ap;
    int len;
    va_start(ap, format);
    len = libc_rom->vsnprintf(s, n, format, ap);
    va_end(ap);
    return (len);
}
int vsprintf(char *s, const char *format, va_list arg)
{
    return libc_rom->vsprintf(s, format, arg);
}
int vsnprintf(char *s, size_t n, const char *format, va_list arg)
{
    return libc_rom->vsnprintf(s, n, format, arg);
}
int sscanf(const char *s, const char *format, ...)
{
    va_list args;
    int i;
    va_start(args, format);
    i = libc_rom->vsscanf(s, format, args);
    va_end(args);
    return i;
}
int vsscanf(const char *s, const char *format, va_list arg)
{
    return libc_rom->vsscanf(s, format, arg);
}
double atof(const char *nptr)
{
    return libc_rom->atof(nptr);
}
int atoi(const char *nptr)
{
    return libc_rom->atoi(nptr);
}
long int atol(const char *nptr)
{
    return libc_rom->atol(nptr);
}
long long atoll(const char *nptr)
{
    return libc_rom->atoll(nptr);
}
double strtod(const char *nptr, char **endptr)
{
    return libc_rom->strtod(nptr, endptr);
}
long int strtol(const char *nptr, char **endptr, int base)
{
    return libc_rom->strtol(nptr, endptr, base);
}
unsigned long int strtoul(const char *nptr, char **endptr, int base)
{
    return libc_rom->strtoul(nptr, endptr, base);
}
long long strtoll(const char *nptr, char **endptr, int base)
{
    return libc_rom->strtoll(nptr, endptr, base);
}
unsigned long long strtoull(const char *nptr, char **endptr, int base)
{
    return libc_rom->strtoull(nptr, endptr, base);
}
int rand(void)
{
    return libc_rom->rand();
}
void srand(unsigned int seed)
{
    libc_rom->srand(seed);
}
void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
{
    return libc_rom->bsearch(key, base, nmemb, size, compar);
}
void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
{
    libc_rom->qsort(base, nmemb, size, compar);
}
#if !defined(__ICCARM__)
int abs(int j)
{
    return libc_rom->abs(j);
}
div_t div(int numer, int denom)
{
    return libc_rom->div(numer, denom);
}
long int labs(long int j)
{
    return libc_rom->labs(j);
}
ldiv_t ldiv(long int numer, long int denom)
{
    return libc_rom->ldiv(numer, denom);
}
long long llabs(long long j)
{
    return libc_rom->llabs(j);
}
lldiv_t lldiv(long long numer, long long denom)
{
    return libc_rom->lldiv(numer, denom);
}
#endif
double acos(double x)
{
    return libc_rom->acos(x);
}
double asin(double x)
{
    return libc_rom->asin(x);
}
double atan(double x)
{
    return libc_rom->atan(x);
}
double atan2(double y, double x)
{
    return libc_rom->atan2(y, x);
}
double cos(double x)
{
    return libc_rom->cos(x);
}
double sin(double x)
{
    return libc_rom->sin(x);
}
double tan(double x)
{
    return libc_rom->tan(x);
}
double cosh(double x)
{
    return libc_rom->cosh(x);
}
double sinh(double x)
{
    return libc_rom->sinh(x);
}
double tanh(double x)
{
    return libc_rom->tanh(x);
}
double exp(double x)
{
    return libc_rom->exp(x);
}
double frexp(double value, int *exp)
{
    return libc_rom->frexp(value, exp);
}
double ldexp(double x, int exp)
{
    return libc_rom->ldexp(x, exp);
}
double log(double x)
{
    return libc_rom->log(x);
}
double log10(double x)
{
    return libc_rom->log10(x);
}
double modf(double value, double *iptr)
{
    return libc_rom->modf(value, iptr);
}
double pow(double x, double y)
{
    return libc_rom->pow(x, y);
}
double sqrt(double x)
{
    return libc_rom->sqrt(x);
}
double ceil(double x)
{
    return libc_rom->ceil(x);
}
double fabs(double x)
{
    return libc_rom->fabs(x);
}
double floor(double d)
{
    return libc_rom->floor(d);
}
double fmod(double x, double y)
{
    return libc_rom->fmod(x, y);
}
double acosh(double x)
{
    return libc_rom->acosh(x);
}
double asinh(double x)
{
    return libc_rom->asinh(x);
}
double atanh(double x)
{
    return libc_rom->atanh(x);
}
double cbrt(double x)
{
    return libc_rom->cbrt(x);
}
double erf(double x)
{
    return libc_rom->erf(x);
}
double erfc(double x)
{
    return libc_rom->erfc(x);
}
double expm1(double x)
{
    return libc_rom->expm1(x);
}
double hypot(double x, double y)
{
    return libc_rom->hypot(x, y);
}
double remainder(double x, double y)
{
    return libc_rom->remainder(x, y);
}
double rint(double x)
{
    return libc_rom->rint(x);
}
double scalbln(double x, long int n)
{
    return libc_rom->scalbln(x, n);
}
float scalblnf(float x, long int n)
{
    return libc_rom->scalblnf(x, n);
}
long double scalblnl(long double x, long int n)
{
    return libc_rom->scalblnl(x, n);
}
float fabsf(float x)
{
    return libc_rom->fabsf(x);
}
float sinf(float x)
{
    return libc_rom->sinf(x);
}
float cosf(float x)
{
    return libc_rom->cosf(x);
}
float tanf(float x)
{
    return libc_rom->tanf(x);
}
float acosf(float x)
{
    return libc_rom->acosf(x);
}
float asinf(float x)
{
    return libc_rom->asinf(x);
}
float atanf(float x)
{
    return libc_rom->atanf(x);
}
float atan2f(float y, float x)
{
    return libc_rom->atan2f(y, x);
}
float sinhf(float x)
{
    return libc_rom->sinhf(x);
}
float coshf(float x)
{
    return libc_rom->coshf(x);
}
float tanhf(float x)
{
    return libc_rom->tanhf(x);
}
float expf(float x)
{
    return libc_rom->expf(x);
}
float logf(float x)
{
    return libc_rom->logf(x);
}
float log10f(float x)
{
    return libc_rom->log10f(x);
}
float powf(float x, float y)
{
    return libc_rom->powf(x, y);
}
float sqrtf(float x)
{
    return libc_rom->sqrtf(x);
}
float ldexpf(float x, int exp)
{
    return libc_rom->ldexpf(x, exp);
}
float frexpf(float value, int *exp)
{
    return libc_rom->frexpf(value, exp);
}
float ceilf(float x)
{
    return libc_rom->ceilf(x);
}
float floorf(float x)
{
    return libc_rom->floorf(x);
}
float fmodf(float x, float y)
{
    return libc_rom->fmodf(x, y);
}
float modff(float value, float *iptr)
{
    return libc_rom->modff(value, iptr);
}
long double acosl(long double x)
{
    return libc_rom->acosl(x);
}
long double asinl(long double x)
{
    return libc_rom->asinl(x);
}
long double atanl(long double x)
{
    return libc_rom->atanl(x);
}
long double atan2l(long double x, long double y)
{
    return libc_rom->atan2l(x, y);
}
long double ceill(long double x)
{
    return libc_rom->ceill(x);
}
long double cosl(long double x)
{
    return libc_rom->cosl(x);
}
long double coshl(long double x)
{
    return libc_rom->coshl(x);
}
long double expl(long double x)
{
    return libc_rom->expl(x);
}
long double fabsl(long double x)
{
    return libc_rom->fabsl(x);
}
long double floorl(long double x)
{
    return libc_rom->floorl(x);
}
long double fmodl(long double x, long double y)
{
    return libc_rom->fmodl(x, y);
}
long double frexpl(long double x, int *p)
{
    return libc_rom->frexpl(x, p);
}
long double ldexpl(long double x, int p)
{
    return libc_rom->ldexpl(x, p);
}
long double logl(long double x)
{
    return libc_rom->logl(x);
}
long double log10l(long double x)
{
    return libc_rom->log10l(x);
}
long double modfl(long double x, long double *p)
{
    return libc_rom->modfl(x, p);
}
long double powl(long double x, long double y)
{
    return libc_rom->powl(x, y);
}
long double sinl(long double x)
{
    return libc_rom->sinl(x);
}
long double sinhl(long double x)
{
    return libc_rom->sinhl(x);
}
long double sqrtl(long double x)
{
    return libc_rom->sqrtl(x);
}
long double tanl(long double x)
{
    return libc_rom->tanl(x);
}
long double tanhl(long double x)
{
    return libc_rom->tanhl(x);
}
float acoshf(float x)
{
    return libc_rom->acoshf(x);
}
long double acoshl(long double x)
{
    return libc_rom->acoshl(x);
}
float asinhf(float x)
{
    return libc_rom->asinhf(x);
}
long double asinhl(long double x)
{
    return libc_rom->asinhl(x);
}
float atanhf(float x)
{
    return libc_rom->atanhf(x);
}
long double atanhl(long double x)
{
    return libc_rom->atanhl(x);
}
long double copysignl(long double x, long double y)
{
    return libc_rom->copysignl(x, y);
}
float cbrtf(float x)
{
    return libc_rom->cbrtf(x);
}
long double cbrtl(long double x)
{
    return libc_rom->cbrtl(x);
}
float erff(float x)
{
    return libc_rom->erff(x);
}
long double erfl(long double x)
{
    return libc_rom->erfl(x);
}
float erfcf(float x)
{
    return libc_rom->erfcf(x);
}
long double erfcl(long double x)
{
    return libc_rom->erfcl(x);
}
float expm1f(float x)
{
    return libc_rom->expm1f(x);
}
long double expm1l(long double x)
{
    return libc_rom->expm1l(x);
}
float log1pf(float x)
{
    return libc_rom->log1pf(x);
}
long double log1pl(long double x)
{
    return libc_rom->log1pl(x);
}
float hypotf(float x, float y)
{
    return libc_rom->hypotf(x, y);
}
long double hypotl(long double x, long double y)
{
    return libc_rom->hypotl(x, y);
}
float remainderf(float x, float y)
{
    return libc_rom->remainderf(x, y);
}
long double remainderl(long double x, long double y)
{
    return libc_rom->remainderl(x, y);
}
float rintf(float x)
{
    return libc_rom->rintf(x);
}
long double rintl(long double x)
{
    return libc_rom->rintl(x);
}
double exp2(double x)
{
    return libc_rom->exp2(x);
}
float exp2f(float x)
{
    return libc_rom->exp2f(x);
}
long double exp2l(long double x)
{
    return libc_rom->exp2l(x);
}
double fdim(double x, double y)
{
    return libc_rom->fdim(x, y);
}
float fdimf(float x, float y)
{
    return libc_rom->fdimf(x, y);
}
long double fdiml(long double x, long double y)
{
    return libc_rom->fdiml(x, y);
}
double fma(double x, double y, double z)
{
    return libc_rom->fma(x, y, z);
}
float fmaf(float x, float y, float z)
{
    return libc_rom->fmaf(x, y, z);
}
double fmax(double x, double y)
{
    return libc_rom->fmax(x, y);
}
float fmaxf(float x, float y)
{
    return libc_rom->fmaxf(x, y);
}
long double fmaxl(long double x, long double y)
{
    return libc_rom->fmaxl(x, y);
}
double fmin(double x, double y)
{
    return libc_rom->fmin(x, y);
}
float fminf(float x, float y)
{
    return libc_rom->fminf(x, y);
}
long double fminl(long double x, long double y)
{
    return libc_rom->fminl(x, y);
}
#if !defined(__GNUC__)
double log2(double x)
{
    return libc_rom->log2(x);
}
#endif
float log2f(float x)
{
    return libc_rom->log2f(x);
}
long double log2l(long double x)
{
    return libc_rom->log2l(x);
}
long lrint(double x)
{
    return libc_rom->lrint(x);
}
long lrintf(float x)
{
    return libc_rom->lrintf(x);
}
long long llrint(double x)
{
    return libc_rom->llrint(x);
}
long long llrintf(float x)
{
    return libc_rom->llrintf(x);
}
long lround(double x)
{
    return libc_rom->lround(x);
}
long lroundf(float x)
{
    return libc_rom->lroundf(x);
}
long long llround(double x)
{
    return libc_rom->llround(x);
}
long long llroundf(float x)
{
    return libc_rom->llroundf(x);
}
double nan(const char *tagp)
{
    return libc_rom->nan(tagp);
}
float nanf(const char *tagp)
{
    return libc_rom->nanf(tagp);
}
double nearbyint(double x)
{
    return libc_rom->nearbyint(x);
}
float nearbyintf(float x)
{
    return libc_rom->nearbyintf(x);
}
long double nearbyintl(long double x)
{
    return libc_rom->nearbyintl(x);
}
double remquo(double x, double y, int *quo)
{
    return libc_rom->remquo(x, y, quo);
}
float remquof(float x, float y, int *quo)
{
    return libc_rom->remquof(x, y, quo);
}
double round(double x)
{
    return libc_rom->round(x);
}
float roundf(float x)
{
    return libc_rom->roundf(x);
}
long double roundl(long double x)
{
    return libc_rom->roundl(x);
}
double tgamma(double x)
{
    return libc_rom->tgamma(x);
}
float tgammaf(float x)
{
    return libc_rom->tgammaf(x);
}
long double tgammal(long double x)
{
    return libc_rom->tgammal(x);
}
double trunc(double x)
{
    return libc_rom->trunc(x);
}
float truncf(float x)
{
    return libc_rom->truncf(x);
}
long double truncl(long double x)
{
    return libc_rom->truncl(x);
}
#else
#if defined(__ARMCC_VERSION)
static const void *libc_rom __attribute__((section(".bss.noinit"), used));
#endif
#endif