Permalink
Browse files

lab3

  • Loading branch information...
1 parent 8303029 commit 808cf08271e47ffd13d086b1b9f8349dfe29e117 @aclements aclements committed Sep 30, 2009
Showing with 1,678 additions and 15 deletions.
  1. +3 −3 .gdbinit.tmpl
  2. +2 −0 GNUmakefile
  3. +1 −1 boot/main.c
  4. +2 −2 conf/lab.mk
  5. +106 −1 grade-functions.sh
  6. +117 −0 grade-lab3.sh
  7. +51 −0 inc/lib.h
  8. +14 −0 inc/syscall.h
  9. +12 −1 kern/Makefrag
  10. +3 −2 kern/entry.S
  11. +389 −0 kern/env.c
  12. +43 −0 kern/env.h
  13. +15 −3 kern/init.c
  14. +27 −2 kern/kdebug.c
  15. +3 −0 kern/monitor.c
  16. +63 −0 kern/pmap.c
  17. +4 −0 kern/pmap.h
  18. +84 −0 kern/syscall.c
  19. +11 −0 kern/syscall.h
  20. +172 −0 kern/trap.c
  21. +49 −0 kern/trapentry.S
  22. +31 −0 lib/Makefrag
  23. +21 −0 lib/console.c
  24. +37 −0 lib/entry.S
  25. +9 −0 lib/exit.c
  26. +28 −0 lib/libmain.c
  27. +29 −0 lib/panic.c
  28. +62 −0 lib/printf.c
  29. +64 −0 lib/syscall.c
  30. +12 −0 user/Makefrag
  31. +11 −0 user/badsegment.c
  32. +10 −0 user/breakpoint.c
  33. +11 −0 user/buggyhello.c
  34. +12 −0 user/divzero.c
  35. +12 −0 user/evilhello.c
  36. +10 −0 user/faultread.c
  37. +10 −0 user/faultreadkernel.c
  38. +10 −0 user/faultwrite.c
  39. +10 −0 user/faultwritekernel.c
  40. +9 −0 user/hello.c
  41. +10 −0 user/softint.c
  42. +27 −0 user/testbss.c
  43. +72 −0 user/user.ld
View
@@ -3,13 +3,13 @@ set $lastcs = -1
define hook-stop
# There doesn't seem to be a good way to detect if we're in 16- or
# 32-bit mode, but we always run with CS == 8 in 32-bit mode.
- if $cs == 8
- if $lastcs != 8
+ if $cs == 8 || $cs == 27
+ if $lastcs != 8 && $lastcs != 27
set architecture i386
end
x/i $pc
else
- if $lastcs == -1 || $lastcs == 8
+ if $lastcs == -1 || $lastcs == 8 || $lastcs == 27
set architecture i8086
end
# Translate the segment:offset into a physical address
View
@@ -125,6 +125,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
View
@@ -23,7 +23,7 @@
* * Assuming this boot loader is stored in the first sector of the
* hard-drive, this code takes over...
*
- * * control starts in bootloader.S -- which sets up protected mode,
+ * * control starts in boot.S -- which sets up protected mode,
* and a stack so C code then run, then calls bootmain()
*
* * bootmain() in this file takes over, reads in the kernel and jumps to it.
View
@@ -1,2 +1,2 @@
-LAB=2
-PACKAGEDATE=Wed Sep 16 15:18:45 EDT 2009
+LAB=3
+PACKAGEDATE=Wed Sep 30 18:12:19 EDT 2009
View
@@ -37,7 +37,7 @@ run () {
t0=`date +%s.%N 2>/dev/null`
(
ulimit -t $timeout
- $qemu -nographic $qemuopts -serial file:jos.out -monitor null -s -S -p $port
+ $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot -s -S -p $port
) >$out 2>$err &
(
@@ -57,3 +57,108 @@ run () {
time="(${time}s)"
rm jos.in
}
+
+# Usage: runtest <tagname> <defs> <strings...>
+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
+ echo $make $2 failed
+ exit 1
+ fi
+ run
+ if [ ! -s jos.out ]
+ then
+ echo 'no jos.out'
+ else
+ shift
+ shift
+ continuetest "$@"
+ fi
+}
+
+quicktest () {
+ perl -e "print '$1: '"
+ shift
+ continuetest "$@"
+}
+
+stubtest () {
+ perl -e "print qq|$1: OK $2\n|";
+ shift
+ score=`expr $pts + $score`
+}
+
+continuetest () {
+ 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'"
+ if $verbose
+ then
+ exit 1
+ fi
+ okay=no
+ fi
+ not=false
+ else
+ egrep "^$i\$" jos.out >/dev/null
+ if [ $? -ne 0 ]
+ then
+ echo "missing '$i'"
+ if $verbose
+ then
+ exit 1
+ fi
+ okay=no
+ fi
+ not=false
+ fi
+ done
+ if [ "$okay" = "yes" ]
+ then
+ score=`expr $pts + $score`
+ echo OK $time
+ else
+ echo WRONG $time
+ fi
+}
+
+# Usage: runtest1 [-tag <tagname>] <progname> [-Ddef...] STRINGS...
+runtest1 () {
+ if [ $1 = -tag ]
+ then
+ shift
+ tag=$1
+ prog=$2
+ shift
+ shift
+ else
+ tag=$1
+ prog=$1
+ shift
+ fi
+ runtest1_defs=
+ while expr "x$1" : 'x-D.*' >/dev/null; do
+ runtest1_defs="DEFS+='$1' $runtest1_defs"
+ shift
+ done
+ runtest "$tag" "DEFS='-DTEST=_binary_obj_user_${prog}_start' DEFS+='-DTESTSIZE=_binary_obj_user_${prog}_size' $runtest1_defs" "$@"
+}
+
View
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+qemuopts="-hda obj/kern/kernel.img"
+. ./grade-functions.sh
+
+
+$make
+run
+
+score=0
+
+# 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.
+
+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'
+
+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 evilhello \
+ '.00001000. user_mem_check assertion failure for va f0100...' \
+ '.00001000. free env 00001000'
+
+
+
+
+echo "Score: $score/60"
+
+if [ $score -lt 60 ]; then
+ exit 1
+fi
View
@@ -0,0 +1,51 @@
+// Main public header file for our user-land support library,
+// whose code lives in the lib directory.
+// This library is roughly our OS's version of a standard C library,
+// and is intended to be linked into all user-mode applications
+// (NOT the kernel or boot loader).
+
+#ifndef JOS_INC_LIB_H
+#define JOS_INC_LIB_H 1
+
+#include <inc/types.h>
+#include <inc/stdio.h>
+#include <inc/stdarg.h>
+#include <inc/string.h>
+#include <inc/error.h>
+#include <inc/assert.h>
+#include <inc/env.h>
+#include <inc/memlayout.h>
+#include <inc/syscall.h>
+
+#define USED(x) (void)(x)
+
+// libos.c or entry.S
+extern char *binaryname;
+extern volatile struct Env *env;
+extern volatile struct Env envs[NENV];
+extern volatile struct Page pages[];
+void exit(void);
+
+// readline.c
+char* readline(const char *buf);
+
+// syscall.c
+void sys_cputs(const char *string, size_t len);
+int sys_cgetc(void);
+envid_t sys_getenvid(void);
+int sys_env_destroy(envid_t);
+
+
+
+/* File open modes */
+#define O_RDONLY 0x0000 /* open for reading only */
+#define O_WRONLY 0x0001 /* open for writing only */
+#define O_RDWR 0x0002 /* open for reading and writing */
+#define O_ACCMODE 0x0003 /* mask for above modes */
+
+#define O_CREAT 0x0100 /* create if nonexistent */
+#define O_TRUNC 0x0200 /* truncate to zero length */
+#define O_EXCL 0x0400 /* error if already exists */
+#define O_MKDIR 0x0800 /* create directory, not regular file */
+
+#endif // !JOS_INC_LIB_H
View
@@ -0,0 +1,14 @@
+#ifndef JOS_INC_SYSCALL_H
+#define JOS_INC_SYSCALL_H
+
+/* system call numbers */
+enum
+{
+ SYS_cputs = 0,
+ SYS_cgetc,
+ SYS_getenvid,
+ SYS_env_destroy,
+ NSYSCALLS
+};
+
+#endif /* !JOS_INC_SYSCALL_H */
View
@@ -34,7 +34,18 @@ KERN_SRCFILES := kern/entry.S \
# Only build files if they exist.
KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
-KERN_BINFILES :=
+KERN_BINFILES := user/hello \
+ user/buggyhello \
+ user/evilhello \
+ user/testbss \
+ user/divzero \
+ user/breakpoint \
+ user/softint \
+ user/badsegment \
+ user/faultread \
+ user/faultreadkernel \
+ user/faultwrite \
+ user/faultwritekernel
KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
View
@@ -2,6 +2,7 @@
#include <inc/mmu.h>
#include <inc/memlayout.h>
+#include <inc/trap.h>
# Shift Right Logical
#define SRL(val, shamt) (((val) >> (shamt)) & ~(-1 << (32 - (shamt))))
@@ -60,8 +61,8 @@ relocated:
# stack backtraces will be terminated properly.
movl $0x0,%ebp # nuke frame pointer
- # Set the stack pointer
- movl $(bootstacktop),%esp
+ # Leave a few words on the stack for the user trap frame
+ movl $(bootstacktop-SIZEOF_STRUCT_TRAPFRAME),%esp
# now to C code
call i386_init
Oops, something went wrong.

0 comments on commit 808cf08

Please sign in to comment.