mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
Kernel/riscv64: Implement enter_thread_context
This code is based on the aarch64 implementation.
This commit is contained in:
parent
2f33e7a964
commit
7fbcceb657
2 changed files with 34 additions and 1 deletions
|
@ -93,6 +93,11 @@ struct [[gnu::packed]] alignas(u64) SATP {
|
||||||
{
|
{
|
||||||
return bit_cast<SATP>(CSR::read(CSR::Address::SATP));
|
return bit_cast<SATP>(CSR::read(CSR::Address::SATP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(SATP const& other) const
|
||||||
|
{
|
||||||
|
return bit_cast<u64>(*this) == bit_cast<u64>(other);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
static_assert(AssertSize<SATP, 8>());
|
static_assert(AssertSize<SATP, 8>());
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ static void store_fpu_state(FPUState* fpu_state)
|
||||||
: "t0", "memory");
|
: "t0", "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]] static void load_fpu_state(FPUState* fpu_state)
|
static void load_fpu_state(FPUState* fpu_state)
|
||||||
{
|
{
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"fld f0, 0*8(%0) \n"
|
"fld f0, 0*8(%0) \n"
|
||||||
|
@ -276,6 +276,34 @@ ErrorOr<Vector<FlatPtr, 32>> ProcessorBase<T>::capture_stack_trace(Thread&, size
|
||||||
return Vector<FlatPtr, 32> {};
|
return Vector<FlatPtr, 32> {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread);
|
||||||
|
extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread)
|
||||||
|
{
|
||||||
|
VERIFY(from_thread == to_thread || from_thread->state() != Thread::State::Running);
|
||||||
|
VERIFY(to_thread->state() == Thread::State::Running);
|
||||||
|
|
||||||
|
Processor::set_current_thread(*to_thread);
|
||||||
|
|
||||||
|
store_fpu_state(&from_thread->fpu_state());
|
||||||
|
|
||||||
|
auto& from_regs = from_thread->regs();
|
||||||
|
auto& to_regs = to_thread->regs();
|
||||||
|
if (from_regs.satp != to_regs.satp) {
|
||||||
|
RISCV64::CSR::SATP::write(to_regs.satp);
|
||||||
|
Processor::flush_entire_tlb_local();
|
||||||
|
}
|
||||||
|
|
||||||
|
to_thread->set_cpu(Processor::current().id());
|
||||||
|
|
||||||
|
Processor::set_thread_specific_data(to_thread->thread_specific_data());
|
||||||
|
|
||||||
|
auto in_critical = to_thread->saved_critical();
|
||||||
|
VERIFY(in_critical > 0);
|
||||||
|
Processor::restore_critical(in_critical);
|
||||||
|
|
||||||
|
load_fpu_state(&to_thread->fpu_state());
|
||||||
|
}
|
||||||
|
|
||||||
NAKED void thread_context_first_enter(void)
|
NAKED void thread_context_first_enter(void)
|
||||||
{
|
{
|
||||||
asm("unimp");
|
asm("unimp");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue