From 32898a17a21b43dd7954965dd8292ce195bff32f Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 2 Oct 2019 02:20:15 +0900 Subject: [PATCH] Save/restore the EBP register used in kernel-space during task switches, otherwise the new task will execute on the old stack (causing a page fault) after the C function that called task_switch returns --- kernel/arch/defs.h | 1 + kernel/arch/task.S | 3 +++ kernel/include/arch.h | 1 + 3 files changed, 5 insertions(+) diff --git a/kernel/arch/defs.h b/kernel/arch/defs.h index 6ec11a2..43e7150 100644 --- a/kernel/arch/defs.h +++ b/kernel/arch/defs.h @@ -76,6 +76,7 @@ #define OFFSET_TASK_KSTACK 8 #define OFFSET_TASK_PRIVL 12 #define OFFSET_TASK_STATE 16 +#define OFFSET_TASK_EBP0 20 #define CPU_SIZE (TSS_OFFSET + TSS_SIZE + 4) #define OFFSET_CPU_CTASK (TSS_OFFSET + TSS_SIZE) diff --git a/kernel/arch/task.S b/kernel/arch/task.S index 32e376b..e09095f 100644 --- a/kernel/arch/task.S +++ b/kernel/arch/task.S @@ -162,6 +162,7 @@ task_prepare: /* put EAX into the task structure - task pointer is still in EDI */ movl %eax, OFFSET_TASK_ESP0(%edi) + movl %eax, OFFSET_TASK_EBP0(%edi) /* that should be it */ ret @@ -221,6 +222,7 @@ task_switch: test %esi, %esi jz 2f movl %esp, OFFSET_TASK_ESP0(%esi) + movl %ebp, OFFSET_TASK_EBP0(%esi) /* * Clear interrupts, since we won't have a valid stack until the @@ -233,6 +235,7 @@ task_switch: * linear address while we're in the context of the kernel */ movl OFFSET_TASK_ESP0(%edi), %esp + movl OFFSET_TASK_EBP0(%edi), %ebp /* * If this is a new task, we have to use _int_restore to return, diff --git a/kernel/include/arch.h b/kernel/include/arch.h index fec57bb..260707d 100644 --- a/kernel/include/arch.h +++ b/kernel/include/arch.h @@ -35,6 +35,7 @@ struct task { void *t_kstack; u32_t t_privl; u32_t t_state; + u32_t t_bp; u32_t t_tslice; u32_t t_rslice; -- 2.47.3