From fa00ab211da4457111c8069ce98f80526cae5b3c Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 4 Aug 2020 10:15:57 +0800 Subject: [PATCH] Updated zc706 dependency and fixed compiler errors. --- src/Cargo.lock | 10 +++++----- src/runtime/Cargo.toml | 2 +- src/runtime/link.x | 9 ++++++--- src/runtime/src/comms.rs | 13 ++++++------- src/runtime/src/kernel/control.rs | 29 +++++++++++++++++++++-------- src/runtime/src/kernel/core1.rs | 25 +++++++++++++------------ src/runtime/src/kernel/mod.rs | 18 +++++++++--------- src/runtime/src/kernel/rpc.rs | 6 +++--- src/runtime/src/main.rs | 7 +++++-- src/szl/link.x | 6 ++++++ 10 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 414b1764..41f3f78f 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -201,7 +201,7 @@ dependencies = [ [[package]] name = "libasync" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#0aa75d3544a2092a0ba6ce689c3f025f22ec30e4" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#b65606f2d02fab273645835a102048b23c3394f7" dependencies = [ "embedded-hal", "libcortex_a9", @@ -213,7 +213,7 @@ dependencies = [ [[package]] name = "libboard_zynq" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#0aa75d3544a2092a0ba6ce689c3f025f22ec30e4" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#b65606f2d02fab273645835a102048b23c3394f7" dependencies = [ "bit_field", "embedded-hal", @@ -237,7 +237,7 @@ dependencies = [ [[package]] name = "libcortex_a9" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#0aa75d3544a2092a0ba6ce689c3f025f22ec30e4" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#b65606f2d02fab273645835a102048b23c3394f7" dependencies = [ "bit_field", "libregister", @@ -252,7 +252,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libregister" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#0aa75d3544a2092a0ba6ce689c3f025f22ec30e4" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#b65606f2d02fab273645835a102048b23c3394f7" dependencies = [ "bit_field", "vcell", @@ -262,7 +262,7 @@ dependencies = [ [[package]] name = "libsupport_zynq" version = "0.0.0" -source = "git+https://git.m-labs.hk/M-Labs/zc706.git#0aa75d3544a2092a0ba6ce689c3f025f22ec30e4" +source = "git+https://git.m-labs.hk/M-Labs/zc706.git#b65606f2d02fab273645835a102048b23c3394f7" dependencies = [ "compiler_builtins", "libboard_zynq", diff --git a/src/runtime/Cargo.toml b/src/runtime/Cargo.toml index e8dc899e..6ffc8891 100644 --- a/src/runtime/Cargo.toml +++ b/src/runtime/Cargo.toml @@ -26,7 +26,7 @@ log_buffer = { version = "1.2" } libm = { version = "0.2", features = ["unstable"] } libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } -libsupport_zynq = { default-features = false, git = "https://git.m-labs.hk/M-Labs/zc706.git" } +libsupport_zynq = { default-features = false, features = ["alloc_core", "dummy_irq_handler"], git = "https://git.m-labs.hk/M-Labs/zc706.git" } libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libasync = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libregister = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } diff --git a/src/runtime/link.x b/src/runtime/link.x index 91159ad2..e93a5602 100644 --- a/src/runtime/link.x +++ b/src/runtime/link.x @@ -48,9 +48,12 @@ SECTIONS .heap (NOLOAD) : ALIGN(8) { - __heap_start = .; - . += 0x1000000; - __heap_end = .; + __heap0_start = .; + . += 0x800000; + __heap0_end = .; + __heap1_start = .; + . += 0x800000; + __heap1_end = .; } > SDRAM .stack1 (NOLOAD) : ALIGN(8) diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index 882998a2..30df324b 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -2,7 +2,6 @@ use core::fmt; use core::cell::RefCell; use core::str::Utf8Error; use alloc::rc::Rc; -use alloc::sync::Arc; use alloc::{vec, vec::Vec, string::String}; use log::{info, warn, error}; @@ -126,7 +125,7 @@ async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc { if stream.is_none() { error!("Unexpected RPC from startup/idle kernel!"); @@ -141,7 +140,7 @@ async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc { let tag = read_bytes(stream, 512).await?; - let slot = match *control.borrow_mut().rx.async_recv().await { + let slot = match control.borrow_mut().rx.async_recv().await { kernel::Message::RpcRecvRequest(slot) => slot, other => panic!("expected root value slot from core1, not {:?}", other), }; @@ -155,7 +154,7 @@ async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc slot, other => panic!("expected nested value slot from kernel CPU, not {:?}", other), } @@ -166,7 +165,7 @@ async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc { let mut control = control.borrow_mut(); - match *control.rx.async_recv().await { + match control.rx.async_recv().await { kernel::Message::RpcRecvRequest(_) => (), other => panic!("expected (ignored) root value slot from kernel CPU, not {:?}", other), } @@ -233,9 +232,9 @@ async fn handle_run_kernel(stream: Option<&TcpStream>, control: &Rc, control: &Rc>, stream: Option<&TcpStream>) -> Result<()> { let mut control = control.borrow_mut(); - control.tx.async_send(kernel::Message::LoadRequest(Arc::new(buffer))).await; + control.tx.async_send(kernel::Message::LoadRequest(buffer)).await; let reply = control.rx.async_recv().await; - match *reply { + match reply { kernel::Message::LoadCompleted => { if let Some(stream) = stream { write_header(stream, Reply::LoadCompleted).await?; diff --git a/src/runtime/src/kernel/control.rs b/src/runtime/src/kernel/control.rs index fb40abf6..17930227 100644 --- a/src/runtime/src/kernel/control.rs +++ b/src/runtime/src/kernel/control.rs @@ -1,21 +1,33 @@ -use libcortex_a9::sync_channel::{self, sync_channel}; +use libcortex_a9::sync_channel::{Sender, Receiver}; use libsupport_zynq::boot::Core1; use super::{CHANNEL_0TO1, CHANNEL_1TO0, Message}; pub struct Control { - pub tx: sync_channel::Sender, - pub rx: sync_channel::Receiver, + pub tx: Sender<'static, Message>, + pub rx: Receiver<'static, Message>, +} + +fn get_channels() -> (Sender<'static, Message>, Receiver<'static, Message>) { + let mut core0_tx = None; + while core0_tx.is_none() { + core0_tx = CHANNEL_0TO1.lock().take(); + } + let core0_tx = core0_tx.unwrap(); + + let mut core0_rx = None; + while core0_rx.is_none() { + core0_rx = CHANNEL_1TO0.lock().take(); + } + let core0_rx = core0_rx.unwrap(); + + (core0_tx, core0_rx) } impl Control { pub fn start() -> Self { Core1::start(true); - - let (core0_tx, core1_rx) = sync_channel(4); - let (core1_tx, core0_rx) = sync_channel(4); - *CHANNEL_0TO1.lock() = Some(core1_rx); - *CHANNEL_1TO0.lock() = Some(core1_tx); + let (core0_tx, core0_rx) = get_channels(); Control { tx: core0_tx, @@ -23,3 +35,4 @@ impl Control { } } } + diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 50e81943..9bc2ad0f 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -9,7 +9,10 @@ use libcortex_a9::{ enable_fpu, cache::{dcci_slice, iciallu, bpiall}, asm::{dsb, isb}, + sync_channel, }; +use libboard_zynq::{mpcore, gic}; +use libsupport_zynq::ram; use dyld::{self, Library}; use crate::eh_artiq; use super::{ @@ -138,23 +141,23 @@ pub fn main_core1() { enable_fpu(); debug!("FPU enabled on Core1"); - let mut core1_tx = None; - while core1_tx.is_none() { - core1_tx = CHANNEL_1TO0.lock().take(); - } - let mut core1_tx = core1_tx.unwrap(); + ram::init_alloc_core1(); + gic::InterruptController::new(mpcore::RegisterBlock::new()).enable_interrupts(); - let mut core1_rx = None; - while core1_rx.is_none() { - core1_rx = CHANNEL_0TO1.lock().take(); + let (mut core0_tx, mut core1_rx) = sync_channel!(Message, 4); + let (mut core1_tx, core0_rx) = sync_channel!(Message, 4); + unsafe { + core0_tx.reset(); + core1_tx.reset(); } - let mut core1_rx = core1_rx.unwrap(); + *CHANNEL_0TO1.lock() = Some(core0_tx); + *CHANNEL_1TO0.lock() = Some(core0_rx); // set on load, cleared on start let mut loaded_kernel = None; loop { let message = core1_rx.recv(); - match *message { + match message { Message::LoadRequest(data) => { let result = dyld::load(&data, &resolve) .and_then(KernelImage::new); @@ -213,8 +216,6 @@ pub fn terminate(exception: &'static eh_artiq::Exception<'static>, backtrace: &' let mut core1_tx = KERNEL_CHANNEL_1TO0.lock(); core1_tx.as_mut().unwrap().send(Message::KernelException(exception, &backtrace[..cursor])); } - // TODO: remove after implementing graceful kernel termination. - error!("Core1 uncaught exception"); loop {} } diff --git a/src/runtime/src/kernel/mod.rs b/src/runtime/src/kernel/mod.rs index b3d94fbd..c2bb35b1 100644 --- a/src/runtime/src/kernel/mod.rs +++ b/src/runtime/src/kernel/mod.rs @@ -1,5 +1,5 @@ use core::ptr; -use alloc::{vec::Vec, sync::Arc, string::String}; +use alloc::{vec::Vec, string::String}; use libcortex_a9::{mutex::Mutex, sync_channel}; use crate::eh_artiq; @@ -12,7 +12,7 @@ mod rpc; mod dma; mod cache; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct RPCException { pub name: String, pub message: String, @@ -23,24 +23,24 @@ pub struct RPCException { pub function: String } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Message { - LoadRequest(Arc>), + LoadRequest(Vec), LoadCompleted, LoadFailed, StartRequest, KernelFinished, KernelException(&'static eh_artiq::Exception<'static>, &'static [usize]), - RpcSend { is_async: bool, data: Arc> }, + RpcSend { is_async: bool, data: Vec }, RpcRecvRequest(*mut ()), RpcRecvReply(Result), } -static CHANNEL_0TO1: Mutex>> = Mutex::new(None); -static CHANNEL_1TO0: Mutex>> = Mutex::new(None); +static CHANNEL_0TO1: Mutex>> = Mutex::new(None); +static CHANNEL_1TO0: Mutex>> = Mutex::new(None); -static KERNEL_CHANNEL_0TO1: Mutex>> = Mutex::new(None); -static KERNEL_CHANNEL_1TO0: Mutex>> = Mutex::new(None); +static KERNEL_CHANNEL_0TO1: Mutex>> = Mutex::new(None); +static KERNEL_CHANNEL_1TO0: Mutex>> = Mutex::new(None); static mut KERNEL_IMAGE: *const core1::KernelImage = ptr::null(); diff --git a/src/runtime/src/kernel/rpc.rs b/src/runtime/src/kernel/rpc.rs index e41c51e1..31e77868 100644 --- a/src/runtime/src/kernel/rpc.rs +++ b/src/runtime/src/kernel/rpc.rs @@ -1,6 +1,6 @@ //! Kernel-side RPC API -use alloc::{vec::Vec, sync::Arc}; +use alloc::vec::Vec; use cslice::{CSlice, AsCSlice}; use crate::eh_artiq; @@ -14,7 +14,7 @@ fn rpc_send_common(is_async: bool, service: u32, tag: &CSlice, data: *const let mut core1_tx = KERNEL_CHANNEL_1TO0.lock(); let mut buffer = Vec::::new(); send_args(&mut buffer, service, tag.as_ref(), data).expect("RPC encoding failed"); - core1_tx.as_mut().unwrap().send(Message::RpcSend { is_async, data: Arc::new(buffer) }); + core1_tx.as_mut().unwrap().send(Message::RpcSend { is_async, data: buffer }); } pub extern fn rpc_send(service: u32, tag: &CSlice, data: *const *const ()) { @@ -32,7 +32,7 @@ pub extern fn rpc_recv(slot: *mut ()) -> usize { core1_tx.as_mut().unwrap().send(Message::RpcRecvRequest(slot)); core1_rx.as_mut().unwrap().recv() }; - match *reply { + match reply { Message::RpcRecvReply(Ok(alloc_size)) => alloc_size, Message::RpcRecvReply(Err(exception)) => unsafe { eh_artiq::raise(&eh_artiq::Exception { diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index 7d12fba3..5842b347 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -6,13 +6,15 @@ #![feature(c_variadic)] #![feature(const_btree_new)] #![feature(ptr_offset_from)] +#![feature(const_in_array_repeat_expressions)] +#![feature(naked_functions)] extern crate alloc; use core::{cmp, str}; use log::{info, warn, error}; -use libboard_zynq::{timer::GlobalTimer, devc, slcr}; +use libboard_zynq::{timer::GlobalTimer, devc, slcr, mpcore, gic}; use libasync::{task, block_async}; use libsupport_zynq::ram; use libregister::RegisterW; @@ -183,7 +185,8 @@ pub fn main_core0() { info!("NAR3/Zynq7000 starting..."); - ram::init_alloc_linker(); + ram::init_alloc_core0(); + gic::InterruptController::new(mpcore::RegisterBlock::new()).enable_interrupts(); init_gateware(); info!("detected gateware: {}", identifier_read(&mut [0; 64])); diff --git a/src/szl/link.x b/src/szl/link.x index d8f6782c..91fb2718 100644 --- a/src/szl/link.x +++ b/src/szl/link.x @@ -34,6 +34,12 @@ SECTIONS __bss_end = .; } > OCM3 + .heap (NOLOAD) : ALIGN(8) + { + __heap0_start = .; + __heap0_end = .; + } > OCM3 + .stack1 (NOLOAD) : ALIGN(8) { __stack1_end = .;