.intel_syntax noprefix .section .text .global switch_to_task switch_to_task: push ebx push ebp push edi push esi // save the current stack pointer to the old stack mov [current_task], esp mov edi, [eip_backup] mov [current_task+16], edi // save instruction before Interrupt // stack pointer + the 4 regs pushed // and + 1 to get the argument (next task) mov esi, [esp+(4+1)*4] mov [current_task], esi mov esp, [current_task] // esp mov eax, [current_task+4] // esp0 mov ebx, [current_task+8] // cr3 mov [TSS+4], eax // tss.esp0 mov ecx, cr3 // if cr3 hasn't change, do nothing cmp ecx, ebx je .END // mov cr3, ebx // TODO replace the eip store in stack by the [current_task+16](current_task->eip) .END: pop esi pop edi pop ebp pop ebx ret // this will also change eip to the next task's instructions