Fix user project for new toolchain

master
WangRunji 6 years ago
parent 4c402a5706
commit b61a2c9dd2

@ -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 = "riscv32")] #[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;
Loading…
Cancel
Save