1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Kernel: Implement and use the syscall/sysret instruction pair on x86_64

This commit is contained in:
Owen Smith 2021-07-23 21:52:25 +01:00 committed by Andreas Kling
parent d36c84c331
commit e6df1c9988
6 changed files with 169 additions and 1 deletions

View file

@ -483,10 +483,17 @@ int sync();
inline uintptr_t invoke(Function function)
{
uintptr_t result;
# if ARCH(I386)
asm volatile("int $0x82"
: "=a"(result)
: "a"(function)
: "memory");
# else
asm volatile("syscall"
: "=a"(result)
: "a"(function)
: "rcx", "r11", "memory");
# endif
return result;
}
@ -494,10 +501,17 @@ template<typename T1>
inline uintptr_t invoke(Function function, T1 arg1)
{
uintptr_t result;
# if ARCH(I386)
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1)
: "memory");
# else
asm volatile("syscall"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1)
: "rcx", "r11", "memory");
# endif
return result;
}
@ -505,10 +519,17 @@ template<typename T1, typename T2>
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2)
{
uintptr_t result;
# if ARCH(I386)
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1), "c"((uintptr_t)arg2)
: "memory");
# else
asm volatile("syscall"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2)
: "rcx", "r11", "memory");
# endif
return result;
}
@ -516,10 +537,17 @@ template<typename T1, typename T2, typename T3>
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
{
uintptr_t result;
# if ARCH(I386)
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1), "c"((uintptr_t)arg2), "b"((uintptr_t)arg3)
: "memory");
# else
asm volatile("syscall"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3)
: "rcx", "r11", "memory");
# endif
return result;
}
@ -527,10 +555,17 @@ template<typename T1, typename T2, typename T3, typename T4>
inline uintptr_t invoke(Function function, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
uintptr_t result;
# if ARCH(I386)
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1), "c"((uintptr_t)arg2), "b"((uintptr_t)arg3), "S"((uintptr_t)arg4)
: "memory");
# else
asm volatile("syscall"
: "=a"(result)
: "a"(function), "d"((uintptr_t)arg1), "D"((uintptr_t)arg2), "b"((uintptr_t)arg3), "S"((uintptr_t)arg4)
: "memory");
# endif
return result;
}
# endif