初始化ch2
parent
9ef817ce97
commit
a53ff6520d
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "os"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "user_lib"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
@ -0,0 +1,16 @@
|
||||
MODE := release
|
||||
TARGET := riscv64gc-unknown-none-elf
|
||||
|
||||
|
||||
RUST_FLAGS := -Clink-arg=-Tsrc/linker.ld # 使用我们自己的链接脚本
|
||||
RUST_FLAGS += -Cforce-frame-pointers=yes # 强制编译器生成帧指针
|
||||
RUST_FLAGS:=$(strip ${RUST_FLAGS})
|
||||
|
||||
# 编译elf文件
|
||||
build_elf: clean
|
||||
CARGO_BUILD_RUSTFLAGS="$(RUST_FLAGS)" \
|
||||
cargo build --$(MODE) --target=$(TARGET)
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf ./target*
|
@ -0,0 +1,8 @@
|
||||
#![no_std]
|
||||
#![feature(linkage)] // 开启弱链接特性
|
||||
|
||||
#[linkage = "weak"] // 设置我们默认的main函数, 弱链接
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
panic!("Cannot find main!");
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
OUTPUT_ARCH(riscv)
|
||||
ENTRY(_start)
|
||||
|
||||
/*设置用户程序链接的基础起始位置为0x80400000*/
|
||||
BASE_ADDRESS = 0x80400000;
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = BASE_ADDRESS;
|
||||
.text : {
|
||||
*(.text.entry)
|
||||
*(.text .text.*)
|
||||
}
|
||||
.rodata : {
|
||||
*(.rodata .rodata.*)
|
||||
*(.srodata .srodata.*)
|
||||
}
|
||||
.data : {
|
||||
*(.data .data.*)
|
||||
*(.sdata .sdata.*)
|
||||
}
|
||||
.bss : {
|
||||
start_bss = .;
|
||||
*(.bss .bss.*)
|
||||
*(.sbss .sbss.*)
|
||||
end_bss = .;
|
||||
}
|
||||
/DISCARD/ : {
|
||||
*(.eh_frame)
|
||||
*(.debug*)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue