From 15bddd15d5903cfead402c7370c29e2e3b17b3cd Mon Sep 17 00:00:00 2001 From: 423A35C7 <609514299@qq.com> Date: Sun, 28 Apr 2024 22:00:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E9=AA=8C3=E7=8E=AF=E5=A2=83=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makefile里的gdb和之前不一样了!要添加$(QEMUOPTS),不然会导致没有挂载交换分区。 --- .vscode/c_cpp_properties.json | 2 +- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- labcodes_answer/lab3_result/Makefile | 6 ++++-- labcodes_answer/lab3_result/kern/mm/vmm.c | 21 ++++++++++++++++++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index d9c7c87..979a682 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,7 +6,7 @@ "${workspaceFolder}/**", // "${workspaceFolder}/labcodes_answer/**/", // 由于按顺序搜索,所以如果这样的话搜索到lab1_result中的同名头文件就不会引用到lab2_result中的同名头文件导致错误 - "${workspaceFolder}/labcodes_answer/lab2_result/kern/mm/" + "${workspaceFolder}/labcodes_answer/lab3_result/**/" ], "defines": [], "compilerPath": "/usr/bin/gcc", diff --git a/.vscode/launch.json b/.vscode/launch.json index 927fca1..4382c07 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "program": "bin/kernel", "args": [], "stopAtEntry": false, - "cwd": "${workspaceFolder}/labcodes_answer/lab2_result", + "cwd": "${workspaceFolder}/labcodes_answer/lab3_result", "environment": [], "externalConsole": false, "MIMode": "gdb", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ffc8a37..c12ab8c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -9,7 +9,7 @@ "env": { "DISPLAY": ":0", }, - "cwd": "${workspaceFolder}/labcodes_answer/lab2_result" + "cwd": "${workspaceFolder}/labcodes_answer/lab3_result" }, "problemMatcher": [ diff --git a/labcodes_answer/lab3_result/Makefile b/labcodes_answer/lab3_result/Makefile index 8184802..e824a0f 100644 --- a/labcodes_answer/lab3_result/Makefile +++ b/labcodes_answer/lab3_result/Makefile @@ -210,7 +210,8 @@ endif # files for grade script TARGETS: $(TARGETS) - +targets: $(TARGETS) +all: $(TARGETS) .DEFAULT_GOAL := TARGETS QEMUOPTS = -hda $(UCOREIMG) -drive file=$(SWAPIMG),media=disk,cache=writeback @@ -225,7 +226,8 @@ qemu-nox: $(UCOREIMG) $(SWAPIMG) $(V)$(QEMU) -serial mon:stdio $(QEMUOPTS) -nographic TERMINAL := gnome-terminal - +gdb: $(UCOREIMG) $(SWAPIMG) + $(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null debug: $(UCOREIMG) $(SWAPIMG) $(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null & $(V)sleep 2 diff --git a/labcodes_answer/lab3_result/kern/mm/vmm.c b/labcodes_answer/lab3_result/kern/mm/vmm.c index 89bdfb8..26d4870 100644 --- a/labcodes_answer/lab3_result/kern/mm/vmm.c +++ b/labcodes_answer/lab3_result/kern/mm/vmm.c @@ -260,13 +260,32 @@ check_pgfault(void) { *(char *)(addr + i) = i; sum += i; } + + for (i = 0; i < 100; i ++) { + // 获取页目录项和页表项 + pte_t *pte = get_pte(pgdir, addr + i, 0); + if (pte != NULL && (*pte & PTE_P)) { + // 检查访问位 + if (*pte & PTE_A) { + // A 位已置位 + cprintf("Access bit is set.\n"); + } else { + // A 位未置位 + cprintf("Access bit is not set.\n"); + } + } else { + // 页表项不存在或未呈现 + cprintf("PTE not present.\n"); + } + } + for (i = 0; i < 100; i ++) { sum -= *(char *)(addr + i); } assert(sum == 0); page_remove(pgdir, ROUNDDOWN(addr, PGSIZE)); - free_page(pde2page(pgdir[0])); + free_page(pa2page(pgdir[0])); pgdir[0] = 0; mm->pgdir = NULL;