Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/native: Support native64 Board on ARM #20739

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carl-tud
Copy link

@carl-tud carl-tud commented Jun 10, 2024

Contribution Description.

This PR adds support for the native64 board on arm64/aarch641

  • ISR functionality has been extended to work on 64-bit ARMv82
  • Since gcc cannot be compiled to support the -m32 and -m64 flags on ARM (?) (hence gcc-multilib is unavailable on ARM), -mXX flags are omitted when they would match getconf LONG_BIT

Testing procedure (GNU/Linux)

Compile and run on an ARM 64-bit CPU.

Footnotes

  1. Why? E.g., with 64-bit ARM support, you can use the native board on Apple Silicon Macs in a Linux-based virtualized environment (i.e., multipass (or qemu directly), Docker, Virtualization.framework or Hypervisor.framework), without having to resort to emulating a 32-bit ARM or x86 CPU.

  2. For anyone else also wondering how the PC can be set on ARM 64-bit, v8, while preserving all general-purpose registers: You don't. On ARMv8, PC cannot be written to anymore, and branch instructions (and friends) either require a static address (which isn't available to us (stored in _native_saved_eip) or a register containing the destination address. If you look at the glibc implementation of setcontext (which lets you set the instruction pointer) in glibc's setcontext.S, you'll notice x16 is used as the register for the br instruction. This PR adopts the same technique.

@github-actions github-actions bot added Platform: native Platform: This PR/issue effects the native platform Area: build system Area: Build system Area: cpu Area: CPU/MCU ports labels Jun 10, 2024
@Teufelchen1 Teufelchen1 self-requested a review June 11, 2024 11:08
@Teufelchen1
Copy link
Contributor

Cool! Let me know when you need a review. I can also aid in testing as I have an Apple Silicon ARM PC at hand.

cpu/native/tramp.S Outdated Show resolved Hide resolved
cpu/native/tramp.S Outdated Show resolved Hide resolved
cpu/native/tramp.S Outdated Show resolved Hide resolved
cpu/native/tramp.S Outdated Show resolved Hide resolved
@carl-tud carl-tud changed the title [DRAFT] Support native64 Board on ARM Support native64 Board on ARM Jun 27, 2024
@carl-tud carl-tud changed the title Support native64 Board on ARM cpu/native: Support native64 Board on ARM Jun 27, 2024
@carl-tud carl-tud marked this pull request as ready for review June 27, 2024 13:39
@carl-tud
Copy link
Author

@Teufelchen1 PR is ready for review :)

@Teufelchen1
Copy link
Contributor

Thanks for waiting.

I noticed a few things, maybe I have an invalid setup for testing or this PR need more work.
My setup:

  • MacOS Ventura 13.2.1
  • ARM64 / Apple M2
  • Docker
    • Ubuntu (latest) for --platform linux/arm64
  • Within docker, running BOARD=native64 make all term

Does that sound reasonable to you? Would you expect everything to work with the given setup?

Following things did not work as expected:

  • The ipc_pingpong example, indefinitely hangs after both threads are created.
  • The default example, crashes immediately after hitting an assertion within gnrc.
  • Building for 32 bit native does not work (the issue marked in your PR description). I think we should handle that case more gracefully.

If needed, I can also arrange a plain linux on ARM64 environment.

@carl-tud
Copy link
Author

carl-tud commented Jul 8, 2024

Thank‘s for testing. These issues definitely need to be resolved first, I’m going to try and figure out what’s going on there with these non-functional examples..

On ARM 64 bit, building for 32 bit platforms with gcc seems to be inherently impossible due to lacking gcc multilib support, at least to my knowledge.. Your setup seems fine and similar to mine.
(edit: haven’t tried compiling with clang)

What is it exactly you had in mind when you said »we should handle that case more gracefully«? A pretty error message with a reference to RIOT‘s doc perhaps..

carl

@carl-tud carl-tud force-pushed the native64-arm branch 2 times, most recently from 0419f5e to 8beb57c Compare August 12, 2024 14:06
@chrysn
Copy link
Member

chrysn commented Sep 3, 2024

This branch also works for the Raspberry Pi devices used by for the exercises. Skimming the discussion I'm afraid we won't get this merged by tomorrow so it could go into this summit's tutorials :-)

Could you add a branch to cpu/native/Makefile.include already in this PR so that on matching platforms, the RUST_TARGET can be aarch64-unknown-linux-gnu? (You can verify that by building and running examples/rust-gcoap or any other Rust example).

@benpicco benpicco added the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Platform: native Platform: This PR/issue effects the native platform State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants