Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BitInit committed Aug 6, 2023
1 parent a6c8a2b commit 41f1268
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRC := arch/x86/boot kernel mm drivers
all: clean iso

iso: build
ld -b elf64-x86-64 -z muldefs -o kernel.elf -T link.lds $(shell find $(SRC) -name "*.o")
ld -b elf64-x86-64 -z muldefs -o kernel.elf -Map=./kernel.map -T link.lds $(shell find $(SRC) -name "*.o")
@bash build_iso.sh

build: $(SRC)
Expand All @@ -17,4 +17,7 @@ clean: $(SRC)
@for s in $(SRC); do \
make -C $$s clean || exit 1; \
done
rm -rf *.elf *.iso
rm -rf *.elf *.iso *.map

qemu-run:
qemu-system-x86_64 -m 2G HelloOS.iso
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
1. 安装依赖

```bash
$ apt install -y make gcc grub git
$ apt install -y make gcc grub git xorriso
```

2. 代码拉取
Expand Down
Binary file added docs/resources/Linux设备驱动程序.pdf
Binary file not shown.
Binary file added docs/resources/interceptor_descriptor.webp
Binary file not shown.
Binary file added docs/resources/memory_addr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/resources/seg_gdtr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/resources/segment_descriptor.webp
Binary file not shown.
Binary file added docs/resources/segment_selector.webp
Binary file not shown.
37 changes: 37 additions & 0 deletions docs/分段分页.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## 内存地址
![](./resources/memory_addr.png)

* 逻辑地址:程序代码指令中的地址,可以认为是虚拟地址;
* 线性地址:逻辑地址经过分段计算后得到。在现代 x86-64 位操作系统中,线性地址和逻辑地址是一样的;
* 物理地址:线性地址经过 MMU 后,得到物理上真正地址;



## 分段

段描述符:用于描述一个段的信息。在长模式下,其格式是:

<img src="./resources/segment_descriptor.webp" style="zoom:13%;" />

在操作系统中,多个段描述符组成一个描述符表。通过 gdtr(全局描述符寄存器)指向表的基地址。

> 还有一个 ldtr(局部描述符寄存器),现代操作系统都是通过分页来管理内存,分段处理只是为了兼容,ldtr 用的比较少,所以也不讨论 ldtr。
段选择子:通过段选择子可以确定该使用哪个段描述符:

<img src="./resources/segment_selector.webp" style="zoom:23%;" />

通过分段来计算线性地址流程:

![](./resources/seg_gdtr.png)

同理,在长模式下中断门描述符格式:

<img src="./resources/interceptor_descriptor.webp" style="zoom:13%;" />







2 changes: 1 addition & 1 deletion mm/mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void page_bitmap_init(uint_t start_addr) {

gmdsc.total_mem_length = total_mem;
gmdsc.page_bits = (uint_t*)start_addr;
gmdsc.page_bits_size = total_mem >> PAGE_4K_SHIFT;
gmdsc.page_bits_size = total_mem >> PAGE_4K_SHIFT;
gmdsc.page_bits_length = (((uint_t)(total_mem >> PAGE_4K_SHIFT) + sizeof(uint_t) * 8 - 1) / 8) & ( ~ (sizeof(uint_t) - 1));
kinfo("page_bitmap start_addr:%x page_bits_size:%d page_bits_length:%d\n", gmdsc.page_bits, gmdsc.page_bits_size, gmdsc.page_bits_length);
memset(gmdsc.page_bits, 0xff, gmdsc.page_bits_length);
Expand Down

0 comments on commit 41f1268

Please sign in to comment.