-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: implement prototype background RPCs.
whitequark
committed
Oct 29, 2016
1 parent
c656a53
commit 2ac85cd
Showing
18 changed files
with
252 additions
and
87 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
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
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
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,61 @@ | ||
#![allow(dead_code)] | ||
|
||
use core::ptr::{read_volatile, write_volatile}; | ||
use core::slice; | ||
use board; | ||
|
||
const SEND_MAILBOX: *mut usize = (board::mem::MAILBOX_BASE + 4) as *mut usize; | ||
const RECV_MAILBOX: *mut usize = (board::mem::MAILBOX_BASE + 8) as *mut usize; | ||
|
||
const QUEUE_BEGIN: usize = 0x40400000; | ||
const QUEUE_END: usize = 0x40800000; | ||
const QUEUE_CHUNK: usize = 0x1000; | ||
|
||
pub unsafe fn init() { | ||
write_volatile(SEND_MAILBOX, QUEUE_BEGIN); | ||
write_volatile(RECV_MAILBOX, QUEUE_END); | ||
} | ||
|
||
fn next(mut addr: usize) -> usize { | ||
debug_assert!(addr % QUEUE_CHUNK == 0); | ||
debug_assert!(addr >= QUEUE_BEGIN && addr < QUEUE_END); | ||
|
||
addr += QUEUE_CHUNK; | ||
if addr == QUEUE_END { addr = QUEUE_BEGIN } | ||
addr | ||
} | ||
|
||
pub fn empty() -> bool { | ||
unsafe { read_volatile(SEND_MAILBOX) == read_volatile(RECV_MAILBOX) } | ||
} | ||
|
||
pub fn full() -> bool { | ||
unsafe { next(read_volatile(SEND_MAILBOX)) == read_volatile(RECV_MAILBOX) } | ||
} | ||
|
||
pub fn enqueue<T, E, F>(f: F) -> Result<T, E> | ||
where F: FnOnce(&mut [u8]) -> Result<T, E> { | ||
debug_assert!(!full()); | ||
|
||
unsafe { | ||
let slice = slice::from_raw_parts_mut(read_volatile(SEND_MAILBOX) as *mut u8, QUEUE_CHUNK); | ||
f(slice).and_then(|x| { | ||
write_volatile(SEND_MAILBOX, next(read_volatile(SEND_MAILBOX))); | ||
Ok(x) | ||
}) | ||
} | ||
} | ||
|
||
pub fn dequeue<T, E, F>(f: F) -> Result<T, E> | ||
where F: FnOnce(&mut [u8]) -> Result<T, E> { | ||
debug_assert!(!empty()); | ||
|
||
unsafe { | ||
board::flush_cpu_dcache(); | ||
let slice = slice::from_raw_parts_mut(read_volatile(RECV_MAILBOX) as *mut u8, QUEUE_CHUNK); | ||
f(slice).and_then(|x| { | ||
write_volatile(RECV_MAILBOX, next(read_volatile(RECV_MAILBOX))); | ||
Ok(x) | ||
}) | ||
} | ||
} |
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