Jiaxun Yang
2022-Aug-13  16:45 UTC
[klibc] [PATCH] mips/mips64: Get rid of delay slot hacks
There are some MIPS assembly code trying to take advantage of
delay slots. However nowadays MIPS Release 6 removed delay slots
so they become an ordering problem.
Moreover, nowadays assmbler are smart enough to fill delay slots
properly. All those hacks can actually be archived by binutils.
Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
---
 usr/klibc/arch/mips/syscall.S    | 4 ----
 usr/klibc/arch/mips/sysstub.ph   | 4 +---
 usr/klibc/arch/mips/vfork.S      | 3 +--
 usr/klibc/arch/mips64/sysstub.ph | 4 +---
 4 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/usr/klibc/arch/mips/syscall.S b/usr/klibc/arch/mips/syscall.S
index cca0db22..a5cc73de 100644
--- a/usr/klibc/arch/mips/syscall.S
+++ b/usr/klibc/arch/mips/syscall.S
@@ -1,14 +1,10 @@
 #include <machine/asm.h>
 #include <asm/unistd.h>
 
-	.set noreorder
 
 LEAF(__syscall_common)
 	syscall
         beqz    a3, 1f
-	# sw is actually two instructions; the first one goes
-	# in the branch delay slot
-	# XXX: Break this up manually; as it is now it generates warnings.
         sw      v0, errno
         li      v0, -1
 1:      jr      ra
diff --git a/usr/klibc/arch/mips/sysstub.ph b/usr/klibc/arch/mips/sysstub.ph
index 36895291..a3475b70 100644
--- a/usr/klibc/arch/mips/sysstub.ph
+++ b/usr/klibc/arch/mips/sysstub.ph
@@ -17,11 +17,9 @@ sub make_sysstub($$$$$@) {
     print OUT "#include <machine/asm.h>\n";
     print OUT "#include <asm/unistd.h>\n";
     print OUT "\n";
-    print OUT "\t.set noreorder\n";
-    print OUT "\n";
     print OUT "LEAF(${fname})\n";
-    print OUT "\tj\t__syscall_${stype}\n";
     print OUT "\t  li\tv0, __NR_${sname}\n";
+    print OUT "\tj\t__syscall_${stype}\n";
     print OUT "\tEND(${fname})\n";
     close(OUT);
 }
diff --git a/usr/klibc/arch/mips/vfork.S b/usr/klibc/arch/mips/vfork.S
index 9aa955ae..ae36d5fd 100644
--- a/usr/klibc/arch/mips/vfork.S
+++ b/usr/klibc/arch/mips/vfork.S
@@ -5,11 +5,10 @@
 #define CLONE_VFORK	0x00004000
 #define SIGCHLD		18
 
-	.set noreorder
 
 LEAF(vfork)
 	li	a0, CLONE_VFORK | CLONE_VM | SIGCHLD
 	li	a1, 0
+	li	v0, __NR_clone
 	j	__syscall_common
-	  li	v0, __NR_clone
 	END(vfork)
diff --git a/usr/klibc/arch/mips64/sysstub.ph b/usr/klibc/arch/mips64/sysstub.ph
index e8a02009..57af657f 100644
--- a/usr/klibc/arch/mips64/sysstub.ph
+++ b/usr/klibc/arch/mips64/sysstub.ph
@@ -17,11 +17,9 @@ sub make_sysstub($$$$$@) {
     print OUT "#include <machine/asm.h>\n";
     print OUT "#include <asm/unistd.h>\n";
     print OUT "\n";
-    print OUT "\t.set noreorder\n";
-    print OUT "\n";
     print OUT "LEAF(${fname})\n";
-    print OUT "\tj\t__syscall_${stype}\n";
     print OUT "\t  li\tv0, __NR_${sname}\n";
+    print OUT "\tj\t__syscall_${stype}\n";
     print OUT "\tEND(${fname})\n";
     close(OUT);
 }
-- 
2.32.1 (Apple Git-133)
Ben Hutchings
2022-Aug-28  20:43 UTC
[klibc] [PATCH] mips/mips64: Get rid of delay slot hacks
On Sat, 2022-08-13 at 17:45 +0100, Jiaxun Yang wrote:> There are some MIPS assembly code trying to take advantage of > delay slots. However nowadays MIPS Release 6 removed delay slots > so they become an ordering problem.It didn't remove delay slots. It added "compact" branch instructions that don't have them, but after this patch the new instructions still aren't used.> Moreover, nowadays assmbler are smart enough to fill delay slots > properly. All those hacks can actually be archived by binutils.I can see that it does move instructions into the delay slot for a "j" instruction. However, in this case: [...]> --- a/usr/klibc/arch/mips/syscall.S > +++ b/usr/klibc/arch/mips/syscall.S > @@ -1,14 +1,10 @@ > #include <machine/asm.h> > #include <asm/unistd.h> > > - .set noreorder > > LEAF(__syscall_common) > syscall > beqz a3, 1f > - # sw is actually two instructions; the first one goes > - # in the branch delay slot > - # XXX: Break this up manually; as it is now it generates warnings. > sw v0, errno > li v0, -1 > 1: jr ra[...] the delay slot gets filled with a nop. I don't think that matters much, but this means the commit message is not really accurate. I think I would be happy to accept this as cleanup if you correct the commit message. Ben. -- Ben Hutchings It is a miracle that curiosity survives formal education. - Albert Einstein -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: <https://lists.zytor.com/archives/klibc/attachments/20220828/ceecd99f/attachment.sig>