Subversion Repositories HelenOS

Rev

Rev 2452 | Rev 2454 | 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
 
36
## Common compiler flags
37
#
38
 
955 palkovsky 39
DEFS = -D$(ARCH) -DARCH=\"$(ARCH)\" -DRELEASE=\"$(RELEASE)\" "-DNAME=\"$(NAME)\"" -DKERNEL
2437 decky 40
CFLAGS = -fno-builtin -fomit-frame-pointer -Wall -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -Igeneric/include/
2453 jermar 41
 
42
#SUNCC_CFLAGS = -xO3 -Igeneric/include/ -xnolib -xc99=all \
43
#-D__FUNCTION__=__func__ -features=extensions \
44
#-erroff=E_ZERO_SIZED_STRUCT_UNION
45
 
452 decky 46
LFLAGS = -M
462 decky 47
AFLAGS =
452 decky 48
 
561 decky 49
ifdef REVISION
50
	DEFS += "-DREVISION=\"$(REVISION)\""
462 decky 51
endif
52
 
561 decky 53
ifdef TIMESTAMP
54
	DEFS += "-DTIMESTAMP=\"$(TIMESTAMP)\""
55
endif
56
 
452 decky 57
## Setup kernel configuration
58
#
59
 
558 palkovsky 60
-include arch/$(ARCH)/Makefile.inc
61
-include genarch/Makefile.inc
1 jermar 62
 
471 decky 63
ifeq ($(CONFIG_DEBUG),y)
64
	DEFS += -DCONFIG_DEBUG
452 decky 65
endif
1802 decky 66
 
452 decky 67
ifeq ($(CONFIG_DEBUG_SPINLOCK),y)
458 decky 68
	DEFS += -DCONFIG_DEBUG_SPINLOCK
452 decky 69
endif
1802 decky 70
 
1072 palkovsky 71
ifeq ($(CONFIG_DEBUG_AS_WATCHPOINT),y)
72
	DEFS += -DCONFIG_DEBUG_AS_WATCHPOINT
73
endif
1802 decky 74
 
568 palkovsky 75
ifeq ($(CONFIG_FPU_LAZY),y)
76
	DEFS += -DCONFIG_FPU_LAZY
77
endif
1802 decky 78
 
1094 palkovsky 79
ifeq ($(CONFIG_DEBUG_ALLREGS),y)
80
	DEFS += -DCONFIG_DEBUG_ALLREGS
81
endif
1802 decky 82
 
1210 vana 83
ifeq ($(CONFIG_VHPT),y)
84
	DEFS += -DCONFIG_VHPT
85
endif
1802 decky 86
 
1891 jermar 87
ifeq ($(CONFIG_TSB),y)
88
	DEFS += -DCONFIG_TSB
89
endif
90
 
1896 jermar 91
ifeq ($(CONFIG_Z8530),y)
92
	DEFS += -DCONFIG_Z8530
93
endif
94
 
95
ifeq ($(CONFIG_NS16550),y)
96
	DEFS += -DCONFIG_NS16550
97
endif
98
 
2009 jermar 99
ifeq ($(CONFIG_VIRT_IDX_DCACHE),y)
100
	DEFS += -DCONFIG_VIRT_IDX_DCACHE
1996 jermar 101
endif
102
 
1287 vana 103
ifeq ($(CONFIG_FB),y)
1802 decky 104
	ifeq ($(ARCH),ia32)
105
		DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
106
		DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
107
		DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
108
	endif
109
 
110
	ifeq ($(ARCH),amd64)
111
		DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
112
		DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
113
		DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
114
	endif
115
 
1953 jermar 116
	ifeq ($(ARCH),ia32xen)
1802 decky 117
		DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
118
		DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
119
		DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
120
	endif
1287 vana 121
endif
452 decky 122
 
123
## Toolchain configuration
124
#
125
 
2437 decky 126
ifeq ($(COMPILER),gcc_native)
452 decky 127
	CC = gcc
2444 jermar 128
	AS_CC = gcc
452 decky 129
	AS = as
130
	LD = ld
131
	OBJCOPY = objcopy
132
	OBJDUMP = objdump
2125 decky 133
	LIBDIR = /usr/lib
2437 decky 134
endif
135
 
136
ifeq ($(COMPILER),icc_native)
137
	CC = icc
2444 jermar 138
	AS_CC = gcc
2437 decky 139
	AS = as
140
	LD = ld
141
	OBJCOPY = objcopy
142
	OBJDUMP = objdump
143
	LIBDIR = /usr/lib
144
endif
145
 
2443 jermar 146
ifeq ($(COMPILER),suncc_native)
147
	CC = suncc
2444 jermar 148
	AS_CC = gcc
2443 jermar 149
	AS = as
150
	LD = ld
151
	OBJCOPY = objcopy
152
	OBJDUMP = objdump
153
	LIBDIR = /usr/lib
154
endif
155
 
2437 decky 156
ifeq ($(COMPILER),gcc_cross)
2125 decky 157
	CC = $(TOOLCHAIN_DIR)/bin/$(TARGET)-gcc
2444 jermar 158
	AS_CC = $(CC)
2125 decky 159
	AS = $(TOOLCHAIN_DIR)/bin/$(TARGET)-as
160
	LD = $(TOOLCHAIN_DIR)/bin/$(TARGET)-ld
161
	OBJCOPY = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objcopy
162
	OBJDUMP = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objdump
163
	LIBDIR = $(TOOLCHAIN_DIR)/lib
452 decky 164
endif
165
 
166
## Generic kernel sources
167
#
168
 
169
GENERIC_SOURCES = \
1200 jermar 170
	generic/src/adt/bitmap.c \
1101 jermar 171
	generic/src/adt/btree.c \
790 jermar 172
	generic/src/adt/hash_table.c \
788 jermar 173
	generic/src/adt/list.c \
510 jermar 174
	generic/src/console/chardev.c \
175
	generic/src/console/console.c \
518 jermar 176
	generic/src/console/kconsole.c \
1595 palkovsky 177
	generic/src/console/klog.c \
596 jermar 178
	generic/src/console/cmd.c \
452 decky 179
	generic/src/cpu/cpu.c \
1178 jermar 180
	generic/src/ddi/ddi.c \
1920 jermar 181
	generic/src/ddi/irq.c \
182
	generic/src/ddi/device.c \
575 palkovsky 183
	generic/src/interrupt/interrupt.c \
430 jermar 184
	generic/src/main/main.c \
185
	generic/src/main/kinit.c \
186
	generic/src/main/uinit.c \
673 jermar 187
	generic/src/main/version.c \
2227 decky 188
	generic/src/main/shutdown.c \
430 jermar 189
	generic/src/proc/scheduler.c \
190
	generic/src/proc/thread.c \
191
	generic/src/proc/task.c \
192
	generic/src/proc/the.c \
678 decky 193
	generic/src/syscall/syscall.c \
1288 jermar 194
	generic/src/syscall/copy.c \
430 jermar 195
	generic/src/mm/buddy.c \
196
	generic/src/mm/frame.c \
197
	generic/src/mm/page.c \
198
	generic/src/mm/tlb.c \
703 jermar 199
	generic/src/mm/as.c \
1424 jermar 200
	generic/src/mm/backend_anon.c \
201
	generic/src/mm/backend_elf.c \
202
	generic/src/mm/backend_phys.c \
759 palkovsky 203
	generic/src/mm/slab.c \
430 jermar 204
	generic/src/lib/func.c \
205
	generic/src/lib/memstr.c \
206
	generic/src/lib/sort.c \
938 jermar 207
	generic/src/lib/elf.c \
2000 decky 208
	generic/src/lib/rd.c \
1273 cejka 209
	generic/src/printf/printf_core.c \
210
	generic/src/printf/printf.c \
211
	generic/src/printf/sprintf.c \
212
	generic/src/printf/snprintf.c \
213
	generic/src/printf/vprintf.c \
214
	generic/src/printf/vsprintf.c \
215
	generic/src/printf/vsnprintf.c \
430 jermar 216
	generic/src/debug/symtab.c \
217
	generic/src/time/clock.c \
218
	generic/src/time/timeout.c \
219
	generic/src/time/delay.c \
220
	generic/src/preempt/preemption.c \
221
	generic/src/synch/spinlock.c \
222
	generic/src/synch/condvar.c \
223
	generic/src/synch/rwlock.c \
224
	generic/src/synch/mutex.c \
225
	generic/src/synch/semaphore.c \
226
	generic/src/synch/waitq.c \
1109 jermar 227
	generic/src/synch/futex.c \
955 palkovsky 228
	generic/src/smp/ipi.c \
1901 jermar 229
	generic/src/smp/smp.c \
965 palkovsky 230
	generic/src/ipc/ipc.c \
1072 palkovsky 231
	generic/src/ipc/sysipc.c \
1174 jermar 232
	generic/src/ipc/ipcrsc.c \
1281 palkovsky 233
	generic/src/ipc/irq.c \
1317 vana 234
	generic/src/security/cap.c \
235
	generic/src/sysinfo/sysinfo.c
1 jermar 236
 
459 decky 237
## Test sources
238
#
239
 
2020 decky 240
ifeq ($(CONFIG_TEST),y)
459 decky 241
	DEFS += -DCONFIG_TEST
2019 decky 242
	CFLAGS += -Itest/
243
	GENERIC_SOURCES += \
244
		test/test.c \
2020 decky 245
		test/atomic/atomic1.c \
246
		test/btree/btree1.c \
247
		test/debug/mips1.c \
248
		test/fault/fault1.c \
2021 decky 249
		test/fpu/fpu1.c \
250
		test/fpu/sse1.c \
251
		test/fpu/mips2.c \
252
		test/mm/falloc1.c \
253
		test/mm/falloc2.c \
254
		test/mm/mapping1.c \
255
		test/mm/slab1.c \
256
		test/mm/slab2.c \
2022 decky 257
		test/mm/purge1.c \
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 \
266
		test/thread/thread1.c \
267
		test/sysinfo/sysinfo1.c
459 decky 268
endif
269
 
2125 decky 270
## Experimental features
271
#
272
 
273
ifeq ($(CONFIG_EXPERIMENTAL),y)
2126 decky 274
	GENERIC_SOURCES += generic/src/lib/objc_ext.c \
275
		generic/src/lib/objc.c
2125 decky 276
	EXTRA_OBJECTS = $(LIBDIR)/libobjc.a
277
	EXTRA_FLAGS += -x objective-c
278
endif
279
 
452 decky 280
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
281
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
282
GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
326 palkovsky 283
 
1017 decky 284
.PHONY: all build config distclean clean archlinks depend disasm
1 jermar 285
 
558 palkovsky 286
all:
1802 decky 287
	../tools/config.py kernel.config default $(ARCH) $(COMPILER) $(CONFIG_DEBUG) $(MACHINE)
561 decky 288
	$(MAKE) -C . build
34 jermar 289
 
1017 decky 290
build: kernel.bin disasm
558 palkovsky 291
 
292
config:
580 palkovsky 293
	-rm Makefile.depend
2011 decky 294
	../tools/config.py kernel.config
558 palkovsky 295
 
452 decky 296
-include Makefile.depend
1 jermar 297
 
558 palkovsky 298
distclean: clean
299
	-rm Makefile.config
300
 
452 decky 301
clean:
576 palkovsky 302
	-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 303
	find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
1802 decky 304
	for arch in arch/* ; do \
305
	    [ -e $$arch/_link.ld ] && rm $$arch/_link.ld 2>/dev/null ; \
306
	done ; exit 0
1 jermar 307
 
558 palkovsky 308
archlinks:
452 decky 309
	ln -sfn ../../arch/$(ARCH)/include/ generic/include/arch
310
	ln -sfn ../../genarch/include/ generic/include/genarch
1 jermar 311
 
577 palkovsky 312
depend: archlinks
651 decky 313
	-makedepend $(DEFS) $(CFLAGS) -f - $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null
576 palkovsky 314
 
452 decky 315
arch/$(ARCH)/_link.ld: arch/$(ARCH)/_link.ld.in
2089 decky 316
	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
1 jermar 317
 
452 decky 318
generic/src/debug/real_map.bin: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
430 jermar 319
	$(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab Makefile generic/src/debug/empty_map.o
2125 decky 320
	$(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 321
	$(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
430 jermar 322
	tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin 
602 palkovsky 323
	# Do it once again, this time to get correct even the symbols
324
	# on architectures, that have bss after symtab
325
	$(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab generic/src/debug/real_map.bin generic/src/debug/sizeok_map.o
2125 decky 326
	$(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 327
	$(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
328
	tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin 
293 palkovsky 329
 
430 jermar 330
generic/src/debug/real_map.o: generic/src/debug/real_map.bin
293 palkovsky 331
	$(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab $< $@
332
 
461 decky 333
kernel.raw: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o
2125 decky 334
	$(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 335
 
461 decky 336
kernel.bin: kernel.raw
337
	$(OBJCOPY) -O $(BFD) kernel.raw kernel.bin
338
 
472 jermar 339
disasm: kernel.raw
340
	$(OBJDUMP) -d kernel.raw > kernel.disasm
341
 
314 palkovsky 342
%.o: %.S
2444 jermar 343
	$(AS_CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
1 jermar 344
 
345
%.o: %.s
455 decky 346
	$(AS) $(AFLAGS) $< -o $@
1 jermar 347
 
348
%.o: %.c
2125 decky 349
	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@