环境搭建:解决不存在riscv64-linux-gnu-gdb的问题
- 窗口1运行:
make qemu-gdb
- 这里会有一个端口号,如
tcp::26000
- 这里会有一个端口号,如
- 窗口2运行:
gdb-multiarch
- 先回车,再执行
target remote localhost:26000
即可
- 先回车,再执行
Using gdb
Looking at the backtrace output, which function called syscall?
What is the value of p->trapframe->a7 and what does that value represent? (Hint: look user/initcode.S, the first user program xv6 starts.)
What was the previous mode that the CPU was in?
- 通过
(gdb) p /x $sstatus
得到sstatus寄存器的值为0x22
,在书riscv-privileged-20211203的64页找到如下描述- The SPP bit indicates the privilege level at which a hart was executing before entering supervisor mode. When a trap is taken, SPP is set to 0 if the trap originated from user mode, or 1 otherwise.
0x22=0b00100010
,可见SPP
及以前的位数空缺,补零,即SPP
为0,所以为User Mode
Write down the assembly instruction the kernel is panicing at. Which register corresponds to the varialable num?
Why does the kernel crash? Hint: look at figure 3-3 in the text; is address 0 mapped in the kernel address space? Is that confirmed by the value in scause above? (See description of scause in RISC-V privileged instructions)
- 0xd=13
- The kernel crashed due to loading an unused memory data at address 0. As we can see from Figure 3.3, address 0 does not map into kernel space. The abnormal code in scause is 0xd(13), corresponding to the “Load page fault”, which confirms the above view.