1 # Makefile for GeekOS kernel, userspace, and tools
3 # Northwestern University
4 # (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
5 # (c) 2008, Peter Dinda <pdinda@northwestern.edu>
6 # (c) 2008, Lei Xia <xiaxlei@gmail.com>
7 # (c) 2008, The V3VEE Project <http://www.v3vee.org>
9 # Based on GeekOS Makefile:
10 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
14 # This is free software. You are permitted to use,
15 # redistribute, and modify it as specified in the file "COPYING".
17 # Required software to build GeekOS:
18 # - GNU Make (http://www.gnu.org/software/make)
19 # - gcc 2.95.2 generating code for target (i386/ELF) and host platforms
20 # - nasm (http://nasm.sourceforge.net)
21 # - Perl5, AWK (any version), egrep
23 # Cygwin (http://cygwin.com) may be used to build GeekOS.
24 # Make sure that gcc, binutils, nasm, and perl are installed.
27 # - This makefile has been written carefully to work correctly
28 # with the -j (parallel make) option. I regularly use "make -j 2"
29 # to speed the build process on 2 processor systems.
32 # Base address of kernel
34 # Note: at top of memory minus three pages (GDT/TSS/IDT)
38 # Note that the code will initially load at 0x10000
40 # The setup code needs to copy it up to this address and jump there
42 KERNEL_BASE_ADDR := 0x00100000
44 # Kernel entry point function
45 KERNEL_ENTRY = $(SYM_PFX)Main
49 V3_ROOT := $(PROJECT_ROOT)/../palacios
50 VPATH := $(PROJECT_ROOT)/src
56 #TCPSTACK, uIP is used currently
61 #LWIP, ON -- used, OFF -- not used
67 # This is wrong for current cygwin - no changes needed
69 # Figure out if we're compiling with cygwin, http://cygwin.com
72 #SYSTEM_NAME := $(shell uname -s)
73 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
75 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
76 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
77 #NON_ELF_SYSTEM := yes
78 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
84 # ----------------------------------------------------------------------
86 # Various options specifying how GeekOS should be built,
87 # what source files to build, which user programs to build,
88 # etc. This is generally the only section of the makefile
89 # that will need to be modified.
90 # ----------------------------------------------------------------------
92 # List of targets to build by default.
93 # These targets encompass everything needed to boot
95 ALL_TARGETS := vmm.img
99 KERNEL_C_SRCS := idt.c int.c trap.c irq.c io.c \
100 blockdev.c ide.c ne2k.c \
101 keyboard.c screen.c timer.c \
103 gdt.c tss.c segment.c \
108 debug.c vmm_stubs.c vm.c pci.c\
109 queue.c socket.c net.c ring_buffer.c \
113 # Kernel object files built from C source files
114 KERNEL_C_OBJS := $(KERNEL_C_SRCS:%.c=geekos/%.o)
116 # Kernel assembly files
117 KERNEL_ASM_SRCS := lowlevel.asm
121 # Kernel object files build from assembler source files
122 KERNEL_ASM_OBJS := $(KERNEL_ASM_SRCS:%.asm=geekos/%.o)
124 KERNEL_GAS_OBJS := $(KERNEL_GAS_SRCS:%.s=geekos/%.o)
127 # All kernel object files
128 KERNEL_OBJS := $(KERNEL_C_OBJS) \
129 $(KERNEL_ASM_OBJS) $(KERNEL_GAS_OBJS)
131 # Common library source files.
132 # This library is linked into both the kernel and user programs.
133 # It provides string functions and generic printf()-style
135 COMMON_C_SRCS := fmtout.c string.c memmove.c
137 # Common library object files.
138 COMMON_C_OBJS := $(COMMON_C_SRCS:%.c=common/%.o)
143 V3_LD_FLAGS := -L./palacios/
144 #V3_LIBS := -lxed -lv3vee
145 V3_LIBS := ./palacios/libxed.a ./palacios/libv3vee.a ./palacios/libxed.a ./palacios/libv3vee.a
153 UIP_C_SRCS := psock.c timer.c uip_arp.c uip.c uip-fw.c uiplib.c uip-neighbor.c uip-split.c resolv.c
154 UIP_C_OBJS := $(UIP_C_SRCS:%.c=net/%.o)
161 LWIP_OBJS := lwip/*.o
162 CC_LWIP_OPTS := -I$(PROJECT_ROOT)/include/lwip -I$(PROJECT_ROOT)/include/lwip/ipv4 -I$(PROJECT_ROOT)/include/libc -DLWIP_DEBUG
168 TCPSTACK_OBJS := $(UIP_C_OBJS) $(LWIP_OBJS)
171 # ----------------------------------------------------------------------
173 # This section defines programs that are used to build GeekOS.
174 # ----------------------------------------------------------------------
176 # Uncomment if cross compiling
177 TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
178 #TARGET_CC_PREFIX := i386-elf-
180 # Target C compiler. gcc 2.95.2 or later should work.
181 TARGET_CC := $(TARGET_CC_PREFIX)gcc
182 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
184 # Host C compiler. This is used to compile programs to execute on
185 # the host platform, not the target (x86) platform. On x86/ELF
186 # systems, such as Linux and FreeBSD, it can generally be the same
187 # as the target C compiler.
190 # Target linker. GNU ld is probably to only one that will work.
191 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
194 TARGET_AR := $(TARGET_CC_PREFIX)ar
197 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
200 TARGET_NM := $(TARGET_CC_PREFIX)nm
203 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
205 # Nasm (http://nasm.sourceforge.net)
206 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
207 #NASM := /opt/vmm-tools/bin/nasm
211 # Tool to build PFAT filesystem images.
212 BUILDFAT := tools/builtFat.exe
217 # Pad a file so its size is a multiple of some unit (i.e., sector size)
218 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
220 # Create a file filled with zeroes.
221 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
223 # Calculate size of file in sectors
224 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
227 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
230 # ----------------------------------------------------------------------
232 # Options passed to the tools.
233 # ----------------------------------------------------------------------
235 # Flags used for all C source files
236 GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(BOOT_FLAGS) -fPIC
237 CC_GENERAL_OPTS := $(GENERAL_OPTS) -Werror
239 # Flags used for kernel C source files
240 CC_KERNEL_OPTS := -g -DGEEKOS -I$(PROJECT_ROOT)/include -I$(V3_ROOT)/include
243 # Flags user for kernel assembly files
244 NASM_KERNEL_OPTS := -I$(PROJECT_ROOT)/src/geekos/ -f elf $(EXTRA_NASM_OPTS)
246 # Flags used for common library and libc source files
247 CC_USER_OPTS := -I$(PROJECT_ROOT)/include -I$(PROJECT_ROOT)/include/libc \
248 $(EXTRA_CC_USER_OPTS) -I$(V3_ROOT)/include
250 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
251 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
253 # ----------------------------------------------------------------------
255 # Describes how to compile the source files.
256 # ----------------------------------------------------------------------
258 # Compilation of kernel C source files
260 geekos/%.o : geekos/%.c
261 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $(CC_LWIP_OPTS) $< -o geekos/$*.o
264 # Compilation of kernel assembly source files
265 geekos/%.o : geekos/%.asm
266 $(NASM) $(NASM_KERNEL_OPTS) $< -o geekos/$*.o
269 # Compilation of common library C source files
270 common/%.o : common/%.c
271 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_USER_OPTS) $< -o common/$*.o
275 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_USER_OPTS) $< -o net/$*.o
277 # ----------------------------------------------------------------------
279 # Specifies files to be built
280 # ----------------------------------------------------------------------
282 # Default target - see definition of ALL_TARGETS in Configuration section
287 (cd ../src/lwip/build; make clean; make)
290 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
293 # -I$(PROJECT_ROOT)/src/geekos/ \
294 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
298 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
299 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
301 # Standard floppy image - just boots the kernel
302 fd.img : geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin
303 cat geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin > _temp
310 $(PAD) vmm.img 1474560
317 # Floppy boot sector (first stage boot loader).
318 geekos/fd_boot.bin : geekos/setup.bin geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/fd_boot.asm
320 -I$(PROJECT_ROOT)/src/geekos/ \
321 -DNUM_SETUP_SECTORS=`$(NUMSECS) geekos/setup.bin` \
322 -DNUM_KERN_SECTORS=`$(NUMSECS) geekos/kernel.bin` \
323 -DSECTORS_PER_TRACK=`$(FD_SECTORS_PER_TRACK) geekos/kernel.bin geekos/setup.bin` \
324 $(PROJECT_ROOT)/src/geekos/fd_boot.asm \
327 # Setup program (second stage boot loader).
328 geekos/setup.bin : geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/setup.asm
330 -I$(PROJECT_ROOT)/src/geekos/ \
331 -DENTRY_POINT=0x`egrep 'Main$$' geekos/kernel.syms |awk '{print $$1}'` \
332 -DVMM_SIZE=`$(NUMSECS) geekos/kernel.bin` \
333 $(PROJECT_ROOT)/src/geekos/setup.asm \
337 # Loadable (flat) kernel image.
338 geekos/kernel.bin : geekos/kernel.exe
339 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary geekos/kernel.exe geekos/kernel.bin
342 # The kernel executable and symbol map.
343 geekos/kernel.exe : $(KERNEL_OBJS) $(COMMON_C_OBJS) force_lwip $(TCPSTACK_OBJS)
344 $(TARGET_LD) -o geekos/kernel.exe -Ttext $(KERNEL_BASE_ADDR) -e $(KERNEL_ENTRY) \
346 $(KERNEL_OBJS) $(COMMON_C_OBJS) $(TCPSTACK_OBJS) $(V3_LIBS) -b binary ./palacios/vm_kernel
347 $(TARGET_NM) geekos/kernel.exe > geekos/kernel.syms
354 # $(PAD) vm_kernel 512
355 # @echo "VM kernel lives at 0x100000 and is" `$(NUMSECS) vm_kernel` "sectors long"
360 # Clean build directories of generated files
362 for d in geekos common libc user tools net; do \
363 (cd $$d && rm -f *); \
367 # Build header file dependencies, so source files are recompiled when
368 # header files they depend on are modified.
369 depend : $(GENERATED_LIBC_SRCS)
370 $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
371 $(KERNEL_C_SRCS:%.c=$(PROJECT_ROOT)/src/geekos/%.c) \
372 | $(PERL) -n -e 's,^(\S),geekos/$$1,;print' \
374 $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_USER_OPTS) \
375 $(COMMON_C_SRCS:%.c=$(PROJECT_ROOT)/src/common/%.c) \
376 | $(PERL) -n -e 's,^(\S),common/$$1,;print' \
380 # By default, there are no header file dependencies.