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
56 ifeq ($(LEAN_AND_MEAN),1)
66 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
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_CTRL_REGS),1)
78 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
80 ifeq ($(DEBUG_CTRL_REGS),0)
81 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
85 ifeq ($(DEBUG_INTERRUPTS),1)
86 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
88 ifeq ($(DEBUG_INTERRUPTS),0)
89 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
94 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
97 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
101 ifeq ($(DEBUG_KEYBOARD),1)
102 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
104 ifeq ($(DEBUG_KEYBOARD),0)
105 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
109 ifeq ($(DEBUG_PIC),1)
110 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
112 ifeq ($(DEBUG_PIC),0)
113 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
117 ifeq ($(DEBUG_PIT),1)
118 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
120 ifeq ($(DEBUG_PIT),0)
121 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
125 ifeq ($(DEBUG_NVRAM),1)
126 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
128 ifeq ($(DEBUG_NVRAM),0)
129 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
133 ifeq ($(DEBUG_GENERIC),1)
134 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
136 ifeq ($(DEBUG_GENERIC),0)
137 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
141 ifeq ($(DEBUG_EMULATOR),1)
142 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
144 ifeq ($(DEBUG_EMULATOR),0)
145 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
149 ifeq ($(DEBUG_RAMDISK),1)
150 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
152 ifeq ($(DEBUG_RAMDISK),0)
153 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
157 ifeq ($(TRACE_RAMDISK),1)
158 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
160 ifeq ($(TRACE_RAMDSK),0)
161 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
165 ifeq ($(DEBUG_XED),1)
166 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
168 ifeq ($(DEBUG_XED),0)
169 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
173 ifeq ($(DEBUG_HALT),1)
174 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
176 ifeq ($(DEBUG_HALT),0)
177 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
181 ifeq ($(DEBUG_DEV_MGR),1)
182 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
184 ifeq ($(DEBUG_DEV_MGR),0)
185 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
189 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
192 JRLDEBUG= -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
199 # DECODER is the decoder that will be used
200 # currently we only support xed
208 ifeq ($(DECODER),XED)
209 DECODER_SRCS := vmm_xed.c
210 DECODER_FLAGS := -L../lib/xed
212 DECODER_LIBS := $(PROJECT_ROOT)/lib/xed/libxed32e.a
214 DECODER_LIBS := $(PROJECT_ROOT)/lib/xed/libxed.a
226 # This is wrong for current cygwin - no changes needed
228 # Figure out if we're compiling with cygwin, http://cygwin.com
231 #SYSTEM_NAME := $(shell uname -s)
232 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
234 #EXTRA_C_OPTS := -DNEED_UNDERSCORE -DGNU_WIN32
235 #EXTRA_NASM_OPTS := -DNEED_UNDERSCORE
236 #NON_ELF_SYSTEM := yes
237 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
243 # ----------------------------------------------------------------------
245 # Various options specifying how GeekOS should be built,
246 # what source files to build, which user programs to build,
247 # etc. This is generally the only section of the makefile
248 # that will need to be modified.
249 # ----------------------------------------------------------------------
251 # List of targets to build by default.
252 # These targets encompass everything needed to boot
254 ALL_TARGETS := vmm vm_kernel
262 VMM_ASM_OBJS := $(VMM_ASM_SRCS:%.asm=palacios/%.o)
264 VMM_GAS_SRCS := svm_lowlevel.s
265 VMM_GAS_OBJS := $(VMM_GAS_SRCS:%.s=palacios/%.o)
267 VMM_C_SRCS := vm_guest.c \
268 svm.c svm_handler.c vmm.c vmm_util.c vmm_ctrl_regs.c \
269 vmcb.c vmm_mem.c vmm_paging.c vmm_io.c vmm_debug.c svm_io.c \
270 vmm_intr.c vmm_time.c \
271 vmm_shadow_paging.c vm_guest_mem.c \
272 vm_dev.c vmm_dev_mgr.c vmm_decoder.c \
273 svm_halt.c svm_pause.c svm_wbinvd.c \
274 vmm_config.c vmm_hashtable.c \
275 vmm_string.c vmm_emulator.c vmm_queue.c\
278 # vmx.c vmcs_gen.c vmcs.c
280 VMM_C_OBJS := $(VMM_C_SRCS:%.c=palacios/%.o)
282 VMM_OBJS := $(VMM_C_OBJS) $(VMM_ASM_OBJS) $(VMM_GAS_OBJS)
286 XED_C_SRCS := v3-xed-compat.c
287 XED_C_OBJS := $(XED_C_SRCS:%.c=xed/%.o)
289 XED_GAS_SRCS := v3-udiv-compat.s
290 XED_GAS_OBJS := $(XED_GAS_SRCS:%.s=xed/%.o)
292 XED_OBJS := $(XED_C_OBJS) $(XED_GAS_OBJS)
296 DEVICE_C_SRCS := generic.c keyboard.c nvram.c timer.c simple_pic.c 8259a.c 8254.c serial.c ramdisk.c cdrom.c bochs_debug.c
298 DEVICE_C_OBJS := $(DEVICE_C_SRCS:%.c=devices/%.o)
300 DEVICE_OBJS := $(DEVICE_C_OBJS)
302 V3LIBS := $(DECODER_LIBS)
308 # ----------------------------------------------------------------------
310 # This section defines programs that are used to build GeekOS.
311 # ----------------------------------------------------------------------
314 V3_ARCH := __V3_64BIT__
316 V3_ARCH := __V3_32BIT__
320 # Uncomment if cross compiling
321 #TARGET_CC_PREFIX := $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
322 #TARGET_CC_PREFIX := i386-elf-
324 # Target C compiler. gcc 2.95.2 or later should work.
326 TARGET_CC := $(TARGET_CC_PREFIX)gcc
328 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
330 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
333 # Target linker. GNU ld is probably to only one that will work.
334 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
337 TARGET_AR := $(TARGET_CC_PREFIX)ar
340 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
343 TARGET_NM := $(TARGET_CC_PREFIX)nm
346 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
348 # Nasm (http://nasm.sourceforge.net)
349 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
350 #NASM := /opt/vmm-tools/bin/nasm
362 # Tool to build PFAT filesystem images.
363 BUILDFAT := tools/builtFat.exe
368 # Pad a file so its size is a multiple of some unit (i.e., sector size)
369 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
371 # Create a file filled with zeroes.
372 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
374 # Calculate size of file in sectors
375 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
378 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
381 # ----------------------------------------------------------------------
383 # Options passed to the tools.
384 # ----------------------------------------------------------------------
386 # Flags used for all C source files
387 #GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(VMM_FLAGS) -fPIC #-fvisibility=hidden
388 GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(VMM_FLAGS) -fPIC -Werror#-fvisibility=hidden
389 CC_GENERAL_OPTS := $(GENERAL_OPTS)
391 # Flags used for VMM C source files
392 CC_VMM_OPTS := -g -I$(PROJECT_ROOT)/include -D__V3VEE__ -D$(V3_ARCH) $(DECODER_FLAGS) $(JRLDEBUG)
394 # Flags used for VMM C ASM files
395 NASM_VMM_OPTS := -I$(PROJECT_ROOT)/src/palacios/ -f elf $(EXTRA_NASM_OPTS)
401 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
402 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
404 # ----------------------------------------------------------------------
406 # Describes how to compile the source files.
407 # ----------------------------------------------------------------------
411 palacios/%.o : palacios/%.c
412 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o palacios/$*.o
414 palacios/%.o : palacios/%.asm
415 $(NASM) $(NASM_VMM_OPTS) $< -o palacios/$*.o
417 palacios/%.o : palacios/%.S
418 $(CPP) $(CC_VMM_OPTS) $< | $(AS) -o palacios/$*.o
422 devices/%.o : devices/%.c
423 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o devices/$*.o
425 devices/%.o : devices/%.asm
426 $(NASM) $(NASM_VMM_OPTS) $< -o devices/$*.o
430 $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o xed/$*.o
436 # ----------------------------------------------------------------------
438 # Specifies files to be built
439 # ----------------------------------------------------------------------
441 # Default target - see definition of ALL_TARGETS in Configuration section
445 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
448 # -I$(PROJECT_ROOT)/src/geekos/ \
449 # $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
453 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o
454 # $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o -o geekos/test
459 ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
462 ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
465 force_rombios: rombios_link
466 (cd ../src/vmboot/rombios; make clean; make)
468 force_vgabios: vgabios_link
469 (cd ../src/vmboot/vgabios; make clean; make)
471 force_payload: force_rombios force_vgabios
472 ../scripts/make_payload.pl payload_layout.txt vm_kernel
474 inter1: force_payload
479 vmm: palacios/vmm.lib
484 # Loadable (flat) kernel image.
485 palacios/vmm.bin : palacios/vmm.lib
486 $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
489 # The kernel executable and symbol map.
490 palacios/vmm.lib: $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS) vm_kernel
491 # $(TARGET_LD) -o palacios/vmm.lib \
493 # $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS) $(V3LIBS) -b binary vm_kernel
494 # $(TARGET_NM) palacios/vmm.lib > palacios/vmm.syms
495 $(TARGET_AR) rcs libv3vee.a \
496 $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS)
506 # Clean build directories of generated files
508 for d in palacios devices xed; do \
509 (cd $$d && rm -f *); \
513 # Build header file dependencies, so source files are recompiled when
514 # header files they depend on are modified.
515 depend : $(GENERATED_LIBC_SRCS)
517 $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
518 $(VMM_C_SRCS:%.c=$(PROJECT_ROOT)/src/palacios/%.c) \
519 | $(PERL) -n -e 's,^(\S),palacios/$$1,;print' \
521 $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
522 $(DEVICE_C_SRCS:%.c=$(PROJECT_ROOT)/src/devices/%.c) \
523 | $(PERL) -n -e 's,^(\S),devices/$$1,;print' \
526 # By default, there are no header file dependencies.