[e16e036a] | 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 |
|
---|
[9371c30] | 30 | ## Include configuration
|
---|
[e16e036a] | 31 | #
|
---|
| 32 |
|
---|
[41f7564] | 33 | -include ../version
|
---|
[839470f] | 34 | -include Makefile.config
|
---|
[e16e036a] | 35 |
|
---|
| 36 | ## Common compiler flags
|
---|
| 37 | #
|
---|
| 38 |
|
---|
[6d9c49a] | 39 | DEFS = -D$(ARCH) -DARCH=\"$(ARCH)\" -DRELEASE=\"$(RELEASE)\" "-DNAME=\"$(NAME)\"" -DKERNEL
|
---|
[41f7564] | 40 | CFLAGS = -fno-builtin -fomit-frame-pointer -Wall -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -Igeneric/include/
|
---|
[e16e036a] | 41 | LFLAGS = -M
|
---|
[ba22dcb] | 42 | AFLAGS =
|
---|
| 43 |
|
---|
[940cac0] | 44 | ifdef REVISION
|
---|
| 45 | DEFS += "-DREVISION=\"$(REVISION)\""
|
---|
| 46 | endif
|
---|
| 47 |
|
---|
| 48 | ifdef TIMESTAMP
|
---|
| 49 | DEFS += "-DTIMESTAMP=\"$(TIMESTAMP)\""
|
---|
[ba22dcb] | 50 | endif
|
---|
[e16e036a] | 51 |
|
---|
| 52 | ## Setup kernel configuration
|
---|
| 53 | #
|
---|
| 54 |
|
---|
[839470f] | 55 | -include arch/$(ARCH)/Makefile.inc
|
---|
| 56 | -include genarch/Makefile.inc
|
---|
[c9ed176] | 57 |
|
---|
[b183865e] | 58 | ifeq ($(CONFIG_DEBUG),y)
|
---|
| 59 | DEFS += -DCONFIG_DEBUG
|
---|
[e16e036a] | 60 | endif
|
---|
[41f7564] | 61 |
|
---|
[e16e036a] | 62 | ifeq ($(CONFIG_DEBUG_SPINLOCK),y)
|
---|
[5f85c91] | 63 | DEFS += -DCONFIG_DEBUG_SPINLOCK
|
---|
[e16e036a] | 64 | endif
|
---|
[41f7564] | 65 |
|
---|
[4e49572] | 66 | ifeq ($(CONFIG_DEBUG_AS_WATCHPOINT),y)
|
---|
| 67 | DEFS += -DCONFIG_DEBUG_AS_WATCHPOINT
|
---|
| 68 | endif
|
---|
[41f7564] | 69 |
|
---|
[944b15c] | 70 | ifeq ($(CONFIG_FPU_LAZY),y)
|
---|
| 71 | DEFS += -DCONFIG_FPU_LAZY
|
---|
| 72 | endif
|
---|
[41f7564] | 73 |
|
---|
[8d25b44] | 74 | ifeq ($(CONFIG_DEBUG_ALLREGS),y)
|
---|
| 75 | DEFS += -DCONFIG_DEBUG_ALLREGS
|
---|
| 76 | endif
|
---|
[41f7564] | 77 |
|
---|
[68091bd] | 78 | ifeq ($(CONFIG_VHPT),y)
|
---|
| 79 | DEFS += -DCONFIG_VHPT
|
---|
| 80 | endif
|
---|
[41f7564] | 81 |
|
---|
[29b2bbf] | 82 | ifeq ($(CONFIG_TSB),y)
|
---|
| 83 | DEFS += -DCONFIG_TSB
|
---|
| 84 | endif
|
---|
| 85 |
|
---|
[28ecadb] | 86 | ifeq ($(CONFIG_Z8530),y)
|
---|
| 87 | DEFS += -DCONFIG_Z8530
|
---|
| 88 | endif
|
---|
| 89 |
|
---|
| 90 | ifeq ($(CONFIG_NS16550),y)
|
---|
| 91 | DEFS += -DCONFIG_NS16550
|
---|
| 92 | endif
|
---|
| 93 |
|
---|
[92778f2] | 94 | ifeq ($(CONFIG_VIRT_IDX_DCACHE),y)
|
---|
| 95 | DEFS += -DCONFIG_VIRT_IDX_DCACHE
|
---|
[44d0758] | 96 | endif
|
---|
| 97 |
|
---|
[afc12d0] | 98 | ifeq ($(CONFIG_POWEROFF),y)
|
---|
| 99 | DEFS += -DCONFIG_POWEROFF
|
---|
| 100 | endif
|
---|
[41f7564] | 101 |
|
---|
[22cf454d] | 102 | ifeq ($(CONFIG_FB),y)
|
---|
[41f7564] | 103 | ifeq ($(ARCH),ia32)
|
---|
| 104 | DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
|
---|
| 105 | DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
|
---|
| 106 | DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
|
---|
| 107 | endif
|
---|
| 108 |
|
---|
| 109 | ifeq ($(ARCH),amd64)
|
---|
| 110 | DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
|
---|
| 111 | DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
|
---|
| 112 | DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
|
---|
| 113 | endif
|
---|
| 114 |
|
---|
[19dce27] | 115 | ifeq ($(ARCH),ia32xen)
|
---|
[41f7564] | 116 | DEFS += -DCONFIG_VESA_WIDTH=$(CONFIG_VESA_WIDTH)
|
---|
| 117 | DEFS += -DCONFIG_VESA_HEIGHT=$(CONFIG_VESA_HEIGHT)
|
---|
| 118 | DEFS += -DCONFIG_VESA_BPP=$(CONFIG_VESA_BPP)
|
---|
| 119 | endif
|
---|
[ab5f8bf] | 120 | endif
|
---|
[e16e036a] | 121 |
|
---|
| 122 | ## Toolchain configuration
|
---|
| 123 | #
|
---|
| 124 |
|
---|
| 125 | ifeq ($(COMPILER),native)
|
---|
| 126 | CC = gcc
|
---|
| 127 | AS = as
|
---|
| 128 | LD = ld
|
---|
| 129 | OBJCOPY = objcopy
|
---|
| 130 | OBJDUMP = objdump
|
---|
| 131 | else
|
---|
| 132 | CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
|
---|
| 133 | AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
|
---|
| 134 | LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
|
---|
| 135 | OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy
|
---|
| 136 | OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
|
---|
| 137 | endif
|
---|
| 138 |
|
---|
| 139 | ## Generic kernel sources
|
---|
| 140 | #
|
---|
| 141 |
|
---|
| 142 | GENERIC_SOURCES = \
|
---|
[97a7eff] | 143 | generic/src/adt/bitmap.c \
|
---|
[018d957e] | 144 | generic/src/adt/btree.c \
|
---|
[c585827] | 145 | generic/src/adt/hash_table.c \
|
---|
[5c9a08b] | 146 | generic/src/adt/list.c \
|
---|
[2677758] | 147 | generic/src/console/chardev.c \
|
---|
| 148 | generic/src/console/console.c \
|
---|
[f4338d2] | 149 | generic/src/console/kconsole.c \
|
---|
[874621f] | 150 | generic/src/console/klog.c \
|
---|
[442d0ae] | 151 | generic/src/console/cmd.c \
|
---|
[e16e036a] | 152 | generic/src/cpu/cpu.c \
|
---|
[9a8d91b] | 153 | generic/src/ddi/ddi.c \
|
---|
[7dcf22a] | 154 | generic/src/ddi/irq.c \
|
---|
| 155 | generic/src/ddi/device.c \
|
---|
[973be64e] | 156 | generic/src/interrupt/interrupt.c \
|
---|
[169c408] | 157 | generic/src/main/main.c \
|
---|
| 158 | generic/src/main/kinit.c \
|
---|
| 159 | generic/src/main/uinit.c \
|
---|
[0132630] | 160 | generic/src/main/version.c \
|
---|
[169c408] | 161 | generic/src/proc/scheduler.c \
|
---|
| 162 | generic/src/proc/thread.c \
|
---|
| 163 | generic/src/proc/task.c \
|
---|
| 164 | generic/src/proc/the.c \
|
---|
[a59e81e] | 165 | generic/src/syscall/syscall.c \
|
---|
[e3c762cd] | 166 | generic/src/syscall/copy.c \
|
---|
[169c408] | 167 | generic/src/mm/buddy.c \
|
---|
| 168 | generic/src/mm/frame.c \
|
---|
| 169 | generic/src/mm/page.c \
|
---|
| 170 | generic/src/mm/tlb.c \
|
---|
[20d50a1] | 171 | generic/src/mm/as.c \
|
---|
[0ee077ee] | 172 | generic/src/mm/backend_anon.c \
|
---|
| 173 | generic/src/mm/backend_elf.c \
|
---|
| 174 | generic/src/mm/backend_phys.c \
|
---|
[4e147a6] | 175 | generic/src/mm/slab.c \
|
---|
[169c408] | 176 | generic/src/lib/func.c \
|
---|
| 177 | generic/src/lib/memstr.c \
|
---|
| 178 | generic/src/lib/sort.c \
|
---|
[de6b301] | 179 | generic/src/lib/elf.c \
|
---|
[d4b5542] | 180 | generic/src/lib/rd.c \
|
---|
[6445baf] | 181 | generic/src/printf/printf_core.c \
|
---|
| 182 | generic/src/printf/printf.c \
|
---|
| 183 | generic/src/printf/sprintf.c \
|
---|
| 184 | generic/src/printf/snprintf.c \
|
---|
| 185 | generic/src/printf/vprintf.c \
|
---|
| 186 | generic/src/printf/vsprintf.c \
|
---|
| 187 | generic/src/printf/vsnprintf.c \
|
---|
[169c408] | 188 | generic/src/debug/symtab.c \
|
---|
| 189 | generic/src/time/clock.c \
|
---|
| 190 | generic/src/time/timeout.c \
|
---|
| 191 | generic/src/time/delay.c \
|
---|
| 192 | generic/src/preempt/preemption.c \
|
---|
| 193 | generic/src/synch/spinlock.c \
|
---|
| 194 | generic/src/synch/condvar.c \
|
---|
| 195 | generic/src/synch/rwlock.c \
|
---|
| 196 | generic/src/synch/mutex.c \
|
---|
| 197 | generic/src/synch/semaphore.c \
|
---|
| 198 | generic/src/synch/waitq.c \
|
---|
[9aa72b4] | 199 | generic/src/synch/futex.c \
|
---|
[6d9c49a] | 200 | generic/src/smp/ipi.c \
|
---|
[26678e5] | 201 | generic/src/smp/smp.c \
|
---|
[e74cb73] | 202 | generic/src/ipc/ipc.c \
|
---|
[4e49572] | 203 | generic/src/ipc/sysipc.c \
|
---|
[1077d91] | 204 | generic/src/ipc/ipcrsc.c \
|
---|
[162f919] | 205 | generic/src/ipc/irq.c \
|
---|
[2666daa] | 206 | generic/src/security/cap.c \
|
---|
| 207 | generic/src/sysinfo/sysinfo.c
|
---|
[bbf5657] | 208 |
|
---|
[36a140b] | 209 | ## Test sources
|
---|
| 210 | #
|
---|
| 211 |
|
---|
[50661ab] | 212 | ifeq ($(CONFIG_TEST),y)
|
---|
[36a140b] | 213 | DEFS += -DCONFIG_TEST
|
---|
[319e60e] | 214 | CFLAGS += -Itest/
|
---|
| 215 | GENERIC_SOURCES += \
|
---|
| 216 | test/test.c \
|
---|
[50661ab] | 217 | test/atomic/atomic1.c \
|
---|
| 218 | test/btree/btree1.c \
|
---|
| 219 | test/debug/mips1.c \
|
---|
| 220 | test/fault/fault1.c \
|
---|
[f272cb8] | 221 | test/fpu/fpu1.c \
|
---|
| 222 | test/fpu/sse1.c \
|
---|
| 223 | test/fpu/mips2.c \
|
---|
| 224 | test/mm/falloc1.c \
|
---|
| 225 | test/mm/falloc2.c \
|
---|
| 226 | test/mm/mapping1.c \
|
---|
| 227 | test/mm/slab1.c \
|
---|
| 228 | test/mm/slab2.c \
|
---|
[70b6de1] | 229 | test/mm/purge1.c \
|
---|
| 230 | test/synch/rwlock1.c \
|
---|
| 231 | test/synch/rwlock2.c \
|
---|
| 232 | test/synch/rwlock3.c \
|
---|
| 233 | test/synch/rwlock4.c \
|
---|
| 234 | test/synch/rwlock5.c \
|
---|
| 235 | test/synch/semaphore1.c \
|
---|
| 236 | test/synch/semaphore2.c \
|
---|
| 237 | test/print/print1.c \
|
---|
| 238 | test/thread/thread1.c \
|
---|
| 239 | test/sysinfo/sysinfo1.c
|
---|
[36a140b] | 240 | endif
|
---|
| 241 |
|
---|
[e16e036a] | 242 | GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
|
---|
| 243 | ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
|
---|
| 244 | GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
|
---|
[c9ed176] | 245 |
|
---|
[b629483] | 246 | .PHONY: all build config distclean clean archlinks depend disasm
|
---|
[c9ed176] | 247 |
|
---|
[839470f] | 248 | all:
|
---|
[41f7564] | 249 | ../tools/config.py kernel.config default $(ARCH) $(COMPILER) $(CONFIG_DEBUG) $(MACHINE)
|
---|
[940cac0] | 250 | $(MAKE) -C . build
|
---|
[839470f] | 251 |
|
---|
[b629483] | 252 | build: kernel.bin disasm
|
---|
[839470f] | 253 |
|
---|
| 254 | config:
|
---|
[208189f] | 255 | -rm Makefile.depend
|
---|
[d178208] | 256 | ../tools/config.py kernel.config
|
---|
[c9ed176] | 257 |
|
---|
| 258 | -include Makefile.depend
|
---|
| 259 |
|
---|
[839470f] | 260 | distclean: clean
|
---|
| 261 | -rm Makefile.config
|
---|
| 262 |
|
---|
[e16e036a] | 263 | clean:
|
---|
[fcfac420] | 264 | -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
|
---|
[839470f] | 265 | find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
|
---|
[41f7564] | 266 | for arch in arch/* ; do \
|
---|
| 267 | [ -e $$arch/_link.ld ] && rm $$arch/_link.ld 2>/dev/null ; \
|
---|
| 268 | done ; exit 0
|
---|
[c9ed176] | 269 |
|
---|
[839470f] | 270 | archlinks:
|
---|
[e16e036a] | 271 | ln -sfn ../../arch/$(ARCH)/include/ generic/include/arch
|
---|
| 272 | ln -sfn ../../genarch/include/ generic/include/genarch
|
---|
[c9ed176] | 273 |
|
---|
[6095342] | 274 | depend: archlinks
|
---|
[d6e8529] | 275 | -makedepend $(DEFS) $(CFLAGS) -f - $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null
|
---|
[c9ed176] | 276 |
|
---|
[e16e036a] | 277 | arch/$(ARCH)/_link.ld: arch/$(ARCH)/_link.ld.in
|
---|
[d1f8a87] | 278 | $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -E -x c $< | grep -v "^\#" > $@
|
---|
[c9ed176] | 279 |
|
---|
[e16e036a] | 280 | generic/src/debug/real_map.bin: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
|
---|
[169c408] | 281 | $(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab Makefile generic/src/debug/empty_map.o
|
---|
[e16e036a] | 282 | $(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/empty_map.o -o $@ -Map kernel.map.pre
|
---|
| 283 | $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
|
---|
[169c408] | 284 | tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin
|
---|
[3550c393] | 285 | # Do it once again, this time to get correct even the symbols
|
---|
| 286 | # on architectures, that have bss after symtab
|
---|
| 287 | $(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab generic/src/debug/real_map.bin generic/src/debug/sizeok_map.o
|
---|
| 288 | $(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/sizeok_map.o -o $@ -Map kernel.map.pre
|
---|
| 289 | $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
|
---|
| 290 | tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin
|
---|
[c9ed176] | 291 |
|
---|
[169c408] | 292 | generic/src/debug/real_map.o: generic/src/debug/real_map.bin
|
---|
[c9ed176] | 293 | $(OBJCOPY) -I binary -O $(BFD_NAME) -B $(BFD_ARCH) --prefix-sections=symtab $< $@
|
---|
| 294 |
|
---|
[6e259d5] | 295 | kernel.raw: depend arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o
|
---|
[e16e036a] | 296 | $(LD) -T arch/$(ARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) generic/src/debug/real_map.o -o $@ -Map kernel.map
|
---|
[c9ed176] | 297 |
|
---|
[6e259d5] | 298 | kernel.bin: kernel.raw
|
---|
| 299 | $(OBJCOPY) -O $(BFD) kernel.raw kernel.bin
|
---|
| 300 |
|
---|
[2ccd275] | 301 | disasm: kernel.raw
|
---|
| 302 | $(OBJDUMP) -d kernel.raw > kernel.disasm
|
---|
| 303 |
|
---|
[c9ed176] | 304 | %.o: %.S
|
---|
[6a78e84] | 305 | $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
|
---|
[c9ed176] | 306 |
|
---|
| 307 | %.o: %.s
|
---|
[6bc4dbd] | 308 | $(AS) $(AFLAGS) $< -o $@
|
---|
[c9ed176] | 309 |
|
---|
| 310 | %.o: %.c
|
---|
[6bc4dbd] | 311 | $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
|
---|