From 2182d3ff4c3cad1fda965bef88671154c8112936 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Wed, 17 Jan 2024 22:17:16 +0100 Subject: [PATCH 1/6] [build] Compile with -O3 for hosted targets -Os is not properly supported by LLVM for ARM64 --- tools/build_script_generator/common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/build_script_generator/common.py b/tools/build_script_generator/common.py index bc0948fa73..432fea35a4 100644 --- a/tools/build_script_generator/common.py +++ b/tools/build_script_generator/common.py @@ -244,9 +244,10 @@ def common_compiler_flags(compiler, target): "-finline-limit=10000", "-funsigned-bitfields", ] - flags["ccflags.release"] = [ - "-Os", - ] + if target.identifier["platform"] in ["hosted"]: + flags["ccflags.release"] = ["-O3"] + else: + flags["ccflags.release"] = ["-Os"] # not a valid profile # flags["ccflags.fast"] = [ # "-O3", From 5db4aa71abf28d08c754bcc63f722e5589ec8716 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Wed, 17 Jan 2024 22:18:15 +0100 Subject: [PATCH 2/6] [fiber] Fix alignment of stack underneath promise --- src/modm/processing/fiber/task.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modm/processing/fiber/task.hpp b/src/modm/processing/fiber/task.hpp index 5014c619bf..a0270add92 100644 --- a/src/modm/processing/fiber/task.hpp +++ b/src/modm/processing/fiber/task.hpp @@ -126,13 +126,13 @@ Task::Task(Stack& stack, T&& closure, Start start) } else { - // lambda functions with a closure must be allocated on the stack - constexpr size_t closure_size = sizeof(std::decay_t); + // lambda functions with a closure must be allocated on the stack ALIGNED! + constexpr size_t align_mask = std::max(StackAlignment, alignof(std::decay_t)) - 1u; + constexpr size_t closure_size = (sizeof(std::decay_t) + align_mask) & ~align_mask; static_assert(Size >= closure_size + StackSizeMinimum, - "Stack size must ≥({{min_stack_size}}B + sizeof(closure))!"); + "Stack size must ≥({{min_stack_size}}B + aligned sizeof(closure))!"); // Find a suitable aligned area at the top of stack to allocate the closure - uintptr_t ptr = uintptr_t(stack.memory + stack.words) - closure_size; - ptr &= ~(std::max(sizeof(uintptr_t), alignof(std::decay_t)) - 1u); + const uintptr_t ptr = uintptr_t(stack.memory + stack.words) - closure_size; // construct closure in place ::new ((void*)ptr) std::decay_t{std::forward(closure)}; // Encapsulate the proper ABI function call into a simpler function From f9685317bab11fbcf885a478a05c14c2286bdaf8 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Thu, 18 Jan 2024 19:42:22 +0100 Subject: [PATCH 3/6] [devices] Remove RPi target in favor of Linux --- README.md | 7 +- examples/rpi/blinky/main.cpp | 28 ------ examples/rpi/blinky/project.xml | 10 --- src/modm/board/raspberrypi/board.hpp | 30 ------- src/modm/board/raspberrypi/board.xml | 14 --- src/modm/board/raspberrypi/module.lb | 29 ------- .../platform/core/hosted/delay_impl.hpp.in | 2 +- src/modm/platform/gpio/rpi/base.hpp | 52 ----------- src/modm/platform/gpio/rpi/module.lb | 34 -------- src/modm/platform/gpio/rpi/pin.hpp | 67 -------------- src/modm/platform/gpio/rpi/unused.hpp | 87 ------------------- tools/devices/hosted/rpi.xml | 11 --- tools/scripts/docs_modm_io_generator.py | 3 +- tools/scripts/examples_check.py | 2 +- tools/scripts/synchronize_docs.py | 1 - 15 files changed, 6 insertions(+), 371 deletions(-) delete mode 100644 examples/rpi/blinky/main.cpp delete mode 100644 examples/rpi/blinky/project.xml delete mode 100644 src/modm/board/raspberrypi/board.hpp delete mode 100644 src/modm/board/raspberrypi/board.xml delete mode 100644 src/modm/board/raspberrypi/module.lb delete mode 100644 src/modm/platform/gpio/rpi/base.hpp delete mode 100644 src/modm/platform/gpio/rpi/module.lb delete mode 100644 src/modm/platform/gpio/rpi/pin.hpp delete mode 100644 src/modm/platform/gpio/rpi/unused.hpp delete mode 100644 tools/devices/hosted/rpi.xml diff --git a/README.md b/README.md index 98297ef321..5147d6d0c9 100644 --- a/README.md +++ b/README.md @@ -677,21 +677,20 @@ We have out-of-box support for many development boards including documentation. NUCLEO-U575ZI-Q OLIMEXINO-STM32 -Raspberry Pi Raspberry Pi Pico SAMD21-MINI - SAMD21-XPLAINED-PRO + SAME54-XPLAINED-PRO SAME70-XPLAINED SAMG55-XPLAINED-PRO - SAMV71-XPLAINED-ULTRA + Smart Response XE STM32-F4VE STM32F030-DEMO - THINGPLUS-RP2040 + diff --git a/examples/rpi/blinky/main.cpp b/examples/rpi/blinky/main.cpp deleted file mode 100644 index 3a8cf054ac..0000000000 --- a/examples/rpi/blinky/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020, Erik Henriksson - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include -#include - -using namespace Board; - -int main() -{ - Board::initialize(); - GpioPin<0>::setOutput(); - MODM_LOG_INFO << "Blink blink..."; - - for (int i = 0; i < 10; ++i) - { - GpioPin<0>::toggle(); - modm::delay(500ms); - } - return 0; -} diff --git a/examples/rpi/blinky/project.xml b/examples/rpi/blinky/project.xml deleted file mode 100644 index a722c39ba3..0000000000 --- a/examples/rpi/blinky/project.xml +++ /dev/null @@ -1,10 +0,0 @@ - - modm:raspberrypi - - - - - modm:build:scons - modm:build:make - - diff --git a/src/modm/board/raspberrypi/board.hpp b/src/modm/board/raspberrypi/board.hpp deleted file mode 100644 index 65ec809934..0000000000 --- a/src/modm/board/raspberrypi/board.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2020, Erik Henriksson - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -#pragma once - -#include -#include - -#include - -using namespace modm::platform; - -namespace Board -{ - -inline void -initialize() -{ - wiringPiSetup(); -} - -} // Board namespace diff --git a/src/modm/board/raspberrypi/board.xml b/src/modm/board/raspberrypi/board.xml deleted file mode 100644 index 8b4daa2270..0000000000 --- a/src/modm/board/raspberrypi/board.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - ../../../../repo.lb - - - - - - - - modm:board:raspberrypi - - diff --git a/src/modm/board/raspberrypi/module.lb b/src/modm/board/raspberrypi/module.lb deleted file mode 100644 index 680e2f3332..0000000000 --- a/src/modm/board/raspberrypi/module.lb +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (c) 2020, Erik Henriksson -# -# This file is part of the modm project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# ----------------------------------------------------------------------------- - -def init(module): - module.name = ":board:raspberrypi" - module.description = """\ -# Raspberry Pi -""" - -def prepare(module, options): - if options[":target"].partname != "hosted-rpi": - return False - - module.depends(":platform:core", ":platform:gpio", ":debug") - return True - -def build(env): - env.outbasepath = "modm/src/modm/board" - env.copy('.') - diff --git a/src/modm/platform/core/hosted/delay_impl.hpp.in b/src/modm/platform/core/hosted/delay_impl.hpp.in index a8d346ac8d..ba2dcf6412 100644 --- a/src/modm/platform/core/hosted/delay_impl.hpp.in +++ b/src/modm/platform/core/hosted/delay_impl.hpp.in @@ -22,7 +22,7 @@ #define MODM_DELAY_NS_IS_ACCURATE 0 -%% if target.family in ["darwin", "linux", "rpi"] +%% if target.family in ["darwin", "linux"] extern "C" { #include } diff --git a/src/modm/platform/gpio/rpi/base.hpp b/src/modm/platform/gpio/rpi/base.hpp deleted file mode 100644 index dad07bc557..0000000000 --- a/src/modm/platform/gpio/rpi/base.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020, Erik Henriksson - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -#pragma once - -#include - -namespace modm::platform -{ - -/// @ingroup modm_platform_gpio -enum class -Peripheral -{ - BitBang, - // ... -}; - -/// @ingroup modm_platform_gpio -struct Gpio -{ - /// Each Input Pin can be configured in one of these states. - enum class - InputType : uint8_t - { - Floating = PUD_OFF, - PullUp = PUD_UP, - PullDown = PUD_DOWN, - }; - - enum class - OutputType : uint8_t - { - PushPull ///< push-pull on output - }; - - enum class - Signal - { - BitBang, - }; -}; - -} // namespace modm::platform diff --git a/src/modm/platform/gpio/rpi/module.lb b/src/modm/platform/gpio/rpi/module.lb deleted file mode 100644 index 0bbe2dbd12..0000000000 --- a/src/modm/platform/gpio/rpi/module.lb +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (c) 2020, Erik Henriksson -# -# This file is part of the modm project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# ----------------------------------------------------------------------------- - - -def init(module): - module.name = ":platform:gpio" - module.description = "Hosted GPIO for Raspberry Pi" - - -def prepare(module, options): - if not options[":target"].has_driver("gpio:wiring-rpi"): - return False - - module.depends(":architecture:gpio") - return True - - -def build(env): - env.substitutions = {"target": env[":target"].identifier} - env.outbasepath = "modm/src/modm/platform/gpio" - - env.collect(":build:library", "wiringPi") - - env.copy(".") - env.copy("../common/inverted.hpp", "inverted.hpp") diff --git a/src/modm/platform/gpio/rpi/pin.hpp b/src/modm/platform/gpio/rpi/pin.hpp deleted file mode 100644 index c6f1190d84..0000000000 --- a/src/modm/platform/gpio/rpi/pin.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021, Niklas Hauser - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -#pragma once - -#include -#include - -#include "base.hpp" - - -namespace modm::platform -{ - -/// @ingroup modm_platform_gpio -template< int Pin > -class GpioPin : public Gpio, public modm::GpioIO -{ - static inline bool output{false}; -public: - using Output = GpioPin; - using Input = GpioPin; - using IO = GpioPin; - using Type = GpioPin; - -public: - inline static void setOutput() { pinMode(Pin, OUTPUT);} - inline static void setOutput(OutputType) { setOutput(); } - inline static void setOutput(bool status) - { - setOutput(); - set(status); - } - - inline static void set() { set(true); } - inline static void reset() { set(false); } - inline static bool isSet() { return output; } - inline static void set(bool status) { digitalWrite(Pin, status); output = status; } - inline static void toggle() - { - if (isSet()) { set(); } - else { reset(); } - } - - inline static void setInput() { pinMode(Pin, INPUT); } - inline static void setInput(Gpio::InputType type) { setInput(); configure(type); } - inline static void configure(Gpio::InputType type) { pullUpDnControl(Pin, int(type)); } - - inline static bool read() { return digitalRead(Pin); } - - inline static modm::Gpio::Direction getDirection() - { return modm::Gpio::Direction::InOut; } - -public: - struct BitBang {} -}; - -} // namespace modm::platform - diff --git a/src/modm/platform/gpio/rpi/unused.hpp b/src/modm/platform/gpio/rpi/unused.hpp deleted file mode 100644 index 37e000bf93..0000000000 --- a/src/modm/platform/gpio/rpi/unused.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2017, Niklas Hauser - * Copyright (c) 2018, Fabian Greif - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -#ifndef MODM_HOSTED_GPIO_PIN_UNUSED_HPP -#define MODM_HOSTED_GPIO_PIN_UNUSED_HPP - -#include "base.hpp" -#include - -namespace modm -{ - -namespace platform -{ - -/** - * Dummy implementation of an I/O pin. - * - * This class can be used when a pin is not required. All functions - * are dummy functions which do nothing. `read()` will always - * return `false`. - * - * For example when creating a software SPI with the modm::SoftwareSimpleSpi - * class and the return channel (MISO - Master In Slave Out) is not needed, - * a good way is to use this class as a parameter when defining the - * SPI class. - * - * Example: - * @code - * #include - * - * namespace pin - * { - * typedef GpioOutputD7 Clk; - * typedef GpioOutputD5 Mosi; - * } - * - * modm::SoftwareSpiMaster< pin::Clk, pin::Mosi, GpioUnused > Spi; - * - * ... - * Spi::write(0xaa); - * @endcode - * - * @author Fabian Greif - * @author Niklas Hauser - * @ingroup modm_platform_gpio - */ -class GpioUnused : public Gpio, public ::modm::GpioIO -{ -public: - using Output = GpioUnused; - using Input = GpioUnused; - using IO = GpioUnused; - using Type = GpioUnused; - -public: - // GpioOutput - static void setOutput() {} - static void setOutput(bool) {} - static void set() {} - static void set(bool) {} - static void reset() {} - static void toggle() {} - static bool isSet() { return false; } - - // GpioInput - static void setInput() {} - static bool read() { return false; } - - // GpioIO - static Direction getDirection() { return Direction::Special; } -}; - -} // namespace platform - -} // namespace modm - -#endif diff --git a/tools/devices/hosted/rpi.xml b/tools/devices/hosted/rpi.xml deleted file mode 100644 index 1e64700d6f..0000000000 --- a/tools/devices/hosted/rpi.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - {platform}-{family} - - - - - - diff --git a/tools/scripts/docs_modm_io_generator.py b/tools/scripts/docs_modm_io_generator.py index c032500392..55ed7f5b79 100755 --- a/tools/scripts/docs_modm_io_generator.py +++ b/tools/scripts/docs_modm_io_generator.py @@ -36,8 +36,7 @@ def rename_board(name): .replace("BLUE-PILL", "Blue Pill") \ .replace("BLACK-PILL", "Black Pill") \ .replace("ARDUINO-UNO", "Arduino UNO") \ - .replace("ARDUINO-NANO", "Arduino NANO") \ - .replace("RASPBERRYPI", "Raspberry Pi") + .replace("ARDUINO-NANO", "Arduino NANO") sys.path.append(str(repopath("ext/modm-devices"))) from modm_devices.device_identifier import * diff --git a/tools/scripts/examples_check.py b/tools/scripts/examples_check.py index 6c23f07111..3fa837568a 100755 --- a/tools/scripts/examples_check.py +++ b/tools/scripts/examples_check.py @@ -64,7 +64,7 @@ def check_is_part_of_ci(projects): result = 0 # Linux files paths = _get_paths_from_ci([repopath(".github/workflows/linux.yml")]) - paths = folders - paths - {'rpi'} + paths = folders - paths if paths: print("\nLinux CI is missing examples: '{}'" .format("', '".join(sorted(list(paths)))), file=sys.stderr) diff --git a/tools/scripts/synchronize_docs.py b/tools/scripts/synchronize_docs.py index 969051ecd1..3ce9c7e5e0 100755 --- a/tools/scripts/synchronize_docs.py +++ b/tools/scripts/synchronize_docs.py @@ -51,7 +51,6 @@ def name(raw_name): .replace("BLACK-PILL-", "Black Pill ")\ .replace("ARDUINO-UNO", "Arduino UNO")\ .replace("ARDUINO-NANO", "Arduino NANO")\ - .replace("RASPBERRYPI", "Raspberry Pi")\ .replace("RP-PICO", "Raspberry Pi Pico")\ .replace("SRXE", "Smart Response XE")\ .replace("GENERIC", "Generic")\ From 6dff63042ca4e8ec0a848695189e1ffe77e0fcb1 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Wed, 17 Jan 2024 22:15:36 +0100 Subject: [PATCH 4/6] [fiber] Add support for ARM64 targets Co-authored-by: Raphael Lehmann --- .../fiber/{context.h.in => context.h} | 2 +- src/modm/processing/fiber/context_arm64.cpp | 200 ++++++++++++++++++ src/modm/processing/fiber/module.lb | 13 +- test/modm/processing/module.lb | 8 +- 4 files changed, 213 insertions(+), 10 deletions(-) rename src/modm/processing/fiber/{context.h.in => context.h} (97%) create mode 100644 src/modm/processing/fiber/context_arm64.cpp diff --git a/src/modm/processing/fiber/context.h.in b/src/modm/processing/fiber/context.h similarity index 97% rename from src/modm/processing/fiber/context.h.in rename to src/modm/processing/fiber/context.h index f532d6be36..d0e78a8fe8 100644 --- a/src/modm/processing/fiber/context.h.in +++ b/src/modm/processing/fiber/context.h @@ -72,7 +72,7 @@ modm_context_start(modm_context_t *to); * to jump from one fiber to the next. */ void -modm_context_jump(modm_context_t *from, modm_context_t *to); +modm_context_jump(modm_context_t *from, modm_context_t *to) asm("modm_context_jump"); /** * Switches control from the fiber context back to the main context. diff --git a/src/modm/processing/fiber/context_arm64.cpp b/src/modm/processing/fiber/context_arm64.cpp new file mode 100644 index 0000000000..a6fc451e9c --- /dev/null +++ b/src/modm/processing/fiber/context_arm64.cpp @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2020, Erik Henriksson + * Copyright (c) 2021, 2023, Niklas Hauser + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include "context.h" +#include + +/* Stack layout (growing downwards): + * + * Permanent Storage: + * Fiber Function + * Fiber Function Argument + * + * Temporary Prepare: + * Entry Function + * + * Register file: + * LR + * FP + * x28 + * x27 + * x26 + * x25 + * x24 + * x23 + * x22 + * x21 + * x20 + * x19 + * d15 + * d14 + * d13 + * d12 + * d11 + * d10 + * d9 + * d8 + */ + +namespace +{ + +constexpr size_t StackWordsReset = 1; +constexpr size_t StackWordsStorage = 2; +constexpr size_t StackWordsRegisters = 20; +constexpr size_t StackWordsAll = StackWordsStorage + StackWordsRegisters; +constexpr size_t StackSizeWord = sizeof(uintptr_t); +constexpr uintptr_t StackWatermark = 0xc0ffee'f00d'facade; + +} + +extern "C" void modm_context_entry() asm("modm_context_entry"); +asm +( + ".globl modm_context_entry \n\t" + "modm_context_entry: \n\t" + "ldr x0, [sp] \n\t" // Load closure data pointer + "ldr x1, [sp, #8] \n\t" // Load closure function + "br x1 \n\t" // Jump to closure function +); + + +void +modm_context_init(modm_context_t *ctx, + uintptr_t *bottom, uintptr_t *top, + uintptr_t fn, uintptr_t fn_arg) +{ + ctx->bottom = bottom; + ctx->top = top; + + ctx->sp = top; + *--ctx->sp = fn; + *--ctx->sp = fn_arg; +} + +void +modm_context_reset(modm_context_t *ctx) +{ + *ctx->bottom = StackWatermark; + + ctx->sp = ctx->top - StackWordsStorage; + *--ctx->sp = (uintptr_t) modm_context_entry; + ctx->sp -= StackWordsRegisters - StackWordsReset; +} + +void +modm_context_watermark(modm_context_t *ctx) +{ + // clear the register file on the stack + for (auto *word = ctx->top - StackWordsAll; + word < ctx->top - StackWordsStorage - StackWordsReset; word++) + *word = 0; + + // then color the whole stack *below* the register file + for (auto *word = ctx->bottom; word < ctx->top - StackWordsAll; word++) + *word = StackWatermark; +} + +size_t +modm_context_stack_usage(const modm_context_t *ctx) +{ + for (auto *word = ctx->bottom; word < ctx->top; word++) + if (StackWatermark != *word) + return (ctx->top - word) * StackSizeWord; + return 0; +} + +bool +modm_context_stack_overflow(const modm_context_t *ctx) +{ + return *ctx->bottom != StackWatermark; +} + +static modm_context_t main_context; + +void +modm_context_start(modm_context_t *to) +{ + modm_context_jump(&main_context, to); +} + +void +modm_context_end() +{ + modm_context_t dummy; + modm_context_jump(&dummy, &main_context); + __builtin_unreachable(); +} + +/* +The assembly code below is adapted from the Boost Context library to work +for Windows, Linux and macOS. +See https://github.com/boostorg/context/tree/develop/src/asm +- Windows: jump_arm64_aapcs_pe_armasm.asm +- Linux: jump_arm64_aapcs_elf_gas.S +- macOS: jump_arm64_aapcs_macho_gas.S + + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +asm +( + ".globl modm_context_jump \n\t" + "modm_context_jump: \n\t" + + /* move stack pointer down */ + "sub sp, sp, #0xa0 \n\t" + + /* save d8 - d15 */ + "stp d8, d9, [sp, #0x00] \n\t" + "stp d10, d11, [sp, #0x10] \n\t" + "stp d12, d13, [sp, #0x20] \n\t" + "stp d14, d15, [sp, #0x30] \n\t" + + /* save x19-x30 */ + "stp x19, x20, [sp, #0x40] \n\t" + "stp x21, x22, [sp, #0x50] \n\t" + "stp x23, x24, [sp, #0x60] \n\t" + "stp x25, x26, [sp, #0x70] \n\t" + "stp x27, x28, [sp, #0x80] \n\t" + "stp fp, lr, [sp, #0x90] \n\t" + + /* Store the SP in from->sp */ + "mov x19, sp \n\t" + "str x19, [x0] \n\t" + + /* Restore SP from to->sp */ + "ldr x19, [x1] \n\t" + "mov sp, x19 \n\t" + + /* load d8 - d15 */ + "ldp d8, d9, [sp, #0x00] \n\t" + "ldp d10, d11, [sp, #0x10] \n\t" + "ldp d12, d13, [sp, #0x20] \n\t" + "ldp d14, d15, [sp, #0x30] \n\t" + + /* load x19-x30 */ + "ldp x19, x20, [sp, #0x40] \n\t" + "ldp x21, x22, [sp, #0x50] \n\t" + "ldp x23, x24, [sp, #0x60] \n\t" + "ldp x25, x26, [sp, #0x70] \n\t" + "ldp x27, x28, [sp, #0x80] \n\t" + "ldp fp, lr, [sp, #0x90] \n\t" + + /* restore stack from GP + FPU */ + "add sp, sp, #0xa0 \n\t" + + "ret \n\t" +); diff --git a/src/modm/processing/fiber/module.lb b/src/modm/processing/fiber/module.lb index 22e09dbe3f..9289a2608f 100644 --- a/src/modm/processing/fiber/module.lb +++ b/src/modm/processing/fiber/module.lb @@ -26,8 +26,9 @@ def prepare(module, options): module.add_query( EnvironmentQuery(name="__enabled", factory=is_enabled)) - # No ARM64 support yet! - return "arm64" not in options[":target"].get_driver("core")["type"] + core = options[":target"].get_driver("core")["type"] + return (core.startswith("cortex-m") or core.startswith("avr") or + "x86_64" in core or "arm64" in core) def build(env): @@ -40,6 +41,7 @@ def build(env): "is_cm0": core.startswith("cortex-m0"), "is_avr": core.startswith("avr"), "is_windows": env[":target"].identifier.family == "windows", + "is_darwin": env[":target"].identifier.family == "darwin", "core": core, "with_fpu": with_fpu, "target": env[":target"].identifier, @@ -64,7 +66,12 @@ def build(env): env.substitutions["default_stack_size"] = 2**20 # 1MB env.template("context_x86_64.cpp.in") - env.template("context.h.in") + elif "arm64" in core: + env.substitutions["stack_minimum"] = (20 + 2) * 8 + env.substitutions["default_stack_size"] = 2**20 # 1MB + env.copy("context_arm64.cpp") + + env.copy("context.h") env.template("stack.hpp.in") env.template("scheduler.hpp.in") env.copy("task.hpp") diff --git a/test/modm/processing/module.lb b/test/modm/processing/module.lb index ecd2f590a2..126784da99 100644 --- a/test/modm/processing/module.lb +++ b/test/modm/processing/module.lb @@ -21,19 +21,15 @@ def prepare(module, options): "modm:architecture", "modm:math:utils", "modm:math:filter", + "modm:processing:fiber", "modm:processing:protothread", "modm:processing:resumable", "modm:processing:timer", "modm:processing:scheduler", ":mock:clock") - if "arm64" not in options[":target"].get_driver("core")["type"]: - module.depends("modm:processing:fiber") return True def build(env): env.outbasepath = "modm-test/src/modm-test/processing" - if "arm64" in env[":target"].get_driver("core")["type"]: - env.copy('.', ignore=env.ignore_paths("fiber")) - else: - env.copy('.') + env.copy('.') From c5dc4b11df2453554c3378cd82d7453f35b4e706 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Sat, 20 Jan 2024 21:22:30 +0100 Subject: [PATCH 5/6] [devices] Add ARM64 version of hosted targets --- test/Makefile | 4 ++++ tools/devices/hosted/darwin-arm64.xml | 13 +++++++++++++ .../hosted/{darwin.xml => darwin-x86_64.xml} | 2 +- tools/devices/hosted/linux-arm64.xml | 14 ++++++++++++++ .../devices/hosted/{linux.xml => linux-x86_64.xml} | 2 +- tools/devices/hosted/windows.xml | 2 +- tools/scripts/examples_compile.py | 2 ++ 7 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tools/devices/hosted/darwin-arm64.xml rename tools/devices/hosted/{darwin.xml => darwin-x86_64.xml} (86%) create mode 100644 tools/devices/hosted/linux-arm64.xml rename tools/devices/hosted/{linux.xml => linux-x86_64.xml} (88%) diff --git a/test/Makefile b/test/Makefile index dbb55d7b99..5d41f9d46b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -27,8 +27,12 @@ endef run-hosted-linux: $(call compile-test,hosted,run,-D":target=hosted-linux") +run-hosted-linux-arm64: + $(call compile-test,hosted,run,-D":target=hosted-linux-arm64") run-hosted-darwin: $(call compile-test,hosted,run,-D":target=hosted-darwin") +run-hosted-darwin-arm64: + $(call compile-test,hosted,run,-D":target=hosted-darwin-arm64") run-hosted-windows: $(call compile-test,hosted,run,-D":target=hosted-windows") diff --git a/tools/devices/hosted/darwin-arm64.xml b/tools/devices/hosted/darwin-arm64.xml new file mode 100644 index 0000000000..5d2d79aa7f --- /dev/null +++ b/tools/devices/hosted/darwin-arm64.xml @@ -0,0 +1,13 @@ + + + + + {platform}-{family}-{arch} + + + + + + + + diff --git a/tools/devices/hosted/darwin.xml b/tools/devices/hosted/darwin-x86_64.xml similarity index 86% rename from tools/devices/hosted/darwin.xml rename to tools/devices/hosted/darwin-x86_64.xml index 7ac1b5b7a9..b2db0d85d6 100644 --- a/tools/devices/hosted/darwin.xml +++ b/tools/devices/hosted/darwin-x86_64.xml @@ -1,7 +1,7 @@ - + {platform}-{family} diff --git a/tools/devices/hosted/linux-arm64.xml b/tools/devices/hosted/linux-arm64.xml new file mode 100644 index 0000000000..50ec66b0af --- /dev/null +++ b/tools/devices/hosted/linux-arm64.xml @@ -0,0 +1,14 @@ + + + + + {platform}-{family}-{arch} + + + + + + + + + diff --git a/tools/devices/hosted/linux.xml b/tools/devices/hosted/linux-x86_64.xml similarity index 88% rename from tools/devices/hosted/linux.xml rename to tools/devices/hosted/linux-x86_64.xml index d0e5221a72..8bb6e90bc3 100644 --- a/tools/devices/hosted/linux.xml +++ b/tools/devices/hosted/linux-x86_64.xml @@ -1,7 +1,7 @@ - + {platform}-{family} diff --git a/tools/devices/hosted/windows.xml b/tools/devices/hosted/windows.xml index 79c2c0c27b..06eb4450e9 100644 --- a/tools/devices/hosted/windows.xml +++ b/tools/devices/hosted/windows.xml @@ -1,7 +1,7 @@ - + {platform}-{family} diff --git a/tools/scripts/examples_compile.py b/tools/scripts/examples_compile.py index 072bb8f10e..455ea55245 100755 --- a/tools/scripts/examples_compile.py +++ b/tools/scripts/examples_compile.py @@ -20,6 +20,7 @@ os.getenv("TRAVIS") is not None or os.getenv("GITHUB_ACTIONS") is not None) is_running_on_windows = "Windows" in platform.platform() +is_running_on_arm64 = "arm64" in platform.machine() build_dir = (Path(os.path.abspath(__file__)).parents[2] / "build") cache_dir = build_dir / "cache" global_options = {} @@ -52,6 +53,7 @@ def generate(project): # Compile Linux examples under macOS with hosted-darwin target if "hosted-linux" in project.read_text(): options += " -D:target=hosted-{}".format(platform.system().lower()) + if is_running_on_arm64: options += "-arm64" rc, ro = run_command(path, "lbuild {} build".format(options)) print("\n".join(output + [ro])) return None if rc else project From 623a13bb6c6435911b7b45b19c488d751e65a985 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Sat, 20 Jan 2024 22:50:30 +0100 Subject: [PATCH 6/6] [scons] Hardcode gcc-12 compiler suffix on macOS --- tools/build_script_generator/scons/resources/SConscript.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/build_script_generator/scons/resources/SConscript.in b/tools/build_script_generator/scons/resources/SConscript.in index 3381e6b540..74e4f04e0a 100644 --- a/tools/build_script_generator/scons/resources/SConscript.in +++ b/tools/build_script_generator/scons/resources/SConscript.in @@ -23,8 +23,8 @@ env["COMPILERPREFIX"] = "avr-" env["COMPILERPREFIX"] = "arm-none-eabi-" %% endif %% if family == "darwin" -# Using homebrew gcc on macOS instead of clang -env["COMPILERSUFFIX"] = env.Detect(["gcc-12", "gcc-11", "gcc-10"])[3:] +# Using homebrew gcc-12 on macOS instead of clang +env["COMPILERSUFFIX"] = "-12" %% endif %% endif