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