Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / include / nolibc / arch-s390.h
blobf9ab83a219b8a2d5e53b0b303d8bf0bf78280d5f
1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2 /*
3 * s390 specific definitions for NOLIBC
4 */
6 #ifndef _NOLIBC_ARCH_S390_H
7 #define _NOLIBC_ARCH_S390_H
8 #include <asm/signal.h>
9 #include <asm/unistd.h>
11 #include "compiler.h"
12 #include "crt.h"
13 #include "std.h"
15 /* Syscalls for s390:
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) \
28 ({ \
29 register long _num __asm__ ("1") = (num); \
30 register long _rc __asm__ ("2"); \
32 __asm__ volatile ( \
33 "svc 0\n" \
34 : "=d"(_rc) \
35 : "d"(_num) \
36 : "memory", "cc" \
37 ); \
38 _rc; \
41 #define my_syscall1(num, arg1) \
42 ({ \
43 register long _num __asm__ ("1") = (num); \
44 register long _arg1 __asm__ ("2") = (long)(arg1); \
46 __asm__ volatile ( \
47 "svc 0\n" \
48 : "+d"(_arg1) \
49 : "d"(_num) \
50 : "memory", "cc" \
51 ); \
52 _arg1; \
55 #define my_syscall2(num, arg1, arg2) \
56 ({ \
57 register long _num __asm__ ("1") = (num); \
58 register long _arg1 __asm__ ("2") = (long)(arg1); \
59 register long _arg2 __asm__ ("3") = (long)(arg2); \
61 __asm__ volatile ( \
62 "svc 0\n" \
63 : "+d"(_arg1) \
64 : "d"(_arg2), "d"(_num) \
65 : "memory", "cc" \
66 ); \
67 _arg1; \
70 #define my_syscall3(num, arg1, arg2, arg3) \
71 ({ \
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); \
77 __asm__ volatile ( \
78 "svc 0\n" \
79 : "+d"(_arg1) \
80 : "d"(_arg2), "d"(_arg3), "d"(_num) \
81 : "memory", "cc" \
82 ); \
83 _arg1; \
86 #define my_syscall4(num, arg1, arg2, arg3, arg4) \
87 ({ \
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); \
94 __asm__ volatile ( \
95 "svc 0\n" \
96 : "+d"(_arg1) \
97 : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_num) \
98 : "memory", "cc" \
99 ); \
100 _arg1; \
103 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
104 ({ \
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); \
112 __asm__ volatile ( \
113 "svc 0\n" \
114 : "+d"(_arg1) \
115 : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \
116 "d"(_num) \
117 : "memory", "cc" \
118 ); \
119 _arg1; \
122 #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
123 ({ \
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); \
132 __asm__ volatile ( \
133 "svc 0\n" \
134 : "+d"(_arg1) \
135 : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \
136 "d"(_arg6), "d"(_num) \
137 : "memory", "cc" \
138 ); \
139 _arg1; \
142 /* startup code */
143 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
145 __asm__ volatile (
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 {
155 unsigned long addr;
156 unsigned long len;
157 unsigned long prot;
158 unsigned long flags;
159 unsigned long fd;
160 unsigned long offset;
163 static __attribute__((unused))
164 void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
165 off_t offset)
167 struct s390_mmap_arg_struct args = {
168 .addr = (unsigned long)addr,
169 .len = (unsigned long)length,
170 .prot = prot,
171 .flags = flags,
172 .fd = fd,
173 .offset = (unsigned long)offset
176 return (void *)my_syscall1(__NR_mmap, &args);
178 #define sys_mmap sys_mmap
180 static __attribute__((unused))
181 pid_t sys_fork(void)
183 return my_syscall5(__NR_clone, 0, SIGCHLD, 0, 0, 0);
185 #define sys_fork sys_fork
187 #endif /* _NOLIBC_ARCH_S390_H */