mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
Kernel/riscv64: Implement thread_context_first_enter
thread_context_first_enter reuses the context restoring code in the trap handler, just like other arches already do. The `ld x2, 1*8(sp)` is unnecessary in the trap handler, as the stack pointer should be equal to the stack pointer slot in the RegisterState if the trap is from supervisor mode (and we currently don't support user traps). This load will however make us unable to reuse that code for thread_context_first_enter.
This commit is contained in:
parent
7fbcceb657
commit
efdc433ebc
2 changed files with 18 additions and 4 deletions
|
@ -276,6 +276,12 @@ ErrorOr<Vector<FlatPtr, 32>> ProcessorBase<T>::capture_stack_trace(Thread&, size
|
|||
return Vector<FlatPtr, 32> {};
|
||||
}
|
||||
|
||||
extern "C" void context_first_init(Thread* from_thread, Thread* to_thread);
|
||||
extern "C" void context_first_init(Thread* from_thread, Thread* to_thread)
|
||||
{
|
||||
do_context_first_init(from_thread, to_thread);
|
||||
}
|
||||
|
||||
extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread);
|
||||
extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread)
|
||||
{
|
||||
|
@ -304,9 +310,16 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread)
|
|||
load_fpu_state(&to_thread->fpu_state());
|
||||
}
|
||||
|
||||
NAKED void thread_context_first_enter(void)
|
||||
NAKED void thread_context_first_enter()
|
||||
{
|
||||
asm("unimp");
|
||||
asm(
|
||||
"ld a0, 0(sp) \n"
|
||||
"ld a1, 8(sp) \n"
|
||||
"addi sp, sp, 32 \n"
|
||||
"call context_first_init \n"
|
||||
"mv a0, sp \n"
|
||||
"call exit_trap \n"
|
||||
"tail restore_context_and_sret \n");
|
||||
}
|
||||
|
||||
NAKED void do_assume_context(Thread*, u32)
|
||||
|
|
|
@ -90,6 +90,9 @@ asm_trap_handler:
|
|||
|
||||
call trap_handler
|
||||
|
||||
.global restore_context_and_sret
|
||||
restore_context_and_sret:
|
||||
|
||||
// Remove TrapFrame from the stack
|
||||
addi sp, sp, 16
|
||||
|
||||
|
@ -131,7 +134,5 @@ asm_trap_handler:
|
|||
ld x30, 29*8(sp)
|
||||
ld x31, 30*8(sp)
|
||||
|
||||
ld x2, 1*8(sp)
|
||||
|
||||
addi sp, sp, REGISTER_STATE_SIZE
|
||||
sret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue