diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 6c6b307..99030d5 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "aarch64" version = "2.2.2" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 36ad8af..b6c5217 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -11,7 +11,9 @@ authors = [ "koumingyang <1761674434@qq.com>", "lcy1996 <992195697@qq.com>", "chenqiuhao ", - "maoyuchaxue " + "maoyuchaxue ", + "Jiajie Chen ", + "chyyuu " ] [features] diff --git a/kernel/Makefile b/kernel/Makefile index fbe27b6..c011e0e 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -250,7 +250,10 @@ else ifeq ($(arch), riscv32) src/arch/riscv32/atomic.patch @cargo xbuild $(build_args) else ifeq ($(arch), riscv64) - @./build-rv64 + @-patch -p0 -N -b \ + $(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \ + src/arch/riscv32/atomic.patch + @cargo xbuild $(build_args) else ifeq ($(arch), aarch64) @cargo xbuild $(build_args) endif diff --git a/kernel/build-rv64 b/kernel/build-rv64 deleted file mode 100755 index b4d467f..0000000 --- a/kernel/build-rv64 +++ /dev/null @@ -1,678 +0,0 @@ -#!/bin/bash -# The contents are adopted from xbuild verbose output. -# Output files are in target/${ARCH}/debug -# -# By default riscv64 is built. To build for riscv32, -# set the environment variable `RV32` to "1" -set -e - -if [[ ${RV32} = 1 ]]; then - TARGET_ARCH=riscv32 - CFLAGS="-march=rv32imac -mabi=ilp32" -else - TARGET_ARCH=riscv64 - CFLAGS="-march=rv64imac -mabi=lp64" -fi -UCORE_USER_IMAGE="../user/img/ucore-${TARGET_ARCH}.img" -LLC=$PWD/../tools/llc -RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/src -CARGO_PATH=~/.cargo -LLC_ARCH=${TARGET_ARCH} -OUTDIR=$PWD/target/${TARGET_ARCH}/debug -TARGET_JSON=$PWD/targets/${TARGET_ARCH}.json -CC=${TARGET_ARCH}-unknown-elf-gcc -AR=${TARGET_ARCH}-unknown-elf-ar -OBJCOPY=${TARGET_ARCH}-unknown-elf-objcopy -QEMU=qemu-system-${TARGET_ARCH} -export SMP=4 - -#============================================================================ -# Check env before build - -mkdir -p ${OUTDIR} - -# auto download K210 SDK lib -if [[ ${board} = k210 ]] && ! [[ -f ${OUTDIR}/libkendryte.a ]] -then - wget https://github.com/wangrunji0408/RustOS/releases/download/v0.1/libkendryte.a - mv libkendryte.a ${OUTDIR} -fi - -# auto download llc -if ! [[ -f ${LLC} ]] -then - cd ../tools -if [[ $(uname) = Linux ]]; then - wget https://github.com/wangrunji0408/RustOS/releases/download/v0.1/llc-ubuntu - mv llc-ubuntu llc -else - wget https://github.com/wangrunji0408/RustOS/releases/download/v0.1/llc-macOS - mv llc-macOS llc -fi - chmod +x llc - cd ../kernel -fi - -# if some crates are not exist, build for riscv32 first -if ! [[ -f $CARGO_PATH/git/checkouts/bit-vec-437fa4a002bd318d/9861a58/src/lib.rs ]] || ! [[ -z ${TRAVIS_OS_NAME} ]] -then - make kernel arch=riscv32 board=none -fi - -#============================================================================ -# Stupid long implementation - -gen_full_rlib() { - PWD0=${PWD} - cd ${OUTDIR} - for X in ${CNAME}.*bc - do - ${LLC} -march=${LLC_ARCH} -filetype=obj -mattr=+m,+c ${X} - done - for X in ${CNAME}.*o - do - ${AR} r lib${CNAME}.rlib ${X} - done - cd ${PWD0} -} - -# -# Basic dependencies -CNAME=core -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name ${CNAME} $RUST_SRC_PATH/libcore/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=3 \ - -C debuginfo=2 \ - -Z force-unstable-if-unmarked \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON -gen_full_rlib -fi - -# Note: In recent nightly, compiler_builtins has been removed from rust_src. -CNAME=compiler_builtins -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then - if [[ -d $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.5 ]] - then - COMPILER_BUILTINS_PATH=$CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.5 - else - echo "Cannot find compiler_builtins crate! Please file an issue report" - fi - - rustc --crate-name compiler_builtins ${COMPILER_BUILTINS_PATH}/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=3 \ - -C debuginfo=2 \ - -Z force-unstable-if-unmarked \ - --cfg 'feature="compiler-builtins"' \ - --cfg 'feature="mem"' \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} - gen_full_rlib -fi - -CNAME=alloc -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name alloc $RUST_SRC_PATH/liballoc/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=3 \ - -C debuginfo=2 \ - -Z force-unstable-if-unmarked \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} -gen_full_rlib -fi - - -CNAME=semver_parser -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name semver_parser $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/semver-parser-0.7.0/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=cfg_if -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name cfg_if $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.6/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=spin -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name spin $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/spin-0.4.10/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="const_fn"' \ - --cfg 'feature="default"' \ - --cfg 'feature="once"' \ - --cfg 'feature="unstable"' \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=static_assertions -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name static_assertions $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/static_assertions-0.3.1/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=bit_field -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name bit_field $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/bit_field-0.9.0/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=zero -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name zero $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/zero-0.1.2/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=bit_vec -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name bit_vec $CARGO_PATH/git/checkouts/bit-vec-437fa4a002bd318d/9861a58*/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=bitflags -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name bitflags $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/bitflags-1.0.4/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="default"' \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=managed -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name managed $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/managed-0.7.1/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="alloc"' \ - --cfg 'feature="map"' \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=device_tree -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name device_tree $CARGO_PATH/git/checkouts/device_tree-rs-7c4f9e86f346d07b/1bd9b4d*/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=byteorder -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name byteorder $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.1/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=log -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name log $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/log-0.4.6/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=smoltcp -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name smoltcp $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/smoltcp-0.5.0/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="alloc"' \ - --cfg 'feature="log"' \ - --cfg 'feature="managed"' \ - --cfg 'feature="proto-igmp"' \ - --cfg 'feature="proto-ipv4"' \ - --cfg 'feature="socket-icmp"' \ - --cfg 'feature="socket-tcp"' \ - --cfg 'feature="socket-udp"' \ - --extern bitflags=${OUTDIR}/libbitflags.rlib \ - --extern byteorder=${OUTDIR}/libbyteorder.rlib \ - --extern log=${OUTDIR}/liblog.rlib \ - --extern managed=${OUTDIR}/libmanaged.rlib \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=volatile -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name volatile $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/volatile-0.2.5/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=once -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name once $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/once-0.3.3/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=bbl -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name bbl $PWD/../crate/bbl/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} -gen_full_rlib -fi - -CNAME=linked_list_allocator -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name linked_list_allocator $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/linked_list_allocator-0.6.3/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="default"' \ - --cfg 'feature="spin"' \ - --cfg 'feature="use_spin"' \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=lazy_static -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name lazy_static $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.2.0/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="spin"' \ - --cfg 'feature="spin_no_std"' \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi -# - -CNAME=xmas_elf -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name xmas_elf $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/xmas-elf-0.6.2/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=bit_allocator -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name bit_allocator $PWD/../crate/bit-allocator/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} -gen_full_rlib -fi - - -CNAME=simple_filesystem -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --edition=2018 --crate-name simple_filesystem $CARGO_PATH/git/checkouts/simplefilesystem-rust-868ccb44dbeefdea/48b3c26*/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --extern bit_vec=${OUTDIR}/libbit_vec.rlib \ - --extern spin=${OUTDIR}/libspin.rlib \ - --extern static_assertions=${OUTDIR}/libstatic_assertions.rlib \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=rcore_process -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -M_MODE="" rustc --edition=2018 --crate-name rcore_process $PWD/../crate/process/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - --extern log=${OUTDIR}/liblog.rlib \ - --extern spin=${OUTDIR}/libspin.rlib \ - -L ${OUTDIR} -gen_full_rlib -fi - -CNAME=rcore_memory -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --edition=2018 --crate-name rcore_memory $PWD/../crate/memory/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - --extern log=${OUTDIR}/liblog.rlib \ - -L ${OUTDIR} -gen_full_rlib -fi - -CNAME=semver -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name semver $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/semver-0.9.0/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --cfg 'feature="default"' \ - --out-dir ${OUTDIR} \ - -L ${OUTDIR} \ - --extern semver_parser=${OUTDIR}/libsemver_parser.rlib \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=rustc_version -# omit build_script_build -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name rustc_version $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/rustc_version-0.2.3/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - -L ${OUTDIR} \ - --extern semver=${OUTDIR}/libsemver.rlib \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=bare_metal -# omit build_script_build -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name bare_metal $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/bare-metal-0.2.4/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --cap-lints allow -gen_full_rlib -fi - -CNAME=riscv -if ! [[ -f ${OUTDIR}/${CNAME}.o ]] -then -rustc --crate-name riscv $CARGO_PATH/git/checkouts/riscv-1e845b622ce46f1d/ac09fc6*/src/lib.rs \ - --color always --crate-type lib --emit=metadata,llvm-bc \ - -C opt-level=1 \ - -C debuginfo=2 \ - -C debug-assertions=on \ - --out-dir ${OUTDIR} \ - --target $TARGET_JSON \ - -L ${OUTDIR} \ - --extern bare_metal=${OUTDIR}/libbare_metal.rlib \ - --extern bit_field=${OUTDIR}/libbit_field.rlib \ - --extern bitflags=${OUTDIR}/libbitflags.rlib \ - --extern log=${OUTDIR}/liblog.rlib \ - --cap-lints allow -gen_full_rlib -fi - - -# Hand generate build.rs -if ! [[ -f ${OUTDIR}/libatomic_rt.a ]] -then -${CC} src/arch/riscv32/compiler_rt.c ${CFLAGS} -O3 -Wno-builtin-declaration-mismatch -c -o ${OUTDIR}/compiler_rt.o -${AR} r ${OUTDIR}/libatomic_rt.a ${OUTDIR}/compiler_rt.o -fi - -if ! [[ -f ${OUTDIR}/libsfsimg.a ]] -then -cat >${OUTDIR}/sfsimg.S < { - println!("cargo:rerun-if-changed=src/arch/riscv32/compiler_rt.c"); - cc::Build::new() - .file("src/arch/riscv32/compiler_rt.c") - .flag("-march=rv32imac") - .flag("-mabi=ilp32") - .flag("-Wno-builtin-declaration-mismatch") - .flag("-O3") - .compile("atomic_rt"); if let Ok(file_path) = gen_sfsimg_asm() { cc::Build::new() .file(&file_path) @@ -29,6 +21,15 @@ fn main() { .compile("sfsimg"); } } + "riscv64" => { + if let Ok(file_path) = gen_sfsimg_asm() { + cc::Build::new() + .file(&file_path) + .flag("-march=rv64imac") + .flag("-mabi=lp64") + .compile("sfsimg"); + } + } "aarch64" => { if let Ok(file_path) = gen_sfsimg_asm() { cc::Build::new().file(&file_path).compile("sfsimg"); diff --git a/kernel/src/arch/riscv32/compiler_rt.c b/kernel/src/arch/riscv32/compiler_rt.c deleted file mode 100644 index 8125759..0000000 --- a/kernel/src/arch/riscv32/compiler_rt.c +++ /dev/null @@ -1,135 +0,0 @@ -// http://llvm.org/docs/Atomics.html#libcalls-atomic - -inline void mb() { - __asm__ __volatile__("fence" ::: "memory"); -} - -typedef unsigned u32; - -// K210 doesn't support atomic operation on 0x40000000 (io port) -// We have to detect it and move it to 0x80000000 -inline u32* fix_ptr32(u32 *ptr) { - return ptr < (u32*)0x80000000? - ptr + 0x40000000 / sizeof(u32): - ptr; -} - -u32 __atomic_load_1(u32 *ptr) { - ptr = fix_ptr32(ptr); - return *ptr; -} - -u32 __atomic_load_2(u32 *ptr) { - ptr = fix_ptr32(ptr); - return *ptr; -} - -// relaxed -u32 __atomic_load_4(u32 *ptr) { - ptr = fix_ptr32(ptr); - return *ptr; -} - -// release -void __atomic_store_4(u32 *ptr, u32 val) { - ptr = fix_ptr32(ptr); - mb(); - __asm__ __volatile__("amoswap.w zero, %0, (%1)" :: "r"(val), "r"(ptr) : "memory"); -} - -// strong, acquire -char __atomic_compare_exchange_4(u32* ptr, u32* expected, u32 desired) { - ptr = fix_ptr32(ptr); - u32 val, expect = *expected, result, ret; - while(1) { - __asm__ __volatile__("lr.w.aq %0, (%1)" : "=r"(val) : "r"(ptr) : "memory"); - - ret = val == expect; - if(!ret) { - // *expected should always equal to the previous value of *ptr - *expected = val; - return ret; - } - - // Try: *ptr = desired. If success, result == 0, otherwise result != 0. - __asm__ __volatile__("sc.w.aq %0, %1, (%2)" : "=r"(result) : "r"(desired), "r"(ptr) : "memory"); - if(result == 0) { - return ret; - } - } -} - -u32 __atomic_fetch_add_4(u32* ptr, u32 val) { - ptr = fix_ptr32(ptr); - u32 res; - __asm__ __volatile__("amoadd.w %0, %1, (%2)" : "=r"(res) : "r"(val), "r"(ptr) : "memory"); - return res; -} - -u32 __atomic_fetch_sub_4(u32* ptr, u32 val) { - ptr = fix_ptr32(ptr); - u32 res; - __asm__ __volatile__("amoadd.w %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory"); - return res; -} - -#if __riscv_xlen == 64 -typedef unsigned long long u64; - -// K210 doesn't support atomic operation on 0x40000000 (io port) -// We have to detect it and move it to 0x80000000 -inline u64* fix_ptr64(u64 *ptr) { - return ptr < (u64*)0x80000000? - ptr + 0x40000000 / sizeof(u64): - ptr; -} - -// relaxed -u64 __atomic_load_8(u64 *ptr) { - ptr = fix_ptr64(ptr); - return *ptr; -} - -// release -void __atomic_store_8(u64 *ptr, u64 val) { - ptr = fix_ptr64(ptr); - mb(); - __asm__ __volatile__("amoswap.d zero, %0, (%1)" :: "r"(val), "r"(ptr) : "memory"); -} - -// strong, acquire -char __atomic_compare_exchange_8(u64* ptr, u64* expected, u64 desired) { - ptr = fix_ptr64(ptr); - u64 val, expect = *expected, result, ret; - while(1) { - __asm__ __volatile__("lr.d.aq %0, (%1)" : "=r"(val) : "r"(ptr) : "memory"); - - ret = val == expect; - if(!ret) { - // *expected should always equal to the previous value of *ptr - *expected = val; - return ret; - } - - // Try: *ptr = desired. If success, result == 0, otherwise result != 0. - __asm__ __volatile__("sc.d.aq %0, %1, (%2)" : "=r"(result) : "r"(desired), "r"(ptr) : "memory"); - if(result == 0) { - return ret; - } - } -} - -u64 __atomic_fetch_add_8(u64* ptr, u64 val) { - ptr = fix_ptr64(ptr); - u64 res; - __asm__ __volatile__("amoadd.d %0, %1, (%2)" : "=r"(res) : "r"(val), "r"(ptr) : "memory"); - return res; -} - -u64 __atomic_fetch_sub_8(u64* ptr, u64 val) { - ptr = fix_ptr64(ptr); - u64 res; - __asm__ __volatile__("amoadd.d %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory"); - return res; -} -#endif diff --git a/kernel/targets/riscv32.json b/kernel/targets/riscv32.json index 9430baf..377a0e5 100644 --- a/kernel/targets/riscv32.json +++ b/kernel/targets/riscv32.json @@ -7,7 +7,7 @@ "os": "none", "arch": "riscv32", "cpu": "generic-rv32", - "features": "", + "features": "+m,+a,+c", "max-atomic-width": "32", "linker": "rust-lld", "linker-flavor": "ld.lld", diff --git a/kernel/targets/riscv64.json b/kernel/targets/riscv64.json index 7cf840a..7448021 100644 --- a/kernel/targets/riscv64.json +++ b/kernel/targets/riscv64.json @@ -7,8 +7,8 @@ "os": "none", "arch": "riscv64", "cpu": "generic-rv64", - "features": "", - "max-atomic-width": "32", + "features": "+m,+a,+c", + "max-atomic-width": "64", "linker": "rust-lld", "linker-flavor": "ld.lld", "pre-link-args": {