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.


*** empty log message ***
[palacios.git] / palacios / build / Makefile
1 # Makefile for GeekOS kernel, userspace, and tools
2 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
3 # $Revision: 1.41 $
4
5 # This is free software.  You are permitted to use,
6 # redistribute, and modify it as specified in the file "COPYING".
7
8 # Required software to build GeekOS:
9 # - GNU Make (http://www.gnu.org/software/make)
10 # - gcc 2.95.2 generating code for target (i386/ELF) and host platforms
11 # - nasm (http://nasm.sourceforge.net)
12 # - Perl5, AWK (any version), egrep
13 #
14 # Cygwin (http://cygwin.com) may be used to build GeekOS.
15 # Make sure that gcc, binutils, nasm, and perl are installed.
16
17 # NOTES:
18 # - This makefile has been written carefully to work correctly
19 #   with the -j (parallel make) option.  I regularly use "make -j 2"
20 #   to speed the build process on 2 processor systems.
21
22
23 # Base address of kernel
24 #
25 # Note: at top of memory minus three pages (GDT/TSS/IDT) 
26 # minus maximum size
27 #
28 #
29 # Note that the code will initially load at 0x10000
30 #
31 # The setup code needs to copy it up to this address and jump there
32 #
33 KERNEL_BASE_ADDR := 0x00010000
34
35 # Kernel entry point function
36 KERNEL_ENTRY = $(SYM_PFX)Main
37
38
39 PROJECT_ROOT := ..
40 VPATH := $(PROJECT_ROOT)/src
41
42 #when -DNDEBUG is set the kassert functions are disabled
43 #JRLDEBUG=-DNDEBUG
44 JRLDEBUG= -DSERIAL_PRINT_DEBUG=1 -DSERIAL_PRINT_DEBUG_LEVEL=10 -DSERIAL_PRINT=1
45
46 #
47 #
48 #Peter's compile flags
49 PADFLAGS =
50
51 #
52 # This is wrong for current cygwin - no changes needed
53 #
54 # Figure out if we're compiling with cygwin, http://cygwin.com
55 #
56
57 #SYSTEM_NAME := $(shell uname -s)
58 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
59 #SYM_PFX            := _
60 #EXTRA_C_OPTS       := -DNEED_UNDERSCORE -DGNU_WIN32
61 #EXTRA_NASM_OPTS    := -DNEED_UNDERSCORE
62 #NON_ELF_SYSTEM     := yes
63 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
64 #endif
65
66
67
68
69 # ----------------------------------------------------------------------
70 # Configuration -
71 #   Various options specifying how GeekOS should be built,
72 #   what source files to build, which user programs to build,
73 #   etc.  This is generally the only section of the makefile
74 #   that will need to be modified.
75 # ----------------------------------------------------------------------
76
77 # List of targets to build by default.
78 # These targets encompass everything needed to boot
79 # and run GeekOS.
80 ALL_TARGETS := vmm.img vm_kernel
81
82
83 # Kernel source files
84 KERNEL_C_SRCS := idt.c int.c trap.c irq.c io.c \
85         blockdev.c ide.c \
86         keyboard.c screen.c timer.c \
87         mem.c crc32.c \
88         gdt.c tss.c segment.c \
89         bget.c malloc.c \
90         synch.c kthread.c \
91         serial.c  reboot.c \
92         paging.c \
93         debug.c vmm_stubs.c  vm.c  pci.c\
94         main.c
95
96 # Kernel object files built from C source files
97 KERNEL_C_OBJS := $(KERNEL_C_SRCS:%.c=geekos/%.o)
98
99 # Kernel assembly files
100 KERNEL_ASM_SRCS := lowlevel.asm
101
102 KERNEL_GAS_SRCS := testvm.s
103
104 # Kernel object files build from assembler source files
105 KERNEL_ASM_OBJS := $(KERNEL_ASM_SRCS:%.asm=geekos/%.o) 
106
107 KERNEL_GAS_OBJS := $(KERNEL_GAS_SRCS:%.s=geekos/%.o)
108
109
110 # All kernel object files
111 KERNEL_OBJS := $(KERNEL_C_OBJS) \
112   $(KERNEL_ASM_OBJS) $(KERNEL_GAS_OBJS)
113
114 # Common library source files.
115 # This library is linked into both the kernel and user programs.
116 # It provides string functions and generic printf()-style
117 # formatted output.
118 COMMON_C_SRCS := fmtout.c string.c memmove.c
119
120 # Common library object files.
121 COMMON_C_OBJS := $(COMMON_C_SRCS:%.c=common/%.o)
122
123 VMM_ASM_SRCS :=  svm_lowlevel.asm \
124 #                       vmx_lowlevel.asm
125
126 VMM_ASM_OBJS := $(VMM_ASM_SRCS:%.asm=palacios/%.o)
127
128
129 VMM_C_SRCS :=   vm_guest.c \
130                 svm.c svm_handler.c vmm.c vmm_util.c vmm_ctrl_regs.c \
131                 vmcb.c vmm_mem.c vmm_paging.c vmm_io.c vmm_debug.c svm_io.c \
132                 vmm_intr.c vmm_time.c\
133                 vmm_shadow_paging.c vm_guest_mem.c  \
134                 vm_dev.c vmm_dev_mgr.c vmm_decoder.c \
135                 svm_halt.c 
136 #\
137 #               vmx.c vmcs_gen.c vmcs.c
138
139 VMM_C_OBJS := $(VMM_C_SRCS:%.c=palacios/%.o)
140
141 VMM_OBJS := $(VMM_C_OBJS) $(VMM_ASM_OBJS)
142
143 DEVICE_C_SRCS :=  generic.c keyboard.c nvram.c timer.c simple_pic.c 8259a.c 8254.c
144
145 DEVICE_C_OBJS := $(DEVICE_C_SRCS:%.c=devices/%.o)
146
147 DEVICE_OBJS := $(DEVICE_C_OBJS)
148
149
150
151 # ----------------------------------------------------------------------
152 # Tools -
153 #   This section defines programs that are used to build GeekOS.
154 # ----------------------------------------------------------------------
155
156 # Uncomment if cross compiling
157 TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
158 #TARGET_CC_PREFIX :=  i386-elf-
159
160 # Target C compiler.  gcc 2.95.2 or later should work.
161 TARGET_CC := $(TARGET_CC_PREFIX)gcc
162 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
163
164 # Host C compiler.  This is used to compile programs to execute on
165 # the host platform, not the target (x86) platform.  On x86/ELF
166 # systems, such as Linux and FreeBSD, it can generally be the same
167 # as the target C compiler.
168 HOST_CC := gcc
169
170 # Target linker.  GNU ld is probably to only one that will work.
171 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
172
173 # Target archiver
174 TARGET_AR := $(TARGET_CC_PREFIX)ar
175
176 # Target ranlib
177 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
178
179 # Target nm
180 TARGET_NM := $(TARGET_CC_PREFIX)nm
181
182 # Target objcopy
183 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
184
185 # Nasm (http://nasm.sourceforge.net)
186 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
187 #NASM := /opt/vmm-tools/bin/nasm
188
189 AS = as --32
190
191 # Tool to build PFAT filesystem images.
192 BUILDFAT := tools/builtFat.exe
193
194 # Perl5 or later
195 PERL := perl
196
197 # Pad a file so its size is a multiple of some unit (i.e., sector size)
198 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
199
200 # Create a file filled with zeroes.
201 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
202
203 # Calculate size of file in sectors
204 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
205
206
207 # ----------------------------------------------------------------------
208 # Definitions -
209 #   Options passed to the tools.
210 # ----------------------------------------------------------------------
211
212 # Flags used for all C source files
213 GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(JRLDEBUG) $(PADFLAGS) -fPIC
214 CC_GENERAL_OPTS := $(GENERAL_OPTS) -Werror 
215
216 # Flags used for kernel C source files
217 CC_KERNEL_OPTS := -g -DGEEKOS -I$(PROJECT_ROOT)/include
218
219 # Flags used for VMM C source files
220 CC_VMM_OPTS := -g -I$(PROJECT_ROOT)/include -D__V3VEE__ -D__V3_32BIT__
221
222 # Flags used for VMM C ASM files
223 NASM_VMM_OPTS := -I$(PROJECT_ROOT)/src/palacios/ -f elf $(EXTRA_NASM_OPTS)
224
225 # Flags user for kernel assembly files
226 NASM_KERNEL_OPTS := -I$(PROJECT_ROOT)/src/geekos/ -f elf $(EXTRA_NASM_OPTS)
227
228 # Flags used for common library and libc source files
229 CC_USER_OPTS := -I$(PROJECT_ROOT)/include -I$(PROJECT_ROOT)/include/libc \
230         $(EXTRA_CC_USER_OPTS)
231
232 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
233 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
234
235 # ----------------------------------------------------------------------
236 # Rules -
237 #   Describes how to compile the source files.
238 # ----------------------------------------------------------------------
239
240 # Compilation of kernel C source files
241
242 geekos/%.o : geekos/%.c
243         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $< -o geekos/$*.o
244
245
246 # Compilation of kernel assembly source files
247 geekos/%.o : geekos/%.asm
248         $(NASM) $(NASM_KERNEL_OPTS) $< -o geekos/$*.o
249
250 # Compilation of test VM
251 geekos/%.o : geekos/%.s
252         $(AS) $< -o geekos/$*.o
253
254 geekos/%.o : geekos/%.S
255         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $< -o geekos/$*.o
256
257 # Compilation of common library C source files
258 common/%.o : common/%.c
259         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_USER_OPTS) $< -o common/$*.o
260
261 palacios/%.o : palacios/%.c
262         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o palacios/$*.o
263
264 palacios/%.o : palacios/%.asm
265         $(NASM) $(NASM_VMM_OPTS) $< -o palacios/$*.o
266
267 devices/%.o : devices/%.c
268         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_VMM_OPTS) $< -o devices/$*.o
269
270 devices/%.o : devices/%.asm
271         $(NASM) $(NASM_VMM_OPTS) $< -o devices/$*.o
272
273 # ----------------------------------------------------------------------
274 # Targets -
275 #   Specifies files to be built
276 # ----------------------------------------------------------------------
277
278 # Default target - see definition of ALL_TARGETS in Configuration section
279 all : $(ALL_TARGETS)
280
281
282 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
283 #       $(NASM) -O99 \
284 #       -f elf \
285 #               -I$(PROJECT_ROOT)/src/geekos/ \
286 #               $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
287 #       -o $@
288
289
290 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o 
291 #       $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o  -o geekos/test
292
293 # Standard floppy image - just boots the kernel
294 fd.img : geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin vm_kernel
295         cat geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin > _temp
296         $(PAD) _temp 512
297         cat _temp vm_kernel > $@
298
299 vmm.img : fd.img
300         cp fd.img vmm.img
301         $(PAD) vmm.img 1474560
302
303 force_rombios: 
304         (cd ../src/vmboot/rombios; make clean; make)
305 #       cp ../src/vmboot/rombios/BIOS-bochs-latest rombios
306
307 force_vgabios:
308         (cd ../src/vmboot/vgabios; make clean; make)
309
310 world: force_rombios force_vgabios
311         ../scripts/make_payload.pl payload_layout.txt vm_kernel
312         - make clean
313         make vmm.img
314
315 # make ready to boot over PXE
316 pxe:    vmm.img
317         cp vmm.img /tftpboot/vmm.img
318
319
320
321 # Floppy boot sector (first stage boot loader).
322 geekos/fd_boot.bin : geekos/setup.bin geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/fd_boot.asm vm_kernel
323         $(NASM) -f bin \
324                 -I$(PROJECT_ROOT)/src/geekos/ \
325                 -DNUM_SETUP_SECTORS=`$(NUMSECS) geekos/setup.bin` \
326                 -DNUM_KERN_SECTORS=`$(NUMSECS) geekos/kernel.bin` \
327                 -DNUM_VM_KERNEL_SECTORS=`$(NUMSECS) vm_kernel` \
328                 $(PROJECT_ROOT)/src/geekos/fd_boot.asm \
329                 -o $@
330
331 # Setup program (second stage boot loader).
332 geekos/setup.bin : geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/setup.asm
333         $(NASM) -f bin \
334                 -I$(PROJECT_ROOT)/src/geekos/ \
335                 -DENTRY_POINT=0x`egrep 'Main$$' geekos/kernel.syms |awk '{print $$1}'` \
336                 -DVMM_SIZE=`$(NUMSECS) geekos/kernel.bin` \
337                 -DGUEST_SIZE=`$(NUMSECS) vm_kernel` \
338                 $(PROJECT_ROOT)/src/geekos/setup.asm \
339                 -o $@
340         $(PAD) $@ 512
341
342 # Loadable (flat) kernel image.
343 geekos/kernel.bin : geekos/kernel.exe
344         $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary geekos/kernel.exe geekos/kernel.bin
345         $(PAD) $@ 512
346
347 # The kernel executable and symbol map.
348 geekos/kernel.exe : $(KERNEL_OBJS) $(COMMON_C_OBJS) $(VMM_OBJS) $(DEVICE_OBJS)
349         $(TARGET_LD) -o geekos/kernel.exe -Ttext $(KERNEL_BASE_ADDR) -e $(KERNEL_ENTRY) \
350                 $(KERNEL_OBJS) $(COMMON_C_OBJS) $(VMM_OBJS) $(DEVICE_OBJS)
351         $(TARGET_NM) geekos/kernel.exe > geekos/kernel.syms
352
353
354 force:
355
356
357 vm_kernel: force
358         $(PAD) vm_kernel 512
359         @echo "VM kernel lives at 0x100000 and is" `$(NUMSECS) vm_kernel` "sectors long"
360
361
362
363
364 # Clean build directories of generated files
365 clean :
366         for d in geekos common libc user tools palacios devices; do \
367                 (cd $$d && rm -f *); \
368         done
369
370
371 # Build header file dependencies, so source files are recompiled when
372 # header files they depend on are modified.
373 depend : $(GENERATED_LIBC_SRCS)
374         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
375                 $(KERNEL_C_SRCS:%.c=$(PROJECT_ROOT)/src/geekos/%.c) \
376                 | $(PERL) -n -e 's,^(\S),geekos/$$1,;print' \
377                 > depend.mak
378         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_USER_OPTS) \
379                 $(COMMON_C_SRCS:%.c=$(PROJECT_ROOT)/src/common/%.c) \
380                 | $(PERL) -n -e 's,^(\S),common/$$1,;print' \
381                 >> depend.mak
382         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
383                 $(VMM_C_SRCS:%.c=$(PROJECT_ROOT)/src/palacios/%.c) \
384                 | $(PERL) -n -e 's,^(\S),palacios/$$1,;print' \
385                 >> depend.mak
386         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
387                 $(DEVICE_C_SRCS:%.c=$(PROJECT_ROOT)/src/devices/%.c) \
388                 | $(PERL) -n -e 's,^(\S),devices/$$1,;print' \
389                 >> depend.mak
390
391 # By default, there are no header file dependencies.
392 depend.mak :
393         touch $@
394
395 include depend.mak