Massive reorganizing and making all the makefiles consistent.
authorKevin Klues <klueska@cs.berkeley.edu>
Mon, 25 May 2009 00:47:38 +0000 (17:47 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Tue, 26 May 2009 03:39:17 +0000 (20:39 -0700)
Only minor code changes to make include directories correct.  Still haven't fixed the problem of the
kernel relying on compiling some user space library files.

378 files changed:
GNUmakefile
boot/Makefrag
conf/env.mk [deleted file]
conf/lab.mk [deleted file]
inc/COPYRIGHT [deleted file]
inc/assert.h [deleted file]
inc/atomic.h [deleted file]
inc/elf.h [deleted file]
inc/env.h [deleted file]
inc/error.h [deleted file]
inc/kbdreg.h [deleted file]
inc/lib.h [deleted file]
inc/malloc.h [deleted file]
inc/measure.h [deleted file]
inc/memlayout.h [deleted file]
inc/mmu.h [deleted file]
inc/multiboot.h [deleted file]
inc/null.h [deleted file]
inc/pool.h [deleted file]
inc/queue.h [deleted file]
inc/ring_buffer.h [deleted file]
inc/stab.h [deleted file]
inc/stdarg.h [deleted file]
inc/stdio.h [deleted file]
inc/string.h [deleted file]
inc/syscall.h [deleted file]
inc/timer.h [deleted file]
inc/trap.h [deleted file]
inc/types.h [deleted file]
inc/x86.h [deleted file]
ivylib/Makefrag [deleted file]
ivylib/deputy_kern.c [deleted file]
ivylib/deputy_user.c [deleted file]
kern/Makefrag
kern/apic.c [deleted file]
kern/atomic.c [deleted file]
kern/console.c [deleted file]
kern/entry.S [deleted file]
kern/env.c [deleted file]
kern/init.c [deleted file]
kern/ivylib/Makefrag [new file with mode: 0644]
kern/ivylib/deputy.c [new file with mode: 0644]
kern/kclock.c [deleted file]
kern/kdebug.c [deleted file]
kern/monitor.c [deleted file]
kern/pmap.c [deleted file]
kern/printf.c [deleted file]
kern/smp.c [deleted file]
kern/smp_entry.S [deleted file]
kern/src/Makefrag [new file with mode: 0644]
kern/src/apic.c [new file with mode: 0644]
kern/src/atomic.c [new file with mode: 0644]
kern/src/console.c [new file with mode: 0644]
kern/src/entry.S [new file with mode: 0644]
kern/src/env.c [new file with mode: 0644]
kern/src/init.c [new file with mode: 0644]
kern/src/kclock.c [new file with mode: 0644]
kern/src/kdebug.c [new file with mode: 0644]
kern/src/monitor.c [new file with mode: 0644]
kern/src/pmap.c [new file with mode: 0644]
kern/src/printf.c [new file with mode: 0644]
kern/src/smp.c [new file with mode: 0644]
kern/src/smp_entry.S [new file with mode: 0644]
kern/src/syscall.c [new file with mode: 0644]
kern/src/testing.c [new file with mode: 0644]
kern/src/trap.c [new file with mode: 0644]
kern/src/trapentry.S [new file with mode: 0644]
kern/syscall.c [deleted file]
kern/testing.c [deleted file]
kern/trap.c [deleted file]
kern/trapentry.S [deleted file]
lib/Makefrag [deleted file]
lib/asynccall.c [deleted file]
lib/console.c [deleted file]
lib/entry.S [deleted file]
lib/exit.c [deleted file]
lib/libmain.c [deleted file]
lib/null.c [deleted file]
lib/panic.c [deleted file]
lib/printf.c [deleted file]
lib/printfmt.c [deleted file]
lib/readline.c [deleted file]
lib/string.c [deleted file]
lib/syscall.c [deleted file]
lib/timer.c [deleted file]
mergedep.pl [deleted file]
newlib/Makefrag [deleted file]
newlib/include/_ansi.h [deleted file]
newlib/include/_syslist.h [deleted file]
newlib/include/alloca.h [deleted file]
newlib/include/ar.h [deleted file]
newlib/include/argz.h [deleted file]
newlib/include/assert.h [deleted file]
newlib/include/ctype.h [deleted file]
newlib/include/dirent.h [deleted file]
newlib/include/envlock.h [deleted file]
newlib/include/envz.h [deleted file]
newlib/include/errno.h [deleted file]
newlib/include/fastmath.h [deleted file]
newlib/include/fcntl.h [deleted file]
newlib/include/fnmatch.h [deleted file]
newlib/include/getopt.h [deleted file]
newlib/include/glob.h [deleted file]
newlib/include/grp.h [deleted file]
newlib/include/iconv.h [deleted file]
newlib/include/ieeefp.h [deleted file]
newlib/include/inttypes.h [deleted file]
newlib/include/langinfo.h [deleted file]
newlib/include/libgen.h [deleted file]
newlib/include/limits.h [deleted file]
newlib/include/locale.h [deleted file]
newlib/include/machine/_default_types.h [deleted file]
newlib/include/machine/_types.h [deleted file]
newlib/include/machine/ansi.h [deleted file]
newlib/include/machine/endian.h [deleted file]
newlib/include/machine/fastmath.h [deleted file]
newlib/include/machine/ieeefp.h [deleted file]
newlib/include/machine/malloc.h [deleted file]
newlib/include/machine/param.h [deleted file]
newlib/include/machine/setjmp-dj.h [deleted file]
newlib/include/machine/setjmp.h [deleted file]
newlib/include/machine/stdlib.h [deleted file]
newlib/include/machine/termios.h [deleted file]
newlib/include/machine/time.h [deleted file]
newlib/include/machine/types.h [deleted file]
newlib/include/malloc.h [deleted file]
newlib/include/math.h [deleted file]
newlib/include/newlib.h [deleted file]
newlib/include/paths.h [deleted file]
newlib/include/process.h [deleted file]
newlib/include/pthread.h [deleted file]
newlib/include/pwd.h [deleted file]
newlib/include/reent.h [deleted file]
newlib/include/regdef.h [deleted file]
newlib/include/regex.h [deleted file]
newlib/include/sched.h [deleted file]
newlib/include/search.h [deleted file]
newlib/include/setjmp.h [deleted file]
newlib/include/signal.h [deleted file]
newlib/include/stdint.h [deleted file]
newlib/include/stdio.h [deleted file]
newlib/include/stdlib.h [deleted file]
newlib/include/string.h [deleted file]
newlib/include/sys/_default_fcntl.h [deleted file]
newlib/include/sys/_types.h [deleted file]
newlib/include/sys/cdefs.h [deleted file]
newlib/include/sys/config.h [deleted file]
newlib/include/sys/custom_file.h [deleted file]
newlib/include/sys/dirent.h [deleted file]
newlib/include/sys/errno.h [deleted file]
newlib/include/sys/fcntl.h [deleted file]
newlib/include/sys/features.h [deleted file]
newlib/include/sys/file.h [deleted file]
newlib/include/sys/iconvnls.h [deleted file]
newlib/include/sys/lock.h [deleted file]
newlib/include/sys/param.h [deleted file]
newlib/include/sys/queue.h [deleted file]
newlib/include/sys/reent.h [deleted file]
newlib/include/sys/resource.h [deleted file]
newlib/include/sys/sched.h [deleted file]
newlib/include/sys/signal.h [deleted file]
newlib/include/sys/stat.h [deleted file]
newlib/include/sys/stdio.h [deleted file]
newlib/include/sys/string.h [deleted file]
newlib/include/sys/syslimits.h [deleted file]
newlib/include/sys/time.h [deleted file]
newlib/include/sys/timeb.h [deleted file]
newlib/include/sys/times.h [deleted file]
newlib/include/sys/types.h [deleted file]
newlib/include/sys/unistd.h [deleted file]
newlib/include/sys/utime.h [deleted file]
newlib/include/sys/wait.h [deleted file]
newlib/include/tar.h [deleted file]
newlib/include/termios.h [deleted file]
newlib/include/time.h [deleted file]
newlib/include/unctrl.h [deleted file]
newlib/include/unistd.h [deleted file]
newlib/include/utime.h [deleted file]
newlib/include/utmp.h [deleted file]
newlib/include/wchar.h [deleted file]
newlib/include/wctype.h [deleted file]
newlib/include/wordexp.h [deleted file]
newlib/lib/libc.a [deleted file]
newlib/lib/libg.a [deleted file]
newlib/lib/libm.a [deleted file]
newlib/libc_wrappers.c [deleted file]
newlib/libc_wrappers.h [deleted file]
scripts/mergedep.pl [new file with mode: 0755]
user/Makefrag
user/apps/Makefrag [new file with mode: 0644]
user/apps/newlib/Makefrag [new file with mode: 0644]
user/apps/newlib/apps.ld [new file with mode: 0644]
user/apps/newlib/hello.c [new file with mode: 0644]
user/apps/newlib/null.c [new file with mode: 0644]
user/apps/parlib/Makefrag [new file with mode: 0644]
user/apps/parlib/apps.ld [new file with mode: 0644]
user/apps/parlib/badsegment.c [new file with mode: 0644]
user/apps/parlib/breakpoint.c [new file with mode: 0644]
user/apps/parlib/buggyhello.c [new file with mode: 0644]
user/apps/parlib/divzero.c [new file with mode: 0644]
user/apps/parlib/evilhello.c [new file with mode: 0644]
user/apps/parlib/faultread.c [new file with mode: 0644]
user/apps/parlib/faultreadkernel.c [new file with mode: 0644]
user/apps/parlib/faultwrite.c [new file with mode: 0644]
user/apps/parlib/faultwritekernel.c [new file with mode: 0644]
user/apps/parlib/hello.c [new file with mode: 0644]
user/apps/parlib/measurements.c [new file with mode: 0644]
user/apps/parlib/null.c [new file with mode: 0644]
user/apps/parlib/print_tests.c [new file with mode: 0644]
user/apps/parlib/softint.c [new file with mode: 0644]
user/apps/parlib/testbss.c [new file with mode: 0644]
user/apps/parlib/testpmap.c [new file with mode: 0644]
user/badsegment.c [deleted file]
user/breakpoint.c [deleted file]
user/buggyhello.c [deleted file]
user/divzero.c [deleted file]
user/evilhello.c [deleted file]
user/faultread.c [deleted file]
user/faultreadkernel.c [deleted file]
user/faultwrite.c [deleted file]
user/faultwritekernel.c [deleted file]
user/hello.c [deleted file]
user/measurements.c [deleted file]
user/newlib/Makefrag [new file with mode: 0644]
user/newlib/include/_ansi.h [new file with mode: 0644]
user/newlib/include/_syslist.h [new file with mode: 0644]
user/newlib/include/alloca.h [new file with mode: 0644]
user/newlib/include/ar.h [new file with mode: 0644]
user/newlib/include/argz.h [new file with mode: 0644]
user/newlib/include/assert.h [new file with mode: 0644]
user/newlib/include/ctype.h [new file with mode: 0644]
user/newlib/include/dirent.h [new file with mode: 0644]
user/newlib/include/envlock.h [new file with mode: 0644]
user/newlib/include/envz.h [new file with mode: 0644]
user/newlib/include/errno.h [new file with mode: 0644]
user/newlib/include/fastmath.h [new file with mode: 0644]
user/newlib/include/fcntl.h [new file with mode: 0644]
user/newlib/include/fnmatch.h [new file with mode: 0644]
user/newlib/include/getopt.h [new file with mode: 0644]
user/newlib/include/glob.h [new file with mode: 0644]
user/newlib/include/grp.h [new file with mode: 0644]
user/newlib/include/iconv.h [new file with mode: 0644]
user/newlib/include/ieeefp.h [new file with mode: 0644]
user/newlib/include/inttypes.h [new file with mode: 0644]
user/newlib/include/langinfo.h [new file with mode: 0644]
user/newlib/include/libgen.h [new file with mode: 0644]
user/newlib/include/limits.h [new file with mode: 0644]
user/newlib/include/locale.h [new file with mode: 0644]
user/newlib/include/machine/_default_types.h [new file with mode: 0644]
user/newlib/include/machine/_types.h [new file with mode: 0644]
user/newlib/include/machine/ansi.h [new file with mode: 0644]
user/newlib/include/machine/endian.h [new file with mode: 0644]
user/newlib/include/machine/fastmath.h [new file with mode: 0644]
user/newlib/include/machine/ieeefp.h [new file with mode: 0644]
user/newlib/include/machine/malloc.h [new file with mode: 0644]
user/newlib/include/machine/param.h [new file with mode: 0644]
user/newlib/include/machine/setjmp-dj.h [new file with mode: 0644]
user/newlib/include/machine/setjmp.h [new file with mode: 0644]
user/newlib/include/machine/stdlib.h [new file with mode: 0644]
user/newlib/include/machine/termios.h [new file with mode: 0644]
user/newlib/include/machine/time.h [new file with mode: 0644]
user/newlib/include/machine/types.h [new file with mode: 0644]
user/newlib/include/malloc.h [new file with mode: 0644]
user/newlib/include/math.h [new file with mode: 0644]
user/newlib/include/newlib.h [new file with mode: 0644]
user/newlib/include/paths.h [new file with mode: 0644]
user/newlib/include/process.h [new file with mode: 0644]
user/newlib/include/pthread.h [new file with mode: 0644]
user/newlib/include/pwd.h [new file with mode: 0644]
user/newlib/include/reent.h [new file with mode: 0644]
user/newlib/include/regdef.h [new file with mode: 0644]
user/newlib/include/regex.h [new file with mode: 0644]
user/newlib/include/sched.h [new file with mode: 0644]
user/newlib/include/search.h [new file with mode: 0644]
user/newlib/include/setjmp.h [new file with mode: 0644]
user/newlib/include/signal.h [new file with mode: 0644]
user/newlib/include/stdint.h [new file with mode: 0644]
user/newlib/include/stdio.h [new file with mode: 0644]
user/newlib/include/stdlib.h [new file with mode: 0644]
user/newlib/include/string.h [new file with mode: 0644]
user/newlib/include/sys/_default_fcntl.h [new file with mode: 0644]
user/newlib/include/sys/_types.h [new file with mode: 0644]
user/newlib/include/sys/cdefs.h [new file with mode: 0644]
user/newlib/include/sys/config.h [new file with mode: 0644]
user/newlib/include/sys/custom_file.h [new file with mode: 0644]
user/newlib/include/sys/dirent.h [new file with mode: 0644]
user/newlib/include/sys/errno.h [new file with mode: 0644]
user/newlib/include/sys/fcntl.h [new file with mode: 0644]
user/newlib/include/sys/features.h [new file with mode: 0644]
user/newlib/include/sys/file.h [new file with mode: 0644]
user/newlib/include/sys/iconvnls.h [new file with mode: 0644]
user/newlib/include/sys/lock.h [new file with mode: 0644]
user/newlib/include/sys/param.h [new file with mode: 0644]
user/newlib/include/sys/queue.h [new file with mode: 0644]
user/newlib/include/sys/reent.h [new file with mode: 0644]
user/newlib/include/sys/resource.h [new file with mode: 0644]
user/newlib/include/sys/sched.h [new file with mode: 0644]
user/newlib/include/sys/signal.h [new file with mode: 0644]
user/newlib/include/sys/stat.h [new file with mode: 0644]
user/newlib/include/sys/stdio.h [new file with mode: 0644]
user/newlib/include/sys/string.h [new file with mode: 0644]
user/newlib/include/sys/syslimits.h [new file with mode: 0644]
user/newlib/include/sys/time.h [new file with mode: 0644]
user/newlib/include/sys/timeb.h [new file with mode: 0644]
user/newlib/include/sys/times.h [new file with mode: 0644]
user/newlib/include/sys/types.h [new file with mode: 0644]
user/newlib/include/sys/unistd.h [new file with mode: 0644]
user/newlib/include/sys/utime.h [new file with mode: 0644]
user/newlib/include/sys/wait.h [new file with mode: 0644]
user/newlib/include/tar.h [new file with mode: 0644]
user/newlib/include/termios.h [new file with mode: 0644]
user/newlib/include/time.h [new file with mode: 0644]
user/newlib/include/unctrl.h [new file with mode: 0644]
user/newlib/include/unistd.h [new file with mode: 0644]
user/newlib/include/utime.h [new file with mode: 0644]
user/newlib/include/utmp.h [new file with mode: 0644]
user/newlib/include/wchar.h [new file with mode: 0644]
user/newlib/include/wctype.h [new file with mode: 0644]
user/newlib/include/wordexp.h [new file with mode: 0644]
user/newlib/lib/libc.a [new file with mode: 0644]
user/newlib/lib/libg.a [new file with mode: 0644]
user/newlib/lib/libm.a [new file with mode: 0644]
user/newlib/src/Makefrag [new file with mode: 0644]
user/newlib/src/libc_wrappers.c [new file with mode: 0644]
user/newlib/src/libc_wrappers.h [new file with mode: 0644]
user/null.c [deleted file]
user/parlib/COPYRIGHT [new file with mode: 0644]
user/parlib/Makefrag [new file with mode: 0644]
user/parlib/inc/assert.h [new file with mode: 0644]
user/parlib/inc/atomic.h [new file with mode: 0644]
user/parlib/inc/elf.h [new file with mode: 0644]
user/parlib/inc/env.h [new file with mode: 0644]
user/parlib/inc/error.h [new file with mode: 0644]
user/parlib/inc/kbdreg.h [new file with mode: 0644]
user/parlib/inc/lib.h [new file with mode: 0644]
user/parlib/inc/malloc.h [new file with mode: 0644]
user/parlib/inc/measure.h [new file with mode: 0644]
user/parlib/inc/memlayout.h [new file with mode: 0644]
user/parlib/inc/mmu.h [new file with mode: 0644]
user/parlib/inc/multiboot.h [new file with mode: 0644]
user/parlib/inc/null.h [new file with mode: 0644]
user/parlib/inc/pool.h [new file with mode: 0644]
user/parlib/inc/queue.h [new file with mode: 0644]
user/parlib/inc/ring_buffer.h [new file with mode: 0644]
user/parlib/inc/stab.h [new file with mode: 0644]
user/parlib/inc/stdarg.h [new file with mode: 0644]
user/parlib/inc/stdio.h [new file with mode: 0644]
user/parlib/inc/string.h [new file with mode: 0644]
user/parlib/inc/syscall.h [new file with mode: 0644]
user/parlib/inc/timer.h [new file with mode: 0644]
user/parlib/inc/trap.h [new file with mode: 0644]
user/parlib/inc/types.h [new file with mode: 0644]
user/parlib/inc/x86.h [new file with mode: 0644]
user/parlib/ivylib/Makefrag [new file with mode: 0644]
user/parlib/ivylib/deputy.c [new file with mode: 0644]
user/parlib/src/Makefrag [new file with mode: 0644]
user/parlib/src/asynccall.c [new file with mode: 0644]
user/parlib/src/console.c [new file with mode: 0644]
user/parlib/src/entry.S [new file with mode: 0644]
user/parlib/src/exit.c [new file with mode: 0644]
user/parlib/src/libmain.c [new file with mode: 0644]
user/parlib/src/null.c [new file with mode: 0644]
user/parlib/src/panic.c [new file with mode: 0644]
user/parlib/src/printf.c [new file with mode: 0644]
user/parlib/src/printfmt.c [new file with mode: 0644]
user/parlib/src/readline.c [new file with mode: 0644]
user/parlib/src/string.c [new file with mode: 0644]
user/parlib/src/syscall.c [new file with mode: 0644]
user/parlib/src/timer.c [new file with mode: 0644]
user/print_tests.c [deleted file]
user/softint.c [deleted file]
user/testbss.c [deleted file]
user/testpmap.c [deleted file]
user/user.ld [deleted file]
user_newlib/Makefrag [deleted file]
user_newlib/hello.c [deleted file]
user_newlib/null.c [deleted file]
user_newlib/user_newlib.ld [deleted file]

index ad88d09..6b4da62 100644 (file)
@@ -7,27 +7,9 @@
 #
 OBJDIR := obj
 
-ifdef LAB
-SETTINGLAB := true
-else
--include conf/lab.mk
-endif
-
--include conf/env.mk
-
-ifndef SOL
-SOL := 0
-endif
-ifndef LABADJUST
-LABADJUST := 0
-endif
-
-ifndef LABSETUP
-LABSETUP := ./
-endif
-
-
 TOP = .
+UNAME=$(shell uname -m)
+V = @
 
 # Cross-compiler ros toolchain
 #
@@ -53,84 +35,77 @@ GCCPREFIX := $(shell if i386-ros-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/de
        echo "***" 1>&2; exit 1; fi)
 endif
 
-CC     := $(GCCPREFIX)gcc -pipe
-GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
-AS     := $(GCCPREFIX)as
-AR     := $(GCCPREFIX)ar
-LD     := $(GCCPREFIX)ld
+# Default programs for compilation
+CC         := $(GCCPREFIX)ivycc --deputy
+AS         := $(GCCPREFIX)as
+AR         := $(GCCPREFIX)ar
+LD         := $(GCCPREFIX)ld
 OBJCOPY        := $(GCCPREFIX)objcopy
 OBJDUMP        := $(GCCPREFIX)objdump
-NM     := $(GCCPREFIX)nm
-ARCH ?= NONE
+NM         := $(GCCPREFIX)nm
+PERL    := perl
 
-# Native commands
-NCC    := gcc $(CC_VER) -pipe
-TAR    := gtar
-PERL   := perl
+# User defined constants passed on the command line 
+ARCH ?= NONE
 
-# Compiler flags
+# Universal 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) -D$(ARCH) -O -fno-builtin -fno-stack-protector -I$(TOP) -MD -Wall -Wno-format -Wno-unused -gstabs #-save-temps
+CFLAGS := $(CFLAGS) -D$(ARCH) 
+CFLAGS += -O -pipe -MD -fno-builtin -fno-stack-protector -gstabs
+CFLAGS += -Wall -Wno-format -Wno-unused
+CFLAGS += -I$(TOP)
 
-# 64 Bit machines need these settings to compile and link
-UNAME=$(shell uname -m)
+# Kernel vs. user universal compiler flags
+KERN_CFLAGS := $(CFLAGS) -DROS_KERNEL -nostdinc
+USER_CFLAGS := $(CFLAGS) -DROS_USER
+
+# Universal loader flags
+LDFLAGS := -nostdlib
+
+# Kernel vs. user universal loader flags
+KERN_LDFLAGS := 
+USER_LDFLAGS :=
+
+# GCC Library path 
+GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
+
+# 64 Bit specific flags / definitions
 ifeq ($(UNAME),x86_64)
-       LD += -melf_i386
        CFLAGS += -m32
+       LDFLAGS += -melf_i386
        GCC_LIB = $(shell $(CC) -print-libgcc-file-name | sed 's/libgcc.a/32\/libgcc.a/')
 endif
 
-# Linker flags for ROS user programs
-ULDFLAGS := -T user/user.ld -nostdlib
-ULDFLAGS := -T user_newlib/user_newlib.ld -nostdlib
-
-# Lists that the */Makefrag makefile fragments will add to
+# List of directories that the */Makefrag makefile fragments will add to
 OBJDIRS :=
 
 # Make sure that 'all' is the first target
 all:
 
-# Eliminate default suffix rules
-.SUFFIXES:
-
-# Delete target files if there is an error (or make is interrupted)
-.DELETE_ON_ERROR:
-
-# make it so that no intermediate .o files are ever deleted
-.PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
-       $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o \
-       $(OBJDIR)/newlib/%.o $(OBJDIR)/user_newlib/%.o
-
-KERN_CFLAGS := $(CFLAGS) -DROS_KERNEL -gstabs -nostdinc
-USER_CFLAGS := $(CFLAGS) -DROS_USER -gstabs
-
 # Include Makefrags for subdirectories
+include user/Makefrag
+# A hack until we get the story figured out with the kernel including files from 
+# parlib/inc
+KERN_CFLAGS += -I$(USER_PARLIB_DIR)
 include boot/Makefrag
-include lib/Makefrag
-include newlib/Makefrag
-include ivylib/Makefrag
 include kern/Makefrag
-include user/Makefrag
-include user_newlib/Makefrag
 -include Makelocal
 
-IMAGES = $(OBJDIR)/kern/bochs.img
-
-# For deleting the build
-clean:
-       rm -rf $(OBJDIR)
-
-realclean: clean
-       rm -rf lab$(LAB).tar.gz bochs.out bochs.log
+# Eliminate default suffix rules
+.SUFFIXES:
 
-distclean: realclean
-       rm -rf conf/gcc.mk
+# Delete target files if there is an error (or make is interrupted)
+.DELETE_ON_ERROR:
 
-usb: $(IMAGES)
-       sudo mount /dev/sde4 /media/usb
-       sudo cp obj/kern/kernel /media/usb/
-       sudo umount /media/usb
+# make it so that no intermediate .o files are ever deleted
+.PRECIOUS: %.o                                    \
+           $(OBJDIR)/$(BOOT_DIR)/%.o              \
+           $(OBJDIR)/$(KERN_DIR)/%.o              \
+              $(OBJDIR)/$(USER_PARLIB_DIR)/%.o       \
+              $(OBJDIR)/$(USER_NEWLIB_DIR)/%.o       \
+           $(OBJDIR)/$(USER_APPS_NEWLIB_DIR)/%.o  \
+           $(OBJDIR)/$(USER_APPS_PARLAB_DIR)/%.o
 
 # This magic automatically generates makefile dependencies
 # for header files included from C source files we compile,
@@ -138,12 +113,16 @@ usb: $(IMAGES)
 # See 'mergedep.pl' for more information.
 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
        @mkdir -p $(@D)
-       @$(PERL) mergedep.pl $@ $^
+       @$(PERL) scripts/mergedep.pl $@ $^
 
 -include $(OBJDIR)/.deps
 
+# For deleting the build
+clean:
+       rm -rf $(OBJDIR)
+
 always:
        @:
 
-.PHONY: all always \
-       handin tarball clean realclean clean-labsetup distclean grade labsetup
+.PHONY: all always clean
+
index 5fc6cfd..ced83d5 100644 (file)
@@ -5,28 +5,27 @@
 # where the GNUmakefile is located.
 #
 
-OBJDIRS += boot
+BOOT_DIR = boot
+OBJDIRS += $(BOOT_DIR)
 
-BOOT_OBJS := $(OBJDIR)/boot/boot.o $(OBJDIR)/boot/main.o
+BOOT_CFLAGS  := $(KERN_CFLAGS) -Os -I$(USER_PARLIB_DIR)
+BOOT_LDFLAGS := $(KERN_LDFLAGS) -N -e start -Ttext 0x7C00
+BOOT_OBJS    := $(OBJDIR)/$(BOOT_DIR)/boot.o $(OBJDIR)/$(BOOT_DIR)/main.o
 
-$(OBJDIR)/boot/%.o: boot/%.c
-       @echo + cc -Os $<
+$(OBJDIR)/$(BOOT_DIR)/%.o: $(BOOT_DIR)/%.c
+       @echo + cc [BOOT] $<
        @mkdir -p $(@D)
-       $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $@ $<
+       $(V)$(CC) $(BOOT_CFLAGS) -c -o $@ $<
 
-$(OBJDIR)/boot/%.o: boot/%.S
-       @echo + as $<
+$(OBJDIR)/$(BOOT_DIR)/%.o: $(BOOT_DIR)/%.S
+       @echo + as [BOOT] $<
        @mkdir -p $(@D)
-       $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
+       $(V)$(CC) $(BOOT_CFLAGS) -c -o $@ $<
 
-$(OBJDIR)/boot/main.o: boot/main.c
-       @echo + cc -Os $<
-       $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $(OBJDIR)/boot/main.o boot/main.c
-
-$(OBJDIR)/boot/boot: $(BOOT_OBJS)
-       @echo + ld boot/boot
-       $(V)$(LD) -N -e start -Ttext 0x7C00 -o $@.out $^
+$(OBJDIR)/$(BOOT_DIR)/boot: $(BOOT_OBJS)
+       @echo + ld [BOOT] $<
+       $(V)$(LD) $(BOOT_LDFLAGS) -o $@.out $^
        $(V)$(OBJDUMP) -S $@.out >$@.asm
        $(V)$(OBJCOPY) -S -O binary $@.out $@
-       $(V)perl boot/sign.pl $(OBJDIR)/boot/boot
+       $(V)perl boot/sign.pl $(OBJDIR)/$(BOOT_DIR)/boot
 
diff --git a/conf/env.mk b/conf/env.mk
deleted file mode 100644 (file)
index 96ef79f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-# env.mk - configuration variables for the ROS lab
-
-
-# '$(V)' controls whether the lab makefiles print verbose commands (the
-# actual shell commands run by Make), as well as the "overview" commands
-# (such as '+ cc lib/readline.c').
-#
-# For overview commands only, the line should read 'V = @'.
-# For overview and verbose commands, the line should read 'V ='.
-V = @
-
-
-# '$(HANDIN_EMAIL)' is the email address to which lab handins should be
-# sent.
-HANDIN_EMAIL = 6.828-handin@pdos.lcs.mit.edu
-
-
-##
-## If your system-standard GNU toolchain is ELF-compatible, then comment
-## out the following line to use those tools (as opposed to the i386-ros-elf
-## tools that the 6.828 make system looks for by default).
-##
-# GCCPREFIX=''
diff --git a/conf/lab.mk b/conf/lab.mk
deleted file mode 100644 (file)
index ce926b6..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-LAB=3
-PACKAGEDATE=Sun Jan 14 15:36:47 CST 2007
diff --git a/inc/COPYRIGHT b/inc/COPYRIGHT
deleted file mode 100644 (file)
index 54e7f32..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-The files in this directory are:
-
-/*
- * Copyright (C) 1997 Massachusetts Institute of Technology 
- *
- * This software is being provided by the copyright holders under the
- * following license. By obtaining, using and/or copying this software,
- * you agree that you have read, understood, and will comply with the
- * following terms and conditions:
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose and without fee or royalty is
- * hereby granted, provided that the full text of this NOTICE appears on
- * ALL copies of the software and documentation or portions thereof,
- * including modifications, that you make.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
- * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
- * BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
- * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
- * THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
- * THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT
- * HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE OR
- * DOCUMENTATION.
- *
- * The name and trademarks of copyright holders may NOT be used in
- * advertising or publicity pertaining to the software without specific,
- * written prior permission. Title to copyright in this software and any
- * associated documentation will at all times remain with copyright
- * holders. See the file AUTHORS which should have accompanied this software
- * for a list of all copyright holders.
- *
- * This file may be derived from previously copyrighted software. This
- * copyright applies only to those changes made by the copyright
- * holders listed in the AUTHORS file. The rest of this file is covered by
- * the copyright notices, if any, listed below.
- */
-
-isareg.h is copyright:
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     @(#)isa.h       5.7 (Berkeley) 5/9/91
- */
-
-queue.h is:
-
-/* 
- * Copyright (c) 1991, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     @(#)queue.h     8.5 (Berkeley) 8/20/94
- */
-
-stdarg.h is:
-
-/*-
- * Copyright (c) 1991, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     @(#)stdarg.h    8.1 (Berkeley) 6/10/93
- */
-
-timerreg.h is:
-
-/*-
- * Copyright (c) 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by the University of
- *      California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-types.h is:
-
-/*-
- * Copyright (c) 1982, 1986, 1991, 1993
- *     The Regents of the University of California.  All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     @(#)types.h     8.4 (Berkeley) 1/21/94
- */
-
diff --git a/inc/assert.h b/inc/assert.h
deleted file mode 100644 (file)
index 1f762d3..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-#ifndef ROS_INC_ASSERT_H
-#define ROS_INC_ASSERT_H
-
-#include <inc/stdio.h>
-
-void _warn(const char* NTS, int, const char* NTS, ...);
-void _panic(const char* NTS, int, const char* NTS, ...) __attribute__((noreturn));
-
-#define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__)
-#define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__)
-
-#define assert(x)              \
-       do { if (!(x)) panic("assertion failed: %s", #x); } while (0)
-
-// static_assert(x) will generate a compile-time error if 'x' is false.
-#define static_assert(x)       switch (x) case 0: case (x):
-
-#endif /* !ROS_INC_ASSERT_H */
diff --git a/inc/atomic.h b/inc/atomic.h
deleted file mode 100644 (file)
index 3a26328..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef ROS_INC_ATOMIC_H
-#define ROS_INC_ATOMIC_H
-
-// TODO - check these, wrt x86
-#define mb() {rmb(); wmb();}
-#define rmb() ({ asm volatile("lfence"); })
-#define wmb() 
-
-#endif /* !ROS_INC_ATOMIC_H */
diff --git a/inc/elf.h b/inc/elf.h
deleted file mode 100644 (file)
index f7bef79..0000000
--- a/inc/elf.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef ROS_INC_ELF_H
-#define ROS_INC_ELF_H
-
-#define ELF_MAGIC 0x464C457FU  /* "\x7FELF" in little endian */
-
-#include <inc/types.h>
-
-typedef struct Elf {
-       uint32_t e_magic;       // must equal ELF_MAGIC
-       uint8_t e_elf[12];
-       uint16_t e_type;
-       uint16_t e_machine;
-       uint32_t e_version;
-       uint32_t e_entry;
-       uint32_t e_phoff;
-       uint32_t e_shoff;
-       uint32_t e_flags;
-       uint16_t e_ehsize;
-       uint16_t e_phentsize;
-       uint16_t e_phnum;
-       uint16_t e_shentsize;
-       uint16_t e_shnum;
-       uint16_t e_shstrndx;
-} elf_t;
-
-typedef struct Proghdr {
-       uint32_t p_type;
-       uint32_t p_offset;
-       uint32_t p_va;
-       uint32_t p_pa;
-       uint32_t p_filesz;
-       uint32_t p_memsz;
-       uint32_t p_flags;
-       uint32_t p_align;
-} proghdr_t;
-
-typedef struct Secthdr {
-       uint32_t sh_name;
-       uint32_t sh_type;
-       uint32_t sh_flags;
-       uint32_t sh_addr;
-       uint32_t sh_offset;
-       uint32_t sh_size;
-       uint32_t sh_link;
-       uint32_t sh_info;
-       uint32_t sh_addralign;
-       uint32_t sh_entsize;
-} secthdr_t;
-
-// Values for Proghdr::p_type
-#define ELF_PROG_LOAD          1
-
-// Flag bits for Proghdr::p_flags
-#define ELF_PROG_FLAG_EXEC     1
-#define ELF_PROG_FLAG_WRITE    2
-#define ELF_PROG_FLAG_READ     4
-
-// Values for Secthdr::sh_type
-#define ELF_SHT_NULL           0
-#define ELF_SHT_PROGBITS       1
-#define ELF_SHT_SYMTAB         2
-#define ELF_SHT_STRTAB         3
-
-// Values for Secthdr::sh_name
-#define ELF_SHN_UNDEF          0
-
-#endif /* !ROS_INC_ELF_H */
diff --git a/inc/env.h b/inc/env.h
deleted file mode 100644 (file)
index f72c328..0000000
--- a/inc/env.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-#ifndef ROS_INC_ENV_H
-#define ROS_INC_ENV_H
-
-#include <inc/types.h>
-#include <inc/queue.h>
-#include <inc/trap.h>
-#include <inc/memlayout.h>
-
-#include <inc/syscall.h>
-
-struct Env;
-typedef struct Env env_t;
-
-typedef int32_t envid_t;
-
-// An environment ID 'envid_t' has three parts:
-//
-// +1+---------------21-----------------+--------10--------+
-// |0|          Uniqueifier             |   Environment    |
-// | |                                  |      Index       |
-// +------------------------------------+------------------+
-//                                       \--- ENVX(eid) --/
-//
-// The environment index ENVX(eid) equals the environment's offset in the
-// 'envs[]' array.  The uniqueifier distinguishes environments that were
-// created at different times, but share the same environment index.
-//
-// All real environments are greater than 0 (so the sign bit is zero).
-// envid_ts less than 0 signify errors.  The envid_t == 0 is special, and
-// stands for the current environment.
-
-#define LOG2NENV               10
-#define NENV                   (1 << LOG2NENV)
-#define ENVX(envid)            ((envid) & (NENV - 1))
-
-// Values of env_status in struct Env
-#define ENV_FREE               0
-#define ENV_RUNNABLE           1
-#define ENV_NOT_RUNNABLE       2
-
-struct Env {
-       trapframe_t env_tf;                     // Saved registers
-       LIST_ENTRY(env_t) env_link;     // Free list link pointers
-       envid_t env_id;                         // Unique environment identifier
-       envid_t env_parent_id;          // env_id of this env's parent
-       unsigned env_status;            // Status of the environment
-       uint32_t env_runs;                      // Number of times environment has run
-       // Note this is the actual backring, not a pointer to it somewhere else
-       syscall_back_ring_t env_sysbackring;    // BackRing for generic syscalls
-
-       // Address space
-       pde_t *env_pgdir;                       // Kernel virtual address of page dir
-       physaddr_t env_cr3;                     // Physical address of page dir
-       // TODO - give these two proper types (pointers to structs)
-       void* env_procinfo;             // KVA of per-process shared info table (RO)
-       void* env_procdata;             // KVA of per-process shared data table (RW)
-       // Eventually want to move this to a per-system shared-info page
-       uint64_t env_tscfreq;           // Frequency of the TSC for measurements
-};
-
-#endif // !ROS_INC_ENV_H
diff --git a/inc/error.h b/inc/error.h
deleted file mode 100644 (file)
index 28fa1f9..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-#ifndef ROS_INC_ERROR_H
-#define ROS_INC_ERROR_H
-
-typedef enum {
-       E_DEADLOCK      =       -3,
-       E_BUSY          =       -2,
-       E_FAIL          =       -1,
-       E_SUCCESS       =       0,
-} error_t;
-
-// Kernel error codes -- keep in sync with list in lib/printfmt.c.
-#define E_UNSPECIFIED  1       // Unspecified or unknown problem
-#define E_BAD_ENV              2       // Environment doesn't exist or otherwise
-                                                       // cannot be used in requested action
-#define E_INVAL                        3       // Invalid parameter
-#define E_NO_MEM               4       // Request failed due to memory shortage
-#define E_NO_FREE_ENV  5       // Attempt to create a new environment beyond
-                                                       // the maximum allowed
-#define E_FAULT                        6       // Memory fault
-#define        MAXERROR                6
-
-#endif // !ROS_INC_ERROR_H */
diff --git a/inc/kbdreg.h b/inc/kbdreg.h
deleted file mode 100644 (file)
index 0c7ffea..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifndef ROS_KBDREG_H
-#define ROS_KBDREG_H
-
-// Special keycodes
-#define KEY_HOME       0xE0
-#define KEY_END                0xE1
-#define KEY_UP         0xE2
-#define KEY_DN         0xE3
-#define KEY_LF         0xE4
-#define KEY_RT         0xE5
-#define KEY_PGUP       0xE6
-#define KEY_PGDN       0xE7
-#define KEY_INS                0xE8
-#define KEY_DEL                0xE9
-
-
-/* This is i8042reg.h + kbdreg.h from NetBSD. */
-
-#define        KBSTATP         0x64    /* kbd controller status port(I) */
-#define         KBS_DIB        0x01    /* kbd data in buffer */
-#define         KBS_IBF        0x02    /* kbd input buffer low */
-#define         KBS_WARM       0x04    /* kbd input buffer low */
-#define         KBS_OCMD       0x08    /* kbd output buffer has command */
-#define         KBS_NOSEC      0x10    /* kbd security lock not engaged */
-#define         KBS_TERR       0x20    /* kbd transmission error */
-#define         KBS_RERR       0x40    /* kbd receive error */
-#define         KBS_PERR       0x80    /* kbd parity error */
-
-#define        KBCMDP          0x64    /* kbd controller port(O) */
-#define         KBC_RAMREAD    0x20    /* read from RAM */
-#define         KBC_RAMWRITE   0x60    /* write to RAM */
-#define         KBC_AUXDISABLE 0xa7    /* disable auxiliary port */
-#define         KBC_AUXENABLE  0xa8    /* enable auxiliary port */
-#define         KBC_AUXTEST    0xa9    /* test auxiliary port */
-#define         KBC_KBDECHO    0xd2    /* echo to keyboard port */
-#define         KBC_AUXECHO    0xd3    /* echo to auxiliary port */
-#define         KBC_AUXWRITE   0xd4    /* write to auxiliary port */
-#define         KBC_SELFTEST   0xaa    /* start self-test */
-#define         KBC_KBDTEST    0xab    /* test keyboard port */
-#define         KBC_KBDDISABLE 0xad    /* disable keyboard port */
-#define         KBC_KBDENABLE  0xae    /* enable keyboard port */
-#define         KBC_PULSE0     0xfe    /* pulse output bit 0 */
-#define         KBC_PULSE1     0xfd    /* pulse output bit 1 */
-#define         KBC_PULSE2     0xfb    /* pulse output bit 2 */
-#define         KBC_PULSE3     0xf7    /* pulse output bit 3 */
-
-#define        KBDATAP         0x60    /* kbd data port(I) */
-#define        KBOUTP          0x60    /* kbd data port(O) */
-
-#define        K_RDCMDBYTE     0x20
-#define        K_LDCMDBYTE     0x60
-
-#define        KC8_TRANS       0x40    /* convert to old scan codes */
-#define        KC8_MDISABLE    0x20    /* disable mouse */
-#define        KC8_KDISABLE    0x10    /* disable keyboard */
-#define        KC8_IGNSEC      0x08    /* ignore security lock */
-#define        KC8_CPU         0x04    /* exit from protected mode reset */
-#define        KC8_MENABLE     0x02    /* enable mouse interrupt */
-#define        KC8_KENABLE     0x01    /* enable keyboard interrupt */
-#define        CMDBYTE         (KC8_TRANS|KC8_CPU|KC8_MENABLE|KC8_KENABLE)
-
-/* keyboard commands */
-#define        KBC_RESET       0xFF    /* reset the keyboard */
-#define        KBC_RESEND      0xFE    /* request the keyboard resend the last byte */
-#define        KBC_SETDEFAULT  0xF6    /* resets keyboard to its power-on defaults */
-#define        KBC_DISABLE     0xF5    /* as per KBC_SETDEFAULT, but also disable key scanning */
-#define        KBC_ENABLE      0xF4    /* enable key scanning */
-#define        KBC_TYPEMATIC   0xF3    /* set typematic rate and delay */
-#define        KBC_SETTABLE    0xF0    /* set scancode translation table */
-#define        KBC_MODEIND     0xED    /* set mode indicators(i.e. LEDs) */
-#define        KBC_ECHO        0xEE    /* request an echo from the keyboard */
-
-/* keyboard responses */
-#define        KBR_EXTENDED    0xE0    /* extended key sequence */
-#define        KBR_RESEND      0xFE    /* needs resend of command */
-#define        KBR_ACK         0xFA    /* received a valid command */
-#define        KBR_OVERRUN     0x00    /* flooded */
-#define        KBR_FAILURE     0xFD    /* diagnosic failure */
-#define        KBR_BREAK       0xF0    /* break code prefix - sent on key release */
-#define        KBR_RSTDONE     0xAA    /* reset complete */
-#define        KBR_ECHO        0xEE    /* echo response */
-
-#endif /* !ROS_KBDREG_H */
diff --git a/inc/lib.h b/inc/lib.h
deleted file mode 100644 (file)
index 5813e47..0000000
--- a/inc/lib.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// 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 ROS_INC_LIB_H
-#define ROS_INC_LIB_H 1
-
-#include <inc/types.h>
-#include <inc/stdarg.h>
-#include <inc/string.h>
-#include <inc/error.h>
-#include <inc/env.h>
-#include <inc/memlayout.h>
-#include <inc/syscall.h>
-#include <inc/pool.h>
-#include <inc/timer.h>
-// These two are included below because of dependency issues.
-//#include <inc/stdio.h>
-//#include <inc/assert.h>
-
-#define USED(x)                (void)(x)
-
-// libos.c or entry.S
-extern char *binaryname;
-extern volatile env_t *env;
-// will need to change these types when we have real structs
-// seems like they need to be either arrays [] or functions () for it to work
-extern volatile uint8_t (COUNT(PGSIZE * UINFO_PAGES) procinfo)[];
-extern volatile uint8_t (COUNT(PGSIZE * UDATA_PAGES) procdata)[];
-extern syscall_front_ring_t sysfrontring;
-extern volatile page_t pages[];
-void   exit(void);
-
-// readline.c
-char*  readline(const char *buf);
-
-// syscall.c
-void sys_null();
-error_t sys_null_async(syscall_desc_t* desc);
-void sys_cache_buster(uint32_t num_writes, uint32_t val);
-error_t sys_cache_buster_async(syscall_desc_t* desc, uint32_t num_writes,
-                               uint32_t val);
-void sys_cputs(const char *string, size_t len);
-error_t sys_cputs_async(const char *s, size_t len, syscall_desc_t* desc,
-                     void (*cleanup_handler)(void*), void* cleanup_data);
-int    sys_cgetc(void);
-envid_t        sys_getenvid(void);
-int    sys_env_destroy(envid_t);
-error_t waiton_syscall(syscall_desc_t* desc, syscall_rsp_t* rsp);
-
-// async callback
-#define MAX_SYSCALLS 100
-#define MAX_ASYNCCALLS 100
-// The high-level object a process waits on, with multiple syscalls within.
-typedef struct async_desc {
-       syscall_desc_list_t syslist;
-       void (*cleanup)(void* data);
-       void* data;
-} async_desc_t;
-
-// Response to an async call.  Should be some sort of aggregation of the
-// syscall responses.
-typedef struct async_rsp_t {
-       int32_t retval;
-} async_rsp_t;
-
-// This is per-thread, and used when entering a async library call to properly
-// group syscall_desc_t used during the processing of that async call
-extern async_desc_t* current_async_desc;
-// stdio.h needs to be included after async_desc_t.  assert.h includes stdio.h.
-#include <inc/stdio.h>
-#include <inc/assert.h>
-
-// This pooltype contains syscall_desc_t, which is how you wait on one syscall.
-POOL_TYPE_DEFINE(syscall_desc_t, syscall_desc_pool, MAX_SYSCALLS);
-POOL_TYPE_DEFINE(async_desc_t, async_desc_pool, MAX_ASYNCCALLS);
-
-// This pooltype contains all the timers used in user level time tracking
-POOL_TYPE_DEFINE(timer_t, timer_pool, MAX_TIMERS);
-
-// These are declared in libmain.c
-extern syscall_desc_pool_t syscall_desc_pool;
-extern async_desc_pool_t async_desc_pool;
-extern timer_pool_t timer_pool;
-
-error_t waiton_async_call(async_desc_t* desc, async_rsp_t* rsp);
-async_desc_t* get_async_desc(void);
-syscall_desc_t* get_sys_desc(async_desc_t* desc);
-error_t get_all_desc(async_desc_t** a_desc, syscall_desc_t** s_desc);
-
-
-/* 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 // !ROS_INC_LIB_H
diff --git a/inc/malloc.h b/inc/malloc.h
deleted file mode 100644 (file)
index c9fbec8..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef ROS_INC_MALLOC_H
-#define ROS_INC_MALLOC_H 1
-
-void *malloc(size_t size);
-void free(void *addr);
-
-#endif
diff --git a/inc/measure.h b/inc/measure.h
deleted file mode 100644 (file)
index af228f9..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef ROS_INC_MEASURE_H
-#define ROS_INC_MEASURE_H
-
-#include <inc/types.h>
-#include <inc/stdio.h>
-#include <inc/timer.h>
-#include <inc/x86.h>
-
-/* Macro for printing out debug information about our measurement setup.
- * If MEASURE_DEBUG is set to 1, debug info will be printed.  If set to 0
- * no debug info will be printed.
- */
-#define MEASURE_DEBUG  1
-#if MEASURE_DEBUG
-#ifndef ROS_KERNEL
-       #define mdebug(string, ...)     cprintf(string, ## __VA_ARGS__)
-#else
-       #define mdebug(string, ...)     printk(string, ## __VA_ARGS__)
-#endif
-#else
-       #define mdebug(string, ...)
-#endif
-
-#define __measure_runtime(__CODE_BLOCK__)                                      \
-({                                                                             \
-       uint64_t time = start_timing();                                            \
-       __CODE_BLOCK__;                                                            \
-       stop_timing(time);                                                         \
-})
-
-#define measure_func_runtime(func, ...)                                        \
-({                                                                             \
-       __measure_runtime(func(__VA_ARGS__));                                      \
-})
-
-
-#define measure_function(func, iters, name)                                    \
-({                                                                             \
-       uint64_t ticks;                                                            \
-       cpuid(0, 0, 0, 0, 0);                                                      \
-       ticks = read_tsc();                                                        \
-       /* Run this a bunch of times to make sure its accurate */                  \
-       for(int i=0; i< (iters); i++) {                                            \
-               func ;                                                                 \
-       }                                                                          \
-       cpuid(0, 0, 0, 0, 0);                                                      \
-       ticks = read_tsc() - ticks;                                                \
-       /* Compute the average and print it */                                     \
-       uint64_t a = (1000000000LL/(iters) * ticks) / (env->env_tscfreq);          \
-       if ((name))                                                                \
-               cprintf("Measuring %s:\n"                                              \
-                       "    Total ticks:          %20lld\n"                           \
-                       "    Num Iterations:       %20d\n"                             \
-                       "    Time Per Iteration:   %20lld\n",                          \
-               name, ticks, (iters), a);                                          \
-       ticks;                                                                     \
-})
-
-#define measure_function_async(func, _desc_type, _rsp_type, wait_func,         \
-                                  desc_name, i_iters, o_iters, name)              \
-({                                                                             \
-       uint64_t ticks;                                                            \
-       _desc_type* desc_array[i_iters];                                           \
-       _desc_type* desc_name;                                                     \
-       /* Could use an array of rsps, but we're throwing away the responses*/     \
-       _rsp_type rsp;                                                             \
-       error_t err;                                                               \
-       uint32_t safe_i_iters = i_iters;                                           \
-       cpuid(0, 0, 0, 0, 0);                                                      \
-       ticks = read_tsc();                                                        \
-       /* Run this a bunch of times to make sure its accurate */                  \
-       for(int i=0; i< (o_iters); i++) {                                          \
-               for (int j = 0; j < (safe_i_iters); j++) {                             \
-                       err = func ;                                                       \
-                       if (err)                                                           \
-                               (safe_i_iters) = j;                                            \
-                       desc_array[j] = desc_name;                                         \
-               }                                                                      \
-               for (int j = 0; j < (safe_i_iters); j++) {                             \
-                       wait_func(desc_array[j], &rsp);                                    \
-               }                                                                      \
-       }                                                                          \
-       cpuid(0, 0, 0, 0, 0);                                                      \
-       ticks = read_tsc() - ticks;                                                \
-       /* Compute the average and print it */                                     \
-       uint64_t a = (1000000000LL/((o_iters)*(safe_i_iters)) * ticks) /           \
-                    (env->env_tscfreq);                                           \
-       if ((name))                                                                \
-               cprintf("Measuring %s:\n"                                              \
-                       "    Total ticks:          %20lld\n"                           \
-                       "    Num Total Iterations: %20d\n"                             \
-                       "    Num Inner Iterations: %20d\n"                             \
-                       "    Time Per Iteration:   %20lld\n",                          \
-               name, ticks, ((o_iters)*(safe_i_iters)), safe_i_iters, a);         \
-       ticks;                                                                     \
-})
-
-#define measure_async_call(func, desc_name, i_iters, o_iters, name)            \
-       measure_function_async(func, async_desc_t, async_rsp_t, waiton_async_call, \
-                              desc_name, i_iters, o_iters, name)
-
-#endif /* !ROS_INC_MEASURE_H */
-
-
-
diff --git a/inc/memlayout.h b/inc/memlayout.h
deleted file mode 100644 (file)
index 2c6fc5b..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-#ifndef ROS_INC_MEMLAYOUT_H
-#define ROS_INC_MEMLAYOUT_H
-
-#ifndef __ASSEMBLER__
-#include <inc/types.h>
-#include <inc/queue.h>
-#include <inc/mmu.h>
-#endif /* not __ASSEMBLER__ */
-
-/*
- * This file contains definitions for memory management in our OS,
- * which are relevant to both the kernel and user-mode software.
- */
-
-// Global descriptor numbers
-#define GD_KT     0x08     // kernel text
-#define GD_KD     0x10     // kernel data
-#define GD_UT     0x18     // user text
-#define GD_UD     0x20     // user data
-#define GD_TSS    0x28     // Task segment selector
-
-/*
- * Virtual memory map:                                Permissions
- *                                                    kernel/user
- *
- *    4 Gig -------->  +------------------------------+
- *                     |                              | RW/--
- *                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *                     :              .               :
- *                     :              .               :
- *                     :              .               :
- *                     |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| RW/--
- *                     |                              | RW/--
- *                     |   Remapped Physical Memory   | RW/--
- *                     |                              | RW/--
- *    KERNBASE ----->  +------------------------------+ 0xc0000000
- *                     |  Cur. Page Table (Kern. RW)  | RW/--  PTSIZE
- *    VPT,KSTACKTOP--> +------------------------------+ 0xbfc00000      --+
- *                     |         Kernel Stack         | RW/--  KSTKSIZE   |
- *                     | - - - - - - - - - - - - - - -|                 PTSIZE
- *                     |      Invalid Memory (*)      | --/--             |
- *    ULIM     ------> +------------------------------+ 0xbf800000      --+
- *                     |  Cur. Page Table (User R-)   | R-/R-  PTSIZE
- *    UVPT      ---->  +------------------------------+ 0xbf400000
- *                     |          RO PAGES            | R-/R-  PTSIZE
- *    UPAGES    ---->  +------------------------------+ 0xbf000000      --+
- *                     |  Unmapped (future expansion) | --/--             |
- *                     +------------------------------+ 0xbec01000      PTSIZE
- *                     |     Per-Process R/O Info     | R-/R-  PGSIZE     |
- * UTOP, UINFO  ---->  +------------------------------+ 0xbec00000      --+
- *                     |  Unmapped (future expansion) | --/--             |
- *                     +------------------------------+ 0xbe801000      PTSIZE
- *                     |     Per-Process R/W Data     | RW/RW  PGSIZE     |
- * UDATA,UXSTACKTOP--> +------------------------------+ 0xbe800000      --+
- *                     |     User Exception Stack     | RW/RW  PGSIZE
- *                     +------------------------------+ 0xbe7ff000
- *                     |       Empty Memory (*)       | --/--  PGSIZE
- *    USTACKTOP  --->  +------------------------------+ 0xbe7fe000
- *                     |      Normal User Stack       | RW/RW  PGSIZE
- *                     +------------------------------+ 0xbe7fd000
- *                     |                              |
- *                     |                              |
- *                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *                     .                              .
- *                     .                              .
- *                     .                              .
- *                     |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
- *                     |     Program Data & Heap      |
- *    UTEXT -------->  +------------------------------+ 0x00800000
- *    PFTEMP ------->  |       Empty Memory (*)       |        PTSIZE
- *                     |                              |
- *    UTEMP -------->  +------------------------------+ 0x00400000      --+
- *                     |       Empty Memory (*)       |                   |
- *                     | - - - - - - - - - - - - - - -|                   |
- *                     |  User STAB Data (optional)   |                 PTSIZE
- *    USTABDATA ---->  +------------------------------+ 0x00200000        |
- *                     |       Empty Memory (*)       |                   |
- *    0 ------------>  +------------------------------+                 --+
- *
- * (*) Note: The kernel ensures that "Invalid Memory" (ULIM) is *never*
- *     mapped.  "Empty Memory" is normally unmapped, but user programs may
- *     map pages there if desired.  ROS user programs map pages temporarily
- *     at UTEMP.
- */
-
-
-// All physical memory mapped at this address
-#define        KERNBASE        0xC0000000
-
-// At IOPHYSMEM (640K) there is a 384K hole for I/O.  From the kernel,
-// IOPHYSMEM can be addressed at KERNBASE + IOPHYSMEM.  The hole ends
-// at physical address EXTPHYSMEM.
-#define IOPHYSMEM      0x0A0000
-#define VGAPHYSMEM     0x0A0000
-#define DEVPHYSMEM     0x0C0000
-#define BIOSPHYSMEM    0x0F0000
-#define EXTPHYSMEM     0x100000
-
-// Virtual page table.  Entry PDX(VPT) in the PD contains a pointer to
-// the page directory itself, thereby turning the PD into a page table,
-// which maps all the PTEs containing the page mappings for the entire
-// virtual address space into that 4 Meg region starting at VPT.
-#define VPT            (KERNBASE - PTSIZE)
-#define KSTACKTOP      VPT
-#define KSTKSIZE       (8*PGSIZE)              // size of a kernel stack
-#define ULIM           (KSTACKTOP - PTSIZE) 
-
-/*
- * User read-only mappings! Anything below here til UTOP are readonly to user.
- * They are global pages mapped in at env allocation time.
- */
-
-// Same as VPT but read-only for users
-#define UVPT           (ULIM - PTSIZE)
-// Read-only copies of the Page structures
-#define UPAGES         (UVPT - PTSIZE)
-// Read-only, per-process shared info structures
-#define UINFO          (UPAGES - PTSIZE)
-#define UINFO_PAGES 1
-
-/*
- * Top of user VM. User can manipulate VA from UTOP-1 and down!
- */
-
-// Top of user-accessible VM
-#define UTOP           UINFO
-
-// Read-write, per-process shared data structures
-#define UDATA          (UTOP - PTSIZE)
-#define UDATA_PAGES 1
-
-// Top of one-page user exception stack
-#define UXSTACKTOP     UDATA
-// Next page left invalid to guard against exception stack overflow; then:
-// Top of normal user stack
-#define USTACKTOP      (UXSTACKTOP - 2*PGSIZE)
-
-// Where user programs generally begin
-#define UTEXT          (2*PTSIZE)
-
-// Used for temporary page mappings.  Typed 'void*' for convenience
-#define UTEMP          ((void*) PTSIZE)
-// Used for temporary page mappings for the user page-fault handler
-// (should not conflict with other temporary page mappings)
-#define PFTEMP         (UTEMP + PTSIZE - PGSIZE)
-// The location of the user-level STABS data structure
-#define USTABDATA      (PTSIZE / 2)    
-
-
-#ifndef __ASSEMBLER__
-
-/*
- * The page directory entry corresponding to the virtual address range
- * [VPT, VPT + PTSIZE) points to the page directory itself.  Thus, the page
- * directory is treated as a page table as well as a page directory.
- *
- * One result of treating the page directory as a page table is that all PTEs
- * can be accessed through a "virtual page table" at virtual address VPT (to
- * which vpt is set in entry.S).  The PTE for page number N is stored in
- * vpt[N].  (It's worth drawing a diagram of this!)
- *
- * A second consequence is that the contents of the current page directory
- * will always be available at virtual address (VPT + (VPT >> PGSHIFT)), to
- * which vpd is set in entry.S.
- */
-typedef uint32_t pte_t;
-typedef uint32_t pde_t;
-
-extern volatile pte_t vpt[];     // VA of "virtual page table"
-extern volatile pde_t vpd[];     // VA of current page directory
-
-/*
- * Page descriptor structures, mapped at UPAGES.
- * Read/write to the kernel, read-only to user programs.
- *
- * Each Page describes one physical page.
- * You can map a Page * to the corresponding physical address
- * with page2pa() in kern/pmap.h.
- */
-
-struct Page;
-typedef struct Page page_t;
-
-LIST_HEAD(page_list_t, page_t);
-typedef LIST_ENTRY(page_t) page_list_entry_t;
-
-struct Page {
-       page_list_entry_t pp_link;      /* free list link */
-
-       // pp_ref is the count of pointers (usually in page table entries)
-       // to this page, for pages allocated using page_alloc.
-       // Pages allocated at boot time using pmap.c's
-       // boot_alloc do not have valid reference count fields.
-
-       uint16_t pp_ref;
-};
-
-#endif /* !__ASSEMBLER__ */
-#endif /* !ROS_INC_MEMLAYOUT_H */
diff --git a/inc/mmu.h b/inc/mmu.h
deleted file mode 100644 (file)
index 4ea4a45..0000000
--- a/inc/mmu.h
+++ /dev/null
@@ -1,329 +0,0 @@
-#ifndef ROS_INC_MMU_H
-#define ROS_INC_MMU_H
-
-/*
- * This file contains definitions for the x86 memory management unit (MMU),
- * including paging- and segmentation-related data structures and constants,
- * the %cr0, %cr4, and %eflags registers, and traps.
- */
-
-/*
- *
- *     Part 1.  Paging data structures and constants.
- *
- */
-
-// A linear address 'la' has a three-part structure as follows:
-//
-// +--------10------+-------10-------+---------12----------+
-// | Page Directory |   Page Table   | Offset within Page  |
-// |      Index     |      Index     |                     |
-// +----------------+----------------+---------------------+
-//  \--- PDX(la) --/ \--- PTX(la) --/ \---- PGOFF(la) ----/
-//  \----------- PPN(la) -----------/
-//
-// The PDX, PTX, PGOFF, and PPN macros decompose linear addresses as shown.
-// To construct a linear address la from PDX(la), PTX(la), and PGOFF(la),
-// use PGADDR(PDX(la), PTX(la), PGOFF(la)).
-
-// page number field of address
-#define PPN(la)                (((uintptr_t) (la)) >> PTXSHIFT)
-#define VPN(la)                PPN(la)         // used to index into vpt[]
-
-// page directory index
-#define PDX(la)                ((((uintptr_t) (la)) >> PDXSHIFT) & 0x3FF)
-#define VPD(la)                PDX(la)         // used to index into vpd[]
-
-// page table index
-#define PTX(la)                ((((uintptr_t) (la)) >> PTXSHIFT) & 0x3FF)
-
-// offset in page
-#define PGOFF(la)      (((uintptr_t) (la)) & 0xFFF)
-
-// offset in jumbo page
-#define JPGOFF(la)     (((uintptr_t) (la)) & 0x003FFFFF)
-
-// construct linear address from indexes and offset
-#define PGADDR(d, t, o)        ((void*) ((d) << PDXSHIFT | (t) << PTXSHIFT | (o)))
-
-// Page directory and page table constants.
-#define NPDENTRIES     1024            // page directory entries per page directory
-#define NPTENTRIES     1024            // page table entries per page table
-
-#define PGSIZE         4096            // bytes mapped by a page
-#define JPGSIZE                4096*1024       // bytes mapped by a jumbo page (4MB)
-#define PGSHIFT                12              // log2(PGSIZE)
-
-#define PTSIZE         (PGSIZE*NPTENTRIES) // bytes mapped by a page directory entry
-#define PTSHIFT                22              // log2(PTSIZE)
-
-#define PTXSHIFT       12              // offset of PTX in a linear address
-#define PDXSHIFT       22              // offset of PDX in a linear address
-
-// Page table/directory entry flags.
-#define PTE_P          0x001   // Present
-#define PTE_W          0x002   // Writeable
-#define PTE_U          0x004   // User
-#define PTE_PWT                0x008   // Write-Through
-#define PTE_PCD                0x010   // Cache-Disable
-#define PTE_A          0x020   // Accessed
-#define PTE_D          0x040   // Dirty
-#define PTE_PS         0x080   // Page Size (only applies to PDEs)
-#define PTE_PAT                0x080   // PAT (only applies to second layer PTEs)
-#define PTE_G          0x100   // Global Page
-
-// The PTE_AVAIL bits aren't used by the kernel or interpreted by the
-// hardware, so user processes are allowed to set them arbitrarily.
-#define PTE_AVAIL      0xE00   // Available for software use
-
-// Only flags in PTE_USER may be used in system calls.
-#define PTE_USER       (PTE_AVAIL | PTE_P | PTE_W | PTE_U)
-
-// address in page table entry
-#define PTE_ADDR(pte)  ((physaddr_t) (pte) & ~0xFFF)
-
-// Control Register flags
-#define CR0_PE         0x00000001      // Protection Enable
-#define CR0_MP         0x00000002      // Monitor coProcessor
-#define CR0_EM         0x00000004      // Emulation
-#define CR0_TS         0x00000008      // Task Switched
-#define CR0_ET         0x00000010      // Extension Type
-#define CR0_NE         0x00000020      // Numeric Error
-#define CR0_WP         0x00010000      // Write Protect
-#define CR0_AM         0x00040000      // Alignment Mask
-#define CR0_NW         0x20000000      // Not Writethrough - more tricky than it sounds
-#define CR0_CD         0x40000000      // Cache Disable
-#define CR0_PG         0x80000000      // Paging
-
-// These two relate to the cacheability (L1, etc) of the page directory
-#define CR3_PWT                0x00000008      // Page directory caching write through
-#define CR3_PCD                0x00000010      // Page directory caching disabled
-
-#define CR4_VME                0x00000001      // V86 Mode Extensions
-#define CR4_PVI                0x00000002      // Protected-Mode Virtual Interrupts
-#define CR4_TSD                0x00000004      // Time Stamp Disable
-#define CR4_DE         0x00000008      // Debugging Extensions
-#define CR4_PSE                0x00000010      // Page Size Extensions
-#define CR4_PAE                0x00000020      // Physical Address Extensions
-#define CR4_MCE                0x00000040      // Machine Check Enable
-#define CR4_PGE                0x00000080      // Global Pages Enabled
-#define CR4_PCE                0x00000100      // Performance counter enable
-#define CR4_OSFXSR     0x00000200      // OS support for FXSAVE/FXRSTOR
-#define CR4_OSXMME     0x00000400      // OS support for unmasked SIMD FP exceptions
-#define CR4_VMXE       0x00002000      // VMX enable
-#define CR4_SMXE       0x00004000      // SMX enable
-#define CR4_OSXSAVE    0x00040000      // XSAVE and processor extended states-enabled
-
-// Eflags register
-#define FL_CF          0x00000001      // Carry Flag
-#define FL_PF          0x00000004      // Parity Flag
-#define FL_AF          0x00000010      // Auxiliary carry Flag
-#define FL_ZF          0x00000040      // Zero Flag
-#define FL_SF          0x00000080      // Sign Flag
-#define FL_TF          0x00000100      // Trap Flag
-#define FL_IF          0x00000200      // Interrupt Flag
-#define FL_DF          0x00000400      // Direction Flag
-#define FL_OF          0x00000800      // Overflow Flag
-#define FL_IOPL_MASK   0x00003000      // I/O Privilege Level bitmask
-#define FL_IOPL_0      0x00000000      //   IOPL == 0
-#define FL_IOPL_1      0x00001000      //   IOPL == 1
-#define FL_IOPL_2      0x00002000      //   IOPL == 2
-#define FL_IOPL_3      0x00003000      //   IOPL == 3
-#define FL_NT          0x00004000      // Nested Task
-#define FL_RF          0x00010000      // Resume Flag
-#define FL_VM          0x00020000      // Virtual 8086 mode
-#define FL_AC          0x00040000      // Alignment Check
-#define FL_VIF         0x00080000      // Virtual Interrupt Flag
-#define FL_VIP         0x00100000      // Virtual Interrupt Pending
-#define FL_ID          0x00200000      // ID flag
-
-// Page fault error codes
-#define FEC_PR         0x1     // Page fault caused by protection violation
-#define FEC_WR         0x2     // Page fault caused by a write
-#define FEC_U          0x4     // Page fault occured while in user mode
-
-
-/*
- *
- *     Part 2.  Segmentation data structures and constants.
- *
- */
-
-#ifdef __ASSEMBLER__
-
-/*
- * Macros to build GDT entries in assembly.
- */
-#define SEG_NULL                                               \
-       .word 0, 0;                                             \
-       .byte 0, 0, 0, 0
-#define SEG(type,base,lim)                                     \
-       .word (((lim) >> 12) & 0xffff), ((base) & 0xffff);      \
-       .byte (((base) >> 16) & 0xff), (0x90 | (type)),         \
-               (0xC0 | (((lim) >> 28) & 0xf)), (((base) >> 24) & 0xff)
-
-#else  // not __ASSEMBLER__
-
-#include <inc/types.h>
-
-// Segment Descriptors
-typedef struct Segdesc {
-       unsigned sd_lim_15_0 : 16;  // Low bits of segment limit
-       unsigned sd_base_15_0 : 16; // Low bits of segment base address
-       unsigned sd_base_23_16 : 8; // Middle bits of segment base address
-       unsigned sd_type : 4;       // Segment type (see STS_ constants)
-       unsigned sd_s : 1;          // 0 = system, 1 = application
-       unsigned sd_dpl : 2;        // Descriptor Privilege Level
-       unsigned sd_p : 1;          // Present
-       unsigned sd_lim_19_16 : 4;  // High bits of segment limit
-       unsigned sd_avl : 1;        // Unused (available for software use)
-       unsigned sd_rsv1 : 1;       // Reserved
-       unsigned sd_db : 1;         // 0 = 16-bit segment, 1 = 32-bit segment
-       unsigned sd_g : 1;          // Granularity: limit scaled by 4K when set
-       unsigned sd_base_31_24 : 8; // High bits of segment base address
-} segdesc_t;
-// Null segment
-#define SEG_NULL       (segdesc_t){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-// Segment that is loadable but faults when used
-#define SEG_FAULT      (segdesc_t){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
-// Normal segment
-#define SEG(type, base, lim, dpl) (segdesc_t)                                          \
-{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff,      \
-    type, 1, dpl, 1, (unsigned) (lim) >> 28, 0, 0, 1, 1,                       \
-    (unsigned) (base) >> 24 }
-#define SEG16(type, base, lim, dpl) (segdesc_t)                                                \
-{ (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff,                      \
-    type, 1, dpl, 1, (unsigned) (lim) >> 16, 0, 0, 1, 0,                       \
-    (unsigned) (base) >> 24 }
-
-#endif /* !__ASSEMBLER__ */
-
-// Application segment type bits
-#define STA_X          0x8         // Executable segment
-#define STA_E          0x4         // Expand down (non-executable segments)
-#define STA_C          0x4         // Conforming code segment (executable only)
-#define STA_W          0x2         // Writeable (non-executable segments)
-#define STA_R          0x2         // Readable (executable segments)
-#define STA_A          0x1         // Accessed
-
-// System segment type bits
-#define STS_T16A       0x1         // Available 16-bit TSS
-#define STS_LDT                0x2         // Local Descriptor Table
-#define STS_T16B       0x3         // Busy 16-bit TSS
-#define STS_CG16       0x4         // 16-bit Call Gate
-#define STS_TG         0x5         // Task Gate / Coum Transmitions
-#define STS_IG16       0x6         // 16-bit Interrupt Gate
-#define STS_TG16       0x7         // 16-bit Trap Gate
-#define STS_T32A       0x9         // Available 32-bit TSS
-#define STS_T32B       0xB         // Busy 32-bit TSS
-#define STS_CG32       0xC         // 32-bit Call Gate
-#define STS_IG32       0xE         // 32-bit Interrupt Gate
-#define STS_TG32       0xF         // 32-bit Trap Gate
-
-#define SEG_COUNT      6               // Number of segments in the steady state
-
-/*
- *
- *     Part 3.  Traps.
- *
- */
-
-#ifndef __ASSEMBLER__
-
-// Task state segment format (as described by the Pentium architecture book)
-typedef struct Taskstate {
-       uint32_t ts_link;       // Old ts selector
-       uintptr_t ts_esp0;      // Stack pointers and segment selectors
-       uint16_t ts_ss0;        //   after an increase in privilege level
-       uint16_t ts_padding1;
-       uintptr_t ts_esp1;
-       uint16_t ts_ss1;
-       uint16_t ts_padding2;
-       uintptr_t ts_esp2;
-       uint16_t ts_ss2;
-       uint16_t ts_padding3;
-       physaddr_t ts_cr3;      // Page directory base
-       uintptr_t ts_eip;       // Saved state from last task switch
-       uint32_t ts_eflags;
-       uint32_t ts_eax;        // More saved state (registers)
-       uint32_t ts_ecx;
-       uint32_t ts_edx;
-       uint32_t ts_ebx;
-       uintptr_t ts_esp;
-       uintptr_t ts_ebp;
-       uint32_t ts_esi;
-       uint32_t ts_edi;
-       uint16_t ts_es;         // Even more saved state (segment selectors)
-       uint16_t ts_padding4;
-       uint16_t ts_cs;
-       uint16_t ts_padding5;
-       uint16_t ts_ss;
-       uint16_t ts_padding6;
-       uint16_t ts_ds;
-       uint16_t ts_padding7;
-       uint16_t ts_fs;
-       uint16_t ts_padding8;
-       uint16_t ts_gs;
-       uint16_t ts_padding9;
-       uint16_t ts_ldt;
-       uint16_t ts_padding10;
-       uint16_t ts_t;          // Trap on task switch
-       uint16_t ts_iomb;       // I/O map base address
-} taskstate_t;
-
-// Gate descriptors for interrupts and traps
-typedef struct Gatedesc {
-       unsigned gd_off_15_0 : 16;   // low 16 bits of offset in segment
-       unsigned gd_ss : 16;         // segment selector
-       unsigned gd_args : 5;        // # args, 0 for interrupt/trap gates
-       unsigned gd_rsv1 : 3;        // reserved(should be zero I guess)
-       unsigned gd_type : 4;        // type(STS_{TG,IG32,TG32})
-       unsigned gd_s : 1;           // must be 0 (system)
-       unsigned gd_dpl : 2;         // DPL - highest ring allowed to use this
-       unsigned gd_p : 1;           // Present
-       unsigned gd_off_31_16 : 16;  // high bits of offset in segment
-} gatedesc_t;
-
-// Set up a normal interrupt/trap gate descriptor.
-// - istrap: 1 for a trap (= exception) gate, 0 for an interrupt gate.
-// - sel: Code segment selector for interrupt/trap handler
-// - off: Offset in code segment for interrupt/trap handler
-// - dpl: Descriptor Privilege Level -
-//       the privilege level required for software to invoke
-//       this interrupt/trap gate explicitly using an int instruction.
-#define SETGATE(gate, istrap, sel, off, dpl)                   \
-{                                                              \
-       (gate).gd_off_15_0 = (uint32_t) (off) & 0xffff;         \
-       (gate).gd_ss = (sel);                                   \
-       (gate).gd_args = 0;                                     \
-       (gate).gd_rsv1 = 0;                                     \
-       (gate).gd_type = (istrap) ? STS_TG32 : STS_IG32;        \
-       (gate).gd_s = 0;                                        \
-       (gate).gd_dpl = (dpl);                                  \
-       (gate).gd_p = 1;                                        \
-       (gate).gd_off_31_16 = (uint32_t) (off) >> 16;           \
-}
-
-// Set up a call gate descriptor.
-#define SETCALLGATE(gate, ss, off, dpl)                        \
-{                                                              \
-       (gate).gd_off_15_0 = (uint32_t) (off) & 0xffff;         \
-       (gate).gd_ss = (ss);                                    \
-       (gate).gd_args = 0;                                     \
-       (gate).gd_rsv1 = 0;                                     \
-       (gate).gd_type = STS_CG32;                              \
-       (gate).gd_s = 0;                                        \
-       (gate).gd_dpl = (dpl);                                  \
-       (gate).gd_p = 1;                                        \
-       (gate).gd_off_31_16 = (uint32_t) (off) >> 16;           \
-}
-
-// Pseudo-descriptors used for LGDT, LLDT and LIDT instructions.
-typedef struct Pseudodesc {
-       uint16_t pd_lim;                // Limit
-       uint32_t pd_base;               // Base address
-} __attribute__ ((packed)) pseudodesc_t;
-
-#endif /* !__ASSEMBLER__ */
-
-#endif /* !ROS_INC_MMU_H */
diff --git a/inc/multiboot.h b/inc/multiboot.h
deleted file mode 100644 (file)
index b32982a..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-     /* multiboot.h - the header for Multiboot */
-     /* Copyright (C) 1999, 2001  Free Software Foundation, Inc.
-     
-        This program is free software; you can redistribute it and/or modify
-        it under the terms of the GNU General Public License as published by
-        the Free Software Foundation; either version 2 of the License, or
-        (at your option) any later version.
-     
-        This program is distributed in the hope that it will be useful,
-        but WITHOUT ANY WARRANTY; without even the implied warranty of
-        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-        GNU General Public License for more details.
-     
-        You should have received a copy of the GNU General Public License
-        along with this program; if not, write to the Free Software
-        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-     
-     /* Macros. */
-     
-     /* The magic number for the Multiboot header. */
-     #define MULTIBOOT_HEADER_MAGIC          0x1BADB002
-     
-     /* The flags for the Multiboot header. */
-     #ifdef __ELF__
-     # define MULTIBOOT_HEADER_FLAGS         0x00000003
-     #else
-     # define MULTIBOOT_HEADER_FLAGS         0x00010003
-     #endif
-     
-     /* The magic number passed by a Multiboot-compliant boot loader. */
-     #define MULTIBOOT_BOOTLOADER_MAGIC      0x2BADB002
-     
-     /* The size of our stack (16KB). */
-     #define STACK_SIZE                      0x4000
-     
-     /* C symbol format. HAVE_ASM_USCORE is defined by configure. */
-     #ifdef HAVE_ASM_USCORE
-     # define EXT_C(sym)                     _ ## sym
-     #else
-     # define EXT_C(sym)                     sym
-     #endif
-     
-     #ifndef ASM
-     /* Do not include here in boot.S. */
-     
-     /* Types. */
-     
-     /* The Multiboot header. */
-     typedef struct multiboot_header
-     {
-       unsigned long magic;
-       unsigned long flags;
-       unsigned long checksum;
-       unsigned long header_addr;
-       unsigned long load_addr;
-       unsigned long load_end_addr;
-       unsigned long bss_end_addr;
-       unsigned long entry_addr;
-     } multiboot_header_t;
-     
-     /* The symbol table for a.out. */
-     typedef struct aout_symbol_table
-     {
-       unsigned long tabsize;
-       unsigned long strsize;
-       unsigned long addr;
-       unsigned long reserved;
-     } aout_symbol_table_t;
-     
-     /* The section header table for ELF. */
-     typedef struct elf_section_header_table
-     {
-       unsigned long num;
-       unsigned long size;
-       unsigned long addr;
-       unsigned long shndx;
-     } elf_section_header_table_t;
-     
-     /* The Multiboot information. */
-     typedef struct multiboot_info
-     {
-       unsigned long flags;
-       unsigned long mem_lower;
-       unsigned long mem_upper;
-       unsigned long boot_device;
-       unsigned long cmdline;
-       unsigned long mods_count;
-       unsigned long mods_addr;
-       union
-       {
-         aout_symbol_table_t aout_sym;
-         elf_section_header_table_t elf_sec;
-       } u;
-       unsigned long mmap_length;
-       unsigned long mmap_addr;
-     } multiboot_info_t;
-     
-     /* The module structure. */
-     typedef struct module
-     {
-       unsigned long mod_start;
-       unsigned long mod_end;
-       unsigned long string;
-       unsigned long reserved;
-     } module_t;
-     
-     /* The memory map. Be careful that the offset 0 is base_addr_low
-        but no size. */
-     typedef struct memory_map
-     {
-       unsigned long size;
-       unsigned long base_addr_low;
-       unsigned long base_addr_high;
-       unsigned long length_low;
-       unsigned long length_high;
-       unsigned long type;
-     } memory_map_t;
-     
-     #endif /* ! ASM */
diff --git a/inc/null.h b/inc/null.h
deleted file mode 100644 (file)
index 0665096..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef ROS_INC_NULL_H
-#define ROS_INC_NULL_H
-
-void null();
-error_t null_async(async_desc_t** desc);
-void cache_buster(uint32_t num_writes, uint32_t val);
-error_t cache_buster_async(async_desc_t** desc, uint32_t num_writes,
-                           uint32_t val);
-
-#endif // ROS_INC_NULL_H
diff --git a/inc/pool.h b/inc/pool.h
deleted file mode 100644 (file)
index 7852c5a..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-/* Kevin Klues <klueska@cs.berkeley.edu>       */
-
-#ifndef ROS_INC_POOL_H
-#define ROS_INC_POOL_H
-
-#include <inc/string.h>
-
-#define POOL_TYPE_DEFINE(_type, p, sz)                                                \
-typedef struct struct_##p {                                                             \
-       uint32_t size;                                                         \
-       uint32_t free;                                                         \
-       uint32_t index;                                                        \
-       _type* queue[(sz)];                                                       \
-       _type pool[(sz)];                                                         \
-} p##_t;
-
-#define POOL_INIT(p, sz)                                                       \
-({                                                                             \
-       (p)->size = (sz);                                                          \
-       (p)->free = (sz);                                                          \
-       (p)->index = 0;                                                            \
-       memset((p)->pool, 0, (sz) * sizeof((p)->pool[0]));                         \
-       for(int i=0; i<(p)->size; i++) {                                           \
-               (p)->queue[i] = &((p)->pool[i]);                                       \
-       }                                                                          \
-})
-// removed unnecessary (p)->queue[(p)->index] = NULL;
-#define POOL_GET(p)                                            \
-({                                                             \
-       void* rval = NULL;                                         \
-       if((p)->free) {                                            \
-               rval = (p)->queue[(p)->index];                         \
-               (p)->free--;                                           \
-               (p)->index++;                                          \
-               if((p)->index == (p)->size) {                          \
-               (p)->index = 0;                                    \
-       }                                                      \
-       }                                                          \
-       rval;                                                      \
-})
-
-// emptyIndex is also the first element that has been allocated, iterate thru to index-1
-
-#define POOL_FOR_EACH(p, func)                                                                 \
-({                                                                                                                             \
-       int emptyIndex = ((p)->index + (p)->free);                  \
-       if (emptyIndex >= (p)->size) {                                          \
-               emptyIndex -= (p)->size;                                        \
-       }                                                                   \
-       for(int _i = emptyIndex;  _i < (p)->index; _i++){                       \
-               func((p)->queue[_i]);                                                           \
-       }                                                                                                                       \
-})                                                                                                                             \
-
-#define POOL_PUT(p, val)                                                       \
-({                                                                             \
-       int rval = -1;                                                            \
-       if((p)->free < (p)->size) {                                           \
-               int emptyIndex = ((p)->index + (p)->free);                     \
-               if (emptyIndex >= (p)->size) {                                 \
-                       emptyIndex -= (p)->size;                               \
-               }                                                              \
-               (p)->queue[emptyIndex] = val;                                  \
-               (p)->free++;                                                   \
-               rval = 1;                                                             \
-       }                                                                      \
-       rval;                                                                 \
-})
-
-#define POOL_EMPTY(p) ((p)->free == 0)
-#define POOL_SIZE(p) ((p)->free)
-#define POOL_MAX_SIZE(p) ((p)->size)
-
-#endif //ROS_INC_POOL_H
diff --git a/inc/queue.h b/inc/queue.h
deleted file mode 100644 (file)
index 1102ed4..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright (c) 1991, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     @(#)queue.h     8.3 (Berkeley) 12/13/93
- *
- * For Jos, extra comments have been added to this file, and the original
- * TAILQ and CIRCLEQ definitions have been removed.   - August 9, 2005
- */
-
-#ifndef ROS_INC_QUEUE_H
-#define ROS_INC_QUEUE_H
-
-/*
- * A list is headed by a single forward pointer (or an array of forward
- * pointers for a hash table header). The elements are doubly linked
- * so that an arbitrary element can be removed without a need to
- * traverse the list. New elements can be added to the list before
- * or after an existing element or at the head of the list. A list
- * may only be traversed in the forward direction.
- */
-
-/*
- * An example using the below functions.
- */
-#if 0
-
-typedef struct Frob
-{
-       int frobozz;
-       LIST_ENTRY(frob_t) frob_link;   /* this contains the list element pointers */
-} frob_t;
-
-LIST_HEAD(frob_list_t, frob_t)         /* defines struct Frob_list as a list of Frob */
-
-frob_list_t flist;                     /* declare a Frob list */
-
-LIST_INIT(&flist);                     /* clear flist (globals are cleared anyway) */
-flist = LIST_HEAD_INITIALIZER(&flist); /* alternate way to clear flist */
-
-if(LIST_EMPTY(&flist))                 /* check whether list is empty */
-       printf("list is empty\n");
-
-frob_t *f = LIST_FIRST(&flist);        /* f is first element in list */
-f = LIST_NEXT(f, frob_link);           /* now f is next (second) element in list */
-f = LIST_NEXT(f, frob_link);           /* now f is next (third) element in list */
-
-for(f=LIST_FIRST(&flist); f != 0;      /* iterate over elements in flist */
-    f = LIST_NEXT(f, frob_link))
-       printf("f %d\n", f->frobozz);
-
-LIST_FOREACH(f, &flist, frob_link)     /* alternate way to say that */
-       printf("f %d\n", f->frobozz);
-
-f = LIST_NEXT(LIST_FIRST(&flist));     /* f is second element in list */
-LIST_INSERT_AFTER(f, g, frob_link);    /* add g right after f in list */
-LIST_REMOVE(g, frob_link);             /* remove g from list (can't insert twice!) */
-LIST_INSERT_BEFORE(f, g, frob_link);   /* add g right before f */
-LIST_REMOVE(g, frob_link);             /* remove g again */
-LIST_INSERT_HEAD(&flist, g, frob_link);        /* add g as first element in list */
-
-#endif
-
-/*
- * List declarations.
- */
-
-/*
- * A list is headed by a structure defined by the LIST_HEAD macro.  This structure con‐
- * tains a single pointer to the first element on the list.  The elements are doubly
- * linked so that an arbitrary element can be removed without traversing the list.  New
- * elements can be added to the list after an existing element or at the head of the list.
- * A LIST_HEAD structure is declared as follows:
- * 
- *       LIST_HEAD(HEADNAME, TYPE) head;
- * 
- * where HEADNAME is the name of the structure to be defined, and TYPE is the type of the
- * elements to be linked into the list.  A pointer to the head of the list can later be
- * declared as:
- * 
- *       HEADNAME *headp;
- * 
- * (The names head and headp are user selectable.)
- */
-#define        LIST_HEAD(name, type)                                   \
-typedef struct {                                                               \
-       type *lh_first; /* first element */                     \
-       type *lh_last;  /* last element */                      \
-} name;
-
-/*
- * Set a list head variable to LIST_HEAD_INITIALIZER(head)
- * to reset it to the empty list.
- */
-#define        LIST_HEAD_INITIALIZER(head)                                     \
-       { NULL, NULL }
-
-/*
- * Use this inside a structure "LIST_ENTRY(type) field" to use
- * x as the list piece.
- *
- * The le_prev points at the pointer to the structure containing
- * this very LIST_ENTRY, so that if we want to remove this list entry,
- * we can do *le_prev = le_next to update the structure pointing at us.
- */
-#define        LIST_ENTRY(type)                                                \
-struct {                                                               \
-       type *le_next;  /* next element */                      \
-       type **le_prev; /* ptr to ptr to this element */        \
-}
-
-/*
- * List functions.
- */
-
-/*
- * Is the list named "head" empty?
- */
-#define        LIST_EMPTY(head)        ((head)->lh_first == NULL)
-
-/*
- * Return the first element in the list named "head".
- */
-#define        LIST_FIRST(head)        ((head)->lh_first)
-
-/*
- * Return the last element in the list named "head".
- */
-#define        LIST_LAST(head) ((head)->lh_last)
-
-/*
- * Return the element after "elm" in the list.
- * The "field" name is the link element as above.
- */
-#define        LIST_NEXT(elm, field)   ((elm)->field.le_next)
-
-/*
- * Iterate over the elements in the list named "head".
- * During the loop, assign the list elements to the variable "var"
- * and use the LIST_ENTRY structure member "field" as the link field.
- */
-#define        LIST_FOREACH(var, head, field)                                  \
-       for ((var) = LIST_FIRST((head));                                \
-           (var);                                                      \
-           (var) = LIST_NEXT((var), field))
-
-/*
- * Reset the list named "head" to the empty list.
- */
-#define        LIST_INIT(head) do {                                            \
-       LIST_FIRST((head)) = NULL;                                      \
-       LIST_LAST((head)) = NULL;                                       \
-} while (0)
-
-/*
- * TODO : DON'T USE THIS because of tail pointer issues
- * Insert the element "elm" *after* the element "listelm" which is
- * already in the list.  The "field" name is the link element
- * as above.
-#define        LIST_INSERT_AFTER(listelm, elm, field) do {                     \
-       if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
-               LIST_NEXT((listelm), field)->field.le_prev =            \
-                   &LIST_NEXT((elm), field);                           \
-       LIST_NEXT((listelm), field) = (elm);                            \
-       (elm)->field.le_prev = &LIST_NEXT((listelm), field);            \
-} while (0)
- */
-
-/*
- * TODO : DON'T USE THIS because of tail pointer issues
- * Insert the element "elm" *after* the element "listelm" which is
- * Insert the element "elm" *before* the element "listelm" which is
- * already in the list.  The "field" name is the link element
- * as above.
-#define        LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
-       (elm)->field.le_prev = (listelm)->field.le_prev;                \
-       LIST_NEXT((elm), field) = (listelm);                            \
-       *(listelm)->field.le_prev = (elm);                              \
-       (listelm)->field.le_prev = &LIST_NEXT((elm), field);            \
-} while (0)
- */
-
-/*
- * Insert the element "elm" at the head of the list named "head".
- * The "field" name is the link element as above.
- */
-#define        LIST_INSERT_HEAD(head, elm, field) do {                         \
-       if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)     \
-               LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
-       else                                                       \
-               LIST_LAST((head)) = (elm);                                      \
-       LIST_FIRST((head)) = (elm);                                     \
-       (elm)->field.le_prev = &LIST_FIRST((head));                     \
-} while (0)
-
-/*
- * TODO : DO NOT USE THIS AFTER YOU'VE REMOVED AN ITEM!!
- * Insert the element "elm" at the tail of the list named "head".
- * The "field" name is the link element as above.
- * (you have been warned) ((sorry))
- */
-#define        LIST_INSERT_TAIL(head, elm, field) do {                                            \
-       if (LIST_EMPTY((head)))                                                    \
-               LIST_INSERT_HEAD((head), (elm), field);                                \
-       else {                                                                     \
-               (elm)->field.le_prev = &(LIST_LAST((head))->field.le_next);            \
-               LIST_LAST((head))->field.le_next = (elm);                              \
-               LIST_LAST((head)) = (elm);                                             \
-               (elm)->field.le_next = NULL;                                           \
-       }                                                                          \
-} while (0)
-
-/*
- * Remove the element "elm" from the list.
- * The "field" name is the link element as above.
- */
-#define        LIST_REMOVE(elm, field) do {                                    \
-       if (LIST_NEXT((elm), field) != NULL)                            \
-               LIST_NEXT((elm), field)->field.le_prev =                \
-                   (elm)->field.le_prev;                               \
-       *(elm)->field.le_prev = LIST_NEXT((elm), field);                \
-} while (0)
-
-#endif /* !_SYS_QUEUE_H_ */
diff --git a/inc/ring_buffer.h b/inc/ring_buffer.h
deleted file mode 100644 (file)
index 619c308..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/******************************************************************************
- * ring.h
- * 
- * Shared producer-consumer ring macros.
- *
- * 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.
- *
- * Tim Deegan and Andrew Warfield November 2004.
- */
-
-#ifndef ROS_INC_RING_BUFFER_H
-#define ROS_INC_RING_BUFFER_H
-
-#include <inc/atomic.h>
-
-#define xen_mb()  mb()
-#define xen_rmb() rmb()
-#define xen_wmb() wmb()
-
-typedef unsigned int RING_IDX;
-
-/* Round a 32-bit unsigned constant down to the nearest power of two. */
-#define __RD2(_x)  (((_x) & 0x00000002) ? 0x2                  : ((_x) & 0x1))
-#define __RD4(_x)  (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2    : __RD2(_x))
-#define __RD8(_x)  (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4    : __RD4(_x))
-#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8    : __RD8(_x))
-#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
-
-/*
- * Calculate size of a shared ring, given the total available space for the
- * ring and indexes (_sz), and the name tag of the request/response structure.
- * A ring contains as many entries as will fit, rounded down to the nearest 
- * power of two (so we can mask with (size-1) to loop around).
- * This tells us how many elements the ring _s can contain, given _sz space.
- */
-#define __RING_SIZE(_s, _sz) \
-    (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
-
-/*
- * Macros to make the correct C datatypes for a new kind of ring.
- * 
- * To make a new ring datatype, you need to have two message structures,
- * let's say request_t, and response_t already defined.
- *
- * In a header where you want the ring datatype declared, you then do:
- *
- *     DEFINE_RING_TYPES(mytag, request_t, response_t);
- *
- * These expand out to give you a set of types, as you can see below.
- * The most important of these are:
- * 
- *     mytag_sring_t      - The shared ring.
- *     mytag_front_ring_t - The 'front' half of the ring.
- *     mytag_back_ring_t  - The 'back' half of the ring.
- *
- * To initialize a ring in your code you need to know the location and size
- * of the shared memory area (PAGE_SIZE, for instance). To initialise
- * the front half:
- *
- *     mytag_front_ring_t front_ring;
- *     SHARED_RING_INIT((mytag_sring_t *)shared_page);
- *     FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
- *
- * Initializing the back follows similarly (note that only the front
- * initializes the shared ring):
- *
- *     mytag_back_ring_t back_ring;
- *     BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
- */
-
-#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t)                     \
-                                                                        \
-/* Shared ring entry */                                                 \
-union __name##_sring_entry {                                            \
-    __req_t req;                                                        \
-    __rsp_t rsp;                                                        \
-};                                                                      \
-                                                                        \
-/* Shared ring page */                                                  \
-struct __name##_sring {                                                 \
-    RING_IDX req_prod, req_event;                                       \
-    RING_IDX rsp_prod, rsp_event;                                       \
-    uint8_t  pad[48];                                                   \
-    union __name##_sring_entry ring[1]; /* variable-length */           \
-};                                                                      \
-                                                                        \
-/* "Front" end's private variables */                                   \
-struct __name##_front_ring {                                            \
-    RING_IDX req_prod_pvt;                                              \
-    RING_IDX rsp_cons;                                                  \
-    unsigned int nr_ents;                                               \
-    struct __name##_sring *sring;                                       \
-};                                                                      \
-                                                                        \
-/* "Back" end's private variables */                                    \
-struct __name##_back_ring {                                             \
-    RING_IDX rsp_prod_pvt;                                              \
-    RING_IDX req_cons;                                                  \
-    unsigned int nr_ents;                                               \
-    struct __name##_sring *sring;                                       \
-};                                                                      \
-                                                                        \
-/* Syntactic sugar */                                                   \
-typedef struct __name##_sring __name##_sring_t;                         \
-typedef struct __name##_front_ring __name##_front_ring_t;               \
-typedef struct __name##_back_ring __name##_back_ring_t
-
-/*
- * Macros for manipulating rings.
- * 
- * FRONT_RING_whatever works on the "front end" of a ring: here 
- * requests are pushed on to the ring and responses taken off it.
- * 
- * BACK_RING_whatever works on the "back end" of a ring: here 
- * requests are taken off the ring and responses put on.
- * 
- * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL. 
- * This is OK in 1-for-1 request-response situations where the 
- * requestor (front end) never has more than RING_SIZE()-1
- * outstanding requests.
- */
-
-/* Initialising empty rings */
-#define SHARED_RING_INIT(_s) do {                                       \
-    (_s)->req_prod  = (_s)->rsp_prod  = 0;                              \
-    (_s)->req_event = (_s)->rsp_event = 1;                              \
-    (void)memset((_s)->pad, 0, sizeof((_s)->pad));                      \
-} while(0)
-
-#define FRONT_RING_INIT(_r, _s, __size) do {                            \
-    (_r)->req_prod_pvt = 0;                                             \
-    (_r)->rsp_cons = 0;                                                 \
-    (_r)->nr_ents = __RING_SIZE(_s, __size);                            \
-    (_r)->sring = (_s);                                                 \
-} while (0)
-
-#define BACK_RING_INIT(_r, _s, __size) do {                             \
-    (_r)->rsp_prod_pvt = 0;                                             \
-    (_r)->req_cons = 0;                                                 \
-    (_r)->nr_ents = __RING_SIZE(_s, __size);                            \
-    (_r)->sring = (_s);                                                 \
-} while (0)
-
-/* Initialize to existing shared indexes -- for recovery */
-#define FRONT_RING_ATTACH(_r, _s, __size) do {                          \
-    (_r)->sring = (_s);                                                 \
-    (_r)->req_prod_pvt = (_s)->req_prod;                                \
-    (_r)->rsp_cons = (_s)->rsp_prod;                                    \
-    (_r)->nr_ents = __RING_SIZE(_s, __size);                            \
-} while (0)
-
-#define BACK_RING_ATTACH(_r, _s, __size) do {                           \
-    (_r)->sring = (_s);                                                 \
-    (_r)->rsp_prod_pvt = (_s)->rsp_prod;                                \
-    (_r)->req_cons = (_s)->req_prod;                                    \
-    (_r)->nr_ents = __RING_SIZE(_s, __size);                            \
-} while (0)
-
-/* How big is this ring? */
-#define RING_SIZE(_r)                                                   \
-    ((_r)->nr_ents)
-
-/* Number of free requests (for use on front side only). */
-#define RING_FREE_REQUESTS(_r)                                          \
-    (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
-
-/* Test if there is an empty slot available on the front ring.
- * (This is only meaningful from the front. )
- */
-#define RING_FULL(_r)                                                   \
-    (RING_FREE_REQUESTS(_r) == 0)
-
-/* Test if there are outstanding messages to be processed on a ring. */
-#define RING_HAS_UNCONSUMED_RESPONSES(_r)                               \
-    ((_r)->sring->rsp_prod - (_r)->rsp_cons)
-
-#ifdef __GNUC__
-#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({                             \
-    unsigned int req = (_r)->sring->req_prod - (_r)->req_cons;          \
-    unsigned int rsp = RING_SIZE(_r) -                                  \
-        ((_r)->req_cons - (_r)->rsp_prod_pvt);                          \
-    req < rsp ? req : rsp;                                              \
-})
-#else
-/* Same as above, but without the nice GCC ({ ... }) syntax. */
-#define RING_HAS_UNCONSUMED_REQUESTS(_r)                                \
-    ((((_r)->sring->req_prod - (_r)->req_cons) <                        \
-      (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ?        \
-     ((_r)->sring->req_prod - (_r)->req_cons) :                         \
-     (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt)))
-#endif
-
-/* Direct access to individual ring elements, by index. */
-#define RING_GET_REQUEST(_r, _idx)                                      \
-    (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
-
-#define RING_GET_RESPONSE(_r, _idx)                                     \
-    (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
-
-/* Loop termination condition: Would the specified index overflow the ring? */
-#define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
-    (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
-
-#define RING_PUSH_REQUESTS(_r) do {                                     \
-    xen_wmb(); /* back sees requests /before/ updated producer index */ \
-    (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \
-} while (0)
-
-#define RING_PUSH_RESPONSES(_r) do {                                    \
-    xen_wmb(); /* front sees resps /before/ updated producer index */   \
-    (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt;                         \
-} while (0)
-
-/*
- * Notification hold-off (req_event and rsp_event):
- * 
- * When queueing requests or responses on a shared ring, it may not always be
- * necessary to notify the remote end. For example, if requests are in flight
- * in a backend, the front may be able to queue further requests without
- * notifying the back (if the back checks for new requests when it queues
- * responses).
- * 
- * When enqueuing requests or responses:
- * 
- *  Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument
- *  is a boolean return value. True indicates that the receiver requires an
- *  asynchronous notification.
- * 
- * After dequeuing requests or responses (before sleeping the connection):
- * 
- *  Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES().
- *  The second argument is a boolean return value. True indicates that there
- *  are pending messages on the ring (i.e., the connection should not be put
- *  to sleep).
- * 
- *  These macros will set the req_event/rsp_event field to trigger a
- *  notification on the very next message that is enqueued. If you want to
- *  create batches of work (i.e., only receive a notification after several
- *  messages have been enqueued) then you will need to create a customised
- *  version of the FINAL_CHECK macro in your own code, which sets the event
- *  field appropriately.
- */
-
-#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do {           \
-    RING_IDX __old = (_r)->sring->req_prod;                             \
-    RING_IDX __new = (_r)->req_prod_pvt;                                \
-    xen_wmb(); /* back sees requests /before/ updated producer index */ \
-    (_r)->sring->req_prod = __new;                                      \
-    xen_mb(); /* back sees new requests /before/ we check req_event */  \
-    (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) <           \
-                 (RING_IDX)(__new - __old));                            \
-} while (0)
-
-#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do {          \
-    RING_IDX __old = (_r)->sring->rsp_prod;                             \
-    RING_IDX __new = (_r)->rsp_prod_pvt;                                \
-    xen_wmb(); /* front sees resps /before/ updated producer index */   \
-    (_r)->sring->rsp_prod = __new;                                      \
-    xen_mb(); /* front sees new resps /before/ we check rsp_event */    \
-    (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) <           \
-                 (RING_IDX)(__new - __old));                            \
-} while (0)
-
-#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do {             \
-    (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r);                   \
-    if (_work_to_do) break;                                             \
-    (_r)->sring->req_event = (_r)->req_cons + 1;                        \
-    xen_mb();                                                           \
-    (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r);                   \
-} while (0)
-
-#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do {            \
-    (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r);                  \
-    if (_work_to_do) break;                                             \
-    (_r)->sring->rsp_event = (_r)->rsp_cons + 1;                        \
-    xen_mb();                                                           \
-    (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r);                  \
-} while (0)
-
-#endif /* ROS_INC_RING_BUFFER_H */
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/inc/stab.h b/inc/stab.h
deleted file mode 100644 (file)
index 413b579..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef ROS_STAB_H
-#define ROS_STAB_H
-#include <inc/types.h>
-
-// <inc/stab.h>
-// STABS debugging info
-
-// The ROS kernel debugger can understand some debugging information
-// in the STABS format.  For more information on this format, see
-// http://sources.redhat.com/gdb/onlinedocs/stabs_toc.html
-
-// The constants below define some symbol types used by various debuggers
-// and compilers.  ROS uses the N_SO, N_SOL, N_FUN, and N_SLINE types.
-
-#define        N_GSYM          0x20    // global symbol
-#define        N_FNAME         0x22    // F77 function name
-#define        N_FUN           0x24    // procedure name
-#define        N_STSYM         0x26    // data segment variable
-#define        N_LCSYM         0x28    // bss segment variable
-#define        N_MAIN          0x2a    // main function name
-#define        N_PC            0x30    // global Pascal symbol
-#define        N_RSYM          0x40    // register variable
-#define        N_SLINE         0x44    // text segment line number
-#define        N_DSLINE        0x46    // data segment line number
-#define        N_BSLINE        0x48    // bss segment line number
-#define        N_SSYM          0x60    // structure/union element
-#define        N_SO            0x64    // main source file name
-#define        N_LSYM          0x80    // stack variable
-#define        N_BINCL         0x82    // include file beginning
-#define        N_SOL           0x84    // included source file name
-#define        N_PSYM          0xa0    // parameter variable
-#define        N_EINCL         0xa2    // include file end
-#define        N_ENTRY         0xa4    // alternate entry point
-#define        N_LBRAC         0xc0    // left bracket
-#define        N_EXCL          0xc2    // deleted include file
-#define        N_RBRAC         0xe0    // right bracket
-#define        N_BCOMM         0xe2    // begin common
-#define        N_ECOMM         0xe4    // end common
-#define        N_ECOML         0xe8    // end common (local name)
-#define        N_LENG          0xfe    // length of preceding entry
-
-// Entries in the STABS table are formatted as follows.
-typedef struct Stab {
-       uint32_t n_strx;        // index into string table of name
-       uint8_t n_type;         // type of symbol
-       uint8_t n_other;        // misc info (usually empty)
-       uint16_t n_desc;        // description field
-       uintptr_t n_value;      // value of symbol
-} stab_t;
-
-#endif /* !ROS_STAB_H */
diff --git a/inc/stdarg.h b/inc/stdarg.h
deleted file mode 100644 (file)
index 8548ce6..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*     $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $      */
-
-#ifndef ROS_INC_STDARG_H
-#define        ROS_INC_STDARG_H
-
-typedef void * TRUSTED va_list;
-
-#define        __va_size(type) \
-       (((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long))
-
-#define        va_start(ap, last) \
-       ((ap) = (va_list)&(last) + __va_size(last))
-
-#define        va_arg(ap, type) \
-       (*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
-
-#define        va_end(ap)      ((void)0)
-
-#endif /* !ROS_INC_STDARG_H */
diff --git a/inc/stdio.h b/inc/stdio.h
deleted file mode 100644 (file)
index 2f6b4c1..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef ROS_INC_STDIO_H
-#define ROS_INC_STDIO_H
-
-#include <inc/stdarg.h>
-
-#ifndef NULL
-#define NULL   ((void *) 0)
-#endif /* !NULL */
-
-#ifdef DEBUG
-#define printd(args...) cprintf(args)
-#else
-#define printd(args...) {}
-#endif
-
-#define printk(args...) cprintf(args)
-
-// lib/stdio.c
-void   cputchar(int c);
-int    getchar(void);
-int    iscons(int fd);
-
-// lib/printfmt.c
-void   printfmt(void (*putch)(int, void**), void **putdat, const char *NTS fmt, ...);
-//void vprintfmt(void (*putch)(int, TV(t)), TV(t) putdat, const char *NTS fmt, va_list);
-void   vprintfmt(void (*putch)(int, void**), void **putdat, const char *NTS fmt, va_list);
-
-// lib/printf.c
-int    cprintf(const char * NTS fmt, ...);
-int    vcprintf(const char * NTS fmt, va_list);
-
-// lib/sprintf.c
-int    snprintf(char *str, int size, const char *fmt, ...);
-int    vsnprintf(char *COUNT(size) str, int size, const char *fmt, va_list);
-
-// lib/fprintf.c
-int    printf(const char *fmt, ...);
-int    fprintf(int fd, const char *fmt, ...);
-int    vfprintf(int fd, const char *fmt, va_list);
-
-// lib/readline.c
-char *NTS readline(const char *NTS prompt);
-
-/* USERSPACE ONLY */
-#ifndef ROS_KERNEL
-
-#include <inc/lib.h>
-
-int    cprintf_async(async_desc_t** desc, const char * NTS fmt, ...);
-
-#endif /* USERSPACE ONLY */
-
-#endif /* !ROS_INC_STDIO_H */
diff --git a/inc/string.h b/inc/string.h
deleted file mode 100644 (file)
index 615a2b1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef ROS_INC_STRING_H
-#define ROS_INC_STRING_H
-
-#include <inc/types.h>
-
-int    strlen(const char *s);
-int    strnlen(const char *s, size_t size);
-char * strcpy(char *dst, const char *src);
-char * strncpy(char *dst, const char *src, size_t size);
-size_t strlcpy(char *dst, const char *src, size_t size);
-int    strcmp(const char *s1, const char *s2);
-int    strncmp(const char *s1, const char *s2, size_t size);
-char * strchr(const char *s, char c);
-char * strfind(const char *s, char c);
-
-void * memset(void *dst, int c, size_t len);
-void * memcpy(void *dst, const void *src, size_t len);
-void * memmove(void *dst, const void *src, size_t len);
-int    memcmp(const void *s1, const void *s2, size_t len);
-void * memfind(const void *s, int c, size_t len);
-
-long   strtol(const char *s, char **endptr, int base);
-
-#endif /* not ROS_INC_STRING_H */
diff --git a/inc/syscall.h b/inc/syscall.h
deleted file mode 100644 (file)
index 9a62440..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef ROS_INC_SYSCALL_H
-#define ROS_INC_SYSCALL_H
-
-#include <inc/types.h>
-#include <inc/ring_buffer.h>
-#include <inc/queue.h>
-
-/* system call numbers */
-enum
-{
-       SYS_null = 1,
-       SYS_cache_buster,
-       SYS_cputs,
-       SYS_cgetc,
-       SYS_getenvid,
-       SYS_env_destroy,
-};
-#define NSYSCALLS (SYS_env_destroy)
-// syscall number starts at 1 and goes up to NSYSCALLS, without holes.
-#define INVALID_SYSCALL(syscallno) ((syscallno) > NSYSCALLS)
-
-#define NUM_SYS_ARGS 6
-typedef struct syscall_req {
-       uint32_t num;
-       uint32_t flags;
-       uint32_t args[NUM_SYS_ARGS];
-} syscall_req_t;
-
-typedef struct syscall_rsp {
-       int32_t retval;
-} syscall_rsp_t;
-
-// Generic Syscall Ring Buffer
-DEFINE_RING_TYPES(syscall, syscall_req_t, syscall_rsp_t);
-
-typedef struct syscall_desc syscall_desc_t;
-struct syscall_desc {
-       LIST_ENTRY(syscall_desc_t) next;
-       syscall_front_ring_t* sysfr;
-       uint32_t idx;
-       // cleanup
-       void (*cleanup)(void* data);
-       void* data;
-};
-LIST_HEAD(syscall_desc_list_t, syscall_desc_t);
-
-static uint32_t
-syscall_sysenter(int num, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5);
-
-#endif /* !ROS_INC_SYSCALL_H */
diff --git a/inc/timer.h b/inc/timer.h
deleted file mode 100644 (file)
index 305a2aa..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef ROS_INC_TIMER_H
-#define ROS_INC_TIMER_H
-#include <inc/pool.h>
-#include <inc/string.h>
-
-#define TIMER_TAG_SIZE 20
-#define MAX_TIMERS 20
-
-/* start_timing()
- * This function simply reads the tsc in a serialized fashion and returns its
- * value.  It is pusposefully annotated with a noinline so that the overheads 
- * assocaited with calling it are as deterministic as possible.
- */
-uint64_t start_timing() __attribute__((noinline));
-
-/* stop_timing()
- * This function reads the tsc in a serialized fashion and subtracts the value
- * it reads from the value passed in as a paramter in order to determine the 
- * difference between the two values.  A global timing_overhead value is also 
- * subtracted to compensate for the overhead associated with calling both
- * start and stop timing and returning their values.
- * This function is purposefully annotated with a noinline so that 
- * the overheads assocaited with calling it are as deterministic as possible.
- */
-uint64_t stop_timing(uint64_t val) __attribute__((noinline));
-
-/* train_timing()
- * This function is intended to train the timing_overhead variable for use by
- * stop_timing().  It runs through a loop calling start/stop and averaging the 
- * overhead of calling them without doing any useful work in between.
- */
-void train_timing();
-
-/* timer_t
- * This struct is used to keep track of counter values as they are spread
- * throughput code and timing measurements are made calling TAGGED_TIMING_BEGIN
- * and TAGGED_TIMING_END
- */
-typedef struct Timer{
-       uint64_t curr_run;
-       uint64_t aggr_run;
-       char label[TIMER_TAG_SIZE];
-} timer_t;
-
-//TODO: ifdef measurement? error check when pool runs low
-#define TAGGED_TIMING_BEGIN(tag)                    \
-       static timer_t* _timer_##tag = NULL;            \
-       if (_timer_##tag == NULL) {                     \
-               _timer_##tag = POOL_GET(&timer_pool);       \
-               strcpy((_timer_##tag->label), #tag);        \
-               _timer_##tag->aggr_run = 0;                 \
-       }                                               \
-       _timer_##tag->curr_run = start_timing();
-#define TAGGED_TIMING_END(tag)                                              \
-({                                                                          \
-       _timer_##tag->curr_run = stop_timing(_timer_##tag->curr_run);           \
-       _timer_##tag->aggr_run += _timer_##tag->curr_run;                       \
-})
-
-#endif /* !ROS_INC_TIMER_H */
-
diff --git a/inc/trap.h b/inc/trap.h
deleted file mode 100644 (file)
index b2d35d7..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef ROS_INC_TRAP_H
-#define ROS_INC_TRAP_H
-
-// Trap numbers
-// These are processor defined:
-#define T_DIVIDE     0         // divide error
-#define T_DEBUG      1         // debug exception
-#define T_NMI        2         // non-maskable interrupt
-#define T_BRKPT      3         // breakpoint
-#define T_OFLOW      4         // overflow
-#define T_BOUND      5         // bounds check
-#define T_ILLOP      6         // illegal opcode
-#define T_DEVICE     7         // device not available 
-#define T_DBLFLT     8         // double fault
-/* #define T_COPROC  9 */      // reserved (not generated by recent processors)
-#define T_TSS       10         // invalid task switch segment
-#define T_SEGNP     11         // segment not present
-#define T_STACK     12         // stack exception
-#define T_GPFLT     13         // genernal protection fault
-#define T_PGFLT     14         // page fault
-/* #define T_RES    15 */      // reserved
-#define T_FPERR     16         // floating point error
-#define T_ALIGN     17         // aligment check
-#define T_MCHK      18         // machine check
-#define T_SIMDERR   19         // SIMD floating point error
-
-// These are arbitrarily chosen, but with care not to overlap
-// processor defined exceptions or interrupt vectors.
-#define T_SYSCALL   0x80                       // system call
-#define T_DEFAULT   0xdeadbeef         // catchall
-
-#ifndef __ASSEMBLER__
-
-#include <inc/types.h>
-
-typedef struct PushRegs {
-       /* registers as pushed by pusha */
-       uint32_t reg_edi;
-       uint32_t reg_esi;
-       uint32_t reg_ebp;
-       uint32_t reg_oesp;              /* Useless */
-       uint32_t reg_ebx;
-       uint32_t reg_edx;
-       uint32_t reg_ecx;
-       uint32_t reg_eax;
-} push_regs_t;
-
-typedef struct Trapframe {
-       push_regs_t tf_regs;
-       uint16_t tf_es;
-       uint16_t tf_padding1;
-       uint16_t tf_ds;
-       uint16_t tf_padding2;
-       uint32_t tf_trapno;
-       /* below here defined by x86 hardware */
-       uint32_t tf_err;
-       uintptr_t tf_eip;
-       uint16_t tf_cs;
-       uint16_t tf_padding3;
-       uint32_t tf_eflags;
-       /* below here only when crossing rings, such as from user to kernel */
-       uintptr_t tf_esp;
-       uint16_t tf_ss;
-       uint16_t tf_padding4;
-} trapframe_t;
-
-
-#endif /* !__ASSEMBLER__ */
-
-// Must equal 'sizeof(trapframe_t)'.
-// A static_assert in kern/trap.c checks this.
-#define SIZEOF_STRUCT_TRAPFRAME        0x44
-
-#endif /* !ROS_INC_TRAP_H */
diff --git a/inc/types.h b/inc/types.h
deleted file mode 100644 (file)
index e40c342..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-#ifndef ROS_INC_TYPES_H
-#define ROS_INC_TYPES_H
-
-#ifndef NULL
-#define NULL ((void*) 0)
-#endif
-
-#ifndef TRUE
-#define TRUE   1
-#endif
-
-#ifndef FALSE
-#define FALSE  0
-#endif
-
-// Represents true-or-false values
-typedef int bool;
-
-// Explicitly-sized versions of integer types
-typedef __signed char int8_t;
-typedef unsigned char uint8_t;
-typedef short int16_t;
-typedef unsigned short uint16_t;
-typedef int int32_t;
-typedef unsigned int uint32_t;
-typedef long long int64_t;
-typedef unsigned long long uint64_t;
-
-// Pointers and addresses are 32 bits long.
-// We use pointer types to represent virtual addresses,
-// uintptr_t to represent the numerical values of virtual addresses,
-// and physaddr_t to represent physical addresses.
-typedef int32_t intptr_t;
-typedef uint32_t uintptr_t;
-typedef uint32_t physaddr_t;
-
-// Page numbers are 32 bits long.
-typedef uint32_t ppn_t;
-
-// size_t is used for memory object sizes.
-typedef uint32_t size_t;
-// ssize_t is a signed version of ssize_t, used in case there might be an
-// error return.
-typedef int32_t ssize_t;
-
-// off_t is used for file offsets and lengths.
-typedef int32_t off_t;
-
-// Efficient min and max operations
-#define MIN(_a, _b)                                            \
-({                                                             \
-       typeof(_a) __a = (_a);                                  \
-       typeof(_b) __b = (_b);                                  \
-       __a <= __b ? __a : __b;                                 \
-})
-#define MAX(_a, _b)                                            \
-({                                                             \
-       typeof(_a) __a = (_a);                                  \
-       typeof(_b) __b = (_b);                                  \
-       __a >= __b ? __a : __b;                                 \
-})
-
-// Rounding operations (efficient when n is a power of 2)
-// Round down to the nearest multiple of n
-#define ROUNDDOWN(a, n)                                                \
-({                                                             \
-       uint32_t __a = (uint32_t) (a);                          \
-       (typeof(a)) (__a - __a % (n));                          \
-})
-// Round up to the nearest multiple of n
-#define ROUNDUP(a, n)                                          \
-({                                                             \
-       uint32_t __n = (uint32_t) (n);                          \
-       (typeof(a)) (ROUNDDOWN((uint32_t) (a) + __n - 1, __n)); \
-})
-
-// Return the offset of 'member' relative to the beginning of a struct type
-#define offsetof(type, member)  ((size_t) (&((type*)0)->member))
-
-// Ivy currently can only handle 63 bits (OCaml thing), so use this to make
-// a uint64_t programatically
-#define UINT64(upper, lower) ( (((uint64_t)(upper)) << 32) | (lower) )
-
-/*********************** Bitmask stuff **********************/
-#define BYTES_FOR_BITMASK(size) (((size) - 1) / 8 + 1)
-#define BYTES_FOR_BITMASK_WITH_CHECK(size) ((size) ? ((size) - (1)) / (8) + (1) : (0))
-#define DECL_BITMASK(name, size) uint8_t (name)[BYTES_FOR_BITMASK((size))]
-
-#define GET_BITMASK_BIT(name, bit) (((name)[(bit)/8] & (1 << ((bit) % 8))) ? 1 : 0)
-// TODO - Need to do these atomically, or provide alternatives
-#define SET_BITMASK_BIT(name, bit) ((name)[(bit)/8] |= (1 << ((bit) % 8)))
-#define CLR_BITMASK_BIT(name, bit) ((name)[(bit)/8] &= ~(1 << ((bit) % 8)))
-#define CLR_BITMASK_BIT_ATOMIC(name, bit) (atomic_andb(&(name)[(bit)/8], ~(1 << ((bit) % 8))))
-
-#define CLR_BITMASK(name, size) (memset((name), 0, BYTES_FOR_BITMASK((size))))
-#define FILL_BITMASK(name, size) ({ \
-       memset((name), 255, BYTES_FOR_BITMASK((size))); \
-       (name)[BYTES_FOR_BITMASK((size))-1] >>= (((size) % 8) ? (8 - ((size) % 8)) : 0 );}) 
-
-#define COPY_BITMASK(newmask, oldmask, size) (memcpy((newmask), (oldmask), BYTES_FOR_BITMASK((size))))
-
-// this checks the entire last byte, so keep it 0 in the other macros
-#define BITMASK_IS_CLEAR(name, size) ({ \
-       uint32_t __n = BYTES_FOR_BITMASK((size)); \
-       bool clear = 1; \
-       while (__n-- > 0) { \
-               if ((name)[__n]) { \
-                       clear = 0; \
-                       break;\
-               }\
-       } \
-       clear; })
-
-#define PRINT_MASK(name, size) { \
-       int i;  \
-       for (i = 0; i < BYTES_FOR_BITMASK(size); i++) { \
-               int j;  \
-               for (j = 0; j < 8; j++) \
-                       printk("%x", ((name)[i] >> j) & 1);     \
-       } \
-       printk("\n"); \
-}
-/**************************************************************/
-
-#endif /* !ROS_INC_TYPES_H */
diff --git a/inc/x86.h b/inc/x86.h
deleted file mode 100644 (file)
index 88e4560..0000000
--- a/inc/x86.h
+++ /dev/null
@@ -1,421 +0,0 @@
-#ifndef ROS_INC_X86_H
-#define ROS_INC_X86_H
-
-#include <inc/types.h>
-#include <inc/mmu.h>
-
-#define CHECK_FLAG(flags,bit)   ((flags) & (1 << (bit)))
-
-/* Model Specific Registers */
-#define IA32_APIC_BASE                         0x1b
-#define IA32_MTRR_DEF_TYPE                     0x2ff
-#define IA32_MTRR_PHYSBASE0                    0x200
-#define IA32_MTRR_PHYSMASK0                    0x201
-#define IA32_MTRR_PHYSBASE1                    0x202
-#define IA32_MTRR_PHYSMASK1                    0x203
-#define IA32_MTRR_PHYSBASE2                    0x204
-#define IA32_MTRR_PHYSMASK2                    0x205
-#define IA32_MTRR_PHYSBASE3                    0x206
-#define IA32_MTRR_PHYSMASK3                    0x207
-#define IA32_MTRR_PHYSBASE4                    0x208
-#define IA32_MTRR_PHYSMASK4                    0x209
-#define IA32_MTRR_PHYSBASE5                    0x20a
-#define IA32_MTRR_PHYSMASK5                    0x20b
-#define IA32_MTRR_PHYSBASE6                    0x20c
-#define IA32_MTRR_PHYSMASK6                    0x20d
-#define IA32_MTRR_PHYSBASE7                    0x20e
-#define IA32_MTRR_PHYSMASK7                    0x20f
-
-#define MSR_APIC_ENABLE                                0x00000800
-#define MSR_APIC_BASE_ADDRESS          0x0000000FFFFFF000
-
-/* CPUID */
-#define CPUID_PSE_SUPPORT                      0x00000008
-
-/* Arch Constants */
-#define MAX_NUM_CPUS                           255
-
-static __inline void breakpoint(void) __attribute__((always_inline));
-static __inline uint8_t inb(int port) __attribute__((always_inline));
-static __inline void insb(int port, void *addr, int cnt) __attribute__((always_inline));
-static __inline uint16_t inw(int port) __attribute__((always_inline));
-static __inline void insw(int port, void *addr, int cnt) __attribute__((always_inline));
-static __inline uint32_t inl(int port) __attribute__((always_inline));
-static __inline void insl(int port, void *addr, int cnt) __attribute__((always_inline));
-static __inline void outb(int port, uint8_t data) __attribute__((always_inline));
-static __inline void outsb(int port, const void *addr, int cnt) __attribute__((always_inline));
-static __inline void outw(int port, uint16_t data) __attribute__((always_inline));
-static __inline void outsw(int port, const void *addr, int cnt) __attribute__((always_inline));
-static __inline void outsl(int port, const void *addr, int cnt) __attribute__((always_inline));
-static __inline void outl(int port, uint32_t data) __attribute__((always_inline));
-static __inline void invlpg(void *addr) __attribute__((always_inline));
-static __inline void lidt(void *p) __attribute__((always_inline));
-static __inline void lldt(uint16_t sel) __attribute__((always_inline));
-static __inline void ltr(uint16_t sel) __attribute__((always_inline));
-static __inline void lcr0(uint32_t val) __attribute__((always_inline));
-static __inline uint32_t rcr0(void) __attribute__((always_inline));
-static __inline uint32_t rcr2(void) __attribute__((always_inline));
-static __inline void lcr3(uint32_t val) __attribute__((always_inline));
-static __inline uint32_t rcr3(void) __attribute__((always_inline));
-static __inline void lcr4(uint32_t val) __attribute__((always_inline));
-static __inline uint32_t rcr4(void) __attribute__((always_inline));
-static __inline void tlbflush(void) __attribute__((always_inline));
-static __inline uint32_t read_eflags(void) __attribute__((always_inline));
-static __inline void write_eflags(uint32_t eflags) __attribute__((always_inline));
-static __inline uint32_t read_ebp(void) __attribute__((always_inline));
-static __inline uint32_t read_esp(void) __attribute__((always_inline));
-static __inline void cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *edxp);
-static __inline uint64_t read_tsc(void) __attribute__((always_inline));
-static __inline uint64_t read_tsc_serialized(void) __attribute__((always_inline));
-static __inline uint64_t read_msr(uint32_t reg) __attribute__((always_inline));
-static __inline void write_msr(uint32_t reg, uint64_t val) __attribute__((always_inline));
-static __inline uint32_t read_mmreg32(uint32_t reg) __attribute__((always_inline));
-static __inline void write_mmreg32(uint32_t reg, uint32_t val) __attribute__((always_inline));
-static __inline void enable_irq(void) __attribute__((always_inline));
-static __inline void disable_irq(void) __attribute__((always_inline));
-static __inline void enable_irqsave(int8_t* state) __attribute__((always_inline));
-static __inline void disable_irqsave(int8_t* state) __attribute__((always_inline));
-static __inline void cpu_relax(void) __attribute__((always_inline));
-static __inline void wbinvd(void) __attribute__((always_inline));
-static __inline void clflush(uintptr_t* addr) __attribute__((always_inline));
-
-static __inline void
-breakpoint(void)
-{
-       __asm __volatile("int3");
-}
-
-static __inline uint8_t
-inb(int port)
-{
-       uint8_t data;
-       __asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port));
-       return data;
-}
-
-static __inline void
-insb(int port, void *addr, int cnt)
-{
-       __asm __volatile("cld\n\trepne\n\tinsb"                 :
-                        "=D" (addr), "=c" (cnt)                :
-                        "d" (port), "0" (addr), "1" (cnt)      :
-                        "memory", "cc");
-}
-
-static __inline uint16_t
-inw(int port)
-{
-       uint16_t data;
-       __asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port));
-       return data;
-}
-
-static __inline void
-insw(int port, void *addr, int cnt)
-{
-       __asm __volatile("cld\n\trepne\n\tinsw"                 :
-                        "=D" (addr), "=c" (cnt)                :
-                        "d" (port), "0" (addr), "1" (cnt)      :
-                        "memory", "cc");
-}
-
-static __inline uint32_t
-inl(int port)
-{
-       uint32_t data;
-       __asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port));
-       return data;
-}
-
-static __inline void
-insl(int port, void *addr, int cnt)
-{
-       __asm __volatile("cld\n\trepne\n\tinsl"                 :
-                        "=D" (addr), "=c" (cnt)                :
-                        "d" (port), "0" (addr), "1" (cnt)      :
-                        "memory", "cc");
-}
-
-static __inline void
-outb(int port, uint8_t data)
-{
-       __asm __volatile("outb %0,%w1" : : "a" (data), "d" (port));
-}
-
-static __inline void
-outsb(int port, const void *addr, int cnt)
-{
-       __asm __volatile("cld\n\trepne\n\toutsb"                :
-                        "=S" (addr), "=c" (cnt)                :
-                        "d" (port), "0" (addr), "1" (cnt)      :
-                        "cc");
-}
-
-static __inline void
-outw(int port, uint16_t data)
-{
-       __asm __volatile("outw %0,%w1" : : "a" (data), "d" (port));
-}
-
-static __inline void
-outsw(int port, const void *addr, int cnt)
-{
-       __asm __volatile("cld\n\trepne\n\toutsw"                :
-                        "=S" (addr), "=c" (cnt)                :
-                        "d" (port), "0" (addr), "1" (cnt)      :
-                        "cc");
-}
-
-static __inline void
-outsl(int port, const void *addr, int cnt)
-{
-       __asm __volatile("cld\n\trepne\n\toutsl"                :
-                        "=S" (addr), "=c" (cnt)                :
-                        "d" (port), "0" (addr), "1" (cnt)      :
-                        "cc");
-}
-
-static __inline void
-outl(int port, uint32_t data)
-{
-       __asm __volatile("outl %0,%w1" : : "a" (data), "d" (port));
-}
-
-static __inline void 
-invlpg(void *addr)
-{ 
-       __asm __volatile("invlpg (%0)" : : "r" (addr) : "memory");
-}  
-
-static __inline void
-lidt(void *p)
-{
-       __asm __volatile("lidt (%0)" : : "r" (p));
-}
-
-static __inline void
-lldt(uint16_t sel)
-{
-       __asm __volatile("lldt %0" : : "r" (sel));
-}
-
-static __inline void
-ltr(uint16_t sel)
-{
-       __asm __volatile("ltr %0" : : "r" (sel));
-}
-
-static __inline void
-lcr0(uint32_t val)
-{
-       __asm __volatile("movl %0,%%cr0" : : "r" (val));
-}
-
-static __inline uint32_t
-rcr0(void)
-{
-       uint32_t val;
-       __asm __volatile("movl %%cr0,%0" : "=r" (val));
-       return val;
-}
-
-static __inline uint32_t
-rcr2(void)
-{
-       uint32_t val;
-       __asm __volatile("movl %%cr2,%0" : "=r" (val));
-       return val;
-}
-
-static __inline void
-lcr3(uint32_t val)
-{
-       __asm __volatile("movl %0,%%cr3" : : "r" (val));
-}
-
-static __inline uint32_t
-rcr3(void)
-{
-       uint32_t val;
-       __asm __volatile("movl %%cr3,%0" : "=r" (val));
-       return val;
-}
-
-static __inline void
-lcr4(uint32_t val)
-{
-       __asm __volatile("movl %0,%%cr4" : : "r" (val));
-}
-
-static __inline uint32_t
-rcr4(void)
-{
-       uint32_t cr4;
-       __asm __volatile("movl %%cr4,%0" : "=r" (cr4));
-       return cr4;
-}
-
-static __inline void
-tlbflush(void)
-{
-       uint32_t cr3;
-       __asm __volatile("movl %%cr3,%0" : "=r" (cr3));
-       __asm __volatile("movl %0,%%cr3" : : "r" (cr3));
-}
-
-static __inline uint32_t
-read_eflags(void)
-{
-        uint32_t eflags;
-        __asm __volatile("pushfl; popl %0" : "=r" (eflags));
-        return eflags;
-}
-
-static __inline void
-write_eflags(uint32_t eflags)
-{
-        __asm __volatile("pushl %0; popfl" : : "r" (eflags));
-}
-
-static __inline uint32_t
-read_ebp(void)
-{
-        uint32_t ebp;
-        __asm __volatile("movl %%ebp,%0" : "=r" (ebp));
-        return ebp;
-}
-
-static __inline uint32_t
-read_esp(void)
-{
-        uint32_t esp;
-        __asm __volatile("movl %%esp,%0" : "=r" (esp));
-        return esp;
-}
-
-static __inline void
-cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *edxp)
-{
-       uint32_t eax, ebx, ecx, edx;
-       asm volatile("cpuid" 
-               : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
-               : "a" (info));
-       if (eaxp)
-               *eaxp = eax;
-       if (ebxp)
-               *ebxp = ebx;
-       if (ecxp)
-               *ecxp = ecx;
-       if (edxp)
-               *edxp = edx;
-}
-
-static __inline uint64_t
-read_tsc(void)
-{
-       uint64_t tsc;
-       __asm __volatile("rdtsc" : "=A" (tsc));
-       return tsc;
-}
-
-static __inline uint64_t 
-read_tsc_serialized(void)
-{
-    uint64_t tsc;
-       cpuid(0, 0, 0, 0, 0);
-       tsc = read_tsc();
-       return tsc;
-}
-
-// Might need to mfence rdmsr.  supposedly wrmsr serializes, but not for x2APIC
-static __inline uint64_t
-read_msr(uint32_t reg)
-{
-       uint32_t edx, eax;
-       asm volatile("rdmsr; mfence" : "=d"(edx), "=a"(eax) : "c"(reg));
-       return (uint64_t)edx << 32 | eax;
-}
-
-static __inline void
-write_msr(uint32_t reg, uint64_t val)
-{
-       asm volatile("wrmsr" : : "d"((uint32_t)(val >> 32)),
-                                "a"((uint32_t)(val & 0xFFFFFFFF)), 
-                                "c"(reg));
-}
-
-static __inline void
-write_mmreg32(uint32_t reg, uint32_t val)
-{
-       {TRUSTEDBLOCK *((volatile uint32_t*)reg) = val; }
-       //the C ends up producing better asm than this:
-       //asm volatile("movl %0, (%1)" : : "r"(val), "r"(reg));
-}
-
-static __inline uint32_t
-read_mmreg32(uint32_t reg)
-{
-       {TRUSTEDBLOCK return *((volatile uint32_t*)reg); }
-}
-
-static __inline void
-enable_irq(void)
-{
-       asm volatile("sti");
-}
-
-static __inline void
-disable_irq(void)
-{
-       asm volatile("cli");
-}
-
-static __inline void
-enable_irqsave(int8_t* state)
-{
-       // *state tracks the number of nested enables and disables
-       // initial value of state: 0 = first run / no favorite
-       // > 0 means more enabled calls have been made
-       // < 0 means more disabled calls have been made
-       // Mostly doing this so we can call disable_irqsave first if we want
-
-       // one side or another "gets a point" if interrupts were already the
-       // way it wanted to go.  o/w, state stays at 0.  if the state was not 0
-       // then, enabling/disabling isn't even an option.  just increment/decrement
-
-       // if enabling is winning or tied, make sure it's enabled
-       if ((*state == 0) && (!(read_eflags() & FL_IF)))
-               enable_irq();
-       else
-               (*state)++;
-}
-
-static __inline void
-disable_irqsave(int8_t* state)
-{
-       if ((*state == 0) && (read_eflags() & FL_IF))
-               disable_irq();
-       else 
-               (*state)--;
-}
-
-static __inline void
-cpu_relax(void)
-{
-       // in case the compiler doesn't serialize for pause, the "m" will make sure
-       // no memory is reordered around this instruction.
-       asm volatile("pause" : : : "memory");
-}
-
-static __inline void
-wbinvd(void) __attribute__((always_inline))
-{
-       asm volatile("wbinvd");
-}
-
-static __inline void
-clflush(uintptr_t* addr) __attribute__((always_inline))
-{
-       asm volatile("clflush %0" : : "m"(*addr));
-}
-#endif /* !ROS_INC_X86_H */
diff --git a/ivylib/Makefrag b/ivylib/Makefrag
deleted file mode 100644 (file)
index bbeab02..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-NATIVECC := ivycc
-
-OBJDIRS += ivylib
-
-IVYLIB_KERN_SRCFILES :=                ivylib/deputy_kern.c
-
-IVYLIB_USER_SRCFILES :=                ivylib/deputy_user.c
-
-IVYLIB_KERN_OBJFILES := $(patsubst ivylib/%.c, $(OBJDIR)/ivylib/%.o, $(IVYLIB_KERN_SRCFILES))
-IVYLIB_USER_OBJFILES := $(patsubst ivylib/%.c, $(OBJDIR)/ivylib/%.o, $(IVYLIB_USER_SRCFILES))
-
-
-$(OBJDIR)/ivylib/deputy_kern.o: ivylib/deputy_kern.c
-       @echo + cc[IVYLIB] $<
-       @mkdir -p $(@D)
-       $(NATIVECC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
-
-$(OBJDIR)/ivylib/deputy_user.o: ivylib/deputy_user.c
-       @echo + cc[IVYLIB] $<
-       @mkdir -p $(@D)
-       $(V)$(NATIVECC) -nostdinc $(USER_CFLAGS) -c -o $@ $<
-
-$(OBJDIR)/ivylib/libivykern.a: $(IVYLIB_KERN_OBJFILES)
-       @echo + ar $@
-       $(AR) r $@ $(IVYLIB_KERN_OBJFILES)
-
-$(OBJDIR)/ivylib/libivyuser.a: $(IVYLIB_USER_OBJFILES)
-       @echo + ar $@
-       $(V)$(AR) r $@ $(IVYLIB_USER_OBJFILES)
diff --git a/ivylib/deputy_kern.c b/ivylib/deputy_kern.c
deleted file mode 100644 (file)
index 5596b16..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <inc/stdio.h>
-#include <inc/assert.h>
-#include <inc/string.h>
-
-#define IN_DEPUTY_LIBRARY
-
-// Use inline even when not optimizing for speed, since it prevents
-// warnings that would occur due to unused static functions.
-#ifdef DEPUTY_ALWAYS_STOP_ON_ERROR
-  #define INLINE inline __attribute__((always_inline))
-#else
-  #define INLINE inline
-#endif
-
-#define __LOCATION__        __FILE__, __LINE__, __FUNCTION__
-#define __LOCATION__FORMALS const char* file, int line, const char* func
-#define __LOCATION__ACTUALS file, line, func
-
-#ifndef asmlinkage
-#define asmlinkage __attribute__((regparm(0)))
-#endif
-
-#ifndef noreturn
-#define noreturn __attribute__((noreturn))
-#endif
-
-asmlinkage
-void deputy_fail_mayreturn(const char *check, const char *text,
-                           __LOCATION__FORMALS) {
-    cprintf("%s:%d: %s: Assertion failed in %s: %s\n",
-            __LOCATION__ACTUALS, check, text);
-/*
-    dump_stack();
-*/
-}
-
-asmlinkage noreturn
-void deputy_fail_noreturn_fast(void) {
-    panic("Deputy assertion failure\n");
-}
-
-int deputy_strlen(const char *str) {
-    return strlen(str);
-}
-
-char *deputy_strcpy(char *dest, const char *src) {
-    char *tmp = dest;
-    while ((*dest++ = *src++) != '\0') {
-        // do nothing
-    }
-    return tmp;
-}
-
-char *deputy_strncpy(char *dest, const char *src, size_t count) {
-    char *tmp = dest;
-    int c = count;
-    while (c >= 0) {
-        if ((*tmp = *src) != 0) src++;
-        tmp++;
-        c--;
-    }
-    return dest;
-}
-
-/* Search for a NULL starting at e and return its index */
-int deputy_findnull(const void *e, unsigned int bytes) {
-#define NULLCHECK(type) \
-    do { \
-        type *p = (type*) e; \
-        while (*p != 0) { \
-            p++; \
-        } \
-        length = (p - (type*) e); \
-    } while (0)
-
-    int length = 0;
-
-    switch (bytes) {
-        case 1:
-            NULLCHECK(char);
-            break;
-        case 2:
-            NULLCHECK(short);
-            break;
-        case 4:
-            NULLCHECK(long);
-            break;
-        default:
-            cprintf("Invalid byte size for nullcheck.\n");
-            break;
-    }
-
-    return length;
-#undef NULLCHECK
-}
-
-void *__deputy_memset(void *s, int c, unsigned int n) {
-  return memset(s, c, n);
-}
-
-void __ivy_handler_atomic_entry() __attribute__((weak));
-void __ivy_handler_atomic_entry() {return;}
-
-void __ivy_handler_atomic_exit() __attribute__((weak));
-void __ivy_handler_atomic_exit() {return;}
-
-void __ivy_handler_atomic_locks_entry(unsigned int n, ...) __attribute__((weak));
-void __ivy_handler_atomic_locks_entry(unsigned int n, ...) {return;}
-
-void __ivy_handler_atomic_locks_exit(unsigned int n, ...) __attribute__((weak));
-void __ivy_handler_atomic_locks_exit(unsigned int n, ...) {return;}
diff --git a/ivylib/deputy_user.c b/ivylib/deputy_user.c
deleted file mode 100644 (file)
index 609252b..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-#include <inc/stdio.h>
-#include <inc/string.h>
-#include <inc/lib.h>
-
-// Use inline even when not optimizing for speed, since it prevents
-// warnings that would occur due to unused static functions.
-#ifdef DEPUTY_ALWAYS_STOP_ON_ERROR
-  #define INLINE inline __attribute__((always_inline))
-#else
-  #define INLINE inline
-#endif
-
-#define __LOCATION__        __FILE__, __LINE__, __FUNCTION__
-#define __LOCATION__FORMALS const char* file, int line, const char* func
-#define __LOCATION__ACTUALS file, line, func
-
-#ifndef asmlinkage
-#define asmlinkage __attribute__((regparm(0)))
-#endif
-
-#ifndef noreturn
-#define noreturn __attribute__((noreturn))
-#endif
-
-#define IN_DEPUTY_LIBRARY
-
-#include "deputy/checks.h"
-
-// If Deputy fails, it checks to see if you have specified special handling
-// for failed checks.
-enum handlerKind {
-    HANDLE_DEFAULT, // no handler specified
-    HANDLE_IGNORE,  // ignore
-    HANDLE_STOP,    // warn and stop
-    HANDLE_WARN,    // warn but do not stop
-    HANDLE_SLEEP,   // sleep and wait for the the debugger
-};
-
-static enum handlerKind deputyErrorHandler = HANDLE_DEFAULT;
-
-static int deputyInited = 0;
-static void deputyInitOnFirstFailure(void) {
-    // Cache the result of environment lookup
-    //char *onerror = getenv("DEPUTY_ONERROR");
-    deputyErrorHandler = HANDLE_DEFAULT;
-/*
-    if (onerror) {
-        if (!strcasecmp(onerror, "stop")) {
-            deputyErrorHandler = HANDLE_STOP;
-        } else if (!strcasecmp(onerror, "ignore")) {
-            deputyErrorHandler = HANDLE_IGNORE;
-        } else if (!strcasecmp(onerror, "warn")) {
-            deputyErrorHandler = HANDLE_WARN;
-        } else if (!strcasecmp(onerror, "sleep")) {
-            deputyErrorHandler = HANDLE_SLEEP;
-        } else {
-            fprintf(stderr, "Unexpected value for env var DEPUTY_ONERROR\n");
-        }
-    }
-*/
-}
-
-// This function is called directly from the checks unless the code was
-// compiled with --deputyAlwaysStopOnError . It is also called from
-// deputy_fail_noreturn to do the real work.
-asmlinkage
-void deputy_fail_mayreturn(const char *check, const char *text,
-                           __LOCATION__FORMALS) {
-    if (!deputyInited) {
-        deputyInitOnFirstFailure(); deputyInited = 1;
-    }
-    if (deputyErrorHandler != HANDLE_IGNORE) {
-        cprintf("%s:%d: %s: Assertion failed in %s:\n  %s\n",
-                __LOCATION__ACTUALS, check, text);
-    }
-    // Now look whether we should return or not
-    switch (deputyErrorHandler) {
-        case HANDLE_DEFAULT:
-        case HANDLE_STOP:
-            cprintf("Execution aborted.\n");
-            exit(/*1*/);
-#if 0
-        case HANDLE_SLEEP:
-#if defined(_MSVC)
-            // On Windows, this will fire the just-in-time debugger.
-            _asm { int 3 }
-#else
-            // Pause for debugging multithreaded code.
-            // (Trick due to Ben Liblit, via Dan Wilkerson.)
-            {
-                volatile int stopped = 1;
-
-                fprintf(stderr, "Execution paused for debugging (pid = %d).\n",
-                        getpid());
-                fflush(stderr);
-
-                while (stopped) {
-                    // 1. Execution will stop here.
-                    sleep(1);
-                }
-
-                // 2. Set breakpoint here, and set stopped to 0.
-                // (This statement exists so we have a place to put
-                // that breakpoint.)
-                stopped ++;
-            }
-#endif
-            break;
-#endif /* 0 */
-        default:
-            break;
-    }
-}
-
-// This function must NOT return. This is the function that is called
-// by the checks if we compiled with --alwaysStopOnError
-asmlinkage noreturn
-void deputy_fail_noreturn(const char *check, const char *text,
-                          __LOCATION__FORMALS) {
-    deputy_fail_mayreturn(check, text, __LOCATION__ACTUALS);
-    cprintf("Deputy check failed; execution aborted.\n");
-    exit(/*1*/);
-}
-
-// This function must NOT return. This is the function that is called
-// by the checks if we compiled with --alwaysStopOnError and --deputyFastChecks
-asmlinkage noreturn
-void deputy_fail_noreturn_fast(void) {
-    cprintf("Deputy check failed; execution aborted.\n");
-    cprintf("Detailed error report suppressed (--deputyFastChecks).\n");
-    exit(/*1*/);
-}
-
-/* Search for a NULL starting at e and return its index */
-asmlinkage
-int deputy_findnull(const void *e, unsigned int bytes) {
-#define NULLCHECK(type) \
-    do { \
-        type *p = (type*) e; \
-        while (*p != 0) { \
-            p++; \
-        } \
-        length = (p - (type*) e); \
-    } while (0)
-
-    int length = 0;
-
-    switch (bytes) {
-        case 1:
-            NULLCHECK(char);
-            break;
-        case 2:
-            NULLCHECK(short);
-            break;
-        case 4:
-            NULLCHECK(long);
-            break;
-        default:
-           cprintf("Invalid byte size for nullcheck.\n");
-           exit(/*1*/);
-    }
-
-    return length;
-#undef NULLCHECK
-}
-
-asmlinkage
-void *__deputy_memset(void *s, int c, unsigned int n) {
-  return memset(s, c, n);
-}
index 714ed06..8502400 100644 (file)
@@ -1,105 +1,4 @@
-#
-# Makefile fragment for ROS kernel.
-# This is NOT a complete makefile;
-# you must run GNU make in the top-level directory
-# where the GNUmakefile is located.
-#
 
-OBJDIRS += kern
-CC=ivycc --deputy
-
-KERN_LDFLAGS := $(LDFLAGS) -Lobj/ivylib -T kern/kernel.ld
-
-# entry.S must be first, so that it's the first code in the text segment!!!
-#
-# We also snatch the use of a couple handy source files
-# from the lib directory, to avoid gratuitous code duplication.
-KERN_SRCFILES :=       kern/entry.S \
-                       kern/smp_entry.S \
-                       kern/init.c \
-                       kern/console.c \
-                       kern/monitor.c \
-                       kern/pmap.c \
-                       kern/env.c \
-                       kern/kclock.c \
-                       kern/picirq.c \
-                       kern/printf.c \
-                       kern/trap.c \
-                       kern/trapentry.S \
-                       kern/sched.c \
-                       kern/syscall.c \
-                       kern/kdebug.c \
-                       kern/apic.c \
-                       kern/testing.c \
-                       kern/atomic.c \
-                       kern/smp.c \
-                       lib/printfmt.c \
-                       lib/readline.c \
-                       lib/string.c \
-                       lib/timer.c
-
-# Only build files if they exist.
-KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
-
-KERN_BINFILES :=       user_newlib/hello
-#                                      user/null \
-#                                      user/hello \
-#                                      user_newlib/null \
-#                              user/hello \
-#                              user/buggyhello \
-#                              user/evilhello \
-#                              user/testbss \
-#                              user/divzero \
-#                              user/breakpoint \
-#                              user/softint \
-#                              user/badsegment \
-#                              user/faultread \
-#                              user/faultreadkernel \
-#                              user/faultwrite \
-#                              user/faultwritekernel \
-#                              user_newlib/null \
-
-KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
-KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
-KERN_OBJFILES := $(patsubst obj/lib/%, obj/kern/%, $(KERN_OBJFILES))
-
-KERN_BINFILES := $(patsubst %, $(OBJDIR)/%, $(KERN_BINFILES))
-
-# How to build kernel object files
-$(OBJDIR)/kern/%.o: kern/%.c
-       @echo + cc $<
-       @mkdir -p $(@D)
-       $(V)$(CC) $(KERN_CFLAGS) -c -o $@ $<
-
-$(OBJDIR)/kern/%.o: kern/%.S
-       @echo + as $<
-       @mkdir -p $(@D)
-       $(V)$(CC) $(KERN_CFLAGS) -c -o $@ $<
-
-$(OBJDIR)/kern/%.o: lib/%.c
-       @echo + cc $<
-       @mkdir -p $(@D)
-       $(V)$(CC) $(KERN_CFLAGS) -c -o $@ $<
-
-# How to build the kernel itself
-$(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES) kern/kernel.ld $(OBJDIR)/ivylib/libivykern.a
-       @echo + ld $@
-       $(V)$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) -livykern $(GCC_LIB) -b binary $(KERN_BINFILES)
-       $(V)$(OBJDUMP) -S $@ > $@.asm
-       $(V)$(NM) -n $@ > $@.sym
-
-# How to build the Bochs disk image
-$(OBJDIR)/kern/bochs.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
-       @echo + mk $@
-       $(V)dd if=/dev/zero of=$(OBJDIR)/kern/bochs.img~ count=10000 2>/dev/null
-       $(V)dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/bochs.img~ conv=notrunc 2>/dev/null
-       $(V)dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/bochs.img~ seek=1 conv=notrunc 2>/dev/null
-       $(V)mv $(OBJDIR)/kern/bochs.img~ $(OBJDIR)/kern/bochs.img
-
-all: $(OBJDIR)/kern/bochs.img
-
-grub: $(OBJDIR)/ros-grub
-
-$(OBJDIR)/ros-grub: $(OBJDIR)/kern/kernel
-       @echo + oc $@
-       $(V)$(OBJCOPY) --adjust-vma=0x10000000 $^ $@
+KERN_DIR := kern
+include $(KERN_DIR)/ivylib/Makefrag
+include $(KERN_DIR)/src/Makefrag
diff --git a/kern/apic.c b/kern/apic.c
deleted file mode 100644 (file)
index 28b56e3..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2009 The Regents of the University of California
- * See LICENSE for details.
- */
-
-#include <inc/mmu.h>
-#include <inc/x86.h>
-#include <inc/assert.h>
-#include <inc/timer.h>
-
-#include <kern/apic.h>
-
-system_timing_t system_timing = {0, 0, 0xffff, 0};
-
-/*
- * Remaps the Programmable Interrupt Controller to use IRQs 32-47
- * http://wiki.osdev.org/PIC
- * Not 100% on this stuff, after looking over 
- * http://bochs.sourceforge.net/techspec/PORTS.LST  The cascading and other 
- * stuff might need to be in one command, and after that all we are doing
- * is toggling masks.
- */
-void pic_remap() 
-{
-       // start initialization
-       outb(PIC1_CMD, 0x11);
-       outb(PIC2_CMD, 0x11);
-       // set new offsets
-       outb(PIC1_DATA, PIC1_OFFSET);
-       outb(PIC2_DATA, PIC2_OFFSET);
-       // set up cascading
-       outb(PIC1_DATA, 0x04);
-       outb(PIC2_DATA, 0x02);
-       // other stuff (put in 8086/88 mode, or whatever)
-       outb(PIC1_DATA, 0x01);
-       outb(PIC2_DATA, 0x01);
-       // set masks, defaulting to all masked for now
-       outb(PIC1_DATA, 0xff);
-       outb(PIC2_DATA, 0xff);
-}
-
-void pic_mask_irq(uint8_t irq)
-{
-       if (irq > 7)
-               outb(PIC2_DATA, inb(PIC2_DATA) | (1 << (irq - 8)));
-       else
-               outb(PIC1_DATA, inb(PIC1_DATA) | (1 << irq));
-}
-
-void pic_unmask_irq(uint8_t irq)
-{
-       if (irq > 7) {
-               outb(PIC2_DATA, inb(PIC2_DATA) & ~(1 << (irq - 8)));
-               outb(PIC1_DATA, inb(PIC1_DATA) & 0xfd); // make sure irq2 is unmasked
-       } else
-               outb(PIC1_DATA, inb(PIC1_DATA) & ~(1 << irq));
-}
-
-
-/*
- * Sets the LAPIC timer to go off after a certain number of ticks.  The primary
- * clock freq is actually the bus clock, which we figure out during timer_init
- * Unmasking is implied.  Ref SDM, 3A, 9.6.4
- */
-void __lapic_set_timer(uint32_t ticks, uint8_t vec, bool periodic, uint8_t div)
-{
-       // clears bottom bit and then set divider
-       write_mmreg32(LAPIC_TIMER_DIVIDE, (read_mmreg32(LAPIC_TIMER_DIVIDE) &~0xf) |
-                     (div & 0xf));
-       // set LVT with interrupt handling information
-       write_mmreg32(LAPIC_LVT_TIMER, vec | (periodic << 17));
-       write_mmreg32(LAPIC_TIMER_INIT, ticks);
-       // For debugging when we expand this
-       //cprintf("LAPIC LVT Timer: 0x%08x\n", read_mmreg32(LAPIC_LVT_TIMER));
-       //cprintf("LAPIC Init Count: 0x%08x\n", read_mmreg32(LAPIC_TIMER_INIT));
-       //cprintf("LAPIC Current Count: 0x%08x\n", read_mmreg32(LAPIC_TIMER_CURRENT));
-}
-
-void lapic_set_timer(uint32_t usec, bool periodic)
-{
-       // divide the bus clock by 128, which is the max.
-       uint32_t ticks = (usec * system_timing.bus_freq / 128) / 1000000;
-       __lapic_set_timer(ticks, LAPIC_TIMER_DEFAULT_VECTOR, periodic,
-                         LAPIC_TIMER_DEFAULT_DIVISOR);
-}
-
-uint32_t lapic_get_default_id(void)
-{
-       uint32_t ebx;
-       cpuid(1, 0, &ebx, 0, 0);
-       // p6 family only uses 4 bits here, and 0xf is reserved for the IOAPIC
-       return (ebx & 0xFF000000) >> 24;
-}
-
-// timer init calibrates both tsc timer and lapic timer using PIT
-void timer_init(void){
-       uint64_t tscval[2];
-       long timercount[2];
-       pit_set_timer(0xffff, TIMER_RATEGEN);
-       // assume tsc exist
-       tscval[0] = read_tsc();
-       udelay_pit(1000000);
-       tscval[1] = read_tsc();
-       system_timing.tsc_freq = tscval[1] - tscval[0];
-       
-       cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq);
-
-       __lapic_set_timer(0xffffffff, LAPIC_TIMER_DEFAULT_VECTOR, FALSE,
-                         LAPIC_TIMER_DEFAULT_DIVISOR);
-       // Mask the LAPIC Timer, so we never receive this interrupt (minor race)
-       mask_lapic_lvt(LAPIC_LVT_TIMER);
-       timercount[0] = read_mmreg32(LAPIC_TIMER_CURRENT);
-       udelay_pit(1000000);
-       timercount[1] = read_mmreg32(LAPIC_TIMER_CURRENT);
-       system_timing.bus_freq = (timercount[0] - timercount[1])*128;
-               
-       cprintf("Bus Frequency: %llu\n", system_timing.bus_freq);
-}
-
-void pit_set_timer(uint32_t divisor, uint32_t mode)
-{
-       if (divisor & 0xffff0000)
-               warn("Divisor too large!");
-       mode = TIMER_SEL0|TIMER_16BIT|mode;
-       outb(TIMER_MODE, mode); 
-       outb(TIMER_CNTR0, divisor & 0xff);
-       outb(TIMER_CNTR0, (divisor >> 8) );
-       system_timing.pit_mode = mode;
-       system_timing.pit_divisor = divisor;
-       // cprintf("timer mode set to %d, divisor %d\n",mode, divisor);
-}
-
-static int getpit()
-{
-    int high, low;
-       // TODO: need a lock to protect access to PIT
-
-    /* Select timer0 and latch counter value. */
-    outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
-    
-    low = inb(TIMER_CNTR0);
-    high = inb(TIMER_CNTR0);
-
-    return ((high << 8) | low);
-}
-
-// forces cpu to relax for usec miliseconds
-void udelay(uint64_t usec)
-{
-       #if !defined(__BOCHS__)
-       if (system_timing.tsc_freq != 0)
-       {
-               uint64_t start, end, now;
-
-               start = read_tsc();
-        end = start + (system_timing.tsc_freq * usec) / 1000000;
-        //cprintf("start %llu, end %llu\n", start, end);
-               if (end == 0) cprintf("This is terribly wrong \n");
-               do {
-            cpu_relax();
-            now = read_tsc();
-                       //cprintf("now %llu\n", now);
-               } while (now < end || (now > start && end < start));
-        return;
-
-       } else
-       #endif
-       {
-               udelay_pit(usec);
-       }
-}
-
-void udelay_pit(uint64_t usec)
-{
-       
-       int64_t delta, prev_tick, tick, ticks_left;
-       prev_tick = getpit();
-       /*
-        * Calculate (n * (i8254_freq / 1e6)) without using floating point
-        * and without any avoidable overflows.
-        */
-       if (usec <= 0)
-               ticks_left = 0;
-       // some optimization from bsd code
-       else if (usec < 256)
-               /*
-                * Use fixed point to avoid a slow division by 1000000.
-                * 39099 = 1193182 * 2^15 / 10^6 rounded to nearest.
-                * 2^15 is the first power of 2 that gives exact results
-                * for n between 0 and 256.
-                */
-               ticks_left = ((uint64_t)usec * 39099 + (1 << 15) - 1) >> 15;
-       else
-               // round up the ticks left
-               ticks_left = ((uint64_t)usec * (long long)PIT_FREQ+ 999999)
-                            / 1000000; 
-       while (ticks_left > 0) {
-               tick = getpit();
-               delta = prev_tick - tick;
-               prev_tick = tick;
-               if (delta < 0) {
-                       // counter looped around during the delta time period
-                       delta += system_timing.pit_divisor; // maximum count 
-                       if (delta < 0)
-                               delta = 0;
-               }
-               ticks_left -= delta;
-       }
-}
-
-uint64_t gettimer(void)
-{
-       return read_tsc();      
-}
-
-uint64_t getfreq(void)
-{
-       return system_timing.tsc_freq;
-}
-
diff --git a/kern/atomic.c b/kern/atomic.c
deleted file mode 100644 (file)
index f7d9e97..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-#include <inc/string.h>
-#include <inc/assert.h>
-#include <inc/error.h>
-
-#include <kern/atomic.h>
-#include <kern/apic.h>
-
-// Must be called in a pair with waiton_checklist
-int commit_checklist_wait(checklist_t* list, checklist_mask_t* mask)
-{
-       assert(list->mask.size == mask->size);
-       // abort if the list is locked.  this will protect us from trying to commit
-       // and thus spin on a checklist that we are already waiting on.  it is
-       // still possible to not get the lock, but the holder is on another core.
-       // Or, bail out if we can see the list is already in use.  This check is
-       // just an optimization before we try to use the list for real.
-       if ((checklist_is_locked(list)) || !checklist_is_clear(list))
-               return E_BUSY;
-
-       // possession of this lock means you can wait on it and set it
-       spin_lock_irqsave(&list->lock);
-       // wait til the list is available.  could have some adaptive thing here
-       // where it fails after X tries (like 500), gives up the lock, and returns
-       // an error code
-       while (!checklist_is_clear(list))
-               cpu_relax();
-
-       // list is ours and clear, set it to the settings of our list
-       COPY_BITMASK(list->mask.bits, mask->bits, mask->size); 
-       return 0;
-}
-
-int commit_checklist_nowait(checklist_t* list, checklist_mask_t* mask)
-{
-       int e = 0;
-       if (e = commit_checklist_wait(list, mask))
-               return e;
-       // give up the lock, since we won't wait for completion
-       spin_unlock_irqsave(&list->lock);
-       return e;
-}
-// The deal with the lock:
-// what if two different actors are waiting on the list, but for different reasons?
-// part of the problem is we are doing both set and check via the same path
-//
-// aside: we made this a lot more difficult than the usual barriers or even 
-// the RCU grace-period checkers, since we have to worry about this construct
-// being used by others before we are done with it.
-//
-// how about this: if we want to wait on this later, we just don't release the
-// lock.  if we release it, then we don't care who comes in and grabs and starts
-// checking the list.  
-//     - regardless, there are going to be issues with people looking for a free 
-//     item.  even if they grab the lock, they may end up waiting a while and 
-//     wantint to bail (like test for a while, give up, move on, etc).  
-//     - still limited in that only the setter can check, and only one person
-//     can spinwait / check for completion.  if someone else tries to wait (wanting
-//     completion), they may miss it if someone else comes in and grabs the lock
-//     to use it for a new checklist
-//             - if we had the ability to sleep and get woken up, we could have a 
-//             queue.  actually, we could do a queue anyway, but they all spin
-//             and it's the bosses responsibility to *wake* them
-
-// Must be called after commit_checklist
-// Assumed we held the lock if we ever call this
-int waiton_checklist(checklist_t* list)
-{
-       extern uint32_t outstanding_calls;
-       // can consider breakout out early, like above, and erroring out
-       while (!checklist_is_clear(list))
-               cpu_relax();
-       spin_unlock_irqsave(&list->lock);
-       // global counter of wrappers either waited on or being contended for.
-       atomic_dec(&outstanding_calls);
-       return 0;
-}
-
-// like waiton, but don't bother waiting either
-int release_checklist(checklist_t* list)
-{
-       spin_unlock_irqsave(&list->lock);
-       return 0;
-}
-
-// peaks in and sees if the list is locked with it's spinlock
-int checklist_is_locked(checklist_t* list)
-{
-       // remember the lock status is the lowest byte of the lock
-       return list->lock & 0xff;
-}
-
-// no synch guarantees - just looks at the list
-int checklist_is_clear(checklist_t* list)
-{
-       return BITMASK_IS_CLEAR(list->mask.bits, list->mask.size);
-}
-
-// no synch guarantees - just resets the list to empty
-void reset_checklist(checklist_t* list)
-{
-       CLR_BITMASK(list->mask.bits, list->mask.size);
-}
-
-// CPU mask specific - this is how cores report in
-void down_checklist(checklist_t* list)
-{
-       CLR_BITMASK_BIT_ATOMIC(list->mask.bits, lapic_get_id());
-}
-
-/* Barriers */
-void init_barrier(barrier_t* barrier, uint32_t count)
-{
-       barrier->lock = 0;
-       barrier->init_count = count;
-       barrier->current_count = count;
-       barrier->ready = 0;
-}
-
-void reset_barrier(barrier_t* barrier)
-{
-       barrier->current_count = barrier->init_count;
-}
-
-// primitive barrier function.  all cores call this.
-void waiton_barrier(barrier_t* barrier)
-{
-       uint8_t local_ready = barrier->ready;
-
-       spin_lock_irqsave(&barrier->lock);
-       barrier->current_count--;
-       if (barrier->current_count) {
-               spin_unlock_irqsave(&barrier->lock);
-               while (barrier->ready == local_ready)
-                       cpu_relax();
-       } else {
-               spin_unlock_irqsave(&barrier->lock);
-               reset_barrier(barrier);
-               // if we need to wmb(), it'll be here
-               barrier->ready++;
-       }
-}
diff --git a/kern/console.c b/kern/console.c
deleted file mode 100644 (file)
index ad94a80..0000000
+++ /dev/null
@@ -1,566 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-#include <inc/x86.h>
-#include <inc/memlayout.h>
-#include <inc/kbdreg.h>
-#include <inc/string.h>
-#include <inc/assert.h>
-
-#include <kern/console.h>
-
-
-void cons_intr(int (*proc)(void));
-void scroll_screen(void);
-
-
-/***** Serial I/O code *****/
-
-#define COM1           0x3F8
-
-#define        COM_RX                  0               // In:  Receive buffer (DLAB=0)
-#define COM_DLL                        0               // Out: Divisor Latch Low (DLAB=1)
-#define COM_DLM                        1               // Out: Divisor Latch High (DLAB=1)
-#define COM_IER                        1               // Out: Interrupt Enable Register
-#define        COM_IER_RDI             0x01    //   Enable receiver data interrupt
-#define COM_IIR                        2               // In:  Interrupt ID Register
-#define COM_FCR                        2               // Out: FIFO Control Register
-#define COM_LCR                        3               // Out: Line Control Register
-#define        COM_LCR_DLAB    0x80    //   Divisor latch access bit
-#define        COM_LCR_WLEN8   0x03    //   Wordlength: 8 bits
-#define COM_MCR                        4               // Out: Modem Control Register
-#define        COM_MCR_RTS             0x02    // RTS complement
-#define        COM_MCR_DTR             0x01    // DTR complement
-#define        COM_MCR_OUT2    0x08    // Out2 complement
-#define COM_LSR                        5               // In:  Line Status Register
-#define COM_LSR_DATA   0x01    //   Data available
-#define COM_LSR_READY  0x20    //   Ready to send
-
-static bool serial_exists;
-
-int
-serial_proc_data(void)
-{
-       if (!(inb(COM1+COM_LSR) & COM_LSR_DATA))
-               return -1;
-       return inb(COM1+COM_RX);
-}
-
-void
-serial_intr(void)
-{
-       if (serial_exists)
-               cons_intr(serial_proc_data);
-}
-
-void
-serial_init(void)
-{
-       // Turn off the FIFO
-       outb(COM1+COM_FCR, 0);
-       
-       // Set speed; requires DLAB latch
-       outb(COM1+COM_LCR, COM_LCR_DLAB);
-       // Setting speed to 115200 (setting the divider to 1)
-       outb(COM1+COM_DLL, 1);
-       outb(COM1+COM_DLM, 0);
-
-       // 8 data bits, 1 stop bit, parity off; turn off DLAB latch
-       outb(COM1+COM_LCR, COM_LCR_WLEN8 & ~COM_LCR_DLAB);
-
-       // No modem controls
-       outb(COM1+COM_MCR, 0);
-       // Enable rcv interrupts
-       outb(COM1+COM_IER, COM_IER_RDI);
-
-       // Clear any preexisting overrun indications and interrupts
-       // Serial port doesn't exist if COM_LSR returns 0xFF
-       serial_exists = (inb(COM1+COM_LSR) != 0xFF);
-       (void) inb(COM1+COM_IIR);
-       (void) inb(COM1+COM_RX);
-
-}
-
-static void
-serial_send_byte(uint8_t b)
-{
-       while (!(inb(COM1+COM_LSR) & COM_LSR_READY));
-       outb(COM1, b);
-}
-
-static void
-serial_putc(int c)
-{
-       switch (c & 0xff) {
-       case '\b':
-               serial_send_byte('\b');
-               serial_send_byte((uint8_t)(' '));
-               serial_send_byte('\b');
-               break;
-       case '\n':
-       case '\r':
-               serial_send_byte((uint8_t)('\n'));
-               serial_send_byte((uint8_t)('\r'));
-               break;
-       default:
-               serial_send_byte((uint8_t)(c & 0xff));
-               break;
-       }
-       return;
-}
-
-
-
-/***** Parallel port output code *****/
-// For information on PC parallel port programming, see the class References
-// page.
-
-// Stupid I/O delay routine necessitated by historical PC design flaws
-static void
-delay(void)
-{
-       inb(0x84);
-       inb(0x84);
-       inb(0x84);
-       inb(0x84);
-}
-
-static void
-lpt_putc(int c)
-{
-       int i;
-
-       for (i = 0; !(inb(0x378+1) & 0x80) && i < 12800; i++)
-               delay();
-       outb(0x378+0, c);
-       outb(0x378+2, 0x08|0x04|0x01);
-       outb(0x378+2, 0x08);
-}
-
-
-
-
-/***** Text-mode CGA/VGA display output with scrolling *****/
-#define MAX_SCROLL_LENGTH      20
-#define SCROLLING_CRT_SIZE     (MAX_SCROLL_LENGTH * CRT_SIZE)
-
-static unsigned addr_6845;
-static uint16_t *COUNT(CRT_SIZE) crt_buf;
-static uint16_t crt_pos;
-
-static uint16_t scrolling_crt_buf[SCROLLING_CRT_SIZE];
-static uint16_t scrolling_crt_pos;
-static uint8_t current_crt_buf;
-
-void
-cga_init(void)
-{
-       volatile uint16_t *COUNT(CRT_SIZE) cp;
-       uint16_t was;
-       unsigned pos;
-
-       cp = (uint16_t *COUNT(CRT_SIZE)) TC(KERNBASE + CGA_BUF);
-       was = *cp;
-       *cp = (uint16_t) 0xA55A;
-       if (*cp != 0xA55A) {
-               cp = (uint16_t *COUNT(CRT_SIZE)) TC(KERNBASE + MONO_BUF);
-               addr_6845 = MONO_BASE;
-       } else {
-               *cp = was;
-               addr_6845 = CGA_BASE;
-       }
-       
-       /* Extract cursor location */
-       outb(addr_6845, 14);
-       pos = inb(addr_6845 + 1) << 8;
-       outb(addr_6845, 15);
-       pos |= inb(addr_6845 + 1);
-
-       crt_buf = (uint16_t *COUNT(CRT_SIZE)) cp;
-       crt_pos = pos;
-       scrolling_crt_pos = 0;
-       current_crt_buf = 0;
-}
-
-static void set_screen(uint8_t screen_num) {
-       uint16_t leftovers = (scrolling_crt_pos % CRT_COLS);
-       leftovers = (leftovers) ? CRT_COLS - leftovers : 0;
-       
-       int offset = scrolling_crt_pos + leftovers - (screen_num + 1)*CRT_SIZE;
-       offset = (offset > 0) ? offset : 0;
-
-       memcpy(crt_buf, scrolling_crt_buf + offset, CRT_SIZE * sizeof(uint16_t));
-}
-
-static void scroll_screen_up(void) {
-       if(current_crt_buf <  (scrolling_crt_pos / CRT_SIZE))
-               current_crt_buf++;
-       set_screen(current_crt_buf);
-}
-
-static void scroll_screen_down(void) {
-       if(current_crt_buf > 0) 
-               current_crt_buf--;
-       set_screen(current_crt_buf);
-}
-
-static void reset_screen(void) {
-       current_crt_buf = 0;
-       set_screen(current_crt_buf);
-}
-
-void
-cga_putc(int c)
-{
-       // if no attribute given, then use black on white
-       if (!(c & ~0xFF))
-               c |= 0x0700;
-
-       switch (c & 0xff) {
-       case '\b':
-               if (crt_pos > 0) {
-                       crt_pos--;
-                       scrolling_crt_pos--;
-
-                       crt_buf[crt_pos] = (c & ~0xff) | ' ';
-                       scrolling_crt_buf[scrolling_crt_pos] = crt_buf[crt_pos];
-               }
-               break;
-       case '\n':
-               crt_pos += CRT_COLS;
-               scrolling_crt_pos += CRT_COLS;
-               /* fallthru */
-       case '\r':
-               crt_pos -= (crt_pos % CRT_COLS);
-               scrolling_crt_pos -= (scrolling_crt_pos % CRT_COLS);
-               break;
-       case '\t':
-               cons_putc(' ');
-               cons_putc(' ');
-               cons_putc(' ');
-               cons_putc(' ');
-               cons_putc(' ');
-               break;
-       default:
-               crt_buf[crt_pos++] = c;         /* write the character */
-               scrolling_crt_buf[scrolling_crt_pos++] = c;
-               break;
-       }
-
-       // The purpose of this is to allow the screen to appear as if it is scrolling as
-       // more lines are added beyond the size of the monitor.  The top line is dropped
-       // and everything is shifted up by one.
-       if (crt_pos >= CRT_SIZE) {
-               int i;
-
-               memcpy(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t));
-               for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++)
-                       crt_buf[i] = 0x0700 | ' ';
-               crt_pos -= CRT_COLS;
-       }
-       // Do the same for the scrolling crt buffer when it hits its capacity
-       if (scrolling_crt_pos >= SCROLLING_CRT_SIZE) {
-               int i;
-
-               memcpy(scrolling_crt_buf, scrolling_crt_buf + CRT_COLS, 
-                      (SCROLLING_CRT_SIZE - CRT_COLS) * sizeof(uint16_t));
-               for (i = SCROLLING_CRT_SIZE - CRT_COLS; i < SCROLLING_CRT_SIZE; i++)
-                       scrolling_crt_buf[i] = 0x0700 | ' ';
-               scrolling_crt_pos -= CRT_COLS;
-       }
-
-
-       /* move that little blinky thing */
-       outb(addr_6845, 14);
-       outb(addr_6845 + 1, crt_pos >> 8);
-       outb(addr_6845, 15);
-       outb(addr_6845 + 1, crt_pos);
-}
-
-
-/***** Keyboard input code *****/
-
-#define NO             0
-
-#define SHIFT  (1<<0)
-#define CTL            (1<<1)
-#define ALT            (1<<2)
-
-#define CAPSLOCK       (1<<3)
-#define NUMLOCK                (1<<4)
-#define SCROLLLOCK     (1<<5)
-
-#define E0ESC          (1<<6)
-
-static uint8_t shiftcode[256] = 
-{
-       [0x1D] CTL,
-       [0x2A] SHIFT,
-       [0x36] SHIFT,
-       [0x38] ALT,
-       [0x9D] CTL,
-       [0xB8] ALT
-};
-
-static uint8_t togglecode[256] = 
-{
-       [0x3A] CAPSLOCK,
-       [0x45] NUMLOCK,
-       [0x46] SCROLLLOCK
-};
-
-static uint8_t normalmap[256] =
-{
-       NO,   0x1B, '1',  '2',  '3',  '4',  '5',  '6',  // 0x00
-       '7',  '8',  '9',  '0',  '-',  '=',  '\b', '\t',
-       'q',  'w',  'e',  'r',  't',  'y',  'u',  'i',  // 0x10
-       'o',  'p',  '[',  ']',  '\n', NO,   'a',  's',
-       'd',  'f',  'g',  'h',  'j',  'k',  'l',  ';',  // 0x20
-       '\'', '`',  NO,   '\\', 'z',  'x',  'c',  'v',
-       'b',  'n',  'm',  ',',  '.',  '/',  NO,   '*',  // 0x30
-       NO,   ' ',  NO,   NO,   NO,   NO,   NO,   NO,
-       NO,   NO,   NO,   NO,   NO,   NO,   NO,   '7',  // 0x40
-       '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1',
-       '2',  '3',  '0',  '.',  NO,   NO,   NO,   NO,   // 0x50
-       [0xC7] KEY_HOME,        [0x9C] '\n' /*KP_Enter*/,
-       [0xB5] '/' /*KP_Div*/,  [0xC8] KEY_UP,
-       [0xC9] KEY_PGUP,        [0xCB] KEY_LF,
-       [0xCD] KEY_RT,          [0xCF] KEY_END,
-       [0xD0] KEY_DN,          [0xD1] KEY_PGDN,
-       [0xD2] KEY_INS,         [0xD3] KEY_DEL
-};
-
-static uint8_t shiftmap[256] = 
-{
-       NO,   033,  '!',  '@',  '#',  '$',  '%',  '^',  // 0x00
-       '&',  '*',  '(',  ')',  '_',  '+',  '\b', '\t',
-       'Q',  'W',  'E',  'R',  'T',  'Y',  'U',  'I',  // 0x10
-       'O',  'P',  '{',  '}',  '\n', NO,   'A',  'S',
-       'D',  'F',  'G',  'H',  'J',  'K',  'L',  ':',  // 0x20
-       '"',  '~',  NO,   '|',  'Z',  'X',  'C',  'V',
-       'B',  'N',  'M',  '<',  '>',  '?',  NO,   '*',  // 0x30
-       NO,   ' ',  NO,   NO,   NO,   NO,   NO,   NO,
-       NO,   NO,   NO,   NO,   NO,   NO,   NO,   '7',  // 0x40
-       '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1',
-       '2',  '3',  '0',  '.',  NO,   NO,   NO,   NO,   // 0x50
-       [0xC7] KEY_HOME,        [0x9C] '\n' /*KP_Enter*/,
-       [0xB5] '/' /*KP_Div*/,  [0xC8] KEY_UP,
-       [0xC9] KEY_PGUP,        [0xCB] KEY_LF,
-       [0xCD] KEY_RT,          [0xCF] KEY_END,
-       [0xD0] KEY_DN,          [0xD1] KEY_PGDN,
-       [0xD2] KEY_INS,         [0xD3] KEY_DEL
-};
-
-#define C(x) (x - '@')
-
-static uint8_t ctlmap[256] = 
-{
-       NO,      NO,      NO,      NO,      NO,      NO,      NO,      NO, 
-       NO,      NO,      NO,      NO,      NO,      NO,      NO,      NO, 
-       C('Q'),  C('W'),  C('E'),  C('R'),  C('T'),  C('Y'),  C('U'),  C('I'),
-       C('O'),  C('P'),  NO,      NO,      '\r',    NO,      C('A'),  C('S'),
-       C('D'),  C('F'),  C('G'),  C('H'),  C('J'),  C('K'),  C('L'),  NO, 
-       NO,      NO,      NO,      C('\\'), C('Z'),  C('X'),  C('C'),  C('V'),
-       C('B'),  C('N'),  C('M'),  NO,      NO,      C('/'),  NO,      NO,
-       [0x97] KEY_HOME,
-       [0xB5] C('/'),          [0xC8] KEY_UP,
-       [0xC9] KEY_PGUP,        [0xCB] KEY_LF,
-       [0xCD] KEY_RT,          [0xCF] KEY_END,
-       [0xD0] KEY_DN,          [0xD1] KEY_PGDN,
-       [0xD2] KEY_INS,         [0xD3] KEY_DEL
-};
-
-static uint8_t * COUNT(256) charcode[4] = {
-       normalmap,
-       shiftmap,
-       ctlmap,
-       ctlmap
-};
-
-/*
- * Get data from the keyboard.  If we finish a character, return it.  Else 0.
- * Return -1 if no data.
- */
-static int
-kbd_proc_data(void)
-{
-       int c;
-       uint8_t data;
-       static uint32_t shift;
-       static bool crt_scrolled = FALSE;
-
-       if ((inb(KBSTATP) & KBS_DIB) == 0)
-               return -1;
-
-       data = inb(KBDATAP);
-
-       if (data == 0xE0) {
-               // E0 escape character
-               shift |= E0ESC;
-               return 0;
-       } else if (data & 0x80) {
-               // Key released
-               data = (shift & E0ESC ? data : data & 0x7F);
-               shift &= ~(shiftcode[data] | E0ESC);
-               return 0;
-       } else if (shift & E0ESC) {
-               // Last character was an E0 escape; or with 0x80
-               data |= 0x80;
-               shift &= ~E0ESC;
-       }
-
-       shift |= shiftcode[data];
-       shift ^= togglecode[data];
-
-       c = charcode[shift & (CTL | SHIFT)][data];
-
-       //Scrolling screen functionality
-       if((shift & SHIFT) && ((c == KEY_UP) || (c == KEY_PGUP))) {
-               crt_scrolled = TRUE;
-               scroll_screen_up();
-               return 0;
-       }
-       else if((shift & SHIFT) && ((c == KEY_DN) || (c == KEY_PGDN))) {
-               crt_scrolled = TRUE;
-               scroll_screen_down();
-               return 0;
-       }
-       else if((shift & SHIFT) && c == KEY_RT) {
-               crt_scrolled = FALSE;
-               reset_screen();
-               return 0;
-       }
-
-       // On keypress other than SHIFT, reset if we were scrolled
-       if(crt_scrolled && (!(shift & SHIFT))) {
-               crt_scrolled = FALSE;
-               reset_screen();
-       }
-
-       //Force character to capital if caps lock on
-       if (shift & CAPSLOCK) {
-               if ('a' <= c && c <= 'z')
-                       c += 'A' - 'a';
-               else if ('A' <= c && c <= 'Z')
-                       c += 'a' - 'A';
-       }
-
-       // Process special keys
-       // Ctrl-Alt-Del: reboot
-       if (!(~shift & (CTL | ALT)) && c == KEY_DEL) {
-               cprintf("Rebooting!\n");
-               outb(0x92, 0x3); // courtesy of Chris Frost
-       }
-
-       return c;
-}
-
-void
-kbd_intr(void)
-{
-       cons_intr(kbd_proc_data);
-}
-
-void
-kbd_init(void)
-{
-}
-
-
-
-/***** General device-independent console code *****/
-// Here we manage the console input buffer,
-// where we stash characters received from the keyboard or serial port
-// whenever the corresponding interrupt occurs.
-
-#define CONSBUFSIZE    512
-
-static struct {
-       uint8_t buf[CONSBUFSIZE];
-       uint32_t rpos;
-       uint32_t wpos;
-} cons;
-
-// called by device interrupt routines to feed input characters
-// into the circular console input buffer.
-void
-cons_intr(int (*proc)(void))
-{
-       int c;
-
-       while ((c = (*proc)()) != -1) {
-               if (c == 0)
-                       continue;
-               cons.buf[cons.wpos++] = c;
-               if (cons.wpos == CONSBUFSIZE)
-                       cons.wpos = 0;
-       }
-}
-
-// return the next input character from the console, or 0 if none waiting
-int
-cons_getc(void)
-{
-       int c;
-
-       // poll for any pending input characters,
-       // so that this function works even when interrupts are disabled
-       // (e.g., when called from the kernel monitor).
-       serial_intr();
-       kbd_intr();
-
-       // grab the next character from the input buffer.
-       if (cons.rpos != cons.wpos) {
-               c = cons.buf[cons.rpos++];
-               if (cons.rpos == CONSBUFSIZE)
-                       cons.rpos = 0;
-               return c;
-       }
-       return 0;
-}
-
-// output a character to the console
-void
-cons_putc(int c)
-{
-       serial_putc(c);
-       //lpt_putc(c);
-       cga_putc(c);
-}
-
-// initialize the console devices
-void
-cons_init(void)
-{
-       cga_init();
-       kbd_init();
-       serial_init();
-
-       if (!serial_exists)
-               cprintf("Serial port does not exist!\n");
-}
-
-
-// `High'-level console I/O.  Used by readline and cprintf.
-
-void
-cputchar(int c)
-{
-       cons_putc(c);
-}
-
-int
-getchar(void)
-{
-       int c;
-
-       while ((c = cons_getc()) == 0)
-               /* do nothing */;
-       return c;
-}
-
-int
-iscons(int fdnum)
-{
-       // used by readline
-       return 1;
-}
diff --git a/kern/entry.S b/kern/entry.S
deleted file mode 100644 (file)
index 3330be9..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-#include <inc/mmu.h>
-#include <inc/memlayout.h>
-#include <inc/trap.h>
-
-# Shift Right Logical 
-#define SRL(val, shamt)                (((val) >> (shamt)) & ~(-1 << (32 - (shamt))))
-
-
-###################################################################
-# The kernel (this code) is linked at address (KERNBASE + 0x00100000 (1MB)), 
-# but we tell the bootloader to load it at physical address 
-# 0x00100000 (1MB), which is the start of extended memory.
-# (See kernel.ld)
-###################################################################
-
-
-###################################################################
-# RELOC(x) maps a symbol x from its link address to its actual
-# location in physical memory (its load address).       
-###################################################################
-#define        RELOC(x) ((x) - KERNBASE)
-
-
-.set CODE_SEL,0x8              # index of code seg within mygdt
-.set DATA_SEL,0x10             # index of data seg within mygdt
-
-#define MULTIBOOT_PAGE_ALIGN  (1<<0)
-#define MULTIBOOT_MEMORY_INFO (1<<1)
-#define MULTIBOOT_HEADER_MAGIC (0x1BADB002)
-#define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_MEMORY_INFO | MULTIBOOT_PAGE_ALIGN)
-#define CHECKSUM (-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS))
-
-###################################################################
-# entry point
-###################################################################
-
-.text
-
-# The Multiboot header
-.align 4
-.long MULTIBOOT_HEADER_MAGIC
-.long MULTIBOOT_HEADER_FLAGS
-.long CHECKSUM
-
-.globl         _start
-_start:
-       movw    $0x1234,0x472                   # warm boot
-
-       # Establish our own GDT in place of the boot loader's temporary GDT.
-       lgdt    RELOC(mygdtdesc)                # load descriptor table
-
-       # Immediately reload all segment registers (including CS!)
-       # with segment selectors from the new GDT.
-       movl    $DATA_SEL, %eax                 # Data segment selector
-       movw    %ax,%ds                         # -> DS: Data Segment
-       movw    %ax,%es                         # -> ES: Extra Segment
-       movw    %ax,%ss                         # -> SS: Stack Segment
-       ljmp    $CODE_SEL,$relocated            # reload CS by jumping
-relocated:
-
-       # Clear the frame pointer register (EBP)
-       # so that once we get into debugging C code,
-       # stack backtraces will be terminated properly.
-       movl    $0x0,%ebp                       # nuke frame pointer
-
-    # Set the stack pointer
-       movl    $(bootstacktop),%esp
-
-       # Save multiboot info
-       push    %ebx
-
-       # now to C code
-       movl    $0x1,num_cpus           # init global var, for now
-       call    kernel_init
-
-       # Should never get here, but in case we do, just spin.
-spin:  jmp     spin
-
-###################################################################    
-# See <inc/memlayout.h> for a complete description of these two symbols.
-###################################################################
-.data
-       .globl  vpt
-       .set    vpt, VPT
-       .globl  vpd
-       .set    vpd, (VPT + SRL(VPT, 10))
-
-
-###################################################################
-# boot stack
-###################################################################
-       .p2align        PGSHIFT         # force page alignment
-       .globl          bootstack
-bootstack:
-       .space          KSTKSIZE
-       .globl          bootstacktop   
-bootstacktop:
-
-###################################################################
-# setup the GDT        
-###################################################################
-       .p2align        2               # force 4 byte alignment
-mygdt:
-       SEG_NULL                                # null seg
-       SEG(STA_X|STA_R, -KERNBASE, 0xffffffff) # code seg
-       SEG(STA_W, -KERNBASE, 0xffffffff)       # data seg
-mygdtdesc:
-       .word   0x17                    # sizeof(mygdt) - 1
-       .long   RELOC(mygdt)            # address mygdt
-
diff --git a/kern/env.c b/kern/env.c
deleted file mode 100644 (file)
index f6c6072..0000000
+++ /dev/null
@@ -1,535 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-#ifdef __DEPUTY__
-#pragma nodeputy
-#endif
-
-#include <inc/x86.h>
-#include <inc/mmu.h>
-#include <inc/error.h>
-#include <inc/string.h>
-#include <inc/assert.h>
-#include <inc/elf.h>
-#include <inc/syscall.h>
-
-#include <kern/env.h>
-#include <kern/pmap.h>
-#include <kern/trap.h>
-#include <kern/monitor.h>
-#include <kern/apic.h>
-#include <kern/smp.h>
-
-env_t *envs = NULL;            // All environments
-// TODO: make this a struct of info including the pointer and cacheline-align it
-// This lets the kernel know what process is running on the core it traps into.
-// A lot of the Env business, including this and its usage, will change when we
-// redesign the env as a multi-process.
-env_t* curenvs[MAX_NUM_CPUS] = {[0 ... (MAX_NUM_CPUS-1)] NULL};
-static env_list_t env_free_list;       // Free list
-
-#define ENVGENSHIFT    12              // >= LOGNENV
-
-//
-// Converts an envid to an env pointer.
-//
-// RETURNS
-//   0 on success, -E_BAD_ENV on error.
-//   On success, sets *env_store to the environment.
-//   On error, sets *env_store to NULL.
-//
-int
-envid2env(envid_t envid, env_t **env_store, bool checkperm)
-{
-       env_t *e;
-       env_t* curenv = curenvs[lapic_get_id()];
-
-       // If envid is zero, return the current environment.
-       if (envid == 0) {
-               *env_store = curenv;
-               return 0;
-       }
-
-       // Look up the Env structure via the index part of the envid,
-       // then check the env_id field in that env_t
-       // to ensure that the envid is not stale
-       // (i.e., does not refer to a _previous_ environment
-       // that used the same slot in the envs[] array).
-       e = &envs[ENVX(envid)];
-       if (e->env_status == ENV_FREE || e->env_id != envid) {
-               *env_store = 0;
-               return -E_BAD_ENV;
-       }
-
-       // Check that the calling environment has legitimate permission
-       // to manipulate the specified environment.
-       // If checkperm is set, the specified environment
-       // must be either the current environment
-       // or an immediate child of the current environment.
-       if (checkperm && e != curenv && e->env_parent_id != curenv->env_id) {
-               *env_store = 0;
-               return -E_BAD_ENV;
-       }
-
-       *env_store = e;
-       return 0;
-}
-
-//
-// Mark all environments in 'envs' as free, set their env_ids to 0,
-// and insert them into the env_free_list.
-// Insert in reverse order, so that the first call to env_alloc()
-// returns envs[0].
-//
-void
-env_init(void)
-{
-       int i;
-       LIST_INIT(&env_free_list);
-       for (i = NENV-1; i >= 0; i--) {
-               // these should already be set from when i memset'd the array to 0
-               envs[i].env_status = ENV_FREE;
-               envs[i].env_id = 0;
-               LIST_INSERT_HEAD(&env_free_list, &envs[i], env_link);
-       }
-}
-
-//
-// Initialize the kernel virtual memory layout for environment e.
-// Allocate a page directory, set e->env_pgdir and e->env_cr3 accordingly,
-// and initialize the kernel portion of the new environment's address space.
-// Do NOT (yet) map anything into the user portion
-// of the environment's virtual address space.
-//
-// Returns 0 on success, < 0 on error.  Errors include:
-//     -E_NO_MEM if page directory or table could not be allocated.
-//
-static int
-env_setup_vm(env_t *e)
-{
-       int i, r;
-       page_t *pgdir = NULL, *pginfo = NULL, *pgdata = NULL;
-
-       // Allocate pages for the page directory, shared info, and shared data pages
-       r = page_alloc(&pgdir);
-       r = page_alloc(&pginfo);
-       r = page_alloc(&pgdata);
-       if (r < 0) {
-               page_free(pgdir);
-               page_free(pginfo);
-               return r;
-       }
-
-       // Now, set e->env_pgdir and e->env_cr3,
-       // and initialize the page directory.
-       //
-       // Hint:
-       //    - The VA space of all envs is identical above UTOP
-       //      (except at VPT and UVPT, which we've set below).
-       //      (and not for UINFO either)
-       //      See inc/memlayout.h for permissions and layout.
-       //      Can you use boot_pgdir as a template?  Hint: Yes.
-       //      (Make sure you got the permissions right in Lab 2.)
-       //    - The initial VA below UTOP is empty.
-       //    - You do not need to make any more calls to page_alloc.
-       //    - Note: pp_ref is not maintained for most physical pages
-       //      mapped above UTOP -- but you do need to increment
-       //      env_pgdir's pp_ref!
-
-       // need to up pgdir's reference, since it will never be done elsewhere
-       pgdir->pp_ref++;
-       e->env_pgdir = page2kva(pgdir);
-       e->env_cr3 = page2pa(pgdir);
-       e->env_procinfo = page2kva(pginfo);
-       e->env_procdata = page2kva(pgdata);
-
-       memset(e->env_pgdir, 0, PGSIZE);
-       memset(e->env_procinfo, 0, PGSIZE);
-       memset(e->env_procdata, 0, PGSIZE);
-
-       // Initialize the generic syscall ring buffer
-       SHARED_RING_INIT((syscall_sring_t*)e->env_procdata);
-       // Initialize the backend of the ring buffer
-       BACK_RING_INIT(&e->env_sysbackring, (syscall_sring_t*)e->env_procdata, PGSIZE);
-
-       // should be able to do this so long as boot_pgdir never has
-       // anything put below UTOP
-       memcpy(e->env_pgdir, boot_pgdir, PGSIZE);
-
-       // something like this.  TODO, if you want
-       //memcpy(&e->env_pgdir[PDX(UTOP)], &boot_pgdir[PDX(UTOP)], PGSIZE - PDX(UTOP));
-       // check with
-       // assert(memcmp(e->env_pgdir, boot_pgdir, PGSIZE) == 0);
-
-       // VPT and UVPT map the env's own page table, with
-       // different permissions.
-       e->env_pgdir[PDX(VPT)]  = e->env_cr3 | PTE_P | PTE_W;
-       e->env_pgdir[PDX(UVPT)] = e->env_cr3 | PTE_P | PTE_U;
-
-       // Insert the per-process info and data pages into this process's pgdir
-       // I don't want to do these two pages later (like with the stack), since
-       // the kernel wants to keep pointers to it easily.
-       // Could place all of this with a function that maps a shared memory page
-       // that can work between any two address spaces or something.
-       r = page_insert(e->env_pgdir, pginfo, (void*)UINFO, PTE_U);
-       r = page_insert(e->env_pgdir, pgdata, (void*)UDATA, PTE_U | PTE_W);
-       if (r < 0) {
-               // note that we can't currently deallocate the pages created by
-               // pgdir_walk (inside insert).  should be able to gather them up when
-               // we destroy environments and their page tables.
-               page_free(pgdir);
-               page_free(pginfo);
-               page_free(pgdata);
-               return r;
-       }
-       return 0;
-}
-
-//
-// Allocates and initializes a new environment.
-// On success, the new environment is stored in *newenv_store.
-//
-// Returns 0 on success, < 0 on failure.  Errors include:
-//     -E_NO_FREE_ENV if all NENVS environments are allocated
-//     -E_NO_MEM on memory exhaustion
-//
-int
-env_alloc(env_t **newenv_store, envid_t parent_id)
-{
-       int32_t generation;
-       int r;
-       env_t *e;
-
-       if (!(e = LIST_FIRST(&env_free_list)))
-               return -E_NO_FREE_ENV;
-
-       // Allocate and set up the page directory for this environment.
-       if ((r = env_setup_vm(e)) < 0)
-               return r;
-
-       // Generate an env_id for this environment.
-       generation = (e->env_id + (1 << ENVGENSHIFT)) & ~(NENV - 1);
-       if (generation <= 0)    // Don't create a negative env_id.
-               generation = 1 << ENVGENSHIFT;
-       e->env_id = generation | (e - envs);
-
-       // Set the basic status variables.
-       e->env_parent_id = parent_id;
-       e->env_status = ENV_RUNNABLE;
-       e->env_runs = 0;
-
-       // Clear out all the saved register state,
-       // to prevent the register values
-       // of a prior environment inhabiting this Env structure
-       // from "leaking" into our new environment.
-       memset(&e->env_tf, 0, sizeof(e->env_tf));
-
-       // Set up appropriate initial values for the segment registers.
-       // GD_UD is the user data segment selector in the GDT, and
-       // GD_UT is the user text segment selector (see inc/memlayout.h).
-       // The low 2 bits of each segment register contains the
-       // Requestor Privilege Level (RPL); 3 means user mode.
-       e->env_tf.tf_ds = GD_UD | 3;
-       e->env_tf.tf_es = GD_UD | 3;
-       e->env_tf.tf_ss = GD_UD | 3;
-       e->env_tf.tf_esp = USTACKTOP;
-       e->env_tf.tf_cs = GD_UT | 3;
-       // You will set e->env_tf.tf_eip later.
-       // set the env's EFLAGSs to have interrupts enabled
-       e->env_tf.tf_eflags |= 0x00000200; // bit 9 is the interrupts-enabled
-
-       // commit the allocation
-       LIST_REMOVE(e, env_link);
-       *newenv_store = e;
-
-       e->env_tscfreq = system_timing.tsc_freq;
-       // TODO: for now, the only info at procinfo is this env's struct
-       // note that we need to copy this over every time we make a change to env
-       // that we want userspace to see.  also note that we don't even want to
-       // show them all of env, only specific things like PID, PPID, etc
-       memcpy(e->env_procinfo, e, sizeof(env_t));
-
-       env_t* curenv = curenvs[lapic_get_id()];
-
-       cprintf("[%08x] new env %08x\n", curenv ? curenv->env_id : 0, e->env_id);
-       return 0;
-}
-
-//
-// Allocate len bytes of physical memory for environment env,
-// and map it at virtual address va in the environment's address space.
-// Does not zero or otherwise initialize the mapped pages in any way.
-// Pages should be writable by user and kernel.
-// Panic if any allocation attempt fails.
-//
-static void
-segment_alloc(env_t *e, void *va, size_t len)
-{
-       void *start, *end;
-       size_t num_pages;
-       int i, r;
-       page_t *page;
-       pte_t *pte;
-
-       start = ROUNDDOWN(va, PGSIZE);
-       end = ROUNDUP(va + len, PGSIZE);
-       if (start >= end)
-               panic("Wrap-around in memory allocation addresses!");
-       if ((uintptr_t)end > UTOP)
-               panic("Attempting to map above UTOP!");
-       // page_insert/pgdir_walk alloc a page and read/write to it via its address
-       // starting from pgdir (e's), so we need to be using e's pgdir
-       assert(e->env_cr3 == rcr3());
-       num_pages = PPN(end - start);
-       for (i = 0; i < num_pages; i++, start += PGSIZE) {
-               // skip if a page is already mapped.  yes, page_insert will page_remove
-               // whatever page was already there, but if we are seg allocing adjacent
-               // regions, we don't want to destroy that old mapping/page
-               // though later on we are told we can ignore this...
-               pte = pgdir_walk(e->env_pgdir, start, 0);
-               if (pte && *pte & PTE_P)
-                       continue;
-               if ((r = page_alloc(&page)) < 0)
-                       panic("segment_alloc: %e", r);
-               page_insert(e->env_pgdir, page, start, PTE_U | PTE_W);
-       }
-}
-
-//
-// Set up the initial program binary, stack, and processor flags
-// for a user process.
-// This function is ONLY called during kernel initialization,
-// before running the first user-mode environment.
-//
-// This function loads all loadable segments from the ELF binary image
-// into the environment's user memory, starting at the appropriate
-// virtual addresses indicated in the ELF program header.
-// At the same time it clears to zero any portions of these segments
-// that are marked in the program header as being mapped
-// but not actually present in the ELF file - i.e., the program's bss section.
-//
-// All this is very similar to what our boot loader does, except the boot
-// loader also needs to read the code from disk.  Take a look at
-// boot/main.c to get ideas.
-//
-// Finally, this function maps one page for the program's initial stack.
-//
-// load_icode panics if it encounters problems.
-//  - How might load_icode fail?  What might be wrong with the given input?
-//
-static void
-load_icode(env_t *e, uint8_t *binary, size_t size)
-{
-       // Hints:
-       //  Load each program segment into virtual memory
-       //  at the address specified in the ELF section header.
-       //  You should only load segments with ph->p_type == ELF_PROG_LOAD.
-       //  Each segment's virtual address can be found in ph->p_va
-       //  and its size in memory can be found in ph->p_memsz.
-       //  The ph->p_filesz bytes from the ELF binary, starting at
-       //  'binary + ph->p_offset', should be copied to virtual address
-       //  ph->p_va.  Any remaining memory bytes should be cleared to zero.
-       //  (The ELF header should have ph->p_filesz <= ph->p_memsz.)
-       //  Use functions from the previous lab to allocate and map pages.
-       //
-       //  All page protection bits should be user read/write for now.
-       //  ELF segments are not necessarily page-aligned, but you can
-       //  assume for this function that no two segments will touch
-       //  the same virtual page.
-       //
-       //  You may find a function like segment_alloc useful.
-       //
-       //  Loading the segments is much simpler if you can move data
-       //  directly into the virtual addresses stored in the ELF binary.
-       //  So which page directory should be in force during
-       //  this function?
-       //
-       // Hint:
-       //  You must also do something with the program's entry point,
-       //  to make sure that the environment starts executing there.
-       //  What?  (See env_run() and env_pop_tf() below.)
-
-       elf_t *elfhdr = (elf_t *)binary;
-       int i, r;
-
-       // is this an elf?
-       assert(elfhdr->e_magic == ELF_MAGIC);
-       // make sure we have proghdrs to load
-       assert(elfhdr->e_phnum);
-
-       // to actually access any pages alloc'd for this environment, we
-       // need to have the hardware use this environment's page tables.
-       // we can use e's tables as long as we want, since it has the same
-       // mappings for the kernel as does boot_pgdir
-       lcr3(e->env_cr3);
-
-       proghdr_t *phdr = (proghdr_t *)(binary + elfhdr->e_phoff);
-       for (i = 0; i < elfhdr->e_phnum; i++, phdr++) {
-               if (phdr->p_type != ELF_PROG_LOAD)
-                       continue;
-               // seg alloc creates PTE_U|PTE_W pages.  if you ever want to change
-               // this, there will be issues with overlapping sections
-               segment_alloc(e, (void*)phdr->p_va, phdr->p_memsz);
-               memcpy((void*)phdr->p_va, binary + phdr->p_offset, phdr->p_filesz);
-               memset((void*)phdr->p_va + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
-       }
-
-       e->env_tf.tf_eip = elfhdr->e_entry;
-
-       // Now map one page for the program's initial stack
-       // at virtual address USTACKTOP - PGSIZE.
-
-       segment_alloc(e, (void*)(USTACKTOP - PGSIZE), PGSIZE);
-}
-
-//
-// Allocates a new env and loads the named elf binary into it.
-// This function is ONLY called during kernel initialization,
-// before running the first user-mode environment.
-// The new env's parent ID is set to 0.
-//
-// Where does the result go?
-// By convention, envs[0] is the first environment allocated, so
-// whoever calls env_create simply looks for the newly created
-// environment there.
-void
-env_create(uint8_t *binary, size_t size)
-{
-       env_t *e;
-       int r;
-
-       if ((r = env_alloc(&e, 0)) < 0)
-               panic("env_create: %e", r);
-       load_icode(e, binary, size);
-}
-
-//
-// Frees env e and all memory it uses.
-//
-void
-env_free(env_t *e)
-{
-       pte_t *pt;
-       uint32_t pdeno, pteno;
-       physaddr_t pa;
-
-       // Note the environment's demise.
-       env_t* curenv = curenvs[lapic_get_id()];
-       cprintf("[%08x] free env %08x\n", curenv ? curenv->env_id : 0, e->env_id);
-
-       // Flush all mapped pages in the user portion of the address space
-       static_assert(UTOP % PTSIZE == 0);
-       for (pdeno = 0; pdeno < PDX(UTOP); pdeno++) {
-
-               // only look at mapped page tables
-               if (!(e->env_pgdir[pdeno] & PTE_P))
-                       continue;
-
-               // find the pa and va of the page table
-               pa = PTE_ADDR(e->env_pgdir[pdeno]);
-               pt = (pte_t*) KADDR(pa);
-
-               // unmap all PTEs in this page table
-               for (pteno = 0; pteno <= PTX(~0); pteno++) {
-                       if (pt[pteno] & PTE_P)
-                               page_remove(e->env_pgdir, PGADDR(pdeno, pteno, 0));
-               }
-
-               // free the page table itself
-               e->env_pgdir[pdeno] = 0;
-               page_decref(pa2page(pa));
-       }
-
-       // need a known good pgdir before releasing the old one
-       lcr3(boot_cr3);
-
-       // free the page directory
-       pa = e->env_cr3;
-       e->env_pgdir = 0;
-       e->env_cr3 = 0;
-       page_decref(pa2page(pa));
-
-       // return the environment to the free list
-       e->env_status = ENV_FREE;
-       LIST_INSERT_HEAD(&env_free_list, e, env_link);
-}
-
-//
-// Frees environment e.
-// If e was the current env, then runs a new environment (and does not return
-// to the caller).
-//
-void
-env_destroy(env_t *e)
-{
-       env_free(e);
-
-       // for old envs that die on user cores.  since env run never returns, cores
-       // never get back to their old hlt/relaxed/spin state, so we need to force
-       // them back to an idle function.
-       uint32_t id = lapic_get_id();
-       if (id) {
-               smp_idle();
-               panic("should never see me");
-       }
-       // else we're core 0 and can do the usual
-
-       // ugly, but for now just linearly search through all possible
-       // environments for a runnable one.
-       for (int i = 0; i < NENV; i++) {
-               e = &envs[ENVX(i)];
-               if (e && e->env_status == ENV_RUNNABLE)
-                       env_run(e);
-       }
-       cprintf("Destroyed the only environment - nothing more to do!\n");
-       while (1)
-               monitor(NULL);
-}
-
-
-//
-// Restores the register values in the Trapframe with the 'iret' instruction.
-// This exits the kernel and starts executing some environment's code.
-// This function does not return.
-//
-void
-env_pop_tf(trapframe_t *tf)
-{
-       __asm __volatile("movl %0,%%esp\n"
-               "\tpopal\n"
-               "\tpopl %%es\n"
-               "\tpopl %%ds\n"
-               "\taddl $0x8,%%esp\n" /* skip tf_trapno and tf_errcode */
-               "\tiret"
-               : : "g" (tf) : "memory");
-       panic("iret failed");  /* mostly to placate the compiler */
-}
-
-//
-// Context switch from curenv to env e.
-// Note: if this is the first call to env_run, curenv is NULL.
-//  (This function does not return.)
-//
-void
-env_run(env_t *e)
-{
-       // Step 1: If this is a context switch (a new environment is running),
-       //         then set 'curenv' to the new environment,
-       //         update its 'env_runs' counter, and
-       //         and use lcr3() to switch to its address space.
-       // Step 2: Use env_pop_tf() to restore the environment's
-       //         registers and drop into user mode in the
-       //         environment.
-
-       // Hint: This function loads the new environment's state from
-       //      e->env_tf.  Go back through the code you wrote above
-       //      and make sure you have set the relevant parts of
-       //      e->env_tf to sensible values.
-
-               // would set the curenv->env_status if we had more states
-       if (e != curenvs[lapic_get_id()]) {
-               curenvs[lapic_get_id()] = e;
-               e->env_runs++;
-               lcr3(e->env_cr3);
-       }
-    env_pop_tf(&e->env_tf);
-}
-
diff --git a/kern/init.c b/kern/init.c
deleted file mode 100644 (file)
index 9b88df5..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-#ifdef __DEPUTY__
-#pragma nodeputy
-#endif
-
-#ifdef __BSD_ON_CORE_0__
-#include Everything For Free -- It just works!!
-#else
-
-#include <inc/stdio.h>
-#include <inc/string.h>
-#include <inc/assert.h>
-#include <inc/multiboot.h>
-#include <inc/stab.h>
-#include <inc/x86.h>
-
-#include <kern/monitor.h>
-#include <kern/console.h>
-#include <kern/pmap.h>
-#include <kern/kclock.h>
-#include <kern/env.h>
-#include <kern/trap.h>
-#include <kern/apic.h>
-#include <kern/testing.h>
-#include <kern/atomic.h>
-#include <kern/smp.h>
-#include <kern/syscall.h>
-
-static void print_cpuinfo(void);
-
-static void run_env_handler(trapframe_t *tf, void* data)
-{
-       assert(data);
-       env_run((env_t*)data);
-}
-
-void kernel_init(multiboot_info_t *mboot_info)
-{
-       extern char (BND(__this, end) edata)[], (SNT end)[];
-
-       // Before doing anything else, complete the ELF loading process.
-       // Clear the uninitialized global data (BSS) section of our program.
-       // This ensures that all static/global variables start out zero.
-       memset(edata, 0, end - edata);
-
-       // Initialize the console.
-       // Can't call cprintf until after we do this!
-       cons_init();
-
-       print_cpuinfo();
-
-       i386_detect_memory((multiboot_info_t*)((uint32_t)mboot_info + KERNBASE));
-       i386_print_memory_map((multiboot_info_t*)((uint32_t)mboot_info + KERNBASE));
-       i386_vm_init();
-       page_init();
-       page_check();
-
-       env_init();
-       idt_init();
-       sysenter_init();
-       timer_init();
-       // this returns when all other cores are done and ready to receive IPIs
-       smp_boot();
-       /*
-       test_smp_call_functions();
-       test_checklists();
-       test_barrier();
-       test_print_info();
-       test_lapic_status_bit();
-       test_ipi_sending();
-       test_pit();
-       */
-
-       //ENV_CREATE(user_faultread);
-       //ENV_CREATE(user_faultreadkernel);
-       //ENV_CREATE(user_faultwrite);
-       //ENV_CREATE(user_faultwritekernel);
-       //ENV_CREATE(user_breakpoint);
-       //ENV_CREATE(user_badsegment);
-       //ENV_CREATE(user_divzero);
-       //ENV_CREATE(user_buggyhello);
-       //ENV_CREATE(user_evilhello);
-       //ENV_CREATE(user_hello);
-       //ENV_CREATE(user_hello);
-       //ENV_CREATE(user_hello);
-       //ENV_CREATE(user_hello);
-       ENV_CREATE(user_null);
-       ENV_CREATE(user_null);
-       env_run(&envs[0]);
-       //env_run(&envs[1]);
-       panic("Don't Panic");
-       // ENV_CREATE(user_null);
-       /*ENV_CREATE(user_null);
-       ENV_CREATE(user_null);
-
-       //env_run(&envs[0]);
-       smp_call_function_single(2, run_env_handler, &envs[0], 0);
-       //smp_call_function_single(4, run_env_handler, &envs[1], 0);
-       //smp_call_function_single(6, run_env_handler, &envs[2], 0);
-
-       // wait 5 sec, then print what's in shared mem
-       udelay(5000000);
-       printk("Servicing syscalls from Core 0:\n\n");
-       while (1) {
-               process_generic_syscalls(&envs[0], 1);
-               //process_generic_syscalls(&envs[1], 1);
-               //process_generic_syscalls(&envs[2], 1);
-               cpu_relax();
-       }
-       panic("Don't Panic");
-       */
-}
-
-/*
- * Panic is called on unresolvable fatal errors.
- * It prints "panic: mesg", and then enters the kernel monitor.
- */
-void _panic(const char *file, int line, const char *fmt,...)
-{
-       va_list ap;
-
-       va_start(ap, fmt);
-       cprintf("kernel panic at %s:%d, from core %d: ", file, line, lapic_get_id());
-       vcprintf(fmt, ap);
-       cprintf("\n");
-       va_end(ap);
-
-dead:
-       /* break into the kernel monitor, if we're core 0 */
-       if (lapic_get_id()) {
-               smp_idle();
-               panic("should never see me");
-       }
-       while (1)
-               monitor(NULL);
-}
-
-/* like panic, but don't */
-void _warn(const char *file, int line, const char *fmt,...)
-{
-       va_list ap;
-
-       va_start(ap, fmt);
-       cprintf("kernel warning at %s:%d, from core %d: ", file, line, lapic_get_id());
-       vcprintf(fmt, ap);
-       cprintf("\n");
-       va_end(ap);
-}
-
-static void print_cpuinfo(void) {
-       uint32_t eax, ebx, ecx, edx;
-       uint32_t model, family;
-       uint64_t msr_val;
-       char vendor_id[13];
-
-       asm volatile ("cpuid;"
-                  "movl    %%ebx, (%2);"
-                  "movl    %%edx, 4(%2);"
-                  "movl    %%ecx, 8(%2);"
-                     : "=a"(eax)
-                                 : "a"(0), "D"(vendor_id)
-                     : "%ebx", "%ecx", "%edx");
-
-       vendor_id[12] = '\0';
-       cprintf("Vendor ID: %s\n", vendor_id);
-       cprintf("Largest Standard Function Number Supported: %d\n", eax);
-       cpuid(0x80000000, &eax, 0, 0, 0);
-       cprintf("Largest Extended Function Number Supported: 0x%08x\n", eax);
-       cpuid(1, &eax, &ebx, &ecx, &edx);
-       family = ((eax & 0x0FF00000) >> 20) + ((eax & 0x00000F00) >> 8);
-       model = ((eax & 0x000F0000) >> 12) + ((eax & 0x000000F0) >> 4);
-       cprintf("Family: %d\n", family);
-       cprintf("Model: %d\n", model);
-       cprintf("Stepping: %d\n", eax & 0x0000000F);
-       // eventually can fill this out with SDM Vol3B App B info, or
-       // better yet with stepping info.  or cpuid 8000_000{2,3,4}
-       switch ( family << 8 | model ) {
-               case(0x061a):
-                       cprintf("Processor: Core i7\n");
-                       break;
-               case(0x060f):
-                       cprintf("Processor: Core 2 Duo or Similar\n");
-                       break;
-               default:
-                       cprintf("Unknown or non-Intel CPU\n");
-       }
-       if (!(edx & 0x00000020))
-               panic("MSRs not supported!");
-       if (!(edx & 0x00001000))
-               panic("MTRRs not supported!");
-       if (!(edx & 0x00002000))
-               panic("Global Pages not supported!");
-       if (!(edx & 0x00000200))
-               panic("Local APIC Not Detected!");
-       if (ecx & 0x00200000)
-               cprintf("x2APIC Detected\n");
-       else
-               cprintf("x2APIC Not Detected\n");
-       cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
-       cprintf("Physical Address Bits: %d\n", eax & 0x000000FF);
-       cprintf("Cores per Die: %d\n", (ecx & 0x000000FF) + 1);
-    cprintf("This core's Default APIC ID: 0x%08x\n", lapic_get_default_id());
-       msr_val = read_msr(IA32_APIC_BASE);
-       if (msr_val & MSR_APIC_ENABLE)
-               cprintf("Local APIC Enabled\n");
-       else
-               cprintf("Local APIC Disabled\n");
-       if (msr_val & 0x00000100)
-               cprintf("I am the Boot Strap Processor\n");
-       else
-               cprintf("I am an Application Processor\n");
-       cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
-       if (edx & 0x00000100)
-               printk("Invariant TSC present\n");
-       else
-               printk("Invariant TSC not present\n");
-}
-
-#endif //Everything For Free
diff --git a/kern/ivylib/Makefrag b/kern/ivylib/Makefrag
new file mode 100644 (file)
index 0000000..10343de
--- /dev/null
@@ -0,0 +1,20 @@
+NATIVECC := ivycc
+
+KERN_IVYLIB_DIR = $(KERN_DIR)/ivylib
+OBJDIRS += $(KERN_IVYLIB_DIR)
+
+KERN_IVYLIB_CFLAGS   := $(KERN_CFLAGS)
+KERN_IVYLIB_SRCFILES := $(KERN_IVYLIB_DIR)/deputy.c
+KERN_IVYLIB_OBJFILES := $(patsubst $(KERN_IVYLIB_DIR)/%.c, \
+                                   $(OBJDIR)/$(KERN_IVYLIB_DIR)/%.o, \
+                                   $(KERN_IVYLIB_SRCFILES))
+
+$(OBJDIR)/$(KERN_IVYLIB_DIR)/deputy.o: $(KERN_IVYLIB_SRCFILES)
+       @echo + cc [KERN IVYLIB] $<
+       @mkdir -p $(@D)
+       $(V)$(NATIVECC) $(KERN_IVYLIB_CFLAGS) -c -o $@ $<
+
+$(OBJDIR)/$(KERN_IVYLIB_DIR)/libivykern.a: $(KERN_IVYLIB_OBJFILES)
+       @echo + ar [KERN IVYLIB] $@
+       $(V)$(AR) r $@ $(KERN_IVYLIB_OBJFILES) 2>/dev/null
+
diff --git a/kern/ivylib/deputy.c b/kern/ivylib/deputy.c
new file mode 100644 (file)
index 0000000..5596b16
--- /dev/null
@@ -0,0 +1,111 @@
+#include <inc/stdio.h>
+#include <inc/assert.h>
+#include <inc/string.h>
+
+#define IN_DEPUTY_LIBRARY
+
+// Use inline even when not optimizing for speed, since it prevents
+// warnings that would occur due to unused static functions.
+#ifdef DEPUTY_ALWAYS_STOP_ON_ERROR
+  #define INLINE inline __attribute__((always_inline))
+#else
+  #define INLINE inline
+#endif
+
+#define __LOCATION__        __FILE__, __LINE__, __FUNCTION__
+#define __LOCATION__FORMALS const char* file, int line, const char* func
+#define __LOCATION__ACTUALS file, line, func
+
+#ifndef asmlinkage
+#define asmlinkage __attribute__((regparm(0)))
+#endif
+
+#ifndef noreturn
+#define noreturn __attribute__((noreturn))
+#endif
+
+asmlinkage
+void deputy_fail_mayreturn(const char *check, const char *text,
+                           __LOCATION__FORMALS) {
+    cprintf("%s:%d: %s: Assertion failed in %s: %s\n",
+            __LOCATION__ACTUALS, check, text);
+/*
+    dump_stack();
+*/
+}
+
+asmlinkage noreturn
+void deputy_fail_noreturn_fast(void) {
+    panic("Deputy assertion failure\n");
+}
+
+int deputy_strlen(const char *str) {
+    return strlen(str);
+}
+
+char *deputy_strcpy(char *dest, const char *src) {
+    char *tmp = dest;
+    while ((*dest++ = *src++) != '\0') {
+        // do nothing
+    }
+    return tmp;
+}
+
+char *deputy_strncpy(char *dest, const char *src, size_t count) {
+    char *tmp = dest;
+    int c = count;
+    while (c >= 0) {
+        if ((*tmp = *src) != 0) src++;
+        tmp++;
+        c--;
+    }
+    return dest;
+}
+
+/* Search for a NULL starting at e and return its index */
+int deputy_findnull(const void *e, unsigned int bytes) {
+#define NULLCHECK(type) \
+    do { \
+        type *p = (type*) e; \
+        while (*p != 0) { \
+            p++; \
+        } \
+        length = (p - (type*) e); \
+    } while (0)
+
+    int length = 0;
+
+    switch (bytes) {
+        case 1:
+            NULLCHECK(char);
+            break;
+        case 2:
+            NULLCHECK(short);
+            break;
+        case 4:
+            NULLCHECK(long);
+            break;
+        default:
+            cprintf("Invalid byte size for nullcheck.\n");
+            break;
+    }
+
+    return length;
+#undef NULLCHECK
+}
+
+void *__deputy_memset(void *s, int c, unsigned int n) {
+  return memset(s, c, n);
+}
+
+void __ivy_handler_atomic_entry() __attribute__((weak));
+void __ivy_handler_atomic_entry() {return;}
+
+void __ivy_handler_atomic_exit() __attribute__((weak));
+void __ivy_handler_atomic_exit() {return;}
+
+void __ivy_handler_atomic_locks_entry(unsigned int n, ...) __attribute__((weak));
+void __ivy_handler_atomic_locks_entry(unsigned int n, ...) {return;}
+
+void __ivy_handler_atomic_locks_exit(unsigned int n, ...) __attribute__((weak));
+void __ivy_handler_atomic_locks_exit(unsigned int n, ...) {return;}
diff --git a/kern/kclock.c b/kern/kclock.c
deleted file mode 100644 (file)
index d52f8f7..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-
-/* Support for two time-related hardware gadgets: 1) the run time
- * clock with its NVRAM access functions; 2) the 8253 timer, which
- * generates interrupts on IRQ 0.
- */
-
-#include <inc/x86.h>
-
-#include <kern/kclock.h>
-
-
-unsigned
-mc146818_read(unsigned reg)
-{
-       outb(IO_RTC, reg);
-       return inb(IO_RTC+1);
-}
-
-void
-mc146818_write(unsigned reg, unsigned datum)
-{
-       outb(IO_RTC, reg);
-       outb(IO_RTC+1, datum);
-}
-
-
-
diff --git a/kern/kdebug.c b/kern/kdebug.c
deleted file mode 100644 (file)
index 15c2d4b..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-#ifdef __DEPUTY__
-#pragma nodeputy
-#endif
-
-#include <inc/stab.h>
-#include <inc/string.h>
-#include <inc/memlayout.h>
-#include <inc/assert.h>
-
-#include <kern/kdebug.h>
-#include <kern/pmap.h>
-#include <kern/env.h>
-
-extern const stab_t __STAB_BEGIN__[];  // Beginning of stabs table
-extern const stab_t __STAB_END__[];    // End of stabs table
-extern const char __STABSTR_BEGIN__[];         // Beginning of string table
-extern const char __STABSTR_END__[];           // End of string table
-
-typedef struct UserStabData {
-       const stab_t *stabs;
-       const stab_t *stab_end;
-       const char *stabstr;
-       const char *stabstr_end;
-} user_stab_data_t;
-
-
-// stab_binsearch(stabs, region_left, region_right, type, addr)
-//
-//     Some stab types are arranged in increasing order by instruction
-//     address.  For example, N_FUN stabs (stab entries with n_type ==
-//     N_FUN), which mark functions, and N_SO stabs, which mark source files.
-//
-//     Given an instruction address, this function finds the single stab
-//     entry of type 'type' that contains that address.
-//
-//     The search takes place within the range [*region_left, *region_right].
-//     Thus, to search an entire set of N stabs, you might do:
-//
-//             left = 0;
-//             right = N - 1;     /* rightmost stab */
-//             stab_binsearch(stabs, &left, &right, type, addr);
-//
-//     The search modifies *region_left and *region_right to bracket the
-//     'addr'.  *region_left points to the matching stab that contains
-//     'addr', and *region_right points just before the next stab.  If
-//     *region_left > *region_right, then 'addr' is not contained in any
-//     matching stab.
-//
-//     For example, given these N_SO stabs:
-//             Index  Type   Address
-//             0      SO     f0100000
-//             13     SO     f0100040
-//             117    SO     f0100176
-//             118    SO     f0100178
-//             555    SO     f0100652
-//             556    SO     f0100654
-//             657    SO     f0100849
-//     this code:
-//             left = 0, right = 657;
-//             stab_binsearch(stabs, &left, &right, N_SO, 0xf0100184);
-//     will exit setting left = 118, right = 554.
-//
-static void
-stab_binsearch(const stab_t *stabs, int *region_left, int *region_right,
-              int type, uintptr_t addr)
-{
-       int l = *region_left, r = *region_right, any_matches = 0;
-       
-       while (l <= r) {
-               int true_m = (l + r) / 2, m = true_m;
-               
-               // search for earliest stab with right type
-               while (m >= l && stabs[m].n_type != type)
-                       m--;
-               if (m < l) {    // no match in [l, m]
-                       l = true_m + 1;
-                       continue;
-               }
-
-               // actual binary search
-               any_matches = 1;
-               if (stabs[m].n_value < addr) {
-                       *region_left = m;
-                       l = true_m + 1;
-               } else if (stabs[m].n_value > addr) {
-                       *region_right = m - 1;
-                       r = m - 1;
-               } else {
-                       // exact match for 'addr', but continue loop to find
-                       // *region_right
-                       *region_left = m;
-                       l = m;
-                       addr++;
-               }
-       }
-
-       if (!any_matches)
-               *region_right = *region_left - 1;
-       else {
-               // find rightmost region containing 'addr'
-               for (l = *region_right;
-                    l > *region_left && stabs[l].n_type != type;
-                    l--)
-                       /* do nothing */;
-               *region_left = l;
-       }
-}
-
-
-// debuginfo_eip(addr, info)
-//
-//     Fill in the 'info' structure with information about the specified
-//     instruction address, 'addr'.  Returns 0 if information was found, and
-//     negative if not.  But even if it returns negative it has stored some
-//     information into '*info'.
-//
-int
-debuginfo_eip(uintptr_t addr, eipdebuginfo_t *info)
-{
-       const stab_t *stabs, *stab_end;
-       const char *stabstr, *stabstr_end;
-       int lfile, rfile, lfun, rfun, lline, rline;
-
-       // Initialize *info
-       info->eip_file = "<unknown>";
-       info->eip_line = 0;
-       info->eip_fn_name = "<unknown>";
-       info->eip_fn_namelen = 9;
-       info->eip_fn_addr = addr;
-       info->eip_fn_narg = 0;
-
-       // Find the relevant set of stabs
-       if (addr >= ULIM) {
-               stabs = __STAB_BEGIN__;
-               stab_end = __STAB_END__;
-               stabstr = __STABSTR_BEGIN__;
-               stabstr_end = __STABSTR_END__;
-       } else {
-               // The user-application linker script, user/user.ld,
-               // puts information about the application's stabs (equivalent
-               // to __STAB_BEGIN__, __STAB_END__, __STABSTR_BEGIN__, and
-               // __STABSTR_END__) in a structure located at virtual address
-               // USTABDATA.
-               const user_stab_data_t *usd = (const user_stab_data_t *) USTABDATA;
-
-               // Make sure this memory is valid.
-               // Return -1 if it is not.  Hint: Call user_mem_check.
-               // LAB 3: Your code here.
-               
-               stabs = usd->stabs;
-               stab_end = usd->stab_end;
-               stabstr = usd->stabstr;
-               stabstr_end = usd->stabstr_end;
-
-               // Make sure the STABS and string table memory is valid.
-               // LAB 3: Your code here.
-       }
-
-       // String table validity checks
-       if (stabstr_end <= stabstr || stabstr_end[-1] != 0)
-               return -1;
-
-       // Now we find the right stabs that define the function containing
-       // 'eip'.  First, we find the basic source file containing 'eip'.
-       // Then, we look in that source file for the function.  Then we look
-       // for the line number.
-       
-       // Search the entire set of stabs for the source file (type N_SO).
-       lfile = 0;
-       rfile = (stab_end - stabs) - 1;
-       stab_binsearch(stabs, &lfile, &rfile, N_SO, addr);
-       if (lfile == 0)
-               return -1;
-
-       // Search within that file's stabs for the function definition
-       // (N_FUN).
-       lfun = lfile;
-       rfun = rfile;
-       stab_binsearch(stabs, &lfun, &rfun, N_FUN, addr);
-
-       if (lfun <= rfun) {
-               // stabs[lfun] points to the function name
-               // in the string table, but check bounds just in case.
-               if (stabs[lfun].n_strx < stabstr_end - stabstr)
-                       info->eip_fn_name = stabstr + stabs[lfun].n_strx;
-               info->eip_fn_addr = stabs[lfun].n_value;
-               addr -= info->eip_fn_addr;
-               // Search within the function definition for the line number.
-               lline = lfun;
-               rline = rfun;
-       } else {
-               // Couldn't find function stab!  Maybe we're in an assembly
-               // file.  Search the whole file for the line number.
-               info->eip_fn_addr = addr;
-               lline = lfile;
-               rline = rfile;
-       }
-       // Ignore stuff after the colon.
-       info->eip_fn_namelen = strfind(info->eip_fn_name, ':') - info->eip_fn_name;
-       
-       // Search within [lline, rline] for the line number stab.
-       // If found, set info->eip_line to the right line number.
-       // If not found, return -1.
-       //
-       // Hint:
-       //      There's a particular stabs type used for line numbers.
-       //      Look at the STABS documentation and <inc/stab.h> to find
-       //      which one.
-       // Your code here.
-
-       stab_binsearch(stabs, &lline, &rline, N_SLINE, addr);
-       if (lline <= rline) 
-               // stabs[lline] points to the line number
-               info->eip_line = stabs[lline].n_value;
-       else
-               return -1;
-       
-       // Search backwards from the line number for the relevant filename
-       // stab.
-       // We can't just use the "lfile" stab because inlined functions
-       // can interpolate code from a different file!
-       // Such included source files use the N_SOL stab type.
-       while (lline >= lfile
-              && stabs[lline].n_type != N_SOL
-              && (stabs[lline].n_type != N_SO || !stabs[lline].n_value))
-               lline--;
-       if (lline >= lfile && stabs[lline].n_strx < stabstr_end - stabstr)
-               info->eip_file = stabstr + stabs[lline].n_strx;
-
-       // Set eip_fn_narg to the number of arguments taken by the function,
-       // or 0 if there was no containing function.
-       // Your code here.
-       info->eip_fn_narg = 0;
-       if (lfun <= rfun) {
-               lfun++;
-               while (stabs[lfun++].n_type == N_PSYM)
-                       info->eip_fn_narg++;
-       }
-       
-       return 0;
-}
diff --git a/kern/monitor.c b/kern/monitor.c
deleted file mode 100644 (file)
index 3041662..0000000
+++ /dev/null
@@ -1,285 +0,0 @@
-// Simple command-line kernel monitor useful for
-// controlling the kernel and exploring the system interactively.
-
-#ifdef __DEPUTY__
-#pragma nodeputy
-#endif
-
-#include <inc/stdio.h>
-#include <inc/string.h>
-#include <inc/memlayout.h>
-#include <inc/assert.h>
-#include <inc/x86.h>
-#include <inc/stab.h>
-
-#include <kern/console.h>
-#include <kern/monitor.h>
-#include <kern/trap.h>
-#include <kern/kdebug.h>
-#include <kern/pmap.h>
-#include <kern/apic.h>
-#include <kern/smp.h>
-#include <kern/testing.h>
-
-#define CMDBUF_SIZE    80      // enough for one VGA text line
-
-typedef struct command {
-       const char *NTS name;
-       const char *NTS desc;
-       // return -1 to force monitor to exit
-       int (*func)(int argc, char *NTS *NT COUNT(argc) argv, trapframe_t *tf);
-} command_t;
-
-static command_t commands[] = {
-       { "help", "Display this list of commands", mon_help },
-       { "kerninfo", "Display information about the kernel", mon_kerninfo },
-       { "backtrace", "Dump a backtrace", mon_backtrace },
-       { "reboot", "Take a ride to the South Bay", mon_reboot },
-       { "showmapping", "Shows VA->PA mappings between two virtual addresses (parameters)", mon_showmapping},
-       { "setmapperm", "Sets permissions on a VA->PA mapping", mon_setmapperm},
-       { "cpuinfo", "Prints CPU diagnostics", mon_cpuinfo},
-};
-#define NCOMMANDS (sizeof(commands)/sizeof(commands[0]))
-
-/***** Implementations of basic kernel monitor commands *****/
-
-int mon_help(int argc, char **argv, trapframe_t *tf)
-{
-       int i;
-
-       for (i = 0; i < NCOMMANDS; i++)
-               cprintf("%s - %s\n", commands[i].name, commands[i].desc);
-       return 0;
-}
-
-int mon_kerninfo(int argc, char **argv, trapframe_t *tf)
-{
-       extern char (SNT _start)[], (SNT etext)[], (SNT edata)[], (SNT end)[];
-
-       cprintf("Special kernel symbols:\n");
-       cprintf("  _start %08x (virt)  %08x (phys)\n", _start, (uint32_t)(_start - KERNBASE));
-       cprintf("  etext  %08x (virt)  %08x (phys)\n", etext, (uint32_t)(etext - KERNBASE));
-       cprintf("  edata  %08x (virt)  %08x (phys)\n", edata, (uint32_t)(edata - KERNBASE));
-       cprintf("  end    %08x (virt)  %08x (phys)\n", end, (uint32_t)(end - KERNBASE));
-       cprintf("Kernel executable memory footprint: %dKB\n",
-               (uint32_t)(end-_start+1023)/1024);
-       return 0;
-}
-
-static char* function_of(uint32_t address) 
-{
-       extern stab_t stab[], estab[];
-       extern char stabstr[];
-       stab_t* symtab;
-       stab_t* best_symtab = 0;
-       uint32_t best_func = 0;
-       
-       // ugly and unsorted
-       for (symtab = stab; symtab < estab; symtab++) {
-               // only consider functions, type = N_FUN
-               if ((symtab->n_type == N_FUN) && 
-                   (symtab->n_value <= address) && 
-                       (symtab->n_value > best_func)) {
-                       best_func = symtab->n_value;
-                       best_symtab = symtab;
-               }
-       }
-       // maybe the first stab really is the right one...  we'll see.
-       if (best_symtab == 0)
-               return "Function not found!";
-       return stabstr + best_symtab->n_strx;
-}
-
-int mon_backtrace(int argc, char **argv, trapframe_t *tf)
-{
-       uint32_t* ebp, eip;
-       eipdebuginfo_t debuginfo;
-       char buf[256];
-       int j, i = 1;
-       ebp = (uint32_t*)read_ebp();    
-       // this is part of the way back into the call() instruction's bytes
-       // eagle-eyed readers should be able to explain why this is good enough,
-       // and retaddr (just *(ebp + 1) is not)
-       eip = *(ebp + 1) - 1;
-       // jump back a frame (out of mon_backtrace)
-       ebp = (uint32_t*)(*ebp);
-       cprintf("Stack Backtrace:\n");
-       // on each iteration, ebp holds the stack frame and eip an addr in that func
-       while (ebp != 0) {
-               debuginfo_eip(eip, &debuginfo);
-               memset(buf, 0, 256);
-               strncpy(buf, debuginfo.eip_fn_name, MIN(debuginfo.eip_fn_namelen, 256));
-               buf[MIN(debuginfo.eip_fn_namelen, 255)] = 0;
-               cprintf("#%02d [<%x>] in %s+%x(%p) from %s:%d\n", i++,  eip, buf, 
-                       debuginfo.eip_fn_addr - (uint32_t)_start, debuginfo.eip_fn_addr, 
-                       debuginfo.eip_file, debuginfo.eip_line);
-               cprintf("    ebp: %x   Args:", ebp);
-               for (j = 0; j < MIN(debuginfo.eip_fn_narg, 5); j++)
-                       cprintf(" %08x", *(ebp + 2 + j));
-               cprintf("\n");
-               eip = *(ebp + 1) - 1;
-               ebp = (uint32_t*)(*ebp);
-       }
-       return 0;
-}
-
-int mon_reboot(int argc, char **argv, trapframe_t *tf)
-{
-       cprintf("[Irish Accent]: She's goin' down, Cap'n!\n");
-       outb(0x92, 0x3);
-       // KVM doesn't reboot yet, but this next bit will make it
-       // if you're in kernel mode and you can't do a push, when an interrupt
-       // comes in, the system just resets.  if esp = 0, there's no room left.
-       // somewhat curious about what happens in an SMP....
-       cprintf("[Irish Accent]: I'm givin' you all she's got!\n");
-       asm volatile ("movl $0, %esp; int $0");
-       // really, should never see this
-       cprintf("Sigh....\n");
-       return 0;
-}
-
-int mon_showmapping(int argc, char **argv, trapframe_t *tf)
-{
-       if (argc < 2) {
-               cprintf("Shows virtual -> physical mappings for a virtual address range.\n");
-               cprintf("Usage: showmappings START_ADDR [END_ADDR]\n");
-               return 1;
-       }
-       pde_t* pgdir = (pde_t*)vpd;
-       pte_t *pte, *pde;
-       page_t* page;
-       uintptr_t start, i;
-       size_t size;
-       start = ROUNDDOWN(strtol(argv[1], 0, 16), PGSIZE);
-       size = (argc == 2) ? 1 : strtol(argv[2], 0, 16) - start;
-       if (size/PGSIZE > 512) {
-               cprintf("Not going to do this for more than 512 items\n");
-               return 1;
-       }
-       cprintf("   Virtual    Physical  Ps Dr Ac CD WT U W\n");
-       cprintf("------------------------------------------\n");
-       for(i = 0; i < size; i += PGSIZE, start += PGSIZE) {
-               page = page_lookup(pgdir, (void*)start, &pte);
-               cprintf("%08p  ", start);
-               if (page) {
-                       pde = &pgdir[PDX(start)];
-                       // for a jumbo, pde = pte and PTE_PS (better be) = 1
-                       cprintf("%08p  %1d  %1d  %1d  %1d  %1d  %1d %1d\n", page2pa(page), 
-                              (*pte & PTE_PS) >> 7, (*pte & PTE_D) >> 6, (*pte & PTE_A) >> 5,
-                              (*pte & PTE_PCD) >> 4, (*pte & PTE_PWT) >> 3, 
-                              (*pte & *pde & PTE_U) >> 2, (*pte & *pde & PTE_W) >> 1);
-               } else
-                       cprintf("%08p\n", 0);
-       }
-       return 0;
-}
-
-int mon_setmapperm(int argc, char **argv, trapframe_t *tf)
-{
-       if (argc < 3) {
-               cprintf("Sets VIRT_ADDR's mapping's permissions to PERMS (in hex)\n");
-               cprintf("Only affects the lowest level PTE.  To adjust the PDE, do the math.\n");
-               cprintf("Be careful with this around UVPT, VPT, and friends.\n");
-               cprintf("Usage: setmapperm VIRT_ADDR PERMS\n");
-               return 1;
-       }
-       pde_t* pgdir = (pde_t*)vpd;
-       pte_t *pte, *pde;
-       page_t* page;
-       uintptr_t va;
-       va = ROUNDDOWN(strtol(argv[1], 0, 16), PGSIZE);
-       page = page_lookup(pgdir, (void*)va, &pte);
-       if (!page) {
-               cprintf("No such mapping\n");
-               return 1;
-       }
-       pde = &pgdir[PDX(va)];
-       cprintf("   Virtual    Physical  Ps Dr Ac CD WT U W\n");
-       cprintf("------------------------------------------\n");
-       cprintf("%08p  %08p  %1d  %1d  %1d  %1d  %1d  %1d %1d\n", va, page2pa(page), 
-              (*pte & PTE_PS) >> 7, (*pte & PTE_D) >> 6, (*pte & PTE_A) >> 5, 
-              (*pte & PTE_PCD) >> 4, (*pte & PTE_PWT) >> 3, (*pte & *pde & PTE_U) >> 2, 
-              (*pte & *pde & PTE_W) >> 1);
-       *pte = PTE_ADDR(*pte) | (*pte & PTE_PS) |
-              (PGOFF(strtol(argv[2], 0, 16)) & ~PTE_PS ) | PTE_P;
-       cprintf("%08p  %08p  %1d  %1d  %1d  %1d  %1d  %1d %1d\n", va, page2pa(page), 
-              (*pte & PTE_PS) >> 7, (*pte & PTE_D) >> 6, (*pte & PTE_A) >> 5, 
-              (*pte & PTE_PCD) >> 4, (*pte & PTE_PWT) >> 3, (*pte & *pde & PTE_U) >> 2, 
-              (*pte & *pde & PTE_W) >> 1);
-       return 0;
-}
-
-int mon_cpuinfo(int argc, char **argv, trapframe_t *tf)
-{
-       extern uint8_t num_cpus;
-
-       cprintf("Number of CPUs detected: %d\n", num_cpus);     
-       cprintf("Calling CPU's LAPIC ID: 0x%08x\n", lapic_get_id());
-       if (argc < 2)
-               smp_call_function_self(test_print_info_handler, 0, 0);
-       else
-               smp_call_function_single(strtol(argv[1], 0, 16),
-                                        test_print_info_handler, 0, 0);
-       return 0;
-}
-
-/***** Kernel monitor command interpreter *****/
-
-#define WHITESPACE "\t\r\n "
-#define MAXARGS 16
-
-static int runcmd(char *COUNT(CMDBUF_SIZE) real_buf, trapframe_t *tf) {
-       char *BND(real_buf, real_buf+CMDBUF_SIZE) buf = real_buf;
-       int argc;
-       char *NTS argv[MAXARGS];
-       int i;
-
-       // Parse the command buffer into whitespace-separated arguments
-       argc = 0;
-       argv[argc] = 0;
-       while (1) {
-               // gobble whitespace
-               while (*buf && strchr(WHITESPACE, *buf))
-                       *buf++ = 0;
-               if (*buf == 0)
-                       break;
-
-               // save and scan past next arg
-               if (argc == MAXARGS-1) {
-                       cprintf("Too many arguments (max %d)\n", MAXARGS);
-                       return 0;
-               }
-               //This will get fucked at runtime..... in the ASS
-               argv[argc++] = (char *NTS) TC(buf);
-               while (*buf && !strchr(WHITESPACE, *buf))
-                       buf++;
-       }
-       argv[argc] = 0;
-
-       // Lookup and invoke the command
-       if (argc == 0)
-               return 0;
-       for (i = 0; i < NCOMMANDS; i++) {
-               if (strcmp(argv[0], commands[i].name) == 0)
-                       return commands[i].func(argc, argv, tf);
-       }
-       cprintf("Unknown command '%s'\n", argv[0]);
-       return 0;
-}
-
-void monitor(trapframe_t *tf) {
-       char *buf;
-
-       cprintf("Welcome to the ROS kernel monitor!\n");
-       cprintf("Type 'help' for a list of commands.\n");
-
-       if (tf != NULL)
-               print_trapframe(tf);
-
-       while (1) {
-               buf = readline("K> ");
-               if (buf != NULL)
-                       if (runcmd(buf, tf) < 0)
-                               break;
-       }
-}
diff --git a/kern/pmap.c b/kern/pmap.c
deleted file mode 100644 (file)
index e9d3ac8..0000000
+++ /dev/null
@@ -1,1259 +0,0 @@
-/* See COPYRIGHT for copyright information. */
-#ifdef __DEPUTY__
-#pragma nodeputy
-#endif
-
-#include <inc/x86.h>
-#include <inc/mmu.h>
-#include <inc/error.h>
-#include <inc/string.h>
-#include <inc/assert.h>
-
-#include <kern/pmap.h>
-#include <kern/kclock.h>
-#include <kern/env.h>
-#include <kern/apic.h>
-#include <kern/atomic.h>
-
-// These variables are set by i386_detect_memory()
-static physaddr_t maxpa;       // Maximum physical address
-static physaddr_t maxaddrpa;   // Maximum directly addressable physical address
-size_t npage;                  // Amount of physical memory (in pages)
-size_t naddrpage;                      // Amount of addressable physical memory (in pages)
-static size_t basemem;         // Amount of base memory (in bytes)
-static size_t extmem;          // Amount of extended memory (in bytes)
-
-// These variables are set in i386_vm_init()
-pde_t* boot_pgdir;             // Virtual address of boot time page directory
-physaddr_t boot_cr3;           // Physical address of boot time page directory
-static char* boot_freemem;     // Pointer to next byte of free mem
-
-page_t *pages;         // Virtual address of physical page array
-static page_list_t page_free_list;     // Free list of physical pages
-
-extern env_t *envs;
-
-// Global descriptor table.
-//
-// The kernel and user segments are identical (except for the DPL).
-// To load the SS register, the CPL must equal the DPL.  Thus,
-// we must duplicate the segments for the user and the kernel.
-//
-segdesc_t gdt[] =
-{
-       // 0x0 - unused (always faults -- for trapping NULL far pointers)
-       SEG_NULL,
-
-       // 0x8 - kernel code segment
-       [GD_KT >> 3] = SEG(STA_X | STA_R, 0x0, 0xffffffff, 0),
-
-       // 0x10 - kernel data segment
-       [GD_KD >> 3] = SEG(STA_W, 0x0, 0xffffffff, 0),
-
-       // 0x18 - user code segment
-       [GD_UT >> 3] = SEG(STA_X | STA_R, 0x0, 0xffffffff, 3),
-
-       // 0x20 - user data segment
-       [GD_UD >> 3] = SEG(STA_W, 0x0, 0xffffffff, 3),
-
-       // 0x28 - tss, initialized in idt_init()
-       [GD_TSS >> 3] = SEG_NULL
-};
-
-pseudodesc_t gdt_pd = {
-       sizeof(gdt) - 1, (unsigned long) gdt
-};
-
-static int
-nvram_read(int r)
-{
-       return mc146818_read(r) | (mc146818_read(r + 1) << 8);
-}
-
-void i386_print_memory_map(multiboot_info_t *mbi) {
-       const char* memory_type[] = {"", "FREE", "RESERVED", "UNDEFINED", "UNDEFINED4"};
-
-
-       if(CHECK_FLAG(mbi->flags, 6)) {
-               cprintf ("mmap_addr = 0x%x, mmap_length = 0x%x\n", (unsigned long)mbi->mmap_addr,
-                                                                  (unsigned long)mbi->mmap_length);
-               
-               memory_map_t* mmap = (memory_map_t*) ((uint32_t)mbi->mmap_addr + KERNBASE);
-               while((uint32_t)mmap < ((uint32_t)mbi->mmap_addr + KERNBASE) + mbi->mmap_length) {                      
-                       cprintf ("base = 0x%08x%08x, length = 0x%08x%08x, type = %s\n",
-                               (unsigned) mmap->base_addr_high,
-                               (unsigned) mmap->base_addr_low,
-                               (unsigned) mmap->length_high,
-                               (unsigned) mmap->length_low,
-                               (unsigned) memory_type[mmap->type]);
-                       mmap = (memory_map_t*) ((uint32_t) mmap + mmap->size + sizeof (mmap->size));
-               }
-       }
-}
-
-void i386_detect_memory(multiboot_info_t *mbi)
-{
-       // Tells us how many kilobytes there are
-       basemem = ROUNDDOWN(mbi->mem_lower*1024, PGSIZE);
-       extmem = ROUNDDOWN(mbi->mem_upper*1024, PGSIZE);
-
-       // Calculate the maximum physical address based on whether
-       // or not there is any extended memory.  See comment in <inc/memlayout.h>
-       if (extmem)
-               maxpa = EXTPHYSMEM + extmem;
-       else
-               maxpa = basemem;
-
-       npage = maxpa / PGSIZE;
-       // IOAPIC - KERNBASE is the max amount of virtual addresses we can use
-       // for the physical memory mapping (aka - the KERNBASE mapping)
-       maxaddrpa = MIN(maxpa, IOAPIC_BASE - KERNBASE);
-       naddrpage = maxaddrpa / PGSIZE;
-
-       cprintf("Physical memory: %dK available, ", (int)(maxpa/1024));
-       cprintf("base = %dK, extended = %dK\n", (int)(basemem/1024), (int)(extmem/1024));
-       printk("Maximum directly addressable physical memory: %dK\n", (int)(maxaddrpa/1024));
-}
-
-bool enable_pse(void)
-{
-       uint32_t edx, cr4;
-       cpuid(1, 0, 0, 0, &edx);
-       if (edx & CPUID_PSE_SUPPORT) {
-               cr4 = rcr4();
-               cr4 |= CR4_PSE;
-               lcr4(cr4);
-               return 1;
-       } else
-               return 0;
-}
-
-// --------------------------------------------------------------
-// Set up initial memory mappings and turn on MMU.
-// --------------------------------------------------------------
-
-static void check_boot_pgdir(bool pse);
-
-//
-// Allocate n bytes of physical memory aligned on an 
-// align-byte boundary.  Align must be a power of two.
-// Return kernel virtual address.  Returned memory is uninitialized.
-//
-// If we're out of memory, boot_alloc should panic.
-// This function may ONLY be used during initialization,
-// before the page_free_list has been set up.
-// 
-static void*
-boot_alloc(uint32_t n, uint32_t align)
-{
-       extern char end[];
-       void *v;
-
-       // Initialize boot_freemem if this is the first time.
-       // 'end' is a magic symbol automatically generated by the linker,
-       // which points to the end of the kernel's bss segment -
-       // i.e., the first virtual address that the linker
-       // did _not_ assign to any kernel