.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