compile rv64 pass on macOS

master
WangRunji 6 years ago
parent 02bd2b2317
commit d4b6cc1082

@ -9,12 +9,11 @@
"cpu": "generic-rv64", "cpu": "generic-rv64",
"features": "", "features": "",
"max-atomic-width": "32", "max-atomic-width": "32",
"linker": "riscv64-unknown-elf-ld", "linker": "rust-lld",
"linker-flavor": "ld", "linker-flavor": "ld.lld",
"pre-link-args": { "pre-link-args": {
"ld": [ "ld.lld": [
"-Tboot/linker.ld", "-Tsrc/arch/riscv32/boot/linker64.ld"
"-melf64lriscv"
] ]
}, },
"executables": true, "executables": true,

@ -6,7 +6,7 @@
# $ ./run-qemu-script-custom-llc # $ ./run-qemu-script-custom-llc
set -e set -e
if ! [ -d outdir ] if ! [[ -d outdir ]]
then then
echo "You have to \`mkdir outdir\` first." echo "You have to \`mkdir outdir\` first."
echo "If you know what you're doing, do this yourself, otherwise quit." echo "If you know what you're doing, do this yourself, otherwise quit."
@ -14,11 +14,13 @@ then
fi fi
# CONFIGURATIONS # CONFIGURATIONS
export LLC=~dzy/llvm/rust-llvm-build/bin/llc export LLC=$PWD/../../llvm/build/bin/llc
export LLC_ARCH=riscv32 export LLC_ARCH=riscv64
export RUSTUP_SRCDIR=/home/dzy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/src
export TARGET_JSON=$PWD/riscv32-blog_os.json export TARGET_JSON=$PWD/riscv64-blog_os.json
export CARGO_PATH=/home/dzy/.cargo export CARGO_PATH=~/.cargo
export CC=riscv64-unknown-elf-gcc
export AR=riscv64-unknown-elf-ar
#============================================================================ #============================================================================
@ -35,7 +37,7 @@ gen_full_rlib() {
done done
for X in ${CNAME}.*o for X in ${CNAME}.*o
do do
ar r lib${CNAME}.rlib ${X} ${AR} r lib${CNAME}.rlib ${X}
done done
cd .. cd ..
} }
@ -43,19 +45,24 @@ gen_full_rlib() {
# #
# Basic dependencies # Basic dependencies
CNAME=core CNAME=core
rustc --crate-name ${CNAME} $RUSTUP_SRCDIR/libcore/lib.rs \ if ! [[ -f outdir/${CNAME}.o ]]
--color never --crate-type lib --emit=metadata,llvm-ir \ then
rustc --crate-name ${CNAME} $RUST_SRC_PATH/libcore/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=3 \ -C opt-level=3 \
-C debuginfo=2 \ -C debuginfo=2 \
-Z force-unstable-if-unmarked \ -Z force-unstable-if-unmarked \
--out-dir $PWD/outdir \ --out-dir $PWD/outdir \
--target $TARGET_JSON --target $TARGET_JSON
gen_full_rlib gen_full_rlib
fi
# Note: In recent nightly, compiler_builtins has been removed from rust_src.
CNAME=compiler_builtins CNAME=compiler_builtins
# omit build_script_build if ! [[ -f outdir/${CNAME}.o ]]
rustc --crate-name compiler_builtins $RUSTUP_SRCDIR/libcompiler_builtins/src/lib.rs \ then
--color never --crate-type lib --emit=metadata,llvm-ir \ rustc --crate-name compiler_builtins $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.2/src/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=3 \ -C opt-level=3 \
-C debuginfo=2 \ -C debuginfo=2 \
-Z force-unstable-if-unmarked \ -Z force-unstable-if-unmarked \
@ -65,10 +72,13 @@ rustc --crate-name compiler_builtins $RUSTUP_SRCDIR/libcompiler_builtins/src/lib
--target $TARGET_JSON \ --target $TARGET_JSON \
-L $PWD/outdir -L $PWD/outdir
gen_full_rlib gen_full_rlib
fi
CNAME=alloc CNAME=alloc
rustc --crate-name alloc $RUSTUP_SRCDIR/liballoc/lib.rs \ if ! [[ -f outdir/${CNAME}.o ]]
--color never --crate-type lib --emit=metadata,llvm-ir \ then
rustc --crate-name alloc $RUST_SRC_PATH/liballoc/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=3 \ -C opt-level=3 \
-C debuginfo=2 \ -C debuginfo=2 \
-Z force-unstable-if-unmarked \ -Z force-unstable-if-unmarked \
@ -76,11 +86,14 @@ rustc --crate-name alloc $RUSTUP_SRCDIR/liballoc/lib.rs \
--target $TARGET_JSON \ --target $TARGET_JSON \
-L $PWD/outdir -L $PWD/outdir
gen_full_rlib gen_full_rlib
fi
CNAME=semver_parser 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 \ rustc --crate-name semver_parser $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/semver-parser-0.7.0/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -88,10 +101,13 @@ rustc --crate-name semver_parser $CARGO_PATH/registry/src/github.com-1ecc6299db9
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=cfg_if 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 \ rustc --crate-name cfg_if $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/cfg-if-0.1.6/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -100,10 +116,13 @@ rustc --crate-name cfg_if $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/c
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=spin 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 \ rustc --crate-name spin $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/spin-0.4.10/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -116,21 +135,13 @@ rustc --crate-name spin $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/spi
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=cc
rustc --crate-name cc $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/cc-1.0.25/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \
-C debuginfo=2 \
-C debug-assertions=on \
--out-dir $PWD/outdir \
-L $PWD/outdir \
--cap-lints allow
gen_full_rlib
CNAME=static_assertions 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 \ rustc --crate-name static_assertions $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/static_assertions-0.3.1/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -139,10 +150,13 @@ rustc --crate-name static_assertions $CARGO_PATH/registry/src/github.com-1ecc629
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=bit_field 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 \ rustc --crate-name bit_field $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/bit_field-0.9.0/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -151,10 +165,13 @@ rustc --crate-name bit_field $CARGO_PATH/registry/src/github.com-1ecc6299db9ec82
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=zero 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 \ rustc --crate-name zero $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/zero-0.1.2/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -163,10 +180,13 @@ rustc --crate-name zero $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/zer
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=bit_vec CNAME=bit_vec
rustc --crate-name bit_vec $CARGO_PATH/git/checkouts/bit-vec-437fa4a002bd318d/9861a58d6e76/src/lib.rs \ if ! [[ -f outdir/${CNAME}.o ]]
--color never --crate-type lib --emit=metadata,llvm-ir \ 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-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -175,10 +195,13 @@ rustc --crate-name bit_vec $CARGO_PATH/git/checkouts/bit-vec-437fa4a002bd318d/98
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=bitflags 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 \ rustc --crate-name bitflags $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/bitflags-1.0.4/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -188,10 +211,13 @@ rustc --crate-name bitflags $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=volatile 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 \ rustc --crate-name volatile $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/volatile-0.2.5/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -200,10 +226,13 @@ rustc --crate-name volatile $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=once 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 \ rustc --crate-name once $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/once-0.3.3/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -212,10 +241,13 @@ rustc --crate-name once $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/onc
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=bbl CNAME=bbl
if ! [[ -f outdir/${CNAME}.o ]]
then
rustc --crate-name bbl $PWD/../crate/bbl/src/lib.rs \ rustc --crate-name bbl $PWD/../crate/bbl/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -223,10 +255,13 @@ rustc --crate-name bbl $PWD/../crate/bbl/src/lib.rs \
--target $TARGET_JSON \ --target $TARGET_JSON \
-L $PWD/outdir -L $PWD/outdir
gen_full_rlib gen_full_rlib
fi
CNAME=log 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 \ rustc --crate-name log $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/log-0.4.6/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -235,10 +270,13 @@ rustc --crate-name log $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/log-
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=linked_list_allocator 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 \ rustc --crate-name linked_list_allocator $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/linked_list_allocator-0.6.3/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -250,10 +288,13 @@ rustc --crate-name linked_list_allocator $CARGO_PATH/registry/src/github.com-1ec
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=lazy_static 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 \ rustc --crate-name lazy_static $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.2.0/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -264,11 +305,14 @@ rustc --crate-name lazy_static $CARGO_PATH/registry/src/github.com-1ecc6299db9ec
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
# #
CNAME=xmas_elf 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 \ rustc --crate-name xmas_elf $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/xmas-elf-0.6.2/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -277,10 +321,13 @@ rustc --crate-name xmas_elf $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=bit_allocator CNAME=bit_allocator
if ! [[ -f outdir/${CNAME}.o ]]
then
rustc --crate-name bit_allocator $PWD/../crate/bit-allocator/src/lib.rs \ rustc --crate-name bit_allocator $PWD/../crate/bit-allocator/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -288,11 +335,14 @@ rustc --crate-name bit_allocator $PWD/../crate/bit-allocator/src/lib.rs \
--target $TARGET_JSON \ --target $TARGET_JSON \
-L $PWD/outdir -L $PWD/outdir
gen_full_rlib gen_full_rlib
fi
CNAME=simple_filesystem CNAME=simple_filesystem
rustc --edition=2018 --crate-name simple_filesystem $CARGO_PATH/git/checkouts/simplefilesystem-rust-868ccb44dbeefdea/249383f7e3f1/src/lib.rs \ if ! [[ -f outdir/${CNAME}.o ]]
--color never --crate-type lib --emit=metadata,llvm-ir \ then
rustc --edition=2018 --crate-name simple_filesystem $CARGO_PATH/git/checkouts/simplefilesystem-rust-868ccb44dbeefdea/249383f*/src/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -304,10 +354,13 @@ rustc --edition=2018 --crate-name simple_filesystem $CARGO_PATH/git/checkouts/si
--extern static_assertions=$PWD/outdir/libstatic_assertions.rlib \ --extern static_assertions=$PWD/outdir/libstatic_assertions.rlib \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=ucore_process CNAME=ucore_process
if ! [[ -f outdir/${CNAME}.o ]]
then
rustc --edition=2018 --crate-name ucore_process $PWD/../crate/process/src/lib.rs \ rustc --edition=2018 --crate-name ucore_process $PWD/../crate/process/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -317,10 +370,13 @@ rustc --edition=2018 --crate-name ucore_process $PWD/../crate/process/src/lib.rs
--extern spin=$PWD/outdir/libspin.rlib \ --extern spin=$PWD/outdir/libspin.rlib \
-L $PWD/outdir -L $PWD/outdir
gen_full_rlib gen_full_rlib
fi
CNAME=ucore_memory CNAME=ucore_memory
if ! [[ -f outdir/${CNAME}.o ]]
then
rustc --edition=2018 --crate-name ucore_memory $PWD/../crate/memory/src/lib.rs \ rustc --edition=2018 --crate-name ucore_memory $PWD/../crate/memory/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -329,10 +385,13 @@ rustc --edition=2018 --crate-name ucore_memory $PWD/../crate/memory/src/lib.rs \
--extern log=$PWD/outdir/liblog.rlib \ --extern log=$PWD/outdir/liblog.rlib \
-L $PWD/outdir -L $PWD/outdir
gen_full_rlib gen_full_rlib
fi
CNAME=semver 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 \ rustc --crate-name semver $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/semver-0.9.0/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -342,11 +401,14 @@ rustc --crate-name semver $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/s
--extern semver_parser=$PWD/outdir/libsemver_parser.rlib \ --extern semver_parser=$PWD/outdir/libsemver_parser.rlib \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=rustc_version CNAME=rustc_version
# omit build_script_build # 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 \ rustc --crate-name rustc_version $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/rustc_version-0.2.3/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -355,11 +417,14 @@ rustc --crate-name rustc_version $CARGO_PATH/registry/src/github.com-1ecc6299db9
--extern semver=$PWD/outdir/libsemver.rlib \ --extern semver=$PWD/outdir/libsemver.rlib \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=bare_metal CNAME=bare_metal
# omit build_script_build # 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 \ rustc --crate-name bare_metal $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/bare-metal-0.2.4/src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -368,10 +433,13 @@ rustc --crate-name bare_metal $CARGO_PATH/registry/src/github.com-1ecc6299db9ec8
-L $PWD/outdir \ -L $PWD/outdir \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
CNAME=riscv CNAME=riscv
rustc --crate-name riscv $CARGO_PATH/git/checkouts/riscv-1e845b622ce46f1d/966eb26d5e8d/src/lib.rs \ if ! [[ -f outdir/${CNAME}.o ]]
--color never --crate-type lib --emit=metadata,llvm-ir \ then
rustc --crate-name riscv $CARGO_PATH/git/checkouts/riscv-1e845b622ce46f1d/1f59ef7*/src/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -383,11 +451,12 @@ rustc --crate-name riscv $CARGO_PATH/git/checkouts/riscv-1e845b622ce46f1d/966eb2
--extern bitflags=$PWD/outdir/libbitflags.rlib \ --extern bitflags=$PWD/outdir/libbitflags.rlib \
--cap-lints allow --cap-lints allow
gen_full_rlib gen_full_rlib
fi
# Hand generate build.rs # Hand generate build.rs
riscv32-unknown-elf-gcc src/arch/riscv32/compiler_rt.c -march=rv32ia -mabi=ilp32 -c -o outdir/compiler_rt.o ${CC} src/arch/riscv32/compiler_rt.c -march=rv64ia -mabi=lp64 -c -o outdir/compiler_rt.o
ar r outdir/libatomic_rt.a outdir/compiler_rt.o ${AR} r outdir/libatomic_rt.a outdir/compiler_rt.o
cat >outdir/sfsimg.S <<EOF cat >outdir/sfsimg.S <<EOF
.section .rodata .section .rodata
@ -398,15 +467,17 @@ _user_img_start:
.incbin "../user/build/user-riscv32.img" .incbin "../user/build/user-riscv32.img"
_user_img_end: _user_img_end:
EOF EOF
riscv32-unknown-elf-gcc outdir/sfsimg.S -march=rv32ia -mabi=ilp32 -c -o outdir/sfsimg.o ${CC} outdir/sfsimg.S -march=rv64ia -mabi=lp64 -c -o outdir/sfsimg.o
ar r outdir/libsfsimg.a outdir/sfsimg.o ${AR} r outdir/libsfsimg.a outdir/sfsimg.o
make sfsimg make sfsimg
CNAME=ucore CNAME=ucore
if ! [[ -f outdir/${CNAME}.o ]]
then
rustc --edition=2018 --crate-name ucore src/lib.rs \ rustc --edition=2018 --crate-name ucore src/lib.rs \
--color never --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-ir \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -431,9 +502,10 @@ rustc --edition=2018 --crate-name ucore src/lib.rs \
-L native=outdir -l static=sfsimg -l static=atomic_rt -L native=outdir -l static=sfsimg -l static=atomic_rt
gen_full_rlib gen_full_rlib
fi
rustc --edition=2018 --crate-name ucore src/main.rs \ rustc --edition=2018 --crate-name ucore src/main.rs \
--color never --crate-type bin --emit=link \ --color always --crate-type bin --emit=link \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -461,10 +533,10 @@ rustc --edition=2018 --crate-name ucore src/main.rs \
cd ../riscv-pk && mkdir -p build && cd build cd ../riscv-pk && mkdir -p build && cd build
../configure \ ../configure \
--with-arch=rv32imac \ --with-arch=rv64imac \
--disable-fp-emulation \ --disable-fp-emulation \
--host=riscv32-unknown-elf \ --host=riscv64-unknown-elf \
--with-payload=../../kernel/outdir/ucore --with-payload=../../kernel/outdir/ucore
make make
@ -472,6 +544,4 @@ cp bbl ../../kernel/outdir/kernel.bin
cd ../../kernel cd ../../kernel
qemu-system-riscv32 -smp cores=4 -nographic -machine virt -kernel outdir/kernel.bin || [ $? -eq 11 ] # run qemu and assert it exit 11 qemu-system-riscv64 -smp cores=4 -nographic -machine virt -kernel outdir/kernel.bin

@ -1,5 +1,17 @@
// http://llvm.org/docs/Atomics.html#libcalls-atomic // http://llvm.org/docs/Atomics.html#libcalls-atomic
int __atomic_load_1(int *src) {
int res = 0;
__asm__ __volatile__("amoadd.w.rl %0, zero, (%1)" : "=r"(res) : "r"(src) : "memory");
return res;
}
int __atomic_load_2(int *src) {
int res = 0;
__asm__ __volatile__("amoadd.w.rl %0, zero, (%1)" : "=r"(res) : "r"(src) : "memory");
return res;
}
int __atomic_load_4(int *src) { int __atomic_load_4(int *src) {
int res = 0; int res = 0;
__asm__ __volatile__("amoadd.w.rl %0, zero, (%1)" : "=r"(res) : "r"(src) : "memory"); __asm__ __volatile__("amoadd.w.rl %0, zero, (%1)" : "=r"(res) : "r"(src) : "memory");
@ -36,3 +48,42 @@ int __atomic_fetch_sub_4(int* ptr, int val) {
__asm__ __volatile__("amoadd.w.rl %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory"); __asm__ __volatile__("amoadd.w.rl %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory");
return res; return res;
} }
typedef unsigned long long u64;
u64 __atomic_load_8(u64 *src) {
u64 res = 0;
__asm__ __volatile__("amoadd.d.rl %0, zero, (%1)" : "=r"(res) : "r"(src) : "memory");
return res;
}
u64 __atomic_store_8(u64 *dst, u64 val) {
__asm__ __volatile__("amoswap.d.aq zero, %0, (%1)" :: "r"(val), "r"(dst) : "memory");
}
char __atomic_compare_exchange_8(u64* dst, u64* expected, u64 desired) {
u64 val;
// val = *dst
__asm__ __volatile__("lr.d %0, (%1)" : "=r"(val) : "r"(dst) : "memory");
if (val == *expected) {
u64 result;
// Try: *dst = desired. If success, result = 0, otherwise result != 0.
__asm__ __volatile__("sc.d %0, %1, (%2)" : "=r"(result) : "r"(desired), "r"(dst) : "memory");
return result == 0;
}
// *expected should always equal to the previous value of *dst
*expected = val;
return 0;
}
u64 __atomic_fetch_add_8(u64* ptr, u64 val) {
u64 res;
__asm__ __volatile__("amoadd.d.rl %0, %1, (%2)" : "=r"(res) : "r"(val), "r"(ptr) : "memory");
return res;
}
u64 __atomic_fetch_sub_8(u64* ptr, u64 val) {
u64 res;
__asm__ __volatile__("amoadd.d.rl %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory");
return res;
}

@ -18,6 +18,7 @@ use log::*;
* setup page table in the frame * setup page table in the frame
*/ */
// need 1 page // need 1 page
#[cfg(target_arch = "riscv32")]
pub fn setup_page_table(frame: Frame) { pub fn setup_page_table(frame: Frame) {
let p2 = unsafe { &mut *(frame.start_address().as_u32() as *mut RvPageTable) }; let p2 = unsafe { &mut *(frame.start_address().as_u32() as *mut RvPageTable) };
p2.zero(); p2.zero();
@ -37,6 +38,11 @@ pub fn setup_page_table(frame: Frame) {
info!("setup init page table end"); info!("setup init page table end");
} }
#[cfg(target_arch = "riscv64")]
pub fn setup_page_table(_frame: Frame) {
unimplemented!();
}
pub struct ActivePageTable(RecursivePageTable<'static>); pub struct ActivePageTable(RecursivePageTable<'static>);
pub struct PageEntry(PageTableEntry); pub struct PageEntry(PageTableEntry);
@ -274,7 +280,7 @@ impl InactivePageTable for InactivePageTable0 {
let new_frame = self.p2_frame.clone(); let new_frame = self.p2_frame.clone();
debug!("switch table {:x?} -> {:x?}", old_frame, new_frame); debug!("switch table {:x?} -> {:x?}", old_frame, new_frame);
if old_frame != new_frame { if old_frame != new_frame {
satp::set(satp::Mode::Sv32, 0, new_frame); satp::set(SATP_MODE, 0, new_frame);
sfence_vma_all(); sfence_vma_all();
} }
} }
@ -292,13 +298,13 @@ impl InactivePageTable for InactivePageTable0 {
let new_frame = self.p2_frame.clone(); let new_frame = self.p2_frame.clone();
debug!("switch table {:x?} -> {:x?}", old_frame, new_frame); debug!("switch table {:x?} -> {:x?}", old_frame, new_frame);
if old_frame != new_frame { if old_frame != new_frame {
satp::set(satp::Mode::Sv32, 0, new_frame); satp::set(SATP_MODE, 0, new_frame);
sfence_vma_all(); sfence_vma_all();
} }
let target = f(); let target = f();
debug!("switch table {:x?} -> {:x?}", new_frame, old_frame); debug!("switch table {:x?} -> {:x?}", new_frame, old_frame);
if old_frame != new_frame { if old_frame != new_frame {
satp::set(satp::Mode::Sv32, 0, old_frame); satp::set(SATP_MODE, 0, old_frame);
sfence_vma_all(); sfence_vma_all();
} }
target target
@ -323,6 +329,11 @@ impl InactivePageTable for InactivePageTable0 {
} }
} }
#[cfg(target_arch = "riscv32")]
const SATP_MODE: satp::Mode = satp::Mode::Sv32;
#[cfg(target_arch = "riscv64")]
const SATP_MODE: satp::Mode = satp::Mode::Sv39;
impl InactivePageTable0 { impl InactivePageTable0 {
/* /*
* @brief: * @brief:

@ -10,7 +10,7 @@ use crate::sync::SpinNoIrqLock as Mutex;
lazy_static! { lazy_static! {
pub static ref ROOT_INODE: Arc<INode> = { pub static ref ROOT_INODE: Arc<INode> = {
#[cfg(any(target_arch = "riscv32", target_arch = "aarch64"))] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64", target_arch = "aarch64"))]
let device = { let device = {
extern { extern {
fn _user_img_start(); fn _user_img_start();

@ -32,7 +32,7 @@ mod shell;
#[path = "arch/x86_64/mod.rs"] #[path = "arch/x86_64/mod.rs"]
pub mod arch; pub mod arch;
#[cfg(target_arch = "riscv32")] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
#[path = "arch/riscv32/mod.rs"] #[path = "arch/riscv32/mod.rs"]
pub mod arch; pub mod arch;

@ -24,7 +24,7 @@ pub type MemorySet = ucore_memory::no_mmu::MemorySet<NoMMUSupportImpl>;
pub type FrameAlloc = BitAlloc64K; pub type FrameAlloc = BitAlloc64K;
// RISCV only have 8M memory // RISCV only have 8M memory
#[cfg(target_arch = "riscv32")] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
pub type FrameAlloc = BitAlloc4K; pub type FrameAlloc = BitAlloc4K;
// Raspberry Pi 3 has 1G memory // Raspberry Pi 3 has 1G memory

@ -215,7 +215,7 @@ impl MutexSupport for Spin {
unsafe { unsafe {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
asm!("pause" :::: "volatile"); asm!("pause" :::: "volatile");
#[cfg(target_arch = "riscv32")] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
asm!("nop" :::: "volatile"); asm!("nop" :::: "volatile");
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
asm!("yield" :::: "volatile"); asm!("yield" :::: "volatile");
@ -247,7 +247,7 @@ impl MutexSupport for SpinNoIrq {
unsafe { unsafe {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
asm!("pause" :::: "volatile"); asm!("pause" :::: "volatile");
#[cfg(target_arch = "riscv32")] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
asm!("nop" :::: "volatile"); asm!("nop" :::: "volatile");
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
asm!("yield" :::: "volatile"); asm!("yield" :::: "volatile");

Loading…
Cancel
Save