1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include <dirent.h>
4#include <mos/filesystem/fs_types.h>
5#include <mos/tasks/signal_types.h>
6#include <mos/types.h>
7#include <mos_stdio.h>
8#include <mos_stdlib.h>
9#include <mos_string.h>
10
11static __maybe_unused char **environ = NULL;
12
13fd_t open(const char *path, open_flags flags);
14
15fd_t openat(fd_t fd, const char *path, open_flags flags);
16
17int raise(signal_t sig);
18
19int kill(pid_t pid, signal_t sig);
20
21bool lstatat(int fd, const char *path, file_stat_t *buf);
22
23bool chdir(const char *path);
24
25bool unlink(const char *path);
26
27#ifndef __NO_START_FUNCTION
28void _start(size_t argc, char **argv, char **envp)
29{
30 extern int main(int argc, char **argv);
31
32// ensure that the stack is 16-byte aligned
33#if defined(__x86_64__)
34 __asm__ volatile("andq $-16, %rsp");
35#elif defined(__riscv)
36 __asm__ volatile("\
37 .option push\n\
38 .option norelax\n\
39 lla gp, __global_pointer$\n\
40 .option pop\n");
41 __asm__ volatile("and sp, sp, -16");
42#else
43#error "unsupported architecture"
44#endif
45
46 environ = envp;
47 int r = main(argc, argv);
48 syscall_exit(exit_code: r);
49}
50#endif
51