aboutsummaryrefslogtreecommitdiff
path: root/src/core/scheduler_asm.S
blob: 0c9d5ba183b108f3046db316518814ae60f40384 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
.globl switch

switch:
  
    # Load task page table
    mov (%rdi), %rax
    mov %rax, %cr3

    # First load the task stack
    mov 64(%rdi), %rsp

    # Prepare for iret
    push 96(%rdi)   # ds
    push 64(%rdi)   # rsp
    push 128(%rdi)  # Flags
    pop %rax
    or $0x200, %rax # Enable interrupt
    mov $0xffffffffbfff, %rbx # NT flag
    and %rbx, %rax
    push %rax       # Apply flags changes
    push 40(%rdi)   # cs
    push 48(%rdi)   # rip

    # Prepare to restore general registers
    push 8(%rdi)    # rax
    push 16(%rdi)   # rbx
    push 24(%rdi)   # rcx
    push 32(%rdi)   # rdx
    push 72(%rdi)   # rbp
    push 80(%rdi)   # rsi
    push 88(%rdi)   # rdi
    push 144(%rdi)  # r8
    push 152(%rdi)  # r9
    push 160(%rdi)  # r10
    push 160(%rdi)  # r11
    push 176(%rdi)  # r12
    push 184(%rdi)  # r13
    push 192(%rdi)  # r14
    push 200(%rdi)  # r15

    # ds
    mov 96(%rdi), %ax
    mov %ax, %ds
    mov %ax, %gs
    mov %ax, %fs
    mov %ax, %es

    # Restore general registers
    pop %r15
    pop %r14
    pop %r13
    pop %r12
    pop %r11
    pop %r10
    pop %r9
    pop %r8
    pop %rdi
    pop %rsi
    pop %rbp
    pop %rdx
    pop %rcx
    pop %rbx
    pop %rax

 
    # Perform task switching
    iretq