diff --git a/ChangeLog b/ChangeLog index bdb177d75..6596c16d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-06-26 Pavel Roskin + + * include/grub/types.h: Define GRUB_TARGET_WORDSIZE. + * include/grub/elf.h: Define symbols without "32" or "64" based + on GRUB_TARGET_WORDSIZE. + * include/grub/multiboot2.h: Use GRUB_TARGET_WORDSIZE. + * efiemu/loadcore32.c: Redefine GRUB_TARGET_WORDSIZE, remove own + ELF definitions. + * efiemu/loadcore64.c: Likewise. + * loader/i386/bsd32.c: Likewise. + * loader/i386/bsd64.c: Likewise. + * kern/dl.c: Remove own ELF definitions. + * util/i386/efi/grub-mkimage.c: Likewise. + 2009-06-23 Robert Millan * kern/i386/pc/startup.S (real_to_prot): Access `gdtdesc' using diff --git a/efiemu/loadcore32.c b/efiemu/loadcore32.c index b4f61c794..c1e033b78 100644 --- a/efiemu/loadcore32.c +++ b/efiemu/loadcore32.c @@ -18,10 +18,5 @@ */ #define SUFFIX(x) x ## 32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Word Elf32_Word -#define ELF_ST_TYPE ELF32_ST_TYPE -#define ELF_ST_BIND ELF32_ST_BIND +#define GRUB_TARGET_WORDSIZE 32 #include "loadcore.c" diff --git a/efiemu/loadcore64.c b/efiemu/loadcore64.c index 097276cc8..ce7284fea 100644 --- a/efiemu/loadcore64.c +++ b/efiemu/loadcore64.c @@ -18,10 +18,5 @@ */ #define SUFFIX(x) x ## 64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Word Elf64_Word -#define ELF_ST_TYPE ELF64_ST_TYPE -#define ELF_ST_BIND ELF64_ST_BIND +#define GRUB_TARGET_WORDSIZE 64 #include "loadcore.c" diff --git a/include/grub/elf.h b/include/grub/elf.h index 319bc7ce6..49570a60e 100644 --- a/include/grub/elf.h +++ b/include/grub/elf.h @@ -2330,4 +2330,44 @@ typedef Elf32_Addr Elf32_Conflict; #define R_X86_64_NUM 24 +#if GRUB_TARGET_WORDSIZE == 32 + +typedef Elf32_Addr Elf_Addr; +typedef Elf32_Ehdr Elf_Ehdr; +typedef Elf32_Half Elf_Half; +typedef Elf32_Off Elf_Off; +typedef Elf32_Rel Elf_Rel; +typedef Elf32_Rela Elf_Rela; +typedef Elf32_Section Elf_Section; +typedef Elf32_Shdr Elf_Shdr; +typedef Elf32_Sym Elf_Sym; +typedef Elf32_Word Elf_Word; + +#define ELF_ST_BIND(val) ELF32_ST_BIND(val) +#define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) +#define ELF_R_SYM(val) ELF32_R_SYM(val) +#define ELF_R_TYPE(val) ELF32_R_TYPE(val) +#define ELF_R_INFO(sym, type) ELF32_R_INFO(sym, type) + +#elif GRUB_TARGET_WORDSIZE == 64 + +typedef Elf64_Addr Elf_Addr; +typedef Elf64_Ehdr Elf_Ehdr; +typedef Elf64_Half Elf_Half; +typedef Elf64_Off Elf_Off; +typedef Elf64_Rel Elf_Rel; +typedef Elf64_Rela Elf_Rela; +typedef Elf64_Section Elf_Section; +typedef Elf64_Shdr Elf_Shdr; +typedef Elf64_Sym Elf_Sym; +typedef Elf64_Word Elf_Word; + +#define ELF_ST_BIND(val) ELF64_ST_BIND (val) +#define ELF_ST_TYPE(val) ELF64_ST_TYPE (val) +#define ELF_R_SYM(val) ELF64_R_SYM(val) +#define ELF_R_TYPE(val) ELF64_R_TYPE(val) +#define ELF_R_INFO(sym, type) ELF64_R_INFO(sym, type) + +#endif /* GRUB_TARGET_WORDSIZE == 64 */ + #endif /* ! GRUB_ELF_H */ diff --git a/include/grub/multiboot2.h b/include/grub/multiboot2.h index 1d2324a53..2c9780996 100644 --- a/include/grub/multiboot2.h +++ b/include/grub/multiboot2.h @@ -27,7 +27,7 @@ #ifndef GRUB_UTIL typedef grub_uint32_t uint32_t; typedef grub_uint64_t uint64_t; -#define __WORDSIZE (8 * GRUB_TARGET_SIZEOF_VOID_P) +#define __WORDSIZE GRUB_TARGET_WORDSIZE #endif struct multiboot_tag_header; diff --git a/include/grub/types.h b/include/grub/types.h index 114b4564a..3eb8290af 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -50,6 +50,14 @@ # error "This architecture is not supported because sizeof(void *) != 4 and sizeof(void *) != 8" #endif +#ifndef GRUB_TARGET_WORDSIZE +# if GRUB_TARGET_SIZEOF_VOID_P == 4 +# define GRUB_TARGET_WORDSIZE 32 +# elif GRUB_TARGET_SIZEOF_VOID_P == 8 +# define GRUB_TARGET_WORDSIZE 64 +# endif +#endif + /* Define various wide integers. */ typedef signed char grub_int8_t; typedef short grub_int16_t; diff --git a/kern/dl.c b/kern/dl.c index d729c0874..cd34e3178 100644 --- a/kern/dl.c +++ b/kern/dl.c @@ -29,30 +29,6 @@ #include #include -#if GRUB_CPU_SIZEOF_VOID_P == 4 - -typedef Elf32_Word Elf_Word; -typedef Elf32_Addr Elf_Addr; -typedef Elf32_Ehdr Elf_Ehdr; -typedef Elf32_Shdr Elf_Shdr; -typedef Elf32_Sym Elf_Sym; - -# define ELF_ST_BIND(val) ELF32_ST_BIND (val) -# define ELF_ST_TYPE(val) ELF32_ST_TYPE (val) - -#elif GRUB_CPU_SIZEOF_VOID_P == 8 - -typedef Elf64_Word Elf_Word; -typedef Elf64_Addr Elf_Addr; -typedef Elf64_Ehdr Elf_Ehdr; -typedef Elf64_Shdr Elf_Shdr; -typedef Elf64_Sym Elf_Sym; - -# define ELF_ST_BIND(val) ELF64_ST_BIND (val) -# define ELF_ST_TYPE(val) ELF64_ST_TYPE (val) - -#endif - struct grub_dl_list diff --git a/loader/i386/bsd32.c b/loader/i386/bsd32.c index 24dab6cf4..26704c486 100644 --- a/loader/i386/bsd32.c +++ b/loader/i386/bsd32.c @@ -1,7 +1,5 @@ #define SUFFIX(x) x ## 32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym +#define GRUB_TARGET_WORDSIZE 32 #define OBJSYM 0 #include typedef grub_uint32_t grub_freebsd_addr_t; diff --git a/loader/i386/bsd64.c b/loader/i386/bsd64.c index f4ff8b233..f8aad1ca7 100644 --- a/loader/i386/bsd64.c +++ b/loader/i386/bsd64.c @@ -1,7 +1,5 @@ #define SUFFIX(x) x ## 64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym +#define GRUB_TARGET_WORDSIZE 64 #define OBJSYM 1 #include typedef grub_uint64_t grub_freebsd_addr_t; diff --git a/util/i386/efi/grub-mkimage.c b/util/i386/efi/grub-mkimage.c index 2813e799d..466aa9f87 100644 --- a/util/i386/efi/grub-mkimage.c +++ b/util/i386/efi/grub-mkimage.c @@ -31,44 +31,10 @@ #include #include -#if GRUB_TARGET_SIZEOF_VOID_P == 4 - -typedef Elf32_Word Elf_Word; -typedef Elf32_Addr Elf_Addr; -typedef Elf32_Ehdr Elf_Ehdr; -typedef Elf32_Shdr Elf_Shdr; -typedef Elf32_Sym Elf_Sym; -typedef Elf32_Half Elf_Half; -typedef Elf32_Off Elf_Off; -typedef Elf32_Section Elf_Section; -typedef Elf32_Rel Elf_Rel; -typedef Elf32_Rela Elf_Rela; - -#define ELF_R_SYM ELF32_R_SYM -#define ELF_R_TYPE ELF32_R_TYPE -#define ELF_R_INFO ELF32_R_INFO - -#define grub_le_to_cpu grub_le_to_cpu32 - -#elif GRUB_TARGET_SIZEOF_VOID_P == 8 - -typedef Elf64_Word Elf_Word; -typedef Elf64_Addr Elf_Addr; -typedef Elf64_Ehdr Elf_Ehdr; -typedef Elf64_Shdr Elf_Shdr; -typedef Elf64_Sym Elf_Sym; -typedef Elf64_Half Elf_Half; -typedef Elf64_Off Elf_Off; -typedef Elf64_Section Elf_Section; -typedef Elf64_Rel Elf_Rel; -typedef Elf64_Rela Elf_Rela; - -#define ELF_R_SYM ELF64_R_SYM -#define ELF_R_TYPE ELF64_R_TYPE -#define ELF_R_INFO ELF64_R_INFO - -#define grub_le_to_cpu grub_le_to_cpu64 - +#if GRUB_TARGET_WORDSIZE == 32 +# define grub_le_to_cpu(val) grub_le_to_cpu32(val) +#elif GRUB_TARGET_WORDSIZE == 64 +# define grub_le_to_cpu(val) grub_le_to_cpu64(val) #endif static const grub_uint8_t stub[] = GRUB_PE32_MSDOS_STUB;