任务2

1
2
cd pintos/src/threads
cd build
1
pintos --bochs --gdb -- run loader.S

换一个命令行

1
2
3
4
cd pintos/src/threads
cd build
pintos-gdb kernel.o
target remote localhost:1234
1
break *0x7c00

开始执行代码,直到断点处停止:

1
c

一旦程序停在断点处,你可以使用 x/i 命令来反汇编当前指令:

1
x/i $pc

连续查看3条

1
x/3i 0xffff0 + 1

练习4

1
2
cd pintos/src/threads
cd build
1
pintos --bochs --gdb -- run start.S

换一个命令行

1
2
3
4
5
6
7
8
9
10
pintos-gdb kernel.o
target remote localhost:1234

//打断点
break pintos_init
//运行
c
//查看init_page_dir[pd_no(ptov(0))]的值:

print/x init_page_dir[pd_no(ptov(0))]
1
2
3
4
break palloc_get_page
c
backtrace
print/x init_page_dir[pd_no(ptov(0))]

练习5

修改init.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if (*argv != NULL) run_actions(argv);
else{
// TODO: no command line passed to kernel. Run interactively;
console_init();
while (true){
char buffer[1024];
int index = 0;
printf("OS2021> ");
while (true){
char c = input_getc();
if (c == '\r' || c == '\n'){
buffer[index] = '\0';
if (strcmp(buffer, "msk") == 0)
printf("\nYour Name: [msk]\nYour ID: [202110120428]\n");
else if (strcmp(buffer, "exit") == 0)
shutdown_power_off();
else
printf("\nInvalid command\n");
memset(buffer, 0, sizeof(buffer));
index = 0;
break;
}
else if (c > ' ' && c < '~'){
printf("%c",c);
buffer[index++] = c;
}
}
}
}

每次修改完都要 make all 进行编译,形成 .o 文件

1
2
3
4
cd pintos/src/threads
cd build
make all
pintos --