Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: zImage: gather some string functions into string.c

This is a small subset of string functions needed by commits to come.
Except for memcpy() which is unchanged from its original location, their
implementation is meant to be small, and -Os is enforced to prevent gcc
from doing pointless loop unrolling.

Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Tested-by: Dave Martin <dave.martin@linaro.org>
Tested-by: Thomas Abraham <thomas.abraham@linaro.org>

authored by

Nicolas Pitre and committed by
Nicolas Pitre
df4879fa 5ffb04f6

+132 -41
+4
arch/arm/boot/compressed/Makefile
··· 26 26 OBJS += misc.o decompress.o 27 27 FONTC = $(srctree)/drivers/video/console/font_acorn_8x8.c 28 28 29 + # string library code (-Os is enforced to keep it much smaller) 30 + OBJS += string.o 31 + CFLAGS_string.o := -Os 32 + 29 33 # 30 34 # Architecture dependencies 31 35 #
+1 -41
arch/arm/boot/compressed/misc.c
··· 18 18 19 19 unsigned int __machine_arch_type; 20 20 21 - #define _LINUX_STRING_H_ 22 - 23 21 #include <linux/compiler.h> /* for inline */ 24 - #include <linux/types.h> /* for size_t */ 25 - #include <linux/stddef.h> /* for NULL */ 22 + #include <linux/types.h> 26 23 #include <linux/linkage.h> 27 - #include <asm/string.h> 28 - 29 24 30 25 static void putstr(const char *ptr); 31 26 extern void error(char *x); ··· 94 99 } 95 100 96 101 flush(); 97 - } 98 - 99 - 100 - void *memcpy(void *__dest, __const void *__src, size_t __n) 101 - { 102 - int i = 0; 103 - unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src; 104 - 105 - for (i = __n >> 3; i > 0; i--) { 106 - *d++ = *s++; 107 - *d++ = *s++; 108 - *d++ = *s++; 109 - *d++ = *s++; 110 - *d++ = *s++; 111 - *d++ = *s++; 112 - *d++ = *s++; 113 - *d++ = *s++; 114 - } 115 - 116 - if (__n & 1 << 2) { 117 - *d++ = *s++; 118 - *d++ = *s++; 119 - *d++ = *s++; 120 - *d++ = *s++; 121 - } 122 - 123 - if (__n & 1 << 1) { 124 - *d++ = *s++; 125 - *d++ = *s++; 126 - } 127 - 128 - if (__n & 1) 129 - *d++ = *s++; 130 - 131 - return __dest; 132 102 } 133 103 134 104 /*
+127
arch/arm/boot/compressed/string.c
··· 1 + /* 2 + * arch/arm/boot/compressed/string.c 3 + * 4 + * Small subset of simple string routines 5 + */ 6 + 7 + #include <linux/string.h> 8 + 9 + void *memcpy(void *__dest, __const void *__src, size_t __n) 10 + { 11 + int i = 0; 12 + unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src; 13 + 14 + for (i = __n >> 3; i > 0; i--) { 15 + *d++ = *s++; 16 + *d++ = *s++; 17 + *d++ = *s++; 18 + *d++ = *s++; 19 + *d++ = *s++; 20 + *d++ = *s++; 21 + *d++ = *s++; 22 + *d++ = *s++; 23 + } 24 + 25 + if (__n & 1 << 2) { 26 + *d++ = *s++; 27 + *d++ = *s++; 28 + *d++ = *s++; 29 + *d++ = *s++; 30 + } 31 + 32 + if (__n & 1 << 1) { 33 + *d++ = *s++; 34 + *d++ = *s++; 35 + } 36 + 37 + if (__n & 1) 38 + *d++ = *s++; 39 + 40 + return __dest; 41 + } 42 + 43 + void *memmove(void *__dest, __const void *__src, size_t count) 44 + { 45 + unsigned char *d = __dest; 46 + const unsigned char *s = __src; 47 + 48 + if (__dest == __src) 49 + return __dest; 50 + 51 + if (__dest < __src) 52 + return memcpy(__dest, __src, count); 53 + 54 + while (count--) 55 + d[count] = s[count]; 56 + return __dest; 57 + } 58 + 59 + size_t strlen(const char *s) 60 + { 61 + const char *sc = s; 62 + 63 + while (*sc != '\0') 64 + sc++; 65 + return sc - s; 66 + } 67 + 68 + int memcmp(const void *cs, const void *ct, size_t count) 69 + { 70 + const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count; 71 + int res = 0; 72 + 73 + while (su1 < end) { 74 + res = *su1++ - *su2++; 75 + if (res) 76 + break; 77 + } 78 + return res; 79 + } 80 + 81 + int strcmp(const char *cs, const char *ct) 82 + { 83 + unsigned char c1, c2; 84 + int res = 0; 85 + 86 + do { 87 + c1 = *cs++; 88 + c2 = *ct++; 89 + res = c1 - c2; 90 + if (res) 91 + break; 92 + } while (c1); 93 + return res; 94 + } 95 + 96 + void *memchr(const void *s, int c, size_t count) 97 + { 98 + const unsigned char *p = s; 99 + 100 + while (count--) 101 + if ((unsigned char)c == *p++) 102 + return (void *)(p - 1); 103 + return NULL; 104 + } 105 + 106 + char *strchr(const char *s, int c) 107 + { 108 + while (*s != (char)c) 109 + if (*s++ == '\0') 110 + return NULL; 111 + return (char *)s; 112 + } 113 + 114 + #undef memset 115 + 116 + void *memset(void *s, int c, size_t count) 117 + { 118 + char *xs = s; 119 + while (count--) 120 + *xs++ = c; 121 + return s; 122 + } 123 + 124 + void __memzero(void *s, size_t count) 125 + { 126 + memset(s, 0, count); 127 + }