#include <config.h>
#include "defs.h"
-#define CPU_SIZE (TSS_OFFSET + TSS_SIZE + 4)
-#define CUR_TASK (TSS_OFFSET + TSS_SIZE)
-
-#define OFFSET_ESP0 0
-#define OFFSET_CR3 4
-#define OFFSET_KSTACK 8
-#define OFFSET_PRIVL 12
-#define OFFSET_STATE 16
-
.extern _cpu
.global task_prepare
/* store cr3 in task structure */
movl 8(%esp), %eax
- movl %eax, OFFSET_CR3(%edi)
+ movl %eax, OFFSET_TASK_CR3(%edi)
/* store privilege level in task structure */
movl 24(%esp), %eax
- movl %eax, OFFSET_PRIVL(%edi)
+ movl %eax, OFFSET_TASK_PRIVL(%edi)
/* calculate stack start (since it grows down) */
movl 16(%esp), %eax
movl %ecx, 60(%eax)
/* put EAX into the task structure - task pointer is still in EDI */
- movl %eax, OFFSET_ESP0(%edi)
+ movl %eax, OFFSET_TASK_ESP0(%edi)
/* that should be it */
ret
addl $CPU_SIZE, %eax
jmp 0b
-1: movl CUR_TASK(%eax), %esi
+1: movl OFFSET_CPU_CTASK(%eax), %esi
movl 4(%esp), %edi
cmpl %esi, %edi
ret
/* put the task's ESP0 into the TSS */
-2: movl OFFSET_ESP0(%edi), %ecx
+2: movl OFFSET_TASK_ESP0(%edi), %ecx
movl %ecx, CPU_ESP0(%eax)
movl $KERNEL_DATA, CPU_SS0(%eax)
/* set CS according to the task's privilege level */
- movl OFFSET_PRIVL(%edi), %ecx
+ movl OFFSET_TASK_PRIVL(%edi), %ecx
shll $4, %ecx
addl $8, %ecx
- orl OFFSET_PRIVL(%edi), %ecx
+ orl OFFSET_TASK_PRIVL(%edi), %ecx
movl %ecx, CPU_CS(%eax)
/*
movl %ecx, CPU_GS(%eax)
movl %ecx, CPU_SS(%eax)
- movl OFFSET_CR3(%edi), %ecx
-
- /* check if we can avoid writing to cr3, which would clear the TLB */
- movl %cr3, %edx
- cmpl %ecx, %edx
- jz 2f
+ movl OFFSET_TASK_CR3(%edi), %ecx
/*
* Clear interrupts, since we won't have a valid stack until the
*/
cli
- /* switch page directory */
+ /* switch to the task's page directory since the kernel uses a separate one */
movl %ecx, %cr3
-2: movl %edi, CUR_TASK(%eax)
+ movl %edi, OFFSET_CPU_CTASK(%eax)
/* write ESP to the previous TCB, if any */
test %esi, %esi
jz 3f
- movl %esp, OFFSET_ESP0(%esi)
+ movl %esp, OFFSET_TASK_ESP0(%esi)
/* load new ESP */
-3: movl OFFSET_ESP0(%edi), %esp
+3: movl OFFSET_TASK_ESP0(%edi), %esp
/*
* If this is a new task, we have to use _int_restore to return,
* New tasks have state TASK_STATE_NEW, which is zero.
*/
- movl OFFSET_STATE(%edi), %eax
+ movl OFFSET_TASK_STATE(%edi), %eax
test %eax, %eax
jz 4f
xorl %eax, %eax
*/
ret
-4: movl $1, OFFSET_STATE(%edi)
+4: movl $1, OFFSET_TASK_STATE(%edi)
/*
* In the previous line, the task state is set to TASK_STATE_RUNNING.
* This is the only place where a transition from NEW to any other state
addl $CPU_SIZE, %eax
jmp 0b
-1: movl CUR_TASK(%eax), %eax
+1: movl OFFSET_CPU_CTASK(%eax), %eax
ret
task_set_current:
jmp 0b
1: movl 4(%esp), %ecx
- movl %ecx, CUR_TASK(%eax)
+ movl %ecx, OFFSET_CPU_CTASK(%eax)
ret