source: mainline/kernel/Makefile@ 3d9d948

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3d9d948 was 7a0359b, checked in by Martin Decky <martin@…>, 15 years ago

improve kernel function tracing

  • add support for more generic kernel sources
  • replace attribute((no_instrument_function)) with NO_TRACE macro (shorter and for future compatibility with different compilers)
  • to be on the safe side, do not instrument most of the inline and static functions (plus some specific non-static functions)

collateral code cleanup (no change in functionality)

  • Property mode set to 100644
File size: 13.6 KB
Line 
1#
2# Copyright (c) 2005 Martin Decky
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29## Configuration
30#
31
32ROOT_PATH = ..
33
34VERSION_DEF = $(ROOT_PATH)/version
35
36COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
37COMMON_HEADER = $(ROOT_PATH)/common.h
38COMMON_HEADER_ARCH = arch/$(KARCH)/include/common.h
39
40CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
41CONFIG_HEADER = $(ROOT_PATH)/config.h
42
43-include $(VERSION_DEF)
44-include $(COMMON_MAKEFILE)
45-include $(CONFIG_MAKEFILE)
46
47## Common names
48#
49
50DEPEND = Makefile.depend
51DEPEND_PREV = $(DEPEND).prev
52RAW = kernel.raw
53BIN = kernel.bin
54MAP = kernel.map
55JOB = kernel.job
56MAP_PREV = $(MAP).prev
57DISASM = kernel.disasm
58DUMP = kernel.dump
59REAL_MAP = generic/src/debug/real_map
60
61ARCH_INCLUDE = generic/include/arch
62GENARCH_INCLUDE = generic/include/genarch
63
64GENMAP = tools/genmap.py
65JOBFILE = $(ROOT_PATH)/tools/jobfile.py
66
67LINK = arch/$(KARCH)/_link.ld
68EMPTY_MAP = generic/src/debug/empty_map.o
69SIZEOK_MAP = generic/src/debug/sizeok_map.o
70
71.PHONY: all clean
72
73all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BIN) $(DISASM)
74 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
75
76clean:
77 rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* $(ARCH_INCLUDE) $(GENARCH_INCLUDE) arch/*/_link.ld arch/*/include/common.h
78 find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
79
80## Common compiler flags
81#
82
83INCLUDES = generic/include
84
85ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
86 OPTIMIZATION = s
87else
88 OPTIMIZATION = 3
89endif
90
91DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
92
93GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
94 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
95 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
96 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
97 -Werror-implicit-function-declaration -Wwrite-strings \
98 -pipe
99
100ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
101 -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
102 -Werror-implicit-function-declaration -wd170
103
104SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
105 -xnolib -xc99=all -features=extensions \
106 -erroff=E_ZERO_SIZED_STRUCT_UNION
107
108CLANG_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
109 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
110 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
111 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
112 -Werror-implicit-function-declaration -Wwrite-strings \
113 -pipe -arch $(CLANG_ARCH)
114
115ifeq ($(CONFIG_DEBUG),y)
116 GCC_CFLAGS += -Werror
117 ICC_CFLAGS += -Werror
118endif
119
120ifeq ($(CONFIG_LTO),y)
121 GCC_CFLAGS += -flto
122endif
123
124#
125# Mind the mutual ordering with the inclusion of the arch Makefile.inc.
126# AFLAGS and LFLAGS must be initialized before the inclusion.
127#
128AFLAGS =
129LFLAGS = -N -T $(LINK) -M
130
131#
132# Mind the mutual ordering with the initialization of AFLAGS and LFLAGS.
133# The arch Makefile.inc must be included after the initialization.
134#
135-include arch/$(KARCH)/Makefile.inc
136-include genarch/Makefile.inc
137-include $(DEPEND)
138
139## The at-sign
140#
141# The $(ATSIGN) variable holds the ASCII character representing the at-sign
142# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
143# don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
144# those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
145# defined as the percentile-sign ('%') in the architecture-dependent
146# Makefile.inc.
147#
148
149ATSIGN ?= @
150
151## Cross-platform assembly to start a symtab.data section
152#
153
154SYMTAB_SECTION = ".section symtab.data, \"a\", $(ATSIGN)progbits;"
155
156## Compilation options
157#
158
159ifeq ($(COMPILER),gcc_native)
160 CFLAGS = $(GCC_CFLAGS)
161 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
162 INSTRUMENTATION = -finstrument-functions
163endif
164
165ifeq ($(COMPILER),gcc_cross)
166 CFLAGS = $(GCC_CFLAGS)
167 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
168 INSTRUMENTATION = -finstrument-functions
169endif
170
171ifeq ($(COMPILER),icc)
172 CFLAGS = $(ICC_CFLAGS)
173 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
174 INSTRUMENTATION =
175endif
176
177ifeq ($(COMPILER),suncc)
178 CFLAGS = $(SUNCC_CFLAGS)
179 DEFS += $(CONFIG_DEFS)
180 DEPEND_DEFS = $(DEFS)
181 INSTRUMENTATION =
182endif
183
184ifeq ($(COMPILER),clang)
185 CFLAGS = $(CLANG_CFLAGS)
186 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
187 INSTRUMENTATION =
188endif
189
190
191## Generic kernel sources
192#
193
194GENERIC_SOURCES = \
195 generic/src/adt/avl.c \
196 generic/src/adt/bitmap.c \
197 generic/src/adt/btree.c \
198 generic/src/adt/hash_table.c \
199 generic/src/adt/list.c \
200 generic/src/console/chardev.c \
201 generic/src/console/console.c \
202 generic/src/cpu/cpu.c \
203 generic/src/ddi/ddi.c \
204 generic/src/ddi/irq.c \
205 generic/src/ddi/device.c \
206 generic/src/debug/symtab.c \
207 generic/src/debug/stacktrace.c \
208 generic/src/debug/panic.c \
209 generic/src/debug/debug.c \
210 generic/src/interrupt/interrupt.c \
211 generic/src/main/main.c \
212 generic/src/main/kinit.c \
213 generic/src/main/uinit.c \
214 generic/src/main/version.c \
215 generic/src/main/shutdown.c \
216 generic/src/proc/program.c \
217 generic/src/proc/scheduler.c \
218 generic/src/proc/thread.c \
219 generic/src/proc/task.c \
220 generic/src/proc/the.c \
221 generic/src/proc/tasklet.c \
222 generic/src/syscall/syscall.c \
223 generic/src/syscall/copy.c \
224 generic/src/mm/buddy.c \
225 generic/src/mm/frame.c \
226 generic/src/mm/page.c \
227 generic/src/mm/tlb.c \
228 generic/src/mm/as.c \
229 generic/src/mm/backend_anon.c \
230 generic/src/mm/backend_elf.c \
231 generic/src/mm/backend_phys.c \
232 generic/src/mm/slab.c \
233 generic/src/lib/func.c \
234 generic/src/lib/memstr.c \
235 generic/src/lib/sort.c \
236 generic/src/lib/str.c \
237 generic/src/lib/elf.c \
238 generic/src/lib/rd.c \
239 generic/src/printf/printf_core.c \
240 generic/src/printf/printf.c \
241 generic/src/printf/snprintf.c \
242 generic/src/printf/vprintf.c \
243 generic/src/printf/vsnprintf.c \
244 generic/src/time/clock.c \
245 generic/src/time/timeout.c \
246 generic/src/time/delay.c \
247 generic/src/preempt/preemption.c \
248 generic/src/synch/spinlock.c \
249 generic/src/synch/condvar.c \
250 generic/src/synch/mutex.c \
251 generic/src/synch/semaphore.c \
252 generic/src/synch/smc.c \
253 generic/src/synch/waitq.c \
254 generic/src/synch/futex.c \
255 generic/src/smp/ipi.c \
256 generic/src/smp/smp.c \
257 generic/src/ipc/ipc.c \
258 generic/src/ipc/sysipc.c \
259 generic/src/ipc/ipcrsc.c \
260 generic/src/ipc/irq.c \
261 generic/src/ipc/event.c \
262 generic/src/security/cap.c \
263 generic/src/sysinfo/sysinfo.c \
264 generic/src/sysinfo/stats.c
265
266## Kernel console support
267#
268
269ifeq ($(CONFIG_KCONSOLE),y)
270GENERIC_SOURCES += \
271 generic/src/console/kconsole.c \
272 generic/src/console/cmd.c
273endif
274
275## Udebug interface sources
276#
277
278ifeq ($(CONFIG_UDEBUG),y)
279GENERIC_SOURCES += \
280 generic/src/ipc/kbox.c \
281 generic/src/udebug/udebug.c \
282 generic/src/udebug/udebug_ops.c \
283 generic/src/udebug/udebug_ipc.c
284endif
285
286## Test sources
287#
288
289ifeq ($(CONFIG_TEST),y)
290 CFLAGS += -Itest/
291 GENERIC_SOURCES += \
292 test/test.c \
293 test/atomic/atomic1.c \
294 test/btree/btree1.c \
295 test/avltree/avltree1.c \
296 test/fault/fault1.c \
297 test/mm/falloc1.c \
298 test/mm/falloc2.c \
299 test/mm/mapping1.c \
300 test/mm/slab1.c \
301 test/mm/slab2.c \
302 test/synch/semaphore1.c \
303 test/synch/semaphore2.c \
304 test/print/print1.c \
305 test/print/print2.c \
306 test/print/print3.c \
307 test/print/print4.c \
308 test/thread/thread1.c
309
310 ifeq ($(KARCH),mips32)
311 GENERIC_SOURCES += test/debug/mips1.c
312 else
313 GENERIC_SOURCES += test/debug/mips1_skip.c
314 endif
315
316 ifeq ($(KARCH),ia64)
317 GENERIC_SOURCES += test/mm/purge1.c
318 else
319 GENERIC_SOURCES += test/mm/purge1_skip.c
320 endif
321
322 ifeq ($(CONFIG_FPU),y)
323 ifeq ($(KARCH),ia32)
324 TEST_FPU1 = y
325 TEST_SSE1 = y
326 GENERIC_SOURCES += test/fpu/fpu1_x86.c
327 endif
328
329 ifeq ($(KARCH),amd64)
330 TEST_FPU1 = y
331 TEST_SSE1 = y
332 GENERIC_SOURCES += test/fpu/fpu1_x86.c
333 endif
334
335 ifeq ($(KARCH),ia64)
336 TEST_FPU1 = y
337 GENERIC_SOURCES += test/fpu/fpu1_ia64.c
338 endif
339
340 ifeq ($(KARCH),mips32)
341 TEST_MIPS2 = y
342 endif
343 endif
344
345 ifneq ($(TEST_FPU1),y)
346 GENERIC_SOURCES += test/fpu/fpu1_skip.c
347 endif
348
349 ifeq ($(TEST_SSE1),y)
350 GENERIC_SOURCES += test/fpu/sse1.c
351 else
352 GENERIC_SOURCES += test/fpu/sse1_skip.c
353 endif
354
355 ifeq ($(TEST_MIPS2),y)
356 GENERIC_SOURCES += test/fpu/mips2.c
357 else
358 GENERIC_SOURCES += test/fpu/mips2_skip.c
359 endif
360
361endif
362
363## Sources where instrumentation is enabled
364#
365
366ifeq ($(CONFIG_TRACE),y)
367 INSTRUMENTED_SOURCES = \
368 generic/src/adt/btree.c \
369 generic/src/cpu/cpu.c \
370 generic/src/ddi/ddi.c \
371 generic/src/interrupt/interrupt.c \
372 generic/src/main/main.c \
373 generic/src/main/kinit.c \
374 generic/src/proc/the.c \
375 generic/src/proc/tasklet.c \
376 generic/src/mm/frame.c \
377 generic/src/mm/page.c \
378 generic/src/mm/tlb.c \
379 generic/src/mm/as.c \
380 generic/src/mm/slab.c \
381 generic/src/sysinfo/sysinfo.c \
382 generic/src/console/kconsole.c
383else
384 INSTRUMENTED_SOURCES =
385endif
386
387GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
388ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
389GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
390
391LFLAGS_LTO := $(addprefix -Xlinker ,$(LFLAGS))
392
393ifeq ($(CONFIG_SYMTAB),y)
394 SYMTAB_OBJECTS := generic/src/debug/real_map.o
395else
396 SYMTAB_OBJECTS :=
397endif
398
399$(BIN): $(RAW)
400 $(OBJCOPY) -O $(BFD) $< $@
401
402$(DISASM): $(RAW)
403 $(OBJDUMP) -d $< > $@
404
405$(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
406ifeq ($(CONFIG_LTO),y)
407 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
408else
409 $(LD) $(LFLAGS) -Map $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
410endif
411ifeq ($(CONFIG_STRIP_BINARIES),y)
412 $(STRIP) $(RAW)
413endif
414
415$(LINK): $(LINK).in $(DEPEND)
416 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
417
418%.o: %.S $(DEPEND)
419 $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c -o $@ $<
420ifeq ($(PRECHECK),y)
421 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(GCC_CFLAGS) -D__ASM__
422endif
423
424%.o: %.s $(DEPEND)
425 $(AS) $(AFLAGS) -o $@ $<
426ifeq ($(PRECHECK),y)
427 $(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
428endif
429
430#
431# The FPU tests are the only objects for which we allow the compiler to generate
432# FPU instructions.
433#
434
435test/fpu/%.o: test/fpu/%.c $(DEPEND)
436 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c -o $@ $<
437ifeq ($(PRECHECK),y)
438 $(JOBFILE) $(JOB) $< $@ cc test $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
439endif
440
441#
442# Ordinary objects.
443#
444
445%.o: %.c $(DEPEND)
446 $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) $(if $(findstring $<,$(INSTRUMENTED_SOURCES)),$(INSTRUMENTATION)) -c -o $@ $<
447ifeq ($(PRECHECK),y)
448 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS)
449endif
450
451$(REAL_MAP).o: $(REAL_MAP).bin
452 echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
453
454$(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
455 echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
456ifeq ($(CONFIG_LTO),y)
457 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
458else
459 $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
460endif
461 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
462 $(GENMAP) $(MAP_PREV) $(DUMP) $@
463
464 # Do it once again, this time to get correct even the symbols
465 # on architectures that have bss after symtab
466
467 echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
468ifeq ($(CONFIG_LTO),y)
469 $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
470else
471 $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
472endif
473 $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > $(DUMP)
474 $(GENMAP) $(MAP_PREV) $(DUMP) $@
475
476$(DEPEND): $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH)
477 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > $@ 2> /dev/null
478 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
479
480$(ARCH_INCLUDE): arch/$(KARCH)/include/
481 ln -sfn ../../$< $@
482
483$(GENARCH_INCLUDE): genarch/include/
484 ln -sfn ../../$< $@
485
486$(COMMON_HEADER_ARCH): $(COMMON_HEADER)
487 ln -sfn ../../../$< $@
Note: See TracBrowser for help on using the repository browser.