From patchwork Sat Feb 18 20:37:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 65220 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9ADE6382E699 for ; Sat, 18 Feb 2023 20:38:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9ADE6382E699 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676752696; bh=jlY8s5Momk93VyyBPAA+QkUCa9KqCf3ZVCnVTO9Uyq4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=m2o6uPCj7hkCexEysjZ4SQhBE7+duvs8WmU78/UT6ua4AOrkfWyAvcLgzVPeSoI7d 6n3PKkQ/KeFn4ajZvkxqyzwDdGhyl/2DNYhBMXV5SEn/IOnO+P0HCCwihVUahiK3zs fAhr41LACRaFFOawL3+aHZNZkesHvWWGMprvPcCc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 703363857835 for ; Sat, 18 Feb 2023 20:37:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 703363857835 Received: by mail-lj1-x232.google.com with SMTP id w17so1438497ljw.13 for ; Sat, 18 Feb 2023 12:37:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jlY8s5Momk93VyyBPAA+QkUCa9KqCf3ZVCnVTO9Uyq4=; b=bQmLwpp1MonWEi8bLJYqVRItQ8RtzfzjzDX36ovxdRiaj7GaEjWlXR3fzXkD5G9Sm+ 2SLhgOcgBQt+QQm/sdzwaITH/dHQXK+Hh8ADhIxK6Ti8lQIsLJvzJDxXgIW/GxBvFWmP XUlKPDok18RseIFIXynUPXUNYpwipP5yDeVKvLL/Wj1wGL6llMHUcoIFFBdI16u2zV2o FZF379jVMZw2F/Y7UtHCCAQESaMb+EXI/xFXFoDJdewU2PY6ohIuZp52t/vyMqPwGXTK 5YvgXVkSXyjVGZorrwySapHM+cZH3GSEyxPib4iUdjmkuaDxUd9jbfB4osZAWucOoeBS szHA== X-Gm-Message-State: AO0yUKWoNPrOZ+03pVv9L+IjP1IodxW6209jAAsAJnvv6cubPR7mt2yL YFgg8zPxU1WsL4fhXdqDwuo= X-Google-Smtp-Source: AK7set+tmOaMaIRtiA7TNRBHv7NIbTv9tslI8JgETh8dR+EnANWZVicBSnIMBfCvkgOoyuf6vb93qg== X-Received: by 2002:a2e:a238:0:b0:294:70b7:fd65 with SMTP id i24-20020a2ea238000000b0029470b7fd65mr1988768ljm.30.1676752659047; Sat, 18 Feb 2023 12:37:39 -0800 (PST) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e4a7:ca9:e8d7:4ead]) by smtp.gmail.com with ESMTPSA id u15-20020a05651c130f00b002934febffe4sm1004049lja.128.2023.02.18.12.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:37:38 -0800 (PST) To: bug-hurd@gnu.org, libc-alpha@sourceware.org Cc: =?utf-8?q?Fl=C3=A1vio_Cruz?= , Sergey Bugaev Subject: [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Date: Sat, 18 Feb 2023 23:37:13 +0300 Message-Id: <20230218203717.373211-6-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230218203717.373211-1-bugaevc@gmail.com> References: <20230218203717.373211-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" And make it a bit more 64-bit ready. This is in preparation to moving this file into x86/ Signed-off-by: Sergey Bugaev --- 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");