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 64bit support to makefiles
[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 # - nasm (http://nasm.sourceforge.net)
21 # - Perl5, AWK (any version), egrep
22 #
23 # Cygwin (http://cygwin.com) may be used to build GeekOS.
24 # Make sure that gcc, binutils, nasm, and perl are installed.
25
26 # NOTES:
27 # - This makefile has been written carefully to work correctly
28 #   with the -j (parallel make) option.  I regularly use "make -j 2"
29 #   to speed the build process on 2 processor systems.
30
31
32 # Base address of kernel
33 #
34 # Note: at top of memory minus three pages (GDT/TSS/IDT) 
35 # minus maximum size
36 #
37 #
38 # Note that the code will initially load at 0x10000
39 #
40 # The setup code needs to copy it up to this address and jump there
41 #
42
43
44
45
46 PROJECT_ROOT := ..
47 VPATH := $(PROJECT_ROOT)/src
48
49 #when -DNDEBUG is set the kassert functions are disabled
50 #JRLDEBUG=-DNDEBUG
51
52 # DEBUG=1 means VMM_DEBUG, VMM_INFO, and VMM_TRACE are enabled
53 # as are SERIAL_PRINT_DEBUG
54
55
56 ifeq ($(LEAN_AND_MEAN),1) 
57 DEBUG=0
58 DEBUG_SECTIONS=
59 else
60 DEBUG=1
61 DEBUG_SECTIONS= 
62 endif
63
64
65 ifeq ($(DEBUG_ALL),1)
66   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
67 endif
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_DEV_MGR),1)
182 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DDEBUG_DEV_MGR
183 else 
184 ifeq ($(DEBUG_DEV_MGR),0)
185 DEBUG_SECTIONS := $(DEBUG_SECTIONS) -UDEBUG_DEV_MGR
186 endif
187 endif
188
189 #DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
190
191 ifeq ($(DEBUG),1)
192   JRLDEBUG=  -DVMM_DEBUG -DVMM_INFO -DVMM_TRACE $(DEBUG_SECTIONS)
193 else
194
195 endif
196
197
198 #
199 # DECODER is the decoder that will be used 
200 # currently we only support xed
201 #
202 DECODER=XED
203
204 DECODER_FLAGS=
205 DECODER_SRCS=
206 DECODER_LIBS=
207
208 ifeq ($(DECODER),XED)
209 DECODER_SRCS := vmm_xed.c
210 DECODER_FLAGS :=  -L../lib/xed
211 ifeq ($(ARCH),64)
212 DECODER_LIBS := $(PROJECT_ROOT)/lib/xed/libxed32e.a
213 else 
214 DECODER_LIBS := $(PROJECT_ROOT)/lib/xed/libxed.a
215 endif
216 else
217 # This is an error
218 endif
219
220
221
222
223
224
225 #
226 # This is wrong for current cygwin - no changes needed
227 #
228 # Figure out if we're compiling with cygwin, http://cygwin.com
229 #
230
231 #SYSTEM_NAME := $(shell uname -s)
232 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
233 #SYM_PFX            := _
234 #EXTRA_C_OPTS       := -DNEED_UNDERSCORE -DGNU_WIN32
235 #EXTRA_NASM_OPTS    := -DNEED_UNDERSCORE
236 #NON_ELF_SYSTEM     := yes
237 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
238 #endif
239
240
241
242
243 # ----------------------------------------------------------------------
244 # Configuration -
245 #   Various options specifying how GeekOS should be built,
246 #   what source files to build, which user programs to build,
247 #   etc.  This is generally the only section of the makefile
248 #   that will need to be modified.
249 # ----------------------------------------------------------------------
250
251 # List of targets to build by default.
252 # These targets encompass everything needed to boot
253 # and run GeekOS.
254 ALL_TARGETS := vmm vm_kernel
255
256
257
258
259
260
261 VMM_ASM_SRCS :=
262 VMM_ASM_OBJS := $(VMM_ASM_SRCS:%.asm=palacios/%.o)
263
264 VMM_GAS_SRCS := svm_lowlevel.s
265 VMM_GAS_OBJS := $(VMM_GAS_SRCS:%.s=palacios/%.o)
266
267 VMM_C_SRCS :=   vm_guest.c \
268                 svm.c svm_handler.c vmm.c vmm_util.c vmm_ctrl_regs.c \
269                 vmcb.c vmm_mem.c vmm_paging.c vmm_io.c vmm_debug.c svm_io.c \
270                 vmm_intr.c vmm_time.c \
271                 vmm_shadow_paging.c vm_guest_mem.c  \
272                 vm_dev.c vmm_dev_mgr.c vmm_decoder.c \
273                 svm_halt.c svm_pause.c svm_wbinvd.c \
274                 vmm_config.c vmm_hashtable.c \
275                 vmm_string.c vmm_emulator.c vmm_queue.c\
276                 vmm_host_events.c \
277                  $(DECODER_SRCS)
278 #               vmx.c vmcs_gen.c vmcs.c
279
280 VMM_C_OBJS := $(VMM_C_SRCS:%.c=palacios/%.o)
281
282 VMM_OBJS := $(VMM_C_OBJS) $(VMM_ASM_OBJS) $(VMM_GAS_OBJS)
283
284
285
286 XED_C_SRCS := v3-xed-compat.c
287 XED_C_OBJS := $(XED_C_SRCS:%.c=xed/%.o)
288
289 XED_GAS_SRCS := v3-udiv-compat.s
290 XED_GAS_OBJS := $(XED_GAS_SRCS:%.s=xed/%.o)
291
292 XED_OBJS := $(XED_C_OBJS) $(XED_GAS_OBJS)
293
294
295
296 DEVICE_C_SRCS := generic.c keyboard.c nvram.c timer.c simple_pic.c 8259a.c 8254.c serial.c ramdisk.c cdrom.c bochs_debug.c
297
298 DEVICE_C_OBJS := $(DEVICE_C_SRCS:%.c=devices/%.o)
299
300 DEVICE_OBJS := $(DEVICE_C_OBJS)
301
302 V3LIBS := $(DECODER_LIBS)
303
304
305
306
307
308 # ----------------------------------------------------------------------
309 # Tools -
310 #   This section defines programs that are used to build GeekOS.
311 # ----------------------------------------------------------------------
312
313 ifeq ($(ARCH),64)
314 V3_ARCH := __V3_64BIT__
315 else 
316 V3_ARCH := __V3_32BIT__
317 endif
318
319
320 # Uncomment if cross compiling
321 #TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
322 #TARGET_CC_PREFIX :=  i386-elf-
323
324 # Target C compiler.  gcc 2.95.2 or later should work.
325 ifeq ($(ARCH),64)
326 TARGET_CC := $(TARGET_CC_PREFIX)gcc
327 else 
328 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32
329 endif
330 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
331
332
333 # Target linker.  GNU ld is probably to only one that will work.
334 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
335
336 # Target archiver
337 TARGET_AR := $(TARGET_CC_PREFIX)ar
338
339 # Target ranlib
340 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
341
342 # Target nm
343 TARGET_NM := $(TARGET_CC_PREFIX)nm
344
345 # Target objcopy
346 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
347
348 # Nasm (http://nasm.sourceforge.net)
349 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
350 #NASM := /opt/vmm-tools/bin/nasm
351
352 CPP := cpp
353
354
355 ifeq ($(ARCH),64)
356 AS = as
357 else 
358 AS = as --32
359 endif
360
361
362 # Tool to build PFAT filesystem images.
363 BUILDFAT := tools/builtFat.exe
364
365 # Perl5 or later
366 PERL := perl
367
368 # Pad a file so its size is a multiple of some unit (i.e., sector size)
369 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
370
371 # Create a file filled with zeroes.
372 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
373
374 # Calculate size of file in sectors
375 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
376
377
378 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
379
380
381 # ----------------------------------------------------------------------
382 # Definitions -
383 #   Options passed to the tools.
384 # ----------------------------------------------------------------------
385
386 # Flags used for all C source files
387 #GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(VMM_FLAGS) -fPIC #-fvisibility=hidden
388 GENERAL_OPTS :=  -O -Wall  $(EXTRA_C_OPTS) $(VMM_FLAGS) -fPIC -Werror#-fvisibility=hidden
389 CC_GENERAL_OPTS := $(GENERAL_OPTS) 
390
391 # Flags used for VMM C source files
392 CC_VMM_OPTS := -g -I$(PROJECT_ROOT)/include -D__V3VEE__ -D$(V3_ARCH) $(DECODER_FLAGS) $(JRLDEBUG)
393
394 # Flags used for VMM C ASM files
395 NASM_VMM_OPTS := -I$(PROJECT_ROOT)/src/palacios/ -f elf $(EXTRA_NASM_OPTS)
396
397
398
399
400
401 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
402 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
403
404 # ----------------------------------------------------------------------
405 # Rules -
406 #   Describes how to compile the source files.
407 # ----------------------------------------------------------------------
408
409
410
411 palacios/%.o : palacios/%.c
412         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o palacios/$*.o
413
414 palacios/%.o : palacios/%.asm
415         $(NASM) $(NASM_VMM_OPTS) $< -o palacios/$*.o
416
417 palacios/%.o : palacios/%.S
418         $(CPP) $(CC_VMM_OPTS) $< | $(AS) -o palacios/$*.o
419
420
421
422 devices/%.o : devices/%.c
423         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o devices/$*.o
424
425 devices/%.o : devices/%.asm
426         $(NASM) $(NASM_VMM_OPTS) $< -o devices/$*.o
427
428
429 xed/%.o : xed/%.c
430         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o xed/$*.o
431
432 xed/%.o : xed/%.s
433         $(AS) $< -o xed/$*.o
434
435
436 # ----------------------------------------------------------------------
437 # Targets -
438 #   Specifies files to be built
439 # ----------------------------------------------------------------------
440
441 # Default target - see definition of ALL_TARGETS in Configuration section
442 all : $(ALL_TARGETS)
443
444
445 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
446 #       $(NASM) -O99 \
447 #       -f elf \
448 #               -I$(PROJECT_ROOT)/src/geekos/ \
449 #               $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
450 #       -o $@
451
452
453 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o 
454 #       $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o  -o geekos/test
455
456
457
458 rombios_link:
459         ln -s -f ../src/vmboot/rombios/BIOS-bochs-latest rombios
460
461 vgabios_link:
462         ln -s -f ../src/vmboot/vgabios/VGABIOS-lgpl-latest.bin vgabios
463
464
465 force_rombios: rombios_link
466         (cd ../src/vmboot/rombios; make clean; make)
467
468 force_vgabios: vgabios_link
469         (cd ../src/vmboot/vgabios; make clean; make)
470
471 force_payload: force_rombios force_vgabios
472         ../scripts/make_payload.pl payload_layout.txt vm_kernel
473
474 inter1: force_payload
475         -make clean
476
477 world: inter1 vmm
478
479 vmm: palacios/vmm.lib 
480
481
482
483
484 # Loadable (flat) kernel image.
485 palacios/vmm.bin : palacios/vmm.lib
486         $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary palacios/vmm.lib palacios/vmm.bin
487
488
489 # The kernel executable and symbol map.
490 palacios/vmm.lib: $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS) vm_kernel
491 #       $(TARGET_LD) -o palacios/vmm.lib  \
492 #               $(DECODER_FLAGS) \
493 #                $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS) $(V3LIBS) -b binary vm_kernel
494 #       $(TARGET_NM) palacios/vmm.lib > palacios/vmm.syms
495         $(TARGET_AR) rcs libv3vee.a  \
496                  $(VMM_OBJS) $(DEVICE_OBJS) $(XED_OBJS)
497
498
499
500 force:
501
502
503
504
505
506 # Clean build directories of generated files
507 clean :
508         for d in palacios devices; do \
509                 (cd $$d && rm -f *); \
510         done
511
512
513 # Build header file dependencies, so source files are recompiled when
514 # header files they depend on are modified.
515 depend : $(GENERATED_LIBC_SRCS)
516
517         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
518                 $(VMM_C_SRCS:%.c=$(PROJECT_ROOT)/src/palacios/%.c) \
519                 | $(PERL) -n -e 's,^(\S),palacios/$$1,;print' \
520                 >> depend.mak
521         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
522                 $(DEVICE_C_SRCS:%.c=$(PROJECT_ROOT)/src/devices/%.c) \
523                 | $(PERL) -n -e 's,^(\S),devices/$$1,;print' \
524                 >> depend.mak
525
526 # By default, there are no header file dependencies.
527 depend.mak :
528         touch $@
529
530 include depend.mak