├── lab1 ├── obj │ ├── .vars.INIT_CFLAGS │ ├── .vars.KERN_LDFLAGS │ ├── boot │ │ ├── boot │ │ ├── boot.o │ │ ├── boot.out │ │ └── main.o │ ├── kern │ │ ├── entry.o │ │ ├── init.o │ │ ├── kdebug.o │ │ ├── kernel │ │ ├── printf.o │ │ ├── string.o │ │ ├── console.o │ │ ├── kernel.img │ │ ├── monitor.o │ │ ├── printfmt.o │ │ ├── readline.o │ │ └── entrypgdir.o │ ├── .vars.KERN_CFLAGS │ └── .deps ├── conf │ ├── lab.mk │ └── env.mk ├── gradelib.pyc ├── .gitignore ├── inc │ ├── stdarg.h │ ├── error.h │ ├── assert.h │ ├── stdio.h │ ├── string.h │ └── elf.h ├── boot │ ├── sign.pl │ └── Makefrag ├── kern │ ├── console.h │ ├── monitor.h │ ├── kdebug.h │ ├── printf.c │ └── kernel.ld ├── lib │ └── readline.c ├── user │ └── sendpage.c ├── CODING ├── jos.out └── grade-lab1 ├── lab4 ├── obj │ ├── .vars.INIT_CFLAGS │ ├── .vars.KERN_LDFLAGS │ ├── boot │ │ ├── boot │ │ ├── boot.o │ │ ├── boot.out │ │ └── main.o │ ├── kern │ │ ├── env.o │ │ ├── entry.o │ │ ├── init.o │ │ ├── kclock.o │ │ ├── kdebug.o │ │ ├── kernel │ │ ├── lapic.o │ │ ├── picirq.o │ │ ├── pmap.o │ │ ├── printf.o │ │ ├── sched.o │ │ ├── string.o │ │ ├── trap.o │ │ ├── console.o │ │ ├── kernel.img │ │ ├── monitor.o │ │ ├── mpconfig.o │ │ ├── mpentry.o │ │ ├── printfmt.o │ │ ├── readline.o │ │ ├── spinlock.o │ │ ├── syscall.o │ │ ├── entrypgdir.o │ │ ├── trapentry.o │ │ └── init.d │ ├── lib │ │ ├── exit.o │ │ ├── fork.o │ │ ├── ipc.o │ │ ├── console.o │ │ ├── entry.o │ │ ├── libjos.a │ │ ├── libmain.o │ │ ├── panic.o │ │ ├── pfentry.o │ │ ├── pgfault.o │ │ ├── printf.o │ │ ├── string.o │ │ ├── syscall.o │ │ ├── printfmt.o │ │ └── readline.o │ ├── user │ │ ├── hello │ │ ├── idle │ │ ├── spin │ │ ├── yield │ │ ├── divzero │ │ ├── dumbfork │ │ ├── fairness │ │ ├── faultdie │ │ ├── forktree │ │ ├── hello.o │ │ ├── idle.o │ │ ├── pingpong │ │ ├── primes │ │ ├── primes.o │ │ ├── sendpage │ │ ├── softint │ │ ├── spin.o │ │ ├── testbss │ │ ├── yield.o │ │ ├── badsegment │ │ ├── breakpoint │ │ ├── buggyhello │ │ ├── divzero.o │ │ ├── dumbfork.o │ │ ├── evilhello │ │ ├── fairness.o │ │ ├── faultalloc │ │ ├── faultdie.o │ │ ├── faultread │ │ ├── faultregs │ │ ├── faultwrite │ │ ├── forktree.o │ │ ├── pingpong.o │ │ ├── pingpongs │ │ ├── sendpage.o │ │ ├── softint.o │ │ ├── testbss.o │ │ ├── badsegment.o │ │ ├── breakpoint.o │ │ ├── buggyhello.o │ │ ├── buggyhello2 │ │ ├── buggyhello2.o │ │ ├── evilhello.o │ │ ├── faultalloc.o │ │ ├── faultallocbad │ │ ├── faultnostack │ │ ├── faultread.o │ │ ├── faultregs.o │ │ ├── faultwrite.o │ │ ├── pingpongs.o │ │ ├── stresssched │ │ ├── stresssched.o │ │ ├── faultallocbad.o │ │ ├── faultbadhandler │ │ ├── faultnostack.o │ │ ├── faultreadkernel │ │ ├── faultbadhandler.o │ │ ├── faultevilhandler │ │ ├── faultevilhandler.o │ │ ├── faultreadkernel.o │ │ ├── faultwritekernel │ │ ├── faultwritekernel.o │ │ ├── hello.sym │ │ ├── idle.sym │ │ ├── yield.sym │ │ ├── badsegment.sym │ │ ├── breakpoint.sym │ │ ├── buggyhello.sym │ │ ├── evilhello.sym │ │ ├── faultread.sym │ │ ├── faultwrite.sym │ │ ├── softint.sym │ │ ├── faultbadhandler.sym │ │ ├── faultevilhandler.sym │ │ ├── faultreadkernel.sym │ │ ├── faultwritekernel.sym │ │ ├── divzero.sym │ │ ├── buggyhello2.sym │ │ ├── testbss.sym │ │ ├── dumbfork.sym │ │ ├── fairness.sym │ │ ├── faultnostack.sym │ │ ├── faultalloc.sym │ │ ├── faultdie.sym │ │ ├── faultallocbad.sym │ │ ├── spin.sym │ │ ├── stresssched.sym │ │ ├── faultregs.sym │ │ ├── forktree.sym │ │ ├── pingpong.sym │ │ ├── pingpongs.sym │ │ ├── primes.sym │ │ └── sendpage.sym │ ├── .vars.KERN_CFLAGS │ └── .vars.USER_CFLAGS ├── conf │ ├── lab.mk │ └── env.mk ├── gradelib.pyc ├── lib │ ├── exit.c │ ├── console.c │ ├── panic.c │ ├── libmain.c │ ├── readline.c │ ├── entry.S │ ├── Makefrag │ ├── printf.c │ └── pgfault.c ├── user │ ├── breakpoint.c │ ├── faultwrite.c │ ├── hello.c │ ├── softint.c │ ├── faultwritekernel.c │ ├── faultread.c │ ├── divzero.c │ ├── faultreadkernel.c │ ├── buggyhello.c │ ├── badsegment.c │ ├── faultnostack.c │ ├── faultevilhandler.c │ ├── buggyhello2.c │ ├── evilhello.c │ ├── yield.c │ ├── faultdie.c │ ├── faultbadhandler.c │ ├── Makefrag │ ├── idle.c │ ├── fairness.c │ ├── pingpong.c │ ├── faultalloc.c │ ├── forktree.c │ ├── faultallocbad.c │ ├── testbss.c │ ├── spin.c │ ├── pingpongs.c │ ├── stresssched.c │ ├── sendpage.c │ └── primes.c ├── kern │ ├── syscall.h │ ├── sched.h │ ├── kclock.c │ ├── console.h │ ├── kdebug.h │ ├── printf.c │ ├── trap.h │ ├── monitor.h │ ├── picirq.h │ ├── kclock.h │ ├── env.h │ ├── cpu.h │ ├── spinlock.h │ └── kernel.ld ├── inc │ ├── stdarg.h │ ├── syscall.h │ ├── assert.h │ ├── error.h │ ├── stdio.h │ ├── string.h │ └── elf.h ├── boot │ ├── sign.pl │ └── Makefrag ├── README.md ├── grade-lab2 ├── CODING └── grade-lab1 ├── lab2 ├── conf │ ├── lab.mk │ └── env.mk ├── .gitignore ├── inc │ ├── stdarg.h │ ├── error.h │ ├── assert.h │ ├── stdio.h │ ├── string.h │ └── elf.h ├── kern │ ├── kclock.c │ ├── console.h │ ├── kdebug.h │ ├── printf.c │ ├── monitor.h │ ├── kclock.h │ └── kernel.ld ├── boot │ ├── sign.pl │ └── Makefrag ├── lib │ └── readline.c ├── grade-lab2 ├── user │ └── sendpage.c ├── CODING └── grade-lab1 ├── lab3 ├── conf │ ├── lab.mk │ └── env.mk ├── lib │ ├── exit.c │ ├── console.c │ ├── panic.c │ ├── libmain.c │ ├── readline.c │ ├── Makefrag │ ├── entry.S │ ├── printf.c │ └── syscall.c ├── user │ ├── breakpoint.c │ ├── faultwrite.c │ ├── hello.c │ ├── softint.c │ ├── faultwritekernel.c │ ├── faultread.c │ ├── divzero.c │ ├── faultreadkernel.c │ ├── buggyhello.c │ ├── badsegment.c │ ├── buggyhello2.c │ ├── evilhello.c │ ├── Makefrag │ ├── testbss.c │ └── sendpage.c ├── .gitignore ├── inc │ ├── syscall.h │ ├── stdarg.h │ ├── error.h │ ├── assert.h │ ├── stdio.h │ ├── string.h │ ├── elf.h │ └── lib.h ├── kern │ ├── syscall.h │ ├── kclock.c │ ├── console.h │ ├── kdebug.h │ ├── printf.c │ ├── trap.h │ ├── monitor.h │ ├── kclock.h │ ├── env.h │ └── kernel.ld ├── boot │ ├── sign.pl │ └── Makefrag ├── grade-lab2 ├── CODING └── grade-lab1 ├── HW_Shell └── t.sh └── README.md /lab1/obj/.vars.INIT_CFLAGS: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lab4/obj/.vars.INIT_CFLAGS: -------------------------------------------------------------------------------- 1 | -DTEST=user_spin 2 | -------------------------------------------------------------------------------- /lab1/conf/lab.mk: -------------------------------------------------------------------------------- 1 | LAB=1 2 | PACKAGEDATE=Wed Sep 14 12:18:32 EDT 2016 3 | -------------------------------------------------------------------------------- /lab1/obj/.vars.KERN_LDFLAGS: -------------------------------------------------------------------------------- 1 | -m elf_i386 -T kern/kernel.ld -nostdlib 2 | -------------------------------------------------------------------------------- /lab2/conf/lab.mk: -------------------------------------------------------------------------------- 1 | LAB=2 2 | PACKAGEDATE=Wed Sep 21 11:13:24 EDT 2016 3 | -------------------------------------------------------------------------------- /lab3/conf/lab.mk: -------------------------------------------------------------------------------- 1 | LAB=3 2 | PACKAGEDATE=Thu Sep 29 14:25:51 EDT 2016 3 | -------------------------------------------------------------------------------- /lab4/conf/lab.mk: -------------------------------------------------------------------------------- 1 | LAB=4 2 | PACKAGEDATE=Wed Oct 12 17:19:29 EDT 2016 3 | -------------------------------------------------------------------------------- /lab4/obj/.vars.KERN_LDFLAGS: -------------------------------------------------------------------------------- 1 | -m elf_i386 -T kern/kernel.ld -nostdlib 2 | -------------------------------------------------------------------------------- /lab1/gradelib.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/gradelib.pyc -------------------------------------------------------------------------------- /lab4/gradelib.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/gradelib.pyc -------------------------------------------------------------------------------- /lab1/obj/boot/boot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/boot/boot -------------------------------------------------------------------------------- /lab4/obj/boot/boot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/boot/boot -------------------------------------------------------------------------------- /lab4/obj/kern/env.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/env.o -------------------------------------------------------------------------------- /lab4/obj/lib/exit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/exit.o -------------------------------------------------------------------------------- /lab4/obj/lib/fork.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/fork.o -------------------------------------------------------------------------------- /lab4/obj/lib/ipc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/ipc.o -------------------------------------------------------------------------------- /lab4/obj/user/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/hello -------------------------------------------------------------------------------- /lab4/obj/user/idle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/idle -------------------------------------------------------------------------------- /lab4/obj/user/spin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/spin -------------------------------------------------------------------------------- /lab4/obj/user/yield: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/yield -------------------------------------------------------------------------------- /lab1/obj/boot/boot.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/boot/boot.o -------------------------------------------------------------------------------- /lab1/obj/boot/boot.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/boot/boot.out -------------------------------------------------------------------------------- /lab1/obj/boot/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/boot/main.o -------------------------------------------------------------------------------- /lab1/obj/kern/entry.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/entry.o -------------------------------------------------------------------------------- /lab1/obj/kern/init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/init.o -------------------------------------------------------------------------------- /lab1/obj/kern/kdebug.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/kdebug.o -------------------------------------------------------------------------------- /lab1/obj/kern/kernel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/kernel -------------------------------------------------------------------------------- /lab1/obj/kern/printf.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/printf.o -------------------------------------------------------------------------------- /lab1/obj/kern/string.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/string.o -------------------------------------------------------------------------------- /lab4/obj/boot/boot.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/boot/boot.o -------------------------------------------------------------------------------- /lab4/obj/boot/boot.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/boot/boot.out -------------------------------------------------------------------------------- /lab4/obj/boot/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/boot/main.o -------------------------------------------------------------------------------- /lab4/obj/kern/entry.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/entry.o -------------------------------------------------------------------------------- /lab4/obj/kern/init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/init.o -------------------------------------------------------------------------------- /lab4/obj/kern/kclock.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/kclock.o -------------------------------------------------------------------------------- /lab4/obj/kern/kdebug.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/kdebug.o -------------------------------------------------------------------------------- /lab4/obj/kern/kernel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/kernel -------------------------------------------------------------------------------- /lab4/obj/kern/lapic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/lapic.o -------------------------------------------------------------------------------- /lab4/obj/kern/picirq.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/picirq.o -------------------------------------------------------------------------------- /lab4/obj/kern/pmap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/pmap.o -------------------------------------------------------------------------------- /lab4/obj/kern/printf.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/printf.o -------------------------------------------------------------------------------- /lab4/obj/kern/sched.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/sched.o -------------------------------------------------------------------------------- /lab4/obj/kern/string.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/string.o -------------------------------------------------------------------------------- /lab4/obj/kern/trap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/trap.o -------------------------------------------------------------------------------- /lab4/obj/lib/console.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/console.o -------------------------------------------------------------------------------- /lab4/obj/lib/entry.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/entry.o -------------------------------------------------------------------------------- /lab4/obj/lib/libjos.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/libjos.a -------------------------------------------------------------------------------- /lab4/obj/lib/libmain.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/libmain.o -------------------------------------------------------------------------------- /lab4/obj/lib/panic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/panic.o -------------------------------------------------------------------------------- /lab4/obj/lib/pfentry.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/pfentry.o -------------------------------------------------------------------------------- /lab4/obj/lib/pgfault.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/pgfault.o -------------------------------------------------------------------------------- /lab4/obj/lib/printf.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/printf.o -------------------------------------------------------------------------------- /lab4/obj/lib/string.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/string.o -------------------------------------------------------------------------------- /lab4/obj/lib/syscall.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/syscall.o -------------------------------------------------------------------------------- /lab4/obj/user/divzero: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/divzero -------------------------------------------------------------------------------- /lab4/obj/user/dumbfork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/dumbfork -------------------------------------------------------------------------------- /lab4/obj/user/fairness: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/fairness -------------------------------------------------------------------------------- /lab4/obj/user/faultdie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultdie -------------------------------------------------------------------------------- /lab4/obj/user/forktree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/forktree -------------------------------------------------------------------------------- /lab4/obj/user/hello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/hello.o -------------------------------------------------------------------------------- /lab4/obj/user/idle.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/idle.o -------------------------------------------------------------------------------- /lab4/obj/user/pingpong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/pingpong -------------------------------------------------------------------------------- /lab4/obj/user/primes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/primes -------------------------------------------------------------------------------- /lab4/obj/user/primes.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/primes.o -------------------------------------------------------------------------------- /lab4/obj/user/sendpage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/sendpage -------------------------------------------------------------------------------- /lab4/obj/user/softint: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/softint -------------------------------------------------------------------------------- /lab4/obj/user/spin.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/spin.o -------------------------------------------------------------------------------- /lab4/obj/user/testbss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/testbss -------------------------------------------------------------------------------- /lab4/obj/user/yield.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/yield.o -------------------------------------------------------------------------------- /HW_Shell/t.sh: -------------------------------------------------------------------------------- 1 | ls > y 2 | cat < y | sort | uniq | wc > y1 3 | cat y1 4 | rm y1 5 | ls | sort | uniq | wc 6 | rm y 7 | -------------------------------------------------------------------------------- /lab1/obj/kern/console.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/console.o -------------------------------------------------------------------------------- /lab1/obj/kern/kernel.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/kernel.img -------------------------------------------------------------------------------- /lab1/obj/kern/monitor.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/monitor.o -------------------------------------------------------------------------------- /lab1/obj/kern/printfmt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/printfmt.o -------------------------------------------------------------------------------- /lab1/obj/kern/readline.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/readline.o -------------------------------------------------------------------------------- /lab4/obj/kern/console.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/console.o -------------------------------------------------------------------------------- /lab4/obj/kern/kernel.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/kernel.img -------------------------------------------------------------------------------- /lab4/obj/kern/monitor.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/monitor.o -------------------------------------------------------------------------------- /lab4/obj/kern/mpconfig.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/mpconfig.o -------------------------------------------------------------------------------- /lab4/obj/kern/mpentry.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/mpentry.o -------------------------------------------------------------------------------- /lab4/obj/kern/printfmt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/printfmt.o -------------------------------------------------------------------------------- /lab4/obj/kern/readline.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/readline.o -------------------------------------------------------------------------------- /lab4/obj/kern/spinlock.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/spinlock.o -------------------------------------------------------------------------------- /lab4/obj/kern/syscall.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/syscall.o -------------------------------------------------------------------------------- /lab4/obj/lib/printfmt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/printfmt.o -------------------------------------------------------------------------------- /lab4/obj/lib/readline.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/lib/readline.o -------------------------------------------------------------------------------- /lab4/obj/user/badsegment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/badsegment -------------------------------------------------------------------------------- /lab4/obj/user/breakpoint: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/breakpoint -------------------------------------------------------------------------------- /lab4/obj/user/buggyhello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/buggyhello -------------------------------------------------------------------------------- /lab4/obj/user/divzero.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/divzero.o -------------------------------------------------------------------------------- /lab4/obj/user/dumbfork.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/dumbfork.o -------------------------------------------------------------------------------- /lab4/obj/user/evilhello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/evilhello -------------------------------------------------------------------------------- /lab4/obj/user/fairness.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/fairness.o -------------------------------------------------------------------------------- /lab4/obj/user/faultalloc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultalloc -------------------------------------------------------------------------------- /lab4/obj/user/faultdie.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultdie.o -------------------------------------------------------------------------------- /lab4/obj/user/faultread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultread -------------------------------------------------------------------------------- /lab4/obj/user/faultregs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultregs -------------------------------------------------------------------------------- /lab4/obj/user/faultwrite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultwrite -------------------------------------------------------------------------------- /lab4/obj/user/forktree.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/forktree.o -------------------------------------------------------------------------------- /lab4/obj/user/pingpong.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/pingpong.o -------------------------------------------------------------------------------- /lab4/obj/user/pingpongs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/pingpongs -------------------------------------------------------------------------------- /lab4/obj/user/sendpage.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/sendpage.o -------------------------------------------------------------------------------- /lab4/obj/user/softint.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/softint.o -------------------------------------------------------------------------------- /lab4/obj/user/testbss.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/testbss.o -------------------------------------------------------------------------------- /lab1/obj/kern/entrypgdir.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab1/obj/kern/entrypgdir.o -------------------------------------------------------------------------------- /lab4/obj/kern/entrypgdir.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/entrypgdir.o -------------------------------------------------------------------------------- /lab4/obj/kern/trapentry.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/kern/trapentry.o -------------------------------------------------------------------------------- /lab4/obj/user/badsegment.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/badsegment.o -------------------------------------------------------------------------------- /lab4/obj/user/breakpoint.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/breakpoint.o -------------------------------------------------------------------------------- /lab4/obj/user/buggyhello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/buggyhello.o -------------------------------------------------------------------------------- /lab4/obj/user/buggyhello2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/buggyhello2 -------------------------------------------------------------------------------- /lab4/obj/user/buggyhello2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/buggyhello2.o -------------------------------------------------------------------------------- /lab4/obj/user/evilhello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/evilhello.o -------------------------------------------------------------------------------- /lab4/obj/user/faultalloc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultalloc.o -------------------------------------------------------------------------------- /lab4/obj/user/faultallocbad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultallocbad -------------------------------------------------------------------------------- /lab4/obj/user/faultnostack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultnostack -------------------------------------------------------------------------------- /lab4/obj/user/faultread.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultread.o -------------------------------------------------------------------------------- /lab4/obj/user/faultregs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultregs.o -------------------------------------------------------------------------------- /lab4/obj/user/faultwrite.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultwrite.o -------------------------------------------------------------------------------- /lab4/obj/user/pingpongs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/pingpongs.o -------------------------------------------------------------------------------- /lab4/obj/user/stresssched: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/stresssched -------------------------------------------------------------------------------- /lab4/obj/user/stresssched.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/stresssched.o -------------------------------------------------------------------------------- /lab3/lib/exit.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void 5 | exit(void) 6 | { 7 | sys_env_destroy(0); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /lab4/lib/exit.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void 5 | exit(void) 6 | { 7 | sys_env_destroy(0); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /lab4/obj/user/faultallocbad.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultallocbad.o -------------------------------------------------------------------------------- /lab4/obj/user/faultbadhandler: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultbadhandler -------------------------------------------------------------------------------- /lab4/obj/user/faultnostack.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultnostack.o -------------------------------------------------------------------------------- /lab4/obj/user/faultreadkernel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultreadkernel -------------------------------------------------------------------------------- /lab4/obj/user/faultbadhandler.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultbadhandler.o -------------------------------------------------------------------------------- /lab4/obj/user/faultevilhandler: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultevilhandler -------------------------------------------------------------------------------- /lab4/obj/user/faultevilhandler.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultevilhandler.o -------------------------------------------------------------------------------- /lab4/obj/user/faultreadkernel.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultreadkernel.o -------------------------------------------------------------------------------- /lab4/obj/user/faultwritekernel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultwritekernel -------------------------------------------------------------------------------- /lab4/obj/user/faultwritekernel.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/double-free/MIT6.828-2016-Chinese/HEAD/lab4/obj/user/faultwritekernel.o -------------------------------------------------------------------------------- /lab3/user/breakpoint.c: -------------------------------------------------------------------------------- 1 | // program to cause a breakpoint trap 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | asm volatile("int $3"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab4/user/breakpoint.c: -------------------------------------------------------------------------------- 1 | // program to cause a breakpoint trap 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | asm volatile("int $3"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab1/obj/.vars.KERN_CFLAGS: -------------------------------------------------------------------------------- 1 | -O1 -fno-builtin -I. -MD -fno-omit-frame-pointer -std=gnu99 -Wall -Wno-format -Wno-unused -Werror -gstabs -m32 -fno-tree-ch -fno-stack-protector -DJOS_KERNEL -gstabs 2 | -------------------------------------------------------------------------------- /lab4/obj/.vars.KERN_CFLAGS: -------------------------------------------------------------------------------- 1 | -O1 -fno-builtin -I. -MD -fno-omit-frame-pointer -std=gnu99 -static -Wall -Wno-format -Wno-unused -Werror -gstabs -m32 -fno-tree-ch -fno-stack-protector -DJOS_KERNEL -gstabs 2 | -------------------------------------------------------------------------------- /lab4/obj/.vars.USER_CFLAGS: -------------------------------------------------------------------------------- 1 | -O1 -fno-builtin -I. -MD -fno-omit-frame-pointer -std=gnu99 -static -Wall -Wno-format -Wno-unused -Werror -gstabs -m32 -fno-tree-ch -fno-stack-protector -DJOS_USER -gstabs 2 | -------------------------------------------------------------------------------- /lab3/user/faultwrite.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a write to location zero 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | *(unsigned*)0 = 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab4/user/faultwrite.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a write to location zero 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | *(unsigned*)0 = 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab3/user/hello.c: -------------------------------------------------------------------------------- 1 | // hello, world 2 | #include 3 | 4 | void 5 | umain(int argc, char **argv) 6 | { 7 | cprintf("hello, world\n"); 8 | cprintf("i am environment %08x\n", thisenv->env_id); 9 | } 10 | -------------------------------------------------------------------------------- /lab4/user/hello.c: -------------------------------------------------------------------------------- 1 | // hello, world 2 | #include 3 | 4 | void 5 | umain(int argc, char **argv) 6 | { 7 | cprintf("hello, world\n"); 8 | cprintf("i am environment %08x\n", thisenv->env_id); 9 | } 10 | -------------------------------------------------------------------------------- /lab3/user/softint.c: -------------------------------------------------------------------------------- 1 | // buggy program - causes an illegal software interrupt 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | asm volatile("int $14"); // page fault 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab4/user/softint.c: -------------------------------------------------------------------------------- 1 | // buggy program - causes an illegal software interrupt 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | asm volatile("int $14"); // page fault 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab3/user/faultwritekernel.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a write to a kernel location 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | *(unsigned*)0xf0100000 = 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab4/user/faultwritekernel.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a write to a kernel location 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | *(unsigned*)0xf0100000 = 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab3/user/faultread.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a read from location zero 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | cprintf("I read %08x from location 0!\n", *(unsigned*)0); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab4/user/faultread.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a read from location zero 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | cprintf("I read %08x from location 0!\n", *(unsigned*)0); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab3/user/divzero.c: -------------------------------------------------------------------------------- 1 | // buggy program - causes a divide by zero exception 2 | 3 | #include 4 | 5 | int zero; 6 | 7 | void 8 | umain(int argc, char **argv) 9 | { 10 | zero = 0; 11 | cprintf("1/0 is %08x!\n", 1/zero); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lab4/user/divzero.c: -------------------------------------------------------------------------------- 1 | // buggy program - causes a divide by zero exception 2 | 3 | #include 4 | 5 | int zero; 6 | 7 | void 8 | umain(int argc, char **argv) 9 | { 10 | zero = 0; 11 | cprintf("1/0 is %08x!\n", 1/zero); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lab3/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a read from kernel space 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | cprintf("I read %08x from location 0xf0100000!\n", *(unsigned*)0xf0100000); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab4/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | // buggy program - faults with a read from kernel space 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | cprintf("I read %08x from location 0xf0100000!\n", *(unsigned*)0xf0100000); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab1/.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /jos.in 3 | /jos.log 4 | /jos.out 5 | /jos.out.* 6 | /jos.cmd 7 | /.gdbinit 8 | /wget.log 9 | /qemu.pcap 10 | /qemu.pcap.* 11 | /qemu.out 12 | /qemu.log 13 | /gradelib.pyc 14 | /lab?-handin.tar.gz 15 | /lab?/ 16 | /sol?/ 17 | /myapi.key 18 | -------------------------------------------------------------------------------- /lab2/.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /jos.in 3 | /jos.log 4 | /jos.out 5 | /jos.out.* 6 | /jos.cmd 7 | /.gdbinit 8 | /wget.log 9 | /qemu.pcap 10 | /qemu.pcap.* 11 | /qemu.out 12 | /qemu.log 13 | /gradelib.pyc 14 | /lab?-handin.tar.gz 15 | /lab?/ 16 | /sol?/ 17 | /myapi.key 18 | -------------------------------------------------------------------------------- /lab3/.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /jos.in 3 | /jos.log 4 | /jos.out 5 | /jos.out.* 6 | /jos.cmd 7 | /.gdbinit 8 | /wget.log 9 | /qemu.pcap 10 | /qemu.pcap.* 11 | /qemu.out 12 | /qemu.log 13 | /gradelib.pyc 14 | /lab?-handin.tar.gz 15 | /lab?/ 16 | /sol?/ 17 | /myapi.key 18 | -------------------------------------------------------------------------------- /lab3/inc/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_SYSCALL_H 2 | #define JOS_INC_SYSCALL_H 3 | 4 | /* system call numbers */ 5 | enum { 6 | SYS_cputs = 0, 7 | SYS_cgetc, 8 | SYS_getenvid, 9 | SYS_env_destroy, 10 | NSYSCALLS 11 | }; 12 | 13 | #endif /* !JOS_INC_SYSCALL_H */ 14 | -------------------------------------------------------------------------------- /lab3/user/buggyhello.c: -------------------------------------------------------------------------------- 1 | // buggy hello world -- unmapped pointer passed to kernel 2 | // kernel should destroy user environment in response 3 | 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | sys_cputs((char*)1, 1); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lab4/user/buggyhello.c: -------------------------------------------------------------------------------- 1 | // buggy hello world -- unmapped pointer passed to kernel 2 | // kernel should destroy user environment in response 3 | 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | sys_cputs((char*)1, 1); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lab3/user/badsegment.c: -------------------------------------------------------------------------------- 1 | // program to cause a general protection exception 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | // Try to load the kernel's TSS selector into the DS register. 9 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lab4/user/badsegment.c: -------------------------------------------------------------------------------- 1 | // program to cause a general protection exception 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | // Try to load the kernel's TSS selector into the DS register. 9 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lab4/user/faultnostack.c: -------------------------------------------------------------------------------- 1 | // test user fault handler being called with no exception stack mapped 2 | 3 | #include 4 | 5 | void _pgfault_upcall(); 6 | 7 | void 8 | umain(int argc, char **argv) 9 | { 10 | sys_env_set_pgfault_upcall(0, (void*) _pgfault_upcall); 11 | *(int*)0 = 0; 12 | } 13 | -------------------------------------------------------------------------------- /lab4/user/faultevilhandler.c: -------------------------------------------------------------------------------- 1 | // test evil pointer for user-level fault handler 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | sys_page_alloc(0, (void*) (UXSTACKTOP - PGSIZE), PTE_P|PTE_U|PTE_W); 9 | sys_env_set_pgfault_upcall(0, (void*) 0xF0100020); 10 | *(int*)0 = 0; 11 | } 12 | -------------------------------------------------------------------------------- /lab4/obj/kern/init.d: -------------------------------------------------------------------------------- 1 | obj/kern/init.o: kern/init.c inc/stdio.h inc/stdarg.h inc/string.h \ 2 | inc/types.h inc/assert.h kern/monitor.h kern/console.h kern/pmap.h \ 3 | inc/memlayout.h inc/mmu.h kern/kclock.h kern/env.h inc/env.h inc/trap.h \ 4 | kern/cpu.h kern/trap.h kern/sched.h kern/picirq.h inc/x86.h \ 5 | kern/spinlock.h 6 | -------------------------------------------------------------------------------- /lab3/user/buggyhello2.c: -------------------------------------------------------------------------------- 1 | // buggy hello world 2 -- pointed-to region extends into unmapped memory 2 | // kernel should destroy user environment in response 3 | 4 | #include 5 | 6 | const char *hello = "hello, world\n"; 7 | 8 | void 9 | umain(int argc, char **argv) 10 | { 11 | sys_cputs(hello, 1024*1024); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lab4/user/buggyhello2.c: -------------------------------------------------------------------------------- 1 | // buggy hello world 2 -- pointed-to region extends into unmapped memory 2 | // kernel should destroy user environment in response 3 | 4 | #include 5 | 6 | const char *hello = "hello, world\n"; 7 | 8 | void 9 | umain(int argc, char **argv) 10 | { 11 | sys_cputs(hello, 1024*1024); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lab3/user/evilhello.c: -------------------------------------------------------------------------------- 1 | // evil hello world -- kernel pointer passed to kernel 2 | // kernel should destroy user environment in response 3 | 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | // try to print the kernel entry point as a string! mua ha ha! 10 | sys_cputs((char*)0xf010000c, 100); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lab4/user/evilhello.c: -------------------------------------------------------------------------------- 1 | // evil hello world -- kernel pointer passed to kernel 2 | // kernel should destroy user environment in response 3 | 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | // try to print the kernel entry point as a string! mua ha ha! 10 | sys_cputs((char*)0xf010000c, 100); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lab3/kern/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_SYSCALL_H 2 | #define JOS_KERN_SYSCALL_H 3 | #ifndef JOS_KERNEL 4 | # error "This is a JOS kernel header; user programs should not #include it" 5 | #endif 6 | 7 | #include 8 | 9 | int32_t syscall(uint32_t num, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5); 10 | 11 | #endif /* !JOS_KERN_SYSCALL_H */ 12 | -------------------------------------------------------------------------------- /lab4/kern/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_SYSCALL_H 2 | #define JOS_KERN_SYSCALL_H 3 | #ifndef JOS_KERNEL 4 | # error "This is a JOS kernel header; user programs should not #include it" 5 | #endif 6 | 7 | #include 8 | 9 | int32_t syscall(uint32_t num, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5); 10 | 11 | #endif /* !JOS_KERN_SYSCALL_H */ 12 | -------------------------------------------------------------------------------- /lab4/kern/sched.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_SCHED_H 4 | #define JOS_KERN_SCHED_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | // This function does not return. 10 | void sched_yield(void) __attribute__((noreturn)); 11 | 12 | #endif // !JOS_KERN_SCHED_H 13 | -------------------------------------------------------------------------------- /lab1/inc/stdarg.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $ */ 2 | 3 | #ifndef JOS_INC_STDARG_H 4 | #define JOS_INC_STDARG_H 5 | 6 | typedef __builtin_va_list va_list; 7 | 8 | #define va_start(ap, last) __builtin_va_start(ap, last) 9 | 10 | #define va_arg(ap, type) __builtin_va_arg(ap, type) 11 | 12 | #define va_end(ap) __builtin_va_end(ap) 13 | 14 | #endif /* !JOS_INC_STDARG_H */ 15 | -------------------------------------------------------------------------------- /lab2/inc/stdarg.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $ */ 2 | 3 | #ifndef JOS_INC_STDARG_H 4 | #define JOS_INC_STDARG_H 5 | 6 | typedef __builtin_va_list va_list; 7 | 8 | #define va_start(ap, last) __builtin_va_start(ap, last) 9 | 10 | #define va_arg(ap, type) __builtin_va_arg(ap, type) 11 | 12 | #define va_end(ap) __builtin_va_end(ap) 13 | 14 | #endif /* !JOS_INC_STDARG_H */ 15 | -------------------------------------------------------------------------------- /lab3/inc/stdarg.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $ */ 2 | 3 | #ifndef JOS_INC_STDARG_H 4 | #define JOS_INC_STDARG_H 5 | 6 | typedef __builtin_va_list va_list; 7 | 8 | #define va_start(ap, last) __builtin_va_start(ap, last) 9 | 10 | #define va_arg(ap, type) __builtin_va_arg(ap, type) 11 | 12 | #define va_end(ap) __builtin_va_end(ap) 13 | 14 | #endif /* !JOS_INC_STDARG_H */ 15 | -------------------------------------------------------------------------------- /lab4/inc/stdarg.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $ */ 2 | 3 | #ifndef JOS_INC_STDARG_H 4 | #define JOS_INC_STDARG_H 5 | 6 | typedef __builtin_va_list va_list; 7 | 8 | #define va_start(ap, last) __builtin_va_start(ap, last) 9 | 10 | #define va_arg(ap, type) __builtin_va_arg(ap, type) 11 | 12 | #define va_end(ap) __builtin_va_end(ap) 13 | 14 | #endif /* !JOS_INC_STDARG_H */ 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 介绍 2 | === 3 | 这是 MIT6.828 的个人学习笔记,限于非计算机专业出身,可能会有不少纰漏,烦请大神斧正。 4 | 个人认为,操作系统是计算机专业课之中综合性很强的一门课,牵涉面广,知识点多,相对也非常难学。 5 | 6 | 大名鼎鼎的 6.828 的最大的特点就是基于实践。自己写一个操作系统,把坑都踩过一遍,自然就明白了。 7 | 8 | 进度 9 | --- 10 | - [x] **Lab 1: C, Assembly, Tools, and Bootstrapping** 11 | - [x] **Lab 2: Memory management** 12 | - [x] **Lab 3: User-Level Environments** 13 | - [x] **Lab 4: Preemptive Multitasking** 14 | - [ ] **Lab 5: File system, spawn, and sh** 15 | -------------------------------------------------------------------------------- /lab4/user/yield.c: -------------------------------------------------------------------------------- 1 | // yield the processor to other environments 2 | 3 | #include 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | int i; 9 | 10 | cprintf("Hello, I am environment %08x.\n", thisenv->env_id); 11 | for (i = 0; i < 5; i++) { 12 | sys_yield(); 13 | cprintf("Back in environment %08x, iteration %d.\n", 14 | thisenv->env_id, i); 15 | } 16 | cprintf("All done in environment %08x.\n", thisenv->env_id); 17 | } 18 | -------------------------------------------------------------------------------- /lab2/kern/kclock.c: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | /* Support for reading the NVRAM from the real-time clock. */ 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | unsigned 11 | mc146818_read(unsigned reg) 12 | { 13 | outb(IO_RTC, reg); 14 | return inb(IO_RTC+1); 15 | } 16 | 17 | void 18 | mc146818_write(unsigned reg, unsigned datum) 19 | { 20 | outb(IO_RTC, reg); 21 | outb(IO_RTC+1, datum); 22 | } 23 | -------------------------------------------------------------------------------- /lab3/kern/kclock.c: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | /* Support for reading the NVRAM from the real-time clock. */ 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | unsigned 11 | mc146818_read(unsigned reg) 12 | { 13 | outb(IO_RTC, reg); 14 | return inb(IO_RTC+1); 15 | } 16 | 17 | void 18 | mc146818_write(unsigned reg, unsigned datum) 19 | { 20 | outb(IO_RTC, reg); 21 | outb(IO_RTC+1, datum); 22 | } 23 | -------------------------------------------------------------------------------- /lab4/kern/kclock.c: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | /* Support for reading the NVRAM from the real-time clock. */ 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | unsigned 11 | mc146818_read(unsigned reg) 12 | { 13 | outb(IO_RTC, reg); 14 | return inb(IO_RTC+1); 15 | } 16 | 17 | void 18 | mc146818_write(unsigned reg, unsigned datum) 19 | { 20 | outb(IO_RTC, reg); 21 | outb(IO_RTC+1, datum); 22 | } 23 | -------------------------------------------------------------------------------- /lab3/lib/console.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void 6 | cputchar(int ch) 7 | { 8 | char c = ch; 9 | 10 | // Unlike standard Unix's putchar, 11 | // the cputchar function _always_ outputs to the system console. 12 | sys_cputs(&c, 1); 13 | } 14 | 15 | int 16 | getchar(void) 17 | { 18 | int r; 19 | // sys_cgetc does not block, but getchar should. 20 | while ((r = sys_cgetc()) == 0) 21 | ; 22 | return r; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /lab4/inc/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_SYSCALL_H 2 | #define JOS_INC_SYSCALL_H 3 | 4 | /* system call numbers */ 5 | enum { 6 | SYS_cputs = 0, 7 | SYS_cgetc, 8 | SYS_getenvid, 9 | SYS_env_destroy, 10 | SYS_page_alloc, 11 | SYS_page_map, 12 | SYS_page_unmap, 13 | SYS_exofork, 14 | SYS_env_set_status, 15 | SYS_env_set_pgfault_upcall, 16 | SYS_yield, 17 | SYS_ipc_try_send, 18 | SYS_ipc_recv, 19 | NSYSCALLS 20 | }; 21 | 22 | #endif /* !JOS_INC_SYSCALL_H */ 23 | -------------------------------------------------------------------------------- /lab4/lib/console.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void 6 | cputchar(int ch) 7 | { 8 | char c = ch; 9 | 10 | // Unlike standard Unix's putchar, 11 | // the cputchar function _always_ outputs to the system console. 12 | sys_cputs(&c, 1); 13 | } 14 | 15 | int 16 | getchar(void) 17 | { 18 | int r; 19 | // sys_cgetc does not block, but getchar should. 20 | while ((r = sys_cgetc()) == 0) 21 | sys_yield(); 22 | return r; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /lab4/user/faultdie.c: -------------------------------------------------------------------------------- 1 | // test user-level fault handler -- just exit when we fault 2 | 3 | #include 4 | 5 | void 6 | handler(struct UTrapframe *utf) 7 | { 8 | void *addr = (void*)utf->utf_fault_va; 9 | uint32_t err = utf->utf_err; 10 | cprintf("i faulted at va %x, err %x\n", addr, err & 7); 11 | sys_env_destroy(sys_getenvid()); 12 | } 13 | 14 | void 15 | umain(int argc, char **argv) 16 | { 17 | set_pgfault_handler(handler); 18 | *(int*)0xDeadBeef = 0; 19 | } 20 | -------------------------------------------------------------------------------- /lab1/boot/sign.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | open(BB, $ARGV[0]) || die "open $ARGV[0]: $!"; 4 | 5 | binmode BB; 6 | my $buf; 7 | read(BB, $buf, 1000); 8 | $n = length($buf); 9 | 10 | if($n > 510){ 11 | print STDERR "boot block too large: $n bytes (max 510)\n"; 12 | exit 1; 13 | } 14 | 15 | print STDERR "boot block is $n bytes (max 510)\n"; 16 | 17 | $buf .= "\0" x (510-$n); 18 | $buf .= "\x55\xAA"; 19 | 20 | open(BB, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; 21 | binmode BB; 22 | print BB $buf; 23 | close BB; 24 | -------------------------------------------------------------------------------- /lab2/boot/sign.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | open(BB, $ARGV[0]) || die "open $ARGV[0]: $!"; 4 | 5 | binmode BB; 6 | my $buf; 7 | read(BB, $buf, 1000); 8 | $n = length($buf); 9 | 10 | if($n > 510){ 11 | print STDERR "boot block too large: $n bytes (max 510)\n"; 12 | exit 1; 13 | } 14 | 15 | print STDERR "boot block is $n bytes (max 510)\n"; 16 | 17 | $buf .= "\0" x (510-$n); 18 | $buf .= "\x55\xAA"; 19 | 20 | open(BB, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; 21 | binmode BB; 22 | print BB $buf; 23 | close BB; 24 | -------------------------------------------------------------------------------- /lab3/boot/sign.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | open(BB, $ARGV[0]) || die "open $ARGV[0]: $!"; 4 | 5 | binmode BB; 6 | my $buf; 7 | read(BB, $buf, 1000); 8 | $n = length($buf); 9 | 10 | if($n > 510){ 11 | print STDERR "boot block too large: $n bytes (max 510)\n"; 12 | exit 1; 13 | } 14 | 15 | print STDERR "boot block is $n bytes (max 510)\n"; 16 | 17 | $buf .= "\0" x (510-$n); 18 | $buf .= "\x55\xAA"; 19 | 20 | open(BB, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; 21 | binmode BB; 22 | print BB $buf; 23 | close BB; 24 | -------------------------------------------------------------------------------- /lab4/boot/sign.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | open(BB, $ARGV[0]) || die "open $ARGV[0]: $!"; 4 | 5 | binmode BB; 6 | my $buf; 7 | read(BB, $buf, 1000); 8 | $n = length($buf); 9 | 10 | if($n > 510){ 11 | print STDERR "boot block too large: $n bytes (max 510)\n"; 12 | exit 1; 13 | } 14 | 15 | print STDERR "boot block is $n bytes (max 510)\n"; 16 | 17 | $buf .= "\0" x (510-$n); 18 | $buf .= "\x55\xAA"; 19 | 20 | open(BB, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; 21 | binmode BB; 22 | print BB $buf; 23 | close BB; 24 | -------------------------------------------------------------------------------- /lab4/user/faultbadhandler.c: -------------------------------------------------------------------------------- 1 | // test bad pointer for user-level fault handler 2 | // this is going to fault in the fault handler accessing eip (always!) 3 | // so eventually the kernel kills it (PFM_KILL) because 4 | // we outrun the stack with invocations of the user-level handler 5 | 6 | #include 7 | 8 | void 9 | umain(int argc, char **argv) 10 | { 11 | sys_page_alloc(0, (void*) (UXSTACKTOP - PGSIZE), PTE_P|PTE_U|PTE_W); 12 | sys_env_set_pgfault_upcall(0, (void*) 0xDeadBeef); 13 | *(int*)0 = 0; 14 | } 15 | -------------------------------------------------------------------------------- /lab3/user/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += user 2 | 3 | 4 | USERLIBS += jos 5 | 6 | $(OBJDIR)/user/%.o: user/%.c $(OBJDIR)/.vars.USER_CFLAGS 7 | @echo + cc[USER] $< 8 | @mkdir -p $(@D) 9 | $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $< 10 | 11 | $(OBJDIR)/user/%: $(OBJDIR)/user/%.o $(OBJDIR)/lib/entry.o $(USERLIBS:%=$(OBJDIR)/lib/lib%.a) user/user.ld 12 | @echo + ld $@ 13 | $(V)$(LD) -o $@ $(ULDFLAGS) $(LDFLAGS) -nostdlib $(OBJDIR)/lib/entry.o $@.o -L$(OBJDIR)/lib $(USERLIBS:%=-l%) $(GCC_LIB) 14 | $(V)$(OBJDUMP) -S $@ > $@.asm 15 | $(V)$(NM) -n $@ > $@.sym 16 | 17 | -------------------------------------------------------------------------------- /lab4/user/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += user 2 | 3 | 4 | USERLIBS += jos 5 | 6 | $(OBJDIR)/user/%.o: user/%.c $(OBJDIR)/.vars.USER_CFLAGS 7 | @echo + cc[USER] $< 8 | @mkdir -p $(@D) 9 | $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $< 10 | 11 | $(OBJDIR)/user/%: $(OBJDIR)/user/%.o $(OBJDIR)/lib/entry.o $(USERLIBS:%=$(OBJDIR)/lib/lib%.a) user/user.ld 12 | @echo + ld $@ 13 | $(V)$(LD) -o $@ $(ULDFLAGS) $(LDFLAGS) -nostdlib $(OBJDIR)/lib/entry.o $@.o -L$(OBJDIR)/lib $(USERLIBS:%=-l%) $(GCC_LIB) 14 | $(V)$(OBJDUMP) -S $@ > $@.asm 15 | $(V)$(NM) -n $@ > $@.sym 16 | 17 | -------------------------------------------------------------------------------- /lab4/user/idle.c: -------------------------------------------------------------------------------- 1 | // idle loop 2 | 3 | #include 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | binaryname = "idle"; 10 | 11 | // Loop forever, simply trying to yield to a different environment. 12 | // Instead of busy-waiting like this, 13 | // a better way would be to use the processor's HLT instruction 14 | // to cause the processor to stop executing until the next interrupt - 15 | // doing so allows the processor to conserve power more effectively. 16 | while (1) { 17 | sys_yield(); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /lab4/user/fairness.c: -------------------------------------------------------------------------------- 1 | // Demonstrate lack of fairness in IPC. 2 | // Start three instances of this program as envs 1, 2, and 3. 3 | // (user/idle is env 0). 4 | 5 | #include 6 | 7 | void 8 | umain(int argc, char **argv) 9 | { 10 | envid_t who, id; 11 | 12 | id = sys_getenvid(); 13 | 14 | if (thisenv == &envs[1]) { 15 | while (1) { 16 | ipc_recv(&who, 0, 0); 17 | cprintf("%x recv from %x\n", id, who); 18 | } 19 | } else { 20 | cprintf("%x loop sending to %x\n", id, envs[1].env_id); 21 | while (1) 22 | ipc_send(envs[1].env_id, 0, 0, 0); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /lab4/README.md: -------------------------------------------------------------------------------- 1 | 介绍 2 | === 3 | 在 lab4 中我们将实现多个同时运行的用户进程之间的抢占式多任务处理。 4 | 5 | 在 part A 中,我们需要给 JOS 增加多处理器支持。实现轮询( round-robin, RR )调度,并增加基本的用户程序管理系统调用( 创建和销毁进程,分配和映射内存 )。 6 | 7 | 在 part B 中,我们需要实现一个与 Unix 类似的 `fork()`,允许一个用户进程创建自己的拷贝。 8 | 9 | 在 part C中,我们会添加对进程间通信 ( IPC ) 的支持,允许不同的用户进程相互通信和同步。还要增加对硬件时钟中断和抢占的支持。 10 | 11 | 由于本次 lab 内容较多,报告将分为 [part A](https://github.com/double-free/MIT6.828-2016-Chinese/blob/master/lab4/part_A.md), [part B](https://github.com/double-free/MIT6.828-2016-Chinese/blob/master/lab4/part_B.md), [part C](https://github.com/double-free/MIT6.828-2016-Chinese/blob/master/lab4/part_C.md) 三个部分。 12 | -------------------------------------------------------------------------------- /lab3/lib/panic.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | /* 5 | * Panic is called on unresolvable fatal errors. 6 | * It prints "panic: ", then causes a breakpoint exception, 7 | * which causes JOS to enter the JOS kernel monitor. 8 | */ 9 | void 10 | _panic(const char *file, int line, const char *fmt, ...) 11 | { 12 | va_list ap; 13 | 14 | va_start(ap, fmt); 15 | 16 | // Print the panic message 17 | cprintf("[%08x] user panic in %s at %s:%d: ", 18 | sys_getenvid(), binaryname, file, line); 19 | vcprintf(fmt, ap); 20 | cprintf("\n"); 21 | 22 | // Cause a breakpoint exception 23 | while (1) 24 | asm volatile("int3"); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lab4/lib/panic.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | /* 5 | * Panic is called on unresolvable fatal errors. 6 | * It prints "panic: ", then causes a breakpoint exception, 7 | * which causes JOS to enter the JOS kernel monitor. 8 | */ 9 | void 10 | _panic(const char *file, int line, const char *fmt, ...) 11 | { 12 | va_list ap; 13 | 14 | va_start(ap, fmt); 15 | 16 | // Print the panic message 17 | cprintf("[%08x] user panic in %s at %s:%d: ", 18 | sys_getenvid(), binaryname, file, line); 19 | vcprintf(fmt, ap); 20 | cprintf("\n"); 21 | 22 | // Cause a breakpoint exception 23 | while (1) 24 | asm volatile("int3"); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lab1/kern/console.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef _CONSOLE_H_ 4 | #define _CONSOLE_H_ 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #include 10 | 11 | #define MONO_BASE 0x3B4 12 | #define MONO_BUF 0xB0000 13 | #define CGA_BASE 0x3D4 14 | #define CGA_BUF 0xB8000 15 | 16 | #define CRT_ROWS 25 17 | #define CRT_COLS 80 18 | #define CRT_SIZE (CRT_ROWS * CRT_COLS) 19 | 20 | void cons_init(void); 21 | int cons_getc(void); 22 | 23 | void kbd_intr(void); // irq 1 24 | void serial_intr(void); // irq 4 25 | 26 | #endif /* _CONSOLE_H_ */ 27 | -------------------------------------------------------------------------------- /lab2/kern/console.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef _CONSOLE_H_ 4 | #define _CONSOLE_H_ 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #include 10 | 11 | #define MONO_BASE 0x3B4 12 | #define MONO_BUF 0xB0000 13 | #define CGA_BASE 0x3D4 14 | #define CGA_BUF 0xB8000 15 | 16 | #define CRT_ROWS 25 17 | #define CRT_COLS 80 18 | #define CRT_SIZE (CRT_ROWS * CRT_COLS) 19 | 20 | void cons_init(void); 21 | int cons_getc(void); 22 | 23 | void kbd_intr(void); // irq 1 24 | void serial_intr(void); // irq 4 25 | 26 | #endif /* _CONSOLE_H_ */ 27 | -------------------------------------------------------------------------------- /lab3/kern/console.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef _CONSOLE_H_ 4 | #define _CONSOLE_H_ 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #include 10 | 11 | #define MONO_BASE 0x3B4 12 | #define MONO_BUF 0xB0000 13 | #define CGA_BASE 0x3D4 14 | #define CGA_BUF 0xB8000 15 | 16 | #define CRT_ROWS 25 17 | #define CRT_COLS 80 18 | #define CRT_SIZE (CRT_ROWS * CRT_COLS) 19 | 20 | void cons_init(void); 21 | int cons_getc(void); 22 | 23 | void kbd_intr(void); // irq 1 24 | void serial_intr(void); // irq 4 25 | 26 | #endif /* _CONSOLE_H_ */ 27 | -------------------------------------------------------------------------------- /lab4/kern/console.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef _CONSOLE_H_ 4 | #define _CONSOLE_H_ 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #include 10 | 11 | #define MONO_BASE 0x3B4 12 | #define MONO_BUF 0xB0000 13 | #define CGA_BASE 0x3D4 14 | #define CGA_BUF 0xB8000 15 | 16 | #define CRT_ROWS 25 17 | #define CRT_COLS 80 18 | #define CRT_SIZE (CRT_ROWS * CRT_COLS) 19 | 20 | void cons_init(void); 21 | int cons_getc(void); 22 | 23 | void kbd_intr(void); // irq 1 24 | void serial_intr(void); // irq 4 25 | 26 | #endif /* _CONSOLE_H_ */ 27 | -------------------------------------------------------------------------------- /lab1/inc/error.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ERROR_H 4 | #define JOS_INC_ERROR_H 5 | 6 | enum { 7 | // Kernel error codes -- keep in sync with list in lib/printfmt.c. 8 | E_UNSPECIFIED = 1, // Unspecified or unknown problem 9 | E_BAD_ENV , // Environment doesn't exist or otherwise 10 | // cannot be used in requested action 11 | E_INVAL , // Invalid parameter 12 | E_NO_MEM , // Request failed due to memory shortage 13 | E_NO_FREE_ENV , // Attempt to create a new environment beyond 14 | // the maximum allowed 15 | E_FAULT , // Memory fault 16 | 17 | MAXERROR 18 | }; 19 | 20 | #endif // !JOS_INC_ERROR_H */ 21 | -------------------------------------------------------------------------------- /lab2/inc/error.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ERROR_H 4 | #define JOS_INC_ERROR_H 5 | 6 | enum { 7 | // Kernel error codes -- keep in sync with list in lib/printfmt.c. 8 | E_UNSPECIFIED = 1, // Unspecified or unknown problem 9 | E_BAD_ENV , // Environment doesn't exist or otherwise 10 | // cannot be used in requested action 11 | E_INVAL , // Invalid parameter 12 | E_NO_MEM , // Request failed due to memory shortage 13 | E_NO_FREE_ENV , // Attempt to create a new environment beyond 14 | // the maximum allowed 15 | E_FAULT , // Memory fault 16 | 17 | MAXERROR 18 | }; 19 | 20 | #endif // !JOS_INC_ERROR_H */ 21 | -------------------------------------------------------------------------------- /lab3/inc/error.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ERROR_H 4 | #define JOS_INC_ERROR_H 5 | 6 | enum { 7 | // Kernel error codes -- keep in sync with list in lib/printfmt.c. 8 | E_UNSPECIFIED = 1, // Unspecified or unknown problem 9 | E_BAD_ENV , // Environment doesn't exist or otherwise 10 | // cannot be used in requested action 11 | E_INVAL , // Invalid parameter 12 | E_NO_MEM , // Request failed due to memory shortage 13 | E_NO_FREE_ENV , // Attempt to create a new environment beyond 14 | // the maximum allowed 15 | E_FAULT , // Memory fault 16 | 17 | MAXERROR 18 | }; 19 | 20 | #endif // !JOS_INC_ERROR_H */ 21 | -------------------------------------------------------------------------------- /lab4/user/pingpong.c: -------------------------------------------------------------------------------- 1 | // Ping-pong a counter between two processes. 2 | // Only need to start one of these -- splits into two with fork. 3 | 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | envid_t who; 10 | 11 | if ((who = fork()) != 0) { 12 | // get the ball rolling 13 | cprintf("send 0 from %x to %x\n", sys_getenvid(), who); 14 | ipc_send(who, 0, 0, 0); 15 | } 16 | 17 | while (1) { 18 | uint32_t i = ipc_recv(&who, 0, 0); 19 | cprintf("%x got %d from %x\n", sys_getenvid(), i, who); 20 | if (i == 10) 21 | return; 22 | i++; 23 | ipc_send(who, i, 0, 0); 24 | if (i == 10) 25 | return; 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lab1/kern/monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_MONITOR_H 2 | #define JOS_KERN_MONITOR_H 3 | #ifndef JOS_KERNEL 4 | # error "This is a JOS kernel header; user programs should not #include it" 5 | #endif 6 | 7 | struct Trapframe; 8 | 9 | // Activate the kernel monitor, 10 | // optionally providing a trap frame indicating the current state 11 | // (NULL if none). 12 | void monitor(struct Trapframe *tf); 13 | 14 | // Functions implementing monitor commands. 15 | int mon_help(int argc, char **argv, struct Trapframe *tf); 16 | int mon_kerninfo(int argc, char **argv, struct Trapframe *tf); 17 | int mon_backtrace(int argc, char **argv, struct Trapframe *tf); 18 | 19 | #endif // !JOS_KERN_MONITOR_H 20 | -------------------------------------------------------------------------------- /lab4/user/faultalloc.c: -------------------------------------------------------------------------------- 1 | // test user-level fault handler -- alloc pages to fix faults 2 | 3 | #include 4 | 5 | void 6 | handler(struct UTrapframe *utf) 7 | { 8 | int r; 9 | void *addr = (void*)utf->utf_fault_va; 10 | 11 | cprintf("fault %x\n", addr); 12 | if ((r = sys_page_alloc(0, ROUNDDOWN(addr, PGSIZE), 13 | PTE_P|PTE_U|PTE_W)) < 0) 14 | panic("allocating at %x in page fault handler: %e", addr, r); 15 | snprintf((char*) addr, 100, "this string was faulted in at %x", addr); 16 | } 17 | 18 | void 19 | umain(int argc, char **argv) 20 | { 21 | set_pgfault_handler(handler); 22 | cprintf("%s\n", (char*)0xDeadBeef); 23 | cprintf("%s\n", (char*)0xCafeBffe); 24 | } 25 | -------------------------------------------------------------------------------- /lab1/kern/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_KDEBUG_H 2 | #define JOS_KERN_KDEBUG_H 3 | 4 | #include 5 | 6 | // Debug information about a particular instruction pointer 7 | struct Eipdebuginfo { 8 | const char *eip_file; // Source code filename for EIP 9 | int eip_line; // Source code linenumber for EIP 10 | 11 | const char *eip_fn_name; // Name of function containing EIP 12 | // - Note: not null terminated! 13 | int eip_fn_namelen; // Length of function name 14 | uintptr_t eip_fn_addr; // Address of start of function 15 | int eip_fn_narg; // Number of function arguments 16 | }; 17 | 18 | int debuginfo_eip(uintptr_t eip, struct Eipdebuginfo *info); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lab2/kern/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_KDEBUG_H 2 | #define JOS_KERN_KDEBUG_H 3 | 4 | #include 5 | 6 | // Debug information about a particular instruction pointer 7 | struct Eipdebuginfo { 8 | const char *eip_file; // Source code filename for EIP 9 | int eip_line; // Source code linenumber for EIP 10 | 11 | const char *eip_fn_name; // Name of function containing EIP 12 | // - Note: not null terminated! 13 | int eip_fn_namelen; // Length of function name 14 | uintptr_t eip_fn_addr; // Address of start of function 15 | int eip_fn_narg; // Number of function arguments 16 | }; 17 | 18 | int debuginfo_eip(uintptr_t eip, struct Eipdebuginfo *info); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lab3/kern/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_KDEBUG_H 2 | #define JOS_KERN_KDEBUG_H 3 | 4 | #include 5 | 6 | // Debug information about a particular instruction pointer 7 | struct Eipdebuginfo { 8 | const char *eip_file; // Source code filename for EIP 9 | int eip_line; // Source code linenumber for EIP 10 | 11 | const char *eip_fn_name; // Name of function containing EIP 12 | // - Note: not null terminated! 13 | int eip_fn_namelen; // Length of function name 14 | uintptr_t eip_fn_addr; // Address of start of function 15 | int eip_fn_narg; // Number of function arguments 16 | }; 17 | 18 | int debuginfo_eip(uintptr_t eip, struct Eipdebuginfo *info); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lab4/kern/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_KDEBUG_H 2 | #define JOS_KERN_KDEBUG_H 3 | 4 | #include 5 | 6 | // Debug information about a particular instruction pointer 7 | struct Eipdebuginfo { 8 | const char *eip_file; // Source code filename for EIP 9 | int eip_line; // Source code linenumber for EIP 10 | 11 | const char *eip_fn_name; // Name of function containing EIP 12 | // - Note: not null terminated! 13 | int eip_fn_namelen; // Length of function name 14 | uintptr_t eip_fn_addr; // Address of start of function 15 | int eip_fn_narg; // Number of function arguments 16 | }; 17 | 18 | int debuginfo_eip(uintptr_t eip, struct Eipdebuginfo *info); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lab1/kern/printf.c: -------------------------------------------------------------------------------- 1 | // Simple implementation of cprintf console output for the kernel, 2 | // based on printfmt() and the kernel console's cputchar(). 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | static void 10 | putch(int ch, int *cnt) 11 | { 12 | cputchar(ch); 13 | *cnt++; 14 | } 15 | 16 | int 17 | vcprintf(const char *fmt, va_list ap) 18 | { 19 | int cnt = 0; 20 | 21 | vprintfmt((void*)putch, &cnt, fmt, ap); 22 | return cnt; 23 | } 24 | 25 | int 26 | cprintf(const char *fmt, ...) 27 | { 28 | va_list ap; 29 | int cnt; 30 | 31 | va_start(ap, fmt); 32 | cnt = vcprintf(fmt, ap); 33 | va_end(ap); 34 | 35 | return cnt; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lab2/kern/printf.c: -------------------------------------------------------------------------------- 1 | // Simple implementation of cprintf console output for the kernel, 2 | // based on printfmt() and the kernel console's cputchar(). 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | static void 10 | putch(int ch, int *cnt) 11 | { 12 | cputchar(ch); 13 | *cnt++; 14 | } 15 | 16 | int 17 | vcprintf(const char *fmt, va_list ap) 18 | { 19 | int cnt = 0; 20 | 21 | vprintfmt((void*)putch, &cnt, fmt, ap); 22 | return cnt; 23 | } 24 | 25 | int 26 | cprintf(const char *fmt, ...) 27 | { 28 | va_list ap; 29 | int cnt; 30 | 31 | va_start(ap, fmt); 32 | cnt = vcprintf(fmt, ap); 33 | va_end(ap); 34 | 35 | return cnt; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lab3/kern/printf.c: -------------------------------------------------------------------------------- 1 | // Simple implementation of cprintf console output for the kernel, 2 | // based on printfmt() and the kernel console's cputchar(). 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | static void 10 | putch(int ch, int *cnt) 11 | { 12 | cputchar(ch); 13 | *cnt++; 14 | } 15 | 16 | int 17 | vcprintf(const char *fmt, va_list ap) 18 | { 19 | int cnt = 0; 20 | 21 | vprintfmt((void*)putch, &cnt, fmt, ap); 22 | return cnt; 23 | } 24 | 25 | int 26 | cprintf(const char *fmt, ...) 27 | { 28 | va_list ap; 29 | int cnt; 30 | 31 | va_start(ap, fmt); 32 | cnt = vcprintf(fmt, ap); 33 | va_end(ap); 34 | 35 | return cnt; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lab4/kern/printf.c: -------------------------------------------------------------------------------- 1 | // Simple implementation of cprintf console output for the kernel, 2 | // based on printfmt() and the kernel console's cputchar(). 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | static void 10 | putch(int ch, int *cnt) 11 | { 12 | cputchar(ch); 13 | *cnt++; 14 | } 15 | 16 | int 17 | vcprintf(const char *fmt, va_list ap) 18 | { 19 | int cnt = 0; 20 | 21 | vprintfmt((void*)putch, &cnt, fmt, ap); 22 | return cnt; 23 | } 24 | 25 | int 26 | cprintf(const char *fmt, ...) 27 | { 28 | va_list ap; 29 | int cnt; 30 | 31 | va_start(ap, fmt); 32 | cnt = vcprintf(fmt, ap); 33 | va_end(ap); 34 | 35 | return cnt; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lab1/inc/assert.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ASSERT_H 4 | #define JOS_INC_ASSERT_H 5 | 6 | #include 7 | 8 | void _warn(const char*, int, const char*, ...); 9 | void _panic(const char*, int, const char*, ...) __attribute__((noreturn)); 10 | 11 | #define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__) 12 | #define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__) 13 | 14 | #define assert(x) \ 15 | do { if (!(x)) panic("assertion failed: %s", #x); } while (0) 16 | 17 | // static_assert(x) will generate a compile-time error if 'x' is false. 18 | #define static_assert(x) switch (x) case 0: case (x): 19 | 20 | #endif /* !JOS_INC_ASSERT_H */ 21 | -------------------------------------------------------------------------------- /lab2/inc/assert.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ASSERT_H 4 | #define JOS_INC_ASSERT_H 5 | 6 | #include 7 | 8 | void _warn(const char*, int, const char*, ...); 9 | void _panic(const char*, int, const char*, ...) __attribute__((noreturn)); 10 | 11 | #define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__) 12 | #define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__) 13 | 14 | #define assert(x) \ 15 | do { if (!(x)) panic("assertion failed: %s", #x); } while (0) 16 | 17 | // static_assert(x) will generate a compile-time error if 'x' is false. 18 | #define static_assert(x) switch (x) case 0: case (x): 19 | 20 | #endif /* !JOS_INC_ASSERT_H */ 21 | -------------------------------------------------------------------------------- /lab3/inc/assert.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ASSERT_H 4 | #define JOS_INC_ASSERT_H 5 | 6 | #include 7 | 8 | void _warn(const char*, int, const char*, ...); 9 | void _panic(const char*, int, const char*, ...) __attribute__((noreturn)); 10 | 11 | #define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__) 12 | #define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__) 13 | 14 | #define assert(x) \ 15 | do { if (!(x)) panic("assertion failed: %s", #x); } while (0) 16 | 17 | // static_assert(x) will generate a compile-time error if 'x' is false. 18 | #define static_assert(x) switch (x) case 0: case (x): 19 | 20 | #endif /* !JOS_INC_ASSERT_H */ 21 | -------------------------------------------------------------------------------- /lab4/inc/assert.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ASSERT_H 4 | #define JOS_INC_ASSERT_H 5 | 6 | #include 7 | 8 | void _warn(const char*, int, const char*, ...); 9 | void _panic(const char*, int, const char*, ...) __attribute__((noreturn)); 10 | 11 | #define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__) 12 | #define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__) 13 | 14 | #define assert(x) \ 15 | do { if (!(x)) panic("assertion failed: %s", #x); } while (0) 16 | 17 | // static_assert(x) will generate a compile-time error if 'x' is false. 18 | #define static_assert(x) switch (x) case 0: case (x): 19 | 20 | #endif /* !JOS_INC_ASSERT_H */ 21 | -------------------------------------------------------------------------------- /lab3/kern/trap.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_TRAP_H 4 | #define JOS_KERN_TRAP_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | /* The kernel's interrupt descriptor table */ 13 | extern struct Gatedesc idt[]; 14 | extern struct Pseudodesc idt_pd; 15 | 16 | void trap_init(void); 17 | void trap_init_percpu(void); 18 | void print_regs(struct PushRegs *regs); 19 | void print_trapframe(struct Trapframe *tf); 20 | void page_fault_handler(struct Trapframe *); 21 | void backtrace(struct Trapframe *); 22 | 23 | #endif /* JOS_KERN_TRAP_H */ 24 | -------------------------------------------------------------------------------- /lab4/kern/trap.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_TRAP_H 4 | #define JOS_KERN_TRAP_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | /* The kernel's interrupt descriptor table */ 13 | extern struct Gatedesc idt[]; 14 | extern struct Pseudodesc idt_pd; 15 | 16 | void trap_init(void); 17 | void trap_init_percpu(void); 18 | void print_regs(struct PushRegs *regs); 19 | void print_trapframe(struct Trapframe *tf); 20 | void page_fault_handler(struct Trapframe *); 21 | void backtrace(struct Trapframe *); 22 | 23 | #endif /* JOS_KERN_TRAP_H */ 24 | -------------------------------------------------------------------------------- /lab4/user/forktree.c: -------------------------------------------------------------------------------- 1 | // Fork a binary tree of processes and display their structure. 2 | 3 | #include 4 | 5 | #define DEPTH 3 6 | 7 | void forktree(const char *cur); 8 | 9 | void 10 | forkchild(const char *cur, char branch) 11 | { 12 | char nxt[DEPTH+1]; 13 | 14 | if (strlen(cur) >= DEPTH) 15 | return; 16 | 17 | snprintf(nxt, DEPTH+1, "%s%c", cur, branch); 18 | if (fork() == 0) { 19 | forktree(nxt); 20 | exit(); 21 | } 22 | } 23 | 24 | void 25 | forktree(const char *cur) 26 | { 27 | cprintf("%04x: I am '%s'\n", sys_getenvid(), cur); 28 | 29 | forkchild(cur, '0'); 30 | forkchild(cur, '1'); 31 | } 32 | 33 | void 34 | umain(int argc, char **argv) 35 | { 36 | forktree(""); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lab4/user/faultallocbad.c: -------------------------------------------------------------------------------- 1 | // test user-level fault handler -- alloc pages to fix faults 2 | // doesn't work because we sys_cputs instead of cprintf (exercise: why?) 3 | 4 | #include 5 | 6 | void 7 | handler(struct UTrapframe *utf) 8 | { 9 | int r; 10 | void *addr = (void*)utf->utf_fault_va; 11 | 12 | cprintf("fault %x\n", addr); 13 | if ((r = sys_page_alloc(0, ROUNDDOWN(addr, PGSIZE), 14 | PTE_P|PTE_U|PTE_W)) < 0) 15 | panic("allocating at %x in page fault handler: %e", addr, r); 16 | snprintf((char*) addr, 100, "this string was faulted in at %x", addr); 17 | } 18 | 19 | void 20 | umain(int argc, char **argv) 21 | { 22 | set_pgfault_handler(handler); 23 | sys_cputs((char*)0xDEADBEEF, 4); 24 | } 25 | -------------------------------------------------------------------------------- /lab3/user/testbss.c: -------------------------------------------------------------------------------- 1 | // test reads and writes to a large bss 2 | 3 | #include 4 | 5 | #define ARRAYSIZE (1024*1024) 6 | 7 | uint32_t bigarray[ARRAYSIZE]; 8 | 9 | void 10 | umain(int argc, char **argv) 11 | { 12 | int i; 13 | 14 | cprintf("Making sure bss works right...\n"); 15 | for (i = 0; i < ARRAYSIZE; i++) 16 | if (bigarray[i] != 0) 17 | panic("bigarray[%d] isn't cleared!\n", i); 18 | for (i = 0; i < ARRAYSIZE; i++) 19 | bigarray[i] = i; 20 | for (i = 0; i < ARRAYSIZE; i++) 21 | if (bigarray[i] != i) 22 | panic("bigarray[%d] didn't hold its value!\n", i); 23 | 24 | cprintf("Yes, good. Now doing a wild write off the end...\n"); 25 | bigarray[ARRAYSIZE+1024] = 0; 26 | panic("SHOULD HAVE TRAPPED!!!"); 27 | } 28 | -------------------------------------------------------------------------------- /lab4/user/testbss.c: -------------------------------------------------------------------------------- 1 | // test reads and writes to a large bss 2 | 3 | #include 4 | 5 | #define ARRAYSIZE (1024*1024) 6 | 7 | uint32_t bigarray[ARRAYSIZE]; 8 | 9 | void 10 | umain(int argc, char **argv) 11 | { 12 | int i; 13 | 14 | cprintf("Making sure bss works right...\n"); 15 | for (i = 0; i < ARRAYSIZE; i++) 16 | if (bigarray[i] != 0) 17 | panic("bigarray[%d] isn't cleared!\n", i); 18 | for (i = 0; i < ARRAYSIZE; i++) 19 | bigarray[i] = i; 20 | for (i = 0; i < ARRAYSIZE; i++) 21 | if (bigarray[i] != i) 22 | panic("bigarray[%d] didn't hold its value!\n", i); 23 | 24 | cprintf("Yes, good. Now doing a wild write off the end...\n"); 25 | bigarray[ARRAYSIZE+1024] = 0; 26 | panic("SHOULD HAVE TRAPPED!!!"); 27 | } 28 | -------------------------------------------------------------------------------- /lab3/lib/libmain.c: -------------------------------------------------------------------------------- 1 | // Called from entry.S to get us going. 2 | // entry.S already took care of defining envs, pages, uvpd, and uvpt. 3 | 4 | #include 5 | 6 | extern void umain(int argc, char **argv); 7 | 8 | const volatile struct Env *thisenv; 9 | const char *binaryname = ""; 10 | 11 | void 12 | libmain(int argc, char **argv) 13 | { 14 | // set thisenv to point at our Env structure in envs[]. 15 | // LAB 3: Your code here. 16 | // thisenv = 0; 17 | thisenv = &envs[ENVX(sys_getenvid())]; 18 | 19 | // save the name of the program so that panic() can use it 20 | if (argc > 0) 21 | binaryname = argv[0]; 22 | 23 | // call user main routine 24 | umain(argc, argv); 25 | 26 | // exit gracefully 27 | exit(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lab4/lib/libmain.c: -------------------------------------------------------------------------------- 1 | // Called from entry.S to get us going. 2 | // entry.S already took care of defining envs, pages, uvpd, and uvpt. 3 | 4 | #include 5 | 6 | extern void umain(int argc, char **argv); 7 | 8 | const volatile struct Env *thisenv; 9 | const char *binaryname = ""; 10 | 11 | void 12 | libmain(int argc, char **argv) 13 | { 14 | // set thisenv to point at our Env structure in envs[]. 15 | // LAB 3: Your code here. 16 | // thisenv = 0; 17 | thisenv = &envs[ENVX(sys_getenvid())]; 18 | 19 | // save the name of the program so that panic() can use it 20 | if (argc > 0) 21 | binaryname = argv[0]; 22 | 23 | // call user main routine 24 | umain(argc, argv); 25 | 26 | // exit gracefully 27 | exit(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lab2/kern/monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_MONITOR_H 2 | #define JOS_KERN_MONITOR_H 3 | #ifndef JOS_KERNEL 4 | # error "This is a JOS kernel header; user programs should not #include it" 5 | #endif 6 | 7 | struct Trapframe; 8 | 9 | // Activate the kernel monitor, 10 | // optionally providing a trap frame indicating the current state 11 | // (NULL if none). 12 | void monitor(struct Trapframe *tf); 13 | 14 | // Functions implementing monitor commands. 15 | int mon_help(int argc, char **argv, struct Trapframe *tf); 16 | int mon_kerninfo(int argc, char **argv, struct Trapframe *tf); 17 | int mon_backtrace(int argc, char **argv, struct Trapframe *tf); 18 | 19 | int mon_showmappings(int argc, char **argv, struct Trapframe *tf); 20 | 21 | #endif // !JOS_KERN_MONITOR_H 22 | -------------------------------------------------------------------------------- /lab3/kern/monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_MONITOR_H 2 | #define JOS_KERN_MONITOR_H 3 | #ifndef JOS_KERNEL 4 | # error "This is a JOS kernel header; user programs should not #include it" 5 | #endif 6 | 7 | struct Trapframe; 8 | 9 | // Activate the kernel monitor, 10 | // optionally providing a trap frame indicating the current state 11 | // (NULL if none). 12 | void monitor(struct Trapframe *tf); 13 | 14 | // Functions implementing monitor commands. 15 | int mon_help(int argc, char **argv, struct Trapframe *tf); 16 | int mon_kerninfo(int argc, char **argv, struct Trapframe *tf); 17 | int mon_backtrace(int argc, char **argv, struct Trapframe *tf); 18 | 19 | int mon_showmappings(int argc, char **argv, struct Trapframe *tf); 20 | 21 | #endif // !JOS_KERN_MONITOR_H 22 | -------------------------------------------------------------------------------- /lab4/kern/monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_KERN_MONITOR_H 2 | #define JOS_KERN_MONITOR_H 3 | #ifndef JOS_KERNEL 4 | # error "This is a JOS kernel header; user programs should not #include it" 5 | #endif 6 | 7 | struct Trapframe; 8 | 9 | // Activate the kernel monitor, 10 | // optionally providing a trap frame indicating the current state 11 | // (NULL if none). 12 | void monitor(struct Trapframe *tf); 13 | 14 | // Functions implementing monitor commands. 15 | int mon_help(int argc, char **argv, struct Trapframe *tf); 16 | int mon_kerninfo(int argc, char **argv, struct Trapframe *tf); 17 | int mon_backtrace(int argc, char **argv, struct Trapframe *tf); 18 | 19 | int mon_showmappings(int argc, char **argv, struct Trapframe *tf); 20 | 21 | #endif // !JOS_KERN_MONITOR_H 22 | -------------------------------------------------------------------------------- /lab4/user/spin.c: -------------------------------------------------------------------------------- 1 | // Test preemption by forking off a child process that just spins forever. 2 | // Let it run for a couple time slices, then kill it. 3 | 4 | #include 5 | 6 | void 7 | umain(int argc, char **argv) 8 | { 9 | envid_t env; 10 | 11 | cprintf("I am the parent. Forking the child...\n"); 12 | if ((env = fork()) == 0) { 13 | cprintf("I am the child. Spinning...\n"); 14 | while (1) 15 | /* do nothing */; 16 | } 17 | 18 | cprintf("I am the parent. Running the child...\n"); 19 | sys_yield(); 20 | sys_yield(); 21 | sys_yield(); 22 | sys_yield(); 23 | sys_yield(); 24 | sys_yield(); 25 | sys_yield(); 26 | sys_yield(); 27 | 28 | cprintf("I am the parent. Killing the child...\n"); 29 | sys_env_destroy(env); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lab4/inc/error.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_INC_ERROR_H 4 | #define JOS_INC_ERROR_H 5 | 6 | enum { 7 | // Kernel error codes -- keep in sync with list in lib/printfmt.c. 8 | E_UNSPECIFIED = 1, // Unspecified or unknown problem 9 | E_BAD_ENV , // Environment doesn't exist or otherwise 10 | // cannot be used in requested action 11 | E_INVAL , // Invalid parameter 12 | E_NO_MEM , // Request failed due to memory shortage 13 | E_NO_FREE_ENV , // Attempt to create a new environment beyond 14 | // the maximum allowed 15 | E_FAULT , // Memory fault 16 | 17 | E_IPC_NOT_RECV , // Attempt to send to env that is not recving 18 | E_EOF , // Unexpected end of file 19 | 20 | MAXERROR 21 | }; 22 | 23 | #endif // !JOS_INC_ERROR_H */ 24 | -------------------------------------------------------------------------------- /lab1/conf/env.mk: -------------------------------------------------------------------------------- 1 | # env.mk - configuration variables for the JOS lab 2 | 3 | # '$(V)' controls whether the lab makefiles print verbose commands (the 4 | # actual shell commands run by Make), as well as the "overview" commands 5 | # (such as '+ cc lib/readline.c'). 6 | # 7 | # For overview commands only, the line should read 'V = @'. 8 | # For overview and verbose commands, the line should read 'V ='. 9 | V = @ 10 | 11 | # If your system-standard GNU toolchain is ELF-compatible, then comment 12 | # out the following line to use those tools (as opposed to the i386-jos-elf 13 | # tools that the 6.828 make system looks for by default). 14 | # 15 | # GCCPREFIX='' 16 | 17 | # If the makefile cannot find your QEMU binary, uncomment the 18 | # following line and set it to the full path to QEMU. 19 | # 20 | # QEMU= 21 | -------------------------------------------------------------------------------- /lab2/conf/env.mk: -------------------------------------------------------------------------------- 1 | # env.mk - configuration variables for the JOS lab 2 | 3 | # '$(V)' controls whether the lab makefiles print verbose commands (the 4 | # actual shell commands run by Make), as well as the "overview" commands 5 | # (such as '+ cc lib/readline.c'). 6 | # 7 | # For overview commands only, the line should read 'V = @'. 8 | # For overview and verbose commands, the line should read 'V ='. 9 | V = @ 10 | 11 | # If your system-standard GNU toolchain is ELF-compatible, then comment 12 | # out the following line to use those tools (as opposed to the i386-jos-elf 13 | # tools that the 6.828 make system looks for by default). 14 | # 15 | # GCCPREFIX='' 16 | 17 | # If the makefile cannot find your QEMU binary, uncomment the 18 | # following line and set it to the full path to QEMU. 19 | # 20 | # QEMU= 21 | -------------------------------------------------------------------------------- /lab3/conf/env.mk: -------------------------------------------------------------------------------- 1 | # env.mk - configuration variables for the JOS lab 2 | 3 | # '$(V)' controls whether the lab makefiles print verbose commands (the 4 | # actual shell commands run by Make), as well as the "overview" commands 5 | # (such as '+ cc lib/readline.c'). 6 | # 7 | # For overview commands only, the line should read 'V = @'. 8 | # For overview and verbose commands, the line should read 'V ='. 9 | V = @ 10 | 11 | # If your system-standard GNU toolchain is ELF-compatible, then comment 12 | # out the following line to use those tools (as opposed to the i386-jos-elf 13 | # tools that the 6.828 make system looks for by default). 14 | # 15 | # GCCPREFIX='' 16 | 17 | # If the makefile cannot find your QEMU binary, uncomment the 18 | # following line and set it to the full path to QEMU. 19 | # 20 | # QEMU= 21 | -------------------------------------------------------------------------------- /lab4/conf/env.mk: -------------------------------------------------------------------------------- 1 | # env.mk - configuration variables for the JOS lab 2 | 3 | # '$(V)' controls whether the lab makefiles print verbose commands (the 4 | # actual shell commands run by Make), as well as the "overview" commands 5 | # (such as '+ cc lib/readline.c'). 6 | # 7 | # For overview commands only, the line should read 'V = @'. 8 | # For overview and verbose commands, the line should read 'V ='. 9 | V = @ 10 | 11 | # If your system-standard GNU toolchain is ELF-compatible, then comment 12 | # out the following line to use those tools (as opposed to the i386-jos-elf 13 | # tools that the 6.828 make system looks for by default). 14 | # 15 | # GCCPREFIX='' 16 | 17 | # If the makefile cannot find your QEMU binary, uncomment the 18 | # following line and set it to the full path to QEMU. 19 | # 20 | # QEMU= 21 | -------------------------------------------------------------------------------- /lab1/lib/readline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BUFLEN 1024 5 | static char buf[BUFLEN]; 6 | 7 | char * 8 | readline(const char *prompt) 9 | { 10 | int i, c, echoing; 11 | 12 | if (prompt != NULL) 13 | cprintf("%s", prompt); 14 | 15 | i = 0; 16 | echoing = iscons(0); 17 | while (1) { 18 | c = getchar(); 19 | if (c < 0) { 20 | cprintf("read error: %e\n", c); 21 | return NULL; 22 | } else if ((c == '\b' || c == '\x7f') && i > 0) { 23 | if (echoing) 24 | cputchar('\b'); 25 | i--; 26 | } else if (c >= ' ' && i < BUFLEN-1) { 27 | if (echoing) 28 | cputchar(c); 29 | buf[i++] = c; 30 | } else if (c == '\n' || c == '\r') { 31 | if (echoing) 32 | cputchar('\n'); 33 | buf[i] = 0; 34 | return buf; 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lab2/lib/readline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BUFLEN 1024 5 | static char buf[BUFLEN]; 6 | 7 | char * 8 | readline(const char *prompt) 9 | { 10 | int i, c, echoing; 11 | 12 | if (prompt != NULL) 13 | cprintf("%s", prompt); 14 | 15 | i = 0; 16 | echoing = iscons(0); 17 | while (1) { 18 | c = getchar(); 19 | if (c < 0) { 20 | cprintf("read error: %e\n", c); 21 | return NULL; 22 | } else if ((c == '\b' || c == '\x7f') && i > 0) { 23 | if (echoing) 24 | cputchar('\b'); 25 | i--; 26 | } else if (c >= ' ' && i < BUFLEN-1) { 27 | if (echoing) 28 | cputchar(c); 29 | buf[i++] = c; 30 | } else if (c == '\n' || c == '\r') { 31 | if (echoing) 32 | cputchar('\n'); 33 | buf[i] = 0; 34 | return buf; 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lab3/lib/readline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BUFLEN 1024 5 | static char buf[BUFLEN]; 6 | 7 | char * 8 | readline(const char *prompt) 9 | { 10 | int i, c, echoing; 11 | 12 | if (prompt != NULL) 13 | cprintf("%s", prompt); 14 | 15 | i = 0; 16 | echoing = iscons(0); 17 | while (1) { 18 | c = getchar(); 19 | if (c < 0) { 20 | cprintf("read error: %e\n", c); 21 | return NULL; 22 | } else if ((c == '\b' || c == '\x7f') && i > 0) { 23 | if (echoing) 24 | cputchar('\b'); 25 | i--; 26 | } else if (c >= ' ' && i < BUFLEN-1) { 27 | if (echoing) 28 | cputchar(c); 29 | buf[i++] = c; 30 | } else if (c == '\n' || c == '\r') { 31 | if (echoing) 32 | cputchar('\n'); 33 | buf[i] = 0; 34 | return buf; 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lab4/kern/picirq.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_PICIRQ_H 4 | #define JOS_KERN_PICIRQ_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #define MAX_IRQS 16 // Number of IRQs 10 | 11 | // I/O Addresses of the two 8259A programmable interrupt controllers 12 | #define IO_PIC1 0x20 // Master (IRQs 0-7) 13 | #define IO_PIC2 0xA0 // Slave (IRQs 8-15) 14 | 15 | #define IRQ_SLAVE 2 // IRQ at which slave connects to master 16 | 17 | 18 | #ifndef __ASSEMBLER__ 19 | 20 | #include 21 | #include 22 | 23 | extern uint16_t irq_mask_8259A; 24 | void pic_init(void); 25 | void irq_setmask_8259A(uint16_t mask); 26 | #endif // !__ASSEMBLER__ 27 | 28 | #endif // !JOS_KERN_PICIRQ_H 29 | -------------------------------------------------------------------------------- /lab4/lib/readline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BUFLEN 1024 5 | static char buf[BUFLEN]; 6 | 7 | char * 8 | readline(const char *prompt) 9 | { 10 | int i, c, echoing; 11 | 12 | if (prompt != NULL) 13 | cprintf("%s", prompt); 14 | 15 | i = 0; 16 | echoing = iscons(0); 17 | while (1) { 18 | c = getchar(); 19 | if (c < 0) { 20 | cprintf("read error: %e\n", c); 21 | return NULL; 22 | } else if ((c == '\b' || c == '\x7f') && i > 0) { 23 | if (echoing) 24 | cputchar('\b'); 25 | i--; 26 | } else if (c >= ' ' && i < BUFLEN-1) { 27 | if (echoing) 28 | cputchar(c); 29 | buf[i++] = c; 30 | } else if (c == '\n' || c == '\r') { 31 | if (echoing) 32 | cputchar('\n'); 33 | buf[i] = 0; 34 | return buf; 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lab2/grade-lab2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from gradelib import * 4 | 5 | r = Runner(save("jos.out"), 6 | stop_breakpoint("readline")) 7 | 8 | @test(0, "running JOS") 9 | def test_jos(): 10 | r.run_qemu() 11 | 12 | @test(20, "Physical page allocator", parent=test_jos) 13 | def test_check_page_alloc(): 14 | r.match(r"check_page_alloc\(\) succeeded!") 15 | 16 | @test(20, "Page management", parent=test_jos) 17 | def test_check_page(): 18 | r.match(r"check_page\(\) succeeded!") 19 | 20 | @test(20, "Kernel page directory", parent=test_jos) 21 | def test_check_kern_pgdir(): 22 | r.match(r"check_kern_pgdir\(\) succeeded!") 23 | 24 | @test(10, "Page management 2", parent=test_jos) 25 | def test_check_page_installed_pgdir(): 26 | r.match(r"check_page_installed_pgdir\(\) succeeded!") 27 | 28 | run_tests() 29 | -------------------------------------------------------------------------------- /lab3/grade-lab2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from gradelib import * 4 | 5 | r = Runner(save("jos.out"), 6 | stop_breakpoint("readline")) 7 | 8 | @test(0, "running JOS") 9 | def test_jos(): 10 | r.run_qemu() 11 | 12 | @test(20, "Physical page allocator", parent=test_jos) 13 | def test_check_page_alloc(): 14 | r.match(r"check_page_alloc\(\) succeeded!") 15 | 16 | @test(20, "Page management", parent=test_jos) 17 | def test_check_page(): 18 | r.match(r"check_page\(\) succeeded!") 19 | 20 | @test(20, "Kernel page directory", parent=test_jos) 21 | def test_check_kern_pgdir(): 22 | r.match(r"check_kern_pgdir\(\) succeeded!") 23 | 24 | @test(10, "Page management 2", parent=test_jos) 25 | def test_check_page_installed_pgdir(): 26 | r.match(r"check_page_installed_pgdir\(\) succeeded!") 27 | 28 | run_tests() 29 | -------------------------------------------------------------------------------- /lab4/grade-lab2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from gradelib import * 4 | 5 | r = Runner(save("jos.out"), 6 | stop_breakpoint("readline")) 7 | 8 | @test(0, "running JOS") 9 | def test_jos(): 10 | r.run_qemu() 11 | 12 | @test(20, "Physical page allocator", parent=test_jos) 13 | def test_check_page_alloc(): 14 | r.match(r"check_page_alloc\(\) succeeded!") 15 | 16 | @test(20, "Page management", parent=test_jos) 17 | def test_check_page(): 18 | r.match(r"check_page\(\) succeeded!") 19 | 20 | @test(20, "Kernel page directory", parent=test_jos) 21 | def test_check_kern_pgdir(): 22 | r.match(r"check_kern_pgdir\(\) succeeded!") 23 | 24 | @test(10, "Page management 2", parent=test_jos) 25 | def test_check_page_installed_pgdir(): 26 | r.match(r"check_page_installed_pgdir\(\) succeeded!") 27 | 28 | run_tests() 29 | -------------------------------------------------------------------------------- /lab4/user/pingpongs.c: -------------------------------------------------------------------------------- 1 | // Ping-pong a counter between two shared-memory processes. 2 | // Only need to start one of these -- splits into two with sfork. 3 | 4 | #include 5 | 6 | uint32_t val; 7 | 8 | void 9 | umain(int argc, char **argv) 10 | { 11 | envid_t who; 12 | uint32_t i; 13 | 14 | i = 0; 15 | if ((who = sfork()) != 0) { 16 | cprintf("i am %08x; thisenv is %p\n", sys_getenvid(), thisenv); 17 | // get the ball rolling 18 | cprintf("send 0 from %x to %x\n", sys_getenvid(), who); 19 | ipc_send(who, 0, 0, 0); 20 | } 21 | 22 | while (1) { 23 | ipc_recv(&who, 0, 0); 24 | cprintf("%x got %d from %x (thisenv is %p %x)\n", sys_getenvid(), val, who, thisenv, thisenv->env_id); 25 | if (val == 10) 26 | return; 27 | ++val; 28 | ipc_send(who, 0, 0, 0); 29 | if (val == 10) 30 | return; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /lab3/lib/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += lib 2 | 3 | LIB_SRCFILES := lib/console.c \ 4 | lib/libmain.c \ 5 | lib/exit.c \ 6 | lib/panic.c \ 7 | lib/printf.c \ 8 | lib/printfmt.c \ 9 | lib/readline.c \ 10 | lib/string.c \ 11 | lib/syscall.c 12 | 13 | 14 | 15 | 16 | LIB_OBJFILES := $(patsubst lib/%.c, $(OBJDIR)/lib/%.o, $(LIB_SRCFILES)) 17 | LIB_OBJFILES := $(patsubst lib/%.S, $(OBJDIR)/lib/%.o, $(LIB_OBJFILES)) 18 | 19 | $(OBJDIR)/lib/%.o: lib/%.c $(OBJDIR)/.vars.USER_CFLAGS 20 | @echo + cc[USER] $< 21 | @mkdir -p $(@D) 22 | $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $< 23 | 24 | $(OBJDIR)/lib/%.o: lib/%.S $(OBJDIR)/.vars.USER_CFLAGS 25 | @echo + as[USER] $< 26 | @mkdir -p $(@D) 27 | $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $< 28 | 29 | $(OBJDIR)/lib/libjos.a: $(LIB_OBJFILES) 30 | @echo + ar $@ 31 | $(V)$(AR) r $@ $(LIB_OBJFILES) 32 | -------------------------------------------------------------------------------- /lab4/user/stresssched.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | volatile int counter; 4 | 5 | void 6 | umain(int argc, char **argv) 7 | { 8 | int i, j; 9 | int seen; 10 | envid_t parent = sys_getenvid(); 11 | 12 | // Fork several environments 13 | for (i = 0; i < 20; i++) 14 | if (fork() == 0) 15 | break; 16 | if (i == 20) { 17 | sys_yield(); 18 | return; 19 | } 20 | 21 | // Wait for the parent to finish forking 22 | while (envs[ENVX(parent)].env_status != ENV_FREE) 23 | asm volatile("pause"); 24 | 25 | // Check that one environment doesn't run on two CPUs at once 26 | for (i = 0; i < 10; i++) { 27 | sys_yield(); 28 | for (j = 0; j < 10000; j++) 29 | counter++; 30 | } 31 | 32 | if (counter != 10*10000) 33 | panic("ran on two CPUs at once (counter is %d)", counter); 34 | 35 | // Check that we see environments running on different CPUs 36 | cprintf("[%08x] stresssched on CPU %d\n", thisenv->env_id, thisenv->env_cpunum); 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /lab3/lib/entry.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | .data 5 | // Define the global symbols 'envs', 'pages', 'uvpt', and 'uvpd' 6 | // so that they can be used in C as if they were ordinary global arrays. 7 | .globl envs 8 | .set envs, UENVS 9 | .globl pages 10 | .set pages, UPAGES 11 | .globl uvpt 12 | .set uvpt, UVPT 13 | .globl uvpd 14 | .set uvpd, (UVPT+(UVPT>>12)*4) 15 | 16 | 17 | // Entrypoint - this is where the kernel (or our parent environment) 18 | // starts us running when we are initially loaded into a new environment. 19 | .text 20 | .globl _start 21 | _start: 22 | // See if we were started with arguments on the stack 23 | cmpl $USTACKTOP, %esp 24 | jne args_exist 25 | 26 | // If not, push dummy argc/argv arguments. 27 | // This happens when we are loaded by the kernel, 28 | // because the kernel does not know about passing arguments. 29 | pushl $0 30 | pushl $0 31 | 32 | args_exist: 33 | call libmain 34 | 1: jmp 1b 35 | 36 | -------------------------------------------------------------------------------- /lab4/lib/entry.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | .data 5 | // Define the global symbols 'envs', 'pages', 'uvpt', and 'uvpd' 6 | // so that they can be used in C as if they were ordinary global arrays. 7 | .globl envs 8 | .set envs, UENVS 9 | .globl pages 10 | .set pages, UPAGES 11 | .globl uvpt 12 | .set uvpt, UVPT 13 | .globl uvpd 14 | .set uvpd, (UVPT+(UVPT>>12)*4) 15 | 16 | 17 | // Entrypoint - this is where the kernel (or our parent environment) 18 | // starts us running when we are initially loaded into a new environment. 19 | .text 20 | .globl _start 21 | _start: 22 | // See if we were started with arguments on the stack 23 | cmpl $USTACKTOP, %esp 24 | jne args_exist 25 | 26 | // If not, push dummy argc/argv arguments. 27 | // This happens when we are loaded by the kernel, 28 | // because the kernel does not know about passing arguments. 29 | pushl $0 30 | pushl $0 31 | 32 | args_exist: 33 | call libmain 34 | 1: jmp 1b 35 | 36 | -------------------------------------------------------------------------------- /lab1/inc/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STDIO_H 2 | #define JOS_INC_STDIO_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif /* !NULL */ 9 | 10 | // lib/stdio.c 11 | void cputchar(int c); 12 | int getchar(void); 13 | int iscons(int fd); 14 | 15 | // lib/printfmt.c 16 | void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...); 17 | void vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list); 18 | int snprintf(char *str, int size, const char *fmt, ...); 19 | int vsnprintf(char *str, int size, const char *fmt, va_list); 20 | 21 | // lib/printf.c 22 | int cprintf(const char *fmt, ...); 23 | int vcprintf(const char *fmt, va_list); 24 | 25 | // lib/fprintf.c 26 | int printf(const char *fmt, ...); 27 | int fprintf(int fd, const char *fmt, ...); 28 | int vfprintf(int fd, const char *fmt, va_list); 29 | 30 | // lib/readline.c 31 | char* readline(const char *prompt); 32 | 33 | #endif /* !JOS_INC_STDIO_H */ 34 | -------------------------------------------------------------------------------- /lab2/inc/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STDIO_H 2 | #define JOS_INC_STDIO_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif /* !NULL */ 9 | 10 | // lib/stdio.c 11 | void cputchar(int c); 12 | int getchar(void); 13 | int iscons(int fd); 14 | 15 | // lib/printfmt.c 16 | void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...); 17 | void vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list); 18 | int snprintf(char *str, int size, const char *fmt, ...); 19 | int vsnprintf(char *str, int size, const char *fmt, va_list); 20 | 21 | // lib/printf.c 22 | int cprintf(const char *fmt, ...); 23 | int vcprintf(const char *fmt, va_list); 24 | 25 | // lib/fprintf.c 26 | int printf(const char *fmt, ...); 27 | int fprintf(int fd, const char *fmt, ...); 28 | int vfprintf(int fd, const char *fmt, va_list); 29 | 30 | // lib/readline.c 31 | char* readline(const char *prompt); 32 | 33 | #endif /* !JOS_INC_STDIO_H */ 34 | -------------------------------------------------------------------------------- /lab3/inc/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STDIO_H 2 | #define JOS_INC_STDIO_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif /* !NULL */ 9 | 10 | // lib/stdio.c 11 | void cputchar(int c); 12 | int getchar(void); 13 | int iscons(int fd); 14 | 15 | // lib/printfmt.c 16 | void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...); 17 | void vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list); 18 | int snprintf(char *str, int size, const char *fmt, ...); 19 | int vsnprintf(char *str, int size, const char *fmt, va_list); 20 | 21 | // lib/printf.c 22 | int cprintf(const char *fmt, ...); 23 | int vcprintf(const char *fmt, va_list); 24 | 25 | // lib/fprintf.c 26 | int printf(const char *fmt, ...); 27 | int fprintf(int fd, const char *fmt, ...); 28 | int vfprintf(int fd, const char *fmt, va_list); 29 | 30 | // lib/readline.c 31 | char* readline(const char *prompt); 32 | 33 | #endif /* !JOS_INC_STDIO_H */ 34 | -------------------------------------------------------------------------------- /lab4/inc/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STDIO_H 2 | #define JOS_INC_STDIO_H 3 | 4 | #include 5 | 6 | #ifndef NULL 7 | #define NULL ((void *) 0) 8 | #endif /* !NULL */ 9 | 10 | // lib/stdio.c 11 | void cputchar(int c); 12 | int getchar(void); 13 | int iscons(int fd); 14 | 15 | // lib/printfmt.c 16 | void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...); 17 | void vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list); 18 | int snprintf(char *str, int size, const char *fmt, ...); 19 | int vsnprintf(char *str, int size, const char *fmt, va_list); 20 | 21 | // lib/printf.c 22 | int cprintf(const char *fmt, ...); 23 | int vcprintf(const char *fmt, va_list); 24 | 25 | // lib/fprintf.c 26 | int printf(const char *fmt, ...); 27 | int fprintf(int fd, const char *fmt, ...); 28 | int vfprintf(int fd, const char *fmt, va_list); 29 | 30 | // lib/readline.c 31 | char* readline(const char *prompt); 32 | 33 | #endif /* !JOS_INC_STDIO_H */ 34 | -------------------------------------------------------------------------------- /lab1/inc/string.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STRING_H 2 | #define JOS_INC_STRING_H 3 | 4 | #include 5 | 6 | int strlen(const char *s); 7 | int strnlen(const char *s, size_t size); 8 | char * strcpy(char *dst, const char *src); 9 | char * strncpy(char *dst, const char *src, size_t size); 10 | char * strcat(char *dst, const char *src); 11 | size_t strlcpy(char *dst, const char *src, size_t size); 12 | int strcmp(const char *s1, const char *s2); 13 | int strncmp(const char *s1, const char *s2, size_t size); 14 | char * strchr(const char *s, char c); 15 | char * strfind(const char *s, char c); 16 | 17 | void * memset(void *dst, int c, size_t len); 18 | void * memcpy(void *dst, const void *src, size_t len); 19 | void * memmove(void *dst, const void *src, size_t len); 20 | int memcmp(const void *s1, const void *s2, size_t len); 21 | void * memfind(const void *s, int c, size_t len); 22 | 23 | long strtol(const char *s, char **endptr, int base); 24 | 25 | #endif /* not JOS_INC_STRING_H */ 26 | -------------------------------------------------------------------------------- /lab2/inc/string.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STRING_H 2 | #define JOS_INC_STRING_H 3 | 4 | #include 5 | 6 | int strlen(const char *s); 7 | int strnlen(const char *s, size_t size); 8 | char * strcpy(char *dst, const char *src); 9 | char * strncpy(char *dst, const char *src, size_t size); 10 | char * strcat(char *dst, const char *src); 11 | size_t strlcpy(char *dst, const char *src, size_t size); 12 | int strcmp(const char *s1, const char *s2); 13 | int strncmp(const char *s1, const char *s2, size_t size); 14 | char * strchr(const char *s, char c); 15 | char * strfind(const char *s, char c); 16 | 17 | void * memset(void *dst, int c, size_t len); 18 | void * memcpy(void *dst, const void *src, size_t len); 19 | void * memmove(void *dst, const void *src, size_t len); 20 | int memcmp(const void *s1, const void *s2, size_t len); 21 | void * memfind(const void *s, int c, size_t len); 22 | 23 | long strtol(const char *s, char **endptr, int base); 24 | 25 | #endif /* not JOS_INC_STRING_H */ 26 | -------------------------------------------------------------------------------- /lab3/inc/string.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STRING_H 2 | #define JOS_INC_STRING_H 3 | 4 | #include 5 | 6 | int strlen(const char *s); 7 | int strnlen(const char *s, size_t size); 8 | char * strcpy(char *dst, const char *src); 9 | char * strncpy(char *dst, const char *src, size_t size); 10 | char * strcat(char *dst, const char *src); 11 | size_t strlcpy(char *dst, const char *src, size_t size); 12 | int strcmp(const char *s1, const char *s2); 13 | int strncmp(const char *s1, const char *s2, size_t size); 14 | char * strchr(const char *s, char c); 15 | char * strfind(const char *s, char c); 16 | 17 | void * memset(void *dst, int c, size_t len); 18 | void * memcpy(void *dst, const void *src, size_t len); 19 | void * memmove(void *dst, const void *src, size_t len); 20 | int memcmp(const void *s1, const void *s2, size_t len); 21 | void * memfind(const void *s, int c, size_t len); 22 | 23 | long strtol(const char *s, char **endptr, int base); 24 | 25 | #endif /* not JOS_INC_STRING_H */ 26 | -------------------------------------------------------------------------------- /lab4/inc/string.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_STRING_H 2 | #define JOS_INC_STRING_H 3 | 4 | #include 5 | 6 | int strlen(const char *s); 7 | int strnlen(const char *s, size_t size); 8 | char * strcpy(char *dst, const char *src); 9 | char * strncpy(char *dst, const char *src, size_t size); 10 | char * strcat(char *dst, const char *src); 11 | size_t strlcpy(char *dst, const char *src, size_t size); 12 | int strcmp(const char *s1, const char *s2); 13 | int strncmp(const char *s1, const char *s2, size_t size); 14 | char * strchr(const char *s, char c); 15 | char * strfind(const char *s, char c); 16 | 17 | void * memset(void *dst, int c, size_t len); 18 | void * memcpy(void *dst, const void *src, size_t len); 19 | void * memmove(void *dst, const void *src, size_t len); 20 | int memcmp(const void *s1, const void *s2, size_t len); 21 | void * memfind(const void *s, int c, size_t len); 22 | 23 | long strtol(const char *s, char **endptr, int base); 24 | 25 | #endif /* not JOS_INC_STRING_H */ 26 | -------------------------------------------------------------------------------- /lab4/lib/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += lib 2 | 3 | LIB_SRCFILES := lib/console.c \ 4 | lib/libmain.c \ 5 | lib/exit.c \ 6 | lib/panic.c \ 7 | lib/printf.c \ 8 | lib/printfmt.c \ 9 | lib/readline.c \ 10 | lib/string.c \ 11 | lib/syscall.c 12 | 13 | LIB_SRCFILES := $(LIB_SRCFILES) \ 14 | lib/pgfault.c \ 15 | lib/pfentry.S \ 16 | lib/fork.c \ 17 | lib/ipc.c 18 | 19 | 20 | 21 | LIB_OBJFILES := $(patsubst lib/%.c, $(OBJDIR)/lib/%.o, $(LIB_SRCFILES)) 22 | LIB_OBJFILES := $(patsubst lib/%.S, $(OBJDIR)/lib/%.o, $(LIB_OBJFILES)) 23 | 24 | $(OBJDIR)/lib/%.o: lib/%.c $(OBJDIR)/.vars.USER_CFLAGS 25 | @echo + cc[USER] $< 26 | @mkdir -p $(@D) 27 | $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $< 28 | 29 | $(OBJDIR)/lib/%.o: lib/%.S $(OBJDIR)/.vars.USER_CFLAGS 30 | @echo + as[USER] $< 31 | @mkdir -p $(@D) 32 | $(V)$(CC) -nostdinc $(USER_CFLAGS) -c -o $@ $< 33 | 34 | $(OBJDIR)/lib/libjos.a: $(LIB_OBJFILES) 35 | @echo + ar $@ 36 | $(V)$(AR) r $@ $(LIB_OBJFILES) 37 | -------------------------------------------------------------------------------- /lab1/boot/Makefrag: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile fragment for the JOS kernel. 3 | # This is NOT a complete makefile; 4 | # you must run GNU make in the top-level directory 5 | # where the GNUmakefile is located. 6 | # 7 | 8 | OBJDIRS += boot 9 | 10 | BOOT_OBJS := $(OBJDIR)/boot/boot.o $(OBJDIR)/boot/main.o 11 | 12 | $(OBJDIR)/boot/%.o: boot/%.c 13 | @echo + cc -Os $< 14 | @mkdir -p $(@D) 15 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $@ $< 16 | 17 | $(OBJDIR)/boot/%.o: boot/%.S 18 | @echo + as $< 19 | @mkdir -p $(@D) 20 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $< 21 | 22 | $(OBJDIR)/boot/main.o: boot/main.c 23 | @echo + cc -Os $< 24 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $(OBJDIR)/boot/main.o boot/main.c 25 | 26 | $(OBJDIR)/boot/boot: $(BOOT_OBJS) 27 | @echo + ld boot/boot 28 | $(V)$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o $@.out $^ 29 | $(V)$(OBJDUMP) -S $@.out >$@.asm 30 | $(V)$(OBJCOPY) -S -O binary -j .text $@.out $@ 31 | $(V)perl boot/sign.pl $(OBJDIR)/boot/boot 32 | 33 | -------------------------------------------------------------------------------- /lab2/boot/Makefrag: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile fragment for the JOS kernel. 3 | # This is NOT a complete makefile; 4 | # you must run GNU make in the top-level directory 5 | # where the GNUmakefile is located. 6 | # 7 | 8 | OBJDIRS += boot 9 | 10 | BOOT_OBJS := $(OBJDIR)/boot/boot.o $(OBJDIR)/boot/main.o 11 | 12 | $(OBJDIR)/boot/%.o: boot/%.c 13 | @echo + cc -Os $< 14 | @mkdir -p $(@D) 15 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $@ $< 16 | 17 | $(OBJDIR)/boot/%.o: boot/%.S 18 | @echo + as $< 19 | @mkdir -p $(@D) 20 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $< 21 | 22 | $(OBJDIR)/boot/main.o: boot/main.c 23 | @echo + cc -Os $< 24 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $(OBJDIR)/boot/main.o boot/main.c 25 | 26 | $(OBJDIR)/boot/boot: $(BOOT_OBJS) 27 | @echo + ld boot/boot 28 | $(V)$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o $@.out $^ 29 | $(V)$(OBJDUMP) -S $@.out >$@.asm 30 | $(V)$(OBJCOPY) -S -O binary -j .text $@.out $@ 31 | $(V)perl boot/sign.pl $(OBJDIR)/boot/boot 32 | 33 | -------------------------------------------------------------------------------- /lab3/boot/Makefrag: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile fragment for the JOS kernel. 3 | # This is NOT a complete makefile; 4 | # you must run GNU make in the top-level directory 5 | # where the GNUmakefile is located. 6 | # 7 | 8 | OBJDIRS += boot 9 | 10 | BOOT_OBJS := $(OBJDIR)/boot/boot.o $(OBJDIR)/boot/main.o 11 | 12 | $(OBJDIR)/boot/%.o: boot/%.c 13 | @echo + cc -Os $< 14 | @mkdir -p $(@D) 15 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $@ $< 16 | 17 | $(OBJDIR)/boot/%.o: boot/%.S 18 | @echo + as $< 19 | @mkdir -p $(@D) 20 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $< 21 | 22 | $(OBJDIR)/boot/main.o: boot/main.c 23 | @echo + cc -Os $< 24 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $(OBJDIR)/boot/main.o boot/main.c 25 | 26 | $(OBJDIR)/boot/boot: $(BOOT_OBJS) 27 | @echo + ld boot/boot 28 | $(V)$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o $@.out $^ 29 | $(V)$(OBJDUMP) -S $@.out >$@.asm 30 | $(V)$(OBJCOPY) -S -O binary -j .text $@.out $@ 31 | $(V)perl boot/sign.pl $(OBJDIR)/boot/boot 32 | 33 | -------------------------------------------------------------------------------- /lab4/boot/Makefrag: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile fragment for the JOS kernel. 3 | # This is NOT a complete makefile; 4 | # you must run GNU make in the top-level directory 5 | # where the GNUmakefile is located. 6 | # 7 | 8 | OBJDIRS += boot 9 | 10 | BOOT_OBJS := $(OBJDIR)/boot/boot.o $(OBJDIR)/boot/main.o 11 | 12 | $(OBJDIR)/boot/%.o: boot/%.c 13 | @echo + cc -Os $< 14 | @mkdir -p $(@D) 15 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $@ $< 16 | 17 | $(OBJDIR)/boot/%.o: boot/%.S 18 | @echo + as $< 19 | @mkdir -p $(@D) 20 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $< 21 | 22 | $(OBJDIR)/boot/main.o: boot/main.c 23 | @echo + cc -Os $< 24 | $(V)$(CC) -nostdinc $(KERN_CFLAGS) -Os -c -o $(OBJDIR)/boot/main.o boot/main.c 25 | 26 | $(OBJDIR)/boot/boot: $(BOOT_OBJS) 27 | @echo + ld boot/boot 28 | $(V)$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o $@.out $^ 29 | $(V)$(OBJDUMP) -S $@.out >$@.asm 30 | $(V)$(OBJCOPY) -S -O binary -j .text $@.out $@ 31 | $(V)perl boot/sign.pl $(OBJDIR)/boot/boot 32 | 33 | -------------------------------------------------------------------------------- /lab2/kern/kclock.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_KCLOCK_H 4 | #define JOS_KERN_KCLOCK_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #define IO_RTC 0x070 /* RTC port */ 10 | 11 | #define MC_NVRAM_START 0xe /* start of NVRAM: offset 14 */ 12 | #define MC_NVRAM_SIZE 50 /* 50 bytes of NVRAM */ 13 | 14 | /* NVRAM bytes 7 & 8: base memory size */ 15 | #define NVRAM_BASELO (MC_NVRAM_START + 7) /* low byte; RTC off. 0x15 */ 16 | #define NVRAM_BASEHI (MC_NVRAM_START + 8) /* high byte; RTC off. 0x16 */ 17 | 18 | /* NVRAM bytes 9 & 10: extended memory size (between 1MB and 16MB) */ 19 | #define NVRAM_EXTLO (MC_NVRAM_START + 9) /* low byte; RTC off. 0x17 */ 20 | #define NVRAM_EXTHI (MC_NVRAM_START + 10) /* high byte; RTC off. 0x18 */ 21 | 22 | /* NVRAM bytes 38 and 39: extended memory size (between 16MB and 4G) */ 23 | #define NVRAM_EXT16LO (MC_NVRAM_START + 38) /* low byte; RTC off. 0x34 */ 24 | #define NVRAM_EXT16HI (MC_NVRAM_START + 39) /* high byte; RTC off. 0x35 */ 25 | 26 | unsigned mc146818_read(unsigned reg); 27 | void mc146818_write(unsigned reg, unsigned datum); 28 | 29 | #endif // !JOS_KERN_KCLOCK_H 30 | -------------------------------------------------------------------------------- /lab3/kern/kclock.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_KCLOCK_H 4 | #define JOS_KERN_KCLOCK_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #define IO_RTC 0x070 /* RTC port */ 10 | 11 | #define MC_NVRAM_START 0xe /* start of NVRAM: offset 14 */ 12 | #define MC_NVRAM_SIZE 50 /* 50 bytes of NVRAM */ 13 | 14 | /* NVRAM bytes 7 & 8: base memory size */ 15 | #define NVRAM_BASELO (MC_NVRAM_START + 7) /* low byte; RTC off. 0x15 */ 16 | #define NVRAM_BASEHI (MC_NVRAM_START + 8) /* high byte; RTC off. 0x16 */ 17 | 18 | /* NVRAM bytes 9 & 10: extended memory size (between 1MB and 16MB) */ 19 | #define NVRAM_EXTLO (MC_NVRAM_START + 9) /* low byte; RTC off. 0x17 */ 20 | #define NVRAM_EXTHI (MC_NVRAM_START + 10) /* high byte; RTC off. 0x18 */ 21 | 22 | /* NVRAM bytes 38 and 39: extended memory size (between 16MB and 4G) */ 23 | #define NVRAM_EXT16LO (MC_NVRAM_START + 38) /* low byte; RTC off. 0x34 */ 24 | #define NVRAM_EXT16HI (MC_NVRAM_START + 39) /* high byte; RTC off. 0x35 */ 25 | 26 | unsigned mc146818_read(unsigned reg); 27 | void mc146818_write(unsigned reg, unsigned datum); 28 | 29 | #endif // !JOS_KERN_KCLOCK_H 30 | -------------------------------------------------------------------------------- /lab4/kern/kclock.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_KCLOCK_H 4 | #define JOS_KERN_KCLOCK_H 5 | #ifndef JOS_KERNEL 6 | # error "This is a JOS kernel header; user programs should not #include it" 7 | #endif 8 | 9 | #define IO_RTC 0x070 /* RTC port */ 10 | 11 | #define MC_NVRAM_START 0xe /* start of NVRAM: offset 14 */ 12 | #define MC_NVRAM_SIZE 50 /* 50 bytes of NVRAM */ 13 | 14 | /* NVRAM bytes 7 & 8: base memory size */ 15 | #define NVRAM_BASELO (MC_NVRAM_START + 7) /* low byte; RTC off. 0x15 */ 16 | #define NVRAM_BASEHI (MC_NVRAM_START + 8) /* high byte; RTC off. 0x16 */ 17 | 18 | /* NVRAM bytes 9 & 10: extended memory size (between 1MB and 16MB) */ 19 | #define NVRAM_EXTLO (MC_NVRAM_START + 9) /* low byte; RTC off. 0x17 */ 20 | #define NVRAM_EXTHI (MC_NVRAM_START + 10) /* high byte; RTC off. 0x18 */ 21 | 22 | /* NVRAM bytes 38 and 39: extended memory size (between 16MB and 4G) */ 23 | #define NVRAM_EXT16LO (MC_NVRAM_START + 38) /* low byte; RTC off. 0x34 */ 24 | #define NVRAM_EXT16HI (MC_NVRAM_START + 39) /* high byte; RTC off. 0x35 */ 25 | 26 | unsigned mc146818_read(unsigned reg); 27 | void mc146818_write(unsigned reg, unsigned datum); 28 | 29 | #endif // !JOS_KERN_KCLOCK_H 30 | -------------------------------------------------------------------------------- /lab1/obj/.deps: -------------------------------------------------------------------------------- 1 | obj/kern/console.o: kern/console.c inc/x86.h inc/types.h inc/memlayout.h \ 2 | inc/mmu.h inc/kbdreg.h inc/string.h inc/assert.h inc/stdio.h \ 3 | inc/stdarg.h kern/console.h 4 | obj/kern/kdebug.o: kern/kdebug.c inc/stab.h inc/types.h inc/string.h \ 5 | inc/memlayout.h inc/mmu.h inc/assert.h inc/stdio.h inc/stdarg.h \ 6 | kern/kdebug.h 7 | obj/boot/boot.o: boot/boot.S inc/mmu.h 8 | obj/boot/main.o: boot/main.c inc/x86.h inc/types.h inc/elf.h 9 | obj/kern/printf.o: kern/printf.c inc/types.h inc/stdio.h inc/stdarg.h 10 | obj/kern/entry.o: kern/entry.S inc/mmu.h inc/memlayout.h 11 | obj/kern/readline.o: lib/readline.c inc/stdio.h inc/stdarg.h inc/error.h 12 | obj/kern/entrypgdir.o: kern/entrypgdir.c inc/mmu.h inc/types.h \ 13 | inc/memlayout.h 14 | obj/kern/init.o: kern/init.c inc/stdio.h inc/stdarg.h inc/string.h \ 15 | inc/types.h inc/assert.h kern/monitor.h kern/console.h 16 | obj/kern/string.o: lib/string.c inc/string.h inc/types.h 17 | obj/kern/monitor.o: kern/monitor.c inc/stdio.h inc/stdarg.h inc/string.h \ 18 | inc/types.h inc/memlayout.h inc/mmu.h inc/assert.h inc/x86.h \ 19 | kern/console.h kern/monitor.h kern/kdebug.h 20 | obj/kern/printfmt.o: lib/printfmt.c inc/types.h inc/stdio.h inc/stdarg.h \ 21 | inc/string.h inc/error.h 22 | -------------------------------------------------------------------------------- /lab3/kern/env.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_ENV_H 4 | #define JOS_KERN_ENV_H 5 | 6 | #include 7 | 8 | extern struct Env *envs; // All environments 9 | extern struct Env *curenv; // Current environment 10 | extern struct Segdesc gdt[]; 11 | 12 | void env_init(void); 13 | void env_init_percpu(void); 14 | int env_alloc(struct Env **e, envid_t parent_id); 15 | void env_free(struct Env *e); 16 | void env_create(uint8_t *binary, enum EnvType type); 17 | void env_destroy(struct Env *e); // Does not return if e == curenv 18 | 19 | int envid2env(envid_t envid, struct Env **env_store, bool checkperm); 20 | // The following two functions do not return 21 | void env_run(struct Env *e) __attribute__((noreturn)); 22 | void env_pop_tf(struct Trapframe *tf) __attribute__((noreturn)); 23 | 24 | // Without this extra macro, we couldn't pass macros like TEST to 25 | // ENV_CREATE because of the C pre-processor's argument prescan rule. 26 | #define ENV_PASTE3(x, y, z) x ## y ## z 27 | 28 | #define ENV_CREATE(x, type) \ 29 | do { \ 30 | extern uint8_t ENV_PASTE3(_binary_obj_, x, _start)[]; \ 31 | env_create(ENV_PASTE3(_binary_obj_, x, _start), \ 32 | type); \ 33 | } while (0) 34 | 35 | #endif // !JOS_KERN_ENV_H 36 | -------------------------------------------------------------------------------- /lab1/user/sendpage.c: -------------------------------------------------------------------------------- 1 | // Test Conversation between parent and child environment 2 | // Contributed by Varun Agrawal at Stony Brook 3 | 4 | #include 5 | 6 | const char *str1 = "hello child environment! how are you?"; 7 | const char *str2 = "hello parent environment! I'm good."; 8 | 9 | #define TEMP_ADDR ((char*)0xa00000) 10 | #define TEMP_ADDR_CHILD ((char*)0xb00000) 11 | 12 | void 13 | umain(int argc, char **argv) 14 | { 15 | envid_t who; 16 | 17 | if ((who = fork()) == 0) { 18 | // Child 19 | ipc_recv(&who, TEMP_ADDR_CHILD, 0); 20 | cprintf("%x got message: %s\n", who, TEMP_ADDR_CHILD); 21 | if (strncmp(TEMP_ADDR_CHILD, str1, strlen(str1)) == 0) 22 | cprintf("child received correct message\n"); 23 | 24 | memcpy(TEMP_ADDR_CHILD, str2, strlen(str2) + 1); 25 | ipc_send(who, 0, TEMP_ADDR_CHILD, PTE_P | PTE_W | PTE_U); 26 | return; 27 | } 28 | 29 | // Parent 30 | sys_page_alloc(thisenv->env_id, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 31 | memcpy(TEMP_ADDR, str1, strlen(str1) + 1); 32 | ipc_send(who, 0, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 33 | 34 | ipc_recv(&who, TEMP_ADDR, 0); 35 | cprintf("%x got message: %s\n", who, TEMP_ADDR); 36 | if (strncmp(TEMP_ADDR, str2, strlen(str2)) == 0) 37 | cprintf("parent received correct message\n"); 38 | return; 39 | } 40 | -------------------------------------------------------------------------------- /lab2/user/sendpage.c: -------------------------------------------------------------------------------- 1 | // Test Conversation between parent and child environment 2 | // Contributed by Varun Agrawal at Stony Brook 3 | 4 | #include 5 | 6 | const char *str1 = "hello child environment! how are you?"; 7 | const char *str2 = "hello parent environment! I'm good."; 8 | 9 | #define TEMP_ADDR ((char*)0xa00000) 10 | #define TEMP_ADDR_CHILD ((char*)0xb00000) 11 | 12 | void 13 | umain(int argc, char **argv) 14 | { 15 | envid_t who; 16 | 17 | if ((who = fork()) == 0) { 18 | // Child 19 | ipc_recv(&who, TEMP_ADDR_CHILD, 0); 20 | cprintf("%x got message: %s\n", who, TEMP_ADDR_CHILD); 21 | if (strncmp(TEMP_ADDR_CHILD, str1, strlen(str1)) == 0) 22 | cprintf("child received correct message\n"); 23 | 24 | memcpy(TEMP_ADDR_CHILD, str2, strlen(str2) + 1); 25 | ipc_send(who, 0, TEMP_ADDR_CHILD, PTE_P | PTE_W | PTE_U); 26 | return; 27 | } 28 | 29 | // Parent 30 | sys_page_alloc(thisenv->env_id, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 31 | memcpy(TEMP_ADDR, str1, strlen(str1) + 1); 32 | ipc_send(who, 0, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 33 | 34 | ipc_recv(&who, TEMP_ADDR, 0); 35 | cprintf("%x got message: %s\n", who, TEMP_ADDR); 36 | if (strncmp(TEMP_ADDR, str2, strlen(str2)) == 0) 37 | cprintf("parent received correct message\n"); 38 | return; 39 | } 40 | -------------------------------------------------------------------------------- /lab3/user/sendpage.c: -------------------------------------------------------------------------------- 1 | // Test Conversation between parent and child environment 2 | // Contributed by Varun Agrawal at Stony Brook 3 | 4 | #include 5 | 6 | const char *str1 = "hello child environment! how are you?"; 7 | const char *str2 = "hello parent environment! I'm good."; 8 | 9 | #define TEMP_ADDR ((char*)0xa00000) 10 | #define TEMP_ADDR_CHILD ((char*)0xb00000) 11 | 12 | void 13 | umain(int argc, char **argv) 14 | { 15 | envid_t who; 16 | 17 | if ((who = fork()) == 0) { 18 | // Child 19 | ipc_recv(&who, TEMP_ADDR_CHILD, 0); 20 | cprintf("%x got message: %s\n", who, TEMP_ADDR_CHILD); 21 | if (strncmp(TEMP_ADDR_CHILD, str1, strlen(str1)) == 0) 22 | cprintf("child received correct message\n"); 23 | 24 | memcpy(TEMP_ADDR_CHILD, str2, strlen(str2) + 1); 25 | ipc_send(who, 0, TEMP_ADDR_CHILD, PTE_P | PTE_W | PTE_U); 26 | return; 27 | } 28 | 29 | // Parent 30 | sys_page_alloc(thisenv->env_id, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 31 | memcpy(TEMP_ADDR, str1, strlen(str1) + 1); 32 | ipc_send(who, 0, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 33 | 34 | ipc_recv(&who, TEMP_ADDR, 0); 35 | cprintf("%x got message: %s\n", who, TEMP_ADDR); 36 | if (strncmp(TEMP_ADDR, str2, strlen(str2)) == 0) 37 | cprintf("parent received correct message\n"); 38 | return; 39 | } 40 | -------------------------------------------------------------------------------- /lab4/user/sendpage.c: -------------------------------------------------------------------------------- 1 | // Test Conversation between parent and child environment 2 | // Contributed by Varun Agrawal at Stony Brook 3 | 4 | #include 5 | 6 | const char *str1 = "hello child environment! how are you?"; 7 | const char *str2 = "hello parent environment! I'm good."; 8 | 9 | #define TEMP_ADDR ((char*)0xa00000) 10 | #define TEMP_ADDR_CHILD ((char*)0xb00000) 11 | 12 | void 13 | umain(int argc, char **argv) 14 | { 15 | envid_t who; 16 | 17 | if ((who = fork()) == 0) { 18 | // Child 19 | ipc_recv(&who, TEMP_ADDR_CHILD, 0); 20 | cprintf("%x got message: %s\n", who, TEMP_ADDR_CHILD); 21 | if (strncmp(TEMP_ADDR_CHILD, str1, strlen(str1)) == 0) 22 | cprintf("child received correct message\n"); 23 | 24 | memcpy(TEMP_ADDR_CHILD, str2, strlen(str2) + 1); 25 | ipc_send(who, 0, TEMP_ADDR_CHILD, PTE_P | PTE_W | PTE_U); 26 | return; 27 | } 28 | 29 | // Parent 30 | sys_page_alloc(thisenv->env_id, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 31 | memcpy(TEMP_ADDR, str1, strlen(str1) + 1); 32 | ipc_send(who, 0, TEMP_ADDR, PTE_P | PTE_W | PTE_U); 33 | 34 | ipc_recv(&who, TEMP_ADDR, 0); 35 | cprintf("%x got message: %s\n", who, TEMP_ADDR); 36 | if (strncmp(TEMP_ADDR, str2, strlen(str2)) == 0) 37 | cprintf("parent received correct message\n"); 38 | return; 39 | } 40 | -------------------------------------------------------------------------------- /lab4/kern/env.h: -------------------------------------------------------------------------------- 1 | /* See COPYRIGHT for copyright information. */ 2 | 3 | #ifndef JOS_KERN_ENV_H 4 | #define JOS_KERN_ENV_H 5 | 6 | #include 7 | #include 8 | 9 | extern struct Env *envs; // All environments 10 | #define curenv (thiscpu->cpu_env) // Current environment 11 | extern struct Segdesc gdt[]; 12 | 13 | void env_init(void); 14 | void env_init_percpu(void); 15 | int env_alloc(struct Env **e, envid_t parent_id); 16 | void env_free(struct Env *e); 17 | void env_create(uint8_t *binary, enum EnvType type); 18 | void env_destroy(struct Env *e); // Does not return if e == curenv 19 | 20 | int envid2env(envid_t envid, struct Env **env_store, bool checkperm); 21 | // The following two functions do not return 22 | void env_run(struct Env *e) __attribute__((noreturn)); 23 | void env_pop_tf(struct Trapframe *tf) __attribute__((noreturn)); 24 | 25 | // Without this extra macro, we couldn't pass macros like TEST to 26 | // ENV_CREATE because of the C pre-processor's argument prescan rule. 27 | #define ENV_PASTE3(x, y, z) x ## y ## z 28 | 29 | #define ENV_CREATE(x, type) \ 30 | do { \ 31 | extern uint8_t ENV_PASTE3(_binary_obj_, x, _start)[]; \ 32 | env_create(ENV_PASTE3(_binary_obj_, x, _start), \ 33 | type); \ 34 | } while (0) 35 | 36 | #endif // !JOS_KERN_ENV_H 37 | -------------------------------------------------------------------------------- /lab4/kern/cpu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef JOS_INC_CPU_H 3 | #define JOS_INC_CPU_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // Maximum number of CPUs 11 | #define NCPU 8 12 | 13 | // Values of status in struct Cpu 14 | enum { 15 | CPU_UNUSED = 0, 16 | CPU_STARTED, 17 | CPU_HALTED, 18 | }; 19 | 20 | // Per-CPU state 21 | struct CpuInfo { 22 | uint8_t cpu_id; // Local APIC ID; index into cpus[] below 23 | volatile unsigned cpu_status; // The status of the CPU 24 | struct Env *cpu_env; // The currently-running environment. 25 | struct Taskstate cpu_ts; // Used by x86 to find stack for interrupt 26 | }; 27 | 28 | // Initialized in mpconfig.c 29 | extern struct CpuInfo cpus[NCPU]; 30 | extern int ncpu; // Total number of CPUs in the system 31 | extern struct CpuInfo *bootcpu; // The boot-strap processor (BSP) 32 | extern physaddr_t lapicaddr; // Physical MMIO address of the local APIC 33 | 34 | // Per-CPU kernel stacks 35 | extern unsigned char percpu_kstacks[NCPU][KSTKSIZE]; 36 | 37 | int cpunum(void); 38 | #define thiscpu (&cpus[cpunum()]) 39 | 40 | void mp_init(void); 41 | void lapic_init(void); 42 | void lapic_startap(uint8_t apicid, uint32_t addr); 43 | void lapic_eoi(void); 44 | void lapic_ipi(int vector); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lab1/CODING: -------------------------------------------------------------------------------- 1 | JOS CODING STANDARDS 2 | 3 | It's easier on everyone if all authors working on a shared 4 | code base are consistent in the way they write their programs. 5 | We have the following conventions in our code: 6 | 7 | * No space after the name of a function in a call 8 | For example, printf("hello") not printf ("hello"). 9 | 10 | * One space after keywords "if", "for", "while", "switch". 11 | For example, if (x) not if(x). 12 | 13 | * Space before braces. 14 | For example, if (x) { not if (x){. 15 | 16 | * Function names are all lower-case separated by underscores. 17 | 18 | * Beginning-of-line indentation via tabs, not spaces. 19 | 20 | * Preprocessor macros are always UPPERCASE. 21 | There are a few grandfathered exceptions: assert, panic, 22 | static_assert, offsetof. 23 | 24 | * Pointer types have spaces: (uint16_t *) not (uint16_t*). 25 | 26 | * Multi-word names are lower_case_with_underscores. 27 | 28 | * Comments in imported code are usually C /* ... */ comments. 29 | Comments in new code are C++ style //. 30 | 31 | * In a function definition, the function name starts a new line. 32 | Then you can grep -n '^foo' */*.c to find the definition of foo. 33 | 34 | * Functions that take no arguments are declared f(void) not f(). 35 | 36 | The included .dir-locals.el file will automatically set up the basic 37 | indentation style in Emacs. 38 | -------------------------------------------------------------------------------- /lab2/CODING: -------------------------------------------------------------------------------- 1 | JOS CODING STANDARDS 2 | 3 | It's easier on everyone if all authors working on a shared 4 | code base are consistent in the way they write their programs. 5 | We have the following conventions in our code: 6 | 7 | * No space after the name of a function in a call 8 | For example, printf("hello") not printf ("hello"). 9 | 10 | * One space after keywords "if", "for", "while", "switch". 11 | For example, if (x) not if(x). 12 | 13 | * Space before braces. 14 | For example, if (x) { not if (x){. 15 | 16 | * Function names are all lower-case separated by underscores. 17 | 18 | * Beginning-of-line indentation via tabs, not spaces. 19 | 20 | * Preprocessor macros are always UPPERCASE. 21 | There are a few grandfathered exceptions: assert, panic, 22 | static_assert, offsetof. 23 | 24 | * Pointer types have spaces: (uint16_t *) not (uint16_t*). 25 | 26 | * Multi-word names are lower_case_with_underscores. 27 | 28 | * Comments in imported code are usually C /* ... */ comments. 29 | Comments in new code are C++ style //. 30 | 31 | * In a function definition, the function name starts a new line. 32 | Then you can grep -n '^foo' */*.c to find the definition of foo. 33 | 34 | * Functions that take no arguments are declared f(void) not f(). 35 | 36 | The included .dir-locals.el file will automatically set up the basic 37 | indentation style in Emacs. 38 | -------------------------------------------------------------------------------- /lab3/CODING: -------------------------------------------------------------------------------- 1 | JOS CODING STANDARDS 2 | 3 | It's easier on everyone if all authors working on a shared 4 | code base are consistent in the way they write their programs. 5 | We have the following conventions in our code: 6 | 7 | * No space after the name of a function in a call 8 | For example, printf("hello") not printf ("hello"). 9 | 10 | * One space after keywords "if", "for", "while", "switch". 11 | For example, if (x) not if(x). 12 | 13 | * Space before braces. 14 | For example, if (x) { not if (x){. 15 | 16 | * Function names are all lower-case separated by underscores. 17 | 18 | * Beginning-of-line indentation via tabs, not spaces. 19 | 20 | * Preprocessor macros are always UPPERCASE. 21 | There are a few grandfathered exceptions: assert, panic, 22 | static_assert, offsetof. 23 | 24 | * Pointer types have spaces: (uint16_t *) not (uint16_t*). 25 | 26 | * Multi-word names are lower_case_with_underscores. 27 | 28 | * Comments in imported code are usually C /* ... */ comments. 29 | Comments in new code are C++ style //. 30 | 31 | * In a function definition, the function name starts a new line. 32 | Then you can grep -n '^foo' */*.c to find the definition of foo. 33 | 34 | * Functions that take no arguments are declared f(void) not f(). 35 | 36 | The included .dir-locals.el file will automatically set up the basic 37 | indentation style in Emacs. 38 | -------------------------------------------------------------------------------- /lab4/CODING: -------------------------------------------------------------------------------- 1 | JOS CODING STANDARDS 2 | 3 | It's easier on everyone if all authors working on a shared 4 | code base are consistent in the way they write their programs. 5 | We have the following conventions in our code: 6 | 7 | * No space after the name of a function in a call 8 | For example, printf("hello") not printf ("hello"). 9 | 10 | * One space after keywords "if", "for", "while", "switch". 11 | For example, if (x) not if(x). 12 | 13 | * Space before braces. 14 | For example, if (x) { not if (x){. 15 | 16 | * Function names are all lower-case separated by underscores. 17 | 18 | * Beginning-of-line indentation via tabs, not spaces. 19 | 20 | * Preprocessor macros are always UPPERCASE. 21 | There are a few grandfathered exceptions: assert, panic, 22 | static_assert, offsetof. 23 | 24 | * Pointer types have spaces: (uint16_t *) not (uint16_t*). 25 | 26 | * Multi-word names are lower_case_with_underscores. 27 | 28 | * Comments in imported code are usually C /* ... */ comments. 29 | Comments in new code are C++ style //. 30 | 31 | * In a function definition, the function name starts a new line. 32 | Then you can grep -n '^foo' */*.c to find the definition of foo. 33 | 34 | * Functions that take no arguments are declared f(void) not f(). 35 | 36 | The included .dir-locals.el file will automatically set up the basic 37 | indentation style in Emacs. 38 | -------------------------------------------------------------------------------- /lab4/kern/spinlock.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_SPINLOCK_H 2 | #define JOS_INC_SPINLOCK_H 3 | 4 | #include 5 | 6 | // Comment this to disable spinlock debugging 7 | #define DEBUG_SPINLOCK 8 | 9 | // Mutual exclusion lock. 10 | struct spinlock { 11 | unsigned locked; // Is the lock held? 12 | 13 | #ifdef DEBUG_SPINLOCK 14 | // For debugging: 15 | char *name; // Name of lock. 16 | struct CpuInfo *cpu; // The CPU holding the lock. 17 | uintptr_t pcs[10]; // The call stack (an array of program counters) 18 | // that locked the lock. 19 | #endif 20 | }; 21 | 22 | void __spin_initlock(struct spinlock *lk, char *name); 23 | void spin_lock(struct spinlock *lk); 24 | void spin_unlock(struct spinlock *lk); 25 | 26 | #define spin_initlock(lock) __spin_initlock(lock, #lock) 27 | 28 | extern struct spinlock kernel_lock; 29 | 30 | static inline void 31 | lock_kernel(void) 32 | { 33 | spin_lock(&kernel_lock); 34 | } 35 | 36 | static inline void 37 | unlock_kernel(void) 38 | { 39 | spin_unlock(&kernel_lock); 40 | 41 | // Normally we wouldn't need to do this, but QEMU only runs 42 | // one CPU at a time and has a long time-slice. Without the 43 | // pause, this CPU is likely to reacquire the lock before 44 | // another CPU has even been given a chance to acquire it. 45 | asm volatile("pause"); 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lab4/user/primes.c: -------------------------------------------------------------------------------- 1 | // Concurrent version of prime sieve of Eratosthenes. 2 | // Invented by Doug McIlroy, inventor of Unix pipes. 3 | // See http://swtch.com/~rsc/thread/. 4 | // The picture halfway down the page and the text surrounding it 5 | // explain what's going on here. 6 | // 7 | // Since NENVS is 1024, we can print 1022 primes before running out. 8 | // The remaining two environments are the integer generator at the bottom 9 | // of main and user/idle. 10 | 11 | #include 12 | 13 | unsigned 14 | primeproc(void) 15 | { 16 | int i, id, p; 17 | envid_t envid; 18 | 19 | // fetch a prime from our left neighbor 20 | top: 21 | p = ipc_recv(&envid, 0, 0); 22 | cprintf("CPU %d: %d ", thisenv->env_cpunum, p); 23 | 24 | // fork a right neighbor to continue the chain 25 | if ((id = fork()) < 0) 26 | panic("fork: %e", id); 27 | if (id == 0) 28 | goto top; 29 | 30 | // filter out multiples of our prime 31 | while (1) { 32 | i = ipc_recv(&envid, 0, 0); 33 | if (i % p) 34 | ipc_send(id, i, 0, 0); 35 | } 36 | } 37 | 38 | void 39 | umain(int argc, char **argv) 40 | { 41 | int i, id; 42 | 43 | // fork the first prime process in the chain 44 | if ((id = fork()) < 0) 45 | panic("fork: %e", id); 46 | if (id == 0) 47 | primeproc(); 48 | 49 | // feed all the integers through 50 | for (i = 2; ; i++) 51 | ipc_send(id, i, 0, 0); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /lab4/obj/user/hello.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029e0 R __STAB_END__ 3 | 002029e1 R __STABSTR_BEGIN__ 4 | 00204459 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080005e T libmain 9 | 008000a4 T exit 10 | 008000b6 t putch 11 | 008000f8 T vcprintf 12 | 00800149 T cprintf 13 | 0080015d t printnum 14 | 0080020c t getuint 15 | 00800246 t sprintputch 16 | 00800263 T printfmt 17 | 00800280 T vprintfmt 18 | 0080062d T vsnprintf 19 | 0080067b T snprintf 20 | 00800695 T strlen 21 | 008006ad T strnlen 22 | 008006ce T strcpy 23 | 008006ee T strcat 24 | 00800710 T strncpy 25 | 0080073d T strlcpy 26 | 00800778 T strcmp 27 | 0080079e T strncmp 28 | 008007d6 T strchr 29 | 008007f7 T strfind 30 | 00800813 T memset 31 | 00800860 T memmove 32 | 008008c8 T memcpy 33 | 008008db T memcmp 34 | 00800914 T memfind 35 | 00800937 T strtol 36 | 00800a15 T sys_cputs 37 | 00800a33 T sys_cgetc 38 | 00800a52 T sys_env_destroy 39 | 00800a93 T sys_getenvid 40 | 00800ab2 T sys_yield 41 | 00800ad1 T sys_page_alloc 42 | 00800b14 T sys_page_map 43 | 00800b56 T sys_page_unmap 44 | 00800b98 T sys_env_set_status 45 | 00800bda T sys_env_set_pgfault_upcall 46 | 00800c1c T sys_ipc_try_send 47 | 00800c3f T sys_ipc_recv 48 | 00800c80 T _panic 49 | 00800cd0 T __udivdi3 50 | 00800e00 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/idle.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029ec R __STAB_END__ 3 | 002029ed R __STABSTR_BEGIN__ 4 | 00204488 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080004a T libmain 9 | 00800090 T exit 10 | 008000a2 T sys_cputs 11 | 008000c0 T sys_cgetc 12 | 008000df T sys_env_destroy 13 | 00800120 T sys_getenvid 14 | 0080013f T sys_yield 15 | 0080015e T sys_page_alloc 16 | 008001a1 T sys_page_map 17 | 008001e3 T sys_page_unmap 18 | 00800225 T sys_env_set_status 19 | 00800267 T sys_env_set_pgfault_upcall 20 | 008002a9 T sys_ipc_try_send 21 | 008002cc T sys_ipc_recv 22 | 0080030d T _panic 23 | 00800353 t putch 24 | 00800395 T vcprintf 25 | 008003e6 T cprintf 26 | 008003fa t printnum 27 | 008004a9 t getuint 28 | 008004e3 t sprintputch 29 | 00800500 T printfmt 30 | 0080051d T vprintfmt 31 | 008008ca T vsnprintf 32 | 00800918 T snprintf 33 | 00800932 T strlen 34 | 0080094a T strnlen 35 | 0080096b T strcpy 36 | 0080098b T strcat 37 | 008009ad T strncpy 38 | 008009da T strlcpy 39 | 00800a15 T strcmp 40 | 00800a3b T strncmp 41 | 00800a73 T strchr 42 | 00800a94 T strfind 43 | 00800ab0 T memset 44 | 00800afd T memmove 45 | 00800b65 T memcpy 46 | 00800b78 T memcmp 47 | 00800bb1 T memfind 48 | 00800bd4 T strtol 49 | 00800cc0 T __udivdi3 50 | 00800df0 T __umoddi3 51 | 008011e0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/yield.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202a40 R __STAB_END__ 3 | 00202a41 R __STABSTR_BEGIN__ 4 | 002044c2 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080009a T libmain 9 | 008000e0 T exit 10 | 008000f2 t putch 11 | 00800134 T vcprintf 12 | 00800185 T cprintf 13 | 00800199 t printnum 14 | 00800248 t getuint 15 | 00800282 t sprintputch 16 | 0080029f T printfmt 17 | 008002bc T vprintfmt 18 | 00800669 T vsnprintf 19 | 008006b7 T snprintf 20 | 008006d1 T strlen 21 | 008006e9 T strnlen 22 | 0080070a T strcpy 23 | 0080072a T strcat 24 | 0080074c T strncpy 25 | 00800779 T strlcpy 26 | 008007b4 T strcmp 27 | 008007da T strncmp 28 | 00800812 T strchr 29 | 00800833 T strfind 30 | 0080084f T memset 31 | 0080089c T memmove 32 | 00800904 T memcpy 33 | 00800917 T memcmp 34 | 00800950 T memfind 35 | 00800973 T strtol 36 | 00800a51 T sys_cputs 37 | 00800a6f T sys_cgetc 38 | 00800a8e T sys_env_destroy 39 | 00800acf T sys_getenvid 40 | 00800aee T sys_yield 41 | 00800b0d T sys_page_alloc 42 | 00800b50 T sys_page_map 43 | 00800b92 T sys_page_unmap 44 | 00800bd4 T sys_env_set_status 45 | 00800c16 T sys_env_set_pgfault_upcall 46 | 00800c58 T sys_ipc_try_send 47 | 00800c7b T sys_ipc_recv 48 | 00800cbc T _panic 49 | 00800d10 T __udivdi3 50 | 00800e40 T __umoddi3 51 | 00801240 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/badsegment.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204452 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080003e T libmain 9 | 00800084 T exit 10 | 00800096 T sys_cputs 11 | 008000b4 T sys_cgetc 12 | 008000d3 T sys_env_destroy 13 | 00800114 T sys_getenvid 14 | 00800133 T sys_yield 15 | 00800152 T sys_page_alloc 16 | 00800195 T sys_page_map 17 | 008001d7 T sys_page_unmap 18 | 00800219 T sys_env_set_status 19 | 0080025b T sys_env_set_pgfault_upcall 20 | 0080029d T sys_ipc_try_send 21 | 008002c0 T sys_ipc_recv 22 | 00800301 T _panic 23 | 00800347 t putch 24 | 00800389 T vcprintf 25 | 008003da T cprintf 26 | 008003ee t printnum 27 | 0080049d t getuint 28 | 008004d7 t sprintputch 29 | 008004f4 T printfmt 30 | 00800511 T vprintfmt 31 | 008008be T vsnprintf 32 | 0080090c T snprintf 33 | 00800926 T strlen 34 | 0080093e T strnlen 35 | 0080095f T strcpy 36 | 0080097f T strcat 37 | 008009a1 T strncpy 38 | 008009ce T strlcpy 39 | 00800a09 T strcmp 40 | 00800a2f T strncmp 41 | 00800a67 T strchr 42 | 00800a88 T strfind 43 | 00800aa4 T memset 44 | 00800af1 T memmove 45 | 00800b59 T memcpy 46 | 00800b6c T memcmp 47 | 00800ba5 T memfind 48 | 00800bc8 T strtol 49 | 00800cb0 T __udivdi3 50 | 00800de0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/breakpoint.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204452 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800039 T libmain 9 | 0080007f T exit 10 | 00800091 T sys_cputs 11 | 008000af T sys_cgetc 12 | 008000ce T sys_env_destroy 13 | 0080010f T sys_getenvid 14 | 0080012e T sys_yield 15 | 0080014d T sys_page_alloc 16 | 00800190 T sys_page_map 17 | 008001d2 T sys_page_unmap 18 | 00800214 T sys_env_set_status 19 | 00800256 T sys_env_set_pgfault_upcall 20 | 00800298 T sys_ipc_try_send 21 | 008002bb T sys_ipc_recv 22 | 008002fc T _panic 23 | 00800342 t putch 24 | 00800384 T vcprintf 25 | 008003d5 T cprintf 26 | 008003e9 t printnum 27 | 00800498 t getuint 28 | 008004d2 t sprintputch 29 | 008004ef T printfmt 30 | 0080050c T vprintfmt 31 | 008008b9 T vsnprintf 32 | 00800907 T snprintf 33 | 00800921 T strlen 34 | 00800939 T strnlen 35 | 0080095a T strcpy 36 | 0080097a T strcat 37 | 0080099c T strncpy 38 | 008009c9 T strlcpy 39 | 00800a04 T strcmp 40 | 00800a2a T strncmp 41 | 00800a62 T strchr 42 | 00800a83 T strfind 43 | 00800a9f T memset 44 | 00800aec T memmove 45 | 00800b54 T memcpy 46 | 00800b67 T memcmp 47 | 00800ba0 T memfind 48 | 00800bc3 T strtol 49 | 00800cb0 T __udivdi3 50 | 00800de0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/buggyhello.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204452 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800047 T libmain 9 | 0080008d T exit 10 | 0080009f T sys_cputs 11 | 008000bd T sys_cgetc 12 | 008000dc T sys_env_destroy 13 | 0080011d T sys_getenvid 14 | 0080013c T sys_yield 15 | 0080015b T sys_page_alloc 16 | 0080019e T sys_page_map 17 | 008001e0 T sys_page_unmap 18 | 00800222 T sys_env_set_status 19 | 00800264 T sys_env_set_pgfault_upcall 20 | 008002a6 T sys_ipc_try_send 21 | 008002c9 T sys_ipc_recv 22 | 0080030a T _panic 23 | 00800350 t putch 24 | 00800392 T vcprintf 25 | 008003e3 T cprintf 26 | 008003f7 t printnum 27 | 008004a6 t getuint 28 | 008004e0 t sprintputch 29 | 008004fd T printfmt 30 | 0080051a T vprintfmt 31 | 008008c7 T vsnprintf 32 | 00800915 T snprintf 33 | 0080092f T strlen 34 | 00800947 T strnlen 35 | 00800968 T strcpy 36 | 00800988 T strcat 37 | 008009aa T strncpy 38 | 008009d7 T strlcpy 39 | 00800a12 T strcmp 40 | 00800a38 T strncmp 41 | 00800a70 T strchr 42 | 00800a91 T strfind 43 | 00800aad T memset 44 | 00800afa T memmove 45 | 00800b62 T memcpy 46 | 00800b75 T memcmp 47 | 00800bae T memfind 48 | 00800bd1 T strtol 49 | 00800cb0 T __udivdi3 50 | 00800de0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/evilhello.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204451 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080004a T libmain 9 | 00800090 T exit 10 | 008000a2 T sys_cputs 11 | 008000c0 T sys_cgetc 12 | 008000df T sys_env_destroy 13 | 00800120 T sys_getenvid 14 | 0080013f T sys_yield 15 | 0080015e T sys_page_alloc 16 | 008001a1 T sys_page_map 17 | 008001e3 T sys_page_unmap 18 | 00800225 T sys_env_set_status 19 | 00800267 T sys_env_set_pgfault_upcall 20 | 008002a9 T sys_ipc_try_send 21 | 008002cc T sys_ipc_recv 22 | 0080030d T _panic 23 | 00800353 t putch 24 | 00800395 T vcprintf 25 | 008003e6 T cprintf 26 | 008003fa t printnum 27 | 008004a9 t getuint 28 | 008004e3 t sprintputch 29 | 00800500 T printfmt 30 | 0080051d T vprintfmt 31 | 008008ca T vsnprintf 32 | 00800918 T snprintf 33 | 00800932 T strlen 34 | 0080094a T strnlen 35 | 0080096b T strcpy 36 | 0080098b T strcat 37 | 008009ad T strncpy 38 | 008009da T strlcpy 39 | 00800a15 T strcmp 40 | 00800a3b T strncmp 41 | 00800a73 T strchr 42 | 00800a94 T strfind 43 | 00800ab0 T memset 44 | 00800afd T memmove 45 | 00800b65 T memcpy 46 | 00800b78 T memcmp 47 | 00800bb1 T memfind 48 | 00800bd4 T strtol 49 | 00800cc0 T __udivdi3 50 | 00800df0 T __umoddi3 51 | 008011e0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/faultread.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204451 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080004e T libmain 9 | 00800094 T exit 10 | 008000a6 t putch 11 | 008000e8 T vcprintf 12 | 00800139 T cprintf 13 | 0080014d t printnum 14 | 008001fc t getuint 15 | 00800236 t sprintputch 16 | 00800253 T printfmt 17 | 00800270 T vprintfmt 18 | 0080061d T vsnprintf 19 | 0080066b T snprintf 20 | 00800685 T strlen 21 | 0080069d T strnlen 22 | 008006be T strcpy 23 | 008006de T strcat 24 | 00800700 T strncpy 25 | 0080072d T strlcpy 26 | 00800768 T strcmp 27 | 0080078e T strncmp 28 | 008007c6 T strchr 29 | 008007e7 T strfind 30 | 00800803 T memset 31 | 00800850 T memmove 32 | 008008b8 T memcpy 33 | 008008cb T memcmp 34 | 00800904 T memfind 35 | 00800927 T strtol 36 | 00800a05 T sys_cputs 37 | 00800a23 T sys_cgetc 38 | 00800a42 T sys_env_destroy 39 | 00800a83 T sys_getenvid 40 | 00800aa2 T sys_yield 41 | 00800ac1 T sys_page_alloc 42 | 00800b04 T sys_page_map 43 | 00800b46 T sys_page_unmap 44 | 00800b88 T sys_env_set_status 45 | 00800bca T sys_env_set_pgfault_upcall 46 | 00800c0c T sys_ipc_try_send 47 | 00800c2f T sys_ipc_recv 48 | 00800c70 T _panic 49 | 00800cc0 T __udivdi3 50 | 00800df0 T __umoddi3 51 | 008011a0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/faultwrite.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204452 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800042 T libmain 9 | 00800088 T exit 10 | 0080009a T sys_cputs 11 | 008000b8 T sys_cgetc 12 | 008000d7 T sys_env_destroy 13 | 00800118 T sys_getenvid 14 | 00800137 T sys_yield 15 | 00800156 T sys_page_alloc 16 | 00800199 T sys_page_map 17 | 008001db T sys_page_unmap 18 | 0080021d T sys_env_set_status 19 | 0080025f T sys_env_set_pgfault_upcall 20 | 008002a1 T sys_ipc_try_send 21 | 008002c4 T sys_ipc_recv 22 | 00800305 T _panic 23 | 0080034b t putch 24 | 0080038d T vcprintf 25 | 008003de T cprintf 26 | 008003f2 t printnum 27 | 008004a1 t getuint 28 | 008004db t sprintputch 29 | 008004f8 T printfmt 30 | 00800515 T vprintfmt 31 | 008008c2 T vsnprintf 32 | 00800910 T snprintf 33 | 0080092a T strlen 34 | 00800942 T strnlen 35 | 00800963 T strcpy 36 | 00800983 T strcat 37 | 008009a5 T strncpy 38 | 008009d2 T strlcpy 39 | 00800a0d T strcmp 40 | 00800a33 T strncmp 41 | 00800a6b T strchr 42 | 00800a8c T strfind 43 | 00800aa8 T memset 44 | 00800af5 T memmove 45 | 00800b5d T memcpy 46 | 00800b70 T memcmp 47 | 00800ba9 T memfind 48 | 00800bcc T strtol 49 | 00800cb0 T __udivdi3 50 | 00800de0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/softint.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 0020444f R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080003a T libmain 9 | 00800080 T exit 10 | 00800092 T sys_cputs 11 | 008000b0 T sys_cgetc 12 | 008000cf T sys_env_destroy 13 | 00800110 T sys_getenvid 14 | 0080012f T sys_yield 15 | 0080014e T sys_page_alloc 16 | 00800191 T sys_page_map 17 | 008001d3 T sys_page_unmap 18 | 00800215 T sys_env_set_status 19 | 00800257 T sys_env_set_pgfault_upcall 20 | 00800299 T sys_ipc_try_send 21 | 008002bc T sys_ipc_recv 22 | 008002fd T _panic 23 | 00800343 t putch 24 | 00800385 T vcprintf 25 | 008003d6 T cprintf 26 | 008003ea t printnum 27 | 00800499 t getuint 28 | 008004d3 t sprintputch 29 | 008004f0 T printfmt 30 | 0080050d T vprintfmt 31 | 008008ba T vsnprintf 32 | 00800908 T snprintf 33 | 00800922 T strlen 34 | 0080093a T strnlen 35 | 0080095b T strcpy 36 | 0080097b T strcat 37 | 0080099d T strncpy 38 | 008009ca T strlcpy 39 | 00800a05 T strcmp 40 | 00800a2b T strncmp 41 | 00800a63 T strchr 42 | 00800a84 T strfind 43 | 00800aa0 T memset 44 | 00800aed T memmove 45 | 00800b55 T memcpy 46 | 00800b68 T memcmp 47 | 00800ba1 T memfind 48 | 00800bc4 T strtol 49 | 00800cb0 T __udivdi3 50 | 00800de0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/faultbadhandler.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029ec R __STAB_END__ 3 | 002029ed R __STABSTR_BEGIN__ 4 | 0020446f R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800065 T libmain 9 | 008000ab T exit 10 | 008000bd T sys_cputs 11 | 008000db T sys_cgetc 12 | 008000fa T sys_env_destroy 13 | 0080013b T sys_getenvid 14 | 0080015a T sys_yield 15 | 00800179 T sys_page_alloc 16 | 008001bc T sys_page_map 17 | 008001fe T sys_page_unmap 18 | 00800240 T sys_env_set_status 19 | 00800282 T sys_env_set_pgfault_upcall 20 | 008002c4 T sys_ipc_try_send 21 | 008002e7 T sys_ipc_recv 22 | 00800328 T _panic 23 | 0080036e t putch 24 | 008003b0 T vcprintf 25 | 00800401 T cprintf 26 | 00800415 t printnum 27 | 008004c4 t getuint 28 | 008004fe t sprintputch 29 | 0080051b T printfmt 30 | 00800538 T vprintfmt 31 | 008008e5 T vsnprintf 32 | 00800933 T snprintf 33 | 0080094d T strlen 34 | 00800965 T strnlen 35 | 00800986 T strcpy 36 | 008009a6 T strcat 37 | 008009c8 T strncpy 38 | 008009f5 T strlcpy 39 | 00800a30 T strcmp 40 | 00800a56 T strncmp 41 | 00800a8e T strchr 42 | 00800aaf T strfind 43 | 00800acb T memset 44 | 00800b18 T memmove 45 | 00800b80 T memcpy 46 | 00800b93 T memcmp 47 | 00800bcc T memfind 48 | 00800bef T strtol 49 | 00800cd0 T __udivdi3 50 | 00800e00 T __umoddi3 51 | 008011e0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/faultevilhandler.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029ec R __STAB_END__ 3 | 002029ed R __STABSTR_BEGIN__ 4 | 00204470 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800065 T libmain 9 | 008000ab T exit 10 | 008000bd T sys_cputs 11 | 008000db T sys_cgetc 12 | 008000fa T sys_env_destroy 13 | 0080013b T sys_getenvid 14 | 0080015a T sys_yield 15 | 00800179 T sys_page_alloc 16 | 008001bc T sys_page_map 17 | 008001fe T sys_page_unmap 18 | 00800240 T sys_env_set_status 19 | 00800282 T sys_env_set_pgfault_upcall 20 | 008002c4 T sys_ipc_try_send 21 | 008002e7 T sys_ipc_recv 22 | 00800328 T _panic 23 | 0080036e t putch 24 | 008003b0 T vcprintf 25 | 00800401 T cprintf 26 | 00800415 t printnum 27 | 008004c4 t getuint 28 | 008004fe t sprintputch 29 | 0080051b T printfmt 30 | 00800538 T vprintfmt 31 | 008008e5 T vsnprintf 32 | 00800933 T snprintf 33 | 0080094d T strlen 34 | 00800965 T strnlen 35 | 00800986 T strcpy 36 | 008009a6 T strcat 37 | 008009c8 T strncpy 38 | 008009f5 T strlcpy 39 | 00800a30 T strcmp 40 | 00800a56 T strncmp 41 | 00800a8e T strchr 42 | 00800aaf T strfind 43 | 00800acb T memset 44 | 00800b18 T memmove 45 | 00800b80 T memcpy 46 | 00800b93 T memcmp 47 | 00800bcc T memfind 48 | 00800bef T strtol 49 | 00800cd0 T __udivdi3 50 | 00800e00 T __umoddi3 51 | 008011e0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/faultreadkernel.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204457 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080004e T libmain 9 | 00800094 T exit 10 | 008000a6 t putch 11 | 008000e8 T vcprintf 12 | 00800139 T cprintf 13 | 0080014d t printnum 14 | 008001fc t getuint 15 | 00800236 t sprintputch 16 | 00800253 T printfmt 17 | 00800270 T vprintfmt 18 | 0080061d T vsnprintf 19 | 0080066b T snprintf 20 | 00800685 T strlen 21 | 0080069d T strnlen 22 | 008006be T strcpy 23 | 008006de T strcat 24 | 00800700 T strncpy 25 | 0080072d T strlcpy 26 | 00800768 T strcmp 27 | 0080078e T strncmp 28 | 008007c6 T strchr 29 | 008007e7 T strfind 30 | 00800803 T memset 31 | 00800850 T memmove 32 | 008008b8 T memcpy 33 | 008008cb T memcmp 34 | 00800904 T memfind 35 | 00800927 T strtol 36 | 00800a05 T sys_cputs 37 | 00800a23 T sys_cgetc 38 | 00800a42 T sys_env_destroy 39 | 00800a83 T sys_getenvid 40 | 00800aa2 T sys_yield 41 | 00800ac1 T sys_page_alloc 42 | 00800b04 T sys_page_map 43 | 00800b46 T sys_page_unmap 44 | 00800b88 T sys_env_set_status 45 | 00800bca T sys_env_set_pgfault_upcall 46 | 00800c0c T sys_ipc_try_send 47 | 00800c2f T sys_ipc_recv 48 | 00800c70 T _panic 49 | 00800cc0 T __udivdi3 50 | 00800df0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/faultwritekernel.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029d4 R __STAB_END__ 3 | 002029d5 R __STABSTR_BEGIN__ 4 | 00204458 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800042 T libmain 9 | 00800088 T exit 10 | 0080009a T sys_cputs 11 | 008000b8 T sys_cgetc 12 | 008000d7 T sys_env_destroy 13 | 00800118 T sys_getenvid 14 | 00800137 T sys_yield 15 | 00800156 T sys_page_alloc 16 | 00800199 T sys_page_map 17 | 008001db T sys_page_unmap 18 | 0080021d T sys_env_set_status 19 | 0080025f T sys_env_set_pgfault_upcall 20 | 008002a1 T sys_ipc_try_send 21 | 008002c4 T sys_ipc_recv 22 | 00800305 T _panic 23 | 0080034b t putch 24 | 0080038d T vcprintf 25 | 008003de T cprintf 26 | 008003f2 t printnum 27 | 008004a1 t getuint 28 | 008004db t sprintputch 29 | 008004f8 T printfmt 30 | 00800515 T vprintfmt 31 | 008008c2 T vsnprintf 32 | 00800910 T snprintf 33 | 0080092a T strlen 34 | 00800942 T strnlen 35 | 00800963 T strcpy 36 | 00800983 T strcat 37 | 008009a5 T strncpy 38 | 008009d2 T strlcpy 39 | 00800a0d T strcmp 40 | 00800a33 T strncmp 41 | 00800a6b T strchr 42 | 00800a8c T strfind 43 | 00800aa8 T memset 44 | 00800af5 T memmove 45 | 00800b5d T memcpy 46 | 00800b70 T memcmp 47 | 00800ba9 T memfind 48 | 00800bcc T strtol 49 | 00800cb0 T __udivdi3 50 | 00800de0 T __umoddi3 51 | 008011c0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B thisenv 54 | eec00000 A envs 55 | ef000000 A pages 56 | ef400000 A uvpt 57 | ef7bd000 A uvpd 58 | -------------------------------------------------------------------------------- /lab4/obj/user/divzero.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029ec R __STAB_END__ 3 | 002029ed R __STABSTR_BEGIN__ 4 | 00204473 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800060 T libmain 9 | 008000a6 T exit 10 | 008000b8 t putch 11 | 008000fa T vcprintf 12 | 0080014b T cprintf 13 | 0080015f t printnum 14 | 0080020e t getuint 15 | 00800248 t sprintputch 16 | 00800265 T printfmt 17 | 00800282 T vprintfmt 18 | 0080062f T vsnprintf 19 | 0080067d T snprintf 20 | 00800697 T strlen 21 | 008006af T strnlen 22 | 008006d0 T strcpy 23 | 008006f0 T strcat 24 | 00800712 T strncpy 25 | 0080073f T strlcpy 26 | 0080077a T strcmp 27 | 008007a0 T strncmp 28 | 008007d8 T strchr 29 | 008007f9 T strfind 30 | 00800815 T memset 31 | 00800862 T memmove 32 | 008008ca T memcpy 33 | 008008dd T memcmp 34 | 00800916 T memfind 35 | 00800939 T strtol 36 | 00800a17 T sys_cputs 37 | 00800a35 T sys_cgetc 38 | 00800a54 T sys_env_destroy 39 | 00800a95 T sys_getenvid 40 | 00800ab4 T sys_yield 41 | 00800ad3 T sys_page_alloc 42 | 00800b16 T sys_page_map 43 | 00800b58 T sys_page_unmap 44 | 00800b9a T sys_env_set_status 45 | 00800bdc T sys_env_set_pgfault_upcall 46 | 00800c1e T sys_ipc_try_send 47 | 00800c41 T sys_ipc_recv 48 | 00800c82 T _panic 49 | 00800cd0 T __udivdi3 50 | 00800e00 T __umoddi3 51 | 008011a0 r error_string 52 | 00802000 D binaryname 53 | 00802004 B zero 54 | 00802008 B thisenv 55 | eec00000 A envs 56 | ef000000 A pages 57 | ef400000 A uvpt 58 | ef7bd000 A uvpd 59 | -------------------------------------------------------------------------------- /lab4/obj/user/buggyhello2.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002029e0 R __STAB_END__ 3 | 002029e1 R __STABSTR_BEGIN__ 4 | 00204474 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 0080004e T libmain 9 | 00800094 T exit 10 | 008000a6 T sys_cputs 11 | 008000c4 T sys_cgetc 12 | 008000e3 T sys_env_destroy 13 | 00800124 T sys_getenvid 14 | 00800143 T sys_yield 15 | 00800162 T sys_page_alloc 16 | 008001a5 T sys_page_map 17 | 008001e7 T sys_page_unmap 18 | 00800229 T sys_env_set_status 19 | 0080026b T sys_env_set_pgfault_upcall 20 | 008002ad T sys_ipc_try_send 21 | 008002d0 T sys_ipc_recv 22 | 00800311 T _panic 23 | 00800357 t putch 24 | 00800399 T vcprintf 25 | 008003ea T cprintf 26 | 008003fe t printnum 27 | 008004ad t getuint 28 | 008004e7 t sprintputch 29 | 00800504 T printfmt 30 | 00800521 T vprintfmt 31 | 008008ce T vsnprintf 32 | 0080091c T snprintf 33 | 00800936 T strlen 34 | 0080094e T strnlen 35 | 0080096f T strcpy 36 | 0080098f T strcat 37 | 008009b1 T strncpy 38 | 008009de T strlcpy 39 | 00800a19 T strcmp 40 | 00800a3f T strncmp 41 | 00800a77 T strchr 42 | 00800a98 T strfind 43 | 00800ab4 T memset 44 | 00800b01 T memmove 45 | 00800b69 T memcpy 46 | 00800b7c T memcmp 47 | 00800bb5 T memfind 48 | 00800bd8 T strtol 49 | 00800cc0 T __udivdi3 50 | 00800df0 T __umoddi3 51 | 008011e0 r error_string 52 | 00802000 D hello 53 | 00802004 D binaryname 54 | 00802008 B thisenv 55 | eec00000 A envs 56 | ef000000 A pages 57 | ef400000 A uvpt 58 | ef7bd000 A uvpd 59 | -------------------------------------------------------------------------------- /lab4/obj/user/testbss.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202a64 R __STAB_END__ 3 | 00202a65 R __STABSTR_BEGIN__ 4 | 0020451f R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 008000dc T libmain 9 | 00800122 T exit 10 | 00800134 T _panic 11 | 0080017a t putch 12 | 008001bc T vcprintf 13 | 0080020d T cprintf 14 | 00800221 t printnum 15 | 008002d0 t getuint 16 | 0080030a t sprintputch 17 | 00800327 T printfmt 18 | 00800344 T vprintfmt 19 | 008006f1 T vsnprintf 20 | 0080073f T snprintf 21 | 00800759 T strlen 22 | 00800771 T strnlen 23 | 00800792 T strcpy 24 | 008007b2 T strcat 25 | 008007d4 T strncpy 26 | 00800801 T strlcpy 27 | 0080083c T strcmp 28 | 00800862 T strncmp 29 | 0080089a T strchr 30 | 008008bb T strfind 31 | 008008d7 T memset 32 | 00800924 T memmove 33 | 0080098c T memcpy 34 | 0080099f T memcmp 35 | 008009d8 T memfind 36 | 008009fb T strtol 37 | 00800ad9 T sys_cputs 38 | 00800af7 T sys_cgetc 39 | 00800b16 T sys_env_destroy 40 | 00800b57 T sys_getenvid 41 | 00800b76 T sys_yield 42 | 00800b95 T sys_page_alloc 43 | 00800bd8 T sys_page_map 44 | 00800c1a T sys_page_unmap 45 | 00800c5c T sys_env_set_status 46 | 00800c9e T sys_env_set_pgfault_upcall 47 | 00800ce0 T sys_ipc_try_send 48 | 00800d03 T sys_ipc_recv 49 | 00800d50 T __udivdi3 50 | 00800e80 T __umoddi3 51 | 00801300 r error_string 52 | 00802000 D binaryname 53 | 00802020 B bigarray 54 | 00c02020 B thisenv 55 | eec00000 A envs 56 | ef000000 A pages 57 | ef400000 A uvpt 58 | ef7bd000 A uvpd 59 | -------------------------------------------------------------------------------- /lab1/jos.out: -------------------------------------------------------------------------------- 1 | *** Now run 'make gdb'. 2 | *** 3 | 6828 decimal is 15254 octal! 4 | entering test_backtrace 5 5 | entering test_backtrace 4 6 | entering test_backtrace 3 7 | entering test_backtrace 2 8 | entering test_backtrace 1 9 | entering test_backtrace 0 10 | Stack backtrace: 11 | ebp f010ff18 eip f010007b args 00000000 00000000 00000000 00000000 f010093e 12 | kern/init.c:18: test_backtrace+59 13 | ebp f010ff38 eip f0100068 args 00000000 00000001 f010ff78 00000000 f010093e 14 | kern/init.c:16: test_backtrace+40 15 | ebp f010ff58 eip f0100068 args 00000001 00000002 f010ff98 00000000 f010093e 16 | kern/init.c:16: test_backtrace+40 17 | ebp f010ff78 eip f0100068 args 00000002 00000003 f010ffb8 00000000 f010093e 18 | kern/init.c:16: test_backtrace+40 19 | ebp f010ff98 eip f0100068 args 00000003 00000004 00000000 00000000 00000000 20 | kern/init.c:16: test_backtrace+40 21 | ebp f010ffb8 eip f0100068 args 00000004 00000005 00000000 00010094 00010094 22 | kern/init.c:16: test_backtrace+40 23 | ebp f010ffd8 eip f01000d4 args 00000005 00001aac 00000644 00000000 00000000 24 | kern/init.c:39: i386_init+64 25 | ebp f010fff8 eip f010003e args 00111021 00000000 00000000 00000000 00000000 26 | kern/entry.S:83: +0 27 | leaving test_backtrace 0 28 | leaving test_backtrace 1 29 | leaving test_backtrace 2 30 | leaving test_backtrace 3 31 | leaving test_backtrace 4 32 | leaving test_backtrace 5 33 | Welcome to the JOS kernel monitor! 34 | Type 'help' for a list of commands. 35 | qemu: terminating on signal 15 from pid 5119 36 | -------------------------------------------------------------------------------- /lab3/lib/printf.c: -------------------------------------------------------------------------------- 1 | // Implementation of cprintf console output for user environments, 2 | // based on printfmt() and the sys_cputs() system call. 3 | // 4 | // cprintf is a debugging statement, not a generic output statement. 5 | // It is very important that it always go to the console, especially when 6 | // debugging file descriptor code! 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | // Collect up to 256 characters into a buffer 15 | // and perform ONE system call to print all of them, 16 | // in order to make the lines output to the console atomic 17 | // and prevent interrupts from causing context switches 18 | // in the middle of a console output line and such. 19 | struct printbuf { 20 | int idx; // current buffer index 21 | int cnt; // total bytes printed so far 22 | char buf[256]; 23 | }; 24 | 25 | 26 | static void 27 | putch(int ch, struct printbuf *b) 28 | { 29 | b->buf[b->idx++] = ch; 30 | if (b->idx == 256-1) { 31 | sys_cputs(b->buf, b->idx); 32 | b->idx = 0; 33 | } 34 | b->cnt++; 35 | } 36 | 37 | int 38 | vcprintf(const char *fmt, va_list ap) 39 | { 40 | struct printbuf b; 41 | 42 | b.idx = 0; 43 | b.cnt = 0; 44 | vprintfmt((void*)putch, &b, fmt, ap); 45 | sys_cputs(b.buf, b.idx); 46 | 47 | return b.cnt; 48 | } 49 | 50 | int 51 | cprintf(const char *fmt, ...) 52 | { 53 | va_list ap; 54 | int cnt; 55 | 56 | va_start(ap, fmt); 57 | cnt = vcprintf(fmt, ap); 58 | va_end(ap); 59 | 60 | return cnt; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /lab4/lib/printf.c: -------------------------------------------------------------------------------- 1 | // Implementation of cprintf console output for user environments, 2 | // based on printfmt() and the sys_cputs() system call. 3 | // 4 | // cprintf is a debugging statement, not a generic output statement. 5 | // It is very important that it always go to the console, especially when 6 | // debugging file descriptor code! 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | // Collect up to 256 characters into a buffer 15 | // and perform ONE system call to print all of them, 16 | // in order to make the lines output to the console atomic 17 | // and prevent interrupts from causing context switches 18 | // in the middle of a console output line and such. 19 | struct printbuf { 20 | int idx; // current buffer index 21 | int cnt; // total bytes printed so far 22 | char buf[256]; 23 | }; 24 | 25 | 26 | static void 27 | putch(int ch, struct printbuf *b) 28 | { 29 | b->buf[b->idx++] = ch; 30 | if (b->idx == 256-1) { 31 | sys_cputs(b->buf, b->idx); 32 | b->idx = 0; 33 | } 34 | b->cnt++; 35 | } 36 | 37 | int 38 | vcprintf(const char *fmt, va_list ap) 39 | { 40 | struct printbuf b; 41 | 42 | b.idx = 0; 43 | b.cnt = 0; 44 | vprintfmt((void*)putch, &b, fmt, ap); 45 | sys_cputs(b.buf, b.idx); 46 | 47 | return b.cnt; 48 | } 49 | 50 | int 51 | cprintf(const char *fmt, ...) 52 | { 53 | va_list ap; 54 | int cnt; 55 | 56 | va_start(ap, fmt); 57 | cnt = vcprintf(fmt, ap); 58 | va_end(ap); 59 | 60 | return cnt; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /lab4/obj/user/dumbfork.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202c20 R __STAB_END__ 3 | 00202c21 R __STABSTR_BEGIN__ 4 | 0020472a R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T duppage 8 | 008000d1 T dumbfork 9 | 00800183 T umain 10 | 008001db T libmain 11 | 00800221 T exit 12 | 00800233 T _panic 13 | 00800279 t putch 14 | 008002bb T vcprintf 15 | 0080030c T cprintf 16 | 00800320 t printnum 17 | 008003cf t getuint 18 | 00800409 t sprintputch 19 | 00800426 T printfmt 20 | 00800443 T vprintfmt 21 | 008007f0 T vsnprintf 22 | 0080083e T snprintf 23 | 00800858 T strlen 24 | 00800870 T strnlen 25 | 00800891 T strcpy 26 | 008008b1 T strcat 27 | 008008d3 T strncpy 28 | 00800900 T strlcpy 29 | 0080093b T strcmp 30 | 00800961 T strncmp 31 | 00800999 T strchr 32 | 008009ba T strfind 33 | 008009d6 T memset 34 | 00800a23 T memmove 35 | 00800a8b T memcpy 36 | 00800a9e T memcmp 37 | 00800ad7 T memfind 38 | 00800afa T strtol 39 | 00800bd8 T sys_cputs 40 | 00800bf6 T sys_cgetc 41 | 00800c15 T sys_env_destroy 42 | 00800c56 T sys_getenvid 43 | 00800c75 T sys_yield 44 | 00800c94 T sys_page_alloc 45 | 00800cd7 T sys_page_map 46 | 00800d19 T sys_page_unmap 47 | 00800d5b T sys_env_set_status 48 | 00800d9d T sys_env_set_pgfault_upcall 49 | 00800ddf T sys_ipc_try_send 50 | 00800e02 T sys_ipc_recv 51 | 00800e50 T __udivdi3 52 | 00800f80 T __umoddi3 53 | 008013c0 r error_string 54 | 00802000 D binaryname 55 | 00802004 B thisenv 56 | 00802008 B end 57 | eec00000 A envs 58 | ef000000 A pages 59 | ef400000 A uvpt 60 | ef7bd000 A uvpd 61 | -------------------------------------------------------------------------------- /lab1/inc/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_ELF_H 2 | #define JOS_INC_ELF_H 3 | 4 | #define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */ 5 | 6 | struct Elf { 7 | uint32_t e_magic; // must equal ELF_MAGIC 8 | uint8_t e_elf[12]; 9 | uint16_t e_type; 10 | uint16_t e_machine; 11 | uint32_t e_version; 12 | uint32_t e_entry; 13 | uint32_t e_phoff; 14 | uint32_t e_shoff; 15 | uint32_t e_flags; 16 | uint16_t e_ehsize; 17 | uint16_t e_phentsize; 18 | uint16_t e_phnum; 19 | uint16_t e_shentsize; 20 | uint16_t e_shnum; 21 | uint16_t e_shstrndx; 22 | }; 23 | 24 | struct Proghdr { 25 | uint32_t p_type; 26 | uint32_t p_offset; 27 | uint32_t p_va; 28 | uint32_t p_pa; 29 | uint32_t p_filesz; 30 | uint32_t p_memsz; 31 | uint32_t p_flags; 32 | uint32_t p_align; 33 | }; 34 | 35 | struct Secthdr { 36 | uint32_t sh_name; 37 | uint32_t sh_type; 38 | uint32_t sh_flags; 39 | uint32_t sh_addr; 40 | uint32_t sh_offset; 41 | uint32_t sh_size; 42 | uint32_t sh_link; 43 | uint32_t sh_info; 44 | uint32_t sh_addralign; 45 | uint32_t sh_entsize; 46 | }; 47 | 48 | // Values for Proghdr::p_type 49 | #define ELF_PROG_LOAD 1 50 | 51 | // Flag bits for Proghdr::p_flags 52 | #define ELF_PROG_FLAG_EXEC 1 53 | #define ELF_PROG_FLAG_WRITE 2 54 | #define ELF_PROG_FLAG_READ 4 55 | 56 | // Values for Secthdr::sh_type 57 | #define ELF_SHT_NULL 0 58 | #define ELF_SHT_PROGBITS 1 59 | #define ELF_SHT_SYMTAB 2 60 | #define ELF_SHT_STRTAB 3 61 | 62 | // Values for Secthdr::sh_name 63 | #define ELF_SHN_UNDEF 0 64 | 65 | #endif /* !JOS_INC_ELF_H */ 66 | -------------------------------------------------------------------------------- /lab2/inc/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_ELF_H 2 | #define JOS_INC_ELF_H 3 | 4 | #define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */ 5 | 6 | struct Elf { 7 | uint32_t e_magic; // must equal ELF_MAGIC 8 | uint8_t e_elf[12]; 9 | uint16_t e_type; 10 | uint16_t e_machine; 11 | uint32_t e_version; 12 | uint32_t e_entry; 13 | uint32_t e_phoff; 14 | uint32_t e_shoff; 15 | uint32_t e_flags; 16 | uint16_t e_ehsize; 17 | uint16_t e_phentsize; 18 | uint16_t e_phnum; 19 | uint16_t e_shentsize; 20 | uint16_t e_shnum; 21 | uint16_t e_shstrndx; 22 | }; 23 | 24 | struct Proghdr { 25 | uint32_t p_type; 26 | uint32_t p_offset; 27 | uint32_t p_va; 28 | uint32_t p_pa; 29 | uint32_t p_filesz; 30 | uint32_t p_memsz; 31 | uint32_t p_flags; 32 | uint32_t p_align; 33 | }; 34 | 35 | struct Secthdr { 36 | uint32_t sh_name; 37 | uint32_t sh_type; 38 | uint32_t sh_flags; 39 | uint32_t sh_addr; 40 | uint32_t sh_offset; 41 | uint32_t sh_size; 42 | uint32_t sh_link; 43 | uint32_t sh_info; 44 | uint32_t sh_addralign; 45 | uint32_t sh_entsize; 46 | }; 47 | 48 | // Values for Proghdr::p_type 49 | #define ELF_PROG_LOAD 1 50 | 51 | // Flag bits for Proghdr::p_flags 52 | #define ELF_PROG_FLAG_EXEC 1 53 | #define ELF_PROG_FLAG_WRITE 2 54 | #define ELF_PROG_FLAG_READ 4 55 | 56 | // Values for Secthdr::sh_type 57 | #define ELF_SHT_NULL 0 58 | #define ELF_SHT_PROGBITS 1 59 | #define ELF_SHT_SYMTAB 2 60 | #define ELF_SHT_STRTAB 3 61 | 62 | // Values for Secthdr::sh_name 63 | #define ELF_SHN_UNDEF 0 64 | 65 | #endif /* !JOS_INC_ELF_H */ 66 | -------------------------------------------------------------------------------- /lab3/inc/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_ELF_H 2 | #define JOS_INC_ELF_H 3 | 4 | #define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */ 5 | 6 | struct Elf { 7 | uint32_t e_magic; // must equal ELF_MAGIC 8 | uint8_t e_elf[12]; 9 | uint16_t e_type; 10 | uint16_t e_machine; 11 | uint32_t e_version; 12 | uint32_t e_entry; 13 | uint32_t e_phoff; 14 | uint32_t e_shoff; 15 | uint32_t e_flags; 16 | uint16_t e_ehsize; 17 | uint16_t e_phentsize; 18 | uint16_t e_phnum; 19 | uint16_t e_shentsize; 20 | uint16_t e_shnum; 21 | uint16_t e_shstrndx; 22 | }; 23 | 24 | struct Proghdr { 25 | uint32_t p_type; 26 | uint32_t p_offset; 27 | uint32_t p_va; 28 | uint32_t p_pa; 29 | uint32_t p_filesz; 30 | uint32_t p_memsz; 31 | uint32_t p_flags; 32 | uint32_t p_align; 33 | }; 34 | 35 | struct Secthdr { 36 | uint32_t sh_name; 37 | uint32_t sh_type; 38 | uint32_t sh_flags; 39 | uint32_t sh_addr; 40 | uint32_t sh_offset; 41 | uint32_t sh_size; 42 | uint32_t sh_link; 43 | uint32_t sh_info; 44 | uint32_t sh_addralign; 45 | uint32_t sh_entsize; 46 | }; 47 | 48 | // Values for Proghdr::p_type 49 | #define ELF_PROG_LOAD 1 50 | 51 | // Flag bits for Proghdr::p_flags 52 | #define ELF_PROG_FLAG_EXEC 1 53 | #define ELF_PROG_FLAG_WRITE 2 54 | #define ELF_PROG_FLAG_READ 4 55 | 56 | // Values for Secthdr::sh_type 57 | #define ELF_SHT_NULL 0 58 | #define ELF_SHT_PROGBITS 1 59 | #define ELF_SHT_SYMTAB 2 60 | #define ELF_SHT_STRTAB 3 61 | 62 | // Values for Secthdr::sh_name 63 | #define ELF_SHN_UNDEF 0 64 | 65 | #endif /* !JOS_INC_ELF_H */ 66 | -------------------------------------------------------------------------------- /lab4/inc/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef JOS_INC_ELF_H 2 | #define JOS_INC_ELF_H 3 | 4 | #define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */ 5 | 6 | struct Elf { 7 | uint32_t e_magic; // must equal ELF_MAGIC 8 | uint8_t e_elf[12]; 9 | uint16_t e_type; 10 | uint16_t e_machine; 11 | uint32_t e_version; 12 | uint32_t e_entry; 13 | uint32_t e_phoff; 14 | uint32_t e_shoff; 15 | uint32_t e_flags; 16 | uint16_t e_ehsize; 17 | uint16_t e_phentsize; 18 | uint16_t e_phnum; 19 | uint16_t e_shentsize; 20 | uint16_t e_shnum; 21 | uint16_t e_shstrndx; 22 | }; 23 | 24 | struct Proghdr { 25 | uint32_t p_type; 26 | uint32_t p_offset; 27 | uint32_t p_va; 28 | uint32_t p_pa; 29 | uint32_t p_filesz; 30 | uint32_t p_memsz; 31 | uint32_t p_flags; 32 | uint32_t p_align; 33 | }; 34 | 35 | struct Secthdr { 36 | uint32_t sh_name; 37 | uint32_t sh_type; 38 | uint32_t sh_flags; 39 | uint32_t sh_addr; 40 | uint32_t sh_offset; 41 | uint32_t sh_size; 42 | uint32_t sh_link; 43 | uint32_t sh_info; 44 | uint32_t sh_addralign; 45 | uint32_t sh_entsize; 46 | }; 47 | 48 | // Values for Proghdr::p_type 49 | #define ELF_PROG_LOAD 1 50 | 51 | // Flag bits for Proghdr::p_flags 52 | #define ELF_PROG_FLAG_EXEC 1 53 | #define ELF_PROG_FLAG_WRITE 2 54 | #define ELF_PROG_FLAG_READ 4 55 | 56 | // Values for Secthdr::sh_type 57 | #define ELF_SHT_NULL 0 58 | #define ELF_SHT_PROGBITS 1 59 | #define ELF_SHT_SYMTAB 2 60 | #define ELF_SHT_STRTAB 3 61 | 62 | // Values for Secthdr::sh_name 63 | #define ELF_SHN_UNDEF 0 64 | 65 | #endif /* !JOS_INC_ELF_H */ 66 | -------------------------------------------------------------------------------- /lab4/obj/user/fairness.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202e60 R __STAB_END__ 3 | 00202e61 R __STABSTR_BEGIN__ 4 | 002049f6 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 008000a1 T libmain 9 | 008000e7 T exit 10 | 008000f9 t putch 11 | 0080013b T vcprintf 12 | 0080018c T cprintf 13 | 008001a0 t printnum 14 | 0080024f t getuint 15 | 00800289 t sprintputch 16 | 008002a6 T printfmt 17 | 008002c3 T vprintfmt 18 | 00800670 T vsnprintf 19 | 008006be T snprintf 20 | 008006d8 T strlen 21 | 008006f0 T strnlen 22 | 00800711 T strcpy 23 | 00800731 T strcat 24 | 00800753 T strncpy 25 | 00800780 T strlcpy 26 | 008007bb T strcmp 27 | 008007e1 T strncmp 28 | 00800819 T strchr 29 | 0080083a T strfind 30 | 00800856 T memset 31 | 008008a3 T memmove 32 | 0080090b T memcpy 33 | 0080091e T memcmp 34 | 00800957 T memfind 35 | 0080097a T strtol 36 | 00800a58 T sys_cputs 37 | 00800a76 T sys_cgetc 38 | 00800a95 T sys_env_destroy 39 | 00800ad6 T sys_getenvid 40 | 00800af5 T sys_yield 41 | 00800b14 T sys_page_alloc 42 | 00800b57 T sys_page_map 43 | 00800b99 T sys_page_unmap 44 | 00800bdb T sys_env_set_status 45 | 00800c1d T sys_env_set_pgfault_upcall 46 | 00800c5f T sys_ipc_try_send 47 | 00800c82 T sys_ipc_recv 48 | 00800cc3 T ipc_recv 49 | 00800d38 T ipc_send 50 | 00800d92 T ipc_find_env 51 | 00800dcb T _panic 52 | 00800e20 T __udivdi3 53 | 00800f50 T __umoddi3 54 | 00801320 r error_string 55 | 00802000 D binaryname 56 | 00802004 B thisenv 57 | eec00000 A envs 58 | ef000000 A pages 59 | ef400000 A uvpt 60 | ef7bd000 A uvpd 61 | -------------------------------------------------------------------------------- /lab1/grade-lab1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import re 4 | from gradelib import * 5 | 6 | r = Runner(save("jos.out"), 7 | stop_breakpoint("readline")) 8 | 9 | @test(0, "running JOS") 10 | def test_jos(): 11 | r.run_qemu() 12 | 13 | @test(20, parent=test_jos) 14 | def test_printf(): 15 | r.match("6828 decimal is 15254 octal!") 16 | 17 | BACKTRACE_RE = r"^ *ebp +f01[0-9a-z]{5} +eip +f0100[0-9a-z]{3} +args +([0-9a-z]+)" 18 | 19 | @test(10, parent=test_jos) 20 | def test_backtrace_count(): 21 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 22 | assert_equal(len(matches), 8) 23 | 24 | @test(10, parent=test_jos) 25 | def test_backtrace_arguments(): 26 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 27 | assert_equal("\n".join(matches[:7]), 28 | "\n".join("%08x" % n for n in [0,0,1,2,3,4,5])) 29 | 30 | @test(5, parent=test_jos) 31 | def test_backtrace_symbols(): 32 | matches = re.findall(r"kern/init.c:[0-9]+: +([^+]*)\+", r.qemu.output) 33 | assert_equal("\n".join(matches[:7]), 34 | "\n".join(["test_backtrace"] * 6 + ["i386_init"])) 35 | 36 | @test(5, parent=test_jos) 37 | def test_backtrace_lines(): 38 | matches = re.findall(r"([^ ]*init.c:([0-9]+):) +test_backtrace\+", r.qemu.output) 39 | assert matches, "No line numbers" 40 | if any(int(m[1]) < 5 or int(m[1]) > 50 for m in matches): 41 | assert_equal("\n".join(m[0] for m in matches), 42 | "Line numbers between 5 and 50") 43 | 44 | run_tests() 45 | -------------------------------------------------------------------------------- /lab2/grade-lab1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import re 4 | from gradelib import * 5 | 6 | r = Runner(save("jos.out"), 7 | stop_breakpoint("readline")) 8 | 9 | @test(0, "running JOS") 10 | def test_jos(): 11 | r.run_qemu() 12 | 13 | @test(20, parent=test_jos) 14 | def test_printf(): 15 | r.match("6828 decimal is 15254 octal!") 16 | 17 | BACKTRACE_RE = r"^ *ebp +f01[0-9a-z]{5} +eip +f0100[0-9a-z]{3} +args +([0-9a-z]+)" 18 | 19 | @test(10, parent=test_jos) 20 | def test_backtrace_count(): 21 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 22 | assert_equal(len(matches), 8) 23 | 24 | @test(10, parent=test_jos) 25 | def test_backtrace_arguments(): 26 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 27 | assert_equal("\n".join(matches[:7]), 28 | "\n".join("%08x" % n for n in [0,0,1,2,3,4,5])) 29 | 30 | @test(5, parent=test_jos) 31 | def test_backtrace_symbols(): 32 | matches = re.findall(r"kern/init.c:[0-9]+: +([^+]*)\+", r.qemu.output) 33 | assert_equal("\n".join(matches[:7]), 34 | "\n".join(["test_backtrace"] * 6 + ["i386_init"])) 35 | 36 | @test(5, parent=test_jos) 37 | def test_backtrace_lines(): 38 | matches = re.findall(r"([^ ]*init.c:([0-9]+):) +test_backtrace\+", r.qemu.output) 39 | assert matches, "No line numbers" 40 | if any(int(m[1]) < 5 or int(m[1]) > 50 for m in matches): 41 | assert_equal("\n".join(m[0] for m in matches), 42 | "Line numbers between 5 and 50") 43 | 44 | run_tests() 45 | -------------------------------------------------------------------------------- /lab3/grade-lab1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import re 4 | from gradelib import * 5 | 6 | r = Runner(save("jos.out"), 7 | stop_breakpoint("readline")) 8 | 9 | @test(0, "running JOS") 10 | def test_jos(): 11 | r.run_qemu() 12 | 13 | @test(20, parent=test_jos) 14 | def test_printf(): 15 | r.match("6828 decimal is 15254 octal!") 16 | 17 | BACKTRACE_RE = r"^ *ebp +f01[0-9a-z]{5} +eip +f0100[0-9a-z]{3} +args +([0-9a-z]+)" 18 | 19 | @test(10, parent=test_jos) 20 | def test_backtrace_count(): 21 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 22 | assert_equal(len(matches), 8) 23 | 24 | @test(10, parent=test_jos) 25 | def test_backtrace_arguments(): 26 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 27 | assert_equal("\n".join(matches[:7]), 28 | "\n".join("%08x" % n for n in [0,0,1,2,3,4,5])) 29 | 30 | @test(5, parent=test_jos) 31 | def test_backtrace_symbols(): 32 | matches = re.findall(r"kern/init.c:[0-9]+: +([^+]*)\+", r.qemu.output) 33 | assert_equal("\n".join(matches[:7]), 34 | "\n".join(["test_backtrace"] * 6 + ["i386_init"])) 35 | 36 | @test(5, parent=test_jos) 37 | def test_backtrace_lines(): 38 | matches = re.findall(r"([^ ]*init.c:([0-9]+):) +test_backtrace\+", r.qemu.output) 39 | assert matches, "No line numbers" 40 | if any(int(m[1]) < 5 or int(m[1]) > 50 for m in matches): 41 | assert_equal("\n".join(m[0] for m in matches), 42 | "Line numbers between 5 and 50") 43 | 44 | run_tests() 45 | -------------------------------------------------------------------------------- /lab4/grade-lab1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import re 4 | from gradelib import * 5 | 6 | r = Runner(save("jos.out"), 7 | stop_breakpoint("readline")) 8 | 9 | @test(0, "running JOS") 10 | def test_jos(): 11 | r.run_qemu() 12 | 13 | @test(20, parent=test_jos) 14 | def test_printf(): 15 | r.match("6828 decimal is 15254 octal!") 16 | 17 | BACKTRACE_RE = r"^ *ebp +f01[0-9a-z]{5} +eip +f0100[0-9a-z]{3} +args +([0-9a-z]+)" 18 | 19 | @test(10, parent=test_jos) 20 | def test_backtrace_count(): 21 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 22 | assert_equal(len(matches), 8) 23 | 24 | @test(10, parent=test_jos) 25 | def test_backtrace_arguments(): 26 | matches = re.findall(BACKTRACE_RE, r.qemu.output, re.MULTILINE) 27 | assert_equal("\n".join(matches[:7]), 28 | "\n".join("%08x" % n for n in [0,0,1,2,3,4,5])) 29 | 30 | @test(5, parent=test_jos) 31 | def test_backtrace_symbols(): 32 | matches = re.findall(r"kern/init.c:[0-9]+: +([^+]*)\+", r.qemu.output) 33 | assert_equal("\n".join(matches[:7]), 34 | "\n".join(["test_backtrace"] * 6 + ["i386_init"])) 35 | 36 | @test(5, parent=test_jos) 37 | def test_backtrace_lines(): 38 | matches = re.findall(r"([^ ]*init.c:([0-9]+):) +test_backtrace\+", r.qemu.output) 39 | assert matches, "No line numbers" 40 | if any(int(m[1]) < 5 or int(m[1]) > 50 for m in matches): 41 | assert_equal("\n".join(m[0] for m in matches), 42 | "Line numbers between 5 and 50") 43 | 44 | run_tests() 45 | -------------------------------------------------------------------------------- /lab1/kern/kernel.ld: -------------------------------------------------------------------------------- 1 | /* Simple linker script for the JOS kernel. 2 | See the GNU ld 'info' manual ("info ld") to learn the syntax. */ 3 | 4 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 5 | OUTPUT_ARCH(i386) 6 | ENTRY(_start) 7 | 8 | SECTIONS 9 | { 10 | /* Link the kernel at this address: "." means the current address */ 11 | . = 0xF0100000; 12 | 13 | /* AT(...) gives the load address of this section, which tells 14 | the boot loader where to load the kernel in physical memory */ 15 | .text : AT(0x100000) { 16 | *(.text .stub .text.* .gnu.linkonce.t.*) 17 | } 18 | 19 | PROVIDE(etext = .); /* Define the 'etext' symbol to this value */ 20 | 21 | .rodata : { 22 | *(.rodata .rodata.* .gnu.linkonce.r.*) 23 | } 24 | 25 | /* Include debugging information in kernel memory */ 26 | .stab : { 27 | PROVIDE(__STAB_BEGIN__ = .); 28 | *(.stab); 29 | PROVIDE(__STAB_END__ = .); 30 | BYTE(0) /* Force the linker to allocate space 31 | for this section */ 32 | } 33 | 34 | .stabstr : { 35 | PROVIDE(__STABSTR_BEGIN__ = .); 36 | *(.stabstr); 37 | PROVIDE(__STABSTR_END__ = .); 38 | BYTE(0) /* Force the linker to allocate space 39 | for this section */ 40 | } 41 | 42 | /* Adjust the address for the data segment to the next page */ 43 | . = ALIGN(0x1000); 44 | 45 | /* The data segment */ 46 | .data : { 47 | *(.data) 48 | } 49 | 50 | PROVIDE(edata = .); 51 | 52 | .bss : { 53 | *(.bss) 54 | } 55 | 56 | PROVIDE(end = .); 57 | 58 | /DISCARD/ : { 59 | *(.eh_frame .note.GNU-stack) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lab2/kern/kernel.ld: -------------------------------------------------------------------------------- 1 | /* Simple linker script for the JOS kernel. 2 | See the GNU ld 'info' manual ("info ld") to learn the syntax. */ 3 | 4 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 5 | OUTPUT_ARCH(i386) 6 | ENTRY(_start) 7 | 8 | SECTIONS 9 | { 10 | /* Link the kernel at this address: "." means the current address */ 11 | . = 0xF0100000; 12 | 13 | /* AT(...) gives the load address of this section, which tells 14 | the boot loader where to load the kernel in physical memory */ 15 | .text : AT(0x100000) { 16 | *(.text .stub .text.* .gnu.linkonce.t.*) 17 | } 18 | 19 | PROVIDE(etext = .); /* Define the 'etext' symbol to this value */ 20 | 21 | .rodata : { 22 | *(.rodata .rodata.* .gnu.linkonce.r.*) 23 | } 24 | 25 | /* Include debugging information in kernel memory */ 26 | .stab : { 27 | PROVIDE(__STAB_BEGIN__ = .); 28 | *(.stab); 29 | PROVIDE(__STAB_END__ = .); 30 | BYTE(0) /* Force the linker to allocate space 31 | for this section */ 32 | } 33 | 34 | .stabstr : { 35 | PROVIDE(__STABSTR_BEGIN__ = .); 36 | *(.stabstr); 37 | PROVIDE(__STABSTR_END__ = .); 38 | BYTE(0) /* Force the linker to allocate space 39 | for this section */ 40 | } 41 | 42 | /* Adjust the address for the data segment to the next page */ 43 | . = ALIGN(0x1000); 44 | 45 | /* The data segment */ 46 | .data : { 47 | *(.data) 48 | } 49 | 50 | PROVIDE(edata = .); 51 | 52 | .bss : { 53 | *(.bss) 54 | } 55 | 56 | PROVIDE(end = .); 57 | 58 | /DISCARD/ : { 59 | *(.eh_frame .note.GNU-stack) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lab3/kern/kernel.ld: -------------------------------------------------------------------------------- 1 | /* Simple linker script for the JOS kernel. 2 | See the GNU ld 'info' manual ("info ld") to learn the syntax. */ 3 | 4 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 5 | OUTPUT_ARCH(i386) 6 | ENTRY(_start) 7 | 8 | SECTIONS 9 | { 10 | /* Link the kernel at this address: "." means the current address */ 11 | . = 0xF0100000; 12 | 13 | /* AT(...) gives the load address of this section, which tells 14 | the boot loader where to load the kernel in physical memory */ 15 | .text : AT(0x100000) { 16 | *(.text .stub .text.* .gnu.linkonce.t.*) 17 | } 18 | 19 | PROVIDE(etext = .); /* Define the 'etext' symbol to this value */ 20 | 21 | .rodata : { 22 | *(.rodata .rodata.* .gnu.linkonce.r.*) 23 | } 24 | 25 | /* Include debugging information in kernel memory */ 26 | .stab : { 27 | PROVIDE(__STAB_BEGIN__ = .); 28 | *(.stab); 29 | PROVIDE(__STAB_END__ = .); 30 | BYTE(0) /* Force the linker to allocate space 31 | for this section */ 32 | } 33 | 34 | .stabstr : { 35 | PROVIDE(__STABSTR_BEGIN__ = .); 36 | *(.stabstr); 37 | PROVIDE(__STABSTR_END__ = .); 38 | BYTE(0) /* Force the linker to allocate space 39 | for this section */ 40 | } 41 | 42 | /* Adjust the address for the data segment to the next page */ 43 | . = ALIGN(0x1000); 44 | 45 | /* The data segment */ 46 | .data : { 47 | *(.data) 48 | } 49 | 50 | PROVIDE(edata = .); 51 | 52 | .bss : { 53 | *(.bss) 54 | } 55 | 56 | PROVIDE(end = .); 57 | 58 | /DISCARD/ : { 59 | *(.eh_frame .note.GNU-stack) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lab3/lib/syscall.c: -------------------------------------------------------------------------------- 1 | // System call stubs. 2 | 3 | #include 4 | #include 5 | 6 | static inline int32_t 7 | syscall(int num, int check, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) 8 | { 9 | int32_t ret; 10 | 11 | // Generic system call: pass system call number in AX, 12 | // up to five parameters in DX, CX, BX, DI, SI. 13 | // Interrupt kernel with T_SYSCALL. 14 | // 15 | // The "volatile" tells the assembler not to optimize 16 | // this instruction away just because we don't use the 17 | // return value. 18 | // 19 | // The last clause tells the assembler that this can 20 | // potentially change the condition codes and arbitrary 21 | // memory locations. 22 | 23 | asm volatile("int %1\n" 24 | : "=a" (ret) 25 | : "i" (T_SYSCALL), 26 | "a" (num), 27 | "d" (a1), 28 | "c" (a2), 29 | "b" (a3), 30 | "D" (a4), 31 | "S" (a5) 32 | : "cc", "memory"); 33 | 34 | if(check && ret > 0) 35 | panic("syscall %d returned %d (> 0)", num, ret); 36 | 37 | return ret; 38 | } 39 | 40 | void 41 | sys_cputs(const char *s, size_t len) 42 | { 43 | syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0); 44 | } 45 | 46 | int 47 | sys_cgetc(void) 48 | { 49 | return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0); 50 | } 51 | 52 | int 53 | sys_env_destroy(envid_t envid) 54 | { 55 | return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0); 56 | } 57 | 58 | envid_t 59 | sys_getenvid(void) 60 | { 61 | return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0); 62 | } 63 | 64 | -------------------------------------------------------------------------------- /lab4/kern/kernel.ld: -------------------------------------------------------------------------------- 1 | /* Simple linker script for the JOS kernel. 2 | See the GNU ld 'info' manual ("info ld") to learn the syntax. */ 3 | 4 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 5 | OUTPUT_ARCH(i386) 6 | ENTRY(_start) 7 | 8 | SECTIONS 9 | { 10 | /* Link the kernel at this address: "." means the current address */ 11 | . = 0xF0100000; 12 | 13 | /* AT(...) gives the load address of this section, which tells 14 | the boot loader where to load the kernel in physical memory */ 15 | .text : AT(0x100000) { 16 | *(.text .stub .text.* .gnu.linkonce.t.*) 17 | } 18 | 19 | PROVIDE(etext = .); /* Define the 'etext' symbol to this value */ 20 | 21 | .rodata : { 22 | *(.rodata .rodata.* .gnu.linkonce.r.*) 23 | } 24 | 25 | /* Include debugging information in kernel memory */ 26 | .stab : { 27 | PROVIDE(__STAB_BEGIN__ = .); 28 | *(.stab); 29 | PROVIDE(__STAB_END__ = .); 30 | BYTE(0) /* Force the linker to allocate space 31 | for this section */ 32 | } 33 | 34 | .stabstr : { 35 | PROVIDE(__STABSTR_BEGIN__ = .); 36 | *(.stabstr); 37 | PROVIDE(__STABSTR_END__ = .); 38 | BYTE(0) /* Force the linker to allocate space 39 | for this section */ 40 | } 41 | 42 | /* Adjust the address for the data segment to the next page */ 43 | . = ALIGN(0x1000); 44 | 45 | /* The data segment */ 46 | .data : { 47 | *(.data) 48 | } 49 | 50 | PROVIDE(edata = .); 51 | 52 | .bss : { 53 | *(.bss) 54 | } 55 | 56 | PROVIDE(end = .); 57 | 58 | /DISCARD/ : { 59 | *(.eh_frame .note.GNU-stack) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lab4/obj/user/faultnostack.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202d10 R __STAB_END__ 3 | 00202d11 R __STABSTR_BEGIN__ 4 | 0020481d R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800054 T libmain 9 | 0080009a T exit 10 | 008000ac T sys_cputs 11 | 008000ca T sys_cgetc 12 | 008000e9 T sys_env_destroy 13 | 0080012a T sys_getenvid 14 | 00800149 T sys_yield 15 | 00800168 T sys_page_alloc 16 | 008001ab T sys_page_map 17 | 008001ed T sys_page_unmap 18 | 0080022f T sys_env_set_status 19 | 00800271 T sys_env_set_pgfault_upcall 20 | 008002b3 T sys_ipc_try_send 21 | 008002d6 T sys_ipc_recv 22 | 00800317 T _pgfault_upcall 23 | 0080033e T _panic 24 | 00800384 t putch 25 | 008003c6 T vcprintf 26 | 00800417 T cprintf 27 | 0080042b t printnum 28 | 008004da t getuint 29 | 00800514 t sprintputch 30 | 00800531 T printfmt 31 | 0080054e T vprintfmt 32 | 008008fb T vsnprintf 33 | 00800949 T snprintf 34 | 00800963 T strlen 35 | 0080097b T strnlen 36 | 0080099c T strcpy 37 | 008009bc T strcat 38 | 008009de T strncpy 39 | 00800a0b T strlcpy 40 | 00800a46 T strcmp 41 | 00800a6c T strncmp 42 | 00800aa4 T strchr 43 | 00800ac5 T strfind 44 | 00800ae1 T memset 45 | 00800b2e T memmove 46 | 00800b96 T memcpy 47 | 00800ba9 T memcmp 48 | 00800be2 T memfind 49 | 00800c05 T strtol 50 | 00800ce3 T set_pgfault_handler 51 | 00800d60 T __udivdi3 52 | 00800e90 T __umoddi3 53 | 00801280 r error_string 54 | 00802000 D binaryname 55 | 00802004 B thisenv 56 | 00802008 B _pgfault_handler 57 | eec00000 A envs 58 | ef000000 A pages 59 | ef400000 A uvpt 60 | ef7bd000 A uvpd 61 | -------------------------------------------------------------------------------- /lab4/obj/user/faultalloc.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202dc4 R __STAB_END__ 3 | 00202dc5 R __STABSTR_BEGIN__ 4 | 00204927 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T handler 8 | 00800091 T umain 9 | 008000ca T libmain 10 | 00800110 T exit 11 | 00800122 T _panic 12 | 00800168 t putch 13 | 008001aa T vcprintf 14 | 008001fb T cprintf 15 | 0080020f t printnum 16 | 008002be t getuint 17 | 008002f8 t sprintputch 18 | 00800315 T printfmt 19 | 00800332 T vprintfmt 20 | 008006df T vsnprintf 21 | 0080072d T snprintf 22 | 00800747 T strlen 23 | 0080075f T strnlen 24 | 00800780 T strcpy 25 | 008007a0 T strcat 26 | 008007c2 T strncpy 27 | 008007ef T strlcpy 28 | 0080082a T strcmp 29 | 00800850 T strncmp 30 | 00800888 T strchr 31 | 008008a9 T strfind 32 | 008008c5 T memset 33 | 00800912 T memmove 34 | 0080097a T memcpy 35 | 0080098d T memcmp 36 | 008009c6 T memfind 37 | 008009e9 T strtol 38 | 00800ac7 T sys_cputs 39 | 00800ae5 T sys_cgetc 40 | 00800b04 T sys_env_destroy 41 | 00800b45 T sys_getenvid 42 | 00800b64 T sys_yield 43 | 00800b83 T sys_page_alloc 44 | 00800bc6 T sys_page_map 45 | 00800c08 T sys_page_unmap 46 | 00800c4a T sys_env_set_status 47 | 00800c8c T sys_env_set_pgfault_upcall 48 | 00800cce T sys_ipc_try_send 49 | 00800cf1 T sys_ipc_recv 50 | 00800d32 T set_pgfault_handler 51 | 00800da6 T _pgfault_upcall 52 | 00800dd0 T __udivdi3 53 | 00800f00 T __umoddi3 54 | 00801320 r error_string 55 | 00802000 D binaryname 56 | 00802004 B thisenv 57 | 00802008 B _pgfault_handler 58 | eec00000 A envs 59 | ef000000 A pages 60 | ef400000 A uvpt 61 | ef7bd000 A uvpd 62 | -------------------------------------------------------------------------------- /lab4/obj/user/faultdie.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202d64 R __STAB_END__ 3 | 00202d65 R __STABSTR_BEGIN__ 4 | 002048b0 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T handler 8 | 00800061 T umain 9 | 00800080 T libmain 10 | 008000c6 T exit 11 | 008000d8 t putch 12 | 0080011a T vcprintf 13 | 0080016b T cprintf 14 | 0080017f t printnum 15 | 0080022e t getuint 16 | 00800268 t sprintputch 17 | 00800285 T printfmt 18 | 008002a2 T vprintfmt 19 | 0080064f T vsnprintf 20 | 0080069d T snprintf 21 | 008006b7 T strlen 22 | 008006cf T strnlen 23 | 008006f0 T strcpy 24 | 00800710 T strcat 25 | 00800732 T strncpy 26 | 0080075f T strlcpy 27 | 0080079a T strcmp 28 | 008007c0 T strncmp 29 | 008007f8 T strchr 30 | 00800819 T strfind 31 | 00800835 T memset 32 | 00800882 T memmove 33 | 008008ea T memcpy 34 | 008008fd T memcmp 35 | 00800936 T memfind 36 | 00800959 T strtol 37 | 00800a37 T sys_cputs 38 | 00800a55 T sys_cgetc 39 | 00800a74 T sys_env_destroy 40 | 00800ab5 T sys_getenvid 41 | 00800ad4 T sys_yield 42 | 00800af3 T sys_page_alloc 43 | 00800b36 T sys_page_map 44 | 00800b78 T sys_page_unmap 45 | 00800bba T sys_env_set_status 46 | 00800bfc T sys_env_set_pgfault_upcall 47 | 00800c3e T sys_ipc_try_send 48 | 00800c61 T sys_ipc_recv 49 | 00800ca2 T set_pgfault_handler 50 | 00800d16 T _pgfault_upcall 51 | 00800d3d T _panic 52 | 00800d90 T __udivdi3 53 | 00800ec0 T __umoddi3 54 | 00801260 r error_string 55 | 00802000 D binaryname 56 | 00802004 B thisenv 57 | 00802008 B _pgfault_handler 58 | eec00000 A envs 59 | ef000000 A pages 60 | ef400000 A uvpt 61 | ef7bd000 A uvpd 62 | -------------------------------------------------------------------------------- /lab4/obj/user/faultallocbad.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00202db8 R __STAB_END__ 3 | 00202db9 R __STABSTR_BEGIN__ 4 | 0020491e R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T handler 8 | 00800091 T umain 9 | 008000b5 T libmain 10 | 008000fb T exit 11 | 0080010d T _panic 12 | 00800153 t putch 13 | 00800195 T vcprintf 14 | 008001e6 T cprintf 15 | 008001fa t printnum 16 | 008002a9 t getuint 17 | 008002e3 t sprintputch 18 | 00800300 T printfmt 19 | 0080031d T vprintfmt 20 | 008006ca T vsnprintf 21 | 00800718 T snprintf 22 | 00800732 T strlen 23 | 0080074a T strnlen 24 | 0080076b T strcpy 25 | 0080078b T strcat 26 | 008007ad T strncpy 27 | 008007da T strlcpy 28 | 00800815 T strcmp 29 | 0080083b T strncmp 30 | 00800873 T strchr 31 | 00800894 T strfind 32 | 008008b0 T memset 33 | 008008fd T memmove 34 | 00800965 T memcpy 35 | 00800978 T memcmp 36 | 008009b1 T memfind 37 | 008009d4 T strtol 38 | 00800ab2 T sys_cputs 39 | 00800ad0 T sys_cgetc 40 | 00800aef T sys_env_destroy 41 | 00800b30 T sys_getenvid 42 | 00800b4f T sys_yield 43 | 00800b6e T sys_page_alloc 44 | 00800bb1 T sys_page_map 45 | 00800bf3 T sys_page_unmap 46 | 00800c35 T sys_env_set_status 47 | 00800c77 T sys_env_set_pgfault_upcall 48 | 00800cb9 T sys_ipc_try_send 49 | 00800cdc T sys_ipc_recv 50 | 00800d1d T set_pgfault_handler 51 | 00800d91 T _pgfault_upcall 52 | 00800dc0 T __udivdi3 53 | 00800ef0 T __umoddi3 54 | 00801320 r error_string 55 | 00802000 D binaryname 56 | 00802004 B thisenv 57 | 00802008 B _pgfault_handler 58 | eec00000 A envs 59 | ef000000 A pages 60 | ef400000 A uvpt 61 | ef7bd000 A uvpd 62 | -------------------------------------------------------------------------------- /lab4/obj/user/spin.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00203280 R __STAB_END__ 3 | 00203281 R __STABSTR_BEGIN__ 4 | 00204dfc R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 008000b5 T libmain 9 | 008000fb T exit 10 | 0080010d t putch 11 | 0080014f T vcprintf 12 | 008001a0 T cprintf 13 | 008001b4 t printnum 14 | 00800263 t getuint 15 | 0080029d t sprintputch 16 | 008002ba T printfmt 17 | 008002d7 T vprintfmt 18 | 00800684 T vsnprintf 19 | 008006d2 T snprintf 20 | 008006ec T strlen 21 | 00800704 T strnlen 22 | 00800725 T strcpy 23 | 00800745 T strcat 24 | 00800767 T strncpy 25 | 00800794 T strlcpy 26 | 008007cf T strcmp 27 | 008007f5 T strncmp 28 | 0080082d T strchr 29 | 0080084e T strfind 30 | 0080086a T memset 31 | 008008b7 T memmove 32 | 0080091f T memcpy 33 | 00800932 T memcmp 34 | 0080096b T memfind 35 | 0080098e T strtol 36 | 00800a6c T sys_cputs 37 | 00800a8a T sys_cgetc 38 | 00800aa9 T sys_env_destroy 39 | 00800aea T sys_getenvid 40 | 00800b09 T sys_yield 41 | 00800b28 T sys_page_alloc 42 | 00800b6b T sys_page_map 43 | 00800bad T sys_page_unmap 44 | 00800bef T sys_env_set_status 45 | 00800c31 T sys_env_set_pgfault_upcall 46 | 00800c73 T sys_ipc_try_send 47 | 00800c96 T sys_ipc_recv 48 | 00800cd7 t pgfault 49 | 00800dd1 T fork 50 | 00800f84 T sfork 51 | 00800f9e T _panic 52 | 00800fe4 T set_pgfault_handler 53 | 00801058 T _pgfault_upcall 54 | 00801080 T __udivdi3 55 | 008011b0 T __umoddi3 56 | 008015e0 r error_string 57 | 00802000 D binaryname 58 | 00802004 B thisenv 59 | 00802008 B _pgfault_handler 60 | eec00000 A envs 61 | ef000000 A pages 62 | ef400000 A uvpt 63 | ef7bd000 A uvpd 64 | -------------------------------------------------------------------------------- /lab4/obj/user/stresssched.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002032b0 R __STAB_END__ 3 | 002032b1 R __STABSTR_BEGIN__ 4 | 00204e4e R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 008000ed T libmain 9 | 00800133 T exit 10 | 00800145 T _panic 11 | 0080018b t putch 12 | 008001cd T vcprintf 13 | 0080021e T cprintf 14 | 00800232 t printnum 15 | 008002e1 t getuint 16 | 0080031b t sprintputch 17 | 00800338 T printfmt 18 | 00800355 T vprintfmt 19 | 00800702 T vsnprintf 20 | 00800750 T snprintf 21 | 0080076a T strlen 22 | 00800782 T strnlen 23 | 008007a3 T strcpy 24 | 008007c3 T strcat 25 | 008007e5 T strncpy 26 | 00800812 T strlcpy 27 | 0080084d T strcmp 28 | 00800873 T strncmp 29 | 008008ab T strchr 30 | 008008cc T strfind 31 | 008008e8 T memset 32 | 00800935 T memmove 33 | 0080099d T memcpy 34 | 008009b0 T memcmp 35 | 008009e9 T memfind 36 | 00800a0c T strtol 37 | 00800aea T sys_cputs 38 | 00800b08 T sys_cgetc 39 | 00800b27 T sys_env_destroy 40 | 00800b68 T sys_getenvid 41 | 00800b87 T sys_yield 42 | 00800ba6 T sys_page_alloc 43 | 00800be9 T sys_page_map 44 | 00800c2b T sys_page_unmap 45 | 00800c6d T sys_env_set_status 46 | 00800caf T sys_env_set_pgfault_upcall 47 | 00800cf1 T sys_ipc_try_send 48 | 00800d14 T sys_ipc_recv 49 | 00800d55 t pgfault 50 | 00800e4f T fork 51 | 00801002 T sfork 52 | 0080101c T set_pgfault_handler 53 | 00801090 T _pgfault_upcall 54 | 008010c0 T __udivdi3 55 | 008011f0 T __umoddi3 56 | 00801600 r error_string 57 | 00802000 D binaryname 58 | 00802004 B counter 59 | 00802008 B thisenv 60 | 0080200c B _pgfault_handler 61 | eec00000 A envs 62 | ef000000 A pages 63 | ef400000 A uvpt 64 | ef7bd000 A uvpd 65 | -------------------------------------------------------------------------------- /lab4/lib/pgfault.c: -------------------------------------------------------------------------------- 1 | // User-level page fault handler support. 2 | // Rather than register the C page fault handler directly with the 3 | // kernel as the page fault handler, we register the assembly language 4 | // wrapper in pfentry.S, which in turns calls the registered C 5 | // function. 6 | 7 | #include 8 | 9 | 10 | // Assembly language pgfault entrypoint defined in lib/pfentry.S. 11 | extern void _pgfault_upcall(void); 12 | 13 | // Pointer to currently installed C-language pgfault handler. 14 | void (*_pgfault_handler)(struct UTrapframe *utf); 15 | 16 | // 17 | // Set the page fault handler function. 18 | // If there isn't one yet, _pgfault_handler will be 0. 19 | // The first time we register a handler, we need to 20 | // allocate an exception stack (one page of memory with its top 21 | // at UXSTACKTOP), and tell the kernel to call the assembly-language 22 | // _pgfault_upcall routine when a page fault occurs. 23 | // 24 | void 25 | set_pgfault_handler(void (*handler)(struct UTrapframe *utf)) 26 | { 27 | int r; 28 | 29 | if (_pgfault_handler == 0) { 30 | // First time through! 31 | // LAB 4: Your code here. 32 | // panic("set_pgfault_handler not implemented"); 33 | envid_t e_id = sys_getenvid(); 34 | r = sys_page_alloc(e_id, (void *)(UXSTACKTOP-PGSIZE), PTE_U | PTE_W | PTE_P); 35 | if (r < 0) { 36 | panic("pgfault_handler: %e", r); 37 | } 38 | // r = sys_env_set_pgfault_upcall(e_id, handler); 39 | r = sys_env_set_pgfault_upcall(e_id, _pgfault_upcall); 40 | if (r < 0) { 41 | panic("pgfault_handler: %e", r); 42 | } 43 | } 44 | 45 | // Save handler pointer for assembly to call. 46 | _pgfault_handler = handler; 47 | } 48 | -------------------------------------------------------------------------------- /lab4/obj/user/faultregs.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002030ac R __STAB_END__ 3 | 002030ad R __STABSTR_BEGIN__ 4 | 00204cf6 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 t check_regs 8 | 008003a0 t pgfault 9 | 00800480 T umain 10 | 00800597 T libmain 11 | 008005dd T exit 12 | 008005ef T _panic 13 | 00800635 t putch 14 | 00800677 T vcprintf 15 | 008006c8 T cprintf 16 | 008006dc t printnum 17 | 0080078b t getuint 18 | 008007c5 t sprintputch 19 | 008007e2 T printfmt 20 | 008007ff T vprintfmt 21 | 00800bac T vsnprintf 22 | 00800bfa T snprintf 23 | 00800c14 T strlen 24 | 00800c2c T strnlen 25 | 00800c4d T strcpy 26 | 00800c6d T strcat 27 | 00800c8f T strncpy 28 | 00800cbc T strlcpy 29 | 00800cf7 T strcmp 30 | 00800d1d T strncmp 31 | 00800d55 T strchr 32 | 00800d76 T strfind 33 | 00800d92 T memset 34 | 00800ddf T memmove 35 | 00800e47 T memcpy 36 | 00800e5a T memcmp 37 | 00800e93 T memfind 38 | 00800eb6 T strtol 39 | 00800f94 T sys_cputs 40 | 00800fb2 T sys_cgetc 41 | 00800fd1 T sys_env_destroy 42 | 00801012 T sys_getenvid 43 | 00801031 T sys_yield 44 | 00801050 T sys_page_alloc 45 | 00801093 T sys_page_map 46 | 008010d5 T sys_page_unmap 47 | 00801117 T sys_env_set_status 48 | 00801159 T sys_env_set_pgfault_upcall 49 | 0080119b T sys_ipc_try_send 50 | 008011be T sys_ipc_recv 51 | 008011ff T set_pgfault_handler 52 | 00801273 T _pgfault_upcall 53 | 008012a0 T __udivdi3 54 | 008013d0 T __umoddi3 55 | 008018a0 r error_string 56 | 00802000 D binaryname 57 | 00802020 b after 58 | 00802060 b during 59 | 008020a0 b before 60 | 008020cc B thisenv 61 | 008020d0 B _pgfault_handler 62 | eec00000 A envs 63 | ef000000 A pages 64 | ef400000 A uvpt 65 | ef7bd000 A uvpd 66 | -------------------------------------------------------------------------------- /lab4/obj/user/forktree.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002032c8 R __STAB_END__ 3 | 002032c9 R __STABSTR_BEGIN__ 4 | 00204ee1 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T forktree 8 | 0080006f T forkchild 9 | 008000cc T umain 10 | 008000e1 T libmain 11 | 00800127 T exit 12 | 00800139 t putch 13 | 0080017b T vcprintf 14 | 008001cc T cprintf 15 | 008001e0 t printnum 16 | 0080028f t getuint 17 | 008002c9 t sprintputch 18 | 008002e6 T printfmt 19 | 00800303 T vprintfmt 20 | 008006b0 T vsnprintf 21 | 008006fe T snprintf 22 | 00800718 T strlen 23 | 00800730 T strnlen 24 | 00800751 T strcpy 25 | 00800771 T strcat 26 | 00800793 T strncpy 27 | 008007c0 T strlcpy 28 | 008007fb T strcmp 29 | 00800821 T strncmp 30 | 00800859 T strchr 31 | 0080087a T strfind 32 | 00800896 T memset 33 | 008008e3 T memmove 34 | 0080094b T memcpy 35 | 0080095e T memcmp 36 | 00800997 T memfind 37 | 008009ba T strtol 38 | 00800a98 T sys_cputs 39 | 00800ab6 T sys_cgetc 40 | 00800ad5 T sys_env_destroy 41 | 00800b16 T sys_getenvid 42 | 00800b35 T sys_yield 43 | 00800b54 T sys_page_alloc 44 | 00800b97 T sys_page_map 45 | 00800bd9 T sys_page_unmap 46 | 00800c1b T sys_env_set_status 47 | 00800c5d T sys_env_set_pgfault_upcall 48 | 00800c9f T sys_ipc_try_send 49 | 00800cc2 T sys_ipc_recv 50 | 00800d03 t pgfault 51 | 00800dfd T fork 52 | 00800fb0 T sfork 53 | 00800fca T _panic 54 | 00801010 T set_pgfault_handler 55 | 00801084 T _pgfault_upcall 56 | 008010b0 T __udivdi3 57 | 008011e0 T __umoddi3 58 | 00801580 r error_string 59 | 00802000 D binaryname 60 | 00802004 B thisenv 61 | 00802008 B _pgfault_handler 62 | eec00000 A envs 63 | ef000000 A pages 64 | ef400000 A uvpt 65 | ef7bd000 A uvpd 66 | -------------------------------------------------------------------------------- /lab4/obj/user/pingpong.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00203670 R __STAB_END__ 3 | 00203671 R __STABSTR_BEGIN__ 4 | 002052f5 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 008000be T libmain 9 | 00800104 T exit 10 | 00800116 t putch 11 | 00800158 T vcprintf 12 | 008001a9 T cprintf 13 | 008001bd t printnum 14 | 0080026c t getuint 15 | 008002a6 t sprintputch 16 | 008002c3 T printfmt 17 | 008002e0 T vprintfmt 18 | 0080068d T vsnprintf 19 | 008006db T snprintf 20 | 008006f5 T strlen 21 | 0080070d T strnlen 22 | 0080072e T strcpy 23 | 0080074e T strcat 24 | 00800770 T strncpy 25 | 0080079d T strlcpy 26 | 008007d8 T strcmp 27 | 008007fe T strncmp 28 | 00800836 T strchr 29 | 00800857 T strfind 30 | 00800873 T memset 31 | 008008c0 T memmove 32 | 00800928 T memcpy 33 | 0080093b T memcmp 34 | 00800974 T memfind 35 | 00800997 T strtol 36 | 00800a75 T sys_cputs 37 | 00800a93 T sys_cgetc 38 | 00800ab2 T sys_env_destroy 39 | 00800af3 T sys_getenvid 40 | 00800b12 T sys_yield 41 | 00800b31 T sys_page_alloc 42 | 00800b74 T sys_page_map 43 | 00800bb6 T sys_page_unmap 44 | 00800bf8 T sys_env_set_status 45 | 00800c3a T sys_env_set_pgfault_upcall 46 | 00800c7c T sys_ipc_try_send 47 | 00800c9f T sys_ipc_recv 48 | 00800ce0 t pgfault 49 | 00800dda T fork 50 | 00800f8d T sfork 51 | 00800fa7 T ipc_recv 52 | 0080101c T ipc_send 53 | 00801076 T ipc_find_env 54 | 008010af T _panic 55 | 008010f5 T set_pgfault_handler 56 | 00801169 T _pgfault_upcall 57 | 00801190 T __udivdi3 58 | 008012c0 T __umoddi3 59 | 00801680 r error_string 60 | 00802000 D binaryname 61 | 00802004 B thisenv 62 | 00802008 B _pgfault_handler 63 | eec00000 A envs 64 | ef000000 A pages 65 | ef400000 A uvpt 66 | ef7bd000 A uvpd 67 | -------------------------------------------------------------------------------- /lab4/obj/user/pingpongs.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 00203688 R __STAB_END__ 3 | 00203689 R __STABSTR_BEGIN__ 4 | 00205319 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 008000fe T libmain 9 | 00800144 T exit 10 | 00800156 t putch 11 | 00800198 T vcprintf 12 | 008001e9 T cprintf 13 | 008001fd t printnum 14 | 008002ac t getuint 15 | 008002e6 t sprintputch 16 | 00800303 T printfmt 17 | 00800320 T vprintfmt 18 | 008006cd T vsnprintf 19 | 0080071b T snprintf 20 | 00800735 T strlen 21 | 0080074d T strnlen 22 | 0080076e T strcpy 23 | 0080078e T strcat 24 | 008007b0 T strncpy 25 | 008007dd T strlcpy 26 | 00800818 T strcmp 27 | 0080083e T strncmp 28 | 00800876 T strchr 29 | 00800897 T strfind 30 | 008008b3 T memset 31 | 00800900 T memmove 32 | 00800968 T memcpy 33 | 0080097b T memcmp 34 | 008009b4 T memfind 35 | 008009d7 T strtol 36 | 00800ab5 T sys_cputs 37 | 00800ad3 T sys_cgetc 38 | 00800af2 T sys_env_destroy 39 | 00800b33 T sys_getenvid 40 | 00800b52 T sys_yield 41 | 00800b71 T sys_page_alloc 42 | 00800bb4 T sys_page_map 43 | 00800bf6 T sys_page_unmap 44 | 00800c38 T sys_env_set_status 45 | 00800c7a T sys_env_set_pgfault_upcall 46 | 00800cbc T sys_ipc_try_send 47 | 00800cdf T sys_ipc_recv 48 | 00800d20 t pgfault 49 | 00800e1a T fork 50 | 00800fcd T sfork 51 | 00800fe7 T ipc_recv 52 | 0080105c T ipc_send 53 | 008010b6 T ipc_find_env 54 | 008010ef T _panic 55 | 00801135 T set_pgfault_handler 56 | 008011a9 T _pgfault_upcall 57 | 008011d0 T __udivdi3 58 | 00801300 T __umoddi3 59 | 008016e0 r error_string 60 | 00802000 D binaryname 61 | 00802004 B val 62 | 00802008 B thisenv 63 | 0080200c B _pgfault_handler 64 | eec00000 A envs 65 | ef000000 A pages 66 | ef400000 A uvpt 67 | ef7bd000 A uvpd 68 | -------------------------------------------------------------------------------- /lab4/obj/user/primes.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 0020370c R __STAB_END__ 3 | 0020370d R __STABSTR_BEGIN__ 4 | 002053b5 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T primeproc 8 | 008000b5 T umain 9 | 008000f8 T libmain 10 | 0080013e T exit 11 | 00800150 T _panic 12 | 00800196 t putch 13 | 008001d8 T vcprintf 14 | 00800229 T cprintf 15 | 0080023d t printnum 16 | 008002ec t getuint 17 | 00800326 t sprintputch 18 | 00800343 T printfmt 19 | 00800360 T vprintfmt 20 | 0080070d T vsnprintf 21 | 0080075b T snprintf 22 | 00800775 T strlen 23 | 0080078d T strnlen 24 | 008007ae T strcpy 25 | 008007ce T strcat 26 | 008007f0 T strncpy 27 | 0080081d T strlcpy 28 | 00800858 T strcmp 29 | 0080087e T strncmp 30 | 008008b6 T strchr 31 | 008008d7 T strfind 32 | 008008f3 T memset 33 | 00800940 T memmove 34 | 008009a8 T memcpy 35 | 008009bb T memcmp 36 | 008009f4 T memfind 37 | 00800a17 T strtol 38 | 00800af5 T sys_cputs 39 | 00800b13 T sys_cgetc 40 | 00800b32 T sys_env_destroy 41 | 00800b73 T sys_getenvid 42 | 00800b92 T sys_yield 43 | 00800bb1 T sys_page_alloc 44 | 00800bf4 T sys_page_map 45 | 00800c36 T sys_page_unmap 46 | 00800c78 T sys_env_set_status 47 | 00800cba T sys_env_set_pgfault_upcall 48 | 00800cfc T sys_ipc_try_send 49 | 00800d1f T sys_ipc_recv 50 | 00800d60 t pgfault 51 | 00800e5a T fork 52 | 0080100d T sfork 53 | 00801027 T ipc_recv 54 | 0080109c T ipc_send 55 | 008010f6 T ipc_find_env 56 | 0080112f T set_pgfault_handler 57 | 008011a3 T _pgfault_upcall 58 | 008011d0 T __udivdi3 59 | 00801300 T __umoddi3 60 | 008016e0 r error_string 61 | 00802000 D binaryname 62 | 00802004 B thisenv 63 | 00802008 B _pgfault_handler 64 | eec00000 A envs 65 | ef000000 A pages 66 | ef400000 A uvpt 67 | ef7bd000 A uvpd 68 | -------------------------------------------------------------------------------- /lab4/obj/user/sendpage.sym: -------------------------------------------------------------------------------- 1 | 00200010 R __STAB_BEGIN__ 2 | 002036d0 R __STAB_END__ 3 | 002036d1 R __STABSTR_BEGIN__ 4 | 00205376 R __STABSTR_END__ 5 | 00800020 T _start 6 | 0080002c t args_exist 7 | 00800033 T umain 8 | 00800199 T libmain 9 | 008001df T exit 10 | 008001f1 t putch 11 | 00800233 T vcprintf 12 | 00800284 T cprintf 13 | 00800298 t printnum 14 | 00800347 t getuint 15 | 00800381 t sprintputch 16 | 0080039e T printfmt 17 | 008003bb T vprintfmt 18 | 00800768 T vsnprintf 19 | 008007b6 T snprintf 20 | 008007d0 T strlen 21 | 008007e8 T strnlen 22 | 00800809 T strcpy 23 | 00800829 T strcat 24 | 0080084b T strncpy 25 | 00800878 T strlcpy 26 | 008008b3 T strcmp 27 | 008008d9 T strncmp 28 | 00800911 T strchr 29 | 00800932 T strfind 30 | 0080094e T memset 31 | 0080099b T memmove 32 | 00800a03 T memcpy 33 | 00800a16 T memcmp 34 | 00800a4f T memfind 35 | 00800a72 T strtol 36 | 00800b50 T sys_cputs 37 | 00800b6e T sys_cgetc 38 | 00800b8d T sys_env_destroy 39 | 00800bce T sys_getenvid 40 | 00800bed T sys_yield 41 | 00800c0c T sys_page_alloc 42 | 00800c4f T sys_page_map 43 | 00800c91 T sys_page_unmap 44 | 00800cd3 T sys_env_set_status 45 | 00800d15 T sys_env_set_pgfault_upcall 46 | 00800d57 T sys_ipc_try_send 47 | 00800d7a T sys_ipc_recv 48 | 00800dbb t pgfault 49 | 00800eb5 T fork 50 | 00801068 T sfork 51 | 00801082 T ipc_recv 52 | 008010f7 T ipc_send 53 | 00801151 T ipc_find_env 54 | 0080118a T _panic 55 | 008011d0 T set_pgfault_handler 56 | 00801244 T _pgfault_upcall 57 | 00801270 T __udivdi3 58 | 008013a0 T __umoddi3 59 | 008017e0 r error_string 60 | 00802000 D str2 61 | 00802004 D str1 62 | 00802008 D binaryname 63 | 0080200c B thisenv 64 | 00802010 B _pgfault_handler 65 | eec00000 A envs 66 | ef000000 A pages 67 | ef400000 A uvpt 68 | ef7bd000 A uvpd 69 | -------------------------------------------------------------------------------- /lab3/inc/lib.h: -------------------------------------------------------------------------------- 1 | // Main public header file for our user-land support library, 2 | // whose code lives in the lib directory. 3 | // This library is roughly our OS's version of a standard C library, 4 | // and is intended to be linked into all user-mode applications 5 | // (NOT the kernel or boot loader). 6 | 7 | #ifndef JOS_INC_LIB_H 8 | #define JOS_INC_LIB_H 1 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define USED(x) (void)(x) 21 | 22 | // main user program 23 | void umain(int argc, char **argv); 24 | 25 | // libmain.c or entry.S 26 | extern const char *binaryname; 27 | extern const volatile struct Env *thisenv; 28 | extern const volatile struct Env envs[NENV]; 29 | extern const volatile struct PageInfo pages[]; 30 | 31 | // exit.c 32 | void exit(void); 33 | 34 | // readline.c 35 | char* readline(const char *buf); 36 | 37 | // syscall.c 38 | void sys_cputs(const char *string, size_t len); 39 | int sys_cgetc(void); 40 | envid_t sys_getenvid(void); 41 | int sys_env_destroy(envid_t); 42 | 43 | 44 | 45 | /* File open modes */ 46 | #define O_RDONLY 0x0000 /* open for reading only */ 47 | #define O_WRONLY 0x0001 /* open for writing only */ 48 | #define O_RDWR 0x0002 /* open for reading and writing */ 49 | #define O_ACCMODE 0x0003 /* mask for above modes */ 50 | 51 | #define O_CREAT 0x0100 /* create if nonexistent */ 52 | #define O_TRUNC 0x0200 /* truncate to zero length */ 53 | #define O_EXCL 0x0400 /* error if already exists */ 54 | #define O_MKDIR 0x0800 /* create directory, not regular file */ 55 | 56 | #endif // !JOS_INC_LIB_H 57 | --------------------------------------------------------------------------------