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