aboutsummaryrefslogtreecommitdiff
path: root/libc/inc/sys.h
blob: e776f44a58e9b8589126ebc9df4ecb7369d25f5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// MIT License, Copyright (c) 2020 Marvin Borner
// Syscall implementation

#ifndef SYS_H
#define SYS_H

enum sys {
	SYS_LOOP,
	SYS_MALLOC,
	SYS_FREE,
	SYS_READ,
	SYS_WRITE,
	SYS_EXEC,
	SYS_EXIT,
	SYS_MAP,
	SYS_UNMAP
};
enum event { EVENT_KEYBOARD, EVENT_MOUSE };

#if defined(userspace)

int sys0(enum sys num);
int sys1(enum sys num, int d1);
int sys2(enum sys num, int d1, int d2);
int sys3(enum sys num, int d1, int d2, int d3);
int sys4(enum sys num, int d1, int d2, int d3, int d4);
int sys5(enum sys num, int d1, int d2, int d3, int d4, int d5);
int sysv(enum sys num, ...);

/**
 * Wrappers
 */

#define loop() sys0(SYS_LOOP)
#define read(path) (void *)sys1(SYS_READ, (int)path)
#define write(path, buf) sys2(SYS_WRITE, (int)path, buf)
#define exec(path, ...) sysv(SYS_EXEC, (int)path, ##__VA_ARGS__)
#define exit(status)                                                                               \
	{                                                                                          \
		sys1(SYS_EXIT, (int)status);                                                       \
		while (1) {                                                                        \
		}                                                                                  \
	}
#define map(id, func) sys2(SYS_MAP, (int)id, (int)func)
#define unmap(id, func) sys2(SYS_UNMAP, (int)id, (int)func)

#endif
#endif