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 -DDEBUG_IO -DDEBUG_GENERIC -DDEBUG_RAMDISK
69 ifeq ($(DEBUG_SHADOW_PAGING),1)
70 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
72 ifeq ($(DEBUG_SHADOW_PAGING),0)
73 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
77 ifeq ($(DEBUG_NESTED_PAGING),1)
78 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NESTED_PAGING
80 ifeq ($(DEBUG_NESTED_PAGING),0)
81 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NESTED_PAGING
85 ifeq ($(DEBUG_CTRL_REGS),1)
86 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
88 ifeq ($(DEBUG_CTRL_REGS),0)
89 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
93 ifeq ($(DEBUG_INTERRUPTS),1)
94 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
96 ifeq ($(DEBUG_INTERRUPTS),0)
97 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
102 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
105 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
109 ifeq ($(DEBUG_KEYBOARD),1)
110 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
112 ifeq ($(DEBUG_KEYBOARD),0)
113 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
117 ifeq ($(DEBUG_PIC),1)
118 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
120 ifeq ($(DEBUG_PIC),0)
121 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
125 ifeq ($(DEBUG_PIT),1)
126 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
128 ifeq ($(DEBUG_PIT),0)
129 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
133 ifeq ($(DEBUG_NVRAM),1)
134 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
136 ifeq ($(DEBUG_NVRAM),0)
137 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
141 ifeq ($(DEBUG_GENERIC),1)
142 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
144 ifeq ($(DEBUG_GENERIC),0)
145 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
149 ifeq ($(DEBUG_EMULATOR),1)
150 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
152 ifeq ($(DEBUG_EMULATOR),0)
153 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
157 ifeq ($(DEBUG_RAMDISK),1)
158 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
160 ifeq ($(DEBUG_RAMDISK),0)
161 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
165 ifeq ($(TRACE_RAMDISK),1)
166 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
168 ifeq ($(TRACE_RAMDSK),0)
169 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
173 ifeq ($(DEBUG_XED),1)
174 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
176 ifeq ($(DEBUG_XED),0)
177 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
181 ifeq ($(DEBUG_HALT),1)
182 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
184 ifeq ($(DEBUG_HALT),0)
185 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
189 ifeq ($(DEBUG_APIC),1)
190 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_APIC
192 ifeq ($(DEBUG_APIC),0)
193 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_APIC
197 ifeq ($(DEBUG_PCI),1)
198 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PCI
200 ifeq ($(DEBUG_PCI),0)
201 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PCI
205 ifeq ($(DEBUG_DEV_MGR),1)
206 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
208 ifeq ($(DEBUG_DEV_MGR),0)
209 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
213 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
216 JRLDEBUG= -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
227 # This is wrong for current cygwin - no changes needed
229 # Figure out if we're compiling with cygwin, http://cygwin.com
232 #SYSTEM_NAME := $(shell uname -s)
233 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
235 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
236 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
237 #NON_ELF_SYSTEM := yes
238 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
243 ifeq ($(INSTRUMENT_VMM),1)
244 EXTRA_C_OPTS:= -DINSTRUMENT_VMM
245 INSTRUMENT_OPT := -finstrument-functions
246 OBJ_FILES := palacios/vmm_instrument.o
253 # ----------------------------------------------------------------------
255 # Various options specifying how GeekOS should be built,
256 # what source files to build, which user programs to build,
257 # etc. This is generally the only section of the makefile
258 # that will need to be modified.
259 # ----------------------------------------------------------------------
261 # List of targets to build by default.
262 # These targets encompass everything needed to boot
264 ALL_TARGETS := vmm force_payload
268 palacios/vm_guest.o \
270 palacios/svm_handler.o \
272 palacios/vmm_util.o \
273 palacios/vmm_ctrl_regs.o \
276 palacios/vmm_paging.o \
278 palacios/vmm_debug.o \
280 palacios/vmm_intr.o \
281 palacios/vmm_excp.o \
282 palacios/vmm_time.o \
283 palacios/vmm_shadow_paging.o \
284 palacios/vm_guest_mem.o \
286 palacios/vmm_dev_mgr.o \
287 palacios/vmm_decoder.o \
288 palacios/svm_halt.o \
289 palacios/svm_pause.o \
290 palacios/svm_wbinvd.o \
291 palacios/vmm_config.o \
292 palacios/vmm_hashtable.o \
293 palacios/vmm_string.o \
294 palacios/vmm_emulator.o \
295 palacios/vmm_queue.o \
296 palacios/vmm_host_events.o \
297 palacios/svm_lowlevel.o \
300 palacios/vmm_socket.o \
302 palacios/vmm_rbtree.o \
303 palacios/vmm_profiler.o \
304 palacios/vmm_direct_paging.o \
305 palacios/vmm_ringbuffer.o \
306 palacios/vmm_hypercall.o \
309 # vmx.c vmcs_gen.c vmcs.c
311 # Extra C flags for the VMM objects
312 $(VMM_OBJS) :: EXTRA_CFLAGS = \
318 xed/v3-xed-compat.o \
319 xed/v3-udiv-compat.o \
321 $(XED_OBJS) :: EXTRA_CFLAGS = \
329 devices/simple_pic.o \
335 devices/bochs_debug.o \
344 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
349 # ----------------------------------------------------------------------
351 # This section defines programs that are used to build GeekOS.
352 # ----------------------------------------------------------------------
355 V3_ARCH := __V3_64BIT__
357 V3_ARCH := __V3_32BIT__
362 EXTRA_C_OPTS := $(EXTRA_C_OPTS) -DCRAY_XT
366 # Uncomment if cross compiling
367 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
368 #TARGET_CC_PREFIX := i386-elf-
370 # Target C compiler. gcc 2.95.2 or later should work.
372 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
374 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
376 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
379 # Target linker. GNU ld is probably to only one that will work.
380 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
383 TARGET_AR := $(TARGET_CC_PREFIX)ar
386 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
389 TARGET_NM := $(TARGET_CC_PREFIX)nm
392 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
394 # Nasm (http://nasm.sourceforge.net)
395 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
396 #NASM := /opt/vmm-tools/bin/nasm
408 # Tool to build PFAT filesystem images.
409 BUILDFAT := tools/builtFat.exe
414 # Pad a file so its size is a multiple of some unit (i.e., sector size)
415 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
417 # Create a file filled with zeroes.
418 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
420 # Calculate size of file in sectors
421 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
424 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
427 # ----------------------------------------------------------------------
429 # Options passed to the tools.
430 # ----------------------------------------------------------------------
432 # Flags used for all C source files
442 -I$(PROJECT_ROOT)/include \
446 -Wp,-MD,$(@D)/.$(@F).d \
453 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
454 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
456 # ----------------------------------------------------------------------
458 # Describes how to compile the source files.
459 # ----------------------------------------------------------------------
461 # Compilation of kernel C source files
463 # $(call build,TAG,commandline)
465 # If V=1 on the command line or the environment, then the actual
466 # command executed will be echoed to the terminal. Otherwise
467 # only the tag and the output file will be printed to make
468 # any warnings stand out from the compile messages.
471 @if [ -z "$V" ]; then \
482 $(call build,CC,$(TARGET_CC) \
492 $(call build,AS,$(TARGET_CC) \
510 # ----------------------------------------------------------------------
512 # Specifies files to be built
513 # ----------------------------------------------------------------------
515 # Default target - see definition of ALL_TARGETS in Configuration section
519 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
522 # -I$(PROJECT_ROOT)/src/geekos/ \
523 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
527 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
528 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
533 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
536 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
539 force_payload: rombios_link vgabios_link
540 ../scripts/make_payload.pl payload_layout.txt vm_kernel
542 inter1: force_payload
547 vmm: palacios/vmm.lib
552 # Loadable (flat) kernel image.
553 palacios/vmm.bin : palacios/vmm.lib
554 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
557 # The kernel executable and symbol map.
558 palacios/vmm.lib: libv3vee.a
564 $(call build,AR,$(TARGET_AR) rcs $@ $^)
572 # Clean build directories of generated files
574 for d in palacios devices xed; do \
575 (cd $$d && rm -f * .*.d); \
579 # Include all of the generated dependency files if they exist