ucore lab1 实验讲解

练习1:1.1操作系统镜像文件ucore.img是如何一步一步生成的?

(需要比较详细地解释Makefile中每一条相关命令和命令参数的含义,以及说明命令导致的结果)

moocos-> cd Desktop/
[~/Desktop]
moocos-> ls
friendcode-gitbook.desktop
lab1
ucore_os_lab
vmware-tools-distrib
[~/Desktop]
moocos-> cd lab1/
[~/Desktop/lab1]
moocos-> make qemu
+ 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
kern/debug/panic.c: In function ‘__panic’:
kern/debug/panic.c:27:5: warning: implicit declaration of function ‘print_stackframe’ [-Wimplicit-function-declaration]
     print_stackframe();
     ^
+ 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.0273808 s, 187 MB/s
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000310096 s, 1.7 MB/s
146+1 records in
146+1 records out
74871 bytes (75 kB) copied, 0.000395147 s, 189 MB/s
(THU.CST) os is loading ...

Special kernel symbols:
  entry  0x00100000 (phys)
  etext  0x0010321c (phys)
  edata  0x0010ea16 (phys)
  end    0x0010fd20 (phys)
Kernel executable memory footprint: 64KB
++ setup timer interrupts
[~/Desktop/lab1]

  • cc kern/init/init.c //编译 init.c

  • cc kern/libs/readline.c //编译 readline.c

  • cc kern/libs/stdio.c //编译 stdio.c

  • cc kern/debug/kdebug.c//编译 kdebug.c

  • cc kern/debug/kmonitor.c //编译 kmonitor

  • cc kern/debug/panic.c//编译 panic.c

  • cc kern/driver/clock.c //编译 clock.c

  • cc kern/driver/console.c //编译 console.c

  • cc kern/driver/intr.c//编译 intr.c

  • cc kern/driver/picirq.c //编译 picirq.c

  • cc kern/trap/trap.c //编译 trap.c

  • cc kern/trap/trapentry.S //编译 trapentry.S

  • cc kern/trap/vectors.S //编译 vector.S

  • cc kern/mm/pmm.c//编译 pmm.c

  • cc libs/printfmt.c // printgmt.c

  • cc libs/string.c //编译 string.c

  • ld bin/kernel//接下来用ld合并目标文件(object) 和 库文件(archive),生成kernel程序

  • cc boot/bootasm.S //编译 bootasm.S

  • cc boot/bootmain.c //编译 bootmain.c

  • cc tools/sign.c //编译 sign.c

  • ld bin/bootblock//接下来连接源文件与目标文件,生成bootblock程序

//最后将bootloader放入虚拟硬盘ucore.img中去。

1、先编译链接生成kernel文件

2、再编译链接生成bootblock文件

3、生成ucore.img

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

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;

主引导扇区大小为512字节,并且最后结尾为 0x55,0xAA

练习2:使用qemu执行并调试lab1中的软件

##1. 从CPU加电后执行的第一条指令开始,单步跟踪BIOS的执行。
(1).首先启动一个终端,使用qemu-S-s-hda /home/moocos/Desktop/lab1/bin/ucore.img -monitor stdio 的方式启动qemu

moocos-> ls
bin  boot  kern  libs  Makefile  obj  tools
[~/Desktop/lab1]
moocos-> qemu -S -s -hda /home/moocos/Desktop/lab1/bin/ucore.img -monitor stdio 
QEMU 2.0.0 monitor - type 'help' for more information
(qemu) x /6i $pc
0xfffffff0:  ljmp   $0xf000,$0xe05b
0xfffffff5:  xor    %dh,0x322f
0xfffffff9:  xor    (%bx),%bp
0xfffffffb:  cmp    %di,(%bx,%di)
0xfffffffd:  add    %bh,%ah
0xffffffff:  add    %al,(%bx,%si)

(2).再启动另一个终端,启动gdb
target remote :1234
Remote debugging using :1234
在gdb终端输入 i r观察寄存器值

moocos-> ls
boot  kern  libs  Makefile  report.md  tools
[~/Desktop/ucore_os_lab/labcodes_answer/lab1_result]
moocos-> gdb
GNU gdb (Ubuntu 7.7-0ubuntu3.1) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
---Type <return> to continue, or q <return> to quit---return
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值