From patchwork Thu May 18 17:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 95999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp649524vqo; Thu, 18 May 2023 10:07:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iS8Hc6xyIU9R6QZ94QtRIZmznP0A/8p71Xffmb8G1WqoF7PJRs9OEf57kbC+8OmIB2Gvg X-Received: by 2002:a05:6a21:9808:b0:f0:c858:2d68 with SMTP id ue8-20020a056a21980800b000f0c8582d68mr320191pzb.35.1684429638369; Thu, 18 May 2023 10:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684429638; cv=none; d=google.com; s=arc-20160816; b=TJFSg0NAyQoBqX1KDzhEmyJLvs9Dbm9XlQ6RLQLyTP0/VhGFl+4N06uWEMF1Sjteso Bjn5OOYaupNSCar+5Vh919C9yej4GzBU9zPjul0l2OjL9afGGcsmdeVAeX8vuqG/RNvv HY+HCYyJTZbIBUsmEGPEeeGcfyLTC7pylhaITuy3D7Adx/Ibe+jLPn6EzUKWmSU3HaxF RO5eqX2ecqLWxwS+0WtTPSQfZ6b1oQFicfHDaqQogTUWpLj/a4svzPsDuoq++e812NRR yBWeiTEMs1NI1CNU/zbo6r+r1GI9oYTRT17J4RKthAcvb48rdlLICPYzMPQ5ULtT6+Ra OUyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=/+NKM1/A51htXeqCxKoc7d/ucDrKA5mKtCPEPL9nVH8=; b=cYjLVrV18VtVX9mEoiu6ZR66g0JnYz1MtCZ9/VW70fL2CHTYocevdFRqFYwT9Sn83L wtHJvkt4pSdeYBaSyubdPra/vXvXRBZ62j2Fl0EbrjB1CdvESq2IaDJ+MHC9oy0gqy6q Biq47GDuKZqeDSGF2S9Bx5eGQSlU3OPojiwFgA7CRAtSTCkuV6dIr1+caoGoG6iv3he5 lXrhpKwdCNrYZPF7N1Rz2NUbCoGXFjvFnz1ZkmzYpeVi42NuKFVyRhE6xwLLYSAEz+R2 M+cbXuYmCgKNrHgGpYM+mSCnIFKq8na0G7SY0hGlGppjdA7DDqPbKKAmNtTiz0NKufuA 6P+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q26-20020aa7961a000000b006432e218a1csi2046123pfg.152.2023.05.18.10.07.03; Thu, 18 May 2023 10:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbjERREp (ORCPT + 99 others); Thu, 18 May 2023 13:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjERREn (ORCPT ); Thu, 18 May 2023 13:04:43 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9DAE199 for ; Thu, 18 May 2023 10:04:34 -0700 (PDT) X-QQ-mid: bizesmtp70t1684429359tgkq75s7 Received: from linux-lab-host.localdomain ( [119.123.131.162]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 19 May 2023 01:02:38 +0800 (CST) X-QQ-SSF: 01200000000000C0V000000A0000000 X-QQ-FEAT: 83ShfzFP0oBUigIVReinYVVse+wZCQ1xyB9c0HLHomQcRIhIHH1Wbj3e7QJxl XRGA27Pmu0I1ZUz4S0zTfxBJxpCfVY2O9Br44TiESs6isz5Vtok9zA/tKqQIvvWrYlIROuQ VsD2bhbVu+YdqHdX2WGGQQw6BHsVl4Z09JVxFJM5MQcYeYxSk+6352EdRNFQ3hgEXSLPsK6 QovuyY9gP1bqHyd5vMUnXOTo0nsszRnIY6GU2j5ZcqtHegYeeXIai6gsSucGfGBHzffKm4C jGFszYGPzvI101y+uvQLGL7xjE/aa444ATZrCbazXXe267+pOQOFXlumTidsRyO2v7gjq+7 pcRoZsDZ0W0oy7EGPePzY2orOyZI5oF1gzrkbGSrZrveR9gzn4= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13521670369968386674 From: Zhangjin Wu To: Willy Tarreau , Palmer Dabbelt , Paul Walmsley , Albert Ou Cc: "Paul E . McKenney" , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Zhangjin Wu Subject: [PATCH 1/2] tools/nolibc: riscv: Fix up load/store instructions for rv32 Date: Fri, 19 May 2023 01:02:12 +0800 Message-Id: <1425d092ef4c1242646ede2bbcbc3ac945c2b274.1684425792.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766252492398688038?= X-GMAIL-MSGID: =?utf-8?q?1766252492398688038?= Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-riscv.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index e197fcb10ac0..7d7c4beabb8d 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -33,9 +33,13 @@ struct sys_stat_struct { #if __riscv_xlen == 64 #define PTRLOG "3" #define SZREG "8" +#define REG_L "ld" +#define REG_S "sd" #elif __riscv_xlen == 32 #define PTRLOG "2" #define SZREG "4" +#define REG_L "lw" +#define REG_S "sw" #endif /* Syscalls for RISCV : @@ -181,7 +185,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" - "lw a0, 0(sp)\n" // argc (a0) was in the stack + REG_L" a0, 0(sp)\n" // argc (a0) was in the stack "add a1, sp, "SZREG"\n" // argv (a1) = sp "slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ... "add a2, a2, "SZREG"\n" // + SZREG (skip null) @@ -189,14 +193,14 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "add a3, a2, zero\n" // iterate a3 over envp to find auxv (after NULL) "0:\n" // do { - "ld a4, 0(a3)\n" // a4 = *a3; + REG_L" a4, 0(a3)\n" // a4 = *a3; "add a3, a3, "SZREG"\n" // a3 += sizeof(void*); "bne a4, zero, 0b\n" // } while (a4); "lui a4, %hi(_auxv)\n" // a4 = &_auxv (high bits) - "sd a3, %lo(_auxv)(a4)\n" // store a3 into _auxv + REG_S" a3, %lo(_auxv)(a4)\n" // store a3 into _auxv - "lui a3, %hi(environ)\n" // a3 = &environ (high bits) - "sd a2,%lo(environ)(a3)\n" // store envp(a2) into environ + "lui a3, %hi(environ)\n" // a3 = &environ (high bits) + REG_S" a2,%lo(environ)(a3)\n"// store envp(a2) into environ "andi sp,a1,-16\n" // sp must be 16-byte aligned "call main\n" // main() returns the status code, we'll exit with it. "li a7, 93\n" // NR_exit == 93 From patchwork Thu May 18 17:03:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 96000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp651305vqo; Thu, 18 May 2023 10:09:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mJGRm5RE39SEiNYWT3PnFNqIvdQlmvpux2h4N7WgWJpcurA5uDdFWYn/oyFXhXw909XcX X-Received: by 2002:a17:902:eccc:b0:1ac:7245:ba5a with SMTP id a12-20020a170902eccc00b001ac7245ba5amr3280911plh.61.1684429764671; Thu, 18 May 2023 10:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684429764; cv=none; d=google.com; s=arc-20160816; b=ginvUnoAoUwqKRk6rwsgGp7LR/QO68Mb5/v0nI1PVJ7Xj2+ktdLLjMNu83uXz2DBFD c8MZu0PTAXIp5qLHhi5dWlHc9b2lYGD6FGSHDDyQjTLJ96JcYFZGPCyG2THOytZHnJ/a dVyA3JANAL+LHPdDHdxrgf3waZlI6K1fMw49E+6V073IIeGYsqofcdT+n9U6DbBgqd15 B/7fZBZH2T4B+HkjDCsIGDkqlvG3yFELxZU299OxFIS6s3WtxLbSEVLWBHpUzUe3fInZ Gdy2N1+y0wxW7GQAJqrM2CqECdL7PGUvP9EaeUxfS+qlN64WC+fgTImSjct/CsLRtLY9 YUng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=s2eDFovB1uDMGZtdYq1v4QFuDaUcAK2z1MF4fV7eBr4=; b=Cak8b3+LG/WWTrgxY0wztYuuXDwciiCzAuyToL/bIs1q8GkWB8FWlG6WVRLNBSWQT9 TykjZ5k7aCTp2QqY/71azHLmNjq9yvX3Bxfhk9KApZJ9JIGbGKSDhSiun8uSYDUT+8Mr XO1LDmi82me90YuWof5++zEHCBku8QSglrus1hrMnq6XM9FT6oVD0PfhBplhP73pkobV pT4kBI9BOShLExFUfDK8oP+kv+3r0/wqjfbG61ZSd/TyiNQvviJB7yq83WlTCa/aff0l BtwsKfD7NTB1I1PTl2mWDHRScs2Ovx5ipLvom6GBXoggw2oM+10S56RTtjC/NA/563J6 XKpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a170902f68d00b001a95b85b070si1757910plg.604.2023.05.18.10.09.09; Thu, 18 May 2023 10:09:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjERREJ (ORCPT + 99 others); Thu, 18 May 2023 13:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbjERREG (ORCPT ); Thu, 18 May 2023 13:04:06 -0400 X-Greylist: delayed 73 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 18 May 2023 10:04:00 PDT Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01297E69 for ; Thu, 18 May 2023 10:04:00 -0700 (PDT) X-QQ-mid: bizesmtp68t1684429433tu2oywf5 Received: from linux-lab-host.localdomain ( [119.123.131.162]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 19 May 2023 01:03:52 +0800 (CST) X-QQ-SSF: 01200000000000C0V000000A0000000 X-QQ-FEAT: 52Hx6s90yLUx+utHt+6bFHvQXW0WiAszRJitTBNppc4EY8DRALtcS1CtKQmqa TlWtRfGFRGdejKhmIK/ziEf82MHLcOCF001VkX/uXD0B++NhRtTTDurusfZESve9dnnCNgi U9kLGSI7H5NovK8Rgj69s+0mxS+gcgeFK5f04VREl2E2oDKb2UCJ58NxYZtirW4PjGxaWLK 9/XKatAVxn3FMJyE0UnD0GrU3aB6SS1sWsAPGi5YpxGRrPReBfcgFn4rMltjipWtP39m5nO /5zvjVkwm2aRD8tQepNl9SrNYf1dckkmjtIfWrRL8Ot2aVtRUuMBqpL5kNDxD5a8dezAs1J vfjeSpTfnhNqZiZyu6VAHo+loFHyNWHSAgdXVSidN1akhiKr4czN4x8zk31KQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3862181891431925915 From: Zhangjin Wu To: Willy Tarreau , Palmer Dabbelt , Paul Walmsley , Albert Ou Cc: "Paul E . McKenney" , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Zhangjin Wu Subject: [PATCH 2/2] tools/nolibc: riscv: Support __NR_llseek for rv32 Date: Fri, 19 May 2023 01:03:50 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766252625028127495?= X-GMAIL-MSGID: =?utf-8?q?1766252625028127495?= There is no __NR_lseek for rv32, use __NR_llseek instead. This code is based on sysdeps/unix/sysv/linux/lseek.c of glibc. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/std.h | 1 + tools/include/nolibc/sys.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tools/include/nolibc/std.h b/tools/include/nolibc/std.h index 933bc0be7e1c..83c0b0cb9564 100644 --- a/tools/include/nolibc/std.h +++ b/tools/include/nolibc/std.h @@ -32,5 +32,6 @@ typedef signed long off_t; typedef signed long blksize_t; typedef signed long blkcnt_t; typedef signed long time_t; +typedef long long loff_t; #endif /* _NOLIBC_STD_H */ diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 5d624dc63a42..ab32f3c0a460 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -668,7 +668,26 @@ int link(const char *old, const char *new) static __attribute__((unused)) off_t sys_lseek(int fd, off_t offset, int whence) { +#ifdef __NR_lseek return my_syscall3(__NR_lseek, fd, offset, whence); +#elif defined(__NR_llseek) + loff_t res; + off_t retval; + + int rc = my_syscall5(__NR_llseek, fd, (long) (((uint64_t) (offset)) >> 32), (long) offset, &res, whence); + + if (rc) + return rc; + + retval = (off_t) res; + if (retval == res) + return retval; + + SET_ERRNO(EOVERFLOW); + return (off_t) -1; +#else +#error Neither __NR_lseek nor __NR_llseek defined, cannot implement sys_lseek() +#endif } static __attribute__((unused))