42_KFS/src/multitasking/switch_to_task.s

45 lines
760 B
ArmAsm

.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+0], esp
mov edi, [esp_backup] // get eip
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
.END:
mov edi, [current_task+16]
mov [esp_backup], edi
pop esi
pop edi
pop ebp
pop ebx
ret