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: b3b1ea71c5db
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: 5701b2095be8
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Oct 1, 2016

  1. runtime: remove useless copy of flush_cpu_dcache().

    ksupport used to not link to libbase, I think.
    whitequark committed Oct 1, 2016
    Copy the full SHA
    d3dcb4b View commit details
  2. runtime: link ksupport with libm, not runtime.

    We need libm for the %g format specifier.
    whitequark committed Oct 1, 2016
    Copy the full SHA
    999290f View commit details
  3. Rust: style (NFC).

    whitequark committed Oct 1, 2016
    Copy the full SHA
    ab3bd67 View commit details
  4. Copy the full SHA
    5701b20 View commit details
Showing with 133 additions and 43 deletions.
  1. +11 −11 artiq/runtime.rs/src/clock.rs
  2. +4 −4 artiq/runtime.rs/src/kernel.rs
  3. +111 −3 artiq/runtime.rs/src/kernel_proto.rs
  4. +3 −2 artiq/runtime.rs/src/session.rs
  5. +3 −3 artiq/runtime/Makefile
  6. +1 −20 artiq/runtime/mailbox.c
22 changes: 11 additions & 11 deletions artiq/runtime.rs/src/clock.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
use board::csr::timer0;
use board::csr;

const INIT: u64 = ::core::i64::MAX as u64;
const FREQ: u64 = ::board::csr::CONFIG_CLOCK_FREQUENCY as u64;

pub fn init() {
unsafe {
timer0::en_write(0);
timer0::load_write(INIT);
timer0::reload_write(INIT);
timer0::en_write(1);
csr::timer0::en_write(0);
csr::timer0::load_write(INIT);
csr::timer0::reload_write(INIT);
csr::timer0::en_write(1);
}
}

pub fn get_ms() -> u64 {
unsafe {
timer0::update_value_write(1);
(INIT - timer0::value_read()) / (FREQ / 1_000)
csr::timer0::update_value_write(1);
(INIT - csr::timer0::value_read()) / (FREQ / 1_000)
}
}

pub fn spin_us(interval: u64) {
unsafe {
timer0::update_value_write(1);
let threshold = timer0::value_read() - interval * (FREQ / 1_000_000);
while timer0::value_read() > threshold {
timer0::update_value_write(1)
csr::timer0::update_value_write(1);
let threshold = csr::timer0::value_read() - interval * (FREQ / 1_000_000);
while csr::timer0::value_read() > threshold {
csr::timer0::update_value_write(1)
}
}
}
8 changes: 4 additions & 4 deletions artiq/runtime.rs/src/kernel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::ptr;
use board::csr::kernel_cpu;
use board::csr;
use mailbox;

const KERNELCPU_EXEC_ADDRESS: usize = 0x42000000;
@@ -8,7 +8,7 @@ const KERNELCPU_LAST_ADDRESS: usize = (0x4fffffff - 1024*1024);
const KSUPPORT_HEADER_SIZE: usize = 0x80;

pub unsafe fn start() {
if kernel_cpu::reset_read() == 0 {
if csr::kernel_cpu::reset_read() == 0 {
panic!("attempted to start kernel CPU when it is already running")
}

@@ -24,11 +24,11 @@ pub unsafe fn start() {
(KERNELCPU_EXEC_ADDRESS - KSUPPORT_HEADER_SIZE) as *mut u8,
ksupport_end - ksupport_start);

kernel_cpu::reset_write(0);
csr::kernel_cpu::reset_write(0);
}

pub fn stop() {
unsafe { kernel_cpu::reset_write(1) }
unsafe { csr::kernel_cpu::reset_write(1) }
mailbox::acknowledge();
}

114 changes: 111 additions & 3 deletions artiq/runtime.rs/src/kernel_proto.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::{ptr, mem, slice};
use std::string::String;
use std::io;
use mailbox;
use kernel;
@@ -76,6 +78,60 @@ impl<'a> Message<'a> {
f(&msg as *const _ as *const _)
}

Message::WatchdogSetReply { id } => {
let msg = c::WatchdogSetReply {
ty: c::Type::WatchdogSetReply,
id: id as _
};
f(&msg as *const _ as *const _)
}

Message::RpcRecvReply { alloc_size, exception } => {
let exn = exception.map(|exception| {
// FIXME: disgusting
let name = String::from(exception.name) + "\0";
let file = String::from(exception.file) + "\0";
let function = String::from(exception.function) + "\0";
let message = String::from(exception.message) + "\0";
let exn = c::Exception {
name: name.as_ptr() as *const _,
file: file.as_ptr() as *const _,
line: exception.line,
column: exception.column,
function: function.as_ptr() as *const _,
message: message.as_ptr() as *const _,
param: exception.param,
};
mem::forget(name);
mem::forget(file);
mem::forget(function);
mem::forget(message);
exn
});
let msg = c::RpcRecvReply {
ty: c::Type::RpcRecvReply,
alloc_size: alloc_size as _,
exception: exn.map_or(ptr::null(), |exn| &exn as *const _)
};
f(&msg as *const _ as *const _)
}

Message::CacheGetReply { value } => {
let msg = c::CacheGetReply {
ty: c::Type::CacheGetReply,
length: value.len(),
elements: value.as_ptr()
};
f(&msg as *const _ as *const _)
}
Message::CachePutReply { succeeded } => {
let msg = c::CachePutReply {
ty: c::Type::CachePutReply,
succeeded: succeeded as _
};
f(&msg as *const _ as *const _)
}

other => panic!("Message::into_lower: {:?} unimplemented", other)
}
}
@@ -100,6 +156,57 @@ impl<'a> Message<'a> {
}

c::Type::RunFinished => Message::RunFinished,
c::Type::RunException => {
let msg = ptr as *const c::RunException;
let exc = (*msg).exception;
Message::RunException {
exception: Exception {
name: c::from_c_str((*exc).name),
file: c::from_c_str((*exc).file),
line: (*exc).line,
column: (*exc).column,
function: c::from_c_str((*exc).function),
message: c::from_c_str((*exc).message),
param: (*exc).param,
},
backtrace: slice::from_raw_parts((*msg).backtrace, (*msg).backtrace_size)
}
}

c::Type::WatchdogSetRequest => {
let msg = ptr as *const c::WatchdogSetRequest;
Message::WatchdogSetRequest { ms: (*msg).ms as u64 }
},
c::Type::WatchdogClear => {
let msg = ptr as *const c::WatchdogClear;
Message::WatchdogClear { id: (*msg).id as usize }
}

c::Type::RpcSend => {
let msg = ptr as *const c::RpcSend;
Message::RpcSend {
service: (*msg).service as _,
tag: slice::from_raw_parts((*msg).tag as *const _,
c::strlen((*msg).tag) as usize),
data: (*msg).data as *const _
}
}
c::Type::RpcRecvRequest => {
let msg = ptr as *const c::RpcRecvRequest;
Message::RpcRecvRequest { slot: (*msg).slot as *mut _ }
}

c::Type::CacheGetRequest => {
let msg = ptr as *const c::CacheGetRequest;
let key = c::from_c_str((*msg).key);
Message::CacheGetRequest { key: key }
}
c::Type::CachePutRequest => {
let msg = ptr as *const c::CachePutRequest;
let key = c::from_c_str((*msg).key);
let value = slice::from_raw_parts((*msg).elements, (*msg).length);
Message::CachePutRequest { key: key, value: value }
}

c::Type::Log => {
let msg = ptr as *const c::Log;
@@ -129,13 +236,16 @@ impl<'a> Message<'a> {
}

pub fn acknowledge() {
unsafe { mailbox::acknowledge() }
mailbox::acknowledge()
}
}

// Low-level representation, compatible with the C code in ksupport
mod c {
use libc::{c_void, c_int, c_char, size_t};
use core::{str, slice};

extern { pub fn strlen(ptr: *const c_char) -> size_t; }

#[repr(u32)]
#[derive(Debug)]
@@ -312,12 +422,10 @@ mod c {
}

pub unsafe fn from_c_str_len<'a>(ptr: *const c_char, len: size_t) -> &'a str {
use core::{str, slice};
str::from_utf8_unchecked(slice::from_raw_parts(ptr as *const u8, len))
}

pub unsafe fn from_c_str<'a>(ptr: *const c_char) -> &'a str {
extern { fn strlen(cs: *const c_char) -> size_t; }
from_c_str_len(ptr, strlen(ptr))
}
}
5 changes: 3 additions & 2 deletions artiq/runtime.rs/src/session.rs
Original file line number Diff line number Diff line change
@@ -186,10 +186,11 @@ fn comm_handle(waiter: Waiter,
}

session.kernel_state = KernelState::Running;
// TODO: make this a separate request
kern_acknowledge()
}

request => unexpected!("unexpected {:?}", request)
request => unexpected!("unexpected request {:?} from host machine", request)
}
}

@@ -225,7 +226,7 @@ fn kern_handle(waiter: Waiter,
kern_acknowledge()
}

request => unexpected!("unexpected {:?}", request)
request => unexpected!("unexpected request {:?} from kernel CPU", request)
}
})
}
6 changes: 3 additions & 3 deletions artiq/runtime/Makefile
Original file line number Diff line number Diff line change
@@ -36,11 +36,10 @@ runtime.elf: $(OBJECTS) libruntime.a
$(OBJECTS) \
-L../libcompiler-rt \
-L../libbase \
-L../libm \
-L../liballoc \
-L../liblwip \
-Lcargo/or1k-unknown-none/debug/ \
-lruntime -lbase -lm -lcompiler-rt -lalloc -llwip
-lruntime -lbase-nofloat -lcompiler-rt -lalloc -llwip
@chmod -x $@

ksupport.elf: $(OBJECTS_KSUPPORT)
@@ -51,10 +50,11 @@ ksupport.elf: $(OBJECTS_KSUPPORT)
../libbase/crt0-$(CPU).o \
$^ \
-L../libbase \
-L../libm \
-L../libcompiler-rt \
-L../libunwind \
-L../libdyld \
-lbase-nofloat -lcompiler-rt -ldyld -lunwind
-lbase -lm -lcompiler-rt -ldyld -lunwind
@chmod -x $@

ksupport_data.o: ksupport.elf
21 changes: 1 addition & 20 deletions artiq/runtime/mailbox.c
Original file line number Diff line number Diff line change
@@ -10,25 +10,6 @@

static unsigned int last_transmission;

static void _flush_cpu_dcache(void)
{
unsigned long dccfgr;
unsigned long cache_set_size;
unsigned long cache_ways;
unsigned long cache_block_size;
unsigned long cache_size;
int i;

dccfgr = mfspr(SPR_DCCFGR);
cache_ways = 1 << (dccfgr & SPR_ICCFGR_NCW);
cache_set_size = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3);
cache_block_size = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16;
cache_size = cache_set_size * cache_ways * cache_block_size;

for (i = 0; i < cache_size; i += cache_block_size)
mtspr(SPR_DCBIR, i);
}

void mailbox_send(void *ptr)
{
last_transmission = (unsigned int)ptr;
@@ -58,7 +39,7 @@ void *mailbox_receive(void)
return NULL;
else {
if(r) {
_flush_cpu_dcache();
flush_cpu_dcache();
}
return (void *)r;
}