[haiku-commits] Re: BRANCH xyzzy-github.x86_64 - in src/system/libroot: os/arch/x86_64 posix/string/arch/x86_64 posix/arch/x86_64

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 23 Jul 2012 10:11:58 +0200

On 2012-07-22 at 23:42:16 [+0200], Alex Smith <alex@xxxxxxxxxxxxxxxx> wrote:
> On 22 July 2012 17:12, Ingo Weinhold <ingo_weinhold@xxxxxx> wrote:
> > xyzzy-github.x86_64 wrote:
> > > diff --git a/src/system/libroot/os/arch/x86_64/syscalls.inc
> > b/src/system/libroot/os/arch/x86_64/syscalls.inc
> > > new file mode 100644
> > > index 0000000..f318d59
> > > --- /dev/null
> > > +++ b/src/system/libroot/os/arch/x86_64/syscalls.inc
> > > @@ -0,0 +1,46 @@
> > > +/*
> > > + * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
> > > + * Distributed under the terms of the MIT License.
> > > + */
> > > +
> > > +
> > > +#include <asm_defs.h>
> > > +
> > > +
> > > +// The kernel follows the AMD64 ABI for parameter passing (first 6
> > arguments in
> > > +// registers and the remaining ones in on the stack), except that RCX
> > is used
> > > +// by SYSCALL so it is moved to R10. Syscall number goes in RAX.
> >
> > Why not the other way around? Not that the saved instruction matters much,
> > but since it's free...
> 
> Not sure I follow. RCX is the 4th argument by the calling convention, but
> the SYSCALL instruction overwrites that with the saved RIP, so it's
> necessary to move it to another register. Though I just realised I don't
> need to be doing that move for < 4 arguments.

Ah, sorry, I totally misread that. I thought you where talking about RAX. But 
that isn't even used for parameter passing.

> > That aside, it may make sense to pass all parameters to the kernel via
> > registers. ATM the syscalls don't have more than 11 parameters, so that
> > should be feasible. It would save the kernel entry code from accessing the
> > userland stack. Not important ATM, but something to come back to when the
> > port is otherwise complete.
> 
> Hmm. I'm not sure whether that would be any better. There's 6 arguments
> already in registers, RAX is the syscall number, SYSCALL uses 2 more
> registers (RCX = saved RIP, R11 = saved RFLAGS). That leaves RBX and
> R12-R15 for the rest of the arguments, which are callee-save registers so
> they would need to be preserved. That means a write to the stack to save,
> then a read to copy the argument from the stack to the register. Leaving
> them on the stack just requires setting a fault handler and doing rep movsq
> in the kernel.

Yeah, good point. Given that most syscalls don't have more than 6 parameters, 
copying wouldn't be necessary often, anyway.

CU, Ingo

Other related posts: