DragonOS/docs/kernel/boot/multiboot2.md
2022-07-12 17:57:11 +08:00

47 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Multiboot2支持模块
  Multiboot2支持模块提供对Multiboot2协议的支持。位于`kernel/driver/multiboot2`文件夹中。
  根据Multiboot2协议操作系统能够从BootLoader处获得一些信息比如基本的硬件信息以及ACPI表的起始地址等。
---
## 数据结构
  `kernel/driver/multiboot2/multiboot2.h`中按照Multiboot2协议的规定定义了大部分的数据结构具体细节可查看该文件: [DragonOS/multiboot2.h at master · fslongjin/DragonOS · GitHub](https://github.com/fslongjin/DragonOS/blob/master/kernel/driver/multiboot2/multiboot2.h)
---
## 迭代器
  由于Multiboot2的信息存储在自`multiboot2_boot_info_addr`开始的一段连续的内存空间之中且不同类型的header的长度不同因此设计了一迭代器`multiboot2_iter`
### 函数原型
```c
void multiboot2_iter(bool (*_fun)(const struct iter_data_t *, void *, unsigned int *),
void *data, unsigned int *count)
```
**_fun**
  指定的handler。当某个header的tag与该handler所处理的tag相同时handler将处理该header并返回true。
  其第一个参数为tag类型第二个参数为返回的数据的指针第三个值为计数某些没有用到该值的地方该值可以为空
**data**
  传递给`_fun`的第二个参数,`_fun`函数将填充该指针所指向的内存区域,从而返回数据。
**count**
  当返回的**data**为一个列表时,通过该值来指示列表中有多少项。
---
## 迭代工作函数
  在模块中按照我们需要获取不同类型的tag的需要定义了一些迭代器工作函数。