Skip to content

Commit 95e88e8

Browse files
committed
software: constrain the alignment of memory-mapped registers.
Otherwise, GCC/Clang will serialize 32-bit accesses as four 8-bit instructions. Clang will schedule them in descending order, which violates the SoC memory model (Amaranth SoC CSRs must be accessed in ascending order of addresses).
1 parent 172215e commit 95e88e8

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

chipflow_lib/software/drivers/gpio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdint.h>
66

7-
typedef struct __attribute__((packed)) {
7+
typedef struct __attribute__((packed, aligned(4))) {
88
uint32_t out;
99
uint32_t oe;
1010
uint32_t in;

chipflow_lib/software/drivers/plat_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdint.h>
66

7-
typedef struct __attribute__((packed)) {
7+
typedef struct __attribute__((packed, aligned(4))) {
88
uint32_t cnt_lo;
99
uint32_t cnt_hi;
1010
uint32_t cmp_lo;

chipflow_lib/software/drivers/soc_id.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdint.h>
66

7-
typedef struct __attribute__((packed)) {
7+
typedef struct __attribute__((packed, aligned(4))) {
88
uint32_t type;
99
uint32_t version;
1010
} soc_id_regs_t;

chipflow_lib/software/drivers/spiflash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define WINBOND_ID 0x40
88
#define ISSI_ID 0x60
99

10-
typedef struct __attribute__((packed)) {
10+
typedef struct __attribute__((packed, aligned(4))) {
1111
uint32_t ctrl;
1212
} spiflash_regs_t;
1313

chipflow_lib/software/drivers/uart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdint.h>
66

7-
typedef struct __attribute__((packed)) {
7+
typedef struct __attribute__((packed, aligned(4))) {
88
uint32_t tx_data;
99
uint32_t rx_data;
1010
uint32_t tx_ready;

0 commit comments

Comments
 (0)