public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Add Syscall Assembly Implementation
@ 2023-03-23 12:00 caiyinyu
  0 siblings, 0 replies; 12+ messages in thread
From: caiyinyu @ 2023-03-23 12:00 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella, xry111, caiyinyu

---
 sysdeps/unix/sysv/linux/loongarch/syscall.S | 49 +++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/syscall.S

diff --git a/sysdeps/unix/sysv/linux/loongarch/syscall.S b/sysdeps/unix/sysv/linux/loongarch/syscall.S
new file mode 100644
index 0000000000..2b2cce3443
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/syscall.S
@@ -0,0 +1,49 @@
+/* Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* syscall (int nr, ...)
+
+   LoongArch system calls take between 0 and 7 arguments. On entry here nr
+   is in a0 and any other system call arguments are in register a1..a7.
+
+   For kernel entry we need to move the system call nr to a0 then
+   load the remaining arguments to register.  */
+
+ENTRY (syscall)
+	move	t0, a7
+	move	a7, a0		/* Syscall number -> a0.  */
+	move	a0, a1		/* shift arg1 - arg6.  */
+	move	a1, a2
+	move	a2, a3
+	move	a3, a4
+	move	a4, a5
+	move	a5, a6
+	move	a6, t0		/* arg7 is saved in t0.  */
+	syscall 0		/* Do the system call.  */
+
+	LI	t0, -4096
+	bltu	t0, a0, L (error)
+
+	jirl	zero, ra, 0	/* Return to caller.  */
+
+L (error):
+	b	__syscall_error
+
+PSEUDO_END (syscall)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH] LoongArch: Add Syscall Assembly Implementation
@ 2023-03-23  8:40 caiyinyu
  2023-03-23  9:25 ` Xi Ruoyao
  0 siblings, 1 reply; 12+ messages in thread
From: caiyinyu @ 2023-03-23  8:40 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella, xry111, caiyinyu

---
 sysdeps/unix/sysv/linux/loongarch/syscall.S | 48 +++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/loongarch/syscall.S

diff --git a/sysdeps/unix/sysv/linux/loongarch/syscall.S b/sysdeps/unix/sysv/linux/loongarch/syscall.S
new file mode 100644
index 0000000000..de2d5e9fb8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/loongarch/syscall.S
@@ -0,0 +1,48 @@
+/* Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* syscall (int nr, ...)
+
+   LoongArch system calls take between 0 and 7 arguments. On entry here nr
+   is in a0 and any other system call arguments are in register a1..a7.
+
+   For kernel entry we need to move the system call nr to a7 then
+   load the remaining arguments to register.  */
+
+ ENTRY (syscall)
+        move	t0, a7
+        move	a7, a0		/* Syscall number -> a0.  */
+        move	a0, a1		/* shift arg1 - arg6.  */
+        move	a1, a2
+        move	a2, a3
+        move	a3, a4
+        move	a4, a5
+        move	a5, a6
+        move	a6, t0		/* arg7 is saved in t0.  */
+        syscall 0		/* Do the system call.  */
+
+	lu12i.w	t0, -1
+        bltu	t0, a0, L (error)
+        ret                     /* Return to caller.  */
+
+L (error):
+        b	__syscall_error
+
+PSEUDO_END (syscall)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-03-23 19:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 12:00 [PATCH] LoongArch: Add Syscall Assembly Implementation caiyinyu
  -- strict thread matches above, loose matches on Subject: below --
2023-03-23  8:40 caiyinyu
2023-03-23  9:25 ` Xi Ruoyao
2023-03-23 12:01   ` caiyinyu
2023-03-23 13:12     ` Andreas Schwab
2023-03-23 13:34       ` Xi Ruoyao
2023-03-23 13:43         ` Xi Ruoyao
2023-03-23 17:34           ` Xi Ruoyao
2023-03-23 18:26             ` Xi Ruoyao
2023-03-23 18:40               ` Adhemerval Zanella Netto
2023-03-23 19:08                 ` Xi Ruoyao
2023-03-23 13:12     ` Xi Ruoyao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).