# 开发环境配置

#### Linux / macOS

需要安装以下软件：

* [Rust](https://rustup.rs) nightly编译器
* Cargo工具: [cargo-xbuild](https://github.com/rust-osdev/cargo-xbuild), [bootimage](https://github.com/rust-osdev/bootimage)
* QEMU >= 2.12.0
* [RISCV64 GNU toolchain](https://www.sifive.com/products/tools/) (for riscv32)
* [AArch64 GNU toolchain](https://web.stanford.edu/class/cs140e/assignments/0-blinky/) (for aarch64)

安装依赖：

```bash
# 安装Rust工具链
curl https://sh.rustup.rs -sSf | sh

# 手动安装QEMU，RV64/AArch64工具链
# macOS：brew install qemu

# 由于天朝特殊的网络环境，建议配置代理服务器
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

# 安装cargo工具
rustup component add rust-src
cargo install cargo-xbuild bootimage
```

```bash
git clone https://github.com/wangrunji0408/RustOS.git --recursive
cd RustOS/kernel
rustup override set nightly
make run arch=riscv32
```

#### IDE & Editor

* 推荐配置：[IDEA](https://www.jetbrains.com/idea/) / [CLion](https://www.jetbrains.com/clion/) + [Rust插件](https://intellij-rust.github.io)
* 低配版本：Visual Studio Code + Rust插件

#### Debug

注：不能使用普通gdb，会触发Bug：`Remote 'g' packet reply is too long`

macOS下使用homebrew安装 altkatz/gcc\_cross\_compilers/x64-elf-gdb

```bash
brew install altkatz/gcc_cross_compilers/x64-elf-gdb
```

使用`make debug`运行QEMU，再运行gdb连接

在CLion中可以使用GDB Remote Debug功能，进行GUI debug

#### Make

辅助命令：

* `make asm`：查看kernel的反汇编（objdump -d）
* `make header`：查看kernel的各段信息（objdump -h）
* `make sym`：查看kernel的符号表（objdump -t）

参数：

* arch：目标平台，可选：x86\_64, riscv32, aarch64
* mode：编译模式，可选：debug, release
* LOG：输出调试信息等级，可选：off, error, warn, info, debug, trace，信息量依次递增
* d：QEMU的调试参数，可输入`qemu-system-riscv32 -d help` 查看选项
* smp：CPU核心数
* board：目标硬件\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rcore.gitbook.io/rust-os-docs/kai-fa-huan-jing-pei-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
