Subversion Repositories HelenOS

Rev

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