lab1 练习1:理解通过make生成执行文件的过程

练习1:理解通过make生成执行文件的过程。(要求在报告中写出对下述问题的回答)

列出本实验各练习中对应的OS原理的知识点,并说明本实验中的实现部分如何对应和体现了原理中的基本概念和关键知识点。

在此练习中,大家需要通过静态分析代码来了解:

  1. 操作系统镜像文件ucore.img是如何一步一步生成的?(需要比较详细地解释Makefile中每一条相关命令和命令参数的含义,以及说明命令导致的结果)
  2. 一个被系统认为是符合规范的硬盘主引导扇区的特征是什么?

补充材料:

如何调试Makefile

当执行make时,一般只会显示输出,不会显示make到底执行了哪些命令。

如想了解make执行了哪些命令,可以执行:

$ make "V="

要获取更多有关make的信息,可上网查询,并请执行

$ man make

实验报告 练习1:

1.操作系统镜像文件ucore.img是如何一步一步生成的?(需要比较详细地解释Makefile中每一条相关命令和命令参数的含义,以及说明命令导致的结果)

在lab1目录下输入 make v=查看编译顺序,得到结果:

+ cc kern/init/init.c
kern/init/init.c:95:1: warning: ‘lab1_switch_test’ defined but not used [-Wunused-function]
 lab1_switch_test(void) {
 ^
+ cc kern/libs/readline.c
+ cc kern/libs/stdio.c
+ cc kern/debug/kdebug.c
kern/debug/kdebug.c:251:1: warning: ‘read_eip’ defined but not used [-Wunused-function]
 read_eip(void) {
 ^
+ cc kern/debug/kmonitor.c
+ cc kern/debug/panic.c
+ cc kern/driver/clock.c
+ cc kern/driver/console.c
+ cc kern/driver/intr.c
+ cc kern/driver/picirq.c
+ cc kern/trap/trap.c
kern/trap/trap.c:14:13: warning: ‘print_ticks’ defined but not used [-Wunused-function]
 static void print_ticks() {
             ^
kern/trap/trap.c:30:26: warning: ‘idt_pd’ defined but not used [-Wunused-variable]
 static struct pseudodesc idt_pd = {
                          ^
+ cc kern/trap/trapentry.S
+ cc kern/trap/vectors.S
+ cc kern/mm/pmm.c
+ cc libs/printfmt.c
+ cc libs/string.c
+ ld bin/kernel
+ cc boot/bootasm.S
+ cc boot/bootmain.c
+ cc tools/sign.c
+ ld bin/bootblock
'obj/bootblock.out' size: 472 bytes
build 512 bytes boot sector: 'bin/bootblock' success!
10000+0 records in
10000+0 records out
5120000 bytes (5.1 MB) copied, 0.0363158 s, 141 MB/s
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.0013384 s, 383 kB/s
138+1 records in
138+1 records out
70775 bytes (71 kB) copied, 0.000284194 s, 249 MB/s

可以得到生成img编译文件顺序:

  1. 编译 kern/init/init.c
  2. compile readlin.c
  3. compile stdio.c
  4. compile kdebug.c
  5. compile kern/debug/knonitor.c
  6. compile kern/debug/panic.c
  7. compile kern/driver/clock.c
  8. compile kern/driver/console.c
  9. compile kern/driver/intr.c
  10. compile kern/driver/picirq.c
  11. cpmpile kern/trap/trap.cile kern/trap/trapentry.S
  12. compile lebs/string.c
  13. link bin/kernel
  14. compile boot/bootasm.S
  15. compiile boot/bootmain.c
  16. compile tools/sign.c
  17. link bin/bootblock: bootblock.out size is 472 b,but build 512b boot sector, use dd to create 5.1MB ucore.img,then write bootblock to ucore.img first 512byte(addr 0-511),finally write kernel to ucore.img begin at address 512

2.一个被系统认为是符合规范的硬盘主引导扇区的特征是什么?

在tools/sign.c里可以看到, 引导扇区512字节最后两字节必须是ox55aa

buf[510] = 0x55;
buf[511] = 0xAA;
FILE *ofp = fopen(argv[2], "wb+");
size = fwrite(buf, 1, 512, ofp);
if (size != 512) {
    fprintf(stderr, "write '%s' error, size is %d.\n", argv[2], size);
    return -1;
}
fclose(ofp);
printf("build 512 bytes boot sector: '%s' success!\n", argv[2]);
return 0;

}
posted @ 2020-12-31 15:25  lsxkugou  阅读(338)  评论(0编辑  收藏  举报