Skip to content

Commit

Permalink
Merge pull request #3965 from alevy/bug/statimut-stopgap
Browse files Browse the repository at this point in the history
Stopgap changes to treatment of `static mut` to get around compiler warnings.
  • Loading branch information
bradjc committed Apr 17, 2024
2 parents 9f6fbc8 + c22999d commit 28a132f
Show file tree
Hide file tree
Showing 109 changed files with 649 additions and 383 deletions.
10 changes: 5 additions & 5 deletions arch/cortex-m/src/syscall.rs
Expand Up @@ -9,7 +9,7 @@ use core::fmt::Write;
use core::marker::PhantomData;
use core::mem::{self, size_of};
use core::ops::Range;
use core::ptr::{self, read_volatile, write_volatile};
use core::ptr::{self, addr_of, addr_of_mut, read_volatile, write_volatile};
use kernel::errorcode::ErrorCode;

use crate::CortexMVariant;
Expand Down Expand Up @@ -264,13 +264,13 @@ impl<A: CortexMVariant> kernel::syscall::UserspaceKernelBoundary for SysCall<A>

// Check to see if the fault handler was called while the process was
// running.
let app_fault = read_volatile(&APP_HARD_FAULT);
write_volatile(&mut APP_HARD_FAULT, 0);
let app_fault = read_volatile(&*addr_of!(APP_HARD_FAULT));
write_volatile(&mut *addr_of_mut!(APP_HARD_FAULT), 0);

// Check to see if the svc_handler was called and the process called a
// syscall.
let syscall_fired = read_volatile(&SYSCALL_FIRED);
write_volatile(&mut SYSCALL_FIRED, 0);
let syscall_fired = read_volatile(&*addr_of!(SYSCALL_FIRED));
write_volatile(&mut *addr_of_mut!(SYSCALL_FIRED), 0);

// Now decide the reason based on which flags were set.
let switch_reason = if app_fault == 1 || invalid_stack_pointer {
Expand Down
10 changes: 6 additions & 4 deletions boards/acd52832/src/main.rs
Expand Up @@ -10,6 +10,8 @@
#![cfg_attr(not(doc), no_main)]
#![deny(missing_docs)]

use core::ptr::{addr_of, addr_of_mut};

use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
use kernel::capabilities;
use kernel::component::Component;
Expand Down Expand Up @@ -192,7 +194,7 @@ unsafe fn start() -> (
create_capability!(capabilities::ProcessManagementCapability);
let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));

// Make non-volatile memory writable and activate the reset button
let uicr = nrf52832::uicr::Uicr::new();
Expand Down Expand Up @@ -598,7 +600,7 @@ unsafe fn start() -> (
while !base_peripherals.clock.low_started() {}
while !base_peripherals.clock.high_started() {}

let scheduler = components::sched::round_robin::RoundRobinComponent::new(&PROCESSES)
let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
.finalize(components::round_robin_component_static!(NUM_PROCS));

let platform = Platform {
Expand Down Expand Up @@ -631,7 +633,7 @@ unsafe fn start() -> (
nrf52832_peripherals.gpio_port[Pin::P0_31].clear();

debug!("Initialization complete. Entering main loop\r");
debug!("{}", &nrf52832::ficr::FICR_INSTANCE);
debug!("{}", &*addr_of!(nrf52832::ficr::FICR_INSTANCE));

// These symbols are defined in the linker script.
extern "C" {
Expand All @@ -656,7 +658,7 @@ unsafe fn start() -> (
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut PROCESSES,
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_management_capability,
)
Expand Down
10 changes: 6 additions & 4 deletions boards/apollo3/lora_things_plus/src/io.rs
Expand Up @@ -4,6 +4,8 @@

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;

use crate::CHIP;
use crate::PROCESSES;
Expand Down Expand Up @@ -45,15 +47,15 @@ pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
apollo3::gpio::Pin::Pin26,
);
let led = &mut led::LedLow::new(led_pin);
let writer = &mut WRITER;
let writer = &mut *addr_of_mut!(WRITER);

debug::panic(
&mut [led],
writer,
info,
&cortexm4::support::nop,
&PROCESSES,
&CHIP,
&PROCESS_PRINTER,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}
9 changes: 6 additions & 3 deletions boards/apollo3/lora_things_plus/src/main.rs
Expand Up @@ -39,6 +39,9 @@
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]

use core::ptr::addr_of;
use core::ptr::addr_of_mut;

use apollo3::chip::Apollo3DefaultPeripherals;
use capsules_core::virtualizers::virtual_alarm::MuxAlarm;
use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
Expand Down Expand Up @@ -232,7 +235,7 @@ unsafe fn setup() -> (
let process_mgmt_cap = create_capability!(capabilities::ProcessManagementCapability);
let memory_allocation_cap = create_capability!(capabilities::MemoryAllocationCapability);

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));

// Power up components
pwr_ctrl.enable_uart0();
Expand Down Expand Up @@ -458,7 +461,7 @@ unsafe fn setup() -> (
static _eappmem: u8;
}

let scheduler = components::sched::round_robin::RoundRobinComponent::new(&PROCESSES)
let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
.finalize(components::round_robin_component_static!(NUM_PROCS));

let systick = cortexm4::systick::SysTick::new_with_calibration(48_000_000);
Expand Down Expand Up @@ -500,7 +503,7 @@ unsafe fn setup() -> (
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut PROCESSES,
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_mgmt_cap,
)
Expand Down
10 changes: 6 additions & 4 deletions boards/apollo3/redboard_artemis_atp/src/io.rs
Expand Up @@ -4,6 +4,8 @@

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;

use crate::CHIP;
use crate::PROCESSES;
Expand Down Expand Up @@ -45,15 +47,15 @@ pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
apollo3::gpio::Pin::Pin19,
);
let led = &mut led::LedLow::new(led_pin);
let writer = &mut WRITER;
let writer = &mut *addr_of_mut!(WRITER);

debug::panic(
&mut [led],
writer,
info,
&cortexm4::support::nop,
&PROCESSES,
&CHIP,
&PROCESS_PRINTER,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}
9 changes: 6 additions & 3 deletions boards/apollo3/redboard_artemis_atp/src/main.rs
Expand Up @@ -15,6 +15,9 @@
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]

use core::ptr::addr_of;
use core::ptr::addr_of_mut;

use apollo3::chip::Apollo3DefaultPeripherals;
use capsules_core::i2c_master_slave_driver::I2CMasterSlaveDriver;
use capsules_core::virtualizers::virtual_alarm::MuxAlarm;
Expand Down Expand Up @@ -172,7 +175,7 @@ unsafe fn setup() -> (
let process_mgmt_cap = create_capability!(capabilities::ProcessManagementCapability);
let memory_allocation_cap = create_capability!(capabilities::MemoryAllocationCapability);

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));

// Power up components
pwr_ctrl.enable_uart0();
Expand Down Expand Up @@ -333,7 +336,7 @@ unsafe fn setup() -> (
static _eappmem: u8;
}

let scheduler = components::sched::round_robin::RoundRobinComponent::new(&PROCESSES)
let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
.finalize(components::round_robin_component_static!(NUM_PROCS));

let systick = cortexm4::systick::SysTick::new_with_calibration(48_000_000);
Expand Down Expand Up @@ -369,7 +372,7 @@ unsafe fn setup() -> (
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut PROCESSES,
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_mgmt_cap,
)
Expand Down
10 changes: 6 additions & 4 deletions boards/apollo3/redboard_artemis_nano/src/io.rs
Expand Up @@ -4,6 +4,8 @@

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;

use crate::CHIP;
use crate::PROCESSES;
Expand Down Expand Up @@ -45,15 +47,15 @@ pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
apollo3::gpio::Pin::Pin19,
);
let led = &mut led::LedLow::new(led_pin);
let writer = &mut WRITER;
let writer = &mut *addr_of_mut!(WRITER);

debug::panic(
&mut [led],
writer,
info,
&cortexm4::support::nop,
&PROCESSES,
&CHIP,
&PROCESS_PRINTER,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}
9 changes: 6 additions & 3 deletions boards/apollo3/redboard_artemis_nano/src/main.rs
Expand Up @@ -15,6 +15,9 @@
#![test_runner(test_runner)]
#![reexport_test_harness_main = "test_main"]

use core::ptr::addr_of;
use core::ptr::addr_of_mut;

use apollo3::chip::Apollo3DefaultPeripherals;
use capsules_core::virtualizers::virtual_alarm::MuxAlarm;
use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
Expand Down Expand Up @@ -194,7 +197,7 @@ unsafe fn setup() -> (
let process_mgmt_cap = create_capability!(capabilities::ProcessManagementCapability);
let memory_allocation_cap = create_capability!(capabilities::MemoryAllocationCapability);

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));

// Power up components
pwr_ctrl.enable_uart0();
Expand Down Expand Up @@ -386,7 +389,7 @@ unsafe fn setup() -> (
static _eappmem: u8;
}

let scheduler = components::sched::round_robin::RoundRobinComponent::new(&PROCESSES)
let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
.finalize(components::round_robin_component_static!(NUM_PROCS));

let systick = cortexm4::systick::SysTick::new_with_calibration(48_000_000);
Expand Down Expand Up @@ -426,7 +429,7 @@ unsafe fn setup() -> (
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut PROCESSES,
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_mgmt_cap,
)
Expand Down
10 changes: 6 additions & 4 deletions boards/arty_e21/src/io.rs
Expand Up @@ -4,6 +4,8 @@

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;
use core::str;
use kernel::debug;
use kernel::debug::IoWrite;
Expand Down Expand Up @@ -64,14 +66,14 @@ pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
);

let led_red = &mut led::LedHigh::new(led_red_pin);
let writer = &mut WRITER;
let writer = &mut *addr_of_mut!(WRITER);
debug::panic(
&mut [led_red],
writer,
pi,
&rv32i::support::nop,
&PROCESSES,
&CHIP,
&PROCESS_PRINTER,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}
6 changes: 4 additions & 2 deletions boards/arty_e21/src/main.rs
Expand Up @@ -9,6 +9,8 @@
// https://github.com/rust-lang/rust/issues/62184.
#![cfg_attr(not(doc), no_main)]

use core::ptr::{addr_of, addr_of_mut};

use arty_e21_chip::chip::ArtyExxDefaultPeripherals;
use capsules_core::virtualizers::virtual_alarm::{MuxAlarm, VirtualMuxAlarm};

Expand Down Expand Up @@ -139,7 +141,7 @@ unsafe fn start() -> (

let process_mgmt_cap = create_capability!(capabilities::ProcessManagementCapability);

let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));

// Configure kernel debug gpios as early as possible
kernel::debug::assign_gpios(
Expand Down Expand Up @@ -285,7 +287,7 @@ unsafe fn start() -> (
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut PROCESSES,
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_mgmt_cap,
)
Expand Down
14 changes: 8 additions & 6 deletions boards/clue_nrf52840/src/io.rs
Expand Up @@ -4,6 +4,8 @@

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;
use kernel::ErrorCode;

use kernel::debug;
Expand Down Expand Up @@ -96,8 +98,8 @@ impl IoWrite for Writer {
// mutate it.
let usb = &mut cdc.controller();
STATIC_PANIC_BUF[..max].copy_from_slice(&buf[..max]);
let static_buf = &mut STATIC_PANIC_BUF;
cdc.set_transmit_client(&DUMMY);
let static_buf = &mut *addr_of_mut!(STATIC_PANIC_BUF);
cdc.set_transmit_client(&*addr_of!(DUMMY));
let _ = cdc.transmit_buffer(static_buf, max);
loop {
if let Some(interrupt) = cortexm4::nvic::next_pending() {
Expand Down Expand Up @@ -130,14 +132,14 @@ impl IoWrite for Writer {
pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
let led_kernel_pin = &nrf52840::gpio::GPIOPin::new(Pin::P1_01);
let led = &mut led::LedHigh::new(led_kernel_pin);
let writer = &mut WRITER;
let writer = &mut *addr_of_mut!(WRITER);
debug::panic(
&mut [led],
writer,
pi,
&cortexm4::support::nop,
&PROCESSES,
&CHIP,
&PROCESS_PRINTER,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}

0 comments on commit 28a132f

Please sign in to comment.