From patchwork Sat Feb 18 20:37:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 65223 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 DEA5A383FB8D for ; Sat, 18 Feb 2023 20:39:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEA5A383FB8D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676752763; bh=tr3GiOLSPHhnoS46QIfw1VZNQ/rESRBBVBRMhvWQec0=; 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=oPzzTCR+0rgM3Qbq7cGPBmAucbolWy9Puyphyp7Xtc714y5nCX/H3JodN0A2mRx/e R9ixIRNWsT6CvT6ZUkusdLSFmS4mCrnTrf1Knc2IVAV+yWrJqorcZpbtnIOVuIZCdS wIS5TH/prpmY/Ww01HO1L2PMyc++tGHgwnQZtX6M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 83D393858D38 for ; Sat, 18 Feb 2023 20:37:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83D393858D38 Received: by mail-lj1-x233.google.com with SMTP id j3so1396485lji.7 for ; Sat, 18 Feb 2023 12:37:42 -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=tr3GiOLSPHhnoS46QIfw1VZNQ/rESRBBVBRMhvWQec0=; b=p+yomVv407ESV3dkg0XouyELBWR6129BSYRc/itA2Uu7iAgPwrTg8nTpjjHBryF6Jq Lfny4buUf4+KkJ35zoCtT9LsW5mfcq4JWX6q03R3K6+iBQi2bMhd1wIAo/MtLp1szOEO 8A/l7cke49rVkOOhzURUN/FyxD6sjMQv+TSYsDVuSu14BS5RdZaauurzoRk9np2mc6Gn EYZ5px0HJOyiD2Y/MdXDTM/23HHCARbcf5HpKcYoI7wUbju8WGH3NNDtQnKh28RPxaWn st6NwguOZ0f8nGHEj6PDgou0Twue8uNVA+fMf9z86raPrFHPxjDpjcr3NPl8St3YoN6p mLZQ== X-Gm-Message-State: AO0yUKWtrkmtyl4tkXG2RwN3RHGtAG16PxuPmOGpmHEotNu5eiJgCzdj haILaUGYMUS1keXMlztPruLFpqpzQ2ik5A== X-Google-Smtp-Source: AK7set9TBGDDiNG+iIFj98nnw7yEnqGVocCYy4uejD7C5tVtFo9ilVKDRr1zSkuoOiwI8U82CxoCzw== X-Received: by 2002:a2e:b5d8:0:b0:290:6a6f:48d1 with SMTP id g24-20020a2eb5d8000000b002906a6f48d1mr1503402ljn.43.1676752662073; Sat, 18 Feb 2023 12:37:42 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:37:41 -0800 (PST) To: bug-hurd@gnu.org, libc-alpha@sourceware.org Cc: =?utf-8?q?Fl=C3=A1vio_Cruz?= , Sergey Bugaev Subject: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Date: Sat, 18 Feb 2023 23:37:15 +0300 Message-Id: <20230218203717.373211-8-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.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, 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" Signed-off-by: Sergey Bugaev --- 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. */ + "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 */ }