Skip to content
This repository was archived by the owner on Aug 12, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build]
target = "riscv64gc-unknown-none-elf"

[target.riscv64gc-unknown-none-elf]
rustflags = [
"-Cforce-frame-pointers=yes"
]
# cargo automatically use ELF's path as the first argument
runner = "tools/run_qemu.sh"
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v8

- name: kernel test
run: nix develop --command bash -c "cd os && make run"
run: nix develop --command bash -c "make run"

9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
/.nix-tools
/.direnv
/os/src/linker.ld
/kernel/target


# Added by cargo
#
# already existing elements were commented out

#/target
/kernel/src/link_app.S
65 changes: 36 additions & 29 deletions os/Cargo.lock → Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions os/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
[package]
name = "os"
[workspace]
resolver = "2"
members = [
"kernel",
"user_lib",
]
exclude = [
"framework",
]

[workspace.package]
version = "0.1.0"
edition = "2024"

[dependencies]
[workspace.dependencies]
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
log = "0.4"
Expand All @@ -12,5 +21,12 @@ sbi-rt = { version = "0.0.2", features = ["legacy"] }
buddy_system_allocator = "0.6"
bitflags = "1.2.1"

[workspace.lints.rust]
redundant_imports = "warn"
unused_qualifications = "warn"

[workspace.lints.clippy]
allow_attributes = "warn"

[profile.release]
debug = true
26 changes: 24 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
all:
cd os ; cargo build;
cargo build -p user_lib --release
cargo build -p kernel --release

run:
./run_tcp_off.sh
cargo build -p user_lib --release
cargo run -p kernel --release

debug:
cargo build -p user_lib --release
RACHO_GDB=1 cargo run -p kernel --release

gdb_client:
./tools/gdb_client.sh

disasm:
cargo build -p kernel --release
llvm-objdump -x target/riscv64gc-unknown-none-elf/release/kernel | less

disasm-vim:
cargo build -p kernel --release
llvm-objdump -x target/riscv64gc-unknown-none-elf/release/kernel > /tmp/racho.asm
vim /tmp/racho.asm

clean:
cargo clean
9 changes: 5 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
];
shellHook = ''
echo "==> racho dev shell"
echo " Rust: rust-toolchain.toml (auto-installs on first cargo run)"
echo " QEMU: qemu-system-riscv64"
echo " GDB: gdb"
echo " Build: cd os && make run"
echo " Rust: rust-toolchain.toml (auto-installs on first cargo run)"
echo " Rust: Cargo.toml (for Build system + Package manager)"
echo " QEMU: make run"
echo " GDB: make debug / make gdb_client"
echo " Build: make all"
echo ""
'';
};
Expand Down
9 changes: 9 additions & 0 deletions framework/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "framework"
version.workspace = true
edition.workspace = true

[dependencies]

[lints]
workspace = true
3 changes: 3 additions & 0 deletions framework/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
16 changes: 16 additions & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "kernel"
version.workspace = true
edition.workspace = true

[dependencies]
riscv.workspace = true
lazy_static.workspace = true
log.workspace = true
xmas-elf.workspace = true
sbi-rt.workspace = true
buddy_system_allocator.workspace = true
bitflags.workspace = true

[lints]
workspace = true
29 changes: 20 additions & 9 deletions os/build.rs → kernel/build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
use std::fs::{File, read_dir};
use std::io::{Result, Write};
use std::path::PathBuf;

fn main() {
println!("cargo:rerun-if-changed=../user/src/");
println!("cargo:rerun-if-changed={}", TARGET_PATH);
insert_app_data().unwrap();
}
println!("cargo:rustc-link-arg=-Tkernel/src/linker-qemu.ld");
println!("cargo:rerun-if-changed=../user_lib/src/");

let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let target_dir = manifest_dir
.parent()
.unwrap()
.join("target")
.join("riscv64gc-unknown-none-elf")
.join("release");

static TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/release/";
let target_path = target_dir.to_string_lossy().into_owned();
println!("cargo:rerun-if-changed={}", target_path);

insert_app_data(&target_path).unwrap();
}

fn insert_app_data() -> Result<()> {
fn insert_app_data(target_path: &str) -> Result<()> {
let mut f = File::create("src/link_app.S").unwrap();
let mut apps: Vec<_> = read_dir("../user/src/bin")
let mut apps: Vec<_> = read_dir("../user_lib/src/bin")
.unwrap()
.map(|dir_entry| {
let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap();
Expand Down Expand Up @@ -46,9 +57,9 @@ fn insert_app_data() -> Result<()> {
.global app_{0}_start
.global app_{0}_end
app_{0}_start:
.incbin "{2}{1}"
.incbin "{1}/{2}"
app_{0}_end:"#,
idx, app, TARGET_PATH
idx, target_path, app
)?;
}
Ok(())
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions os/src/main.rs → kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ pub fn rust_main() -> ! {
// TODO:
// 7.19,20;继续排除问题重构代码让上面这两个函数的调用链正常,遇到必要时,重构代码和写测试代码
// 重构代码,参考framework kernel,分离safe rust和unsafe rust;
// 给孙班主任分享想法(重构framework kernel后,录制演示视频)
// 关键给孙老师直接录制演示视频,写一个架构介绍去咨询意见
// 分享想法(重构framework kernel后,录制演示视频)
// 直接录制演示视频,写一个架构介绍去咨询意见
mm::init();
trap::init(); // setup the kernel trap
trap::enable_timer_interrupt();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions os/.cargo/config.toml

This file was deleted.

Loading
Loading