Merge branch 'new-rv-toolchain' into board

# Conflicts:
#	kernel/Makefile
#	kernel/src/arch/riscv32/boot/entry.asm
master
WangRunji 6 years ago
commit 3d0d6e3d02

2
.gitignore vendored

@ -1,3 +1,3 @@
build build
target target
kernel/src/arch/x86_64/boot/vector.asm /kernel/src/arch/x86_64/interrupt/vector.asm

@ -2,13 +2,11 @@ sudo: required
language: rust language: rust
rust: nightly-2018-06-25 rust: nightly-2018-08-03
cache: cache:
cargo: true cargo: true
services: docker
addons: addons:
apt: apt:
packages: packages:
@ -20,18 +18,19 @@ env:
- ARCH="riscv32" - ARCH="riscv32"
- ARCH="x86_64" - ARCH="x86_64"
before_script: install:
- if [ $ARCH = x86_64 ]; then - if [ $ARCH = riscv32 ]; then
rustup component add rust-src && export FILE="riscv64-unknown-elf-gcc-2018.07.0-x86_64-linux-ubuntu14";
(test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) && wget https://static.dev.sifive.com/dev-tools/$FILE.tar.gz;
(test -x $HOME/.cargo/bin/xargo || cargo install xargo) && tar xf $FILE.tar.gz;
cargo install-update -a; export PATH=$PATH:$PWD/$FILE/bin;
fi 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: script:
- if [ $ARCH = riscv32 ]; then - cd kernel && make build arch=$ARCH
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

@ -1,6 +1,5 @@
#![no_std] #![no_std]
#![feature(asm)] #![feature(asm)]
#![feature(universal_impl_trait)]
extern crate bit_field; extern crate bit_field;

@ -20,7 +20,7 @@
use super::paging::*; use super::paging::*;
use super::*; use super::*;
use alloc::BTreeMap; use alloc::collections::BTreeMap;
use core::ops::{Deref, DerefMut}; use core::ops::{Deref, DerefMut};
/// Wrapper for page table, supporting shared map & copy-on-write /// Wrapper for page table, supporting shared map & copy-on-write

@ -1,7 +1,5 @@
#![no_std] #![no_std]
#![feature(alloc)] #![feature(alloc)]
#![feature(universal_impl_trait, conservative_impl_trait)]
#![feature(match_default_bindings)]
extern crate alloc; extern crate alloc;

@ -1,4 +1,4 @@
use alloc::vec_deque::VecDeque; use alloc::collections::VecDeque;
use super::*; use super::*;
use paging::Entry; use paging::Entry;

@ -1,4 +1,4 @@
use alloc::vec_deque::VecDeque; use alloc::collections::VecDeque;
use super::*; use super::*;
#[derive(Default)] #[derive(Default)]

@ -4,4 +4,4 @@ version = "0.1.0"
authors = ["WangRunji <wangrunji0408@163.com>"] authors = ["WangRunji <wangrunji0408@163.com>"]
[dependencies] [dependencies]
log = { git = "https://github.com/riscv-and-rust-and-decaf/log.git" } log = "0.4"

@ -1,4 +1,4 @@
use alloc::BinaryHeap; use alloc::collections::BinaryHeap;
use core::cmp::{Ordering, PartialOrd}; use core::cmp::{Ordering, PartialOrd};
type Time = usize; type Time = usize;

@ -1,8 +1,6 @@
#![no_std] #![no_std]
#![feature(alloc)] #![feature(alloc)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(linkage)]
#![feature(universal_impl_trait, conservative_impl_trait)]
extern crate alloc; extern crate alloc;
#[macro_use] #[macro_use]

@ -1,4 +1,4 @@
use alloc::{boxed::Box, BTreeMap}; use alloc::{boxed::Box, collections::BTreeMap};
use scheduler::*; use scheduler::*;
use event_hub::EventHub; use event_hub::EventHub;
use util::GetMut2; use util::GetMut2;

@ -1,4 +1,4 @@
use alloc::{BinaryHeap, Vec}; use alloc::{collections::BinaryHeap, vec::Vec};
type Pid = usize; type Pid = usize;

@ -27,7 +27,7 @@
//! ``` //! ```
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::BTreeMap; use alloc::collections::BTreeMap;
use core::any::Any; use core::any::Any;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::ptr; use core::ptr;

@ -1 +1 @@
Subproject commit 590eb508d4ddc503bf7220b8ec78a291129af4ef Subproject commit ed6e4c5b935d9d027303da829a7508c105df3139

102
kernel/Cargo.lock generated

@ -14,18 +14,10 @@ dependencies = [
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "bit-vec" name = "bit-vec"
version = "0.5.0" 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]] [[package]]
name = "bit_field" name = "bit_field"
@ -55,14 +47,6 @@ dependencies = [
"spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "linked_list_allocator" name = "linked_list_allocator"
version = "0.6.3" version = "0.6.3"
@ -74,14 +58,14 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.3" 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 = [ dependencies = [
"cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "multiboot2" name = "multiboot2"
version = "0.6.0" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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]] [[package]]
name = "simple-filesystem" name = "simple-filesystem"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust#7251ab7fb70f88172b31e3f38322b5ab81bca74b" source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust#ca10d11264c85932e95e6c7c29e8b10c91ae0720"
dependencies = [ 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)", "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" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
@ -180,7 +157,7 @@ version = "0.1.0"
name = "ucore-process" name = "ucore-process"
version = "0.1.0" version = "0.1.0"
dependencies = [ 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]] [[package]]
@ -200,7 +177,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "x86_64" name = "x86_64"
version = "0.2.8" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "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] [metadata]
"checksum bare-metal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eda0f54b2d49f18f3867a5e6d458299bb886db6e64c34d319d6b1aa0839ac31c" "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 (git+https://github.com/AltSysrq/bit-vec.git)" = "<none>"
"checksum bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf"
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" "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 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 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 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 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 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)" = "<none>" "checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2"
"checksum multiboot2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc447d7e888cd9ae093fb7a9117411c85e7c799afd69d0fff64bf47332bb91f7" "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 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 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 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)" = "<none>" "checksum simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)" = "<none>"
"checksum spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14db77c5b914df6d6173dda9a3b3f5937bd802934fa5edaf934df06a3491e56f" "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" "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 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 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 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 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" "checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5"

@ -1,22 +1,17 @@
[package] [package]
name = "rust-ucore" name = "ucore"
version = "0.1.0" version = "0.1.0"
authors = ["Runji Wang <wangrunji0408@163.com>"] authors = ["Runji Wang <wangrunji0408@163.com>"]
[lib] [lib]
crate-type = ["staticlib"] crate-type = ["staticlib", "rlib"]
[features] [features]
use_apic = [] use_apic = []
test = []
qemu_auto_exit = []
link_user_program = [] link_user_program = []
[profile.dev] [profile.dev]
# MUST >= 1 : Enable RVO to avoid stack overflow # 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 # MUST <= 1 : Avoid double fault at -O2 T_T
opt-level = 1 opt-level = 1
@ -24,30 +19,27 @@ opt-level = 1
debug = true debug = true
[dependencies] [dependencies]
# Fixed version for RV32 log = "0.4"
log = { git = "https://github.com/riscv-and-rust-and-decaf/log.git" }
rlibc = "1.0"
spin = "0.4.8" spin = "0.4.8"
once = "0.3.3" once = "0.3.3"
xmas-elf = "0.6" xmas-elf = "0.6"
bitflags = "1.0" bitflags = "1.0"
bit_field = "0.9.0" bit_field = "0.9.0"
volatile = "0.1.0" volatile = "0.1.0"
linked_list_allocator = "0.6"
lazy_static = { version = "1.0.0", features = ["spin_no_std"] } lazy_static = { version = "1.0.0", features = ["spin_no_std"] }
bit-allocator = { path = "../crate/bit-allocator" } bit-allocator = { path = "../crate/bit-allocator" }
ucore-memory = { path = "../crate/memory" } ucore-memory = { path = "../crate/memory" }
ucore-process = { path = "../crate/process" } ucore-process = { path = "../crate/process" }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" } simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }
[target.x86_64-blog_os.dependencies] [target.'cfg(target_arch = "x86_64")'.dependencies]
multiboot2 = "0.6" multiboot2 = "0.7"
x86_64 = "0.2.6" x86_64 = "0.2.11"
linked_list_allocator = "0.6"
redox_syscall = "0.1" redox_syscall = "0.1"
uart_16550 = "0.1" uart_16550 = "0.1"
[target.riscv32-blog_os.dependencies] [target.'cfg(target_arch = "riscv32")'.dependencies]
linked_list_allocator = "0.5" # due to rust version
riscv = { path = "../crate/riscv" } riscv = { path = "../crate/riscv" }
bbl = { path = "../crate/bbl" } bbl = { path = "../crate/bbl" }

@ -14,7 +14,7 @@ kernel := build/$(arch)/kernel.bin
iso := build/$(arch)/os.iso iso := build/$(arch)/os.iso
target ?= $(arch)-blog_os target ?= $(arch)-blog_os
mode ?= debug mode ?= debug
rust_lib := target/$(target)/$(mode)/librust_ucore.a rust_lib := target/$(target)/$(mode)/ucore
boot_src := src/arch/$(arch)/boot boot_src := src/arch/$(arch)/boot
linker_script := $(boot_src)/linker.ld 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 user_obj := build/$(arch)/user.o
SFSIMG := ../user/ucore32.img SFSIMG := ../user/ucore32.img
ifeq ($(arch), x86_64) 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 endif
ifeq ($(arch), riscv32) ifeq ($(arch), riscv32)
qemu_opts := -machine virt -kernel $(iso) -nographic qemu_opts := -machine virt -kernel $(iso) -nographic
@ -42,33 +42,20 @@ features := $(features) link_user_program
assembly_object_files := $(assembly_object_files) $(user_obj) assembly_object_files := $(assembly_object_files) $(user_obj)
endif endif
# Link user-riscv.img for RV32 ifdef d
ifeq ($(arch), riscv32) qemu_opts := $(qemu_opts) -d $(d)
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
endif endif
build_args := --target $(target) --features "$(features)" build_args := --target $(target).json --features "$(features)"
ifeq ($(mode), release) ifeq ($(mode), release)
build_args := $(build_args) --release build_args := $(build_args) --release
endif endif
ifeq ($(arch), x86_64)
build_args := $(build_args) --lib
endif
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
uname := Win32 uname := Win32
@ -80,7 +67,7 @@ ifeq ($(uname), Darwin)
prefix := x86_64-elf- prefix := x86_64-elf-
endif endif
ifeq ($(arch), riscv32) ifeq ($(arch), riscv32)
prefix := riscv32-unknown-elf- prefix := riscv64-unknown-elf-
endif endif
ld := $(prefix)ld ld := $(prefix)ld
@ -123,33 +110,22 @@ build/x86_64/os.iso: $(kernel) $(grub_cfg)
@grub-mkrescue -o $(iso) build/isofiles 2> /dev/null @grub-mkrescue -o $(iso) build/isofiles 2> /dev/null
@rm -r build/isofiles @rm -r build/isofiles
build/riscv32/os.iso: $(kernel) build/riscv32/os.iso: kernel
@cp $(kernel) $@ @cp $(rust_lib) $@
$(kernel): kernel $(assembly_object_files) $(linker_script) $(kernel): kernel $(assembly_object_files) $(linker_script)
@$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \ @$(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: kernel:
@RUST_TARGET_PATH=$(shell pwd) CC=$(cc) xargo build $(build_args) @CC=$(cc) cargo xbuild $(build_args)
# compile assembly files # compile assembly files
build/x86_64/boot/%.o: $(boot_src)/%.asm build/x86_64/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@) @mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@ @nasm -felf64 $< -o $@
build/riscv32/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@$(as) -march=rv32i $< -o $@
# make user.o from binary files # make user.o from binary files
$(user_obj): $(user_bins) $(user_obj): $(user_bins)
@cd $(user_bin_path) && \ @cd $(user_bin_path) && \
$(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins))) $(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

@ -1,6 +0,0 @@
[dependencies]
alloc = {}
[target.riscv32-blog_os.dependencies.compiler_builtins]
features = ["mem"]
stage = 1

@ -4,7 +4,7 @@ use std::fs::File;
use std::io::{Write, Result}; use std::io::{Write, Result};
fn main() { 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() cc::Build::new()
.file("src/arch/x86_64/driver/apic/lapic.c") .file("src/arch/x86_64/driver/apic/lapic.c")
.file("src/arch/x86_64/driver/keyboard/keyboard.c") .file("src/arch/x86_64/driver/keyboard/keyboard.c")
@ -15,11 +15,11 @@ fn main() {
} }
fn gen_vector_asm() -> Result<()> { 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, "# generated by build.rs - do not edit")?;
writeln!(f, "section .text")?; writeln!(f, ".section .text")?;
writeln!(f, "extern __alltraps")?; writeln!(f, ".intel_syntax noprefix")?;
for i in 0..256 { for i in 0..256 {
writeln!(f, "vector{}:", i)?; writeln!(f, "vector{}:", i)?;
if !(i == 8 || (i >= 10 && i <= 14) || i == 17) { if !(i == 8 || (i >= 10 && i <= 14) || i == 17) {
@ -29,11 +29,11 @@ fn gen_vector_asm() -> Result<()> {
writeln!(f, "\tjmp __alltraps")?; writeln!(f, "\tjmp __alltraps")?;
} }
writeln!(f, "\nsection .rodata")?; writeln!(f, "\n.section .rodata")?;
writeln!(f, "global __vectors")?; writeln!(f, ".global __vectors")?;
writeln!(f, "__vectors:")?; writeln!(f, "__vectors:")?;
for i in 0..256 { for i in 0..256 {
writeln!(f, "\tdq vector{}", i)?; writeln!(f, "\t.quad vector{}", i)?;
} }
Ok(()) Ok(())
} }

@ -5,12 +5,18 @@
"target-pointer-width": "32", "target-pointer-width": "32",
"target-c-int-width": "32", "target-c-int-width": "32",
"os": "none", "os": "none",
"arch": "riscv", "arch": "riscv32",
"cpu": "generic-rv32", "cpu": "generic-rv32",
"features": "+m", "features": "",
"max-atomic-width": "32", "max-atomic-width": "32",
"linker": "ld.lld", "linker": "riscv64-unknown-elf-ld",
"linker-flavor": "ld", "linker-flavor": "ld",
"pre-link-args": {
"ld": [
"-Tsrc/arch/riscv32/boot/linker.ld",
"-melf32lriscv"
]
},
"executables": true, "executables": true,
"panic-strategy": "abort", "panic-strategy": "abort",
"relocation-model": "static", "relocation-model": "static",

@ -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<T>(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<T>(dst: *mut T, val: T, _order: Ordering) {
+ use ptr::write;
+ write(dst, val);
}
#[inline]
@@ -1580,15 +1574,22 @@
}
#[inline]
-unsafe fn atomic_swap<T>(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<T>(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<T>(dst: *mut T,
+#[cfg(target_arch = "riscv")]
+unsafe fn atomic_compare_exchange<T: PartialEq>(dst: *mut T,
old: T,
new: T,
- success: Ordering,
- failure: Ordering)
+ _success: Ordering,
+ _failure: Ordering)
-> Result<T, T> {
- 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]

@ -1,20 +1,22 @@
.section .entry .section .entry
.global _start .global _start
_start: _start:
csrw mie, 0 csrwi 0x304, 0 # mie
csrw mip, 0 csrwi 0x344, 0 # mip
csrw mscratch, 0 csrwi 0x340, 0 # mscratch
csrw satp, 0 csrwi 0x180, 0 # satp
li t0, -1 li t0, -1
csrw medeleg, t0 csrw 0x302, t0 # medeleg
csrw mideleg, t0 csrw 0x303, t0 # mideleg
csrw mcounteren, t0 csrw 0x306, t0 # mcounteren
csrw scounteren, t0 csrw 0x106, t0 # scounteren
li t0, 1 << 11 ; MPP = S li t0, 1 << 11 # MPP = S
csrw mstatus, t0 csrw 0x300, t0 # mstatus
la t0, rust_main lui t0, %hi(rust_main)
csrw mepc, t0 addi t0, t0, %lo(rust_main)
la sp, bootstacktop csrw 0x341, t0 # mepc
lui sp, %hi(bootstacktop)
addi sp, sp, %lo(bootstacktop)
mret mret
.section .bss .section .bss

@ -2,10 +2,10 @@
# If coming from userspace, preserve the user stack pointer and load # If coming from userspace, preserve the user stack pointer and load
# the kernel stack pointer. If we came from the kernel, sscratch # the kernel stack pointer. If we came from the kernel, sscratch
# will contain 0, and we should continue on the current stack. # will contain 0, and we should continue on the current stack.
csrrw sp, sscratch, sp csrrw sp, 0x140, sp # sscratch
bnez sp, _save_context bnez sp, _save_context
_restore_kernel_sp: _restore_kernel_sp:
csrr sp, sscratch csrr sp, 0x140 # sscratch
# sscratch = previous-sp, sp = kernel-sp # sscratch = previous-sp, sp = kernel-sp
_save_context: _save_context:
# provide room for trap frame # provide room for trap frame
@ -42,13 +42,13 @@ _save_context:
sw x30, 30*4(sp) sw x30, 30*4(sp)
sw x31, 31*4(sp) sw x31, 31*4(sp)
# get sp, sstatus, sepc, sbadvaddr, scause # get sp, sstatus, sepc, stval, scause
# set sscratch = 0 # set sscratch = 0
csrrw s0, sscratch, x0 csrrw s0, 0x140, x0 # sscratch
csrr s1, sstatus csrr s1, 0x100 # sstatus
csrr s2, sepc csrr s2, 0x141 # sepc
csrr s3, sbadaddr csrr s3, 0x143 # stval
csrr s4, scause csrr s4, 0x142 # scause
# store sp, sstatus, sepc, sbadvaddr, scause # store sp, sstatus, sepc, sbadvaddr, scause
sw s0, 2*4(sp) sw s0, 2*4(sp)
sw s1, 32*4(sp) sw s1, 32*4(sp)
@ -64,11 +64,11 @@ _save_context:
bnez s0, _restore_context # back to U-mode? (sstatus.SPP = 1) bnez s0, _restore_context # back to U-mode? (sstatus.SPP = 1)
_save_kernel_sp: _save_kernel_sp:
addi s0, sp, 36*4 addi s0, sp, 36*4
csrw sscratch, s0 # sscratch = kernel-sp csrw 0x140, s0 # sscratch = kernel-sp
_restore_context: _restore_context:
# restore sstatus, sepc # restore sstatus, sepc
csrw sstatus, s1 csrw 0x100, s1
csrw sepc, s2 csrw 0x141, s2
# restore x registers except x2 (sp) # restore x registers except x2 (sp)
lw x1, 1*4(sp) lw x1, 1*4(sp)
@ -109,7 +109,7 @@ _restore_context:
.globl __alltraps .globl __alltraps
__alltraps: __alltraps:
SAVE_ALL SAVE_ALL
move a0, sp mv a0, sp
jal rust_trap jal rust_trap
.globl __trapret .globl __trapret
__trapret: __trapret:

@ -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<T: PartialEq>(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)
}

@ -5,10 +5,14 @@ pub mod interrupt;
pub mod timer; pub mod timer;
pub mod paging; pub mod paging;
pub mod memory; pub mod memory;
pub mod compiler_rt;
pub fn init() { pub fn init() {
println!("Hello RISCV! {}", 123); println!("Hello RISCV! {}", 123);
interrupt::init(); interrupt::init();
memory::init(); memory::init();
timer::init(); timer::init();
} }
global_asm!(include_str!("boot/entry.asm"));
global_asm!(include_str!("boot/trap.asm"));

File diff suppressed because it is too large Load Diff

@ -67,6 +67,9 @@
use super::consts::*; use super::consts::*;
use super::TrapFrame; use super::TrapFrame;
global_asm!(include_str!("trap.asm"));
global_asm!(include_str!("vector.asm"));
#[no_mangle] #[no_mangle]
pub extern fn rust_trap(tf: &mut TrapFrame) { pub extern fn rust_trap(tf: &mut TrapFrame) {
trace!("Interrupt: {:#x}", tf.trap_num); trace!("Interrupt: {:#x}", tf.trap_num);

@ -1,5 +1,7 @@
section .text .section .text
global __alltraps .global __alltraps
.intel_syntax noprefix
__alltraps: __alltraps:
push rax push rax
push rcx push rcx
@ -19,14 +21,12 @@ __alltraps:
push r15 push r15
mov rdi, rsp mov rdi, rsp
extern rust_trap
call rust_trap call rust_trap
global trap_ret .global trap_ret
trap_ret: trap_ret:
mov rdi, rsp mov rdi, rsp
extern set_return_rsp
call set_return_rsp call set_return_rsp
pop r15 pop r15
@ -46,7 +46,7 @@ trap_ret:
pop rcx pop rcx
pop rax pop rax
; pop trap_num, error_code # pop trap_num, error_code
add rsp, 16 add rsp, 16
iretq iretq

@ -25,7 +25,7 @@ fn init_frame_allocator(boot_info: &BootInformation) {
let mut ba = FRAME_ALLOCATOR.lock(); let mut ba = FRAME_ALLOCATOR.lock();
for area in memory_areas { 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 { for section in elf_sections {
ba.remove(to_range(section.start_address() as usize, section.end_address() as usize)); ba.remove(to_range(section.start_address() as usize, section.end_address() as usize));

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
#[cfg(target_arch = "riscv")] #[cfg(target_arch = "riscv32")]
pub use self::riscv::*; pub use self::riscv::*;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub use self::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_CPU_NUM: usize = 8;
pub const MAX_PROCESS_NUM: usize = 48; pub const MAX_PROCESS_NUM: usize = 48;
#[cfg(target_arch = "riscv")] #[cfg(target_arch = "riscv32")]
mod riscv { mod riscv {
// Physical address available on THINPAD: // Physical address available on THINPAD:
// [0x80000000, 0x80800000] // [0x80000000, 0x80800000]

@ -4,8 +4,18 @@ use alloc::boxed::Box;
use arch::driver::ide; use arch::driver::ide;
use spin::Mutex; 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() { pub fn shell() {
#[cfg(target_arch = "riscv")] #[cfg(target_arch = "riscv32")]
let device = { let device = {
extern { extern {
fn _binary_user_riscv_img_start(); fn _binary_user_riscv_img_start();

@ -1,37 +1,23 @@
// Rust language features implementions // Rust language features implementions
use core::panic::PanicInfo; use core::panic::PanicInfo;
use core::alloc::Layout;
#[lang = "eh_personality"] #[lang = "eh_personality"]
extern fn eh_personality() { extern fn eh_personality() {
} }
#[cfg(target_arch = "x86_64")]
#[panic_implementation] #[panic_implementation]
#[no_mangle] #[no_mangle]
pub fn panic(info: &PanicInfo) -> ! { pub fn panic(info: &PanicInfo) -> ! {
let location = info.location().unwrap(); let location = info.location().unwrap();
let message = info.message().unwrap(); let message = info.message().unwrap();
error!("\n\nPANIC in {} at line {}\n {}", location.file(), location.line(), message); error!("\n\nPANIC in {} at line {}\n {}", location.file(), location.line(), message);
if cfg!(feature = "qemu_auto_exit") { loop { }
use arch::cpu;
unsafe{ cpu::exit_in_qemu(3) }
} else {
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"] #[lang = "oom"]
#[no_mangle] #[no_mangle]
pub fn oom() -> ! { pub fn oom(_: Layout) -> ! {
panic!("out of memory"); panic!("out of memory");
} }

@ -5,7 +5,6 @@
#![feature(const_unique_new, const_atomic_usize_new)] #![feature(const_unique_new, const_atomic_usize_new)]
#![feature(unique)] #![feature(unique)]
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(global_allocator)]
#![feature(abi_x86_interrupt)] #![feature(abi_x86_interrupt)]
#![feature(iterator_step_by)] #![feature(iterator_step_by)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
@ -14,7 +13,6 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(panic_implementation)] #![feature(panic_implementation)]
#![feature(panic_info_message)] #![feature(panic_info_message)]
#![feature(universal_impl_trait)]
#![feature(global_asm)] #![feature(global_asm)]
#![feature(compiler_builtins_lib)] #![feature(compiler_builtins_lib)]
#![no_std] #![no_std]
@ -33,30 +31,19 @@ extern crate linked_list_allocator;
extern crate log; extern crate log;
#[macro_use] #[macro_use]
extern crate once; 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 simple_filesystem;
extern crate spin; extern crate spin;
extern crate ucore_memory; extern crate ucore_memory;
extern crate ucore_process; extern crate ucore_process;
extern crate volatile; extern crate volatile;
#[macro_use]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
extern crate x86_64; extern crate x86_64;
extern crate xmas_elf; 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; use linked_list_allocator::LockedHeap;
#[macro_use] // print! #[macro_use] // print!
mod logging; pub mod logging;
mod memory; mod memory;
mod lang; mod lang;
mod util; mod util;
@ -73,11 +60,11 @@ mod console;
#[allow(dead_code)] #[allow(dead_code)]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[path = "arch/x86_64/mod.rs"] #[path = "arch/x86_64/mod.rs"]
mod arch; pub mod arch;
#[cfg(target_arch = "riscv")] #[cfg(target_arch = "riscv32")]
#[path = "arch/riscv32/mod.rs"] #[path = "arch/riscv32/mod.rs"]
mod arch; pub mod arch;
/// The entry point of Rust kernel /// The entry point of Rust kernel
#[no_mangle] #[no_mangle]

@ -15,12 +15,14 @@ pub fn init() {
}); });
} }
#[macro_export]
macro_rules! print { macro_rules! print {
($($arg:tt)*) => ({ ($($arg:tt)*) => ({
$crate::logging::print(format_args!($($arg)*)); $crate::logging::print(format_args!($($arg)*));
}); });
} }
#[macro_export]
macro_rules! println { macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n"))); ($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));

@ -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;

@ -1,4 +1,4 @@
use alloc::VecDeque; use alloc::collections::VecDeque;
use super::*; use super::*;
use thread; use thread;
use thread_; use thread_;

@ -1,4 +1,4 @@
use alloc::{arc::Arc, arc::Weak, VecDeque}; use alloc::{sync::Arc, sync::Weak, collections::VecDeque};
use super::Condvar; use super::Condvar;
use super::SpinLock as Mutex; use super::SpinLock as Mutex;

@ -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 = "riscv")] #[cfg(target_arch = "riscv32")]
asm!("nop" :::: "volatile"); asm!("nop" :::: "volatile");
} }
} }
@ -245,7 +245,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 = "riscv")] #[cfg(target_arch = "riscv32")]
asm!("nop" :::: "volatile"); asm!("nop" :::: "volatile");
} }
} }

@ -2,7 +2,7 @@
//! //!
//! The code is borrowed from [RustDoc - Dining Philosophers](https://doc.rust-lang.org/1.6.0/book/dining-philosophers.html) //! 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 core::time::Duration;
use sync::Condvar; use sync::Condvar;
use sync::ThreadLock as Mutex; use sync::ThreadLock as Mutex;

@ -4084,8 +4084,8 @@ fi
case "${BUILD_32BIT}" in case "${BUILD_32BIT}" in
yes|default) yes|default)
echo "Building 32-bit pk" echo "Building 32-bit pk"
CFLAGS="$default_CFLAGS -m32" CFLAGS="$default_CFLAGS -march=rv32i -mabi=ilp32"
LDFLAGS="-m32" LDFLAGS="-march=rv32i -mabi=ilp32"
install_subdir="riscv32-unknown-elf" install_subdir="riscv32-unknown-elf"
;; ;;
*) *)

@ -88,8 +88,8 @@ AC_ARG_ENABLE([32bit],
case "${BUILD_32BIT}" in case "${BUILD_32BIT}" in
yes|default) yes|default)
echo "Building 32-bit pk" echo "Building 32-bit pk"
CFLAGS="$default_CFLAGS -m32" CFLAGS="$default_CFLAGS -march=rv32i -mabi=ilp32"
LDFLAGS="-m32" LDFLAGS="-march=rv32i -mabi=ilp32"
install_subdir="riscv32-unknown-elf" install_subdir="riscv32-unknown-elf"
;; ;;
*) *)

@ -91,7 +91,7 @@ static void memory_init()
static void hart_init() static void hart_init()
{ {
mstatus_init(); mstatus_init();
fp_init(); // fp_init();
delegate_traps(); delegate_traps();
} }

@ -2,4 +2,4 @@
arch := riscv32 arch := riscv32
all: all:
@RUST_TARGET_PATH=$(shell pwd) xargo build --target $(arch)-ucore cargo xbuild --target $(arch)-ucore.json

@ -1,6 +0,0 @@
[dependencies]
alloc = {}
[dependencies.compiler_builtins]
features = ["mem"]
stage = 1

@ -5,12 +5,17 @@
"target-pointer-width": "32", "target-pointer-width": "32",
"target-c-int-width": "32", "target-c-int-width": "32",
"os": "none", "os": "none",
"arch": "riscv", "arch": "riscv32",
"cpu": "generic-rv32", "cpu": "generic-rv32",
"features": "+m", "features": "",
"max-atomic-width": "32", "max-atomic-width": "32",
"linker": "riscv32-unknown-elf-ld", "linker": "riscv64-unknown-elf-ld",
"linker-flavor": "ld", "linker-flavor": "ld",
"pre-link-args": {
"ld": [
"-melf32lriscv"
]
},
"executables": true, "executables": true,
"panic-strategy": "abort", "panic-strategy": "abort",
"relocation-model": "static", "relocation-model": "static",

@ -1,4 +1,6 @@
use syscall::sys_exit; use syscall::sys_exit;
use core::alloc::Layout;
use core::panic::PanicInfo;
#[linkage = "weak"] #[linkage = "weak"]
#[no_mangle] #[no_mangle]
@ -7,8 +9,7 @@ fn main() {
} }
#[no_mangle] #[no_mangle]
pub extern fn _start(_argc: isize, _argv: *const *const u8) -> ! pub extern fn _start(_argc: isize, _argv: *const *const u8) -> ! {
{
main(); main();
sys_exit(0) sys_exit(0)
} }
@ -16,25 +17,35 @@ pub extern fn _start(_argc: isize, _argv: *const *const u8) -> !
#[lang = "eh_personality"] #[lang = "eh_personality"]
fn eh_personality() {} fn eh_personality() {}
#[cfg(target_arch = "x86_64")]
#[panic_implementation] #[panic_implementation]
fn panic(info: &::core::panic::PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
let location = info.location().unwrap(); let location = info.location().unwrap();
let message = info.message().unwrap(); let message = info.message().unwrap();
println!("\n\nPANIC in {} at line {}\n {}", location.file(), location.line(), message); println!("\n\nPANIC in {} at line {}\n {}", location.file(), location.line(), message);
sys_exit(1) sys_exit(1)
} }
#[cfg(target_arch = "riscv")] #[lang = "oom"]
#[lang = "panic_fmt"] fn oom(_: Layout) -> ! {
panic!("out of memory");
}
#[no_mangle] #[no_mangle]
pub fn panic_fmt(fmt: ::core::fmt::Arguments, file: &'static str, line: u32, col: u32) -> ! { pub extern fn abort() -> ! {
println!("\n\nPANIC in {} at {}:{}\n {}", file, line, col, fmt); sys_exit(2)
sys_exit(1)
} }
#[cfg(target_arch = "x86_64")] #[no_mangle]
#[lang = "oom"] pub extern fn __mulsi3(mut a: u32, mut b: u32) -> u32 {
fn oom() -> ! { let mut r: u32 = 0;
panic!("out of memory");
while a > 0 {
if a & 1 > 0 {
r += b;
}
a >>= 1;
b <<= 1;
}
r
} }

@ -6,8 +6,6 @@
#![feature(linkage)] #![feature(linkage)]
#![feature(compiler_builtins_lib)] #![feature(compiler_builtins_lib)]
extern crate compiler_builtins;
#[macro_use] #[macro_use]
pub mod syscall; pub mod syscall;
pub mod lang_items; pub mod lang_items;

@ -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 { fn sys_call(id: usize, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> i32 {
let ret: i32; let ret: i32;
unsafe { unsafe {
#[cfg(target_arch = "riscv")] #[cfg(target_arch = "riscv32")]
asm!("ecall" asm!("ecall"
: "={x10}" (ret) : "={x10}" (ret)
: "{x10}" (id), "{x11}" (arg0), "{x12}" (arg1), "{x13}" (arg2), "{x14}" (arg3), "{x15}" (arg4), "{x16}" (arg5) : "{x10}" (id), "{x11}" (arg0), "{x12}" (arg1), "{x13}" (arg2), "{x14}" (arg3), "{x15}" (arg4), "{x16}" (arg5)

Loading…
Cancel
Save