mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 23:41:23 +01:00
lib: Include helper libc functions directly in libsbi.
libsbi needs some of the custom libc functions. It should be directly included in libsbi instead of platform specific libraries. Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Atish Patra <atish.patra@wdc.com>
|
||||
*/
|
||||
|
||||
#ifndef __STRING_H__
|
||||
#define __STRING_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
int strcmp(const char *a, const char *b);
|
||||
|
||||
size_t strlen(const char *str);
|
||||
|
||||
size_t strnlen(const char *str, size_t count);
|
||||
|
||||
char *strcpy(char *dest, const char *src);
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t count);
|
||||
|
||||
char *strchr(const char *s, int c);
|
||||
|
||||
char *strrchr(const char *s, int c);
|
||||
|
||||
void *memset(void *s, int c, size_t count);
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t count);
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t count);
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t count);
|
||||
|
||||
void *memchr(const void *s, int c, size_t count);
|
||||
|
||||
#endif
|
@@ -10,7 +10,7 @@
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/riscv_encoding.h>
|
||||
#include <sbi/sbi_console.h>
|
||||
#include <plat/string.h>
|
||||
#include <sbi/string.h>
|
||||
#include <plat/tinyfdt.h>
|
||||
#include <plat/irqchip/plic.h>
|
||||
|
||||
|
@@ -1,15 +0,0 @@
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Atish Patra<atish.patra@wdc.com>
|
||||
#
|
||||
|
||||
libc_files = string.o
|
||||
|
||||
$(foreach file, $(libc_files), \
|
||||
$(eval CFLAGS_$(file) = -I$(src)/../../common/libc))
|
||||
|
||||
platform-common-objs-$(PLATFORM_INCLUDE_LIBC) += $(addprefix libc/,$(libc_files))
|
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Atish Patra <atish.patra@wdc.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple libc functions. These are not optimized at all and might have some
|
||||
* bugs as well. Use any optimized routines from newlib or glibc if required.
|
||||
*/
|
||||
|
||||
#include <plat/string.h>
|
||||
|
||||
int strcmp(const char *a, const char *b)
|
||||
{
|
||||
/* search first diff or end of string */
|
||||
for (; *a == *b && *a != '\0'; a++, b++)
|
||||
;
|
||||
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
size_t strlen(const char *str)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
|
||||
while (*str != '\0') {
|
||||
ret++;
|
||||
str++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t strnlen(const char *str, size_t count)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
|
||||
while (*str != '\0' && ret < count) {
|
||||
ret++;
|
||||
str++;
|
||||
count--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *ret = dest;
|
||||
|
||||
while (*src != '\0') {
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t count)
|
||||
{
|
||||
char *ret = dest;
|
||||
|
||||
while (count-- && *src != '\0') {
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *strchr(const char *s, int c)
|
||||
{
|
||||
while (*s != '\0' && *s != (char)c)
|
||||
s++;
|
||||
|
||||
if (*s == '\0')
|
||||
return NULL;
|
||||
else
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
char *strrchr(const char *s, int c)
|
||||
{
|
||||
const char *last = s + strlen(s);
|
||||
|
||||
while (last > s && *last != (char)c)
|
||||
last--;
|
||||
|
||||
if (*last != (char)c)
|
||||
return NULL;
|
||||
else
|
||||
return (char *)last;
|
||||
}
|
||||
void *memset(void *s, int c, size_t count)
|
||||
{
|
||||
char *temp = s;
|
||||
|
||||
while (count > 0) {
|
||||
count--;
|
||||
*temp++ = c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t count)
|
||||
{
|
||||
char *temp1 = dest;
|
||||
const char *temp2 = src;
|
||||
|
||||
while (count > 0) {
|
||||
*temp1++ = *temp2++;
|
||||
count--;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t count)
|
||||
{
|
||||
char *temp1 = (char *)dest;
|
||||
const char *temp2 = (char *)src;
|
||||
|
||||
if (src == dest)
|
||||
return dest;
|
||||
|
||||
if (dest < src) {
|
||||
while (count > 0) {
|
||||
*temp1++ = *temp2++;
|
||||
count--;
|
||||
}
|
||||
} else {
|
||||
temp1 = dest + count - 1;
|
||||
temp2 = src + count - 1;
|
||||
|
||||
while (count > 0) {
|
||||
*temp1-- = *temp2--;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t count)
|
||||
{
|
||||
const char *temp1 = s1;
|
||||
const char *temp2 = s2;
|
||||
|
||||
for (; count > 0 && (*temp1 == *temp2); count--) {
|
||||
temp1++;
|
||||
temp2++;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
return *(unsigned char *)temp1 - *(unsigned char *)temp2;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memchr(const void *s, int c, size_t count)
|
||||
{
|
||||
const unsigned char *temp = s;
|
||||
|
||||
while (count > 0) {
|
||||
if ((unsigned char)c == *temp++) {
|
||||
return (void *)(temp - 1);
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@@ -52,7 +52,7 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <plat/string.h>
|
||||
#include <sbi/string.h>
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
#define INT_MAX ((int)(~0U >> 1))
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*/
|
||||
|
||||
#include <plat/string.h>
|
||||
#include <sbi/string.h>
|
||||
#include <plat/tinyfdt.h>
|
||||
|
||||
#define FDT_MAGIC 0xd00dfeed
|
||||
|
Reference in New Issue
Block a user