Skip to content

Commit

Permalink
Merge pull request #20257 from fzi-haxel/native64-part1
Browse files Browse the repository at this point in the history
core, sys, drivers: 64-bit support preparations
  • Loading branch information
maribu authored Jan 17, 2024
2 parents de7d72c + 3feb1a3 commit 0cffb7f
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 110 deletions.
7 changes: 6 additions & 1 deletion core/lib/include/priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern "C" {
typedef struct priority_queue_node {
struct priority_queue_node *next; /**< next queue node */
uint32_t priority; /**< queue node priority */
unsigned int data; /**< queue node data */
uintptr_t data; /**< queue node data */
} priority_queue_node_t;

/**
Expand All @@ -47,6 +47,11 @@ typedef struct {
*/
#define PRIORITY_QUEUE_NODE_INIT { NULL, 0, 0 }

/**
* @brief Constant for signaling in the priority queue data member.
*/
#define PRIORITY_QUEUE_DATA_SIGNALING (UINTPTR_MAX)

/**
* @brief Initialize a priority queue node object.
* @details For initialization of variables use PRIORITY_QUEUE_NODE_INIT
Expand Down
8 changes: 4 additions & 4 deletions core/lib/priority_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ void priority_queue_print(priority_queue_t *root)
printf("queue:\n");

for (priority_queue_node_t *node = root->first; node; node = node->next) {
printf("Data: %u Priority: %lu\n", node->data,
(unsigned long)node->priority);
printf("Data: %" PRIuPTR " Priority: %" PRIu32 "\n", node->data,
node->priority);
}
}

void priority_queue_print_node(priority_queue_node_t *node)
{
printf("Data: %u Priority: %lu Next: %u\n", (unsigned int)node->data,
(unsigned long)node->priority, (unsigned int)node->next);
printf("Data: %" PRIuPTR " Priority: %" PRIu32 " Next: %p\n", node->data,
node->priority, (void *)node->next);
}
#endif
12 changes: 6 additions & 6 deletions core/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
list_node_t *next = list_remove_head(&mbox->readers);

if (next) {
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08x: _tryput(): "
"there's a waiter.\n", thread_getpid(), (unsigned)mbox);
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08" PRIxPTR ": _tryput(): "
"there's a waiter.\n", thread_getpid(), (uintptr_t)mbox);
thread_t *thread =
container_of((clist_node_t *)next, thread_t, rq_entry);
*(msg_t *)thread->wait_data = *msg;
Expand All @@ -84,8 +84,8 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
}
}

DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08x: _tryput(): "
"queued message.\n", thread_getpid(), (unsigned)mbox);
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08" PRIxPTR ": _tryput(): "
"queued message.\n", thread_getpid(), (uintptr_t)mbox);
msg->sender_pid = thread_getpid();
/* copy msg into queue */
mbox->msg_array[cib_put_unsafe(&mbox->cib)] = *msg;
Expand All @@ -99,8 +99,8 @@ int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking)
unsigned irqstate = irq_disable();

if (cib_avail(&mbox->cib)) {
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08x: _tryget(): "
"got queued message.\n", thread_getpid(), (unsigned)mbox);
DEBUG("mbox: Thread %" PRIkernel_pid " mbox 0x%08" PRIxPTR ": _tryget(): "
"got queued message.\n", thread_getpid(), (uintptr_t)mbox);
/* copy msg from queue */
*msg = mbox->msg_array[cib_get_unsafe(&mbox->cib)];
list_node_t *next = list_remove_head(&mbox->writers);
Expand Down
4 changes: 2 additions & 2 deletions core/thread_flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static inline int __attribute__((always_inline)) _thread_flags_wake(
thread_t *thread)
{
unsigned wakeup;
thread_flags_t mask = (uint16_t)(unsigned)thread->wait_data;
thread_flags_t mask = (uint16_t)(uintptr_t)thread->wait_data;

switch (thread->status) {
case STATUS_FLAG_BLOCKED_ANY:
Expand Down Expand Up @@ -76,7 +76,7 @@ static void _thread_flags_wait(thread_flags_t mask, thread_t *thread,
"_thread_flags_wait: me->flags=0x%08x me->mask=0x%08x. going blocked.\n",
(unsigned)thread->flags, (unsigned)mask);

thread->wait_data = (void *)(unsigned)mask;
thread->wait_data = (void *)(uintptr_t)mask;
sched_set_status(thread, threadstate);
irq_restore(irqstate);
thread_yield_higher();
Expand Down
9 changes: 6 additions & 3 deletions drivers/mtd_flashpage/mtd_flashpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define ENABLE_DEBUG 0
#include "debug.h"

#define MTD_FLASHPAGE_END_ADDR ((uint32_t) CPU_FLASH_BASE + (FLASHPAGE_NUMOF * FLASHPAGE_SIZE))
#define MTD_FLASHPAGE_END_ADDR ((uintptr_t) CPU_FLASH_BASE + (FLASHPAGE_NUMOF * FLASHPAGE_SIZE))

static int _init(mtd_dev_t *dev)
{
Expand All @@ -44,11 +44,14 @@ static int _init(mtd_dev_t *dev)
assert(dev->pages_per_sector * dev->page_size == FLASHPAGE_SIZE);
assert(!(super->offset % dev->pages_per_sector));

assert((int)flashpage_addr(super->offset / dev->pages_per_sector) >= (int)CPU_FLASH_BASE);
/* Use separate variable to avoid '>= 0 is always true' warning */
static const uintptr_t cpu_flash_base = CPU_FLASH_BASE;

assert((uintptr_t)flashpage_addr(super->offset / dev->pages_per_sector) >= cpu_flash_base);
assert((uintptr_t)flashpage_addr(super->offset / dev->pages_per_sector)
+ dev->pages_per_sector * dev->page_size * dev->sector_count <= MTD_FLASHPAGE_END_ADDR);
assert((uintptr_t)flashpage_addr(super->offset / dev->pages_per_sector)
+ dev->pages_per_sector * dev->page_size * dev->sector_count > CPU_FLASH_BASE);
+ dev->pages_per_sector * dev->page_size * dev->sector_count > cpu_flash_base);
return 0;
}

Expand Down
12 changes: 6 additions & 6 deletions drivers/soft_uart/soft_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct uart_ctx {

static void _tx_timer_cb(void *arg, int chan)
{
soft_uart_t uart = (soft_uart_t)arg;
soft_uart_t uart = (soft_uart_t)(uintptr_t)arg;

const soft_uart_conf_t *cfg = &soft_uart_config[uart];
struct uart_ctx *ctx = &soft_uart_ctx[uart];
Expand All @@ -81,7 +81,7 @@ static void _tx_timer_cb(void *arg, int chan)

static void _rx_timer_cb(void *arg, int chan)
{
soft_uart_t uart = (soft_uart_t)arg;
soft_uart_t uart = (soft_uart_t)(uintptr_t)arg;

const soft_uart_conf_t *cfg = &soft_uart_config[uart];
struct uart_ctx *ctx = &soft_uart_ctx[uart];
Expand All @@ -101,7 +101,7 @@ static void _rx_timer_cb(void *arg, int chan)

static void _rx_gpio_cb(void *arg)
{
soft_uart_t uart = (soft_uart_t)arg;
soft_uart_t uart = (soft_uart_t)(uintptr_t)arg;

const soft_uart_conf_t *cfg = &soft_uart_config[uart];
struct uart_ctx *ctx = &soft_uart_ctx[uart];
Expand Down Expand Up @@ -166,18 +166,18 @@ int soft_uart_init(soft_uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void
ctx->state_rx = STATE_RX_IDLE;

if (gpio_is_valid(cfg->tx_pin)) {
timer_init(cfg->tx_timer, cfg->timer_freq, _tx_timer_cb, (void *)uart);
timer_init(cfg->tx_timer, cfg->timer_freq, _tx_timer_cb, (void *)(uintptr_t)uart);
gpio_write(cfg->tx_pin, !(cfg->flags & SOFT_UART_FLAG_INVERT_TX));
gpio_init(cfg->tx_pin, GPIO_OUT);
}

if (rx_cb) {
timer_init(cfg->rx_timer, cfg->timer_freq, _rx_timer_cb, (void *)uart);
timer_init(cfg->rx_timer, cfg->timer_freq, _rx_timer_cb, (void *)(uintptr_t)uart);
timer_stop(cfg->rx_timer);
/* timer should fire at the end of the byte */
timer_set_periodic(cfg->rx_timer, 0, ctx->bit_time * (BITS_DATA(ctx) + BITS_PARITY(ctx) + 1),

Check warning on line 178 in drivers/soft_uart/soft_uart.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
TIM_FLAG_RESET_ON_MATCH | TIM_FLAG_RESET_ON_SET);
gpio_init_int(cfg->rx_pin, GPIO_IN, GPIO_BOTH, _rx_gpio_cb, (void*) uart);
gpio_init_int(cfg->rx_pin, GPIO_IN, GPIO_BOTH, _rx_gpio_cb, (void*)(uintptr_t)uart);
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions sys/cpp11-compat/condition_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void condition_variable::notify_one() noexcept {
other_prio = other_thread->priority;
sched_set_status(other_thread, STATUS_PENDING);
}
head->data = -1u;
head->data = PRIORITY_QUEUE_DATA_SIGNALING;
}
irq_restore(old_state);
if (other_prio >= 0) {
Expand All @@ -69,7 +69,7 @@ void condition_variable::notify_all() noexcept {
other_prio = max_prio(other_prio, other_thread->priority);
sched_set_status(other_thread, STATUS_PENDING);
}
head->data = -1u;
head->data = PRIORITY_QUEUE_DATA_SIGNALING;
}
irq_restore(old_state);
if (other_prio >= 0) {
Expand All @@ -87,8 +87,8 @@ void condition_variable::wait(unique_lock<mutex>& lock) noexcept {
priority_queue_add(&m_queue, &n);
irq_restore(old_state);
mutex_unlock_and_sleep(lock.mutex()->native_handle());
if (n.data != -1u) {
// on signaling n.data is set to -1u
if (n.data != PRIORITY_QUEUE_DATA_SIGNALING) {
// on signaling n.data is set to PRIORITY_QUEUE_DATA_SIGNALING
// if it isn't set, then the wakeup is either spurious or a timer wakeup
old_state = irq_disable();
priority_queue_remove(&m_queue, &n);
Expand Down
82 changes: 51 additions & 31 deletions sys/include/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,83 @@ extern "C" {
/**
* @brief Size of a word in bits
*
* @details Depending on architecture, this can have a value of 8, 16, or 32
* @details Depending on architecture, this can have a value of 8, 16, 32, or 64
*/
#define ARCHITECTURE_WORD_BITS <NUM>
/**
* @brief Size of a word in bytes
*
* @details Depending on architecture, this can have a value or 1, 2, or 4.
* @details Depending on architecture, this can have a value or 1, 2, 4, or 8.
*/
#define ARCHITECTURE_WORD_BYTES <NUM>
#define ARCHITECTURE_WORD_BYTES <ARCHITECTURE_WORD_BITS / 8>
/**
* @brief Word sized unsigned integer
*
* @details Synonym to `uint8_t`, `uint16_t` or `uint32_t` depending on
* architecture
* @details Synonym to `uint8_t`, `uint16_t`, `uint32_t`, or `uint64_t`
* depending on architecture
*/
typedef uint<num>_t uword_t;
typedef uint<NUM>_t uword_t;
/**
* @brief Word sized signed integer
*
* @details Synonym to `int8_t`, `int16_t` or `int32_t` depending on
* @details Synonym to `int8_t`, `int16_t`, `int32_t`, or `int64_t` depending on
* architecture
*
* @note This type is pronounce es-word-tea. When slaying dragons, this is
* not the tool you're looking for.
*/
typedef int<num>_t sword_t;
typedef int<NUM>_t sword_t;
/**
* @brief Highest number an sword_t can hold
*/
#define SWORD_MAX <2^(ARCHITECTURE_WORD_BITS - 1) - 1>
/**
* @brief Smallest number an sword_t can hold
*/
#define SWORD_MIN <-2^(ARCHITECTURE_WORD_BITS - 1)>
/**
* @brief Highest number an uword_t can hold
*/
#define UWORD_MAX <2^ARCHITECTURE_WORD_BITS - 1>

/* end of ifdef DOXYGEN */
#elif (ARCHITECTURE_WORD_BITS == 8)
#define ARCHITECTURE_WORD_BYTES (1U)
typedef uint8_t uword_t;
typedef int8_t sword_t;
#define SWORD_MAX (INT8_MAX)
#define SWORD_MIN (INT8_MIN)
#define UWORD_MAX (UINT8_MAX)
#elif (ARCHITECTURE_WORD_BITS == 16)
#define ARCHITECTURE_WORD_BYTES (2U)
typedef uint16_t uword_t;
typedef int16_t sword_t;
#define SWORD_MAX (INT16_MAX)
#define SWORD_MIN (INT16_MIN)
#define UWORD_MAX (UINT16_MAX)
#elif (ARCHITECTURE_WORD_BITS == 32)
#define ARCHITECTURE_WORD_BYTES (4U)
typedef uint32_t uword_t;
typedef int32_t sword_t;
#define SWORD_MAX (INT32_MAX)
#define SWORD_MIN (INT32_MIN)
#define UWORD_MAX (UINT32_MAX)
#elif (ARCHITECTURE_WORD_BITS == 64)
#define ARCHITECTURE_WORD_BYTES (8U)
typedef uint64_t uword_t;
typedef int64_t sword_t;
#define SWORD_MAX (INT64_MAX)
#define SWORD_MIN (INT64_MIN)
#define UWORD_MAX (UINT64_MAX)
#else
#error "Unsupported word size (check ARCHITECTURE_WORD_BITS in architecture_arch.h)"
#endif

/**
* @brief Smallest number an uword_t can hold
*/
#define UWORD_MIN (0U)

#if !defined(ARCHITECTURE_LARGE_TXT_PTR) || DOXYGEN
/**
* @brief Pointer type to point anywhere in the .text section
Expand Down Expand Up @@ -135,7 +170,6 @@ typedef uintptr_t uinttxtptr_t;
/**
* @brief Macro holding the format specifier to print an `ssize_t` variable
* in octal representation.
* `0x` or `0`, respectively.
*/
#define PRIoSIZE PRI_SIZE_T_MODIFIER "o"
/**
Expand All @@ -145,12 +179,18 @@ typedef uintptr_t uinttxtptr_t;
#define PRIuSIZE PRI_SIZE_T_MODIFIER "u"
/**
* @brief Macro holding the format specifier to print an `size_t` variable
* in hexadecimal representation (e.g. `2a` for 42).
* in hexadecimal representation.
*
* @details Same as @ref PRIXSIZE for input, but uses lowercase letters for
* output (e.g. `2a` for 42).
*/
#define PRIxSIZE PRI_SIZE_T_MODIFIER "x"
/**
* @brief Macro holding the format specifier to print an `size_t` variable
* in hexadecimal representation (e.g. `2A` for 42).
* in hexadecimal representation.
*
* @details Same as @ref PRIxSIZE for input, but uses uppercase letters for
* output (e.g. `2A` for 42).
*/
#define PRIXSIZE PRI_SIZE_T_MODIFIER "X"

Expand Down Expand Up @@ -185,26 +225,6 @@ typedef uintptr_t uinttxtptr_t;
*/
#define IS_WORD_ALIGNED(addr) HAS_ALIGNMENT_OF(addr, ARCHITECTURE_WORD_BYTES)

/**
* @brief Smallest number an uword_t can hold
*/
#define UWORD_MIN 0

/**
* @brief Highest number an uword_t can hold
*/
#define UWORD_MAX ((1ULL << ARCHITECTURE_WORD_BITS) - 1)

/**
* @brief Smallest number an sword_t can hold
*/
#define SWORD_MIN (-(1LL << (ARCHITECTURE_WORD_BITS - 1)))

/**
* @brief Highest number an sword_t can hold
*/
#define SWORD_MAX ((1LL << (ARCHITECTURE_WORD_BITS - 1)) - 1)

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion sys/include/bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern "C" {
/**
* @brief hash function to use in thee filter
*/
typedef uint32_t (*hashfp_t)(const uint8_t *, int len);
typedef uint32_t (*hashfp_t)(const uint8_t *, size_t len);

/**
* @brief bloom_t bloom filter object
Expand Down
Loading

0 comments on commit 0cffb7f

Please sign in to comment.