From: drahn Date: Sun, 9 May 2021 21:26:06 +0000 (+0000) Subject: Change offsets to (N * 8) to reduce chance of register clobber and mistakes. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1cb19090bf0e66960b2e1fc2e5f52f7be1ca5353;p=openbsd Change offsets to (N * 8) to reduce chance of register clobber and mistakes. Simplify integer loading, use 'li , ' instead of x0/zero register Adjust _JB_SIGMASK to not collide with saved registers. --- diff --git a/lib/libc/arch/riscv64/gen/_setjmp.S b/lib/libc/arch/riscv64/gen/_setjmp.S index 5de861ce7ed..85bbe0bd716 100644 --- a/lib/libc/arch/riscv64/gen/_setjmp.S +++ b/lib/libc/arch/riscv64/gen/_setjmp.S @@ -1,4 +1,4 @@ -/* $OpenBSD: _setjmp.S,v 1.1 2021/04/28 15:28:54 drahn Exp $ */ +/* $OpenBSD: _setjmp.S,v 1.2 2021/05/09 21:26:06 drahn Exp $ */ /* * Copyright (c) 2020 Dale Rahn * @@ -23,38 +23,38 @@ ENTRY(_setjmp) addi sp, sp, -32 RETGUARD_SETUP(_setjmp, t6) - sd sp, 8(a0) + sd sp, (1 * 8)(a0) /* Store the general purpose registers and ra */ - sd s0, 16(a0) - sd s1, 24(a0) - sd s2, 32(a0) - sd s3, 40(a0) - sd s4, 48(a0) - sd s5, 56(a0) - sd s6, 64(a0) - sd s7, 72(a0) - sd s8, 90(a0) - sd s9, 98(a0) - sd s10, 106(a0) - sd s11, 112(a0) - sd ra, 120(a0) + sd s0, (2 * 8)(a0) + sd s1, (3 * 8)(a0) + sd s2, (4 * 8)(a0) + sd s3, (5 * 8)(a0) + sd s4, (6 * 8)(a0) + sd s5, (7 * 8)(a0) + sd s6, (8 * 8)(a0) + sd s7, (9 * 8)(a0) + sd s8, (10 * 8)(a0) + sd s9, (11 * 8)(a0) + sd s10, (12 * 8)(a0) + sd s11, (13 * 8)(a0) + sd ra, (14 * 8)(a0) #ifndef _STANDALONE /* Store the fp registers */ - fsd fs0, 128(a0) - fsd fs1, 136(a0) - fsd fs2, 144(a0) - fsd fs3, 152(a0) - fsd fs4, 160(a0) - fsd fs5, 168(a0) - fsd fs6, 176(a0) - fsd fs7, 184(a0) - fsd fs8, 192(a0) - fsd fs9, 200(a0) - fsd fs10, 208(a0) - fsd fs11, 216(a0) + fsd fs0, (15 * 8)(a0) + fsd fs1, (16 * 8)(a0) + fsd fs2, (17 * 8)(a0) + fsd fs3, (18 * 8)(a0) + fsd fs4, (19 * 8)(a0) + fsd fs5, (20 * 8)(a0) + fsd fs6, (21 * 8)(a0) + fsd fs7, (22 * 8)(a0) + fsd fs8, (23 * 8)(a0) + fsd fs9, (24 * 8)(a0) + fsd fs10, (25 * 8)(a0) + fsd fs11, (26 * 8)(a0) frcsr t0 - sd t0, 232(a0) + sd t0, (27 * 8)(a0) #endif /* Return value */ @@ -69,44 +69,44 @@ ENTRY(_longjmp) RETGUARD_LOAD_RANDOM(_longjmp, t6) /* Restore the stack pointer */ - ld t0, 8(a0) + ld t0, (1 * 8)(a0) mv sp, t0 /* Store the general purpose registers and ra */ - ld s0, 16(a0) - ld s1, 24(a0) - ld s2, 32(a0) - ld s3, 40(a0) - ld s4, 48(a0) - ld s5, 56(a0) - ld s6, 64(a0) - ld s7, 72(a0) - ld s8, 90(a0) - ld s9, 98(a0) - ld s10, 106(a0) - ld s11, 112(a0) - sd ra, 120(a0) + ld s0, (2 * 8)(a0) + ld s1, (3 * 8)(a0) + ld s2, (4 * 8)(a0) + ld s3, (5 * 8)(a0) + ld s4, (6 * 8)(a0) + ld s5, (7 * 8)(a0) + ld s6, (8 * 8)(a0) + ld s7, (9 * 8)(a0) + ld s8, (10 * 8)(a0) + ld s9, (11 * 8)(a0) + ld s10, (12 * 8)(a0) + ld s11, (13 * 8)(a0) + ld ra, (14 * 8)(a0) #ifndef _STANDALONE /* Store the fp registers */ - fld fs0, 128(a0) - fld fs1, 136(a0) - fld fs2, 144(a0) - fld fs3, 152(a0) - fld fs4, 160(a0) - fld fs5, 168(a0) - fld fs6, 176(a0) - fld fs7, 184(a0) - fld fs8, 192(a0) - fld fs9, 200(a0) - fld fs10, 208(a0) - fld fs11, 216(a0) - ld t0, 232(a0) + fld fs0, (15 * 8)(a0) + fld fs1, (16 * 8)(a0) + fld fs2, (17 * 8)(a0) + fld fs3, (18 * 8)(a0) + fld fs4, (19 * 8)(a0) + fld fs5, (20 * 8)(a0) + fld fs6, (21 * 8)(a0) + fld fs7, (22 * 8)(a0) + fld fs8, (23 * 8)(a0) + fld fs9, (24 * 8)(a0) + fld fs10, (25 * 8)(a0) + fld fs11, (26 * 8)(a0) + ld t0, (27 * 8)(a0) fscsr t0 #endif /* Load the return value */ - add a0, zero, 1 + li a0, 1 beqz a1, 1f mv a0, a1 1: diff --git a/lib/libc/arch/riscv64/gen/setjmp.S b/lib/libc/arch/riscv64/gen/setjmp.S index 411fc5ab049..92f11dd1873 100644 --- a/lib/libc/arch/riscv64/gen/setjmp.S +++ b/lib/libc/arch/riscv64/gen/setjmp.S @@ -1,4 +1,4 @@ -/* $OpenBSD: setjmp.S,v 1.1 2021/04/28 15:28:54 drahn Exp $ */ +/* $OpenBSD: setjmp.S,v 1.2 2021/05/09 21:26:06 drahn Exp $ */ /* * Copyright (c) 2020 Dale Rahn * @@ -21,51 +21,50 @@ ENTRY(setjmp) RETGUARD_SETUP(setjmp, t6) - mv a2, a0 /* save jmpbuf in x2 */ + mv a2, a0 /* save jmpbuf in a2 */ /* Store the signal mask */ - mv a2, a0 /* set */ - mv a1, zero - add a0, zero, 1 + li a1, 0 + li a0, 1 SYSTRAP(sigprocmask) sw a0, (_JB_SIGMASK * 8)(a2) /* oset */ mv a0, a2 - sd sp, 8(a0) + sd sp, (1 * 8)(a0) /* Store the general purpose registers and ra */ - sd s0, 16(a0) - sd s1, 24(a0) - sd s2, 32(a0) - sd s3, 40(a0) - sd s4, 48(a0) - sd s5, 56(a0) - sd s6, 64(a0) - sd s7, 72(a0) - sd s8, 90(a0) - sd s9, 98(a0) - sd s10, 106(a0) - sd s11, 112(a0) - sd ra, 120(a0) + sd s0, (2 * 8)(a0) + sd s1, (3 * 8)(a0) + sd s2, (4 * 8)(a0) + sd s3, (5 * 8)(a0) + sd s4, (6 * 8)(a0) + sd s5, (7 * 8)(a0) + sd s6, (8 * 8)(a0) + sd s7, (9 * 8)(a0) + sd s8, (10 * 8)(a0) + sd s9, (11 * 8)(a0) + sd s10, (12 * 8)(a0) + sd s11, (13 * 8)(a0) + sd ra, (14 * 8)(a0) /* Store the fp registers */ - fsd fs0, 128(a0) - fsd fs1, 136(a0) - fsd fs2, 144(a0) - fsd fs3, 152(a0) - fsd fs4, 160(a0) - fsd fs5, 168(a0) - fsd fs6, 176(a0) - fsd fs7, 184(a0) - fsd fs8, 192(a0) - fsd fs9, 200(a0) - fsd fs10, 208(a0) - fsd fs11, 216(a0) + fsd fs0, (15 * 8)(a0) + fsd fs1, (16 * 8)(a0) + fsd fs2, (17 * 8)(a0) + fsd fs3, (18 * 8)(a0) + fsd fs4, (19 * 8)(a0) + fsd fs5, (20 * 8)(a0) + fsd fs6, (21 * 8)(a0) + fsd fs7, (22 * 8)(a0) + fsd fs8, (23 * 8)(a0) + fsd fs9, (24 * 8)(a0) + fsd fs10, (25 * 8)(a0) + fsd fs11, (26 * 8)(a0) frcsr t0 - sd t0, 232(a0) + sd t0, (27 * 8)(a0) /* Return value */ - mv a0, zero + li a0, 0 RETGUARD_CHECK(setjmp, t6) ret @@ -79,49 +78,49 @@ ENTRY(longjmp) /* Restore the signal mask */ lw a1, (_JB_SIGMASK * 8)(a2) /* set */ - add a0, zero, 3 /* SIG_SETMASK */ + li a0, 3 /* SIG_SETMASK */ SYSTRAP(sigprocmask) mv a0, a2 mv a1, a3 /* Restore the stack pointer */ - ld t0, 8(a0) + ld t0, (1 * 8)(a0) mv sp, t0 /* Store the general purpose registers and ra */ - ld s0, 16(a0) - ld s1, 24(a0) - ld s2, 32(a0) - ld s3, 40(a0) - ld s4, 48(a0) - ld s5, 56(a0) - ld s6, 64(a0) - ld s7, 72(a0) - ld s8, 90(a0) - ld s9, 98(a0) - ld s10, 106(a0) - ld s11, 112(a0) - sd ra, 120(a0) + ld s0, (2 * 8)(a0) + ld s1, (3 * 8)(a0) + ld s2, (4 * 8)(a0) + ld s3, (5 * 8)(a0) + ld s4, (6 * 8)(a0) + ld s5, (7 * 8)(a0) + ld s6, (8 * 8)(a0) + ld s7, (9 * 8)(a0) + ld s8, (10 * 8)(a0) + ld s9, (11 * 8)(a0) + ld s10, (12 * 8)(a0) + ld s11, (13 * 8)(a0) + ld ra, (14 * 8)(a0) /* Store the fp registers */ - fld fs0, 128(a0) - fld fs1, 136(a0) - fld fs2, 144(a0) - fld fs3, 152(a0) - fld fs4, 160(a0) - fld fs5, 168(a0) - fld fs6, 176(a0) - fld fs7, 184(a0) - fld fs8, 192(a0) - fld fs9, 200(a0) - fld fs10, 208(a0) - fld fs11, 216(a0) - ld t0, 232(a0) + fld fs0, (15 * 8)(a0) + fld fs1, (16 * 8)(a0) + fld fs2, (17 * 8)(a0) + fld fs3, (18 * 8)(a0) + fld fs4, (19 * 8)(a0) + fld fs5, (20 * 8)(a0) + fld fs6, (21 * 8)(a0) + fld fs7, (22 * 8)(a0) + fld fs8, (23 * 8)(a0) + fld fs9, (24 * 8)(a0) + fld fs10, (25 * 8)(a0) + fld fs11, (26 * 8)(a0) + ld t0, (27 * 8)(a0) fscsr t0 /* Load the return value */ - add a0, zero, 1 + li a0, 1 beqz a1, 1f mv a0, a1 1: diff --git a/lib/libc/arch/riscv64/gen/sigsetjmp.S b/lib/libc/arch/riscv64/gen/sigsetjmp.S index 944562debb0..49067438f23 100644 --- a/lib/libc/arch/riscv64/gen/sigsetjmp.S +++ b/lib/libc/arch/riscv64/gen/sigsetjmp.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sigsetjmp.S,v 1.1 2021/04/28 15:28:54 drahn Exp $ */ +/* $OpenBSD: sigsetjmp.S,v 1.2 2021/05/09 21:26:06 drahn Exp $ */ /* * Copyright (c) 2020 Dale Rahn * @@ -21,11 +21,10 @@ ENTRY(sigsetjmp) RETGUARD_SETUP(setjmp, t6) - mv a2, a0 /* save jmpbuf in x2 */ + mv a2, a0 /* save jmpbuf in a2 */ li a0, 0 beqz a1, 1f /* Store the signal mask */ - mv a2, a0 /* set */ li a1, 0 li a0, 1 /* SIG_BLOCK */ SYSTRAP(sigprocmask) @@ -33,41 +32,41 @@ ENTRY(sigsetjmp) sw a0, (_JB_SIGMASK * 8)(a2) /* oset */ mv a0, a2 - sd sp, 8(a0) + sd sp, (1 * 8)(a0) /* Store the general purpose registers and ra */ - sd s0, 16(a0) - sd s1, 24(a0) - sd s2, 32(a0) - sd s3, 40(a0) - sd s4, 48(a0) - sd s5, 56(a0) - sd s6, 64(a0) - sd s7, 72(a0) - sd s8, 90(a0) - sd s9, 98(a0) - sd s10, 106(a0) - sd s11, 112(a0) - sd ra, 120(a0) + sd s0, (2 * 8)(a0) + sd s1, (3 * 8)(a0) + sd s2, (4 * 8)(a0) + sd s3, (5 * 8)(a0) + sd s4, (6 * 8)(a0) + sd s5, (7 * 8)(a0) + sd s6, (8 * 8)(a0) + sd s7, (9 * 8)(a0) + sd s8, (10 * 8)(a0) + sd s9, (11 * 8)(a0) + sd s10, (12 * 8)(a0) + sd s11, (13 * 8)(a0) + sd ra, (14 * 8)(a0) /* Store the fp registers */ - fsd fs0, 128(a0) - fsd fs1, 136(a0) - fsd fs2, 144(a0) - fsd fs3, 152(a0) - fsd fs4, 160(a0) - fsd fs5, 168(a0) - fsd fs6, 176(a0) - fsd fs7, 184(a0) - fsd fs8, 192(a0) - fsd fs9, 200(a0) - fsd fs10, 208(a0) - fsd fs11, 216(a0) + fsd fs0, (15 * 8)(a0) + fsd fs1, (16 * 8)(a0) + fsd fs2, (17 * 8)(a0) + fsd fs3, (18 * 8)(a0) + fsd fs4, (19 * 8)(a0) + fsd fs5, (20 * 8)(a0) + fsd fs6, (21 * 8)(a0) + fsd fs7, (22 * 8)(a0) + fsd fs8, (23 * 8)(a0) + fsd fs9, (24 * 8)(a0) + fsd fs10, (25 * 8)(a0) + fsd fs11, (26 * 8)(a0) frcsr t0 - sd t0, 232(a0) + sd t0, (27 * 8)(a0) /* Return value */ - mv a0, x0 + li a0, 0 RETGUARD_CHECK(setjmp, t6) ret @@ -83,7 +82,7 @@ ENTRY(siglongjmp) lw a1, (_JB_SIGMASK * 8)(a2) /* set */ beqz a1, 1f - add a0, zero, 3 /* SIG_SETMASK */ + li a0, 3 /* SIG_SETMASK */ SYSTRAP(sigprocmask) 1: @@ -91,42 +90,42 @@ ENTRY(siglongjmp) mv a1, a3 /* Restore the stack pointer */ - ld t0, 8(a0) + ld t0, (1 * 8)(a0) mv sp, t0 /* Store the general purpose registers and ra */ - ld s0, 16(a0) - ld s1, 24(a0) - ld s2, 32(a0) - ld s3, 40(a0) - ld s4, 48(a0) - ld s5, 56(a0) - ld s6, 64(a0) - ld s7, 72(a0) - ld s8, 90(a0) - ld s9, 98(a0) - ld s10, 106(a0) - ld s11, 112(a0) - ld ra, 120(a0) + ld s0, (2 * 8)(a0) + ld s1, (3 * 8)(a0) + ld s2, (4 * 8)(a0) + ld s3, (5 * 8)(a0) + ld s4, (6 * 8)(a0) + ld s5, (7 * 8)(a0) + ld s6, (8 * 8)(a0) + ld s7, (9 * 8)(a0) + ld s8, (10 * 8)(a0) + ld s9, (11 * 8)(a0) + ld s10, (12 * 8)(a0) + ld s11, (13 * 8)(a0) + ld ra, (14 * 8)(a0) /* Store the fp registers */ - fld fs0, 128(a0) - fld fs1, 136(a0) - fld fs2, 144(a0) - fld fs3, 152(a0) - fld fs4, 160(a0) - fld fs5, 168(a0) - fld fs6, 176(a0) - fld fs7, 184(a0) - fld fs8, 192(a0) - fld fs9, 200(a0) - fld fs10, 208(a0) - fld fs11, 216(a0) - ld t0, 232(a0) + fld fs0, (15 * 8)(a0) + fld fs1, (16 * 8)(a0) + fld fs2, (17 * 8)(a0) + fld fs3, (18 * 8)(a0) + fld fs4, (19 * 8)(a0) + fld fs5, (20 * 8)(a0) + fld fs6, (21 * 8)(a0) + fld fs7, (22 * 8)(a0) + fld fs8, (23 * 8)(a0) + fld fs9, (24 * 8)(a0) + fld fs10, (25 * 8)(a0) + fld fs11, (26 * 8)(a0) + ld t0, (27 * 8)(a0) fscsr t0 /* Load the return value */ - add a0, zero, 1 + li a0, 1 beqz a1, 1f mv a0, a1 1: diff --git a/sys/arch/riscv64/include/setjmp.h b/sys/arch/riscv64/include/setjmp.h index 74dee613f78..fedb40aa5b6 100644 --- a/sys/arch/riscv64/include/setjmp.h +++ b/sys/arch/riscv64/include/setjmp.h @@ -1,8 +1,8 @@ -/* $OpenBSD: setjmp.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ +/* $OpenBSD: setjmp.h,v 1.2 2021/05/09 21:26:06 drahn Exp $ */ /* * machine/setjmp.h: machine dependent setjmp-related information. */ -#define _JBLEN 256 /* sp, ra, [f]s0-11, magic val, sigmask */ -#define _JB_SIGMASK 27 +#define _JBLEN 256 /* sp, ra, [f]s0-11, fscr, magic val, sigmask */ +#define _JB_SIGMASK 28