]> git.corax.cc Git - corax/commitdiff
Fix control flow in task_switch function; add userspace esp argument to task_prepare...
authorMatthias Kruk <m@m10k.eu>
Sat, 21 Sep 2019 02:31:50 +0000 (11:31 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 21 Sep 2019 02:31:50 +0000 (11:31 +0900)
kernel/arch/task.S

index 9e1433c6340e21ab9fb1fb89ab897f3fca9259b0..faed92a4a4cb7956a0caf2a6199ed6a57b986322 100644 (file)
@@ -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