Fix formatting.
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
diff --git a/boards/nordic/nrf52840_dongle/src/main.rs b/boards/nordic/nrf52840_dongle/src/main.rs
|
diff --git a/boards/nordic/nrf52840_dongle/src/main.rs b/boards/nordic/nrf52840_dongle/src/main.rs
|
||||||
index fc53f59..d72d204 100644
|
index fc53f59c8..d72d20482 100644
|
||||||
--- a/boards/nordic/nrf52840_dongle/src/main.rs
|
--- a/boards/nordic/nrf52840_dongle/src/main.rs
|
||||||
+++ b/boards/nordic/nrf52840_dongle/src/main.rs
|
+++ b/boards/nordic/nrf52840_dongle/src/main.rs
|
||||||
@@ -55,6 +55,11 @@ const NUM_PROCS: usize = 8;
|
@@ -55,6 +55,11 @@ const NUM_PROCS: usize = 8;
|
||||||
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
|
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
|
||||||
[None; NUM_PROCS];
|
[None; NUM_PROCS];
|
||||||
|
|
||||||
+static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
|
+static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
|
||||||
+ address: 0xC0000,
|
+ address: 0xC0000,
|
||||||
+ size: 0x40000,
|
+ size: 0x40000,
|
||||||
@@ -13,16 +13,16 @@ index fc53f59..d72d204 100644
|
|||||||
+
|
+
|
||||||
// Static reference to chip for panic dumps
|
// Static reference to chip for panic dumps
|
||||||
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;
|
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;
|
||||||
|
|
||||||
@@ -90,6 +95,7 @@ pub struct Platform {
|
@@ -90,6 +95,7 @@ pub struct Platform {
|
||||||
'static,
|
'static,
|
||||||
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
|
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
|
||||||
>,
|
>,
|
||||||
+ nvmc: &'static nrf52840::nvmc::SyscallDriver,
|
+ nvmc: &'static nrf52840::nvmc::SyscallDriver,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl kernel::Platform for Platform {
|
impl kernel::Platform for Platform {
|
||||||
@@ -108,19 +114,42 @@ impl kernel::Platform for Platform {
|
@@ -108,10 +114,30 @@ impl kernel::Platform for Platform {
|
||||||
capsules::ieee802154::DRIVER_NUM => f(Some(self.ieee802154_radio)),
|
capsules::ieee802154::DRIVER_NUM => f(Some(self.ieee802154_radio)),
|
||||||
capsules::temperature::DRIVER_NUM => f(Some(self.temp)),
|
capsules::temperature::DRIVER_NUM => f(Some(self.temp)),
|
||||||
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
|
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
|
||||||
@@ -51,25 +51,24 @@ index fc53f59..d72d204 100644
|
|||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Entry point in the vector table called on hard reset.
|
/// Entry point in the vector table called on hard reset.
|
||||||
#[no_mangle]
|
@@ -120,7 +146,10 @@ pub unsafe fn reset_handler() {
|
||||||
pub unsafe fn reset_handler() {
|
|
||||||
// Loads relocations and clears BSS
|
// Loads relocations and clears BSS
|
||||||
nrf52840::init();
|
nrf52840::init();
|
||||||
|
|
||||||
- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
|
- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
|
||||||
+ let board_kernel = static_init!(
|
+ let board_kernel = static_init!(
|
||||||
+ kernel::Kernel,
|
+ kernel::Kernel,
|
||||||
+ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
|
+ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
|
||||||
+ );
|
+ );
|
||||||
|
|
||||||
// GPIOs
|
// GPIOs
|
||||||
let gpio = components::gpio::GpioComponent::new(
|
let gpio = components::gpio::GpioComponent::new(
|
||||||
@@ -286,6 +315,14 @@ pub unsafe fn reset_handler() {
|
@@ -286,6 +315,14 @@ pub unsafe fn reset_handler() {
|
||||||
nrf52840::acomp::Comparator
|
nrf52840::acomp::Comparator
|
||||||
));
|
));
|
||||||
|
|
||||||
+ let nvmc = static_init!(
|
+ let nvmc = static_init!(
|
||||||
+ nrf52840::nvmc::SyscallDriver,
|
+ nrf52840::nvmc::SyscallDriver,
|
||||||
+ nrf52840::nvmc::SyscallDriver::new(
|
+ nrf52840::nvmc::SyscallDriver::new(
|
||||||
@@ -79,7 +78,7 @@ index fc53f59..d72d204 100644
|
|||||||
+ );
|
+ );
|
||||||
+
|
+
|
||||||
nrf52_components::NrfClockComponent::new().finalize(());
|
nrf52_components::NrfClockComponent::new().finalize(());
|
||||||
|
|
||||||
let platform = Platform {
|
let platform = Platform {
|
||||||
@@ -300,6 +337,7 @@ pub unsafe fn reset_handler() {
|
@@ -300,6 +337,7 @@ pub unsafe fn reset_handler() {
|
||||||
temp,
|
temp,
|
||||||
@@ -88,22 +87,22 @@ index fc53f59..d72d204 100644
|
|||||||
+ nvmc,
|
+ nvmc,
|
||||||
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
|
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
|
||||||
};
|
};
|
||||||
|
|
||||||
diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs
|
diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs
|
||||||
index 169f3d3..2ebb384 100644
|
index 169f3d393..2ebb384d8 100644
|
||||||
--- a/boards/nordic/nrf52840dk/src/main.rs
|
--- a/boards/nordic/nrf52840dk/src/main.rs
|
||||||
+++ b/boards/nordic/nrf52840dk/src/main.rs
|
+++ b/boards/nordic/nrf52840dk/src/main.rs
|
||||||
@@ -123,6 +123,11 @@ const NUM_PROCS: usize = 8;
|
@@ -123,6 +123,11 @@ const NUM_PROCS: usize = 8;
|
||||||
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
|
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
|
||||||
[None; NUM_PROCS];
|
[None; NUM_PROCS];
|
||||||
|
|
||||||
+static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
|
+static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
|
||||||
+ address: 0xC0000,
|
+ address: 0xC0000,
|
||||||
+ size: 0x40000,
|
+ size: 0x40000,
|
||||||
+}];
|
+}];
|
||||||
+
|
+
|
||||||
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;
|
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;
|
||||||
|
|
||||||
/// Dummy buffer that causes the linker to reserve enough space for the stack.
|
/// Dummy buffer that causes the linker to reserve enough space for the stack.
|
||||||
@@ -158,6 +163,7 @@ pub struct Platform {
|
@@ -158,6 +163,7 @@ pub struct Platform {
|
||||||
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
|
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
|
||||||
@@ -111,7 +110,7 @@ index 169f3d3..2ebb384 100644
|
|||||||
nonvolatile_storage: &'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>,
|
nonvolatile_storage: &'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>,
|
||||||
+ nvmc: &'static nrf52840::nvmc::SyscallDriver,
|
+ nvmc: &'static nrf52840::nvmc::SyscallDriver,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl kernel::Platform for Platform {
|
impl kernel::Platform for Platform {
|
||||||
@@ -177,10 +183,30 @@ impl kernel::Platform for Platform {
|
@@ -177,10 +183,30 @@ impl kernel::Platform for Platform {
|
||||||
capsules::temperature::DRIVER_NUM => f(Some(self.temp)),
|
capsules::temperature::DRIVER_NUM => f(Some(self.temp)),
|
||||||
@@ -142,24 +141,24 @@ index 169f3d3..2ebb384 100644
|
|||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Entry point in the vector table called on hard reset.
|
/// Entry point in the vector table called on hard reset.
|
||||||
@@ -204,7 +230,10 @@ pub unsafe fn reset_handler() {
|
@@ -204,7 +230,10 @@ pub unsafe fn reset_handler() {
|
||||||
UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD))
|
UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD))
|
||||||
};
|
};
|
||||||
|
|
||||||
- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
|
- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
|
||||||
+ let board_kernel = static_init!(
|
+ let board_kernel = static_init!(
|
||||||
+ kernel::Kernel,
|
+ kernel::Kernel,
|
||||||
+ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
|
+ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
|
||||||
+ );
|
+ );
|
||||||
|
|
||||||
let gpio = components::gpio::GpioComponent::new(
|
let gpio = components::gpio::GpioComponent::new(
|
||||||
board_kernel,
|
board_kernel,
|
||||||
@@ -411,6 +440,14 @@ pub unsafe fn reset_handler() {
|
@@ -411,6 +440,14 @@ pub unsafe fn reset_handler() {
|
||||||
nrf52840::acomp::Comparator
|
nrf52840::acomp::Comparator
|
||||||
));
|
));
|
||||||
|
|
||||||
+ let nvmc = static_init!(
|
+ let nvmc = static_init!(
|
||||||
+ nrf52840::nvmc::SyscallDriver,
|
+ nrf52840::nvmc::SyscallDriver,
|
||||||
+ nrf52840::nvmc::SyscallDriver::new(
|
+ nrf52840::nvmc::SyscallDriver::new(
|
||||||
@@ -169,7 +168,7 @@ index 169f3d3..2ebb384 100644
|
|||||||
+ );
|
+ );
|
||||||
+
|
+
|
||||||
nrf52_components::NrfClockComponent::new().finalize(());
|
nrf52_components::NrfClockComponent::new().finalize(());
|
||||||
|
|
||||||
let platform = Platform {
|
let platform = Platform {
|
||||||
@@ -426,6 +463,7 @@ pub unsafe fn reset_handler() {
|
@@ -426,6 +463,7 @@ pub unsafe fn reset_handler() {
|
||||||
alarm,
|
alarm,
|
||||||
@@ -178,33 +177,32 @@ index 169f3d3..2ebb384 100644
|
|||||||
+ nvmc,
|
+ nvmc,
|
||||||
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
|
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
|
||||||
};
|
};
|
||||||
|
|
||||||
diff --git a/chips/nrf52/src/nvmc.rs b/chips/nrf52/src/nvmc.rs
|
diff --git a/chips/nrf52/src/nvmc.rs b/chips/nrf52/src/nvmc.rs
|
||||||
index b70162c..9dcb82b 100644
|
index b70162cae..9dcb82b07 100644
|
||||||
--- a/chips/nrf52/src/nvmc.rs
|
--- a/chips/nrf52/src/nvmc.rs
|
||||||
+++ b/chips/nrf52/src/nvmc.rs
|
+++ b/chips/nrf52/src/nvmc.rs
|
||||||
@@ -3,15 +3,16 @@
|
@@ -3,6 +3,7 @@
|
||||||
//! Used in order read and write to internal flash.
|
//! Used in order read and write to internal flash.
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
+use core::convert::TryFrom;
|
+use core::convert::TryFrom;
|
||||||
use core::ops::{Index, IndexMut};
|
use core::ops::{Index, IndexMut};
|
||||||
use kernel::common::cells::OptionalCell;
|
use kernel::common::cells::OptionalCell;
|
||||||
use kernel::common::cells::TakeCell;
|
use kernel::common::cells::TakeCell;
|
||||||
use kernel::common::cells::VolatileCell;
|
@@ -11,7 +12,7 @@ use kernel::common::deferred_call::DeferredCall;
|
||||||
use kernel::common::deferred_call::DeferredCall;
|
|
||||||
use kernel::common::registers::{register_bitfields, ReadOnly, ReadWrite};
|
use kernel::common::registers::{register_bitfields, ReadOnly, ReadWrite};
|
||||||
use kernel::common::StaticRef;
|
use kernel::common::StaticRef;
|
||||||
use kernel::hil;
|
use kernel::hil;
|
||||||
-use kernel::ReturnCode;
|
-use kernel::ReturnCode;
|
||||||
+use kernel::{AppId, AppSlice, Callback, Driver, Grant, ReturnCode, Shared};
|
+use kernel::{AppId, AppSlice, Callback, Driver, Grant, ReturnCode, Shared};
|
||||||
|
|
||||||
use crate::deferred_call_tasks::DeferredCallTask;
|
use crate::deferred_call_tasks::DeferredCallTask;
|
||||||
|
|
||||||
@@ -141,7 +142,13 @@ register_bitfields! [u32,
|
@@ -141,7 +142,13 @@ register_bitfields! [u32,
|
||||||
static DEFERRED_CALL: DeferredCall<DeferredCallTask> =
|
static DEFERRED_CALL: DeferredCall<DeferredCallTask> =
|
||||||
unsafe { DeferredCall::new(DeferredCallTask::Nvmc) };
|
unsafe { DeferredCall::new(DeferredCallTask::Nvmc) };
|
||||||
|
|
||||||
+type WORD = u32;
|
+type WORD = u32;
|
||||||
+const WORD_SIZE: usize = core::mem::size_of::<WORD>();
|
+const WORD_SIZE: usize = core::mem::size_of::<WORD>();
|
||||||
const PAGE_SIZE: usize = 4096;
|
const PAGE_SIZE: usize = 4096;
|
||||||
@@ -212,13 +210,13 @@ index b70162c..9dcb82b 100644
|
|||||||
+const MAX_PAGE_ERASES: usize = 10000;
|
+const MAX_PAGE_ERASES: usize = 10000;
|
||||||
+const WORD_MASK: usize = WORD_SIZE - 1;
|
+const WORD_MASK: usize = WORD_SIZE - 1;
|
||||||
+const PAGE_MASK: usize = PAGE_SIZE - 1;
|
+const PAGE_MASK: usize = PAGE_SIZE - 1;
|
||||||
|
|
||||||
/// This is a wrapper around a u8 array that is sized to a single page for the
|
/// This is a wrapper around a u8 array that is sized to a single page for the
|
||||||
/// nrf. Users of this module must pass an object of this type to use the
|
/// nrf. Users of this module must pass an object of this type to use the
|
||||||
@@ -219,6 +226,11 @@ impl Nvmc {
|
@@ -219,6 +226,11 @@ impl Nvmc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ pub fn configure_readonly(&self) {
|
+ pub fn configure_readonly(&self) {
|
||||||
+ let regs = &*self.registers;
|
+ let regs = &*self.registers;
|
||||||
+ regs.config.write(Configuration::WEN::Ren);
|
+ regs.config.write(Configuration::WEN::Ren);
|
||||||
@@ -235,11 +233,11 @@ index b70162c..9dcb82b 100644
|
|||||||
+ regs.eraseuicr.write(EraseUicr::ERASEUICR::ERASE);
|
+ regs.eraseuicr.write(EraseUicr::ERASEUICR::ERASE);
|
||||||
while !self.is_ready() {}
|
while !self.is_ready() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +338,7 @@ impl Nvmc {
|
@@ -326,7 +338,7 @@ impl Nvmc {
|
||||||
// Put the NVMC in write mode.
|
// Put the NVMC in write mode.
|
||||||
regs.config.write(Configuration::WEN::Wen);
|
regs.config.write(Configuration::WEN::Wen);
|
||||||
|
|
||||||
- for i in (0..data.len()).step_by(4) {
|
- for i in (0..data.len()).step_by(4) {
|
||||||
+ for i in (0..data.len()).step_by(WORD_SIZE) {
|
+ for i in (0..data.len()).step_by(WORD_SIZE) {
|
||||||
let word: u32 = (data[i + 0] as u32) << 0
|
let word: u32 = (data[i + 0] as u32) << 0
|
||||||
@@ -427,7 +425,7 @@ index b70162c..9dcb82b 100644
|
|||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
|
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
|
||||||
index dbe5035..428d90c 100644
|
index dbe503515..428d90c29 100644
|
||||||
--- a/kernel/src/lib.rs
|
--- a/kernel/src/lib.rs
|
||||||
+++ b/kernel/src/lib.rs
|
+++ b/kernel/src/lib.rs
|
||||||
@@ -123,7 +123,7 @@ pub use crate::sched::cooperative::{CoopProcessNode, CooperativeSched};
|
@@ -123,7 +123,7 @@ pub use crate::sched::cooperative::{CoopProcessNode, CooperativeSched};
|
||||||
@@ -436,17 +434,17 @@ index dbe5035..428d90c 100644
|
|||||||
pub use crate::sched::round_robin::{RoundRobinProcessNode, RoundRobinSched};
|
pub use crate::sched::round_robin::{RoundRobinProcessNode, RoundRobinSched};
|
||||||
-pub use crate::sched::{Kernel, Scheduler};
|
-pub use crate::sched::{Kernel, Scheduler};
|
||||||
+pub use crate::sched::{Kernel, Scheduler, StorageLocation};
|
+pub use crate::sched::{Kernel, Scheduler, StorageLocation};
|
||||||
|
|
||||||
// Export only select items from the process module. To remove the name conflict
|
// Export only select items from the process module. To remove the name conflict
|
||||||
// this cannot be called `process`, so we use a shortened version. These
|
// this cannot be called `process`, so we use a shortened version. These
|
||||||
diff --git a/kernel/src/memop.rs b/kernel/src/memop.rs
|
diff --git a/kernel/src/memop.rs b/kernel/src/memop.rs
|
||||||
index 348c746..5465c95 100644
|
index 348c746a5..5465c95f4 100644
|
||||||
--- a/kernel/src/memop.rs
|
--- a/kernel/src/memop.rs
|
||||||
+++ b/kernel/src/memop.rs
|
+++ b/kernel/src/memop.rs
|
||||||
@@ -108,6 +108,25 @@ pub(crate) fn memop(process: &dyn ProcessType, op_type: usize, r1: usize) -> Ret
|
@@ -108,6 +108,25 @@ pub(crate) fn memop(process: &dyn ProcessType, op_type: usize, r1: usize) -> Ret
|
||||||
ReturnCode::SUCCESS
|
ReturnCode::SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
+ // Op Type 12: Number of storage locations.
|
+ // Op Type 12: Number of storage locations.
|
||||||
+ 12 => ReturnCode::SuccessWithValue { value: process.number_storage_locations() },
|
+ 12 => ReturnCode::SuccessWithValue { value: process.number_storage_locations() },
|
||||||
+
|
+
|
||||||
@@ -470,13 +468,13 @@ index 348c746..5465c95 100644
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff --git a/kernel/src/process.rs b/kernel/src/process.rs
|
diff --git a/kernel/src/process.rs b/kernel/src/process.rs
|
||||||
index 4dfde3b..0ceff3e 100644
|
index 4dfde3b4f..8380af673 100644
|
||||||
--- a/kernel/src/process.rs
|
--- a/kernel/src/process.rs
|
||||||
+++ b/kernel/src/process.rs
|
+++ b/kernel/src/process.rs
|
||||||
@@ -360,6 +360,15 @@ pub trait ProcessType {
|
@@ -360,6 +360,15 @@ pub trait ProcessType {
|
||||||
/// writeable flash region.
|
/// writeable flash region.
|
||||||
fn get_writeable_flash_region(&self, region_index: usize) -> (u32, u32);
|
fn get_writeable_flash_region(&self, region_index: usize) -> (u32, u32);
|
||||||
|
|
||||||
+ /// How many storage locations are defined for this process.
|
+ /// How many storage locations are defined for this process.
|
||||||
+ fn number_storage_locations(&self) -> usize;
|
+ fn number_storage_locations(&self) -> usize;
|
||||||
+
|
+
|
||||||
@@ -489,10 +487,10 @@ index 4dfde3b..0ceff3e 100644
|
|||||||
/// Debug function to update the kernel on where the stack starts for this
|
/// Debug function to update the kernel on where the stack starts for this
|
||||||
/// process. Processes are not required to call this through the memop
|
/// process. Processes are not required to call this through the memop
|
||||||
/// system call, but it aids in debugging the process.
|
/// system call, but it aids in debugging the process.
|
||||||
@@ -1015,6 +1024,32 @@ impl<C: Chip> ProcessType for Process<'_, C> {
|
@@ -1015,6 +1024,35 @@ impl<C: Chip> ProcessType for Process<'_, C> {
|
||||||
self.header.get_writeable_flash_region(region_index)
|
self.header.get_writeable_flash_region(region_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
+ fn number_storage_locations(&self) -> usize {
|
+ fn number_storage_locations(&self) -> usize {
|
||||||
+ self.kernel.storage_locations().len()
|
+ self.kernel.storage_locations().len()
|
||||||
+ }
|
+ }
|
||||||
@@ -502,30 +500,33 @@ index 4dfde3b..0ceff3e 100644
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ fn fits_in_storage_location(&self, ptr: usize, len: usize) -> bool {
|
+ fn fits_in_storage_location(&self, ptr: usize, len: usize) -> bool {
|
||||||
+ self.kernel.storage_locations().iter().any(|storage_location| {
|
+ self.kernel
|
||||||
+ let storage_ptr = storage_location.address;
|
+ .storage_locations()
|
||||||
+ let storage_len = storage_location.size;
|
+ .iter()
|
||||||
+ // We want to check the 2 following inequalities:
|
+ .any(|storage_location| {
|
||||||
+ // (1) `storage_ptr <= ptr`
|
+ let storage_ptr = storage_location.address;
|
||||||
+ // (2) `ptr + len <= storage_ptr + storage_len`
|
+ let storage_len = storage_location.size;
|
||||||
+ // However, the second one may overflow written as is. We introduce a third
|
+ // We want to check the 2 following inequalities:
|
||||||
+ // inequality to solve this issue:
|
+ // (1) `storage_ptr <= ptr`
|
||||||
+ // (3) `len <= storage_len`
|
+ // (2) `ptr + len <= storage_ptr + storage_len`
|
||||||
+ // Using this third inequality, we can rewrite the second one as:
|
+ // However, the second one may overflow written as is. We introduce a third
|
||||||
+ // (4) `ptr - storage_ptr <= storage_len - len`
|
+ // inequality to solve this issue:
|
||||||
+ // This fourth inequality is equivalent to the second one but doesn't overflow when
|
+ // (3) `len <= storage_len`
|
||||||
+ // the first and third inequalities hold.
|
+ // Using this third inequality, we can rewrite the second one as:
|
||||||
+ storage_ptr <= ptr && len <= storage_len && ptr - storage_ptr <= storage_len - len
|
+ // (4) `ptr - storage_ptr <= storage_len - len`
|
||||||
+ })
|
+ // This fourth inequality is equivalent to the second one but doesn't overflow when
|
||||||
|
+ // the first and third inequalities hold.
|
||||||
|
+ storage_ptr <= ptr && len <= storage_len && ptr - storage_ptr <= storage_len - len
|
||||||
|
+ })
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
fn update_stack_start_pointer(&self, stack_pointer: *const u8) {
|
fn update_stack_start_pointer(&self, stack_pointer: *const u8) {
|
||||||
if stack_pointer >= self.mem_start() && stack_pointer < self.mem_end() {
|
if stack_pointer >= self.mem_start() && stack_pointer < self.mem_end() {
|
||||||
self.debug.map(|debug| {
|
self.debug.map(|debug| {
|
||||||
@@ -1664,6 +1699,33 @@ impl<C: 'static + Chip> Process<'_, C> {
|
@@ -1664,6 +1702,33 @@ impl<C: 'static + Chip> Process<'_, C> {
|
||||||
return Err(ProcessLoadError::MpuInvalidFlashLength);
|
return Err(ProcessLoadError::MpuInvalidFlashLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ // Allocate MPU region for the storage locations. The storage locations are currently
|
+ // Allocate MPU region for the storage locations. The storage locations are currently
|
||||||
+ // readable by all processes due to lack of stable app id.
|
+ // readable by all processes due to lack of stable app id.
|
||||||
+ for storage_location in kernel.storage_locations() {
|
+ for storage_location in kernel.storage_locations() {
|
||||||
@@ -557,13 +558,13 @@ index 4dfde3b..0ceff3e 100644
|
|||||||
// memory space just for kernel and grant state. We need to make
|
// memory space just for kernel and grant state. We need to make
|
||||||
// sure we allocate enough memory just for that.
|
// sure we allocate enough memory just for that.
|
||||||
diff --git a/kernel/src/sched.rs b/kernel/src/sched.rs
|
diff --git a/kernel/src/sched.rs b/kernel/src/sched.rs
|
||||||
index 88eea40..ed3ae82 100644
|
index 88eea4042..ed3ae8260 100644
|
||||||
--- a/kernel/src/sched.rs
|
--- a/kernel/src/sched.rs
|
||||||
+++ b/kernel/src/sched.rs
|
+++ b/kernel/src/sched.rs
|
||||||
@@ -118,15 +118,24 @@ pub enum SchedulingDecision {
|
@@ -118,6 +118,12 @@ pub enum SchedulingDecision {
|
||||||
TrySleep,
|
TrySleep,
|
||||||
}
|
}
|
||||||
|
|
||||||
+/// Represents a storage location in flash.
|
+/// Represents a storage location in flash.
|
||||||
+pub struct StorageLocation {
|
+pub struct StorageLocation {
|
||||||
+ pub address: usize,
|
+ pub address: usize,
|
||||||
@@ -573,12 +574,10 @@ index 88eea40..ed3ae82 100644
|
|||||||
/// Main object for the kernel. Each board will need to create one.
|
/// Main object for the kernel. Each board will need to create one.
|
||||||
pub struct Kernel {
|
pub struct Kernel {
|
||||||
/// How many "to-do" items exist at any given time. These include
|
/// How many "to-do" items exist at any given time. These include
|
||||||
/// outstanding callbacks and processes in the Running state.
|
@@ -127,6 +133,9 @@ pub struct Kernel {
|
||||||
work: Cell<usize>,
|
|
||||||
|
|
||||||
/// This holds a pointer to the static array of Process pointers.
|
/// This holds a pointer to the static array of Process pointers.
|
||||||
processes: &'static [Option<&'static dyn process::ProcessType>],
|
processes: &'static [Option<&'static dyn process::ProcessType>],
|
||||||
|
|
||||||
+ /// List of storage locations.
|
+ /// List of storage locations.
|
||||||
+ storage_locations: &'static [StorageLocation],
|
+ storage_locations: &'static [StorageLocation],
|
||||||
+
|
+
|
||||||
@@ -586,7 +585,7 @@ index 88eea40..ed3ae82 100644
|
|||||||
/// created. This is used to create new unique identifiers for processes.
|
/// created. This is used to create new unique identifiers for processes.
|
||||||
process_identifier_max: Cell<usize>,
|
process_identifier_max: Cell<usize>,
|
||||||
@@ -170,9 +179,17 @@ pub enum StoppedExecutingReason {
|
@@ -170,9 +179,17 @@ pub enum StoppedExecutingReason {
|
||||||
|
|
||||||
impl Kernel {
|
impl Kernel {
|
||||||
pub fn new(processes: &'static [Option<&'static dyn process::ProcessType>]) -> Kernel {
|
pub fn new(processes: &'static [Option<&'static dyn process::ProcessType>]) -> Kernel {
|
||||||
+ Kernel::new_with_storage(processes, &[])
|
+ Kernel::new_with_storage(processes, &[])
|
||||||
@@ -604,7 +603,7 @@ index 88eea40..ed3ae82 100644
|
|||||||
grant_counter: Cell::new(0),
|
grant_counter: Cell::new(0),
|
||||||
grants_finalized: Cell::new(false),
|
grants_finalized: Cell::new(false),
|
||||||
@@ -899,4 +916,8 @@ impl Kernel {
|
@@ -899,4 +916,8 @@ impl Kernel {
|
||||||
|
|
||||||
(return_reason, time_executed_us)
|
(return_reason, time_executed_us)
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
|
|||||||
Reference in New Issue
Block a user