]> git.corax.cc Git - corax/commitdiff
Move some of the definitions from arch/task.S to arch/defs.h so they can be shared...
authorMatthias Kruk <m@m10k.eu>
Tue, 1 Oct 2019 06:37:52 +0000 (15:37 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 1 Oct 2019 06:37:52 +0000 (15:37 +0900)
config.h
kernel/arch/defs.h
kernel/arch/task.S

index 8c8cc546acebfa83e62abd2357aa4c286621f02f..c9df92245d04e9924332219ff686aa0dd856abb3 100644 (file)
--- a/config.h
+++ b/config.h
 
 #define CONFIG_KERNEL_HEAP_SIZE     4096
 #define CONFIG_KERNEL_STACK_SIZE    4096
+#ifdef __ASSEMBLY_SOURCE
+#define CONFIG_KERNEL_STACK_BASE    0xffffe000
+#else /* !__ASSEMBLY_SOURCE */
 #define CONFIG_KERNEL_STACK_BASE    ((void*)0xffffe000)
+#endif /* !__ASSEMBLY_SOURCE */
 #define CONFIG_USER_STACK_SIZE      4096
 
 #define CONFIG_APIC     0
@@ -32,7 +36,7 @@
 #define CONFIG_SMP_CPUS 1
 
 #define CONFIG_POSIX    1
-#define CONFIG_DEBUG    1
+#define CONFIG_DEBUG    0
 
 /* sanity checks */
 
index 0ddfc10277199a557fa751c8ac1a983ef0bdbd9c..6ec11a2afda5e5baa76f12bfff68f531b4983f22 100644 (file)
 #define OFFSET_TSS_GS   92
 #define OFFSET_TSS_SS   80
 
+#define OFFSET_TASK_ESP0   0
+#define OFFSET_TASK_CR3    4
+#define OFFSET_TASK_KSTACK 8
+#define OFFSET_TASK_PRIVL  12
+#define OFFSET_TASK_STATE  16
+
+#define CPU_SIZE           (TSS_OFFSET + TSS_SIZE + 4)
+#define OFFSET_CPU_CTASK   (TSS_OFFSET + TSS_SIZE)
+
 #define CPU_ESP0        (TSS_OFFSET + OFFSET_TSS_ESP0)
 #define CPU_SS0         (TSS_OFFSET + OFFSET_TSS_SS0)
 #define CPU_SS1         (TSS_OFFSET + OFFSET_TSS_SS1)
index 43f3b12fb4896f5fbf73313f980a0d7af3df6dfa..bd092ea21b95ff4286c3cb6e2fdaaf6c432c6c7f 100644 (file)
 #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
@@ -54,11 +45,11 @@ 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
@@ -141,7 +132,7 @@ task_prepare:
        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
@@ -162,7 +153,7 @@ task_switch:
        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
@@ -172,15 +163,15 @@ task_switch:
        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)
 
        /*
@@ -194,12 +185,7 @@ task_switch:
        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
@@ -207,18 +193,18 @@ task_switch:
         */
        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,
@@ -226,7 +212,7 @@ task_switch:
         * 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
@@ -239,7 +225,7 @@ task_switch:
         */
        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
@@ -255,7 +241,7 @@ task_get_current:
        addl    $CPU_SIZE, %eax
        jmp             0b
 
-1:     movl    CUR_TASK(%eax), %eax
+1:     movl    OFFSET_CPU_CTASK(%eax), %eax
        ret
 
 task_set_current:
@@ -267,5 +253,5 @@ task_set_current:
        jmp             0b
 
 1:     movl    4(%esp), %ecx
-       movl    %ecx, CUR_TASK(%eax)
+       movl    %ecx, OFFSET_CPU_CTASK(%eax)
        ret