├── labcodes ├── lab1 │ ├── .projectile │ ├── tools │ │ └── gdbinit │ ├── kern │ │ ├── mm │ │ │ └── pmm.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ └── console.h │ │ └── debug │ │ │ ├── kdebug.h │ │ │ └── kmonitor.h │ └── libs │ │ └── stdarg.h ├── lab2 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── kern │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ └── console.h │ │ ├── mm │ │ │ └── default_pmm.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── sync │ │ │ └── sync.h │ └── libs │ │ └── stdarg.h ├── lab3 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ └── default_pmm.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── sync │ │ │ └── sync.h │ └── libs │ │ ├── stdlib.h │ │ └── stdarg.h ├── lab4 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ ├── process │ │ │ └── entry.S │ │ └── sync │ │ │ └── sync.h │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab5 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── libs │ │ │ ├── umain.c │ │ │ ├── initcode.S │ │ │ └── syscall.h │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── yield.c │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── process │ │ │ └── entry.S │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab6 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── libs │ │ │ ├── umain.c │ │ │ ├── initcode.S │ │ │ └── syscall.h │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── yield.c │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── default_sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── process │ │ │ └── entry.S │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab7 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── libs │ │ │ ├── umain.c │ │ │ ├── initcode.S │ │ │ └── syscall.h │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── sleepkill.c │ │ ├── yield.c │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── default_sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ ├── process │ │ │ └── entry.S │ │ └── sync │ │ │ └── sem.h │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab8 │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── sleepkill.c │ │ ├── yield.c │ │ ├── libs │ │ │ ├── dir.h │ │ │ └── initcode.S │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ ├── clock.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── default_sched.h │ │ ├── debug │ │ │ └── kdebug.h │ │ ├── fs │ │ │ ├── swap │ │ │ │ └── swapfs.h │ │ │ └── sfs │ │ │ │ └── sfs.c │ │ ├── process │ │ │ └── entry.S │ │ └── sync │ │ │ └── sem.h │ └── libs │ │ ├── dirent.h │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── autobuild.sh ├── cleanall.sh ├── gccbuildall.sh └── clangbuildall.sh ├── labcodes_answer ├── lab1_result │ ├── .projectile │ ├── tools │ │ ├── moninit │ │ ├── gdbinit │ │ └── lab1init │ ├── kern │ │ ├── mm │ │ │ └── pmm.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ └── console.h │ │ └── debug │ │ │ ├── kdebug.h │ │ │ └── kmonitor.h │ └── libs │ │ └── stdarg.h ├── lab2_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── kern │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ └── console.h │ │ ├── mm │ │ │ └── default_pmm.h │ │ └── debug │ │ │ └── kdebug.h │ └── libs │ │ └── stdarg.h ├── lab3_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ └── default_pmm.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ └── debug │ │ │ └── kdebug.h │ └── libs │ │ ├── stdlib.h │ │ └── stdarg.h ├── lab4_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── process │ │ │ └── entry.S │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab5_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── libs │ │ │ ├── umain.c │ │ │ ├── initcode.S │ │ │ └── syscall.h │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── yield.c │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── process │ │ │ └── entry.S │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab6_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── libs │ │ │ ├── umain.c │ │ │ ├── initcode.S │ │ │ └── syscall.h │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── yield.c │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── default_sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ └── process │ │ │ └── entry.S │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab7_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── libs │ │ │ ├── umain.c │ │ │ ├── initcode.S │ │ │ └── syscall.h │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── sleepkill.c │ │ ├── yield.c │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── clock.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── default_sched.h │ │ ├── fs │ │ │ ├── fs.h │ │ │ └── swapfs.h │ │ ├── debug │ │ │ └── kdebug.h │ │ ├── process │ │ │ └── entry.S │ │ └── sync │ │ │ └── sem.h │ └── libs │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── lab8_result │ ├── .projectile │ ├── tools │ │ ├── gdbinit │ │ └── boot.ld │ ├── user │ │ ├── softint.c │ │ ├── faultread.c │ │ ├── divzero.c │ │ ├── faultreadkernel.c │ │ ├── pgdir.c │ │ ├── hello.c │ │ ├── badsegment.c │ │ ├── sleepkill.c │ │ ├── yield.c │ │ ├── libs │ │ │ ├── dir.h │ │ │ └── initcode.S │ │ └── badarg.c │ ├── kern │ │ ├── mm │ │ │ ├── swap_fifo.h │ │ │ ├── default_pmm.h │ │ │ └── kmalloc.h │ │ ├── syscall │ │ │ └── syscall.h │ │ ├── driver │ │ │ ├── intr.h │ │ │ ├── picirq.h │ │ │ ├── intr.c │ │ │ ├── console.h │ │ │ ├── clock.h │ │ │ └── ide.h │ │ ├── schedule │ │ │ └── default_sched.h │ │ ├── debug │ │ │ └── kdebug.h │ │ ├── fs │ │ │ ├── swap │ │ │ │ └── swapfs.h │ │ │ └── sfs │ │ │ │ └── sfs.c │ │ ├── process │ │ │ └── entry.S │ │ └── sync │ │ │ └── sem.h │ └── libs │ │ ├── dirent.h │ │ ├── stdlib.h │ │ ├── stdarg.h │ │ └── hash.c ├── README.txt ├── cleanall.sh └── gccbuildall.sh ├── .dir-locals.el ├── related_info ├── lab4 │ ├── lab4-spoc-discuss │ │ ├── tools │ │ │ ├── gdbinit │ │ │ └── boot.ld │ │ ├── kern │ │ │ ├── driver │ │ │ │ ├── intr.h │ │ │ │ ├── clock.h │ │ │ │ ├── picirq.h │ │ │ │ ├── intr.c │ │ │ │ └── console.h │ │ │ ├── mm │ │ │ │ ├── default_pmm.h │ │ │ │ └── kmalloc.h │ │ │ ├── schedule │ │ │ │ └── sched.h │ │ │ ├── debug │ │ │ │ └── kdebug.h │ │ │ └── process │ │ │ │ └── entry.S │ │ ├── libs │ │ │ ├── stdlib.h │ │ │ └── stdarg.h │ │ └── lab4-spoc-discuss.md │ └── some-exercises │ │ ├── build.sh │ │ ├── call.c │ │ ├── prog.s │ │ ├── build-2.sh │ │ ├── call2.c │ │ ├── caller.c │ │ └── callee.s ├── lab5 │ ├── lab5-spoc-discuss │ │ ├── tools │ │ │ ├── gdbinit │ │ │ └── boot.ld │ │ ├── user │ │ │ ├── libs │ │ │ │ ├── umain.c │ │ │ │ ├── initcode.S │ │ │ │ └── syscall.h │ │ │ ├── softint.c │ │ │ ├── divzero.c │ │ │ ├── faultread.c │ │ │ ├── faultreadkernel.c │ │ │ ├── pgdir.c │ │ │ ├── hello.c │ │ │ ├── badsegment.c │ │ │ ├── yield.c │ │ │ └── badarg.c │ │ ├── kern │ │ │ ├── mm │ │ │ │ ├── swap_fifo.h │ │ │ │ ├── default_pmm.h │ │ │ │ └── kmalloc.h │ │ │ ├── syscall │ │ │ │ └── syscall.h │ │ │ ├── driver │ │ │ │ ├── intr.h │ │ │ │ ├── clock.h │ │ │ │ ├── picirq.h │ │ │ │ ├── intr.c │ │ │ │ ├── console.h │ │ │ │ └── ide.h │ │ │ ├── schedule │ │ │ │ └── sched.h │ │ │ ├── fs │ │ │ │ ├── fs.h │ │ │ │ └── swapfs.h │ │ │ ├── debug │ │ │ │ └── kdebug.h │ │ │ └── process │ │ │ │ └── entry.S │ │ └── libs │ │ │ ├── stdlib.h │ │ │ ├── stdarg.h │ │ │ └── hash.c │ └── fork-related │ │ └── fork-ex1-with-some-error.c ├── lab1 │ ├── lab1-ex1.c │ ├── lab1-ex2.md │ ├── toybootloader │ │ ├── toy.md │ │ └── Makefile │ ├── pmbootloader │ │ ├── pmboot.md │ │ └── Makefile │ ├── lab1-ex0.s │ ├── lab1-ex3.md │ ├── lab1-ex1.md │ ├── lab1-ex0.md │ ├── defines.h │ ├── lab1-ex3.c │ └── Makefile ├── lab7 │ ├── race-condition │ │ ├── loop.s │ │ ├── test.s │ │ ├── simple-race.s │ │ ├── wait-for-me.s │ │ └── looping-race-nolock.s │ ├── semaphore_condition │ │ ├── thr-ex4.py │ │ └── thr-ex2.py │ └── software-hardware-locks │ │ ├── test-and-set.s │ │ └── flag.s ├── ostep │ ├── ostep11-threadintro │ │ ├── loop.s │ │ ├── simple-race.s │ │ ├── wait-for-me.s │ │ └── looping-race-nolock.s │ └── ostep12-threadlock │ │ ├── test-and-set.s │ │ ├── flag.s │ │ └── ticket.s ├── lab0 │ ├── lab0_ex2.c │ ├── lab0_ex2.md │ ├── lab0_ex1.md │ ├── lab0_ex5.c │ ├── lab0_ex4.md │ ├── lab0_ex1.c │ ├── lab0_ex6.md │ └── lab0_ex6.c ├── lab3 │ └── locality │ │ ├── locality.md │ │ ├── Makefile │ │ ├── badlocality.c │ │ └── goodlocality.c ├── labX │ ├── lab8_X.md │ ├── lab7_X.md │ ├── lab6_X.md │ └── lab2_X.md └── lab2 │ └── kr_malloc_free_2 │ ├── memory.h │ └── Makefile ├── .gitignore └── .travis.yml /labcodes/lab1/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab2/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab3/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab4/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab5/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab6/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab7/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes/lab8/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/.projectile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /labcodes_answer/README.txt: -------------------------------------------------------------------------------- 1 | ## 注意 2 | 这个目录下的内容并不是标准参考答案,也存在这样那样的bug,请酌情使用。 3 | -------------------------------------------------------------------------------- /labcodes/autobuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Nothing to be done here 4 | exit 0 5 | -------------------------------------------------------------------------------- /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((c-mode . ((indent-tabs-mode . nil) 2 | (c-basic-offset . 4)))) 3 | -------------------------------------------------------------------------------- /labcodes/lab2/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab3/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab4/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab5/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab6/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab7/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab8/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes/lab1/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | continue -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/tools/moninit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab2_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab3_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab4_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab5_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab6_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab7_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /labcodes_answer/lab8_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-spoc-discuss/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /related_info/lab4/some-exercises/build.sh: -------------------------------------------------------------------------------- 1 | as -arch i386 -o prog.o prog.s 2 | ld -arch i386 -o prog prog.o 3 | -------------------------------------------------------------------------------- /related_info/lab5/lab5-spoc-discuss/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file bin/kernel 2 | target remote :1234 3 | break kern_init 4 | -------------------------------------------------------------------------------- /related_info/lab1/lab1-ex1.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main(void) 3 | { 4 | printf("hello world\n"); 5 | } 6 | -------------------------------------------------------------------------------- /related_info/lab4/some-exercises/call.c: -------------------------------------------------------------------------------- 1 | int addtwo(int a) 2 | { 3 | int x = 2; 4 | return a + x; 5 | } 6 | -------------------------------------------------------------------------------- /labcodes_answer/lab1_result/tools/gdbinit: -------------------------------------------------------------------------------- 1 | file obj/bootblock.o 2 | target remote :1234 3 | break bootmain 4 | continue 5 | -------------------------------------------------------------------------------- /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/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/lab0/lab0_ex2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int 3 | main(void) 4 | { 5 | printf("Hello, world!\n"); 6 | return 0; 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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /related_info/lab3/locality/locality.md: -------------------------------------------------------------------------------- 1 | #在linux下分析程序的局部性 2 | 可通过如下命令在时间上看出在执行时间上的差异 3 | ``` 4 | make 5 | time ./goodlocality 6 | time ./badlocality 7 | ``` 8 | -------------------------------------------------------------------------------- /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/lab4/some-exercises/prog.s: -------------------------------------------------------------------------------- 1 | .section __TEXT,__text 2 | .globl start 3 | start: 4 | mov $0x1, %eax 5 | push $0x0 6 | call _syscall 7 | _syscall: 8 | int $0x80 9 | -------------------------------------------------------------------------------- /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/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/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_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 | -------------------------------------------------------------------------------- /related_info/lab4/some-exercises/build-2.sh: -------------------------------------------------------------------------------- 1 | as -gstabs --32 -o callee.o callee.s 2 | gcc -m32 -g -c -fno-stack-protector caller.c 3 | gcc -m32 -g -o caller caller.o callee.o 4 | -------------------------------------------------------------------------------- /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/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/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/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_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/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/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 | -------------------------------------------------------------------------------- /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/lab4/some-exercises/call2.c: -------------------------------------------------------------------------------- 1 | void func2(int a, int b) 2 | { 3 | a++; 4 | b+=2; 5 | } 6 | 7 | int main() 8 | { 9 | func2( 1111, 2222); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /related_info/lab4/some-exercises/caller.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char* mystr = "Welcome to baby OS!\n"; 5 | mywrite(1, mystr, strlen(mystr)); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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_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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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_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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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_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/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/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/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 | -------------------------------------------------------------------------------- /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-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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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_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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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_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/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/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/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 | -------------------------------------------------------------------------------- /labcodes/cleanall.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | cd lab1; make clean; cd .. 3 | cd lab2; make clean; cd .. 4 | cd lab3; make clean; cd .. 5 | cd lab4; make clean; cd .. 6 | cd lab5; make clean; cd .. 7 | cd lab6; make clean; cd .. 8 | cd lab7; make clean; cd .. 9 | cd lab8; make clean; cd .. 10 | -------------------------------------------------------------------------------- /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_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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/labX/lab8_X.md: -------------------------------------------------------------------------------- 1 | challenge1 参考unix的pipe/fifo机制,实现基于VFS接口的pipe/fifo机制 2 | =================================================== 3 | 状态:未完成 4 | 完成人: 5 | 6 | 7 | challenge 支持现有文件系统之外的其他文件系统的读写 8 | =================================================== 9 | 状态:未完成 10 | 完成人: 11 | -------------------------------------------------------------------------------- /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/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/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/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_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/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/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/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/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/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/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_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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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.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.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.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.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.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.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.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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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_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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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_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/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.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.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.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.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.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.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.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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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_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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /labcodes/gccbuildall.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | cd lab1; make clean; make; cd .. 3 | cd lab2; make clean; make; cd .. 4 | cd lab3; make clean; make; cd .. 5 | cd lab4; make clean; make; cd .. 6 | cd lab5; make clean; make; cd .. 7 | cd lab6; make clean; make; cd .. 8 | cd lab7; make clean; make; cd .. 9 | cd lab8; make clean; make; cd .. 10 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /labcodes_answer/cleanall.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | cd lab1_result; make clean; cd .. 3 | cd lab2_result; make clean; cd .. 4 | cd lab3_result; make clean; cd .. 5 | cd lab4_result; make clean; cd .. 6 | cd lab5_result; make clean; cd .. 7 | cd lab6_result; make clean; cd .. 8 | cd lab7_result; make clean; cd .. 9 | cd lab8_result; make clean; cd .. 10 | -------------------------------------------------------------------------------- /related_info/lab4/lab4-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/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/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/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/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 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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: c 4 | 5 | os: 6 | - linux 7 | - osx 8 | 9 | addons: 10 | apt: 11 | packages: 12 | - qemu 13 | homebrew: 14 | packages: 15 | - qemu 16 | - i386-elf-gcc 17 | update: true 18 | 19 | script: 20 | - cd labcodes && bash ./gccbuildall.sh && cd .. 21 | - cd labcodes_answer && bash ./gccbuildall.sh && cd .. -------------------------------------------------------------------------------- /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/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/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/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_answer/gccbuildall.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | cd lab1_result; make clean; make; cd .. 3 | cd lab2_result; make clean; make; cd .. 4 | cd lab3_result; make clean; make; cd .. 5 | cd lab4_result; make clean; make; cd .. 6 | cd lab5_result; make clean; make; cd .. 7 | cd lab6_result; make clean; make; cd .. 8 | cd lab7_result; make clean; make; cd .. 9 | cd lab8_result; make clean; make; cd .. 10 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /related_info/lab5/fork-related/fork-ex1-with-some-error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | pid_t child = fork(); 6 | if (child) { // in parent 7 | sleep(5); 8 | kill(child, SIGKILL); 9 | } else { // in child 10 | for (;;); // loop until killed 11 | } 12 | 13 | return 0; 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/lab4/some-exercises/callee.s: -------------------------------------------------------------------------------- 1 | .code32 2 | SYSWRITE = 4 # sys_write()系统调用号 3 | .global mywrite 4 | .text 5 | mywrite: 6 | pushl %ebp 7 | movl %esp, %ebp 8 | pushl %ebx 9 | movl 8(%ebp),%ebx # ebx :文件描述符 10 | movl 12(%ebp),%ecx # ecx :缓冲区指针 11 | movl 16(%ebp),%edx # edx :显示字符数 12 | movl $SYSWRITE,%eax # eax :系统调用号 13 | int $0x80 14 | popl %ebx 15 | mov %ebp, %esp 16 | popl %ebp 17 | ret 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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_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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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_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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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_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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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_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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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_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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------