Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fnu Harsh committed Nov 24, 2019
0 parents commit 62c45a3
Show file tree
Hide file tree
Showing 414 changed files with 145,385 additions and 0 deletions.
36 changes: 36 additions & 0 deletions GRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Grading

1. Download student submissions:

```bash
mkdir -p submissions
rsync -rtLP ${your_kerberos}@athena.dialup.mit.edu:/mit/6.828/web_scripts/$(date +"%Y")/uploads/lab-${lab_name}/ submissions/
```

2. Start the grading VM and SSH in:

```bash
vagrant up
vagrant ssh
```

3. Grade submissions (in the VM):

```bash
cd /xv6
./batch-grade --config conf/lab-${lab_name}.json --output lab-${lab_name}.json submissions
```

4. Copy grades to Athena:

```bash
rsync lab-${lab_name}.json ${your_kerberos}@athena.dialup.mit.edu:/mit/6.828/web_scripts/$(date +"%Y")/grades/
```

5. Import grades:

```bash
ssh ${your_kerberos}@athena.dialup.mit.edu
cd /mit/6.828/web_scripts/$(date +"%Y")/
./import-grades.py -l ${lab_name}
```
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
The xv6 software is:

Copyright (c) 2006-2019 Frans Kaashoek, Robert Morris, Russ Cox,
Massachusetts Institute of Technology

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

287 changes: 287 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
K=kernel
U=user
LWIP=lwip

OBJS = \
$K/entry.o \
$K/start.o \
$K/console.o \
$K/printf.o \
$K/uart.o \
$K/kalloc.o \
$K/spinlock.o \
$K/string.o \
$K/main.o \
$K/vm.o \
$K/proc.o \
$K/swtch.o \
$K/trampoline.o \
$K/trap.o \
$K/syscall.o \
$K/sysproc.o \
$K/bio.o \
$K/fs.o \
$K/log.o \
$K/sleeplock.o \
$K/file.o \
$K/pipe.o \
$K/exec.o \
$K/sysfile.o \
$K/kernelvec.o \
$K/plic.o \
$K/virtio_disk.o \
$K/buddy.o \
$K/list.o

# uncomment for lab net
#OBJS += \
$K/net.o \
$K/virtio_net.o \
$(LWIP)/core/init.o \
$(LWIP)/core/def.o \
$(LWIP)/core/dns.o \
$(LWIP)/core/inet_chksum.o \
$(LWIP)/core/ip.o \
$(LWIP)/core/mem.o \
$(LWIP)/core/memp.o \
$(LWIP)/core/netif.o \
$(LWIP)/core/pbuf.o \
$(LWIP)/core/raw.o \
$(LWIP)/core/stats.o \
$(LWIP)/core/sys.o \
$(LWIP)/core/tcp.o \
$(LWIP)/core/tcp_in.o \
$(LWIP)/core/tcp_out.o \
$(LWIP)/core/timeouts.o \
$(LWIP)/core/udp.o \
$(LWIP)/core/ipv4/autoip.o \
$(LWIP)/core/ipv4/dhcp.o \
$(LWIP)/core/ipv4/etharp.o \
$(LWIP)/core/ipv4/icmp.o \
$(LWIP)/core/ipv4/igmp.o \
$(LWIP)/core/ipv4/ip4_frag.o \
$(LWIP)/core/ipv4/ip4.o \
$(LWIP)/core/ipv4/ip4_addr.o \
$(LWIP)/api/err.o \
$(LWIP)/netif/ethernet.o \
# riscv64-unknown-elf- or riscv64-linux-gnu-
# perhaps in /opt/riscv/bin
#TOOLPREFIX =

# Try to infer the correct TOOLPREFIX if not set
ifndef TOOLPREFIX
TOOLPREFIX := $(shell if riscv64-unknown-elf-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-unknown-elf-'; \
elif riscv64-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-linux-gnu-'; \
else echo "***" 1>&2; \
echo "*** Error: Couldn't find an riscv64 version of GCC/binutils." 1>&2; \
echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
echo "***" 1>&2; exit 1; fi)
endif

QEMU = qemu-system-riscv64

CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
GDB = $(TOOLPREFIX)gdb
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump

CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb
CFLAGS += -MD
CFLAGS += -mcmodel=medany
CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
CFLAGS += -I.
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)

# Disable PIE when possible (for Ubuntu 16.10 toolchain)
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),)
CFLAGS += -fno-pie -no-pie
endif
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]nopie'),)
CFLAGS += -fno-pie -nopie
endif

CFLAGS += -I $K/lwip -I $(LWIP)/include

LDFLAGS = -z max-page-size=4096

$K/kernel: $(OBJS) $K/kernel.ld $U/initcode
$(LD) $(LDFLAGS) -T $K/kernel.ld -o $K/kernel $(OBJS)
$(OBJDUMP) -S $K/kernel > $K/kernel.asm
$(OBJDUMP) -t $K/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $K/kernel.sym

$U/initcode: $U/initcode.S
$(CC) $(CFLAGS) -nostdinc -I. -Ikernel -c $U/initcode.S -o $U/initcode.o
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/initcode.out $U/initcode.o
$(OBJCOPY) -S -O binary $U/initcode.out $U/initcode
$(OBJDUMP) -S $U/initcode.o > $U/initcode.asm

tags: $(OBJS) _init
etags *.S *.c

ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o

_%: %.o $(ULIB)
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
$(OBJDUMP) -S $@ > $*.asm
$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym

$U/usys.S : $U/usys.pl
perl $U/usys.pl > $U/usys.S

$U/usys.o : $U/usys.S
$(CC) $(CFLAGS) -c -o $U/usys.o $U/usys.S

$U/_forktest: $U/forktest.o $(ULIB)
# forktest has less library code linked in - needs to be small
# in order to be able to max out the proc table.
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o
$(OBJDUMP) -S $U/_forktest > $U/forktest.asm

$U/_uthread: $U/uthread.o $U/uthread_switch.o $(ULIB)
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_uthread $U/uthread.o $U/uthread_switch.o $(ULIB)
$(OBJDUMP) -S $U/_uthread > $U/uthread.asm

mkfs/mkfs: mkfs/mkfs.c $K/fs.h
gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c

# Prevent deletion of intermediate files, e.g. cat.o, after first build, so
# that disk image changes after first build are persistent until clean. More
# details:
# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
.PRECIOUS: %.o

UPROGS=\
$U/_lazytests\
$U/_cat\
$U/_echo\
$U/_forktest\
$U/_grep\
$U/_init\
$U/_kill\
$U/_ln\
$U/_ls\
$U/_mkdir\
$U/_rm\
$U/_sh\
$U/_stressfs\
$U/_usertests\
$U/_wc\
$U/_zombie\
$U/_cowtest\
$U/_uthread\
$U/_call\
$U/_testsh\
$U/_kalloctest\
$U/_bcachetest\
$U/_alloctest\
$U/_specialtest\
# $U/_symlinktest\
fs.img: mkfs/mkfs README user/xargstest.sh $(UPROGS)
mkfs/mkfs fs.img README user/xargstest.sh $(UPROGS)

-include kernel/*.d user/*.d
-include lwip/api/*.d lwip/core/*.d lwip/core/ipv4/*.d lwip/netif/*.d

clean:
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
*/*.o */*.d */*.asm */*.sym \
$(LWIP)/*/*.o $(LWIP)/*/*.d \
$(LWIP)/*/*/*.o $(LWIP)/*/*/*.d \
$U/initcode $U/initcode.out $K/kernel fs.img \
mkfs/mkfs .gdbinit \
$U/usys.S \
$(UPROGS)

# try to generate a unique GDB port
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
PORT80 = $(shell expr $(GDBPORT) + 1)
# QEMU's gdb stub command line changed in 0.11
QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
ifndef CPUS
CPUS := 3
endif

QEMUEXTRA =
QEMUOPTS = -machine virt -bios none -kernel $K/kernel -m 128M -smp $(CPUS) -nographic
QEMUOPTS += -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
QEMUOPTS += -no-user-config
QEMUOPTS += -device virtio-net-device,netdev=en0 -object filter-dump,id=f0,netdev=en0,file=en0.pcap
# to foward a host port $(PORT80) to port 80 inside QEMU,
# use "-netdev type=user,id=en0,hostfwd=tcp::$(PORT80)-:80"
QEMUOPTS += -netdev type=user,id=en0

qemu: $K/kernel fs.img
$(QEMU) $(QEMUOPTS)

qemu-trace: $K/kernel stacktrace fs.img
$(QEMU) $(QEMUOPTS) | ./stacktrace

.gdbinit: .gdbinit.tmpl-riscv
sed "s/:1234/:$(GDBPORT)/" < $^ > $@

qemu-gdb: $K/kernel .gdbinit fs.img
@echo "*** Now run 'make gdb' in another window." 1>&2
$(QEMU) $(QEMUOPTS) -S $(QEMUGDB)

gdb: $K/kernel .gdbinit
$(GDB)

##
## FOR submitting lab solutions
##

LAB := $(shell git symbolic-ref --short HEAD 2> /dev/null)
ifeq ($(LAB),)
LAB := $(shell cat conf/LAB)
endif

ifneq ($(V),@)
GRADEFLAGS += -v
endif

print-gdbport:
@echo $(GDBPORT)

grade:
@echo $(MAKE) clean
@$(MAKE) clean || \
(echo "'make clean' failed. HINT: Do you have another running instance of xv6?" && exit 1)
./grade-lab-$(LAB) $(GRADEFLAGS)

handin-check:
@if ! test -d .git; then \
echo No .git directory, is this a git repository?; \
false; \
fi
@if test "$$(git symbolic-ref HEAD)" != refs/heads/$(LAB); then \
git branch; \
read -p "You are not on the $(LAB) branch. Hand-in the current branch? [y/N] " r; \
test "$$r" = y; \
fi
@if ! git diff-files --quiet || ! git diff-index --quiet --cached HEAD; then \
git status -s; \
echo; \
echo "You have uncomitted changes. Please commit or stash them."; \
false; \
fi
@if test -n "`git status -s`"; then \
git status -s; \
read -p "Untracked files will not be handed in. Continue? [y/N] " r; \
test "$$r" = y; \
fi

tarball: handin-check
echo $(LAB) > conf/LAB
git archive --format=tar -o lab-$(LAB)-handin.tar HEAD
tar rf lab-$(LAB)-handin.tar conf/LAB
gzip -f lab-$(LAB)-handin.tar

.PHONY: qemu qemu-gdb gdb qemu-trace tarball tarball-pref clean grade handin-check
43 changes: 43 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix
Version 6 (v6). xv6 loosely follows the structure and style of v6,
but is implemented for a modern RISC-V multiprocessor using ANSI C.

ACKNOWLEDGMENTS

xv6 is inspired by John Lions's Commentary on UNIX 6th Edition (Peer
to Peer Communications; ISBN: 1-57398-013-7; 1st edition (June 14,
2000)). See also https://pdos.csail.mit.edu/6.828/, which
provides pointers to on-line resources for v6.

The following people have made contributions: Russ Cox (context switching,
locking), Cliff Frey (MP), Xiao Yu (MP), Nickolai Zeldovich, and Austin
Clements.

We are also grateful for the bug reports and patches contributed by
Silas Boyd-Wickizer, Anton Burtsev, Dan Cross, Cody Cutler, Mike CAT,
Tej Chajed, eyalz800, Nelson Elhage, Saar Ettinger, Alice Ferrazzi,
Nathaniel Filardo, Peter Froehlich, Yakir Goaron,Shivam Handa, Bryan
Henry, Jim Huang, Alexander Kapshuk, Anders Kaseorg, kehao95, Wolfgang
Keller, Eddie Kohler, Austin Liew, Imbar Marinescu, Yandong Mao, Matan
Shabtay, Hitoshi Mitake, Carmi Merimovich, Mark Morrissey, mtasm, Joel
Nider, Greg Price, Ayan Shafqat, Eldar Sehayek, Yongming Shen, Cam
Tenny, tyfkda, Rafael Ubal, Warren Toomey, Stephen Tu, Pablo Ventura,
Xi Wang, Keiichi Watanabe, Nicolas Wolovick, wxdao, Grant Wu, Jindong
Zhang, Icenowy Zheng, and Zou Chang Wei.

The code in the files that constitute xv6 is
Copyright 2006-2019 Frans Kaashoek, Robert Morris, and Russ Cox.

ERROR REPORTS

Please send errors and suggestions to Frans Kaashoek and Robert Morris
(kaashoek,[email protected]). The main purpose of xv6 is as a teaching
operating system for MIT's 6.828, so we are more interested in
simplifications and clarifications than new features.

BUILDING AND RUNNING XV6

You will need a RISC-V "newlib" tool chain from
https://github.com/riscv/riscv-gnu-toolchain, and qemu compiled for
riscv64-softmmu. Once they are installed, and in your shell
search path, you can run "make qemu".
Loading

0 comments on commit 62c45a3

Please sign in to comment.