From d8d09e219fe7e6131f23b177bf6bcd7d6fcd50f8 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 26 Apr 2020 09:57:42 +0800 Subject: [PATCH] start kernel --- runtime/src/comms.rs | 4 ++++ runtime/src/kernel.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/runtime/src/comms.rs b/runtime/src/comms.rs index 2d1f5dc..8d3ddf9 100644 --- a/runtime/src/comms.rs +++ b/runtime/src/comms.rs @@ -143,6 +143,10 @@ async fn handle_connection(stream: &TcpStream, control: Rc { + let mut control = control.borrow_mut(); + control.tx.async_send(kernel::Message::StartRequest).await; } _ => return Err(Error::UnrecognizedPacket) } diff --git a/runtime/src/kernel.rs b/runtime/src/kernel.rs index 7006d49..7db9555 100644 --- a/runtime/src/kernel.rs +++ b/runtime/src/kernel.rs @@ -1,3 +1,4 @@ +use core::{ptr, mem}; use log::{debug, error}; use alloc::{vec, vec::Vec, sync::Arc}; @@ -14,6 +15,7 @@ pub enum Message { LoadRequest(Arc>), LoadCompleted, LoadFailed, + StartRequest, } static CHANNEL_0TO1: Mutex>> = Mutex::new(None); @@ -84,6 +86,8 @@ fn resolve(required: &[u8]) -> Option { api!(rtio_input_timestamp = rtio::input_timestamp), api!(rtio_input_data = rtio::input_data), api!(rtio_input_timestamped_data = rtio::input_timestamped_data), + + api!(__artiq_personality = 0), // HACK ]; api.iter() .find(|&&(exported, _)| exported.as_bytes() == required) @@ -108,11 +112,19 @@ pub fn main_core1() { let core1_rx = core1_rx.unwrap(); let mut image = vec![0; 1024*1024]; + let mut current_modinit: Option = None; for message in core1_rx { match *message { Message::LoadRequest(data) => { match dyld::Library::load(&data, &mut image, &resolve) { Ok(library) => { + let __bss_start = library.lookup(b"__bss_start").unwrap(); + let _end = library.lookup(b"_end").unwrap(); + let __modinit__ = library.lookup(b"__modinit__").unwrap(); + unsafe { + ptr::write_bytes(__bss_start as *mut u8, 0, (_end - __bss_start) as usize); + } + current_modinit = Some(__modinit__); core1_tx.send(Message::LoadCompleted) }, Err(error) => { @@ -121,6 +133,15 @@ pub fn main_core1() { } } }, + Message::StartRequest => { + debug!("starting"); + if let Some(__modinit__) = current_modinit { + unsafe { + (mem::transmute::(__modinit__))(); + } + } + debug!("stopping"); + } _ => error!("Core1 received unexpected message: {:?}", message), } }