1. PartB: Page Faults, Breakpoints Exceptions, and System Calls
1.1. 处理页错误
1.1.1. Exercise 5.
修改
trap_dispatch()
将 page fault exceptions 分配到 page_fault_handler(). 记住你可以用make run-x
ormake run-x-nox
是启动JOS执行特定的用户程序. For instance, make run-hello-nox runs the hello user program.
直接修改trap_dispatch
函数,用switch case实现
// LAB 3: Your code here.
switch(tf->tf_trapno) {
case T_PGFLT: page_fault_handler(tf);break;
default: break;
}
faultread: OK (4.0s)
(Old jos.out.faultread failure log removed)
faultreadkernel: OK (3.7s)
(Old jos.out.faultreadkernel failure log removed)
faultwrite: OK (3.1s)
(Old jos.out.faultwrite failure log removed)
faultwritekernel: OK (3.3s)
(Old jos.out.faultwritekernel failure log removed)
1.2. The Breakpoint Exception(断点异常)
断点异常,中断向量3(T_BRKPT),通常用于允许调试器通过使用特殊的1字节int 3
软件中断指令临时替换相关的程序指令,在程序代码中插入断点。
在JOS中,我们将稍微滥用此异常,将其转换为用户环境用于调用JOS内核监视器的原始伪系统调用。 如果我们将JOS内核监视器视为原始调试器,这种用法实际上是合适的。 例如,lib/panic.c
中的panic()
的用户模式实现在打印panic消息后执行int 3
。
// Cause a breakpoint exception
while (1)
asm volatile("int3");
1.2.1. Exercise 6
Modify
trap_dispatch()
to make breakpoint exceptions invoke the kernel monitor. You should now be able to get make grade to succeed on the breakpoint test.
同样在trap_dispatch中加入一个breakpiont的case就可以了。
case T_BRKPT:
monitor(tf);
break;