From 46326716fd77e58678885773602fb583acfcf489 Mon Sep 17 00:00:00 2001 From: occheung Date: Fri, 8 Oct 2021 14:38:30 +0800 Subject: [PATCH] runtime: bump libfringe, impl ecall abi See libfringe PR: https://git.m-labs.hk/M-Labs/libfringe/pulls/1 --- artiq/firmware/Cargo.lock | 4 ++-- artiq/firmware/runtime/Cargo.toml | 2 +- artiq/firmware/runtime/main.rs | 12 ++++++++++++ artiq/firmware/runtime/sched.rs | 3 ++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/artiq/firmware/Cargo.lock b/artiq/firmware/Cargo.lock index 194952672..dd890c625 100644 --- a/artiq/firmware/Cargo.lock +++ b/artiq/firmware/Cargo.lock @@ -163,9 +163,9 @@ dependencies = [ [[package]] name = "fringe" version = "1.2.1" -source = "git+https://git.m-labs.hk/M-Labs/libfringe.git?rev=9748bb#9748bb8af86c131d45be1238ea4d5f965a974630" +source = "git+https://git.m-labs.hk/M-Labs/libfringe.git?rev=3ecbe5#3ecbe53f7644b18ee46ebd5b2ca12c9cbceec43a" dependencies = [ - "libc 0.2.101", + "libc 0.2.103", ] [[package]] diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index a29acbb86..ee987ad2d 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -32,6 +32,6 @@ riscv = { version = "0.6.0", features = ["inline-asm"] } [dependencies.fringe] git = "https://git.m-labs.hk/M-Labs/libfringe.git" -rev = "9748bb" +rev = "3ecbe5" default-features = false features = ["alloc"] diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index 45e73d78c..04af01be0 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -290,6 +290,18 @@ pub extern fn exception(regs: *const TrapFrame) { mcause::Trap::Interrupt(source) => { info!("Called interrupt with {:?}", source); }, + + mcause::Trap::Exception(mcause::Exception::UserEnvCall) => { + unsafe { + if (*regs).a7 == 0 { + pmp::pop_pmp_region() + } else { + pmp::push_pmp_region((*regs).a7) + } + } + mepc::write(pc + 4); + }, + mcause::Trap::Exception(e) => { println!("Trap frame: {:x?}", unsafe { *regs }); diff --git a/artiq/firmware/runtime/sched.rs b/artiq/firmware/runtime/sched.rs index 7b182a3e4..d6a347269 100644 --- a/artiq/firmware/runtime/sched.rs +++ b/artiq/firmware/runtime/sched.rs @@ -61,7 +61,8 @@ impl Thread { let spawned = io.spawned.clone(); let sockets = io.sockets.clone(); - let stack = OwnedStack::new(stack_size); + // Add a 4k stack guard to the stack of any new threads + let stack = OwnedStack::new(stack_size + 4096); ThreadHandle::new(Thread { generator: Generator::unsafe_new(stack, |yielder, _| { f(Io {