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