r/cprogramming • • Jun 16 '26

Question about low level C integration

Hi, I have some experience in C but I still am fairly new, please correct me anytime.

I am coming from Python where everything is neatly organized, meaning the Python org is "controlling everything". As I understand this is not the case with C. Of course there is the ISO C standard, but there are many different compilers, implementations of the stdlib and different operating systems (in relevance to low level/embedded programming).

I really took liking in embedded programming. Experimenting with the Atmega328 (the standard Arduino MCU) is really fun. One thing I wanted to try is to combine C and Assembly, and it worked. I needed a function to slice one byte into each of its bits and put them into an array. I can call the assembly function from my C code. While researching how to do this I found the GCC ABI for AVR MCUs.

This brings me to my two questions:

1. How can one adapt a compiler to a specific target?

GCC was not developed for AVR MCUs. Is there just some file where the op-codes for AVR MCUs are written down? Something like a config file?

And the more important question:

2. Who makes/maintains ABIs?

They have to be different for every processor (architecture), OS and maybe even compilers? How can I find the relevant ABI if I want to make a function like above on a 64 bit, x86, AMD processor running Linux, using GCC?

Thanks in advance, please correct me if I am wrong. All this is a bit overwhelming.

15 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/noob_main22 Jun 16 '26

I read somewhere that Linux syscalls use specific registers as a "function call". Is that something that would need an ABI or is this something that the POSIX standard regulates? Or is there some other documentation for this on Linux?

2

u/Maleficent_Memory831 Jun 16 '26

You won't have anything like a "syscall" on an AVR. A syscall is a transition from a user-space code to kernel-space code, meaning separate address spaces. AVR cannot even support different address spaces, so literally all code gets linked together. (well, maybe there are bigger AVRs now and I'm out of date, but if it's still an 8-bit CPU then forget about thinking like Linux)

1

u/noob_main22 Jun 16 '26

Yes, I know. The question was not related to AVRs, maybe should have added that. If I am not mistaken there are bigger AVRs that can/could run Linux, but the one I am using is the classic 8-bit MCU.

2

u/edgmnt_net Jun 16 '26

That would be the Linux syscall ABI to be very specific. It's different from the userspace / calling convention ABI. I think neither are set in stone by POSIX in any significant way, although POSIX may mandate certain syscalls exist.