Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fdadf550fb86
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b14c19a886aa
Choose a head ref
  • 4 commits
  • 11 files changed
  • 1 contributor

Commits on Sep 27, 2016

  1. Rust: liblwip: call tcp_recved where appropriate.

    whitequark committed Sep 27, 2016
    Copy the full SHA
    9562d8d View commit details
  2. Rust: fix prelude.

    whitequark committed Sep 27, 2016
    Copy the full SHA
    b813710 View commit details
  3. Rust: fix TcpStream::read.

    whitequark committed Sep 27, 2016
    Copy the full SHA
    89d4621 View commit details
  4. Rust: add skeleton session protocol implementation.

    Only ident requests are supported right now.
    whitequark committed Sep 27, 2016
    Copy the full SHA
    b14c19a View commit details
7 changes: 7 additions & 0 deletions artiq/runtime.rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion artiq/runtime.rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,8 +10,9 @@ path = "src/lib.rs"

[dependencies]
std_artiq = { path = "libstd_artiq" }
fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] }
lwip = { path = "liblwip" }
fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] }
byteorder = { version = "0.5", default-features = false }

[profile.dev]
panic = 'abort'
5 changes: 4 additions & 1 deletion artiq/runtime.rs/liblwip/lib.rs
Original file line number Diff line number Diff line change
@@ -505,7 +505,10 @@ impl TcpStream {
Some(_) => ()
}
match state.recv_buffer.pop_front() {
Some(Ok(pbuf)) => return Ok(Some(pbuf)),
Some(Ok(pbuf)) => {
unsafe { lwip_sys::tcp_recved(self.raw, pbuf.len() as u16) }
return Ok(Some(pbuf))
},
_ => unreachable!()
}
}
2 changes: 2 additions & 0 deletions artiq/runtime.rs/libstd_artiq/io/buffered.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ use core::cmp;
use core::fmt;
use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom};
use io::memchr;
use alloc::boxed::Box;
use collections::vec::Vec;

/// The `BufReader` struct adds buffering to any reader.
///
2 changes: 2 additions & 0 deletions artiq/runtime.rs/libstd_artiq/io/cursor.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ use io::prelude::*;

use core::cmp;
use io::{self, SeekFrom, Error, ErrorKind};
use alloc::boxed::Box;
use collections::vec::Vec;

/// A `Cursor` wraps another type and provides it with a
/// [`Seek`](trait.Seek.html) implementation.
3 changes: 0 additions & 3 deletions artiq/runtime.rs/libstd_artiq/io/prelude.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,3 @@
pub use super::{Read, Write, Seek};
pub use super::BufRead;

pub use alloc::boxed::Box;
pub use collections::vec::Vec;
10 changes: 6 additions & 4 deletions artiq/runtime.rs/libstd_artiq/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#![feature(lang_items, asm, alloc, collections, libc, needs_panic_runtime,
question_mark, unicode, reflect_marker, raw, int_error_internals,
try_from, try_borrow)]
try_from, try_borrow, macro_reexport, allow_internal_unstable)]
#![no_std]
#![needs_panic_runtime]

extern crate rustc_unicode;
extern crate alloc_artiq;
extern crate alloc;
#[macro_use]
#[macro_reexport(vec)]
extern crate collections;
extern crate libc;

@@ -21,9 +22,10 @@ pub use collections::{binary_heap, borrow, boxed, btree_map, btree_set, fmt, lin
pub mod prelude {
pub mod v1 {
pub use core::prelude::v1::*;
pub use collections::*;
pub use io::{Read, Write, Seek};
pub use io::BufRead;
pub use collections::boxed::Box;
pub use collections::borrow::ToOwned;
pub use collections::string::{String, ToString};
pub use collections::vec::Vec;
}
}

2 changes: 1 addition & 1 deletion artiq/runtime.rs/src/io.rs
Original file line number Diff line number Diff line change
@@ -293,7 +293,7 @@ impl<'a> Read for TcpStream<'a> {
let (pbuf, pos) = self.buffer.take().unwrap();
let slice = &pbuf.as_slice()[pos..];
let len = ::std::cmp::min(buf.len(), slice.len());
buf.copy_from_slice(&slice[..len]);
buf[..len].copy_from_slice(&slice[..len]);
if len < slice.len() {
self.buffer = Some((pbuf, pos + len))
}
25 changes: 3 additions & 22 deletions artiq/runtime.rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2,44 +2,25 @@

#[macro_use]
extern crate std_artiq as std;
extern crate byteorder;

use std::prelude::v1::*;

pub mod io;
pub mod session;

extern {
fn network_init();
fn lwip_service();
}

fn timer(waiter: io::Waiter) {
loop {
println!("tick");
waiter.sleep(std::time::Duration::from_millis(1000)).unwrap();
}
}

fn echo(waiter: io::Waiter) {
let addr = io::SocketAddr::new(io::IP_ANY, 1234);
let listener = io::TcpListener::bind(waiter, addr).unwrap();
loop {
let (mut stream, _addr) = listener.accept().unwrap();
loop {
let mut buf = [0];
stream.read(&mut buf).unwrap();
stream.write(&buf).unwrap();
}
}
}

#[no_mangle]
pub unsafe extern fn rust_main() {
println!("Accepting network sessions in Rust.");
network_init();

let mut scheduler = io::Scheduler::new();
scheduler.spawn(4096, timer);
scheduler.spawn(4096, echo);
scheduler.spawn(4096, session::handler);
loop {
lwip_service();
scheduler.run()
103 changes: 103 additions & 0 deletions artiq/runtime.rs/src/session/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use std::prelude::v1::*;
use std::io::{self, Read};
use self::protocol::*;

mod protocol;

#[derive(Debug, Clone, Copy)]
enum KernelState {
Absent,
Loaded,
Running,
RpcWait
}

#[derive(Debug)]
pub struct Session {
kernel_state: KernelState,
}

extern {
fn kloader_stop();
fn watchdog_init();
fn kloader_start_idle_kernel();
}

impl Session {
pub fn start() -> Session {
unsafe { kloader_stop(); }
Session {
kernel_state: KernelState::Absent
}
}

pub fn end(self) {
unsafe {
kloader_stop();
watchdog_init();
kloader_start_idle_kernel();
}
}
}

fn check_magic(stream: &mut ::io::TcpStream) -> io::Result<()> {
const MAGIC: &'static [u8] = b"ARTIQ coredev\n";

let mut magic: [u8; 14] = [0; 14];
try!(stream.read_exact(&mut magic));
if magic != MAGIC {
Err(io::Error::new(io::ErrorKind::InvalidData, "unrecognized magic"))
} else {
Ok(())
}
}

fn handle_request(stream: &mut ::io::TcpStream) -> io::Result<()> {
fn read_request(stream: &mut ::io::TcpStream) -> io::Result<Request> {
let request = try!(Request::read_from(stream));
println!("comm<-host {:?}", request);
Ok(request)
}

fn write_reply(stream: &mut ::io::TcpStream, reply: Reply) -> io::Result<()> {
println!("comm->host {:?}", reply);
reply.write_to(stream)
}

match try!(read_request(stream)) {
Request::Ident => {
let mut ident: [u8; 256];
let ident = unsafe {
extern { fn get_ident(ident: *mut u8); }

ident = ::core::mem::uninitialized();
get_ident(ident.as_mut_ptr());
&ident[..ident.iter().position(|&c| c == 0).unwrap()]
};

write_reply(stream, Reply::Ident(ident))
},
_ => unreachable!()
}
}

fn handle_requests(stream: &mut ::io::TcpStream) -> io::Result<()> {
try!(check_magic(stream));
loop {
try!(handle_request(stream))
}
}

pub fn handler(waiter: ::io::Waiter) {
let addr = ::io::SocketAddr::new(::io::IP_ANY, 1381);
let listener = ::io::TcpListener::bind(waiter, addr).unwrap();
loop {
let (mut stream, _addr) = listener.accept().unwrap();
match handle_requests(&mut stream) {
Ok(()) => (),
Err(err) => {
println!("cannot handle network request: {:?}", err);
}
}
}
}
Loading