Add public syscall ABI for loongarch64. Unlike the Linux kernel ABI, we use $t0 ($r12) instead of $a7 ($r11) to accommodate system calls (such as vm_map()) that may take more than seven arguments, make full use of the argument registers $a0-$a7, and keep the code simple.
>From d3b74152c3bae334fd6a90694bf023614e71dbe7 Mon Sep 17 00:00:00 2001 From: Donjuanplatinum <[email protected]> Date: Fri, 4 Dec 2026 01:01:11 +0800 Subject: [PATCH] loongarch64: Add public syscall ABI Unlike the Linux kernel ABI, we use $t0 ($r12) instead of $a7 ($r11) to accommodate system calls (such as vm_map()) that may take more than seven arguments, make full use of the argument registers $a0-$a7, and keep the code simple. See the related mailing list discussion: - https://lists.gnu.org/archive/html/bug-hurd/2026-12/msg00012.html * loongarch64/include/mach/loongarch64/asm.h: New file. * loongarch64/include/mach/loongarch64/syscall_sw.h: New file. --- loongarch64/include/mach/loongarch64/asm.h | 44 +++++++++++++++++++ .../include/mach/loongarch64/syscall_sw.h | 33 ++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 loongarch64/include/mach/loongarch64/asm.h create mode 100644 loongarch64/include/mach/loongarch64/syscall_sw.h diff --git a/loongarch64/include/mach/loongarch64/asm.h b/loongarch64/include/mach/loongarch64/asm.h new file mode 100644 index 00000000..39ced135 --- /dev/null +++ b/loongarch64/include/mach/loongarch64/asm.h @@ -0,0 +1,44 @@ +/* Macros for loongarch64 assembly code. + +Copyright (C) 2026 Free Software Foundation, Inc. + +Author: DonjuanPlatinum <[email protected]> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#ifndef _MACH_LOONGARCH64_ASM_H_ +#define _MACH_LOONGARCH64_ASM_H_ + +#define TEXT_ALIGN 2 + +/* For simplicity and the number of syscall arguments, we use $t0 + here. */ +#define SYSCALL_NUMBER_REG $t0 + +/* Macros for assembler code. */ +#define INT_ADDI addi.w + +#define EXT(x) x +#define LEXT(x) x ## : +#define SEXT(x) #x + + + +#define ENTRY(name) \ + .globl name; .type name, @function; .p2align TEXT_ALIGN; LEXT(name) + +#define END(name) \ + .size name, .-name +#endif /* _MACH_LOONGARCH64_ASM_H_ */ diff --git a/loongarch64/include/mach/loongarch64/syscall_sw.h b/loongarch64/include/mach/loongarch64/syscall_sw.h new file mode 100644 index 00000000..0b181c36 --- /dev/null +++ b/loongarch64/include/mach/loongarch64/syscall_sw.h @@ -0,0 +1,33 @@ +/* System call entry macros for loongarch64. + +Copyright (C) 2026 Free Software Foundation, Inc. + +Author: DonjuanPlatinum <[email protected]> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#ifndef _MACH_LOONGARCH64_SYSCALL_SW_H_ +#define _MACH_LOONGARCH64_SYSCALL_SW_H_ + +#include <mach/machine/asm.h> + +#define kernel_trap(trap_name, trap_number, number_args) \ + ENTRY(trap_name) \ + INT_ADDI SYSCALL_NUMBER_REG, $zero, (trap_number); \ + syscall 0; \ + jirl $zero, $ra, 0; \ + END(trap_name) + +#endif /* _MACH_LOONGARCH64_SYSCALL_SW_H_ */ -- 2.56.0
-- Donjuanplatinum, Yifei Yao <[email protected]> GPG: 1C9E EEE5 4C8E D5A8 3039 1C87 A9F6 8632 D259 40E6 满堂兮美人 忽独与余兮目成
