添加用户应用
parent
7f64711219
commit
771e7b12ff
@ -1,10 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use user_lib::*;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("hello 2");
|
||||
0
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("Into Test store_fault, we will insert an invalid store operation...");
|
||||
println!("Kernel should kill this application!");
|
||||
unsafe {
|
||||
core::ptr::null_mut::<u8>().write_volatile(0);
|
||||
}
|
||||
0
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
const SIZE: usize = 10;
|
||||
const P: u32 = 3;
|
||||
const STEP: usize = 100000;
|
||||
const MOD: u32 = 10007;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
let mut pow = [0u32; SIZE];
|
||||
let mut index: usize = 0;
|
||||
pow[index] = 1;
|
||||
for i in 1..=STEP {
|
||||
let last = pow[index];
|
||||
index = (index + 1) % SIZE;
|
||||
pow[index] = last * P % MOD;
|
||||
if i % 10000 == 0 {
|
||||
println!("{}^{}={}(MOD {})", P, i, pow[index], MOD);
|
||||
}
|
||||
}
|
||||
println!("Test power OK!");
|
||||
0
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use core::arch::asm;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("Try to execute privileged instruction in U Mode");
|
||||
println!("Kernel should kill this application!");
|
||||
unsafe {
|
||||
asm!("sret");
|
||||
}
|
||||
0
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use riscv::register::sstatus::{self, SPP};
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("Try to access privileged CSR in U Mode");
|
||||
println!("Kernel should kill this application!");
|
||||
unsafe {
|
||||
sstatus::set_spp(SPP::User);
|
||||
}
|
||||
0
|
||||
}
|
Loading…
Reference in New Issue