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.


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