forked from woai3c/MIT6.828
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Lab1 总结 | ||
在本章中学习了《x86汇编语言:从实模式到保护模式》以及一些汇编语言的知识。 | ||
|
||
## 物理地址布局 | ||
``` | ||
+------------------+ <- 0xFFFFFFFF (4GB) | ||
| 32-bit | | ||
| memory mapped | | ||
| devices | | ||
| | | ||
/\/\/\/\/\/\/\/\/\/\ | ||
/\/\/\/\/\/\/\/\/\/\ | ||
| | | ||
| Unused | | ||
| | | ||
+------------------+ <- depends on amount of RAM | ||
| | | ||
| | | ||
| Extended Memory | | ||
| | | ||
| | | ||
+------------------+ <- 0x00100000 (1MB) | ||
| BIOS ROM | | ||
+------------------+ <- 0x000F0000 (960KB) | ||
| 16-bit devices, | | ||
| expansion ROMs | | ||
+------------------+ <- 0x000C0000 (768KB) | ||
| VGA Display | | ||
+------------------+ <- 0x000A0000 (640KB) | ||
| | | ||
| Low Memory | | ||
| | | ||
+------------------+ <- 0x00000000 | ||
``` | ||
## 计算机启动过程 | ||
1. CPU 加电后首先会读取 BIOS 的指令,对计算机进行自检。 | ||
2. 自检完成后加载第一个扇区的内容到物理内存 0x7c00 处,然后跳转到 0x7c00,开始执行指令,将计算机的控制权从 BIOS 转交给加载程序。 | ||
3. 加载程序开启A20,也就是处理器的第21根地址线,并加载 GDT,然后 CPU 从实模式转为保护模式。 | ||
4. 从磁盘上读取内核,并加载到内存,跳转到内核开始执行指令。 | ||
5. 开启分页,跳转到 i386_init 开始初始化内核。 | ||
|
||
## 小知识点 | ||
* 磁盘每 512 个字节的区域,称为扇区。扇区是磁盘的最小传输粒度:每个读或写操作必须是一个或多个扇区,并且必须在扇区边界上对齐。 | ||
* 如果磁盘是可引导的,则第一个扇区称为引导扇区,因为这是引导加载程序代码所在的位置。 | ||
* 调用函数前先将参数入栈,再将返回地址入栈,跳转到函数后将 ebp(指向栈底) 入栈,esp 的值赋给 ebp。 | ||
* 函数返回的时候通过先操作 esp 释放栈资源,然后恢复相应的被调用者保存的寄存器的值,最后调用汇编指令 leave、ret 返回;leave 指令先将 ebp 的值赋值给 esp,然后再从栈中取出被保存的ebp的旧值;ret 从栈中取出返回地址并跳转。 |