From b324c54285d5cd918b06059cb4da0a4edbc3bddb Mon Sep 17 00:00:00 2001 From: Frederik Haxel Date: Thu, 11 Jan 2024 13:16:17 +0100 Subject: [PATCH 1/3] tests: 64 bit compatibility Fixed compilation errors. Mostly DEBUG/printf formatting and void pointer casting. Other changes are: * net/gnrc_sixlowpan_frag_*: Generalized packet size calculation * cpu/native_backtrace: Reduced required backtrace size to 3 for 64-bit * periph/flashpage: Simplified test * unittests/tests-pktbuf: Generalized alignment * sys/architecture: Extended test for 64-bit --- tests/core/msg_queue_print/main.c | 4 ++-- tests/core/thread_zombie/main.c | 4 ++-- tests/cpu/native_backtrace/Makefile | 10 ++++++++ tests/drivers/at86rf215/main.c | 2 +- tests/drivers/at86rf2xx/main.c | 2 +- tests/drivers/cc2420/main.c | 2 +- tests/drivers/mrf24j40/main.c | 2 +- tests/drivers/mtd_raw/main.c | 2 +- tests/drivers/sds011/main.c | 4 ++-- tests/drivers/soft_uart/main.c | 6 ++--- tests/net/gnrc_sixlowpan_frag_minfwd/Makefile | 2 ++ tests/net/gnrc_sixlowpan_frag_minfwd/main.c | 21 ++++++++++++----- tests/net/gnrc_sixlowpan_frag_sfr/Makefile | 2 ++ tests/net/gnrc_sixlowpan_frag_sfr/main.c | 20 +++++++++++----- tests/periph/flashpage/main.c | 23 ++++--------------- tests/periph/flashpage_unittest/main.c | 6 ++--- tests/periph/gpio/main.c | 4 ++-- tests/periph/timer/main.c | 4 ++-- tests/periph/uart/main.c | 2 +- tests/pkg/cayenne-lpp/main.c | 2 +- tests/pkg/lora-serialization/main.c | 2 +- tests/sys/architecture/Makefile | 4 ++++ tests/sys/cb_mux/main.c | 6 ++--- tests/sys/conn_can/main.c | 4 ++-- tests/sys/events/main.c | 11 +++++---- tests/sys/heap_cmd/main.c | 2 +- tests/sys/ps_schedstatistics/main.c | 6 ++--- tests/sys/pthread_cooperation/main.c | 6 ++--- tests/sys/pthread_tls/main.c | 22 +++++++++--------- tests/unittests/tests-pktbuf/tests-pktbuf.c | 16 +++++++------ 30 files changed, 114 insertions(+), 89 deletions(-) diff --git a/tests/core/msg_queue_print/main.c b/tests/core/msg_queue_print/main.c index 0a2523471b04..f52ee7dedee6 100644 --- a/tests/core/msg_queue_print/main.c +++ b/tests/core/msg_queue_print/main.c @@ -35,9 +35,9 @@ int main(void) msg_init_queue(msg_queue, QUEUE_SIZE); msg_queue_print(); - for (int i = 0; i < QUEUE_SIZE; i++) { + for (uintptr_t i = 0; i < QUEUE_SIZE; i++) { messages[i].type = i; - messages[i].content.value = i; + messages[i].content.ptr = (void *) i; msg_send_to_self(&messages[i]); } diff --git a/tests/core/thread_zombie/main.c b/tests/core/thread_zombie/main.c index b2880fa0ffd5..47df0995dc44 100644 --- a/tests/core/thread_zombie/main.c +++ b/tests/core/thread_zombie/main.c @@ -35,8 +35,8 @@ static char t4_stack[TEST_THREAD_STACKSIZE]; /* function for testing threads */ void *second_thread(void *arg) { - printf("Thread: %d is starting\n", (int)arg); - printf("Thread: %d calls zombify\n", (int)arg); + printf("Thread: %" PRIdPTR " is starting\n", (intptr_t)arg); + printf("Thread: %" PRIdPTR " calls zombify\n", (intptr_t)arg); thread_zombify(); puts("ERROR zombie runs again!"); return NULL; diff --git a/tests/cpu/native_backtrace/Makefile b/tests/cpu/native_backtrace/Makefile index 6310e242319e..22e07d03f64c 100644 --- a/tests/cpu/native_backtrace/Makefile +++ b/tests/cpu/native_backtrace/Makefile @@ -5,3 +5,13 @@ USEMODULE += backtrace BOARD_WHITELIST := native include $(RIOTBASE)/Makefile.include + +ifeq ($(BOARD),native) + ifneq (,$(filter arch_64bit,$(FEATURES_USED))) + # 64 bit + CFLAGS += -DBACKTRACE_SIZE=3 + else + # 32 bit + CFLAGS += -DBACKTRACE_SIZE=4 + endif +endif diff --git a/tests/drivers/at86rf215/main.c b/tests/drivers/at86rf215/main.c index c91f43a0acb7..7729433c283f 100644 --- a/tests/drivers/at86rf215/main.c +++ b/tests/drivers/at86rf215/main.c @@ -191,7 +191,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { at86rf215_t *at86rf215_subghz = NULL; at86rf215_t *at86rf215_24ghz = NULL; - printf("%d out of %d\n", i + 1, AT86RF215_NUM); + printf("%d out of %u\n", i + 1, (unsigned)AT86RF215_NUM); if (IS_USED(MODULE_AT86RF215_SUBGHZ)) { puts("Sub-GHz"); diff --git a/tests/drivers/at86rf2xx/main.c b/tests/drivers/at86rf2xx/main.c index a24251eab3ed..3b7685a121f9 100644 --- a/tests/drivers/at86rf2xx/main.c +++ b/tests/drivers/at86rf2xx/main.c @@ -73,7 +73,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { puts("Initializing AT86RF2XX devices"); for (unsigned i = 0; i < AT86RF2XX_NUM; i++) { - printf("%d out of %d\n", i + 1, AT86RF2XX_NUM); + printf("%d out of %u\n", i + 1, (unsigned)AT86RF2XX_NUM); /* setup the specific driver */ at86rf2xx_setup(&at86rf2xx[i], &at86rf2xx_params[i], i); diff --git a/tests/drivers/cc2420/main.c b/tests/drivers/cc2420/main.c index 8ec9fcb014ed..6c87f76759e1 100644 --- a/tests/drivers/cc2420/main.c +++ b/tests/drivers/cc2420/main.c @@ -31,7 +31,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { puts("Initializing CC2420 devices"); for (unsigned i = 0; i < CC2420_NUM; i++) { - printf("%d out of %d\n", i + 1, CC2420_NUM); + printf("%d out of %u\n", i + 1, (unsigned)CC2420_NUM); netdev_t *netdev = &cc2420[i].netdev.netdev; /* setup the specific driver */ diff --git a/tests/drivers/mrf24j40/main.c b/tests/drivers/mrf24j40/main.c index 9783083ceb86..a6b5650faffb 100644 --- a/tests/drivers/mrf24j40/main.c +++ b/tests/drivers/mrf24j40/main.c @@ -47,7 +47,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { ieee802154_hal_test_init_devs(_reg_callback, &c); for (unsigned i = 0; i < MRF24J40_NUM; i++) { - printf("%d out of %d\n", i + 1, MRF24J40_NUM); + printf("%d out of %u\n", i + 1, (unsigned)MRF24J40_NUM); netdev_register(&mrf24j40_netdev[i].dev.netdev, NETDEV_MRF24J40, 0); netdev_ieee802154_submac_init(&mrf24j40_netdev[i]); diff --git a/tests/drivers/mtd_raw/main.c b/tests/drivers/mtd_raw/main.c index 1252f28e86e0..8a7a03873f2b 100644 --- a/tests/drivers/mtd_raw/main.c +++ b/tests/drivers/mtd_raw/main.c @@ -279,7 +279,7 @@ static void _print_info(mtd_dev_t *dev) static int cmd_info(int argc, char **argv) { if (argc < 2) { - printf("mtd devices: %d\n", MTD_NUMOF); + printf("mtd devices: %d\n", (unsigned)MTD_NUMOF); for (unsigned i = 0; i < MTD_NUMOF; ++i) { printf(" -=[ MTD_%d ]=-\n", i); diff --git a/tests/drivers/sds011/main.c b/tests/drivers/sds011/main.c index 78e5cbd76f72..8817b42d5170 100644 --- a/tests/drivers/sds011/main.c +++ b/tests/drivers/sds011/main.c @@ -76,7 +76,7 @@ static void _print_measurement(sds011_data_t *data) void measure_cb(sds011_data_t *data, void *ctx) { msg_t msg = { .content.value = (((uint32_t)data->pm_10) << 16 | data->pm_2_5) }; - kernel_pid_t target_pid = (int)ctx; + kernel_pid_t target_pid = (intptr_t)ctx; msg_send(&msg, target_pid); } @@ -194,7 +194,7 @@ int main(void) } } - sds011_register_callback(&dev, measure_cb, (void*)(int)thread_getpid()); + sds011_register_callback(&dev, measure_cb, (void*)(intptr_t)thread_getpid()); printf("switching to active reporting mode for %u measurements...\n", ACTIVE_REPORTING_TEST_CNT); diff --git a/tests/drivers/soft_uart/main.c b/tests/drivers/soft_uart/main.c index d5763a55ade6..95a36e051e36 100644 --- a/tests/drivers/soft_uart/main.c +++ b/tests/drivers/soft_uart/main.c @@ -72,7 +72,7 @@ static int parse_dev(char *arg) static void rx_cb(void *arg, uint8_t data) { - uart_t dev = (soft_uart_t)arg; + uart_t dev = (soft_uart_t)(intptr_t)arg; ringbuffer_add_one(&(ctx[dev].rx_buf), data); if (data == '\n' || ringbuffer_full(&(ctx[dev].rx_buf))) { @@ -139,7 +139,7 @@ static int cmd_init(int argc, char **argv) baud = strtol(argv[2], NULL, 0); /* initialize UART */ - res = soft_uart_init(dev, baud, rx_cb, (void *)dev); + res = soft_uart_init(dev, baud, rx_cb, (void *)(intptr_t)dev); if (res == UART_NOBAUD) { printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud); return 1; @@ -269,7 +269,7 @@ int main(void) "NOTE: all strings need to be '\\n' terminated!\n"); puts("\nUART INFO:"); - printf("Available devices: %i\n", SOFT_UART_NUMOF); + printf("Available devices: %u\n", (unsigned)SOFT_UART_NUMOF); /* initialize ringbuffers */ for (unsigned i = 0; i < SOFT_UART_NUMOF; i++) { diff --git a/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile b/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile index 961e8c010a3f..4026d0a91a77 100644 --- a/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile +++ b/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile @@ -11,6 +11,8 @@ USEMODULE += netdev_test CFLAGS += -DTEST_SUITES +INCLUDES += -I$(RIOTBASE)/sys/net/gnrc/pktbuf_static/include + include $(RIOTBASE)/Makefile.include ifndef CONFIG_GNRC_IPV6_NIB_NO_RTR_SOL diff --git a/tests/net/gnrc_sixlowpan_frag_minfwd/main.c b/tests/net/gnrc_sixlowpan_frag_minfwd/main.c index dfe49089259b..f65e518b48ec 100644 --- a/tests/net/gnrc_sixlowpan_frag_minfwd/main.c +++ b/tests/net/gnrc_sixlowpan_frag_minfwd/main.c @@ -41,6 +41,8 @@ #include "utlist.h" #include "xtimer.h" +#include "pktbuf_static.h" + #define SEND_PACKET_TIMEOUT (500U) #define LOC_L2 { _LL0, _LL1, _LL2, _LL3, _LL4, _LL5, _LL6, _LL7 } @@ -624,12 +626,19 @@ static void test_minfwd_forward__ENOMEM__netif_hdr_build_fail(void) gnrc_pktsnip_t *pkt, *frag, *filled_space; vrbe->super.arrival = xtimer_now_usec(); - TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add( - NULL, NULL, - /* 115U == 2 * sizeof(gnrc_pktsnip_t) + movement due to mark */ - CONFIG_GNRC_PKTBUF_SIZE - sizeof(_test_nth_frag) - 115U, - GNRC_NETTYPE_UNDEF - ))); + + size_t test_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(_test_nth_frag)); + size_t marked_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(sixlowpan_frag_n_t)) + + _align(sizeof(_test_nth_frag) - sizeof(sixlowpan_frag_n_t)); + + /* Calculate the maximum payload size to fill the buffer with the following three packets */ + size_t dummy_pkt_payload_size = CONFIG_GNRC_PKTBUF_SIZE - _align(sizeof(gnrc_pktsnip_t)) + - test_pkt_size - marked_pkt_size; + + TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(NULL, NULL, + dummy_pkt_payload_size, + GNRC_NETTYPE_UNDEF))); + TEST_ASSERT_NOT_NULL((pkt = gnrc_pktbuf_add(NULL, _test_nth_frag, sizeof(_test_nth_frag), GNRC_NETTYPE_SIXLOWPAN))); diff --git a/tests/net/gnrc_sixlowpan_frag_sfr/Makefile b/tests/net/gnrc_sixlowpan_frag_sfr/Makefile index 5fe020e3d7a3..34b4c2146b96 100644 --- a/tests/net/gnrc_sixlowpan_frag_sfr/Makefile +++ b/tests/net/gnrc_sixlowpan_frag_sfr/Makefile @@ -11,6 +11,8 @@ USEMODULE += netdev_test CFLAGS += -DTEST_SUITES +INCLUDES += -I$(RIOTBASE)/sys/net/gnrc/pktbuf_static/include + # microbit qemu failing currently TEST_ON_CI_BLACKLIST += microbit diff --git a/tests/net/gnrc_sixlowpan_frag_sfr/main.c b/tests/net/gnrc_sixlowpan_frag_sfr/main.c index c2e9504ad54d..6310de3cd7d7 100644 --- a/tests/net/gnrc_sixlowpan_frag_sfr/main.c +++ b/tests/net/gnrc_sixlowpan_frag_sfr/main.c @@ -43,6 +43,8 @@ #include "utlist.h" #include "xtimer.h" +#include "pktbuf_static.h" + #define SEND_PACKET_TIMEOUT (500U) #define LOC_L2 { _LL0, _LL1, _LL2, _LL3, _LL4, _LL5, _LL6, _LL7 } @@ -540,12 +542,18 @@ static void test_sfr_forward__ENOMEM__netif_hdr_build_fail(void) ); gnrc_pktsnip_t *pkt, *frag, *filled_space; - TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add( - NULL, NULL, - /* 115U == 2 * sizeof(gnrc_pktsnip_t) + movement due to mark */ - CONFIG_GNRC_PKTBUF_SIZE - sizeof(_test_nth_frag) - 115U, - GNRC_NETTYPE_UNDEF - ))); + size_t test_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(_test_nth_frag)); + size_t marked_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(sixlowpan_frag_n_t)) + + _align(sizeof(_test_nth_frag) - sizeof(sixlowpan_frag_n_t)); + + /* Calculate the maximum payload size to fill the buffer with the following three packets */ + size_t dummy_pkt_payload_size = CONFIG_GNRC_PKTBUF_SIZE - _align(sizeof(gnrc_pktsnip_t)) + - test_pkt_size - marked_pkt_size; + + TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(NULL, NULL, + dummy_pkt_payload_size, + GNRC_NETTYPE_UNDEF))); + TEST_ASSERT_NOT_NULL((pkt = gnrc_pktbuf_add(NULL, _test_nth_frag, sizeof(_test_nth_frag), GNRC_NETTYPE_SIXLOWPAN))); diff --git a/tests/periph/flashpage/main.c b/tests/periph/flashpage/main.c index 3bdc087fdd4c..4f80a653da47 100644 --- a/tests/periph/flashpage/main.c +++ b/tests/periph/flashpage/main.c @@ -204,42 +204,29 @@ static int cmd_write(int argc, char **argv) } #endif -static uint32_t getaddr(const char *str) +static uintptr_t getaddr(const char *str) { - uint32_t addr = strtol(str, NULL, 16); + uintptr_t addr = (uintptr_t)strtol(str, NULL, 16); return addr; } static int cmd_write_raw(int argc, char **argv) { -#if (__SIZEOF_POINTER__ == 2) - uint16_t addr; -#else - uint32_t addr; -#endif + uintptr_t addr; if (argc < 3) { printf("usage: %s \n", argv[0]); return 1; } -#if (__SIZEOF_POINTER__ == 2) - addr = (uint16_t) getaddr(argv[1]); -#else addr = getaddr(argv[1]); -#endif /* try to align */ memcpy(raw_buf, argv[2], strlen(argv[2])); - flashpage_write((void*)addr, raw_buf, strlen(raw_buf)); -#if (__SIZEOF_POINTER__ == 2) - printf("wrote local data to flash address %#" PRIx16 " of len %" PRIuSIZE "\n", + flashpage_write((void*)(uintptr_t)addr, raw_buf, strlen(raw_buf)); + printf("wrote local data to flash address %#" PRIxPTR " of len %" PRIuSIZE "\n", addr, strlen(raw_buf)); -#else - printf("wrote local data to flash address %#" PRIx32 " of len %" PRIuSIZE "\n", - addr, strlen(raw_buf)); -#endif return 0; } diff --git a/tests/periph/flashpage_unittest/main.c b/tests/periph/flashpage_unittest/main.c index 6e3d231e12f1..da530a9e804d 100644 --- a/tests/periph/flashpage_unittest/main.c +++ b/tests/periph/flashpage_unittest/main.c @@ -47,12 +47,12 @@ static void test_flashbase_addr(void) void *addr; addr = flashpage_addr(0); - TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (unsigned int)addr); + TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (uintptr_t)addr); addr = flashpage_addr(FLASHPAGE_NUMOF - 1); TEST_ASSERT_EQUAL_INT((long)CPU_FLASH_BASE + (((unsigned)FLASHPAGE_NUMOF - 1) * FLASHPAGE_SIZE), - (unsigned int)addr); + (uintptr_t)addr); addr = flashpage_addr(12); - TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (unsigned int)addr); + TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (uintptr_t)addr); } static void test_flashbase_page(void) diff --git a/tests/periph/gpio/main.c b/tests/periph/gpio/main.c index 22a78e00cfb1..d6e0cb6dd277 100644 --- a/tests/periph/gpio/main.c +++ b/tests/periph/gpio/main.c @@ -33,7 +33,7 @@ #ifdef MODULE_PERIPH_GPIO_IRQ static void cb(void *arg) { - printf("INT: external interrupt from pin %i\n", (int)arg); + printf("INT: external interrupt from pin %" PRIiPTR "\n", (intptr_t)arg); } #endif @@ -145,7 +145,7 @@ static int init_int(int argc, char **argv) } } - if (gpio_init_int(GPIO_PIN(po, pi), mode, flank, cb, (void *)pi) < 0) { + if (gpio_init_int(GPIO_PIN(po, pi), mode, flank, cb, (void *)(intptr_t)pi) < 0) { printf("error: init_int of GPIO_PIN(%i, %i) failed\n", po, pi); return 1; } diff --git a/tests/periph/timer/main.c b/tests/periph/timer/main.c index 8f2a1626b603..132677dc90c7 100644 --- a/tests/periph/timer/main.c +++ b/tests/periph/timer/main.c @@ -59,7 +59,7 @@ static unsigned args[TIMER_CHANNEL_NUMOF]; static void cb(void *arg, int chan) { timeouts[chan] = sw_count; - args[chan] = (unsigned)arg + chan; + args[chan] = (uintptr_t)arg + chan; fired++; } @@ -104,7 +104,7 @@ static int test_timer(unsigned num, uint32_t timer_freq) printf(" - Calling timer_init(%u, %" PRIu32 ")\n ", num, timer_freq); /* initialize and halt timer */ - if (timer_init(TIMER_DEV(num), timer_freq, cb, (void *)(COOKIE * num)) != 0) { + if (timer_init(TIMER_DEV(num), timer_freq, cb, (void *)(uintptr_t)(COOKIE * num)) != 0) { printf("ERROR: timer_init() failed\n\n"); return 0; } diff --git a/tests/periph/uart/main.c b/tests/periph/uart/main.c index 132f508ea45b..7f9e76e04efa 100644 --- a/tests/periph/uart/main.c +++ b/tests/periph/uart/main.c @@ -238,7 +238,7 @@ static int cmd_init(int argc, char **argv) baud = strtol(argv[2], NULL, 0); /* initialize UART */ - res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)dev); + res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)(intptr_t)dev); if (res == UART_NOBAUD) { printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud); return 1; diff --git a/tests/pkg/cayenne-lpp/main.c b/tests/pkg/cayenne-lpp/main.c index e0f92a9c1eca..ed12968be5d6 100644 --- a/tests/pkg/cayenne-lpp/main.c +++ b/tests/pkg/cayenne-lpp/main.c @@ -24,7 +24,7 @@ #include "cayenne_lpp.h" #define TEST_BUFFER1 { 0x03, 0x67, 0x01, 0x10, 0x05, 0x67, 0x00, 0xff } -#if defined(BOARD_NATIVE) +#if defined(BOARD_NATIVE) && !(__SIZEOF_POINTER__ == 8) #define TEST_BUFFER2 { 0x01, 0x67, 0xFF, 0xD8, \ 0x06, 0x71, 0x04, 0xD1, 0xFB, 0x2F, 0x00, 0x00 } #else diff --git a/tests/pkg/lora-serialization/main.c b/tests/pkg/lora-serialization/main.c index 7986df8a0dd9..cd1e4112a818 100644 --- a/tests/pkg/lora-serialization/main.c +++ b/tests/pkg/lora-serialization/main.c @@ -23,7 +23,7 @@ #include #include "lora_serialization.h" -#if defined(BOARD_NATIVE) +#if defined(BOARD_NATIVE) && !(__SIZEOF_POINTER__ == 8) #define TEST_01_EXPECTED { 0x1f, 0x4c, 0x0e, 0x27 } #define TEST_02_EXPECTED { 0x65, 0xa6, 0xfa, 0xfd, \ 0x6a, 0x24, 0x04, 0x09, \ diff --git a/tests/sys/architecture/Makefile b/tests/sys/architecture/Makefile index 7a7d9d76b500..f2fa71be6520 100644 --- a/tests/sys/architecture/Makefile +++ b/tests/sys/architecture/Makefile @@ -3,6 +3,10 @@ include ../Makefile.sys_common include $(RIOTBASE)/Makefile.include +ifneq (,$(filter arch_64bit,$(FEATURES_USED))) + CFLAGS += -DCORRECT_WORD_BITS=64 +endif + ifneq (,$(filter arch_32bit,$(FEATURES_USED))) CFLAGS += -DCORRECT_WORD_BITS=32 endif diff --git a/tests/sys/cb_mux/main.c b/tests/sys/cb_mux/main.c index 872834ed7b57..be81ab75ce27 100644 --- a/tests/sys/cb_mux/main.c +++ b/tests/sys/cb_mux/main.c @@ -53,7 +53,7 @@ int main(void) for (num = 0; num < 5; num++) { entries[num].cb = cb; - entries[num].arg = (void *)num; + entries[num].arg = (void *)(uintptr_t)num; entries[num].cbid = num; } @@ -114,7 +114,7 @@ int main(void) while (num < 5) { cb_mux_add(&cb_mux_head, &(entries[num])); - printf("Added entry %i\n", num); + printf("Added entry %u\n", (unsigned)num); num = cb_mux_find_free_id(cb_mux_head); } @@ -125,7 +125,7 @@ int main(void) for (num = 0; num < 5; num++) { if ((uintptr_t)entries[num].info & (1 << ITER_TEST)) { - printf("Entry %i was updated correctly\n", num); + printf("Entry %u was updated correctly\n", (unsigned)num); } } diff --git a/tests/sys/conn_can/main.c b/tests/sys/conn_can/main.c index 637755be5de9..246b603119f1 100644 --- a/tests/sys/conn_can/main.c +++ b/tests/sys/conn_can/main.c @@ -592,7 +592,7 @@ static int _can_handler(int argc, char **argv) static void *_receive_thread(void *args) { - int thread_nb = (int)args; + int thread_nb = (intptr_t)args; struct can_frame frame; msg_t msg, msg_queue[RECEIVE_THREAD_MSG_QUEUE_SIZE]; @@ -729,7 +729,7 @@ static const shell_command_t _commands[] = { int main(void) { - for (int i = 0; i < RCV_THREAD_NUMOF; i++) { + for (intptr_t i = 0; i < RCV_THREAD_NUMOF; i++) { receive_pid[i] = thread_create(thread_stack[i], THREAD_STACKSIZE, THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, _receive_thread, diff --git a/tests/sys/events/main.c b/tests/sys/events/main.c index ee5c038f7ebf..ed7f4442bb09 100644 --- a/tests/sys/events/main.c +++ b/tests/sys/events/main.c @@ -62,7 +62,7 @@ static void callback(event_t *arg) order++; expect(order == 4); expect(arg == &event); - printf("triggered 0x%08x\n", (unsigned)arg); + printf("triggered 0x%08" PRIxPTR "\n", (uintptr_t)arg); } typedef struct { @@ -94,7 +94,8 @@ static void timed_callback(void *arg) uint32_t now = xtimer_now_usec(); #endif expect((now - before >= 100000LU)); - printf("triggered timed callback with arg 0x%08x after %" PRIu32 "us\n", (unsigned)arg, now - before); + printf("triggered timed callback with arg 0x%08" PRIxPTR " after %" PRIu32 "us\n", + (uintptr_t)arg, now - before); puts("[SUCCESS]"); } @@ -176,12 +177,12 @@ int main(void) /* test posting different kind of events in order to a statically * initialized queue */ event_queue_t queue = EVENT_QUEUE_INIT; - printf("posting 0x%08x\n", (unsigned)&event); + printf("posting 0x%08" PRIxPTR "\n", (uintptr_t)&event); event_post(&queue, &event); - printf("posting 0x%08x\n", (unsigned)&event2); + printf("posting 0x%08" PRIxPTR "\n", (uintptr_t)&event2); event_post(&queue, &event2); - printf("canceling 0x%08x\n", (unsigned)&event2); + printf("canceling 0x%08" PRIxPTR "\n", (uintptr_t)&event2); event_cancel(&queue, &event2); puts("posting custom event"); diff --git a/tests/sys/heap_cmd/main.c b/tests/sys/heap_cmd/main.c index 8fb24e4520f5..49faf781425a 100644 --- a/tests/sys/heap_cmd/main.c +++ b/tests/sys/heap_cmd/main.c @@ -41,7 +41,7 @@ static int free_cmd(int argc, char **argv) return 1; } - unsigned int p = strtoul(argv[1], NULL, 16); + uintptr_t p = strtoul(argv[1], NULL, 16); void *ptr = (void *)p; printf("freeing %p\n", ptr); free(ptr); diff --git a/tests/sys/ps_schedstatistics/main.c b/tests/sys/ps_schedstatistics/main.c index a4990c8aef98..308c891d4d01 100644 --- a/tests/sys/ps_schedstatistics/main.c +++ b/tests/sys/ps_schedstatistics/main.c @@ -36,9 +36,9 @@ static kernel_pid_t pids[NB_THREADS]; static void *_thread_fn(void *arg) { - int next = ((int)arg + 1) % NB_THREADS; + int next = ((uintptr_t)arg + 1) % NB_THREADS; - printf("Creating thread #%d, next=%d\n", (int)arg, next); + printf("Creating thread #%" PRIuPTR ", next=%d\n", (uintptr_t)arg, next); while (1) { msg_t m1, m2; @@ -59,7 +59,7 @@ int main(void) { test_utils_interactive_sync(); - for (unsigned i = 0; i < NB_THREADS; ++i) { + for (uintptr_t i = 0; i < NB_THREADS; ++i) { pids[i] = thread_create(stacks[i], sizeof(stacks[i]), THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, diff --git a/tests/sys/pthread_cooperation/main.c b/tests/sys/pthread_cooperation/main.c index b12357de16d9..1c0098d94352 100644 --- a/tests/sys/pthread_cooperation/main.c +++ b/tests/sys/pthread_cooperation/main.c @@ -32,7 +32,7 @@ volatile uint32_t storage = 1; void *run(void *parameter) { - int arg = (int) parameter; + int arg = (intptr_t) parameter; printf("My arg: %d\n", arg); int err = pthread_mutex_lock(&mtx); @@ -56,8 +56,8 @@ int main(void) pthread_attr_init(&th_attr); pthread_mutex_init(&mtx, NULL); - for (int i = 0; i < NUM_THREADS; ++i) { - printf("Creating thread with arg %d\n", (i + 1)); + for (intptr_t i = 0; i < NUM_THREADS; ++i) { + printf("Creating thread with arg %" PRIdPTR "\n", (i + 1)); pthread_create(&ths[i], &th_attr, run, (void *)(i + 1)); } diff --git a/tests/sys/pthread_tls/main.c b/tests/sys/pthread_tls/main.c index 2c1f59be997f..c45e692b6e66 100644 --- a/tests/sys/pthread_tls/main.c +++ b/tests/sys/pthread_tls/main.c @@ -45,8 +45,8 @@ void *run(void *parameter) aTLS_values[i]++; } - printf("pick deliberate storage (key[3]:%d) and change the value\n", - (int)aKeys[3]); + printf("pick deliberate storage (key[3]:%" PRIuPTR ") and change the value\n", + (uintptr_t)aKeys[3]); void *val = pthread_getspecific(aKeys[3]); *((int *)val) = 42; @@ -55,11 +55,11 @@ void *run(void *parameter) for (int i = 0; i < NUMBER_OF_TLS; ++i) { void *val = pthread_getspecific(aKeys[i]); int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } - printf("\n -= TEST 2 - delete deliberate key (key[5]:%d) =-\n", - (int)aKeys[5]); + printf("\n -= TEST 2 - delete deliberate key (key[5]:%" PRIuPTR ") =-\n", + (uintptr_t)aKeys[5]); pthread_key_delete(aKeys[5]); puts("show tls values:"); @@ -69,7 +69,7 @@ void *run(void *parameter) if (val != NULL) { int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } } @@ -80,7 +80,7 @@ void *run(void *parameter) pthread_key_create(&new_key, NULL); pthread_setspecific(new_key, &new_val); - printf("added new tls, key: %d, val: %d\n", (int)new_key, new_val); + printf("added new tls, key: %" PRIuPTR ", val: %d\n", (uintptr_t)new_key, new_val); printf("show tls values:\n"); for (int i = 0; i < NUMBER_OF_TLS; ++i) { @@ -88,7 +88,7 @@ void *run(void *parameter) if (val != NULL) { int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } } @@ -106,7 +106,7 @@ void *run(void *parameter) if (val != NULL) { int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } } @@ -119,13 +119,13 @@ void *run(void *parameter) puts("-= TEST 6 - add key and delete without a tls =-"); pthread_key_create(&new_key, NULL); - printf("created key: %d\n", (int)new_key); + printf("created key: %" PRIuPTR "\n", (uintptr_t)new_key); printf("try to delete returns: %d\n", pthread_key_delete(new_key)); puts(""); puts("-= TEST 7 - add key without tls =-"); pthread_key_create(&new_key, NULL); - printf("created key: %d\n", (int)new_key); + printf("created key: %" PRIuPTR "\n", (uintptr_t)new_key); void* test_7_val = pthread_getspecific(new_key); printf("test_7_val: %p\n", test_7_val); diff --git a/tests/unittests/tests-pktbuf/tests-pktbuf.c b/tests/unittests/tests-pktbuf/tests-pktbuf.c index f1abee38d4b1..a78fd16c84b2 100644 --- a/tests/unittests/tests-pktbuf/tests-pktbuf.c +++ b/tests/unittests/tests-pktbuf/tests-pktbuf.c @@ -25,6 +25,8 @@ #include "unittests-constants.h" #include "tests-pktbuf.h" +#define ALIGNMENT_SIZE (2 * sizeof(uintptr_t)) + typedef struct __attribute__((packed)) { uint8_t u8; uint16_t u16; @@ -250,14 +252,14 @@ static void test_pktbuf_add__packed_struct(void) #ifndef MODULE_GNRC_PKTBUF_MALLOC /* alignment-handling left to malloc, so no certainty here */ static void test_pktbuf_add__unaligned_in_aligned_hole(void) { - gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(NULL, NULL, 8, GNRC_NETTYPE_TEST); - gnrc_pktsnip_t *pkt2 = gnrc_pktbuf_add(NULL, NULL, 8, GNRC_NETTYPE_TEST); - gnrc_pktsnip_t *pkt3 = gnrc_pktbuf_add(NULL, NULL, 8, GNRC_NETTYPE_TEST); + gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(NULL, NULL, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); + gnrc_pktsnip_t *pkt2 = gnrc_pktbuf_add(NULL, NULL, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); + gnrc_pktsnip_t *pkt3 = gnrc_pktbuf_add(NULL, NULL, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); gnrc_pktsnip_t *pkt4; void *tmp_data2 = pkt2->data; gnrc_pktbuf_release(pkt2); - pkt4 = gnrc_pktbuf_add(NULL, TEST_STRING12, 9, GNRC_NETTYPE_TEST); + pkt4 = gnrc_pktbuf_add(NULL, TEST_STRING64, ALIGNMENT_SIZE + 1, GNRC_NETTYPE_TEST); TEST_ASSERT(tmp_data2 != pkt4->data); @@ -820,14 +822,14 @@ static void test_pktbuf_start_write__pkt_users_2(void) static void test_pktbuf_reverse_snips__too_full(void) { gnrc_pktsnip_t *pkt, *pkt_next, *pkt_huge; - const size_t pkt_huge_size = CONFIG_GNRC_PKTBUF_SIZE - (3 * 8) - + const size_t pkt_huge_size = CONFIG_GNRC_PKTBUF_SIZE - (3 * ALIGNMENT_SIZE) - (3 * sizeof(gnrc_pktsnip_t)) - 4; - pkt_next = gnrc_pktbuf_add(NULL, TEST_STRING8, 8, GNRC_NETTYPE_TEST); + pkt_next = gnrc_pktbuf_add(NULL, TEST_STRING16, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt_next); /* hold to enforce duplication */ gnrc_pktbuf_hold(pkt_next, 1); - pkt = gnrc_pktbuf_add(pkt_next, TEST_STRING8, 8, GNRC_NETTYPE_TEST); + pkt = gnrc_pktbuf_add(pkt_next, TEST_STRING16, 8, GNRC_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt); /* filling up rest of packet buffer */ pkt_huge = gnrc_pktbuf_add(NULL, NULL, pkt_huge_size, GNRC_NETTYPE_UNDEF); From a26b1e775c27dbb78ef7ad2e0e6556750812eae1 Mon Sep 17 00:00:00 2001 From: Frederik Haxel Date: Wed, 16 Aug 2023 13:29:16 +0200 Subject: [PATCH 2/3] lua: Increased LUA_MEM_SIZE for 64 bit --- examples/lua_basic/main.c | 4 ++++ tests/pkg/lua_loader/main.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/examples/lua_basic/main.c b/examples/lua_basic/main.c index 5d71fbca9fed..ba1ba378259d 100644 --- a/examples/lua_basic/main.c +++ b/examples/lua_basic/main.c @@ -27,7 +27,11 @@ #include "blob/main.lua.h" +#if (__SIZEOF_POINTER__ == 8) +#define LUA_MEM_SIZE (22000) +#else #define LUA_MEM_SIZE (11000) +#endif static char lua_mem[LUA_MEM_SIZE] __attribute__ ((aligned(__BIGGEST_ALIGNMENT__))); int lua_run_script(const uint8_t *buffer, size_t buffer_len) diff --git a/tests/pkg/lua_loader/main.c b/tests/pkg/lua_loader/main.c index 41f51e6264f1..889546bcc44f 100644 --- a/tests/pkg/lua_loader/main.c +++ b/tests/pkg/lua_loader/main.c @@ -69,7 +69,11 @@ const size_t lua_riot_builtin_lua_table_len = const size_t lua_riot_builtin_c_table_len = ARRAY_SIZE(_lua_riot_builtin_c_table); +#if (__SIZEOF_POINTER__ == 8) +#define LUA_MEM_SIZE (22000) +#else #define LUA_MEM_SIZE (11000) +#endif static char lua_mem[LUA_MEM_SIZE] __attribute__ ((aligned(__BIGGEST_ALIGNMENT__))); #define LINEBUF_SZ (32) From 542abe7ed661a5757c51ba31078782e793e1138d Mon Sep 17 00:00:00 2001 From: Frederik Haxel Date: Fri, 8 Dec 2023 11:22:32 +0100 Subject: [PATCH 3/3] native: 64 bit compatibility and Linux/x86_64 support for the native Initial version to test 64 bit compatibility. Instead of a separate board, 64 bit for Linux/x86_64 is enabled by setting the environment variable `NATIVE_64BIT=y` and compiling as usual. While I personally prefer a separate `native64` board, this ensures that all tests run with the same configuration as the 32 bit version. A separate board would require a major refactoring of many tests, which often have special behavior for the native board, and I didn't want to increase the size of an already large pull request. Not currently implemented: * Architectures other than x86_64 or operating systems other than Linux * No FreeBSD support * No Aarch support * Rust support for x86_64 --- boards/native/Makefile.include | 27 ++++++++-- boards/native/doc.txt | 3 +- cpu/native/Kconfig | 5 +- cpu/native/Makefile.features | 11 +++- cpu/native/Makefile.include | 6 ++- cpu/native/include/architecture_arch.h | 4 ++ cpu/native/include/c11_atomics_compat_cpu.hpp | 33 +++++++++++- cpu/native/include/native_internal.h | 7 +-- cpu/native/irq_cpu.c | 13 +++-- cpu/native/native_cpu.c | 15 ++++-- cpu/native/periph/flashpage.c | 4 +- cpu/native/periph/spidev_linux.c | 2 +- cpu/native/periph/timer.c | 5 +- cpu/native/socket_zep/socket_zep.c | 6 +-- cpu/native/syscalls.c | 14 ++++- cpu/native/tramp.S | 54 +++++++++++++++++++ pkg/wamr/Makefile | 6 ++- 17 files changed, 181 insertions(+), 34 deletions(-) diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index f17eab6cf3d3..df4f5583af9e 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -4,6 +4,9 @@ NATIVEINCLUDES += -I$(RIOTBASE)/core/lib/include/ NATIVEINCLUDES += -I$(RIOTBASE)/core/include/ NATIVEINCLUDES += -I$(RIOTBASE)/drivers/include/ +# Set "NATIVE_64BIT=y" to compile for x86_64 +NATIVE_64BIT ?= n + ifeq ($(OS),Darwin) DEBUGGER ?= lldb else @@ -50,14 +53,22 @@ ifeq (,$(filter -std=%, $(CFLAGS))) endif ifeq ($(OS_ARCH),x86_64) - CFLAGS += -m32 + ifeq ($(NATIVE_64BIT), y) + CFLAGS += -m64 + else + CFLAGS += -m32 + endif endif ifneq (,$(filter -DDEVELHELP,$(CFLAGS))) CFLAGS += -fstack-protector-all endif ifeq ($(OS),FreeBSD) ifeq ($(OS_ARCH),amd64) - CFLAGS += -m32 -DCOMPAT_32BIT -B/usr/lib32 + ifeq ($(NATIVE_64BIT), y) + CFLAGS += -m64 + else + CFLAGS += -m32 -DCOMPAT_32BIT -B/usr/lib32 + endif endif endif ifeq ($(OS),Darwin) @@ -69,11 +80,19 @@ CXXUWFLAGS += CXXEXFLAGS += ifeq ($(OS_ARCH),x86_64) - LINKFLAGS += -m32 + ifeq ($(NATIVE_64BIT), y) + LINKFLAGS += -m64 + else + LINKFLAGS += -m32 + endif endif ifeq ($(OS),FreeBSD) ifeq ($(OS_ARCH),amd64) - LINKFLAGS += -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 + ifeq ($(NATIVE_64BIT), y) + LINKFLAGS += -m64 + else + LINKFLAGS += -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 + endif endif LINKFLAGS += -L $(BINDIR) else diff --git a/boards/native/doc.txt b/boards/native/doc.txt index cb955d90877d..9293915eb151 100644 --- a/boards/native/doc.txt +++ b/boards/native/doc.txt @@ -25,7 +25,8 @@ # Required packages -The `native` version of RIOT will produce a 32 bit binary. +The `native` version of RIOT will produce a 32 bit binary by default. +To compile for x86_64 set the environment variable `NATIVE_64BIT=y`. On Debian/Ubuntu you can install the required libraries with ``` diff --git a/cpu/native/Kconfig b/cpu/native/Kconfig index c3733c1007be..8123fbb3c0c7 100644 --- a/cpu/native/Kconfig +++ b/cpu/native/Kconfig @@ -7,7 +7,8 @@ config CPU_ARCH_NATIVE bool - select HAS_ARCH_32BIT + select HAS_ARCH_32BIT if "$(NATIVE_64BIT)" != "y" + select HAS_ARCH_64BIT if "$(NATIVE_64BIT)" = "y" select HAS_ARCH_NATIVE select HAS_CPP select HAS_CPU_NATIVE @@ -59,7 +60,7 @@ config NATIVE_OS_LINUX select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ select HAS_PERIPH_SPI - select HAS_RUST_TARGET if "$(OS_ARCH)" = "x86_64" + select HAS_RUST_TARGET if "$(OS_ARCH)" = "x86_64" && HAS_ARCH_32BIT config NATIVE_OS_FREEBSD bool diff --git a/cpu/native/Makefile.features b/cpu/native/Makefile.features index 14f89d59fb99..4eaaaa9f6a8a 100644 --- a/cpu/native/Makefile.features +++ b/cpu/native/Makefile.features @@ -2,7 +2,11 @@ ifeq (FreeBSD,$(OS)) DISABLE_LIBSTDCPP ?= 1 endif -FEATURES_PROVIDED += arch_32bit +ifeq ($(NATIVE_64BIT), y) + FEATURES_PROVIDED += arch_64bit +else + FEATURES_PROVIDED += arch_32bit +endif FEATURES_PROVIDED += arch_native FEATURES_PROVIDED += cpp ifneq ($(DISABLE_LIBSTDCPP),1) @@ -19,7 +23,10 @@ FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_timer_periodic ifeq ($(OS) $(OS_ARCH),Linux x86_64) - FEATURES_PROVIDED += rust_target + # TODO: Add rust support for native 64 bit. + ifneq ($(NATIVE_64BIT), y) + FEATURES_PROVIDED += rust_target + endif endif FEATURES_PROVIDED += ssp diff --git a/cpu/native/Makefile.include b/cpu/native/Makefile.include index 5a18218c5731..c664b9cb15a3 100644 --- a/cpu/native/Makefile.include +++ b/cpu/native/Makefile.include @@ -11,5 +11,9 @@ TOOLCHAINS_SUPPORTED = gnu llvm afl # Platform triple as used by Rust ifeq ($(OS) $(OS_ARCH),Linux x86_64) - RUST_TARGET = i686-unknown-linux-gnu + ifneq (,$(filter arch_32bit,$(FEATURES_USED))) + RUST_TARGET = i686-unknown-linux-gnu + else + RUST_TARGET = x86_64-unknown-linux-gnu + endif endif diff --git a/cpu/native/include/architecture_arch.h b/cpu/native/include/architecture_arch.h index 1a9f7ae06db8..604dd08b3972 100644 --- a/cpu/native/include/architecture_arch.h +++ b/cpu/native/include/architecture_arch.h @@ -33,7 +33,11 @@ void native_breakpoint(void); /* Doc is provided centrally in architecture.h, hide this from Doxygen */ #ifndef DOXYGEN +#if (__SIZEOF_POINTER__ == 8) +#define ARCHITECTURE_WORD_BITS (64U) +#else #define ARCHITECTURE_WORD_BITS (32U) +#endif #define ARCHITECTURE_BREAKPOINT(v) native_breakpoint() #endif /* DOXYGEN */ diff --git a/cpu/native/include/c11_atomics_compat_cpu.hpp b/cpu/native/include/c11_atomics_compat_cpu.hpp index ae589ea28fb8..c83f32617a8d 100644 --- a/cpu/native/include/c11_atomics_compat_cpu.hpp +++ b/cpu/native/include/c11_atomics_compat_cpu.hpp @@ -1,4 +1,8 @@ -/* This file was automatically generated using ./dist/tools/generate_c11_atomics_cpp_compat_header/generate_c11_atomics_cpp_compat_header.sh */ +/** + * This file was generated using + * ./dist/tools/generate_c11_atomics_cpp_compat_header/generate_c11_atomics_cpp_compat_header.sh + * for 32 and 64 bit and merged manually. + */ #pragma once #define ATOMIC_BOOL_SIZE (1U) @@ -17,10 +21,17 @@ #define ATOMIC_INT_SAME_SIZED_TYPE uint32_t #define ATOMIC_UINT_SIZE (4U) #define ATOMIC_UINT_SAME_SIZED_TYPE uint32_t +#ifdef __x86_64__ +#define ATOMIC_LONG_SIZE (8U) +#define ATOMIC_LONG_SAME_SIZED_TYPE uint64_t +#define ATOMIC_ULONG_SIZE (8U) +#define ATOMIC_ULONG_SAME_SIZED_TYPE uint64_t +#else #define ATOMIC_LONG_SIZE (4U) #define ATOMIC_LONG_SAME_SIZED_TYPE uint32_t #define ATOMIC_ULONG_SIZE (4U) #define ATOMIC_ULONG_SAME_SIZED_TYPE uint32_t +#endif #define ATOMIC_LLONG_SIZE (8U) #define ATOMIC_LLONG_SAME_SIZED_TYPE uint64_t #define ATOMIC_ULLONG_SIZE (8U) @@ -52,6 +63,16 @@ #define ATOMIC_UINT_FAST8_T_SIZE (1U) #define ATOMIC_UINT_FAST8_T_SAME_SIZED_TYPE uint8_t #endif +#ifdef __x86_64__ +#define ATOMIC_INT_FAST16_T_SIZE (8U) +#define ATOMIC_INT_FAST16_T_SAME_SIZED_TYPE uint64_t +#define ATOMIC_UINT_FAST16_T_SIZE (8U) +#define ATOMIC_UINT_FAST16_T_SAME_SIZED_TYPE uint64_t +#define ATOMIC_INT_FAST32_T_SIZE (8U) +#define ATOMIC_INT_FAST32_T_SAME_SIZED_TYPE uint64_t +#define ATOMIC_UINT_FAST32_T_SIZE (8U) +#define ATOMIC_UINT_FAST32_T_SAME_SIZED_TYPE uint64_t +#else #define ATOMIC_INT_FAST16_T_SIZE (4U) #define ATOMIC_INT_FAST16_T_SAME_SIZED_TYPE uint32_t #define ATOMIC_UINT_FAST16_T_SIZE (4U) @@ -60,16 +81,26 @@ #define ATOMIC_INT_FAST32_T_SAME_SIZED_TYPE uint32_t #define ATOMIC_UINT_FAST32_T_SIZE (4U) #define ATOMIC_UINT_FAST32_T_SAME_SIZED_TYPE uint32_t +#endif #define ATOMIC_INT_FAST64_T_SIZE (8U) #define ATOMIC_INT_FAST64_T_SAME_SIZED_TYPE uint64_t #define ATOMIC_UINT_FAST64_T_SIZE (8U) #define ATOMIC_UINT_FAST64_T_SAME_SIZED_TYPE uint64_t +#ifdef __x86_64__ +#define ATOMIC_INTPTR_T_SIZE (8U) +#define ATOMIC_INTPTR_T_SAME_SIZED_TYPE uint64_t +#define ATOMIC_UINTPTR_T_SIZE (8U) +#define ATOMIC_UINTPTR_T_SAME_SIZED_TYPE uint64_t +#define ATOMIC_SIZE_T_SIZE (8U) +#define ATOMIC_SIZE_T_SAME_SIZED_TYPE uint64_t +#else #define ATOMIC_INTPTR_T_SIZE (4U) #define ATOMIC_INTPTR_T_SAME_SIZED_TYPE uint32_t #define ATOMIC_UINTPTR_T_SIZE (4U) #define ATOMIC_UINTPTR_T_SAME_SIZED_TYPE uint32_t #define ATOMIC_SIZE_T_SIZE (4U) #define ATOMIC_SIZE_T_SAME_SIZED_TYPE uint32_t +#endif #define ATOMIC_PTRDIFF_T_SIZE (8U) #define ATOMIC_PTRDIFF_T_SAME_SIZED_TYPE uint64_t #define ATOMIC_INTMAX_T_SIZE (8U) diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index aab4da6c9eaf..eff3c135fc52 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -32,6 +32,7 @@ #include #include +#include #include /* enable signal handler register access on different platforms * check here for more: @@ -111,7 +112,7 @@ extern int (*real_accept)(int socket, ...); /* The ... is a hack to save includes: */ extern int (*real_bind)(int socket, ...); extern int (*real_connect)(int socket, ...); -extern int (*real_recv)(int sockfd, void *buf, size_t len, int flags); +extern ssize_t (*real_recv)(int sockfd, void *buf, size_t len, int flags); extern int (*real_chdir)(const char *path); extern int (*real_close)(int); extern int (*real_fcntl)(int, int, ...); @@ -127,7 +128,7 @@ extern int (*real_getaddrinfo)(const char *node, ...); extern int (*real_getifaddrs)(struct ifaddrs **ifap); extern int (*real_getpid)(void); extern int (*real_gettimeofday)(struct timeval *t, ...); -extern int (*real_ioctl)(int fildes, int request, ...); +extern int (*real_ioctl)(int fildes, unsigned long request, ...); extern int (*real_listen)(int socket, int backlog); extern int (*real_open)(const char *path, int oflag, ...); extern int (*real_mkdir)(const char *pathname, mode_t mode); @@ -164,7 +165,7 @@ extern ssize_t (*real_send)(int sockfd, const void *buf, size_t len, int flags); * data structures */ extern volatile int native_interrupts_enabled; -extern volatile unsigned int _native_saved_eip; +extern volatile uintptr_t _native_saved_eip; extern int _sig_pipefd[2]; extern volatile int _native_sigpend; extern volatile int _native_in_isr; diff --git a/cpu/native/irq_cpu.c b/cpu/native/irq_cpu.c index ff5a90d60131..165a6eeb6bc7 100644 --- a/cpu/native/irq_cpu.c +++ b/cpu/native/irq_cpu.c @@ -25,7 +25,7 @@ #include #define VALGRIND_DEBUG DEBUG #else -#define VALGRIND_STACK_REGISTER(...) +#define VALGRIND_STACK_REGISTER(...) (0) #define VALGRIND_DEBUG(...) #endif @@ -53,7 +53,7 @@ char __isr_stack[SIGSTKSZ]; ucontext_t native_isr_context; ucontext_t *_native_cur_ctx, *_native_isr_ctx; -volatile unsigned int _native_saved_eip; +volatile uintptr_t _native_saved_eip; volatile int _native_sigpend; int _sig_pipefd[2]; @@ -353,9 +353,14 @@ void native_isr_entry(int sig, siginfo_t *info, void *context) _native_saved_eip = ((ucontext_t *)context)->uc_mcontext.arm_pc; ((ucontext_t *)context)->uc_mcontext.arm_pc = (unsigned int)&_native_sig_leave_tramp; #else /* Linux/x86 */ + #ifdef __x86_64__ + _native_saved_eip = ((ucontext_t *)context)->uc_mcontext.gregs[REG_RIP]; + ((ucontext_t *)context)->uc_mcontext.gregs[REG_RIP] = (uintptr_t)&_native_sig_leave_tramp; + #else //printf("\n\033[31mEIP:\t%p\ngo switching\n\n\033[0m", (void*)((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP]); _native_saved_eip = ((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP]; ((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_tramp; + #endif #endif #endif } @@ -466,9 +471,9 @@ void native_interrupt_init(void) struct sigaction sa; DEBUG("native_interrupt_init\n"); - VALGRIND_STACK_REGISTER(__isr_stack, __isr_stack + sizeof(__isr_stack)); + (void) VALGRIND_STACK_REGISTER(__isr_stack, __isr_stack + sizeof(__isr_stack)); VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n", - (void *)__isr_stack, (void*)((int)__isr_stack + sizeof(__isr_stack))); + (void *)__isr_stack, (void*)(__isr_stack + sizeof(__isr_stack))); _native_sigpend = 0; diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index 13fff4e2c414..96956b74d317 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -39,7 +39,7 @@ #include #define VALGRIND_DEBUG DEBUG #else -#define VALGRIND_STACK_REGISTER(...) +#define VALGRIND_STACK_REGISTER(...) (0) #define VALGRIND_DEBUG(...) #endif @@ -77,8 +77,13 @@ static void _native_mod_ctx_leave_sigh(ucontext_t *ctx) _native_saved_eip = ((ucontext_t *)ctx)->uc_mcontext.arm_pc; ((ucontext_t *)ctx)->uc_mcontext.arm_pc = (unsigned int)&_native_sig_leave_handler; #else /* Linux/x86 */ + #ifdef __x86_64__ + _native_saved_eip = ctx->uc_mcontext.gregs[REG_RIP]; + ctx->uc_mcontext.gregs[REG_RIP] = (unsigned long)&_native_sig_leave_handler; + #else _native_saved_eip = ctx->uc_mcontext.gregs[REG_EIP]; ctx->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_handler; + #endif #endif #endif } @@ -122,9 +127,9 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta stack_start = align_stack((uintptr_t)stack_start, &stacksize); - VALGRIND_STACK_REGISTER(stack_start, (char *)stack_start + stacksize); + (void) VALGRIND_STACK_REGISTER(stack_start, (char *)stack_start + stacksize); VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n", - stack_start, (void*)((int)stack_start + stacksize)); + stack_start, (void*)((char *)stack_start + stacksize)); DEBUG("thread_stack_init\n"); @@ -261,9 +266,9 @@ void native_cpu_init(void) end_context.uc_stack.ss_size = SIGSTKSZ; end_context.uc_stack.ss_flags = 0; makecontext(&end_context, sched_task_exit, 0); - VALGRIND_STACK_REGISTER(__end_stack, __end_stack + sizeof(__end_stack)); + (void) VALGRIND_STACK_REGISTER(__end_stack, __end_stack + sizeof(__end_stack)); VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n", - (void*)__end_stack, (void*)((int)__end_stack + sizeof(__end_stack))); + (void*)__end_stack, (void*)(__end_stack + sizeof(__end_stack))); DEBUG("RIOT native cpu initialized.\n"); } diff --git a/cpu/native/periph/flashpage.c b/cpu/native/periph/flashpage.c index 87bca15699df..e625886f5743 100644 --- a/cpu/native/periph/flashpage.c +++ b/cpu/native/periph/flashpage.c @@ -55,9 +55,9 @@ void flashpage_write(void *target_addr, const void *data, size_t len) assert((uintptr_t)target_addr >= (uintptr_t)_native_flash); assert((uintptr_t)target_addr + len <= (uintptr_t)_native_flash + sizeof(_native_flash)); assert(!(len % FLASHPAGE_WRITE_BLOCK_SIZE)); - assert(!((unsigned)target_addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT)); + assert(!((uintptr_t)target_addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT)); - DEBUG("%p: write %u bytes\n", target_addr, len); + DEBUG("%p: write %zu bytes\n", target_addr, len); _flash_write(target_addr, data, len); } diff --git a/cpu/native/periph/spidev_linux.c b/cpu/native/periph/spidev_linux.c index 7cb94cd28ca4..f5f0d290827c 100644 --- a/cpu/native/periph/spidev_linux.c +++ b/cpu/native/periph/spidev_linux.c @@ -320,7 +320,7 @@ void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont, DEBUG("spi_transfer_bytes: ioctl failed\n"); } else { - DEBUG("spi_transfer_bytes: transferred %u bytes\n", len); + DEBUG("spi_transfer_bytes: transferred %zu bytes\n", len); } #ifdef MODULE_PERIPH_GPIO diff --git a/cpu/native/periph/timer.c b/cpu/native/periph/timer.c index e275dc5574e2..938ca0a5bde3 100644 --- a/cpu/native/periph/timer.c +++ b/cpu/native/periph/timer.c @@ -121,7 +121,8 @@ static void do_timer_set(unsigned int offset, bool periodic) its.it_interval = its.it_value; } - DEBUG("timer_set(): setting %lu.%09lu\n", (unsigned long)its.it_value.tv_sec, its.it_value.tv_nsec); + DEBUG("timer_set(): setting %lu.%09lu\n", (unsigned long)its.it_value.tv_sec, + (unsigned long)its.it_value.tv_nsec); } int timer_set(tim_t dev, int channel, unsigned int offset) @@ -144,7 +145,7 @@ int timer_set(tim_t dev, int channel, unsigned int offset) int timer_set_absolute(tim_t dev, int channel, unsigned int value) { - uint32_t now = timer_read(dev); + unsigned int now = timer_read(dev); return timer_set(dev, channel, value - now); } diff --git a/cpu/native/socket_zep/socket_zep.c b/cpu/native/socket_zep/socket_zep.c index 54ced2aee1e0..ea5617de5a70 100644 --- a/cpu/native/socket_zep/socket_zep.c +++ b/cpu/native/socket_zep/socket_zep.c @@ -409,7 +409,7 @@ static int _request_transmit(ieee802154_dev_t *dev) { socket_zep_t *zepdev = dev->priv; - DEBUG("socket_zep::request_transmit(%zu bytes)\n", zepdev->snd_len); + DEBUG("socket_zep::request_transmit(%u bytes)\n", zepdev->snd_len); dev->cb(dev, IEEE802154_RADIO_INDICATION_TX_START); @@ -448,7 +448,7 @@ int _len(ieee802154_dev_t *dev) } if (res < (int)sizeof(zep_v2_data_hdr_t)) { - DEBUG("socket_zep::len discard short frame (%zu bytes)\n", res); + DEBUG("socket_zep::len discard short frame (%u bytes)\n", res); return 0; } @@ -491,7 +491,7 @@ static int _read(ieee802154_dev_t *dev, void *buf, size_t max_size, socket_zep_t *zepdev = dev->priv; size_t frame_len = max_size + sizeof(zep_v2_data_hdr_t) + 2; - DEBUG("socket_zep::read: reading up to %u bytes into %p\n", max_size, buf); + DEBUG("socket_zep::read: reading up to %zu bytes into %p\n", max_size, buf); if (frame_len > sizeof(zepdev->rcv_buf)) { DEBUG("socket_zep::read: frame size (%zu) exceeds RX buffer (%zu bytes)\n", diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index 82de52e303f1..382183d23aa7 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -82,7 +82,7 @@ int (*real_fork)(void); int (*real_feof)(FILE *stream); int (*real_ferror)(FILE *stream); int (*real_listen)(int socket, int backlog); -int (*real_ioctl)(int fildes, int request, ...); +int (*real_ioctl)(int fildes, unsigned long request, ...); int (*real_open)(const char *path, int oflag, ...); int (*real_pause)(void); int (*real_pipe)(int[2]); @@ -334,29 +334,39 @@ int getc(FILE *fp) __attribute__((__format__ (__printf__, 1, 0))) char *make_message(const char *format, va_list argp) { - int size = 100; + int size = 128; char *message, *temp; if ((message = malloc(size)) == NULL) { return NULL; } + /* argp is undefined after calling vsnprintf, so we copy the list first */ + va_list argp_copy; + va_copy(argp_copy, argp); + while (1) { int n = vsnprintf(message, size, format, argp); if (n < 0) { free(message); + va_end(argp_copy); return NULL; } if (n < size) { + va_end(argp_copy); return message; } size = n + 1; if ((temp = realloc(message, size)) == NULL) { free(message); + va_end(argp_copy); return NULL; } else { message = temp; + /* copy the list back and try again */ + va_end(argp); + va_copy(argp, argp_copy); } } } diff --git a/cpu/native/tramp.S b/cpu/native/tramp.S index 86a16ad02bcd..0a3c1233a6a9 100644 --- a/cpu/native/tramp.S +++ b/cpu/native/tramp.S @@ -69,6 +69,54 @@ _native_sig_leave_handler: #else .globl _native_sig_leave_tramp +#ifdef __x86_64__ +_native_sig_leave_tramp: + pushq _native_saved_eip(%rip) + pushfq + + pushq %rax + pushq %rcx + pushq %rdx + pushq %rbx + pushq %rbp + pushq %rsi + pushq %rdi + pushq %r8 + pushq %r9 + pushq %r10 + pushq %r11 + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + + mov _native_isr_ctx(%rip), %rsi + mov _native_cur_ctx(%rip), %rdi + + call swapcontext@PLT + + call irq_enable + + movl $0x0, _native_in_isr(%rip) + popq %r15 + popq %r14 + popq %r13 + popq %r12 + popq %r11 + popq %r10 + popq %r9 + popq %r8 + popq %rdi + popq %rsi + popq %rbp + popq %rbx + popq %rdx + popq %rcx + popq %rax + + popfq + ret +#else _native_sig_leave_tramp: pushl _native_saved_eip pushfl @@ -86,10 +134,16 @@ _native_sig_leave_tramp: popfl ret +#endif .globl _native_sig_leave_handler _native_sig_leave_handler: +#ifdef __x86_64__ + pushq _native_saved_eip(%rip) + movl $0x0, _native_in_isr(%rip) +#else pushl _native_saved_eip movl $0x0, _native_in_isr +#endif ret #endif diff --git a/pkg/wamr/Makefile b/pkg/wamr/Makefile index 07ebcabf28c9..e97151cc571c 100644 --- a/pkg/wamr/Makefile +++ b/pkg/wamr/Makefile @@ -24,13 +24,17 @@ CFLAGS += -Wno-cast-function-type RIOT_INCLUDES = $(filter-out -%,$(subst -I,,$(INCLUDES))) #translate (CPU_ARCH) to Build Target -#WAMR_BUILD_TARGET is "X86_32" "AARCH64[sub]", "ARM[sub]", +#WAMR_BUILD_TARGET is "X86_32", "X86_64", "AARCH64[sub]", "ARM[sub]", # "THUMB[sub]", "XTENSA" #no msp430, no AVR support for now ifeq ($(CPU),native) ifeq ($(findstring x86,$(OS_ARCH)),x86) +ifneq (,$(filter arch_32bit,$(FEATURES_USED))) WAMR_BUILD_TARGET = X86_32 +else + WAMR_BUILD_TARGET = X86_64 +endif endif ifeq ($(findstring arm,$(OS_ARCH)),arm) WAMR_BUILD_TARGET = ARM