162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci#
362306a36Sopenharmony_ci# Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
462306a36Sopenharmony_ci#
562306a36Sopenharmony_ci
662306a36Sopenharmony_ciKBUILD_DEFCONFIG := haps_hs_smp_defconfig
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciifeq ($(CROSS_COMPILE),)
962306a36Sopenharmony_ciCROSS_COMPILE := $(call cc-cross-prefix, arc-linux- arceb-linux-)
1062306a36Sopenharmony_ciendif
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cicflags-y	+= -fno-common -pipe -fno-builtin -mmedium-calls -D__linux__
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_citune-mcpu-def-$(CONFIG_ISA_ARCOMPACT)	:= -mcpu=arc700
1562306a36Sopenharmony_citune-mcpu-def-$(CONFIG_ISA_ARCV2)	:= -mcpu=hs38
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciifeq ($(CONFIG_ARC_TUNE_MCPU),)
1862306a36Sopenharmony_cicflags-y				+= $(tune-mcpu-def-y)
1962306a36Sopenharmony_cielse
2062306a36Sopenharmony_citune-mcpu				:= $(CONFIG_ARC_TUNE_MCPU)
2162306a36Sopenharmony_ciifneq ($(call cc-option,$(tune-mcpu)),)
2262306a36Sopenharmony_cicflags-y				+= $(tune-mcpu)
2362306a36Sopenharmony_cielse
2462306a36Sopenharmony_ci# The flag provided by 'CONFIG_ARC_TUNE_MCPU' option isn't known by this compiler
2562306a36Sopenharmony_ci# (probably the compiler is too old). Use ISA default mcpu flag instead as a safe option.
2662306a36Sopenharmony_ci$(warning ** WARNING ** CONFIG_ARC_TUNE_MCPU flag '$(tune-mcpu)' is unknown, fallback to '$(tune-mcpu-def-y)')
2762306a36Sopenharmony_cicflags-y				+= $(tune-mcpu-def-y)
2862306a36Sopenharmony_ciendif
2962306a36Sopenharmony_ciendif
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciifdef CONFIG_ARC_CURR_IN_REG
3262306a36Sopenharmony_ci# For a global register definition, make sure it gets passed to every file
3362306a36Sopenharmony_ci# We had a customer reported bug where some code built in kernel was NOT using
3462306a36Sopenharmony_ci# any kernel headers, and missing the global register
3562306a36Sopenharmony_ci# Can't do unconditionally because of recursive include issues
3662306a36Sopenharmony_ci# due to <linux/thread_info.h>
3762306a36Sopenharmony_ciLINUXINCLUDE	+=  -include $(srctree)/arch/arc/include/asm/current.h
3862306a36Sopenharmony_cicflags-y	+= -ffixed-gp
3962306a36Sopenharmony_ciendif
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cicflags-y				+= -fsection-anchors
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_cicflags-$(CONFIG_ARC_HAS_LLSC)		+= -mlock
4462306a36Sopenharmony_cicflags-$(CONFIG_ARC_HAS_SWAPE)		+= -mswape
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ciifdef CONFIG_ISA_ARCV2
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
4962306a36Sopenharmony_cicflags-y				+= -munaligned-access
5062306a36Sopenharmony_cielse
5162306a36Sopenharmony_cicflags-y				+= -mno-unaligned-access
5262306a36Sopenharmony_ciendif
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciifndef CONFIG_ARC_HAS_LL64
5562306a36Sopenharmony_cicflags-y				+= -mno-ll64
5662306a36Sopenharmony_ciendif
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciifndef CONFIG_ARC_HAS_DIV_REM
5962306a36Sopenharmony_cicflags-y				+= -mno-div-rem
6062306a36Sopenharmony_ciendif
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciendif
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_cicfi := $(call as-instr,.cfi_startproc\n.cfi_endproc,-DARC_DW2_UNWIND_AS_CFI)
6562306a36Sopenharmony_cicflags-$(CONFIG_ARC_DW2_UNWIND)		+= -fasynchronous-unwind-tables $(cfi)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci# small data is default for elf32 tool-chain. If not usable, disable it
6862306a36Sopenharmony_ci# This also allows repurposing GP as scratch reg to gcc reg allocator
6962306a36Sopenharmony_cidisable_small_data := y
7062306a36Sopenharmony_cicflags-$(disable_small_data)		+= -mno-sdata
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_cicflags-$(CONFIG_CPU_BIG_ENDIAN)		+= -mbig-endian
7362306a36Sopenharmony_cildflags-$(CONFIG_CPU_BIG_ENDIAN)	+= -EB
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ciLIBGCC	= $(shell $(CC) $(cflags-y) --print-libgcc-file-name)
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci# Modules with short calls might break for calls into builtin-kernel
7862306a36Sopenharmony_ciKBUILD_CFLAGS_MODULE	+= -mlong-calls -mno-millicode
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci# Finally dump eveything into kernel build system
8162306a36Sopenharmony_ciKBUILD_CFLAGS	+= $(cflags-y)
8262306a36Sopenharmony_ciKBUILD_AFLAGS	+= $(KBUILD_CFLAGS)
8362306a36Sopenharmony_ciKBUILD_LDFLAGS	+= $(ldflags-y)
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci# w/o this dtb won't embed into kernel binary
8662306a36Sopenharmony_cicore-y		+= arch/arc/boot/dts/
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_cicore-y				+= arch/arc/plat-sim/
8962306a36Sopenharmony_cicore-$(CONFIG_ARC_PLAT_TB10X)	+= arch/arc/plat-tb10x/
9062306a36Sopenharmony_cicore-$(CONFIG_ARC_PLAT_AXS10X)	+= arch/arc/plat-axs10x/
9162306a36Sopenharmony_cicore-$(CONFIG_ARC_SOC_HSDK)	+= arch/arc/plat-hsdk/
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cilibs-y		+= arch/arc/lib/ $(LIBGCC)
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciboot		:= arch/arc/boot
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciboot_targets := uImage.bin uImage.gz uImage.lzma
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciPHONY += $(boot_targets)
10062306a36Sopenharmony_ci$(boot_targets): vmlinux
10162306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ciuimage-default-y			:= uImage.bin
10462306a36Sopenharmony_ciuimage-default-$(CONFIG_KERNEL_GZIP)	:= uImage.gz
10562306a36Sopenharmony_ciuimage-default-$(CONFIG_KERNEL_LZMA)	:= uImage.lzma
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciPHONY += uImage
10862306a36Sopenharmony_ciuImage: $(uimage-default-y)
10962306a36Sopenharmony_ci	@ln -sf $< $(boot)/uImage
11062306a36Sopenharmony_ci	@$(kecho) '  Image $(boot)/uImage is ready'
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciCLEAN_FILES += $(boot)/uImage
113