1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
3 * s390 specific definitions for NOLIBC
6 #ifndef _NOLIBC_ARCH_S390_H
7 #define _NOLIBC_ARCH_S390_H
8 #include <asm/signal.h>
9 #include <asm/unistd.h>
16 * - registers are 64-bit
17 * - syscall number is passed in r1
18 * - arguments are in r2-r7
19 * - the system call is performed by calling the svc instruction
20 * - syscall return value is in r2
21 * - r1 and r2 are clobbered, others are preserved.
23 * Link s390 ABI: https://github.com/IBM/s390x-abi
27 #define my_syscall0(num) \
29 register long _num __asm__ ("1") = (num); \
30 register long _rc __asm__ ("2"); \
41 #define my_syscall1(num, arg1) \
43 register long _num __asm__ ("1") = (num); \
44 register long _arg1 __asm__ ("2") = (long)(arg1); \
55 #define my_syscall2(num, arg1, arg2) \
57 register long _num __asm__ ("1") = (num); \
58 register long _arg1 __asm__ ("2") = (long)(arg1); \
59 register long _arg2 __asm__ ("3") = (long)(arg2); \
64 : "d"(_arg2), "d"(_num) \
70 #define my_syscall3(num, arg1, arg2, arg3) \
72 register long _num __asm__ ("1") = (num); \
73 register long _arg1 __asm__ ("2") = (long)(arg1); \
74 register long _arg2 __asm__ ("3") = (long)(arg2); \
75 register long _arg3 __asm__ ("4") = (long)(arg3); \
80 : "d"(_arg2), "d"(_arg3), "d"(_num) \
86 #define my_syscall4(num, arg1, arg2, arg3, arg4) \
88 register long _num __asm__ ("1") = (num); \
89 register long _arg1 __asm__ ("2") = (long)(arg1); \
90 register long _arg2 __asm__ ("3") = (long)(arg2); \
91 register long _arg3 __asm__ ("4") = (long)(arg3); \
92 register long _arg4 __asm__ ("5") = (long)(arg4); \
97 : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_num) \
103 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
105 register long _num __asm__ ("1") = (num); \
106 register long _arg1 __asm__ ("2") = (long)(arg1); \
107 register long _arg2 __asm__ ("3") = (long)(arg2); \
108 register long _arg3 __asm__ ("4") = (long)(arg3); \
109 register long _arg4 __asm__ ("5") = (long)(arg4); \
110 register long _arg5 __asm__ ("6") = (long)(arg5); \
115 : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \
122 #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
124 register long _num __asm__ ("1") = (num); \
125 register long _arg1 __asm__ ("2") = (long)(arg1); \
126 register long _arg2 __asm__ ("3") = (long)(arg2); \
127 register long _arg3 __asm__ ("4") = (long)(arg3); \
128 register long _arg4 __asm__ ("5") = (long)(arg4); \
129 register long _arg5 __asm__ ("6") = (long)(arg5); \
130 register long _arg6 __asm__ ("7") = (long)(arg6); \
135 : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \
136 "d"(_arg6), "d"(_num) \
143 void __attribute__((weak
, noreturn
)) __nolibc_entrypoint __no_stack_protector
_start(void)
146 "lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
147 "aghi %r15, -160\n" /* allocate new stackframe */
148 "xc 0(8,%r15), 0(%r15)\n" /* clear backchain */
149 "brasl %r14, _start_c\n" /* transfer to c runtime */
151 __nolibc_entrypoint_epilogue();
154 struct s390_mmap_arg_struct
{
160 unsigned long offset
;
163 static __attribute__((unused
))
164 void *sys_mmap(void *addr
, size_t length
, int prot
, int flags
, int fd
,
167 struct s390_mmap_arg_struct args
= {
168 .addr
= (unsigned long)addr
,
169 .len
= (unsigned long)length
,
173 .offset
= (unsigned long)offset
176 return (void *)my_syscall1(__NR_mmap
, &args
);
178 #define sys_mmap sys_mmap
180 static __attribute__((unused
))
183 return my_syscall5(__NR_clone
, 0, SIGCHLD
, 0, 0, 0);
185 #define sys_fork sys_fork
187 #endif /* _NOLIBC_ARCH_S390_H */