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

Support for function address in ASM #1891

Open
ygorpontelo opened this issue Jan 25, 2025 · 6 comments
Open

Support for function address in ASM #1891

ygorpontelo opened this issue Jan 25, 2025 · 6 comments
Assignees
Labels
Accepted Accepted Request

Comments

@ygorpontelo
Copy link
Contributor

Seems like dealing with function adress is not yet implemented. The assembly i'm trying to inline kinda requires it, so it would be useful to have it. I hit a TODO at c3c/src/compiler/sema_asm.c:537.

Also, as a side note, the asm block is a bit confusing as to what is implemented and what is not. For example, i tried to use jmp but it said it wasn't a valid instruction, another one was xchgq. Can you elaborate a bit more on what's available? I'm using x86 arch. It seems like there's some variations on the syntax to AT&T too, could you clarify that as well?

It would also be very nice to have some of the instructions infer the size, so i don't have to put the suffix all the time, like pushq.

@lerno
Copy link
Collaborator

lerno commented Jan 25, 2025

Inferring the size is problematic.

Regarding the instruction set I am hoping for someone to take charge of this to implement all the remaining instructions. It should be straightforward to contribute additional instructions if you look at the implemented instructions: in / out needs to be defined + the clobbers.

jmp is missing having label implemented, but mostly this is because I didn't have any users, so nothing to really code towards. If you send me the code you want to work, then I'll fix that quickly. I need use-cases basically.

@ygorpontelo
Copy link
Contributor Author

Understood. My use case was implementing coroutines, i'm using this as a reference, other implementations were too confusing for me. Most of the C part was easy to do in C3, but the assembly i was hoping to use with asm blocks to minimize the dependencies of the project, in particular the x86_64 assembly for now.

I'm interested in helping, but i'm no expert so it will take time for me to get it right. Btw, i'm aware @rexim also implemented coroutines in C. I believe his implementation would be classified as symmetric coroutines, because they don't give the control back to the caller. This paper i was reading has more info on it. Maybe he can also help with the assembly given the shared interest in this. :D

@lerno
Copy link
Collaborator

lerno commented Jan 27, 2025

If you give me some asm that works good in C I can use that as a test case, it doesn't need to be the exact same asm.

@lerno lerno added the Accepted Accepted Request label Jan 28, 2025
@lerno lerno self-assigned this Jan 28, 2025
@lerno
Copy link
Collaborator

lerno commented Feb 5, 2025

Is this the same error as #1927 ?

@ygorpontelo
Copy link
Contributor Author

They are similar but are not the same for two reasons that i can see:

  1. TODO line is different, 537 != 206
  2. In the other code he is trying to reference a variable address, i wanted to reference a function address.

Regarding the asm you asked (i forgot to respond, sorry!), i don't quite have anything that is working in C regarding the project i'm working on. I was trying to port some things to C3 but eventually decided it was best to just use nasm. I could try to make something simple that just uses a function address, prob will have some time this weekend. Inline assembly in C is quite ugly.

@lerno
Copy link
Collaborator

lerno commented Feb 5, 2025

I'll hopefully look at the asm this weekend too. It was hard to understand the code when I did an attempt on #1927. In particular I was unsure that I did it correctly. I have also been thinking whether one can make the definition files for each ASM even easier to write. I want to add labels while I am at it.

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

No branches or pull requests

2 participants