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.


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