Add riscv context_switch

This commit is contained in:
songyanguang
2024-12-27 19:01:00 +08:00
parent beef098836
commit b6340dee69
4 changed files with 130 additions and 63 deletions
@@ -211,6 +211,7 @@ static void _dealloc_task_cb(struct Thread* task)
extern void trap_return(void);
__attribute__((optimize("O0"))) void task_prepare_enter()
{
DEBUG_PRINTF("task_prepare_enter\n");
xizi_leave_kernel();
trap_return();
}
@@ -259,7 +260,11 @@ static struct Thread* _new_task_cb(struct MemSpace* pmemspace)
/// 2. context into stack
sp -= sizeof(*task->thread_context.context);
task->thread_context.context = (struct context*)sp;
#ifndef __riscv
arch_init_context(task->thread_context.context);
#else
arch_init_context(task->thread_context.context, task->thread_context.kern_stack_addr);
#endif
return task;
}
@@ -51,12 +51,21 @@ Modification:
extern void context_switch(struct context**, struct context*);
__attribute__((optimize("O0"))) void dabort_handler(struct trapframe* r)
{
#ifndef __riscv
if (r->pc >= DEV_VRTMEM_BASE && is_spinlock_hold_by_current_cpu(&whole_kernel_lock)) {
assert(is_spinlock_hold_by_current_cpu(&whole_kernel_lock));
ERROR("dabort in kernel, current task: %s\n", cur_cpu()->task == NULL ? "NULL" : cur_cpu()->task->name);
dabort_reason(r);
panic("data abort exception\n");
}
#else
if (r->epc >= DEV_VRTMEM_BASE && is_spinlock_hold_by_current_cpu(&whole_kernel_lock)) {
assert(is_spinlock_hold_by_current_cpu(&whole_kernel_lock));
ERROR("dabort in kernel, current task: %s\n", cur_cpu()->task == NULL ? "NULL" : cur_cpu()->task->name);
dabort_reason(r);
panic("data abort exception\n");
}
#endif
struct Thread* cur_task = cur_cpu()->task;
ERROR("dabort in user space: %s\n", cur_task->name);
@@ -71,12 +80,21 @@ __attribute__((optimize("O0"))) void dabort_handler(struct trapframe* r)
__attribute__((optimize("O0"))) void iabort_handler(struct trapframe* r)
{
#ifndef __riscv
if (r->pc >= DEV_VRTMEM_BASE && is_spinlock_hold_by_current_cpu(&whole_kernel_lock)) {
assert(is_spinlock_hold_by_current_cpu(&whole_kernel_lock));
ERROR("iabort in kernel, current task: %s\n", cur_cpu()->task == NULL ? "NULL" : cur_cpu()->task->name);
iabort_reason(r);
panic("kernel prefetch abort exception\n");
}
#else
if (r->epc >= DEV_VRTMEM_BASE && is_spinlock_hold_by_current_cpu(&whole_kernel_lock)) {
assert(is_spinlock_hold_by_current_cpu(&whole_kernel_lock));
ERROR("iabort in kernel, current task: %s\n", cur_cpu()->task == NULL ? "NULL" : cur_cpu()->task->name);
iabort_reason(r);
panic("kernel prefetch abort exception\n");
}
#endif
struct Thread* cur_task = cur_cpu()->task;
ERROR("iabort in user space: %s\n", cur_task->name);