swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame^] | 1 | [bits 32] |
| 2 | [extern _do_switch_task] |
| 3 | [global switch_task] |
| 4 | switch_task: |
| 5 | pusha ; Save everything |
| 6 | push esp ; Arguments for _do_switch_task(eip, ebp, esp) |
| 7 | push ebp |
| 8 | push .after |
| 9 | call _do_switch_task |
| 10 | .after: |
| 11 | popa ; Reset everything |
| 12 | xor eax, eax ; Return 0 |
| 13 | ret |
| 14 | |
| 15 | [global _switch_to_task] |
| 16 | _switch_to_task: ; (page_directory, eip, ebp, esp) |
| 17 | add esp, 4 ; We don't care about the return address |
| 18 | pop eax ; Instruction pointer |
| 19 | pop ebp ; Frame pointer |
| 20 | pop ebx ; Stack pointer |
| 21 | pop ecx ; Page directory |
| 22 | |
| 23 | mov esp, ebx ; Reset old stack |
| 24 | |
| 25 | mov cr3, ecx ; Set page directory |
| 26 | sti |
| 27 | jmp eax ; Jump back to code |
| 28 | |
| 29 | [extern _init_tasks] |
| 30 | [global init_tasks] |
| 31 | init_tasks: |
| 32 | lea eax, [esp + 4] ; Stack pointer before call |
| 33 | mov ebx, [esp] ; Return address |
| 34 | push ebx ; eip |
| 35 | push ebp ; ebp |
| 36 | push eax ; esp |
| 37 | call _init_tasks |
| 38 | add esp, 12 |
| 39 | ret |