rust写操作系统 rCore tutorial 学习笔记:实验指导零 创建项目与启动

这是 os summer of code 2020 项目每日记录的一部分:每日记录github地址(包含根据实验指导实现的每个阶段的代码):https://github.com/yunwei37/os-summer-of-code-daily这里参考的是rCore tutorial的第三版:https://github.com/rcore-os/rCore-TutorialrCore tutorial environment && lab 0环境配置本机环境(新安装的虚拟机系统,上
摘要由CSDN通过智能技术生成

这是 os summer of code 2020 项目每日记录的一部分:
每日记录github地址(包含根据实验指导实现的每个阶段的代码):https://github.com/yunwei37/os-summer-of-code-daily

这里参考的是rCore tutorial的第三版:https://github.com/rcore-os/rCore-Tutorial

rCore tutorial environment && lab 0

环境配置

本机环境(新安装的虚拟机系统,上一个系统是搞xv6的qemu,感觉可能实验环境会有冲突不如再开一个):

Linux ubuntu 5.4.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

已换源至阿里云,但版本过低;

安装 QEMU

  • sudo apt-get install build-essential 安装编译工具链;
  • 下载源码编译:
wget https://download.qemu.org/qemu-4.2.0.tar.xz
tar xvJf qemu-4.2.0.tar.xz
cd qemu-4.2.0
./configure --target-list=riscv32-softmmu,riscv64-softmmu
  • 报错ERROR: glib-2.48 gthread-2.0 is required to compile QEMU:通过 sudo apt-get install libglib2.0-dev 安装;
  • 报错 ERROR: pixman >= 0.21.8 not present ,通过 sudo apt-get install libpixman-1-dev 安装
  • 测试
yunwei@ubuntu:~/rcore$ qemu-system-riscv64 --version
QEMU emulator version 4.2.0
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers

安装 Rust 工具链

  • 运行curl https://sh.rustup.rs -sSf | sh

尝试运行 rCore

  • git clone https://github.com/rcore-os/rCore-Tutorial
  • make
Failed to execute tool: objcopy
No such file or directory (os error 2)
make[1]: *** [Makefile:28: target/riscv64imac-unknown-none-elf/debug/kernel.bin] Error 101

可能是我先做了下面导致的问题,之后再说;

lab 0: 跑起来

创建 Rust 项目

创建文件夹,并创建项目:

mkdir Project     
cd Project     
echo "nightly-2020-06-27" > rust-toolchain
cargo new os
cd os
  • Test:cargo run

移除标准库依赖:

main.rs

#![no_std]

use core::panic::PanicInfo;

/// 当 panic 发生时会调用该函数
/// 我们暂时将它的实现为一个死循环
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

Cargo.toml

[package]
name = "os"
version = "0.1.0"
authors = ["yunwei"]
edition = "2018"

# panic 时直接终止,因为我们没有实现堆栈展开的功能
[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

移除运行时环境依赖

main.rs

#![no_std]

use core::panic::PanicInfo;

/// 当 panic 发生时会调用该函数
/// 我们暂时将它的实现为一个死循环
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

  • 运行:rustup target add riscv64imac-unknown-none-elf
  • 运行:cargo build --target riscv64imac-unknown-none-elf

结果:

yunwei@ubuntu:~/Project/os$ cargo build --target riscv64imac-unknown-none-elf
   Compiling os v0.1.0 (/home/yunwei/Project/os)
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s

在 os/.cargo/config 里面添加了这个:

# 编译的目标平台
[build]
target = "riscv64imac-unknown-none-elf"

就可以 cargo build 啦

生成内核镜像

运行:

cargo install cargo-binutils
rustup component add llvm-tools-preview

  • rust-objdump --version
@ubuntu:~/Project/os$ rust-objdump --version
LLVM (http://llvm.org/):
  LLVM version 10.0.1-rust-1.46.0-nightly
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
 
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值