diff options
Diffstat (limited to 'src/core/scheduler_asm.S')
| -rw-r--r-- | src/core/scheduler_asm.S | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/src/core/scheduler_asm.S b/src/core/scheduler_asm.S index 8f417c4..0c9d5ba 100644 --- a/src/core/scheduler_asm.S +++ b/src/core/scheduler_asm.S @@ -1,34 +1,67 @@ .globl switch - - -.extern kvar_stack_pma - switch: - - # TODO: Check if we come from kernel mode (use kernel stack) - # TODO: restore all registers - - mov 96(%rdi), %ax - mov %ax, %ds - mov %ax, %es - mov %ax, %fs - mov %ax, %gs - + + # Load task page table mov (%rdi), %rax mov %rax, %cr3 - push 96(%rdi) - push 64(%rdi) - pushf + # 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 - push 40(%rdi) - push 48(%rdi) + 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 |
