Compare commits
3 Commits
753de3d9f0
...
b0ff2392a1
Author | SHA1 | Date |
---|---|---|
Bananymous | b0ff2392a1 | |
Bananymous | 001e95f973 | |
Bananymous | db0650cf10 |
|
@ -189,6 +189,7 @@ namespace Kernel::IDT
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
derrorln("Stack pointer out of bounds!");
|
derrorln("Stack pointer out of bounds!");
|
||||||
|
derrorln("rip {H}", interrupt_stack.rip);
|
||||||
derrorln("rsp {H}, stack {H}->{H}, istack {H}->{H}",
|
derrorln("rsp {H}, stack {H}->{H}, istack {H}->{H}",
|
||||||
interrupt_stack.rsp,
|
interrupt_stack.rsp,
|
||||||
stack.vaddr(), stack.vaddr() + stack.size(),
|
stack.vaddr(), stack.vaddr() + stack.size(),
|
||||||
|
@ -218,6 +219,23 @@ namespace Kernel::IDT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if __enable_sse
|
||||||
|
else if (isr == ISR::DeviceNotAvailable)
|
||||||
|
{
|
||||||
|
asm volatile(
|
||||||
|
"movq %cr0, %rax;"
|
||||||
|
"andq $~(1 << 3), %rax;"
|
||||||
|
"movq %rax, %cr0;"
|
||||||
|
);
|
||||||
|
if (auto* current = &Thread::current(); current != Thread::sse_thread())
|
||||||
|
{
|
||||||
|
if (auto* sse = Thread::sse_thread())
|
||||||
|
sse->save_sse();
|
||||||
|
current->load_sse();
|
||||||
|
}
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PageTable::current().get_page_flags(interrupt_stack.rip & PAGE_ADDR_MASK) & PageTable::Flags::Present)
|
if (PageTable::current().get_page_flags(interrupt_stack.rip & PAGE_ADDR_MASK) & PageTable::Flags::Present)
|
||||||
|
@ -259,7 +277,6 @@ namespace Kernel::IDT
|
||||||
int signal = 0;
|
int signal = 0;
|
||||||
switch (isr)
|
switch (isr)
|
||||||
{
|
{
|
||||||
case ISR::DeviceNotAvailable:
|
|
||||||
case ISR::DivisionError:
|
case ISR::DivisionError:
|
||||||
case ISR::SIMDFloatingPointException:
|
case ISR::SIMDFloatingPointException:
|
||||||
case ISR::x87FloatingPointException:
|
case ISR::x87FloatingPointException:
|
||||||
|
@ -290,22 +307,11 @@ namespace Kernel::IDT
|
||||||
ASSERT(Thread::current().state() != Thread::State::Terminated);
|
ASSERT(Thread::current().state() != Thread::State::Terminated);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
#if __enable_sse
|
|
||||||
if (from_userspace)
|
|
||||||
{
|
|
||||||
ASSERT(Thread::current().state() == Thread::State::Executing);
|
|
||||||
Thread::current().load_sse();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void cpp_irq_handler(uint64_t irq, InterruptStack& interrupt_stack)
|
extern "C" void cpp_irq_handler(uint64_t irq, InterruptStack& interrupt_stack)
|
||||||
{
|
{
|
||||||
#if __enable_sse
|
|
||||||
Thread::current().save_sse();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (Scheduler::current_tid())
|
if (Scheduler::current_tid())
|
||||||
{
|
{
|
||||||
Thread::current().set_return_rsp(interrupt_stack.rsp);
|
Thread::current().set_return_rsp(interrupt_stack.rsp);
|
||||||
|
@ -326,10 +332,6 @@ done:
|
||||||
Scheduler::get().reschedule_if_idling();
|
Scheduler::get().reschedule_if_idling();
|
||||||
|
|
||||||
ASSERT(Thread::current().state() != Thread::State::Terminated);
|
ASSERT(Thread::current().state() != Thread::State::Terminated);
|
||||||
|
|
||||||
#if __enable_sse
|
|
||||||
Thread::current().load_sse();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_idt()
|
static void flush_idt()
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace Kernel
|
||||||
vaddr_t interrupt_stack_base() const { return m_interrupt_stack ? m_interrupt_stack->vaddr() : 0; }
|
vaddr_t interrupt_stack_base() const { return m_interrupt_stack ? m_interrupt_stack->vaddr() : 0; }
|
||||||
size_t interrupt_stack_size() const { return m_interrupt_stack ? m_interrupt_stack->size() : 0; }
|
size_t interrupt_stack_size() const { return m_interrupt_stack ? m_interrupt_stack->size() : 0; }
|
||||||
|
|
||||||
static Thread& current() ;
|
static Thread& current();
|
||||||
static pid_t current_tid();
|
static pid_t current_tid();
|
||||||
|
|
||||||
Process& process();
|
Process& process();
|
||||||
|
@ -87,8 +87,9 @@ namespace Kernel
|
||||||
size_t physical_page_count() const { return virtual_page_count(); }
|
size_t physical_page_count() const { return virtual_page_count(); }
|
||||||
|
|
||||||
#if __enable_sse
|
#if __enable_sse
|
||||||
void save_sse() { asm volatile("fxsave %0" :: "m"(m_sse_storage)); }
|
void save_sse();
|
||||||
void load_sse() { asm volatile("fxrstor %0" :: "m"(m_sse_storage)); }
|
void load_sse();
|
||||||
|
static Thread* sse_thread();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -231,6 +231,17 @@ namespace Kernel
|
||||||
|
|
||||||
Thread* current = ¤t_thread();
|
Thread* current = ¤t_thread();
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
|
if (current != Thread::sse_thread())
|
||||||
|
{
|
||||||
|
asm volatile(
|
||||||
|
"movq %cr0, %rax;"
|
||||||
|
"orq $(1 << 3), %rax;"
|
||||||
|
"movq %rax, %cr0"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
while (current->state() == Thread::State::Terminated)
|
while (current->state() == Thread::State::Terminated)
|
||||||
{
|
{
|
||||||
Thread* thread = m_current_thread->thread;
|
Thread* thread = m_current_thread->thread;
|
||||||
|
|
|
@ -26,10 +26,6 @@ namespace Kernel
|
||||||
Thread::current().set_return_rsp(interrupt_stack.rsp);
|
Thread::current().set_return_rsp(interrupt_stack.rsp);
|
||||||
Thread::current().set_return_rip(interrupt_stack.rip);
|
Thread::current().set_return_rip(interrupt_stack.rip);
|
||||||
|
|
||||||
#if __enable_sse
|
|
||||||
Thread::current().save_sse();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
|
|
||||||
(void)arg1;
|
(void)arg1;
|
||||||
|
@ -221,6 +217,9 @@ namespace Kernel
|
||||||
|
|
||||||
asm volatile("cli");
|
asm volatile("cli");
|
||||||
|
|
||||||
|
if (ret.is_error() && ret.error().get_error_code() == ENOTSUP)
|
||||||
|
dprintln("ENOTSUP {}", syscall);
|
||||||
|
|
||||||
if (ret.is_error() && ret.error().is_kernel_error())
|
if (ret.is_error() && ret.error().is_kernel_error())
|
||||||
Kernel::panic("Kernel error while returning to userspace {}", ret.error());
|
Kernel::panic("Kernel error while returning to userspace {}", ret.error());
|
||||||
|
|
||||||
|
@ -230,10 +229,6 @@ namespace Kernel
|
||||||
|
|
||||||
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
ASSERT(Kernel::Thread::current().state() == Kernel::Thread::State::Executing);
|
||||||
|
|
||||||
#if __enable_sse
|
|
||||||
current_thread.load_sse();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret.is_error())
|
if (ret.is_error())
|
||||||
return -ret.error().get_error_code();
|
return -ret.error().get_error_code();
|
||||||
return ret.value();
|
return ret.value();
|
||||||
|
|
|
@ -101,7 +101,16 @@ namespace Kernel
|
||||||
: m_tid(tid), m_process(process)
|
: m_tid(tid), m_process(process)
|
||||||
{
|
{
|
||||||
#if __enable_sse
|
#if __enable_sse
|
||||||
|
uintptr_t cr0;
|
||||||
|
asm volatile(
|
||||||
|
"movq %%cr0, %%rax;"
|
||||||
|
"movq %%rax, %%rbx;"
|
||||||
|
"andq $~(1 << 3), %%rax;"
|
||||||
|
"movq %%rax, %%cr0;"
|
||||||
|
: "=b"(cr0)
|
||||||
|
);
|
||||||
save_sse();
|
save_sse();
|
||||||
|
asm volatile("movq %0, %%cr0" :: "r"(cr0));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,4 +370,24 @@ namespace Kernel
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __enable_sse
|
||||||
|
static Thread* s_sse_thread = nullptr;
|
||||||
|
|
||||||
|
void Thread::save_sse()
|
||||||
|
{
|
||||||
|
asm volatile("fxsave %0" :: "m"(m_sse_storage));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::load_sse()
|
||||||
|
{
|
||||||
|
asm volatile("fxrstor %0" :: "m"(m_sse_storage));
|
||||||
|
s_sse_thread = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread* Thread::sse_thread()
|
||||||
|
{
|
||||||
|
return s_sse_thread;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,6 +13,9 @@ extern "C" char** environ;
|
||||||
|
|
||||||
extern "C" void _fini();
|
extern "C" void _fini();
|
||||||
|
|
||||||
|
static void (*at_exit_funcs[64])();
|
||||||
|
static uint32_t at_exit_funcs_count = 0;
|
||||||
|
|
||||||
void abort(void)
|
void abort(void)
|
||||||
{
|
{
|
||||||
fflush(nullptr);
|
fflush(nullptr);
|
||||||
|
@ -22,6 +25,8 @@ void abort(void)
|
||||||
|
|
||||||
void exit(int status)
|
void exit(int status)
|
||||||
{
|
{
|
||||||
|
for (uint32_t i = at_exit_funcs_count; i > 0; i--)
|
||||||
|
at_exit_funcs[i - 1]();
|
||||||
fflush(nullptr);
|
fflush(nullptr);
|
||||||
__cxa_finalize(nullptr);
|
__cxa_finalize(nullptr);
|
||||||
_fini();
|
_fini();
|
||||||
|
@ -34,9 +39,15 @@ int abs(int val)
|
||||||
return val < 0 ? -val : val;
|
return val < 0 ? -val : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
int atexit(void(*)(void))
|
int atexit(void (*func)(void))
|
||||||
{
|
{
|
||||||
return -1;
|
if (at_exit_funcs_count > sizeof(at_exit_funcs) / sizeof(*at_exit_funcs))
|
||||||
|
{
|
||||||
|
errno = ENOBUFS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
at_exit_funcs[at_exit_funcs_count++] = func;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int atoi(const char* str)
|
int atoi(const char* str)
|
||||||
|
|
Loading…
Reference in New Issue