update ch1:sec2 fix #70 from the help of gdtdpt

This commit is contained in:
Yu Chen
2022-07-17 10:48:39 +08:00
parent a2d28ab648
commit dfe033a6ae

View File

@@ -75,7 +75,18 @@ println! 宏是由标准库 std 提供的,且会使用到一个名为 write
loop {}
}
目前我们遇到错误什么都不做,只在原地 ``loop``
在把 ``panic_handler`` 配置在单独的文件 ``os/src/lang_items.rs``需要在os/src/main.rs文件中添加以下内容才能正常编译整个软件
.. code-block:: rust
// os/src/main.rs
#![no_std]
mod lang_items;
// ... other code
注意panic 处理函数的函数签名需要一个 ``PanicInfo`` 的不可变借用作为输入参数,它在核心库中得以保留,这也是我们第一次与核心库打交道。之后我们会从 ``PanicInfo`` 解析出错位置并打印出来然后杀死应用程序。但目前编译出的简单OS在运行时如果遇到错误什么都不做只在原地 ``loop``
移除 main 函数
-----------------------------
@@ -102,15 +113,16 @@ println! 宏是由标准库 std 提供的,且会使用到一个名为 write
Compiling os v0.1.0 (/home/shinbokuow/workspace/v3/rCore-Tutorial-v3/os)
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
至此,我们终于移除了所有标准库依赖目前的代码如下:
至此,我们终于移除了所有标准库依赖目前的主要代码包括 ``main.rs````lang_items.rs`` ,大致内容如下:
.. code-block:: rust
// os/src/main.rs
#![no_std]
#![no_main]
#![no_std]
mod lang_items;
// ... other code
// os/src/lang_items.rs
use core::panic::PanicInfo;
@@ -130,7 +142,7 @@ println! 宏是由标准库 std 提供的,且会使用到一个名为 write
$ cargo install cargo-binutils
$ rustup component add llvm-tools-preview
我们可以通过一些工具来分析目前的程序:
我们可以通过各种工具来分析目前的程序:
.. code-block:: console