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.


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