~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/include/nolibc/arch-loongarch.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2 /*
  3  * LoongArch specific definitions for NOLIBC
  4  * Copyright (C) 2023 Loongson Technology Corporation Limited
  5  */
  6 
  7 #ifndef _NOLIBC_ARCH_LOONGARCH_H
  8 #define _NOLIBC_ARCH_LOONGARCH_H
  9 
 10 #include "compiler.h"
 11 #include "crt.h"
 12 
 13 /* Syscalls for LoongArch :
 14  *   - stack is 16-byte aligned
 15  *   - syscall number is passed in a7
 16  *   - arguments are in a0, a1, a2, a3, a4, a5
 17  *   - the system call is performed by calling "syscall 0"
 18  *   - syscall return comes in a0
 19  *   - the arguments are cast to long and assigned into the target
 20  *     registers which are then simply passed as registers to the asm code,
 21  *     so that we don't have to experience issues with register constraints.
 22  */
 23 
 24 #define _NOLIBC_SYSCALL_CLOBBERLIST \
 25         "memory", "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8"
 26 
 27 #define my_syscall0(num)                                                      \
 28 ({                                                                            \
 29         register long _num  __asm__ ("a7") = (num);                           \
 30         register long _arg1 __asm__ ("a0");                                   \
 31                                                                               \
 32         __asm__ volatile (                                                    \
 33                 "syscall 0\n"                                                 \
 34                 : "=r"(_arg1)                                                 \
 35                 : "r"(_num)                                                   \
 36                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
 37         );                                                                    \
 38         _arg1;                                                                \
 39 })
 40 
 41 #define my_syscall1(num, arg1)                                                \
 42 ({                                                                            \
 43         register long _num  __asm__ ("a7") = (num);                           \
 44         register long _arg1 __asm__ ("a0") = (long)(arg1);                    \
 45                                                                               \
 46         __asm__ volatile (                                                    \
 47                 "syscall 0\n"                                                 \
 48                 : "+r"(_arg1)                                                 \
 49                 : "r"(_num)                                                   \
 50                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
 51         );                                                                    \
 52         _arg1;                                                                \
 53 })
 54 
 55 #define my_syscall2(num, arg1, arg2)                                          \
 56 ({                                                                            \
 57         register long _num  __asm__ ("a7") = (num);                           \
 58         register long _arg1 __asm__ ("a0") = (long)(arg1);                    \
 59         register long _arg2 __asm__ ("a1") = (long)(arg2);                    \
 60                                                                               \
 61         __asm__ volatile (                                                    \
 62                 "syscall 0\n"                                                 \
 63                 : "+r"(_arg1)                                                 \
 64                 : "r"(_arg2),                                                 \
 65                   "r"(_num)                                                   \
 66                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
 67         );                                                                    \
 68         _arg1;                                                                \
 69 })
 70 
 71 #define my_syscall3(num, arg1, arg2, arg3)                                    \
 72 ({                                                                            \
 73         register long _num  __asm__ ("a7") = (num);                           \
 74         register long _arg1 __asm__ ("a0") = (long)(arg1);                    \
 75         register long _arg2 __asm__ ("a1") = (long)(arg2);                    \
 76         register long _arg3 __asm__ ("a2") = (long)(arg3);                    \
 77                                                                               \
 78         __asm__ volatile (                                                    \
 79                 "syscall 0\n"                                                 \
 80                 : "+r"(_arg1)                                                 \
 81                 : "r"(_arg2), "r"(_arg3),                                     \
 82                   "r"(_num)                                                   \
 83                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
 84         );                                                                    \
 85         _arg1;                                                                \
 86 })
 87 
 88 #define my_syscall4(num, arg1, arg2, arg3, arg4)                              \
 89 ({                                                                            \
 90         register long _num  __asm__ ("a7") = (num);                           \
 91         register long _arg1 __asm__ ("a0") = (long)(arg1);                    \
 92         register long _arg2 __asm__ ("a1") = (long)(arg2);                    \
 93         register long _arg3 __asm__ ("a2") = (long)(arg3);                    \
 94         register long _arg4 __asm__ ("a3") = (long)(arg4);                    \
 95                                                                               \
 96         __asm__ volatile (                                                    \
 97                 "syscall 0\n"                                                 \
 98                 : "+r"(_arg1)                                                 \
 99                 : "r"(_arg2), "r"(_arg3), "r"(_arg4),                         \
100                   "r"(_num)                                                   \
101                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
102         );                                                                    \
103         _arg1;                                                                \
104 })
105 
106 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5)                        \
107 ({                                                                            \
108         register long _num  __asm__ ("a7") = (num);                           \
109         register long _arg1 __asm__ ("a0") = (long)(arg1);                    \
110         register long _arg2 __asm__ ("a1") = (long)(arg2);                    \
111         register long _arg3 __asm__ ("a2") = (long)(arg3);                    \
112         register long _arg4 __asm__ ("a3") = (long)(arg4);                    \
113         register long _arg5 __asm__ ("a4") = (long)(arg5);                    \
114                                                                               \
115         __asm__ volatile (                                                    \
116                 "syscall 0\n"                                                 \
117                 : "+r"(_arg1)                                                 \
118                 : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5),             \
119                   "r"(_num)                                                   \
120                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
121         );                                                                    \
122         _arg1;                                                                \
123 })
124 
125 #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6)                  \
126 ({                                                                            \
127         register long _num  __asm__ ("a7") = (num);                           \
128         register long _arg1 __asm__ ("a0") = (long)(arg1);                    \
129         register long _arg2 __asm__ ("a1") = (long)(arg2);                    \
130         register long _arg3 __asm__ ("a2") = (long)(arg3);                    \
131         register long _arg4 __asm__ ("a3") = (long)(arg4);                    \
132         register long _arg5 __asm__ ("a4") = (long)(arg5);                    \
133         register long _arg6 __asm__ ("a5") = (long)(arg6);                    \
134                                                                               \
135         __asm__ volatile (                                                    \
136                 "syscall 0\n"                                                 \
137                 : "+r"(_arg1)                                                 \
138                 : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \
139                   "r"(_num)                                                   \
140                 : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
141         );                                                                    \
142         _arg1;                                                                \
143 })
144 
145 #if __loongarch_grlen == 32
146 #define LONG_BSTRINS "bstrins.w"
147 #else /* __loongarch_grlen == 64 */
148 #define LONG_BSTRINS "bstrins.d"
149 #endif
150 
151 /* startup code */
152 void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
153 {
154         __asm__ volatile (
155                 "move          $a0, $sp\n"         /* save stack pointer to $a0, as arg1 of _start_c */
156                 LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned                    */
157                 "bl            _start_c\n"         /* transfer to c runtime                          */
158         );
159         __builtin_unreachable();
160 }
161 
162 #endif /* _NOLIBC_ARCH_LOONGARCH_H */
163 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php