2018-03-07 20:57:14 +08:00
|
|
|
#
|
|
|
|
# ACRN Hypervisor
|
|
|
|
#
|
|
|
|
|
|
|
|
MAJOR_VERSION=0
|
|
|
|
MINOR_VERSION=1
|
2018-05-31 07:30:24 +08:00
|
|
|
RC_VERSION=5
|
2018-03-08 16:47:06 +08:00
|
|
|
|
|
|
|
API_MAJOR_VERSION=1
|
|
|
|
API_MINOR_VERSION=0
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
|
|
|
|
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
|
|
|
|
|
|
|
|
#enable stack overflow check
|
|
|
|
STACK_PROTECTOR := 1
|
|
|
|
|
|
|
|
BASEDIR := $(shell pwd)
|
|
|
|
HV_OBJDIR ?= $(CURDIR)/build
|
|
|
|
HV_FILE := acrn
|
|
|
|
|
2018-05-25 22:38:24 +08:00
|
|
|
.PHONY: default
|
|
|
|
default: all
|
|
|
|
|
|
|
|
include $(BASEDIR)/../scripts/deps.mk
|
|
|
|
|
|
|
|
include scripts/kconfig/kconfig.mk
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
CFLAGS += -Wall -W
|
|
|
|
CFLAGS += -ffunction-sections -fdata-sections
|
|
|
|
CFLAGS += -fshort-wchar -ffreestanding
|
2018-05-10 11:14:09 +08:00
|
|
|
CFLAGS += -m64 -mno-mmx -mno-sse -mno-sse2 -mno-80387 -mno-fp-ret-in-387
|
2018-03-07 20:57:14 +08:00
|
|
|
CFLAGS += -mno-red-zone
|
|
|
|
CFLAGS += -static -nostdinc -nostdlib -fno-common
|
2018-05-10 11:14:16 +08:00
|
|
|
CFLAGS += -O2 -D_FORTIFY_SOURCE=2
|
2018-02-12 13:15:06 +08:00
|
|
|
CFLAGS += -Wformat -Wformat-security
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
ifdef STACK_PROTECTOR
|
|
|
|
ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true))
|
|
|
|
CFLAGS += -fstack-protector-strong
|
|
|
|
else
|
|
|
|
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true))
|
|
|
|
CFLAGS += -fstack-protector-strong
|
|
|
|
else
|
|
|
|
CFLAGS += -fstack-protector
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
CFLAGS += -DSTACK_PROTECTOR
|
|
|
|
endif
|
|
|
|
|
|
|
|
ASFLAGS += -m64 -nostdinc -nostdlib
|
|
|
|
|
|
|
|
LDFLAGS += -Wl,--gc-sections -static -nostartfiles -nostdlib
|
|
|
|
LDFLAGS += -Wl,-n,-z,max-page-size=0x1000
|
|
|
|
LDFLAGS += -Wl,-z,noexecstack
|
|
|
|
|
2018-05-10 11:14:03 +08:00
|
|
|
ARCH_CFLAGS += -gdwarf-2
|
2018-03-07 20:57:14 +08:00
|
|
|
ARCH_ASFLAGS += -gdwarf-2 -DASSEMBLER=1
|
|
|
|
ARCH_ARFLAGS +=
|
|
|
|
ARCH_LDFLAGS +=
|
|
|
|
|
|
|
|
ARCH_LDSCRIPT = $(HV_OBJDIR)/link_ram.ld
|
|
|
|
ARCH_LDSCRIPT_IN = bsp/ld/link_ram.ld.in
|
|
|
|
|
|
|
|
INCLUDE_PATH += include
|
|
|
|
INCLUDE_PATH += include/lib
|
2018-03-27 17:28:51 +08:00
|
|
|
INCLUDE_PATH += include/lib/crypto
|
2018-03-07 20:57:14 +08:00
|
|
|
INCLUDE_PATH += include/common
|
|
|
|
INCLUDE_PATH += include/arch/x86
|
|
|
|
INCLUDE_PATH += include/arch/x86/guest
|
|
|
|
INCLUDE_PATH += include/debug
|
|
|
|
INCLUDE_PATH += include/public
|
|
|
|
INCLUDE_PATH += include/common
|
|
|
|
INCLUDE_PATH += bsp/include
|
2018-06-10 11:48:45 +08:00
|
|
|
INCLUDE_PATH += bsp/$(CONFIG_PLATFORM)/include/bsp
|
2018-03-07 20:57:14 +08:00
|
|
|
INCLUDE_PATH += boot/include
|
2018-05-22 23:24:07 +08:00
|
|
|
INCLUDE_PATH += $(HV_OBJDIR)/include
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-03-28 12:33:05 +08:00
|
|
|
CC ?= gcc
|
|
|
|
AS ?= as
|
|
|
|
AR ?= ar
|
|
|
|
LD ?= ld
|
|
|
|
OBJCOPY ?= objcopy
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-03-22 00:38:30 +08:00
|
|
|
D_SRCS += $(wildcard debug/*.c)
|
2018-03-19 20:28:45 +08:00
|
|
|
C_SRCS += boot/acpi.c
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += boot/dmar_parse.c
|
|
|
|
C_SRCS += arch/x86/ioapic.c
|
|
|
|
C_SRCS += arch/x86/intr_lapic.c
|
2018-06-11 20:31:25 +08:00
|
|
|
S_SRCS += arch/x86/trampoline.S
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += arch/x86/cpu.c
|
|
|
|
C_SRCS += arch/x86/softirq.c
|
|
|
|
C_SRCS += arch/x86/cpuid.c
|
|
|
|
C_SRCS += arch/x86/mmu.c
|
|
|
|
C_SRCS += arch/x86/notify.c
|
|
|
|
C_SRCS += arch/x86/intr_main.c
|
|
|
|
C_SRCS += arch/x86/vtd.c
|
|
|
|
C_SRCS += arch/x86/gdt.c
|
|
|
|
S_SRCS += arch/x86/cpu_primary.S
|
|
|
|
S_SRCS += arch/x86/idt.S
|
|
|
|
C_SRCS += arch/x86/irq.c
|
|
|
|
C_SRCS += arch/x86/timer.c
|
|
|
|
C_SRCS += arch/x86/ept.c
|
|
|
|
S_SRCS += arch/x86/vmx_asm.S
|
|
|
|
C_SRCS += arch/x86/io.c
|
|
|
|
C_SRCS += arch/x86/interrupt.c
|
|
|
|
C_SRCS += arch/x86/vmexit.c
|
|
|
|
C_SRCS += arch/x86/vmx.c
|
|
|
|
C_SRCS += arch/x86/assign.c
|
2018-03-01 13:34:41 +08:00
|
|
|
C_SRCS += arch/x86/trusty.c
|
2018-04-04 14:29:46 +08:00
|
|
|
C_SRCS += arch/x86/cpu_state_tbl.c
|
2018-05-30 08:41:52 +08:00
|
|
|
C_SRCS += arch/x86/mtrr.c
|
2018-06-04 16:02:20 +08:00
|
|
|
C_SRCS += arch/x86/pm.c
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += arch/x86/guest/vcpu.c
|
|
|
|
C_SRCS += arch/x86/guest/vm.c
|
|
|
|
C_SRCS += arch/x86/guest/instr_emul_wrapper.c
|
|
|
|
C_SRCS += arch/x86/guest/vlapic.c
|
|
|
|
C_SRCS += arch/x86/guest/guest.c
|
|
|
|
C_SRCS += arch/x86/guest/vmcall.c
|
|
|
|
C_SRCS += arch/x86/guest/vpic.c
|
|
|
|
C_SRCS += arch/x86/guest/vmsr.c
|
|
|
|
C_SRCS += arch/x86/guest/vioapic.c
|
|
|
|
C_SRCS += arch/x86/guest/instr_emul.c
|
2018-03-06 21:22:30 +08:00
|
|
|
C_SRCS += arch/x86/guest/ucode.c
|
2018-04-17 12:12:33 +08:00
|
|
|
C_SRCS += arch/x86/guest/pm.c
|
2018-05-17 22:21:13 +08:00
|
|
|
C_SRCS += arch/x86/debug/reboot.c
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += lib/spinlock.c
|
|
|
|
C_SRCS += lib/udelay.c
|
|
|
|
C_SRCS += lib/mdelay.c
|
|
|
|
C_SRCS += lib/div.c
|
2018-05-15 22:22:50 +08:00
|
|
|
C_SRCS += lib/string.c
|
2018-05-15 22:51:41 +08:00
|
|
|
C_SRCS += lib/memory.c
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += lib/crypto/hkdf.c
|
2018-03-21 18:46:14 +08:00
|
|
|
C_SRCS += lib/sprintf.c
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += common/hv_main.c
|
|
|
|
C_SRCS += common/hypercall.c
|
2018-03-27 17:26:38 +08:00
|
|
|
C_SRCS += common/trusty_hypercall.c
|
2018-03-07 20:57:14 +08:00
|
|
|
C_SRCS += common/schedule.c
|
|
|
|
C_SRCS += common/vm_load.c
|
2018-05-17 16:47:54 +08:00
|
|
|
C_SRCS += common/io_request.c
|
2018-06-14 18:06:26 +08:00
|
|
|
C_SRCS += common/ptdev.c
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
ifdef STACK_PROTECTOR
|
|
|
|
C_SRCS += common/stack_protector.c
|
|
|
|
endif
|
|
|
|
|
2018-06-10 11:48:45 +08:00
|
|
|
C_SRCS += bsp/$(CONFIG_PLATFORM)/vm_description.c
|
|
|
|
C_SRCS += bsp/$(CONFIG_PLATFORM)/$(CONFIG_PLATFORM).c
|
|
|
|
C_SRCS += bsp/$(CONFIG_PLATFORM)/platform_acpi_info.c
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-06-10 11:48:45 +08:00
|
|
|
ifeq ($(CONFIG_PLATFORM),uefi)
|
|
|
|
C_SRCS += bsp/$(CONFIG_PLATFORM)/cmdline.c
|
2018-05-21 22:26:02 +08:00
|
|
|
else
|
2018-06-10 11:48:45 +08:00
|
|
|
ifeq ($(CONFIG_PLATFORM), sbl)
|
2018-05-21 22:26:02 +08:00
|
|
|
C_SRCS += boot/sbl/multiboot.c
|
2018-06-05 10:57:34 +08:00
|
|
|
C_SRCS += boot/sbl/hob_parse.c
|
2018-05-21 22:26:02 +08:00
|
|
|
endif
|
2018-03-07 20:57:14 +08:00
|
|
|
endif
|
|
|
|
|
2018-03-12 20:57:44 +08:00
|
|
|
# retpoline support
|
|
|
|
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 7 ] && [ $(GCC_MINOR) -ge 3 ] && echo true))
|
|
|
|
CFLAGS += -mindirect-branch=thunk-extern -mindirect-branch-register
|
|
|
|
CFLAGS += -DCONFIG_RETPOLINE
|
|
|
|
S_SRCS += arch/x86/retpoline-thunk.S
|
|
|
|
else
|
|
|
|
ifeq (true, $(shell [ $(GCC_MAJOR) -ge 8 ] && echo true))
|
|
|
|
CFLAGS += -mindirect-branch=thunk-extern -mindirect-branch-register
|
|
|
|
CFLAGS += -DCONFIG_RETPOLINE
|
|
|
|
S_SRCS += arch/x86/retpoline-thunk.S
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
C_OBJS := $(patsubst %.c,$(HV_OBJDIR)/%.o,$(C_SRCS))
|
2018-06-10 14:50:58 +08:00
|
|
|
ifeq ($(CONFIG_RELEASE),n)
|
2018-03-07 20:57:14 +08:00
|
|
|
C_OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(D_SRCS))
|
|
|
|
CFLAGS += -DHV_DEBUG
|
|
|
|
endif
|
|
|
|
S_OBJS := $(patsubst %.S,$(HV_OBJDIR)/%.o,$(S_SRCS))
|
|
|
|
|
|
|
|
DISTCLEAN_OBJS := $(shell find $(BASEDIR) -name '*.o')
|
2018-06-10 11:48:45 +08:00
|
|
|
VERSION := bsp/$(CONFIG_PLATFORM)/include/bsp/version.h
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
.PHONY: all
|
2018-06-09 15:37:55 +08:00
|
|
|
all: $(VERSION) $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin
|
2018-03-07 20:57:14 +08:00
|
|
|
rm -f $(VERSION)
|
|
|
|
|
2018-06-10 11:48:45 +08:00
|
|
|
ifeq ($(CONFIG_PLATFORM), uefi)
|
2018-03-07 20:57:14 +08:00
|
|
|
all: efi
|
|
|
|
.PHONY: efi
|
|
|
|
efi: $(HV_OBJDIR)/$(HV_FILE).bin
|
|
|
|
echo "building hypervisor as EFI executable..."
|
2018-06-10 14:50:58 +08:00
|
|
|
make -C bsp/uefi/efi HV_OBJDIR=$(HV_OBJDIR)
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
install: efi
|
2018-06-10 14:50:58 +08:00
|
|
|
make -C bsp/uefi/efi HV_OBJDIR=$(HV_OBJDIR) install
|
2018-03-07 20:57:14 +08:00
|
|
|
endif
|
|
|
|
|
2018-06-10 11:48:45 +08:00
|
|
|
ifeq ($(CONFIG_PLATFORM), sbl)
|
2018-05-24 16:45:21 +08:00
|
|
|
install: $(VERSION) $(HV_OBJDIR)/$(HV_FILE).32.out
|
|
|
|
install -D $(HV_OBJDIR)/$(HV_FILE).32.out $(DESTDIR)/usr/lib/acrn/$(HV_FILE).sbl
|
|
|
|
endif
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
$(HV_OBJDIR)/$(HV_FILE).32.out: $(HV_OBJDIR)/$(HV_FILE).out
|
2018-03-28 12:33:05 +08:00
|
|
|
$(OBJCOPY) -S --section-alignment=0x1000 -O elf32-i386 $< $@
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
$(HV_OBJDIR)/$(HV_FILE).bin: $(HV_OBJDIR)/$(HV_FILE).out
|
2018-03-28 12:33:05 +08:00
|
|
|
$(OBJCOPY) -O binary $< $(HV_OBJDIR)/$(HV_FILE).bin
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
$(HV_OBJDIR)/$(HV_FILE).out: $(C_OBJS) $(S_OBJS)
|
|
|
|
$(CC) -E -x c $(patsubst %, -I%, $(INCLUDE_PATH)) $(ARCH_LDSCRIPT_IN) | grep -v '^#' > $(ARCH_LDSCRIPT)
|
2018-03-28 12:33:05 +08:00
|
|
|
$(CC) -Wl,-Map=$(HV_OBJDIR)/$(HV_FILE).map -o $@ $(LDFLAGS) $(ARCH_LDFLAGS) -T$(ARCH_LDSCRIPT) $^
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -f $(C_OBJS)
|
|
|
|
rm -f $(S_OBJS)
|
|
|
|
rm -f $(VERSION)
|
|
|
|
rm -rf $(HV_OBJDIR)
|
|
|
|
|
|
|
|
.PHONY: distclean
|
|
|
|
distclean:
|
|
|
|
rm -f $(DISTCLEAN_OBJS)
|
|
|
|
rm -f $(C_OBJS)
|
|
|
|
rm -f $(S_OBJS)
|
|
|
|
rm -f $(VERSION)
|
|
|
|
rm -rf $(HV_OBJDIR)
|
|
|
|
rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS
|
|
|
|
|
|
|
|
PHONY: (VERSION)
|
|
|
|
$(VERSION):
|
|
|
|
touch $(VERSION)
|
|
|
|
@COMMIT=`git rev-parse --verify --short HEAD 2>/dev/null`;\
|
|
|
|
DIRTY=`git diff-index --name-only HEAD`;\
|
|
|
|
if [ -n "$$DIRTY" ];then PATCH="$$COMMIT-dirty";else PATCH="$$COMMIT";fi;\
|
2018-04-28 13:13:16 +08:00
|
|
|
TIME=`date "+%F %T"`;\
|
2018-06-10 14:50:58 +08:00
|
|
|
if [ $(CONFIG_RELEASE) = "n" ];then BUILD_TYPE="DBG";else BUILD_TYPE="REL";fi;\
|
2018-05-15 16:24:47 +08:00
|
|
|
echo "/*" > $(VERSION); \
|
|
|
|
sed 's/^/ * /' ../LICENSE >> $(VERSION); \
|
|
|
|
echo " */" >> $(VERSION); \
|
|
|
|
echo "" >> $(VERSION); \
|
2018-03-07 20:57:14 +08:00
|
|
|
echo "#define HV_MAJOR_VERSION $(MAJOR_VERSION)" >> $(VERSION);\
|
|
|
|
echo "#define HV_MINOR_VERSION $(MINOR_VERSION)" >> $(VERSION);\
|
2018-03-08 16:47:06 +08:00
|
|
|
echo "#define HV_RC_VERSION $(RC_VERSION)" >> $(VERSION);\
|
|
|
|
echo "#define HV_API_MAJOR_VERSION $(API_MAJOR_VERSION)" >> $(VERSION);\
|
|
|
|
echo "#define HV_API_MINOR_VERSION $(API_MINOR_VERSION)" >> $(VERSION);\
|
2018-03-07 20:57:14 +08:00
|
|
|
echo "#define HV_BUILD_VERSION "\""$$PATCH"\""" >> $(VERSION);\
|
2018-04-28 13:13:16 +08:00
|
|
|
echo "#define HV_BUILD_TYPE "\""$$BUILD_TYPE"\""" >> $(VERSION);\
|
2018-03-07 20:57:14 +08:00
|
|
|
echo "#define HV_BUILD_TIME "\""$$TIME"\""" >> $(VERSION);\
|
|
|
|
echo "#define HV_BUILD_USER "\""$(USER)"\""" >> $(VERSION)
|
|
|
|
|
2018-05-22 23:24:07 +08:00
|
|
|
$(HV_OBJDIR)/%.o: %.c $(HV_OBJDIR)/$(HV_CONFIG_H)
|
2018-03-07 20:57:14 +08:00
|
|
|
[ ! -e $@ ] && mkdir -p $(dir $@); \
|
|
|
|
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@
|
|
|
|
|
2018-05-22 23:24:07 +08:00
|
|
|
$(HV_OBJDIR)/%.o: %.S $(HV_OBJDIR)/$(HV_CONFIG_H)
|
2018-03-07 20:57:14 +08:00
|
|
|
[ ! -e $@ ] && mkdir -p $(dir $@); \
|
|
|
|
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. $(ASFLAGS) $(ARCH_ASFLAGS) -c $< -o $@
|