diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index ab9047da87da1a..6d9bead1ea5487 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -46,6 +46,7 @@ extern "C" void asm_irq_entry(); asm( ".globl asm_irq_entry\n" "asm_irq_entry: \n" + " pushl $0x0\n" " pusha\n" " pushw %ds\n" " pushw %es\n" @@ -57,10 +58,11 @@ asm( " popw %es\n" " popw %ds\n" " popa\n" + " add $0x4, %esp\n" " iret\n"); #define EH_ENTRY(ec) \ - extern "C" void exception_##ec##_handler(RegisterDumpWithExceptionCode&); \ + extern "C" void exception_##ec##_handler(RegisterDump&); \ extern "C" void exception_##ec##_entry(); \ asm( \ ".globl exception_" #ec "_entry\n" \ @@ -96,6 +98,7 @@ asm( asm( \ ".globl exception_" #ec "_entry\n" \ "exception_" #ec "_entry: \n" \ + " pushl $0x0\n" \ " pusha\n" \ " pushw %ds\n" \ " pushw %es\n" \ @@ -118,10 +121,10 @@ asm( " popw %es\n" \ " popw %ds\n" \ " popa\n" \ + " add $0x4, %esp\n" \ " iret\n"); -template -static void dump(const DumpType& regs) +static void dump(const RegisterDump& regs) { u16 ss; u32 esp; @@ -133,9 +136,7 @@ static void dump(const DumpType& regs) esp = regs.esp_if_crossRing; } - if constexpr (IsSame::value) { - kprintf("exception code: %04x\n", regs.exception_code); - } + kprintf("exception code: %04x\n", regs.exception_code); kprintf(" pc=%04x:%08x ds=%04x es=%04x fs=%04x gs=%04x\n", regs.cs, regs.eip, regs.ds, regs.es, regs.fs, regs.gs); kprintf(" stk=%04x:%08x\n", ss, esp); if (current) @@ -157,8 +158,7 @@ static void dump(const DumpType& regs) } } -template -static void handle_crash(RegisterDumpType& regs, const char* description, int signal) +static void handle_crash(RegisterDump& regs, const char* description, int signal) { if (!current) { kprintf("%s with !current\n", description); @@ -195,7 +195,7 @@ void exception_0_handler(RegisterDump& regs) } EH_ENTRY(13); -void exception_13_handler(RegisterDumpWithExceptionCode& regs) +void exception_13_handler(RegisterDump& regs) { handle_crash(regs, "General protection fault", SIGSEGV); } @@ -232,7 +232,7 @@ void exception_7_handler(RegisterDump& regs) // 14: Page Fault EH_ENTRY(14); -void exception_14_handler(RegisterDumpWithExceptionCode& regs) +void exception_14_handler(RegisterDump& regs) { ASSERT(current); diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index 4d34ff64d10228..d0fa59a824c43e 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -333,29 +333,6 @@ class PageFault { }; struct [[gnu::packed]] RegisterDump -{ - u16 ss; - u16 gs; - u16 fs; - u16 es; - u16 ds; - u32 edi; - u32 esi; - u32 ebp; - u32 esp; - u32 ebx; - u32 edx; - u32 ecx; - u32 eax; - u32 eip; - u16 cs; - u16 __csPadding; - u32 eflags; - u32 esp_if_crossRing; - u16 ss_if_crossRing; -}; - -struct [[gnu::packed]] RegisterDumpWithExceptionCode { u16 ss; u16 gs; @@ -380,6 +357,7 @@ struct [[gnu::packed]] RegisterDumpWithExceptionCode u16 ss_if_crossRing; }; + struct [[gnu::aligned(16)]] FPUState { u8 buffer[512]; diff --git a/Kernel/Arch/i386/PIT.cpp b/Kernel/Arch/i386/PIT.cpp index d1a523da08a242..3082662e651911 100644 --- a/Kernel/Arch/i386/PIT.cpp +++ b/Kernel/Arch/i386/PIT.cpp @@ -12,6 +12,7 @@ extern "C" void timer_interrupt_handler(RegisterDump&); asm( ".globl timer_interrupt_entry \n" "timer_interrupt_entry: \n" + " pushl $0x0\n" " pusha\n" " pushw %ds\n" " pushw %es\n" @@ -34,6 +35,7 @@ asm( " popw %es\n" " popw %ds\n" " popa\n" + " add $0x4, %esp\n" " iret\n"); static u32 s_ticks_this_second; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 4441433750ebdc..221fe8f6351589 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -864,9 +864,12 @@ int Process::sys$sigreturn(RegisterDump& registers) current->m_signal_mask = *stack_ptr; stack_ptr++; - //pop edi, esi, ebp, esp, ebx, edx, ecx, eax and eip - memcpy(®isters.edi, stack_ptr, 9 * sizeof(u32)); - stack_ptr += 9; + //pop edi, esi, ebp, esp, ebx, edx, ecx and eax + memcpy(®isters.edi, stack_ptr, 8 * sizeof(u32)); + stack_ptr += 8; + + registers.eip = *stack_ptr; + stack_ptr++; registers.eflags = *stack_ptr; stack_ptr++; diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index b08b16532ce16e..795a2ef183d956 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -561,8 +561,8 @@ void Scheduler::timer_tick(RegisterDump& regs) outgoing_tss.eflags = regs.eflags; // Compute process stack pointer. - // Add 12 for CS, EIP, EFLAGS (interrupt mechanic) - outgoing_tss.esp = regs.esp + 12; + // Add 16 for CS, EIP, EFLAGS, exception code (interrupt mechanic) + outgoing_tss.esp = regs.esp + 16; outgoing_tss.ss = regs.ss; if ((outgoing_tss.cs & 3) != 0) { diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index d6a47b167c9b92..ba2880b48ac455 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -13,6 +13,7 @@ extern volatile RegisterDump* syscallRegDump; asm( ".globl syscall_trap_handler \n" "syscall_trap_handler:\n" + " pushl $0x0\n" " pusha\n" " pushw %ds\n" " pushw %es\n" @@ -35,6 +36,7 @@ asm( " popw %es\n" " popw %ds\n" " popa\n" + " add $0x4, %esp\n" " iret\n"); namespace Syscall {