[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGzmLMVaKdBSQrpQFsqEw=Vs240vZANa+1-OLC-nNcKDDevnFQ@mail.gmail.com>
Date: Wed, 13 Oct 2021 10:32:03 +0700
From: Ammar Faizi <ammar.faizi@...dents.amikom.ac.id>
To: Willy Tarreau <w@....eu>
Cc: Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Andy Lutomirski <luto@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH] tools/nolibc: x86: Remove `r8`, `r9` and `r10` from the
clobber list
On Wed, Oct 13, 2021 at 10:01 AM Willy Tarreau <w@....eu> wrote:
>
> On Wed, Oct 13, 2021 at 05:23:11AM +0700, Ammar Faizi wrote:
> > According to x86-64 ABI about syscall section A.2 AMD64 Linux Kernel
> > Conventions, A.2.1 Calling Conventions [1]:
> >
> > 1) User-level applications use as integer registers for passing the
> > sequence %rdi, %rsi, %rdx, %rcx, %r8 and %r9. The kernel interface
> > uses %rdi, %rsi, %rdx, %r10, %r8 and %r9.
> >
> > 2) A system-call is done via the syscall instruction. The kernel
> > destroys registers %rcx and %r11.
> >
> > 3) The number of the syscall has to be passed in register %rax.
> >
> > 4) System-calls are limited to six arguments, no argument is passed
> > directly on the stack.
> >
> > 5) Returning from the syscall, register %rax contains the result of
> > the system-call. A value in the range between -4095 and -1
> > indicates an error, it is -errno.
> >
> > 6) Only values of class INTEGER or class MEMORY are passed to the
> > kernel.
> >
> > From (2), (5) and (6), we can conclude that Linux x86-64 syscall only
> > clobbers rax, rcx and r11 (and "memory").
> >
> > - rax for the return value.
> > - rcx to save the return address.
> > - r11 to save the rflags.
> >
> > Other registers are preserved. Right?
>
> I totally agree, and this doc is perfectly clear on this. I think it
> would be worth updating the comments in calling.h to reference this
> document and remind these rules, given that they're not trivial to
> figure from the code itself.
>
Alright, I will wire up patch v2 for this :-)
--
Ammar Faizi
Powered by blists - more mailing lists