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.


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