From: Sergey Bugaev <bugaevc@gmail.com>
To: bug-hurd@gnu.org, libc-alpha@sourceware.org
Cc: "Flávio Cruz" <flaviocruz@gmail.com>,
"Sergey Bugaev" <bugaevc@gmail.com>
Subject: [RFC PATCH 5/9] hurd: Simplify init-first.c a bit
Date: Sat, 18 Feb 2023 23:37:13 +0300 [thread overview]
Message-ID: <20230218203717.373211-6-bugaevc@gmail.com> (raw)
In-Reply-To: <20230218203717.373211-1-bugaevc@gmail.com>
And make it a bit more 64-bit ready. This is in preparation to moving this
file into x86/
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
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 94c94651..a558da16 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");
--
2.39.2
next prev parent reply other threads:[~2023-02-18 20:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
2023-02-19 23:32 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 2/9] hurd: Use proper integer types Sergey Bugaev
2023-02-19 23:33 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 3/9] hurd: Fix xattr function return type Sergey Bugaev
2023-02-19 23:34 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 4/9] hurd: Make timer_t pointer-sized Sergey Bugaev
2023-02-19 23:35 ` Samuel Thibault
2023-02-18 20:37 ` Sergey Bugaev [this message]
2023-02-19 23:45 ` [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 6/9] mach: Use PAGE_SIZE Sergey Bugaev
2023-02-19 23:47 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
2023-02-20 0:01 ` Samuel Thibault
2023-02-20 16:16 ` Sergey Bugaev
2023-02-20 17:10 ` Sergey Bugaev
2023-02-20 17:31 ` Samuel Thibault
2023-02-20 17:27 ` Noah Goldstein
2023-02-18 20:37 ` [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code Sergey Bugaev
2023-02-20 0:30 ` Samuel Thibault
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230218203717.373211-6-bugaevc@gmail.com \
--to=bugaevc@gmail.com \
--cc=bug-hurd@gnu.org \
--cc=flaviocruz@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).