Subversion Repositories HelenOS

Rev

Rev 2603 | Rev 2746 | 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
 
1802 decky 33
-include ../version
558 palkovsky 34
-include Makefile.config
452 decky 35
 
2460 jermar 36
INCLUDES = generic/include
37
OPTIMIZATION = 3
38
 
452 decky 39
## Common compiler flags
40
#
41
 
2454 jermar 42
DEFS = -D$(ARCH) -DARCH=\"$(ARCH)\" -DRELEASE=\"$(RELEASE)\" "-DNAME=\"$(NAME)\"" \
43
	-DKERNEL
2453 jermar 44
 
2460 jermar 45
GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) \
2745 decky 46
	-fno-builtin -fomit-frame-pointer -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Werror \
2460 jermar 47
	-nostdlib -nostdinc
2453 jermar 48
 
2460 jermar 49
ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) \
50
	-fno-builtin -fomit-frame-pointer -Wall -Wmissing-prototypes -Werror \
51
	-nostdlib -nostdinc \
52
	-wd170
53
 
54
SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
2462 jermar 55
	-xnolib -xc99=all -features=extensions \
2454 jermar 56
	-erroff=E_ZERO_SIZED_STRUCT_UNION
57
 
452 decky 58
LFLAGS = -M
462 decky 59
AFLAGS =
452 decky 60
 
561 decky 61
ifdef REVISION
62
	DEFS += "-DREVISION=\"$(REVISION)\""
462 decky 63
endif
64
 
561 decky 65
ifdef TIMESTAMP
66
	DEFS += "-DTIMESTAMP=\"$(TIMESTAMP)\""
67
endif
68
 
558 palkovsky 69
-include arch/$(ARCH)/Makefile.inc
70
-include genarch/Makefile.inc
1 jermar 71
 
2602 jermar 72
## The at-sign
73
#
2603 jermar 74
# The $(ATSIGN) variable holds the ASCII character representing the at-sign
2602 jermar 75
# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
76
# don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
77
# those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
78
# defined as the percentile-sign ('%') in the architecture-dependent
79
# Makefile.inc.
80
#
81
ATSIGN ?= @
82
 
83
## Cross-platform assembly to start a symtab.data section
84
#
85
SYMTAB_SECTION=".section symtab.data, \"a\", $(ATSIGN)progbits;"
86
 
87
## Setup kernel configuration
88
#
471 decky 89
ifeq ($(CONFIG_DEBUG),y)
90
	DEFS += -DCONFIG_DEBUG
452 decky 91
endif
1802 decky 92
 
452 decky 93
ifeq ($(CONFIG_DEBUG_SPINLOCK),y)
458 decky 94
	DEFS += -DCONFIG_DEBUG_SPINLOCK
452 decky 95
endif
1802 decky 96
 
1072 palkovsky 97
ifeq ($(CONFIG_DEBUG_AS_WATCHPOINT),y)
98
	DEFS += -DCONFIG_DEBUG_AS_WATCHPOINT
99
endif
1802 decky 100
 
568 palkovsky 101
ifeq ($(CONFIG_FPU_LAZY),y)
102
	DEFS += -DCONFIG_FPU_LAZY
103
endif
1802 decky 104
 
1094 palkovsky 105
ifeq ($(CONFIG_DEBUG_ALLREGS),y)
106
	DEFS += -DCONFIG_DEBUG_ALLREGS
107
endif
1802 decky 108
 
1210 vana 109
ifeq ($(CONFIG_VHPT),y)
110
	DEFS += -DCONFIG_VHPT
111
endif
1802 decky 112
 
1891 jermar 113
ifeq ($(CONFIG_TSB),y)
114
	DEFS += -DCONFIG_TSB
115
endif
116
 
1896 jermar 117
ifeq ($(CONFIG_Z8530),y)
118
	DEFS += -DCONFIG_Z8530
119
endif
120
 
121
ifeq ($(CONFIG_NS16550),y)
122
	DEFS += -DCONFIG_NS16550
123
endif
124
 
2009 jermar 125
ifeq ($(CONFIG_VIRT_IDX_DCACHE),y)
126
	DEFS += -DCONFIG_VIRT_IDX_DCACHE
1996 jermar 127
endif
128
 
1287 vana 129
ifeq ($(CONFIG_FB),y)
1802 decky 130
	ifeq ($(ARCH),ia32)
131
		DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
132
		DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
133
		DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
134
	endif
135
 
136
	ifeq ($(ARCH),amd64)
137
		DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
138
		DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
139
		DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
140
	endif
141
 
1953 jermar 142
	ifeq ($(ARCH),ia32xen)
1802 decky 143
		DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
144
		DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
145
		DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
146
	endif
1287 vana 147
endif
452 decky 148
 
2489 jermar 149
## Simple detection for the type of the host system
150
#
151
HOST = $(shell uname)
152
 
153
## On Solaris, some utilities have slightly different names
154
#
155
ifeq ($(HOST),SunOS)
156
	BINUTILS_PREFIX = "g"
157
else
158
	BINUTILS_PREFIX = ""
159
endif
160
 
452 decky 161
## Toolchain configuration
162
#
163
 
2437 decky 164
ifeq ($(COMPILER),gcc_native)
452 decky 165
	CC = gcc
2455 jermar 166
	GCC = gcc
2489 jermar 167
	AS = $(BINUTILS_PREFIX)as
168
	LD = $(BINUTILS_PREFIX)ld
169
	OBJCOPY = $(BINUTILS_PREFIX)objcopy
170
	OBJDUMP = $(BINUTILS_PREFIX)objdump
2125 decky 171
	LIBDIR = /usr/lib
2454 jermar 172
	CFLAGS = $(GCC_CFLAGS)
2437 decky 173
endif
174
 
175
ifeq ($(COMPILER),icc_native)
176
	CC = icc
2455 jermar 177
	GCC = gcc
2437 decky 178
	AS = as
179
	LD = ld
180
	OBJCOPY = objcopy
181
	OBJDUMP = objdump
182
	LIBDIR = /usr/lib
2460 jermar 183
	CFLAGS = $(ICC_CFLAGS)
2437 decky 184
endif
185
 
2443 jermar 186
ifeq ($(COMPILER),suncc_native)
187
	CC = suncc
2455 jermar 188
	GCC = gcc
2489 jermar 189
	AS = $(BINUTILS_PREFIX)as
190
	LD = $(BINUTILS_PREFIX)ld
191
	OBJCOPY = $(BINUTILS_PREFIX)objcopy
192
	OBJDUMP = $(BINUTILS_PREFIX)objdump
2443 jermar 193
	LIBDIR = /usr/lib
2454 jermar 194
	CFLAGS = $(SUNCC_CFLAGS)
2443 jermar 195
endif
196
 
2437 decky 197
ifeq ($(COMPILER),gcc_cross)
2125 decky 198
	CC = $(TOOLCHAIN_DIR)/bin/$(TARGET)-gcc
2455 jermar 199
	GCC = $(CC)
2125 decky 200
	AS = $(TOOLCHAIN_DIR)/bin/$(TARGET)-as
201
	LD = $(TOOLCHAIN_DIR)/bin/$(TARGET)-ld
202
	OBJCOPY = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objcopy
203
	OBJDUMP = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objdump
204
	LIBDIR = $(TOOLCHAIN_DIR)/lib
2454 jermar 205
	CFLAGS = $(GCC_CFLAGS)
452 decky 206
endif
207
 
208
## Generic kernel sources
209
#
210
 
211
GENERIC_SOURCES = \
2500 jermar 212
	generic/src/adt/avl.c \
1200 jermar 213
	generic/src/adt/bitmap.c \
1101 jermar 214
	generic/src/adt/btree.c \
790 jermar 215
	generic/src/adt/hash_table.c \
788 jermar 216
	generic/src/adt/list.c \
510 jermar 217
	generic/src/console/chardev.c \
218
	generic/src/console/console.c \
518 jermar 219
	generic/src/console/kconsole.c \
1595 palkovsky 220
	generic/src/console/klog.c \
596 jermar 221
	generic/src/console/cmd.c \
452 decky 222
	generic/src/cpu/cpu.c \
1178 jermar 223
	generic/src/ddi/ddi.c \
1920 jermar 224
	generic/src/ddi/irq.c \
225
	generic/src/ddi/device.c \
575 palkovsky 226
	generic/src/interrupt/interrupt.c \
430 jermar 227
	generic/src/main/main.c \
228
	generic/src/main/kinit.c \
229
	generic/src/main/uinit.c \
673 jermar 230
	generic/src/main/version.c \
2227 decky 231
	generic/src/main/shutdown.c \
430 jermar 232
	generic/src/proc/scheduler.c \
233
	generic/src/proc/thread.c \
234
	generic/src/proc/task.c \
235
	generic/src/proc/the.c \
678 decky 236
	generic/src/syscall/syscall.c \
1288 jermar 237
	generic/src/syscall/copy.c \
430 jermar 238
	generic/src/mm/buddy.c \
239
	generic/src/mm/frame.c \
240
	generic/src/mm/page.c \
241
	generic/src/mm/tlb.c \
703 jermar 242
	generic/src/mm/as.c \
1424 jermar 243
	generic/src/mm/backend_anon.c \
244
	generic/src/mm/backend_elf.c \
245
	generic/src/mm/backend_phys.c \
759 palkovsky 246
	generic/src/mm/slab.c \
430 jermar 247
	generic/src/lib/func.c \
248
	generic/src/lib/memstr.c \
249
	generic/src/lib/sort.c \
938 jermar 250
	generic/src/lib/elf.c \
2000 decky 251
	generic/src/lib/rd.c \
1273 cejka 252
	generic/src/printf/printf_core.c \
253
	generic/src/printf/printf.c \
254
	generic/src/printf/sprintf.c \
255
	generic/src/printf/snprintf.c \
256
	generic/src/printf/vprintf.c \
257
	generic/src/printf/vsprintf.c \
258
	generic/src/printf/vsnprintf.c \
430 jermar 259
	generic/src/debug/symtab.c \
260
	generic/src/time/clock.c \
261
	generic/src/time/timeout.c \
262
	generic/src/time/delay.c \
263
	generic/src/preempt/preemption.c \
264
	generic/src/synch/spinlock.c \
265
	generic/src/synch/condvar.c \
266
	generic/src/synch/rwlock.c \
267
	generic/src/synch/mutex.c \
268
	generic/src/synch/semaphore.c \
269
	generic/src/synch/waitq.c \
1109 jermar 270
	generic/src/synch/futex.c \
955 palkovsky 271
	generic/src/smp/ipi.c \
1901 jermar 272
	generic/src/smp/smp.c \
965 palkovsky 273
	generic/src/ipc/ipc.c \
1072 palkovsky 274
	generic/src/ipc/sysipc.c \
1174 jermar 275
	generic/src/ipc/ipcrsc.c \
1281 palkovsky 276
	generic/src/ipc/irq.c \
1317 vana 277
	generic/src/security/cap.c \
278
	generic/src/sysinfo/sysinfo.c
1 jermar 279
 
459 decky 280
## Test sources
281
#
282
 
2020 decky 283
ifeq ($(CONFIG_TEST),y)
459 decky 284
	DEFS += -DCONFIG_TEST
2019 decky 285
	CFLAGS += -Itest/
286
	GENERIC_SOURCES += \
287
		test/test.c \
2020 decky 288
		test/atomic/atomic1.c \
289
		test/btree/btree1.c \
2500 jermar 290
		test/avltree/avltree1.c \
2020 decky 291
		test/debug/mips1.c \
292
		test/fault/fault1.c \
2021 decky 293
		test/fpu/fpu1.c \
294
		test/fpu/sse1.c \
295
		test/fpu/mips2.c \
296
		test/mm/falloc1.c \
297
		test/mm/falloc2.c \
298
		test/mm/mapping1.c \
299
		test/mm/slab1.c \
300
		test/mm/slab2.c \
2022 decky 301
		test/mm/purge1.c \
302
		test/synch/rwlock1.c \
303
		test/synch/rwlock2.c \
304
		test/synch/rwlock3.c \
305
		test/synch/rwlock4.c \
306
		test/synch/rwlock5.c \
307
		test/synch/semaphore1.c \
308
		test/synch/semaphore2.c \
309
		test/print/print1.c \
310
		test/thread/thread1.c \
311
		test/sysinfo/sysinfo1.c
459 decky 312
endif
313
 
2125 decky 314
## Experimental features
315
#
316
 
317
ifeq ($(CONFIG_EXPERIMENTAL),y)
2126 decky 318
	GENERIC_SOURCES += generic/src/lib/objc_ext.c \
319
		generic/src/lib/objc.c
2125 decky 320
	EXTRA_OBJECTS = $(LIBDIR)/libobjc.a
321
	EXTRA_FLAGS += -x objective-c
322
endif
323
 
452 decky 324
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
325
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
326
GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
326 palkovsky 327
 
1017 decky 328
.PHONY: all build config distclean clean archlinks depend disasm
1 jermar 329
 
558 palkovsky 330
all:
1802 decky 331
	../tools/config.py kernel.config default $(ARCH) $(COMPILER) $(CONFIG_DEBUG) $(MACHINE)
561 decky 332
	$(MAKE) -C . build
34 jermar 333
 
1017 decky 334
build: kernel.bin disasm
558 palkovsky 335
 
336
config:
580 palkovsky 337
	-rm Makefile.depend
2011 decky 338
	../tools/config.py kernel.config
558 palkovsky 339
 
452 decky 340
-include Makefile.depend
1 jermar 341
 
558 palkovsky 342
distclean: clean
343
	-rm Makefile.config
344
 
452 decky 345
clean:
576 palkovsky 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/$(ARCH)/_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:
452 decky 353
	ln -sfn ../../arch/$(ARCH)/include/ generic/include/arch
354
	ln -sfn ../../genarch/include/ generic/include/genarch
1 jermar 355
 
577 palkovsky 356
depend: archlinks
651 decky 357
	-makedepend $(DEFS) $(CFLAGS) -f - $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null
576 palkovsky 358
 
452 decky 359
arch/$(ARCH)/_link.ld: arch/$(ARCH)/_link.ld.in
2455 jermar 360
	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
1 jermar 361
 
452 decky 362
generic/src/debug/real_map.bin: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
2602 jermar 363
	echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o generic/src/debug/empty_map.o
2125 decky 364
	$(LD) -T arch/$(ARCH)/_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
2125 decky 370
	$(LD) -T arch/$(ARCH)/_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
 
461 decky 377
kernel.raw: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o
2125 decky 378
	$(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) generic/src/debug/real_map.o -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
 
392
%.o: %.c
2125 decky 393
	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@