lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230612204514.292087-16-paulmck@kernel.org>
Date:   Mon, 12 Jun 2023 13:44:37 -0700
From:   "Paul E. McKenney" <paulmck@...nel.org>
To:     linux-kernel@...r.kernel.org
Cc:     gwml@...r.gnuweeb.org, kernel-team@...a.com, w@....eu,
        Zhangjin Wu <falcon@...ylab.org>, Willy Tarreau <w@....eu>,
        "Paul E . McKenney" <paulmck@...nel.org>
Subject: [PATCH v2 nolibc 16/53] tools/nolibc: riscv: Fix up load/store instructions for rv32

From: Zhangjin Wu <falcon@...ylab.org>

When compile nolibc application for rv32, we got such errors:
  nolibc/sysroot/riscv/include/arch.h:190: Error: unrecognized opcode `ld a4,0(a3)'
  nolibc/sysroot/riscv/include/arch.h:194: Error: unrecognized opcode `sd a3,%lo(_auxv)(a4)'
  nolibc/sysroot/riscv/include/arch.h:196: Error: unrecognized opcode `sd a2,%lo(environ)(a3)'

Refer to arch/riscv/include/asm/asm.h and add REG_L/REG_S macros here to let
rv32 uses its own lw/sw instructions.

Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
Signed-off-by: Willy Tarreau <w@....eu>
Signed-off-by: Paul E. McKenney <paulmck@...nel.org>
---
 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 0d5f15fdedc4..992a1739dd9c 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                                       */
-- 
2.40.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ