Skip to content

Commit

Permalink
[build] Enable building with the Intel C compiler (icc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brown committed Mar 26, 2009
1 parent 16aa435 commit 1c67623
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/Makefile
Expand Up @@ -22,7 +22,7 @@ ECHO := echo
PRINTF := printf
PERL := /usr/bin/perl
CC := $(CROSS_COMPILE)gcc
CPP := $(CROSS_COMPILE)gcc -E -Wp,-Wall
CPP := $(CC) -E
AS := $(CROSS_COMPILE)as
LD := $(CROSS_COMPILE)ld
SIZE := $(CROSS_COMPILE)size
Expand All @@ -40,6 +40,7 @@ ZBIN := ./util/zbin
ELF2EFI32 := ./util/elf2efi32
ELF2EFI64 := ./util/elf2efi64
EFIROM := ./util/efirom
ICCFIX := ./util/iccfix
DOXYGEN := doxygen

###############################################################################
Expand Down
84 changes: 76 additions & 8 deletions src/Makefile.housekeeping
Expand Up @@ -60,6 +60,22 @@ HOST_OS := $(shell uname -s)
hostos :
@$(ECHO) $(HOST_OS)

###############################################################################
#
# Determine compiler

CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
ccdefs:
@$(ECHO) $(CCDEFS)

ifeq ($(filter __ICC,$(CCDEFS)),__ICC)
CCTYPE := icc
else
CCTYPE := gcc
endif
cctype:
@$(ECHO) $(CCTYPE)

###############################################################################
#
# Check for tools that can cause failed builds
Expand Down Expand Up @@ -103,10 +119,12 @@ oldgas :
# default, even when -ffreestanding is specified. We therefore need
# to disable -fstack-protector if the compiler supports it.
#
ifeq ($(CCTYPE),gcc)
SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
-o /dev/null >/dev/null 2>&1
SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
CFLAGS += $(SP_FLAGS)
endif

###############################################################################
#
Expand Down Expand Up @@ -279,9 +297,38 @@ ifdef BIN
# Common flags
#
CFLAGS += -I include -I arch/$(ARCH)/include -I .
CFLAGS += -Os -ffreestanding
CFLAGS += -Wall -W -Wformat-nonliteral
CFLAGS += -Os
CFLAGS += -g
ifeq ($(CCTYPE),gcc)
CFLAGS += -ffreestanding
CFLAGS += -Wall -W -Wformat-nonliteral
endif
ifeq ($(CCTYPE),icc)
CFLAGS += -fno-builtin
CFLAGS += -no-ip
CFLAGS += -no-gcc
CFLAGS += -diag-disable 111 # Unreachable code
CFLAGS += -diag-disable 128 # Unreachable loop
CFLAGS += -diag-disable 170 # Array boundary checks
CFLAGS += -diag-disable 177 # Unused functions
CFLAGS += -diag-disable 181 # printf() format checks
CFLAGS += -diag-disable 188 # enum strictness
CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
CFLAGS += -diag-disable 280 # switch ( constant )
CFLAGS += -diag-disable 310 # K&R parameter lists
CFLAGS += -diag-disable 424 # Extra semicolon
CFLAGS += -diag-disable 589 # Declarations mid-code
CFLAGS += -diag-disable 593 # Unused variables
CFLAGS += -diag-disable 810 # Casting ints to smaller ints
CFLAGS += -diag-disable 981 # Sequence point violations
CFLAGS += -diag-disable 1292 # Ignored attributes
CFLAGS += -diag-disable 1338 # void pointer arithmetic
CFLAGS += -diag-disable 1361 # Variable-length arrays
CFLAGS += -diag-disable 1418 # Missing prototypes
CFLAGS += -diag-disable 1419 # Missing prototypes
CFLAGS += -diag-disable 1599 # Hidden variables
CFLAGS += -Wall -Wmissing-declarations
endif
CFLAGS += $(EXTRA_CFLAGS)
ASFLAGS += $(EXTRA_ASFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
Expand Down Expand Up @@ -314,11 +361,21 @@ OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
$(BIN)/%.flags :
@$(ECHO) $(OBJ_CFLAGS)

# ICC requires postprocessing objects to fix up table alignments
#
ifeq ($(CCTYPE),icc)
POST_O = && $(ICCFIX) $@
POST_O_DEPS := $(ICCFIX)
else
POST_O :=
POST_O_DEPS :=
endif

# Rules for specific object types.
#
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@ $(POST_O)
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@

Expand Down Expand Up @@ -364,15 +421,17 @@ endef
define obj_template

@$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
-Wno-error -MM $(1) -MT "$(4)_DEPS" -MG -MP | \
sed 's/_DEPS\s*:/_DEPS =/' >> $(2)
@$(ECHO_E) '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
-Wno-error -MM $(1) -MG -MP | \
sed 's/\.o\s*:/_DEPS =/' >> $(2)
@$(ECHO_E) '\n$$(BIN)/$(4).o :' \
'$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(4)_DEPS)' \
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
'\n\t$$(RULE_$(3))\n' \
'\nBOBJS += $$(BIN)/$(4).o\n' \
$(foreach TGT,$(DEBUG_TARGETS), \
$(if $(RULE_$(3)_to_$(TGT)), \
'\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
'\n$$(BIN)/$(4).$(TGT) :' \
'$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(4)_DEPS)' \
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
'\n\t$$(RULE_$(3)_to_$(TGT))\n' \
'\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
Expand Down Expand Up @@ -743,6 +802,15 @@ $(EFIROM) : util/efirom.c $(MAKEDEPS)
$(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
CLEANUP += $(EFIROM)

###############################################################################
#
# The ICC fixup utility
#
$(ICCFIX) : util/iccfix.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
CLEANUP += $(ICCFIX)

###############################################################################
#
# Auto-incrementing build serial number. Append "bs" to your list of
Expand Down
19 changes: 16 additions & 3 deletions src/arch/i386/Makefile
Expand Up @@ -4,30 +4,43 @@ CFLAGS += -march=i386

# Code size reduction.
#
CFLAGS += -fstrength-reduce -fomit-frame-pointer
CFLAGS += -fomit-frame-pointer

# Code size reduction.
#
ifeq ($(CCTYPE),gcc)
CFLAGS += -fstrength-reduce
endif

# Code size reduction. gcc3 needs a different syntax to gcc2 if you
# want to avoid spurious warnings.
#
ifeq ($(CCTYPE),gcc)
GCC_VERSION := $(subst ., ,$(shell $(CC) -dumpversion))
GCC_MAJOR := $(firstword $(GCC_VERSION))
ifeq ($(GCC_MAJOR),2)
CFLAGS += -malign-jumps=1 -malign-loops=1 -malign-functions=1
else
CFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=1
endif
endif # gcc2
endif # gcc

# Code size reduction. This is almost always a win. The kernel uses it, too.
# Code size reduction. This is almost always a win. The kernel uses
# it, too.
#
ifeq ($(CCTYPE),gcc)
CFLAGS += -mpreferred-stack-boundary=2
endif

# Code size reduction. Use regparm for all functions - C functions
# called from assembly (or vice versa) need __asmcall now
#
CFLAGS += -mregparm=3

# Code size reduction. Use -mrtd (same __asmcall requirements as above)
ifeq ($(CCTYPE),gcc)
CFLAGS += -mrtd
endif

# Code size reduction. This is the logical complement to -mregparm=3.
# It doesn't currently buy us anything, but if anything ever tries to
Expand Down
5 changes: 2 additions & 3 deletions src/arch/i386/drivers/net/undiload.c
Expand Up @@ -90,11 +90,10 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
undi_loader_entry = undirom->loader_entry;
__asm__ __volatile__ ( REAL_CODE ( "pushw %%ds\n\t"
"pushw %%ax\n\t"
"lcall *%c2\n\t"
"lcall *undi_loader_entry\n\t"
"addw $4, %%sp\n\t" )
: "=a" ( exit )
: "a" ( __from_data16 ( &undi_loader ) ),
"p" ( __from_data16 ( &undi_loader_entry ) )
: "a" ( __from_data16 ( &undi_loader ) )
: "ebx", "ecx", "edx", "esi", "edi", "ebp" );

/* UNDI API calls may rudely change the status of A20 and not
Expand Down
5 changes: 2 additions & 3 deletions src/arch/i386/drivers/net/undinet.c
Expand Up @@ -173,12 +173,11 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
__asm__ __volatile__ ( REAL_CODE ( "pushw %%es\n\t"
"pushw %%di\n\t"
"pushw %%bx\n\t"
"lcall *%c3\n\t"
"lcall *undinet_entry_point\n\t"
"addw $6, %%sp\n\t" )
: "=a" ( exit ), "=b" ( discard_b ),
"=D" ( discard_D )
: "p" ( __from_data16 ( &undinet_entry_point )),
"b" ( function ),
: "b" ( function ),
"D" ( __from_data16 ( &undinet_params ) )
: "ecx", "edx", "esi", "ebp" );

Expand Down
12 changes: 5 additions & 7 deletions src/crypto/md5.c
Expand Up @@ -26,30 +26,28 @@
#include <gpxe/crypto.h>
#include <gpxe/md5.h>

#define __md5step __attribute__ (( regparm ( 3 ) ))

struct md5_step {
u32 __md5step ( * f ) ( u32 b, u32 c, u32 d );
u32 ( * f ) ( u32 b, u32 c, u32 d );
u8 coefficient;
u8 constant;
};

static u32 __md5step f1(u32 b, u32 c, u32 d)
static u32 f1(u32 b, u32 c, u32 d)
{
return ( d ^ ( b & ( c ^ d ) ) );
}

static u32 __md5step f2(u32 b, u32 c, u32 d)
static u32 f2(u32 b, u32 c, u32 d)
{
return ( c ^ ( d & ( b ^ c ) ) );
}

static u32 __md5step f3(u32 b, u32 c, u32 d)
static u32 f3(u32 b, u32 c, u32 d)
{
return ( b ^ c ^ d );
}

static u32 __md5step f4(u32 b, u32 c, u32 d)
static u32 f4(u32 b, u32 c, u32 d)
{
return ( c ^ ( b | ~d ) );
}
Expand Down
3 changes: 2 additions & 1 deletion src/include/compiler.h
Expand Up @@ -212,7 +212,8 @@ int __debug_disable;
* @v len Length of data
*/
#define DBG_HD_IF( level, data, len ) do { \
DBG_HDA_IF ( level, data, data, len ); \
const void *_data = data; \
DBG_HDA_IF ( level, _data, _data, len ); \
} while ( 0 )

/**
Expand Down
7 changes: 6 additions & 1 deletion src/include/gpxe/efi/efi.h
Expand Up @@ -31,6 +31,11 @@
/* EFI headers rudely redefine NULL */
#undef NULL

/* EFI headers expect ICC to define __GNUC__ */
#if defined ( __ICC ) && ! defined ( __GNUC__ )
#define __GNUC__ 1
#endif

/* Include the top-level EFI header files */
#include <gpxe/efi/Uefi.h>
#include <gpxe/efi/PiDxe.h>
Expand Down Expand Up @@ -69,7 +74,7 @@ struct efi_protocol {
struct efi_protocol __ ## _protocol __efi_protocol = { \
.u.guid = _protocol ## _GUID, \
.protocol = ( ( void ** ) ( void * ) \
( ( (_ptr) == ( ( _protocol ** ) NULL ) ) ? \
( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
(_ptr) : (_ptr) ) ), \
}

Expand Down

0 comments on commit 1c67623

Please sign in to comment.