mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
Kernel/riscv64: Add RISC-V Syscall API
This commit is contained in:
parent
6824d2a788
commit
fd8858ace2
1 changed files with 56 additions and 6 deletions
|
@ -544,16 +544,17 @@ struct SC_faccessat_params {
|
||||||
void initialize();
|
void initialize();
|
||||||
int sync();
|
int sync();
|
||||||
|
|
||||||
# if ARCH(X86_64) || ARCH(AARCH64)
|
# if ARCH(X86_64) || ARCH(AARCH64) || ARCH(RISCV64)
|
||||||
inline uintptr_t invoke(Function function)
|
inline uintptr_t invoke(Function function)
|
||||||
{
|
{
|
||||||
uintptr_t result;
|
|
||||||
# if ARCH(X86_64)
|
# if ARCH(X86_64)
|
||||||
|
uintptr_t result;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(result)
|
: "=a"(result)
|
||||||
: "a"(function)
|
: "a"(function)
|
||||||
: "rcx", "r11", "memory");
|
: "rcx", "r11", "memory");
|
||||||
# elif ARCH(AARCH64)
|
# elif ARCH(AARCH64)
|
||||||
|
uintptr_t result;
|
||||||
register uintptr_t x0 asm("x0");
|
register uintptr_t x0 asm("x0");
|
||||||
register uintptr_t x8 asm("x8") = function;
|
register uintptr_t x8 asm("x8") = function;
|
||||||
asm volatile("svc #0"
|
asm volatile("svc #0"
|
||||||
|
@ -561,6 +562,13 @@ inline uintptr_t invoke(Function function)
|
||||||
: "r"(x8)
|
: "r"(x8)
|
||||||
: "memory");
|
: "memory");
|
||||||
result = x0;
|
result = x0;
|
||||||
|
# elif ARCH(RISCV64)
|
||||||
|
register uintptr_t a7 asm("a7") = function;
|
||||||
|
register uintptr_t result asm("a0");
|
||||||
|
asm volatile("ecall"
|
||||||
|
: "=r"(result)
|
||||||
|
: "r"(a7)
|
||||||
|
: "memory");
|
||||||
# endif
|
# endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -568,13 +576,14 @@ inline uintptr_t invoke(Function function)
|
||||||
template<typename T1>
|
template<typename T1>
|
||||||
inline uintptr_t invoke(Function function, T1 arg1)
|
inline uintptr_t invoke(Function function, T1 arg1)
|
||||||
{
|
{
|
||||||
uintptr_t result;
|
|
||||||
# if ARCH(X86_64)
|
# if ARCH(X86_64)
|
||||||
|
uintptr_t result;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(result)
|
: "=a"(result)
|
||||||
: "a"(function), "d"((uintptr_t)arg1)
|
: "a"(function), "d"((uintptr_t)arg1)
|
||||||
: "rcx", "r11", "memory");
|
: "rcx", "r11", "memory");
|
||||||
# elif ARCH(AARCH64)
|
# elif ARCH(AARCH64)
|
||||||
|
uintptr_t result;
|
||||||
register uintptr_t x0 asm("x0");
|
register uintptr_t x0 asm("x0");
|
||||||
register uintptr_t x1 asm("x1") = arg1;
|
register uintptr_t x1 asm("x1") = arg1;
|
||||||
register uintptr_t x8 asm("x8") = function;
|
register uintptr_t x8 asm("x8") = function;
|
||||||
|
@ -583,6 +592,14 @@ inline uintptr_t invoke(Function function, T1 arg1)
|
||||||
: "r"(x1), "r"(x8)
|
: "r"(x1), "r"(x8)
|
||||||
: "memory");
|
: "memory");
|
||||||
result = x0;
|
result = x0;
|
||||||
|
# elif ARCH(RISCV64)
|
||||||
|
register uintptr_t a0 asm("a0") = arg1;
|
||||||
|
register uintptr_t a7 asm("a7") = function;
|
||||||
|
register uintptr_t result asm("a0");
|
||||||
|
asm volatile("ecall"
|
||||||
|
: "=r"(result)
|
||||||
|
: "0"(a0), "r"(a7)
|
||||||
|
: "memory");
|
||||||
# endif
|
# endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -590,13 +607,14 @@ inline uintptr_t invoke(Function function, T1 arg1)
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2)
|
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2)
|
||||||
{
|
{
|
||||||
uintptr_t result;
|
|
||||||
# if ARCH(X86_64)
|
# if ARCH(X86_64)
|
||||||
|
uintptr_t result;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(result)
|
: "=a"(result)
|
||||||
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2)
|
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2)
|
||||||
: "rcx", "r11", "memory");
|
: "rcx", "r11", "memory");
|
||||||
# elif ARCH(AARCH64)
|
# elif ARCH(AARCH64)
|
||||||
|
uintptr_t result;
|
||||||
register uintptr_t x0 asm("x0");
|
register uintptr_t x0 asm("x0");
|
||||||
register uintptr_t x1 asm("x1") = arg1;
|
register uintptr_t x1 asm("x1") = arg1;
|
||||||
register uintptr_t x2 asm("x2") = arg2;
|
register uintptr_t x2 asm("x2") = arg2;
|
||||||
|
@ -606,6 +624,15 @@ inline uintptr_t invoke(Function function, T1 arg1, T2 arg2)
|
||||||
: "r"(x1), "r"(x2), "r"(x8)
|
: "r"(x1), "r"(x2), "r"(x8)
|
||||||
: "memory");
|
: "memory");
|
||||||
result = x0;
|
result = x0;
|
||||||
|
# elif ARCH(RISCV64)
|
||||||
|
register uintptr_t a0 asm("a0") = arg1;
|
||||||
|
register uintptr_t a1 asm("a1") = arg2;
|
||||||
|
register uintptr_t a7 asm("a7") = function;
|
||||||
|
register uintptr_t result asm("a0");
|
||||||
|
asm volatile("ecall"
|
||||||
|
: "=r"(result)
|
||||||
|
: "0"(a0), "r"(a1), "r"(a7)
|
||||||
|
: "memory");
|
||||||
# endif
|
# endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -613,13 +640,14 @@ inline uintptr_t invoke(Function function, T1 arg1, T2 arg2)
|
||||||
template<typename T1, typename T2, typename T3>
|
template<typename T1, typename T2, typename T3>
|
||||||
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
||||||
{
|
{
|
||||||
uintptr_t result;
|
|
||||||
# if ARCH(X86_64)
|
# if ARCH(X86_64)
|
||||||
|
uintptr_t result;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(result)
|
: "=a"(result)
|
||||||
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3)
|
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3)
|
||||||
: "rcx", "r11", "memory");
|
: "rcx", "r11", "memory");
|
||||||
# elif ARCH(AARCH64)
|
# elif ARCH(AARCH64)
|
||||||
|
uintptr_t result;
|
||||||
register uintptr_t x0 asm("x0");
|
register uintptr_t x0 asm("x0");
|
||||||
register uintptr_t x1 asm("x1") = arg1;
|
register uintptr_t x1 asm("x1") = arg1;
|
||||||
register uintptr_t x2 asm("x2") = arg2;
|
register uintptr_t x2 asm("x2") = arg2;
|
||||||
|
@ -630,6 +658,16 @@ inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
||||||
: "r"(x1), "r"(x2), "r"(x3), "r"(x8)
|
: "r"(x1), "r"(x2), "r"(x3), "r"(x8)
|
||||||
: "memory");
|
: "memory");
|
||||||
result = x0;
|
result = x0;
|
||||||
|
# elif ARCH(RISCV64)
|
||||||
|
register uintptr_t a0 asm("a0") = arg1;
|
||||||
|
register uintptr_t a1 asm("a1") = arg2;
|
||||||
|
register uintptr_t a2 asm("a2") = arg3;
|
||||||
|
register uintptr_t a7 asm("a7") = function;
|
||||||
|
register uintptr_t result asm("a0");
|
||||||
|
asm volatile("ecall"
|
||||||
|
: "=r"(result)
|
||||||
|
: "0"(a0), "r"(a1), "r"(a2), "r"(a7)
|
||||||
|
: "memory");
|
||||||
# endif
|
# endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -637,13 +675,14 @@ inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
||||||
template<typename T1, typename T2, typename T3, typename T4>
|
template<typename T1, typename T2, typename T3, typename T4>
|
||||||
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
|
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
|
||||||
{
|
{
|
||||||
uintptr_t result;
|
|
||||||
# if ARCH(X86_64)
|
# if ARCH(X86_64)
|
||||||
|
uintptr_t result;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(result)
|
: "=a"(result)
|
||||||
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3), "S"((uintptr_t)arg4)
|
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3), "S"((uintptr_t)arg4)
|
||||||
: "memory");
|
: "memory");
|
||||||
# elif ARCH(AARCH64)
|
# elif ARCH(AARCH64)
|
||||||
|
uintptr_t result;
|
||||||
register uintptr_t x0 asm("x0");
|
register uintptr_t x0 asm("x0");
|
||||||
register uintptr_t x1 asm("x1") = arg1;
|
register uintptr_t x1 asm("x1") = arg1;
|
||||||
register uintptr_t x2 asm("x2") = arg2;
|
register uintptr_t x2 asm("x2") = arg2;
|
||||||
|
@ -655,6 +694,17 @@ inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
|
||||||
: "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x8)
|
: "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x8)
|
||||||
: "memory");
|
: "memory");
|
||||||
result = x0;
|
result = x0;
|
||||||
|
# elif ARCH(RISCV64)
|
||||||
|
register uintptr_t a0 asm("a0") = arg1;
|
||||||
|
register uintptr_t a1 asm("a1") = arg2;
|
||||||
|
register uintptr_t a2 asm("a2") = arg3;
|
||||||
|
register uintptr_t a3 asm("a3") = arg4;
|
||||||
|
register uintptr_t a7 asm("a7") = function;
|
||||||
|
register uintptr_t result asm("a0");
|
||||||
|
asm volatile("ecall"
|
||||||
|
: "=r"(result)
|
||||||
|
: "0"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(a7)
|
||||||
|
: "memory");
|
||||||
# endif
|
# endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue