diff --git a/.gitignore b/.gitignore index 23d1ed1..637c5b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ build target -kernel/src/arch/x86_64/boot/vector.asm \ No newline at end of file +/kernel/src/arch/x86_64/interrupt/vector.asm diff --git a/.travis.yml b/.travis.yml index 0f450cb..0e9d60b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,11 @@ sudo: required language: rust -rust: nightly-2018-06-25 +rust: nightly-2018-08-03 cache: cargo: true -services: docker - addons: apt: packages: @@ -20,18 +18,19 @@ env: - ARCH="riscv32" - ARCH="x86_64" -before_script: - - if [ $ARCH = x86_64 ]; then - rustup component add rust-src && - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) && - (test -x $HOME/.cargo/bin/xargo || cargo install xargo) && - cargo install-update -a; +install: + - if [ $ARCH = riscv32 ]; then + export FILE="riscv64-unknown-elf-gcc-2018.07.0-x86_64-linux-ubuntu14"; + wget https://static.dev.sifive.com/dev-tools/$FILE.tar.gz; + tar xf $FILE.tar.gz; + export PATH=$PATH:$PWD/$FILE/bin; fi +before_script: + - rustup component add rust-src + - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) + - (test -x $HOME/.cargo/bin/cargo-xbuild || cargo install cargo-xbuild) + - cargo install-update -a + script: - - if [ $ARCH = riscv32 ]; then - docker run -v $(pwd):$(pwd) -w $(pwd) wangrunji0408/riscv-rust - bash -c "cd kernel && make patch-core && make build arch=riscv32"; - elif [ $ARCH = x86_64 ]; then - cd kernel && make build arch=x86_64; - fi + - cd kernel && make build arch=$ARCH diff --git a/crate/bit-allocator/src/lib.rs b/crate/bit-allocator/src/lib.rs index b84de2f..bc49dcb 100644 --- a/crate/bit-allocator/src/lib.rs +++ b/crate/bit-allocator/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![feature(asm)] -#![feature(universal_impl_trait)] extern crate bit_field; diff --git a/crate/memory/src/cow.rs b/crate/memory/src/cow.rs index 3f132be..a5d27f3 100644 --- a/crate/memory/src/cow.rs +++ b/crate/memory/src/cow.rs @@ -20,7 +20,7 @@ use super::paging::*; use super::*; -use alloc::BTreeMap; +use alloc::collections::BTreeMap; use core::ops::{Deref, DerefMut}; /// Wrapper for page table, supporting shared map & copy-on-write diff --git a/crate/memory/src/lib.rs b/crate/memory/src/lib.rs index a524f07..808d983 100644 --- a/crate/memory/src/lib.rs +++ b/crate/memory/src/lib.rs @@ -1,7 +1,5 @@ #![no_std] #![feature(alloc)] -#![feature(universal_impl_trait, conservative_impl_trait)] -#![feature(match_default_bindings)] extern crate alloc; diff --git a/crate/memory/src/swap/enhanced_clock.rs b/crate/memory/src/swap/enhanced_clock.rs index 374c455..63069f3 100644 --- a/crate/memory/src/swap/enhanced_clock.rs +++ b/crate/memory/src/swap/enhanced_clock.rs @@ -1,4 +1,4 @@ -use alloc::vec_deque::VecDeque; +use alloc::collections::VecDeque; use super::*; use paging::Entry; diff --git a/crate/memory/src/swap/fifo.rs b/crate/memory/src/swap/fifo.rs index 21580ab..fd5189a 100644 --- a/crate/memory/src/swap/fifo.rs +++ b/crate/memory/src/swap/fifo.rs @@ -1,4 +1,4 @@ -use alloc::vec_deque::VecDeque; +use alloc::collections::VecDeque; use super::*; #[derive(Default)] diff --git a/crate/process/Cargo.toml b/crate/process/Cargo.toml index 2a75b85..c73e482 100644 --- a/crate/process/Cargo.toml +++ b/crate/process/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" authors = ["WangRunji "] [dependencies] -log = { git = "https://github.com/riscv-and-rust-and-decaf/log.git" } +log = "0.4" diff --git a/crate/process/src/event_hub.rs b/crate/process/src/event_hub.rs index cf7fa19..f826cd0 100644 --- a/crate/process/src/event_hub.rs +++ b/crate/process/src/event_hub.rs @@ -1,4 +1,4 @@ -use alloc::BinaryHeap; +use alloc::collections::BinaryHeap; use core::cmp::{Ordering, PartialOrd}; type Time = usize; diff --git a/crate/process/src/lib.rs b/crate/process/src/lib.rs index 01e7b4e..e3d2554 100644 --- a/crate/process/src/lib.rs +++ b/crate/process/src/lib.rs @@ -1,8 +1,6 @@ #![no_std] #![feature(alloc)] #![feature(const_fn)] -#![feature(linkage)] -#![feature(universal_impl_trait, conservative_impl_trait)] extern crate alloc; #[macro_use] diff --git a/crate/process/src/processor.rs b/crate/process/src/processor.rs index ffb1332..9083dad 100644 --- a/crate/process/src/processor.rs +++ b/crate/process/src/processor.rs @@ -1,4 +1,4 @@ -use alloc::{boxed::Box, BTreeMap}; +use alloc::{boxed::Box, collections::BTreeMap}; use scheduler::*; use event_hub::EventHub; use util::GetMut2; diff --git a/crate/process/src/scheduler.rs b/crate/process/src/scheduler.rs index b6c69cd..f29df1f 100644 --- a/crate/process/src/scheduler.rs +++ b/crate/process/src/scheduler.rs @@ -1,4 +1,4 @@ -use alloc::{BinaryHeap, Vec}; +use alloc::{collections::BinaryHeap, vec::Vec}; type Pid = usize; diff --git a/crate/process/src/thread.rs b/crate/process/src/thread.rs index a772d04..1a93dd8 100644 --- a/crate/process/src/thread.rs +++ b/crate/process/src/thread.rs @@ -27,7 +27,7 @@ //! ``` use alloc::boxed::Box; -use alloc::BTreeMap; +use alloc::collections::BTreeMap; use core::any::Any; use core::marker::PhantomData; use core::ptr; diff --git a/crate/riscv b/crate/riscv index 590eb50..ed6e4c5 160000 --- a/crate/riscv +++ b/crate/riscv @@ -1 +1 @@ -Subproject commit 590eb508d4ddc503bf7220b8ec78a291129af4ef +Subproject commit ed6e4c5b935d9d027303da829a7508c105df3139 diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 6e1746f..aa2c4c1 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -14,18 +14,10 @@ dependencies = [ "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "bit-set" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bit-vec" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/AltSysrq/bit-vec.git#9861a58d6e761906cc63964c759e71f05bf63540" [[package]] name = "bit_field" @@ -55,14 +47,6 @@ dependencies = [ "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "linked_list_allocator" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "linked_list_allocator" version = "0.6.3" @@ -74,14 +58,14 @@ dependencies = [ [[package]] name = "log" version = "0.4.3" -source = "git+https://github.com/riscv-and-rust-and-decaf/log.git#726fc46eba8960e3630b28af1a3e27b1d9df7b01" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "multiboot2" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -111,45 +95,12 @@ dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rlibc" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rust-ucore" -version = "0.1.0" -dependencies = [ - "bbl 0.1.0", - "bit-allocator 0.1.0", - "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "linked_list_allocator 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (git+https://github.com/riscv-and-rust-and-decaf/log.git)", - "multiboot2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "riscv 0.2.0", - "rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)", - "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ucore-memory 0.1.0", - "ucore-process 0.1.0", - "volatile 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "simple-filesystem" version = "0.0.1" -source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust#7251ab7fb70f88172b31e3f38322b5ab81bca74b" +source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust#ca10d11264c85932e95e6c7c29e8b10c91ae0720" dependencies = [ - "bit-set 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bit-vec 0.5.0 (git+https://github.com/AltSysrq/bit-vec.git)", "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -169,7 +120,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucore" +version = "0.1.0" +dependencies = [ + "bbl 0.1.0", + "bit-allocator 0.1.0", + "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "multiboot2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "riscv 0.2.0", + "simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)", + "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ucore-memory 0.1.0", + "ucore-process 0.1.0", + "volatile 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -180,7 +157,7 @@ version = "0.1.0" name = "ucore-process" version = "0.1.0" dependencies = [ - "log 0.4.3 (git+https://github.com/riscv-and-rust-and-decaf/log.git)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -200,7 +177,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "x86_64" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -225,21 +202,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eda0f54b2d49f18f3867a5e6d458299bb886db6e64c34d319d6b1aa0839ac31c" -"checksum bit-set 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f1efcc46c18245a69c38fcc5cc650f16d3a59d034f3106e9ed63748f695730a" -"checksum bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf" +"checksum bit-vec 0.5.0 (git+https://github.com/AltSysrq/bit-vec.git)" = "" "checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275" "checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" "checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3" -"checksum linked_list_allocator 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6420a3167cee611c9d0f53663c339e85058bf05234e9862a47bf56920db8542" "checksum linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "655d57c71827fe0891ce72231b6aa5e14033dae3f604609e6a6f807267c1678d" -"checksum log 0.4.3 (git+https://github.com/riscv-and-rust-and-decaf/log.git)" = "" -"checksum multiboot2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc447d7e888cd9ae093fb7a9117411c85e7c799afd69d0fff64bf47332bb91f7" +"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" +"checksum multiboot2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebbe89ab663a65cab341428d5fc7013b0eab5543ace92a401a86581e50fdd81" "checksum once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "931fb7a4cf34610cf6cbe58d52a8ca5ef4c726d4e2e178abd0dc13a6551c6d73" "checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" -"checksum rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe" "checksum simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)" = "" "checksum spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14db77c5b914df6d6173dda9a3b3f5937bd802934fa5edaf934df06a3491e56f" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" @@ -247,6 +221,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5" "checksum ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53d8df5dd8d07fedccd202de1887d94481fadaea3db70479f459e8163a1fab41" "checksum volatile 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37c5d76c0f40ba4f8ac10ec4717d4e98ce3e58c5607eea36e9464226fc5e0a95" -"checksum x86_64 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "51b347fd81faca2e19366605a2bb52aa2f0e1572835678e3355b66aab18650e6" +"checksum x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "466c2002e38edde7ebbaae6656793d4f71596634971c7e8cbf7afa4827968445" "checksum xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22678df5df766e8d1e5d609da69f0c3132d794edf6ab5e75e7abcd2270d4cf58" "checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 9355b7c..6c756cc 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -1,22 +1,17 @@ [package] -name = "rust-ucore" +name = "ucore" version = "0.1.0" authors = ["Runji Wang "] [lib] -crate-type = ["staticlib"] +crate-type = ["staticlib", "rlib"] [features] use_apic = [] -test = [] -qemu_auto_exit = [] link_user_program = [] [profile.dev] # MUST >= 1 : Enable RVO to avoid stack overflow -# MUST >= 2 : Avoid (u8, u8) LLVM error in RV32 (at crate 'log') -# Error: Assertion `isSimple() && "Expected a SimpleValueType!"' failed. -# BUT! # MUST <= 1 : Avoid double fault at -O2 T_T opt-level = 1 @@ -24,30 +19,27 @@ opt-level = 1 debug = true [dependencies] -# Fixed version for RV32 -log = { git = "https://github.com/riscv-and-rust-and-decaf/log.git" } -rlibc = "1.0" +log = "0.4" spin = "0.4.8" once = "0.3.3" xmas-elf = "0.6" bitflags = "1.0" bit_field = "0.9.0" volatile = "0.1.0" +linked_list_allocator = "0.6" lazy_static = { version = "1.0.0", features = ["spin_no_std"] } bit-allocator = { path = "../crate/bit-allocator" } ucore-memory = { path = "../crate/memory" } ucore-process = { path = "../crate/process" } simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" } -[target.x86_64-blog_os.dependencies] -multiboot2 = "0.6" -x86_64 = "0.2.6" -linked_list_allocator = "0.6" +[target.'cfg(target_arch = "x86_64")'.dependencies] +multiboot2 = "0.7" +x86_64 = "0.2.11" redox_syscall = "0.1" uart_16550 = "0.1" -[target.riscv32-blog_os.dependencies] -linked_list_allocator = "0.5" # due to rust version +[target.'cfg(target_arch = "riscv32")'.dependencies] riscv = { path = "../crate/riscv" } bbl = { path = "../crate/bbl" } diff --git a/kernel/Makefile b/kernel/Makefile index 5d8a0e8..eae0e89 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -14,7 +14,7 @@ kernel := build/$(arch)/kernel.bin iso := build/$(arch)/os.iso target ?= $(arch)-blog_os mode ?= debug -rust_lib := target/$(target)/$(mode)/librust_ucore.a +rust_lib := target/$(target)/$(mode)/ucore boot_src := src/arch/$(arch)/boot linker_script := $(boot_src)/linker.ld @@ -27,7 +27,7 @@ user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(u user_obj := build/$(arch)/user.o SFSIMG := ../user/ucore32.img ifeq ($(arch), x86_64) -qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback +qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback -device isa-debug-exit endif ifeq ($(arch), riscv32) qemu_opts := -machine virt -kernel $(iso) -nographic @@ -42,33 +42,20 @@ features := $(features) link_user_program assembly_object_files := $(assembly_object_files) $(user_obj) endif -# Link user-riscv.img for RV32 -ifeq ($(arch), riscv32) -riscv_user_img_obj := build/riscv32/user-riscv.o -assembly_object_files := $(assembly_object_files) $(riscv_user_img_obj) -endif - -ifdef travis -test := 1 -features := $(features) qemu_auto_exit -endif - -ifdef test -features := $(features) test -# enable shutdown inside the qemu -qemu_opts := $(qemu_opts) -device isa-debug-exit -endif - -ifdef int -qemu_opts := $(qemu_opts) -d int +ifdef d +qemu_opts := $(qemu_opts) -d $(d) endif -build_args := --target $(target) --features "$(features)" +build_args := --target $(target).json --features "$(features)" ifeq ($(mode), release) build_args := $(build_args) --release endif +ifeq ($(arch), x86_64) +build_args := $(build_args) --lib +endif + ifeq ($(OS),Windows_NT) uname := Win32 @@ -80,7 +67,7 @@ ifeq ($(uname), Darwin) prefix := x86_64-elf- endif ifeq ($(arch), riscv32) -prefix := riscv32-unknown-elf- +prefix := riscv64-unknown-elf- endif ld := $(prefix)ld @@ -123,33 +110,22 @@ build/x86_64/os.iso: $(kernel) $(grub_cfg) @grub-mkrescue -o $(iso) build/isofiles 2> /dev/null @rm -r build/isofiles -build/riscv32/os.iso: $(kernel) - @cp $(kernel) $@ +build/riscv32/os.iso: kernel + @cp $(rust_lib) $@ $(kernel): kernel $(assembly_object_files) $(linker_script) @$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \ - $(assembly_object_files) $(rust_lib) + $(assembly_object_files) target/x86_64-blog_os/$(mode)/libucore.a kernel: - @RUST_TARGET_PATH=$(shell pwd) CC=$(cc) xargo build $(build_args) + @CC=$(cc) cargo xbuild $(build_args) # compile assembly files build/x86_64/boot/%.o: $(boot_src)/%.asm @mkdir -p $(shell dirname $@) @nasm -felf64 $< -o $@ -build/riscv32/boot/%.o: $(boot_src)/%.asm - @mkdir -p $(shell dirname $@) - @$(as) -march=rv32i $< -o $@ - # make user.o from binary files $(user_obj): $(user_bins) @cd $(user_bin_path) && \ $(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins))) - -$(riscv_user_img_obj): ../user/user-riscv.img - @cd ../user && $(ld) -o $(abspath $@) -b binary $(notdir $<) - -# patch Rust core for RISCV32I atomic -patch-core: - @patch -p0 /rust/rust-riscv-rust-1.26.0-1-dev/src/libcore/sync/atomic.rs src/arch/riscv32/atomic.patch \ No newline at end of file diff --git a/kernel/Xargo.toml b/kernel/Xargo.toml deleted file mode 100644 index 2844795..0000000 --- a/kernel/Xargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[dependencies] -alloc = {} - -[target.riscv32-blog_os.dependencies.compiler_builtins] -features = ["mem"] -stage = 1 diff --git a/kernel/build.rs b/kernel/build.rs index 00b9309..6bbe313 100644 --- a/kernel/build.rs +++ b/kernel/build.rs @@ -4,7 +4,7 @@ use std::fs::File; use std::io::{Write, Result}; fn main() { - if std::env::var("TARGET").unwrap().starts_with("x86_64") { + if std::env::var("TARGET").unwrap().find("x86_64").is_some() { cc::Build::new() .file("src/arch/x86_64/driver/apic/lapic.c") .file("src/arch/x86_64/driver/keyboard/keyboard.c") @@ -15,11 +15,11 @@ fn main() { } fn gen_vector_asm() -> Result<()> { - let mut f = File::create("src/arch/x86_64/boot/vector.asm").unwrap(); + let mut f = File::create("src/arch/x86_64/interrupt/vector.asm").unwrap(); writeln!(f, "# generated by build.rs - do not edit")?; - writeln!(f, "section .text")?; - writeln!(f, "extern __alltraps")?; + writeln!(f, ".section .text")?; + writeln!(f, ".intel_syntax noprefix")?; for i in 0..256 { writeln!(f, "vector{}:", i)?; if !(i == 8 || (i >= 10 && i <= 14) || i == 17) { @@ -29,11 +29,11 @@ fn gen_vector_asm() -> Result<()> { writeln!(f, "\tjmp __alltraps")?; } - writeln!(f, "\nsection .rodata")?; - writeln!(f, "global __vectors")?; + writeln!(f, "\n.section .rodata")?; + writeln!(f, ".global __vectors")?; writeln!(f, "__vectors:")?; for i in 0..256 { - writeln!(f, "\tdq vector{}", i)?; + writeln!(f, "\t.quad vector{}", i)?; } Ok(()) } \ No newline at end of file diff --git a/kernel/riscv32-blog_os.json b/kernel/riscv32-blog_os.json index ab76d65..ab160b8 100644 --- a/kernel/riscv32-blog_os.json +++ b/kernel/riscv32-blog_os.json @@ -5,12 +5,18 @@ "target-pointer-width": "32", "target-c-int-width": "32", "os": "none", - "arch": "riscv", + "arch": "riscv32", "cpu": "generic-rv32", - "features": "+m", + "features": "", "max-atomic-width": "32", - "linker": "ld.lld", + "linker": "riscv64-unknown-elf-ld", "linker-flavor": "ld", + "pre-link-args": { + "ld": [ + "-Tsrc/arch/riscv32/boot/linker.ld", + "-melf32lriscv" + ] + }, "executables": true, "panic-strategy": "abort", "relocation-model": "static", diff --git a/kernel/src/arch/riscv32/atomic.patch b/kernel/src/arch/riscv32/atomic.patch deleted file mode 100644 index 96f446a..0000000 --- a/kernel/src/arch/riscv32/atomic.patch +++ /dev/null @@ -1,103 +0,0 @@ ---- atomic_backup.rs 2018-07-10 00:29:48.000000000 +0800 -+++ atomic.rs 2018-07-12 18:32:26.000000000 +0800 -@@ -1556,15 +1556,9 @@ - } - - #[inline] --unsafe fn atomic_store(dst: *mut T, val: T, order: Ordering) { -- match order { -- Release => intrinsics::atomic_store_rel(dst, val), -- Relaxed => intrinsics::atomic_store_relaxed(dst, val), -- SeqCst => intrinsics::atomic_store(dst, val), -- Acquire => panic!("there is no such thing as an acquire store"), -- AcqRel => panic!("there is no such thing as an acquire/release store"), -- __Nonexhaustive => panic!("invalid memory ordering"), -- } -+unsafe fn atomic_store(dst: *mut T, val: T, _order: Ordering) { -+ use ptr::write; -+ write(dst, val); - } - - #[inline] -@@ -1580,15 +1574,22 @@ - } - - #[inline] --unsafe fn atomic_swap(dst: *mut T, val: T, order: Ordering) -> T { -- match order { -- Acquire => intrinsics::atomic_xchg_acq(dst, val), -- Release => intrinsics::atomic_xchg_rel(dst, val), -- AcqRel => intrinsics::atomic_xchg_acqrel(dst, val), -- Relaxed => intrinsics::atomic_xchg_relaxed(dst, val), -- SeqCst => intrinsics::atomic_xchg(dst, val), -- __Nonexhaustive => panic!("invalid memory ordering"), -+unsafe fn atomic_swap(dst: *mut T, val: T, _order: Ordering) -> T { -+ let sstatus: usize; -+ asm!("csrrs $0, 0x100, x0" : "=r"(sstatus) ::: "volatile"); -+ // Disable interrupt: sstatus::clear_sie() -+ asm!("csrrc x0, 0x100, $0" :: "r"(1) :: "volatile"); -+ -+ use ptr::{read, write}; -+ let ret = read(dst); -+ write(dst, val); -+ -+ let sie = sstatus & 1 != 0; -+ if sie { -+ // Enable interrupt: sstatus::set_sie() -+ asm!("csrrs x0, 0x100, $0" :: "r"(1) :: "volatile"); - } -+ ret - } - - /// Returns the previous value (like __sync_fetch_and_add). -@@ -1618,29 +1619,30 @@ - } - - #[inline] --unsafe fn atomic_compare_exchange(dst: *mut T, -+#[cfg(target_arch = "riscv")] -+unsafe fn atomic_compare_exchange(dst: *mut T, - old: T, - new: T, -- success: Ordering, -- failure: Ordering) -+ _success: Ordering, -+ _failure: Ordering) - -> Result { -- let (val, ok) = match (success, failure) { -- (Acquire, Acquire) => intrinsics::atomic_cxchg_acq(dst, old, new), -- (Release, Relaxed) => intrinsics::atomic_cxchg_rel(dst, old, new), -- (AcqRel, Acquire) => intrinsics::atomic_cxchg_acqrel(dst, old, new), -- (Relaxed, Relaxed) => intrinsics::atomic_cxchg_relaxed(dst, old, new), -- (SeqCst, SeqCst) => intrinsics::atomic_cxchg(dst, old, new), -- (Acquire, Relaxed) => intrinsics::atomic_cxchg_acq_failrelaxed(dst, old, new), -- (AcqRel, Relaxed) => intrinsics::atomic_cxchg_acqrel_failrelaxed(dst, old, new), -- (SeqCst, Relaxed) => intrinsics::atomic_cxchg_failrelaxed(dst, old, new), -- (SeqCst, Acquire) => intrinsics::atomic_cxchg_failacq(dst, old, new), -- (__Nonexhaustive, _) => panic!("invalid memory ordering"), -- (_, __Nonexhaustive) => panic!("invalid memory ordering"), -- (_, AcqRel) => panic!("there is no such thing as an acquire/release failure ordering"), -- (_, Release) => panic!("there is no such thing as a release failure ordering"), -- _ => panic!("a failure ordering can't be stronger than a success ordering"), -- }; -- if ok { Ok(val) } else { Err(val) } -+ let sstatus: usize; -+ asm!("csrrs $0, 0x100, x0" : "=r"(sstatus) ::: "volatile"); -+ // Disable interrupt: sstatus::clear_sie() -+ asm!("csrrc x0, 0x100, $0" :: "r"(1) :: "volatile"); -+ -+ use ptr::{read, write}; -+ let ret = read(dst); -+ if ret == old { -+ write(dst, new); -+ } -+ -+ let sie = sstatus & 1 != 0; -+ if sie { -+ // Enable interrupt: sstatus::set_sie() -+ asm!("csrrs x0, 0x100, $0" :: "r"(1) :: "volatile"); -+ } -+ Ok(ret) - } - - #[inline] diff --git a/kernel/src/arch/riscv32/boot/entry.asm b/kernel/src/arch/riscv32/boot/entry.asm index 02fab69..5abca6c 100644 --- a/kernel/src/arch/riscv32/boot/entry.asm +++ b/kernel/src/arch/riscv32/boot/entry.asm @@ -1,20 +1,22 @@ .section .entry .global _start _start: - csrw mie, 0 - csrw mip, 0 - csrw mscratch, 0 - csrw satp, 0 + csrwi 0x304, 0 # mie + csrwi 0x344, 0 # mip + csrwi 0x340, 0 # mscratch + csrwi 0x180, 0 # satp li t0, -1 - csrw medeleg, t0 - csrw mideleg, t0 - csrw mcounteren, t0 - csrw scounteren, t0 - li t0, 1 << 11 ; MPP = S - csrw mstatus, t0 - la t0, rust_main - csrw mepc, t0 - la sp, bootstacktop + 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, %hi(rust_main) + addi t0, t0, %lo(rust_main) + csrw 0x341, t0 # mepc + lui sp, %hi(bootstacktop) + addi sp, sp, %lo(bootstacktop) mret .section .bss diff --git a/kernel/src/arch/riscv32/boot/trap.asm b/kernel/src/arch/riscv32/boot/trap.asm index 7fe159b..d400826 100644 --- a/kernel/src/arch/riscv32/boot/trap.asm +++ b/kernel/src/arch/riscv32/boot/trap.asm @@ -2,10 +2,10 @@ # If coming from userspace, preserve the user stack pointer and load # the kernel stack pointer. If we came from the kernel, sscratch # will contain 0, and we should continue on the current stack. - csrrw sp, sscratch, sp + csrrw sp, 0x140, sp # sscratch bnez sp, _save_context _restore_kernel_sp: - csrr sp, sscratch + csrr sp, 0x140 # sscratch # sscratch = previous-sp, sp = kernel-sp _save_context: # provide room for trap frame @@ -42,13 +42,13 @@ _save_context: sw x30, 30*4(sp) sw x31, 31*4(sp) - # get sp, sstatus, sepc, sbadvaddr, scause + # get sp, sstatus, sepc, stval, scause # set sscratch = 0 - csrrw s0, sscratch, x0 - csrr s1, sstatus - csrr s2, sepc - csrr s3, sbadaddr - csrr s4, scause + csrrw s0, 0x140, x0 # sscratch + csrr s1, 0x100 # sstatus + csrr s2, 0x141 # sepc + csrr s3, 0x143 # stval + csrr s4, 0x142 # scause # store sp, sstatus, sepc, sbadvaddr, scause sw s0, 2*4(sp) sw s1, 32*4(sp) @@ -64,11 +64,11 @@ _save_context: bnez s0, _restore_context # back to U-mode? (sstatus.SPP = 1) _save_kernel_sp: addi s0, sp, 36*4 - csrw sscratch, s0 # sscratch = kernel-sp + csrw 0x140, s0 # sscratch = kernel-sp _restore_context: # restore sstatus, sepc - csrw sstatus, s1 - csrw sepc, s2 + csrw 0x100, s1 + csrw 0x141, s2 # restore x registers except x2 (sp) lw x1, 1*4(sp) @@ -109,7 +109,7 @@ _restore_context: .globl __alltraps __alltraps: SAVE_ALL - move a0, sp + mv a0, sp jal rust_trap .globl __trapret __trapret: diff --git a/kernel/src/arch/riscv32/compiler_rt.rs b/kernel/src/arch/riscv32/compiler_rt.rs new file mode 100644 index 0000000..432f0ef --- /dev/null +++ b/kernel/src/arch/riscv32/compiler_rt.rs @@ -0,0 +1,73 @@ +//! Workaround for missing compiler-builtin symbols +//! +//! [atomic](http://llvm.org/docs/Atomics.html#libcalls-atomic) + +/// Copy from: +/// https://github.com/rust-lang-nursery/compiler-builtins/blob/master/src/riscv32.rs +#[no_mangle] +pub extern fn __mulsi3(mut a: u32, mut b: u32) -> u32 { + let mut r: u32 = 0; + + while a > 0 { + if a & 1 > 0 { + r += b; + } + a >>= 1; + b <<= 1; + } + + r +} + +#[no_mangle] +pub extern fn abort() { + loop {} +} + +use core::ptr::{read, write}; + +#[no_mangle] +pub unsafe extern fn __atomic_load_1(src: *const u8) -> u8 { + read(src) +} + +#[no_mangle] +pub unsafe extern fn __atomic_load_2(src: *const u16) -> u16 { + read(src) +} + +#[no_mangle] +pub unsafe extern fn __atomic_load_4(src: *const u32) -> u32 { + read(src) +} + +#[no_mangle] +pub unsafe extern fn __atomic_store_1(dst: *mut u8, val: u8) { + write(dst, val) +} + +#[no_mangle] +pub unsafe extern fn __atomic_store_4(dst: *mut u32, val: u32) { + write(dst, val) +} + +unsafe fn __atomic_compare_exchange(dst: *mut T, old: T, new: T) -> (T, bool) { + use super::interrupt; + let flags = interrupt::disable_and_store(); + let ret = read(dst); + if ret == old { + write(dst, new); + } + interrupt::restore(flags); + (ret, true) +} + +#[no_mangle] +pub unsafe extern fn __atomic_compare_exchange_1(dst: *mut u8, old: u8, src: u8) -> (u8, bool) { + __atomic_compare_exchange(dst, old, src) +} + +#[no_mangle] +pub unsafe extern fn __atomic_compare_exchange_4(dst: *mut u32, old: u32, src: u32) -> (u32, bool) { + __atomic_compare_exchange(dst, old, src) +} \ No newline at end of file diff --git a/kernel/src/arch/riscv32/mod.rs b/kernel/src/arch/riscv32/mod.rs index 921245b..b4ae1b8 100644 --- a/kernel/src/arch/riscv32/mod.rs +++ b/kernel/src/arch/riscv32/mod.rs @@ -5,10 +5,14 @@ pub mod interrupt; pub mod timer; pub mod paging; pub mod memory; +pub mod compiler_rt; pub fn init() { println!("Hello RISCV! {}", 123); interrupt::init(); memory::init(); timer::init(); -} \ No newline at end of file +} + +global_asm!(include_str!("boot/entry.asm")); +global_asm!(include_str!("boot/trap.asm")); \ No newline at end of file diff --git a/kernel/src/arch/x86_64/boot/vector.asm b/kernel/src/arch/x86_64/boot/vector.asm deleted file mode 100644 index 6ae8219..0000000 --- a/kernel/src/arch/x86_64/boot/vector.asm +++ /dev/null @@ -1,1280 +0,0 @@ -# generated by build.rs - do not edit -section .text -extern __alltraps -vector0: - push 0 - push 0 - jmp __alltraps -vector1: - push 0 - push 1 - jmp __alltraps -vector2: - push 0 - push 2 - jmp __alltraps -vector3: - push 0 - push 3 - jmp __alltraps -vector4: - push 0 - push 4 - jmp __alltraps -vector5: - push 0 - push 5 - jmp __alltraps -vector6: - push 0 - push 6 - jmp __alltraps -vector7: - push 0 - push 7 - jmp __alltraps -vector8: - push 8 - jmp __alltraps -vector9: - push 0 - push 9 - jmp __alltraps -vector10: - push 10 - jmp __alltraps -vector11: - push 11 - jmp __alltraps -vector12: - push 12 - jmp __alltraps -vector13: - push 13 - jmp __alltraps -vector14: - push 14 - jmp __alltraps -vector15: - push 0 - push 15 - jmp __alltraps -vector16: - push 0 - push 16 - jmp __alltraps -vector17: - push 17 - jmp __alltraps -vector18: - push 0 - push 18 - jmp __alltraps -vector19: - push 0 - push 19 - jmp __alltraps -vector20: - push 0 - push 20 - jmp __alltraps -vector21: - push 0 - push 21 - jmp __alltraps -vector22: - push 0 - push 22 - jmp __alltraps -vector23: - push 0 - push 23 - jmp __alltraps -vector24: - push 0 - push 24 - jmp __alltraps -vector25: - push 0 - push 25 - jmp __alltraps -vector26: - push 0 - push 26 - jmp __alltraps -vector27: - push 0 - push 27 - jmp __alltraps -vector28: - push 0 - push 28 - jmp __alltraps -vector29: - push 0 - push 29 - jmp __alltraps -vector30: - push 0 - push 30 - jmp __alltraps -vector31: - push 0 - push 31 - jmp __alltraps -vector32: - push 0 - push 32 - jmp __alltraps -vector33: - push 0 - push 33 - jmp __alltraps -vector34: - push 0 - push 34 - jmp __alltraps -vector35: - push 0 - push 35 - jmp __alltraps -vector36: - push 0 - push 36 - jmp __alltraps -vector37: - push 0 - push 37 - jmp __alltraps -vector38: - push 0 - push 38 - jmp __alltraps -vector39: - push 0 - push 39 - jmp __alltraps -vector40: - push 0 - push 40 - jmp __alltraps -vector41: - push 0 - push 41 - jmp __alltraps -vector42: - push 0 - push 42 - jmp __alltraps -vector43: - push 0 - push 43 - jmp __alltraps -vector44: - push 0 - push 44 - jmp __alltraps -vector45: - push 0 - push 45 - jmp __alltraps -vector46: - push 0 - push 46 - jmp __alltraps -vector47: - push 0 - push 47 - jmp __alltraps -vector48: - push 0 - push 48 - jmp __alltraps -vector49: - push 0 - push 49 - jmp __alltraps -vector50: - push 0 - push 50 - jmp __alltraps -vector51: - push 0 - push 51 - jmp __alltraps -vector52: - push 0 - push 52 - jmp __alltraps -vector53: - push 0 - push 53 - jmp __alltraps -vector54: - push 0 - push 54 - jmp __alltraps -vector55: - push 0 - push 55 - jmp __alltraps -vector56: - push 0 - push 56 - jmp __alltraps -vector57: - push 0 - push 57 - jmp __alltraps -vector58: - push 0 - push 58 - jmp __alltraps -vector59: - push 0 - push 59 - jmp __alltraps -vector60: - push 0 - push 60 - jmp __alltraps -vector61: - push 0 - push 61 - jmp __alltraps -vector62: - push 0 - push 62 - jmp __alltraps -vector63: - push 0 - push 63 - jmp __alltraps -vector64: - push 0 - push 64 - jmp __alltraps -vector65: - push 0 - push 65 - jmp __alltraps -vector66: - push 0 - push 66 - jmp __alltraps -vector67: - push 0 - push 67 - jmp __alltraps -vector68: - push 0 - push 68 - jmp __alltraps -vector69: - push 0 - push 69 - jmp __alltraps -vector70: - push 0 - push 70 - jmp __alltraps -vector71: - push 0 - push 71 - jmp __alltraps -vector72: - push 0 - push 72 - jmp __alltraps -vector73: - push 0 - push 73 - jmp __alltraps -vector74: - push 0 - push 74 - jmp __alltraps -vector75: - push 0 - push 75 - jmp __alltraps -vector76: - push 0 - push 76 - jmp __alltraps -vector77: - push 0 - push 77 - jmp __alltraps -vector78: - push 0 - push 78 - jmp __alltraps -vector79: - push 0 - push 79 - jmp __alltraps -vector80: - push 0 - push 80 - jmp __alltraps -vector81: - push 0 - push 81 - jmp __alltraps -vector82: - push 0 - push 82 - jmp __alltraps -vector83: - push 0 - push 83 - jmp __alltraps -vector84: - push 0 - push 84 - jmp __alltraps -vector85: - push 0 - push 85 - jmp __alltraps -vector86: - push 0 - push 86 - jmp __alltraps -vector87: - push 0 - push 87 - jmp __alltraps -vector88: - push 0 - push 88 - jmp __alltraps -vector89: - push 0 - push 89 - jmp __alltraps -vector90: - push 0 - push 90 - jmp __alltraps -vector91: - push 0 - push 91 - jmp __alltraps -vector92: - push 0 - push 92 - jmp __alltraps -vector93: - push 0 - push 93 - jmp __alltraps -vector94: - push 0 - push 94 - jmp __alltraps -vector95: - push 0 - push 95 - jmp __alltraps -vector96: - push 0 - push 96 - jmp __alltraps -vector97: - push 0 - push 97 - jmp __alltraps -vector98: - push 0 - push 98 - jmp __alltraps -vector99: - push 0 - push 99 - jmp __alltraps -vector100: - push 0 - push 100 - jmp __alltraps -vector101: - push 0 - push 101 - jmp __alltraps -vector102: - push 0 - push 102 - jmp __alltraps -vector103: - push 0 - push 103 - jmp __alltraps -vector104: - push 0 - push 104 - jmp __alltraps -vector105: - push 0 - push 105 - jmp __alltraps -vector106: - push 0 - push 106 - jmp __alltraps -vector107: - push 0 - push 107 - jmp __alltraps -vector108: - push 0 - push 108 - jmp __alltraps -vector109: - push 0 - push 109 - jmp __alltraps -vector110: - push 0 - push 110 - jmp __alltraps -vector111: - push 0 - push 111 - jmp __alltraps -vector112: - push 0 - push 112 - jmp __alltraps -vector113: - push 0 - push 113 - jmp __alltraps -vector114: - push 0 - push 114 - jmp __alltraps -vector115: - push 0 - push 115 - jmp __alltraps -vector116: - push 0 - push 116 - jmp __alltraps -vector117: - push 0 - push 117 - jmp __alltraps -vector118: - push 0 - push 118 - jmp __alltraps -vector119: - push 0 - push 119 - jmp __alltraps -vector120: - push 0 - push 120 - jmp __alltraps -vector121: - push 0 - push 121 - jmp __alltraps -vector122: - push 0 - push 122 - jmp __alltraps -vector123: - push 0 - push 123 - jmp __alltraps -vector124: - push 0 - push 124 - jmp __alltraps -vector125: - push 0 - push 125 - jmp __alltraps -vector126: - push 0 - push 126 - jmp __alltraps -vector127: - push 0 - push 127 - jmp __alltraps -vector128: - push 0 - push 128 - jmp __alltraps -vector129: - push 0 - push 129 - jmp __alltraps -vector130: - push 0 - push 130 - jmp __alltraps -vector131: - push 0 - push 131 - jmp __alltraps -vector132: - push 0 - push 132 - jmp __alltraps -vector133: - push 0 - push 133 - jmp __alltraps -vector134: - push 0 - push 134 - jmp __alltraps -vector135: - push 0 - push 135 - jmp __alltraps -vector136: - push 0 - push 136 - jmp __alltraps -vector137: - push 0 - push 137 - jmp __alltraps -vector138: - push 0 - push 138 - jmp __alltraps -vector139: - push 0 - push 139 - jmp __alltraps -vector140: - push 0 - push 140 - jmp __alltraps -vector141: - push 0 - push 141 - jmp __alltraps -vector142: - push 0 - push 142 - jmp __alltraps -vector143: - push 0 - push 143 - jmp __alltraps -vector144: - push 0 - push 144 - jmp __alltraps -vector145: - push 0 - push 145 - jmp __alltraps -vector146: - push 0 - push 146 - jmp __alltraps -vector147: - push 0 - push 147 - jmp __alltraps -vector148: - push 0 - push 148 - jmp __alltraps -vector149: - push 0 - push 149 - jmp __alltraps -vector150: - push 0 - push 150 - jmp __alltraps -vector151: - push 0 - push 151 - jmp __alltraps -vector152: - push 0 - push 152 - jmp __alltraps -vector153: - push 0 - push 153 - jmp __alltraps -vector154: - push 0 - push 154 - jmp __alltraps -vector155: - push 0 - push 155 - jmp __alltraps -vector156: - push 0 - push 156 - jmp __alltraps -vector157: - push 0 - push 157 - jmp __alltraps -vector158: - push 0 - push 158 - jmp __alltraps -vector159: - push 0 - push 159 - jmp __alltraps -vector160: - push 0 - push 160 - jmp __alltraps -vector161: - push 0 - push 161 - jmp __alltraps -vector162: - push 0 - push 162 - jmp __alltraps -vector163: - push 0 - push 163 - jmp __alltraps -vector164: - push 0 - push 164 - jmp __alltraps -vector165: - push 0 - push 165 - jmp __alltraps -vector166: - push 0 - push 166 - jmp __alltraps -vector167: - push 0 - push 167 - jmp __alltraps -vector168: - push 0 - push 168 - jmp __alltraps -vector169: - push 0 - push 169 - jmp __alltraps -vector170: - push 0 - push 170 - jmp __alltraps -vector171: - push 0 - push 171 - jmp __alltraps -vector172: - push 0 - push 172 - jmp __alltraps -vector173: - push 0 - push 173 - jmp __alltraps -vector174: - push 0 - push 174 - jmp __alltraps -vector175: - push 0 - push 175 - jmp __alltraps -vector176: - push 0 - push 176 - jmp __alltraps -vector177: - push 0 - push 177 - jmp __alltraps -vector178: - push 0 - push 178 - jmp __alltraps -vector179: - push 0 - push 179 - jmp __alltraps -vector180: - push 0 - push 180 - jmp __alltraps -vector181: - push 0 - push 181 - jmp __alltraps -vector182: - push 0 - push 182 - jmp __alltraps -vector183: - push 0 - push 183 - jmp __alltraps -vector184: - push 0 - push 184 - jmp __alltraps -vector185: - push 0 - push 185 - jmp __alltraps -vector186: - push 0 - push 186 - jmp __alltraps -vector187: - push 0 - push 187 - jmp __alltraps -vector188: - push 0 - push 188 - jmp __alltraps -vector189: - push 0 - push 189 - jmp __alltraps -vector190: - push 0 - push 190 - jmp __alltraps -vector191: - push 0 - push 191 - jmp __alltraps -vector192: - push 0 - push 192 - jmp __alltraps -vector193: - push 0 - push 193 - jmp __alltraps -vector194: - push 0 - push 194 - jmp __alltraps -vector195: - push 0 - push 195 - jmp __alltraps -vector196: - push 0 - push 196 - jmp __alltraps -vector197: - push 0 - push 197 - jmp __alltraps -vector198: - push 0 - push 198 - jmp __alltraps -vector199: - push 0 - push 199 - jmp __alltraps -vector200: - push 0 - push 200 - jmp __alltraps -vector201: - push 0 - push 201 - jmp __alltraps -vector202: - push 0 - push 202 - jmp __alltraps -vector203: - push 0 - push 203 - jmp __alltraps -vector204: - push 0 - push 204 - jmp __alltraps -vector205: - push 0 - push 205 - jmp __alltraps -vector206: - push 0 - push 206 - jmp __alltraps -vector207: - push 0 - push 207 - jmp __alltraps -vector208: - push 0 - push 208 - jmp __alltraps -vector209: - push 0 - push 209 - jmp __alltraps -vector210: - push 0 - push 210 - jmp __alltraps -vector211: - push 0 - push 211 - jmp __alltraps -vector212: - push 0 - push 212 - jmp __alltraps -vector213: - push 0 - push 213 - jmp __alltraps -vector214: - push 0 - push 214 - jmp __alltraps -vector215: - push 0 - push 215 - jmp __alltraps -vector216: - push 0 - push 216 - jmp __alltraps -vector217: - push 0 - push 217 - jmp __alltraps -vector218: - push 0 - push 218 - jmp __alltraps -vector219: - push 0 - push 219 - jmp __alltraps -vector220: - push 0 - push 220 - jmp __alltraps -vector221: - push 0 - push 221 - jmp __alltraps -vector222: - push 0 - push 222 - jmp __alltraps -vector223: - push 0 - push 223 - jmp __alltraps -vector224: - push 0 - push 224 - jmp __alltraps -vector225: - push 0 - push 225 - jmp __alltraps -vector226: - push 0 - push 226 - jmp __alltraps -vector227: - push 0 - push 227 - jmp __alltraps -vector228: - push 0 - push 228 - jmp __alltraps -vector229: - push 0 - push 229 - jmp __alltraps -vector230: - push 0 - push 230 - jmp __alltraps -vector231: - push 0 - push 231 - jmp __alltraps -vector232: - push 0 - push 232 - jmp __alltraps -vector233: - push 0 - push 233 - jmp __alltraps -vector234: - push 0 - push 234 - jmp __alltraps -vector235: - push 0 - push 235 - jmp __alltraps -vector236: - push 0 - push 236 - jmp __alltraps -vector237: - push 0 - push 237 - jmp __alltraps -vector238: - push 0 - push 238 - jmp __alltraps -vector239: - push 0 - push 239 - jmp __alltraps -vector240: - push 0 - push 240 - jmp __alltraps -vector241: - push 0 - push 241 - jmp __alltraps -vector242: - push 0 - push 242 - jmp __alltraps -vector243: - push 0 - push 243 - jmp __alltraps -vector244: - push 0 - push 244 - jmp __alltraps -vector245: - push 0 - push 245 - jmp __alltraps -vector246: - push 0 - push 246 - jmp __alltraps -vector247: - push 0 - push 247 - jmp __alltraps -vector248: - push 0 - push 248 - jmp __alltraps -vector249: - push 0 - push 249 - jmp __alltraps -vector250: - push 0 - push 250 - jmp __alltraps -vector251: - push 0 - push 251 - jmp __alltraps -vector252: - push 0 - push 252 - jmp __alltraps -vector253: - push 0 - push 253 - jmp __alltraps -vector254: - push 0 - push 254 - jmp __alltraps -vector255: - push 0 - push 255 - jmp __alltraps - -section .rodata -global __vectors -__vectors: - dq vector0 - dq vector1 - dq vector2 - dq vector3 - dq vector4 - dq vector5 - dq vector6 - dq vector7 - dq vector8 - dq vector9 - dq vector10 - dq vector11 - dq vector12 - dq vector13 - dq vector14 - dq vector15 - dq vector16 - dq vector17 - dq vector18 - dq vector19 - dq vector20 - dq vector21 - dq vector22 - dq vector23 - dq vector24 - dq vector25 - dq vector26 - dq vector27 - dq vector28 - dq vector29 - dq vector30 - dq vector31 - dq vector32 - dq vector33 - dq vector34 - dq vector35 - dq vector36 - dq vector37 - dq vector38 - dq vector39 - dq vector40 - dq vector41 - dq vector42 - dq vector43 - dq vector44 - dq vector45 - dq vector46 - dq vector47 - dq vector48 - dq vector49 - dq vector50 - dq vector51 - dq vector52 - dq vector53 - dq vector54 - dq vector55 - dq vector56 - dq vector57 - dq vector58 - dq vector59 - dq vector60 - dq vector61 - dq vector62 - dq vector63 - dq vector64 - dq vector65 - dq vector66 - dq vector67 - dq vector68 - dq vector69 - dq vector70 - dq vector71 - dq vector72 - dq vector73 - dq vector74 - dq vector75 - dq vector76 - dq vector77 - dq vector78 - dq vector79 - dq vector80 - dq vector81 - dq vector82 - dq vector83 - dq vector84 - dq vector85 - dq vector86 - dq vector87 - dq vector88 - dq vector89 - dq vector90 - dq vector91 - dq vector92 - dq vector93 - dq vector94 - dq vector95 - dq vector96 - dq vector97 - dq vector98 - dq vector99 - dq vector100 - dq vector101 - dq vector102 - dq vector103 - dq vector104 - dq vector105 - dq vector106 - dq vector107 - dq vector108 - dq vector109 - dq vector110 - dq vector111 - dq vector112 - dq vector113 - dq vector114 - dq vector115 - dq vector116 - dq vector117 - dq vector118 - dq vector119 - dq vector120 - dq vector121 - dq vector122 - dq vector123 - dq vector124 - dq vector125 - dq vector126 - dq vector127 - dq vector128 - dq vector129 - dq vector130 - dq vector131 - dq vector132 - dq vector133 - dq vector134 - dq vector135 - dq vector136 - dq vector137 - dq vector138 - dq vector139 - dq vector140 - dq vector141 - dq vector142 - dq vector143 - dq vector144 - dq vector145 - dq vector146 - dq vector147 - dq vector148 - dq vector149 - dq vector150 - dq vector151 - dq vector152 - dq vector153 - dq vector154 - dq vector155 - dq vector156 - dq vector157 - dq vector158 - dq vector159 - dq vector160 - dq vector161 - dq vector162 - dq vector163 - dq vector164 - dq vector165 - dq vector166 - dq vector167 - dq vector168 - dq vector169 - dq vector170 - dq vector171 - dq vector172 - dq vector173 - dq vector174 - dq vector175 - dq vector176 - dq vector177 - dq vector178 - dq vector179 - dq vector180 - dq vector181 - dq vector182 - dq vector183 - dq vector184 - dq vector185 - dq vector186 - dq vector187 - dq vector188 - dq vector189 - dq vector190 - dq vector191 - dq vector192 - dq vector193 - dq vector194 - dq vector195 - dq vector196 - dq vector197 - dq vector198 - dq vector199 - dq vector200 - dq vector201 - dq vector202 - dq vector203 - dq vector204 - dq vector205 - dq vector206 - dq vector207 - dq vector208 - dq vector209 - dq vector210 - dq vector211 - dq vector212 - dq vector213 - dq vector214 - dq vector215 - dq vector216 - dq vector217 - dq vector218 - dq vector219 - dq vector220 - dq vector221 - dq vector222 - dq vector223 - dq vector224 - dq vector225 - dq vector226 - dq vector227 - dq vector228 - dq vector229 - dq vector230 - dq vector231 - dq vector232 - dq vector233 - dq vector234 - dq vector235 - dq vector236 - dq vector237 - dq vector238 - dq vector239 - dq vector240 - dq vector241 - dq vector242 - dq vector243 - dq vector244 - dq vector245 - dq vector246 - dq vector247 - dq vector248 - dq vector249 - dq vector250 - dq vector251 - dq vector252 - dq vector253 - dq vector254 - dq vector255 diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index b22156e..c9e389d 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -67,6 +67,9 @@ use super::consts::*; use super::TrapFrame; +global_asm!(include_str!("trap.asm")); +global_asm!(include_str!("vector.asm")); + #[no_mangle] pub extern fn rust_trap(tf: &mut TrapFrame) { trace!("Interrupt: {:#x}", tf.trap_num); diff --git a/kernel/src/arch/x86_64/boot/trap.asm b/kernel/src/arch/x86_64/interrupt/trap.asm similarity index 78% rename from kernel/src/arch/x86_64/boot/trap.asm rename to kernel/src/arch/x86_64/interrupt/trap.asm index 093f29c..a12d6ee 100644 --- a/kernel/src/arch/x86_64/boot/trap.asm +++ b/kernel/src/arch/x86_64/interrupt/trap.asm @@ -1,5 +1,7 @@ -section .text -global __alltraps +.section .text +.global __alltraps +.intel_syntax noprefix + __alltraps: push rax push rcx @@ -19,14 +21,12 @@ __alltraps: push r15 mov rdi, rsp - extern rust_trap call rust_trap -global trap_ret +.global trap_ret trap_ret: mov rdi, rsp - extern set_return_rsp call set_return_rsp pop r15 @@ -46,7 +46,7 @@ trap_ret: pop rcx pop rax - ; pop trap_num, error_code + # pop trap_num, error_code add rsp, 16 iretq \ No newline at end of file diff --git a/kernel/src/arch/x86_64/memory.rs b/kernel/src/arch/x86_64/memory.rs index 00db06e..b7e695e 100644 --- a/kernel/src/arch/x86_64/memory.rs +++ b/kernel/src/arch/x86_64/memory.rs @@ -25,7 +25,7 @@ fn init_frame_allocator(boot_info: &BootInformation) { let mut ba = FRAME_ALLOCATOR.lock(); for area in memory_areas { - ba.insert(to_range(area.start_address(), area.end_address())); + ba.insert(to_range(area.start_address() as usize, area.end_address() as usize)); } for section in elf_sections { ba.remove(to_range(section.start_address() as usize, section.end_address() as usize)); diff --git a/kernel/src/consts.rs b/kernel/src/consts.rs index 272ccf1..4dddae0 100644 --- a/kernel/src/consts.rs +++ b/kernel/src/consts.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -#[cfg(target_arch = "riscv")] +#[cfg(target_arch = "riscv32")] pub use self::riscv::*; #[cfg(target_arch = "x86_64")] pub use self::x86_64::*; @@ -8,7 +8,7 @@ pub use self::x86_64::*; pub const MAX_CPU_NUM: usize = 8; pub const MAX_PROCESS_NUM: usize = 48; -#[cfg(target_arch = "riscv")] +#[cfg(target_arch = "riscv32")] mod riscv { // Physical address available on THINPAD: // [0x80000000, 0x80800000] diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index f45b6ee..c573623 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -4,8 +4,18 @@ use alloc::boxed::Box; use arch::driver::ide; use spin::Mutex; +// Hard link user program +#[cfg(target_arch = "riscv32")] +global_asm!(r#" + .section .rodata + .align 12 +_binary_user_riscv_img_start: + .incbin "../user/user-riscv.img" +_binary_user_riscv_img_end: +"#); + pub fn shell() { - #[cfg(target_arch = "riscv")] + #[cfg(target_arch = "riscv32")] let device = { extern { fn _binary_user_riscv_img_start(); diff --git a/kernel/src/lang.rs b/kernel/src/lang.rs index 5359cb6..ba7d060 100644 --- a/kernel/src/lang.rs +++ b/kernel/src/lang.rs @@ -1,37 +1,23 @@ // Rust language features implementions use core::panic::PanicInfo; +use core::alloc::Layout; #[lang = "eh_personality"] extern fn eh_personality() { } -#[cfg(target_arch = "x86_64")] #[panic_implementation] #[no_mangle] pub fn panic(info: &PanicInfo) -> ! { let location = info.location().unwrap(); let message = info.message().unwrap(); error!("\n\nPANIC in {} at line {}\n {}", location.file(), location.line(), message); - if cfg!(feature = "qemu_auto_exit") { - use arch::cpu; - unsafe{ cpu::exit_in_qemu(3) } - } else { - loop { } - } + loop { } } -#[cfg(target_arch = "riscv")] -#[lang = "panic_fmt"] -#[no_mangle] -pub fn panic_fmt(fmt: ::core::fmt::Arguments, file: &'static str, line: u32, col: u32) -> ! { - error!("\n\nPANIC in {} at {}:{}\n {}", file, line, col, fmt); - loop {} -} - -#[cfg(target_arch = "x86_64")] #[lang = "oom"] #[no_mangle] -pub fn oom() -> ! { +pub fn oom(_: Layout) -> ! { panic!("out of memory"); } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index cc3b6a0..b24d93a 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -5,7 +5,6 @@ #![feature(const_unique_new, const_atomic_usize_new)] #![feature(unique)] #![feature(allocator_api)] -#![feature(global_allocator)] #![feature(abi_x86_interrupt)] #![feature(iterator_step_by)] #![feature(unboxed_closures)] @@ -14,7 +13,6 @@ #![feature(optin_builtin_traits)] #![feature(panic_implementation)] #![feature(panic_info_message)] -#![feature(universal_impl_trait)] #![feature(global_asm)] #![feature(compiler_builtins_lib)] #![no_std] @@ -33,30 +31,19 @@ extern crate linked_list_allocator; extern crate log; #[macro_use] extern crate once; -#[cfg(target_arch = "x86_64")] -extern crate rlibc; -#[cfg(target_arch = "riscv")] -extern crate compiler_builtins; extern crate simple_filesystem; extern crate spin; extern crate ucore_memory; extern crate ucore_process; extern crate volatile; -#[macro_use] #[cfg(target_arch = "x86_64")] extern crate x86_64; extern crate xmas_elf; -// Export to asm -pub use arch::interrupt::rust_trap; -#[cfg(target_arch = "x86_64")] -pub use arch::interrupt::set_return_rsp; -#[cfg(target_arch = "x86_64")] -pub use arch::other_main; use linked_list_allocator::LockedHeap; #[macro_use] // print! -mod logging; +pub mod logging; mod memory; mod lang; mod util; @@ -73,11 +60,11 @@ mod console; #[allow(dead_code)] #[cfg(target_arch = "x86_64")] #[path = "arch/x86_64/mod.rs"] -mod arch; +pub mod arch; -#[cfg(target_arch = "riscv")] +#[cfg(target_arch = "riscv32")] #[path = "arch/riscv32/mod.rs"] -mod arch; +pub mod arch; /// The entry point of Rust kernel #[no_mangle] diff --git a/kernel/src/logging.rs b/kernel/src/logging.rs index 99b8ab0..a007cb4 100644 --- a/kernel/src/logging.rs +++ b/kernel/src/logging.rs @@ -15,12 +15,14 @@ pub fn init() { }); } +#[macro_export] macro_rules! print { ($($arg:tt)*) => ({ $crate::logging::print(format_args!($($arg)*)); }); } +#[macro_export] macro_rules! println { ($fmt:expr) => (print!(concat!($fmt, "\n"))); ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); diff --git a/kernel/src/main.rs b/kernel/src/main.rs new file mode 100644 index 0000000..8f0dad8 --- /dev/null +++ b/kernel/src/main.rs @@ -0,0 +1,6 @@ +#![no_std] // don't link the Rust standard library +#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points +#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] + +#[macro_use] +extern crate ucore; diff --git a/kernel/src/sync/condvar.rs b/kernel/src/sync/condvar.rs index 186be0e..4dbbc78 100644 --- a/kernel/src/sync/condvar.rs +++ b/kernel/src/sync/condvar.rs @@ -1,4 +1,4 @@ -use alloc::VecDeque; +use alloc::collections::VecDeque; use super::*; use thread; use thread_; diff --git a/kernel/src/sync/mpsc.rs b/kernel/src/sync/mpsc.rs index 1878794..5d2f46f 100644 --- a/kernel/src/sync/mpsc.rs +++ b/kernel/src/sync/mpsc.rs @@ -1,4 +1,4 @@ -use alloc::{arc::Arc, arc::Weak, VecDeque}; +use alloc::{sync::Arc, sync::Weak, collections::VecDeque}; use super::Condvar; use super::SpinLock as Mutex; diff --git a/kernel/src/sync/mutex.rs b/kernel/src/sync/mutex.rs index e288602..c8e62ea 100644 --- a/kernel/src/sync/mutex.rs +++ b/kernel/src/sync/mutex.rs @@ -215,7 +215,7 @@ impl MutexSupport for Spin { unsafe { #[cfg(target_arch = "x86_64")] asm!("pause" :::: "volatile"); - #[cfg(target_arch = "riscv")] + #[cfg(target_arch = "riscv32")] asm!("nop" :::: "volatile"); } } @@ -245,7 +245,7 @@ impl MutexSupport for SpinNoIrq { unsafe { #[cfg(target_arch = "x86_64")] asm!("pause" :::: "volatile"); - #[cfg(target_arch = "riscv")] + #[cfg(target_arch = "riscv32")] asm!("nop" :::: "volatile"); } } diff --git a/kernel/src/sync/test.rs b/kernel/src/sync/test.rs index 5a1c515..8ddb295 100644 --- a/kernel/src/sync/test.rs +++ b/kernel/src/sync/test.rs @@ -2,7 +2,7 @@ //! //! The code is borrowed from [RustDoc - Dining Philosophers](https://doc.rust-lang.org/1.6.0/book/dining-philosophers.html) -use alloc::{arc::Arc, Vec}; +use alloc::{sync::Arc, vec::Vec}; use core::time::Duration; use sync::Condvar; use sync::ThreadLock as Mutex; diff --git a/riscv-pk/configure b/riscv-pk/configure index c3b9c2a..49dddf3 100755 --- a/riscv-pk/configure +++ b/riscv-pk/configure @@ -4084,8 +4084,8 @@ fi case "${BUILD_32BIT}" in yes|default) echo "Building 32-bit pk" - CFLAGS="$default_CFLAGS -m32" - LDFLAGS="-m32" + CFLAGS="$default_CFLAGS -march=rv32i -mabi=ilp32" + LDFLAGS="-march=rv32i -mabi=ilp32" install_subdir="riscv32-unknown-elf" ;; *) diff --git a/riscv-pk/configure.ac b/riscv-pk/configure.ac index 5c08278..107a3f2 100644 --- a/riscv-pk/configure.ac +++ b/riscv-pk/configure.ac @@ -88,8 +88,8 @@ AC_ARG_ENABLE([32bit], case "${BUILD_32BIT}" in yes|default) echo "Building 32-bit pk" - CFLAGS="$default_CFLAGS -m32" - LDFLAGS="-m32" + CFLAGS="$default_CFLAGS -march=rv32i -mabi=ilp32" + LDFLAGS="-march=rv32i -mabi=ilp32" install_subdir="riscv32-unknown-elf" ;; *) diff --git a/riscv-pk/machine/minit.c b/riscv-pk/machine/minit.c index 7690341..c3fce3d 100644 --- a/riscv-pk/machine/minit.c +++ b/riscv-pk/machine/minit.c @@ -91,7 +91,7 @@ static void memory_init() static void hart_init() { mstatus_init(); - fp_init(); +// fp_init(); delegate_traps(); } diff --git a/user/Makefile b/user/Makefile index 52ebf0a..185ca0f 100644 --- a/user/Makefile +++ b/user/Makefile @@ -2,4 +2,4 @@ arch := riscv32 all: - @RUST_TARGET_PATH=$(shell pwd) xargo build --target $(arch)-ucore \ No newline at end of file + cargo xbuild --target $(arch)-ucore.json \ No newline at end of file diff --git a/user/Xargo.toml b/user/Xargo.toml deleted file mode 100644 index f79cb96..0000000 --- a/user/Xargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[dependencies] -alloc = {} - -[dependencies.compiler_builtins] -features = ["mem"] -stage = 1 diff --git a/user/riscv32-ucore.json b/user/riscv32-ucore.json index ef98b18..621b0da 100644 --- a/user/riscv32-ucore.json +++ b/user/riscv32-ucore.json @@ -5,12 +5,17 @@ "target-pointer-width": "32", "target-c-int-width": "32", "os": "none", - "arch": "riscv", + "arch": "riscv32", "cpu": "generic-rv32", - "features": "+m", + "features": "", "max-atomic-width": "32", - "linker": "riscv32-unknown-elf-ld", + "linker": "riscv64-unknown-elf-ld", "linker-flavor": "ld", + "pre-link-args": { + "ld": [ + "-melf32lriscv" + ] + }, "executables": true, "panic-strategy": "abort", "relocation-model": "static", diff --git a/user/ucore-ulib/src/lang_items.rs b/user/ucore-ulib/src/lang_items.rs index ef8a116..89e5334 100644 --- a/user/ucore-ulib/src/lang_items.rs +++ b/user/ucore-ulib/src/lang_items.rs @@ -1,4 +1,6 @@ use syscall::sys_exit; +use core::alloc::Layout; +use core::panic::PanicInfo; #[linkage = "weak"] #[no_mangle] @@ -7,8 +9,7 @@ fn main() { } #[no_mangle] -pub extern fn _start(_argc: isize, _argv: *const *const u8) -> ! -{ +pub extern fn _start(_argc: isize, _argv: *const *const u8) -> ! { main(); sys_exit(0) } @@ -16,25 +17,35 @@ pub extern fn _start(_argc: isize, _argv: *const *const u8) -> ! #[lang = "eh_personality"] fn eh_personality() {} -#[cfg(target_arch = "x86_64")] #[panic_implementation] -fn panic(info: &::core::panic::PanicInfo) -> ! { +fn panic(info: &PanicInfo) -> ! { let location = info.location().unwrap(); let message = info.message().unwrap(); println!("\n\nPANIC in {} at line {}\n {}", location.file(), location.line(), message); sys_exit(1) } -#[cfg(target_arch = "riscv")] -#[lang = "panic_fmt"] +#[lang = "oom"] +fn oom(_: Layout) -> ! { + panic!("out of memory"); +} + #[no_mangle] -pub fn panic_fmt(fmt: ::core::fmt::Arguments, file: &'static str, line: u32, col: u32) -> ! { - println!("\n\nPANIC in {} at {}:{}\n {}", file, line, col, fmt); - sys_exit(1) +pub extern fn abort() -> ! { + sys_exit(2) } -#[cfg(target_arch = "x86_64")] -#[lang = "oom"] -fn oom() -> ! { - panic!("out of memory"); +#[no_mangle] +pub extern fn __mulsi3(mut a: u32, mut b: u32) -> u32 { + let mut r: u32 = 0; + + while a > 0 { + if a & 1 > 0 { + r += b; + } + a >>= 1; + b <<= 1; + } + + r } \ No newline at end of file diff --git a/user/ucore-ulib/src/lib.rs b/user/ucore-ulib/src/lib.rs index c1c1cb7..fb4cf19 100644 --- a/user/ucore-ulib/src/lib.rs +++ b/user/ucore-ulib/src/lib.rs @@ -6,8 +6,6 @@ #![feature(linkage)] #![feature(compiler_builtins_lib)] -extern crate compiler_builtins; - #[macro_use] pub mod syscall; pub mod lang_items; \ No newline at end of file diff --git a/user/ucore-ulib/src/syscall.rs b/user/ucore-ulib/src/syscall.rs index 6e9acff..5d8765b 100644 --- a/user/ucore-ulib/src/syscall.rs +++ b/user/ucore-ulib/src/syscall.rs @@ -32,7 +32,7 @@ impl fmt::Write for StdOut { fn sys_call(id: usize, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> i32 { let ret: i32; unsafe { - #[cfg(target_arch = "riscv")] + #[cfg(target_arch = "riscv32")] asm!("ecall" : "={x10}" (ret) : "{x10}" (id), "{x11}" (arg0), "{x12}" (arg1), "{x13}" (arg2), "{x14}" (arg3), "{x15}" (arg4), "{x16}" (arg5)