From 1afe255fed75a83783482756e51e951a8557a82f Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 20 Nov 2022 16:13:49 +0200 Subject: [PATCH] Hope now scheduler won't crash at IPC Service --- .../amd64/SystemCallsAssemblyStub.asm | 48 ++++++++++--------- Tasking/InterProcessCommunication.cpp | 5 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Architecture/amd64/SystemCallsAssemblyStub.asm b/Architecture/amd64/SystemCallsAssemblyStub.asm index 25e281f1..1944ef13 100644 --- a/Architecture/amd64/SystemCallsAssemblyStub.asm +++ b/Architecture/amd64/SystemCallsAssemblyStub.asm @@ -1,19 +1,6 @@ [BITS 64] -ALIGN 4096 -extern SystemCallsHandler -global SystemCallHandlerStub -SystemCallHandlerStub: - swapgs - mov [gs:0x8], rsp ; CPUData->TempStack - mov rsp, [gs:0x0] ; CPUData->SystemCallStack - push qword 0x1b ; user data segment - push qword [gs:0x8] ; saved stack - push r11 ; saved rflags - push qword 0x23 ; user code segment - push rcx ; Current RIP - - cld +%macro PushAllSC 0 push rax push rbx push rcx @@ -29,11 +16,9 @@ SystemCallHandlerStub: push r13 push r14 push r15 +%endmacro - mov rdi, rsp - mov rbp, 0 - call SystemCallsHandler - +%macro PopAllSC 0 pop r15 pop r14 pop r13 @@ -48,8 +33,27 @@ SystemCallHandlerStub: pop rdx pop rcx pop rbx +%endmacro - mov rsp, [gs:0x8] - swapgs - sti - o64 sysret +ALIGN 4096 +extern SystemCallsHandler +global SystemCallHandlerStub +SystemCallHandlerStub: + swapgs ; Swap gs and kernelgs + mov [gs:0x8], rsp ; CPUData->TempStack + mov rsp, [gs:0x0] ; CPUData->SystemCallStack + push qword 0x1b ; User data segment + push qword [gs:0x8] ; Saved stack + push r11 ; Saved rflags + push qword 0x23 ; User code segment + push rcx ; Current instruction pointer + cld ; Clear direction flag + PushAllSC ; Push all registers + mov rdi, rsp ; Pass pointer to registers + mov rbp, 0 ; Pass 0 as return address + call SystemCallsHandler ; Call system call handler + PopAllSC ; Pop all registers except rax + mov rsp, [gs:0x8] ; Restore stack + swapgs ; Swap back gs and kernelgs + sti ; Enable interrupts + o64 sysret ; Return to user mode diff --git a/Tasking/InterProcessCommunication.cpp b/Tasking/InterProcessCommunication.cpp index 4a94acd2..46e69880 100644 --- a/Tasking/InterProcessCommunication.cpp +++ b/Tasking/InterProcessCommunication.cpp @@ -131,7 +131,10 @@ namespace InterProcessCommunication trace("IPC Service Started."); TaskManager->GetCurrentThread()->SetPriority(1); // TODO: do something useful here, like, IPC event viewer or smth... - CPU::Pause(true); + while (1) + { + // The scheduler doesn't like CPU::Pause for some reason. :/ + } } IPC::IPC()