aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/sysdeps/linux/riscv64/arch-syscall.cpp
blob: 18ac6b09b2dd37b79f82afc141959fed846cd0ac (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <sys/syscall.h>
#include <bits/syscall.h>

using sc_word_t = __sc_word_t;

sc_word_t __do_syscall0(long sc) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) : "r"(sc_reg) : "memory", "a1");
	return ret;
}

sc_word_t __do_syscall1(long sc,
		sc_word_t arg1) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t arg1_reg asm("a0") = arg1;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) :
			"r"(sc_reg),
			"r"(arg1_reg)
			: "memory", "a1");
	return ret;
}

sc_word_t __do_syscall2(long sc,
		sc_word_t arg1, sc_word_t arg2) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t arg1_reg asm("a0") = arg1;
	register sc_word_t arg2_reg asm("a1") = arg2;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) :
			"r"(sc_reg),
			"r"(arg1_reg),
			"r"(arg2_reg)
			: "memory");
	return ret;
}

sc_word_t __do_syscall3(long sc,
		sc_word_t arg1, sc_word_t arg2, sc_word_t arg3) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t arg1_reg asm("a0") = arg1;
	register sc_word_t arg2_reg asm("a1") = arg2;
	register sc_word_t arg3_reg asm("a2") = arg3;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) :
			"r"(sc_reg),
			"r"(arg1_reg),
			"r"(arg2_reg),
			"r"(arg3_reg)
			: "memory");
	return ret;
}

sc_word_t __do_syscall4(long sc,
		sc_word_t arg1, sc_word_t arg2, sc_word_t arg3,
		sc_word_t arg4) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t arg1_reg asm("a0") = arg1;
	register sc_word_t arg2_reg asm("a1") = arg2;
	register sc_word_t arg3_reg asm("a2") = arg3;
	register sc_word_t arg4_reg asm("a3") = arg4;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) :
			"r"(sc_reg),
			"r"(arg1_reg),
			"r"(arg2_reg),
			"r"(arg3_reg),
			"r"(arg4_reg)
			: "memory");
	return ret;
}

sc_word_t __do_syscall5(long sc,
		sc_word_t arg1, sc_word_t arg2, sc_word_t arg3,
		sc_word_t arg4, sc_word_t arg5) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t arg1_reg asm("a0") = arg1;
	register sc_word_t arg2_reg asm("a1") = arg2;
	register sc_word_t arg3_reg asm("a2") = arg3;
	register sc_word_t arg4_reg asm("a3") = arg4;
	register sc_word_t arg5_reg asm("a4") = arg5;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) :
			"r"(sc_reg),
			"r"(arg1_reg),
			"r"(arg2_reg),
			"r"(arg3_reg),
			"r"(arg4_reg),
			"r"(arg5_reg)
			: "memory");
	return ret;
}

sc_word_t __do_syscall6(long sc,
		sc_word_t arg1, sc_word_t arg2, sc_word_t arg3,
		sc_word_t arg4, sc_word_t arg5, sc_word_t arg6) {
	register int sc_reg asm("a7") = sc;
	register sc_word_t arg1_reg asm("a0") = arg1;
	register sc_word_t arg2_reg asm("a1") = arg2;
	register sc_word_t arg3_reg asm("a2") = arg3;
	register sc_word_t arg4_reg asm("a3") = arg4;
	register sc_word_t arg5_reg asm("a4") = arg5;
	register sc_word_t arg6_reg asm("a5") = arg6;
	register sc_word_t ret asm("a0");
	asm volatile ("ecall" : "=r"(ret) :
			"r"(sc_reg),
			"r"(arg1_reg),
			"r"(arg2_reg),
			"r"(arg3_reg),
			"r"(arg4_reg),
			"r"(arg5_reg),
			"r"(arg6_reg)
			: "memory"
			);
	return ret;
}