From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id B84F73858D20; Sun, 19 Feb 2023 23:42:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B84F73858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676850167; bh=GrKGcBVxEzFI409dJWeLG0CsUQMc7M0/Dv5JBDirEsk=; h=From:To:Subject:Date:From; b=hXguuG3bxh2xFM33jzSyA48J7fEE0zpYeb5398CHPBh6gJARKuQB4EkR8Tkntxpnm La+nWCCtvQAs6JzWBBDBVE3K3pmZzErTM1GMQs6iwvLh5CuF1Cc6aQ4HS2NrmS5qk0 xH+3kv7lfXM4hgaVqT9dJVrR6I6EG+GIajPm35GM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] hurd: Simplify init-first.c a bit X-Act-Checkin: glibc X-Git-Author: Sergey Bugaev X-Git-Refname: refs/heads/master X-Git-Oldrev: ee10f5dfd854c827ea5e4ab18e1da6552052bb08 X-Git-Newrev: 90ab316b02d496cfaf09396fcc0c9bc58f15a61c Message-Id: <20230219234247.B84F73858D20@sourceware.org> Date: Sun, 19 Feb 2023 23:42:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=90ab316b02d496cfaf09396fcc0c9bc58f15a61c commit 90ab316b02d496cfaf09396fcc0c9bc58f15a61c Author: Sergey Bugaev Date: Sat Feb 18 23:37:13 2023 +0300 hurd: Simplify init-first.c a bit And make it a bit more 64-bit ready. This is in preparation to moving this file into x86/ Signed-off-by: Sergey Bugaev Message-Id: <20230218203717.373211-6-bugaevc@gmail.com> Diff: --- sysdeps/mach/hurd/i386/init-first.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c index 94c946516a..a558da16bc 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -195,7 +195,7 @@ init (int *data) /* Call `init1' (above) with the user code as the return address, and the argument data immediately above that on the stack. */ - int usercode; + void *usercode, **ret_address; void call_init1 (void); @@ -206,10 +206,11 @@ init (int *data) recognize that this read operation may alias the following write operation, and thus is free to reorder the two, clobbering the original return address. */ - usercode = *((int *) __builtin_frame_address (0) + 1); + ret_address = (void **) __builtin_frame_address (0) + 1; + usercode = *ret_address; /* GCC 4.4.6 also wants us to force loading USERCODE already here. */ asm volatile ("# %0" : : "X" (usercode)); - *((void **) __builtin_frame_address (0) + 1) = &call_init1; + *ret_address = &call_init1; /* Force USERCODE into %eax and &init1 into %ecx, which are not restored by function return. */ asm volatile ("# a %0 c %1" : : "a" (usercode), "c" (&init1)); @@ -223,19 +224,9 @@ init (int *data) /* The return address of `init' above, was redirected to here, so at this point our stack is unwound and callers' registers restored. Only %ecx and %eax are call-clobbered and thus still have the - values we set just above. Fetch from there the new stack pointer - we will run on, and jmp to the run-time address of `init1'; when it - returns, it will run the user code with the argument data at the - top of the stack. */ -asm ("switch_stacks:\n" - " movl %eax, %esp\n" - " jmp *%ecx"); - -/* As in the stack-switching case, at this point our stack is unwound - and callers' registers restored, and only %ecx and %eax communicate - values from the lines above. In this case 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. */ + 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. */ asm ("call_init1:\n" " push %eax\n" " jmp *%ecx\n");