From cde20549260e54c0343fa9ea3eb8ec2e178de5d7 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 3 Feb 2017 12:12:41 +0000 Subject: [PATCH] firmware: do not link to C code in runtime and satman. --- artiq/firmware/ksupport/lib.rs | 2 +- artiq/firmware/libboard/uart_console.rs | 9 +++- artiq/firmware/runtime/Cargo.toml | 5 ++- artiq/firmware/runtime/lib.rs | 59 ++++++++++--------------- artiq/firmware/runtime/session.rs | 1 - artiq/firmware/satman/Cargo.toml | 5 ++- artiq/firmware/satman/Makefile | 6 +-- artiq/firmware/satman/lib.rs | 50 ++++++++++----------- artiq/runtime/Makefile | 6 +-- 9 files changed, 65 insertions(+), 78 deletions(-) diff --git a/artiq/firmware/ksupport/lib.rs b/artiq/firmware/ksupport/lib.rs index 92959d26b..462c930cf 100644 --- a/artiq/firmware/ksupport/lib.rs +++ b/artiq/firmware/ksupport/lib.rs @@ -309,7 +309,7 @@ pub unsafe fn main() { } #[no_mangle] -pub fn exception_handler(vect: u32, _regs: *const u32, pc: u32, ea: u32) { +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) } diff --git a/artiq/firmware/libboard/uart_console.rs b/artiq/firmware/libboard/uart_console.rs index b43b6064e..dcd79ff33 100644 --- a/artiq/firmware/libboard/uart_console.rs +++ b/artiq/firmware/libboard/uart_console.rs @@ -1,11 +1,16 @@ use core::fmt; +use csr; pub struct Console; impl fmt::Write for Console { fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { - extern { fn putchar(c: i32) -> i32; } - for c in s.bytes() { unsafe { putchar(c as i32); } } + for c in s.bytes() { + unsafe { + while csr::uart::txfull_read() != 0 {} + csr::uart::rxtx_write(c) + } + } Ok(()) } } diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index 3fe32e4ad..6f4f8b384 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -13,7 +13,6 @@ path = "lib.rs" build_artiq = { path = "../libbuild_artiq" } [dependencies] -compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins" } alloc_artiq = { path = "../liballoc_artiq" } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } logger_artiq = { path = "../liblogger_artiq" } @@ -23,6 +22,10 @@ board = { path = "../libboard", features = ["uart_console"] } 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" +features = ["mem"] + [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp" rev = "e8ece3e" diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index d5292f9ad..4331db43d 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -1,11 +1,10 @@ #![no_std] -#![feature(compiler_builtins_lib, libc, repr_simd, const_fn)] +#![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 libc; extern crate cslice; #[macro_use] extern crate log; @@ -19,11 +18,6 @@ extern crate board; use std::boxed::Box; use smoltcp::wire::{EthernetAddress, IpAddress}; -extern { - fn readchar() -> libc::c_char; - fn readchar_nonblock() -> libc::c_int; -} - macro_rules! borrow_mut { ($x:expr) => ({ match $x.try_borrow_mut() { @@ -68,7 +62,7 @@ fn startup() { let t = board::clock::get_ms(); info!("press 'e' to erase startup and idle kernels..."); while board::clock::get_ms() < t + 1000 { - if unsafe { readchar_nonblock() != 0 && readchar() == b'e' as libc::c_char } { + if unsafe { board::csr::uart::rxtx_read() == b'e' } { config::remove("startup_kernel").unwrap(); config::remove("idle_kernel").unwrap(); info!("startup and idle kernels erased"); @@ -143,41 +137,36 @@ fn startup() { } } -use board::{irq, csr}; -extern { - fn uart_init(); - fn uart_isr(); - - static mut _fheap: u8; - static mut _eheap: u8; -} - #[no_mangle] -pub unsafe extern fn main() -> i32 { - irq::set_mask(0); - irq::set_ie(true); - uart_init(); +pub extern fn main() -> i32 { + unsafe { + extern { + 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_artiq::seed(&mut _fheap as *mut u8, - &_eheap as *const u8 as usize - &_fheap as *const u8 as usize); - - static mut LOG_BUFFER: [u8; 65536] = [0; 65536]; - logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup); - 0 -} - -#[no_mangle] -pub unsafe extern fn isr() { - let irqs = irq::pending() & irq::get_mask(); - if irqs & (1 << csr::UART_INTERRUPT) != 0 { - uart_isr() + static mut LOG_BUFFER: [u8; 65536] = [0; 65536]; + logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup); + 0 } } +#[no_mangle] +pub extern fn exception_handler(vect: u32, _regs: *const u32, pc: u32, ea: u32) { + panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea) +} + +#[no_mangle] +pub extern fn abort() { + panic!("aborted") +} + // Allow linking with crates that are built as -Cpanic=unwind even if we use -Cpanic=abort. // This is never called. #[allow(non_snake_case)] #[no_mangle] -pub extern "C" fn _Unwind_Resume() -> ! { +pub extern fn _Unwind_Resume() -> ! { loop {} } diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 106ed5412..85afb310f 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -3,7 +3,6 @@ use std::{mem, str}; use std::cell::{Cell, RefCell}; use std::io::{self, Read, Write}; use std::error::Error; -use std::btree_set::BTreeSet; use {config, rtio_mgt, mailbox, rpc_queue, kernel}; use logger_artiq::BufferLogger; use cache::Cache; diff --git a/artiq/firmware/satman/Cargo.toml b/artiq/firmware/satman/Cargo.toml index cab9759c6..5a4b6c938 100644 --- a/artiq/firmware/satman/Cargo.toml +++ b/artiq/firmware/satman/Cargo.toml @@ -13,9 +13,12 @@ path = "lib.rs" build_artiq = { path = "../libbuild_artiq" } [dependencies] -compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins" } alloc_artiq = { path = "../liballoc_artiq" } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } logger_artiq = { path = "../liblogger_artiq" } board = { path = "../libboard", features = ["uart_console"] } log = { version = "0.3", default-features = false } + +[dependencies.compiler_builtins] +git = "https://github.com/rust-lang-nursery/compiler-builtins" +features = ["mem"] diff --git a/artiq/firmware/satman/Makefile b/artiq/firmware/satman/Makefile index d2dd7fcf4..576d69310 100644 --- a/artiq/firmware/satman/Makefile +++ b/artiq/firmware/satman/Makefile @@ -23,11 +23,7 @@ $(RUSTOUT)/libsatman.a: --manifest-path $(realpath $(SATMAN_DIRECTORY))/Cargo.toml satman.elf: $(RUSTOUT)/libsatman.a - $(LD) $(LDFLAGS) \ - -T $(SATMAN_DIRECTORY)/satman.ld \ - -o $@ \ - $^ \ - -lbase-nofloat + $(LD) $(LDFLAGS) -T $(SATMAN_DIRECTORY)/satman.ld -o $@ $^ @chmod -x $@ %.bin: %.elf diff --git a/artiq/firmware/satman/lib.rs b/artiq/firmware/satman/lib.rs index 2cca2421a..ddaa6f934 100644 --- a/artiq/firmware/satman/lib.rs +++ b/artiq/firmware/satman/lib.rs @@ -41,42 +41,38 @@ fn startup() { #[cfg(has_ad9516)] board::ad9516::init().expect("cannot initialize ad9516"); board::i2c::init(); - board::si5324::setup_hitless_clock_switching(&SI5324_SETTINGS).expect("cannot initialize si5324"); + board::si5324::setup_hitless_clock_switching(&SI5324_SETTINGS) + .expect("cannot initialize si5324"); loop {} } -use board::{irq, csr}; -extern { - fn uart_init(); - fn uart_isr(); - - static mut _fheap: u8; - static mut _eheap: u8; -} - #[no_mangle] -pub unsafe extern fn main() -> i32 { - irq::set_mask(0); - irq::set_ie(true); - uart_init(); +pub extern fn main() -> i32 { + unsafe { + extern { + 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_artiq::seed(&mut _fheap as *mut u8, - &_eheap as *const u8 as usize - &_fheap as *const u8 as usize); - - static mut LOG_BUFFER: [u8; 65536] = [0; 65536]; - logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup); - 0 -} - -#[no_mangle] -pub unsafe extern fn isr() { - let irqs = irq::pending() & irq::get_mask(); - if irqs & (1 << csr::UART_INTERRUPT) != 0 { - uart_isr() + static mut LOG_BUFFER: [u8; 65536] = [0; 65536]; + logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup); + 0 } } +#[no_mangle] +pub extern fn exception_handler(vect: u32, _regs: *const u32, pc: u32, ea: u32) { + panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea) +} + +#[no_mangle] +pub extern fn abort() { + panic!("aborted") +} + // Allow linking with crates that are built as -Cpanic=unwind even if we use -Cpanic=abort. // This is never called. #[allow(non_snake_case)] diff --git a/artiq/runtime/Makefile b/artiq/runtime/Makefile index 8bd195a73..b2ba78794 100644 --- a/artiq/runtime/Makefile +++ b/artiq/runtime/Makefile @@ -45,11 +45,7 @@ $(RUSTOUT)/libruntime.a: --manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/runtime/Cargo.toml) runtime.elf: $(RUSTOUT)/libruntime.a ksupport_data.o - $(LD) $(LDFLAGS) \ - -T $(RUNTIME_DIRECTORY)/runtime.ld \ - -o $@ \ - $^ \ - -lbase-nofloat + $(LD) $(LDFLAGS) -T $(RUNTIME_DIRECTORY)/runtime.ld -o $@ $^ @chmod -x $@ .PHONY: $(RUSTOUT_KSUPPORT)/libksupport.a