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 5dcbec1..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 = "riscv32")] -#[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