Skip to content

Commit

Permalink
[feat] Support complie and test musl app on rv64 and aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Oct 22, 2024
1 parent ade3b4c commit 63721e0
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 34 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,54 @@ 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 }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64]
arch: [x86_64, riscv64, aarch64]
rust-toolchain: [nightly]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
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
- name: Build for ${{ matrix.arch }}
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:
Expand Down
21 changes: 13 additions & 8 deletions apps/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} ; \
Expand Down
22 changes: 16 additions & 6 deletions apps/nimbos/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 11 additions & 0 deletions apps/nimbos/c/lib/syscall_ids.h.no_x86.in
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions apps/nimbos/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cfg-if = "1.0"
39 changes: 28 additions & 11 deletions apps/nimbos/rust/src/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@ use crate::arch::syscall;

pub use crate::arch::sys_clone;

pub const SYSCALL_READ: usize = 0;
pub const SYSCALL_WRITE: usize = 1;
pub const SYSCALL_YIELD: usize = 24;
pub const SYSCALL_GETPID: usize = 39;
pub const SYSCALL_CLONE: usize = 56;
pub const SYSCALL_FORK: usize = 57;
pub const SYSCALL_EXEC: usize = 59;
pub const SYSCALL_EXIT: usize = 60;
pub const SYSCALL_WAITPID: usize = 61;
pub const SYSCALL_CLOCK_GETTIME: usize = 228;
pub const SYSCALL_CLOCK_NANOSLEEP: usize = 230;
cfg_if::cfg_if! {
if #[cfg(target_arch = "x86_64")] {
pub const SYSCALL_READ: usize = 0;
pub const SYSCALL_WRITE: usize = 1;
pub const SYSCALL_YIELD: usize = 24;
pub const SYSCALL_GETPID: usize = 39;
pub const SYSCALL_CLONE: usize = 56;
pub const SYSCALL_FORK: usize = 57;
pub const SYSCALL_EXEC: usize = 59;
pub const SYSCALL_EXIT: usize = 60;
pub const SYSCALL_WAITPID: usize = 61;
pub const SYSCALL_CLOCK_GETTIME: usize = 228;
pub const SYSCALL_CLOCK_NANOSLEEP: usize = 230;
}
else {
pub const SYSCALL_READ: usize = 63;
pub const SYSCALL_WRITE: usize = 64;
pub const SYSCALL_YIELD: usize = 124;
pub const SYSCALL_GETPID: usize = 172;
pub const SYSCALL_CLONE: usize = 220;
pub const SYSCALL_FORK: usize = 220;
pub const SYSCALL_EXEC: usize = 221;
pub const SYSCALL_EXIT: usize = 93;
pub const SYSCALL_WAITPID: usize = 260;
pub const SYSCALL_CLOCK_GETTIME: usize = 403;
pub const SYSCALL_CLOCK_NANOSLEEP: usize = 407;
}
}

pub fn sys_read(fd: usize, buffer: &mut [u8]) -> isize {
syscall(
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 63721e0

Please sign in to comment.