2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

firmware: restructure to avoid #[path = "..."] mod ...;

Such code is fragile, introduces mess in dependencies, and
inflates compile times.
This commit is contained in:
whitequark 2017-02-25 17:54:14 +00:00
parent d04e611232
commit 2a81819eb0
20 changed files with 190 additions and 113 deletions

View File

@ -10,6 +10,13 @@ version = "0.0.0"
name = "alloc_none"
version = "0.0.0"
[[package]]
name = "amp"
version = "0.0.0"
dependencies = [
"board 0.0.0",
]
[[package]]
name = "board"
version = "0.0.0"
@ -93,11 +100,13 @@ name = "ksupport"
version = "0.0.0"
dependencies = [
"alloc_none 0.0.0",
"amp 0.0.0",
"board 0.0.0",
"build_artiq 0.0.0",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dyld 0.0.0",
"proto 0.0.0",
"std_artiq 0.0.0",
]
@ -130,21 +139,33 @@ name = "managed"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proto"
version = "0.0.0"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dyld 0.0.0",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"std_artiq 0.0.0",
]
[[package]]
name = "runtime"
version = "0.0.0"
dependencies = [
"alloc_artiq 0.0.0",
"amp 0.0.0",
"board 0.0.0",
"build_artiq 0.0.0",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins?rev=631b568)",
"cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"drtioaux 0.0.0",
"dyld 0.0.0",
"fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"logger_artiq 0.0.0",
"proto 0.0.0",
"smoltcp 0.2.1 (git+https://github.com/m-labs/smoltcp?rev=e8ece3e)",
"std_artiq 0.0.0",
]

View File

@ -13,9 +13,11 @@ crate-type = ["staticlib"]
build_artiq = { path = "../libbuild_artiq" }
[dependencies]
alloc_none = { path = "../liballoc_none" }
std_artiq = { path = "../libstd_artiq" }
board = { path = "../libboard" }
dyld = { path = "../libdyld" }
byteorder = { version = "1.0", default-features = false }
cslice = { version = "0.3" }
alloc_none = { path = "../liballoc_none" }
std_artiq = { path = "../libstd_artiq" }
dyld = { path = "../libdyld" }
board = { path = "../libboard" }
proto = { path = "../libproto" }
amp = { path = "../libamp" }

View File

@ -23,7 +23,7 @@ $(RUSTOUT)/libksupport.a:
ksupport.elf: $(RUSTOUT)/libksupport.a glue.o
$(LD) $(LDFLAGS) -T $(KSUPPORT_DIRECTORY)/ksupport.ld -o $@ $^ \
-lbase -lm -lcompiler-rt -lunwind
-lunwind -lcompiler-rt -lbase -lm
@chmod -x $@
%.o: $(KSUPPORT_DIRECTORY)/%.c

View File

@ -433,3 +433,28 @@ pub unsafe extern fn reraise() -> ! {
uw::_Unwind_Resume(&mut INFLIGHT.uw_exception)
}
}
// Stub implementations for the functions the panic_unwind crate expects to be provided.
// These all do nothing in libunwind, but aren't built for OR1K.
pub mod stubs {
#![allow(bad_style, unused_variables)]
use super::{uw, c_int};
#[export_name="_Unwind_GetIPInfo"]
pub unsafe extern fn _Unwind_GetIPInfo(ctx: *mut uw::_Unwind_Context,
ip_before_insn: *mut c_int) -> uw::_Unwind_Word {
*ip_before_insn = 0;
uw::_Unwind_GetIP(ctx)
}
#[export_name="_Unwind_GetTextRelBase"]
pub unsafe extern fn _Unwind_GetTextRelBase(ctx: *mut uw::_Unwind_Context) -> uw::_Unwind_Ptr {
unimplemented!()
}
#[export_name="_Unwind_GetDataRelBase"]
pub unsafe extern fn _Unwind_GetDataRelBase(ctx: *mut uw::_Unwind_Context) -> uw::_Unwind_Ptr {
unimplemented!()
}
}

View File

@ -1,54 +1,26 @@
#![feature(lang_items, asm, libc, panic_unwind, unwind_attributes)]
#![no_std]
extern crate alloc_none;
#[macro_use]
extern crate std_artiq as std;
extern crate unwind;
extern crate libc;
extern crate byteorder;
extern crate board;
extern crate cslice;
extern crate alloc_none;
extern crate std_artiq as std;
extern crate board;
extern crate dyld;
#[path = "../runtime/mailbox.rs"]
mod mailbox;
#[path = "../runtime/proto.rs"]
mod proto;
#[path = "../runtime/kernel_proto.rs"]
mod kernel_proto;
#[path = "../runtime/rpc_proto.rs"]
mod rpc_proto;
mod api;
extern crate proto;
extern crate amp;
use core::{mem, ptr, slice, str};
use std::io::Cursor;
use cslice::{CSlice, AsCSlice};
use kernel_proto::*;
use dyld::Library;
macro_rules! artiq_raise {
($name:expr, $message:expr, $param0:expr, $param1:expr, $param2:expr) => ({
use cslice::AsCSlice;
let exn = $crate::eh::Exception {
name: concat!("0:artiq.coredevice.exceptions.", $name).as_bytes().as_c_slice(),
file: file!().as_bytes().as_c_slice(),
line: line!(),
column: column!(),
// https://github.com/rust-lang/rfcs/pull/1719
function: "(Rust function)".as_bytes().as_c_slice(),
message: $message.as_bytes().as_c_slice(),
param: [$param0, $param1, $param2]
};
#[allow(unused_unsafe)]
unsafe { $crate::eh::raise(&exn) }
});
($name:expr, $message:expr) => ({
artiq_raise!($name, $message, 0, 0, 0)
});
}
use proto::{kernel_proto, rpc_proto};
use proto::kernel_proto::*;
use amp::{mailbox, rpc_queue};
fn send(request: &Message) {
unsafe { mailbox::send(request as *const _ as usize) }
@ -75,6 +47,14 @@ macro_rules! recv {
}
}
#[no_mangle]
#[lang = "panic_fmt"]
pub extern fn panic_fmt(args: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
send(&Log(format_args!("panic at {}:{}: {}", file, line, args)));
send(&RunAborted);
loop {}
}
macro_rules! print {
($($arg:tt)*) => ($crate::send(&$crate::kernel_proto::Log(format_args!($($arg)*))));
}
@ -84,19 +64,31 @@ macro_rules! println {
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}
#[path = "../runtime/rpc_queue.rs"]
mod rpc_queue;
mod rtio;
mod eh;
#[no_mangle]
#[lang = "panic_fmt"]
pub extern fn panic_fmt(args: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
println!("panic at {}:{}: {}", file, line, args);
send(&RunAborted);
loop {}
macro_rules! raise {
($name:expr, $message:expr, $param0:expr, $param1:expr, $param2:expr) => ({
use cslice::AsCSlice;
let exn = $crate::eh::Exception {
name: concat!("0:artiq.coredevice.exceptions.", $name).as_bytes().as_c_slice(),
file: file!().as_bytes().as_c_slice(),
line: line!(),
column: column!(),
// https://github.com/rust-lang/rfcs/pull/1719
function: "(Rust function)".as_bytes().as_c_slice(),
message: $message.as_bytes().as_c_slice(),
param: [$param0, $param1, $param2]
};
#[allow(unused_unsafe)]
unsafe { $crate::eh::raise(&exn) }
});
($name:expr, $message:expr) => ({
raise!($name, $message, 0, 0, 0)
});
}
pub mod eh;
mod api;
mod rtio;
static mut NOW: u64 = 0;
#[no_mangle]
@ -115,12 +107,6 @@ pub extern fn send_to_rtio_log(timestamp: i64, text: CSlice<u8>) {
rtio::log(timestamp, text.as_ref())
}
extern fn abort() -> ! {
println!("kernel called abort()");
send(&RunAborted);
loop {}
}
extern fn rpc_send(service: u32, tag: CSlice<u8>, data: *const *const ()) {
while !rpc_queue::empty() {}
send(&RpcSend {
@ -139,7 +125,7 @@ extern fn rpc_send_async(service: u32, tag: CSlice<u8>, data: *const *const ())
rpc_proto::send_args(&mut writer, service, tag.as_ref(), data)?;
writer.position()
};
proto::write_u32(&mut slice, length as u32)
proto::io::write_u32(&mut slice, length as u32)
}).unwrap_or_else(|err| {
assert!(err.kind() == std::io::ErrorKind::WriteZero);
@ -202,7 +188,7 @@ fn terminate(exception: &eh::Exception, mut backtrace: &mut [usize]) -> ! {
extern fn watchdog_set(ms: i64) -> i32 {
if ms < 0 {
artiq_raise!("ValueError", "cannot set a watchdog with a negative timeout")
raise!("ValueError", "cannot set a watchdog with a negative timeout")
}
send(&WatchdogSetRequest { ms: ms as u64 });
@ -227,7 +213,7 @@ extern fn cache_put(key: CSlice<u8>, list: CSlice<i32>) {
});
recv!(&CachePutReply { succeeded } => {
if !succeeded {
artiq_raise!("CacheError", "cannot put into a busy cache row")
raise!("CacheError", "cannot put into a busy cache row")
}
})
}
@ -329,6 +315,11 @@ pub unsafe fn main() {
#[no_mangle]
pub extern fn exception_handler(vect: u32, _regs: *const u32, pc: u32, ea: u32) {
println!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea);
send(&RunAborted)
panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea)
}
// We don't export this because libbase does.
// #[no_mangle]
pub extern fn abort() {
panic!("aborted")
}

View File

@ -1,6 +1,3 @@
#[path = "../runtime/kernel_proto.rs"]
mod kernel_proto;
use core::ptr::{read_volatile, write_volatile};
use cslice::CSlice;
use board::csr;
@ -46,25 +43,25 @@ unsafe fn process_exceptional_status(timestamp: i64, channel: i32, status: u32)
}
if status & RTIO_O_STATUS_UNDERFLOW != 0 {
csr::rtio::o_underflow_reset_write(1);
artiq_raise!("RTIOUnderflow",
raise!("RTIOUnderflow",
"RTIO underflow at {0} mu, channel {1}, slack {2} mu",
timestamp, channel as i64, timestamp - get_counter())
}
if status & RTIO_O_STATUS_SEQUENCE_ERROR != 0 {
csr::rtio::o_sequence_error_reset_write(1);
artiq_raise!("RTIOSequenceError",
raise!("RTIOSequenceError",
"RTIO sequence error at {0} mu, channel {1}",
timestamp, channel as i64, 0)
}
if status & RTIO_O_STATUS_COLLISION != 0 {
csr::rtio::o_collision_reset_write(1);
artiq_raise!("RTIOCollision",
raise!("RTIOCollision",
"RTIO collision at {0} mu, channel {1}",
timestamp, channel as i64, 0)
}
if status & RTIO_O_STATUS_BUSY != 0 {
csr::rtio::o_busy_reset_write(1);
artiq_raise!("RTIOBusy",
raise!("RTIOBusy",
"RTIO busy on channel {0}",
channel as i64, 0, 0)
}
@ -122,7 +119,7 @@ pub extern fn input_timestamp(timeout: i64, channel: i32) -> u64 {
}
if status & RTIO_I_STATUS_OVERFLOW != 0 {
artiq_raise!("RTIOOverflow",
raise!("RTIOOverflow",
"RTIO input overflow on channel {0}",
channel as i64, 0, 0);
}
@ -145,7 +142,7 @@ pub extern fn input_data(channel: i32) -> i32 {
if status & RTIO_I_STATUS_OVERFLOW != 0 {
csr::rtio::i_overflow_reset_write(1);
artiq_raise!("RTIOOverflow",
raise!("RTIOOverflow",
"RTIO input overflow on channel {0}",
channel as i64, 0, 0);
}

View File

@ -0,0 +1,11 @@
[package]
authors = ["M-Labs"]
name = "amp"
version = "0.0.0"
[lib]
name = "amp"
path = "lib.rs"
[dependencies]
board = { path = "../libboard" }

View File

@ -0,0 +1,6 @@
#![no_std]
extern crate board;
pub mod mailbox;
pub mod rpc_queue;

View File

@ -1,5 +1,3 @@
#![allow(dead_code)]
use core::ptr::{read_volatile, write_volatile};
use core::slice;
use board::{mem, cache};

View File

@ -0,0 +1,15 @@
[package]
authors = ["M-Labs"]
name = "proto"
version = "0.0.0"
[lib]
name = "proto"
path = "lib.rs"
[dependencies]
byteorder = { version = "1.0", default-features = false }
cslice = { version = "0.3" }
log = { version = "0.3", default-features = false, optional = true }
std_artiq = { path = "../libstd_artiq", features = ["alloc"] }
dyld = { path = "../libdyld" }

View File

@ -1,5 +1,5 @@
use std::io::{self, Write};
use proto::*;
use io::*;
#[derive(Debug)]
pub struct Header {

View File

@ -1,5 +1,3 @@
#![allow(dead_code)]
use std::io::{self, Read, Write};
use std::vec::Vec;
use std::string::String;
@ -55,7 +53,8 @@ pub fn write_u64(writer: &mut Write, value: u64) -> io::Result<()> {
pub fn read_bytes(reader: &mut Read) -> io::Result<Vec<u8>> {
let length = read_u32(reader)?;
let mut value = vec![0; length as usize];
let mut value = Vec::new();
value.resize(length as usize, 0);
reader.read_exact(&mut value)?;
Ok(value)
}

View File

@ -1,5 +1,3 @@
#![allow(dead_code)]
use core::fmt;
use dyld;

View File

@ -0,0 +1,21 @@
#![no_std]
extern crate byteorder;
extern crate cslice;
#[cfg(feature = "log")]
#[macro_use]
extern crate log;
extern crate dyld;
extern crate std_artiq as std;
pub mod io;
// Internal protocols.
pub mod kernel_proto;
// External protocols.
pub mod analyzer_proto;
pub mod moninj_proto;
pub mod session_proto;
pub mod rpc_proto;

View File

@ -1,5 +1,5 @@
use std::io::{self, Read, Write};
use proto::*;
use io::*;
#[derive(Debug)]
pub enum TtlMode {

View File

@ -1,9 +1,7 @@
#![allow(dead_code)]
use core::str;
use std::io::{self, Read, Write};
use std::str;
use cslice::{CSlice, CMutSlice};
use proto::*;
use io::*;
use self::tag::{Tag, TagIterator, split_tag};
unsafe fn recv_value(reader: &mut Read, tag: Tag, data: &mut *mut (),
@ -76,7 +74,7 @@ unsafe fn recv_value(reader: &mut Read, tag: Tag, data: &mut *mut (),
pub fn recv_return(reader: &mut Read, tag_bytes: &[u8], data: *mut (),
alloc: &Fn(usize) -> io::Result<*mut ()>) -> io::Result<()> {
let mut it = TagIterator::new(tag_bytes);
#[cfg(not(ksupport))]
#[cfg(feature = "log")]
trace!("recv ...->{}", it);
let tag = it.next().expect("truncated tag");
@ -162,7 +160,7 @@ pub fn send_args(writer: &mut Write, service: u32, tag_bytes: &[u8],
let (arg_tags_bytes, return_tag_bytes) = split_tag(tag_bytes);
let mut args_it = TagIterator::new(arg_tags_bytes);
#[cfg(not(ksupport))]
#[cfg(feature = "log")]
{
let return_it = TagIterator::new(return_tag_bytes);
trace!("send<{}>({})->{}", service, args_it, return_it);

View File

@ -1,6 +1,7 @@
use std::prelude::v1::*;
use std::io::{self, Read, Write};
use proto::*;
use std::vec::Vec;
use std::string::String;
use io::*;
fn read_sync(reader: &mut Read) -> io::Result<()> {
let mut sync = [0; 4];

View File

@ -13,16 +13,17 @@ path = "lib.rs"
build_artiq = { path = "../libbuild_artiq" }
[dependencies]
byteorder = { version = "1.0", default-features = false }
cslice = { version = "0.3" }
log = { version = "0.3", default-features = false, features = ["max_level_debug"] }
fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] }
alloc_artiq = { path = "../liballoc_artiq" }
std_artiq = { path = "../libstd_artiq", features = ["alloc"] }
logger_artiq = { path = "../liblogger_artiq" }
cslice = { version = "0.3" }
log = { version = "0.3", default-features = false, features = ["max_level_debug"] }
board = { path = "../libboard", features = ["uart_console"] }
dyld = { path = "../libdyld" }
proto = { path = "../libproto", features = ["log"] }
amp = { path = "../libamp" }
drtioaux = { path = "../libdrtioaux" }
fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] }
byteorder = { version = "1.0", default-features = false }
[dependencies.compiler_builtins]
git = "https://github.com/rust-lang-nursery/compiler-builtins"

View File

@ -2,24 +2,28 @@
#![feature(compiler_builtins_lib, repr_simd, const_fn)]
extern crate compiler_builtins;
extern crate alloc_artiq;
#[macro_use]
extern crate std_artiq as std;
extern crate cslice;
#[macro_use]
extern crate log;
extern crate logger_artiq;
extern crate byteorder;
extern crate fringe;
extern crate smoltcp;
extern crate alloc_artiq;
#[macro_use]
extern crate std_artiq as std;
extern crate logger_artiq;
#[macro_use]
extern crate board;
extern crate proto;
extern crate amp;
#[cfg(has_drtio)]
extern crate drtioaux;
extern crate dyld;
use std::boxed::Box;
use smoltcp::wire::{EthernetAddress, IpAddress};
use proto::{analyzer_proto, moninj_proto, rpc_proto, session_proto, kernel_proto};
use amp::{mailbox, rpc_queue};
macro_rules! borrow_mut {
($x:expr) => ({
@ -33,22 +37,11 @@ macro_rules! borrow_mut {
mod config;
mod ethmac;
mod rtio_mgt;
mod mailbox;
mod rpc_queue;
mod urc;
mod sched;
mod cache;
mod proto;
mod kernel_proto;
mod session_proto;
#[cfg(has_rtio_moninj)]
mod moninj_proto;
#[cfg(has_rtio_analyzer)]
mod analyzer_proto;
mod rpc_proto;
mod kernel;
mod session;
#[cfg(has_rtio_moninj)]