parent
ac3e330c9a
commit
5df22c8f87
@ -1,10 +1,8 @@
|
||||
.idea/*
|
||||
os/target/*
|
||||
os/.idea/*
|
||||
os/Cargo.lock
|
||||
.idea
|
||||
Cargo.lock
|
||||
target
|
||||
os/src/link_app.S
|
||||
os/last-*
|
||||
user/target/*
|
||||
user/.idea/*
|
||||
user/Cargo.lock
|
||||
tools/
|
||||
user/build
|
||||
tools
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{get_time, yield_};
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
let current_timer = get_time();
|
||||
let wait_for = current_timer + 3000;
|
||||
while get_time() < wait_for {
|
||||
yield_();
|
||||
}
|
||||
println!("Test sleep OK!");
|
||||
0
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{get_time, yield_};
|
||||
|
||||
/// 正确输出:(无报错信息)
|
||||
/// get_time OK! {...}
|
||||
/// Test sleep OK!
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
let current_time = get_time();
|
||||
assert!(current_time > 0);
|
||||
println!("get_time OK! {}", current_time);
|
||||
let wait_for = current_time + 3000;
|
||||
while get_time() < wait_for {
|
||||
yield_();
|
||||
}
|
||||
println!("Test sleep OK!");
|
||||
0
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{get_time, sleep};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
let start = get_time();
|
||||
println!("current time_msec = {}", start);
|
||||
sleep(100);
|
||||
let end = get_time();
|
||||
println!(
|
||||
"time_msec = {} after sleeping 100 ticks, delta = {}ms!",
|
||||
end,
|
||||
end - start
|
||||
);
|
||||
println!("Test sleep1 passed!");
|
||||
0
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(asm)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
extern crate core;
|
||||
use core::slice;
|
||||
use user_lib::{write, STDOUT};
|
||||
|
||||
/// 正确输出:
|
||||
/// Test write0 OK!
|
||||
|
||||
const STACK_SIZE: usize = 0x1000;
|
||||
|
||||
unsafe fn r_sp() -> usize {
|
||||
let mut sp: usize;
|
||||
asm!("mv {}, sp", out(reg) sp);
|
||||
sp
|
||||
}
|
||||
|
||||
unsafe fn stack_range() -> (usize, usize) {
|
||||
let sp = r_sp();
|
||||
let top = (sp + STACK_SIZE - 1) & (!(STACK_SIZE - 1));
|
||||
(top - STACK_SIZE, top)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
assert_eq!(
|
||||
write(STDOUT, unsafe {
|
||||
#[allow(clippy::zero_ptr)]
|
||||
slice::from_raw_parts(0x0 as *const _, 10)
|
||||
}),
|
||||
-1
|
||||
);
|
||||
let (bottom, top) = unsafe { stack_range() };
|
||||
assert_eq!(
|
||||
write(STDOUT, unsafe {
|
||||
slice::from_raw_parts((top - 5) as *const _, 10)
|
||||
}),
|
||||
-1
|
||||
);
|
||||
assert_eq!(
|
||||
write(STDOUT, unsafe {
|
||||
slice::from_raw_parts((bottom - 5) as *const _, 10)
|
||||
}),
|
||||
-1
|
||||
);
|
||||
// TODO: test string located in .data section
|
||||
println!("Test write0 OK!");
|
||||
0
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{write, STDOUT};
|
||||
const DATA_STRING: &str = "string from data section\n";
|
||||
|
||||
/// 正确输出:
|
||||
/// string from data section
|
||||
/// strinstring from stack section
|
||||
/// strin
|
||||
/// Test write1 OK!
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
assert_eq!(write(1234, DATA_STRING.as_bytes()), -1);
|
||||
assert_eq!(
|
||||
write(STDOUT, DATA_STRING.as_bytes()),
|
||||
DATA_STRING.len() as isize
|
||||
);
|
||||
assert_eq!(write(STDOUT, &DATA_STRING.as_bytes()[..5]), 5);
|
||||
let stack_string = "string from stack section\n";
|
||||
assert_eq!(
|
||||
write(STDOUT, stack_string.as_bytes()),
|
||||
stack_string.len() as isize
|
||||
);
|
||||
assert_eq!(write(STDOUT, &stack_string.as_bytes()[..5]), 5);
|
||||
println!("\nTest write1 OK!");
|
||||
0
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::set_priority;
|
||||
|
||||
/// 正确输出:(无报错信息)
|
||||
/// Test set_priority OK!
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
assert_eq!(set_priority(10), 10);
|
||||
assert_eq!(set_priority(isize::MAX), isize::MAX);
|
||||
assert_eq!(set_priority(0), -1);
|
||||
assert_eq!(set_priority(1), -1);
|
||||
assert_eq!(set_priority(-10), -1);
|
||||
println!("Test set_priority OK!");
|
||||
0
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{get_time, set_priority};
|
||||
|
||||
fn spin_delay() {
|
||||
let mut j = true;
|
||||
for _ in 0..10 {
|
||||
j = !j;
|
||||
}
|
||||
}
|
||||
|
||||
// to get enough accuracy, MAX_TIME (the running time of each process) should > 1000 mseconds.
|
||||
const MAX_TIME: isize = 1000;
|
||||
fn count_during(prio: isize) -> isize {
|
||||
let start_time = get_time();
|
||||
let mut acc = 0;
|
||||
set_priority(prio);
|
||||
loop {
|
||||
spin_delay();
|
||||
acc += 1;
|
||||
if acc % 400 == 0 {
|
||||
let time = get_time() - start_time;
|
||||
if time > MAX_TIME {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> usize {
|
||||
let prio = 6;
|
||||
let count = count_during(prio);
|
||||
println!("priority = {}, exitcode = {}", prio, count);
|
||||
0
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{get_time, set_priority};
|
||||
|
||||
fn spin_delay() {
|
||||
let mut j = true;
|
||||
for _ in 0..10 {
|
||||
j = !j;
|
||||
}
|
||||
}
|
||||
|
||||
// to get enough accuracy, MAX_TIME (the running time of each process) should > 1000 mseconds.
|
||||
const MAX_TIME: isize = 1000;
|
||||
fn count_during(prio: isize) -> isize {
|
||||
let start_time = get_time();
|
||||
let mut acc = 0;
|
||||
set_priority(prio);
|
||||
loop {
|
||||
spin_delay();
|
||||
acc += 1;
|
||||
if acc % 400 == 0 {
|
||||
let time = get_time() - start_time;
|
||||
if time > MAX_TIME {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> usize {
|
||||
let prio = 7;
|
||||
let count = count_during(prio);
|
||||
println!("priority = {}, exitcode = {}", prio, count);
|
||||
0
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{get_time, set_priority};
|
||||
|
||||
fn spin_delay() {
|
||||
let mut j = true;
|
||||
for _ in 0..10 {
|
||||
j = !j;
|
||||
}
|
||||
}
|
||||
|
||||
// to get enough accuracy, MAX_TIME (the running time of each process) should > 1000 mseconds.
|
||||
const MAX_TIME: isize = 1000;
|
||||
fn count_during(prio: isize) -> isize {
|
||||
let start_time = get_time();
|
||||
let mut acc = 0;
|
||||
set_priority(prio);
|
||||
loop {
|
||||
spin_delay();
|
||||
acc += 1;
|
||||
if acc % 400 == 0 {
|
||||
let time = get_time() - start_time;
|
||||
if time > MAX_TIME {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> usize {
|
||||
let prio = 8;
|
||||
let count = count_during(prio);
|
||||
println!("priority = {}, exitcode = {}", prio, count);
|
||||
0
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{get_time, set_priority};
|
||||
|
||||
fn spin_delay() {
|
||||
let mut j = true;
|
||||
for _ in 0..10 {
|
||||
j = !j;
|
||||
}
|
||||
}
|
||||
|
||||
// to get enough accuracy, MAX_TIME (the running time of each process) should > 1000 mseconds.
|
||||
const MAX_TIME: isize = 1000;
|
||||
fn count_during(prio: isize) -> isize {
|
||||
let start_time = get_time();
|
||||
let mut acc = 0;
|
||||
set_priority(prio);
|
||||
loop {
|
||||
spin_delay();
|
||||
acc += 1;
|
||||
if acc % 400 == 0 {
|
||||
let time = get_time() - start_time;
|
||||
if time > MAX_TIME {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> usize {
|
||||
let prio = 9;
|
||||
let count = count_during(prio);
|
||||
println!("priority = {}, exitcode = {}", prio, count);
|
||||
0
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{get_time, set_priority};
|
||||
|
||||
fn spin_delay() {
|
||||
let mut j = true;
|
||||
for _ in 0..10 {
|
||||
j = !j;
|
||||
}
|
||||
}
|
||||
|
||||
// to get enough accuracy, MAX_TIME (the running time of each process) should > 1000 mseconds.
|
||||
const MAX_TIME: isize = 1000;
|
||||
fn count_during(prio: isize) -> isize {
|
||||
let start_time = get_time();
|
||||
let mut acc = 0;
|
||||
set_priority(prio);
|
||||
loop {
|
||||
spin_delay();
|
||||
acc += 1;
|
||||
if acc % 400 == 0 {
|
||||
let time = get_time() - start_time;
|
||||
if time > MAX_TIME {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> usize {
|
||||
let prio = 10;
|
||||
let count = count_during(prio);
|
||||
println!("priority = {}, exitcode = {}", prio, count);
|
||||
0
|
||||
}
|
@ -1,10 +1,17 @@
|
||||
use crate::exit;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
let err = panic_info.message().unwrap();
|
||||
if let Some(location) = panic_info.location() {
|
||||
println!("Panicked at {}:{}, {}", location.file(), location.line(), err);
|
||||
println!(
|
||||
"Panicked at {}:{}, {}",
|
||||
location.file(),
|
||||
location.line(),
|
||||
err
|
||||
);
|
||||
} else {
|
||||
println!("Panicked: {}", err);
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
exit(-1);
|
||||
}
|
||||
|
Loading…
Reference in new issue