1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 00:16:17 +04:00

print hello on K210

This commit is contained in:
WangRunji 2018-12-21 01:50:52 +08:00
parent 6c5cf5689d
commit 62b931d576
8 changed files with 134 additions and 96 deletions

View File

@ -46,7 +46,7 @@ raw-cpuid = "6.0"
uart_16550 = "0.1" uart_16550 = "0.1"
pc-keyboard = "0.3" pc-keyboard = "0.3"
[target.'cfg(target_arch = "riscv32")'.dependencies] [target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies]
riscv = { git = "https://github.com/riscv-and-rust-and-decaf/riscv" } riscv = { git = "https://github.com/riscv-and-rust-and-decaf/riscv" }
bbl = { path = "../crate/bbl" } bbl = { path = "../crate/bbl" }

View File

@ -14,13 +14,15 @@ then
fi fi
# CONFIGURATIONS # CONFIGURATIONS
export LLC=$PWD/../../llvm/build/bin/llc export LLC=$PWD/../tools/llc
export LLC_ARCH=riscv64 export LLC_ARCH=riscv64
export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/src export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/src
export TARGET_JSON=$PWD/riscv64-blog_os.json export TARGET_JSON=$PWD/riscv64-blog_os.json
export CARGO_PATH=~/.cargo export CARGO_PATH=~/.cargo
export CC=riscv64-unknown-elf-gcc export CC=riscv64-unknown-elf-gcc
export AR=riscv64-unknown-elf-ar export AR=riscv64-unknown-elf-ar
export OBJCOPY=riscv64-unknown-elf-objcopy
export QEMU=$PWD/../../@github/qemu/build/riscv64-softmmu/qemu-system-riscv64
#============================================================================ #============================================================================
@ -28,12 +30,9 @@ export AR=riscv64-unknown-elf-ar
gen_full_rlib() { gen_full_rlib() {
cd outdir cd outdir
for X in ${CNAME}.*ll for X in ${CNAME}.*bc
do do
# If using old LLVM because of asb's patch, uncomment the following line. ${LLC} -march=${LLC_ARCH} -filetype=obj ${X}
# It only affects debugging.
# sed 's/, retainedNodes: ![0-9]\+//' -i ${X}
$LLC -march=$LLC_ARCH -filetype=obj ${X}
done done
for X in ${CNAME}.*o for X in ${CNAME}.*o
do do
@ -48,7 +47,7 @@ CNAME=core
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --crate-name ${CNAME} $RUST_SRC_PATH/libcore/lib.rs \ rustc --crate-name ${CNAME} $RUST_SRC_PATH/libcore/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=3 \ -C opt-level=3 \
-C debuginfo=2 \ -C debuginfo=2 \
-Z force-unstable-if-unmarked \ -Z force-unstable-if-unmarked \
@ -62,7 +61,7 @@ CNAME=compiler_builtins
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --crate-name compiler_builtins $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.2/src/lib.rs \ 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 \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=3 \ -C opt-level=3 \
-C debuginfo=2 \ -C debuginfo=2 \
-Z force-unstable-if-unmarked \ -Z force-unstable-if-unmarked \
@ -78,7 +77,7 @@ CNAME=alloc
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --crate-name alloc $RUST_SRC_PATH/liballoc/lib.rs \ rustc --crate-name alloc $RUST_SRC_PATH/liballoc/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=3 \ -C opt-level=3 \
-C debuginfo=2 \ -C debuginfo=2 \
-Z force-unstable-if-unmarked \ -Z force-unstable-if-unmarked \
@ -93,7 +92,7 @@ CNAME=semver_parser
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -107,7 +106,7 @@ CNAME=cfg_if
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -122,7 +121,7 @@ CNAME=spin
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -141,7 +140,7 @@ CNAME=static_assertions
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -156,7 +155,7 @@ CNAME=bit_field
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -171,7 +170,7 @@ CNAME=zero
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -186,7 +185,7 @@ CNAME=bit_vec
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --crate-name bit_vec $CARGO_PATH/git/checkouts/bit-vec-437fa4a002bd318d/9861a58*/src/lib.rs \ 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 \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -201,7 +200,7 @@ CNAME=bitflags
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -213,11 +212,26 @@ rustc --crate-name bitflags $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823
gen_full_rlib gen_full_rlib
fi fi
CNAME=tock_registers
if ! [[ -f outdir/${CNAME}.o ]]
then
rustc --edition=2018 --crate-name tock_registers $CARGO_PATH/registry/src/github.com-1ecc6299db9ec823/tock-registers-0.3.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 $PWD/outdir \
--target $TARGET_JSON \
-L $PWD/outdir \
--cap-lints allow
gen_full_rlib
fi
CNAME=volatile CNAME=volatile
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -232,7 +246,7 @@ CNAME=once
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -247,7 +261,7 @@ CNAME=bbl
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --crate-name bbl $PWD/../crate/bbl/src/lib.rs \ rustc --crate-name bbl $PWD/../crate/bbl/src/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -261,7 +275,7 @@ CNAME=log
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -276,7 +290,7 @@ CNAME=linked_list_allocator
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -294,7 +308,7 @@ CNAME=lazy_static
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -312,7 +326,7 @@ CNAME=xmas_elf
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -327,7 +341,7 @@ CNAME=bit_allocator
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -342,7 +356,7 @@ CNAME=simple_filesystem
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --edition=2018 --crate-name simple_filesystem $CARGO_PATH/git/checkouts/simplefilesystem-rust-868ccb44dbeefdea/249383f*/src/lib.rs \ 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 \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -360,7 +374,7 @@ CNAME=ucore_process
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -376,7 +390,7 @@ CNAME=ucore_memory
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -391,7 +405,7 @@ CNAME=semver
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -408,7 +422,7 @@ CNAME=rustc_version
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -424,7 +438,7 @@ CNAME=bare_metal
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then 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 always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -439,7 +453,7 @@ CNAME=riscv
if ! [[ -f outdir/${CNAME}.o ]] if ! [[ -f outdir/${CNAME}.o ]]
then then
rustc --crate-name riscv $CARGO_PATH/git/checkouts/riscv-1e845b622ce46f1d/1f59ef7*/src/lib.rs \ rustc --crate-name riscv $CARGO_PATH/git/checkouts/riscv-1e845b622ce46f1d/1f59ef7*/src/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
@ -455,32 +469,40 @@ fi
# Hand generate build.rs # Hand generate build.rs
if ! [[ -f outdir/libatomic_rt.a ]]
then
${CC} src/arch/riscv32/compiler_rt.c -march=rv64ia -mabi=lp64 -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
fi
if ! [[ -f outdir/libsfsimg.a ]]
then
cat >outdir/sfsimg.S <<EOF cat >outdir/sfsimg.S <<EOF
.section .rodata .section .rodata
.align 12 .align 12
.global _user_img_start .global _user_img_start
.global _user_img_end .global _user_img_end
_user_img_start: _user_img_start:
.incbin "../user/build/user-riscv32.img" .incbin "../user/img/ucore-riscv64.img"
_user_img_end: _user_img_end:
EOF EOF
${CC} outdir/sfsimg.S -march=rv64ia -mabi=lp64 -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
fi
make sfsimg #make sfsimg
CNAME=ucore CNAME=ucore
if ! [[ -f outdir/${CNAME}.o ]] #if ! [[ -f outdir/${CNAME}.o ]]
then #then
rustc --edition=2018 --crate-name ucore src/lib.rs \ rustc --edition=2018 --crate-name ucore src/lib.rs \
--color always --crate-type lib --emit=metadata,llvm-ir \ --color always --crate-type lib --emit=metadata,llvm-bc \
-C opt-level=1 \ -C opt-level=1 \
-C debuginfo=2 \ -C debuginfo=2 \
-C debug-assertions=on \ -C debug-assertions=on \
--cfg 'feature="m_mode"' \
--cfg 'feature="board_k210"' \
--out-dir $PWD/outdir \ --out-dir $PWD/outdir \
--target $TARGET_JSON \ --target $TARGET_JSON \
-L $PWD/outdir \ -L $PWD/outdir \
@ -495,6 +517,7 @@ rustc --edition=2018 --crate-name ucore src/lib.rs \
--extern riscv=$PWD/outdir/libriscv.rlib \ --extern riscv=$PWD/outdir/libriscv.rlib \
--extern simple_filesystem=$PWD/outdir/libsimple_filesystem.rlib \ --extern simple_filesystem=$PWD/outdir/libsimple_filesystem.rlib \
--extern spin=$PWD/outdir/libspin.rlib \ --extern spin=$PWD/outdir/libspin.rlib \
--extern tock_registers=$PWD/outdir/libtock_registers.rlib \
--extern ucore_memory=$PWD/outdir/libucore_memory.rlib \ --extern ucore_memory=$PWD/outdir/libucore_memory.rlib \
--extern ucore_process=$PWD/outdir/libucore_process.rlib \ --extern ucore_process=$PWD/outdir/libucore_process.rlib \
--extern volatile=$PWD/outdir/libvolatile.rlib \ --extern volatile=$PWD/outdir/libvolatile.rlib \
@ -502,8 +525,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 #fi
#if ! [[ -f outdir/ucore ]]
#then
rustc --edition=2018 --crate-name ucore src/main.rs \ rustc --edition=2018 --crate-name ucore src/main.rs \
--color always --crate-type bin --emit=link \ --color always --crate-type bin --emit=link \
-C opt-level=1 \ -C opt-level=1 \
@ -523,25 +548,31 @@ rustc --edition=2018 --crate-name ucore src/main.rs \
--extern riscv=$PWD/outdir/libriscv.rlib \ --extern riscv=$PWD/outdir/libriscv.rlib \
--extern simple_filesystem=$PWD/outdir/libsimple_filesystem.rlib \ --extern simple_filesystem=$PWD/outdir/libsimple_filesystem.rlib \
--extern spin=$PWD/outdir/libspin.rlib \ --extern spin=$PWD/outdir/libspin.rlib \
--extern tock_registers=$PWD/outdir/libtock_registers.rlib \
--extern ucore=$PWD/outdir/libucore.rlib \ --extern ucore=$PWD/outdir/libucore.rlib \
--extern ucore_memory=$PWD/outdir/libucore_memory.rlib \ --extern ucore_memory=$PWD/outdir/libucore_memory.rlib \
--extern ucore_process=$PWD/outdir/libucore_process.rlib \ --extern ucore_process=$PWD/outdir/libucore_process.rlib \
--extern volatile=$PWD/outdir/libvolatile.rlib \ --extern volatile=$PWD/outdir/libvolatile.rlib \
--extern xmas_elf=$PWD/outdir/libxmas_elf.rlib \ --extern xmas_elf=$PWD/outdir/libxmas_elf.rlib \
-L native=outdir -L native=outdir
#fi
cd ../riscv-pk && mkdir -p build && cd build ${OBJCOPY} outdir/ucore --strip-all -O binary outdir/ucore.bin
../configure \ #cd ../riscv-pk && mkdir -p build && cd build
--with-arch=rv64imac \ #
--disable-fp-emulation \ #../configure \
--host=riscv64-unknown-elf \ # --with-arch=rv64imac \
--with-payload=../../kernel/outdir/ucore # --disable-fp-emulation \
# --host=riscv64-unknown-elf \
# --with-payload=../../kernel/outdir/ucore
#
#make
make #cp bbl ../../kernel/outdir/kernel.bin
cp bbl ../../kernel/outdir/kernel.bin #cd ../../kernel
cd ../../kernel #qemu-system-riscv64 -smp cores=4 -nographic -machine virt -kernel outdir/kernel.bin
qemu-system-riscv64 -smp cores=4 -nographic -machine virt -kernel outdir/kernel.bin ${QEMU} -nographic -cpu sifive-e51 -machine sifive_e -kernel outdir/ucore -d in_asm 2> dump

View File

@ -1,16 +0,0 @@
.section .text.boot
boot:
csrwi 0x304, 0 # mie
csrwi 0x344, 0 # mip
csrwi 0x340, 0 # mscratch
csrwi 0x180, 0 # satp
li t0, -1
csrw 0x302, t0 # medeleg
csrw 0x303, t0 # mideleg
csrw 0x306, t0 # mcounteren
csrw 0x106, t0 # scounteren
li t0, 1 << 11 # MPP = S
csrw 0x300, t0 # mstatus
lui t0, 0x80020
csrw 0x341, t0 # mepc
mret

View File

@ -0,0 +1,36 @@
.section .text.boot
boot:
//lui x1, 0x40000
//jalr x0, x1, 8
csrwi mie, 0
csrwi mip, 0
csrwi mscratch, 0
csrwi medeleg, 0
csrwi mideleg, 0
csrwi mstatus, 0
// uart init
lui x1, 0x38000
li t0, 3384
sw t0, 0x18(x1)
li t0, 1
sw t0, 0x8(x1)
sw t0, 0xc(x1)
li t0, 3
sw t0, 0x14(x1)
sw x0, 0x10(x1)
1: // test
lw t0, 0(x1)
blt t0, zero, 1b
// write
li t0, 0x21
sw t0, 0(x1)
csrr a0, mhartid
j _start

View File

@ -6,30 +6,25 @@
OUTPUT_ARCH(riscv) OUTPUT_ARCH(riscv)
ENTRY(_start) ENTRY(_start)
BASE_ADDRESS = 0x40020000; BASE_ADDRESS = 0x40000000;
SECTIONS SECTIONS
{ {
. = 0x40000000;
.boot : {
KEEP(*(.text.boot))
}
/* Load the kernel at this address: "." means the current address */ /* Load the kernel at this address: "." means the current address */
. = BASE_ADDRESS; . = BASE_ADDRESS;
start = .; start = .;
.text : { .text : {
stext = .; stext = .;
*(.text.entry) KEEP(*(.text.boot))
*(.text .stub .text.* .gnu.linkonce.t.*) *(.text .text.*)
. = ALIGN(4K); . = ALIGN(4K);
etext = .; etext = .;
} }
.rodata : { .rodata : {
srodata = .; srodata = .;
*(.rodata .rodata.* .gnu.linkonce.r.*) *(.rodata .rodata.*)
. = ALIGN(4K); . = ALIGN(4K);
erodata = .; erodata = .;
} }
@ -43,15 +38,10 @@ SECTIONS
.bss : { .bss : {
sbss = .; sbss = .;
*(.bss .bss.* .sbss*) *(.bss .bss.*)
. = ALIGN(4K); . = ALIGN(4K);
ebss = .; ebss = .;
} }
.got : {
*(.got .got.*)
. = ALIGN(4K);
}
PROVIDE(end = .); PROVIDE(end = .);
} }

View File

@ -1,5 +1,4 @@
use core::fmt::{Write, Result, Arguments}; use core::fmt::{Write, Result, Arguments};
use core::ptr::{read_volatile, write_volatile};
use bbl::sbi; use bbl::sbi;
struct SerialPort; struct SerialPort;
@ -20,10 +19,10 @@ impl Write for SerialPort {
} }
fn putchar(c: u8) { fn putchar(c: u8) {
if cfg!(feature = "no_bbl") { if cfg!(feature = "board_k210") {
unsafe { unsafe {
while read_volatile(STATUS) & CAN_WRITE == 0 {} while TXDATA.read_volatile() & (1 << 31) != 0 {}
write_volatile(DATA, c as u8); (TXDATA as *mut u8).write_volatile(c as u8);
} }
} else if cfg!(feature = "m_mode") { } else if cfg!(feature = "m_mode") {
(super::BBL.mcall_console_putchar)(c); (super::BBL.mcall_console_putchar)(c);
@ -33,10 +32,10 @@ fn putchar(c: u8) {
} }
pub fn getchar() -> char { pub fn getchar() -> char {
let c = if cfg!(feature = "no_bbl") { let c = if cfg!(feature = "board_k210") {
unsafe { unsafe {
// while read_volatile(STATUS) & CAN_READ == 0 {} while RXDATA.read_volatile() & (1 << 31) == 0 {}
read_volatile(DATA) (RXDATA as *const u8).read_volatile()
} }
} else if cfg!(feature = "m_mode") { } else if cfg!(feature = "m_mode") {
(super::BBL.mcall_console_getchar)() as u8 (super::BBL.mcall_console_getchar)() as u8
@ -54,7 +53,5 @@ pub fn putfmt(fmt: Arguments) {
SerialPort.write_fmt(fmt).unwrap(); SerialPort.write_fmt(fmt).unwrap();
} }
const DATA: *mut u8 = 0x10000000 as *mut u8; const TXDATA: *mut u32 = 0x38000000 as *mut u32;
const STATUS: *const u8 = 0x10000005 as *const u8; const RXDATA: *mut u32 = 0x38000004 as *mut u32;
const CAN_READ: u8 = 1 << 0;
const CAN_WRITE: u8 = 1 << 5;

View File

@ -57,8 +57,8 @@ global_asm!("
.macro XRET\n sret\n .endm .macro XRET\n sret\n .endm
"); ");
#[cfg(feature = "no_bbl")] #[cfg(feature = "board_k210")]
global_asm!(include_str!("boot/boot.asm")); global_asm!(include_str!("boot/boot_k210.asm"));
global_asm!(include_str!("boot/entry.asm")); global_asm!(include_str!("boot/entry.asm"));
global_asm!(include_str!("boot/trap.asm")); global_asm!(include_str!("boot/trap.asm"));

View File

@ -44,13 +44,13 @@ macro_rules! with_color {
fn print_in_color(args: fmt::Arguments, color: Color) { fn print_in_color(args: fmt::Arguments, color: Color) {
use crate::arch::io; use crate::arch::io;
let mutex = log_mutex.lock(); // let mutex = log_mutex.lock();
io::putfmt(with_color!(args, color)); io::putfmt(with_color!(args, color));
} }
pub fn print(args: fmt::Arguments) { pub fn print(args: fmt::Arguments) {
use crate::arch::io; use crate::arch::io;
let mutex = log_mutex.lock(); // let mutex = log_mutex.lock();
io::putfmt(args); io::putfmt(args);
} }