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 # - nasm (http://nasm.sourceforge.net)
21 # - Perl5, AWK (any version), egrep
23 # Cygwin (http://cygwin.com) may be used to build GeekOS.
24 # Make sure that gcc, binutils, nasm, and perl are installed.
27 # - This makefile has been written carefully to work correctly
28 # with the -j (parallel make) option. I regularly use "make -j 2"
29 # to speed the build process on 2 processor systems.
32 # Base address of kernel
34 # Note: at top of memory minus three pages (GDT/TSS/IDT)
38 # Note that the code will initially load at 0x10000
40 # The setup code needs to copy it up to this address and jump there
47 VPATH := $(PROJECT_ROOT)/src
49 #when -DNDEBUG is set the kassert functions are disabled
52 # DEBUG=1 means VMM_DEBUG, VMM_INFO, and VMM_TRACE are enabled
53 # as are SERIAL_PRINT_DEBUG
59 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
62 ifeq ($(DEBUG_SHADOW_PAGING),1)
63 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
65 ifeq ($(DEBUG_SHADOW_PAGING),0)
66 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
70 ifeq ($(DEBUG_CTRL_REGS),1)
71 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
73 ifeq ($(DEBUG_CTRL_REGS),0)
74 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
78 ifeq ($(DEBUG_INTERRUPTS),1)
79 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
81 ifeq ($(DEBUG_INTERRUPTS),0)
82 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
87 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
90 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
94 ifeq ($(DEBUG_KEYBOARD),1)
95 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
97 ifeq ($(DEBUG_KEYBOARD),0)
98 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
102 ifeq ($(DEBUG_PIC),1)
103 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
105 ifeq ($(DEBUG_PIC),0)
106 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
110 ifeq ($(DEBUG_PIT),1)
111 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
113 ifeq ($(DEBUG_PIT),0)
114 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
118 ifeq ($(DEBUG_NVRAM),1)
119 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
121 ifeq ($(DEBUG_NVRAM),0)
122 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
126 ifeq ($(DEBUG_GENERIC),1)
127 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
129 ifeq ($(DEBUG_GENERIC),0)
130 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
134 ifeq ($(DEBUG_EMULATOR),1)
135 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
137 ifeq ($(DEBUG_EMULATOR),0)
138 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
142 ifeq ($(DEBUG_RAMDISK),1)
143 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
145 ifeq ($(DEBUG_RAMDISK),0)
146 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
150 ifeq ($(TRACE_RAMDISK),1)
151 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
153 ifeq ($(TRACE_RAMDSK),0)
154 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
158 ifeq ($(DEBUG_XED),1)
159 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
161 ifeq ($(DEBUG_XED),0)
162 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
166 ifeq ($(DEBUG_HALT),1)
167 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
169 ifeq ($(DEBUG_HALT),0)
170 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
175 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
178 JRLDEBUG= -DSERIAL_PRINT_DEBUG=1 -DSERIAL_PRINT_DEBUG_LEVEL=10 -DSERIAL_PRINT=1 -DVMM_DEBUG=1 -DVMM_INFO=1 -DVMM_TRACE=1 $(DEBUG_SECTIONS)
181 JRLDEBUG= -DSERIAL_PRINT_DEBUG=0 -DSERIAL_PRINT_DEBUG_LEVEL=999999 -DSERIAL_PRINT=0 -DVMM_DEBUG=0 -DVMM_INFO=0 -DVMM_TRACE=0
186 # DECODER is the decoder that will be used
187 # currently we only support xed
195 ifeq ($(DECODER),XED)
196 DECODER_SRCS := vmm_xed.c
197 DECODER_FLAGS := -L../lib/xed
198 DECODER_LIBS := $(PROJECT_ROOT)/lib/xed/libxed.a
209 # This is wrong for current cygwin - no changes needed
211 # Figure out if we're compiling with cygwin, http://cygwin.com
214 #SYSTEM_NAME := $(shell uname -s)
215 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
217 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
218 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
219 #NON_ELF_SYSTEM := yes
220 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
226 # ----------------------------------------------------------------------
228 # Various options specifying how GeekOS should be built,
229 # what source files to build, which user programs to build,
230 # etc. This is generally the only section of the makefile
231 # that will need to be modified.
232 # ----------------------------------------------------------------------
234 # List of targets to build by default.
235 # These targets encompass everything needed to boot
237 ALL_TARGETS := vmm vm_kernel
244 VMM_ASM_SRCS := svm_lowlevel.asm vmm_lowlevel.asm\
247 VMM_ASM_OBJS := $(VMM_ASM_SRCS:%.asm=palacios/%.o)
250 VMM_C_SRCS := vm_guest.c \
251 svm.c svm_handler.c vmm.c vmm_util.c vmm_ctrl_regs.c \
252 vmcb.c vmm_mem.c vmm_paging.c vmm_io.c vmm_debug.c svm_io.c \
253 vmm_intr.c vmm_time.c \
254 vmm_shadow_paging.c vm_guest_mem.c \
255 vm_dev.c vmm_dev_mgr.c vmm_decoder.c \
256 svm_halt.c svm_pause.c svm_wbinvd.c \
257 vmm_config.c vmm_hashtable.c \
258 vmm_string.c vmm_emulator.c vmm_queue.c\
261 # vmx.c vmcs_gen.c vmcs.c
263 VMM_C_OBJS := $(VMM_C_SRCS:%.c=palacios/%.o)
265 VMM_OBJS := $(VMM_C_OBJS) $(VMM_ASM_OBJS)
269 XED_C_SRCS := v3-xed-compat.c
271 XED_C_OBJS := $(XED_C_SRCS:%.c=xed/%.o)
273 XED_GAS_SRCS := v3-udiv-compat.s
275 XED_GAS_OBJS := $(XED_GAS_SRCS:%.s=xed/%.o)
277 XED_OBJS := $(XED_C_OBJS) $(XED_GAS_OBJS)
281 DEVICE_C_SRCS := generic.c keyboard.c nvram.c timer.c simple_pic.c 8259a.c 8254.c serial.c ramdisk.c cdrom.c
283 DEVICE_C_OBJS := $(DEVICE_C_SRCS:%.c=devices/%.o)
285 DEVICE_OBJS := $(DEVICE_C_OBJS)
287 V3LIBS := $(DECODER_LIBS)
293 # ----------------------------------------------------------------------
295 # This section defines programs that are used to build GeekOS.
296 # ----------------------------------------------------------------------
299 V3_ARCH := __V3_32BIT__
300 #V3_ARCH := __V3_64BIT__
302 # Uncomment if cross compiling
303 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
304 #TARGET_CC_PREFIX := i386-elf-
306 # Target C compiler. gcc 2.95.2 or later should work.
307 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
308 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
311 # Target linker. GNU ld is probably to only one that will work.
312 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
315 TARGET_AR := $(TARGET_CC_PREFIX)ar
318 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
321 TARGET_NM := $(TARGET_CC_PREFIX)nm
324 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
326 # Nasm (http://nasm.sourceforge.net)
327 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
328 #NASM := /opt/vmm-tools/bin/nasm
332 # Tool to build PFAT filesystem images.
333 BUILDFAT := tools/builtFat.exe
338 # Pad a file so its size is a multiple of some unit (i.e., sector size)
339 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
341 # Create a file filled with zeroes.
342 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
344 # Calculate size of file in sectors
345 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
348 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
351 # ----------------------------------------------------------------------
353 # Options passed to the tools.
354 # ----------------------------------------------------------------------
356 # Flags used for all C source files
357 #GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(VMM_FLAGS) -fPIC #-fvisibility=hidden
358 GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(VMM_FLAGS) -fPIC -Werror#-fvisibility=hidden
359 CC_GENERAL_OPTS := $(GENERAL_OPTS)
361 # Flags used for VMM C source files
362 CC_VMM_OPTS := -g -I$(PROJECT_ROOT)/include -D__V3VEE__ -D$(V3_ARCH) $(DECODER_FLAGS) $(JRLDEBUG)
364 # Flags used for VMM C ASM files
365 NASM_VMM_OPTS := -I$(PROJECT_ROOT)/src/palacios/ -f elf $(EXTRA_NASM_OPTS)
371 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
372 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
374 # ----------------------------------------------------------------------
376 # Describes how to compile the source files.
377 # ----------------------------------------------------------------------
381 palacios/%.o : palacios/%.c
382 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o palacios/$*.o
384 palacios/%.o : palacios/%.asm
385 $(NASM) $(NASM_VMM_OPTS) $< -o palacios/$*.o
387 devices/%.o : devices/%.c
388 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o devices/$*.o
390 devices/%.o : devices/%.asm
391 $(NASM) $(NASM_VMM_OPTS) $< -o devices/$*.o
395 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o xed/$*.o
401 # ----------------------------------------------------------------------
403 # Specifies files to be built
404 # ----------------------------------------------------------------------
406 # Default target - see definition of ALL_TARGETS in Configuration section
410 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
413 # -I$(PROJECT_ROOT)/src/geekos/ \
414 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
418 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
419 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
424 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
427 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
430 force_rombios: rombios_link
431 (cd ../src/vmboot/rombios; make clean; make)
433 force_vgabios: vgabios_link
434 (cd ../src/vmboot/vgabios; make clean; make)
436 force_payload: force_rombios force_vgabios
437 ../scripts/make_payload.pl payload_layout.txt vm_kernel
439 inter1: force_payload
444 vmm: palacios/vmm.lib
449 # Loadable (flat) kernel image.
450 palacios/vmm.bin : palacios/vmm.lib
451 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
454 # The kernel executable and symbol map.
455 palacios/vmm.lib: $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS) vm_kernel
456 # $(TARGET_LD) -o palacios/vmm.lib \
458 # $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS) $(V3LIBS) -b binary vm_kernel
459 # $(TARGET_NM) palacios/vmm.lib > palacios/vmm.syms
460 $(TARGET_AR) rcs libv3vee.a \
461 $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS)
471 # Clean build directories of generated files
473 for d in palacios devices; do \
474 (cd $$d && rm -f *); \
478 # Build header file dependencies, so source files are recompiled when
479 # header files they depend on are modified.
480 depend : $(GENERATED_LIBC_SRCS)
482 $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
483 $(VMM_C_SRCS:%.c=$(PROJECT_ROOT)/src/palacios/%.c) \
484 | $(PERL) -n -e 's,^(\S),palacios/$$1,;print' \
486 $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
487 $(DEVICE_C_SRCS:%.c=$(PROJECT_ROOT)/src/devices/%.c) \
488 | $(PERL) -n -e 's,^(\S),devices/$$1,;print' \
491 # By default, there are no header file dependencies.