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_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_RAMDISK
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_CTRL_REGS),1)
79 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
81 ifeq ($(DEBUG_CTRL_REGS),0)
82 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
86 ifeq ($(DEBUG_INTERRUPTS),1)
87 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
89 ifeq ($(DEBUG_INTERRUPTS),0)
90 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
95 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
98 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
102 ifeq ($(DEBUG_KEYBOARD),1)
103 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
105 ifeq ($(DEBUG_KEYBOARD),0)
106 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
110 ifeq ($(DEBUG_PIC),1)
111 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
113 ifeq ($(DEBUG_PIC),0)
114 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
118 ifeq ($(DEBUG_PIT),1)
119 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
121 ifeq ($(DEBUG_PIT),0)
122 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
126 ifeq ($(DEBUG_NVRAM),1)
127 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
129 ifeq ($(DEBUG_NVRAM),0)
130 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
134 ifeq ($(DEBUG_GENERIC),1)
135 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
137 ifeq ($(DEBUG_GENERIC),0)
138 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
142 ifeq ($(DEBUG_EMULATOR),1)
143 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
145 ifeq ($(DEBUG_EMULATOR),0)
146 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
150 ifeq ($(DEBUG_RAMDISK),1)
151 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
153 ifeq ($(DEBUG_RAMDISK),0)
154 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
158 ifeq ($(TRACE_RAMDISK),1)
159 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
161 ifeq ($(TRACE_RAMDSK),0)
162 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
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_DEV_MGR),1)
183 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
185 ifeq ($(DEBUG_DEV_MGR),0)
186 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
190 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
193 JRLDEBUG= -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
204 # This is wrong for current cygwin - no changes needed
206 # Figure out if we're compiling with cygwin, http://cygwin.com
209 #SYSTEM_NAME := $(shell uname -s)
210 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
212 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
213 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
214 #NON_ELF_SYSTEM := yes
215 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
220 ifeq ($(INSTRUMENT_VMM),1)
221 EXTRA_C_OPTS:= -DINSTRUMENT_VMM
224 # ----------------------------------------------------------------------
226 # Various options specifying how GeekOS should be built,
227 # what source files to build, which user programs to build,
228 # etc. This is generally the only section of the makefile
229 # that will need to be modified.
230 # ----------------------------------------------------------------------
232 # List of targets to build by default.
233 # These targets encompass everything needed to boot
235 ALL_TARGETS := vmm force_payload
239 palacios/vm_guest.o \
241 palacios/svm_handler.o \
243 palacios/vmm_util.o \
244 palacios/vmm_ctrl_regs.o \
247 palacios/vmm_paging.o \
249 palacios/vmm_debug.o \
251 palacios/vmm_intr.o \
252 palacios/vmm_time.o \
253 palacios/vmm_shadow_paging.o \
254 palacios/vm_guest_mem.o \
256 palacios/vmm_dev_mgr.o \
257 palacios/vmm_decoder.o \
258 palacios/svm_halt.o \
259 palacios/svm_pause.o \
260 palacios/svm_wbinvd.o \
261 palacios/vmm_config.o \
262 palacios/vmm_hashtable.o \
263 palacios/vmm_string.o \
264 palacios/vmm_emulator.o \
265 palacios/vmm_queue.o \
266 palacios/vmm_host_events.o \
267 palacios/svm_lowlevel.o \
270 palacios/vmm_socket.o \
272 palacios/vmm_rbtree.o \
273 palacios/vmm_profiler.o \
274 palacios/vmm_direct_paging.o \
275 palacios/vmm_ringbuffer.o \
276 palacios/vmm_instrument.o \
278 # vmx.c vmcs_gen.c vmcs.c
280 # Extra C flags for the VMM objects
281 $(VMM_OBJS) :: EXTRA_CFLAGS = \
287 xed/v3-xed-compat.o \
288 xed/v3-udiv-compat.o \
290 $(XED_OBJS) :: EXTRA_CFLAGS = \
298 devices/simple_pic.o \
304 devices/bochs_debug.o \
308 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
313 # ----------------------------------------------------------------------
315 # This section defines programs that are used to build GeekOS.
316 # ----------------------------------------------------------------------
319 V3_ARCH := __V3_64BIT__
321 V3_ARCH := __V3_32BIT__
325 # Uncomment if cross compiling
326 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
327 #TARGET_CC_PREFIX := i386-elf-
329 # Target C compiler. gcc 2.95.2 or later should work.
331 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
333 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
335 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
338 # Target linker. GNU ld is probably to only one that will work.
339 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
342 TARGET_AR := $(TARGET_CC_PREFIX)ar
345 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
348 TARGET_NM := $(TARGET_CC_PREFIX)nm
351 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
353 # Nasm (http://nasm.sourceforge.net)
354 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
355 #NASM := /opt/vmm-tools/bin/nasm
367 # Tool to build PFAT filesystem images.
368 BUILDFAT := tools/builtFat.exe
373 # Pad a file so its size is a multiple of some unit (i.e., sector size)
374 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
376 # Create a file filled with zeroes.
377 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
379 # Calculate size of file in sectors
380 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
383 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
386 # ----------------------------------------------------------------------
388 # Options passed to the tools.
389 # ----------------------------------------------------------------------
391 # Flags used for all C source files
401 -I$(PROJECT_ROOT)/include \
404 -Wp,-MD,$(@D)/.$(@F).d \
410 ifeq ($(INSTRUMENT_VMM),1)
411 INSTRUMENT_OPT = -finstrument-functions
416 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
417 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
419 # ----------------------------------------------------------------------
421 # Describes how to compile the source files.
422 # ----------------------------------------------------------------------
424 # Compilation of kernel C source files
426 # $(call build,TAG,commandline)
428 # If V=1 on the command line or the environment, then the actual
429 # command executed will be echoed to the terminal. Otherwise
430 # only the tag and the output file will be printed to make
431 # any warnings stand out from the compile messages.
434 @if [ -z "$V" ]; then \
445 $(call build,CC,$(TARGET_CC) \
455 $(call build,AS,$(TARGET_CC) \
473 # ----------------------------------------------------------------------
475 # Specifies files to be built
476 # ----------------------------------------------------------------------
478 # Default target - see definition of ALL_TARGETS in Configuration section
482 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
485 # -I$(PROJECT_ROOT)/src/geekos/ \
486 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
490 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
491 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
496 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
499 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
502 force_rombios: rombios_link
503 (cd ../src/vmboot/rombios; make clean; make)
505 force_vgabios: vgabios_link
506 (cd ../src/vmboot/vgabios; make clean; make)
508 force_payload: force_rombios force_vgabios
509 ../scripts/make_payload.pl payload_layout.txt vm_kernel
511 inter1: force_payload
516 vmm: palacios/vmm.lib
521 # Loadable (flat) kernel image.
522 palacios/vmm.bin : palacios/vmm.lib
523 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
526 # The kernel executable and symbol map.
527 palacios/vmm.lib: libv3vee.a
533 $(call build,AR,$(TARGET_AR) rcs $@ $^)
541 # Clean build directories of generated files
543 for d in palacios devices xed; do \
544 (cd $$d && rm -f * .*.d); \
548 # Include all of the generated dependency files if they exist