Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[x86_64] Add support for compilation as an x86_64 binary
Currently the only supported platform for x86_64 is EFI.

Building an EFI64 gPXE requires a version of gcc that supports
__attribute__((ms_abi)).  This currently means a development build of
gcc; the feature should be present when gcc 4.4 is released.

In the meantime; you can grab a suitable gcc tree from

  git://git.etherboot.org/scm/people/mcb30/gcc/.git
  • Loading branch information
Michael Brown committed Dec 5, 2008
1 parent b0d2c9a commit ce0a0cc
Show file tree
Hide file tree
Showing 34 changed files with 997 additions and 51 deletions.
6 changes: 5 additions & 1 deletion src/arch/i386/Makefile
Expand Up @@ -68,7 +68,6 @@ SRCDIRS += arch/i386/drivers/net
SRCDIRS += arch/i386/interface/pcbios
SRCDIRS += arch/i386/interface/pxe
SRCDIRS += arch/i386/interface/syslinux
SRCDIRS += arch/i386/interface/efi

# The various xxx_loader.c files are #included into core/loader.c and
# should not be compiled directly.
Expand All @@ -82,6 +81,11 @@ NON_AUTO_SRCS += arch/i386/core/wince_loader.c
OBJS_unnrv2b = unnrv2b unnrv2b16
CFLAGS_unnrv2b16 = -DCODE16

# Include common x86 Makefile
#
MAKEDEPS += arch/x86/Makefile
include arch/x86/Makefile

# Include platform-specific Makefile
#
MAKEDEPS += arch/i386/Makefile.$(PLATFORM)
Expand Down
45 changes: 5 additions & 40 deletions src/arch/i386/include/bits/byteswap.h
Expand Up @@ -2,7 +2,7 @@
#define ETHERBOOT_BITS_BYTESWAP_H

static inline __attribute__ ((always_inline, const)) uint16_t
__i386_bswap_16(uint16_t x)
__bswap_variable_16(uint16_t x)
{
__asm__("xchgb %b0,%h0\n\t"
: "=q" (x)
Expand All @@ -11,7 +11,7 @@ __i386_bswap_16(uint16_t x)
}

static inline __attribute__ ((always_inline, const)) uint32_t
__i386_bswap_32(uint32_t x)
__bswap_variable_32(uint32_t x)
{
__asm__("xchgb %b0,%h0\n\t"
"rorl $16,%0\n\t"
Expand All @@ -22,55 +22,20 @@ __i386_bswap_32(uint32_t x)
}

static inline __attribute__ ((always_inline, const)) uint64_t
__i386_bswap_64(uint64_t x)
__bswap_variable_64(uint64_t x)
{
union {
uint64_t qword;
uint32_t dword[2];
} u;

u.qword = x;
u.dword[0] = __i386_bswap_32(u.dword[0]);
u.dword[1] = __i386_bswap_32(u.dword[1]);
u.dword[0] = __bswap_variable_32(u.dword[0]);
u.dword[1] = __bswap_variable_32(u.dword[1]);
__asm__("xchgl %0,%1"
: "=r" ( u.dword[0] ), "=r" ( u.dword[1] )
: "0" ( u.dword[0] ), "1" ( u.dword[1] ) );
return u.qword;
}

#define __bswap_constant_16(x) \
((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
(((uint16_t)(x) & 0xff00) >> 8)))

#define __bswap_constant_32(x) \
((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
(((uint32_t)(x) & 0x0000ff00U) << 8) | \
(((uint32_t)(x) & 0x00ff0000U) >> 8) | \
(((uint32_t)(x) & 0xff000000U) >> 24)))

#define __bswap_constant_64(x) \
((uint64_t)((((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & 0xff00000000000000ULL) >> 56)))

#define __bswap_16(x) \
((uint16_t)(__builtin_constant_p(x) ? \
__bswap_constant_16(x) : \
__i386_bswap_16(x)))

#define __bswap_32(x) \
((uint32_t)(__builtin_constant_p(x) ? \
__bswap_constant_32(x) : \
__i386_bswap_32(x)))

#define __bswap_64(x) \
((uint64_t)(__builtin_constant_p(x) ? \
__bswap_constant_64(x) : \
__i386_bswap_64(x)))

#endif /* ETHERBOOT_BITS_BYTESWAP_H */
4 changes: 2 additions & 2 deletions src/arch/i386/include/bits/stdint.h
@@ -1,8 +1,8 @@
#ifndef _BITS_STDINT_H
#define _BITS_STDINT_H

typedef typeof(sizeof(int)) size_t;
typedef signed long ssize_t;
typedef unsigned int size_t;
typedef signed int ssize_t;
typedef signed long off_t;

typedef unsigned char uint8_t;
Expand Down
8 changes: 8 additions & 0 deletions src/arch/x86/Makefile
@@ -0,0 +1,8 @@
# Include common x86 headers
#
CFLAGS += -Iarch/x86/include

# x86-specific directories containing source files
#
SRCDIRS += arch/x86/core
SRCDIRS += arch/x86/interface/efi
Expand Up @@ -16,6 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <gpxe/io.h>
#include <gpxe/pci.h>

/** @file
Expand Down
Expand Up @@ -32,9 +32,7 @@
* @v len Length
* @ret dest Destination address
*/
__attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
const void *src,
size_t len ) {
void * __memcpy ( void *dest, const void *src, size_t len ) {
void *edi = dest;
const void *esi = src;
int discard_ecx;
Expand Down
File renamed without changes.
Expand Up @@ -23,9 +23,7 @@

#define __HAVE_ARCH_MEMCPY

extern __attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
const void *src,
size_t len );
extern void * __memcpy ( void *dest, const void *src, size_t len );

#if 0
static inline __attribute__ (( always_inline )) void *
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions src/arch/x86_64/Makefile
@@ -0,0 +1,41 @@
# Code size reduction.
#
CFLAGS += -fstrength-reduce -fomit-frame-pointer

# Code size reduction. gcc3 needs a different syntax to gcc2 if you
# want to avoid spurious warnings.
#
CFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=1

# Use %rip-relative addressing wherever possible.
#
CFLAGS += -fpie

# Force 64-bit code
#
CFLAGS += -m64
ASFLAGS += --64
LDFLAGS += -m elf_x86_64

# EFI requires -fshort-wchar, and nothing else currently uses wchar_t
#
CFLAGS += -fshort-wchar

# We need to undefine the default macro "i386" when compiling .S
# files, otherwise ".arch i386" translates to ".arch 1"...
#
CFLAGS += -Ui386

# x86_64-specific directories containing source files
#
SRCDIRS += arch/x86_64/prefix

# Include common x86 Makefile
#
MAKEDEPS += arch/x86/Makefile
include arch/x86/Makefile

# Include platform-specific Makefile
#
MAKEDEPS += arch/x86_64/Makefile.$(PLATFORM)
include arch/x86_64/Makefile.$(PLATFORM)
28 changes: 28 additions & 0 deletions src/arch/x86_64/Makefile.efi
@@ -0,0 +1,28 @@
# -*- makefile -*- : Force emacs to use Makefile mode

# EFI probably doesn't guarantee us a red zone, so let's not rely on it.
#
CFLAGS += -mno-red-zone

# The EFI linker script
#
LDSCRIPT = arch/x86_64/scripts/efi.lds

# Use a relocatable link; we perform final relocations in the efilink utility.
#
LDFLAGS += -r -d -S

# Media types.
#
NON_AUTO_MEDIA += efi

# Rule for building EFI files
#
$(BIN)/%.efi.tmp-reloc : $(BIN)/%.efi.tmp $(EFILINK)
$(QM)$(ECHO) " [EFILINK] $@"
$(Q)$(LD) -e 0 -o /dev/null $< # Check for unresolved symbols
$(Q)$(EFILINK) $< $@

$(BIN)/%.efi : $(BIN)/%.efi.tmp-reloc
$(QM)$(ECHO) " [FINISH] $@"
$(Q)$(OBJCOPY) -Obinary $< $@
22 changes: 22 additions & 0 deletions src/arch/x86_64/include/bits/byteswap.h
@@ -0,0 +1,22 @@
#ifndef _BITS_BYTESWAP_H
#define _BITS_BYTESWAP_H

static inline __attribute__ (( always_inline, const )) uint16_t
__bswap_variable_16 ( uint16_t x ) {
__asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
return x;
}

static inline __attribute__ (( always_inline, const )) uint32_t
__bswap_variable_32 ( uint32_t x ) {
__asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
return x;
}

static inline __attribute__ (( always_inline, const )) uint64_t
__bswap_variable_64 ( uint64_t x ) {
__asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
return x;
}

#endif /* _BITS_BYTESWAP_H */
14 changes: 14 additions & 0 deletions src/arch/x86_64/include/bits/compiler.h
@@ -0,0 +1,14 @@
#ifndef _BITS_COMPILER_H
#define _BITS_COMPILER_H

#ifndef ASSEMBLY

/** Declare a function with standard calling conventions */
#define __asmcall __attribute__ (( regparm(0) ))

/** Declare a function with libgcc implicit linkage */
#define __libgcc

#endif /* ASSEMBLY */

#endif /* _BITS_COMPILER_H */
6 changes: 6 additions & 0 deletions src/arch/x86_64/include/bits/endian.h
@@ -0,0 +1,6 @@
#ifndef ETHERBOOT_BITS_ENDIAN_H
#define ETHERBOOT_BITS_ENDIAN_H

#define __BYTE_ORDER __LITTLE_ENDIAN

#endif /* ETHERBOOT_BITS_ENDIAN_H */
11 changes: 11 additions & 0 deletions src/arch/x86_64/include/bits/errfile.h
@@ -0,0 +1,11 @@
#ifndef _BITS_ERRFILE_H
#define _BITS_ERRFILE_H

/**
* @addtogroup errfile Error file identifiers
* @{
*/

/** @} */

#endif /* _BITS_ERRFILE_H */
10 changes: 10 additions & 0 deletions src/arch/x86_64/include/bits/io.h
@@ -0,0 +1,10 @@
#ifndef _BITS_IO_H
#define _BITS_IO_H

/** @file
*
* x86_64-specific I/O API implementations
*
*/

#endif /* _BITS_IO_H */
12 changes: 12 additions & 0 deletions src/arch/x86_64/include/bits/nap.h
@@ -0,0 +1,12 @@
#ifndef _BITS_NAP_H
#define _BITS_NAP_H

/** @file
*
* x86_64-specific CPU sleeping API implementations
*
*/

#include <gpxe/efi/efix86_nap.h>

#endif /* _BITS_MAP_H */
10 changes: 10 additions & 0 deletions src/arch/x86_64/include/bits/smbios.h
@@ -0,0 +1,10 @@
#ifndef _BITS_SMBIOS_H
#define _BITS_SMBIOS_H

/** @file
*
* i386-specific SMBIOS API implementations
*
*/

#endif /* _BITS_SMBIOS_H */
21 changes: 21 additions & 0 deletions src/arch/x86_64/include/bits/stdint.h
@@ -0,0 +1,21 @@
#ifndef _BITS_STDINT_H
#define _BITS_STDINT_H

typedef unsigned long size_t;
typedef signed long ssize_t;
typedef signed long off_t;

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;

typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;

typedef unsigned long physaddr_t;
typedef unsigned long intptr_t;

#endif /* _BITS_STDINT_H */
10 changes: 10 additions & 0 deletions src/arch/x86_64/include/bits/timer.h
@@ -0,0 +1,10 @@
#ifndef _BITS_TIMER_H
#define _BITS_TIMER_H

/** @file
*
* x86_64-specific timer API implementations
*
*/

#endif /* _BITS_TIMER_H */
10 changes: 10 additions & 0 deletions src/arch/x86_64/include/bits/uaccess.h
@@ -0,0 +1,10 @@
#ifndef _BITS_UACCESS_H
#define _BITS_UACCESS_H

/** @file
*
* x86_64-specific user access API implementations
*
*/

#endif /* _BITS_UACCESS_H */
10 changes: 10 additions & 0 deletions src/arch/x86_64/include/bits/umalloc.h
@@ -0,0 +1,10 @@
#ifndef _BITS_UMALLOC_H
#define _BITS_UMALLOC_H

/** @file
*
* x86_64-specific user memory allocation API implementations
*
*/

#endif /* _BITS_UMALLOC_H */

0 comments on commit ce0a0cc

Please sign in to comment.