Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | # This file is included by the global makefile so that you can add your own |
| 2 | # architecture-specific flags and dependencies. Remember to do have actions |
| 3 | # for "archclean" and "archdep" for cleaning up and making dependencies for |
| 4 | # this architecture |
| 5 | # |
| 6 | # This file is subject to the terms and conditions of the GNU General Public |
| 7 | # License. See the file "COPYING" in the main directory of this archive |
| 8 | # for more details. |
| 9 | # |
| 10 | |
| 11 | OBJCOPYFLAGS := -O binary |
| 12 | LDFLAGS_vmlinux := |
| 13 | ifeq ($(CONFIG_DYNAMIC_FTRACE),y) |
| 14 | LDFLAGS_vmlinux := --no-relax |
| 15 | endif |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 16 | |
| 17 | ifeq ($(CONFIG_CMODEL_MEDLOW),y) |
| 18 | KBUILD_CFLAGS_MODULE += -mcmodel=medany |
| 19 | endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 20 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | export BITS |
| 22 | ifeq ($(CONFIG_ARCH_RV64I),y) |
| 23 | BITS := 64 |
| 24 | UTS_MACHINE := riscv64 |
| 25 | |
| 26 | KBUILD_CFLAGS += -mabi=lp64 |
| 27 | KBUILD_AFLAGS += -mabi=lp64 |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 28 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | KBUILD_LDFLAGS += -melf64lriscv |
| 30 | else |
| 31 | BITS := 32 |
| 32 | UTS_MACHINE := riscv32 |
| 33 | |
| 34 | KBUILD_CFLAGS += -mabi=ilp32 |
| 35 | KBUILD_AFLAGS += -mabi=ilp32 |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 36 | KBUILD_LDFLAGS += -melf32lriscv |
| 37 | endif |
| 38 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 39 | ifeq ($(CONFIG_LD_IS_LLD),y) |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 40 | ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 41 | KBUILD_CFLAGS += -mno-relax |
| 42 | KBUILD_AFLAGS += -mno-relax |
| 43 | ifneq ($(LLVM_IAS),1) |
| 44 | KBUILD_CFLAGS += -Wa,-mno-relax |
| 45 | KBUILD_AFLAGS += -Wa,-mno-relax |
| 46 | endif |
| 47 | endif |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 48 | endif |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 49 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 50 | # ISA string setting |
| 51 | riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima |
| 52 | riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima |
| 53 | riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd |
| 54 | riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 55 | |
| 56 | # Newer binutils versions default to ISA spec version 20191213 which moves some |
| 57 | # instructions from the I extension to the Zicsr and Zifencei extensions. |
| 58 | toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei) |
| 59 | riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei |
| 60 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 61 | KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y)) |
| 62 | KBUILD_AFLAGS += -march=$(riscv-march-y) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 63 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 64 | KBUILD_CFLAGS += -mno-save-restore |
| 65 | KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) |
| 66 | |
| 67 | ifeq ($(CONFIG_CMODEL_MEDLOW),y) |
| 68 | KBUILD_CFLAGS += -mcmodel=medlow |
| 69 | endif |
| 70 | ifeq ($(CONFIG_CMODEL_MEDANY),y) |
| 71 | KBUILD_CFLAGS += -mcmodel=medany |
| 72 | endif |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 73 | ifeq ($(CONFIG_PERF_EVENTS),y) |
| 74 | KBUILD_CFLAGS += -fno-omit-frame-pointer |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 75 | endif |
| 76 | |
| 77 | KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 78 | KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 79 | |
| 80 | # GCC versions that support the "-mstrict-align" option default to allowing |
| 81 | # unaligned accesses. While unaligned accesses are explicitly allowed in the |
| 82 | # RISC-V ISA, they're emulated by machine mode traps on all extant |
| 83 | # architectures. It's faster to have GCC emit only aligned accesses. |
| 84 | KBUILD_CFLAGS += $(call cc-option,-mstrict-align) |
| 85 | |
| 86 | # arch specific predefines for sparse |
| 87 | CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS) |
| 88 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 89 | # Default target when executing plain make |
| 90 | boot := arch/riscv/boot |
| 91 | KBUILD_IMAGE := $(boot)/Image.gz |
| 92 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 93 | head-y := arch/riscv/kernel/head.o |
| 94 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 95 | core-y += arch/riscv/ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 96 | |
| 97 | libs-y += arch/riscv/lib/ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 98 | libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 99 | |
| 100 | PHONY += vdso_install |
| 101 | vdso_install: |
| 102 | $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ |
| 103 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 104 | ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_KENDRYTE),yy) |
| 105 | KBUILD_IMAGE := $(boot)/loader.bin |
| 106 | else |
| 107 | KBUILD_IMAGE := $(boot)/Image.gz |
| 108 | endif |
| 109 | BOOT_TARGETS := Image Image.gz loader loader.bin |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 110 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 111 | all: $(notdir $(KBUILD_IMAGE)) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 112 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 113 | $(BOOT_TARGETS): vmlinux |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 114 | $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 115 | @$(kecho) ' Kernel: $(boot)/$@ is ready' |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 116 | |
| 117 | zinstall install: |
| 118 | $(Q)$(MAKE) $(build)=$(boot) $@ |