public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
To: gcc@gcc.gnu.org
Subject: [RFC] Linux system call builtins
Date: Tue, 09 Apr 2024 22:26:49 -0300	[thread overview]
Message-ID: <eca5d74aca1bf2e6d95352d20251badd@gmail.com> (raw)
In-Reply-To: <20240408181831.pizpq7n7k4n5u6dh@ws2202.lin.mbt.kalray.eu>

> As noted by J. Wakely, you don't need to have one variant
> for each number of arguments.

Yes, he is right about that. I have already deleted
all the variants from my code since the variadic
builtin will be able to generate optimal code,
unlike a variadic C function.

> I assume you're talking about the interface
> which is often abstracted by functions such as
> the following which are often found in libcs or
> freestanding libraries.

> long linux_system_call_1(long number, long _1)

Yes, that's exactly what I have in mind.
My goal is to implement those functions
inside the compiler itself as builtins.

> I think that at least on sysv x86_64, syscalls have
> the same calling conventions as regular functions.
However, the
function descriptor is not an address (or a symbol reference) but a
number.

They are similar but not equal.

x86_64 function calling convention passes the first 6 arguments
in the following registers: rdi, rsi, rdx, rcx, r8, r9.
x86_64 system call calling convention passes only 6 arguments
in the following registers: rdi, rsi, rdx, r10, r8, r9.

System calls use r10 instead of rcx
and don't support more than 6 arguments.

> At least, it would be nice if not all freestanding libraries
had to reimplement those syscalls stubs.

Completely agree!

> I think you could have a look at the function 'expand_call'
> in calls.cc to see how regular calls are expanded to RTL

Thanks for the pointer!! I had been looking
in the gcc/config/ directory for platform specific
code that implemented calling conventions.
Somehow that calls.cc file slipped past my attention.

My thinking is that I need to have the compiler
evaluate the input expressions and place the
results in specific registers, while also ensuring
all the input expressions are register sized and
emitting type errors in case they are not.
I looked for some kind of "register" type
but didn't find anything. So I used long int,
just like the libraries do.

Thanks,
    Matheus

  parent reply	other threads:[~2024-04-10  1:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  9:19 Matheus Afonso Martins Moreira
2024-04-08  9:58 ` Jonathan Wakely
2024-04-08 11:59   ` Matheus Afonso Martins Moreira
2024-04-08 14:00     ` Jonathan Wakely
2024-04-08 11:24 ` Florian Weimer
2024-04-08 11:44   ` Alexander Monakov
2024-04-08 11:50     ` Florian Weimer
2024-04-08 13:01       ` Alexander Monakov
2024-04-08 13:37   ` Matheus Afonso Martins Moreira
2024-04-08 18:18 ` Paul Iannetta
2024-04-08 18:26   ` Andrew Pinski
2024-04-08 20:01     ` Paul Iannetta
2024-04-08 20:20       ` Paul Koning
2024-04-10  1:48     ` Matheus Afonso Martins Moreira
2024-04-10 13:15       ` Paul Koning
2024-04-10 14:10         ` Matheus Afonso Martins Moreira
2024-04-10  1:26   ` Matheus Afonso Martins Moreira [this message]
2024-04-08 20:24 ` Paul Floyd
2024-04-10  2:19   ` Matheus Afonso Martins Moreira
2024-04-09 11:45 ` Szabolcs Nagy
2024-04-10  2:59   ` Matheus Afonso Martins Moreira
2024-04-10 11:04     ` Szabolcs Nagy
2024-04-10 14:00       ` Matheus Afonso Martins Moreira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eca5d74aca1bf2e6d95352d20251badd@gmail.com \
    --to=matheus.a.m.moreira@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).