diff options
author | Richard Braun <rbraun@sceen.net> | 2017-06-22 22:05:34 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-06-22 22:05:34 +0200 |
commit | 71b302e2c41f7bfb92beda8961a6d57bef2bd14e (patch) | |
tree | d42cd7a6a9e1e42024e4ed44b9ec0a4d0c516460 | |
parent | 349440892725cc5aefd7839bc4d30611c0092898 (diff) |
kern/string: fetch arch-specific defines from machine/string.h
-rw-r--r-- | arch/x86/Makefrag.am | 1 | ||||
-rw-r--r-- | arch/x86/machine/param.h | 11 | ||||
-rw-r--r-- | arch/x86/machine/string.c | 30 | ||||
-rw-r--r-- | arch/x86/machine/string.h | 32 | ||||
-rw-r--r-- | kern/string.c | 38 |
5 files changed, 67 insertions, 45 deletions
diff --git a/arch/x86/Makefrag.am b/arch/x86/Makefrag.am index d4f9fe74..965bd0bc 100644 --- a/arch/x86/Makefrag.am +++ b/arch/x86/Makefrag.am @@ -62,6 +62,7 @@ x15_SOURCES += \ arch/x86/machine/strace.c \ arch/x86/machine/strace.h \ arch/x86/machine/string.c \ + arch/x86/machine/string.h \ arch/x86/machine/tcb_asm.S \ arch/x86/machine/tcb.c \ arch/x86/machine/tcb.h \ diff --git a/arch/x86/machine/param.h b/arch/x86/machine/param.h index 6ee11cce..557bc800 100644 --- a/arch/x86/machine/param.h +++ b/arch/x86/machine/param.h @@ -52,17 +52,6 @@ #define __read_mostly __section(".data.read_mostly") /* - * Provide architecture-specific string functions. - */ -#define ARCH_STRING_MEMCPY -#define ARCH_STRING_MEMMOVE -#define ARCH_STRING_MEMSET -#define ARCH_STRING_MEMCMP -#define ARCH_STRING_STRLEN -#define ARCH_STRING_STRCPY -#define ARCH_STRING_STRCMP - -/* * System timer frequency. * * The selected value of 200 translates to a period of 5ms, small enough to diff --git a/arch/x86/machine/string.c b/arch/x86/machine/string.c index 10d9ee0a..1f1cab40 100644 --- a/arch/x86/machine/string.c +++ b/arch/x86/machine/string.c @@ -18,9 +18,9 @@ #include <stddef.h> #include <string.h> -#include <kern/param.h> +#include <machine/string.h> -#ifdef ARCH_STRING_MEMCPY +#ifdef STRING_ARCH_MEMCPY void * memcpy(void *dest, const void *src, size_t n) { @@ -32,9 +32,9 @@ memcpy(void *dest, const void *src, size_t n) : : "memory"); return orig_dest; } -#endif /* ARCH_STRING_MEMCPY */ +#endif /* STRING_ARCH_MEMCPY */ -#ifdef ARCH_STRING_MEMMOVE +#ifdef STRING_ARCH_MEMMOVE void * memmove(void *dest, const void *src, size_t n) { @@ -56,9 +56,9 @@ memmove(void *dest, const void *src, size_t n) return orig_dest; } -#endif /* ARCH_STRING_MEMMOVE */ +#endif /* STRING_ARCH_MEMMOVE */ -#ifdef ARCH_STRING_MEMSET +#ifdef STRING_ARCH_MEMSET void * memset(void *s, int c, size_t n) { @@ -71,9 +71,9 @@ memset(void *s, int c, size_t n) : "memory"); return orig_s; } -#endif /* ARCH_STRING_MEMSET */ +#endif /* STRING_ARCH_MEMSET */ -#ifdef ARCH_STRING_MEMCMP +#ifdef STRING_ARCH_MEMCMP int memcmp(const void *s1, const void *s2, size_t n) { @@ -90,9 +90,9 @@ memcmp(const void *s1, const void *s2, size_t n) c2 = *(((const unsigned char *)s2) - 1); return (int)c1 - (int)c2; } -#endif /* ARCH_STRING_MEMCMP */ +#endif /* STRING_ARCH_MEMCMP */ -#ifdef ARCH_STRING_STRLEN +#ifdef STRING_ARCH_STRLEN size_t strlen(const char *s) { @@ -105,9 +105,9 @@ strlen(const char *s) : "memory"); return ~n - 1; } -#endif /* ARCH_STRING_STRLEN */ +#endif /* STRING_ARCH_STRLEN */ -#ifdef ARCH_STRING_STRCPY +#ifdef STRING_ARCH_STRCPY char * strcpy(char *dest, const char *src) { @@ -123,9 +123,9 @@ strcpy(char *dest, const char *src) : : "al", "memory"); return orig_dest; } -#endif /* ARCH_STRING_STRCPY */ +#endif /* STRING_ARCH_STRCPY */ -#ifdef ARCH_STRING_STRCMP +#ifdef STRING_ARCH_STRCMP int strcmp(const char *s1, const char *s2) { @@ -144,4 +144,4 @@ strcmp(const char *s1, const char *s2) c2 = *(((const unsigned char *)s2) - 1); return (int)c1 - (int)c2; } -#endif /* ARCH_STRING_STRCMP */ +#endif /* STRING_ARCH_STRCMP */ diff --git a/arch/x86/machine/string.h b/arch/x86/machine/string.h new file mode 100644 index 00000000..d57bb24e --- /dev/null +++ b/arch/x86/machine/string.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 Richard Braun. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _X86_STRING_H +#define _X86_STRING_H + +/* + * Provide architecture-specific string functions. + */ +#define STRING_ARCH_MEMCPY +#define STRING_ARCH_MEMMOVE +#define STRING_ARCH_MEMSET +#define STRING_ARCH_MEMCMP +#define STRING_ARCH_STRLEN +#define STRING_ARCH_STRCPY +#define STRING_ARCH_STRCMP + +#endif /* _X86_STRING_H */ diff --git a/kern/string.c b/kern/string.c index 584030b9..763012ae 100644 --- a/kern/string.c +++ b/kern/string.c @@ -21,9 +21,9 @@ #include <stddef.h> #include <string.h> -#include <kern/param.h> +#include <machine/string.h> -#ifndef ARCH_STRING_MEMCPY +#ifndef STRING_ARCH_MEMCPY void * memcpy(void *dest, const void *src, size_t n) { @@ -40,9 +40,9 @@ memcpy(void *dest, const void *src, size_t n) return dest; } -#endif /* ARCH_STRING_MEMCPY */ +#endif /* STRING_ARCH_MEMCPY */ -#ifndef ARCH_STRING_MEMMOVE +#ifndef STRING_ARCH_MEMMOVE void * memmove(void *dest, const void *src, size_t n) { @@ -68,9 +68,9 @@ memmove(void *dest, const void *src, size_t n) return dest; } -#endif /* ARCH_STRING_MEMMOVE */ +#endif /* STRING_ARCH_MEMMOVE */ -#ifndef ARCH_STRING_MEMSET +#ifndef STRING_ARCH_MEMSET void * memset(void *s, int c, size_t n) { @@ -85,9 +85,9 @@ memset(void *s, int c, size_t n) return s; } -#endif /* ARCH_STRING_MEMSET */ +#endif /* STRING_ARCH_MEMSET */ -#ifndef ARCH_STRING_MEMCMP +#ifndef STRING_ARCH_MEMCMP int memcmp(const void *s1, const void *s2, size_t n) { @@ -104,9 +104,9 @@ memcmp(const void *s1, const void *s2, size_t n) return 0; } -#endif /* ARCH_STRING_MEMCMP */ +#endif /* STRING_ARCH_MEMCMP */ -#ifndef ARCH_STRING_STRLEN +#ifndef STRING_ARCH_STRLEN size_t strlen(const char *s) { @@ -120,9 +120,9 @@ strlen(const char *s) return i; } -#endif /* ARCH_STRING_STRLEN */ +#endif /* STRING_ARCH_STRLEN */ -#ifndef ARCH_STRING_STRCPY +#ifndef STRING_ARCH_STRCPY char * strcpy(char *dest, const char *src) { @@ -137,7 +137,7 @@ strcpy(char *dest, const char *src) return tmp; } -#endif /* ARCH_STRING_STRCPY */ +#endif /* STRING_ARCH_STRCPY */ size_t strlcpy(char *dest, const char *src, size_t n) @@ -158,7 +158,7 @@ out: return len; } -#ifndef ARCH_STRING_STRCMP +#ifndef STRING_ARCH_STRCMP int strcmp(const char *s1, const char *s2) { @@ -175,9 +175,9 @@ strcmp(const char *s1, const char *s2) return (int)c1 - (int)c2; } -#endif /* ARCH_STRING_STRCMP */ +#endif /* STRING_ARCH_STRCMP */ -#ifndef ARCH_STRING_STRNCMP +#ifndef STRING_ARCH_STRNCMP int strncmp(const char *s1, const char *s2, size_t n) { @@ -198,9 +198,9 @@ strncmp(const char *s1, const char *s2, size_t n) return (int)c1 - (int)c2; } -#endif /* ARCH_STRING_STRNCMP */ +#endif /* STRING_ARCH_STRNCMP */ -#ifndef ARCH_STRING_STRCHR +#ifndef STRING_ARCH_STRCHR char * strchr(const char *s, int c) { @@ -214,4 +214,4 @@ strchr(const char *s, int c) s++; } } -#endif /* ARCH_STRING_STRCHR */ +#endif /* STRING_ARCH_STRCHR */ |