Compare commits

...

27 Commits

Author SHA1 Message Date
e1d17255c1 remove unnecessary queue 2025-02-21 17:11:06 +08:00
f3f7c7223f executor rewrite with separate input queue 2025-02-21 15:22:17 +08:00
e3e4112e62 add static lifetime requirement to spawn, block_on 2025-02-21 14:01:18 +08:00
7614574152 move target-features to silence warns 2025-02-13 11:26:24 +08:00
b8febc13e6 use resolver 2 2025-02-13 11:26:24 +08:00
703778802e remove unnecessary imports 2025-02-13 11:26:24 +08:00
c13299a0c3 fixup addr_of_mut 2025-02-13 11:26:24 +08:00
6c75138b87 fixup rust bump 2025-02-13 11:26:24 +08:00
097679f49d silence static mut ref warns 2025-02-13 11:26:24 +08:00
8b0dae77c0 replace explicit cast with addr_of/addr_of_mut 2025-02-13 11:26:24 +08:00
417579f90f sync_channel: fix Box::from_raw warn 2025-02-13 11:26:24 +08:00
00358add2f update cargo lockfile 2025-02-13 11:26:24 +08:00
949ddb2c86 bump compiler_builtins to 0.1.108 2025-02-13 11:26:24 +08:00
c98b51cb9f bump llvm to 18 2025-02-13 11:26:24 +08:00
701a76b4b0 bump rustc to 1.79 2025-02-13 11:26:24 +08:00
d84c7eb0bb bump to edition 2021 2025-02-13 11:26:24 +08:00
688915d63a fix mmu on core1 2025-02-13 11:26:24 +08:00
ae3efa8c46 update cargo lockfile 2025-02-13 10:57:25 +08:00
29ffc6a058 fix inline_const 2025-02-13 10:57:25 +08:00
9201ac164f remove stabilized feature flags 2025-02-13 10:57:25 +08:00
d73ccb59a3 remove allow incomplete_feature 2025-02-13 10:57:25 +08:00
61f1be5dd2 fix target-features 2025-02-13 10:57:25 +08:00
ce57ae40de bump llvm 2025-02-13 10:57:25 +08:00
aecce03dc8 bump compiler_builtins 2025-02-12 10:36:08 +08:00
74436691ec bump rustc 2025-02-12 10:36:08 +08:00
0ed235475a enable vfp and NEON in boot_core1 2025-02-11 20:15:05 +08:00
c6f6bd292d libasync: clean up executor 2025-02-11 15:25:49 +08:00
24 changed files with 79 additions and 92 deletions

View File

@ -1,9 +1,11 @@
[target.armv7-none-eabihf]
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "target-feature=a9,armv7-a,neon",
"-C", "target-cpu=cortex-a9",
]
[build]
target = "armv7-none-eabihf.json"
[future-incompat-report]
frequency = "never"

4
Cargo.lock generated
View File

@ -34,9 +34,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "compiler_builtins"
version = "0.1.49"
version = "0.1.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20b1438ef42c655665a8ab2c1c6d605a305f031d38d9be689ddfef41a20f3aa2"
checksum = "d68bc55329711cd719c2687bb147bc06211b0521f97ef398280108ccb23227e9"
[[package]]
name = "core_io"

View File

@ -9,6 +9,7 @@ members = [
"experiments",
"szl",
]
resolver = "2"
[profile.release]
panic = "abort"

View File

@ -4,7 +4,7 @@
"emit-debug-gdb-scripts": false,
"env": "",
"executables": true,
"features": "+v7,+vfp3,-d32,+thumb2,-neon",
"features": "+v7,+vfp3,-d32,+thumb2,+neon,+a9,+armv7-a",
"is-builtin": false,
"linker": "rust-lld",
"linker-flavor": "ld.lld",

View File

@ -3,7 +3,7 @@ name = "experiments"
description = "Developing bare-metal Rust on Zynq"
version = "0.0.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[features]
target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706"]

View File

@ -1,14 +1,13 @@
#![no_std]
#![no_main]
#![allow(incomplete_features)]
#![feature(naked_functions)]
#![feature(asm)]
#![feature(inline_const)]
extern crate alloc;
use alloc::collections::BTreeMap;
use core::arch::asm;
use::core::ptr::addr_of_mut;
use libasync::{
delay,
smoltcp::{Sockets, TcpStream},
@ -73,7 +72,7 @@ interrupt_handler!(IRQ, irq, __irq_stack0_start, __irq_stack1_start, {
if id.0 == 0 {
gic.end_interrupt(id);
asm::exit_irq();
SP.write(&mut __stack1_start as *mut _ as u32);
SP.write(addr_of_mut!(__stack1_start) as u32);
asm::enable_irq();
CORE1_RESTART.store(false, Ordering::Relaxed);
notify_spin_lock();

View File

@ -11,7 +11,7 @@
let
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import rust-overlay) crosspkgs-overlay ]; };
rust = pkgs.rust-bin.nightly."2021-09-01".default.override {
rust = pkgs.rust-bin.nightly."2024-04-06".default.override {
extensions = [ "rust-src" ];
targets = [ ];
};
@ -95,9 +95,7 @@
dontFixup = true;
};
cargo-xbuild = pkgs.cargo-xbuild.overrideAttrs(oa: {
postPatch = "substituteInPlace src/sysroot.rs --replace 2021 2018";
});
cargo-xbuild = pkgs.cargo-xbuild;
build-crate = name: crate: features: rustPlatform.buildRustPackage rec {
name = "${crate}";
@ -113,7 +111,7 @@
};
};
nativeBuildInputs = [ cargo-xbuild pkgs.llvmPackages_13.clang-unwrapped ];
nativeBuildInputs = [ cargo-xbuild pkgs.llvmPackages_18.clang-unwrapped ];
buildPhase = ''
export XARGO_RUST_SRC="${rust}/lib/rustlib/src/rust/library"
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
@ -169,7 +167,7 @@
pkgs.openocd pkgs.gdb
pkgs.openssh pkgs.rsync
pkgs.llvmPackages_13.clang-unwrapped
pkgs.llvmPackages_18.clang-unwrapped
(pkgs.python3.withPackages(ps: [ ps.pyftdi ]))
];
};

View File

@ -3,7 +3,7 @@ name = "libasync"
description = "low-level async support"
version = "0.0.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[dependencies]
#futures = { version = "0.3", default-features = false }

View File

@ -1,14 +1,14 @@
use alloc::{boxed::Box, vec::Vec, collections::VecDeque};
use core::{
cell::{RefCell, UnsafeCell},
cell::{UnsafeCell, RefCell},
future::Future,
mem::MaybeUninit,
pin::Pin,
sync::atomic::{AtomicBool, Ordering},
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
use alloc::{boxed::Box, vec::Vec};
//use futures::future::FutureExt;
use pin_utils::pin_mut;
use libcortex_a9::mutex::Mutex;
// NOTE `*const ()` is &AtomicBool
static VTABLE: RawWakerVTable = {
@ -44,15 +44,19 @@ pub struct Executor {
/// Tasks reside on the heap, so that we just queue pointers. They
/// must also be pinned in memory because our RawWaker is a pointer
/// to their `ready` field.
tasks: RefCell<Vec<Pin<Box<Task>>>>,
tasks: RefCell<VecDeque<Pin<Box<Task>>>>,
// we should not be able to add tasks while the executor is draining
input_queue: RefCell<VecDeque<Pin<Box<Task>>>>,
}
impl Executor {
/// Creates a new instance of the executor
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
in_block_on: RefCell::new(false),
tasks: RefCell::new(Vec::new()),
tasks: RefCell::new(VecDeque::new()),
input_queue: RefCell::new(VecDeque::new()),
}
}
@ -61,38 +65,31 @@ impl Executor {
// below has to become more complex. It's also likely that the
// application will only call `block_on` once on an infinite task
// (`Future<Output = !>`)
{
let mut in_block_on = self.in_block_on.borrow_mut();
if *in_block_on {
panic!("nested `block_on`");
}
*in_block_on = true;
if *self.in_block_on.borrow() {
panic!("in block on");
}
pin_mut!(f);
let ready = AtomicBool::new(true);
let waker = wrap_waker(&ready);
let mut backup = Vec::new();
let val = loop {
// advance the main task
if ready.load(Ordering::Relaxed) {
ready.store(false, Ordering::Relaxed);
// println!("run block_on");
let mut cx = Context::from_waker(&waker);
if let Poll::Ready(val) = f.as_mut().poll(&mut cx) {
break val;
}
// println!("ran block_on");
}
// advance all tasks
core::mem::swap(&mut *self.tasks.borrow_mut(), &mut backup);
for mut task in backup.drain(..) {
let mut tasks = self.tasks.borrow_mut();
for _ in 0..tasks.len() {
// NOTE we don't need a CAS operation here because `wake` invocations that come from
// interrupt handlers (the only source of 'race conditions' (!= data races)) are
// "oneshot": they'll issue a `wake` and then disable themselves to not run again
// until the woken task has made more work
let mut task = tasks.pop_front().unwrap();
if task.ready.load(Ordering::Relaxed) {
// we are about to service the task so switch the `ready` flag to `false`
task.ready.store(false, Ordering::Relaxed);
@ -101,57 +98,55 @@ impl Executor {
let mut cx = Context::from_waker(&waker);
let ready = task.f.as_mut().poll(&mut cx).is_ready();
if ready {
// Task is finished, do not requeue
continue;
}
}
// Requeue
self.tasks.borrow_mut().push(task);
tasks.push_back(task);
}
for task in self.input_queue.borrow_mut().drain(..) {
tasks.push_back(task);
}
// // try to sleep; this will be a no-op if any of the previous tasks generated a SEV or an
// // interrupt ran (regardless of whether it generated a wake-up or not)
// asm::wfe();
};
self.in_block_on.replace(false);
val
}
pub fn spawn(&self, f: impl Future + 'static) {
pub fn spawn(&self, f: impl Future<Output = ()> + 'static) {
let task = Box::pin(Task::new(f));
self.tasks.borrow_mut().push(task);
self.input_queue.borrow_mut().push_back(task);
}
}
unsafe impl Sync for Executor {}
pub struct Task {
ready: AtomicBool,
f: Pin<Box<dyn Future<Output = ()>>>,
}
impl Task {
fn new(f: impl Future + 'static) -> Self {
fn new(f: impl Future<Output = ()> + 'static) -> Self {
Task {
ready: AtomicBool::new(true),
f: Box::pin(async { f.await; }),
f: Box::pin(f),
}
}
}
static INIT: AtomicBool = AtomicBool::new(false);
static EXECUTOR: Executor = Executor::new();
/// Returns a handle to the executor singleton
///
/// This lazily initializes the executor and allocator when first called
pub(crate) fn current() -> &'static Executor {
static INIT: AtomicBool = AtomicBool::new(false);
static mut EXECUTOR: UnsafeCell<MaybeUninit<Executor>> = UnsafeCell::new(MaybeUninit::uninit());
if INIT.load(Ordering::Relaxed) {
unsafe { &*(EXECUTOR.get() as *const Executor) }
} else {
unsafe {
let executorp = EXECUTOR.get() as *mut Executor;
executorp.write(Executor::new());
INIT.store(true, Ordering::Relaxed);
&*executorp
}
}
&EXECUTOR
// if INIT.load(Ordering::Relaxed) {
// unsafe { EXECUTOR.get_mut().assume_init_mut() }
// } else {
// unsafe {
// let executor = EXECUTOR.get_mut().write(Executor::new());
// INIT.store(true, Ordering::Relaxed);
// executor
// }
// }
}

View File

@ -17,7 +17,7 @@ pub fn block_on<T>(f: impl Future<Output = T>) -> T {
/// Spawns a task onto the executor
///
/// The spawned task will not make any progress until `block_on` is called.
pub fn spawn(f: impl Future + 'static) {
pub fn spawn(f: impl Future<Output = ()> + 'static) {
executor::current().spawn(f)
}

View File

@ -3,7 +3,7 @@ name = "libboard_zynq"
description = "Drivers for peripherals in the Zynq PS"
version = "0.0.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[features]
target_zc706 = []

View File

@ -9,7 +9,6 @@ use super::time::Milliseconds;
use embedded_hal::timer::CountDown;
use libregister::{RegisterR, RegisterRW, RegisterW};
use log::{trace, debug};
use nb;
/// Basic SDIO Struct with common low-level functions.
pub struct Sdio {

View File

@ -2,7 +2,7 @@
name = "libconfig"
version = "0.1.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[dependencies]
libboard_zynq = { path = "../libboard_zynq" }

View File

@ -1,5 +1,4 @@
use core_io::{BufRead, Error, ErrorKind, Read, Result as IoResult, Seek, SeekFrom, Write};
use fatfs;
use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError};
use log::debug;
use alloc::vec::Vec;

View File

@ -2,7 +2,7 @@
name = "libcortex_a9"
version = "0.0.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[features]
power_saving = []

View File

@ -1,10 +1,6 @@
#![no_std]
#![feature(never_type)]
#![feature(global_asm)]
#![feature(asm)]
#![allow(incomplete_features)]
#![feature(inline_const)]
#![feature(const_fn_trait_bound)]
extern crate alloc;

View File

@ -1,6 +1,7 @@
use bit_field::BitField;
use super::{regs::*, asm::*, cache::*};
use libregister::RegisterW;
use core::ptr::{addr_of_mut};
#[derive(Copy, Clone)]
#[repr(u8)]
@ -136,7 +137,7 @@ pub struct L1Table {
impl L1Table {
pub fn get() -> &'static mut Self {
unsafe {
&mut L1_TABLE
&mut *addr_of_mut!(L1_TABLE)
}
}

View File

@ -37,7 +37,7 @@ impl<'a, T> Sender<'a, T> where T: Clone {
notify_spin_lock();
if !prev.is_null() {
unsafe {
Box::from_raw(prev);
let _ = Box::from_raw(prev);
}
}
Ok(())
@ -91,7 +91,7 @@ impl<'a, T> Sender<'a, T> where T: Clone {
for v in self.list.iter() {
let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed);
if !original.is_null() {
Box::from_raw(original);
let _ = Box::from_raw(original);
}
}
}
@ -177,10 +177,7 @@ macro_rules! sync_channel {
{
use core::sync::atomic::{AtomicUsize, AtomicPtr};
use $crate::sync_channel::{Sender, Receiver};
const fn new_atomic() -> AtomicPtr<$t> {
AtomicPtr::new(core::ptr::null_mut())
}
static LIST: [AtomicPtr<$t>; $cap + 1] = [const { new_atomic() }; $cap + 1];
static LIST: [AtomicPtr<$t>; $cap + 1] = [const { AtomicPtr::new(core::ptr::null_mut()) }; $cap + 1];
static WRITE: AtomicUsize = AtomicUsize::new(0);
static READ: AtomicUsize = AtomicUsize::new(0);
(Sender::new(&LIST, &WRITE, &READ), Receiver::new(&LIST, &WRITE, &READ))

View File

@ -2,7 +2,7 @@
name = "libregister"
version = "0.0.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[dependencies]
vcell = "0.1"

View File

@ -3,7 +3,7 @@ name = "libsupport_zynq"
description = "Software support for running in the Zynq PS"
version = "0.0.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[features]
target_zc706 = ["libboard_zynq/target_zc706"]
@ -20,7 +20,7 @@ default = ["panic_handler", "dummy_irq_handler", "dummy_fiq_handler"]
[dependencies]
r0 = "1"
compiler_builtins = "=0.1.49"
compiler_builtins = "=0.1.108"
linked_list_allocator = { version = "0.8", default-features = false, features = ["const_mut_refs"] }
libregister = { path = "../libregister" }
libcortex_a9 = { path = "../libcortex_a9" }

View File

@ -1,5 +1,5 @@
use r0::zero_bss;
use core::ptr::write_volatile;
use core::ptr::{addr_of, addr_of_mut, write_volatile};
use core::arch::asm;
use libregister::{
VolatileCell,
@ -43,7 +43,7 @@ unsafe extern "C" fn boot_core0() -> ! {
let mpcore = mpcore::RegisterBlock::mpcore();
mpcore.scu_invalidate.invalidate_all_cores();
zero_bss(&mut __bss_start, &mut __bss_end);
zero_bss(addr_of_mut!(__bss_start), addr_of_mut!(__bss_end));
let mmu_table = mmu::L1Table::get()
.setup_flat_layout();
@ -66,10 +66,12 @@ unsafe extern "C" fn boot_core0() -> ! {
unsafe extern "C" fn boot_core1() -> ! {
l1_cache_init();
enable_fpu();
let mpcore = mpcore::RegisterBlock::mpcore();
mpcore.scu_invalidate.invalidate_core1();
let mmu_table = mmu::L1Table::get();
let mmu_table = mmu::L1Table::get()
.setup_flat_layout();
mmu::with_mmu(mmu_table, || {
ACTLR.enable_smp();
ACTLR.enable_prefetch();
@ -132,7 +134,7 @@ impl Core1 {
CORE1_ENABLED.set(true);
}
// Flush cache-line
cache::dcc(unsafe { &CORE1_ENABLED });
cache::dcc(unsafe { &*addr_of!(CORE1_ENABLED) });
if sdram {
cache::dccmvac(0);
asm::dsb();
@ -153,7 +155,7 @@ impl Core1 {
pub fn disable(&self) {
unsafe {
CORE1_ENABLED.set(false);
cache::dccmvac(&CORE1_ENABLED as *const _ as usize);
cache::dccmvac(addr_of!(CORE1_ENABLED) as usize);
asm::dsb();
}
self.restart();

View File

@ -3,8 +3,6 @@
#![feature(alloc_error_handler)]
#![feature(panic_info_message)]
#![feature(naked_functions)]
#![feature(global_asm)]
#![feature(asm)]
pub extern crate alloc;
pub extern crate compiler_builtins;

View File

@ -3,7 +3,7 @@ name = "szl"
description = "Simple Zynq Loader"
version = "0.1.0"
authors = ["M-Labs"]
edition = "2018"
edition = "2021"
[features]
target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706", "libconfig/target_zc706"]

View File

@ -7,7 +7,7 @@ extern crate log;
mod netboot;
use alloc::rc::Rc;
use core::mem;
use core::{mem, ptr::{addr_of, addr_of_mut}};
use core_io::{Read, Seek};
use libboard_zynq::{
self as zynq,
@ -116,18 +116,18 @@ pub fn main_core0() {
unsafe {
let max_len =
&__runtime_end as *const usize as usize - &__runtime_start as *const usize as usize;
addr_of!(__runtime_end) as usize - addr_of!(__runtime_start) as usize;
match slcr::RegisterBlock::unlocked(|slcr| slcr.boot_mode.read().boot_mode_pins()) {
slcr::BootModePins::Jtag => netboot::netboot(
&mut bootgen_file,
config,
&mut __runtime_start as *mut usize as *mut u8,
addr_of_mut!(__runtime_start).cast(),
max_len,
),
slcr::BootModePins::SdCard => {
if boot_sd(
&mut bootgen_file,
&mut __runtime_start as *mut usize as *mut u8,
addr_of_mut!(__runtime_start).cast(),
max_len,
)
.is_err()
@ -137,7 +137,7 @@ pub fn main_core0() {
netboot::netboot(
&mut bootgen_file,
config,
&mut __runtime_start as *mut usize as *mut u8,
addr_of_mut!(__runtime_start).cast(),
max_len,
)
}
@ -148,7 +148,7 @@ pub fn main_core0() {
netboot::netboot(
&mut bootgen_file,
config,
&mut __runtime_start as *mut usize as *mut u8,
addr_of_mut!(__runtime_start).cast(),
max_len,
)
}