diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 757da706..50fc9624 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,22 +9,24 @@ jobs: fail-fast: false matrix: rust-toolchain: [nightly] + targets: [x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust-toolchain }} components: rust-src, clippy, rustfmt + targets: ${{ matrix.targets }} - name: Setup ArceOS run: ./scripts/get_deps.sh - name: Check rust version run: rustc --version --verbose - name: Check code format continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }} - run: cargo fmt -- --check + run: cargo fmt --all -- --check - name: Clippy continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }} - run: cargo clippy + run: cargo clippy --target ${{ matrix.targets }} --all-features -- -D warnings -A clippy::new_without_default build: runs-on: ${{ matrix.os }} @@ -32,7 +34,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - arch: [x86_64] + arch: [x86_64, riscv64, aarch64] rust-toolchain: [nightly] steps: - uses: actions/checkout@v4 @@ -40,7 +42,7 @@ jobs: with: toolchain: ${{ matrix.rust-toolchain }} components: rust-src, llvm-tools - targets: x86_64-unknown-none + targets: x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none, aarch64-unknown-none-softfloat - uses: Swatinem/rust-cache@v2 - run: cargo install cargo-binutils - run: ./scripts/get_deps.sh @@ -48,12 +50,13 @@ jobs: run: make ARCH=${{ matrix.arch }} test-musl: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: + os: [ubuntu-latest] + arch: [x86_64, riscv64, aarch64] rust-toolchain: [nightly] - arch: [x86_64] env: qemu-version: 8.2.0 steps: diff --git a/apps/libc/Makefile b/apps/libc/Makefile index bc647f07..229196dc 100644 --- a/apps/libc/Makefile +++ b/apps/libc/Makefile @@ -12,11 +12,14 @@ ifeq ($(TARGET),musl) CFLAGS := -static ifeq ($(ARCH),x86_64) RUST_TARGET := x86_64-unknown-linux-musl + RUSTFLAGS := "" else ifeq ($(ARCH),aarch64) RUST_TARGET := aarch64-unknown-linux-musl + RUSTFLAGS := "-C linker=aarch64-linux-musl-gcc" else ifeq ($(ARCH),riscv64) $(warning "Warn: Rust musl target not supported for riscv64") - RUST_TARGET := + RUST_TARGET := "" + RUSTFLAGS := "" else $(error "Unknown ARCH") endif @@ -51,15 +54,17 @@ build_c: done build_rust: - @for app in $(shell find rust -name Cargo.toml); do \ - echo "Building $$(dirname $${app})"; \ - app_name=$$(basename $$(dirname $${app})); \ - cargo build --release --target $(RUST_TARGET) --manifest-path $${app} ; \ - cp $$(dirname $${app})/target/$(RUST_TARGET)/release/$${app_name} build/$(ARCH)/$${app_name}_rust ; \ - done + if [ -n $(RUST_TARGET) ]; then \ + for app in $(shell find rust -name Cargo.toml); do \ + echo "Building $$(dirname $${app})"; \ + app_name=$$(basename $$(dirname $${app})); \ + RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target $(RUST_TARGET) --manifest-path $${app} ; \ + cp $$(dirname $${app})/target/$(RUST_TARGET)/release/$${app_name} build/$(ARCH)/$${app_name}_rust ; \ + done \ + fi clean: - @rm -rf build/$(ARCH) + @rm -rf build @for app in $(shell find rust -name Cargo.toml); do \ app_name=$$(basename $$(dirname $${app})); \ cargo clean --manifest-path $${app} ; \ diff --git a/apps/nimbos/actual.out b/apps/nimbos/actual.out new file mode 100644 index 00000000..65c8c559 --- /dev/null +++ b/apps/nimbos/actual.out @@ -0,0 +1,25 @@ +make[1]: Entering directory '/home/yoimiya/OS/arceos-org/starry-next' +Set AX_ROOT (ArceOS directory) to /home/yoimiya/OS/arceos-org/starry-next/.arceos +make[2]: Entering directory '/home/yoimiya/OS/arceos-org/starry-next/.arceos' + Running on qemu... +qemu-system-aarch64 -m 128M -smp 1 -cpu cortex-a72 -machine virt -kernel /home/yoimiya/OS/arceos-org/starry-next/starry-next_aarch64-qemu-virt.bin -nographic + + d8888 .d88888b. .d8888b. + d88888 d88P" "Y88b d88P Y88b + d88P888 888 888 Y88b. + d88P 888 888d888 .d8888b .d88b. 888 888 "Y888b. + d88P 888 888P" d88P" d8P Y8b 888 888 "Y88b. + d88P 888 888 888 88888888 888 888 "888 + d8888888888 888 Y88b. Y8b. Y88b. .d88P Y88b d88P +d88P 888 888 "Y8888P "Y8888 "Y88888P" "Y8888P" + +arch = aarch64 +platform = aarch64-qemu-virt +target = aarch64-unknown-none-softfloat +smp = 1 +build_mode = release +log_level = off + +Hello, world! +make[2]: Leaving directory '/home/yoimiya/OS/arceos-org/starry-next/.arceos' +make[1]: Leaving directory '/home/yoimiya/OS/arceos-org/starry-next' diff --git a/apps/nimbos/c/CMakeLists.txt b/apps/nimbos/c/CMakeLists.txt index b581ab7e..0557bd27 100644 --- a/apps/nimbos/c/CMakeLists.txt +++ b/apps/nimbos/c/CMakeLists.txt @@ -60,9 +60,19 @@ foreach(PATH ${SRCS}) ) endforeach() -add_custom_command( - OUTPUT syscall_ids.h - COMMAND sed ARGS -n -e s/__NR_/SYS_/p - < ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.in - > ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h -) +# If arch is not x86_64, we need to use different syscall ids +if (NOT ${ARCH} STREQUAL x86_64) + add_custom_command( + OUTPUT syscall_ids.h + COMMAND sed ARGS -n -e s/__NR_/SYS_/p + < ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.no_x86.in + > ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h + ) +else() + add_custom_command( + OUTPUT syscall_ids.h + COMMAND sed ARGS -n -e s/__NR_/SYS_/p + < ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.in + > ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h + ) +endif() \ No newline at end of file diff --git a/apps/nimbos/c/lib/syscall_ids.h.no_x86.in b/apps/nimbos/c/lib/syscall_ids.h.no_x86.in new file mode 100644 index 00000000..e1c9c7c5 --- /dev/null +++ b/apps/nimbos/c/lib/syscall_ids.h.no_x86.in @@ -0,0 +1,11 @@ +#define __NR_read 63 +#define __NR_write 64 +#define __NR_exit 93 +#define __NR_yield 124 +#define __NR_getpid 172 +#define __NR_clone 220 +#define __NR_fork 220 +#define __NR_exec 221 +#define __NR_waitpid 260 +#define __NR_clock_gettime 403 +#define __NR_clock_nanosleep 407 diff --git a/build.rs b/build.rs index 64a49f64..40a278e5 100644 --- a/build.rs +++ b/build.rs @@ -102,10 +102,10 @@ fn gen_kernel_config(arch: &str) -> Result<()> { let key_name = key.to_uppercase().replace('-', "_"); match value { toml_edit::Value::Integer(i) => { - writeln!(f, "pub(crate) const {}: usize = {};", key_name, i)?; + writeln!(f, "pub const {}: usize = {};", key_name, i)?; } toml_edit::Value::String(s) => { - writeln!(f, "pub(crate) const {}: &str = \"{}\";", key_name, s)?; + writeln!(f, "pub const {}: &str = \"{}\";", key_name, s)?; } _ => { panic!("Unsupported value type"); diff --git a/src/mm.rs b/src/mm.rs index bae9490d..f5393734 100644 --- a/src/mm.rs +++ b/src/mm.rs @@ -19,7 +19,10 @@ use crate::{config, loader}; /// - The second return value is the top of the user stack. /// - The third return value is the address space of the user app. pub fn load_user_app(app_name: &str) -> AxResult<(VirtAddr, VirtAddr, AddrSpace)> { - let mut uspace = axmm::new_user_aspace()?; + let mut uspace = axmm::new_user_aspace( + VirtAddr::from_usize(config::USER_SPACE_BASE), + config::USER_SPACE_SIZE, + )?; let elf_info = loader::load_elf(app_name, uspace.base()); for segement in elf_info.segments { debug!(