Call SDL / OpenGL from build code on Linux

I am writing a simple graphics program in an assembly for training purposes; for this I intended to use OpenGL or SDL. I am trying to call the OpenGL / SDL function from an assembly.

The problem is that unlike many of the OpenGL / SDL build and tutorials I found on the Internet, OpenGL / SDL on my machine does not seem to use the C calling convention. I wrote a simple C program, compiled it to the assembly (using the -S switch) and, apparently, the assembly code that is generated by GCC calls the OpenGL / SDL functions, passing parameters in registers instead of pushing them onto the stack.

Now, the question is how to determine how to pass arguments to these OpenGL / SDL functions? That is, how can I determine which argument matches which registers?

Obviously, since GCC can compile C code to call OpenGL / SDL, there must therefore be a way to determine the correspondence between function arguments and registers. In C-calling conventions, the rule is easy, push the parameters back and return the value to eax / rax, I can just read their C documentation, and I can easily understand how to pass the parameters. But what about these?

Is there a way to invoke OpenGL / SDL using a C call convention?

btw, I use yasm, with gcc / ld as the linker on Gentoo Linux amd64.

+3
source share
3 answers

The linux x86-64 system uses the standard AB86 x86-64 convention for function calls. In a nutshell:

  • integer/pointer rdi, rsi, rdx, rcx, r8, r9 .
  • xmm0-xmm7.
  • , , . , , rsp 16 .
+5

C, ( -S-), , -, , GCC, OpenGL/SDL, , .

: x86-64 .

, .

+2

, :

http://en.wikipedia.org/wiki/X86_calling_conventions#Borland_fastcall

Evaluating arguments from left to right, it passes three arguments via EAX, EDX, ECX. Remaining arguments are pushed onto the stack, also left to right.
0
source

Source: https://habr.com/ru/post/1749738/


All Articles