18c2ecf20Sopenharmony_ci#
28c2ecf20Sopenharmony_ci# Loongson Processors' Support
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci# Only gcc >= 4.4 have Loongson specific support
68c2ecf20Sopenharmony_cicflags-$(CONFIG_CPU_LOONGSON2EF)	+= -Wa,--trap
78c2ecf20Sopenharmony_cicflags-$(CONFIG_CPU_LOONGSON2E) += \
88c2ecf20Sopenharmony_ci	$(call cc-option,-march=loongson2e,-march=r4600)
98c2ecf20Sopenharmony_cicflags-$(CONFIG_CPU_LOONGSON2F) += \
108c2ecf20Sopenharmony_ci	$(call cc-option,-march=loongson2f,-march=r4600)
118c2ecf20Sopenharmony_ci#
128c2ecf20Sopenharmony_ci# Some versions of binutils, not currently mainline as of 2019/02/04, support
138c2ecf20Sopenharmony_ci# an -mfix-loongson3-llsc flag which emits a sync prior to each ll instruction
148c2ecf20Sopenharmony_ci# to work around a CPU bug (see __SYNC_loongson3_war in asm/sync.h for a
158c2ecf20Sopenharmony_ci# description).
168c2ecf20Sopenharmony_ci#
178c2ecf20Sopenharmony_ci# We disable this in order to prevent the assembler meddling with the
188c2ecf20Sopenharmony_ci# instruction that labels refer to, ie. if we label an ll instruction:
198c2ecf20Sopenharmony_ci#
208c2ecf20Sopenharmony_ci# 1: ll v0, 0(a0)
218c2ecf20Sopenharmony_ci#
228c2ecf20Sopenharmony_ci# ...then with the assembler fix applied the label may actually point at a sync
238c2ecf20Sopenharmony_ci# instruction inserted by the assembler, and if we were using the label in an
248c2ecf20Sopenharmony_ci# exception table the table would no longer contain the address of the ll
258c2ecf20Sopenharmony_ci# instruction.
268c2ecf20Sopenharmony_ci#
278c2ecf20Sopenharmony_ci# Avoid this by explicitly disabling that assembler behaviour. If upstream
288c2ecf20Sopenharmony_ci# binutils does not merge support for the flag then we can revisit & remove
298c2ecf20Sopenharmony_ci# this later - for now it ensures vendor toolchains don't cause problems.
308c2ecf20Sopenharmony_ci#
318c2ecf20Sopenharmony_cicflags-$(CONFIG_CPU_LOONGSON2EF)	+= $(call as-option,-Wa$(comma)-mno-fix-loongson3-llsc,)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci# Enable the workarounds for Loongson2f
348c2ecf20Sopenharmony_ciifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS
358c2ecf20Sopenharmony_ci  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-nop,),)
368c2ecf20Sopenharmony_ci    $(error only binutils >= 2.20.2 have needed option -mfix-loongson2f-nop)
378c2ecf20Sopenharmony_ci  else
388c2ecf20Sopenharmony_ci    cflags-$(CONFIG_CPU_NOP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-nop
398c2ecf20Sopenharmony_ci  endif
408c2ecf20Sopenharmony_ci  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-jump,),)
418c2ecf20Sopenharmony_ci    $(error only binutils >= 2.20.2 have needed option -mfix-loongson2f-jump)
428c2ecf20Sopenharmony_ci  else
438c2ecf20Sopenharmony_ci    cflags-$(CONFIG_CPU_JUMP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-jump
448c2ecf20Sopenharmony_ci  endif
458c2ecf20Sopenharmony_ciendif
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci# Some -march= flags enable MMI instructions, and GCC complains about that
488c2ecf20Sopenharmony_ci# support being enabled alongside -msoft-float. Thus explicitly disable MMI.
498c2ecf20Sopenharmony_cicflags-y += $(call cc-option,-mno-loongson-mmi)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#
528c2ecf20Sopenharmony_ci# Loongson Machines' Support
538c2ecf20Sopenharmony_ci#
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cicflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef -mno-branch-likely
568c2ecf20Sopenharmony_ciload-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000
578c2ecf20Sopenharmony_ciload-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000
58