From 7799413a4105ef050421df3e8e0e86f9656a7ac7 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 24 Sep 2017 17:49:34 +0000 Subject: [PATCH] firmware: update Rust from 1.18.0 to 1.20.0. --- artiq/firmware/Cargo.lock | 30 ++-- artiq/firmware/ksupport/Cargo.toml | 2 +- artiq/firmware/ksupport/lib.rs | 8 +- artiq/firmware/liballoc_artiq/lib.rs | 158 ------------------ .../Cargo.toml | 4 +- artiq/firmware/liballoc_list/lib.rs | 145 ++++++++++++++++ artiq/firmware/liballoc_none/lib.rs | 41 ----- .../Cargo.toml | 4 +- artiq/firmware/liballoc_stub/lib.rs | 18 ++ artiq/firmware/libstd_artiq/io/buffered.rs | 2 +- artiq/firmware/libstd_artiq/io/cursor.rs | 2 +- artiq/firmware/libstd_artiq/io/impls.rs | 4 +- artiq/firmware/libstd_artiq/io/mod.rs | 6 +- artiq/firmware/libstd_artiq/lib.rs | 17 +- artiq/firmware/runtime/Cargo.toml | 13 +- artiq/firmware/runtime/lib.rs | 19 +-- artiq/firmware/satman/Cargo.toml | 2 +- conda/artiq-dev/meta.yaml | 2 +- doc/manual/developing.rst | 10 +- 19 files changed, 228 insertions(+), 259 deletions(-) delete mode 100644 artiq/firmware/liballoc_artiq/lib.rs rename artiq/firmware/{liballoc_none => liballoc_list}/Cargo.toml (64%) create mode 100644 artiq/firmware/liballoc_list/lib.rs delete mode 100644 artiq/firmware/liballoc_none/lib.rs rename artiq/firmware/{liballoc_artiq => liballoc_stub}/Cargo.toml (63%) create mode 100644 artiq/firmware/liballoc_stub/lib.rs diff --git a/artiq/firmware/Cargo.lock b/artiq/firmware/Cargo.lock index de6146004..2ff4e8b6b 100644 --- a/artiq/firmware/Cargo.lock +++ b/artiq/firmware/Cargo.lock @@ -3,11 +3,11 @@ name = "std_artiq" version = "0.0.0" [[package]] -name = "alloc_artiq" +name = "alloc_list" version = "0.0.0" [[package]] -name = "alloc_none" +name = "alloc_stub" version = "0.0.0" [[package]] @@ -67,7 +67,7 @@ version = "0.0.0" [[package]] name = "fringe" version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/m-labs/libfringe?rev=bd23494#bd2349467157969324ca7da5d2ae033c7ffac0c0" dependencies = [ "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -90,7 +90,7 @@ dependencies = [ name = "ksupport" version = "0.0.0" dependencies = [ - "alloc_none 0.0.0", + "alloc_stub 0.0.0", "amp 0.0.0", "board 0.0.0", "build_artiq 0.0.0", @@ -127,7 +127,7 @@ dependencies = [ [[package]] name = "managed" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -145,7 +145,7 @@ dependencies = [ name = "runtime" version = "0.0.0" dependencies = [ - "alloc_artiq 0.0.0", + "alloc_list 0.0.0", "amp 0.0.0", "board 0.0.0", "build_artiq 0.0.0", @@ -153,11 +153,11 @@ dependencies = [ "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", - "fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "logger_artiq 0.0.0", "proto 0.0.0", - "smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp?rev=546b367)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=bf4ddef)", "std_artiq 0.0.0", ] @@ -170,7 +170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "satman" version = "0.0.0" dependencies = [ - "alloc_artiq 0.0.0", + "alloc_list 0.0.0", "board 0.0.0", "build_artiq 0.0.0", "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins?rev=631b568)", @@ -182,12 +182,12 @@ dependencies = [ [[package]] name = "smoltcp" -version = "0.4.0-pre" -source = "git+https://github.com/m-labs/smoltcp?rev=546b367#546b3670eff4867891ab0288264d47ea72ab0dd8" +version = "0.4.0" +source = "git+https://github.com/m-labs/smoltcp?rev=bf4ddef#bf4ddef87dae0e671dc8041b7fffd03376518e1e" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -213,15 +213,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins?rev=631b568)" = "" "checksum cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a" -"checksum fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "987689dcfad85eee8d76b477865641ec483e63fb86d52966bfc350c4a647d78a" +"checksum fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)" = "" "checksum gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "291055c78f59ca3d84c99026c9501c469413d386bb46be1e1cf1d285cd1db3b0" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" "checksum log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec57723b84bbe7bdf76aa93169c9b59e67473317c6de3a83cb2a0f8ccb2aa493" -"checksum managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "61eb783b4fa77e8fa4d27ec400f97ed9168546b8b30341a120b7ba9cc6571aaf" +"checksum managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d48e8c30a4363e2981fe4db20527f6ab0f32a243bbc75379dea5a64f60dae4" "checksum rustc-cfg 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56a596b5718bf5e059d59a30af12f7f462a152de147aa462b70892849ee18704" -"checksum smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp?rev=546b367)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=bf4ddef)" = "" "checksum walkdir 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dd7c16466ecc507c7cb5988db03e6eab4aaeab89a5c37a29251fcfd3ac9b7afe" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/artiq/firmware/ksupport/Cargo.toml b/artiq/firmware/ksupport/Cargo.toml index 7cded1135..c785d0aa3 100644 --- a/artiq/firmware/ksupport/Cargo.toml +++ b/artiq/firmware/ksupport/Cargo.toml @@ -15,7 +15,7 @@ build_artiq = { path = "../libbuild_artiq" } [dependencies] byteorder = { version = "1.0", default-features = false } cslice = { version = "0.3" } -alloc_none = { path = "../liballoc_none" } +alloc_stub = { path = "../liballoc_stub" } std_artiq = { path = "../libstd_artiq" } dyld = { path = "../libdyld" } board = { path = "../libboard" } diff --git a/artiq/firmware/ksupport/lib.rs b/artiq/firmware/ksupport/lib.rs index 2f06b0118..904c069e1 100644 --- a/artiq/firmware/ksupport/lib.rs +++ b/artiq/firmware/ksupport/lib.rs @@ -1,4 +1,4 @@ -#![feature(lang_items, asm, libc, panic_unwind, unwind_attributes)] +#![feature(lang_items, asm, libc, panic_unwind, unwind_attributes, global_allocator)] #![no_std] extern crate unwind; @@ -6,7 +6,7 @@ extern crate libc; extern crate byteorder; extern crate cslice; -extern crate alloc_none; +extern crate alloc_stub; extern crate std_artiq as std; extern crate board; @@ -17,12 +17,16 @@ extern crate amp; use core::{mem, ptr, slice, str}; use std::io::Cursor; use cslice::{CSlice, AsCSlice}; +use alloc_stub::StubAlloc; use board::csr; use dyld::Library; use proto::{kernel_proto, rpc_proto}; use proto::kernel_proto::*; use amp::{mailbox, rpc_queue}; +#[global_allocator] +static mut ALLOC: StubAlloc = StubAlloc; + fn send(request: &Message) { unsafe { mailbox::send(request as *const _ as usize) } while !mailbox::acknowledged() {} diff --git a/artiq/firmware/liballoc_artiq/lib.rs b/artiq/firmware/liballoc_artiq/lib.rs deleted file mode 100644 index 78cc8a56d..000000000 --- a/artiq/firmware/liballoc_artiq/lib.rs +++ /dev/null @@ -1,158 +0,0 @@ -#![feature(allocator)] -#![no_std] -#![allocator] - -use core::{mem, ptr, cmp, fmt}; - -// The minimum alignment guaranteed by the architecture. -const MIN_ALIGN: usize = 4; - -const MAGIC_FREE: usize = 0xDEADDEAD; -const MAGIC_BUSY: usize = 0xFEEDFEED; - -#[derive(Debug)] -struct Header { - magic: usize, - size: usize, - next: *mut Header -} - -static mut ROOT: *mut Header = 0 as *mut _; - -pub unsafe fn seed(ptr: *mut u8, size: usize) { - let header_size = mem::size_of::
(); - - if size < header_size * 2 { return } - - let curr = ptr as *mut Header; - (*curr).magic = MAGIC_FREE; - (*curr).size = size - header_size; - (*curr).next = ROOT; - ROOT = curr; -} - -#[no_mangle] -pub extern fn __rust_allocate(mut size: usize, align: usize) -> *mut u8 { - assert!(align <= MIN_ALIGN); - - let header_size = mem::size_of::
(); - if size % header_size != 0 { - size += header_size - (size % header_size); - } - - unsafe { - let mut curr = ROOT; - while !curr.is_null() { - match (*curr).magic { - MAGIC_BUSY => (), - MAGIC_FREE => { - let mut next = (*curr).next; - while !next.is_null() && (*next).magic == MAGIC_FREE { - // Join - (*next).magic = 0; - (*curr).size += (*next).size + header_size; - (*curr).next = (*next).next; - next = (*curr).next; - } - - if (*curr).size > size + header_size * 2 { - // Split - let offset = header_size + size; - let next = (curr as *mut u8).offset(offset as isize) as *mut Header; - (*next).magic = MAGIC_FREE; - (*next).size = (*curr).size - offset; - (*next).next = (*curr).next; - (*curr).next = next; - (*curr).size = size; - } - - if (*curr).size >= size { - (*curr).magic = MAGIC_BUSY; - return curr.offset(1) as *mut u8 - } - }, - _ => panic!("heap corruption detected at {:p}", curr) - } - - curr = (*curr).next; - } - } - - ptr::null_mut() -} - -#[no_mangle] -pub extern fn __rust_allocate_zeroed(size: usize, align: usize) -> *mut u8 { - let ptr = __rust_allocate(size, align); - unsafe { ptr::write_bytes(ptr, 0, size); } - ptr -} - -#[no_mangle] -pub extern fn __rust_deallocate(ptr: *mut u8, _old_size: usize, _align: usize) { - unsafe { - let curr = (ptr as *mut Header).offset(-1); - if (*curr).magic != MAGIC_BUSY { - panic!("heap corruption detected at {:p}", curr) - } - (*curr).magic = MAGIC_FREE; - } -} - -#[no_mangle] -pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, - align: usize) -> *mut u8 { - unsafe { - let new_ptr = __rust_allocate(size, align); - if !new_ptr.is_null() { - ptr::copy_nonoverlapping(ptr, new_ptr, cmp::min(old_size, size)); - __rust_deallocate(ptr, old_size, align); - } - new_ptr - } -} - -#[no_mangle] -pub extern fn __rust_reallocate_inplace(_ptr: *mut u8, old_size: usize, _size: usize, - _align: usize) -> usize { - old_size -} - -#[no_mangle] -pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize { - size -} - -pub fn debug_dump(f: &mut fmt::Write) -> fmt::Result { - unsafe { - let mut total_busy = 0; - let mut total_idle = 0; - let mut total_meta = 0; - - write!(f, "Heap view:\n")?; - - let mut curr = ROOT; - while !curr.is_null() { - total_meta += mem::size_of::
(); - - let desc = match (*curr).magic { - MAGIC_FREE => { total_idle += (*curr).size; "IDLE" }, - MAGIC_BUSY => { total_busy += (*curr).size; "BUSY" }, - _ => "!!!!" - }; - - write!(f, "{} {:p} + {:#x} + {:#x} -> {:p}\n", - desc, curr, mem::size_of::
(), (*curr).size, (*curr).next)?; - match (*curr).magic { - MAGIC_FREE | MAGIC_BUSY => (), - _ => break - } - - curr = (*curr).next; - } - - write!(f, " === busy: {:#x} idle: {:#x} meta: {:#x} total: {:#x}\n", - total_busy, total_idle, total_meta, - total_busy + total_idle + total_meta) - } -} diff --git a/artiq/firmware/liballoc_none/Cargo.toml b/artiq/firmware/liballoc_list/Cargo.toml similarity index 64% rename from artiq/firmware/liballoc_none/Cargo.toml rename to artiq/firmware/liballoc_list/Cargo.toml index 3cabb1f60..f33a70fbb 100644 --- a/artiq/firmware/liballoc_none/Cargo.toml +++ b/artiq/firmware/liballoc_list/Cargo.toml @@ -1,8 +1,8 @@ [package] authors = ["M-Labs"] -name = "alloc_none" +name = "alloc_list" version = "0.0.0" [lib] -name = "alloc_none" +name = "alloc_list" path = "lib.rs" diff --git a/artiq/firmware/liballoc_list/lib.rs b/artiq/firmware/liballoc_list/lib.rs new file mode 100644 index 000000000..8958c1bce --- /dev/null +++ b/artiq/firmware/liballoc_list/lib.rs @@ -0,0 +1,145 @@ +#![feature(alloc, allocator_api)] +#![no_std] + +extern crate alloc; + +use core::{mem, fmt}; +use alloc::allocator::{Layout, AllocErr, Alloc}; + +// The minimum alignment guaranteed by the architecture. +const MIN_ALIGN: usize = 4; + +const MAGIC_FREE: usize = 0xDEADDEAD; +const MAGIC_BUSY: usize = 0xFEEDFEED; + +#[derive(Debug)] +struct Header { + magic: usize, + size: usize, + next: *mut Header +} + +pub struct ListAlloc { + root: *mut Header +} + +pub const EMPTY: ListAlloc = ListAlloc { root: 0 as *mut Header }; + +impl ListAlloc { + pub unsafe fn add(&mut self, ptr: *mut u8, size: usize) { + let header_size = mem::size_of::
(); + if size < header_size * 2 { return } + + let curr = ptr as *mut Header; + (*curr).magic = MAGIC_FREE; + (*curr).size = size - header_size; + (*curr).next = self.root; + self.root = curr; + } + + pub unsafe fn add_range(&mut self, begin: *mut u8, end: *mut u8) { + self.add(begin, end as usize - begin as usize) + } +} + +unsafe impl<'a> Alloc for &'a ListAlloc { + unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> { + if layout.align() > MIN_ALIGN { + return Err(AllocErr::Unsupported { details: "alignment too large" }) + } + + let header_size = mem::size_of::
(); + let size; + if layout.size() % header_size != 0 { + size = layout.size() + header_size - (layout.size() % header_size); + } else { + size = layout.size() + } + + let mut curr = self.root; + while !curr.is_null() { + match (*curr).magic { + MAGIC_BUSY => (), + MAGIC_FREE => { + let mut next = (*curr).next; + while !next.is_null() && (*next).magic == MAGIC_FREE { + // Join + (*next).magic = 0; + (*curr).size += (*next).size + header_size; + (*curr).next = (*next).next; + next = (*curr).next; + } + + if (*curr).size > size + header_size * 2 { + // Split + let offset = header_size + size; + let next = (curr as *mut u8).offset(offset as isize) as *mut Header; + (*next).magic = MAGIC_FREE; + (*next).size = (*curr).size - offset; + (*next).next = (*curr).next; + (*curr).next = next; + (*curr).size = size; + } + + if (*curr).size >= size { + (*curr).magic = MAGIC_BUSY; + return Ok(curr.offset(1) as *mut u8) + } + }, + _ => panic!("heap corruption detected at {:p}", curr) + } + + curr = (*curr).next; + } + + Err(AllocErr::Exhausted { request: layout }) + } + + unsafe fn dealloc(&mut self, ptr: *mut u8, _layout: Layout) { + let curr = (ptr as *mut Header).offset(-1); + if (*curr).magic != MAGIC_BUSY { + panic!("heap corruption detected at {:p}", curr) + } + (*curr).magic = MAGIC_FREE; + } + + fn oom(&mut self, err: AllocErr) -> ! { + panic!("cannot allocate: {:?}", err) + } +} + +impl ListAlloc { + pub fn debug_dump(&self, f: &mut fmt::Write) -> fmt::Result { + unsafe { + let mut total_busy = 0; + let mut total_idle = 0; + let mut total_meta = 0; + + write!(f, "Heap view:\n")?; + + let mut curr = self.root; + while !curr.is_null() { + total_meta += mem::size_of::
(); + + let desc = match (*curr).magic { + MAGIC_FREE => { total_idle += (*curr).size; "IDLE" }, + MAGIC_BUSY => { total_busy += (*curr).size; "BUSY" }, + _ => "!!!!" + }; + + write!(f, "{} {:p} + {:#x} + {:#x} -> {:p}\n", + desc, curr, mem::size_of::
(), (*curr).size, (*curr).next)?; + match (*curr).magic { + MAGIC_FREE | MAGIC_BUSY => (), + _ => break + } + + curr = (*curr).next; + } + + write!(f, " === busy: {:#x} idle: {:#x} meta: {:#x} total: {:#x}\n", + total_busy, total_idle, total_meta, + total_busy + total_idle + total_meta) + } + } +} diff --git a/artiq/firmware/liballoc_none/lib.rs b/artiq/firmware/liballoc_none/lib.rs deleted file mode 100644 index 79f8cecbf..000000000 --- a/artiq/firmware/liballoc_none/lib.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![feature(allocator)] -#![no_std] -#![allocator] - -#[no_mangle] -pub extern "C" fn __rust_allocate(_size: usize, _align: usize) -> *mut u8 { - unimplemented!() -} - -#[no_mangle] -pub extern fn __rust_allocate_zeroed(_size: usize, _align: usize) -> *mut u8 { - unimplemented!() -} - -#[no_mangle] -pub extern "C" fn __rust_deallocate(_ptr: *mut u8, _old_size: usize, _align: usize) { - unimplemented!() -} - -#[no_mangle] -pub extern "C" fn __rust_reallocate(_ptr: *mut u8, - _old_size: usize, - _size: usize, - _align: usize) - -> *mut u8 { - unimplemented!() -} - -#[no_mangle] -pub extern "C" fn __rust_reallocate_inplace(_ptr: *mut u8, - _old_size: usize, - _size: usize, - _align: usize) - -> usize { - unimplemented!() -} - -#[no_mangle] -pub extern "C" fn __rust_usable_size(_size: usize, _align: usize) -> usize { - unimplemented!() -} diff --git a/artiq/firmware/liballoc_artiq/Cargo.toml b/artiq/firmware/liballoc_stub/Cargo.toml similarity index 63% rename from artiq/firmware/liballoc_artiq/Cargo.toml rename to artiq/firmware/liballoc_stub/Cargo.toml index a232e5be9..1503c9005 100644 --- a/artiq/firmware/liballoc_artiq/Cargo.toml +++ b/artiq/firmware/liballoc_stub/Cargo.toml @@ -1,8 +1,8 @@ [package] authors = ["M-Labs"] -name = "alloc_artiq" +name = "alloc_stub" version = "0.0.0" [lib] -name = "alloc_artiq" +name = "alloc_stub" path = "lib.rs" diff --git a/artiq/firmware/liballoc_stub/lib.rs b/artiq/firmware/liballoc_stub/lib.rs new file mode 100644 index 000000000..941b5e16f --- /dev/null +++ b/artiq/firmware/liballoc_stub/lib.rs @@ -0,0 +1,18 @@ +#![feature(alloc, allocator_api)] +#![no_std] + +extern crate alloc; + +use alloc::allocator::{Layout, AllocErr, Alloc}; + +pub struct StubAlloc; + +unsafe impl<'a> Alloc for &'a StubAlloc { + unsafe fn alloc(&mut self, _layout: Layout) -> Result<*mut u8, AllocErr> { + unimplemented!() + } + + unsafe fn dealloc(&mut self, _ptr: *mut u8, _layout: Layout) { + unimplemented!() + } +} diff --git a/artiq/firmware/libstd_artiq/io/buffered.rs b/artiq/firmware/libstd_artiq/io/buffered.rs index 3088e4e63..d0e7dbf72 100644 --- a/artiq/firmware/libstd_artiq/io/buffered.rs +++ b/artiq/firmware/libstd_artiq/io/buffered.rs @@ -18,7 +18,7 @@ use core::fmt; use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; use io::memchr; use alloc::boxed::Box; -use collections::vec::Vec; +use alloc::vec::Vec; /// The `BufReader` struct adds buffering to any reader. /// diff --git a/artiq/firmware/libstd_artiq/io/cursor.rs b/artiq/firmware/libstd_artiq/io/cursor.rs index 88e7646d5..8b4783ae7 100644 --- a/artiq/firmware/libstd_artiq/io/cursor.rs +++ b/artiq/firmware/libstd_artiq/io/cursor.rs @@ -14,7 +14,7 @@ use io::prelude::*; use core::cmp; use io::{self, SeekFrom, Error, ErrorKind}; use alloc::boxed::Box; -use collections::vec::Vec; +use alloc::vec::Vec; /// A `Cursor` wraps another type and provides it with a /// [`Seek`](trait.Seek.html) implementation. diff --git a/artiq/firmware/libstd_artiq/io/impls.rs b/artiq/firmware/libstd_artiq/io/impls.rs index 9750cd638..128e693ca 100644 --- a/artiq/firmware/libstd_artiq/io/impls.rs +++ b/artiq/firmware/libstd_artiq/io/impls.rs @@ -14,8 +14,8 @@ use io::{self, SeekFrom, Read, Write, Seek, Error, ErrorKind}; use io::BufRead; use core::fmt; use core::mem; - use collections::string::String; - use collections::vec::Vec; + use alloc::string::String; + use alloc::vec::Vec; // ============================================================================= // Forwarding implementations diff --git a/artiq/firmware/libstd_artiq/io/mod.rs b/artiq/firmware/libstd_artiq/io/mod.rs index f0d42ab43..6722b7485 100644 --- a/artiq/firmware/libstd_artiq/io/mod.rs +++ b/artiq/firmware/libstd_artiq/io/mod.rs @@ -255,9 +255,9 @@ use core::marker::Sized; use core::option::Option::{self, Some, None}; use core::result::Result::{Ok, Err}; use core::result; - use collections::string::String; - use collections::vec::Vec; - use collections::str; + use alloc::string::String; + use alloc::vec::Vec; + use alloc::str; mod memchr; pub use self::buffered::{BufReader, BufWriter, LineWriter}; diff --git a/artiq/firmware/libstd_artiq/lib.rs b/artiq/firmware/libstd_artiq/lib.rs index 483926220..f0c7b8c5a 100644 --- a/artiq/firmware/libstd_artiq/lib.rs +++ b/artiq/firmware/libstd_artiq/lib.rs @@ -1,29 +1,28 @@ -#![feature(lang_items, asm, alloc, collections, needs_panic_runtime, +#![feature(lang_items, asm, alloc, needs_panic_runtime, unicode, raw, int_error_internals, try_from, macro_reexport, allow_internal_unstable, stmt_expr_attributes, str_internals)] #![no_std] #![needs_panic_runtime] extern crate std_unicode; -extern crate alloc; #[macro_use] #[macro_reexport(vec, format)] -extern crate collections; +extern crate alloc; pub use core::{any, cell, clone, cmp, convert, default, hash, iter, marker, mem, num, ops, option, ptr, result, sync, char, i16, i32, i64, i8, isize, u16, u32, u64, u8, usize, f32, f64}; -pub use alloc::{arc, rc, oom, raw_vec}; -pub use collections::{binary_heap, borrow, boxed, btree_map, btree_set, fmt, linked_list, slice, +pub use alloc::{arc, rc, raw_vec}; +pub use alloc::{binary_heap, borrow, boxed, btree_map, btree_set, fmt, linked_list, slice, str, string, vec, vec_deque}; pub mod prelude { pub mod v1 { pub use core::prelude::v1::*; - pub use collections::boxed::Box; - pub use collections::borrow::ToOwned; - pub use collections::string::{String, ToString}; - pub use collections::vec::Vec; + pub use alloc::boxed::Box; + pub use alloc::borrow::ToOwned; + pub use alloc::string::{String, ToString}; + pub use alloc::vec::Vec; } } diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index 7da752c38..8b654b373 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -16,8 +16,7 @@ build_artiq = { path = "../libbuild_artiq" } byteorder = { version = "1.0", default-features = false } cslice = { version = "0.3" } log = { version = "0.3", default-features = false } -fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] } -alloc_artiq = { path = "../liballoc_artiq" } +alloc_list = { path = "../liballoc_list" } std_artiq = { path = "../libstd_artiq", features = ["alloc", "io_error_alloc"] } logger_artiq = { path = "../liblogger_artiq" } board = { path = "../libboard", features = ["uart_console"] } @@ -30,8 +29,14 @@ git = "https://github.com/rust-lang-nursery/compiler-builtins" rev = "631b568" features = ["mem"] +[dependencies.fringe] +git = "https://github.com/m-labs/libfringe" +rev = "bd23494" +default-features = false +features = ["alloc"] + [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp" -rev = "64369d9" +rev = "bf4ddef" default-features = false -features = ["alloc", "collections", "log"]#, "verbose"] +features = ["alloc", "log"] diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index af469147b..c9b9acb1f 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -1,6 +1,5 @@ #![no_std] -#![feature(compiler_builtins_lib, alloc, oom, repr_simd, lang_items, const_fn, - closure_to_fn_coercion)] +#![feature(compiler_builtins_lib, alloc, repr_simd, lang_items, const_fn, global_allocator)] extern crate compiler_builtins; extern crate alloc; @@ -11,7 +10,7 @@ extern crate byteorder; extern crate fringe; extern crate smoltcp; -extern crate alloc_artiq; +extern crate alloc_list; #[macro_use] extern crate std_artiq as std; extern crate logger_artiq; @@ -164,6 +163,10 @@ fn startup() { } } +#[global_allocator] +static mut ALLOC: alloc_list::ListAlloc = alloc_list::EMPTY; +static mut LOG_BUFFER: [u8; 1<<17] = [0; 1<<17]; + #[no_mangle] pub extern fn main() -> i32 { unsafe { @@ -171,16 +174,10 @@ pub extern fn main() -> i32 { static mut _fheap: u8; static mut _eheap: u8; } - alloc_artiq::seed(&mut _fheap as *mut u8, - &_eheap as *const u8 as usize - &_fheap as *const u8 as usize); + ALLOC.add_range(&mut _fheap, &mut _eheap); - alloc::oom::set_oom_handler(|| { - alloc_artiq::debug_dump(&mut board::uart_console::Console).unwrap(); - panic!("out of memory"); - }); - - static mut LOG_BUFFER: [u8; 1<<17] = [0; 1<<17]; logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup); + 0 } } diff --git a/artiq/firmware/satman/Cargo.toml b/artiq/firmware/satman/Cargo.toml index 8e68e41ce..b8c7106f5 100644 --- a/artiq/firmware/satman/Cargo.toml +++ b/artiq/firmware/satman/Cargo.toml @@ -13,7 +13,7 @@ path = "lib.rs" build_artiq = { path = "../libbuild_artiq" } [dependencies] -alloc_artiq = { path = "../liballoc_artiq" } +alloc_list = { path = "../liballoc_list" } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } logger_artiq = { path = "../liblogger_artiq" } board = { path = "../libboard", features = ["uart_console"] } diff --git a/conda/artiq-dev/meta.yaml b/conda/artiq-dev/meta.yaml index e476cf990..98ed81eeb 100644 --- a/conda/artiq-dev/meta.yaml +++ b/conda/artiq-dev/meta.yaml @@ -20,7 +20,7 @@ requirements: - binutils-or1k-linux >=2.27 - llvm-or1k - llvmlite-artiq 0.12.0.dev py35_30 - - rust-core-or1k 1.18.0 15 + - rust-core-or1k 1.20.0 16 - cargo 0.11.0 - openocd >=0.10 - lit diff --git a/doc/manual/developing.rst b/doc/manual/developing.rst index 3d7fa7c5b..6fc5673ee 100644 --- a/doc/manual/developing.rst +++ b/doc/manual/developing.rst @@ -103,17 +103,17 @@ and the ARTIQ kernels. * Install Rust: :: $ cd ~/artiq-dev - $ git clone -b artiq-1.18.0 https://github.com/m-labs/rust + $ git clone -b artiq-1.20.0 https://github.com/m-labs/rust $ cd rust $ git submodule update --init $ mkdir build $ cd build - $ ../configure --prefix=/usr/local/rust-or1k --llvm-root=/usr/local/llvm-or1k --disable-manage-submodules + $ ../configure --prefix=/usr/local/rust-or1k --llvm-root=/usr/local/llvm-or1k --disable-manage-submodules --disable-docs $ sudo mkdir /usr/local/rust-or1k $ sudo chown $USER.$USER /usr/local/rust-or1k $ make install - $ libs="libcore liballoc libstd_unicode libcollections liblibc_mini libunwind" + $ libs="libcore libstd_unicode liballoc liblibc_mini libunwind" $ rustc="/usr/local/rust-or1k/bin/rustc --target or1k-unknown-none -g -C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s -L ." $ destdir="/usr/local/rust-or1k/lib/rustlib/or1k-unknown-none/lib/" $ mkdir ../build-or1k @@ -121,8 +121,8 @@ and the ARTIQ kernels. $ for lib in ${libs}; do ${rustc} ../src/${lib}/lib.rs; done $ ${rustc} -Cpanic=abort ../src/libpanic_abort/lib.rs $ ${rustc} -Cpanic=unwind ../src/libpanic_unwind/lib.rs --cfg llvm_libunwind - $ sudo mkdir -p ${destdir} - $ sudo cp *.rlib ${destdir} + $ mkdir -p ${destdir} + $ cp *.rlib ${destdir} .. note:: Compilation of LLVM can take more than 30 min on some machines. Compilation of Rust can take more than two hours.