1#
2# This file is subject to the terms and conditions of the GNU General Public
3# License.  See the file "COPYING" in the main directory of this archive
4# for more details.
5#
6# Copyright (C) 2002, 2003, 2004  Maciej W. Rozycki
7#
8# This file is included by the global makefile so that you can add your own
9# architecture-specific flags and dependencies. Remember to do have actions
10# for "archclean" and "archdep" for cleaning up and making dependencies for
11# this architecture
12#
13
14comma := ,
15
16#
17# Select the object file format to substitute into the linker script.
18#
19ifdef CONFIG_CPU_LITTLE_ENDIAN
20tool-prefix	= mips64el-linux-
21else
22tool-prefix	= mips64-linux-
23endif
24
25ifdef CONFIG_CROSSCOMPILE
26CROSS_COMPILE	= $(tool-prefix)
27endif
28
29check_gas = $(shell if $(CC) $(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
30
31#
32# The ELF GCC uses -G 0 -mabicalls -fpic as default.  We don't need PIC
33# code in the kernel since it only slows down the whole thing.  For the
34# old GCC these options are just the defaults.  At some point we might
35# make use of global pointer optimizations.
36#
37# The DECStation requires an ECOFF kernel for remote booting, other MIPS
38# machines may also.  Since BFD is incredibly buggy with respect to
39# crossformat linking we rely on the elf2ecoff tool for format conversion.
40#
41GCCFLAGS	:= -I $(TOPDIR)/include/asm/gcc
42GCCFLAGS	+= -G 0 -mno-abicalls -fno-pic -Wa,--trap -pipe
43GCCFLAGS	+= $(call check_gcc, -finline-limit=100000,)
44LINKFLAGS	+= -G 0 -static -n
45MODFLAGS	+= -mlong-calls
46
47ifdef CONFIG_DEBUG_INFO
48GCCFLAGS	+= -g
49ifdef CONFIG_SB1XXX_CORELIS
50GCCFLAGS	+= -mno-sched-prolog -fno-omit-frame-pointer
51endif
52endif
53
54#
55# Use: $(call set_gccflags,<cpu0>,<isa0>,<cpu1>,<isa1>)
56#
57# <cpu0>,<isa0> -- preferred CPU and ISA designations (may require
58#                  recent tools)
59# <cpu1>,<isa1> -- fallback CPU and ISA designations (have to work
60#                  with up to the oldest supported tools)
61#
62set_gccflags = $(shell \
63while :; do \
64	cpu=$(1); isa=-$(2); \
65	for gcc_opt in -march= -mcpu=; do \
66		$(CC) $$gcc_opt$$cpu $$isa -S -o /dev/null \
67			-xc /dev/null > /dev/null 2>&1 && \
68			break 2; \
69	done; \
70	cpu=$(3); isa=-$(4); \
71	for gcc_opt in -march= -mcpu=; do \
72		$(CC) $$gcc_opt$$cpu $$isa -S -o /dev/null \
73			-xc /dev/null > /dev/null 2>&1 && \
74			break 2; \
75	done; \
76	break; \
77done; \
78gcc_abi=-mabi=64; \
79gcc_cpu=$$cpu; gcc_isa=$$isa; \
80gas_cpu=$$cpu; gas_isa=-Wa,$$isa; \
81while :; do \
82	for gas_opt in -Wa,-march= -Wa,-mcpu=; do \
83		$(CC) $$gas_opt$$cpu $$gas_isa -Wa,-Z -c -o /dev/null \
84			-xassembler /dev/null > /dev/null 2>&1 && \
85			break 2; \
86	done; \
87	gas_opt=; gas_cpu=; gas_isa=; \
88	break; \
89done; \
90if test "$$gcc_opt" = -march=; then \
91	$(CC) $$gcc_abi $$gcc_opt$$gcc_cpu -S -o /dev/null \
92		-xc /dev/null > /dev/null 2>&1 && \
93		gcc_isa=; \
94fi; \
95echo $$gcc_abi $$gcc_opt$$gcc_cpu $$gcc_isa $$gas_opt$$gas_cpu $$gas_isa)
96
97#
98# CPU-dependent compiler/assembler options for optimization.
99#
100ifdef CONFIG_CPU_R4300
101GCCFLAGS	+= $(call set_gccflags,r4300,mips3,r4300,mips3)
102endif
103ifdef CONFIG_CPU_R4X00
104GCCFLAGS	+= $(call set_gccflags,r4600,mips3,r4600,mips3)
105endif
106ifdef CONFIG_CPU_R5000
107GCCFLAGS	+= $(call set_gccflags,r5000,mips4,r8000,mips4)
108endif
109ifdef CONFIG_CPU_NEVADA
110GCCFLAGS	+= $(call set_gccflags,rm5200,mips4,r8000,mips4)
111#GCCFLAGS	+= $(call check_gcc,-mmad,)
112endif
113ifdef CONFIG_CPU_RM7000
114GCCFLAGS	+= $(call set_gccflags,rm7000,mips4,r5000,mips4)
115endif
116ifdef CONFIG_CPU_RM9000
117GCCFLAGS	+= $(call set_gccflags,rm9000,mips4,r5000,mips4)
118endif
119ifdef CONFIG_CPU_R8000
120GCCFLAGS	+= $(call set_gccflags,r8000,mips4,r8000,mips4)
121endif
122ifdef CONFIG_CPU_R10000
123GCCFLAGS	+= $(call set_gccflags,r10000,mips4,r8000,mips4)
124endif
125ifdef CONFIG_CPU_SB1
126GCCFLAGS	+= $(call set_gccflags,sb1,mips64,r5000,mips4)
127ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
128MODFLAGS	+= -msb1-pass1-workarounds
129endif
130endif
131ifdef CONFIG_CPU_MIPS64
132GCCFLAGS	+= $(call set_gccflags,mips64,mips64,r8000,mips4)
133endif
134
135#
136# We unconditionally build the math emulator
137#
138CORE_FILES	+= arch/mips/math-emu/fpu_emulator.o
139SUBDIRS		+= arch/mips/math-emu
140
141#
142# ramdisk/initrd support
143# You need a compressed ramdisk image, named ramdisk.gz in
144# arch/mips/ramdisk
145#
146ifdef CONFIG_EMBEDDED_RAMDISK
147CORE_FILES	+= arch/mips/ramdisk/ramdisk.o
148SUBDIRS		+= arch/mips/ramdisk
149endif
150
151
152#
153# Board-dependent options and extra files
154#
155
156#
157# Cobalt Server
158#
159ifdef CONFIG_MIPS_COBALT
160SUBDIRS		+= arch/mips/cobalt
161CORE_FILES	+= arch/mips/cobalt/cobalt.o
162LOADADDR	:= 0xffffffff80080000
163endif
164
165#
166# DECstation family
167#
168ifdef CONFIG_DECSTATION
169CORE_FILES	+= arch/mips/dec/dec.o
170SUBDIRS		+= arch/mips/dec arch/mips/dec/prom
171LIBS		+= arch/mips/dec/prom/rexlib.a
172LOADADDR	:= 0xffffffff80040000
173endif
174
175#
176# Galileo EV64120 Board
177#
178ifdef CONFIG_MIPS_EV64120
179LIBS		+= arch/mips/gt64120/common/gt64120.o \
180		   arch/mips/gt64120/ev64120/ev64120.o
181SUBDIRS		+= arch/mips/gt64120/common arch/mips/gt64120/ev64120
182LOADADDR	:= 0xffffffff80100000
183endif
184
185#
186# MIPS Atlas board
187#
188ifdef CONFIG_MIPS_ATLAS
189LIBS		+= arch/mips/mips-boards/atlas/atlas.o \
190		   arch/mips/mips-boards/generic/mipsboards.o
191SUBDIRS		+= arch/mips/mips-boards/generic arch/mips/mips-boards/atlas
192LOADADDR	:= 0xffffffff80100000
193endif
194
195#
196# MIPS Malta board
197#
198ifdef CONFIG_MIPS_MALTA
199LIBS		+= arch/mips/mips-boards/malta/malta.o \
200		   arch/mips/mips-boards/generic/mipsboards.o
201SUBDIRS		+= arch/mips/mips-boards/malta arch/mips/mips-boards/generic
202LOADADDR	:= 0xffffffff80100000
203endif
204
205#
206# MIPS SEAD board
207#
208ifdef CONFIG_MIPS_SEAD
209LIBS		+= arch/mips/mips-boards/sead/sead.o \
210		   arch/mips/mips-boards/generic/mipsboards.o
211SUBDIRS		+= arch/mips/mips-boards/generic arch/mips/mips-boards/sead
212LOADADDR	:= 0xffffffff80100000
213endif
214
215#
216# Momentum Ocelot board
217#
218ifdef CONFIG_MOMENCO_OCELOT
219# The Ocelot setup.o must be linked early - it does the ioremap() for the
220# mips_io_port_base.
221CORE_FILES      += arch/mips/gt64120/common/gt64120.o \
222		   arch/mips/gt64120/momenco_ocelot/momenco_ocelot.o
223SUBDIRS		+= arch/mips/gt64120/common arch/mips/gt64120/momenco_ocelot
224LOADADDR	:= 0xffffffff80100000
225endif
226
227#
228# Momentum Ocelot-G board
229#
230ifdef CONFIG_MOMENCO_OCELOT_G
231# The Ocelot-G setup.o must be linked early - it does the ioremap() for the
232# mips_io_port_base.
233CORE_FILES	+= arch/mips/momentum/ocelot_g/ocelot_g.o
234SUBDIRS		+= arch/mips/momentum/ocelot_g
235LOADADDR	:= 0xffffffff80100000
236endif
237
238#
239# Momentum Ocelot-C and -CS boards
240#
241ifdef CONFIG_MOMENCO_OCELOT_C
242CORE_FILES	+= arch/mips/momentum/ocelot_c/ocelot_c.o
243SUBDIRS		+= arch/mips/momentum/ocelot_c
244LOADADDR	:= 0xffffffff80100000
245endif
246
247ifdef CONFIG_MOMENCO_JAGUAR_ATX
248LIBS		+= arch/mips/momentum/jaguar_atx/jaguar_atx.o
249SUBDIRS		+= arch/mips/momentum/jaguar_atx
250ifdef CONFIG_JAGUAR_DMALOW
251LOADADDR	:= 0xffffffff88000000
252else
253LOADADDR	:= 0xffffffff80100000
254endif
255endif
256
257ifdef CONFIG_PCI
258CORE_FILES    += arch/mips/pci/pci-core.o
259SUBDIRS       += arch/mips/pci
260endif
261
262#
263# SGI IP22 (Indy/Indigo2)
264#
265ifdef CONFIG_SGI_IP22
266CORE_FILES	+= arch/mips/sgi-ip22/ip22-kern.o
267LIBS		+= arch/mips/arc/arclib.a
268SUBDIRS		+= arch/mips/sgi-ip22 arch/mips/arc
269#
270# Set LOADADDR to >= 0xffffffff88069000 if you want to leave space for symmon,
271# 0xffffffff88004000 for production kernels.  Note that the value must be
272# 16kb aligned or the handling of the current variable will break.
273#
274LOADADDR	:= 0xffffffff88004000
275endif
276
277#
278# SGI-IP27 (Origin200/2000)
279#
280ifdef CONFIG_SGI_IP27
281CORE_FILES	+= arch/mips/sgi-ip27/ip27.o
282LIBS		+= arch/mips/arc/arclib.a
283SUBDIRS		+= arch/mips/sgi-ip27 arch/mips/arc
284#
285# Set LOADADDR to >= 0xc000000000300000 if you want to leave space for
286# symmon, 0xc00000000001c000 for production kernels.  Note that the value
287# must be 16kb aligned or the handling of the current variable will break.
288#
289ifdef CONFIG_BUILD_ELF64
290ifdef CONFIG_MAPPED_KERNEL
291LOADADDR	:= 0xc00000004001c000
292OBJCOPYFLAGS	:= --change-addresses=0x3fffffff80000000
293else
294LOADADDR	:= 0xa80000000001c000
295OBJCOPYFLAGS	:= --change-addresses=0x57ffffff80000000
296endif
297else
298ifdef CONFIG_MAPPED_KERNEL
299LOADADDR	:= 0xffffffffc001c000
300OBJCOPYFLAGS	:= --change-addresses=0xc000000080000000
301else
302LOADADDR	:= 0xffffffff8001c000
303OBJCOPYFLAGS	:= --change-addresses=0xa800000080000000
304endif
305endif
306endif
307
308#
309# Sibyte SB1250 SOC and Broadcom (SiByte) BCM112x SOCs
310#
311ifneq ($(CONFIG_SIBYTE_SB1250)$(CONFIG_SIBYTE_BCM112X),)
312# This is a LIB so that it links at the end, and initcalls are later
313# the sequence; but it is built as an object so that modules don't get
314# removed (as happens, even if they have __initcall/module_init)
315LIBS		+= arch/mips/sibyte/sb1250/sb1250.o
316SUBDIRS		+= arch/mips/sibyte/sb1250
317ifdef CONFIG_MIPS_UNCACHED
318LOADADDR	:= 0xffffffffa0100000
319else
320LOADADDR	:= 0xffffffff80100000
321endif
322endif
323
324#
325# Sibyte boards:
326#
327# BCM91250A (SWARM),
328# BCM91250E (Sentosa),
329# BCM91120C (CRhine),
330# BCM91120x (Carmel),
331# BCM91125C (CRhone),
332# BCM91125E (Rhone).
333#
334ifdef CONFIG_SIBYTE_BOARD
335LIBS		+= arch/mips/sibyte/swarm/sbswarm.a
336SUBDIRS		+= arch/mips/sibyte/swarm
337endif
338
339#
340# Sibyte CFE firmware
341#
342ifdef CONFIG_SIBYTE_CFE
343LIBS		+= arch/mips/sibyte/cfe/cfe.a
344SUBDIRS		+= arch/mips/sibyte/cfe
345endif
346
347
348ifdef CONFIG_CPU_LITTLE_ENDIAN
34932bit-bfd = elf32-tradlittlemips
35064bit-bfd = elf64-tradlittlemips
35132bit-emul = elf32ltsmip
35264bit-emul = elf64ltsmip
353else
35432bit-bfd = elf32-tradbigmips
35564bit-bfd = elf64-tradbigmips
35632bit-emul = elf32btsmip
35764bit-emul = elf64btsmip
358endif
359
360ifdef CONFIG_BUILD_ELF64
361GCCFLAGS += -Wa,-64
362LOADSCRIPT = arch/mips64/ld.script.elf64
363ld-emul = $(64bit-emul)
364vmlinux-32 = vmlinux.32
365vmlinux-64 = vmlinux
366else
367GCCFLAGS += $(call check_gcc,-mno-explicit-relocs,)
368GCCFLAGS += -Wa,-32 $(call check_gas,-Wa$(comma)-mgp64,)
369LOADSCRIPT = arch/mips64/ld.script.elf32
370ld-emul = $(32bit-emul)
371vmlinux-32 = vmlinux
372vmlinux-64 = vmlinux.64
373endif
374
375
376AFLAGS		+= $(GCCFLAGS)
377CFLAGS		+= $(GCCFLAGS)
378
379LD		+= -m $(ld-emul)
380
381
382LINKFLAGS += -T $(LOADSCRIPT) -Ttext $(LOADADDR)
383OBJCOPYFLAGS += --remove-section=.reginfo
384
385HEAD := arch/mips64/kernel/head.o arch/mips64/kernel/init_task.o
386
387SUBDIRS := $(addprefix arch/mips/, tools) $(SUBDIRS) $(addprefix arch/mips64/, kernel mm lib)
388CORE_FILES := arch/mips64/kernel/kernel.o arch/mips64/mm/mm.o $(CORE_FILES)
389LIBS := arch/mips64/lib/lib.a $(LIBS)
390
391MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot VMLINUX=$(TOPDIR)/$(vmlinux-32)
392
393arch/mips64/ld.script.elf32: arch/mips64/ld.script.elf32.S
394	$(CPP) -C -P -I$(HPATH) -imacros $(HPATH)/asm-mips64/sn/mapped_kernel.h -Umips arch/mips64/ld.script.elf32.S > arch/mips64/ld.script.elf32
395
396vmlinux: $(LOADSCRIPT)
397
398#
399# Some machines like the Indy need 32-bit ELF binaries for booting purposes.
400# Other need ECOFF, so we build a 32-bit ELF binary for them which we then
401# convert to ECOFF using elf2ecoff.
402#
403vmlinux.32: vmlinux
404	$(OBJCOPY) -O $(32bit-bfd) $(OBJCOPYFLAGS) $< $@
405
406#
407# The 64-bit ELF tools are pretty broken so at this time we generate 64-bit
408# ELF files from 32-bit files by conversion.
409#
410vmlinux.64: vmlinux
411	$(OBJCOPY) -O $(64bit-bfd) $(OBJCOPYFLAGS) $< $@
412
413ifdef CONFIG_BOOT_ELF32
414boot: $(vmlinux-32)
415endif
416
417ifdef CONFIG_BOOT_ELF64
418boot: $(vmlinux-64)
419endif
420
421boot: mips-boot
422
423mips-boot: $(vmlinux-32)
424	@$(MAKEBOOT) boot
425
426vmlinux.ecoff: $(vmlinux-32)
427	@$(MAKEBOOT) $@
428
429vmlinux.srec: $(vmlinux-32)
430	@$(MAKEBOOT) $@
431
432archclean:
433	@$(MAKEBOOT) clean
434	$(MAKE) -C arch/mips/tools clean
435	rm -f vmlinux.32 vmlinux.64 arch/$(ARCH)/ld.script.elf32
436
437archmrproper:
438	@$(MAKEBOOT) mrproper
439	$(MAKE) -C arch/mips/tools mrproper
440	$(RM) $(TOPDIR)/include/asm-$(ARCH)/offset.h
441
442archdep:
443	if [ ! -f $(TOPDIR)/include/asm-$(ARCH)/offset.h ]; then \
444		touch $(TOPDIR)/include/asm-$(ARCH)/offset.h; \
445	fi;
446	@$(MAKEBOOT) dep
447