[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: Alex Smith <alex@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 22 Jul 2012 22:42:16 +0100

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.


> 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.


> [...]
> > diff --git a/src/system/libroot/os/arch/x86_64/thread.cpp
> b/src/system/libroot/os/arch/x86_64/thread.cpp
> > new file mode 100644
> > index 0000000..7b12f02
> > --- /dev/null
> > +++ b/src/system/libroot/os/arch/x86_64/thread.cpp
> > @@ -0,0 +1,18 @@
> > +/*
> > + * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
> > + * Distributed under the terms of the MIT License.
> > + */
> > +
> > +
> > +#include <OS.h>
> > +#include "syscalls.h"
> > +
> > +
> > +thread_id
> > +find_thread(const char* name)
> > +{
> > + // TODO x86_64: x86 is doing some TLS thing here. Should that be done
> here
> > + // too?
> > + return _kern_find_thread(name);
> > +}
>
> find_thread(NULL) is used relatively often (particularly in locking code),
> so ideally it should indeed avoid using a syscall.
>

Ah, OK. I'll fix that when I implement TLS.

>
> [...]
> > diff --git a/src/system/libroot/os/arch/x86_64/tls.cpp
> b/src/system/libroot/os/arch/x86_64/tls.cpp
> > new file mode 100644
> > index 0000000..794c422
> > --- /dev/null
> > +++ b/src/system/libroot/os/arch/x86_64/tls.cpp
> > @@ -0,0 +1,50 @@
> > +/*
> > + * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
> > + * Distributed under the terms of the MIT License.
> > + */
> > +
> > +
> > +// TODO x86_64.
> > +// Also want to add inline versions to support/TLS.h.
>
> I'm a bit undecided whether the performance gain is worth exposing
> implementation details. I think I'd prefer out of line assembly
> implementations.
>

Depends how often TLS gets used. From the look of it the most frequent use
is errno. I don't really think there would be much difference in not
inlining them.

Thanks,
Alex

Other related posts: