Permalink
Browse files

lab3

  • Loading branch information...
aclements committed Sep 29, 2011
1 parent 82f50cb commit 9bf29a358edae52b7e7856207d93187f412b8815
Showing with 2,030 additions and 17 deletions.
  1. +30 −2 GNUmakefile
  2. +2 −2 conf/lab.mk
  3. +134 −1 grade-functions.sh
  4. +120 −0 grade-lab3.sh
  5. +59 −0 inc/env.h
  6. +56 −0 inc/lib.h
  7. +1 −1 inc/memlayout.h
  8. +4 −4 inc/mmu.h
  9. +13 −0 inc/syscall.h
  10. +78 −0 inc/trap.h
  11. +6 −0 inc/x86.h
  12. +13 −1 kern/Makefrag
  13. +1 −0 kern/entry.S
  14. +462 −0 kern/env.c
  15. +37 −0 kern/env.h
  16. +16 −3 kern/init.c
  17. +27 −2 kern/kdebug.c
  18. +3 −0 kern/monitor.c
  19. +64 −1 kern/pmap.c
  20. +4 −0 kern/pmap.h
  21. +75 −0 kern/syscall.c
  22. +11 −0 kern/syscall.h
  23. +213 −0 kern/trap.c
  24. +23 −0 kern/trap.h
  25. +55 −0 kern/trapentry.S
  26. +31 −0 lib/Makefrag
  27. +25 −0 lib/console.c
  28. +35 −0 lib/entry.S
  29. +9 −0 lib/exit.c
  30. +28 −0 lib/libmain.c
  31. +30 −0 lib/panic.c
  32. +62 −0 lib/printf.c
  33. +63 −0 lib/syscall.c
  34. +12 −0 user/Makefrag
  35. +11 −0 user/badsegment.c
  36. +10 −0 user/breakpoint.c
  37. +11 −0 user/buggyhello.c
  38. +13 −0 user/buggyhello2.c
  39. +13 −0 user/divzero.c
  40. +12 −0 user/evilhello.c
  41. +10 −0 user/faultread.c
  42. +10 −0 user/faultreadkernel.c
  43. +10 −0 user/faultwrite.c
  44. +10 −0 user/faultwritekernel.c
  45. +9 −0 user/hello.c
  46. +10 −0 user/softint.c
  47. +27 −0 user/testbss.c
  48. +72 −0 user/user.ld
View
@@ -78,13 +78,14 @@ NM := $(GCCPREFIX)nm
# Native commands
NCC := gcc $(CC_VER) -pipe
NATIVE_CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -I$(TOP) -MD -Wall
TAR := gtar
PERL := perl
# Compiler flags
# -fno-builtin is required to avoid refs to undefined functions in the kernel.
# Only optimize to -O1 to discourage inlining, which complicates backtraces.
CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
CFLAGS += -fno-omit-frame-pointer
CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32
@@ -125,6 +126,8 @@ USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
# Include Makefrags for subdirectories
include boot/Makefrag
include kern/Makefrag
include lib/Makefrag
include user/Makefrag
IMAGES = $(OBJDIR)/kern/kernel.img
@@ -173,12 +176,16 @@ realclean: clean
distclean: realclean
rm -rf conf/gcc.mk
ifneq ($(V),@)
GRADEFLAGS += -v
endif
grade: $(LABSETUP)grade-lab$(LAB).sh
@echo $(MAKE) clean
@$(MAKE) clean || \
(echo "'make clean' failed. HINT: Do you have another running instance of JOS?" && exit 1)
$(MAKE) all
sh $(LABSETUP)grade-lab$(LAB).sh
sh $(LABSETUP)grade-lab$(LAB).sh $(GRADEFLAGS)
handin: tarball
@echo Please visit http://pdos.csail.mit.edu/6.828/submit/
@@ -187,6 +194,27 @@ handin: tarball
tarball: realclean
tar cf - `find . -type f | grep -v '^\.*$$' | grep -v '/CVS/' | grep -v '/\.svn/' | grep -v '/\.git/' | grep -v 'lab[0-9].*\.tar\.gz'` | gzip > lab$(LAB)-handin.tar.gz
# For test runs
prep-%:
$(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
$(V)$(MAKE) "DEFS=-DTEST=user_$*" $(IMAGES)
$(V)rm -f $(OBJDIR)/kern/init.o
run-%-nox-gdb: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
run-%-gdb: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) $(QEMUOPTS) -S $(QEMUGDB)
run-%-nox:
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) -nographic $(QEMUOPTS)
run-%:
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) $(QEMUOPTS)
# This magic automatically generates makefile dependencies
# for header files included from C source files we compile,
View
@@ -1,2 +1,2 @@
LAB=2
PACKAGEDATE=Wed Sep 14 23:28:01 EDT 2011
LAB=3
PACKAGEDATE=Wed Sep 28 23:57:24 EDT 2011
View
@@ -38,10 +38,15 @@ run () {
qemuextra="-S $qemugdb"
fi
qemucommand="$qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot $qemuextra"
if $verbose; then
echo $qemucommand 1>&2
fi
t0=`date +%s.%N 2>/dev/null`
(
ulimit -t $timeout
exec $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot $qemuextra
exec $qemucommand
) >$out 2>$err &
PID=$!
@@ -122,3 +127,131 @@ fail () {
fi
}
#
# User tests
#
# Usage: runtest <tagname> <defs> <check fn> <check args...>
runtest () {
perl -e "print '$1: '"
rm -f obj/kern/init.o obj/kern/kernel obj/kern/kernel.img
[ "$preservefs" = y ] || rm -f obj/fs/fs.img
if $verbose
then
echo "$make $2... "
fi
$make $2 >$out
if [ $? -ne 0 ]
then
rm -f obj/kern/init.o
echo $make $2 failed
exit 1
fi
# We just built a weird init.o that runs a specific test. As
# a result, 'make qemu' will run the last graded test and
# 'make clean; make qemu' will run the user-specified
# environment. Remove our weird init.o to fix this.
rm -f obj/kern/init.o
run
# Give qemu some more time to run (for asynchronous mode).
# This way, we get the small 1 second wait for most tests
# and a longer wait (5 seconds) in case qemu needs that
# time to load.
if [ ! -s jos.out ]
then
sleep 4
fi
if [ ! -s jos.out ]
then
fail > /dev/null # Still increment number of possible points
echo 'no jos.out'
else
shift
shift
check=$1
shift
$check "$@"
fi
}
quicktest () {
perl -e "print '$1: '"
shift
checkregexps "$@"
}
checkregexps () {
okay=yes
not=false
for i
do
if [ "x$i" = "x!" ]
then
not=true
elif $not
then
if egrep "^$i\$" jos.out >/dev/null
then
echo "got unexpected line '$i'"
okay=no
fi
not=false
else
egrep "^$i\$" jos.out >/dev/null
if [ $? -ne 0 ]
then
echo "missing '$i'"
okay=no
fi
not=false
fi
done
if [ "$okay" = "yes" ]
then
pass
else
fail
fi
}
# Usage: runtest1 [-tag <tagname>] [-dir <dirname>] <progname> [-Ddef...] [-check checkfn] checkargs...
runtest1 () {
tag=
dir=user
check=checkregexps
while true; do
if [ $1 = -tag ]
then
tag=$2
elif [ $1 = -dir ]
then
dir=$2
else
break
fi
shift
shift
done
prog=$1
shift
if [ "x$tag" = x ]
then
tag=$prog
fi
runtest1_defs=
while expr "x$1" : 'x-D.*' >/dev/null; do
runtest1_defs="DEFS+='$1' $runtest1_defs"
shift
done
if [ "x$1" = "x-check" ]; then
check=$2
shift
shift
fi
runtest "$tag" "DEFS='-DTEST=${dir}_${prog}' $runtest1_defs" "$check" "$@"
}
View
@@ -0,0 +1,120 @@
#!/bin/sh
qemuopts="-hda obj/kern/kernel.img"
. ./grade-functions.sh
$make
# the [00001000] tags should have [] in them, but that's
# a regular expression reserved character, and i'll be damned if
# I can figure out how many \ i need to add to get through
# however many times the shell interprets this string. sigh.
pts=10
runtest1 divzero \
! '1/0 is ........!' \
'Incoming TRAP frame at 0xefbfff..' \
'TRAP frame at 0xf.......' \
' trap 0x00000000 Divide error' \
' eip 0x008.....' \
' ss 0x----0023' \
'.00001000. free env 00001000'
runtest1 softint \
'Welcome to the JOS kernel monitor!' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000d General Protection' \
' eip 0x008.....' \
' ss 0x----0023' \
'.00001000. free env 00001000'
runtest1 badsegment \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000d General Protection' \
' err 0x00000028' \
' eip 0x008.....' \
' ss 0x----0023' \
'.00001000. free env 00001000'
showpart A
pts=5
runtest1 faultread \
! 'I read ........ from location 0!' \
'.00001000. user fault va 00000000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000004.*' \
'.00001000. free env 00001000'
runtest1 faultreadkernel \
! 'I read ........ from location 0xf0100000!' \
'.00001000. user fault va f0100000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000005.*' \
'.00001000. free env 00001000' \
runtest1 faultwrite \
'.00001000. user fault va 00000000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000006.*' \
'.00001000. free env 00001000'
runtest1 faultwritekernel \
'.00001000. user fault va f0100000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000007.*' \
'.00001000. free env 00001000'
runtest1 breakpoint \
'Welcome to the JOS kernel monitor!' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x00000003 Breakpoint' \
' eip 0x008.....' \
' ss 0x----0023' \
! '.00001000. free env 00001000'
runtest1 testbss \
'Making sure bss works right...' \
'Yes, good. Now doing a wild write off the end...' \
'.00001000. user fault va 00c..... ip 008.....' \
'.00001000. free env 00001000'
runtest1 hello \
'.00000000. new env 00001000' \
'hello, world' \
'i am environment 00001000' \
'.00001000. exiting gracefully' \
'.00001000. free env 00001000' \
'Destroyed the only environment - nothing more to do!'
runtest1 buggyhello \
'.00001000. user_mem_check assertion failure for va 00000001' \
'.00001000. free env 00001000'
runtest1 buggyhello2 \
'.00001000. user_mem_check assertion failure for va 0....000' \
'.00001000. free env 00001000' \
! 'hello, world'
runtest1 evilhello \
'.00001000. user_mem_check assertion failure for va f0100...' \
'.00001000. free env 00001000'
showpart B
showfinal
Oops, something went wrong.

0 comments on commit 9bf29a3

Please sign in to comment.