1// SPDX-License-Identifier: GPL-3.0-or-later
2// Syscall dispatcher
3// This file was generated by scripts/gen_syscall.py
4
5#pragma once
6
7#include <mos/filesystem/fs_types.h>
8#include <mos/io/io_types.h>
9#include <mos/mos_global.h>
10#include <mos/tasks/signal_types.h>
11#include <mos/types.h>
12#include <sys/poll.h>
13#include <sys/select.h>
14#include <sys/uio.h>
15
16// syscall implementation declarations and syscall numbers
17#include <mos/syscall/decl.h>
18#include <mos/syscall/number.h>
19
20// debugging support
21#include "mos/syslog/printk.h"
22
23should_inline reg_t dispatch_syscall(const reg_t number, reg_t arg1, reg_t arg2, reg_t arg3, reg_t arg4, reg_t arg5, reg_t arg6)
24{
25 MOS_UNUSED(arg1);
26 MOS_UNUSED(arg2);
27 MOS_UNUSED(arg3);
28 MOS_UNUSED(arg4);
29 MOS_UNUSED(arg5);
30 MOS_UNUSED(arg6);
31
32 reg_t ret = -ENOSYS;
33
34 switch (number)
35 {
36 case SYSCALL_vfs_openat:
37 {
38 pr_dinfo2(syscall, "vfs_openat(dirfd=%d, file_path='%s', flags=%x)", (fd_t) arg1, (const char *) arg2, (open_flags) arg3);
39 ret = (reg_t) impl_syscall_vfs_openat(dirfd: (fd_t) arg1, file_path: (const char *) arg2, flags: (open_flags) arg3);
40 break;
41 }
42 case SYSCALL_vfs_fstatat:
43 {
44 pr_dinfo2(syscall, "vfs_fstatat(dirfd=%d, file_path='%s', stat_buf=%p, flags=%x)", (fd_t) arg1, (const char *) arg2, (void *) arg3, (fstatat_flags) arg4);
45 ret = (reg_t) impl_syscall_vfs_fstatat(dirfd: (fd_t) arg1, file_path: (const char *) arg2, stat_buf: (file_stat_t *) arg3, flags: (fstatat_flags) arg4);
46 break;
47 }
48 case SYSCALL_io_read:
49 {
50 pr_dinfo2(syscall, "io_read(fd=%d, buffer=%p, size=%zu)", (fd_t) arg1, (void *) arg2, (size_t) arg3);
51 ret = (reg_t) impl_syscall_io_read(fd: (fd_t) arg1, buffer: (void *) arg2, size: (size_t) arg3);
52 break;
53 }
54 case SYSCALL_io_write:
55 {
56 pr_dinfo2(syscall, "io_write(fd=%d, buffer=%p, size=%zu)", (fd_t) arg1, (void *) arg2, (size_t) arg3);
57 ret = (reg_t) impl_syscall_io_write(fd: (fd_t) arg1, buffer: (const void *) arg2, size: (size_t) arg3);
58 break;
59 }
60 case SYSCALL_io_close:
61 {
62 pr_dinfo2(syscall, "io_close(fd=%d)", (fd_t) arg1);
63 ret = (reg_t) impl_syscall_io_close(fd: (fd_t) arg1);
64 break;
65 }
66 case SYSCALL_exit:
67 {
68 pr_dinfo2(syscall, "exit(exit_code=%u)", (u32) arg1);
69 impl_syscall_exit(exit_code: (u32) arg1);
70 break;
71 }
72 case SYSCALL_yield_cpu:
73 {
74 pr_dinfo2(syscall, "yield_cpu()");
75 impl_syscall_yield_cpu();
76 break;
77 }
78 case SYSCALL_fork:
79 {
80 pr_dinfo2(syscall, "fork()");
81 ret = (reg_t) impl_syscall_fork();
82 break;
83 }
84 case SYSCALL_get_pid:
85 {
86 pr_dinfo2(syscall, "get_pid()");
87 ret = (reg_t) impl_syscall_get_pid();
88 break;
89 }
90 case SYSCALL_get_parent_pid:
91 {
92 pr_dinfo2(syscall, "get_parent_pid()");
93 ret = (reg_t) impl_syscall_get_parent_pid();
94 break;
95 }
96 case SYSCALL_spawn:
97 {
98 pr_dinfo2(syscall, "spawn(file_path='%s', argv=%p, envp=%p)", (const char *) arg1, (void *) arg2, (void *) arg3);
99 ret = (reg_t) impl_syscall_spawn(file_path: (const char *) arg1, argv: (const char *const *) arg2, envp: (const char *const *) arg3);
100 break;
101 }
102 case SYSCALL_create_thread:
103 {
104 pr_dinfo2(syscall, "create_thread(name='%s', entry=%p, arg=%p, stack_size=%zu, stack=%p)", (const char *) arg1, (void *) arg2, (void *) arg3, (size_t) arg4, (void *) arg5);
105 ret = (reg_t) impl_syscall_create_thread(name: (const char *) arg1, entry: (thread_entry_t) arg2, arg: (void *) arg3, stack_size: (size_t) arg4, stack: (void *) arg5);
106 break;
107 }
108 case SYSCALL_get_tid:
109 {
110 pr_dinfo2(syscall, "get_tid()");
111 ret = (reg_t) impl_syscall_get_tid();
112 break;
113 }
114 case SYSCALL_thread_exit:
115 {
116 pr_dinfo2(syscall, "thread_exit()");
117 impl_syscall_thread_exit();
118 break;
119 }
120 case SYSCALL_wait_for_thread:
121 {
122 pr_dinfo2(syscall, "wait_for_thread(tid=%d)", (tid_t) arg1);
123 ret = (reg_t) impl_syscall_wait_for_thread(tid: (tid_t) arg1);
124 break;
125 }
126 case SYSCALL_futex_wait:
127 {
128 pr_dinfo2(syscall, "futex_wait(futex=%p, val=%u)", (void *) arg1, (u32) arg2);
129 ret = (reg_t) impl_syscall_futex_wait(futex: (futex_word_t *) arg1, val: (u32) arg2);
130 break;
131 }
132 case SYSCALL_futex_wake:
133 {
134 pr_dinfo2(syscall, "futex_wake(futex=%p, count=%zu)", (void *) arg1, (size_t) arg2);
135 ret = (reg_t) impl_syscall_futex_wake(futex: (futex_word_t *) arg1, count: (size_t) arg2);
136 break;
137 }
138 case SYSCALL_ipc_create:
139 {
140 pr_dinfo2(syscall, "ipc_create(name='%s', max_pending_connections=%zu)", (const char *) arg1, (size_t) arg2);
141 ret = (reg_t) impl_syscall_ipc_create(name: (const char *) arg1, max_pending_connections: (size_t) arg2);
142 break;
143 }
144 case SYSCALL_ipc_accept:
145 {
146 pr_dinfo2(syscall, "ipc_accept(fd=%d)", (fd_t) arg1);
147 ret = (reg_t) impl_syscall_ipc_accept(fd: (fd_t) arg1);
148 break;
149 }
150 case SYSCALL_ipc_connect:
151 {
152 pr_dinfo2(syscall, "ipc_connect(name='%s', buffer_size=%zu)", (const char *) arg1, (size_t) arg2);
153 ret = (reg_t) impl_syscall_ipc_connect(name: (const char *) arg1, buffer_size: (size_t) arg2);
154 break;
155 }
156 case SYSCALL_arch_syscall:
157 {
158 pr_dinfo2(syscall, "arch_syscall(nr=%llu, arg1=%llu, arg2=%llu, arg3=%llu, arg4=%llu)", (u64) arg1, (u64) arg2, (u64) arg3, (u64) arg4, (u64) arg5);
159 ret = (reg_t) impl_syscall_arch_syscall(nr: (u64) arg1, arg1: (u64) arg2, arg2: (u64) arg3, arg3: (u64) arg4, arg4: (u64) arg5);
160 break;
161 }
162 case SYSCALL_vfs_mount:
163 {
164 pr_dinfo2(syscall, "vfs_mount(device='%s', mount_point='%s', fs_type='%s', options='%s')", (const char *) arg1, (const char *) arg2, (const char *) arg3, (const char *) arg4);
165 ret = (reg_t) impl_syscall_vfs_mount(device: (const char *) arg1, mount_point: (const char *) arg2, fs_type: (const char *) arg3, options: (const char *) arg4);
166 break;
167 }
168 case SYSCALL_vfs_readlinkat:
169 {
170 pr_dinfo2(syscall, "vfs_readlinkat(dirfd=%d, path='%s', buf=%p, buf_size=%zu)", (fd_t) arg1, (const char *) arg2, (void *) arg3, (size_t) arg4);
171 ret = (reg_t) impl_syscall_vfs_readlinkat(dirfd: (fd_t) arg1, path: (const char *) arg2, buf: (char *) arg3, buf_size: (size_t) arg4);
172 break;
173 }
174 case SYSCALL_vfs_unlinkat:
175 {
176 pr_dinfo2(syscall, "vfs_unlinkat(dirfd=%d, path='%s')", (fd_t) arg1, (const char *) arg2);
177 ret = (reg_t) impl_syscall_vfs_unlinkat(dirfd: (fd_t) arg1, path: (const char *) arg2);
178 break;
179 }
180 case SYSCALL_vfs_symlink:
181 {
182 pr_dinfo2(syscall, "vfs_symlink(link_path='%s', target='%s')", (const char *) arg1, (const char *) arg2);
183 ret = (reg_t) impl_syscall_vfs_symlink(link_path: (const char *) arg1, target: (const char *) arg2);
184 break;
185 }
186 case SYSCALL_vfs_mkdir:
187 {
188 pr_dinfo2(syscall, "vfs_mkdir(path='%s')", (const char *) arg1);
189 ret = (reg_t) impl_syscall_vfs_mkdir(path: (const char *) arg1);
190 break;
191 }
192 case SYSCALL_vfs_list_dir:
193 {
194 pr_dinfo2(syscall, "vfs_list_dir(fd=%d, buffer=%p, buffer_size=%zu)", (fd_t) arg1, (void *) arg2, (size_t) arg3);
195 ret = (reg_t) impl_syscall_vfs_list_dir(fd: (fd_t) arg1, buffer: (char *) arg2, buffer_size: (size_t) arg3);
196 break;
197 }
198 case SYSCALL_fd_manipulate:
199 {
200 pr_dinfo2(syscall, "fd_manipulate(fd=%d, cmd=%llu, arg=%p)", (fd_t) arg1, (u64) arg2, (void *) arg3);
201 ret = (reg_t) impl_syscall_fd_manipulate(fd: (fd_t) arg1, cmd: (u64) arg2, arg: (void *) arg3);
202 break;
203 }
204 case SYSCALL_mmap_anonymous:
205 {
206 pr_dinfo2(syscall, "mmap_anonymous(hint_addr=" PTR_FMT ", size=%zu, perm=%d, flags=%d)", (ptr_t) arg1, (size_t) arg2, (mem_perm_t) arg3, (mmap_flags_t) arg4);
207 ret = (reg_t) impl_syscall_mmap_anonymous(hint_addr: (ptr_t) arg1, size: (size_t) arg2, perm: (mem_perm_t) arg3, flags: (mmap_flags_t) arg4);
208 break;
209 }
210 case SYSCALL_mmap_file:
211 {
212 pr_dinfo2(syscall, "mmap_file(hint_addr=" PTR_FMT ", size=%zu, perm=%d, flags=%d, fd=%d, offset=%zd)", (ptr_t) arg1, (size_t) arg2, (mem_perm_t) arg3, (mmap_flags_t) arg4, (fd_t) arg5, (off_t) arg6);
213 ret = (reg_t) impl_syscall_mmap_file(hint_addr: (ptr_t) arg1, size: (size_t) arg2, perm: (mem_perm_t) arg3, flags: (mmap_flags_t) arg4, fd: (fd_t) arg5, offset: (off_t) arg6);
214 break;
215 }
216 case SYSCALL_wait_for_process:
217 {
218 pr_dinfo2(syscall, "wait_for_process(pid=%d, exit_code=%p, flags=%u)", (pid_t) arg1, (void *) arg2, (u32) arg3);
219 ret = (reg_t) impl_syscall_wait_for_process(pid: (pid_t) arg1, exit_code: (u32 *) arg2, flags: (u32) arg3);
220 break;
221 }
222 case SYSCALL_munmap:
223 {
224 pr_dinfo2(syscall, "munmap(addr=%p, size=%zu)", (void *) arg1, (size_t) arg2);
225 ret = (reg_t) impl_syscall_munmap(addr: (void *) arg1, size: (size_t) arg2);
226 break;
227 }
228 case SYSCALL_vfs_chdirat:
229 {
230 pr_dinfo2(syscall, "vfs_chdirat(dirfd=%d, path='%s')", (fd_t) arg1, (const char *) arg2);
231 ret = (reg_t) impl_syscall_vfs_chdirat(dirfd: (fd_t) arg1, path: (const char *) arg2);
232 break;
233 }
234 case SYSCALL_vfs_getcwd:
235 {
236 pr_dinfo2(syscall, "vfs_getcwd(buf=%p, buf_size=%zu)", (void *) arg1, (size_t) arg2);
237 ret = (reg_t) impl_syscall_vfs_getcwd(buf: (char *) arg1, buf_size: (size_t) arg2);
238 break;
239 }
240 case SYSCALL_io_seek:
241 {
242 pr_dinfo2(syscall, "io_seek(fd=%d, offset=%zd, whence=%d)", (fd_t) arg1, (off_t) arg2, (io_seek_whence_t) arg3);
243 ret = (reg_t) impl_syscall_io_seek(fd: (fd_t) arg1, offset: (off_t) arg2, whence: (io_seek_whence_t) arg3);
244 break;
245 }
246 case SYSCALL_io_tell:
247 {
248 pr_dinfo2(syscall, "io_tell(fd=%d)", (fd_t) arg1);
249 ret = (reg_t) impl_syscall_io_tell(fd: (fd_t) arg1);
250 break;
251 }
252 case SYSCALL_signal_register:
253 {
254 pr_dinfo2(syscall, "signal_register(signum=%d, action=%p)", (signal_t) arg1, (void *) arg2);
255 ret = (reg_t) impl_syscall_signal_register(signum: (signal_t) arg1, action: (const sigaction_t *) arg2);
256 break;
257 }
258 case SYSCALL_signal_process:
259 {
260 pr_dinfo2(syscall, "signal_process(pid=%d, signum=%d)", (pid_t) arg1, (signal_t) arg2);
261 ret = (reg_t) impl_syscall_signal_process(pid: (pid_t) arg1, signum: (signal_t) arg2);
262 break;
263 }
264 case SYSCALL_signal_thread:
265 {
266 pr_dinfo2(syscall, "signal_thread(tid=%d, signum=%d)", (tid_t) arg1, (signal_t) arg2);
267 ret = (reg_t) impl_syscall_signal_thread(tid: (tid_t) arg1, signum: (signal_t) arg2);
268 break;
269 }
270 case SYSCALL_poweroff:
271 {
272 pr_dinfo2(syscall, "poweroff(reboot=%d, magic=%u)", (bool) arg1, (u32) arg2);
273 impl_syscall_poweroff(reboot: (bool) arg1, magic: (u32) arg2);
274 break;
275 }
276 case SYSCALL_signal_return:
277 {
278 pr_dinfo2(syscall, "signal_return(sp=%p)", (void *) arg1);
279 impl_syscall_signal_return(sp: (void *) arg1);
280 break;
281 }
282 case SYSCALL_vm_protect:
283 {
284 pr_dinfo2(syscall, "vm_protect(addr=%p, size=%zu, perm=%d)", (void *) arg1, (size_t) arg2, (mem_perm_t) arg3);
285 ret = (reg_t) impl_syscall_vm_protect(addr: (void *) arg1, size: (size_t) arg2, perm: (mem_perm_t) arg3);
286 break;
287 }
288 case SYSCALL_io_poll:
289 {
290 pr_dinfo2(syscall, "io_poll(fds=%p, nfds=%ld, timeout=%d)", (void *) arg1, (nfds_t) arg2, (int) arg3);
291 ret = (reg_t) impl_syscall_io_poll(fds: (struct pollfd *) arg1, nfds: (nfds_t) arg2, timeout: (int) arg3);
292 break;
293 }
294 case SYSCALL_io_pselect:
295 {
296 pr_dinfo2(syscall, "io_pselect(nfds=%d, readfds=%p, writefds=%p, exceptfds=%p, timeout=%p, sigmask=%p)", (int) arg1, (void *) arg2, (void *) arg3, (void *) arg4, (void *) arg5, (void *) arg6);
297 ret = (reg_t) impl_syscall_io_pselect(nfds: (int) arg1, readfds: (fd_set *) arg2, writefds: (fd_set *) arg3, exceptfds: (fd_set *) arg4, timeout: (const struct timespec *) arg5, sigmask: (const sigset_t *) arg6);
298 break;
299 }
300 case SYSCALL_execveat:
301 {
302 pr_dinfo2(syscall, "execveat(dirfd=%d, file_path='%s', argv=%p, envp=%p, flags=%u)", (fd_t) arg1, (const char *) arg2, (void *) arg3, (void *) arg4, (u32) arg5);
303 ret = (reg_t) impl_syscall_execveat(dirfd: (fd_t) arg1, file_path: (const char *) arg2, argv: (const char *const *) arg3, envp: (const char *const *) arg4, flags: (u32) arg5);
304 break;
305 }
306 case SYSCALL_clock_msleep:
307 {
308 pr_dinfo2(syscall, "clock_msleep(ms=%llu)", (u64) arg1);
309 ret = (reg_t) impl_syscall_clock_msleep(ms: (u64) arg1);
310 break;
311 }
312 case SYSCALL_io_dup:
313 {
314 pr_dinfo2(syscall, "io_dup(fd=%d)", (fd_t) arg1);
315 ret = (reg_t) impl_syscall_io_dup(fd: (fd_t) arg1);
316 break;
317 }
318 case SYSCALL_io_dup2:
319 {
320 pr_dinfo2(syscall, "io_dup2(old_fd=%d, new_fd=%d)", (fd_t) arg1, (fd_t) arg2);
321 ret = (reg_t) impl_syscall_io_dup2(old_fd: (fd_t) arg1, new_fd: (fd_t) arg2);
322 break;
323 }
324 case SYSCALL_dmabuf_alloc:
325 {
326 pr_dinfo2(syscall, "dmabuf_alloc(n_pages=%zu, out_paddr=%p, out_vaddr=%p)", (size_t) arg1, (void *) arg2, (void *) arg3);
327 ret = (reg_t) impl_syscall_dmabuf_alloc(n_pages: (size_t) arg1, out_paddr: (ptr_t *) arg2, out_vaddr: (ptr_t *) arg3);
328 break;
329 }
330 case SYSCALL_dmabuf_free:
331 {
332 pr_dinfo2(syscall, "dmabuf_free(vaddr=" PTR_FMT ", paddr=" PTR_FMT ")", (ptr_t) arg1, (ptr_t) arg2);
333 ret = (reg_t) impl_syscall_dmabuf_free(vaddr: (ptr_t) arg1, paddr: (ptr_t) arg2);
334 break;
335 }
336 case SYSCALL_dmabuf_share:
337 {
338 pr_dinfo2(syscall, "dmabuf_share(buf=%p, bufsize=%zu, out_paddr=%p)", (void *) arg1, (size_t) arg2, (void *) arg3);
339 ret = (reg_t) impl_syscall_dmabuf_share(buf: (void *) arg1, bufsize: (size_t) arg2, out_paddr: (ptr_t *) arg3);
340 break;
341 }
342 case SYSCALL_dmabuf_unshare:
343 {
344 pr_dinfo2(syscall, "dmabuf_unshare(paddr=" PTR_FMT ", size=%zu, vaddr=%p)", (ptr_t) arg1, (size_t) arg2, (void *) arg3);
345 ret = (reg_t) impl_syscall_dmabuf_unshare(paddr: (ptr_t) arg1, size: (size_t) arg2, vaddr: (void *) arg3);
346 break;
347 }
348 case SYSCALL_pipe:
349 {
350 pr_dinfo2(syscall, "pipe(out_read_fd=%p, out_write_fd=%p, flags=%d)", (void *) arg1, (void *) arg2, (fd_flags_t) arg3);
351 ret = (reg_t) impl_syscall_pipe(out_read_fd: (fd_t *) arg1, out_write_fd: (fd_t *) arg2, flags: (fd_flags_t) arg3);
352 break;
353 }
354 case SYSCALL_io_readv:
355 {
356 pr_dinfo2(syscall, "io_readv(fd=%d, iov=%p, iov_count=%d)", (fd_t) arg1, (void *) arg2, (int) arg3);
357 ret = (reg_t) impl_syscall_io_readv(fd: (fd_t) arg1, iov: (const struct iovec *) arg2, iov_count: (int) arg3);
358 break;
359 }
360 case SYSCALL_vfs_unmount:
361 {
362 pr_dinfo2(syscall, "vfs_unmount(mount_point='%s')", (const char *) arg1);
363 ret = (reg_t) impl_syscall_vfs_unmount(mount_point: (const char *) arg1);
364 break;
365 }
366 case SYSCALL_clock_gettimeofday:
367 {
368 pr_dinfo2(syscall, "clock_gettimeofday(tv=%p)", (void *) arg1);
369 ret = (reg_t) impl_syscall_clock_gettimeofday(tv: (struct timespec *) arg1);
370 break;
371 }
372 case SYSCALL_thread_setname:
373 {
374 pr_dinfo2(syscall, "thread_setname(tid=%d, name='%s')", (tid_t) arg1, (const char *) arg2);
375 ret = (reg_t) impl_syscall_thread_setname(tid: (tid_t) arg1, name: (const char *) arg2);
376 break;
377 }
378 case SYSCALL_thread_getname:
379 {
380 pr_dinfo2(syscall, "thread_getname(tid=%d, buf=%p, buf_size=%zu)", (tid_t) arg1, (void *) arg2, (size_t) arg3);
381 ret = (reg_t) impl_syscall_thread_getname(tid: (tid_t) arg1, buf: (char *) arg2, buf_size: (size_t) arg3);
382 break;
383 }
384 case SYSCALL_vfs_fchmodat:
385 {
386 pr_dinfo2(syscall, "vfs_fchmodat(dirfd=%d, path='%s', mode=%d, flags=%d)", (fd_t) arg1, (const char *) arg2, (int) arg3, (int) arg4);
387 ret = (reg_t) impl_syscall_vfs_fchmodat(dirfd: (fd_t) arg1, path: (const char *) arg2, mode: (int) arg3, flags: (int) arg4);
388 break;
389 }
390 case SYSCALL_io_pread:
391 {
392 pr_dinfo2(syscall, "io_pread(fd=%d, buf=%p, count=%zu, offset=%zd)", (fd_t) arg1, (void *) arg2, (size_t) arg3, (off_t) arg4);
393 ret = (reg_t) impl_syscall_io_pread(fd: (fd_t) arg1, buf: (void *) arg2, count: (size_t) arg3, offset: (off_t) arg4);
394 break;
395 }
396 case SYSCALL_memfd_create:
397 {
398 pr_dinfo2(syscall, "memfd_create(name='%s', flags=%u)", (const char *) arg1, (u32) arg2);
399 ret = (reg_t) impl_syscall_memfd_create(name: (const char *) arg1, flags: (u32) arg2);
400 break;
401 }
402 case SYSCALL_signal_mask_op:
403 {
404 pr_dinfo2(syscall, "signal_mask_op(how=%d, set=%p, oldset=%p)", (int) arg1, (void *) arg2, (void *) arg3);
405 ret = (reg_t) impl_syscall_signal_mask_op(how: (int) arg1, set: (const sigset_t *) arg2, oldset: (sigset_t *) arg3);
406 break;
407 }
408 case SYSCALL_vfs_fsync:
409 {
410 pr_dinfo2(syscall, "vfs_fsync(fd=%d, data_only=%d)", (fd_t) arg1, (bool) arg2);
411 ret = (reg_t) impl_syscall_vfs_fsync(fd: (fd_t) arg1, data_only: (bool) arg2);
412 break;
413 }
414 }
415
416 pr_dcont(syscall, " = 0x%lx", ret);
417 return ret;
418}
419