Cleaning up the file lib/decompress_unxz.c, moving all memory helper functions, e.g. memmove, to a new common source file, lib/boot/mem.c
Subsystems (6)
PATCH v3 1/1 Cleaning up the file lib/decompress_unxz.c, moving all memory helper functions, e.g. memmove, to a new common source file, lib/boot/mem.c
In additon to including the decompressor, any architecture supporting the XZ decompression needs to also include this new source file.
Also moving some other duplicated memory helper functions to this new source file from the arm, s390, sh and x86 preboot environments. All 4 architectures build without error when using any compression methods.
Adding a new file lib/boot/mem.c, containing the weak version of the memory helper functions required by different compression types. Any architecture could override any of the functions with a non-weak more optimized version in a separate memory utility file.
Removing the memmove and memcpy defines workaround and adding the new source file include to arch/arm/boot/compressed/decompress.c
Removing the common functions, memmove and memcmp, from arch/arm/boot/compressed/string.c.
Removing the memset, memcpy and memmove functions and adding the new source file include to arch/s390/boot/compressed/misc.c.
Removing the memset and memcpy functions and adding the new source file include to arch/sh/boot/compressed/misc.c
Removing the memcpy and memset functions and adding the new source file include to arch/x86/boot/compressed/misc.c
Adding the memcpy functions, removed from misc.c, to arch/x86/boot/compressed/string.c
--
Change since v2:
* Instead of calling memcpy, memmove manually copying data to ensure data integrity.
* Replacing ifdef HAVE_PREBOOT_XXX with architecture specific weak functions.
* Replacing __builtin_memcpy call in memcpy with a generic implementation.
Change since v1:
* created and moved common memory helper functions to a new file.
--- arch/arm/boot/compressed/decompress.c | 5 +- arch/arm/boot/compressed/string.c | 38 +----------------- arch/s390/boot/compressed/misc.c | 36 +---------------- arch/sh/boot/compressed/misc.c | 21 +--------- arch/x86/boot/compressed/misc.c | 41 +------------------ arch/x86/boot/compressed/string.c | 30 ++++++++++++++ lib/boot/mem.c | 67 +++++++++++++++++++++++++++++++ lib/decompress_unxz.c | 70 +-------------------------------- lib/xz/xz_private.h | 7 ++- 9 files changed, 114 insertions(+), 201 deletions(-) create mode 100644 lib/boot/mem.c
arch/arm/boot/compressed/decompress.c +3 -2
@@ -10,6 +10,8 @@ extern unsigned long free_mem_ptr;extern unsigned long free_mem_end_ptr;extern void error (char *); +#include "../../../../lib/boot/mem.c" +#define STATIC static#define STATIC_RW_DATA /* non-static please */
@@ -45,8 +47,6 @@ extern void error(char *);#endif #ifdef CONFIG_KERNEL_XZ -#define memmove memmove -#define memcpy memcpy#include "../../../../lib/decompress_unxz.c" #endif
@@ -54,3 +54,4 @@ int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x)) {return decompress (input, len,NULL ,NULL , output,NULL , error); } +
arch/arm/boot/compressed/string.c +1 -37
@@ -40,22 +40,6 @@ void *memcpy(void *__dest, __const void *__src, size_t __n)return __dest; } -void *memmove(void *__dest, __const void *__src, size_t count) -{ -unsigned char *d = __dest; -const unsigned char *s = __src; - -if (__dest == __src) -return __dest; - -if (__dest < __src) -return memcpy (__dest, __src, count); - -while (count--) - d[count] = s[count]; -return __dest; -} -size_t strlen (const char *s) {const char *sc = s;
@@ -65,19 +49,6 @@ size_t strlen(const char *s)return sc - s; } -int memcmp (const void *cs,const void *ct,size_t count) -{ -const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count; -int res =0 ; - -while (su1 < end) { - res = *su1++ - *su2++; -if (res) -break ; - } -return res; -} -int strcmp (const char *cs,const char *ct) {unsigned char c1, c2;
@@ -113,15 +84,8 @@ char *strchr(const char *s, int c)#undef memset -void *memset (void *s,int c,size_t count) -{ -char *xs = s; -while (count--) - *xs++ = c; -return s; -} -void __memzero (void *s,size_t count) {memset (s,0 , count); } +
arch/s390/boot/compressed/misc.c +2 -34
@@ -67,40 +67,6 @@ static int puts(const char *s)return 0 ; } -void *memset (void *s,int c,size_t n) -{ -char *xs; - -if (c ==0 ) -return __builtin_memset (s,0 , n); - - xs = (char *) s; -if (n >0 ) -do { - *xs++ = c; - }while (--n >0 ); -return s; -} - -void *memcpy(void *__dest, __const void *__src, size_t __n) -{ -return __builtin_memcpy (__dest, __src, __n); -} - -void *memmove(void *__dest, __const void *__src, size_t __n) -{ -char *d; -const char *s; - -if (__dest <= __src) -return __builtin_memcpy (__dest, __src, __n); - d = __dest + __n; - s = __src + __n; -while (__n--) - *--d = *--s; -return __dest; -} -static void error (char *x) {unsigned long long psw =0x000a0000deadbeefULL ;
@@ -166,3 +132,5 @@ unsigned long decompress_kernel(void)return (unsigned long ) output; } +#include "../../../../lib/boot/mem.c" +
arch/sh/boot/compressed/misc.c +2 -19
@@ -15,6 +15,8 @@#include <asm/addrspace.h> #include <asm/page.h> +#include "../../../../lib/boot/mem.c" +/* * gzip declarations */
@@ -75,25 +77,6 @@ int puts(const char *s)return 0 ; } -void *memset (void * s,int c,size_t n) -{ -int i; -char *ss = (char *)s; - -for (i=0 ;i<n;i++) ss[i] = c; -return s; -} - -void* memcpy(void* __dest, __const void* __src, -size_t __n) -{ -int i; -char *d = (char *)__dest, *s = (char *)__src; - -for (i=0 ;i<__n;i++) d[i] = s[i]; -return __dest; -} -static void error (char *x) {puts ("\n\n" );
arch/x86/boot/compressed/misc.c +2 -39
50 lines not on this page · raw message
arch/x86/boot/compressed/string.c +30 -0
@@ -8,4 +8,34 @@ int memcmp(const void *s1, const void *s2, size_t len)return diff; } +#ifdef CONFIG_X86_32 +void *memcpy (void *dest,const void *src,size_t n) +{ +int d0, d1, d2; + asmvolatile ( +"rep ; movsl\n\t" +"movl %4,%%ecx\n\t" +"rep ; movsb\n\t" + :"=&c" (d0),"=&D" (d1),"=&S" (d2) + :"0" (n >>2 ),"g" (n &3 ),"1" (dest),"2" (src) + :"memory" ); + +return dest; +} +#else +void *memcpy (void *dest,const void *src,size_t n) +{ +long d0, d1, d2; + asmvolatile ( +"rep ; movsq\n\t" +"movq %4,%%rcx\n\t" +"rep ; movsb\n\t" + :"=&c" (d0),"=&D" (d1),"=&S" (d2) + :"0" (n >>3 ),"g" (n &7 ),"1" (dest),"2" (src) + :"memory" ); + +return dest; +} +#endif +#include "../string.c"
lib/boot/mem.c new file +67 -0
67 lines not on this page · raw message
lib/decompress_unxz.c +2 -68
78 lines not on this page · raw message
lib/xz/xz_private.h +5 -2
@@ -37,9 +37,12 @@# ifdef CONFIG_XZ_DEC_SPARC # define XZ_DEC_SPARC # endif -# define memeq (a, b, size) (memcmp(a, b, size) == 0) -# define memzero (buf, size) memset(buf, 0, size)# endif +/* Make all environments, including preboot, use memcmp for memeq */ +# define memeq (a, b, size) (memcmp(a, b, size) == 0) +/* To suppress redefine warning in some architecture's preboot */ +# undef memzero +# define memzero (buf, size) memset(buf, 0, size)# define get_le32 (p) le32_to_cpup((const uint32_t *)(p))#else /*
Signature · 1 line
1.7.1