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 <lxia@northwestern.edu>
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_NESTED_PAGING -DDEBUG_CTRL_REGS -DDEBUG_INTERRUPTS -DDEBUG_KEYBOARD -DDEBUG_PIC -DDEBUG_PIT -DDEBUG_NVRAM -DDEBUG_EMULATOR -DDEBUG_XED -DDEBUG_HALT -DDEBUG_DEV_MGR
66 # -DDEBUG_IO -DDEBUG_GENERIC -DDEBUG_IDE
70 ifeq ($(DEBUG_SHADOW_PAGING),1)
71 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
73 ifeq ($(DEBUG_SHADOW_PAGING),0)
74 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
78 ifeq ($(DEBUG_NESTED_PAGING),1)
79 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NESTED_PAGING
81 ifeq ($(DEBUG_NESTED_PAGING),0)
82 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NESTED_PAGING
86 ifeq ($(DEBUG_CTRL_REGS),1)
87 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
89 ifeq ($(DEBUG_CTRL_REGS),0)
90 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
94 ifeq ($(DEBUG_INTERRUPTS),1)
95 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
97 ifeq ($(DEBUG_INTERRUPTS),0)
98 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
103 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
106 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
110 ifeq ($(DEBUG_KEYBOARD),1)
111 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
113 ifeq ($(DEBUG_KEYBOARD),0)
114 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
118 ifeq ($(DEBUG_PIC),1)
119 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
121 ifeq ($(DEBUG_PIC),0)
122 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
126 ifeq ($(DEBUG_PIT),1)
127 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
129 ifeq ($(DEBUG_PIT),0)
130 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
134 ifeq ($(DEBUG_NVRAM),1)
135 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
137 ifeq ($(DEBUG_NVRAM),0)
138 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
142 ifeq ($(DEBUG_GENERIC),1)
143 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
145 ifeq ($(DEBUG_GENERIC),0)
146 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
150 ifeq ($(DEBUG_EMULATOR),1)
151 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
153 ifeq ($(DEBUG_EMULATOR),0)
154 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
158 ifeq ($(DEBUG_IDE),1)
159 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IDE
161 ifeq ($(DEBUG_IDE),0)
162 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IDE
166 ifeq ($(DEBUG_XED),1)
167 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
169 ifeq ($(DEBUG_XED),0)
170 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
174 ifeq ($(DEBUG_HALT),1)
175 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
177 ifeq ($(DEBUG_HALT),0)
178 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
182 ifeq ($(DEBUG_APIC),1)
183 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_APIC
185 ifeq ($(DEBUG_APIC),0)
186 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_APIC
190 ifeq ($(DEBUG_PCI),1)
191 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PCI
193 ifeq ($(DEBUG_PCI),0)
194 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PCI
198 ifeq ($(DEBUG_DEV_MGR),1)
199 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
201 ifeq ($(DEBUG_DEV_MGR),0)
202 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
206 ifeq ($(DEBUG_NE2K),1)
207 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NE2K
209 ifeq ($(DEBUG_NE2K),0)
210 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NE2K
214 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
217 JRLDEBUG= -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
228 # This is wrong for current cygwin - no changes needed
230 # Figure out if we're compiling with cygwin, http://cygwin.com
233 #SYSTEM_NAME := $(shell uname -s)
234 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
236 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
237 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
238 #NON_ELF_SYSTEM := yes
239 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
244 ifeq ($(INSTRUMENT_VMM),1)
245 EXTRA_C_OPTS:= -DINSTRUMENT_VMM
246 INSTRUMENT_OPT := -finstrument-functions
247 OBJ_FILES := palacios/vmm_instrument.o
252 CFLAGS = -fno-stack-protector
255 # ----------------------------------------------------------------------
257 # Various options specifying how GeekOS should be built,
258 # what source files to build, which user programs to build,
259 # etc. This is generally the only section of the makefile
260 # that will need to be modified.
261 # ----------------------------------------------------------------------
263 # List of targets to build by default.
264 # These targets encompass everything needed to boot
266 ALL_TARGETS := vmm force_payload
270 palacios/vm_guest.o \
272 palacios/svm_handler.o \
274 palacios/vmm_util.o \
275 palacios/vmm_ctrl_regs.o \
278 palacios/vmm_paging.o \
280 palacios/vmm_debug.o \
282 palacios/vmm_intr.o \
283 palacios/vmm_excp.o \
284 palacios/vmm_time.o \
285 palacios/vmm_shadow_paging.o \
286 palacios/vm_guest_mem.o \
288 palacios/vmm_dev_mgr.o \
289 palacios/vmm_decoder.o \
290 palacios/svm_halt.o \
291 palacios/svm_pause.o \
292 palacios/svm_wbinvd.o \
293 palacios/vmm_config.o \
294 palacios/vmm_hashtable.o \
295 palacios/vmm_string.o \
296 palacios/vmm_emulator.o \
297 palacios/vmm_queue.o \
298 palacios/vmm_host_events.o \
299 palacios/svm_lowlevel.o \
302 palacios/vmm_socket.o \
304 palacios/vmm_rbtree.o \
305 palacios/vmm_profiler.o \
306 palacios/vmm_direct_paging.o \
307 palacios/vmm_ringbuffer.o \
308 palacios/vmm_hypercall.o \
309 palacios/vmm_lock.o \
312 # vmx.c vmcs_gen.c vmcs.c
314 # Extra C flags for the VMM objects
315 $(VMM_OBJS) :: EXTRA_CFLAGS = \
316 $(JRLDEBUG) $(CFLAGS)\
321 xed/v3-xed-compat.o \
322 xed/v3-udiv-compat.o \
324 $(XED_OBJS) :: EXTRA_CFLAGS = \
325 $(JRLDEBUG) $(CFLAGS)\
332 devices/simple_pic.o \
336 devices/bochs_debug.o \
352 # devices/ramdisk.o \
355 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
356 $(JRLDEBUG) $(CFLAGS)\
360 # ----------------------------------------------------------------------
362 # This section defines programs that are used to build GeekOS.
363 # ----------------------------------------------------------------------
366 V3_ARCH := __V3_64BIT__
368 V3_ARCH := __V3_32BIT__
373 EXTRA_C_OPTS := $(EXTRA_C_OPTS) -DCRAY_XT
377 # Uncomment if cross compiling
378 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
379 #TARGET_CC_PREFIX := i386-elf-
381 # Target C compiler. gcc 2.95.2 or later should work.
383 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
385 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
387 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
390 # Target linker. GNU ld is probably to only one that will work.
391 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
394 TARGET_AR := $(TARGET_CC_PREFIX)ar
397 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
400 TARGET_NM := $(TARGET_CC_PREFIX)nm
403 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
405 # Nasm (http://nasm.sourceforge.net)
406 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
407 #NASM := /opt/vmm-tools/bin/nasm
419 # Tool to build PFAT filesystem images.
420 BUILDFAT := tools/builtFat.exe
425 # Pad a file so its size is a multiple of some unit (i.e., sector size)
426 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
428 # Create a file filled with zeroes.
429 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
431 # Calculate size of file in sectors
432 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
435 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
438 # ----------------------------------------------------------------------
440 # Options passed to the tools.
441 # ----------------------------------------------------------------------
443 # Flags used for all C source files
453 -I$(PROJECT_ROOT)/include \
457 -Wp,-MD,$(@D)/.$(@F).d \
464 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
465 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
467 # ----------------------------------------------------------------------
469 # Describes how to compile the source files.
470 # ----------------------------------------------------------------------
472 # Compilation of kernel C source files
474 # $(call build,TAG,commandline)
476 # If V=1 on the command line or the environment, then the actual
477 # command executed will be echoed to the terminal. Otherwise
478 # only the tag and the output file will be printed to make
479 # any warnings stand out from the compile messages.
482 @if [ -z "$V" ]; then \
493 $(call build,CC,$(TARGET_CC) \
503 $(call build,AS,$(TARGET_CC) \
521 # ----------------------------------------------------------------------
523 # Specifies files to be built
524 # ----------------------------------------------------------------------
526 # Default target - see definition of ALL_TARGETS in Configuration section
530 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
533 # -I$(PROJECT_ROOT)/src/geekos/ \
534 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
538 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
539 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
544 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
547 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
550 force_payload: rombios_link vgabios_link
551 ../scripts/make_payload.pl payload_layout.txt vm_kernel
553 inter1: force_payload
558 vmm: palacios/vmm.lib
563 # Loadable (flat) kernel image.
564 palacios/vmm.bin : palacios/vmm.lib
565 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
568 # The kernel executable and symbol map.
569 palacios/vmm.lib: libv3vee.a
575 $(call build,AR,$(TARGET_AR) rcs $@ $^)
583 # Clean build directories of generated files
585 for d in palacios devices xed; do \
586 (cd $$d && rm -f * .*.d); \
590 # Include all of the generated dependency files if they exist