Skip to content

Commit

Permalink
x86, boot: Create a separate string.h file to provide standard string…
Browse files Browse the repository at this point in the history
… functions

Create a separate arch/x86/boot/string.h file to provide declaration of
some of the common string functions.

By default memcpy, memset and memcmp functions will default to gcc
builtin functions. If code wants to use an optimized version of any
of these functions, they need to #undef the respective macro and link
against a local file providing definition of undefed function.

For example, arch/x86/boot/* code links against copy.S to get memcpy()
and memcmp() definitions. arch/86/boot/compressed/* links against
compressed/string.c.

There are quite a few places in arch/x86/ where these functions are
used. Idea is to try to consilidate  their declaration and possibly
definitions so that it can be reused.

I am planning to reuse boot/string.h in arch/x86/purgatory/ and use
gcc builtin functions for memcpy, memset and memcmp.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Link: http://lkml.kernel.org/r/1395170800-11059-3-git-send-email-vgoyal@redhat.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
  • Loading branch information
Vivek Goyal authored and H. Peter Anvin committed Mar 19, 2014
1 parent aad8309 commit c041b5a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
5 changes: 0 additions & 5 deletions arch/x86/boot/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ void copy_to_fs(addr_t dst, void *src, size_t len);
void *copy_from_fs(void *dst, addr_t src, size_t len);
void copy_to_gs(addr_t dst, void *src, size_t len);
void *copy_from_gs(void *dst, addr_t src, size_t len);
void *memcpy(void *dst, void *src, size_t len);
void *memset(void *dst, int c, size_t len);

#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
#define memset(d,c,l) __builtin_memset(d,c,l)

/* a20.c */
int enable_a20(void);
Expand Down
1 change: 1 addition & 0 deletions arch/x86/boot/cpucheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <asm/processor-flags.h>
#include <asm/required-features.h>
#include <asm/msr-index.h>
#include "string.h"

static u32 err_flags[NCAPINTS];

Expand Down
1 change: 1 addition & 0 deletions arch/x86/boot/edd.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "boot.h"
#include <linux/edd.h>
#include "string.h"

#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)

Expand Down
1 change: 1 addition & 0 deletions arch/x86/boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "boot.h"
#include "string.h"

struct boot_params boot_params __attribute__((aligned(16)));

Expand Down
1 change: 1 addition & 0 deletions arch/x86/boot/regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "boot.h"
#include "string.h"

void initregs(struct biosregs *reg)
{
Expand Down
19 changes: 19 additions & 0 deletions arch/x86/boot/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef BOOT_STRING_H
#define BOOT_STRING_H

/* Undef any of these macros coming from string_32.h. */
#undef memcpy
#undef memset
#undef memcmp

void *memcpy(void *dst, const void *src, size_t len);
void *memset(void *dst, int c, size_t len);

/*
* Access builtin version by default. If one needs to use optimized version,
* do "undef memcpy" in .c file and link against right string.c
*/
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
#define memset(d,c,l) __builtin_memset(d,c,l)

#endif /* BOOT_STRING_H */
1 change: 1 addition & 0 deletions arch/x86/boot/video-vesa.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "boot.h"
#include "video.h"
#include "vesa.h"
#include "string.h"

/* VESA information */
static struct vesa_general_info vginfo;
Expand Down

0 comments on commit c041b5a

Please sign in to comment.