From 1c6f8d3cbdeac0548549670ef128641ecd47bcdd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 6 Nov 2019 13:03:45 +0100 Subject: [PATCH] Kernel: Don't build with -mregparm=3 It was really confusing to have different calling conventions in kernel and userspace. Also this has prevented us from linking with libgcc. --- Kernel/Arch/i386/Boot/boot.S | 3 +- Kernel/Arch/i386/CPU.cpp | 72 ++++++++++++++++++------------------ Kernel/Arch/i386/CPU.h | 23 +++++------- Kernel/Arch/i386/PIT.cpp | 3 +- Kernel/Makefile | 2 +- Kernel/Syscall.cpp | 3 +- 6 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Kernel/Arch/i386/Boot/boot.S b/Kernel/Arch/i386/Boot/boot.S index 33b2f26def..baab5ec2e8 100644 --- a/Kernel/Arch/i386/Boot/boot.S +++ b/Kernel/Arch/i386/Boot/boot.S @@ -54,8 +54,9 @@ start: call init - mov $exit_message, %eax + pushl $exit_message call kprintf + add $4, %esp cli diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 834a612a3e..ab98e63454 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -1,7 +1,7 @@ +#include "APIC.h" #include "Assertions.h" #include "IRQHandler.h" #include "PIC.h" -#include "APIC.h" #include "Process.h" #include "Scheduler.h" #include @@ -62,35 +62,36 @@ asm( " add $0x4, %esp\n" " iret\n"); -#define EH_ENTRY(ec) \ +#define EH_ENTRY(ec) \ extern "C" void exception_##ec##_handler(RegisterDump&); \ - extern "C" void exception_##ec##_entry(); \ - asm( \ - ".globl exception_" #ec "_entry\n" \ - "exception_" #ec "_entry: \n" \ - " pusha\n" \ - " pushw %ds\n" \ - " pushw %es\n" \ - " pushw %fs\n" \ - " pushw %gs\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " popw %ds\n" \ - " popw %es\n" \ - " popw %fs\n" \ - " popw %gs\n" \ - " mov %esp, %eax\n" \ - " call exception_" #ec "_handler\n" \ - " popw %gs\n" \ - " popw %gs\n" \ - " popw %fs\n" \ - " popw %es\n" \ - " popw %ds\n" \ - " popa\n" \ - " add $0x4, %esp\n" \ + extern "C" void exception_##ec##_entry(); \ + asm( \ + ".globl exception_" #ec "_entry\n" \ + "exception_" #ec "_entry: \n" \ + " pusha\n" \ + " pushw %ds\n" \ + " pushw %es\n" \ + " pushw %fs\n" \ + " pushw %gs\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " popw %ds\n" \ + " popw %es\n" \ + " popw %fs\n" \ + " popw %gs\n" \ + " pushl %esp\n" \ + " call exception_" #ec "_handler\n" \ + " add $4, %esp\n" \ + " popw %gs\n" \ + " popw %gs\n" \ + " popw %fs\n" \ + " popw %es\n" \ + " popw %ds\n" \ + " popa\n" \ + " add $0x4, %esp\n" \ " iret\n"); #define EH_ENTRY_NO_CODE(ec) \ @@ -114,8 +115,9 @@ asm( " popw %es\n" \ " popw %fs\n" \ " popw %gs\n" \ - " mov %esp, %eax\n" \ + " pushl %esp\n" \ " call exception_" #ec "_handler\n" \ + " add $4, %esp\n" \ " popw %gs\n" \ " popw %gs\n" \ " popw %fs\n" \ @@ -265,10 +267,10 @@ void exception_14_handler(RegisterDump& regs) auto response = MM.handle_page_fault(PageFault(regs.exception_code, VirtualAddress(fault_address))); if (response == PageFaultResponse::ShouldCrash) { - if(current->has_signal_handler(SIGSEGV)){ - current->send_urgent_signal_to_self(SIGSEGV); - return; - } + if (current->has_signal_handler(SIGSEGV)) { + current->send_urgent_signal_to_self(SIGSEGV); + return; + } kprintf("\033[31;1m%s(%u:%u) Unrecoverable page fault, %s address %p\033[0m\n", current->process().name().characters(), @@ -301,7 +303,7 @@ void exception_14_handler(RegisterDump& regs) static void _exception##i() \ { \ kprintf(msg "\n"); \ - u32 cr0, cr2, cr3, cr4; \ + u32 cr0, cr2, cr3, cr4; \ asm("movl %%cr0, %%eax" \ : "=a"(cr0)); \ asm("movl %%cr2, %%eax" \ diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index 2af084c7a3..5b14c84d98 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -251,16 +251,15 @@ inline u32 read_fs_u32(u32 offset) u32 val; asm volatile( "movl %%fs:%a[off], %k[val]" - : [val] "=r" (val) - : [off] "ir" (offset)); + : [ val ] "=r"(val) + : [ off ] "ir"(offset)); return val; } inline void write_fs_u32(u32 offset, u32 val) { asm volatile( - "movl %k[val], %%fs:%a[off]" - :: [off] "ir" (offset), [val] "ir" (val) + "movl %k[val], %%fs:%a[off]" ::[off] "ir"(offset), [ val ] "ir"(val) : "memory"); } @@ -383,7 +382,6 @@ struct [[gnu::packed]] RegisterDump u16 ss_if_crossRing; }; - struct [[gnu::aligned(16)]] FPUState { u8 buffer[512]; @@ -397,8 +395,8 @@ inline constexpr u32 page_base_of(u32 address) class CPUID { public: CPUID(u32 function) { asm volatile("cpuid" - : "=a"(m_eax), "=b"(m_ebx), "=c"(m_ecx), "=d"(m_edx) - : "a"(function), "c"(0)); } + : "=a"(m_eax), "=b"(m_ebx), "=c"(m_ecx), "=d"(m_edx) + : "a"(function), "c"(0)); } u32 eax() const { return m_eax; } u32 ebx() const { return m_ebx; } u32 ecx() const { return m_ecx; } @@ -459,21 +457,20 @@ public: MSR(const MSR&) = delete; MSR& operator=(const MSR&) = delete; - MSR(uint32_t msr): - m_msr(msr) + MSR(uint32_t msr) + : m_msr(msr) { } void get(u32& low, u32& high) { asm volatile("rdmsr" - : "=a"(low), "=d"(high) - : "c"(m_msr)); + : "=a"(low), "=d"(high) + : "c"(m_msr)); } void set(u32 low, u32 high) { - asm volatile("wrmsr" - :: "a"(low), "d"(high), "c"(m_msr)); + asm volatile("wrmsr" ::"a"(low), "d"(high), "c"(m_msr)); } }; diff --git a/Kernel/Arch/i386/PIT.cpp b/Kernel/Arch/i386/PIT.cpp index 3082662e65..1890dac617 100644 --- a/Kernel/Arch/i386/PIT.cpp +++ b/Kernel/Arch/i386/PIT.cpp @@ -27,8 +27,9 @@ asm( " popw %es\n" " popw %fs\n" " popw %gs\n" - " mov %esp, %eax\n" + " pushl %esp\n" " call timer_interrupt_handler\n" + " add $4, %esp\n" " popw %gs\n" " popw %gs\n" " popw %fs\n" diff --git a/Kernel/Makefile b/Kernel/Makefile index abdcbbaa0a..5a745843a8 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -107,7 +107,7 @@ CXX_OBJS = $(KERNEL_OBJS) $(VFS_OBJS) $(AK_OBJS) OBJS = $(CXX_OBJS) Arch/i386/Boot/boot.ao KERNEL = kernel -CXXFLAGS += -ffreestanding -mregparm=3 -mno-80387 -mno-mmx -mno-sse -mno-sse2 +CXXFLAGS += -ffreestanding -mno-80387 -mno-mmx -mno-sse -mno-sse2 CXXFLAGS += -nostdlib -nostdinc -nostdinc++ CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/ CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/i686-pc-serenity/ diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index b313c20729..aa581dc9fc 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -28,8 +28,9 @@ asm( " popw %es\n" " popw %fs\n" " popw %gs\n" - " mov %esp, %eax\n" + " pushl %esp\n" " call syscall_trap_entry\n" + " add $4, %esp\n" " popw %gs\n" " popw %gs\n" " popw %fs\n"