riscv: select ARCH_PROC_KCORE_TEXT
[linux-2.6-block.git] / arch / riscv / Makefile
1 # This file is included by the global makefile so that you can add your own
2 # architecture-specific flags and dependencies.
3 #
4 # This file is subject to the terms and conditions of the GNU General Public
5 # License.  See the file "COPYING" in the main directory of this archive
6 # for more details.
7 #
8
9 OBJCOPYFLAGS    := -O binary
10 LDFLAGS_vmlinux := -z norelro
11 ifeq ($(CONFIG_RELOCATABLE),y)
12         LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs
13         KBUILD_CFLAGS += -fPIE
14 endif
15 ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
16         LDFLAGS_vmlinux += --no-relax
17         KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
18 ifeq ($(CONFIG_RISCV_ISA_C),y)
19         CC_FLAGS_FTRACE := -fpatchable-function-entry=4
20 else
21         CC_FLAGS_FTRACE := -fpatchable-function-entry=2
22 endif
23 endif
24
25 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
26 KBUILD_CFLAGS_MODULE += -mcmodel=medany
27 endif
28
29 export BITS
30 ifeq ($(CONFIG_ARCH_RV64I),y)
31         BITS := 64
32         UTS_MACHINE := riscv64
33
34         KBUILD_CFLAGS += -mabi=lp64
35         KBUILD_AFLAGS += -mabi=lp64
36
37         KBUILD_LDFLAGS += -melf64lriscv
38 else
39         BITS := 32
40         UTS_MACHINE := riscv32
41
42         KBUILD_CFLAGS += -mabi=ilp32
43         KBUILD_AFLAGS += -mabi=ilp32
44         KBUILD_LDFLAGS += -melf32lriscv
45 endif
46
47 ifeq ($(CONFIG_LD_IS_LLD),y)
48 ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y)
49         KBUILD_CFLAGS += -mno-relax
50         KBUILD_AFLAGS += -mno-relax
51 ifndef CONFIG_AS_IS_LLVM
52         KBUILD_CFLAGS += -Wa,-mno-relax
53         KBUILD_AFLAGS += -Wa,-mno-relax
54 endif
55 endif
56 endif
57
58 ifeq ($(CONFIG_SHADOW_CALL_STACK),y)
59         KBUILD_LDFLAGS += --no-relax-gp
60 endif
61
62 # ISA string setting
63 riscv-march-$(CONFIG_ARCH_RV32I)        := rv32ima
64 riscv-march-$(CONFIG_ARCH_RV64I)        := rv64ima
65 riscv-march-$(CONFIG_FPU)               := $(riscv-march-y)fd
66 riscv-march-$(CONFIG_RISCV_ISA_C)       := $(riscv-march-y)c
67 riscv-march-$(CONFIG_RISCV_ISA_V)       := $(riscv-march-y)v
68
69 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
70 KBUILD_CFLAGS += -Wa,-misa-spec=2.2
71 KBUILD_AFLAGS += -Wa,-misa-spec=2.2
72 else
73 riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
74 endif
75
76 # Check if the toolchain supports Zihintpause extension
77 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause
78
79 # Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
80 # matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
81 KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')
82
83 KBUILD_AFLAGS += -march=$(riscv-march-y)
84
85 KBUILD_CFLAGS += -mno-save-restore
86 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
87
88 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
89         KBUILD_CFLAGS += -mcmodel=medlow
90 endif
91 ifeq ($(CONFIG_CMODEL_MEDANY),y)
92         KBUILD_CFLAGS += -mcmodel=medany
93 endif
94
95 # Avoid generating .eh_frame sections.
96 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
97
98 # The RISC-V attributes frequently cause compatibility issues and provide no
99 # information, so just turn them off.
100 KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
101 KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
102 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
103 KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
104
105 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
106 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
107
108 # GCC versions that support the "-mstrict-align" option default to allowing
109 # unaligned accesses.  While unaligned accesses are explicitly allowed in the
110 # RISC-V ISA, they're emulated by machine mode traps on all extant
111 # architectures.  It's faster to have GCC emit only aligned accesses.
112 KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
113
114 ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
115 prepare: stack_protector_prepare
116 stack_protector_prepare: prepare0
117         $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls               \
118                                 -mstack-protector-guard-reg=tp            \
119                                 -mstack-protector-guard-offset=$(shell    \
120                         awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
121                                         include/generated/asm-offsets.h))
122 endif
123
124 # arch specific predefines for sparse
125 CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
126
127 # Default target when executing plain make
128 boot            := arch/riscv/boot
129 ifeq ($(CONFIG_XIP_KERNEL),y)
130 KBUILD_IMAGE := $(boot)/xipImage
131 else
132 KBUILD_IMAGE    := $(boot)/Image.gz
133 endif
134
135 libs-y += arch/riscv/lib/
136 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
137
138 PHONY += vdso_install
139 vdso_install:
140         $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
141         $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
142                 $(build)=arch/riscv/kernel/compat_vdso compat_$@)
143
144 ifeq ($(KBUILD_EXTMOD),)
145 ifeq ($(CONFIG_MMU),y)
146 prepare: vdso_prepare
147 vdso_prepare: prepare0
148         $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
149         $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
150                 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
151
152 endif
153 endif
154
155 ifneq ($(CONFIG_XIP_KERNEL),y)
156 ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy)
157 KBUILD_IMAGE := $(boot)/loader.bin
158 else
159 ifeq ($(CONFIG_EFI_ZBOOT),)
160 KBUILD_IMAGE := $(boot)/Image.gz
161 else
162 KBUILD_IMAGE := $(boot)/vmlinuz.efi
163 endif
164 endif
165 endif
166 BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
167
168 all:    $(notdir $(KBUILD_IMAGE))
169
170 $(BOOT_TARGETS): vmlinux
171         $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
172         @$(kecho) '  Kernel: $(boot)/$@ is ready'
173
174 Image.%: Image
175         $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
176
177 install: KBUILD_IMAGE := $(boot)/Image
178 zinstall: KBUILD_IMAGE := $(boot)/Image.gz
179 install zinstall:
180         $(call cmd,install)
181
182 PHONY += rv32_randconfig
183 rv32_randconfig:
184         $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
185                 -f $(srctree)/Makefile randconfig
186
187 PHONY += rv64_randconfig
188 rv64_randconfig:
189         $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
190                 -f $(srctree)/Makefile randconfig
191
192 PHONY += rv32_defconfig
193 rv32_defconfig:
194         $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
195
196 PHONY += rv32_nommu_virt_defconfig
197 rv32_nommu_virt_defconfig:
198         $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config