forked from Bananymous/banan-os
Kernel/LibC: add flag to enable/disable sse support
SSE support is very experimental and causes GP. I decided to make SSE not default until I get to fixing it :)
This commit is contained in:
parent
f662aa6da2
commit
fe2dca16f0
|
@ -20,6 +20,9 @@ if(NOT EXISTS ${CMAKE_CXX_COMPILER})
|
||||||
set(CMAKE_CXX_COMPILER g++)
|
set(CMAKE_CXX_COMPILER g++)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_compile_options(-mno-sse -mno-sse2)
|
||||||
|
add_compile_definitions(__enable_sse=0)
|
||||||
|
|
||||||
project(banan-os CXX)
|
project(banan-os CXX)
|
||||||
|
|
||||||
set(BANAN_BASE_SYSROOT ${CMAKE_SOURCE_DIR}/base-sysroot.tar.gz)
|
set(BANAN_BASE_SYSROOT ${CMAKE_SOURCE_DIR}/base-sysroot.tar.gz)
|
||||||
|
|
|
@ -139,10 +139,11 @@ namespace IDT
|
||||||
|
|
||||||
extern "C" void cpp_isr_handler(uint64_t isr, uint64_t error, Kernel::InterruptStack& interrupt_stack, const Registers* regs)
|
extern "C" void cpp_isr_handler(uint64_t isr, uint64_t error, Kernel::InterruptStack& interrupt_stack, const Registers* regs)
|
||||||
{
|
{
|
||||||
|
#if __enable_sse
|
||||||
bool from_userspace = (interrupt_stack.cs & 0b11) == 0b11;
|
bool from_userspace = (interrupt_stack.cs & 0b11) == 0b11;
|
||||||
|
|
||||||
if (from_userspace)
|
if (from_userspace)
|
||||||
Kernel::Thread::current().save_sse();
|
Kernel::Thread::current().save_sse();
|
||||||
|
#endif
|
||||||
|
|
||||||
pid_t tid = Kernel::Scheduler::current_tid();
|
pid_t tid = Kernel::Scheduler::current_tid();
|
||||||
pid_t pid = tid ? Kernel::Process::current().pid() : 0;
|
pid_t pid = tid ? Kernel::Process::current().pid() : 0;
|
||||||
|
@ -205,19 +206,22 @@ namespace IDT
|
||||||
|
|
||||||
ASSERT(Kernel::Thread::current().state() != Kernel::Thread::State::Terminated);
|
ASSERT(Kernel::Thread::current().state() != Kernel::Thread::State::Terminated);
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
if (from_userspace)
|
if (from_userspace)
|
||||||
{
|
{
|
||||||
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
||||||
Kernel::Thread::current().load_sse();
|
Kernel::Thread::current().load_sse();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void cpp_irq_handler(uint64_t irq, Kernel::InterruptStack& interrupt_stack)
|
extern "C" void cpp_irq_handler(uint64_t irq, Kernel::InterruptStack& interrupt_stack)
|
||||||
{
|
{
|
||||||
|
#if __enable_sse
|
||||||
bool from_userspace = (interrupt_stack.cs & 0b11) == 0b11;
|
bool from_userspace = (interrupt_stack.cs & 0b11) == 0b11;
|
||||||
|
|
||||||
if (from_userspace)
|
if (from_userspace)
|
||||||
Kernel::Thread::current().save_sse();
|
Kernel::Thread::current().save_sse();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (Kernel::Scheduler::current_tid())
|
if (Kernel::Scheduler::current_tid())
|
||||||
{
|
{
|
||||||
|
@ -240,11 +244,13 @@ namespace IDT
|
||||||
|
|
||||||
ASSERT(Kernel::Thread::current().state() != Kernel::Thread::State::Terminated);
|
ASSERT(Kernel::Thread::current().state() != Kernel::Thread::State::Terminated);
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
if (from_userspace)
|
if (from_userspace)
|
||||||
{
|
{
|
||||||
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
||||||
Kernel::Thread::current().load_sse();
|
Kernel::Thread::current().load_sse();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_idt()
|
static void flush_idt()
|
||||||
|
|
|
@ -82,8 +82,10 @@ namespace Kernel
|
||||||
|
|
||||||
bool is_userspace() const { return m_is_userspace; }
|
bool is_userspace() const { return m_is_userspace; }
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
void save_sse() { asm volatile("fxsave %0" :: "m"(m_sse_storage)); }
|
void save_sse() { asm volatile("fxsave %0" :: "m"(m_sse_storage)); }
|
||||||
void load_sse() { asm volatile("fxrstor %0" :: "m"(m_sse_storage)); }
|
void load_sse() { asm volatile("fxrstor %0" :: "m"(m_sse_storage)); }
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Thread(pid_t tid, Process*);
|
Thread(pid_t tid, Process*);
|
||||||
|
@ -114,7 +116,9 @@ namespace Kernel
|
||||||
|
|
||||||
uint64_t m_terminate_blockers { 0 };
|
uint64_t m_terminate_blockers { 0 };
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
alignas(16) uint8_t m_sse_storage[512] {};
|
alignas(16) uint8_t m_sse_storage[512] {};
|
||||||
|
#endif
|
||||||
|
|
||||||
friend class Scheduler;
|
friend class Scheduler;
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,7 +32,9 @@ namespace Kernel
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
Thread::current().save_sse();
|
Thread::current().save_sse();
|
||||||
|
#endif
|
||||||
|
|
||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
|
|
||||||
|
@ -205,7 +207,10 @@ namespace Kernel
|
||||||
Kernel::panic("Kernel error while returning to userspace {}", ret.error());
|
Kernel::panic("Kernel error while returning to userspace {}", ret.error());
|
||||||
|
|
||||||
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
Thread::current().load_sse();
|
Thread::current().load_sse();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret.is_error())
|
if (ret.is_error())
|
||||||
return -ret.error().get_error_code();
|
return -ret.error().get_error_code();
|
||||||
|
|
|
@ -104,6 +104,7 @@ static void integer_to_string(char* buffer, T value, int base, bool upper, forma
|
||||||
buffer[offset++] = '\0';
|
buffer[offset++] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
template<BAN::floating_point T>
|
template<BAN::floating_point T>
|
||||||
static void floating_point_to_string(char* buffer, T value, bool upper, const format_options_t options)
|
static void floating_point_to_string(char* buffer, T value, bool upper, const format_options_t options)
|
||||||
{
|
{
|
||||||
|
@ -227,6 +228,7 @@ static void floating_point_to_exponent_string(char* buffer, T value, bool upper,
|
||||||
exponent_options.width = 3;
|
exponent_options.width = 3;
|
||||||
integer_to_string<int>(buffer + offset, exponent, 10, upper, exponent_options);
|
integer_to_string<int>(buffer + offset, exponent, 10, upper, exponent_options);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" int printf_impl(const char* format, va_list arguments, int (*putc_fun)(int, void*), void* data)
|
extern "C" int printf_impl(const char* format, va_list arguments, int (*putc_fun)(int, void*), void* data)
|
||||||
{
|
{
|
||||||
|
@ -349,6 +351,7 @@ extern "C" int printf_impl(const char* format, va_list arguments, int (*putc_fun
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if __enable_sse
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
{
|
{
|
||||||
|
@ -367,6 +370,7 @@ extern "C" int printf_impl(const char* format, va_list arguments, int (*putc_fun
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
// TODO
|
// TODO
|
||||||
|
|
Loading…
Reference in New Issue