-
Notifications
You must be signed in to change notification settings - Fork 22
[feat] add docs for runtime module #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
h-yj22
wants to merge
2
commits into
Azure-stars:main
Choose a base branch
from
h-yj22:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,131 @@ | ||
| # 运行时模块 | ||
|
|
||
| 运行时模块为使用 ArceOS 的裸机应用提供了必要的运行时支持。运行时模块会在调用裸机程序的 `main`函数之前进行一些初始化工作,例如初始化内存分配器、初始化文件系统等。运行时模块还在 rust 的语言层面提供了 `no_std`支持,如设置 panic handler 等。使用 ArceOS 的裸机应用必须链接此库。 | ||
|
|
||
| ## 包功能特性 | ||
|
|
||
| 运行时模块提供了以下可选的功能特性: | ||
|
|
||
| - `alloc`:提供动态内存分配支持 | ||
| - `paging`:提供虚拟内存操作支持 | ||
| - `irq`:提供中断处理支持 | ||
| - `multitask`:提供多任务(多线程)支持 | ||
| - `smp`:提供多核支持,即 SMP (symmetric multiprocessing) | ||
| - `fs`:提供文件系统支持 | ||
| - `net`:提供网络支持 | ||
| - `display`:提供图形显示支持 | ||
|
|
||
| 上述特性均为可选特性,且默认情况下均不启用。 | ||
|
|
||
| ## 导出函数 | ||
|
|
||
| 运行时模块提供了以下导出函数: | ||
|
|
||
| - `rust_main`: ArceOS 运行时的入口点 | ||
| - `rust_main_secondary`: 多核情况下的次要入口点,即其他核上 ArceOS 运行时的入口点 | ||
|
|
||
| ### `rust_main` | ||
|
|
||
| `rust_main`函数是 ArceOS 运行时的入口点,其原型如下: | ||
|
|
||
| ```rust | ||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> !; | ||
| ``` | ||
|
|
||
| 这个函数会被 `axhal`(硬件抽象层)模块的引导代码调用,`cpu_id`是当前 CPU 的 ID,`dtb`(device tree blob)是设备树的地址。`rust_main`函数会在初始化运行时环境完成后,调用裸机应用的 `main`函数。 | ||
|
|
||
| ### `rust_main_secondary` | ||
|
|
||
| `rust_main_secondary`函数是多核情况下的次要入口点,在多核情况下,`axhal`会在主核上调用 `rust_main`,在其他核上调用 `rust_main_secondary`。其原型如下: | ||
|
|
||
| ```rust | ||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn rust_main_secondary(cpu_id: usize) -> !; | ||
| ``` | ||
|
|
||
| ## 主要功能 | ||
|
|
||
| 在 `rust_main`函数中,运行时模块会根据启用的 feature 进行初始化工作,feature与功能的对应关系如下: | ||
|
|
||
| - 不需要feature:初始化平台设备、初始化驱动模块 | ||
|
|
||
| ```rust | ||
| info!("Initialize platform devices..."); | ||
| axhal::platform_init(); | ||
| ``` | ||
| ```rust | ||
| let all_devices = axdriver::init_drivers(); | ||
| ``` | ||
| - alloc:初始化内存分配器、虚拟内存管理模块 | ||
|
|
||
| ```rust | ||
| #[cfg(feature = "alloc")] | ||
| init_allocator(); | ||
| ``` | ||
| - paging:启用页表操作支持。 | ||
|
|
||
| ```rust | ||
| #[cfg(feature = "paging")] | ||
| axmm::init_memory_management(); | ||
| ``` | ||
| - multitask:初始化多任务的调度器 | ||
|
|
||
| ```rust | ||
| #[cfg(feature = "multitask")] | ||
| axtask::init_scheduler(); | ||
| ``` | ||
| - fs:初始化文件系统 | ||
| - net:初始化网络模块 | ||
| - display:初始化图形显示模块 | ||
|
|
||
| ```rust | ||
| #[cfg(any(feature = "fs", feature = "net", feature = "display"))] | ||
| { | ||
| #[allow(unused_variables)] | ||
| let all_devices = axdriver::init_drivers(); | ||
|
|
||
| #[cfg(feature = "fs")] | ||
| axfs::init_filesystems(all_devices.block); | ||
|
|
||
| #[cfg(feature = "net")] | ||
| axnet::init_network(all_devices.net); | ||
|
|
||
| #[cfg(feature = "display")] | ||
| axdisplay::init_display(all_devices.display); | ||
| } | ||
| ``` | ||
| - smp:启用对称多处理(SMP)支持,启动其他 CPU 核 | ||
|
|
||
| ```rust | ||
| #[cfg(feature = "smp")] | ||
| self::mp::start_secondary_cpus(cpu_id); | ||
| ``` | ||
| - irq:初始化中断处理模块,包括设置时钟中断处理函数 | ||
|
|
||
| ```rust | ||
| #[cfg(feature = "irq")] | ||
| { | ||
| info!("Initialize interrupt handlers..."); | ||
| init_interrupt(); | ||
| } | ||
|
|
||
| ``` | ||
| - tls:初始化线程本地存储(TLS),但同时需要未启用 multitask | ||
|
|
||
| ```rust | ||
| #[cfg(all(feature = "tls", not(feature = "multitask")))] | ||
| { | ||
| info!("Initialize thread local storage..."); | ||
| init_tls(); | ||
| } | ||
| ``` | ||
| - rtc:启用实时时钟(Real-Time Clock),打印启动时间 | ||
|
|
||
| ``` | ||
| #[cfg(feature = "rtc")] | ||
| ax_println!( | ||
| "Boot at {}\n", | ||
| chrono::DateTime::from_timestamp_nanos(axhal::time::wall_time_nanos() as _), | ||
| ); | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否可以添加一下在所有feature启动后的 rust_main 和 rust_main_secondary 的启动流程分析?