From 79e70fa465ea7990ab253f4d7cae5ee2e3ec7849 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 23 Nov 2016 16:28:05 +0000 Subject: [PATCH] runtime: use correct ABI when accepting ARTIQ lists. --- artiq/runtime.rs/libksupport/lib.rs | 23 +++++++++++++++++++---- artiq/runtime.rs/libksupport/rtio.rs | 8 ++++---- artiq/runtime.rs/src/cache.rs | 6 +++--- artiq/runtime.rs/src/kernel_proto.rs | 4 ++-- artiq/runtime.rs/src/session.rs | 4 ++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/artiq/runtime.rs/libksupport/lib.rs b/artiq/runtime.rs/libksupport/lib.rs index 08673e759..7c0db38c1 100644 --- a/artiq/runtime.rs/libksupport/lib.rs +++ b/artiq/runtime.rs/libksupport/lib.rs @@ -118,6 +118,22 @@ extern fn panic_fmt(args: core::fmt::Arguments, file: &'static str, line: u32) - loop {} } +#[repr(C)] +pub struct ArtiqList { + len: usize, + ptr: *const T +} + +impl ArtiqList { + pub fn from_slice(slice: &'static [T]) -> ArtiqList { + ArtiqList { ptr: slice.as_ptr(), len: slice.len() } + } + + pub unsafe fn as_slice(&self) -> &[T] { + slice::from_raw_parts(self.ptr, self.len) + } +} + static mut NOW: u64 = 0; #[no_mangle] @@ -221,7 +237,7 @@ extern fn watchdog_clear(id: usize) { send(&WatchdogClear { id: id }) } -extern fn cache_get(key: *const u8) -> (usize, *const u32) { +extern fn cache_get(key: *const u8) -> (usize, *const i32) { extern { fn strlen(s: *const c_char) -> size_t; } let key = unsafe { slice::from_raw_parts(key, strlen(key as *const c_char)) }; let key = unsafe { str::from_utf8_unchecked(key) }; @@ -230,13 +246,12 @@ extern fn cache_get(key: *const u8) -> (usize, *const u32) { recv!(&CacheGetReply { value } => (value.len(), value.as_ptr())) } -extern fn cache_put(key: *const u8, &(len, ptr): &(usize, *const u32)) { +extern fn cache_put(key: *const u8, list: ArtiqList) { extern { fn strlen(s: *const c_char) -> size_t; } let key = unsafe { slice::from_raw_parts(key, strlen(key as *const c_char)) }; let key = unsafe { str::from_utf8_unchecked(key) }; - let value = unsafe { slice::from_raw_parts(ptr, len) }; - send(&CachePutRequest { key: key, value: value }); + send(&CachePutRequest { key: key, value: unsafe { list.as_slice() } }); recv!(&CachePutReply { succeeded } => { if !succeeded { artiq_raise!("CacheError", "cannot put into a busy cache row") diff --git a/artiq/runtime.rs/libksupport/rtio.rs b/artiq/runtime.rs/libksupport/rtio.rs index 60dadc815..2825888cc 100644 --- a/artiq/runtime.rs/libksupport/rtio.rs +++ b/artiq/runtime.rs/libksupport/rtio.rs @@ -1,6 +1,7 @@ use board::csr; use core::ptr::{read_volatile, write_volatile}; use core::slice; +use ::ArtiqList; const RTIO_O_STATUS_FULL: u32 = 1; const RTIO_O_STATUS_UNDERFLOW: u32 = 2; @@ -83,17 +84,16 @@ pub extern fn output(timestamp: i64, channel: u32, addr: u32, data: u32) { } } -pub extern fn output_list(timestamp: i64, channel: u32, addr: u32, - &(len, ptr): &(usize, *const u32)) { +pub extern fn output_list(timestamp: i64, channel: u32, addr: u32, list: ArtiqList) { unsafe { csr::rtio::chan_sel_write(channel); csr::rtio::o_timestamp_write(timestamp as u64); csr::rtio::o_address_write(addr); - let data = slice::from_raw_parts(ptr, len); + let data = list.as_slice(); for i in 0..data.len() { write_volatile( csr::rtio::O_DATA_ADDR.offset((csr::rtio::O_DATA_SIZE - 1 - i) as isize), - data[i]); + data[i] as u32); } csr::rtio::o_we_write(1); let status = csr::rtio::o_status_read(); diff --git a/artiq/runtime.rs/src/cache.rs b/artiq/runtime.rs/src/cache.rs index 4136b96f3..082dda287 100644 --- a/artiq/runtime.rs/src/cache.rs +++ b/artiq/runtime.rs/src/cache.rs @@ -4,7 +4,7 @@ use std::btree_map::BTreeMap; #[derive(Debug)] struct Entry { - data: Vec, + data: Vec, borrowed: bool } @@ -18,7 +18,7 @@ impl Cache { Cache { entries: BTreeMap::new() } } - pub fn get(&mut self, key: &str) -> *const [u32] { + pub fn get(&mut self, key: &str) -> *const [i32] { match self.entries.get_mut(key) { None => &[], Some(ref mut entry) => { @@ -28,7 +28,7 @@ impl Cache { } } - pub fn put(&mut self, key: &str, data: &[u32]) -> Result<(), ()> { + pub fn put(&mut self, key: &str, data: &[i32]) -> Result<(), ()> { match self.entries.get_mut(key) { None => (), Some(ref mut entry) => { diff --git a/artiq/runtime.rs/src/kernel_proto.rs b/artiq/runtime.rs/src/kernel_proto.rs index c015b76d2..89b90657f 100644 --- a/artiq/runtime.rs/src/kernel_proto.rs +++ b/artiq/runtime.rs/src/kernel_proto.rs @@ -51,8 +51,8 @@ pub enum Message<'a> { RpcRecvReply(Result>), CacheGetRequest { key: &'a str }, - CacheGetReply { value: &'static [u32] }, - CachePutRequest { key: &'a str, value: &'static [u32] }, + CacheGetReply { value: &'static [i32] }, + CachePutRequest { key: &'a str, value: &'a [i32] }, CachePutReply { succeeded: bool }, Log(fmt::Arguments<'a>), diff --git a/artiq/runtime.rs/src/session.rs b/artiq/runtime.rs/src/session.rs index 083cfa8a9..b2f58b5d1 100644 --- a/artiq/runtime.rs/src/session.rs +++ b/artiq/runtime.rs/src/session.rs @@ -406,7 +406,7 @@ fn process_kern_message(waiter: Waiter, &kern::CacheGetRequest { key } => { let value = session.congress.cache.get(key); kern_send(waiter, &kern::CacheGetReply { - value: unsafe { mem::transmute::<*const [u32], &'static [u32]>(value) } + value: unsafe { mem::transmute::<*const [i32], &'static [i32]>(value) } }) } @@ -470,7 +470,7 @@ fn process_kern_message(waiter: Waiter, } fn process_kern_queued_rpc(stream: &mut TcpStream, - session: &mut Session) -> io::Result<()> { + _session: &mut Session) -> io::Result<()> { rpc_queue::dequeue(|slice| { trace!("comm<-kern (async RPC)"); let length = NetworkEndian::read_u32(slice) as usize;