# rcore **Repository Path**: MetaDatas/rcore ## Basic Information - **Project Name**: rcore - **Description**: 清华三叶草操作系统 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-11-08 - **Last Updated**: 2024-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 环境搭建 ```bash sudo apt-get update && sudo apt-get upgrade sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu ``` ```bash rustup install nightly rustup default nightly ``` ```toml [source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index" ``` ```toml [source.crates-io] replace-with = 'tuna' [source.tuna] registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git" ``` ```bash rustup target add riscv64gc-unknown-none-elf cargo install cargo-binutils rustup component add llvm-tools-preview rustup component add rust-src ``` ```bash sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \ gawk build-essential bison flex texinfo gperf libtool patchutils bc \ zlib1g-dev libexpat-dev pkg-config libglib2.0-dev libpixman-1-dev libsdl2-dev \ git tmux python3 python3-pip ninja-build ``` ## 常用工具 objcopy/objdump/readelf ## 可执行文件生成汇编 ```shell #通常办法,生成的汇编代码有比较冗余的信息 #生成缺省debug模式的汇编 cargo rustc -- --emit asm ls target/debug/deps/-.s #生成release模式的汇编 cargo rustc --release -- --emit asm ls target/release/deps/-.s #在rcore-tutorial-v3中的应用的汇编代码生成举例 cd user cargo rustc --release --bin hello_world -- --emit asm find ./target -name "hello_world*.s" #生成更加干净的汇编代码 #基于 cargo-show-asm(https://github.com/pacak/cargo-show-asm)的办法 #如果没用安装这个cargo asm子命令,就安装它 cargo install cargo-show-asm #在rcore-tutorial-v3中的应用的汇编代码生成举例 cd user cargo asm --release --bin hello_world Compiling user_lib v0.1.0 (/home/chyyuu/thecodes/rCore-Tutorial-v3/user) Finished release [optimized + debuginfo] target(s) in 0.10s .section .text.main,"ax",@progbits .globl main .p2align 1 .type main,@function main: .cfi_sections .debug_frame .cfi_startproc addi sp, sp, -64 .cfi_def_cfa_offset 64 sd ra, 56(sp) sd s0, 48(sp) .cfi_offset ra, -8 .cfi_offset s0, -16 addi s0, sp, 64 .cfi_def_cfa s0, 0 auipc a0, %pcrel_hi(.L__unnamed_1) addi a0, a0, %pcrel_lo(.LBB0_1) sd a0, -64(s0) li a0, 1 sd a0, -56(s0) sd zero, -48(s0) auipc a0, %pcrel_hi(.L__unnamed_2) addi a0, a0, %pcrel_lo(.LBB0_2) sd a0, -32(s0) sd zero, -24(s0) addi a0, s0, -64 call user_lib::console::print li a0, 0 ld ra, 56(sp) ld s0, 48(sp) addi sp, sp, 64 ret ```