mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 19:07:01 +02:00
fiber: save contexts without compiler frames
This commit is contained in:
+32
-39
@@ -2458,47 +2458,40 @@ static void FiberSetContextValid(FiberObject* fiber, bool valid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__x86_64__) || defined(_M_X64)
|
#if defined(__x86_64__) || defined(_M_X64)
|
||||||
__attribute__((noinline, returns_twice)) static int FiberSaveContext(FiberCpuContext* ctx) {
|
[[gnu::naked,
|
||||||
int ret = 0;
|
gnu::returns_twice]] static KYTY_SYSV_ABI int FiberSaveContext(FiberCpuContext* /*ctx*/) {
|
||||||
asm volatile("movq %[ctx], %%r10\n\t"
|
asm volatile("movq %rdi, %r10\n\t"
|
||||||
"movq %%rbx, 0(%%r10)\n\t"
|
"movq %rbx, 0(%r10)\n\t"
|
||||||
"movq %%rbp, 8(%%r10)\n\t"
|
"movq %rbp, 8(%r10)\n\t"
|
||||||
"movq %%rdi, 16(%%r10)\n\t"
|
"movq %rdi, 16(%r10)\n\t"
|
||||||
"movq %%rsi, 24(%%r10)\n\t"
|
"movq %rsi, 24(%r10)\n\t"
|
||||||
"movq %%r12, 32(%%r10)\n\t"
|
"movq %r12, 32(%r10)\n\t"
|
||||||
"movq %%r13, 40(%%r10)\n\t"
|
"movq %r13, 40(%r10)\n\t"
|
||||||
"movq %%r14, 48(%%r10)\n\t"
|
"movq %r14, 48(%r10)\n\t"
|
||||||
"movq %%r15, 56(%%r10)\n\t"
|
"movq %r15, 56(%r10)\n\t"
|
||||||
"leaq 8(%%rsp), %%r11\n\t"
|
"leaq 8(%rsp), %r11\n\t"
|
||||||
"movq %%r11, 64(%%r10)\n\t"
|
"movq %r11, 64(%r10)\n\t"
|
||||||
"movq (%%rsp), %%r11\n\t"
|
"movq (%rsp), %r11\n\t"
|
||||||
"movq %%r11, 72(%%r10)\n\t"
|
"movq %r11, 72(%r10)\n\t"
|
||||||
"xorl %%eax, %%eax\n\t"
|
"xorl %eax, %eax\n\t"
|
||||||
: "=a"(ret)
|
"retq\n");
|
||||||
: [ctx] "r"(ctx)
|
|
||||||
: "memory", "r10", "r11");
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noreturn, noinline)) static void FiberRestoreContext(FiberCpuContext* ctx,
|
[[gnu::naked, gnu::noreturn]] static KYTY_SYSV_ABI void
|
||||||
uint64_t ret) {
|
FiberRestoreContext(FiberCpuContext* /*ctx*/, uint64_t /*ret*/) {
|
||||||
asm volatile("movq %[ctx], %%r10\n\t"
|
asm volatile("movq %rdi, %r10\n\t"
|
||||||
"movq 72(%%r10), %%r11\n\t"
|
"movq %rsi, %rax\n\t"
|
||||||
"movq 0(%%r10), %%rbx\n\t"
|
"movq 72(%r10), %r11\n\t"
|
||||||
"movq 8(%%r10), %%rbp\n\t"
|
"movq 0(%r10), %rbx\n\t"
|
||||||
"movq 16(%%r10), %%rdi\n\t"
|
"movq 8(%r10), %rbp\n\t"
|
||||||
"movq 24(%%r10), %%rsi\n\t"
|
"movq 16(%r10), %rdi\n\t"
|
||||||
"movq 32(%%r10), %%r12\n\t"
|
"movq 24(%r10), %rsi\n\t"
|
||||||
"movq 40(%%r10), %%r13\n\t"
|
"movq 32(%r10), %r12\n\t"
|
||||||
"movq 48(%%r10), %%r14\n\t"
|
"movq 40(%r10), %r13\n\t"
|
||||||
"movq 56(%%r10), %%r15\n\t"
|
"movq 48(%r10), %r14\n\t"
|
||||||
"movq 64(%%r10), %%rsp\n\t"
|
"movq 56(%r10), %r15\n\t"
|
||||||
"movq %[ret], %%rax\n\t"
|
"movq 64(%r10), %rsp\n\t"
|
||||||
"jmp *%%r11\n\t"
|
"jmp *%r11\n");
|
||||||
:
|
|
||||||
: [ctx] "r"(ctx), [ret] "r"(ret)
|
|
||||||
: "memory", "rax", "r10", "r11");
|
|
||||||
__builtin_unreachable();
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int FiberSaveContext(FiberCpuContext* ctx) {
|
static int FiberSaveContext(FiberCpuContext* ctx) {
|
||||||
|
|||||||
Reference in New Issue
Block a user