From 109adc1598d49642a0656175faec44c7f2250028 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Sat, 5 May 2007 16:56:34 +0000 Subject: [PATCH] fix size_t and memory types. We need to be careful, because gcc calls memcpy etc itself. This is trivial (not easy), as it is just reading man pages. Signed-off-by: Stefan Reinauer Acked-by: Stefan Reinauer git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@308 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- arch/x86/linuxbios_table.c | 2 +- include/cpu/generic/x86/arch/types.h | 2 +- include/string.h | 10 +++++----- include/tables.h | 3 --- lib/mem.c | 21 ++++++++++++++------- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/arch/x86/linuxbios_table.c b/arch/x86/linuxbios_table.c index f9653f21ed..0bc43d477d 100644 --- a/arch/x86/linuxbios_table.c +++ b/arch/x86/linuxbios_table.c @@ -171,7 +171,7 @@ void lb_strings(struct lb_header *header) } -void lb_memory_range(struct lb_memory *mem, +static void lb_memory_range(struct lb_memory *mem, u32 type, u64 start, u64 size) { int entries; diff --git a/include/cpu/generic/x86/arch/types.h b/include/cpu/generic/x86/arch/types.h index e69b3d47bf..b217992c42 100644 --- a/include/cpu/generic/x86/arch/types.h +++ b/include/cpu/generic/x86/arch/types.h @@ -15,7 +15,7 @@ typedef signed int s32; typedef signed short s16; typedef signed char s8; -typedef u64 size_t; +typedef long unsigned int size_t; #define NULL ((void *)0) diff --git a/include/string.h b/include/string.h index be5023fa04..087bd8d4a3 100644 --- a/include/string.h +++ b/include/string.h @@ -24,13 +24,13 @@ #include /* Prototypes for functions from lib/mem.c. */ -extern void *memcpy(void *dest, const void *src, size_t len); -extern void *memmove(void *dest, const void *src, size_t len); -extern void *memset(void *v, unsigned char a, size_t len); -extern int memcmp(const void *s1, const void *s2, size_t len); +void *memcpy(void *dest, const void *src, size_t len); +void *memmove(void *dest, const void *src, size_t len); +void *memset(void *s, int c, size_t len); +int memcmp(const void *s1, const void *s2, size_t len); /* Prototypes for functions from console/vsprintf.c. */ -extern int sprintf(char *buf, const char *fmt, ...); +int sprintf(char *buf, const char *fmt, ...); /** * Calculate the length of a fixed-size string. diff --git a/include/tables.h b/include/tables.h index b0d7052168..87dd3e2f3b 100644 --- a/include/tables.h +++ b/include/tables.h @@ -245,8 +245,6 @@ struct lb_record *lb_last_record(struct lb_header *header); struct lb_record *lb_next_record(struct lb_record *rec); struct lb_record *lb_new_record(struct lb_header *header); struct lb_memory *lb_memory(struct lb_header *header); -void lb_memory_range(struct lb_memory *mem, - u32 type, u64 start, u64 size); struct lb_mainboard *lb_mainboard(struct lb_header *header); unsigned long lb_table_fini(struct lb_header *header); @@ -255,7 +253,6 @@ unsigned long lb_table_fini(struct lb_header *header); */ struct lb_memory *get_lb_mem(void); -// extern struct cmos_option_table option_table; struct cmos_option_table *get_option_table(void); diff --git a/lib/mem.c b/lib/mem.c index f0c90e7192..9e123bd191 100644 --- a/lib/mem.c +++ b/lib/mem.c @@ -24,6 +24,7 @@ */ #include +#include /** * memcpy() and memmove() helper that uses unsigned long copying when dest and @@ -108,10 +109,12 @@ static void memcpy_helper(void *dest, const void *src, size_t len, * @param dest Pointer to the destination memory area. * @param src Pointer to the source memory area. * @param len Number of bytes to copy. + * @return Pointer specified by parameter dest */ -void memcpy(void *dest, const void *src, size_t len) +void *memcpy(void *dest, const void *src, size_t len) { memcpy_helper(dest, src, len, 0); + return dest; } /** @@ -122,24 +125,28 @@ void memcpy(void *dest, const void *src, size_t len) * @param dest Pointer to the destination memory area. * @param src Pointer to the source memory area. * @param len Number of bytes to copy. + * @return Pointer specified by parameter dest */ -void memmove(void *dest, const void *src, size_t len) +void *memmove(void *dest, const void *src, size_t len) { memcpy_helper(dest, src, len, dest > src && dest < (src + len)); + return dest; } /** * Fill a memory area with the specified byte. * - * @param v Pointer to the beginning of the memory area. - * @param a The byte which is used for filling the memory area. + * @param s Pointer to the beginning of the memory area. + * @param c The byte which is used for filling the memory area. * @param len The number of bytes to write. + * @return Pointer specified by parameter s */ -void memset(void *v, unsigned char a, size_t len) +void *memset(void *s, int c, size_t len) { - unsigned char *cp = v; + unsigned char *cp = s; while (len--) - *cp++ = a; + *cp++ = (unsigned char)c; + return s; } /**