forked from M-Labs/artiq
1
0
Fork 0

firmware: do not link to C code in runtime and satman.

This commit is contained in:
whitequark 2017-02-03 12:12:41 +00:00
parent fd8b11532f
commit cde2054926
9 changed files with 65 additions and 78 deletions

View File

@ -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)
}

View File

@ -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(())
}
}

View File

@ -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"

View File

@ -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 {}
}

View File

@ -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;

View File

@ -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"]

View File

@ -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

View File

@ -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)]

View File

@ -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