浏览代码

[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
tags/v0.9.7
Michael Brown 16 年前
父节点
当前提交
ce0a0ccf5c
共有 34 个文件被更改,包括 997 次插入51 次删除
  1. 5
    1
      src/arch/i386/Makefile
  2. 5
    40
      src/arch/i386/include/bits/byteswap.h
  3. 2
    2
      src/arch/i386/include/bits/stdint.h
  4. 8
    0
      src/arch/x86/Makefile
  5. 1
    0
      src/arch/x86/core/pcidirect.c
  6. 1
    3
      src/arch/x86/core/x86_string.c
  7. 0
    0
      src/arch/x86/include/bits/pci_io.h
  8. 1
    3
      src/arch/x86/include/bits/string.h
  9. 0
    0
      src/arch/x86/include/gpxe/efi/efix86_nap.h
  10. 0
    0
      src/arch/x86/include/gpxe/pcibios.h
  11. 0
    0
      src/arch/x86/include/gpxe/pcidirect.h
  12. 0
    0
      src/arch/x86/interface/efi/efix86_nap.c
  13. 41
    0
      src/arch/x86_64/Makefile
  14. 28
    0
      src/arch/x86_64/Makefile.efi
  15. 22
    0
      src/arch/x86_64/include/bits/byteswap.h
  16. 14
    0
      src/arch/x86_64/include/bits/compiler.h
  17. 6
    0
      src/arch/x86_64/include/bits/endian.h
  18. 11
    0
      src/arch/x86_64/include/bits/errfile.h
  19. 10
    0
      src/arch/x86_64/include/bits/io.h
  20. 12
    0
      src/arch/x86_64/include/bits/nap.h
  21. 10
    0
      src/arch/x86_64/include/bits/smbios.h
  22. 21
    0
      src/arch/x86_64/include/bits/stdint.h
  23. 10
    0
      src/arch/x86_64/include/bits/timer.h
  24. 10
    0
      src/arch/x86_64/include/bits/uaccess.h
  25. 10
    0
      src/arch/x86_64/include/bits/umalloc.h
  26. 51
    0
      src/arch/x86_64/include/gdbmach.h
  27. 59
    0
      src/arch/x86_64/include/limits.h
  28. 174
    0
      src/arch/x86_64/prefix/efiprefix.S
  29. 180
    0
      src/arch/x86_64/scripts/efi.lds
  30. 35
    0
      src/include/byteswap.h
  31. 9
    0
      src/include/compiler.h
  32. 4
    0
      src/include/gpxe/efi/ProcessorBind.h
  33. 247
    0
      src/include/gpxe/efi/X64/ProcessorBind.h
  34. 10
    2
      src/util/efilink.c

+ 5
- 1
src/arch/i386/Makefile 查看文件

@@ -68,7 +68,6 @@ SRCDIRS		+= arch/i386/drivers/net
68 68
 SRCDIRS		+= arch/i386/interface/pcbios
69 69
 SRCDIRS		+= arch/i386/interface/pxe
70 70
 SRCDIRS 	+= arch/i386/interface/syslinux
71
-SRCDIRS 	+= arch/i386/interface/efi
72 71
 
73 72
 # The various xxx_loader.c files are #included into core/loader.c and
74 73
 # should not be compiled directly.
@@ -82,6 +81,11 @@ NON_AUTO_SRCS	+= arch/i386/core/wince_loader.c
82 81
 OBJS_unnrv2b	= unnrv2b unnrv2b16
83 82
 CFLAGS_unnrv2b16 = -DCODE16
84 83
 
84
+# Include common x86 Makefile
85
+#
86
+MAKEDEPS	+= arch/x86/Makefile
87
+include arch/x86/Makefile
88
+
85 89
 # Include platform-specific Makefile
86 90
 #
87 91
 MAKEDEPS	+= arch/i386/Makefile.$(PLATFORM)

+ 5
- 40
src/arch/i386/include/bits/byteswap.h 查看文件

@@ -2,7 +2,7 @@
2 2
 #define ETHERBOOT_BITS_BYTESWAP_H
3 3
 
4 4
 static inline __attribute__ ((always_inline, const)) uint16_t
5
-__i386_bswap_16(uint16_t x)
5
+__bswap_variable_16(uint16_t x)
6 6
 {
7 7
 	__asm__("xchgb %b0,%h0\n\t"
8 8
 		: "=q" (x)
@@ -11,7 +11,7 @@ __i386_bswap_16(uint16_t x)
11 11
 }
12 12
 
13 13
 static inline __attribute__ ((always_inline, const)) uint32_t
14
-__i386_bswap_32(uint32_t x)
14
+__bswap_variable_32(uint32_t x)
15 15
 {
16 16
 	__asm__("xchgb %b0,%h0\n\t"
17 17
 		"rorl $16,%0\n\t"
@@ -22,7 +22,7 @@ __i386_bswap_32(uint32_t x)
22 22
 }
23 23
 
24 24
 static inline __attribute__ ((always_inline, const)) uint64_t
25
-__i386_bswap_64(uint64_t x)
25
+__bswap_variable_64(uint64_t x)
26 26
 {
27 27
 	union {
28 28
 		uint64_t qword;
@@ -30,47 +30,12 @@ __i386_bswap_64(uint64_t x)
30 30
 	} u;
31 31
 
32 32
 	u.qword = x;
33
-	u.dword[0] = __i386_bswap_32(u.dword[0]);
34
-	u.dword[1] = __i386_bswap_32(u.dword[1]);
33
+	u.dword[0] = __bswap_variable_32(u.dword[0]);
34
+	u.dword[1] = __bswap_variable_32(u.dword[1]);
35 35
 	__asm__("xchgl %0,%1"
36 36
 		: "=r" ( u.dword[0] ), "=r" ( u.dword[1] )
37 37
 		: "0" ( u.dword[0] ), "1" ( u.dword[1] ) );
38 38
 	return u.qword;
39 39
 }
40 40
 
41
-#define __bswap_constant_16(x) \
42
-	((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
43
-		    (((uint16_t)(x) & 0xff00) >> 8)))
44
-
45
-#define __bswap_constant_32(x) \
46
-	((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
47
-		    (((uint32_t)(x) & 0x0000ff00U) <<  8) | \
48
-		    (((uint32_t)(x) & 0x00ff0000U) >>  8) | \
49
-		    (((uint32_t)(x) & 0xff000000U) >> 24)))
50
-
51
-#define __bswap_constant_64(x) \
52
-	((uint64_t)((((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
53
-		    (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
54
-		    (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
55
-		    (((uint64_t)(x) & 0x00000000ff000000ULL) <<  8) | \
56
-		    (((uint64_t)(x) & 0x000000ff00000000ULL) >>  8) | \
57
-		    (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
58
-		    (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
59
-		    (((uint64_t)(x) & 0xff00000000000000ULL) >> 56)))
60
-
61
-#define __bswap_16(x) \
62
-	((uint16_t)(__builtin_constant_p(x) ? \
63
-	__bswap_constant_16(x) : \
64
-	__i386_bswap_16(x)))
65
-
66
-#define __bswap_32(x) \
67
-	((uint32_t)(__builtin_constant_p(x) ? \
68
-	__bswap_constant_32(x) : \
69
-	__i386_bswap_32(x)))
70
-
71
-#define __bswap_64(x) \
72
-	((uint64_t)(__builtin_constant_p(x) ? \
73
-	__bswap_constant_64(x) : \
74
-	__i386_bswap_64(x)))
75
-
76 41
 #endif /* ETHERBOOT_BITS_BYTESWAP_H */

+ 2
- 2
src/arch/i386/include/bits/stdint.h 查看文件

@@ -1,8 +1,8 @@
1 1
 #ifndef _BITS_STDINT_H
2 2
 #define _BITS_STDINT_H
3 3
 
4
-typedef typeof(sizeof(int))	size_t;
5
-typedef signed long		ssize_t;
4
+typedef unsigned int		size_t;
5
+typedef signed int		ssize_t;
6 6
 typedef signed long		off_t;
7 7
 
8 8
 typedef unsigned char		uint8_t;

+ 8
- 0
src/arch/x86/Makefile 查看文件

@@ -0,0 +1,8 @@
1
+# Include common x86 headers
2
+#
3
+CFLAGS		+= -Iarch/x86/include
4
+
5
+# x86-specific directories containing source files
6
+#
7
+SRCDIRS		+= arch/x86/core
8
+SRCDIRS 	+= arch/x86/interface/efi

src/arch/i386/core/pcidirect.c → src/arch/x86/core/pcidirect.c 查看文件

@@ -16,6 +16,7 @@
16 16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
+#include <gpxe/io.h>
19 20
 #include <gpxe/pci.h>
20 21
 
21 22
 /** @file

src/arch/i386/core/i386_string.c → src/arch/x86/core/x86_string.c 查看文件

@@ -32,9 +32,7 @@
32 32
  * @v len		Length
33 33
  * @ret dest		Destination address
34 34
  */
35
-__attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
36
-						    const void *src,
37
-						    size_t len ) {
35
+void * __memcpy ( void *dest, const void *src, size_t len ) {
38 36
 	void *edi = dest;
39 37
 	const void *esi = src;
40 38
 	int discard_ecx;

src/arch/i386/include/bits/pci_io.h → src/arch/x86/include/bits/pci_io.h 查看文件


src/arch/i386/include/bits/string.h → src/arch/x86/include/bits/string.h 查看文件

@@ -23,9 +23,7 @@
23 23
 
24 24
 #define __HAVE_ARCH_MEMCPY
25 25
 
26
-extern __attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
27
-							   const void *src,
28
-							   size_t len );
26
+extern void * __memcpy ( void *dest, const void *src, size_t len );
29 27
 
30 28
 #if 0
31 29
 static inline __attribute__ (( always_inline )) void *

src/arch/i386/include/gpxe/efi/efix86_nap.h → src/arch/x86/include/gpxe/efi/efix86_nap.h 查看文件


src/arch/i386/include/gpxe/pcibios.h → src/arch/x86/include/gpxe/pcibios.h 查看文件


src/arch/i386/include/gpxe/pcidirect.h → src/arch/x86/include/gpxe/pcidirect.h 查看文件


src/arch/i386/interface/efi/efix86_nap.c → src/arch/x86/interface/efi/efix86_nap.c 查看文件


+ 41
- 0
src/arch/x86_64/Makefile 查看文件

@@ -0,0 +1,41 @@
1
+# Code size reduction.
2
+#
3
+CFLAGS		+= -fstrength-reduce -fomit-frame-pointer
4
+
5
+# Code size reduction.  gcc3 needs a different syntax to gcc2 if you
6
+# want to avoid spurious warnings.
7
+#
8
+CFLAGS		+= -falign-jumps=1 -falign-loops=1 -falign-functions=1
9
+
10
+# Use %rip-relative addressing wherever possible.
11
+#
12
+CFLAGS		+= -fpie
13
+
14
+# Force 64-bit code
15
+#
16
+CFLAGS		+= -m64
17
+ASFLAGS		+= --64
18
+LDFLAGS		+= -m elf_x86_64
19
+
20
+# EFI requires -fshort-wchar, and nothing else currently uses wchar_t
21
+#
22
+CFLAGS		+= -fshort-wchar
23
+
24
+# We need to undefine the default macro "i386" when compiling .S
25
+# files, otherwise ".arch i386" translates to ".arch 1"...
26
+#
27
+CFLAGS			+= -Ui386
28
+
29
+# x86_64-specific directories containing source files
30
+#
31
+SRCDIRS		+= arch/x86_64/prefix
32
+
33
+# Include common x86 Makefile
34
+#
35
+MAKEDEPS	+= arch/x86/Makefile
36
+include arch/x86/Makefile
37
+
38
+# Include platform-specific Makefile
39
+#
40
+MAKEDEPS	+= arch/x86_64/Makefile.$(PLATFORM)
41
+include arch/x86_64/Makefile.$(PLATFORM)

+ 28
- 0
src/arch/x86_64/Makefile.efi 查看文件

@@ -0,0 +1,28 @@
1
+# -*- makefile -*- : Force emacs to use Makefile mode
2
+
3
+# EFI probably doesn't guarantee us a red zone, so let's not rely on it.
4
+#
5
+CFLAGS		+= -mno-red-zone
6
+
7
+# The EFI linker script
8
+#
9
+LDSCRIPT	= arch/x86_64/scripts/efi.lds
10
+
11
+# Use a relocatable link; we perform final relocations in the efilink utility.
12
+#
13
+LDFLAGS		+= -r -d -S
14
+
15
+# Media types.
16
+#
17
+NON_AUTO_MEDIA	+= efi
18
+
19
+# Rule for building EFI files
20
+#
21
+$(BIN)/%.efi.tmp-reloc : $(BIN)/%.efi.tmp $(EFILINK)
22
+	$(QM)$(ECHO) "  [EFILINK] $@"
23
+	$(Q)$(LD) -e 0 -o /dev/null $< # Check for unresolved symbols
24
+	$(Q)$(EFILINK) $< $@
25
+
26
+$(BIN)/%.efi : $(BIN)/%.efi.tmp-reloc
27
+	$(QM)$(ECHO) "  [FINISH] $@"
28
+	$(Q)$(OBJCOPY) -Obinary $< $@

+ 22
- 0
src/arch/x86_64/include/bits/byteswap.h 查看文件

@@ -0,0 +1,22 @@
1
+#ifndef _BITS_BYTESWAP_H
2
+#define _BITS_BYTESWAP_H
3
+
4
+static inline __attribute__ (( always_inline, const )) uint16_t
5
+__bswap_variable_16 ( uint16_t x ) {
6
+	__asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
7
+	return x;
8
+}
9
+
10
+static inline __attribute__ (( always_inline, const )) uint32_t
11
+__bswap_variable_32 ( uint32_t x ) {
12
+	__asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
13
+	return x;
14
+}
15
+
16
+static inline __attribute__ (( always_inline, const )) uint64_t
17
+__bswap_variable_64 ( uint64_t x ) {
18
+	__asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
19
+	return x;
20
+}
21
+
22
+#endif /* _BITS_BYTESWAP_H */

+ 14
- 0
src/arch/x86_64/include/bits/compiler.h 查看文件

@@ -0,0 +1,14 @@
1
+#ifndef _BITS_COMPILER_H
2
+#define _BITS_COMPILER_H
3
+
4
+#ifndef ASSEMBLY
5
+
6
+/** Declare a function with standard calling conventions */
7
+#define __asmcall __attribute__ (( regparm(0) ))
8
+
9
+/** Declare a function with libgcc implicit linkage */
10
+#define __libgcc
11
+
12
+#endif /* ASSEMBLY */
13
+
14
+#endif /* _BITS_COMPILER_H */

+ 6
- 0
src/arch/x86_64/include/bits/endian.h 查看文件

@@ -0,0 +1,6 @@
1
+#ifndef ETHERBOOT_BITS_ENDIAN_H
2
+#define ETHERBOOT_BITS_ENDIAN_H
3
+
4
+#define __BYTE_ORDER __LITTLE_ENDIAN
5
+
6
+#endif /* ETHERBOOT_BITS_ENDIAN_H */

+ 11
- 0
src/arch/x86_64/include/bits/errfile.h 查看文件

@@ -0,0 +1,11 @@
1
+#ifndef _BITS_ERRFILE_H
2
+#define _BITS_ERRFILE_H
3
+
4
+/**
5
+ * @addtogroup errfile Error file identifiers
6
+ * @{
7
+ */
8
+
9
+/** @} */
10
+
11
+#endif /* _BITS_ERRFILE_H */

+ 10
- 0
src/arch/x86_64/include/bits/io.h 查看文件

@@ -0,0 +1,10 @@
1
+#ifndef _BITS_IO_H
2
+#define _BITS_IO_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific I/O API implementations
7
+ *
8
+ */
9
+
10
+#endif /* _BITS_IO_H */

+ 12
- 0
src/arch/x86_64/include/bits/nap.h 查看文件

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_NAP_H
2
+#define _BITS_NAP_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific CPU sleeping API implementations
7
+ *
8
+ */
9
+
10
+#include <gpxe/efi/efix86_nap.h>
11
+
12
+#endif /* _BITS_MAP_H */

+ 10
- 0
src/arch/x86_64/include/bits/smbios.h 查看文件

@@ -0,0 +1,10 @@
1
+#ifndef _BITS_SMBIOS_H
2
+#define _BITS_SMBIOS_H
3
+
4
+/** @file
5
+ *
6
+ * i386-specific SMBIOS API implementations
7
+ *
8
+ */
9
+
10
+#endif /* _BITS_SMBIOS_H */

+ 21
- 0
src/arch/x86_64/include/bits/stdint.h 查看文件

@@ -0,0 +1,21 @@
1
+#ifndef _BITS_STDINT_H
2
+#define _BITS_STDINT_H
3
+
4
+typedef unsigned long		size_t;
5
+typedef signed long		ssize_t;
6
+typedef signed long		off_t;
7
+
8
+typedef unsigned char		uint8_t;
9
+typedef unsigned short		uint16_t;
10
+typedef unsigned int		uint32_t;
11
+typedef unsigned long long	uint64_t;
12
+
13
+typedef signed char		int8_t;
14
+typedef signed short		int16_t;
15
+typedef signed int		int32_t;
16
+typedef signed long long	int64_t;
17
+
18
+typedef unsigned long		physaddr_t;
19
+typedef unsigned long		intptr_t;
20
+
21
+#endif /* _BITS_STDINT_H */

+ 10
- 0
src/arch/x86_64/include/bits/timer.h 查看文件

@@ -0,0 +1,10 @@
1
+#ifndef _BITS_TIMER_H
2
+#define _BITS_TIMER_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific timer API implementations
7
+ *
8
+ */
9
+
10
+#endif /* _BITS_TIMER_H */

+ 10
- 0
src/arch/x86_64/include/bits/uaccess.h 查看文件

@@ -0,0 +1,10 @@
1
+#ifndef _BITS_UACCESS_H
2
+#define _BITS_UACCESS_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific user access API implementations
7
+ *
8
+ */
9
+
10
+#endif /* _BITS_UACCESS_H */

+ 10
- 0
src/arch/x86_64/include/bits/umalloc.h 查看文件

@@ -0,0 +1,10 @@
1
+#ifndef _BITS_UMALLOC_H
2
+#define _BITS_UMALLOC_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific user memory allocation API implementations
7
+ *
8
+ */
9
+
10
+#endif /* _BITS_UMALLOC_H */

+ 51
- 0
src/arch/x86_64/include/gdbmach.h 查看文件

@@ -0,0 +1,51 @@
1
+#ifndef GDBMACH_H
2
+#define GDBMACH_H
3
+
4
+/** @file
5
+ *
6
+ * GDB architecture specifics
7
+ *
8
+ * This file declares functions for manipulating the machine state and
9
+ * debugging context.
10
+ *
11
+ */
12
+
13
+#include <stdint.h>
14
+
15
+typedef unsigned long gdbreg_t;
16
+
17
+/* The register snapshot, this must be in sync with interrupt handler and the
18
+ * GDB protocol. */
19
+enum {
20
+	// STUB: don't expect this to work!
21
+	GDBMACH_EIP,
22
+	GDBMACH_EFLAGS,
23
+	GDBMACH_NREGS,
24
+	GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
25
+};
26
+
27
+/* Breakpoint types */
28
+enum {
29
+	GDBMACH_BPMEM,
30
+	GDBMACH_BPHW,
31
+	GDBMACH_WATCH,
32
+	GDBMACH_RWATCH,
33
+	GDBMACH_AWATCH,
34
+};
35
+
36
+static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
37
+	regs [ GDBMACH_EIP ] = pc;
38
+}
39
+
40
+static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
41
+	regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
42
+	regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
43
+}
44
+
45
+static inline void gdbmach_breakpoint ( void ) {
46
+	__asm__ __volatile__ ( "int $3\n" );
47
+}
48
+
49
+extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable );
50
+
51
+#endif /* GDBMACH_H */

+ 59
- 0
src/arch/x86_64/include/limits.h 查看文件

@@ -0,0 +1,59 @@
1
+#ifndef LIMITS_H
2
+#define LIMITS_H	1
3
+
4
+/* Number of bits in a `char' */
5
+#define CHAR_BIT	8
6
+
7
+/* Minimum and maximum values a `signed char' can hold */
8
+#define SCHAR_MIN	(-128)
9
+#define SCHAR_MAX	127
10
+
11
+/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
12
+#define UCHAR_MAX	255
13
+
14
+/* Minimum and maximum values a `char' can hold */
15
+#define CHAR_MIN	SCHAR_MIN
16
+#define CHAR_MAX	SCHAR_MAX
17
+
18
+/* Minimum and maximum values a `signed short int' can hold */
19
+#define SHRT_MIN	(-32768)
20
+#define SHRT_MAX	32767
21
+
22
+/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */
23
+#define USHRT_MAX	65535
24
+
25
+
26
+/* Minimum and maximum values a `signed int' can hold */
27
+#define INT_MIN		(-INT_MAX - 1)
28
+#define INT_MAX		2147483647
29
+
30
+/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
31
+#define UINT_MAX	4294967295U
32
+
33
+
34
+/* Minimum and maximum values a `signed int' can hold */
35
+#define INT_MAX		2147483647
36
+#define INT_MIN		(-INT_MAX - 1)
37
+
38
+
39
+/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
40
+#define UINT_MAX	4294967295U
41
+
42
+
43
+/* Minimum and maximum values a `signed long' can hold */
44
+#define LONG_MAX	9223372036854775807L
45
+#define LONG_MIN	(-LONG_MAX - 1L)
46
+
47
+/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */
48
+#define ULONG_MAX	18446744073709551615UL
49
+
50
+/* Minimum and maximum values a `signed long long' can hold */
51
+#define LLONG_MAX	9223372036854775807LL
52
+#define LLONG_MIN	(-LONG_MAX - 1LL)
53
+
54
+
55
+/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */
56
+#define ULLONG_MAX	18446744073709551615ULL
57
+
58
+
59
+#endif /* LIMITS_H */

+ 174
- 0
src/arch/x86_64/prefix/efiprefix.S 查看文件

@@ -0,0 +1,174 @@
1
+	.text
2
+	.code32
3
+	.arch i386
4
+	.section ".prefix", "a", @progbits
5
+	.org 0x00
6
+
7
+	/* DOS (.com) header
8
+	 *
9
+	 * EFI executables seem to leave most of this empty
10
+	 */
11
+mzhdr:
12
+	.ascii	"MZ"		/* Magic number */
13
+	.word	0		/* Bytes on last page of file */
14
+	.word	0		/* Pages in file */
15
+	.word	0		/* Relocations */
16
+	.word	0		/* Size of header in paragraphs */
17
+	.word	0		/* Minimum extra paragraphs needed */
18
+	.word	0		/* Maximum extra paragraphs needed */
19
+	.word	0		/* Initial (relative) SS value */
20
+	.word	0		/* Initial SP value */
21
+	.word	0		/* "Checksum" */
22
+	.word	0		/* Initial IP value */
23
+	.word	0		/* Initial (relative) CS value */
24
+	.word	0		/* File address of relocation table */
25
+	.word	0		/* Ovesrlay number */
26
+	.word	0, 0, 0, 0	/* Reserved words */
27
+	.word	0		/* OEM identifier (for e_oeminfo) */
28
+	.word	0		/* OEM information; e_oemid specific */
29
+	.word	0, 0, 0, 0, 0	/* Reserved words */
30
+	.word	0, 0, 0, 0, 0	/* Reserved words */
31
+	.long	pehdr_lma	/* File address of new exe header */
32
+	.size	mzhdr, . - mzhdr
33
+
34
+	/* PE header */
35
+	.org	0xc0 /* For compatibility with MS toolchain */
36
+pehdr:
37
+	.ascii	"PE\0\0"	/* Magic number */
38
+	.word	0x8664		/* CPU architecture: x86_64 */
39
+	.word	num_pe_sections	/* Number of sections */
40
+	.long	0x10d1a884	/* Timestamp */
41
+	.long	0		/* Symbol table */
42
+	.long	0		/* Number of symbols */
43
+	.word	opthdr_size	/* Size of optional header */
44
+	.word	0x2002		/* Characteristics */
45
+	.size	pehdr, . - pehdr
46
+	.equ	pehdr_lma, pehdr - mzhdr
47
+
48
+	/* "Optional" header */
49
+opthdr:
50
+	.word	0x020b		/* Magic number */
51
+	.byte	0		/* Linker major version number */
52
+	.byte	0		/* Linker minor version number */
53
+	.long	_text_filesz	/* Size of text section */
54
+	.long	_data_filesz	/* Size of data section */
55
+	.long	_bss_filesz	/* Size of bss section */
56
+	.long	efi_entry_lma	/* Entry point */
57
+	.long	_text_lma	/* Text section start RVA */
58
+	.quad	0		/* Image base address */
59
+	.long	_max_align	/* Section alignment */
60
+	.long	_max_align	/* File alignment */
61
+	.word	0		/* Operating system major version number */
62
+	.word	0		/* Operating system minor version number */
63
+	.word	0		/* Image major version number */
64
+	.word	0		/* Image minor version number */
65
+	.word	0		/* Subsystem major version number */
66
+	.word	0		/* Subsystem minor version number */
67
+	.long	0		/* Reserved */
68
+	.long	_filesz		/* Total image size */
69
+	.long	_prefix_filesz	/* Total header size */
70
+	.long	0		/* "Checksum" */
71
+	.word	0x0a		/* Subsystem: EFI */
72
+	.word	0		/* DLL characteristics */
73
+	.quad	0		/* Size of stack reserve */
74
+	.quad	0		/* Size of stack commit */
75
+	.quad	0		/* Size of heap reserve */
76
+	.quad	0		/* Size of heap commit */
77
+	.long	0		/* Loader flags */
78
+	.long	16		/* Number of data directory entries */
79
+	.long	0, 0		/* Export directory */
80
+	.long	0, 0		/* Import directory */
81
+	.long	0, 0		/* Resource directory */
82
+	.long	0, 0		/* Exception directory */
83
+	.long	0, 0		/* Security directory */
84
+	.long	_reloc_lma, _reloc_filesz /* Base relocation directory */
85
+	.long	debugdir_lma, debugdir_size /* Debug directory */
86
+	.long	0, 0		/* Description directory */
87
+	.long	0, 0		/* Special directory */
88
+	.long	0, 0		/* Thread storage directory */
89
+	.long	0, 0		/* Load configuration directory */
90
+	.long	0, 0		/* Bound import directory */
91
+	.long	0, 0		/* Import address table directory */
92
+	.long	0, 0		/* Delay import directory */
93
+	.long	0, 0		/* Reserved */
94
+	.long	0, 0		/* Reserved */
95
+	.size	opthdr, . - opthdr
96
+	.equ	opthdr_size, . - opthdr
97
+
98
+	/* PE sections */
99
+pe_sections:
100
+text_section:
101
+	.asciz	".text"		/* Section name */
102
+	.align	8
103
+	.long	_text_filesz	/* Section size */
104
+	.long	_text_lma	/* Relative Virtual Address */
105
+	.long	_text_filesz	/* Section size (rounded up) */
106
+	.long	_text_lma	/* Pointer to raw data */
107
+	.long	0		/* Link-time relocations */
108
+	.long	0		/* Line numbers */
109
+	.word	0		/* Number of link-time relocations */
110
+	.word	0		/* Number of line numbers */
111
+	.long	0x68000020	/* Characteristics */
112
+rodata_section:
113
+	.asciz	".rodata"	/* Section name */
114
+	.align	8
115
+	.long	_rodata_filesz	/* Section size */
116
+	.long	_rodata_lma	/* Relative Virtual Address */
117
+	.long	_rodata_filesz	/* Section size (rounded up) */
118
+	.long	_rodata_lma	/* Pointer to raw data */
119
+	.long	0		/* Link-time relocations */
120
+	.long	0		/* Line numbers */
121
+	.word	0		/* Number of link-time relocations */
122
+	.word	0		/* Number of line numbers */
123
+	.long	0x48000040	/* Characteristics */
124
+data_section:
125
+	.asciz	".data"		/* Section name */
126
+	.align	8
127
+	.long	_data_filesz	/* Section size */
128
+	.long	_data_lma	/* Relative Virtual Address */
129
+	.long	_data_filesz	/* Section size (rounded up) */
130
+	.long	_data_lma	/* Pointer to raw data */
131
+	.long	0		/* Link-time relocations */
132
+	.long	0		/* Line numbers */
133
+	.word	0		/* Number of link-time relocations */
134
+	.word	0		/* Number of line numbers */
135
+	.long	0xc8000040	/* Characteristics */
136
+reloc_section:
137
+	.asciz	".reloc"	/* Section name */
138
+	.align	8
139
+	.long	_reloc_filesz	/* Section size */
140
+	.long	_reloc_lma	/* Relative Virtual Address */
141
+	.long	_reloc_filesz	/* Section size (rounded up) */
142
+	.long	_reloc_lma	/* Pointer to raw data */
143
+	.long	0		/* Link-time relocations */
144
+	.long	0		/* Line numbers */
145
+	.word	0		/* Number of link-time relocations */
146
+	.word	0		/* Number of line numbers */
147
+	.long	0x42000040	/* Characteristics */
148
+
149
+pe_sections_end:
150
+	.size	pe_sections, . - pe_sections
151
+	.equ	num_pe_sections, ( ( . - pe_sections ) / 0x28 )
152
+
153
+	/* Debug directory */
154
+	.section ".rodata"
155
+	.globl	debugdir
156
+debugdir:
157
+	.long	0		/* Characteristics */
158
+	.long	0x10d1a884	/* Timestamp */
159
+	.word	0		/* Major version */
160
+	.word	0		/* Minor version */
161
+	.long	0x02		/* RSDS? */
162
+	.long	codeview_rsds_size /* Size of data */
163
+	.long	codeview_rsds_lma /* RVA */
164
+	.long	codeview_rsds_lma /* File offset */
165
+	.size	debugdir, . - debugdir
166
+	.equ	debugdir_size, . - debugdir
167
+	/* Codeview structure */
168
+	.globl	codeview_rsds
169
+codeview_rsds:
170
+	.ascii	"RSDS"		/* Magic number */
171
+	.long	0, 0, 0, 0, 0	/* Unused by EFI */
172
+	.asciz	"efiprefix.pdb"
173
+	.size	codeview_rsds, . - codeview_rsds
174
+	.equ	codeview_rsds_size, . - codeview_rsds

+ 180
- 0
src/arch/x86_64/scripts/efi.lds 查看文件

@@ -0,0 +1,180 @@
1
+/* -*- sh -*- */
2
+
3
+/*
4
+ * Linker script for EFI images
5
+ *
6
+ */
7
+
8
+EXTERN ( efi_entry )
9
+
10
+SECTIONS {
11
+
12
+    /* The file starts at a virtual address of zero, and sections are
13
+     * contiguous.  Each section is aligned to at least _max_align,
14
+     * which defaults to 32.  Load addresses are equal to virtual
15
+     * addresses.
16
+     */
17
+
18
+    . = 0;
19
+    _max_align = 32;
20
+
21
+    /*
22
+     * The prefix
23
+     *
24
+     */
25
+
26
+    .prefix : {
27
+	_prefix = .;
28
+	*(.prefix)
29
+	*(.prefix.*)
30
+	_mprefix = .;
31
+    } .bss.prefix (NOLOAD) : {
32
+	_eprefix = .;
33
+    }
34
+    _prefix_filesz	= ABSOLUTE ( _mprefix - _prefix );
35
+    _prefix_memsz	= ABSOLUTE ( _eprefix - _prefix );
36
+
37
+    /*
38
+     * The text section
39
+     *
40
+     */
41
+
42
+    . = ALIGN ( _max_align );
43
+    .text : {
44
+	_text = .;
45
+	*(.text)
46
+	*(.text.*)
47
+	_mtext = .;
48
+    } .bss.text (NOLOAD) : {
49
+	_etext = .;
50
+    }
51
+    _text_filesz	= ABSOLUTE ( _mtext - _text );
52
+    _text_memsz		= ABSOLUTE ( _etext - _text );
53
+
54
+    /*
55
+     * The rodata section
56
+     *
57
+     */
58
+
59
+    . = ALIGN ( _max_align );
60
+    .rodata : {
61
+	_rodata = .;
62
+	*(.rodata)
63
+	*(.rodata.*)
64
+	_mrodata = .;
65
+    } .bss.rodata (NOLOAD) : {
66
+	_erodata = .;
67
+    }
68
+    _rodata_filesz	= ABSOLUTE ( _mrodata - _rodata );
69
+    _rodata_memsz	= ABSOLUTE ( _erodata - _rodata );
70
+
71
+    /*
72
+     * The data section
73
+     *
74
+     */
75
+
76
+    . = ALIGN ( _max_align );
77
+    .data : {
78
+	_data = .;
79
+	*(.data)
80
+	*(.data.*)
81
+	*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
82
+	/* EFI seems to not support proper bss sections */
83
+	*(.bss)
84
+	*(.bss.*)
85
+	*(COMMON)
86
+	*(.stack)
87
+	*(.stack.*)
88
+	_mdata = .;
89
+    } .bss.data (NOLOAD) : {
90
+	_edata = .;
91
+    }
92
+    _data_filesz	= ABSOLUTE ( _mdata - _data );
93
+    _data_memsz		= ABSOLUTE ( _edata - _data );
94
+
95
+    /*
96
+     * The bss section
97
+     *
98
+     */
99
+
100
+    . = ALIGN ( _max_align );
101
+    .bss : {
102
+	_bss = .;
103
+	/* EFI seems to not support proper bss sections */
104
+	_mbss = .;
105
+    } .bss.bss (NOLOAD) : {
106
+	_ebss = .;
107
+    }
108
+    _bss_filesz		= ABSOLUTE ( _mbss - _bss );
109
+    _bss_memsz		= ABSOLUTE ( _ebss - _bss );
110
+
111
+    /*
112
+     * The reloc section
113
+     *
114
+     */
115
+
116
+    . = ALIGN ( _max_align );
117
+    .reloc : {
118
+	_reloc = .;
119
+	/* Provide some dummy contents to force ld to include this
120
+	 * section.  It will be created by the efilink utility.
121
+	 */
122
+	BYTE(0);
123
+	_mreloc = .;
124
+    } .bss.reloc (NOLOAD) : {
125
+	_ereloc = .;
126
+    }
127
+    _reloc_filesz	= ABSOLUTE ( _mreloc - _reloc );
128
+    _reloc_memsz	= ABSOLUTE ( _ereloc - _reloc );
129
+
130
+    _filesz		= ABSOLUTE ( . );
131
+
132
+    /*
133
+     * Weak symbols that need zero values if not otherwise defined
134
+     *
135
+     */
136
+
137
+    .weak 0x0 : {
138
+	_weak = .;
139
+	*(.weak)
140
+	_eweak = .;
141
+    }
142
+    _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
143
+
144
+    /*
145
+     * Dispose of the comment and note sections to make the link map
146
+     * easier to read
147
+     *
148
+     */
149
+
150
+    /DISCARD/ : {
151
+	*(.comment)
152
+	*(.comment.*)
153
+	*(.note)
154
+	*(.note.*)
155
+	*(.eh_frame)
156
+	*(.eh_frame.*)
157
+	*(.rel)
158
+	*(.rel.*)
159
+    }
160
+
161
+    /*
162
+     * Load address calculations.
163
+     *
164
+     */
165
+
166
+    _prefix_lma		= ABSOLUTE ( _prefix );
167
+    _text_lma		= ABSOLUTE ( _text );
168
+    _rodata_lma		= ABSOLUTE ( _rodata );
169
+    _data_lma		= ABSOLUTE ( _data );
170
+    _bss_lma		= ABSOLUTE ( _bss );
171
+    _reloc_lma		= ABSOLUTE ( _reloc );
172
+
173
+    /*
174
+     * Load addresses required by the prefix
175
+     *
176
+     */
177
+    efi_entry_lma	= ABSOLUTE ( efi_entry );
178
+    debugdir_lma	= ABSOLUTE ( debugdir );
179
+    codeview_rsds_lma	= ABSOLUTE ( codeview_rsds );
180
+}

+ 35
- 0
src/include/byteswap.h 查看文件

@@ -4,6 +4,41 @@
4 4
 #include "endian.h"
5 5
 #include "bits/byteswap.h"
6 6
 
7
+#define __bswap_constant_16(x) \
8
+	((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
9
+		    (((uint16_t)(x) & 0xff00) >> 8)))
10
+
11
+#define __bswap_constant_32(x) \
12
+	((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
13
+		    (((uint32_t)(x) & 0x0000ff00U) <<  8) | \
14
+		    (((uint32_t)(x) & 0x00ff0000U) >>  8) | \
15
+		    (((uint32_t)(x) & 0xff000000U) >> 24)))
16
+
17
+#define __bswap_constant_64(x) \
18
+	((uint64_t)((((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
19
+		    (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
20
+		    (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
21
+		    (((uint64_t)(x) & 0x00000000ff000000ULL) <<  8) | \
22
+		    (((uint64_t)(x) & 0x000000ff00000000ULL) >>  8) | \
23
+		    (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
24
+		    (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
25
+		    (((uint64_t)(x) & 0xff00000000000000ULL) >> 56)))
26
+
27
+#define __bswap_16(x) \
28
+	((uint16_t)(__builtin_constant_p(x) ? \
29
+	__bswap_constant_16(x) : \
30
+	__bswap_variable_16(x)))
31
+
32
+#define __bswap_32(x) \
33
+	((uint32_t)(__builtin_constant_p(x) ? \
34
+	__bswap_constant_32(x) : \
35
+	__bswap_variable_32(x)))
36
+
37
+#define __bswap_64(x) \
38
+	((uint64_t)(__builtin_constant_p(x) ? \
39
+	__bswap_constant_64(x) : \
40
+	__bswap_variable_64(x)))
41
+
7 42
 #if __BYTE_ORDER == __LITTLE_ENDIAN
8 43
 #include "little_bswap.h"
9 44
 #endif

+ 9
- 0
src/include/compiler.h 查看文件

@@ -59,6 +59,15 @@ __asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );
59 59
 #define REQUIRE_OBJECT(object) \
60 60
 	__asm__ ( ".equ\tneed_" #object ", obj_" #object );
61 61
 
62
+/* Force visibility of all symbols to "hidden", i.e. inform gcc that
63
+ * all symbol references resolve strictly within our final binary.
64
+ * This avoids unnecessary PLT/GOT entries on x86_64.
65
+ *
66
+ * This is a stronger claim than specifying "-fvisibility=hidden",
67
+ * since it also affects symbols marked with "extern".
68
+ */
69
+#pragma GCC visibility push(hidden)
70
+
62 71
 /** @def DBG
63 72
  *
64 73
  * Print a debugging message.

+ 4
- 0
src/include/gpxe/efi/ProcessorBind.h 查看文件

@@ -8,3 +8,7 @@
8 8
 #if __i386__
9 9
 #include <gpxe/efi/Ia32/ProcessorBind.h>
10 10
 #endif
11
+
12
+#if __x86_64__
13
+#include <gpxe/efi/X64/ProcessorBind.h>
14
+#endif

+ 247
- 0
src/include/gpxe/efi/X64/ProcessorBind.h 查看文件

@@ -0,0 +1,247 @@
1
+/** @file
2
+  Processor or Compiler specific defines and types x64 (Intel(r) EM64T, AMD64).
3
+
4
+  Copyright (c) 2006, Intel Corporation
5
+  All rights reserved. This program and the accompanying materials
6
+  are licensed and made available under the terms and conditions of the BSD License
7
+  which accompanies this distribution.  The full text of the license may be found at
8
+  http://opensource.org/licenses/bsd-license.php
9
+
10
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
+
13
+**/
14
+
15
+#ifndef __PROCESSOR_BIND_H__
16
+#define __PROCESSOR_BIND_H__
17
+
18
+///
19
+/// Define the processor type so other code can make processor based choices
20
+///
21
+#define MDE_CPU_X64
22
+
23
+
24
+//
25
+// Make sure we are useing the correct packing rules per EFI specification
26
+//
27
+#ifndef __GNUC__
28
+#pragma pack()
29
+#endif
30
+
31
+
32
+#if __INTEL_COMPILER
33
+//
34
+// Disable ICC's remark #869: "Parameter" was never referenced warning.
35
+// This is legal ANSI C code so we disable the remark that is turned on with -Wall
36
+//
37
+#pragma warning ( disable : 869 )
38
+
39
+//
40
+// Disable ICC's remark #1418: external function definition with no prior declaration.
41
+// This is legal ANSI C code so we disable the remark that is turned on with /W4
42
+//
43
+#pragma warning ( disable : 1418 )
44
+
45
+//
46
+// Disable ICC's remark #1419: external declaration in primary source file
47
+// This is legal ANSI C code so we disable the remark that is turned on with /W4
48
+//
49
+#pragma warning ( disable : 1419 )
50
+
51
+#endif
52
+
53
+
54
+#if _MSC_EXTENSIONS
55
+
56
+//
57
+// Disable warning that make it impossible to compile at /W4
58
+// This only works for Microsoft* tools
59
+//
60
+
61
+//
62
+// Disabling bitfield type checking warnings.
63
+//
64
+#pragma warning ( disable : 4214 )
65
+
66
+//
67
+// Disabling the unreferenced formal parameter warnings.
68
+//
69
+#pragma warning ( disable : 4100 )
70
+
71
+//
72
+// Disable slightly different base types warning as CHAR8 * can not be set
73
+// to a constant string.
74
+//
75
+#pragma warning ( disable : 4057 )
76
+
77
+//
78
+// ASSERT(FALSE) or while (TRUE) are legal constructes so supress this warning
79
+//
80
+#pragma warning ( disable : 4127 )
81
+
82
+//
83
+// This warning is caused by functions defined but not used. For precompiled header only.
84
+//
85
+#pragma warning ( disable : 4505 )
86
+
87
+//
88
+// This warning is caused by empty (after preprocessing) souce file. For precompiled header only.
89
+//
90
+#pragma warning ( disable : 4206 )
91
+
92
+#endif
93
+
94
+
95
+#if !defined(__GNUC__) && (__STDC_VERSION__ < 199901L)
96
+  //
97
+  // No ANSI C 2000 stdint.h integer width declarations, so define equivalents
98
+  //
99
+
100
+  #if _MSC_EXTENSIONS
101
+
102
+
103
+    //
104
+    // use Microsoft C complier dependent interger width types
105
+    //
106
+    typedef unsigned __int64    UINT64;
107
+    typedef __int64             INT64;
108
+    typedef unsigned __int32    UINT32;
109
+    typedef __int32             INT32;
110
+    typedef unsigned short      UINT16;
111
+    typedef unsigned short      CHAR16;
112
+    typedef short               INT16;
113
+    typedef unsigned char       BOOLEAN;
114
+    typedef unsigned char       UINT8;
115
+    typedef char                CHAR8;
116
+    typedef char                INT8;
117
+  #else
118
+    #ifdef _EFI_P64
119
+      //
120
+      // P64 - is Intel Itanium(TM) speak for pointers being 64-bit and longs and ints
121
+      //  are 32-bits
122
+      //
123
+      typedef unsigned long long  UINT64;
124
+      typedef long long           INT64;
125
+      typedef unsigned int        UINT32;
126
+      typedef int                 INT32;
127
+      typedef unsigned short      CHAR16;
128
+      typedef unsigned short      UINT16;
129
+      typedef short               INT16;
130
+      typedef unsigned char       BOOLEAN;
131
+      typedef unsigned char       UINT8;
132
+      typedef char                CHAR8;
133
+      typedef char                INT8;
134
+    #else
135
+      //
136
+      // Assume LP64 - longs and pointers are 64-bit. Ints are 32-bit.
137
+      //
138
+      typedef unsigned long   UINT64;
139
+      typedef long            INT64;
140
+      typedef unsigned int    UINT32;
141
+      typedef int             INT32;
142
+      typedef unsigned short  UINT16;
143
+      typedef unsigned short  CHAR16;
144
+      typedef short           INT16;
145
+      typedef unsigned char   BOOLEAN;
146
+      typedef unsigned char   UINT8;
147
+      typedef char            CHAR8;
148
+      typedef char            INT8;
149
+    #endif
150
+  #endif
151
+
152
+  #define UINT8_MAX 0xff
153
+
154
+#else
155
+  //
156
+  // Use ANSI C 2000 stdint.h integer width declarations
157
+  //
158
+  #include <stdint.h>
159
+  typedef uint8_t   BOOLEAN;
160
+  typedef int8_t    INT8;
161
+  typedef uint8_t   UINT8;
162
+  typedef int16_t   INT16;
163
+  typedef uint16_t  UINT16;
164
+  typedef int32_t   INT32;
165
+  typedef uint32_t  UINT32;
166
+  typedef int64_t   INT64;
167
+  typedef uint64_t  UINT64;
168
+  typedef char      CHAR8;
169
+  typedef uint16_t  CHAR16;
170
+
171
+#endif
172
+
173
+typedef UINT64  UINTN;
174
+typedef INT64   INTN;
175
+
176
+
177
+//
178
+// Processor specific defines
179
+//
180
+#define MAX_BIT     0x8000000000000000ULL
181
+#define MAX_2_BITS  0xC000000000000000ULL
182
+
183
+//
184
+// Maximum legal X64 address
185
+//
186
+#define MAX_ADDRESS   0xFFFFFFFFFFFFFFFFULL
187
+
188
+//
189
+// The stack alignment required for X64
190
+//
191
+#define CPU_STACK_ALIGNMENT   16
192
+
193
+//
194
+// Modifier to ensure that all protocol member functions and EFI intrinsics
195
+// use the correct C calling convention. All protocol member functions and
196
+// EFI intrinsics are required to modify thier member functions with EFIAPI.
197
+//
198
+#if _MSC_EXTENSIONS
199
+  ///
200
+  /// Define the standard calling convention reguardless of optimization level.
201
+  /// __cdecl is Microsoft* specific C extension.
202
+  ///
203
+  #define EFIAPI __cdecl
204
+#elif __GNUC__
205
+  ///
206
+  /// Define the standard calling convention reguardless of optimization level.
207
+  /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI
208
+  /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64)
209
+  /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for
210
+  /// x64. Warning the assembly code in the MDE x64 does not follow the correct
211
+  /// ABI for the standard x64 (x86-64) GCC.
212
+  ///
213
+  #define EFIAPI __attribute__((ms_abi))
214
+#else
215
+  ///
216
+  /// The default for a non Microsoft* or GCC compiler is to assume the EFI ABI
217
+  /// is the standard.
218
+  ///
219
+  #define EFIAPI
220
+#endif
221
+
222
+//
223
+// The Microsoft* C compiler can removed references to unreferenced data items
224
+//  if the /OPT:REF linker option is used. We defined a macro as this is a
225
+//  a non standard extension
226
+//
227
+#if _MSC_EXTENSIONS
228
+  #define GLOBAL_REMOVE_IF_UNREFERENCED __declspec(selectany)
229
+#else
230
+  #define GLOBAL_REMOVE_IF_UNREFERENCED
231
+#endif
232
+
233
+//
234
+// For symbol name in GNU assembly code, an extra "_" is necessary
235
+//
236
+#if __GNUC__
237
+  #if defined(linux)
238
+    #define ASM_PFX(name) name
239
+  #else
240
+    #define ASM_PFX(name) _##name
241
+  #endif
242
+#endif
243
+
244
+#define FUNCTION_ENTRY_POINT(p) (p)
245
+
246
+#endif
247
+

+ 10
- 2
src/util/efilink.c 查看文件

@@ -56,6 +56,9 @@ static void generate_pe_reloc ( struct pe_relocs **pe_reltab,
56 56
 	start_rva = ( rva & ~0xfff );
57 57
 	reloc = ( rva & 0xfff );
58 58
 	switch ( size ) {
59
+	case 8:
60
+		reloc |= 0xa000;
61
+		break;
59 62
 	case 4:
60 63
 		reloc |= 0x3000;
61 64
 		break;
@@ -385,13 +388,18 @@ static void process_reloc ( asection *section, arelent *rel,
385 388
 		/* Skip absolute symbols; the symbol value won't
386 389
 		 * change when the object is loaded.
387 390
 		 */
388
-	} else if ( strcmp ( howto->name, "R_386_32" ) == 0 ) {
391
+	} else if ( strcmp ( howto->name, "R_X86_64_64" ) == 0 ) {
392
+		/* Generate an 8-byte PE relocation */
393
+		generate_pe_reloc ( pe_reltab, offset, 8 );
394
+	} else if ( ( strcmp ( howto->name, "R_386_32" ) == 0 ) ||
395
+		    ( strcmp ( howto->name, "R_X86_64_32" ) == 0 ) ) {
389 396
 		/* Generate a 4-byte PE relocation */
390 397
 		generate_pe_reloc ( pe_reltab, offset, 4 );
391 398
 	} else if ( strcmp ( howto->name, "R_386_16" ) == 0 ) {
392 399
 		/* Generate a 2-byte PE relocation */
393 400
 		generate_pe_reloc ( pe_reltab, offset, 2 );
394
-	} else if ( strcmp ( howto->name, "R_386_PC32" ) == 0 ) {
401
+	} else if ( ( strcmp ( howto->name, "R_386_PC32" ) == 0 ) ||
402
+		    ( strcmp ( howto->name, "R_X86_64_PC32" ) == 0 ) ) {
395 403
 		/* Skip PC-relative relocations; all relative offsets
396 404
 		 * remain unaltered when the object is loaded.
397 405
 		 */

正在加载...
取消
保存