├── .dir-locals.el ├── .gitignore ├── LICENSE ├── README-english.md ├── README.md ├── docs └── lab1 │ ├── Makefile函数.md │ ├── Order-Only前提条件.md │ ├── libs │ └── x86_h.md │ ├── 二次扩展.md │ ├── 多目标与自动变量.md │ ├── 控制寄存器.md │ ├── 练习一.md │ ├── 练习二.md │ └── 输入输出重定向.md ├── labcodes ├── autobuild.sh ├── autotest.sh ├── clangbuildall.sh ├── cleanall.sh ├── formatter.py ├── gccbuildall.sh ├── lab1 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── init │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ └── pmm.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── printfmt.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── lab2 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ └── pmm.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── kernel_nopage.ld │ │ ├── sign.c │ │ └── vector.c ├── lab3 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── lab4 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── lab5 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── pgdir.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c ├── lab6 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── default_sched.c │ │ │ ├── default_sched.h │ │ │ ├── default_sched_stride_c │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── skew_heap.h │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── matrix.c │ │ ├── pgdir.c │ │ ├── priority.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c ├── lab7 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── default_sched.c │ │ │ ├── default_sched.h │ │ │ ├── default_sched_stride_c │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ ├── check_sync.c │ │ │ ├── monitor.c │ │ │ ├── monitor.h │ │ │ ├── sem.c │ │ │ ├── sem.h │ │ │ ├── sync.h │ │ │ ├── wait.c │ │ │ └── wait.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── skew_heap.h │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── matrix.c │ │ ├── pgdir.c │ │ ├── priority.c │ │ ├── sleep.c │ │ ├── sleepkill.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c ├── lab8 │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── devs │ │ │ │ ├── dev.c │ │ │ │ ├── dev.h │ │ │ │ ├── dev_disk0.c │ │ │ │ ├── dev_stdin.c │ │ │ │ └── dev_stdout.c │ │ │ ├── file.c │ │ │ ├── file.h │ │ │ ├── fs.c │ │ │ ├── fs.h │ │ │ ├── iobuf.c │ │ │ ├── iobuf.h │ │ │ ├── sfs │ │ │ │ ├── bitmap.c │ │ │ │ ├── bitmap.h │ │ │ │ ├── sfs.c │ │ │ │ ├── sfs.h │ │ │ │ ├── sfs_fs.c │ │ │ │ ├── sfs_inode.c │ │ │ │ ├── sfs_io.c │ │ │ │ └── sfs_lock.c │ │ │ ├── swap │ │ │ │ ├── swapfs.c │ │ │ │ └── swapfs.h │ │ │ ├── sysfile.c │ │ │ ├── sysfile.h │ │ │ └── vfs │ │ │ │ ├── inode.c │ │ │ │ ├── inode.h │ │ │ │ ├── vfs.c │ │ │ │ ├── vfs.h │ │ │ │ ├── vfsdev.c │ │ │ │ ├── vfsfile.c │ │ │ │ ├── vfslookup.c │ │ │ │ └── vfspath.c │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ ├── stdio.c │ │ │ └── string.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── default_sched.c │ │ │ ├── default_sched.h │ │ │ ├── default_sched_stride_c │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ ├── check_sync.c │ │ │ ├── monitor.c │ │ │ ├── monitor.h │ │ │ ├── sem.c │ │ │ ├── sem.h │ │ │ ├── sync.h │ │ │ ├── wait.c │ │ │ └── wait.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── dirent.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── skew_heap.h │ │ ├── stat.h │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── mksfs.c │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── dir.c │ │ ├── dir.h │ │ ├── file.c │ │ ├── file.h │ │ ├── initcode.S │ │ ├── lock.h │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── ls.c │ │ ├── matrix.c │ │ ├── pgdir.c │ │ ├── priority.c │ │ ├── sh.c │ │ ├── sleep.c │ │ ├── sleepkill.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c └── tools │ └── split_score_log.py ├── labcodes_answer ├── README.txt ├── lab1_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── init │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ └── pmm.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── printfmt.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ ├── report.md │ └── tools │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── lab1init │ │ ├── moninit │ │ ├── sign.c │ │ └── vector.c ├── lab2_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ └── pmm.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── lab3_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── lab4_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── rb_tree.c │ │ │ ├── rb_tree.h │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── lab5_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── rb_tree.c │ │ │ ├── rb_tree.h │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── pgdir.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c ├── lab6_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── rb_tree.c │ │ │ ├── rb_tree.h │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── default_sched.c │ │ │ ├── default_sched.h │ │ │ ├── default_sched_stride_c │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── skew_heap.h │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── matrix.c │ │ ├── pgdir.c │ │ ├── priority.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c ├── lab7_result │ ├── .projectile │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── rb_tree.c │ │ │ ├── rb_tree.h │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── default_sched.c │ │ │ ├── default_sched.h │ │ │ ├── default_sched_stride_c │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ ├── check_sync.c │ │ │ ├── monitor.c │ │ │ ├── monitor.h │ │ │ ├── sem.c │ │ │ ├── sem.h │ │ │ ├── sync.h │ │ │ ├── wait.c │ │ │ └── wait.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── skew_heap.h │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── matrix.c │ │ ├── pgdir.c │ │ ├── priority.c │ │ ├── sleep.c │ │ ├── sleepkill.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c └── lab8_result │ ├── .projectile │ ├── Makefile │ ├── boot │ ├── asm.h │ ├── bootasm.S │ └── bootmain.c │ ├── kern │ ├── debug │ │ ├── assert.h │ │ ├── kdebug.c │ │ ├── kdebug.h │ │ ├── kmonitor.c │ │ ├── kmonitor.h │ │ ├── panic.c │ │ └── stab.h │ ├── driver │ │ ├── clock.c │ │ ├── clock.h │ │ ├── console.c │ │ ├── console.h │ │ ├── ide.c │ │ ├── ide.h │ │ ├── intr.c │ │ ├── intr.h │ │ ├── kbdreg.h │ │ ├── picirq.c │ │ └── picirq.h │ ├── fs │ │ ├── devs │ │ │ ├── dev.c │ │ │ ├── dev.h │ │ │ ├── dev_disk0.c │ │ │ ├── dev_stdin.c │ │ │ └── dev_stdout.c │ │ ├── file.c │ │ ├── file.h │ │ ├── fs.c │ │ ├── fs.h │ │ ├── iobuf.c │ │ ├── iobuf.h │ │ ├── sfs │ │ │ ├── bitmap.c │ │ │ ├── bitmap.h │ │ │ ├── sfs.c │ │ │ ├── sfs.h │ │ │ ├── sfs_fs.c │ │ │ ├── sfs_inode.c │ │ │ ├── sfs_io.c │ │ │ └── sfs_lock.c │ │ ├── swap │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── sysfile.c │ │ ├── sysfile.h │ │ └── vfs │ │ │ ├── inode.c │ │ │ ├── inode.h │ │ │ ├── vfs.c │ │ │ ├── vfs.h │ │ │ ├── vfsdev.c │ │ │ ├── vfsfile.c │ │ │ ├── vfslookup.c │ │ │ └── vfspath.c │ ├── init │ │ ├── entry.S │ │ └── init.c │ ├── libs │ │ ├── readline.c │ │ ├── stdio.c │ │ └── string.c │ ├── mm │ │ ├── default_pmm.c │ │ ├── default_pmm.h │ │ ├── kmalloc.c │ │ ├── kmalloc.h │ │ ├── memlayout.h │ │ ├── mmu.h │ │ ├── pmm.c │ │ ├── pmm.h │ │ ├── swap.c │ │ ├── swap.h │ │ ├── swap_fifo.c │ │ ├── swap_fifo.h │ │ ├── vmm.c │ │ └── vmm.h │ ├── process │ │ ├── entry.S │ │ ├── proc.c │ │ ├── proc.h │ │ └── switch.S │ ├── schedule │ │ ├── default_sched.c │ │ ├── default_sched.h │ │ ├── default_sched_stride_c │ │ ├── sched.c │ │ └── sched.h │ ├── sync │ │ ├── check_sync.c │ │ ├── monitor.c │ │ ├── monitor.h │ │ ├── sem.c │ │ ├── sem.h │ │ ├── sync.h │ │ ├── wait.c │ │ └── wait.h │ ├── syscall │ │ ├── syscall.c │ │ └── syscall.h │ └── trap │ │ ├── trap.c │ │ ├── trap.h │ │ ├── trapentry.S │ │ └── vectors.S │ ├── libs │ ├── atomic.h │ ├── defs.h │ ├── dirent.h │ ├── elf.h │ ├── error.h │ ├── hash.c │ ├── list.h │ ├── printfmt.c │ ├── rand.c │ ├── skew_heap.h │ ├── stat.h │ ├── stdarg.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.c │ ├── string.h │ ├── unistd.h │ └── x86.h │ ├── tools │ ├── boot.ld │ ├── function.mk │ ├── gdbinit │ ├── grade.sh │ ├── kernel.ld │ ├── mksfs.c │ ├── sign.c │ ├── user.ld │ └── vector.c │ └── user │ ├── badarg.c │ ├── badsegment.c │ ├── divzero.c │ ├── exit.c │ ├── faultread.c │ ├── faultreadkernel.c │ ├── forktest.c │ ├── forktree.c │ ├── hello.c │ ├── libs │ ├── dir.c │ ├── dir.h │ ├── file.c │ ├── file.h │ ├── initcode.S │ ├── lock.h │ ├── panic.c │ ├── stdio.c │ ├── syscall.c │ ├── syscall.h │ ├── ulib.c │ ├── ulib.h │ └── umain.c │ ├── ls.c │ ├── matrix.c │ ├── pgdir.c │ ├── priority.c │ ├── sh.c │ ├── sleep.c │ ├── sleepkill.c │ ├── softint.c │ ├── spin.c │ ├── testbss.c │ ├── waitkill.c │ └── yield.c ├── opensource_os_list.md └── related_info ├── lab0 ├── defs.h ├── lab0_ex1.c ├── lab0_ex1.md ├── lab0_ex2.c ├── lab0_ex2.md ├── lab0_ex3.c ├── lab0_ex3.md ├── lab0_ex4.c ├── lab0_ex4.md ├── lab0_ex5.c ├── lab0_ex5.md ├── lab0_ex6.c ├── lab0_ex6.md └── list.h ├── lab1 ├── Makefile ├── defines.h ├── lab1-boot-with-grub2-in-udisk.md ├── lab1-ex0.md ├── lab1-ex0.s ├── lab1-ex1.c ├── lab1-ex1.md ├── lab1-ex2.c ├── lab1-ex2.md ├── lab1-ex3.c ├── lab1-ex3.md ├── pmbootloader │ ├── Makefile │ ├── pmboot.S │ └── pmboot.md └── toybootloader │ ├── Makefile │ ├── toy.S │ └── toy.md ├── lab2 ├── buddy_system.c ├── buddy_system.md ├── kr_malloc_free.c ├── kr_malloc_free.md ├── kr_malloc_free_2 │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── memory.c │ └── memory.h └── watch_linux_pagefault.md ├── lab3 ├── locality │ ├── Makefile │ ├── badlocality.c │ ├── goodlocality.c │ └── locality.md ├── page-replacement-policy.md └── page-replacement-policy.py ├── lab4 ├── lab4-spoc-discuss │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ └── pmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── lab4-spoc-discuss.md │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ └── x86.h │ └── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ └── vector.c ├── process-concept-homework.md └── process-concept-homework.py ├── lab5 ├── lab5-spoc-discuss │ ├── Makefile │ ├── boot │ │ ├── asm.h │ │ ├── bootasm.S │ │ └── bootmain.c │ ├── kern │ │ ├── debug │ │ │ ├── assert.h │ │ │ ├── kdebug.c │ │ │ ├── kdebug.h │ │ │ ├── kmonitor.c │ │ │ ├── kmonitor.h │ │ │ ├── panic.c │ │ │ └── stab.h │ │ ├── driver │ │ │ ├── clock.c │ │ │ ├── clock.h │ │ │ ├── console.c │ │ │ ├── console.h │ │ │ ├── ide.c │ │ │ ├── ide.h │ │ │ ├── intr.c │ │ │ ├── intr.h │ │ │ ├── kbdreg.h │ │ │ ├── picirq.c │ │ │ └── picirq.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ ├── swapfs.c │ │ │ └── swapfs.h │ │ ├── init │ │ │ ├── entry.S │ │ │ └── init.c │ │ ├── libs │ │ │ ├── rb_tree.c │ │ │ ├── rb_tree.h │ │ │ ├── readline.c │ │ │ └── stdio.c │ │ ├── mm │ │ │ ├── default_pmm.c │ │ │ ├── default_pmm.h │ │ │ ├── kmalloc.c │ │ │ ├── kmalloc.h │ │ │ ├── memlayout.h │ │ │ ├── mmu.h │ │ │ ├── pmm.c │ │ │ ├── pmm.h │ │ │ ├── swap.c │ │ │ ├── swap.h │ │ │ ├── swap_fifo.c │ │ │ ├── swap_fifo.h │ │ │ ├── vmm.c │ │ │ └── vmm.h │ │ ├── process │ │ │ ├── entry.S │ │ │ ├── proc.c │ │ │ ├── proc.h │ │ │ └── switch.S │ │ ├── schedule │ │ │ ├── sched.c │ │ │ └── sched.h │ │ ├── sync │ │ │ └── sync.h │ │ ├── syscall │ │ │ ├── syscall.c │ │ │ └── syscall.h │ │ └── trap │ │ │ ├── trap.c │ │ │ ├── trap.h │ │ │ ├── trapentry.S │ │ │ └── vectors.S │ ├── libs │ │ ├── atomic.h │ │ ├── defs.h │ │ ├── elf.h │ │ ├── error.h │ │ ├── hash.c │ │ ├── list.h │ │ ├── printfmt.c │ │ ├── rand.c │ │ ├── stdarg.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.c │ │ ├── string.h │ │ ├── unistd.h │ │ └── x86.h │ ├── tools │ │ ├── boot.ld │ │ ├── function.mk │ │ ├── gdbinit │ │ ├── grade.sh │ │ ├── kernel.ld │ │ ├── sign.c │ │ ├── user.ld │ │ └── vector.c │ └── user │ │ ├── badarg.c │ │ ├── badsegment.c │ │ ├── divzero.c │ │ ├── exit.c │ │ ├── faultread.c │ │ ├── faultreadkernel.c │ │ ├── forktest.c │ │ ├── forktree.c │ │ ├── hello.c │ │ ├── libs │ │ ├── initcode.S │ │ ├── panic.c │ │ ├── stdio.c │ │ ├── syscall.c │ │ ├── syscall.h │ │ ├── ulib.c │ │ ├── ulib.h │ │ └── umain.c │ │ ├── pgdir.c │ │ ├── softint.c │ │ ├── spin.c │ │ ├── testbss.c │ │ ├── waitkill.c │ │ └── yield.c ├── process-cpuio-homework.md └── process-cpuio-homework.py ├── lab6 ├── scheduler-homework.md └── scheduler-homework.py ├── lab7 ├── deadlock │ ├── bankers-homework.py │ └── example-output.txt ├── ipc │ ├── pipe-ex1.py │ ├── pipe-ex2.c │ ├── shmem │ │ ├── shmem_client.c │ │ └── shmem_server.c │ └── signal-ex1.c ├── lab7-spoc-exercise.md ├── race-condition │ ├── loop.s │ ├── looping-race-nolock.s │ ├── simple-race.s │ ├── test.s │ ├── wait-for-me.s │ └── x86.py ├── semaphore_condition │ ├── README.md │ ├── thr-ex0.py │ ├── thr-ex1.py │ ├── thr-ex2.py │ ├── thr-ex3.py │ ├── thr-ex4.py │ ├── thr-ex5.py │ ├── thr-ex6.py │ ├── thr-ex7.py │ └── thr-ex8.py └── software-hardware-locks │ ├── flag.s │ ├── peterson.s │ ├── test-and-set.s │ ├── test-and-test-and-set.s │ ├── ticket.s │ ├── x86.py │ └── yield.s ├── lab8 ├── disksim-homework.md ├── disksim-homework.py ├── sfs-homework.md ├── sfs-homework.py └── sfs_states.txt ├── labX ├── lab1_X.md ├── lab2_X.md ├── lab3_X.md ├── lab4_X.md ├── lab5_X.md ├── lab6_X.md ├── lab7_X.md ├── lab8_X.md └── labx_X.md └── ostep ├── README.md ├── ostep1-relocation.md ├── ostep1-relocation.py ├── ostep10-lottery.md ├── ostep10-lottery.py ├── ostep11-threadintro ├── loop.s ├── looping-race-nolock.s ├── race.md ├── simple-race.s ├── wait-for-me.s └── x86.py ├── ostep12-threadlock ├── flag.s ├── locks.md ├── peterson.s ├── test-and-set.s ├── test-and-test-and-set.s ├── ticket.s ├── x86.py └── yield.s ├── ostep13-vsfs.md ├── ostep13-vsfs.py ├── ostep14-afs.md ├── ostep14-afs.py ├── ostep15-disk ├── disk-precise.py ├── disk.md └── disk.py ├── ostep16-raid.md ├── ostep16-raid.py ├── ostep2-segmentation.md ├── ostep2-segmentation.py ├── ostep3-malloc.md ├── ostep3-malloc.py ├── ostep4-paging-linear-translate.md ├── ostep4-paging-linear-translate.py ├── ostep5-paging-multilevel-translate.md ├── ostep5-paging-multilevel-translate.py ├── ostep6-paging-policy.md ├── ostep6-paging-policy.py ├── ostep7-process-run.md ├── ostep7-process-run.py ├── ostep8-scheduler.md ├── ostep8-scheduler.py ├── ostep9-mlfq.md └── ostep9-mlfq.py /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((c-mode . ((indent-tabs-mode . nil) 2 | (c-basic-offset . 4)))) 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | obj/ 3 | bin/ 4 | .gdb.in 5 | .qemu.out 6 | cscope.* 7 | ncscope.* 8 | tags 9 | *swp 10 | .cproject 11 | .project 12 | *.bak 13 | *.org 14 | .codelite 15 | *.project 16 | *.workspace 17 | a.out 18 | *.log 19 | *.exe 20 | chytesting 21 | disk0 22 | *.orig 23 | -------------------------------------------------------------------------------- /docs/lab1/控制寄存器.md: -------------------------------------------------------------------------------- 1 | ### 控制寄存器 2 | 3 | --- 4 | 5 | - **CR0** — 包含系统控制标志,控制处理器的操作模式和状态 6 | - **CR1** — 保留 7 | - **CR2** — 包含 page-fault 线性地址 (造成 page-fault 的线性地址) 8 | - **CR3** — 包含页目录基址以及两个标志位 9 | - **CR4** — 包含一组使能几个CPU扩展的标志位 10 | 11 | #### CR0 控制寄存器 12 | 13 | **PG**:当置位时,允许页表映射,否则不允许页表映射,此时所有线性地址被看做物理地址。 14 | 15 | #### 参考手册 16 | 17 | [1]. intel 手册卷三 2.5 Control Registers 18 | 19 | -------------------------------------------------------------------------------- /labcodes/autobuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Nothing to be done here 4 | exit 0 5 | -------------------------------------------------------------------------------- /labcodes/clangbuildall.sh: -------------------------------------------------------------------------------- 1 | cd lab1; make clean; USELLVM=1 make; cd .. 2 | cd lab2; make clean; USELLVM=1 make; cd .. 3 | cd lab3; make clean; USELLVM=1 make; cd .. 4 | cd lab4; make clean; USELLVM=1 make; cd .. 5 | cd lab5; make clean; USELLVM=1 make; cd .. 6 | cd lab6; make clean; USELLVM=1 make; cd .. 7 | cd lab7; make clean; USELLVM=1 make; cd .. 8 | cd lab8; make clean; USELLVM=1 make; cd .. 9 | -------------------------------------------------------------------------------- /labcodes/cleanall.sh: -------------------------------------------------------------------------------- 1 | cd lab1; make clean; cd .. 2 | cd lab2; make clean; cd .. 3 | cd lab3; make clean; cd .. 4 | cd lab4; make clean; cd .. 5 | cd lab5; make clean; cd .. 6 | cd lab6; make clean; cd .. 7 | cd lab7; make clean; cd .. 8 | cd lab8; make clean; cd .. 9 | -------------------------------------------------------------------------------- /labcodes/gccbuildall.sh: -------------------------------------------------------------------------------- 1 | cd lab1; make clean; make; cd .. 2 | cd lab2; make clean; make; cd .. 3 | cd lab3; make clean; make; cd .. 4 | cd lab4; make clean; make; cd .. 5 | cd lab5; make clean; make; cd .. 6 | cd lab6; make clean; make; cd .. 7 | cd lab7; make clean; make; cd .. 8 | cd lab8; make clean; make; cd .. 9 | -------------------------------------------------------------------------------- /labcodes/lab1/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab1/.projectile -------------------------------------------------------------------------------- /labcodes/lab1/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | 6 | void print_kerninfo(void); 7 | void print_stackframe(void); 8 | void print_debuginfo(uintptr_t eip); 9 | 10 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/debug/kmonitor.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_MONITOR_H__ 2 | #define __KERN_DEBUG_MONITOR_H__ 3 | 4 | #include 5 | 6 | void kmonitor(struct trapframe *tf); 7 | 8 | int mon_help(int argc, char **argv, struct trapframe *tf); 9 | int mon_kerninfo(int argc, char **argv, struct trapframe *tf); 10 | int mon_backtrace(int argc, char **argv, struct trapframe *tf); 11 | 12 | #endif /* !__KERN_DEBUG_MONITOR_H__ */ 13 | 14 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab1/kern/mm/pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_PMM_H__ 2 | #define __KERN_MM_PMM_H__ 3 | 4 | void pmm_init(void); 5 | 6 | #endif /* !__KERN_MM_PMM_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes/lab1/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab1/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | set architecture i8086 4 | b *0x7c00 5 | continue 6 | x /2i $pc 7 | # break kern_init 8 | # continue -------------------------------------------------------------------------------- /labcodes/lab2/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab2/.projectile -------------------------------------------------------------------------------- /labcodes/lab2/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab2/kern/sync/sync.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SYNC_H__ 2 | #define __KERN_SYNC_SYNC_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static inline bool 9 | __intr_save(void) { 10 | if (read_eflags() & FL_IF) { 11 | intr_disable(); 12 | return 1; 13 | } 14 | return 0; 15 | } 16 | 17 | static inline void 18 | __intr_restore(bool flag) { 19 | if (flag) { 20 | intr_enable(); 21 | } 22 | } 23 | 24 | #define local_intr_save(x) do { x = __intr_save(); } while (0) 25 | #define local_intr_restore(x) __intr_restore(x); 26 | 27 | #endif /* !__KERN_SYNC_SYNC_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /labcodes/lab2/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab2/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab2/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab3/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab3/.projectile -------------------------------------------------------------------------------- /labcodes/lab3/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes/lab3/kern/sync/sync.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SYNC_H__ 2 | #define __KERN_SYNC_SYNC_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static inline bool 9 | __intr_save(void) { 10 | if (read_eflags() & FL_IF) { 11 | intr_disable(); 12 | return 1; 13 | } 14 | return 0; 15 | } 16 | 17 | static inline void 18 | __intr_restore(bool flag) { 19 | if (flag) { 20 | intr_enable(); 21 | } 22 | } 23 | 24 | #define local_intr_save(x) do { x = __intr_save(); } while (0) 25 | #define local_intr_restore(x) __intr_restore(x); 26 | 27 | #endif /* !__KERN_SYNC_SYNC_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /labcodes/lab3/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab3/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | /* the largest number rand will return */ 5 | #define RAND_MAX 2147483647UL 6 | 7 | /* libs/rand.c */ 8 | int rand(void); 9 | void srand(unsigned int seed); 10 | 11 | #endif /* !__LIBS_RAND_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab3/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab3/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab4/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab4/.projectile -------------------------------------------------------------------------------- /labcodes/lab4/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_KMALLOC_H__ 2 | #define __KERN_MM_KMALLOC_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | #endif /* !__KERN_MM_KMALLOC_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/schedule/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_H__ 2 | #define __KERN_SCHEDULE_SCHED_H__ 3 | 4 | #include 5 | 6 | void schedule(void); 7 | void wakeup_proc(struct proc_struct *proc); 8 | 9 | #endif /* !__KERN_SCHEDULE_SCHED_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab4/kern/sync/sync.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SYNC_H__ 2 | #define __KERN_SYNC_SYNC_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static inline bool 9 | __intr_save(void) { 10 | if (read_eflags() & FL_IF) { 11 | intr_disable(); 12 | return 1; 13 | } 14 | return 0; 15 | } 16 | 17 | static inline void 18 | __intr_restore(bool flag) { 19 | if (flag) { 20 | intr_enable(); 21 | } 22 | } 23 | 24 | #define local_intr_save(x) do { x = __intr_save(); } while (0) 25 | #define local_intr_restore(x) __intr_restore(x); 26 | 27 | #endif /* !__KERN_SYNC_SYNC_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /labcodes/lab4/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab4/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab4/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes/lab4/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab4/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab5/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab5/.projectile -------------------------------------------------------------------------------- /labcodes/lab5/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_KMALLOC_H__ 2 | #define __KERN_MM_KMALLOC_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_KMALLOC_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/schedule/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_H__ 2 | #define __KERN_SCHEDULE_SCHED_H__ 3 | 4 | #include 5 | 6 | void schedule(void); 7 | void wakeup_proc(struct proc_struct *proc); 8 | 9 | #endif /* !__KERN_SCHEDULE_SCHED_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab5/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes/lab5/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab5/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab5/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes/lab5/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab5/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab5/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes/lab5/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab5/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab5/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab5/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab5/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab5/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab5/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | 13 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab5/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab5/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab5/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab5/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab6/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab6/.projectile -------------------------------------------------------------------------------- /labcodes/lab6/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_KMALLOC_H__ 2 | #define __KERN_MM_KMALLOC_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_KMALLOC_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/schedule/default_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_RR_H__ 2 | #define __KERN_SCHEDULE_SCHED_RR_H__ 3 | 4 | #include 5 | 6 | extern struct sched_class default_sched_class; 7 | 8 | #endif /* !__KERN_SCHEDULE_SCHED_RR_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab6/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes/lab6/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab6/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab6/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes/lab6/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab6/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab6/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes/lab6/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab6/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab6/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab6/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab6/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab6/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab6/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | int sys_gettime(void); 13 | /* FOR LAB6 ONLY */ 14 | void sys_lab6_set_priority(uint32_t priority); 15 | 16 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes/lab6/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab6/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab6/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab6/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab7/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab7/.projectile -------------------------------------------------------------------------------- /labcodes/lab7/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_KMALLOC_H__ 2 | #define __KERN_MM_KMALLOC_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_KMALLOC_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/schedule/default_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_RR_H__ 2 | #define __KERN_SCHEDULE_SCHED_RR_H__ 3 | 4 | #include 5 | 6 | extern struct sched_class default_sched_class; 7 | 8 | #endif /* !__KERN_SCHEDULE_SCHED_RR_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/sync/sem.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SEM_H__ 2 | #define __KERN_SYNC_SEM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct { 9 | int value; 10 | wait_queue_t wait_queue; 11 | } semaphore_t; 12 | 13 | void sem_init(semaphore_t *sem, int value); 14 | void up(semaphore_t *sem); 15 | void down(semaphore_t *sem); 16 | bool try_down(semaphore_t *sem); 17 | 18 | #endif /* !__KERN_SYNC_SEM_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes/lab7/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes/lab7/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab7/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab7/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes/lab7/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab7/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab7/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes/lab7/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab7/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab7/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab7/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab7/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab7/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab7/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | int sys_gettime(void); 13 | /* FOR LAB6 ONLY */ 14 | void sys_lab6_set_priority(uint32_t priority); 15 | 16 | int sys_sleep(unsigned int time); 17 | 18 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes/lab7/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab7/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab7/user/sleepkill.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid; 7 | if ((pid = fork()) == 0) { 8 | sleep(~0); 9 | exit(0xdead); 10 | } 11 | assert(pid > 0); 12 | 13 | sleep(100); 14 | assert(kill(pid) == 0); 15 | cprintf("sleepkill pass.\n"); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab7/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab7/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab8/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes/lab8/.projectile -------------------------------------------------------------------------------- /labcodes/lab8/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | long SYSTEM_READ_TIMER( void ); 11 | 12 | 13 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/fs/sfs/sfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | * sfs_init - mount sfs on disk0 8 | * 9 | * CALL GRAPH: 10 | * kern_init-->fs_init-->sfs_init 11 | */ 12 | void 13 | sfs_init(void) { 14 | int ret; 15 | if ((ret = sfs_mount("disk0")) != 0) { 16 | panic("failed: sfs: sfs_mount: %e.\n", ret); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/fs/swap/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAP_SWAPFS_H__ 2 | #define __KERN_FS_SWAP_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAP_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_KMALLOC_H__ 2 | #define __KERN_MM_KMALLOC_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_KMALLOC_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/schedule/default_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_RR_H__ 2 | #define __KERN_SCHEDULE_SCHED_RR_H__ 3 | 4 | #include 5 | 6 | extern struct sched_class default_sched_class; 7 | 8 | #endif /* !__KERN_SCHEDULE_SCHED_RR_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/sync/sem.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SEM_H__ 2 | #define __KERN_SYNC_SEM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct { 9 | int value; 10 | wait_queue_t wait_queue; 11 | } semaphore_t; 12 | 13 | void sem_init(semaphore_t *sem, int value); 14 | void up(semaphore_t *sem); 15 | void down(semaphore_t *sem); 16 | bool try_down(semaphore_t *sem); 17 | 18 | #endif /* !__KERN_SYNC_SEM_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes/lab8/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes/lab8/libs/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_DIRENT_H__ 2 | #define __LIBS_DIRENT_H__ 3 | 4 | #include 5 | #include 6 | 7 | struct dirent { 8 | off_t offset; 9 | char name[FS_MAX_FNAME_LEN + 1]; 10 | }; 11 | 12 | #endif /* !__LIBS_DIRENT_H__ */ 13 | 14 | -------------------------------------------------------------------------------- /labcodes/lab8/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab8/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes/lab8/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes/lab8/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes/lab8/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab8/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes/lab8/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab8/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab8/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab8/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab8/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab8/user/libs/dir.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_DIR_H__ 2 | #define __USER_LIBS_DIR_H__ 3 | 4 | #include 5 | #include 6 | 7 | typedef struct { 8 | int fd; 9 | struct dirent dirent; 10 | } DIR; 11 | 12 | DIR *opendir(const char *path); 13 | struct dirent *readdir(DIR *dirp); 14 | void closedir(DIR *dirp); 15 | int chdir(const char *path); 16 | int getcwd(char *buffer, size_t len); 17 | 18 | #endif /* !__USER_LIBS_DIR_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes/lab8/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # load argc and argv 8 | movl (%esp), %ebx 9 | lea 0x4(%esp), %ecx 10 | 11 | 12 | # move down the esp register 13 | # since it may cause page fault in backtrace 14 | subl $0x20, %esp 15 | 16 | # save argc and argv on stack 17 | pushl %ecx 18 | pushl %ebx 19 | 20 | # call user-program function 21 | call umain 22 | 1: jmp 1b 23 | 24 | 25 | -------------------------------------------------------------------------------- /labcodes/lab8/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes/lab8/user/sleepkill.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid; 7 | if ((pid = fork()) == 0) { 8 | sleep(~0); 9 | exit(0xdead); 10 | } 11 | assert(pid > 0); 12 | 13 | sleep(100); 14 | assert(kill(pid) == 0); 15 | cprintf("sleepkill pass.\n"); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes/lab8/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes/lab8/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/README.txt: -------------------------------------------------------------------------------- 1 | ## 注意 2 | 这个目录下的内容并不是标准参考答案,也存在这样那样的bug,请酌情使用。 3 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab1_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | 6 | void print_kerninfo(void); 7 | void print_stackframe(void); 8 | void print_debuginfo(uintptr_t eip); 9 | 10 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/debug/kmonitor.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_MONITOR_H__ 2 | #define __KERN_DEBUG_MONITOR_H__ 3 | 4 | #include 5 | 6 | void kmonitor(struct trapframe *tf); 7 | 8 | int mon_help(int argc, char **argv, struct trapframe *tf); 9 | int mon_kerninfo(int argc, char **argv, struct trapframe *tf); 10 | int mon_backtrace(int argc, char **argv, struct trapframe *tf); 11 | 12 | #endif /* !__KERN_DEBUG_MONITOR_H__ */ 13 | 14 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/kern/mm/pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_PMM_H__ 2 | #define __KERN_MM_PMM_H__ 3 | 4 | void pmm_init(void); 5 | 6 | #endif /* !__KERN_MM_PMM_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file obj/bootblock.o 2 | target remote :1234 3 | break bootmain 4 | continue 5 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/tools/lab1init: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | set architecture i8086 4 | b *0x7c00 5 | continue 6 | x /2i $pc 7 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/tools/moninit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab2_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/kern/sync/sync.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SYNC_H__ 2 | #define __KERN_SYNC_SYNC_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static inline bool 9 | __intr_save(void) { 10 | if (read_eflags() & FL_IF) { 11 | intr_disable(); 12 | return 1; 13 | } 14 | return 0; 15 | } 16 | 17 | static inline void 18 | __intr_restore(bool flag) { 19 | if (flag) { 20 | intr_enable(); 21 | } 22 | } 23 | 24 | #define local_intr_save(x) do { x = __intr_save(); } while (0) 25 | #define local_intr_restore(x) __intr_restore(x); 26 | 27 | #endif /* !__KERN_SYNC_SYNC_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab3_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/kern/sync/sync.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SYNC_H__ 2 | #define __KERN_SYNC_SYNC_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static inline bool 9 | __intr_save(void) { 10 | if (read_eflags() & FL_IF) { 11 | intr_disable(); 12 | return 1; 13 | } 14 | return 0; 15 | } 16 | 17 | static inline void 18 | __intr_restore(bool flag) { 19 | if (flag) { 20 | intr_enable(); 21 | } 22 | } 23 | 24 | #define local_intr_save(x) do { x = __intr_save(); } while (0) 25 | #define local_intr_restore(x) __intr_restore(x); 26 | 27 | #endif /* !__KERN_SYNC_SYNC_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | /* the largest number rand will return */ 5 | #define RAND_MAX 2147483647UL 6 | 7 | /* libs/rand.c */ 8 | int rand(void); 9 | void srand(unsigned int seed); 10 | 11 | #endif /* !__LIBS_RAND_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab4_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SLAB_H__ 2 | #define __KERN_MM_SLAB_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | #endif /* !__KERN_MM_SLAB_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/kern/schedule/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_H__ 2 | #define __KERN_SCHEDULE_SCHED_H__ 3 | 4 | #include 5 | 6 | void schedule(void); 7 | void wakeup_proc(struct proc_struct *proc); 8 | 9 | #endif /* !__KERN_SCHEDULE_SCHED_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab5_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SLAB_H__ 2 | #define __KERN_MM_SLAB_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_SLAB_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/schedule/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_H__ 2 | #define __KERN_SCHEDULE_SCHED_H__ 3 | 4 | #include 5 | 6 | void schedule(void); 7 | void wakeup_proc(struct proc_struct *proc); 8 | 9 | #endif /* !__KERN_SCHEDULE_SCHED_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | 13 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab6_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SLAB_H__ 2 | #define __KERN_MM_SLAB_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_SLAB_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/schedule/default_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_RR_H__ 2 | #define __KERN_SCHEDULE_SCHED_RR_H__ 3 | 4 | #include 5 | 6 | extern struct sched_class default_sched_class; 7 | 8 | #endif /* !__KERN_SCHEDULE_SCHED_RR_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | /* FOR LAB6 ONLY */ 13 | void sys_lab6_set_priority(uint32_t priority); 14 | 15 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab7_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SLAB_H__ 2 | #define __KERN_MM_SLAB_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_SLAB_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/schedule/default_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_RR_H__ 2 | #define __KERN_SCHEDULE_SCHED_RR_H__ 3 | 4 | #include 5 | 6 | extern struct sched_class default_sched_class; 7 | 8 | #endif /* !__KERN_SCHEDULE_SCHED_RR_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/sync/sem.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SEM_H__ 2 | #define __KERN_SYNC_SEM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct { 9 | int value; 10 | wait_queue_t wait_queue; 11 | } semaphore_t; 12 | 13 | void sem_init(semaphore_t *sem, int value); 14 | void up(semaphore_t *sem); 15 | void down(semaphore_t *sem); 16 | bool try_down(semaphore_t *sem); 17 | 18 | #endif /* !__KERN_SYNC_SEM_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | /* FOR LAB6 ONLY */ 13 | void sys_lab6_set_priority(uint32_t priority); 14 | 15 | int sys_sleep(unsigned int time); 16 | 17 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/sleepkill.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid; 7 | if ((pid = fork()) == 0) { 8 | sleep(~0); 9 | exit(0xdead); 10 | } 11 | assert(pid > 0); 12 | 13 | sleep(100); 14 | assert(kill(pid) == 0); 15 | cprintf("sleepkill pass.\n"); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/.projectile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiukotsu/ucore/ed68c5c1fa8660de46e5494907d01466d7c10eba/labcodes_answer/lab8_result/.projectile -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | long SYSTEM_READ_TIMER( void ); 11 | 12 | 13 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/fs/sfs/sfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | * sfs_init - mount sfs on disk0 8 | * 9 | * CALL GRAPH: 10 | * kern_init-->fs_init-->sfs_init 11 | */ 12 | void 13 | sfs_init(void) { 14 | int ret; 15 | if ((ret = sfs_mount("disk0")) != 0) { 16 | panic("failed: sfs: sfs_mount: %e.\n", ret); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/fs/swap/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAP_SWAPFS_H__ 2 | #define __KERN_FS_SWAP_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAP_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SLAB_H__ 2 | #define __KERN_MM_SLAB_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_SLAB_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/schedule/default_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_RR_H__ 2 | #define __KERN_SCHEDULE_SCHED_RR_H__ 3 | 4 | #include 5 | 6 | extern struct sched_class default_sched_class; 7 | 8 | #endif /* !__KERN_SCHEDULE_SCHED_RR_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/sync/sem.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYNC_SEM_H__ 2 | #define __KERN_SYNC_SEM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct { 9 | int value; 10 | wait_queue_t wait_queue; 11 | } semaphore_t; 12 | 13 | void sem_init(semaphore_t *sem, int value); 14 | void up(semaphore_t *sem); 15 | void down(semaphore_t *sem); 16 | bool try_down(semaphore_t *sem); 17 | 18 | #endif /* !__KERN_SYNC_SEM_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/libs/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_DIRENT_H__ 2 | #define __LIBS_DIRENT_H__ 3 | 4 | #include 5 | #include 6 | 7 | struct dirent { 8 | off_t offset; 9 | char name[FS_MAX_FNAME_LEN + 1]; 10 | }; 11 | 12 | #endif /* !__LIBS_DIRENT_H__ */ 13 | 14 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/libs/dir.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_DIR_H__ 2 | #define __USER_LIBS_DIR_H__ 3 | 4 | #include 5 | #include 6 | 7 | typedef struct { 8 | int fd; 9 | struct dirent dirent; 10 | } DIR; 11 | 12 | DIR *opendir(const char *path); 13 | struct dirent *readdir(DIR *dirp); 14 | void closedir(DIR *dirp); 15 | int chdir(const char *path); 16 | int getcwd(char *buffer, size_t len); 17 | 18 | #endif /* !__USER_LIBS_DIR_H__ */ 19 | 20 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # load argc and argv 8 | movl (%esp), %ebx 9 | lea 0x4(%esp), %ecx 10 | 11 | 12 | # move down the esp register 13 | # since it may cause page fault in backtrace 14 | subl $0x20, %esp 15 | 16 | # save argc and argv on stack 17 | pushl %ecx 18 | pushl %ebx 19 | 20 | # call user-program function 21 | call umain 22 | 1: jmp 1b 23 | 24 | 25 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/sleepkill.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid; 7 | if ((pid = fork()) == 0) { 8 | sleep(~0); 9 | exit(0xdead); 10 | } 11 | assert(pid > 0); 12 | 13 | sleep(100); 14 | assert(kill(pid) == 0); 15 | cprintf("sleepkill pass.\n"); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex1.c: -------------------------------------------------------------------------------- 1 | int count=1; 2 | int value=1; 3 | int buf[10]; 4 | void main() 5 | { 6 | asm( 7 | "cld \n\t" 8 | "rep \n\t" 9 | "stosl" 10 | : 11 | : "c" (count), "a" (value) , "D" (buf[0]) 12 | : 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex1.md: -------------------------------------------------------------------------------- 1 | #README 2 | Try below command 3 | ``` 4 | $gcc -S -m32 lab0_ex1.c 5 | ``` 6 | Then you will get lab_ex1.S. Try to understand the content & relation of C file and S file. 7 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int 3 | main(void) 4 | { 5 | printf("Hello, world!\n"); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex2.md: -------------------------------------------------------------------------------- 1 | #README 2 | Try below command 3 | ``` 4 | $gcc -g -m32 lab0_ex2.c 5 | ``` 6 | Then you will get a.out. Try to use gdb to debug lab0_ex2. 7 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex4.md: -------------------------------------------------------------------------------- 1 | #README 2 | Try below command 3 | ``` 4 | gcc -g -m32 -I. lab0_ex4.c 2>&1|tee make.log 5 | ``` 6 | If you get gcc's error, try to read make.log and fix the bugs. 7 | 8 | If gcc successed, then you will get a.out. 9 | 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex5.c: -------------------------------------------------------------------------------- 1 | void X(int b) { 2 | if (b==1){ 3 | printf("X:: b is 1!\n"); 4 | }else{ 5 | printf("X:: b is not 1!\n"); 6 | } 7 | } 8 | 9 | int main(int argc, char * argv){ 10 | int a=2; 11 | X(a); 12 | } 13 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main(void){ 4 | int child_status, exec_status; 5 | int pid = fork(); //create a child 6 | if (pid==0) { // child continues here 7 | printf("Child: EXEC lec7_1\n"); 8 | exec_status=execve("lec7_1",NULL,NULL); 9 | printf("Child: Why would I execute?\n"); 10 | } else { // parent continues here 11 | printf("Parent: Whose your daddy?\n"); 12 | child_status=wait(pid); 13 | printf("Parent: the child %d exit with %d\n",pid, child_status); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /related_info/lab0/lab0_ex6.md: -------------------------------------------------------------------------------- 1 | #README 2 | analysis lab0_ex6 3 | ``` 4 | echo "=====================================" 5 | echo "compile and analysis lab0_ex6" 6 | echo "=====================================" 7 | gcc -g -m32 -o lab0_ex6.exe lab0_ex6.c 8 | ./lab0_ex6 9 | ``` 10 | -------------------------------------------------------------------------------- /related_info/lab1/Makefile: -------------------------------------------------------------------------------- 1 | all: lab1-ex0.exe lab1-ex1.exe lab1-ex3.s 2 | 3 | lab1-ex0.exe: defines.h lab1-ex0.s 4 | gcc -m32 -g -o lab1-ex0.exe lab1-ex0.s 5 | strace -f ./lab1-ex0.exe 6 | 7 | lab1-ex1.exe: lab1-ex1.c 8 | echo "compile and watch the syscalls from lab1-ex1" 9 | gcc -m32 -o lab1-ex1.exe lab1-ex1.c 10 | strace -c ./lab1-ex1.exe 11 | echo "watch the interrupts in linux" 12 | more /proc/interrupts 13 | 14 | lab1-ex3.s: lab1-ex3.c 15 | echo "show .s files" 16 | gcc -m32 -S lab1-ex3.c 17 | 18 | clean: 19 | rm lab1-ex0.exe lab1-ex1.exe lab1-ex3.s 20 | -------------------------------------------------------------------------------- /related_info/lab1/defines.h: -------------------------------------------------------------------------------- 1 | SYS_exit = 1 2 | SYS_fork = 2 3 | SYS_write = 4 4 | SYS_open = 5 5 | SYS_close = 6 6 | SYS_execve = 11 7 | SYS_lseek = 19 8 | SYS_dup2 = 63 9 | SYS_mmap = 90 10 | SYS_munmap = 91 11 | SYS_socketcall = 102 12 | SYS_socketcall_socket = 1 13 | SYS_socketcall_bind = 2 14 | SYS_socketcall_listen = 4 15 | SYS_socketcall_accept = 5 16 | 17 | SEEK_END = 2 18 | PROT_READ = 1 19 | MAP_SHARED = 1 20 | 21 | AF_INET = 2 22 | SOCK_STREAM = 1 23 | IPPROTO_TCP = 6 24 | 25 | 26 | STDOUT = 1 27 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex0.md: -------------------------------------------------------------------------------- 1 | # 2 | Try below command 3 | ``` 4 | gcc -g -m32 -o lab1-ex0.exe lab1-ex0.s 5 | ``` 6 | Then you will get lab1_ex0.exe 7 | 8 | Try to use below some tools to analysis lab1_ex0.exe 9 | ``` 10 | objdump -S ... 11 | nm 12 | file 13 | strace -f ... 14 | ``` 15 | Try to understand the contents of this .s file. 16 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex0.s: -------------------------------------------------------------------------------- 1 | .include "defines.h" 2 | .data 3 | hello: 4 | .string "hello world\n" 5 | 6 | .globl main 7 | main: 8 | movl $SYS_write,%eax 9 | movl $STDOUT,%ebx 10 | movl $hello,%ecx 11 | movl $12,%edx 12 | int $0x80 13 | 14 | ret 15 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex1.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main(void) 3 | { 4 | printf("hello world\n"); 5 | } 6 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex1.md: -------------------------------------------------------------------------------- 1 | # 2 | Try below command 3 | 4 | ``` 5 | echo "compile and watch the syscalls from lab1-ex1" 6 | gcc -o lab1-ex1.exe lab1-ex1.c 7 | strace -c ./lab1-ex1.exe 8 | echo "watch the interrupts in linux" 9 | more /proc/interrupts 10 | ``` 11 | 12 | Try to analysis the means of these output log. 13 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex2.md: -------------------------------------------------------------------------------- 1 | # lab1-ex2 2 | Try below command (stack) 3 | 4 | ``` 5 | gcc -m32 -o lab1-ex2.exe lab1-ex2.c 6 | ``` 7 | 8 | Try to analysis the means of these output log. 9 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex3.c: -------------------------------------------------------------------------------- 1 | void inline ex1(void){ 2 | asm ("movl $0xffff, %eax\n"); 3 | } 4 | 5 | void inline ex2(void){ 6 | unsigned cr0; 7 | asm volatile ("movl %%cr0, %0\n" :"=r"(cr0)); 8 | cr0 |= 0x80000000; 9 | asm volatile ("movl %0, %%cr0\n" ::"r"(cr0)); 10 | } 11 | 12 | void inline ex3(void){ 13 | long __res, arg1 = 2, arg2 = 22, arg3 = 222, arg4 = 233; 14 | __asm__ __volatile__("int $0x80" 15 | : "=a" (__res) 16 | : "0" (11),"b" (arg1),"c" (arg2),"d" (arg3),"S" (arg4)); 17 | } 18 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex3.md: -------------------------------------------------------------------------------- 1 | # inline assembly for C example 2 | Try below command 3 | ``` 4 | gcc -m32 -S lab1-ex3.c 5 | ``` 6 | Then you will get lab1_ex3.s 7 | 8 | Try to understand the contents of this .s file and the relation between .c file and .s file. 9 | -------------------------------------------------------------------------------- /related_info/lab1/pmbootloader/Makefile: -------------------------------------------------------------------------------- 1 | all:pmboot 2 | pmboot.s: pmboot.S 3 | gcc -E pmboot.S > pmboot.s 4 | pmboot.o: pmboot.s 5 | as -o pmboot.o pmboot.s 6 | pmboot: pmboot.o 7 | ld --oformat binary -N -e start -Ttext 0x7c00 -o pmboot pmboot.o 8 | run: pmboot 9 | qemu-system-i386 -fda pmboot 10 | .PHONY: clean 11 | clean: 12 | rm pmboot.o pmboot pmboot.s 13 | -------------------------------------------------------------------------------- /related_info/lab1/pmbootloader/pmboot.md: -------------------------------------------------------------------------------- 1 | From http://blog.csdn.net/guocaigao/article/details/8477929 2 | 3 | A toy protect-mode bootloader can display string in real/protect mode of x86. 4 | 5 | Try 6 | ``` 7 | make run 8 | ``` 9 | -------------------------------------------------------------------------------- /related_info/lab1/toybootloader/Makefile: -------------------------------------------------------------------------------- 1 | all:toy 2 | toy.o: toy.S 3 | as -o toy.o toy.S 4 | toy: toy.o 5 | ld --oformat binary -N -e start -Ttext 0x7c00 -o toy toy.o 6 | run: toy 7 | qemu-system-i386 -fda toy 8 | clean: 9 | rm toy.o toy 10 | -------------------------------------------------------------------------------- /related_info/lab1/toybootloader/toy.md: -------------------------------------------------------------------------------- 1 | From http://blog.csdn.net/guocaigao/article/details/8476086 2 | 3 | A toy bootloader can display string in real mode of x86. 4 | 5 | Try 6 | ``` 7 | make run 8 | ``` 9 | -------------------------------------------------------------------------------- /related_info/lab2/kr_malloc_free_2/Makefile: -------------------------------------------------------------------------------- 1 | binaries=memory.o main.o 2 | 3 | all: 4 | gcc -g -ansi -c *.c main.c #-m32: this makes a 32-bit build, but you might have to "sudo apt-get install libc6-dev-i386" first 5 | echo Compiling done 6 | 7 | gcc -g -ansi *.o -o main 8 | echo Linking done 9 | 10 | #make clean #uncomment this if you don't care to debug, symbols and all 11 | 12 | clean: 13 | rm -f $(binaries) 14 | echo Clean done -------------------------------------------------------------------------------- /related_info/lab2/kr_malloc_free_2/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMORY_H_ 2 | #define MEMORY_H_ 3 | 4 | #include /* for size_t */ 5 | 6 | void * dcmalloc(size_t size); 7 | void dcfree(void * ptr); 8 | 9 | void * dcmemset(void * ptr, int value, size_t num); 10 | 11 | void memoryDump(); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /related_info/lab3/locality/Makefile: -------------------------------------------------------------------------------- 1 | all: goodlocality badlocality 2 | goodlocality: 3 | gcc -O0 -g -o goodlocality goodlocality.c 4 | badlocality: 5 | gcc -O0 -g -o badlocality badlocality.c 6 | clean: 7 | rm goodlocality badlocality 8 | -------------------------------------------------------------------------------- /related_info/lab3/locality/badlocality.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define NUM 1024 3 | #define COUNT 10 4 | int A[NUM][NUM]; 5 | void main (void) { 6 | int i,j,k; 7 | for (k = 0; k 2 | #define NUM 1024 3 | #define COUNT 10 4 | int A[NUM][NUM]; 5 | void main (void) { 6 | int i,j,k; 7 | for (k = 0; k 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_KMALLOC_H__ 2 | #define __KERN_MM_KMALLOC_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | #endif /* !__KERN_MM_KMALLOC_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/kern/schedule/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_H__ 2 | #define __KERN_SCHEDULE_SCHED_H__ 3 | 4 | #include 5 | 6 | void schedule(void); 7 | void wakeup_proc(struct proc_struct *proc); 8 | 9 | #endif /* !__KERN_SCHEDULE_SCHED_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/lab4-spoc-discuss.md: -------------------------------------------------------------------------------- 1 | # lab4 spoc discuss 2 | 3 | 4 | ## 掌握知识点 5 | 1. 内核线程的启动、运行、就绪、等待、退出 6 | 2. 内核线程的管理与简单调度 7 | 3. 内核线程的切换过程 8 | 9 | 请完成如下练习,完成代码填写,并形成spoc练习报告 10 | 11 | ## 1. 分析并描述创建分配进程的过程 12 | 13 | > 注意 state、pid、cr3,context,trapframe的含义 14 | 15 | ## 练习2:分析并描述新创建的内核线程是如何分配资源的 16 | ###设计实现 17 | 18 | > 注意 理解对kstack, trapframe, context等的初始化 19 | 20 | 21 | 当前进程中唯一,操作系统的整个生命周期不唯一,在get_pid中会循环使用pid,耗尽会等待 22 | 23 | ## 练习3:阅读代码,在现有基础上再增加一个内核线程,并通过增加cprintf函数到ucore代码中 24 | 能够把进程的生命周期和调度动态执行过程完整地展现出来 25 | 26 | ## 扩展练习4:增加可以睡眠的内核线程,睡眠的条件和唤醒的条件可自行设计,并给出测试用例,并在spoc练习报告中给出设计实现说明 27 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/debug/kdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DEBUG_KDEBUG_H__ 2 | #define __KERN_DEBUG_KDEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_kerninfo(void); 8 | void print_stackframe(void); 9 | void print_debuginfo(uintptr_t eip); 10 | 11 | #endif /* !__KERN_DEBUG_KDEBUG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/driver/clock.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CLOCK_H__ 2 | #define __KERN_DRIVER_CLOCK_H__ 3 | 4 | #include 5 | 6 | extern volatile size_t ticks; 7 | 8 | void clock_init(void); 9 | 10 | #endif /* !__KERN_DRIVER_CLOCK_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/driver/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_CONSOLE_H__ 2 | #define __KERN_DRIVER_CONSOLE_H__ 3 | 4 | void cons_init(void); 5 | void cons_putc(int c); 6 | int cons_getc(void); 7 | void serial_intr(void); 8 | void kbd_intr(void); 9 | 10 | #endif /* !__KERN_DRIVER_CONSOLE_H__ */ 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/driver/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_IDE_H__ 2 | #define __KERN_DRIVER_IDE_H__ 3 | 4 | #include 5 | 6 | void ide_init(void); 7 | bool ide_device_valid(unsigned short ideno); 8 | size_t ide_device_size(unsigned short ideno); 9 | 10 | int ide_read_secs(unsigned short ideno, uint32_t secno, void *dst, size_t nsecs); 11 | int ide_write_secs(unsigned short ideno, uint32_t secno, const void *src, size_t nsecs); 12 | 13 | #endif /* !__KERN_DRIVER_IDE_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/driver/intr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* intr_enable - enable irq interrupt */ 5 | void 6 | intr_enable(void) { 7 | sti(); 8 | } 9 | 10 | /* intr_disable - disable irq interrupt */ 11 | void 12 | intr_disable(void) { 13 | cli(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/driver/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_INTR_H__ 2 | #define __KERN_DRIVER_INTR_H__ 3 | 4 | void intr_enable(void); 5 | void intr_disable(void); 6 | 7 | #endif /* !__KERN_DRIVER_INTR_H__ */ 8 | 9 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/driver/picirq.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_DRIVER_PICIRQ_H__ 2 | #define __KERN_DRIVER_PICIRQ_H__ 3 | 4 | void pic_init(void); 5 | void pic_enable(unsigned int irq); 6 | 7 | #define IRQ_OFFSET 32 8 | 9 | #endif /* !__KERN_DRIVER_PICIRQ_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/fs/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_FS_H__ 2 | #define __KERN_FS_FS_H__ 3 | 4 | #include 5 | 6 | #define SECTSIZE 512 7 | #define PAGE_NSECT (PGSIZE / SECTSIZE) 8 | 9 | #define SWAP_DEV_NO 1 10 | 11 | #endif /* !__KERN_FS_FS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/fs/swapfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_FS_SWAPFS_H__ 2 | #define __KERN_FS_SWAPFS_H__ 3 | 4 | #include 5 | #include 6 | 7 | void swapfs_init(void); 8 | int swapfs_read(swap_entry_t entry, struct Page *page); 9 | int swapfs_write(swap_entry_t entry, struct Page *page); 10 | 11 | #endif /* !__KERN_FS_SWAPFS_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/mm/default_pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_DEFAULT_PMM_H__ 2 | #define __KERN_MM_DEFAULT_PMM_H__ 3 | 4 | #include 5 | 6 | extern const struct pmm_manager default_pmm_manager; 7 | extern free_area_t free_area; 8 | #endif /* ! __KERN_MM_DEFAULT_PMM_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/mm/kmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SLAB_H__ 2 | #define __KERN_MM_SLAB_H__ 3 | 4 | #include 5 | 6 | #define KMALLOC_MAX_ORDER 10 7 | 8 | void kmalloc_init(void); 9 | 10 | void *kmalloc(size_t n); 11 | void kfree(void *objp); 12 | 13 | size_t kallocated(void); 14 | 15 | #endif /* !__KERN_MM_SLAB_H__ */ 16 | 17 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/mm/swap_fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_MM_SWAP_FIFO_H__ 2 | #define __KERN_MM_SWAP_FIFO_H__ 3 | 4 | #include 5 | extern struct swap_manager swap_manager_fifo; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/process/entry.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl kernel_thread_entry 3 | kernel_thread_entry: # void kernel_thread(void) 4 | 5 | pushl %edx # push arg 6 | call *%ebx # call fn 7 | 8 | pushl %eax # save the return value of fn(arg) 9 | call do_exit # call do_exit to terminate current thread 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/schedule/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SCHEDULE_SCHED_H__ 2 | #define __KERN_SCHEDULE_SCHED_H__ 3 | 4 | #include 5 | 6 | void schedule(void); 7 | void wakeup_proc(struct proc_struct *proc); 8 | 9 | #endif /* !__KERN_SCHEDULE_SCHED_H__ */ 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/kern/syscall/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __KERN_SYSCALL_SYSCALL_H__ 2 | #define __KERN_SYSCALL_SYSCALL_H__ 3 | 4 | void syscall(void); 5 | 6 | #endif /* !__KERN_SYSCALL_SYSCALL_H__ */ 7 | 8 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/libs/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 4 | #define GOLDEN_RATIO_PRIME_32 0x9e370001UL 5 | 6 | /* * 7 | * hash32 - generate a hash value in the range [0, 2^@bits - 1] 8 | * @val: the input value 9 | * @bits: the number of bits in a return value 10 | * 11 | * High bits are more random, so we use them. 12 | * */ 13 | uint32_t 14 | hash32(uint32_t val, unsigned int bits) { 15 | uint32_t hash = val * GOLDEN_RATIO_PRIME_32; 16 | return (hash >> (32 - bits)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/libs/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDARG_H__ 2 | #define __LIBS_STDARG_H__ 3 | 4 | /* compiler provides size of save area */ 5 | typedef __builtin_va_list va_list; 6 | 7 | #define va_start(ap, last) (__builtin_va_start(ap, last)) 8 | #define va_arg(ap, type) (__builtin_va_arg(ap, type)) 9 | #define va_end(ap) /*nothing*/ 10 | 11 | #endif /* !__LIBS_STDARG_H__ */ 12 | 13 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/libs/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBS_STDLIB_H__ 2 | #define __LIBS_STDLIB_H__ 3 | 4 | #include 5 | 6 | /* the largest number rand will return */ 7 | #define RAND_MAX 2147483647UL 8 | 9 | /* libs/rand.c */ 10 | int rand(void); 11 | void srand(unsigned int seed); 12 | 13 | /* libs/hash.c */ 14 | uint32_t hash32(uint32_t val, unsigned int bits); 15 | 16 | #endif /* !__LIBS_RAND_H__ */ 17 | 18 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/tools/boot.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | 4 | SECTIONS { 5 | . = 0x7C00; 6 | 7 | .startup : { 8 | *bootasm.o(.text) 9 | } 10 | 11 | .text : { *(.text) } 12 | .data : { *(.data .rodata) } 13 | 14 | /DISCARD/ : { *(.eh_*) } 15 | } 16 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/badarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int pid, exit_code; 7 | if ((pid = fork()) == 0) { 8 | cprintf("fork ok.\n"); 9 | int i; 10 | for (i = 0; i < 10; i ++) { 11 | yield(); 12 | } 13 | exit(0xbeaf); 14 | } 15 | assert(pid > 0); 16 | assert(waitpid(-1, NULL) != 0); 17 | assert(waitpid(pid, (void *)0xC0000000) != 0); 18 | assert(waitpid(pid, &exit_code) == 0 && exit_code == 0xbeaf); 19 | cprintf("badarg pass.\n"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/badsegment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* try to load the kernel's TSS selector into the DS register */ 5 | 6 | int 7 | main(void) { 8 | asm volatile("movw $0x28,%ax; movw %ax,%ds"); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/divzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int zero; 5 | 6 | int 7 | main(void) { 8 | cprintf("value is %d.\n", 1 / zero); 9 | panic("FAIL: T.T\n"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/faultread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %8x from 0.\n", *(unsigned int *)0); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/faultreadkernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I read %08x from 0xfac00000!\n", *(unsigned *)0xfac00000); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("Hello world!!.\n"); 7 | cprintf("I am process %d.\n", getpid()); 8 | cprintf("hello pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/libs/initcode.S: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _start 3 | _start: 4 | # set ebp for backtrace 5 | movl $0x0, %ebp 6 | 7 | # move down the esp register 8 | # since it may cause page fault in backtrace 9 | subl $0x20, %esp 10 | 11 | # call user-program function 12 | call umain 13 | 1: jmp 1b 14 | 15 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/libs/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIBS_SYSCALL_H__ 2 | #define __USER_LIBS_SYSCALL_H__ 3 | 4 | int sys_exit(int error_code); 5 | int sys_fork(void); 6 | int sys_wait(int pid, int *store); 7 | int sys_yield(void); 8 | int sys_kill(int pid); 9 | int sys_getpid(void); 10 | int sys_putc(int c); 11 | int sys_pgdir(void); 12 | 13 | #endif /* !__USER_LIBS_SYSCALL_H__ */ 14 | 15 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/libs/umain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void); 4 | 5 | void 6 | umain(void) { 7 | int ret = main(); 8 | exit(ret); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/pgdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | cprintf("I am %d, print pgdir.\n", getpid()); 7 | print_pgdir(); 8 | cprintf("pgdir pass.\n"); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/softint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | asm volatile("int $14"); 7 | panic("FAIL: T.T\n"); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/user/yield.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) { 6 | int i; 7 | cprintf("Hello, I am process %d.\n", getpid()); 8 | for (i = 0; i < 5; i ++) { 9 | yield(); 10 | cprintf("Back in process %d, iteration %d.\n", getpid(), i); 11 | } 12 | cprintf("All done in process %d.\n", getpid()); 13 | cprintf("yield pass.\n"); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /related_info/lab7/race-condition/loop.s: -------------------------------------------------------------------------------- 1 | .main 2 | .top 3 | sub $1,%dx 4 | test $0,%dx 5 | jgte .top 6 | halt 7 | -------------------------------------------------------------------------------- /related_info/lab7/race-condition/looping-race-nolock.s: -------------------------------------------------------------------------------- 1 | # assumes %bx has loop count in it 2 | 3 | .main 4 | .top 5 | # critical section 6 | mov 2000, %ax # get the value at the address 7 | add $1, %ax # increment it 8 | mov %ax, 2000 # store it back 9 | 10 | # see if we're still looping 11 | sub $1, %bx 12 | test $0, %bx 13 | jgt .top 14 | 15 | halt 16 | -------------------------------------------------------------------------------- /related_info/lab7/race-condition/simple-race.s: -------------------------------------------------------------------------------- 1 | .main 2 | # this is a critical section 3 | mov 2000(%bx), %ax # get the value at the address 4 | add $1, %ax # increment it 5 | mov %ax, 2000(%bx) # store it back 6 | halt 7 | -------------------------------------------------------------------------------- /related_info/lab7/race-condition/test.s: -------------------------------------------------------------------------------- 1 | .main 2 | mov $9,%dx 3 | .top 4 | sub $1,%dx 5 | test $0,%dx 6 | jgte .top 7 | halt 8 | -------------------------------------------------------------------------------- /related_info/lab7/race-condition/wait-for-me.s: -------------------------------------------------------------------------------- 1 | .main 2 | test $1, %ax # ax should be 1 (signaller) or 0 (waiter) 3 | je .signaller 4 | 5 | .waiter 6 | mov 2000, %cx 7 | test $1, %cx 8 | jne .waiter 9 | halt 10 | 11 | .signaller 12 | mov $1, 2000 13 | halt 14 | -------------------------------------------------------------------------------- /related_info/lab7/semaphore_condition/thr-ex2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import threading 3 | import time 4 | count=1 5 | 6 | class KissThread(threading.Thread): 7 | def run(self): 8 | global count 9 | print "Thread # %s:Pretending to do stuff" % count 10 | count+=1 11 | time.sleep(2) 12 | print "done with stuff" 13 | 14 | 15 | for t in range(5): 16 | KissThread().start() 17 | -------------------------------------------------------------------------------- /related_info/lab7/semaphore_condition/thr-ex4.py: -------------------------------------------------------------------------------- 1 | import threading 2 | 3 | class MyThread(threading.Thread): 4 | def __init__(self): 5 | threading.Thread.__init__(self) 6 | 7 | def run(self): 8 | print "I am %s" % (self.name) 9 | 10 | if __name__ == "__main__": 11 | for i in range(0, 5): 12 | my_thread = MyThread() 13 | my_thread.start() 14 | -------------------------------------------------------------------------------- /related_info/lab7/software-hardware-locks/flag.s: -------------------------------------------------------------------------------- 1 | .var flag 2 | .var count 3 | 4 | .main 5 | .top 6 | 7 | .acquire 8 | mov flag, %ax # get flag 9 | test $0, %ax # if we get 0 back: lock is free! 10 | jne .acquire # if not, try again 11 | mov $1, flag # store 1 into flag 12 | 13 | # critical section 14 | mov count, %ax # get the value at the address 15 | add $1, %ax # increment it 16 | mov %ax, count # store it back 17 | 18 | # release lock 19 | mov $0, flag # clear the flag now 20 | 21 | # see if we're still looping 22 | sub $1, %bx 23 | test $0, %bx 24 | jgt .top 25 | 26 | halt 27 | 28 | -------------------------------------------------------------------------------- /related_info/lab7/software-hardware-locks/test-and-set.s: -------------------------------------------------------------------------------- 1 | .var mutex 2 | .var count 3 | 4 | .main 5 | .top 6 | 7 | .acquire 8 | mov $1, %ax 9 | xchg %ax, mutex # atomic swap of 1 and mutex 10 | test $0, %ax # if we get 0 back: lock is free! 11 | jne .acquire # if not, try again 12 | 13 | # critical section 14 | mov count, %ax # get the value at the address 15 | add $1, %ax # increment it 16 | mov %ax, count # store it back 17 | 18 | # release lock 19 | mov $0, mutex 20 | 21 | # see if we're still looping 22 | sub $1, %bx 23 | test $0, %bx 24 | jgt .top 25 | 26 | halt 27 | -------------------------------------------------------------------------------- /related_info/lab7/software-hardware-locks/ticket.s: -------------------------------------------------------------------------------- 1 | .var ticket 2 | .var turn 3 | .var count 4 | 5 | .main 6 | .top 7 | 8 | .acquire 9 | mov $1, %ax 10 | fetchadd %ax, ticket # grab a ticket (keep it in dx) 11 | .tryagain 12 | mov turn, %cx # check if it's your turn 13 | test %cx, %ax 14 | jne .tryagain 15 | 16 | # critical section 17 | mov count, %ax # get the value at the address 18 | add $1, %ax # increment it 19 | mov %ax, count # store it back 20 | 21 | # release lock 22 | mov $1, %ax 23 | fetchadd %ax, turn 24 | 25 | # see if we're still looping 26 | sub $1, %bx 27 | test $0, %bx 28 | jgt .top 29 | 30 | halt 31 | -------------------------------------------------------------------------------- /related_info/labX/lab2_X.md: -------------------------------------------------------------------------------- 1 | challenge1: buddy system(伙伴系统)的page分配算法 2 | 提示:参考“http://coolshell.cn/articles/10427.html 3 | 状态: 4 | 基本完成 (fix 了一个bug) 5 | 感觉在buddy system的管理数据结构的所占空间效率和合并的效率上还有进一步优化的可能 6 | https://github.com/chyyuu/ucore_lab/tree/lab2_X/labcodes_answer/lab2_result 7 | 8 | 完成人: 9 | 黄杰 2012011272 huangjie_cpp@163.com 10 | 袁源 2012011294 thuyuany12@163.com 11 | 杜鹃 2012011354 duj09225@gmail.com 12 | 13 | challenge2: slub分配算法(任意大小的内存单元) 14 | 提示:参考 http://www.ibm.com/developerworks/cn/linux/l-cn-slub/ 15 | 状态:未完成 16 | 完成人: 17 | 18 | 19 | challenge3: 设计一种更加简单的方法,可以不用多次切换段表,修改页表内容等,就完成同样的段页式机制 20 | 提示:xv6? 21 | 状态:未完成 22 | 完成人: 23 | -------------------------------------------------------------------------------- /related_info/labX/lab6_X.md: -------------------------------------------------------------------------------- 1 | challenge1: 参考Linux 的CFS,实现简化的CFS调度算法(基于红黑树) 2 | =================================================== 3 | 状态:未完成 4 | 完成人: 5 | 6 | 7 | challenge2: 参考Linux2.6的O(1)调度器,实现简化的O(1)调度算法 8 | =================================================== 9 | 状态:未完成 10 | 完成人: 11 | 12 | 13 | challenge3: 实现面向Real-time系统的RM/EDF调度算法 14 | =================================================== 15 | 状态:未完成 16 | 完成人: 17 | 18 | 19 | challenge4: 短作业优先(SJF)调度算法/高响应比优先调度算法 20 | =================================================== 21 | 状态:未完成 22 | 完成人: 23 | 24 | 25 | -------------------------------------------------------------------------------- /related_info/labX/lab7_X.md: -------------------------------------------------------------------------------- 1 | challenge1: 实现内核级的进程/线程抢占机制 2 | =================================================== 3 | 状态:未完成 4 | 完成人: 5 | 6 | challenge2: 参考Linux的RCU,实现简化的RCU机制 7 | =================================================== 8 | 提示: 9 | http://www.ibm.com/developerworks/cn/linux/l-rcu/ 10 | http://www.diybl.com/course/6_system/linux/Linuxjs/20081117/151814.html 11 | 状态:未完成 12 | 完成人: 13 | 14 | challenge3: 在内核中增加相应机制,能够探测死锁或破坏互斥现象 15 | =================================================== 16 | 状态:未完成 17 | 完成人: 18 | 19 | -------------------------------------------------------------------------------- /related_info/labX/lab8_X.md: -------------------------------------------------------------------------------- 1 | challenge1 参考unix的pipe/fifo机制,实现基于VFS接口的pipe/fifo机制 2 | =================================================== 3 | 状态:未完成 4 | 完成人: 5 | 6 | 7 | challenge 支持现有文件系统之外的其他文件系统的读写 8 | =================================================== 9 | 状态:未完成 10 | 完成人: 11 | -------------------------------------------------------------------------------- /related_info/ostep/ostep11-threadintro/loop.s: -------------------------------------------------------------------------------- 1 | .main 2 | .top 3 | sub $1,%dx 4 | test $0,%dx 5 | jgte .top 6 | halt 7 | -------------------------------------------------------------------------------- /related_info/ostep/ostep11-threadintro/looping-race-nolock.s: -------------------------------------------------------------------------------- 1 | # assumes %bx has loop count in it 2 | 3 | .main 4 | .top 5 | # critical section 6 | mov 2000, %ax # get the value at the address 7 | add $1, %ax # increment it 8 | mov %ax, 2000 # store it back 9 | 10 | # see if we're still looping 11 | sub $1, %bx 12 | test $0, %bx 13 | jgt .top 14 | 15 | halt 16 | -------------------------------------------------------------------------------- /related_info/ostep/ostep11-threadintro/simple-race.s: -------------------------------------------------------------------------------- 1 | .main 2 | # this is a critical section 3 | mov 2000(%bx), %ax # get the value at the address 4 | add $1, %ax # increment it 5 | mov %ax, 2000(%bx) # store it back 6 | halt 7 | -------------------------------------------------------------------------------- /related_info/ostep/ostep11-threadintro/wait-for-me.s: -------------------------------------------------------------------------------- 1 | .main 2 | test $1, %ax # ax should be 1 (signaller) or 0 (waiter) 3 | je .signaller 4 | 5 | .waiter 6 | mov 2000, %cx 7 | test $1, %cx 8 | jne .waiter 9 | halt 10 | 11 | .signaller 12 | mov $1, 2000 13 | halt 14 | -------------------------------------------------------------------------------- /related_info/ostep/ostep12-threadlock/flag.s: -------------------------------------------------------------------------------- 1 | .var flag 2 | .var count 3 | 4 | .main 5 | .top 6 | 7 | .acquire 8 | mov flag, %ax # get flag 9 | test $0, %ax # if we get 0 back: lock is free! 10 | jne .acquire # if not, try again 11 | mov $1, flag # store 1 into flag 12 | 13 | # critical section 14 | mov count, %ax # get the value at the address 15 | add $1, %ax # increment it 16 | mov %ax, count # store it back 17 | 18 | # release lock 19 | mov $0, flag # clear the flag now 20 | 21 | # see if we're still looping 22 | sub $1, %bx 23 | test $0, %bx 24 | jgt .top 25 | 26 | halt 27 | 28 | -------------------------------------------------------------------------------- /related_info/ostep/ostep12-threadlock/test-and-set.s: -------------------------------------------------------------------------------- 1 | .var mutex 2 | .var count 3 | 4 | .main 5 | .top 6 | 7 | .acquire 8 | mov $1, %ax 9 | xchg %ax, mutex # atomic swap of 1 and mutex 10 | test $0, %ax # if we get 0 back: lock is free! 11 | jne .acquire # if not, try again 12 | 13 | # critical section 14 | mov count, %ax # get the value at the address 15 | add $1, %ax # increment it 16 | mov %ax, count # store it back 17 | 18 | # release lock 19 | mov $0, mutex 20 | 21 | # see if we're still looping 22 | sub $1, %bx 23 | test $0, %bx 24 | jgt .top 25 | 26 | halt 27 | -------------------------------------------------------------------------------- /related_info/ostep/ostep12-threadlock/ticket.s: -------------------------------------------------------------------------------- 1 | .var ticket 2 | .var turn 3 | .var count 4 | 5 | .main 6 | .top 7 | 8 | .acquire 9 | mov $1, %ax 10 | fetchadd %ax, ticket # grab a ticket (keep it in dx) 11 | .tryagain 12 | mov turn, %cx # check if it's your turn 13 | test %cx, %ax 14 | jne .tryagain 15 | 16 | # critical section 17 | mov count, %ax # get the value at the address 18 | add $1, %ax # increment it 19 | mov %ax, count # store it back 20 | 21 | # release lock 22 | mov $1, %ax 23 | fetchadd %ax, turn 24 | 25 | # see if we're still looping 26 | sub $1, %bx 27 | test $0, %bx 28 | jgt .top 29 | 30 | halt 31 | --------------------------------------------------------------------------------