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 ring buffer
[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_DEV_MGR),1)
183 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
184 else 
185 ifeq ($(DEBUG_DEV_MGR),0)
186 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
187 endif
188 endif
189
190 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
191
192 ifeq ($(DEBUG),1)
193   JRLDEBUG=  -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
194 else
195
196 endif
197
198
199
200
201
202
203 #
204 # This is wrong for current cygwin - no changes needed
205 #
206 # Figure out if we're compiling with cygwin, http://cygwin.com
207 #
208
209 #SYSTEM_NAME := $(shell uname -s)
210 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
211 #SYM_PFX            := _
212 #EXTRA_C_OPTS       := -DNEED_UNDERSCORE -DGNU_WIN32
213 #EXTRA_NASM_OPTS    := -DNEED_UNDERSCORE
214 #NON_ELF_SYSTEM     := yes
215 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
216 #endif
217
218
219
220
221 # ----------------------------------------------------------------------
222 # Configuration -
223 #   Various options specifying how GeekOS should be built,
224 #   what source files to build, which user programs to build,
225 #   etc.  This is generally the only section of the makefile
226 #   that will need to be modified.
227 # ----------------------------------------------------------------------
228
229 # List of targets to build by default.
230 # These targets encompass everything needed to boot
231 # and run GeekOS.
232 ALL_TARGETS := vmm force_payload
233
234
235 VMM_OBJS := \
236         palacios/vm_guest.o \
237         palacios/svm.o \
238         palacios/svm_handler.o \
239         palacios/vmm.o \
240         palacios/vmm_util.o \
241         palacios/vmm_ctrl_regs.o \
242         palacios/vmcb.o \
243         palacios/vmm_mem.o \
244         palacios/vmm_paging.o \
245         palacios/vmm_io.o \
246         palacios/vmm_debug.o \
247         palacios/svm_io.o \
248         palacios/vmm_intr.o \
249         palacios/vmm_time.o \
250         palacios/vmm_shadow_paging.o \
251         palacios/vm_guest_mem.o \
252         palacios/vm_dev.o \
253         palacios/vmm_dev_mgr.o \
254         palacios/vmm_decoder.o \
255         palacios/svm_halt.o \
256         palacios/svm_pause.o \
257         palacios/svm_wbinvd.o \
258         palacios/vmm_config.o \
259         palacios/vmm_hashtable.o \
260         palacios/vmm_string.o \
261         palacios/vmm_emulator.o \
262         palacios/vmm_queue.o \
263         palacios/vmm_host_events.o \
264         palacios/svm_lowlevel.o \
265         palacios/vmm_msr.o \
266         palacios/svm_msr.o \
267         palacios/vmm_socket.o \
268         palacios/vmm_xed.o \
269         palacios/vmm_rbtree.o \
270         palacios/vmm_profiler.o \
271         palacios/vmm_direct_paging.o \
272         palacios/vmm_ringbuffer.o \
273
274 #               vmx.c vmcs_gen.c vmcs.c
275
276 # Extra C flags for the VMM objects
277 $(VMM_OBJS) :: EXTRA_CFLAGS = \
278         $(JRLDEBUG) \
279
280
281
282 XED_OBJS := \
283         xed/v3-xed-compat.o \
284         xed/v3-udiv-compat.o \
285
286 $(XED_OBJS) :: EXTRA_CFLAGS = \
287         $(JRLDEBUG) \
288
289 DEVICES_OBJS := \
290         devices/generic.o \
291         devices/keyboard.o \
292         devices/nvram.o \
293         devices/timer.o \
294         devices/simple_pic.o \
295         devices/8259a.o \
296         devices/8254.o \
297         devices/serial.o \
298         devices/ramdisk.o \
299         devices/cdrom.o \
300         devices/bochs_debug.o \
301         devices/os_debug.o \
302         devices/apic.o  \
303
304 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
305         $(JRLDEBUG) \
306
307
308
309 # ----------------------------------------------------------------------
310 # Tools -
311 #   This section defines programs that are used to build GeekOS.
312 # ----------------------------------------------------------------------
313
314 ifeq ($(ARCH),64)
315 V3_ARCH := __V3_64BIT__
316 else 
317 V3_ARCH := __V3_32BIT__
318 endif
319
320
321 # Uncomment if cross compiling
322 #TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
323 #TARGET_CC_PREFIX :=  i386-elf-
324
325 # Target C compiler.  gcc 2.95.2 or later should work.
326 ifeq ($(ARCH),64)
327 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m64
328 else 
329 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
330 endif
331 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
332
333
334 # Target linker.  GNU ld is probably to only one that will work.
335 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
336
337 # Target archiver
338 TARGET_AR := $(TARGET_CC_PREFIX)ar
339
340 # Target ranlib
341 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
342
343 # Target nm
344 TARGET_NM := $(TARGET_CC_PREFIX)nm
345
346 # Target objcopy
347 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
348
349 # Nasm (http://nasm.sourceforge.net)
350 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
351 #NASM := /opt/vmm-tools/bin/nasm
352
353 CPP := cpp
354
355
356 ifeq ($(ARCH),64)
357 AS = as --64
358 else 
359 AS = as --32
360 endif
361
362
363 # Tool to build PFAT filesystem images.
364 BUILDFAT := tools/builtFat.exe
365
366 # Perl5 or later
367 PERL := perl
368
369 # Pad a file so its size is a multiple of some unit (i.e., sector size)
370 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
371
372 # Create a file filled with zeroes.
373 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
374
375 # Calculate size of file in sectors
376 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
377
378
379 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
380
381
382 # ----------------------------------------------------------------------
383 # Definitions -
384 #   Options passed to the tools.
385 # ----------------------------------------------------------------------
386
387 # Flags used for all C source files
388
389 CC_GENERAL_OPTS = \
390         -O \
391         -Wall \
392         -g \
393         -D__V3VEE__ \
394         -D$(V3_ARCH) \
395         $(EXTRA_C_OPTS) \
396         $(VMM_FLAGS) \
397         -I$(PROJECT_ROOT)/include \
398         -Werror \
399         -fPIC \
400         -Wp,-MD,$(@D)/.$(@F).d \
401         -Wp,-MT,$@ \
402
403 #-fPIC \
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