From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-6.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by gnuweeb.org (Postfix) with ESMTPS id 5745D7E409 for ; Tue, 19 Apr 2022 00:42:34 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=I9GbkojD; dkim-atps=neutral Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id CA7F6CE12A8; Tue, 19 Apr 2022 00:42:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F4CCC341D5; Tue, 19 Apr 2022 00:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650328948; bh=hgtXtp6oDk1Z4mAAuthMNuVpmsGa0EQ5/tDSm1m1OLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9GbkojD5TGG1Rz2fcRovMaEQtrYY6dPf61m5dYvkRDtiMRFY95n/0dr6HT84ysRC BnVLtQ/GeRWwyPStzg7GIa1SSgTZo1emgNer2Dk8kKJlvdp4Cxa/K2nQfxBgOnHT/F JOr3qIYD8rL1/pHDQOJ1hHQ3GPpmvhN59Bi+51tFUCcAcDtrSUMPDMzTE9pioK8zZG kZ3cQKe53+tEdtK+sfqOe+0QdCSYVKOue4xD9tJ475Fxi5LUT/SI4THRD3ru++y2yD u02JTZrxoA6ZMSZLtqOYokmOm5n5THEz7ud8sg4+/6JY92ynZvydxtW88c3bU2yGFr cbOQCo9HY1eEw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6E7AB5C04C6; Mon, 18 Apr 2022 17:42:27 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@fb.com, w@lwt.eu, Ammar Faizi , x86@kernel.org, llvm@lists.linux.dev, David Laight , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH nolibc 56/61] tools/nolibc: i386: Implement syscall with 6 arguments Date: Mon, 18 Apr 2022 17:42:20 -0700 Message-Id: <20220419004225.3952530-56-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> References: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi On i386, the 6th argument of syscall goes in %ebp. However, both Clang and GCC cannot use %ebp in the clobber list and in the "r" constraint without using -fomit-frame-pointer. To make it always available for any kind of compilation, the below workaround is implemented. 1) Push the 6-th argument. 2) Push %ebp. 3) Load the 6-th argument from 4(%esp) to %ebp. 4) Do the syscall (int $0x80). 5) Pop %ebp (restore the old value of %ebp). 6) Add %esp by 4 (undo the stack pointer). Cc: x86@kernel.org Cc: llvm@lists.linux.dev Link: https://lore.kernel.org/lkml/2e335ac54db44f1d8496583d97f9dab0@AcuMS.aculab.com Suggested-by: David Laight Acked-by: Willy Tarreau Signed-off-by: Ammar Faizi Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-i386.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index 10aada40680d..d7e7212346e2 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -167,6 +167,29 @@ struct sys_stat_struct { _ret; \ }) +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ +({ \ + long _eax = (long)(num); \ + long _arg6 = (long)(arg6); /* Always in memory */ \ + __asm__ volatile ( \ + "pushl %[_arg6]\n\t" \ + "pushl %%ebp\n\t" \ + "movl 4(%%esp),%%ebp\n\t" \ + "int $0x80\n\t" \ + "popl %%ebp\n\t" \ + "addl $4,%%esp\n\t" \ + : "+a"(_eax) /* %eax */ \ + : "b"(arg1), /* %ebx */ \ + "c"(arg2), /* %ecx */ \ + "d"(arg3), /* %edx */ \ + "S"(arg4), /* %esi */ \ + "D"(arg5), /* %edi */ \ + [_arg6]"m"(_arg6) /* memory */ \ + : "memory", "cc" \ + ); \ + _eax; \ +}) + /* startup code */ /* * i386 System V ABI mandates: -- 2.31.1.189.g2e36527f23