Skip to content

Commit f577dd3

Browse files
authored
Merge pull request #10 from Ivans-11/lab
feat: nobios mode, exercise docs & test cases, CI testing
2 parents 201bfe2 + a2fb756 commit f577dd3

97 files changed

Lines changed: 3390 additions & 387 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/workflow.yml

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,61 @@
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [ "main", "lab" ]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: [ "main", "lab" ]
8+
workflow_dispatch:
89

910
jobs:
10-
make:
11+
fmt:
1112
runs-on: ubuntu-latest
1213
steps:
13-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1415

15-
- name: Build syscall
16-
uses: actions-rs/cargo@v1
16+
- name: Install Rust toolchain
17+
uses: dtolnay/rust-toolchain@stable
1718
with:
18-
command: build
19-
args: --package syscall
19+
components: rustfmt
2020

2121
- name: Check format
22-
uses: actions-rs/cargo@v1
23-
with:
24-
command: fmt
25-
args: --all --check
22+
run: cargo fmt --all --check
23+
24+
qemu-exercise:
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 30
27+
container:
28+
image: duskmoon/dev-env:rcore-ci
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
ch: [3, 4, 5, 6, 8]
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Sanity check toolchain in container
37+
run: |
38+
set -eux
39+
qemu-system-riscv64 --version
40+
python3 --version
41+
rustc --version
42+
cargo --version
43+
rustup --version
44+
45+
- name: Mark workspace as safe git directory
46+
run: |
47+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
48+
49+
- name: Checkout checker
50+
run: |
51+
git clone --depth 1 https://github.com/LearningOS/rCore-Tutorial-Checker-2025S.git checker
52+
53+
- name: Install Rust components/targets
54+
run: |
55+
set -eux
56+
rustup target add riscv64gc-unknown-none-elf
57+
rustup component add rust-src llvm-tools-preview
2658
27-
- name: Make every chapter
59+
- name: Run exercise in QEMU and check output (ch${{ matrix.ch }})
2860
run: |
29-
cargo make --ch 1
30-
cargo make --ch 2
31-
cargo make --ch 3
32-
cargo make --ch 4
33-
cargo make --ch 5
34-
cargo make --ch 6
35-
cargo make --ch 7
36-
cargo make --ch 8
61+
timeout 3m cargo qemu --ch ${{ matrix.ch }} --exercise --nobios --ci 2>&1 \
62+
| python3 checker/check/ch${{ matrix.ch }}.py

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
*.asm
88
*.bin
99
!/rustsbi-qemu.bin
10+
!/**/m_entry.asm

Cargo.lock

Lines changed: 11 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ members = [
2323
"signal",
2424
"signal-impl",
2525
"sync",
26+
"sbi",
2627
]
2728
default-members = ["xtask"]
2829
resolver = "2"

ch1-lab/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ version = "0.0.1"
44
edition = "2021"
55
authors = ["YdrMaster <ydrml@hotmail.com>"]
66

7+
[features]
8+
default = []
9+
nobios = [
10+
"sbi/nobios",
11+
]
12+
713
[dependencies]
8-
sbi-rt = { version = "0.0.2", features = ["legacy"] }
14+
sbi = { path = "../sbi" }
915
rcore-console = { path = "../console" }

ch1-lab/build.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ fn main() {
22
use std::{env, fs, path::PathBuf};
33

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

@@ -28,3 +29,44 @@ SECTIONS {
2829
*(.sbss .sbss.*)
2930
}
3031
}";
32+
33+
34+
const NOBIOS_LINKER: &[u8] = b"
35+
OUTPUT_ARCH(riscv)
36+
ENTRY(_m_start)
37+
M_BASE_ADDRESS = 0x80000000;
38+
S_BASE_ADDRESS = 0x80200000;
39+
40+
SECTIONS {
41+
. = M_BASE_ADDRESS;
42+
.text.m_entry : {
43+
*(.text.m_entry)
44+
}
45+
.text.m_trap : {
46+
*(.text.m_trap)
47+
}
48+
.bss.m_stack : {
49+
*(.bss.m_stack)
50+
}
51+
.bss.m_data : {
52+
*(.bss.m_data)
53+
}
54+
. = S_BASE_ADDRESS;
55+
.text : {
56+
*(.text.entry)
57+
*(.text .text.*)
58+
}
59+
.rodata : {
60+
*(.rodata .rodata.*)
61+
*(.srodata .srodata.*)
62+
}
63+
.data : {
64+
*(.data .data.*)
65+
*(.sdata .sdata.*)
66+
}
67+
.bss : {
68+
*(.bss.uninit)
69+
*(.bss .bss.*)
70+
*(.sbss .sbss.*)
71+
}
72+
}";

ch1-lab/src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#[macro_use]
66
extern crate rcore_console;
77

8-
use sbi_rt::*;
8+
use sbi;
99

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

42-
system_reset(Shutdown, NoReason);
43-
unreachable!()
42+
sbi::shutdown(false)
4443
}
4544

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

5957
/// Rust 异常处理函数,以异常方式关机。
6058
#[panic_handler]
6159
fn panic(info: &core::panic::PanicInfo) -> ! {
6260
println!("{info}");
63-
system_reset(Shutdown, SystemFailure);
64-
loop {}
61+
sbi::shutdown(true)
6562
}

ch1/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ version = "0.0.1"
44
edition = "2021"
55
authors = ["YdrMaster <ydrml@hotmail.com>"]
66

7+
[features]
8+
default = []
9+
nobios = [
10+
"sbi/nobios",
11+
]
12+
713
[dependencies]
8-
sbi-rt = { version = "0.0.2", features = ["legacy"] }
14+
sbi = { path = "../sbi" }

ch1/build.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ fn main() {
22
use std::{env, fs, path::PathBuf};
33

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

@@ -28,3 +29,44 @@ SECTIONS {
2829
*(.sbss .sbss.*)
2930
}
3031
}";
32+
33+
34+
const NOBIOS_LINKER: &[u8] = b"
35+
OUTPUT_ARCH(riscv)
36+
ENTRY(_m_start)
37+
M_BASE_ADDRESS = 0x80000000;
38+
S_BASE_ADDRESS = 0x80200000;
39+
40+
SECTIONS {
41+
. = M_BASE_ADDRESS;
42+
.text.m_entry : {
43+
*(.text.m_entry)
44+
}
45+
.text.m_trap : {
46+
*(.text.m_trap)
47+
}
48+
.bss.m_stack : {
49+
*(.bss.m_stack)
50+
}
51+
.bss.m_data : {
52+
*(.bss.m_data)
53+
}
54+
. = S_BASE_ADDRESS;
55+
.text : {
56+
*(.text.entry)
57+
*(.text .text.*)
58+
}
59+
.rodata : {
60+
*(.rodata .rodata.*)
61+
*(.srodata .srodata.*)
62+
}
63+
.data : {
64+
*(.data .data.*)
65+
*(.sdata .sdata.*)
66+
}
67+
.bss : {
68+
*(.bss.uninit)
69+
*(.bss .bss.*)
70+
*(.sbss .sbss.*)
71+
}
72+
}";

0 commit comments

Comments
 (0)