Skip to content

Commit

Permalink
refactor: remove packed from MMIO structs
Browse files Browse the repository at this point in the history
rust-lang/rust#46043 makes accessing members
of packed structs unsafe. For MMIO structs, `repr(C)` alone should be
sufficient as the layout by definition has no holes.
  • Loading branch information
ppannuto committed Jan 7, 2018
1 parent f02c818 commit dd0e9cc
Show file tree
Hide file tree
Showing 29 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion arch/cortex-m0/src/nvic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use kernel::common::volatile_cell::VolatileCell;

#[repr(C, packed)]
#[repr(C)]
// Registers for the NVIC
struct Registers {
// Interrupt set-enable
Expand Down
4 changes: 2 additions & 2 deletions arch/cortex-m4/src/mpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use kernel::common::math::PowerOfTwo;

/// Indicates whether the MPU is present and, if so, how many regions it
/// supports.
#[repr(C,packed)]
#[repr(C)]
pub struct MpuType {
/// Indicates whether the processor support unified (0) or separate
/// (1) instruction and data regions. Always reads 0 on the
Expand All @@ -23,7 +23,7 @@ pub struct MpuType {
_reserved: u8,
}

#[repr(C,packed)]
#[repr(C)]
/// MPU Registers for the Cortex-M4 family
///
/// Described in section 4.5 of
Expand Down
2 changes: 1 addition & 1 deletion arch/cortex-m4/src/nvic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use kernel::common::volatile_cell::VolatileCell;

#[repr(C, packed)]
#[repr(C)]
// Registers for the NVIC
struct Registers {
// Interrupt set-enable
Expand Down
2 changes: 1 addition & 1 deletion arch/cortex-m4/src/scb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use kernel::common::VolatileCell;

#[repr(C, packed)]
#[repr(C)]
struct ScbRegisters {
cpuid: VolatileCell<u32>,
icsr: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion capsules/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl IPAddr {
}
}

#[repr(C, packed)]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct IP6Header {
pub version_class_flow: [u8; 4],
Expand Down
2 changes: 1 addition & 1 deletion chips/nrf51/src/peripheral_registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use kernel::common::VolatileCell;

pub const RADIO_BASE: usize = 0x40001000;
#[allow(non_snake_case)]
#[repr(C, packed)]
#[repr(C)]
pub struct RADIO_REGS {
pub txen: VolatileCell<u32>, // 0x000 ---> 0x004
pub rxen: VolatileCell<u32>, // 0x004 ---> 0x008
Expand Down
2 changes: 1 addition & 1 deletion chips/nrf51/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use kernel::common::take_cell::TakeCell;
use kernel::hil::uart;
use nrf5x::pinmux::Pinmux;

#[repr(C, packed)]
#[repr(C)]
pub struct Registers {
pub task_startrx: VolatileCell<u32>,
pub task_stoprx: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/nrf52/src/ficr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kernel::common::VolatileCell;
/// Struct of the FICR registers
///
/// Section 13.1 of http://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.0.pdf
#[repr(C, packed)]
#[repr(C)]
struct FicrRegisters {
_reserved0: [VolatileCell<u32>; 4], // (0x10 - 0x00) / 4 = 4
codepagesize: VolatileCell<u32>,
Expand Down
8 changes: 4 additions & 4 deletions chips/nrf52/src/peripheral_registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use kernel::common::VolatileCell;
use nrf5x;

pub const UARTE_BASE: u32 = 0x40002000;
#[repr(C, packed)]
#[repr(C)]
pub struct UARTE {
pub task_startrx: VolatileCell<u32>, // 0x000-0x004
pub task_stoprx: VolatileCell<u32>, // 0x004-0x008
Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct UARTE {
}

pub const UICR_BASE: usize = 0x10001200;
#[repr(C, packed)]
#[repr(C)]
pub struct UICR {
pub pselreset0: VolatileCell<u32>, // 0x200 - 0x204
pub pselreset1: VolatileCell<u32>, // 0x204 - 0x208
Expand All @@ -63,7 +63,7 @@ pub struct UICR {
}

pub const NVMC_BASE: usize = 0x4001E400;
#[repr(C, packed)]
#[repr(C)]
pub struct NVMC {
pub ready: VolatileCell<u32>, // 0x400-0x404
_reserved1: [VolatileCell<u32>; 64], // 0x404-0x504
Expand All @@ -80,7 +80,7 @@ pub struct NVMC {

pub const RADIO_BASE: usize = 0x40001000;
#[allow(non_snake_case)]
#[repr(C, packed)]
#[repr(C)]
pub struct RADIO {
pub task_txen: VolatileCell<u32>, // 0x000 - 0x004
pub task_rxen: VolatileCell<u32>, // 0x004 - 0x008
Expand Down
2 changes: 1 addition & 1 deletion chips/nrf52/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod registers {
}

/// Represents one of NRF52's three `SPIM` instances.
#[repr(C, packed)]
#[repr(C)]
pub struct SPIM {
_reserved0: [u32; 4],
/// Start SPI transaction
Expand Down
2 changes: 1 addition & 1 deletion chips/nrf5x/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::cell::Cell;
use core::mem;
use kernel::common::VolatileCell;

#[repr(C, packed)]
#[repr(C)]
struct Registers {
pub tasks_hfclkstart: VolatileCell<u32>,
pub tasks_hfclkstop: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/nrf5x/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const NUM_GPIOTE: usize = 8;
/// Event) channel, and bind the channel to the desired pin. There are 4
/// channels for the nrf51 and 8 channels for the nrf52. This means that
/// requesting an interrupt can fail, if they are all already allocated.
#[repr(C, packed)]
#[repr(C)]
struct GpioteRegisters {
out: [VolatileCell<u32>; NUM_GPIOTE], // 0x0
_reserved0: [u8; 0x100 - (0x0 + NUM_GPIOTE * 4)],
Expand Down
12 changes: 6 additions & 6 deletions chips/nrf5x/src/peripheral_registers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use kernel::common::VolatileCell;

pub const RTC1_BASE: usize = 0x40011000;
#[repr(C, packed)]
#[repr(C)]
pub struct RTC1 {
pub tasks_start: VolatileCell<u32>,
pub tasks_stop: VolatileCell<u32>,
Expand Down Expand Up @@ -29,7 +29,7 @@ pub struct RTC1 {
// FIXME: check registers and add TIMER3 and TIMER4
pub const TIMER_SIZE: usize = 0x1000;
pub const TIMER_BASE: usize = 0x40008000;
#[repr(C, packed)]
#[repr(C)]
pub struct TIMER {
pub task_start: VolatileCell<u32>,
pub task_stop: VolatileCell<u32>,
Expand All @@ -55,7 +55,7 @@ pub struct TIMER {
}

pub const AESECB_BASE: usize = 0x4000E000;
#[repr(C, packed)]
#[repr(C)]
pub struct AESECB_REGS {
pub task_startecb: VolatileCell<u32>, // 0x000 - 0x004
pub task_stopecb: VolatileCell<u32>, // 0x004 - 0x008
Expand All @@ -70,7 +70,7 @@ pub struct AESECB_REGS {
}

pub const GPIO_BASE: usize = 0x50000000;
#[repr(C, packed)]
#[repr(C)]
pub struct GPIO {
_reserved1: [u32; 321],
pub out: VolatileCell<u32>,
Expand All @@ -85,7 +85,7 @@ pub struct GPIO {
}

pub const TEMP_BASE: usize = 0x4000C000;
#[repr(C, packed)]
#[repr(C)]
pub struct TEMP_REGS {
pub task_start: VolatileCell<u32>, // 0x000 - 0x004
pub task_stop: VolatileCell<u32>, // 0x004 - 0x008
Expand All @@ -100,7 +100,7 @@ pub struct TEMP_REGS {
}

pub const RNG_BASE: usize = 0x4000D000;
#[repr(C, packed)]
#[repr(C)]
pub struct RNG_REGS {
pub task_start: VolatileCell<u32>, // 0x000 - 0x004
pub task_stop: VolatileCell<u32>, // 0x004 - 0x008
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct Adc {
}

/// Memory mapped registers for the ADC.
#[repr(C, packed)]
#[repr(C)]
pub struct AdcRegisters {
// From page 1005 of SAM4L manual
pub cr: VolatileCell<u32>, // Control (0x00)
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use pm;
use scif;

/// The registers used to interface with the hardware
#[repr(C, packed)]
#[repr(C)]
struct AesRegisters {
ctrl: VolatileCell<u32>, // 0x00
mode: VolatileCell<u32>, // 0x04
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use pm::{self, PBDClock};
/// tics. Seems safe enough and in practice has seemed to work.
const ALARM0_SYNC_TICS: u32 = 8;

#[repr(C, packed)]
#[repr(C)]
struct AstRegisters {
cr: VolatileCell<u32>,
cv: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/bpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use kernel::common::VolatileCell;

#[repr(C, packed)]
#[repr(C)]
struct BpmRegisters {
interrupt_enable: VolatileCell<u32>,
interrupt_disable: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/bscif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use kernel::common::VolatileCell;

#[repr(C, packed)]
#[repr(C)]
struct BscifRegisters {
ier: VolatileCell<u32>,
idr: VolatileCell<u32>,
Expand Down
4 changes: 2 additions & 2 deletions chips/sam4l/src/crccu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ registers![
];

// CRCCU Descriptor (from Table 41.2 in Section 41.6):
#[repr(C, packed)]
#[repr(C)]
struct Descriptor {
addr: u32, // Transfer Address Register (RW): Address of memory block to compute
ctrl: TCR, // Transfer Control Register (RW): IEN, TRWIDTH, BTSIZE
Expand All @@ -134,7 +134,7 @@ struct Descriptor {

// Transfer Control Register (see Section 41.6.18)
#[derive(Copy, Clone)]
#[repr(C, packed)]
#[repr(C)]
struct TCR(u32);

impl TCR {
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use kernel::common::VolatileCell;
use kernel::hil;
use pm::{self, Clock, PBAClock};

#[repr(C, packed)]
#[repr(C)]
pub struct DacRegisters {
// From page 905 of SAM4L manual
cr: VolatileCell<u32>, // Control (0x00)
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use kernel::common::take_cell::TakeCell;
use pm;

/// Memory registers for a DMA channel. Section 16.6.1 of the datasheet.
#[repr(C, packed)]
#[repr(C)]
#[allow(dead_code)]
struct DMARegisters {
memory_address: VolatileCell<u32>, // 0x00
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/flashcalw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use kernel::hil;
use pm;

/// Struct of the FLASHCALW registers. Section 14.10 of the datasheet.
#[repr(C, packed)]
#[repr(C)]
struct FlashcalwRegisters {
fcr: VolatileCell<u32>,
fcmd: VolatileCell<u32>,
Expand Down
6 changes: 3 additions & 3 deletions chips/sam4l/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ use core::sync::atomic::{AtomicUsize, Ordering};
use kernel::common::VolatileCell;
use kernel::hil;

#[repr(C, packed)]
#[repr(C)]
struct Register {
val: VolatileCell<u32>,
set: VolatileCell<u32>,
clear: VolatileCell<u32>,
toggle: VolatileCell<u32>,
}

#[repr(C, packed)]
#[repr(C)]
struct RegisterRC {
val: VolatileCell<u32>,
reserved0: u32,
clear: VolatileCell<u32>,
reserved1: u32,
}

#[repr(C, packed)]
#[repr(C)]
struct Registers {
gper: Register,
pmr0: Register,
Expand Down
4 changes: 2 additions & 2 deletions chips/sam4l/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use pm;

// Listing of all registers related to the TWIM peripheral.
// Section 27.9 of the datasheet
#[repr(C, packed)]
#[repr(C)]
#[allow(dead_code)]
struct TWIMRegisters {
control: VolatileCell<u32>,
Expand All @@ -43,7 +43,7 @@ struct TWIMRegisters {

// Listing of all registers related to the TWIS peripheral.
// Section 28.9 of the datasheet
#[repr(C, packed)]
#[repr(C)]
#[allow(dead_code)]
struct TWISRegisters {
control: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/pm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use gpio;
use kernel::common::VolatileCell;
use scif;

#[repr(C, packed)]
#[repr(C)]
struct PmRegisters {
mcctrl: VolatileCell<u32>,
cpusel: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/scif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum GenericClock {
GCLK11,
}

#[repr(C, packed)]
#[repr(C)]
struct Registers {
ier: VolatileCell<u32>,
idr: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use kernel::hil::spi::SpiSlaveClient;
use pm;

/// The registers used to interface with the hardware
#[repr(C, packed)]
#[repr(C)]
struct SpiRegisters {
cr: VolatileCell<u32>, // 0x0
mr: VolatileCell<u32>, // 0x4
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use kernel::hil;
use pm;

// Register map for SAM4L USART
#[repr(C, packed)]
#[repr(C)]
struct USARTRegisters {
cr: VolatileCell<u32>, // 0x00
mr: VolatileCell<u32>,
Expand Down
2 changes: 1 addition & 1 deletion chips/sam4l/src/wdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use kernel::common::VolatileCell;
use kernel::hil;
use pm::{self, Clock, PBDClock};

#[repr(C, packed)]
#[repr(C)]
pub struct WdtRegisters {
cr: VolatileCell<u32>,
clr: VolatileCell<u32>,
Expand Down

0 comments on commit dd0e9cc

Please sign in to comment.