Subversion Repositories HelenOS

Rev

Rev 3803 | Rev 3918 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
452 decky 1
#
2071 jermar 2
# Copyright (c) 2005 Martin Decky
452 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
 
550 palkovsky 30
## Include configuration
452 decky 31
#
32
 
3803 decky 33
include ../version
34
-include ../Makefile.config
3884 decky 35
-include ../config.defs
452 decky 36
 
2460 jermar 37
INCLUDES = generic/include
3105 svoboda 38
OPTIMIZATION = 3
2460 jermar 39
 
3884 decky 40
ifndef CROSS_PREFIX
41
	CROSS_PREFIX = /usr/local
42
endif
43
 
452 decky 44
## Common compiler flags
45
#
46
 
3884 decky 47
DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DNAME=$(NAME)"
2453 jermar 48
 
3884 decky 49
GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
3172 jermar 50
	-fno-builtin -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Werror \
3486 decky 51
	-nostdlib -nostdinc -pipe
2453 jermar 52
 
3884 decky 53
ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
3172 jermar 54
	-fno-builtin -Wall -Wmissing-prototypes -Werror \
2460 jermar 55
	-nostdlib -nostdinc \
56
	-wd170
57
 
58
SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
2462 jermar 59
	-xnolib -xc99=all -features=extensions \
2454 jermar 60
	-erroff=E_ZERO_SIZED_STRUCT_UNION
61
 
452 decky 62
LFLAGS = -M
462 decky 63
AFLAGS =
452 decky 64
 
3884 decky 65
-include arch/$(KARCH)/Makefile.inc
558 palkovsky 66
-include genarch/Makefile.inc
1 jermar 67
 
2602 jermar 68
## The at-sign
69
#
2603 jermar 70
# The $(ATSIGN) variable holds the ASCII character representing the at-sign
2602 jermar 71
# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
72
# don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
73
# those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
74
# defined as the percentile-sign ('%') in the architecture-dependent
75
# Makefile.inc.
76
#
77
ATSIGN ?= @
78
 
79
## Cross-platform assembly to start a symtab.data section
80
#
81
SYMTAB_SECTION=".section symtab.data, \"a\", $(ATSIGN)progbits;"
82
 
2489 jermar 83
## Simple detection for the type of the host system
84
#
85
HOST = $(shell uname)
86
 
87
## On Solaris, some utilities have slightly different names
88
#
89
ifeq ($(HOST),SunOS)
90
	BINUTILS_PREFIX = "g"
91
else
92
	BINUTILS_PREFIX = ""
93
endif
94
 
452 decky 95
## Toolchain configuration
96
#
97
 
2437 decky 98
ifeq ($(COMPILER),gcc_native)
452 decky 99
	CC = gcc
2455 jermar 100
	GCC = gcc
2489 jermar 101
	AS = $(BINUTILS_PREFIX)as
102
	LD = $(BINUTILS_PREFIX)ld
103
	OBJCOPY = $(BINUTILS_PREFIX)objcopy
104
	OBJDUMP = $(BINUTILS_PREFIX)objdump
2125 decky 105
	LIBDIR = /usr/lib
2454 jermar 106
	CFLAGS = $(GCC_CFLAGS)
3884 decky 107
	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
2437 decky 108
endif
109
 
110
ifeq ($(COMPILER),icc_native)
111
	CC = icc
2455 jermar 112
	GCC = gcc
2437 decky 113
	AS = as
114
	LD = ld
115
	OBJCOPY = objcopy
116
	OBJDUMP = objdump
117
	LIBDIR = /usr/lib
2460 jermar 118
	CFLAGS = $(ICC_CFLAGS)
3884 decky 119
	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
2437 decky 120
endif
121
 
2443 jermar 122
ifeq ($(COMPILER),suncc_native)
123
	CC = suncc
2455 jermar 124
	GCC = gcc
2489 jermar 125
	AS = $(BINUTILS_PREFIX)as
126
	LD = $(BINUTILS_PREFIX)ld
127
	OBJCOPY = $(BINUTILS_PREFIX)objcopy
128
	OBJDUMP = $(BINUTILS_PREFIX)objdump
2443 jermar 129
	LIBDIR = /usr/lib
2454 jermar 130
	CFLAGS = $(SUNCC_CFLAGS)
3884 decky 131
	DEFS += $(CONFIG_DEFS)
132
	DEPEND_DEFS = $(DEFS)
2443 jermar 133
endif
134
 
2437 decky 135
ifeq ($(COMPILER),gcc_cross)
2125 decky 136
	CC = $(TOOLCHAIN_DIR)/bin/$(TARGET)-gcc
2455 jermar 137
	GCC = $(CC)
2125 decky 138
	AS = $(TOOLCHAIN_DIR)/bin/$(TARGET)-as
139
	LD = $(TOOLCHAIN_DIR)/bin/$(TARGET)-ld
140
	OBJCOPY = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objcopy
141
	OBJDUMP = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objdump
142
	LIBDIR = $(TOOLCHAIN_DIR)/lib
2454 jermar 143
	CFLAGS = $(GCC_CFLAGS)
3884 decky 144
	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
452 decky 145
endif
146
 
147
## Generic kernel sources
148
#
149
 
150
GENERIC_SOURCES = \
2500 jermar 151
	generic/src/adt/avl.c \
1200 jermar 152
	generic/src/adt/bitmap.c \
1101 jermar 153
	generic/src/adt/btree.c \
790 jermar 154
	generic/src/adt/hash_table.c \
788 jermar 155
	generic/src/adt/list.c \
510 jermar 156
	generic/src/console/chardev.c \
157
	generic/src/console/console.c \
452 decky 158
	generic/src/cpu/cpu.c \
1178 jermar 159
	generic/src/ddi/ddi.c \
1920 jermar 160
	generic/src/ddi/irq.c \
161
	generic/src/ddi/device.c \
575 palkovsky 162
	generic/src/interrupt/interrupt.c \
430 jermar 163
	generic/src/main/main.c \
164
	generic/src/main/kinit.c \
165
	generic/src/main/uinit.c \
673 jermar 166
	generic/src/main/version.c \
2227 decky 167
	generic/src/main/shutdown.c \
3222 svoboda 168
	generic/src/proc/program.c \
430 jermar 169
	generic/src/proc/scheduler.c \
170
	generic/src/proc/thread.c \
171
	generic/src/proc/task.c \
172
	generic/src/proc/the.c \
2746 decky 173
	generic/src/proc/tasklet.c \
678 decky 174
	generic/src/syscall/syscall.c \
1288 jermar 175
	generic/src/syscall/copy.c \
430 jermar 176
	generic/src/mm/buddy.c \
177
	generic/src/mm/frame.c \
178
	generic/src/mm/page.c \
179
	generic/src/mm/tlb.c \
703 jermar 180
	generic/src/mm/as.c \
1424 jermar 181
	generic/src/mm/backend_anon.c \
182
	generic/src/mm/backend_elf.c \
183
	generic/src/mm/backend_phys.c \
759 palkovsky 184
	generic/src/mm/slab.c \
430 jermar 185
	generic/src/lib/func.c \
186
	generic/src/lib/memstr.c \
187
	generic/src/lib/sort.c \
938 jermar 188
	generic/src/lib/elf.c \
2000 decky 189
	generic/src/lib/rd.c \
1273 cejka 190
	generic/src/printf/printf_core.c \
191
	generic/src/printf/printf.c \
192
	generic/src/printf/sprintf.c \
193
	generic/src/printf/snprintf.c \
194
	generic/src/printf/vprintf.c \
195
	generic/src/printf/vsprintf.c \
196
	generic/src/printf/vsnprintf.c \
430 jermar 197
	generic/src/debug/symtab.c \
198
	generic/src/time/clock.c \
199
	generic/src/time/timeout.c \
200
	generic/src/time/delay.c \
201
	generic/src/preempt/preemption.c \
202
	generic/src/synch/spinlock.c \
203
	generic/src/synch/condvar.c \
204
	generic/src/synch/rwlock.c \
205
	generic/src/synch/mutex.c \
206
	generic/src/synch/semaphore.c \
3222 svoboda 207
	generic/src/synch/smc.c \
430 jermar 208
	generic/src/synch/waitq.c \
1109 jermar 209
	generic/src/synch/futex.c \
955 palkovsky 210
	generic/src/smp/ipi.c \
1901 jermar 211
	generic/src/smp/smp.c \
965 palkovsky 212
	generic/src/ipc/ipc.c \
1072 palkovsky 213
	generic/src/ipc/sysipc.c \
1174 jermar 214
	generic/src/ipc/ipcrsc.c \
1281 palkovsky 215
	generic/src/ipc/irq.c \
1317 vana 216
	generic/src/security/cap.c \
217
	generic/src/sysinfo/sysinfo.c
1 jermar 218
 
3703 decky 219
## Kernel console support
220
#
221
 
222
ifeq ($(CONFIG_KCONSOLE),y)
223
GENERIC_SOURCES += \
224
	generic/src/console/kconsole.c \
225
	generic/src/console/cmd.c
226
endif
227
 
3438 svoboda 228
## Udebug interface sources
229
#
230
 
231
ifeq ($(CONFIG_UDEBUG),y)
232
GENERIC_SOURCES += \
3445 jermar 233
	generic/src/ipc/kbox.c \
3438 svoboda 234
	generic/src/udebug/udebug.c \
235
	generic/src/udebug/udebug_ops.c \
236
	generic/src/udebug/udebug_ipc.c
237
endif
238
 
459 decky 239
## Test sources
240
#
241
 
2020 decky 242
ifeq ($(CONFIG_TEST),y)
2019 decky 243
	CFLAGS += -Itest/
244
	GENERIC_SOURCES += \
245
		test/test.c \
2020 decky 246
		test/atomic/atomic1.c \
247
		test/btree/btree1.c \
2500 jermar 248
		test/avltree/avltree1.c \
2020 decky 249
		test/debug/mips1.c \
250
		test/fault/fault1.c \
2021 decky 251
		test/mm/falloc1.c \
252
		test/mm/falloc2.c \
253
		test/mm/mapping1.c \
254
		test/mm/slab1.c \
255
		test/mm/slab2.c \
2022 decky 256
		test/mm/purge1.c \
257
		test/synch/rwlock1.c \
258
		test/synch/rwlock2.c \
259
		test/synch/rwlock3.c \
260
		test/synch/rwlock4.c \
261
		test/synch/rwlock5.c \
262
		test/synch/semaphore1.c \
263
		test/synch/semaphore2.c \
264
		test/print/print1.c \
265
		test/thread/thread1.c \
266
		test/sysinfo/sysinfo1.c
3884 decky 267
 
268
	ifeq ($(CONFIG_FPU),y)
269
		ifeq ($(KARCH),ia32)
270
			TEST_FPU1 = y
271
			TEST_SSE1 = y
272
		endif
273
 
274
		ifeq ($(KARCH),amd64)
275
			TEST_FPU1 = y
276
			TEST_SSE1 = y
277
		endif
278
 
279
		ifeq ($(KARCH),ia64)
280
			TEST_FPU1 = y
281
		endif
282
 
283
		ifeq ($(KARCH),mips32)
284
			TEST_MIPS2 = y
285
		endif
286
	endif
287
 
288
	ifeq ($(TEST_FPU1),y)
289
		GENERIC_SOURCES += test/fpu/fpu1.c
290
	else
291
		GENERIC_SOURCES += test/fpu/fpu1_skip.c
292
	endif
293
 
294
	ifeq ($(TEST_SSE1),y)
295
		GENERIC_SOURCES += test/fpu/sse1.c
296
	else
297
		GENERIC_SOURCES += test/fpu/sse1_skip.c
298
	endif
299
 
300
	ifeq ($(TEST_MIPS2),y)
301
		GENERIC_SOURCES += test/fpu/mips2.c
302
	else
303
		GENERIC_SOURCES += test/fpu/mips2_skip.c
304
	endif
305
 
459 decky 306
endif
307
 
452 decky 308
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
309
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
310
GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
326 palkovsky 311
 
3803 decky 312
.PHONY: all build clean archlinks depend disasm
1 jermar 313
 
3884 decky 314
all: ../Makefile.config ../config.h ../config.defs
3803 decky 315
	-rm Makefile.depend
561 decky 316
	$(MAKE) -C . build
34 jermar 317
 
1017 decky 318
build: kernel.bin disasm
558 palkovsky 319
 
452 decky 320
-include Makefile.depend
1 jermar 321
 
452 decky 322
clean:
3884 decky 323
	-rm -f kernel.bin kernel.raw kernel.map kernel.map.pre kernel.objdump kernel.disasm generic/src/debug/real_map.bin Makefile.depend* generic/include/arch generic/include/genarch arch/$(KARCH)/_link.ld
558 palkovsky 324
	find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
1802 decky 325
	for arch in arch/* ; do \
326
	    [ -e $$arch/_link.ld ] && rm $$arch/_link.ld 2>/dev/null ; \
327
	done ; exit 0
1 jermar 328
 
558 palkovsky 329
archlinks:
3884 decky 330
	ln -sfn ../../arch/$(KARCH)/include/ generic/include/arch
452 decky 331
	ln -sfn ../../genarch/include/ generic/include/genarch
1 jermar 332
 
577 palkovsky 333
depend: archlinks
3884 decky 334
	-makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null
576 palkovsky 335
 
3884 decky 336
arch/$(KARCH)/_link.ld: arch/$(KARCH)/_link.ld.in
2455 jermar 337
	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
1 jermar 338
 
3884 decky 339
generic/src/debug/real_map.bin: depend arch/$(KARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
2602 jermar 340
	echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o generic/src/debug/empty_map.o
3884 decky 341
	$(LD) -T arch/$(KARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) generic/src/debug/empty_map.o  -o $@ -Map kernel.map.pre
452 decky 342
	$(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
430 jermar 343
	tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin 
602 palkovsky 344
	# Do it once again, this time to get correct even the symbols
345
	# on architectures, that have bss after symtab
2602 jermar 346
	echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o generic/src/debug/sizeok_map.o
3884 decky 347
	$(LD) -T arch/$(KARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) generic/src/debug/sizeok_map.o -o $@ -Map kernel.map.pre
602 palkovsky 348
	$(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
349
	tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin 
293 palkovsky 350
 
430 jermar 351
generic/src/debug/real_map.o: generic/src/debug/real_map.bin
2602 jermar 352
	echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@ 
293 palkovsky 353
 
3884 decky 354
kernel.raw: depend arch/$(KARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o
355
	$(LD) -T arch/$(KARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) generic/src/debug/real_map.o -o $@ -Map kernel.map
293 palkovsky 356
 
461 decky 357
kernel.bin: kernel.raw
358
	$(OBJCOPY) -O $(BFD) kernel.raw kernel.bin
359
 
472 jermar 360
disasm: kernel.raw
361
	$(OBJDUMP) -d kernel.raw > kernel.disasm
362
 
314 palkovsky 363
%.o: %.S
2455 jermar 364
	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
1 jermar 365
 
366
%.o: %.s
455 decky 367
	$(AS) $(AFLAGS) $< -o $@
1 jermar 368
 
3179 jermar 369
#
370
# The FPU tests are the only objects for which we allow the compiler to generate
371
# FPU instructions.
372
#
373
test/fpu/%.o: test/fpu/%.c
374
	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@
375
 
376
#
377
# Ordinary objects.
378
#
1 jermar 379
%.o: %.c
3179 jermar 380
	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) -c $< -o $@