aboutsummaryrefslogtreecommitdiff
path: root/src/core/scheduler_asm.S
blob: 1f916ec375d33cd2eb16fad417ce2dae243a0a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.globl task_switch

// This function takes a pointer
// to a PROC structure and jump
// to this process
task_switch:
    pop %esi
    push 8(%esi)  # eax (cf PROC struct)
    push 12(%esi)  # ebx
    push 16(%esi)  # ecx
    push 20(%esi)  # edx
    push 40(%esi)  # ebp
    push 48(%esi)  # edi
    push 52(%esi)  # ds
    push 56(%esi)  # es
    push 60(%esi)  # fs
    push 64(%esi)  # gs

    // Don't forget to clear the interrupt
    movb $0x20, %al
    outb %al, $0x20

    // Setup process page directory
    mov 4(%esi), %eax
    mov %eax, %cr3

    // Setup registers
    pop %gs
    pop %fs
    pop %es
    pop %ds
    pop %edi
    pop %ebp
    pop %edx
    pop %ecx
    pop %ebx
    pop %eax

    // Perform the task switch
    push 32(%esi)  # ss
    push 36(%esi)  # esp
    push 68(%esi)  # eflags
    push 24(%esi)  # cs
    push 28(%esi)  # eip
    mov 52(%esi), %ds # Choose the right data segment
    mov 44(%esi), %esi # Now restore task esi
    iret # Launch task