Update rustsbi-k210 to enable lagacy console_putchar. Adjust alignment of links apps. Run matrix on K210!

This commit is contained in:
Yifan Wu 2020-12-10 17:20:13 +08:00
parent d0af7d26be
commit 63fe64ec0f
9 changed files with 88 additions and 108 deletions

68
user/src/bin/matrix.rs Normal file
View file

@ -0,0 +1,68 @@
#![no_std]
#![no_main]
#[macro_use]
extern crate user_lib;
use user_lib::{fork, wait, yield_, exit, getpid, get_time, wait_once};
static NUM: usize = 13;
const N: usize = 10;
static P: i32 = 10007;
type Arr = [[i32; N]; N];
fn work(times: isize) {
let mut a: Arr = Default::default();
let mut b: Arr = Default::default();
let mut c: Arr = Default::default();
for i in 0..N {
for j in 0..N {
a[i][j] = 1;
b[i][j] = 1;
}
}
yield_();
println!("pid {} is running ({} times)!.", getpid(), times);
for _ in 0..times {
for i in 0..N {
for j in 0..N {
c[i][j] = 0;
for k in 0..N {
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % P;
}
}
}
for i in 0..N {
for j in 0..N {
a[i][j] = c[i][j];
b[i][j] = c[i][j];
}
}
}
println!("pid {} done!.", getpid());
exit(0);
}
#[no_mangle]
pub fn main() -> i32 {
for _ in 0..NUM {
let pid = fork();
if pid == 0 {
let current_time = get_time();
let times = (current_time as i32 as isize) * (current_time as i32 as isize) % 1000;
work(times * 40);
}
}
println!("fork ok.");
let mut xstate: i32 = 0;
for _ in 0..NUM {
if wait(&mut xstate) < 0 {
panic!("wait failed.");
}
}
assert!(wait_once(&mut xstate) < 0);
println!("matrix passed.");
0
}