On Sat, Feb 18, 2023 at 2:40 PM Sergey Bugaev via Libc-alpha
<libc-al...@sourceware.org> wrote:
>
> Signed-off-by: Sergey Bugaev <buga...@gmail.com>
> ---
> sysdeps/mach/hurd/{i386 => x86}/init-first.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
> rename sysdeps/mach/hurd/{i386 => x86}/init-first.c (96%)
>
> diff --git a/sysdeps/mach/hurd/i386/init-first.c
> b/sysdeps/mach/hurd/x86/init-first.c
> similarity index 96%
> rename from sysdeps/mach/hurd/i386/init-first.c
> rename to sysdeps/mach/hurd/x86/init-first.c
> index a558da16..75ac1ff2 100644
> --- a/sysdeps/mach/hurd/i386/init-first.c
> +++ b/sysdeps/mach/hurd/x86/init-first.c
> @@ -227,10 +227,15 @@ init (int *data)
> values we set just above. We have stashed in %eax the user code
> return address. Push it on the top of the stack so it acts as
> init1's return address, and then jump there. */
> +#ifdef __x86_64__
> +asm ("call_init1:\n"
> + " push %rax\n"
> + " jmp *%rcx\n");
> +#else
> asm ("call_init1:\n"
> " push %eax\n"
> " jmp *%ecx\n");
> -
> +#endif
>
> /* Do the first essential initializations that must precede all else. */
> static inline void
> @@ -242,7 +247,7 @@ first_init (void)
> #ifndef SHARED
> /* In the static case, we need to set up TLS early so that the stack
> protection guard can be read at gs:0x14 by the gcc-generated snippets.
> */
> - _hurd_tls_init(&__init1_tcbhead);
> + _hurd_tls_init (&__init1_tcbhead);
> asm ("movw %%gs,%w0" : "=m" (__init1_desc));
> #endif
>
> @@ -300,7 +305,7 @@ _hurd_stack_setup (void)
> {
> /* If we use ``__builtin_frame_address (0) + 2'' here, GCC gets
> confused. */
> - init ((int *) &argc);
> + init (&argc);
> }
>
> /* Push the user return address after the argument data, and then
> @@ -308,9 +313,15 @@ _hurd_stack_setup (void)
> caller had called `doinit1' with the argument data already on the
> stack. */
> *--data = caller;
> +# ifdef __x86_64__
> + asm volatile ("movq %0, %%rsp\n" /* Switch to new outermost stack. */
> + "movq $0, %%rbp\n" /* Clear outermost frame pointer. */
Unless you are intentionally preserving flags, `xorl %%ebp, %%ebp` is
better way to
zero a register.
> + "jmp *%1" : : "r" (data), "r" (&doinit1));
> +# else
> asm volatile ("movl %0, %%esp\n" /* Switch to new outermost stack. */
> "movl $0, %%ebp\n" /* Clear outermost frame pointer. */
> "jmp *%1" : : "r" (data), "r" (&doinit1));
> +# endif
> /* NOTREACHED */
> }
>
> --
> 2.39.2
>