| 1 | # | 
|---|
| 2 | # Copyright (C) 2005 Martin 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 | ## Kernel release | 
|---|
| 30 | # | 
|---|
| 31 |  | 
|---|
| 32 | VERSION = 0 | 
|---|
| 33 | PATCHLEVEL = 2 | 
|---|
| 34 | SUBLEVEL = 0 | 
|---|
| 35 | EXTRAVERSION = | 
|---|
| 36 | NAME = Daylight | 
|---|
| 37 | RELEASE = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) | 
|---|
| 38 |  | 
|---|
| 39 | ## Include configuration | 
|---|
| 40 | # | 
|---|
| 41 |  | 
|---|
| 42 | -include Makefile.config | 
|---|
| 43 |  | 
|---|
| 44 | ## Common compiler flags | 
|---|
| 45 | # | 
|---|
| 46 |  | 
|---|
| 47 | DEFS = -D$(ARCH) -DARCH=\"$(ARCH)\" -DRELEASE=\"$(RELEASE)\" "-DNAME=\"$(NAME)\"" -DKERNEL | 
|---|
| 48 | CFLAGS = -fno-builtin -fomit-frame-pointer -Wall -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -Igeneric/include/ | 
|---|
| 49 | LFLAGS = -M | 
|---|
| 50 | AFLAGS = | 
|---|
| 51 |  | 
|---|
| 52 | ifdef REVISION | 
|---|
| 53 | DEFS += "-DREVISION=\"$(REVISION)\"" | 
|---|
| 54 | endif | 
|---|
| 55 |  | 
|---|
| 56 | ifdef TIMESTAMP | 
|---|
| 57 | DEFS += "-DTIMESTAMP=\"$(TIMESTAMP)\"" | 
|---|
| 58 | endif | 
|---|
| 59 |  | 
|---|
| 60 | ## Setup kernel configuration | 
|---|
| 61 | # | 
|---|
| 62 |  | 
|---|
| 63 | -include arch/$(ARCH)/Makefile.inc | 
|---|
| 64 | -include genarch/Makefile.inc | 
|---|
| 65 |  | 
|---|
| 66 | ifeq ($(CONFIG_DEBUG),y) | 
|---|
| 67 | DEFS += -DCONFIG_DEBUG | 
|---|
| 68 | endif | 
|---|
| 69 | ifeq ($(CONFIG_DEBUG_SPINLOCK),y) | 
|---|
| 70 | DEFS += -DCONFIG_DEBUG_SPINLOCK | 
|---|
| 71 | endif | 
|---|
| 72 | ifeq ($(CONFIG_DEBUG_AS_WATCHPOINT),y) | 
|---|
| 73 | DEFS += -DCONFIG_DEBUG_AS_WATCHPOINT | 
|---|
| 74 | endif | 
|---|
| 75 | ifeq ($(CONFIG_FPU_LAZY),y) | 
|---|
| 76 | DEFS += -DCONFIG_FPU_LAZY | 
|---|
| 77 | endif | 
|---|
| 78 | ifeq ($(CONFIG_DEBUG_ALLREGS),y) | 
|---|
| 79 | DEFS += -DCONFIG_DEBUG_ALLREGS | 
|---|
| 80 | endif | 
|---|
| 81 | ifeq ($(CONFIG_VHPT),y) | 
|---|
| 82 | DEFS += -DCONFIG_VHPT | 
|---|
| 83 | endif | 
|---|
| 84 | ifeq ($(CONFIG_POWEROFF),y) | 
|---|
| 85 | DEFS += -DCONFIG_POWEROFF | 
|---|
| 86 | endif | 
|---|
| 87 | ifeq ($(CONFIG_FB),y) | 
|---|
| 88 | ifeq ($(ARCH),ia32) | 
|---|
| 89 | DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH) | 
|---|
| 90 | DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT) | 
|---|
| 91 | DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP) | 
|---|
| 92 | endif | 
|---|
| 93 | ifeq ($(ARCH),amd64) | 
|---|
| 94 | DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH) | 
|---|
| 95 | DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT) | 
|---|
| 96 | DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP) | 
|---|
| 97 | endif | 
|---|
| 98 | endif | 
|---|
| 99 |  | 
|---|
| 100 | ## Toolchain configuration | 
|---|
| 101 | # | 
|---|
| 102 |  | 
|---|
| 103 | ifeq ($(COMPILER),native) | 
|---|
| 104 | CC = gcc | 
|---|
| 105 | AS = as | 
|---|
| 106 | LD = ld | 
|---|
| 107 | OBJCOPY = objcopy | 
|---|
| 108 | OBJDUMP = objdump | 
|---|
| 109 | else | 
|---|
| 110 | CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc | 
|---|
| 111 | AS = $(TOOLCHAIN_DIR)/$(TARGET)-as | 
|---|
| 112 | LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld | 
|---|
| 113 | OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy | 
|---|
| 114 | OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump | 
|---|
| 115 | endif | 
|---|
| 116 |  | 
|---|
| 117 | ## Generic kernel sources | 
|---|
| 118 | # | 
|---|
| 119 |  | 
|---|
| 120 | GENERIC_SOURCES = \ | 
|---|
| 121 | generic/src/adt/bitmap.c \ | 
|---|
| 122 | generic/src/adt/btree.c \ | 
|---|
| 123 | generic/src/adt/hash_table.c \ | 
|---|
| 124 | generic/src/adt/list.c \ | 
|---|
| 125 | generic/src/console/chardev.c \ | 
|---|
| 126 | generic/src/console/console.c \ | 
|---|
| 127 | generic/src/console/kconsole.c \ | 
|---|
| 128 | generic/src/console/klog.c \ | 
|---|
| 129 | generic/src/console/cmd.c \ | 
|---|
| 130 | generic/src/cpu/cpu.c \ | 
|---|
| 131 | generic/src/ddi/ddi.c \ | 
|---|
| 132 | generic/src/interrupt/interrupt.c \ | 
|---|
| 133 | generic/src/main/main.c \ | 
|---|
| 134 | generic/src/main/kinit.c \ | 
|---|
| 135 | generic/src/main/uinit.c \ | 
|---|
| 136 | generic/src/main/version.c \ | 
|---|
| 137 | generic/src/proc/scheduler.c \ | 
|---|
| 138 | generic/src/proc/thread.c \ | 
|---|
| 139 | generic/src/proc/task.c \ | 
|---|
| 140 | generic/src/proc/the.c \ | 
|---|
| 141 | generic/src/syscall/syscall.c \ | 
|---|
| 142 | generic/src/syscall/copy.c \ | 
|---|
| 143 | generic/src/mm/buddy.c \ | 
|---|
| 144 | generic/src/mm/frame.c \ | 
|---|
| 145 | generic/src/mm/page.c \ | 
|---|
| 146 | generic/src/mm/tlb.c \ | 
|---|
| 147 | generic/src/mm/as.c \ | 
|---|
| 148 | generic/src/mm/backend_anon.c \ | 
|---|
| 149 | generic/src/mm/backend_elf.c \ | 
|---|
| 150 | generic/src/mm/backend_phys.c \ | 
|---|
| 151 | generic/src/mm/slab.c \ | 
|---|
| 152 | generic/src/lib/func.c \ | 
|---|
| 153 | generic/src/lib/memstr.c \ | 
|---|
| 154 | generic/src/lib/sort.c \ | 
|---|
| 155 | generic/src/lib/elf.c \ | 
|---|
| 156 | generic/src/printf/printf_core.c \ | 
|---|
| 157 | generic/src/printf/printf.c \ | 
|---|
| 158 | generic/src/printf/sprintf.c \ | 
|---|
| 159 | generic/src/printf/snprintf.c \ | 
|---|
| 160 | generic/src/printf/vprintf.c \ | 
|---|
| 161 | generic/src/printf/vsprintf.c \ | 
|---|
| 162 | generic/src/printf/vsnprintf.c \ | 
|---|
| 163 | generic/src/debug/symtab.c \ | 
|---|
| 164 | generic/src/time/clock.c \ | 
|---|
| 165 | generic/src/time/timeout.c \ | 
|---|
| 166 | generic/src/time/delay.c \ | 
|---|
| 167 | generic/src/preempt/preemption.c \ | 
|---|
| 168 | generic/src/synch/spinlock.c \ | 
|---|
| 169 | generic/src/synch/condvar.c \ | 
|---|
| 170 | generic/src/synch/rwlock.c \ | 
|---|
| 171 | generic/src/synch/mutex.c \ | 
|---|
| 172 | generic/src/synch/semaphore.c \ | 
|---|
| 173 | generic/src/synch/waitq.c \ | 
|---|
| 174 | generic/src/synch/futex.c \ | 
|---|
| 175 | generic/src/smp/ipi.c \ | 
|---|
| 176 | generic/src/ipc/ipc.c \ | 
|---|
| 177 | generic/src/ipc/sysipc.c \ | 
|---|
| 178 | generic/src/ipc/ipcrsc.c \ | 
|---|
| 179 | generic/src/ipc/irq.c \ | 
|---|
| 180 | generic/src/security/cap.c \ | 
|---|
| 181 | generic/src/sysinfo/sysinfo.c | 
|---|
| 182 |  | 
|---|
| 183 | ## Test sources | 
|---|
| 184 | # | 
|---|
| 185 |  | 
|---|
| 186 | ifneq ($(CONFIG_TEST),) | 
|---|
| 187 | DEFS += -DCONFIG_TEST | 
|---|
| 188 | GENERIC_SOURCES += test/$(CONFIG_TEST)/test.c | 
|---|
| 189 | endif | 
|---|
| 190 |  | 
|---|
| 191 | GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) | 
|---|
| 192 | ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES))) | 
|---|
| 193 | GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES))) | 
|---|
| 194 |  | 
|---|
| 195 | .PHONY: all build config distclean clean archlinks depend disasm | 
|---|
| 196 |  | 
|---|
| 197 | all: | 
|---|
| 198 | tools/config.py default $(NARCH) | 
|---|
| 199 | ifdef NARCH | 
|---|
| 200 | ifneq ($(ARCH), $(NARCH)) | 
|---|
| 201 | $(MAKE) -C . clean | 
|---|
| 202 | endif | 
|---|
| 203 | endif | 
|---|
| 204 | $(MAKE) -C . build | 
|---|
| 205 |  | 
|---|
| 206 | build: kernel.bin disasm | 
|---|
| 207 |  | 
|---|
| 208 | config: | 
|---|
| 209 | -rm Makefile.depend | 
|---|
| 210 | tools/config.py | 
|---|
| 211 |  | 
|---|
| 212 | -include Makefile.depend | 
|---|
| 213 |  | 
|---|
| 214 | distclean: clean | 
|---|
| 215 | -rm Makefile.config | 
|---|
| 216 |  | 
|---|
| 217 | clean: | 
|---|
| 218 | -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 | 
|---|
| 219 | find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \; | 
|---|
| 220 | for arch in arch/*; do \ | 
|---|
| 221 | [ -e $$arch/_link.ld ] && rm $$arch/_link.ld 2>/dev/null;\ | 
|---|
| 222 | done;exit 0 | 
|---|
| 223 |  | 
|---|
| 224 | archlinks: | 
|---|
| 225 | ln -sfn ../../arch/$(ARCH)/include/ generic/include/arch | 
|---|
| 226 | ln -sfn ../../genarch/include/ generic/include/genarch | 
|---|
| 227 |  | 
|---|
| 228 | depend: archlinks | 
|---|
| 229 | -makedepend $(DEFS) $(CFLAGS) -f - $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null | 
|---|
| 230 |  | 
|---|
| 231 | arch/$(ARCH)/_link.ld: arch/$(ARCH)/_link.ld.in | 
|---|
| 232 | $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -E -x c $< | grep -v "^\#" > $@ | 
|---|
| 233 |  | 
|---|
| 234 | generic/src/debug/real_map.bin: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) | 
|---|
| 235 | $(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab Makefile generic/src/debug/empty_map.o | 
|---|
| 236 | $(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/empty_map.o -o $@ -Map kernel.map.pre | 
|---|
| 237 | $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump | 
|---|
| 238 | tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin | 
|---|
| 239 | # Do it once again, this time to get correct even the symbols | 
|---|
| 240 | # on architectures, that have bss after symtab | 
|---|
| 241 | $(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab generic/src/debug/real_map.bin generic/src/debug/sizeok_map.o | 
|---|
| 242 | $(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/sizeok_map.o -o $@ -Map kernel.map.pre | 
|---|
| 243 | $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump | 
|---|
| 244 | tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin | 
|---|
| 245 |  | 
|---|
| 246 | generic/src/debug/real_map.o: generic/src/debug/real_map.bin | 
|---|
| 247 | $(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab $< $@ | 
|---|
| 248 |  | 
|---|
| 249 | kernel.raw: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o | 
|---|
| 250 | $(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o -o $@ -Map kernel.map | 
|---|
| 251 |  | 
|---|
| 252 | kernel.bin: kernel.raw | 
|---|
| 253 | $(OBJCOPY) -O $(BFD) kernel.raw kernel.bin | 
|---|
| 254 |  | 
|---|
| 255 | disasm: kernel.raw | 
|---|
| 256 | $(OBJDUMP) -d kernel.raw > kernel.disasm | 
|---|
| 257 |  | 
|---|
| 258 | %.o: %.S | 
|---|
| 259 | $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@ | 
|---|
| 260 |  | 
|---|
| 261 | %.o: %.s | 
|---|
| 262 | $(AS) $(AFLAGS) $< -o $@ | 
|---|
| 263 |  | 
|---|
| 264 | %.o: %.c | 
|---|
| 265 | $(CC) $(DEFS) $(CFLAGS) -c $< -o $@ | 
|---|