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 support for in/out instructions
[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.21 $
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 # Figure out if we're compiling with cygwin, http://cygwin.com
52 SYSTEM_NAME := $(shell uname -s)
53 ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
54 SYM_PFX            := _
55 EXTRA_C_OPTS       := -DNEED_UNDERSCORE -DGNU_WIN32
56 EXTRA_NASM_OPTS    := -DNEED_UNDERSCORE
57 NON_ELF_SYSTEM     := yes
58 EXTRA_CC_USER_OPTS := -Dmain=geekos_main
59 endif
60
61
62
63
64 # ----------------------------------------------------------------------
65 # Configuration -
66 #   Various options specifying how GeekOS should be built,
67 #   what source files to build, which user programs to build,
68 #   etc.  This is generally the only section of the makefile
69 #   that will need to be modified.
70 # ----------------------------------------------------------------------
71
72 # List of targets to build by default.
73 # These targets encompass everything needed to boot
74 # and run GeekOS.
75 ALL_TARGETS := fd.img vm_kernel
76
77
78 # Kernel source files
79 KERNEL_C_SRCS := idt.c int.c trap.c irq.c io.c \
80         blockdev.c ide.c \
81         keyboard.c screen.c timer.c \
82         mem.c crc32.c \
83         gdt.c tss.c segment.c \
84         bget.c malloc.c \
85         synch.c kthread.c \
86         serial.c  reboot.c \
87         paging.c  vm_guest.c \
88          svm.c svm_handler.c vmm.c vmm_util.c vmm_stubs.c svm_ctrl_regs.c \
89         vmcb.c vmm_mem.c vmm_paging.c vmm_io.c vmm_debug.c svm_io.c \
90         vmm_shadow_paging.c vm_guest_mem.c \
91         debug.c  vmx.c vmcs_gen.c vmcs.c\
92         main.c
93
94 # Kernel object files built from C source files
95 KERNEL_C_OBJS := $(KERNEL_C_SRCS:%.c=geekos/%.o)
96
97 # Kernel assembly files
98 KERNEL_ASM_SRCS := lowlevel.asm vmx_lowlevel.asm svm_lowlevel.asm
99
100 KERNEL_GAS_SRCS := testvm.s
101
102 # Kernel object files build from assembler source files
103 KERNEL_ASM_OBJS := $(KERNEL_ASM_SRCS:%.asm=geekos/%.o) 
104
105 KERNEL_GAS_OBJS := $(KERNEL_GAS_SRCS:%.s=geekos/%.o)
106
107
108 # All kernel object files
109 KERNEL_OBJS := $(KERNEL_C_OBJS) \
110   $(KERNEL_ASM_OBJS) $(KERNEL_GAS_OBJS)
111
112 # Common library source files.
113 # This library is linked into both the kernel and user programs.
114 # It provides string functions and generic printf()-style
115 # formatted output.
116 COMMON_C_SRCS := fmtout.c string.c memmove.c
117
118 # Common library object files.
119 COMMON_C_OBJS := $(COMMON_C_SRCS:%.c=common/%.o)
120
121
122
123
124 # ----------------------------------------------------------------------
125 # Tools -
126 #   This section defines programs that are used to build GeekOS.
127 # ----------------------------------------------------------------------
128
129 # Uncomment if cross compiling
130 TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
131 #TARGET_CC_PREFIX :=  i386-elf-
132
133 # Target C compiler.  gcc 2.95.2 or later should work.
134 TARGET_CC := $(TARGET_CC_PREFIX)gcc
135 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
136
137 # Host C compiler.  This is used to compile programs to execute on
138 # the host platform, not the target (x86) platform.  On x86/ELF
139 # systems, such as Linux and FreeBSD, it can generally be the same
140 # as the target C compiler.
141 HOST_CC := gcc
142
143 # Target linker.  GNU ld is probably to only one that will work.
144 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
145
146 # Target archiver
147 TARGET_AR := $(TARGET_CC_PREFIX)ar
148
149 # Target ranlib
150 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
151
152 # Target nm
153 TARGET_NM := $(TARGET_CC_PREFIX)nm
154
155 # Target objcopy
156 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
157
158 # Nasm (http://nasm.sourceforge.net)
159 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
160 #NASM := /opt/vmm-tools/bin/nasm
161
162 AS = as --32
163
164 # Tool to build PFAT filesystem images.
165 BUILDFAT := tools/builtFat.exe
166
167 # Perl5 or later
168 PERL := perl
169
170 # Pad a file so its size is a multiple of some unit (i.e., sector size)
171 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
172
173 # Create a file filled with zeroes.
174 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
175
176 # Calculate size of file in sectors
177 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
178
179
180 # ----------------------------------------------------------------------
181 # Definitions -
182 #   Options passed to the tools.
183 # ----------------------------------------------------------------------
184
185 # Flags used for all C source files
186 GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(JRLDEBUG) $(PADFLAGS) -fPIC
187 CC_GENERAL_OPTS := $(GENERAL_OPTS) -Werror 
188
189 # Flags used for kernel C source files
190 CC_KERNEL_OPTS := -g -DGEEKOS -I$(PROJECT_ROOT)/include
191
192 # Flags user for kernel assembly files
193 NASM_KERNEL_OPTS := -I$(PROJECT_ROOT)/src/geekos/ -f elf $(EXTRA_NASM_OPTS)
194
195 # Flags used for common library and libc source files
196 CC_USER_OPTS := -I$(PROJECT_ROOT)/include -I$(PROJECT_ROOT)/include/libc \
197         $(EXTRA_CC_USER_OPTS)
198
199 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
200 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
201
202 # ----------------------------------------------------------------------
203 # Rules -
204 #   Describes how to compile the source files.
205 # ----------------------------------------------------------------------
206
207 # Compilation of kernel C source files
208
209 geekos/%.o : geekos/%.c
210         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $< -o geekos/$*.o
211
212
213 # Compilation of kernel assembly source files
214 geekos/%.o : geekos/%.asm
215         $(NASM) $(NASM_KERNEL_OPTS) $< -o geekos/$*.o
216
217 # Compilation of test VM
218 geekos/%.o : geekos/%.s
219         $(AS) $< -o geekos/$*.o
220
221 geekos/%.o : geekos/%.S
222         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $< -o geekos/$*.o
223
224 # Compilation of common library C source files
225 common/%.o : common/%.c
226         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_USER_OPTS) $< -o common/$*.o
227
228 # ----------------------------------------------------------------------
229 # Targets -
230 #   Specifies files to be built
231 # ----------------------------------------------------------------------
232
233 # Default target - see definition of ALL_TARGETS in Configuration section
234 all : $(ALL_TARGETS)
235
236
237 geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
238         $(NASM) -O99 \
239         -f elf \
240                 -I$(PROJECT_ROOT)/src/geekos/ \
241                 $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
242         -o $@
243
244
245 geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o 
246         $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o  -o geekos/test
247
248 # Standard floppy image - just boots the kernel
249 fd.img : geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin vm_kernel
250         cat geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin > _temp
251         $(PAD) _temp 512
252         cat _temp vm_kernel > $@
253
254 # make ready to boot over PXE
255 pxe:    fd.img
256         cp fd.img /tftpboot/vmm.img
257         $(PAD) /tftpboot/vmm.img 1474560
258
259
260
261 # Floppy boot sector (first stage boot loader).
262 geekos/fd_boot.bin : geekos/setup.bin geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/fd_boot.asm vm_kernel
263         $(NASM) -f bin \
264                 -I$(PROJECT_ROOT)/src/geekos/ \
265                 -DNUM_SETUP_SECTORS=`$(NUMSECS) geekos/setup.bin` \
266                 -DNUM_KERN_SECTORS=`$(NUMSECS) geekos/kernel.bin` \
267                 -DNUM_VM_KERNEL_SECTORS=`$(NUMSECS) vm_kernel` \
268                 $(PROJECT_ROOT)/src/geekos/fd_boot.asm \
269                 -o $@
270
271 # Setup program (second stage boot loader).
272 geekos/setup.bin : geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/setup.asm
273         $(NASM) -f bin \
274                 -I$(PROJECT_ROOT)/src/geekos/ \
275                 -DENTRY_POINT=0x`egrep 'Main$$' geekos/kernel.syms |awk '{print $$1}'` \
276                 -DVMM_SIZE=`$(NUMSECS) geekos/kernel.bin` \
277                 -DGUEST_SIZE=`$(NUMSECS) vm_kernel` \
278                 $(PROJECT_ROOT)/src/geekos/setup.asm \
279                 -o $@
280         $(PAD) $@ 512
281
282 # Loadable (flat) kernel image.
283 geekos/kernel.bin : geekos/kernel.exe
284         $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary geekos/kernel.exe geekos/kernel.bin
285         $(PAD) $@ 512
286
287 # The kernel executable and symbol map.
288 geekos/kernel.exe : $(KERNEL_OBJS) $(COMMON_C_OBJS)
289         $(TARGET_LD) -o geekos/kernel.exe -Ttext $(KERNEL_BASE_ADDR) -e $(KERNEL_ENTRY) \
290                 $(KERNEL_OBJS) $(COMMON_C_OBJS)
291         $(TARGET_NM) geekos/kernel.exe > geekos/kernel.syms
292
293
294 force:
295
296
297 vm_kernel: force
298         $(PAD) vm_kernel 512
299         @echo "VM kernel lives at 0x100000 and is" `$(NUMSECS) vm_kernel` "sectors long"
300
301
302
303 vmm_mem_test: geekos/vmm_mem.c
304         $(HOST_CC) -m32 -o mem_test -DVMM_MEM_TEST -I../include ../src/geekos/vmm_mem.c 
305
306
307 # Clean build directories of generated files
308 clean :
309         for d in geekos common libc user tools; do \
310                 (cd $$d && rm -f *); \
311         done
312
313
314 # Build header file dependencies, so source files are recompiled when
315 # header files they depend on are modified.
316 depend : $(GENERATED_LIBC_SRCS)
317         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
318                 $(KERNEL_C_SRCS:%.c=$(PROJECT_ROOT)/src/geekos/%.c) \
319                 | $(PERL) -n -e 's,^(\S),geekos/$$1,;print' \
320                 > depend.mak
321         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_USER_OPTS) \
322                 $(COMMON_C_SRCS:%.c=$(PROJECT_ROOT)/src/common/%.c) \
323                 | $(PERL) -n -e 's,^(\S),common/$$1,;print' \
324                 >> depend.mak
325
326 # By default, there are no header file dependencies.
327 depend.mak :
328         touch $@
329
330 include depend.mak