Clear all code, make it compile for RISCV in docker.

master
WangRunji 6 years ago
parent 98be93e215
commit c0193e69e6

@ -19,7 +19,7 @@ opt-level = 1
[profile.release]
debug = true
[dependencies]
[target.x86_64-blog_os.dependencies]
bit_field = "0.9.0"
rlibc = "1.0"
volatile = "0.1.0"

@ -8,10 +8,13 @@
# make asm Open the deassemble file of the last build
# make clean Clean
arch ?= x86_64
arch ?= riscv
kernel := build/kernel-$(arch).bin
iso := build/os-$(arch).iso
target ?= $(arch)-blog_os
ifeq ($(arch), riscv)
target := riscv32i-unknown-none
endif
mode ?= debug
rust_os := target/$(target)/$(mode)/librust_ucore.a
@ -152,4 +155,7 @@ docker_interactive:
@docker run -it --rm $(docker_args) $(docker_image):$(tag)
docker_clean:
@docker volume rm $(docker_clean_args)
@docker volume rm $(docker_clean_args)
docker_riscv:
@docker run -it --rm $(docker_args) riscv-rust

@ -1,2 +1,2 @@
[target.x86_64-blog_os.dependencies]
[dependencies]
alloc = {}

@ -0,0 +1,30 @@
FROM ubuntu:latest
WORKDIR /rust
# Rust toolchain bins
# https://github.com/riscv-rust/rust/releases/download/riscv-rust-1.26.0-1-dev/rust-1.26.0-dev-x86_64-unknown-linux-gnu.tar.xz
ADD rust-1.26.0-dev-x86_64-unknown-linux-gnu.tar.xz .
# Rust src
# https://github.com/riscv-rust/rust/archive/riscv-rust-1.26.0-1-dev.zip
# with submodule: libcompiler_builtins, stdsimd
ADD rust-riscv-rust-1.26.0-1-dev.tar.gz .
# RISCV32 toolchain
# From tencent cloud for OS2018: ssh 2015011279@140.143.187.14
ADD rv32-toolchains-prebuild.tar.bz2 .
# Dependencies
RUN apt-get update && apt-get install -q -y --no-install-recommends libssl1.0.0 curl libssh2-1 gcc make git libc6-dev
# Rust bins need this
RUN mkdir -p /gnu/store/n6acaivs0jwiwpidjr551dhdni5kgpcr-glibc-2.26.105-g0890d5379c/lib \
&& ln -s /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /gnu/store/n6acaivs0jwiwpidjr551dhdni5kgpcr-glibc-2.26.105-g0890d5379c/lib/ld-linux-x86-64.so.2
# Install Rust toolchains
RUN ./rust-1.26.0-dev-x86_64-unknown-linux-gnu/install.sh && rm -rf ./rust-1.26.0-dev-x86_64-unknown-linux-gnu
# Install xargo
RUN cargo install xargo
# Env
ENV PATH=~/.cargo/bin:/rust/install-rv32/bin:$PATH
ENV XARGO_RUST_SRC=/rust/rust-riscv-rust-1.26.0-1-dev/src
RUN ln -s ~/.cargo/bin/xargo /usr/local/bin/xargo

@ -1,12 +1,12 @@
// Rust language features implementions
use core::panic::PanicInfo;
use arch::cpu;
#[lang = "eh_personality"]
extern fn eh_personality() {
}
#[cfg(target_arch = "x86_64")]
#[panic_implementation]
#[no_mangle]
pub fn panic(info: &PanicInfo) -> ! {
@ -14,12 +14,20 @@ pub fn panic(info: &PanicInfo) -> ! {
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 { }
}
}
#[cfg(target_arch = "riscv")]
#[lang = "panic_fmt"]
unsafe extern "C" fn panic_fmt(_fmt: ::core::fmt::Arguments, _file: &'static str, _line: u32, _col: u32) -> ! {
loop {}
}
#[cfg(target_arch = "x86_64")]
#[lang = "oom"]
#[no_mangle]
fn oom() -> ! {

@ -14,49 +14,79 @@
#![feature(optin_builtin_traits)]
#![feature(panic_implementation)]
#![feature(panic_info_message)]
#![feature(universal_impl_trait)]
#![no_std]
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate alloc;
#[cfg(target_arch = "x86_64")]
extern crate bit_allocator;
#[cfg(target_arch = "x86_64")]
extern crate bit_field;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate bitflags;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate lazy_static;
#[cfg(target_arch = "x86_64")]
extern crate linked_list_allocator;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate log;
#[cfg(target_arch = "x86_64")]
extern crate multiboot2;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate once;
#[cfg(target_arch = "x86_64")]
extern crate rlibc;
#[cfg(target_arch = "x86_64")]
extern crate simple_filesystem;
#[cfg(target_arch = "x86_64")]
extern crate spin;
#[cfg(target_arch = "x86_64")]
extern crate syscall as redox_syscall;
#[cfg(target_arch = "x86_64")]
extern crate uart_16550;
#[cfg(target_arch = "x86_64")]
extern crate ucore_memory;
#[cfg(target_arch = "x86_64")]
extern crate volatile;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate x86_64;
#[cfg(target_arch = "x86_64")]
extern crate xmas_elf;
#[cfg(target_arch = "x86_64")]
pub use arch::interrupt::{rust_trap, set_return_rsp};
#[cfg(target_arch = "x86_64")]
use linked_list_allocator::LockedHeap;
#[macro_use] // print!
#[cfg(target_arch = "x86_64")]
mod io;
#[cfg(target_arch = "x86_64")]
mod memory;
mod lang;
#[cfg(target_arch = "x86_64")]
mod util;
#[macro_use]
mod macros;
#[cfg(target_arch = "x86_64")]
mod consts;
#[cfg(target_arch = "x86_64")]
mod process;
#[cfg(target_arch = "x86_64")]
mod syscall;
#[cfg(target_arch = "x86_64")]
mod fs;
#[cfg(target_arch = "x86_64")]
mod thread;
#[cfg(target_arch = "x86_64")]
mod sync;
#[allow(dead_code)]
@ -66,6 +96,7 @@ mod arch;
/// The entry point of Rust kernel
#[no_mangle]
#[cfg(target_arch = "x86_64")]
pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! {
arch::idt::init();
io::init();
@ -124,6 +155,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! {
/// The entry point for another processors
#[no_mangle]
#[cfg(target_arch = "x86_64")]
pub extern "C" fn other_main() -> ! {
arch::gdt::init();
arch::idt::init();
@ -142,8 +174,10 @@ pub extern "C" fn other_main() -> ! {
///
/// It should be defined in memory mod, but in Rust `global_allocator` must be in root mod.
#[global_allocator]
#[cfg(target_arch = "x86_64")]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
#[cfg(target_arch = "x86_64")]
mod test {
pub fn global_allocator() {
for i in 0..10000 {

Loading…
Cancel
Save