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.


0d114cd6f11a2f0e911859ae635403a6e44f205f
[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_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
67 endif
68
69
70 ifeq ($(DEBUG_SHADOW_PAGING),1)
71 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_SHADOW_PAGING
72 else 
73 ifeq ($(DEBUG_SHADOW_PAGING),0) 
74 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_SHADOW_PAGING
75 endif
76 endif
77
78 ifeq ($(DEBUG_CTRL_REGS),1)
79 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_CTRL_REGS
80 else 
81 ifeq ($(DEBUG_CTRL_REGS),0) 
82 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_CTRL_REGS
83 endif
84 endif
85
86 ifeq ($(DEBUG_INTERRUPTS),1)
87 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_INTERRUPTS
88 else 
89 ifeq ($(DEBUG_INTERRUPTS),0) 
90 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_INTERRUPTS
91 endif
92 endif
93
94 ifeq ($(DEBUG_IO),1)
95 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_IO
96 else 
97 ifeq ($(DEBUG_IO),0) 
98 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_IO
99 endif
100 endif
101
102 ifeq ($(DEBUG_KEYBOARD),1)
103 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_KEYBOARD
104 else 
105 ifeq ($(DEBUG_KEYBOARD),0) 
106 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_KEYBOARD
107 endif
108 endif
109
110 ifeq ($(DEBUG_PIC),1)
111 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIC
112 else 
113 ifeq ($(DEBUG_PIC),0) 
114 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIC
115 endif
116 endif
117
118 ifeq ($(DEBUG_PIT),1)
119 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_PIT
120 else 
121 ifeq ($(DEBUG_PIT),0) 
122 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_PIT
123 endif
124 endif
125
126 ifeq ($(DEBUG_NVRAM),1)
127 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_NVRAM
128 else 
129 ifeq ($(DEBUG_NVRAM),0) 
130 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_NVRAM
131 endif
132 endif
133
134 ifeq ($(DEBUG_GENERIC),1)
135 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_GENERIC
136 else 
137 ifeq ($(DEBUG_GENERIC),0) 
138 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_GENERIC
139 endif
140 endif
141
142 ifeq ($(DEBUG_EMULATOR),1)
143 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_EMULATOR
144 else 
145 ifeq ($(DEBUG_EMULATOR),0) 
146 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_EMULATOR
147 endif
148 endif
149
150 ifeq ($(DEBUG_RAMDISK),1)
151 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_RAMDISK
152 else 
153 ifeq ($(DEBUG_RAMDISK),0) 
154 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_RAMDISK
155 endif
156 endif
157
158 ifeq ($(TRACE_RAMDISK),1)
159 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTRACE_RAMDISK
160 else
161 ifeq ($(TRACE_RAMDSK),0)
162 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UTRACE_RAMDISK
163 endif
164 endif
165
166 ifeq ($(DEBUG_XED),1)
167 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_XED
168 else 
169 ifeq ($(DEBUG_XED),0) 
170 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_XED
171 endif
172 endif
173
174 ifeq ($(DEBUG_HALT),1)
175 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_HALT
176 else 
177 ifeq ($(DEBUG_HALT),0) 
178 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_HALT
179 endif
180 endif
181
182 ifeq ($(DEBUG_APIC),1)
183 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_APIC
184 else 
185 ifeq ($(DEBUG_APIC),0) 
186 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_APIC
187 endif
188 endif
189
190 ifeq ($(DEBUG_DEV_MGR),1)
191 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
192 else 
193 ifeq ($(DEBUG_DEV_MGR),0)
194 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
195 endif
196 endif
197
198 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
199
200 ifeq ($(DEBUG),1)
201   JRLDEBUG=  -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
202 else
203
204 endif
205
206
207
208
209
210
211 #
212 # This is wrong for current cygwin - no changes needed
213 #
214 # Figure out if we're compiling with cygwin, http://cygwin.com
215 #
216
217 #SYSTEM_NAME := $(shell uname -s)
218 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
219 #SYM_PFX            := _
220 #EXTRA_C_OPTS       := -DNEED_UNDERSCORE -DGNU_WIN32
221 #EXTRA_NASM_OPTS    := -DNEED_UNDERSCORE
222 #NON_ELF_SYSTEM     := yes
223 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
224 #endif
225
226
227
228 ifeq ($(INSTRUMENT_VMM),1)
229   EXTRA_C_OPTS:= -DINSTRUMENT_VMM
230   INSTRUMENT_OPT := -finstrument-functions
231   OBJ_FILES := palacios/vmm_instrument.o
232 else
233   INSTRUMENT_OPT := 
234 endif
235
236
237
238 # ----------------------------------------------------------------------
239 # Configuration -
240 #   Various options specifying how GeekOS should be built,
241 #   what source files to build, which user programs to build,
242 #   etc.  This is generally the only section of the makefile
243 #   that will need to be modified.
244 # ----------------------------------------------------------------------
245
246 # List of targets to build by default.
247 # These targets encompass everything needed to boot
248 # and run GeekOS.
249 ALL_TARGETS := vmm force_payload
250
251
252 VMM_OBJS := \
253         palacios/vm_guest.o \
254         palacios/svm.o \
255         palacios/svm_handler.o \
256         palacios/vmm.o \
257         palacios/vmm_util.o \
258         palacios/vmm_ctrl_regs.o \
259         palacios/vmcb.o \
260         palacios/vmm_mem.o \
261         palacios/vmm_paging.o \
262         palacios/vmm_io.o \
263         palacios/vmm_debug.o \
264         palacios/svm_io.o \
265         palacios/vmm_intr.o \
266         palacios/vmm_time.o \
267         palacios/vmm_shadow_paging.o \
268         palacios/vm_guest_mem.o \
269         palacios/vm_dev.o \
270         palacios/vmm_dev_mgr.o \
271         palacios/vmm_decoder.o \
272         palacios/svm_halt.o \
273         palacios/svm_pause.o \
274         palacios/svm_wbinvd.o \
275         palacios/vmm_config.o \
276         palacios/vmm_hashtable.o \
277         palacios/vmm_string.o \
278         palacios/vmm_emulator.o \
279         palacios/vmm_queue.o \
280         palacios/vmm_host_events.o \
281         palacios/svm_lowlevel.o \
282         palacios/vmm_msr.o \
283         palacios/svm_msr.o \
284         palacios/vmm_socket.o \
285         palacios/vmm_xed.o \
286         palacios/vmm_rbtree.o \
287         palacios/vmm_profiler.o \
288         palacios/vmm_direct_paging.o \
289         palacios/vmm_ringbuffer.o \
290         palacios/vmm_hypercall.o \
291         $(OBJ_FILES)
292
293 #               vmx.c vmcs_gen.c vmcs.c
294
295 # Extra C flags for the VMM objects
296 $(VMM_OBJS) :: EXTRA_CFLAGS = \
297         $(JRLDEBUG) \
298
299
300
301 XED_OBJS := \
302         xed/v3-xed-compat.o \
303         xed/v3-udiv-compat.o \
304
305 $(XED_OBJS) :: EXTRA_CFLAGS = \
306         $(JRLDEBUG) \
307
308 DEVICES_OBJS := \
309         devices/generic.o \
310         devices/keyboard.o \
311         devices/nvram.o \
312         devices/timer.o \
313         devices/simple_pic.o \
314         devices/8259a.o \
315         devices/8254.o \
316         devices/serial.o \
317         devices/ramdisk.o \
318         devices/cdrom.o \
319         devices/bochs_debug.o \
320         devices/os_debug.o \
321         devices/apic.o  \
322         devices/io_apic.o \
323         devices/vnic.o \
324         devices/vpci.o \
325
326 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
327         $(JRLDEBUG) \
328
329
330
331 # ----------------------------------------------------------------------
332 # Tools -
333 #   This section defines programs that are used to build GeekOS.
334 # ----------------------------------------------------------------------
335
336 ifeq ($(ARCH),64)
337 V3_ARCH := __V3_64BIT__
338 else 
339 V3_ARCH := __V3_32BIT__
340 endif
341
342
343 # Uncomment if cross compiling
344 #TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
345 #TARGET_CC_PREFIX :=  i386-elf-
346
347 # Target C compiler.  gcc 2.95.2 or later should work.
348 ifeq ($(ARCH),64)
349 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
350 else 
351 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
352 endif
353 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
354
355
356 # Target linker.  GNU ld is probably to only one that will work.
357 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
358
359 # Target archiver
360 TARGET_AR := $(TARGET_CC_PREFIX)ar
361
362 # Target ranlib
363 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
364
365 # Target nm
366 TARGET_NM := $(TARGET_CC_PREFIX)nm
367
368 # Target objcopy
369 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
370
371 # Nasm (http://nasm.sourceforge.net)
372 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
373 #NASM := /opt/vmm-tools/bin/nasm
374
375 CPP := cpp
376
377
378 ifeq ($(ARCH),64)
379 AS = as --64
380 else 
381 AS = as --32
382 endif
383
384
385 # Tool to build PFAT filesystem images.
386 BUILDFAT := tools/builtFat.exe
387
388 # Perl5 or later
389 PERL := perl
390
391 # Pad a file so its size is a multiple of some unit (i.e., sector size)
392 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
393
394 # Create a file filled with zeroes.
395 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
396
397 # Calculate size of file in sectors
398 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
399
400
401 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
402
403
404 # ----------------------------------------------------------------------
405 # Definitions -
406 #   Options passed to the tools.
407 # ----------------------------------------------------------------------
408
409 # Flags used for all C source files
410
411 CC_GENERAL_OPTS = \
412         -O \
413         -Wall \
414         -g \
415         -D__V3VEE__ \
416         -D$(V3_ARCH) \
417         $(EXTRA_C_OPTS) \
418         $(VMM_FLAGS) \
419         -I$(PROJECT_ROOT)/include \
420         -Werror \
421         -fPIC \
422         -Wp,-MD,$(@D)/.$(@F).d \
423         -Wp,-MT,$@ \
424
425 #-fPIC \
426 #-fvisibility=hidden
427
428
429 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
430 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
431
432 # ----------------------------------------------------------------------
433 # Rules -
434 #   Describes how to compile the source files.
435 # ----------------------------------------------------------------------
436
437 # Compilation of kernel C source files
438 # Usage:
439 #       $(call build,TAG,commandline)
440 #
441 # If V=1 on the command line or the environment, then the actual
442 # command executed will be echoed to the terminal.  Otherwise
443 # only the tag and the output file will be printed to make
444 # any warnings stand out from the compile messages.
445 #
446 build = \
447         @if [ -z "$V" ]; then \
448                 echo '    [$1]  $@'; \
449                 $2; \
450         else \
451                 echo '$2'; \
452                 $2; \
453         fi
454
455
456
457 CC_COMPILE = \
458         $(call build,CC,$(TARGET_CC) \
459                 $(CC_GENERAL_OPTS) \
460                 $(EXTRA_CFLAGS) \
461                 -c \
462                 $< \
463                 -o $@ \
464                 $(INSTRUMENT_OPT) \
465         )
466
467 AS_COMPILE = \
468         $(call build,AS,$(TARGET_CC) \
469                 $(CC_GENERAL_OPTS) \
470                 $(EXTRA_CFLAGS) \
471                 -c \
472                 $< \
473                 -o $@ \
474                 $(INSTRUMENT_OPT) \
475         )
476
477
478 %.o: %.c
479         $(CC_COMPILE)
480 %.o: %.S
481         $(AS_COMPILE)
482 %.o: %.s
483         $(AS_COMPILE)
484
485
486 # ----------------------------------------------------------------------
487 # Targets -
488 #   Specifies files to be built
489 # ----------------------------------------------------------------------
490
491 # Default target - see definition of ALL_TARGETS in Configuration section
492 all : $(ALL_TARGETS)
493
494
495 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
496 #       $(NASM) -O99 \
497 #       -f elf \
498 #               -I$(PROJECT_ROOT)/src/geekos/ \
499 #               $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
500 #       -o $@
501
502
503 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o 
504 #       $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o  -o geekos/test
505
506
507
508 rombios_link:
509         ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
510
511 vgabios_link:
512         ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
513
514
515 force_rombios: rombios_link
516         (cd ../src/vmboot/rombios; make clean; make)
517
518 force_vgabios: vgabios_link
519         (cd ../src/vmboot/vgabios; make clean; make)
520
521 force_payload: force_rombios force_vgabios
522         ../scripts/make_payload.pl payload_layout.txt vm_kernel
523
524 inter1: force_payload
525         -make clean
526
527 world: inter1 vmm
528
529 vmm: palacios/vmm.lib 
530
531
532
533
534 # Loadable (flat) kernel image.
535 palacios/vmm.bin : palacios/vmm.lib
536         $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
537
538
539 # The kernel executable and symbol map.
540 palacios/vmm.lib: libv3vee.a
541 libv3vee.a: \
542         $(VMM_OBJS) \
543         $(DEVICES_OBJS) \
544         $(XED_OBJS) \
545
546         $(call build,AR,$(TARGET_AR) rcs $@ $^)
547
548 force:
549
550
551
552
553
554 # Clean build directories of generated files
555 clean :
556         for d in palacios devices xed; do \
557                 (cd $$d && rm -f * .*.d); \
558         done
559
560
561 # Include all of the generated dependency files if they exist
562 -include */.*.o.d