Skip to content

Add aarch64 support #12

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

rickvantooster
Copy link

@rickvantooster rickvantooster commented Feb 3, 2025

No description provided.

@rickvantooster rickvantooster changed the title Added aarch64 support Add aarch64 support Feb 3, 2025
@0dminnimda
Copy link
Contributor

Nice! That works on termux aarch64, except their gcc reports an error for (void)fd, a guard will fix it:

#ifndef __ANDROID__
    (void) fd;
#endif

I really don't know arm, but this (https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#611general-purpose-registers) document on aarch64 suggests that:

A subroutine invocation must preserve the contents of the registers r19-r29 and SP. All 64 bits of each value stored in r19-r29 must be preserved.

And for SIMD/floating-point:

Registers v8-v15 must be preserved by a callee across subroutine calls; [...]. Additionally, only the bottom 64 bits of each value stored in v8-v15 need to be preserved; it is the responsibility of the caller to preserve larger values.

And if I read and understood the code correctly, you are saving r19-r30, but what about v8-v15?

@rickvantooster
Copy link
Author

And if I read and understood the code correctly, you are saving r19-r30, but what about v8-v15?

Thank you for pointing it out. They are now being saved.
I've also added the guard around the fd void cast. However shouldn't

(void)rsp;

in coroutine_restore_context also have the same guard?

I also added the inline assembly to move fd to the correct registers in sleep_write and sleep_read as I forgot to add those in my initial commit 🥲.

@0dminnimda
Copy link
Contributor

0dminnimda commented Feb 5, 2025

in coroutine_restore_context also have the same guard?

yes, all of the cases with (void)... inside naked functions. It's like with clang, compilers don't want to see any code except inline assembly inside naked functions.




*(--rsp) = 0; // push r29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you also need to reserve space for r30 here, since the load will read both r29 and r30?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you also need to reserve space for r30 here, since the load will read both r29 and r30?

r30 is the same as the link register so the line

*(--rsp) = coroutine__finish_current;

will already reserve space for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yeah, we don't need to preserve it's value, so we can just read some garbage into it, instead of the previous value. Now but what about storing to the stack, wouldn't it override *(--rsp) = f; // push r0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I am following you. So far everything runs perfectly fine on the raspberry pi 4 model B.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants