Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Cleaned up debug support for nested paging
[palacios.git] / palacios / build / Makefile
1 # Makefile for GeekOS kernel, userspace, and tools
2 #
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> 
8 #
9 # Based on GeekOS Makefile:
10 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
11 # $Revision: 1.71 $
12
13
14 # This is free software.  You are permitted to use,
15 # redistribute, and modify it as specified in the file "COPYING".
16
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
21 #
22 # Cygwin (http://cygwin.com) may be used to build GeekOS.
23 # Make sure that gcc, binutils, nasm, and perl are installed.
24
25 # NOTES:
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.
29
30
31 # Base address of kernel
32 #
33 # Note: at top of memory minus three pages (GDT/TSS/IDT) 
34 # minus maximum size
35 #
36 #
37 # Note that the code will initially load at 0x10000
38 #
39 # The setup code needs to copy it up to this address and jump there
40 #
41
42
43
44
45 PROJECT_ROOT := ..
46 VPATH := $(PROJECT_ROOT)/src
47
48 #when -DNDEBUG is set the kassert functions are disabled
49 #JRLDEBUG=-DNDEBUG
50
51 # DEBUG=1 means VMM_DEBUG, VMM_INFO, and VMM_TRACE are enabled
52 # as are SERIAL_PRINT_DEBUG
53
54
55 ifeq ($(LEAN_AND_MEAN),1) 
56 DEBUG := 0
57 DEBUG_SECTIONS :=
58 else
59 DEBUG := 1
60 DEBUG_SECTIONS := 
61 endif
62
63
64 ifeq ($(DEBUG_ALL),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
66 endif
67
68
69 ifeq ($(DEBUG_SHADOW_PAGING),1)
70 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
71 else 
72 ifeq ($(DEBUG_SHADOW_PAGING),0) 
73 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
74 endif
75
76 endif
77 ifeq ($(DEBUG_NESTED_PAGING),1)
78 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NESTED_PAGING
79 else 
80 ifeq ($(DEBUG_NESTED_PAGING),0) 
81 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NESTED_PAGING
82 endif
83 endif
84
85 ifeq ($(DEBUG_CTRL_REGS),1)
86 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
87 else 
88 ifeq ($(DEBUG_CTRL_REGS),0) 
89 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
90 endif
91 endif
92
93 ifeq ($(DEBUG_INTERRUPTS),1)
94 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
95 else 
96 ifeq ($(DEBUG_INTERRUPTS),0) 
97 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
98 endif
99 endif
100
101 ifeq ($(DEBUG_IO),1)
102 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
103 else 
104 ifeq ($(DEBUG_IO),0) 
105 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
106 endif
107 endif
108
109 ifeq ($(DEBUG_KEYBOARD),1)
110 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
111 else 
112 ifeq ($(DEBUG_KEYBOARD),0) 
113 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
114 endif
115 endif
116
117 ifeq ($(DEBUG_PIC),1)
118 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
119 else 
120 ifeq ($(DEBUG_PIC),0) 
121 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
122 endif
123 endif
124
125 ifeq ($(DEBUG_PIT),1)
126 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
127 else 
128 ifeq ($(DEBUG_PIT),0) 
129 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
130 endif
131 endif
132
133 ifeq ($(DEBUG_NVRAM),1)
134 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
135 else 
136 ifeq ($(DEBUG_NVRAM),0) 
137 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
138 endif
139 endif
140
141 ifeq ($(DEBUG_GENERIC),1)
142 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
143 else 
144 ifeq ($(DEBUG_GENERIC),0) 
145 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
146 endif
147 endif
148
149 ifeq ($(DEBUG_EMULATOR),1)
150 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
151 else 
152 ifeq ($(DEBUG_EMULATOR),0) 
153 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
154 endif
155 endif
156
157 ifeq ($(DEBUG_RAMDISK),1)
158 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
159 else 
160 ifeq ($(DEBUG_RAMDISK),0) 
161 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
162 endif
163 endif
164
165 ifeq ($(TRACE_RAMDISK),1)
166 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
167 else
168 ifeq ($(TRACE_RAMDSK),0)
169 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
170 endif
171 endif
172
173 ifeq ($(DEBUG_XED),1)
174 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
175 else 
176 ifeq ($(DEBUG_XED),0) 
177 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
178 endif
179 endif
180
181 ifeq ($(DEBUG_HALT),1)
182 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
183 else 
184 ifeq ($(DEBUG_HALT),0) 
185 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
186 endif
187 endif
188
189 ifeq ($(DEBUG_APIC),1)
190 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_APIC
191 else 
192 ifeq ($(DEBUG_APIC),0) 
193 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_APIC
194 endif
195 endif
196
197 ifeq ($(DEBUG_PCI),1)
198 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PCI
199 else 
200 ifeq ($(DEBUG_PCI),0) 
201 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PCI
202 endif
203 endif
204
205 ifeq ($(DEBUG_DEV_MGR),1)
206 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
207 else 
208 ifeq ($(DEBUG_DEV_MGR),0)
209 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
210 endif
211 endif
212
213 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
214
215 ifeq ($(DEBUG),1)
216   JRLDEBUG=  -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
217 else
218
219 endif
220
221
222
223
224
225
226 #
227 # This is wrong for current cygwin - no changes needed
228 #
229 # Figure out if we're compiling with cygwin, http://cygwin.com
230 #
231
232 #SYSTEM_NAME := $(shell uname -s)
233 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
234 #SYM_PFX            := _
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
239 #endif
240
241
242
243 ifeq ($(INSTRUMENT_VMM),1)
244   EXTRA_C_OPTS:= -DINSTRUMENT_VMM
245   INSTRUMENT_OPT := -finstrument-functions
246   OBJ_FILES := palacios/vmm_instrument.o
247 else
248   INSTRUMENT_OPT := 
249 endif
250
251
252
253 # ----------------------------------------------------------------------
254 # Configuration -
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 # ----------------------------------------------------------------------
260
261 # List of targets to build by default.
262 # These targets encompass everything needed to boot
263 # and run GeekOS.
264 ALL_TARGETS := vmm force_payload
265
266
267 VMM_OBJS := \
268         palacios/vm_guest.o \
269         palacios/svm.o \
270         palacios/svm_handler.o \
271         palacios/vmm.o \
272         palacios/vmm_util.o \
273         palacios/vmm_ctrl_regs.o \
274         palacios/vmcb.o \
275         palacios/vmm_mem.o \
276         palacios/vmm_paging.o \
277         palacios/vmm_io.o \
278         palacios/vmm_debug.o \
279         palacios/svm_io.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 \
285         palacios/vm_dev.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 \
298         palacios/vmm_msr.o \
299         palacios/svm_msr.o \
300         palacios/vmm_socket.o \
301         palacios/vmm_xed.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 \
307         $(OBJ_FILES)
308
309 #               vmx.c vmcs_gen.c vmcs.c
310
311 # Extra C flags for the VMM objects
312 $(VMM_OBJS) :: EXTRA_CFLAGS = \
313         $(JRLDEBUG) \
314
315
316
317 XED_OBJS := \
318         xed/v3-xed-compat.o \
319         xed/v3-udiv-compat.o \
320
321 $(XED_OBJS) :: EXTRA_CFLAGS = \
322         $(JRLDEBUG) \
323
324 DEVICES_OBJS := \
325         devices/generic.o \
326         devices/keyboard.o \
327         devices/nvram.o \
328         devices/timer.o \
329         devices/simple_pic.o \
330         devices/8259a.o \
331         devices/8254.o \
332         devices/serial.o \
333         devices/ramdisk.o \
334         devices/cdrom.o \
335         devices/bochs_debug.o \
336         devices/os_debug.o \
337         devices/apic.o  \
338         devices/io_apic.o \
339         devices/pci.o \
340         devices/para_net.o \
341
342 #       devices/vnic.o \
343
344 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
345         $(JRLDEBUG) \
346
347
348
349 # ----------------------------------------------------------------------
350 # Tools -
351 #   This section defines programs that are used to build GeekOS.
352 # ----------------------------------------------------------------------
353
354 ifeq ($(ARCH),64)
355 V3_ARCH := __V3_64BIT__
356 else 
357 V3_ARCH := __V3_32BIT__
358 endif
359
360
361 ifeq ($(CRAY_XT),1)
362 EXTRA_C_OPTS := $(EXTRA_C_OPTS) -DCRAY_XT
363 endif
364
365
366 # Uncomment if cross compiling
367 #TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
368 #TARGET_CC_PREFIX :=  i386-elf-
369
370 # Target C compiler.  gcc 2.95.2 or later should work.
371 ifeq ($(ARCH),64)
372 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
373 else 
374 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
375 endif
376 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
377
378
379 # Target linker.  GNU ld is probably to only one that will work.
380 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
381
382 # Target archiver
383 TARGET_AR := $(TARGET_CC_PREFIX)ar
384
385 # Target ranlib
386 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
387
388 # Target nm
389 TARGET_NM := $(TARGET_CC_PREFIX)nm
390
391 # Target objcopy
392 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
393
394 # Nasm (http://nasm.sourceforge.net)
395 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
396 #NASM := /opt/vmm-tools/bin/nasm
397
398 CPP := cpp
399
400
401 ifeq ($(ARCH),64)
402 AS = as --64
403 else 
404 AS = as --32
405 endif
406
407
408 # Tool to build PFAT filesystem images.
409 BUILDFAT := tools/builtFat.exe
410
411 # Perl5 or later
412 PERL := perl
413
414 # Pad a file so its size is a multiple of some unit (i.e., sector size)
415 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
416
417 # Create a file filled with zeroes.
418 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
419
420 # Calculate size of file in sectors
421 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
422
423
424 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
425
426
427 # ----------------------------------------------------------------------
428 # Definitions -
429 #   Options passed to the tools.
430 # ----------------------------------------------------------------------
431
432 # Flags used for all C source files
433
434 CC_GENERAL_OPTS = \
435         -O \
436         -Wall \
437         -g \
438         -D__V3VEE__ \
439         -D$(V3_ARCH) \
440         $(EXTRA_C_OPTS) \
441         $(VMM_FLAGS) \
442         -I$(PROJECT_ROOT)/include \
443         -Werror \
444         -fPIC \
445         -mno-red-zone \
446         -Wp,-MD,$(@D)/.$(@F).d \
447         -Wp,-MT,$@ \
448
449 #-fPIC \
450 #-fvisibility=hidden
451
452
453 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
454 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
455
456 # ----------------------------------------------------------------------
457 # Rules -
458 #   Describes how to compile the source files.
459 # ----------------------------------------------------------------------
460
461 # Compilation of kernel C source files
462 # Usage:
463 #       $(call build,TAG,commandline)
464 #
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.
469 #
470 build = \
471         @if [ -z "$V" ]; then \
472                 echo '    [$1]  $@'; \
473                 $2; \
474         else \
475                 echo '$2'; \
476                 $2; \
477         fi
478
479
480
481 CC_COMPILE = \
482         $(call build,CC,$(TARGET_CC) \
483                 $(CC_GENERAL_OPTS) \
484                 $(EXTRA_CFLAGS) \
485                 -c \
486                 $< \
487                 -o $@ \
488                 $(INSTRUMENT_OPT) \
489         )
490
491 AS_COMPILE = \
492         $(call build,AS,$(TARGET_CC) \
493                 $(CC_GENERAL_OPTS) \
494                 $(EXTRA_CFLAGS) \
495                 -c \
496                 $< \
497                 -o $@ \
498                 $(INSTRUMENT_OPT) \
499         )
500
501
502 %.o: %.c
503         $(CC_COMPILE)
504 %.o: %.S
505         $(AS_COMPILE)
506 %.o: %.s
507         $(AS_COMPILE)
508
509
510 # ----------------------------------------------------------------------
511 # Targets -
512 #   Specifies files to be built
513 # ----------------------------------------------------------------------
514
515 # Default target - see definition of ALL_TARGETS in Configuration section
516 all : $(ALL_TARGETS)
517
518
519 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
520 #       $(NASM) -O99 \
521 #       -f elf \
522 #               -I$(PROJECT_ROOT)/src/geekos/ \
523 #               $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
524 #       -o $@
525
526
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
529
530
531
532 rombios_link:
533         ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
534
535 vgabios_link:
536         ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
537
538
539 force_payload: rombios_link vgabios_link
540         ../scripts/make_payload.pl payload_layout.txt vm_kernel
541
542 inter1: force_payload
543         -make clean
544
545 world: inter1 vmm
546
547 vmm: palacios/vmm.lib 
548
549
550
551
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
555
556
557 # The kernel executable and symbol map.
558 palacios/vmm.lib: libv3vee.a
559 libv3vee.a: \
560         $(VMM_OBJS) \
561         $(DEVICES_OBJS) \
562         $(XED_OBJS) \
563
564         $(call build,AR,$(TARGET_AR) rcs $@ $^)
565
566 force:
567
568
569
570
571
572 # Clean build directories of generated files
573 clean :
574         for d in palacios devices xed; do \
575                 (cd $$d && rm -f * .*.d); \
576         done
577
578
579 # Include all of the generated dependency files if they exist
580 -include */.*.o.d