Browse Source

实验3环境初始化

Makefile里的gdb和之前不一样了!要添加$(QEMUOPTS),不然会导致没有挂载交换分区。
main
423A35C7 7 months ago
parent
commit
15bddd15d5
5 changed files with 27 additions and 6 deletions
  1. +1
    -1
      .vscode/c_cpp_properties.json
  2. +1
    -1
      .vscode/launch.json
  3. +1
    -1
      .vscode/tasks.json
  4. +4
    -2
      labcodes_answer/lab3_result/Makefile
  5. +20
    -1
      labcodes_answer/lab3_result/kern/mm/vmm.c

+ 1
- 1
.vscode/c_cpp_properties.json View File

@ -6,7 +6,7 @@
"${workspaceFolder}/**", "${workspaceFolder}/**",
// "${workspaceFolder}/labcodes_answer/**/", // "${workspaceFolder}/labcodes_answer/**/",
// lab1_resultlab2_result // lab1_resultlab2_result
"${workspaceFolder}/labcodes_answer/lab2_result/kern/mm/"
"${workspaceFolder}/labcodes_answer/lab3_result/**/"
], ],
"defines": [], "defines": [],
"compilerPath": "/usr/bin/gcc", "compilerPath": "/usr/bin/gcc",

+ 1
- 1
.vscode/launch.json View File

@ -11,7 +11,7 @@
"program": "bin/kernel", "program": "bin/kernel",
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}/labcodes_answer/lab2_result",
"cwd": "${workspaceFolder}/labcodes_answer/lab3_result",
"environment": [], "environment": [],
"externalConsole": false, "externalConsole": false,
"MIMode": "gdb", "MIMode": "gdb",

+ 1
- 1
.vscode/tasks.json View File

@ -9,7 +9,7 @@
"env": { "env": {
"DISPLAY": ":0", "DISPLAY": ":0",
}, },
"cwd": "${workspaceFolder}/labcodes_answer/lab2_result"
"cwd": "${workspaceFolder}/labcodes_answer/lab3_result"
}, },
"problemMatcher": [ "problemMatcher": [

+ 4
- 2
labcodes_answer/lab3_result/Makefile View File

@ -210,7 +210,8 @@ endif
# files for grade script # files for grade script
TARGETS: $(TARGETS) TARGETS: $(TARGETS)
targets: $(TARGETS)
all: $(TARGETS)
.DEFAULT_GOAL := TARGETS .DEFAULT_GOAL := TARGETS
QEMUOPTS = -hda $(UCOREIMG) -drive file=$(SWAPIMG),media=disk,cache=writeback 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 $(V)$(QEMU) -serial mon:stdio $(QEMUOPTS) -nographic
TERMINAL := gnome-terminal TERMINAL := gnome-terminal
gdb: $(UCOREIMG) $(SWAPIMG)
$(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null
debug: $(UCOREIMG) $(SWAPIMG) debug: $(UCOREIMG) $(SWAPIMG)
$(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null & $(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null &
$(V)sleep 2 $(V)sleep 2

+ 20
- 1
labcodes_answer/lab3_result/kern/mm/vmm.c View File

@ -260,13 +260,32 @@ check_pgfault(void) {
*(char *)(addr + i) = i; *(char *)(addr + i) = i;
sum += 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 ++) { for (i = 0; i < 100; i ++) {
sum -= *(char *)(addr + i); sum -= *(char *)(addr + i);
} }
assert(sum == 0); assert(sum == 0);
page_remove(pgdir, ROUNDDOWN(addr, PGSIZE)); page_remove(pgdir, ROUNDDOWN(addr, PGSIZE));
free_page(pde2page(pgdir[0]));
free_page(pa2page(pgdir[0]));
pgdir[0] = 0; pgdir[0] = 0;
mm->pgdir = NULL; mm->pgdir = NULL;

Loading…
Cancel
Save