Skip to content
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
68 changes: 47 additions & 21 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,61 @@

on:
push:
branches: [ "main" ]
branches: [ "main", "lab" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "lab" ]
workflow_dispatch:

jobs:
make:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build syscall
uses: actions-rs/cargo@v1
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
command: build
args: --package syscall
components: rustfmt

- name: Check format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check
run: cargo fmt --all --check

qemu-exercise:
runs-on: ubuntu-latest
timeout-minutes: 30
container:
image: duskmoon/dev-env:rcore-ci
strategy:
fail-fast: false
matrix:
ch: [3, 4, 5, 6, 8]
steps:
- uses: actions/checkout@v4

- name: Sanity check toolchain in container
run: |
set -eux
qemu-system-riscv64 --version
python3 --version
rustc --version
cargo --version
rustup --version

- name: Mark workspace as safe git directory
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Checkout checker
run: |
git clone --depth 1 https://github.com/LearningOS/rCore-Tutorial-Checker-2025S.git checker

- name: Install Rust components/targets
run: |
set -eux
rustup target add riscv64gc-unknown-none-elf
rustup component add rust-src llvm-tools-preview

- name: Make every chapter
- name: Run exercise in QEMU and check output (ch${{ matrix.ch }})
run: |
cargo make --ch 1
cargo make --ch 2
cargo make --ch 3
cargo make --ch 4
cargo make --ch 5
cargo make --ch 6
cargo make --ch 7
cargo make --ch 8
timeout 3m cargo qemu --ch ${{ matrix.ch }} --exercise --nobios --ci 2>&1 \
| python3 checker/check/ch${{ matrix.ch }}.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*.asm
*.bin
!/rustsbi-qemu.bin
!/**/m_entry.asm
36 changes: 11 additions & 25 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"signal",
"signal-impl",
"sync",
"sbi",
]
default-members = ["xtask"]
resolver = "2"
8 changes: 7 additions & 1 deletion ch1-lab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ version = "0.0.1"
edition = "2021"
authors = ["YdrMaster <ydrml@hotmail.com>"]

[features]
default = []
nobios = [
"sbi/nobios",
]

[dependencies]
sbi-rt = { version = "0.0.2", features = ["legacy"] }
sbi = { path = "../sbi" }
rcore-console = { path = "../console" }
44 changes: 43 additions & 1 deletion ch1-lab/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ fn main() {
use std::{env, fs, path::PathBuf};

let ld = &PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
fs::write(ld, LINKER).unwrap();
fs::write(ld, if env::var("CARGO_FEATURE_NOBIOS").is_ok() { NOBIOS_LINKER } else { LINKER }).unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_NOBIOS");
println!("cargo:rustc-link-arg=-T{}", ld.display());
}

Expand All @@ -28,3 +29,44 @@ SECTIONS {
*(.sbss .sbss.*)
}
}";


const NOBIOS_LINKER: &[u8] = b"
OUTPUT_ARCH(riscv)
ENTRY(_m_start)
M_BASE_ADDRESS = 0x80000000;
S_BASE_ADDRESS = 0x80200000;

SECTIONS {
. = M_BASE_ADDRESS;
.text.m_entry : {
*(.text.m_entry)
}
.text.m_trap : {
*(.text.m_trap)
}
.bss.m_stack : {
*(.bss.m_stack)
}
.bss.m_data : {
*(.bss.m_data)
}
. = S_BASE_ADDRESS;
.text : {
*(.text.entry)
*(.text .text.*)
}
.rodata : {
*(.rodata .rodata.*)
*(.srodata .srodata.*)
}
.data : {
*(.data .data.*)
*(.sdata .sdata.*)
}
.bss : {
*(.bss.uninit)
*(.bss .bss.*)
*(.sbss .sbss.*)
}
}";
11 changes: 4 additions & 7 deletions ch1-lab/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#[macro_use]
extern crate rcore_console;

use sbi_rt::*;
use sbi;

/// Supervisor 汇编入口。
///
Expand Down Expand Up @@ -39,8 +39,7 @@ extern "C" fn rust_main() -> ! {
// 测试各种打印
rcore_console::test_log();

system_reset(Shutdown, NoReason);
unreachable!()
sbi::shutdown(false)
}

/// 将传给 `console` 的控制台对象。
Expand All @@ -51,15 +50,13 @@ struct Console;
/// 为 `Console` 实现 `console::Console` trait。
impl rcore_console::Console for Console {
fn put_char(&self, c: u8) {
#[allow(deprecated)]
legacy::console_putchar(c as _);
sbi::console_putchar(c);
}
}

/// Rust 异常处理函数,以异常方式关机。
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
println!("{info}");
system_reset(Shutdown, SystemFailure);
loop {}
sbi::shutdown(true)
}
8 changes: 7 additions & 1 deletion ch1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ version = "0.0.1"
edition = "2021"
authors = ["YdrMaster <ydrml@hotmail.com>"]

[features]
default = []
nobios = [
"sbi/nobios",
]

[dependencies]
sbi-rt = { version = "0.0.2", features = ["legacy"] }
sbi = { path = "../sbi" }
44 changes: 43 additions & 1 deletion ch1/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ fn main() {
use std::{env, fs, path::PathBuf};

let ld = &PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
fs::write(ld, LINKER).unwrap();
fs::write(ld, if env::var("CARGO_FEATURE_NOBIOS").is_ok() { NOBIOS_LINKER } else { LINKER }).unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_NOBIOS");
println!("cargo:rustc-link-arg=-T{}", ld.display());
}

Expand All @@ -28,3 +29,44 @@ SECTIONS {
*(.sbss .sbss.*)
}
}";


const NOBIOS_LINKER: &[u8] = b"
OUTPUT_ARCH(riscv)
ENTRY(_m_start)
M_BASE_ADDRESS = 0x80000000;
S_BASE_ADDRESS = 0x80200000;

SECTIONS {
. = M_BASE_ADDRESS;
.text.m_entry : {
*(.text.m_entry)
}
.text.m_trap : {
*(.text.m_trap)
}
.bss.m_stack : {
*(.bss.m_stack)
}
.bss.m_data : {
*(.bss.m_data)
}
. = S_BASE_ADDRESS;
.text : {
*(.text.entry)
*(.text .text.*)
}
.rodata : {
*(.rodata .rodata.*)
*(.srodata .srodata.*)
}
.data : {
*(.data .data.*)
*(.sdata .sdata.*)
}
.bss : {
*(.bss.uninit)
*(.bss .bss.*)
*(.sbss .sbss.*)
}
}";
Loading
Loading