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 # - Perl5, AWK (any version), egrep
22 # Cygwin (http://cygwin.com) may be used to build GeekOS.
23 # Make sure that gcc, binutils, nasm, and perl are installed.
26 # - This makefile has been written carefully to work correctly
27 # with the -j (parallel make) option. I regularly use "make -j 2"
28 # to speed the build process on 2 processor systems.
31 # Base address of kernel
33 # Note: at top of memory minus three pages (GDT/TSS/IDT)
37 # Note that the code will initially load at 0x10000
39 # The setup code needs to copy it up to this address and jump there
46 VPATH := $(PROJECT_ROOT)/src
48 #when -DNDEBUG is set the kassert functions are disabled
51 # DEBUG=1 means VMM_DEBUG, VMM_INFO, and VMM_TRACE are enabled
52 # as are SERIAL_PRINT_DEBUG
55 ifeq ($(LEAN_AND_MEAN),1)
65 DEBUG_SECTIONS:= $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING -DDEBUG_CTRL_REGS -DDEBUG_INTERRUPTS -DDEBUG_IO -DDEBUG_KEYBOARD -DDEBUG_PIC -DDEBUG_PIT -DDEBUG_NVRAM -DDEBUG_EMULATOR -DDEBUG_GENERIC -DDEBUG_RAMDISK -DDEBUG_XED -DDEBUG_HALT -DDEBUG_DEV_MGR
68 ifeq ($(DEBUG_SHADOW_PAGING),1)
69 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
71 ifeq ($(DEBUG_SHADOW_PAGING),0)
72 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
76 ifeq ($(DEBUG_CTRL_REGS),1)
77 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
79 ifeq ($(DEBUG_CTRL_REGS),0)
80 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
84 ifeq ($(DEBUG_INTERRUPTS),1)
85 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
87 ifeq ($(DEBUG_INTERRUPTS),0)
88 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
93 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
96 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
100 ifeq ($(DEBUG_KEYBOARD),1)
101 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
103 ifeq ($(DEBUG_KEYBOARD),0)
104 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
108 ifeq ($(DEBUG_PIC),1)
109 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
111 ifeq ($(DEBUG_PIC),0)
112 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
116 ifeq ($(DEBUG_PIT),1)
117 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
119 ifeq ($(DEBUG_PIT),0)
120 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
124 ifeq ($(DEBUG_NVRAM),1)
125 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
127 ifeq ($(DEBUG_NVRAM),0)
128 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
132 ifeq ($(DEBUG_GENERIC),1)
133 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
135 ifeq ($(DEBUG_GENERIC),0)
136 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
140 ifeq ($(DEBUG_EMULATOR),1)
141 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
143 ifeq ($(DEBUG_EMULATOR),0)
144 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
148 ifeq ($(DEBUG_RAMDISK),1)
149 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
151 ifeq ($(DEBUG_RAMDISK),0)
152 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
156 ifeq ($(TRACE_RAMDISK),1)
157 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
159 ifeq ($(TRACE_RAMDSK),0)
160 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
164 ifeq ($(DEBUG_XED),1)
165 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
167 ifeq ($(DEBUG_XED),0)
168 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
172 ifeq ($(DEBUG_HALT),1)
173 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
175 ifeq ($(DEBUG_HALT),0)
176 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
180 ifeq ($(DEBUG_DEV_MGR),1)
181 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
183 ifeq ($(DEBUG_DEV_MGR),0)
184 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
188 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
191 JRLDEBUG= -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
202 # This is wrong for current cygwin - no changes needed
204 # Figure out if we're compiling with cygwin, http://cygwin.com
207 #SYSTEM_NAME := $(shell uname -s)
208 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
210 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
211 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
212 #NON_ELF_SYSTEM := yes
213 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
219 # ----------------------------------------------------------------------
221 # Various options specifying how GeekOS should be built,
222 # what source files to build, which user programs to build,
223 # etc. This is generally the only section of the makefile
224 # that will need to be modified.
225 # ----------------------------------------------------------------------
227 # List of targets to build by default.
228 # These targets encompass everything needed to boot
230 ALL_TARGETS := vmm vm_kernel
234 palacios/vm_guest.o \
236 palacios/svm_handler.o \
238 palacios/vmm_util.o \
239 palacios/vmm_ctrl_regs.o \
242 palacios/vmm_paging.o \
244 palacios/vmm_debug.o \
246 palacios/vmm_intr.o \
247 palacios/vmm_time.o \
248 palacios/vmm_shadow_paging.o \
249 palacios/vm_guest_mem.o \
251 palacios/vmm_dev_mgr.o \
252 palacios/vmm_decoder.o \
253 palacios/svm_halt.o \
254 palacios/svm_pause.o \
255 palacios/svm_wbinvd.o \
256 palacios/vmm_config.o \
257 palacios/vmm_hashtable.o \
258 palacios/vmm_string.o \
259 palacios/vmm_emulator.o \
260 palacios/vmm_queue.o \
261 palacios/vmm_host_events.o \
262 palacios/svm_lowlevel.o \
266 # vmx.c vmcs_gen.c vmcs.c
268 # Extra C flags for the VMM objects
269 $(VMM_OBJS) :: EXTRA_CFLAGS = \
275 xed/v3-xed-compat.o \
276 xed/v3-udiv-compat.o \
278 $(XED_OBJS) :: EXTRA_CFLAGS =
286 devices/simple_pic.o \
292 devices/bochs_debug.o \
294 $(DEVICES_OBJS) :: EXTRA_CFLAGS =
297 # DECODER is the decoder that will be used
298 # currently we only support xed
302 ifeq ($(DECODER),XED)
303 VMM_OBJS += palacios/vmm_xed.o
310 # ----------------------------------------------------------------------
312 # This section defines programs that are used to build GeekOS.
313 # ----------------------------------------------------------------------
316 V3_ARCH := __V3_64BIT__
318 V3_ARCH := __V3_32BIT__
322 # Uncomment if cross compiling
323 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
324 #TARGET_CC_PREFIX := i386-elf-
326 # Target C compiler. gcc 2.95.2 or later should work.
328 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
330 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
332 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
335 # Target linker. GNU ld is probably to only one that will work.
336 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
339 TARGET_AR := $(TARGET_CC_PREFIX)ar
342 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
345 TARGET_NM := $(TARGET_CC_PREFIX)nm
348 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
350 # Nasm (http://nasm.sourceforge.net)
351 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
352 #NASM := /opt/vmm-tools/bin/nasm
364 # Tool to build PFAT filesystem images.
365 BUILDFAT := tools/builtFat.exe
370 # Pad a file so its size is a multiple of some unit (i.e., sector size)
371 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
373 # Create a file filled with zeroes.
374 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
376 # Calculate size of file in sectors
377 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
380 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
383 # ----------------------------------------------------------------------
385 # Options passed to the tools.
386 # ----------------------------------------------------------------------
388 # Flags used for all C source files
398 -I$(PROJECT_ROOT)/include \
401 -Wp,-MD,$(@D)/.$(@F).d \
408 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
409 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
411 # ----------------------------------------------------------------------
413 # Describes how to compile the source files.
414 # ----------------------------------------------------------------------
416 # Compilation of kernel C source files
418 # $(call build,TAG,commandline)
420 # If V=1 on the command line or the environment, then the actual
421 # command executed will be echoed to the terminal. Otherwise
422 # only the tag and the output file will be printed to make
423 # any warnings stand out from the compile messages.
426 @if [ -z "$V" ]; then \
437 $(call build,CC,$(TARGET_CC) \
446 $(call build,AS,$(TARGET_CC) \
463 # ----------------------------------------------------------------------
465 # Specifies files to be built
466 # ----------------------------------------------------------------------
468 # Default target - see definition of ALL_TARGETS in Configuration section
472 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
475 # -I$(PROJECT_ROOT)/src/geekos/ \
476 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
480 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
481 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
486 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
489 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
492 force_rombios: rombios_link
493 (cd ../src/vmboot/rombios; make clean; make)
495 force_vgabios: vgabios_link
496 (cd ../src/vmboot/vgabios; make clean; make)
498 force_payload: force_rombios force_vgabios
499 ../scripts/make_payload.pl payload_layout.txt vm_kernel
501 inter1: force_payload
506 vmm: palacios/vmm.lib
511 # Loadable (flat) kernel image.
512 palacios/vmm.bin : palacios/vmm.lib
513 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
516 # The kernel executable and symbol map.
517 palacios/vmm.lib: libv3vee.a
523 $(call build,AR,$(TARGET_AR) rcs $@ $^)
531 # Clean build directories of generated files
533 for d in palacios devices xed; do \
534 (cd $$d && rm -f * .*.d); \
538 # Include all of the generated dependency files if they exist