From: Matthias Kruk Date: Sat, 21 Sep 2019 02:31:50 +0000 (+0900) Subject: Fix control flow in task_switch function; add userspace esp argument to task_prepare... X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=c6294a8ccdea879ba38b87145d04299da2eef75b;p=corax Fix control flow in task_switch function; add userspace esp argument to task_prepare function --- diff --git a/kernel/arch/task.S b/kernel/arch/task.S index 9e1433c..faed92a 100644 --- a/kernel/arch/task.S +++ b/kernel/arch/task.S @@ -38,8 +38,9 @@ task_prepare: * int task_prepare(struct task*, u32_t cr3, u32_t eip, * u32_t esp, u32_t priv) * - * priv = 20(%esp) - * esp = 16(%esp) + * priv = 24(%esp) + * esp = 20(%esp) + * esp0 = 16(%esp) * eip = 12(%esp) * cr3 = 8(%esp) * task = 4(%esp) @@ -91,10 +92,10 @@ task_prepare: subl $64, %eax /* calculate DS from priv and put it on the new stack */ - movl 20(%esp), %ecx + movl 24(%esp), %ecx shll $4, %ecx addl $16, %ecx - orl 20(%esp), %ecx + orl 24(%esp), %ecx movl %ecx, (%eax) /* Clear general purpose registers (and error/intr) */ @@ -114,16 +115,18 @@ task_prepare: movl %ecx, 44(%eax) /* calculate CS from priv and put it on the new stack */ - movl 20(%esp), %ecx + movl 24(%esp), %ecx shll $4, %ecx addl $8, %ecx - orl 20(%esp), %ecx + orl 24(%esp), %ecx movl %ecx, 48(%eax) /* put EFLAGS on the new stack */ movl $USER_EFLAGS, 52(%eax) /* put the stack pointer on the stack */ + movl 20(%esp), %ecx + movl %ecx, 56(%eax) /* put the stack segment on the new stack - use the value from DS */ movl (%eax), %ecx @@ -151,16 +154,16 @@ task_switch: addl $CPU_SIZE, %eax jmp 0b - movl CUR_TASK(%eax), %esi +1: movl CUR_TASK(%eax), %esi movl 4(%esp), %edi cmpl %esi, %edi - jnz 1f + jnz 2f /* FIXME: Return -EALREADY instead */ movl $-1, %eax ret -1: movl OFFSET_CR3(%edi), %ecx +2: movl OFFSET_CR3(%edi), %ecx /* check if we can avoid writing to cr3, which would clear the TLB */ movl %cr3, %edx