2 # Northwestern University
3 # (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
4 # (c) 2008, Peter Dinda <pdinda@northwestern.edu>
5 # (c) 2008, Lei Xia <xiaxlei@gmail.com>
6 # (c) 2008, The V3VEE Project <http://www.v3vee.org>
8 # Based on GeekOS Makefile:
9 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
13 # This is free software. You are permitted to use,
14 # redistribute, and modify it as specified in the file "COPYING".
16 # Required software to build GeekOS:
17 # - GNU Make (http://www.gnu.org/software/make)
18 # - gcc 2.95.2 generating code for target (i386/ELF) and host platforms
19 # - Perl5, AWK (any version), egrep
21 # Cygwin (http://cygwin.com) may be used to build GeekOS.
22 # Make sure that gcc, binutils, nasm, and perl are installed.
25 # - This makefile has been written carefully to work correctly
26 # with the -j (parallel make) option. I regularly use "make -j 2"
27 # to speed the build process on 2 processor systems.
30 # Base address of kernel
32 # Note: at top of memory minus three pages (GDT/TSS/IDT)
36 # Note that the code will initially load at 0x10000
38 # The setup code needs to copy it up to this address and jump there
45 VPATH := $(PROJECT_ROOT)/src
47 #when -DNDEBUG is set the kassert functions are disabled
50 # DEBUG=1 means VMM_DEBUG, VMM_INFO, and VMM_TRACE are enabled
51 # as are SERIAL_PRINT_DEBUG
54 ifeq ($(LEAN_AND_MEAN),1)
64 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
67 ifeq ($(DEBUG_SHADOW_PAGING),1)
68 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
70 ifeq ($(DEBUG_SHADOW_PAGING),0)
71 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
75 ifeq ($(DEBUG_CTRL_REGS),1)
76 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
78 ifeq ($(DEBUG_CTRL_REGS),0)
79 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
83 ifeq ($(DEBUG_INTERRUPTS),1)
84 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
86 ifeq ($(DEBUG_INTERRUPTS),0)
87 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
92 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
95 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
99 ifeq ($(DEBUG_KEYBOARD),1)
100 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
102 ifeq ($(DEBUG_KEYBOARD),0)
103 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
107 ifeq ($(DEBUG_PIC),1)
108 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
110 ifeq ($(DEBUG_PIC),0)
111 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
115 ifeq ($(DEBUG_PIT),1)
116 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
118 ifeq ($(DEBUG_PIT),0)
119 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
123 ifeq ($(DEBUG_NVRAM),1)
124 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
126 ifeq ($(DEBUG_NVRAM),0)
127 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
131 ifeq ($(DEBUG_GENERIC),1)
132 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
134 ifeq ($(DEBUG_GENERIC),0)
135 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
139 ifeq ($(DEBUG_EMULATOR),1)
140 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
142 ifeq ($(DEBUG_EMULATOR),0)
143 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
147 ifeq ($(DEBUG_RAMDISK),1)
148 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
150 ifeq ($(DEBUG_RAMDISK),0)
151 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
155 ifeq ($(TRACE_RAMDISK),1)
156 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
158 ifeq ($(TRACE_RAMDSK),0)
159 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
163 ifeq ($(DEBUG_XED),1)
164 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
166 ifeq ($(DEBUG_XED),0)
167 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
171 ifeq ($(DEBUG_HALT),1)
172 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
174 ifeq ($(DEBUG_HALT),0)
175 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
179 ifeq ($(DEBUG_DEV_MGR),1)
180 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
182 ifeq ($(DEBUG_DEV_MGR),0)
183 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
187 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
190 JRLDEBUG= -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
201 # This is wrong for current cygwin - no changes needed
203 # Figure out if we're compiling with cygwin, http://cygwin.com
206 #SYSTEM_NAME := $(shell uname -s)
207 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
209 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
210 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
211 #NON_ELF_SYSTEM := yes
212 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
218 # ----------------------------------------------------------------------
220 # Various options specifying how GeekOS should be built,
221 # what source files to build, which user programs to build,
222 # etc. This is generally the only section of the makefile
223 # that will need to be modified.
224 # ----------------------------------------------------------------------
226 # List of targets to build by default.
227 # These targets encompass everything needed to boot
229 ALL_TARGETS := vmm vm_kernel
233 palacios/vm_guest.o \
235 palacios/svm_handler.o \
237 palacios/vmm_util.o \
238 palacios/vmm_ctrl_regs.o \
241 palacios/vmm_paging.o \
243 palacios/vmm_debug.o \
245 palacios/vmm_intr.o \
246 palacios/vmm_time.o \
247 palacios/vmm_shadow_paging.o \
248 palacios/vm_guest_mem.o \
250 palacios/vmm_dev_mgr.o \
251 palacios/vmm_decoder.o \
252 palacios/svm_halt.o \
253 palacios/svm_pause.o \
254 palacios/svm_wbinvd.o \
255 palacios/vmm_config.o \
256 palacios/vmm_hashtable.o \
257 palacios/vmm_string.o \
258 palacios/vmm_emulator.o \
259 palacios/vmm_queue.o \
260 palacios/vmm_host_events.o \
261 palacios/svm_lowlevel.o \
263 # vmx.c vmcs_gen.c vmcs.c
265 # Extra C flags for the VMM objects
266 $(VMM_OBJS) :: EXTRA_CFLAGS = \
272 xed/v3-xed-compat.o \
273 xed/v3-udiv-compat.o \
275 $(XED_OBJS) :: EXTRA_CFLAGS =
283 devices/simple_pic.o \
289 devices/bochs_debug.o \
291 $(DEVICES_OBJS) :: EXTRA_CFLAGS =
294 # DECODER is the decoder that will be used
295 # currently we only support xed
299 ifeq ($(DECODER),XED)
300 VMM_OBJS += palacios/vmm_xed.o
307 # ----------------------------------------------------------------------
309 # This section defines programs that are used to build GeekOS.
310 # ----------------------------------------------------------------------
313 V3_ARCH := __V3_64BIT__
315 V3_ARCH := __V3_32BIT__
319 # Uncomment if cross compiling
320 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
321 #TARGET_CC_PREFIX := i386-elf-
323 # Target C compiler. gcc 2.95.2 or later should work.
325 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
327 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
329 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
332 # Target linker. GNU ld is probably to only one that will work.
333 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
336 TARGET_AR := $(TARGET_CC_PREFIX)ar
339 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
342 TARGET_NM := $(TARGET_CC_PREFIX)nm
345 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
347 # Nasm (http://nasm.sourceforge.net)
348 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
349 #NASM := /opt/vmm-tools/bin/nasm
351 CPP := $(TARGET_CC_PREFIX)cpp
355 AS = $(TARGET_CC_PREFIX)as --64
357 AS = $(TARGET_CC_PREFIX)as --32
361 # Tool to build PFAT filesystem images.
362 BUILDFAT := tools/builtFat.exe
367 # Pad a file so its size is a multiple of some unit (i.e., sector size)
368 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
370 # Create a file filled with zeroes.
371 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
373 # Calculate size of file in sectors
374 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
377 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
380 # ----------------------------------------------------------------------
382 # Options passed to the tools.
383 # ----------------------------------------------------------------------
385 # Flags used for all C source files
395 -I$(PROJECT_ROOT)/include \
398 -Wp,-MD,$(@D)/.$(@F).d \
405 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
406 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
408 # ----------------------------------------------------------------------
410 # Describes how to compile the source files.
411 # ----------------------------------------------------------------------
413 # Compilation of kernel C source files
415 # $(call build,TAG,commandline)
417 # If V=1 on the command line or the environment, then the actual
418 # command executed will be echoed to the terminal. Otherwise
419 # only the tag and the output file will be printed to make
420 # any warnings stand out from the compile messages.
423 @if [ -z "$V" ]; then \
434 $(call build,CC,$(TARGET_CC) \
437 -fno-stack-protector \
444 $(call build,AS,$(TARGET_CC) \
461 # ----------------------------------------------------------------------
463 # Specifies files to be built
464 # ----------------------------------------------------------------------
466 # Default target - see definition of ALL_TARGETS in Configuration section
470 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
473 # -I$(PROJECT_ROOT)/src/geekos/ \
474 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
478 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
479 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
484 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
487 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
490 force_rombios: rombios_link
491 (cd ../src/vmboot/rombios; make clean; make)
493 force_vgabios: vgabios_link
494 (cd ../src/vmboot/vgabios; make clean; make)
496 force_payload: force_rombios force_vgabios
497 ../scripts/make_payload.pl payload_layout.txt vm_kernel
499 inter1: force_payload
504 vmm: palacios/vmm.lib
509 # Loadable (flat) kernel image.
510 palacios/vmm.bin : palacios/vmm.lib
511 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
514 # The kernel executable and symbol map.
515 palacios/vmm.lib: libv3vee.a
521 $(call build,AR,$(TARGET_AR) rcs $@ $^)
529 # Clean build directories of generated files
531 for d in palacios devices xed; do \
532 (cd $$d && rm -f * .*.d); \
536 # Include all of the generated dependency files if they exist