From 778585015273f8e0061ae8584a9bd1aac7730ebd Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 08:12:38 +0800 Subject: [PATCH 01/11] Migrate from nightly-2022-01-20 to stable - Remove #![feature(linkage)] and #![cfg_attr(mips, asm_experimental_arch)] - Drop weak default trap_handler (RISC-V, MIPS), users must provide their own - Disable x86_64 crate's nightly feature, use instructions feature instead - Fix set_handler_fn -> set_handler_addr in IDT init (needs abi_x86_interrupt) - Bump UEFI example deps to uefi 0.38, drop uefi-services - Remove naked/efiapi/core_intrinsics feature gates from UEFI example - Rename .cargo/config to .cargo/config.toml - Add -cpu max to UEFI QEMU invocation for FSGSBASE - Fix function-to-integer casts for Rust 1.96 lint - Update CI workflows to use stable toolchain --- .github/workflows/deploy.yml | 4 +-- .github/workflows/main.yml | 13 +++----- Cargo.toml | 2 +- examples/riscv/.cargo/{config => config.toml} | 0 examples/uefi/.cargo/config | 6 ---- examples/uefi/.cargo/config.toml | 2 ++ examples/uefi/Cargo.toml | 13 +++++--- examples/uefi/Makefile | 2 +- examples/uefi/src/main.rs | 32 +++++++++++-------- rust-toolchain | 2 +- src/arch/aarch64/fncall.rs | 8 ++--- src/arch/aarch64/trap.rs | 2 +- src/arch/mipsel/trap.rs | 6 ---- src/arch/riscv/trap.rs | 8 +---- src/arch/x86_64/fncall.rs | 2 +- src/arch/x86_64/idt.rs | 6 ++-- src/arch/x86_64/syscall.rs | 2 +- src/lib.rs | 2 -- 18 files changed, 49 insertions(+), 63 deletions(-) rename examples/riscv/.cargo/{config => config.toml} (100%) delete mode 100644 examples/uefi/.cargo/config create mode 100644 examples/uefi/.cargo/config.toml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9a8325c..33b79d6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2022-01-20 + toolchain: stable profile: minimal components: rust-src - name: Build docs @@ -34,7 +34,7 @@ jobs: do rustup target add ${target} cargo doc --target ${target} - cargo doc --target ${target} -Z build-std=core,alloc + cargo +nightly doc --target ${target} -Z build-std=core,alloc mv target/${target}/doc doc/${target} done - name: Deploy to Github Pages diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b3d4021..75ee909 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,11 +7,10 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: rm rust-toolchain - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-01-20 + toolchain: stable override: true components: rustfmt, clippy - name: Check code format @@ -38,7 +37,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-01-20 + toolchain: stable target: ${{ matrix.target }} components: clippy - name: Build @@ -64,7 +63,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-01-20 + toolchain: nightly components: rust-src - name: Build uses: actions-rs/cargo@v1 @@ -84,11 +83,10 @@ jobs: os: [ubuntu-20.04, macos-latest] steps: - uses: actions/checkout@v2 - - run: rm rust-toolchain - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-01-20 + toolchain: stable override: true - name: Test uses: actions-rs/cargo@v1 @@ -100,11 +98,10 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: rm rust-toolchain - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-01-20 + toolchain: stable target: aarch64-unknown-linux-gnu override: true - uses: actions-rs/cargo@v1 diff --git a/Cargo.toml b/Cargo.toml index 00940b6..205f9d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ exclude = ["docs", ".idea"] [dependencies] [target.'cfg(target_arch = "x86_64")'.dependencies] -x86_64 = "0.15" +x86_64 = { version = "0.15", default-features = false, features = ["instructions"] } raw-cpuid = "11.0" [features] diff --git a/examples/riscv/.cargo/config b/examples/riscv/.cargo/config.toml similarity index 100% rename from examples/riscv/.cargo/config rename to examples/riscv/.cargo/config.toml diff --git a/examples/uefi/.cargo/config b/examples/uefi/.cargo/config deleted file mode 100644 index 704aee0..0000000 --- a/examples/uefi/.cargo/config +++ /dev/null @@ -1,6 +0,0 @@ -[build] -target = "x86_64-unknown-uefi" - -[unstable] -build-std = ["core", "alloc"] -build-std-features = ["compiler-builtins-mem"] diff --git a/examples/uefi/.cargo/config.toml b/examples/uefi/.cargo/config.toml new file mode 100644 index 0000000..85d49dc --- /dev/null +++ b/examples/uefi/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "x86_64-unknown-uefi" diff --git a/examples/uefi/Cargo.toml b/examples/uefi/Cargo.toml index 1d2f962..0c733b7 100644 --- a/examples/uefi/Cargo.toml +++ b/examples/uefi/Cargo.toml @@ -2,13 +2,18 @@ name = "uefi" version = "0.1.0" authors = ["Runji Wang "] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" + [dependencies] log = "0.4" -x86_64 = "0.14" -uefi = "0.14" -uefi-services = "0.11" +x86_64 = { version = "0.15", default-features = false, features = ["instructions"] } +uefi = { version = "0.38", features = ["global_allocator", "logger", "panic_handler"] } trapframe = { path = "../.." } diff --git a/examples/uefi/Makefile b/examples/uefi/Makefile index 98078ad..92af3b4 100644 --- a/examples/uefi/Makefile +++ b/examples/uefi/Makefile @@ -3,7 +3,7 @@ TARGET := target OVMF := OVMF.fd EFI := $(TARGET)/x86_64-unknown-uefi/$(MODE)/uefi.efi ESP := $(TARGET)/x86_64-unknown-uefi/$(MODE)/esp -QEMU_ARGS := -net none -nographic +QEMU_ARGS := -net none -nographic -cpu max OBJDUMP := rust-objdump ifeq (${MODE}, release) diff --git a/examples/uefi/src/main.rs b/examples/uefi/src/main.rs index 597b543..44b2311 100644 --- a/examples/uefi/src/main.rs +++ b/examples/uefi/src/main.rs @@ -1,25 +1,34 @@ #![no_std] #![no_main] -#![feature(abi_efiapi)] -#![feature(core_intrinsics)] -#![feature(naked_functions)] #![deny(warnings)] extern crate alloc; use core::arch::asm; -use core::intrinsics::breakpoint; use log::*; use trapframe::{GeneralRegs, TrapFrame, UserContext}; use uefi::prelude::*; use x86_64::registers::control::*; use x86_64::structures::paging::{PageTable, PageTableFlags}; +core::arch::global_asm!( + r#" +.global user_entry +user_entry: + syscall + int3 +"# +); + +extern "C" { + fn user_entry(); +} + #[entry] -fn efi_main(_image: Handle, mut st: SystemTable) -> uefi::Status { - uefi_services::init(&mut st).expect_success("Failed to initialize utilities"); +fn efi_main() -> Status { + uefi::helpers::init().expect("Failed to initialize utilities"); check_and_set_cpu_features(); - allow_user_access(user_entry as usize); + allow_user_access(user_entry as *const () as usize); unsafe { trapframe::init(); } @@ -42,7 +51,7 @@ fn efi_main(_image: Handle, mut st: SystemTable) -> uefi::Status { r13: 13, r14: 14, r15: 15, - rip: user_entry as usize, + rip: user_entry as *const () as usize, rflags: 0x202, fsbase: 18, gsbase: 19, @@ -62,7 +71,7 @@ fn efi_main(_image: Handle, mut st: SystemTable) -> uefi::Status { // trap from kernel unsafe { - breakpoint(); + asm!("int3", options(nomem, nostack)); } unimplemented!() } @@ -78,11 +87,6 @@ extern "sysv64" fn trap_handler(tf: &mut TrapFrame) { } } -#[naked] -unsafe extern "C" fn user_entry() { - asm!("syscall", "int3", options(noreturn)); -} - /// Set user bit for 4-level PDEs of the `page`. /// This is a workaround since `x86_64` crate does not set user bit for PDEs. fn allow_user_access(vaddr: usize) { diff --git a/rust-toolchain b/rust-toolchain index 12ae469..870bbe4 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-01-20 \ No newline at end of file +stable \ No newline at end of file diff --git a/src/arch/aarch64/fncall.rs b/src/arch/aarch64/fncall.rs index bb9d4ad..b7cc16d 100644 --- a/src/arch/aarch64/fncall.rs +++ b/src/arch/aarch64/fncall.rs @@ -148,7 +148,7 @@ elr_location: let mut cx = UserContext { general, sp: stack.as_mut_ptr() as usize + 0x1000, - elr: dump_registers as usize, + elr: dump_registers as *const () as usize, ..Default::default() }; cx.run_fncall(); @@ -157,7 +157,7 @@ elr_location: assert_eq!( general_dump, GeneralRegs { - x30: dump_registers as usize, + x30: dump_registers as *const () as usize, ..general } ); @@ -195,10 +195,10 @@ elr_location: x27: 100 + 27, x28: 100 + 28, x29: 100 + 29, - x30: elr_location as usize, + x30: elr_location as *const () as usize, ..cx.general } ); - assert_eq!(cx.elr, elr_location as usize); + assert_eq!(cx.elr, elr_location as *const () as usize); } } diff --git a/src/arch/aarch64/trap.rs b/src/arch/aarch64/trap.rs index b0031b0..17e0e5c 100644 --- a/src/arch/aarch64/trap.rs +++ b/src/arch/aarch64/trap.rs @@ -13,7 +13,7 @@ global_asm!(include_str!("trap.S")); /// You **MUST NOT** modify these registers later. pub unsafe fn init() { // Set the exception vector address - asm!("msr VBAR_EL1, {}", in(reg) __vectors as usize); + asm!("msr VBAR_EL1, {}", in(reg) __vectors as *const () as usize); } /// Trap frame of kernel interrupt diff --git a/src/arch/mipsel/trap.rs b/src/arch/mipsel/trap.rs index 217be89..6992765 100644 --- a/src/arch/mipsel/trap.rs +++ b/src/arch/mipsel/trap.rs @@ -19,12 +19,6 @@ pub unsafe fn init() { ); } -#[no_mangle] -#[linkage = "weak"] -extern "C" fn trap_handler(tf: &mut TrapFrame) { - unimplemented!("TRAP: tf={:#x?}", tf); -} - /// Trap frame of kernel interrupt /// /// # Trap handler diff --git a/src/arch/riscv/trap.rs b/src/arch/riscv/trap.rs index 5a5fc68..c6f1a52 100644 --- a/src/arch/riscv/trap.rs +++ b/src/arch/riscv/trap.rs @@ -41,13 +41,7 @@ pub unsafe fn init() { // presently executing in the kernel asm!("csrw sscratch, zero"); // Set the exception vector address - asm!("csrw stvec, {}", in(reg) trap_entry as usize); -} - -#[no_mangle] -#[linkage = "weak"] -extern "C" fn trap_handler(tf: &mut TrapFrame) { - unimplemented!("TRAP: tf={:#x?}", tf); + asm!("csrw stvec, {}", in(reg) trap_entry as *const () as usize); } /// Trap frame of kernel interrupt diff --git a/src/arch/x86_64/fncall.rs b/src/arch/x86_64/fncall.rs index 3c6b6d3..ff3ea55 100644 --- a/src/arch/x86_64/fncall.rs +++ b/src/arch/x86_64/fncall.rs @@ -301,7 +301,7 @@ dump_registers: r13: 13, r14: 14, r15: 15, - rip: dump_registers as usize, + rip: dump_registers as *const () as usize, rflags: 0, fsbase: 0, // don't set to non-zero garbage value gsbase: 0, diff --git a/src/arch/x86_64/idt.rs b/src/arch/x86_64/idt.rs index ad474e4..62c6ee8 100644 --- a/src/arch/x86_64/idt.rs +++ b/src/arch/x86_64/idt.rs @@ -11,11 +11,9 @@ pub fn init() { } let idt = Box::leak(Box::new(InterruptDescriptorTable::new())); - // let idt = sidt().base; - let entries: &'static mut [Entry; 256] = - unsafe { core::mem::transmute_copy(&idt) }; + let entries: &'static mut [Entry<()>; 256] = unsafe { core::mem::transmute_copy(&idt) }; for i in 0..256 { - let opt = entries[i].set_handler_fn(unsafe { core::mem::transmute(VECTORS[i]) }); + let opt = unsafe { entries[i].set_handler_addr(VirtAddr::new(VECTORS[i] as usize as u64)) }; // Enable user space `int3` and `into` if i == 3 || i == 4 { opt.set_privilege_level(PrivilegeLevel::Ring3); diff --git a/src/arch/x86_64/syscall.rs b/src/arch/x86_64/syscall.rs index 51d5044..2aa139b 100644 --- a/src/arch/x86_64/syscall.rs +++ b/src/arch/x86_64/syscall.rs @@ -30,7 +30,7 @@ pub fn init() { // TF|DF|IF|IOPL|AC|NT const RFLAGS_MASK: u64 = 0x47700; - LStar::write(VirtAddr::new(syscall_entry as usize as u64)); + LStar::write(VirtAddr::new(syscall_entry as *const () as usize as u64)); SFMask::write(RFlags::from_bits(RFLAGS_MASK).unwrap()); } } diff --git a/src/lib.rs b/src/lib.rs index 13389fe..bbfd56f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,5 @@ #![no_std] -#![feature(linkage)] #![deny(warnings)] -#![cfg_attr(target_arch = "mips", feature(asm_experimental_arch))] extern crate alloc; From 15baf34ffda65ac3bc42a97fa5e19a243f801d8d Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 08:15:46 +0800 Subject: [PATCH 02/11] CI: use ubuntu-latest instead of ubuntu-20.04 --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 75ee909..63f3ef4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: check: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -20,7 +20,7 @@ jobs: args: --all -- --check build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: target: [ @@ -57,7 +57,7 @@ jobs: args: --target ${{ matrix.target }} build-x86_64-none: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -80,7 +80,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, macos-latest] + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -95,7 +95,7 @@ jobs: args: --all-features test-aarch64: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 From 88abec49bd007d62906268607db7a60cd0b6d165 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 08:18:33 +0800 Subject: [PATCH 03/11] CI: drop mipsel from matrix, use cargo +nightly for build-std --- .github/workflows/main.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 63f3ef4..667daba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,6 @@ jobs: aarch64-unknown-none-softfloat, riscv32imac-unknown-none-elf, riscv64imac-unknown-none-elf, - mipsel-unknown-linux-gnu, ] steps: - uses: actions/checkout@v2 @@ -66,15 +65,9 @@ jobs: toolchain: nightly components: rust-src - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc + run: cargo +nightly build --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc - name: Docs - uses: actions-rs/cargo@v1 - with: - command: doc - args: --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc + run: cargo +nightly doc --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc test-x86_64: runs-on: ${{ matrix.os }} From 62871b32334ef59339ad17d1111f15f9034e6d52 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 08:31:46 +0800 Subject: [PATCH 04/11] CI: replace deprecated actions-rs/* with dtolnay/rust-toolchain and plain run steps --- .github/workflows/deploy.yml | 10 ++--- .github/workflows/main.yml | 80 +++++++++--------------------------- 2 files changed, 24 insertions(+), 66 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 33b79d6..38d98c7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,11 +8,10 @@ jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@nightly with: - toolchain: stable - profile: minimal components: rust-src - name: Build docs run: | @@ -23,8 +22,7 @@ jobs: aarch64-unknown-none-softfloat \ riscv32imac-unknown-none-elf \ riscv64imac-unknown-none-elf \ - riscv64imac-unknown-none-elf \ - mipsel-unknown-linux-gnu + riscv64imac-unknown-none-elf do rustup target add ${target} cargo doc --target ${target} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 667daba..8538889 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,18 +6,11 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable with: - profile: minimal - toolchain: stable - override: true components: rustfmt, clippy - - name: Check code format - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo fmt --all -- --check build: runs-on: ubuntu-latest @@ -32,42 +25,24 @@ jobs: riscv64imac-unknown-none-elf, ] steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable with: - profile: minimal - toolchain: stable - target: ${{ matrix.target }} + targets: ${{ matrix.target }} components: clippy - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --all-features --target ${{ matrix.target }} - - name: Clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --target ${{ matrix.target }} - - name: Docs - uses: actions-rs/cargo@v1 - with: - command: doc - args: --target ${{ matrix.target }} + - run: cargo build --all-features --target ${{ matrix.target }} + - run: cargo clippy --target ${{ matrix.target }} + - run: cargo doc --target ${{ matrix.target }} build-x86_64-none: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly with: - profile: minimal - toolchain: nightly components: rust-src - - name: Build - run: cargo +nightly build --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc - - name: Docs - run: cargo +nightly doc --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc + - run: cargo +nightly build --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc + - run: cargo +nightly doc --all-features --target x86_64-unknown-linux-gnu -Z build-std=core,alloc test-x86_64: runs-on: ${{ matrix.os }} @@ -75,30 +50,15 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - name: Test - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo test --all-features test-aarch64: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: aarch64-unknown-linux-gnu - override: true - - uses: actions-rs/cargo@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable with: - use-cross: true - command: test - args: --target aarch64-unknown-linux-gnu + targets: aarch64-unknown-linux-gnu + - run: cargo build --target aarch64-unknown-linux-gnu From bf3cf7e5a925c4957d35054911dd7d017683667f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 3 Jul 2026 18:46:16 +0200 Subject: [PATCH 05/11] fix(riscv): allow far away `trap_handler` --- src/arch/riscv/trap.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arch/riscv/trap.S b/src/arch/riscv/trap.S index fa0dc54..a3f15e7 100644 --- a/src/arch/riscv/trap.S +++ b/src/arch/riscv/trap.S @@ -62,7 +62,7 @@ trap_from_user: end_trap_from_kernel: mv a0, sp # first arg is TrapFrame la ra, trap_return # set return address - j trap_handler + tail trap_handler end_trap_from_user: # load callee-saved registers From b4218c3b469f81d1983e590beb4fdb76a6341ef8 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 09:03:24 +0800 Subject: [PATCH 06/11] riscv example: use nightly toolchain, fix fn-to-int cast, switch to -kernel --- examples/riscv/Cargo.toml | 2 +- examples/riscv/Makefile | 14 +++++--------- examples/riscv/src/main.rs | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/examples/riscv/Cargo.toml b/examples/riscv/Cargo.toml index ad3a3fb..c30395b 100644 --- a/examples/riscv/Cargo.toml +++ b/examples/riscv/Cargo.toml @@ -9,5 +9,5 @@ edition = "2018" [dependencies] log = "0.4" riscv = "0.7" -opensbi-rt = { git = "https://github.com/rcore-os/opensbi-rt.git", rev = "abdfeb7" } +opensbi-rt = { git = "https://github.com/rcore-os/opensbi-rt.git", rev = "6d44fced33f6116bfea68d52b0e027bea6414e85" } trapframe = { path = "../.." } diff --git a/examples/riscv/Makefile b/examples/riscv/Makefile index a3f8554..e8dac00 100644 --- a/examples/riscv/Makefile +++ b/examples/riscv/Makefile @@ -2,7 +2,6 @@ arch ?= riscv64 target := $(arch)imac-unknown-none-elf mode := debug kernel := target/$(target)/$(mode)/riscv -bin := target/$(target)/$(mode)/kernel.bin sysroot := $(shell rustc --print sysroot) objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=$(arch) @@ -21,17 +20,14 @@ endif .PHONY: kernel build clean qemu run env -build: $(bin) +build: kernel env: - rustup component add llvm-tools-preview rustfmt - rustup target add $(target) + rustup component add llvm-tools-preview rustfmt --toolchain nightly + rustup target add $(target) --toolchain nightly kernel: - cargo build $(BUILD_ARGS) - -$(bin): kernel - $(objcopy) $(kernel) --strip-all -O binary $@ + cargo +nightly build $(BUILD_ARGS) asm: $(objdump) -d $(kernel) | less @@ -50,6 +46,6 @@ qemu: $(bin) -machine virt \ -nographic \ -bios default \ - -device loader,file=$(bin),addr=$(START_ADDR) + -kernel $(kernel) run: build qemu diff --git a/examples/riscv/src/main.rs b/examples/riscv/src/main.rs index 79b95e2..273ae33 100644 --- a/examples/riscv/src/main.rs +++ b/examples/riscv/src/main.rs @@ -52,7 +52,7 @@ extern "C" fn main() { t6: 31, }, sstatus: 0xdead_beaf, - sepc: user_entry as usize, + sepc: user_entry as *const () as usize, }; println!("Go to user: {:#x?}", regs); regs.run(); From 33ddac85dc7ceb6ac94f885cc089eb5c721b5ffb Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 20:55:02 +0800 Subject: [PATCH 07/11] Fix review comments: aliasing UB in idt.rs, deduplicate riscv64 target, fix qemu dep, rename test-aarch64 --- .github/workflows/deploy.yml | 1 - .github/workflows/main.yml | 2 +- examples/riscv/Makefile | 2 +- src/arch/x86_64/idt.rs | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 38d98c7..c953d28 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,7 +21,6 @@ jobs: aarch64-unknown-linux-gnu \ aarch64-unknown-none-softfloat \ riscv32imac-unknown-none-elf \ - riscv64imac-unknown-none-elf \ riscv64imac-unknown-none-elf do rustup target add ${target} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8538889..76c4b20 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,7 +54,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - run: cargo test --all-features - test-aarch64: + build-aarch64: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/examples/riscv/Makefile b/examples/riscv/Makefile index e8dac00..bba7539 100644 --- a/examples/riscv/Makefile +++ b/examples/riscv/Makefile @@ -41,7 +41,7 @@ header: clean: cargo clean -qemu: $(bin) +qemu: kernel qemu-system-$(arch) \ -machine virt \ -nographic \ diff --git a/src/arch/x86_64/idt.rs b/src/arch/x86_64/idt.rs index 62c6ee8..1be6f12 100644 --- a/src/arch/x86_64/idt.rs +++ b/src/arch/x86_64/idt.rs @@ -11,9 +11,9 @@ pub fn init() { } let idt = Box::leak(Box::new(InterruptDescriptorTable::new())); - let entries: &'static mut [Entry<()>; 256] = unsafe { core::mem::transmute_copy(&idt) }; + let entries = idt as *mut InterruptDescriptorTable as *mut Entry<()>; for i in 0..256 { - let opt = unsafe { entries[i].set_handler_addr(VirtAddr::new(VECTORS[i] as usize as u64)) }; + let opt = unsafe { (*entries.add(i)).set_handler_addr(VirtAddr::new(VECTORS[i] as *const () as usize as u64)) }; // Enable user space `int3` and `into` if i == 3 || i == 4 { opt.set_privilege_level(PrivilegeLevel::Ring3); From cc5ea960238ae67f1bcdb8a24053283a64fc094f Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 20:56:15 +0800 Subject: [PATCH 08/11] CI: restore aarch64 test with qemu-user --- .github/workflows/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76c4b20..19d8975 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,11 +54,14 @@ jobs: - uses: dtolnay/rust-toolchain@stable - run: cargo test --all-features - build-aarch64: + test-aarch64: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: aarch64-unknown-linux-gnu - - run: cargo build --target aarch64-unknown-linux-gnu + - run: sudo apt-get update && sudo apt-get install -y qemu-user + - run: cargo test --target aarch64-unknown-linux-gnu + env: + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64 From bf16c92c5707dc0ab084d20290bb7256c3e14bb1 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 20:57:39 +0800 Subject: [PATCH 09/11] Fix fmt: split long unsafe line in idt.rs --- src/arch/x86_64/idt.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/arch/x86_64/idt.rs b/src/arch/x86_64/idt.rs index 1be6f12..c373405 100644 --- a/src/arch/x86_64/idt.rs +++ b/src/arch/x86_64/idt.rs @@ -13,7 +13,10 @@ pub fn init() { let idt = Box::leak(Box::new(InterruptDescriptorTable::new())); let entries = idt as *mut InterruptDescriptorTable as *mut Entry<()>; for i in 0..256 { - let opt = unsafe { (*entries.add(i)).set_handler_addr(VirtAddr::new(VECTORS[i] as *const () as usize as u64)) }; + let opt = unsafe { + (*entries.add(i)) + .set_handler_addr(VirtAddr::new(VECTORS[i] as *const () as usize as u64)) + }; // Enable user space `int3` and `into` if i == 3 || i == 4 { opt.set_privilege_level(PrivilegeLevel::Ring3); From a7cd6ef249c9edae251c77ca32929e9ced56f01b Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 20:59:03 +0800 Subject: [PATCH 10/11] CI: install gcc-aarch64-linux-gnu for aarch64 test linking --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 19d8975..4cd318f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -61,7 +61,8 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: targets: aarch64-unknown-linux-gnu - - run: sudo apt-get update && sudo apt-get install -y qemu-user + - run: sudo apt-get update && sudo apt-get install -y qemu-user gcc-aarch64-linux-gnu - run: cargo test --target aarch64-unknown-linux-gnu env: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64 + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc From 1b109acf8d3a67197a8020426c77a4569ca9f2be Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 4 Jul 2026 20:59:49 +0800 Subject: [PATCH 11/11] CI: add QEMU_LD_PREFIX for aarch64 test runner --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4cd318f..ac96323 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,3 +66,4 @@ jobs: env: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64 CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc + QEMU_LD_PREFIX: /usr/aarch64-linux-gnu