-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
377 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
mod gpio; | ||
// mod ir; | ||
mod lcd; | ||
mod network; | ||
// mod network; | ||
pub fn init() { | ||
gpio::init(); | ||
lcd::init(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,33 @@ | ||
#[inline(always)] | ||
fn scall(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize { | ||
let mut ret; | ||
unsafe { | ||
asm!("ecall", | ||
in( "x10") arg0, | ||
in("x11") arg1, | ||
in ("x12") arg2, | ||
in("x17") which, | ||
lateout("x10") ret, | ||
options(nostack) | ||
); | ||
} | ||
ret | ||
} | ||
|
||
const SBI_SET_TIMER: usize = 0; | ||
const SBI_CONSOLE_PUTCHAR: usize = 1; | ||
const SBI_SHUTDOWN: usize = 8; | ||
|
||
pub fn shutdown() -> ! { | ||
scall(SBI_SHUTDOWN, 0, 0, 0); | ||
panic!("It should shutdown!"); | ||
} | ||
mod proxy; | ||
pub use proxy::*; | ||
mod fs; | ||
mod process; | ||
|
||
pub fn put_char(c: usize) { | ||
scall(SBI_CONSOLE_PUTCHAR, c, 0, 0); | ||
} | ||
use fs::*; | ||
use process::*; | ||
|
||
pub fn set_timer(timer: usize) { | ||
scall(SBI_SET_TIMER, timer, 0, 0); | ||
} | ||
const SYSCALL_READ: usize = 63; | ||
const SYSCALL_WRITE: usize = 64; | ||
const SYSCALL_EXIT: usize = 93; | ||
const SYSCALL_YIELD: usize = 124; | ||
const SYSCALL_GET_TIME: usize = 169; | ||
const SYSCALL_GETPID: usize = 172; | ||
const SYSCALL_FORK: usize = 220; | ||
const SYSCALL_EXEC: usize = 221; | ||
const SYSCALL_WAITPID: usize = 260; | ||
|
||
mod fs; | ||
mod process; | ||
|
||
use fs::*; | ||
use process::*; | ||
// 处理来自 apps 的 trap | ||
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize { | ||
match syscall_id { | ||
SYSCALL_READ => sys_read(args[0], args[1] as *const u8, args[2]), | ||
SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]), | ||
SYSCALL_EXIT => sys_exit(args[0] as i32), | ||
SYSCALL_YIELD => sys_yield(), | ||
SYSCALL_GET_TIME => sys_get_time(), | ||
SYSCALL_GETPID => sys_getpid(), | ||
SYSCALL_FORK => sys_fork(), | ||
SYSCALL_EXEC => sys_exec(args[0] as *const u8), | ||
SYSCALL_WAITPID => sys_waitpid(args[0] as isize, args[1] as *mut i32), | ||
_ => panic!("Unsupported syscall_id: {}", syscall_id), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[inline(always)] | ||
fn scall(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize { | ||
let mut ret; | ||
unsafe { | ||
asm!("ecall", | ||
in( "x10") arg0, | ||
in("x11") arg1, | ||
in ("x12") arg2, | ||
in("x17") which, | ||
lateout("x10") ret, | ||
options(nostack) | ||
); | ||
} | ||
ret | ||
} | ||
|
||
const SBI_SET_TIMER: usize = 0; | ||
const SBI_CONSOLE_PUTCHAR: usize = 1; | ||
const SBI_CONSOLE_GETCHAR: usize = 2; | ||
const SBI_SHUTDOWN: usize = 8; | ||
|
||
pub fn shutdown() -> ! { | ||
scall(SBI_SHUTDOWN, 0, 0, 0); | ||
panic!("It should shutdown!"); | ||
} | ||
|
||
pub fn put_char(c: usize) { | ||
scall(SBI_CONSOLE_PUTCHAR, c, 0, 0); | ||
} | ||
|
||
pub fn set_timer(timer: usize) { | ||
scall(SBI_SET_TIMER, timer, 0, 0); | ||
} | ||
|
||
|
||
pub fn console_getchar() -> usize { | ||
scall(SBI_CONSOLE_GETCHAR, 0, 0, 0) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[macro_use] | ||
extern crate user; | ||
|
||
use user::{fork, wait, exit}; | ||
|
||
const MAX_CHILD: usize = 40; | ||
|
||
#[no_mangle] | ||
pub fn main() -> i32 { | ||
for i in 0..MAX_CHILD { | ||
let pid = fork(); | ||
if pid == 0 { | ||
println!("I am child {}", i); | ||
exit(0); | ||
} else { | ||
println!("forked child pid = {}", pid); | ||
} | ||
assert!(pid > 0); | ||
} | ||
let mut exit_code: i32 = 0; | ||
for _ in 0..MAX_CHILD { | ||
if wait(&mut exit_code) <= 0 { | ||
panic!("wait stopped early"); | ||
} | ||
} | ||
if wait(&mut exit_code) > 0 { | ||
panic!("wait got too many"); | ||
} | ||
println!("forktest pass."); | ||
0 | ||
} |
Oops, something went wrong.