summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile93
1 files changed, 76 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 3ddc1c1..f67c88c 100644
--- a/Makefile
+++ b/Makefile
@@ -26,19 +26,53 @@ OBJS = \
uart.o\
vectors.o\
vm.o\
+ log.o\
# Cross-compiling (e.g., on Mac OS X)
-TOOLPREFIX = i386-jos-elf-
+#TOOLPREFIX = i386-jos-elf-
# Using native tools (e.g., on X86 Linux)
#TOOLPREFIX =
+# Try to infer the correct TOOLPREFIX if not set
+ifndef TOOLPREFIX
+TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
+ then echo 'i386-jos-elf-'; \
+ elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
+ then echo ''; \
+ else echo "***" 1>&2; \
+ echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
+ echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
+ echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
+ echo "*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \
+ echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
+ echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
+ echo "***" 1>&2; exit 1; fi)
+endif
+
+# If the makefile can't find QEMU, specify its path here
+#QEMU =
+
+# Try to infer the correct QEMU
+ifndef QEMU
+QEMU = $(shell if which qemu > /dev/null; \
+ then echo qemu; exit; \
+ else \
+ qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \
+ if test -x $$qemu; then echo $$qemu; exit; fi; fi; \
+ echo "***" 1>&2; \
+ echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \
+ echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \
+ echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \
+ echo "***" 1>&2; exit 1)
+endif
+
CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
-CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror
+CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m32 -gdwarf-2
# FreeBSD ld wants ``elf_i386_fbsd''
@@ -49,6 +83,11 @@ xv6.img: bootblock kernel fs.img
dd if=bootblock of=xv6.img conv=notrunc
dd if=kernel of=xv6.img seek=1 conv=notrunc
+xv6memfs.img: bootblock kernelmemfs
+ dd if=/dev/zero of=xv6memfs.img count=10000
+ dd if=bootblock of=xv6memfs.img conv=notrunc
+ dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
+
bootblock: bootasm.S bootmain.c
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S
@@ -69,11 +108,23 @@ initcode: initcode.S
$(OBJCOPY) -S -O binary initcode.out initcode
$(OBJDUMP) -S initcode.o > initcode.asm
-kernel: $(OBJS) bootother initcode
- $(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernel $(OBJS) -b binary initcode bootother
+kernel: $(OBJS) multiboot.o data.o bootother initcode
+ $(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernel multiboot.o data.o $(OBJS) -b binary initcode bootother
$(OBJDUMP) -S kernel > kernel.asm
$(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
+# kernelmemfs is a copy of kernel that maintains the
+# disk image in memory instead of writing to a disk.
+# This is not so useful for testing persistent storage or
+# exploring disk buffering implementations, but it is
+# great for testing the kernel on real hardware without
+# needing a scratch disk.
+MEMFSOBJS = $(filter-out ide.o,$(OBJS)) memide.o
+kernelmemfs: $(MEMFSOBJS) multiboot.o data.o bootother initcode fs.img
+ $(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernelmemfs multiboot.o data.o $(MEMFSOBJS) -b binary initcode bootother fs.img
+ $(OBJDUMP) -S kernelmemfs > kernelmemfs.asm
+ $(OBJDUMP) -t kernelmemfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym
+
tags: $(OBJS) bootother.S _init
etags *.S *.c
@@ -94,7 +145,7 @@ _forktest: forktest.o $(ULIB)
$(OBJDUMP) -S _forktest > forktest.asm
mkfs: mkfs.c fs.h
- gcc -Wall -o mkfs mkfs.c
+ gcc -m32 -Werror -Wall -o mkfs mkfs.c
UPROGS=\
_cat\
@@ -126,7 +177,7 @@ clean:
# make a printout
FILES = $(shell grep -v '^\#' runoff.list)
-PRINT = runoff.list $(FILES)
+PRINT = runoff.list runoff.spec $(FILES)
xv6.pdf: $(PRINT)
./runoff
@@ -143,27 +194,33 @@ bochs : fs.img xv6.img
# try to generate a unique GDB port
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
# QEMU's gdb stub command line changed in 0.11
-QEMUGDB = $(shell if qemu -help | grep -q '^-gdb'; \
+QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
-QEMUOPTS = -smp 2 -hdb fs.img xv6.img
+ifndef CPUS
+CPUS := 2
+endif
+QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS)
qemu: fs.img xv6.img
- qemu -serial mon:stdio $(QEMUOPTS)
+ $(QEMU) -serial mon:stdio $(QEMUOPTS)
+
+qemu-memfs: xv6memfs.img
+ $(QEMU) xv6memfs.img -smp $(CPUS)
qemu-nox: fs.img xv6.img
- qemu -nographic $(QEMUOPTS)
+ $(QEMU) -nographic $(QEMUOPTS)
.gdbinit: .gdbinit.tmpl
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
qemu-gdb: fs.img xv6.img .gdbinit
@echo "*** Now run 'gdb'." 1>&2
- qemu -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB)
qemu-nox-gdb: fs.img xv6.img .gdbinit
@echo "*** Now run 'gdb'." 1>&2
- qemu -nographic $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
# CUT HERE
# prepare dist for students
@@ -195,14 +252,16 @@ dist-test:
rm -rf dist-test
mkdir dist-test
cp dist/* dist-test
- cd dist-test; ../m print
- cd dist-test; ../m bochs || true
- cd dist-test; ../m qemu
+ cd dist-test; $(MAKE) print
+ cd dist-test; $(MAKE) bochs || true
+ cd dist-test; $(MAKE) qemu
-# update this rule (change rev1) when it is time to
+# update this rule (change rev#) when it is time to
# make a new revision.
tar:
rm -rf /tmp/xv6
mkdir -p /tmp/xv6
cp dist/* dist/.gdbinit.tmpl /tmp/xv6
- (cd /tmp; tar cf - xv6) | gzip >xv6-rev3.tar.gz
+ (cd /tmp; tar cf - xv6) | gzip >xv6-rev5.tar.gz
+
+.PHONY: dist-test dist