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] |
swissChili | 7be3274 | 2021-04-03 21:17:24 -0700 | [diff] [blame] | 16 | ;; _switch_to_task(uint page_directory, uint eip, uint ebp, uint esp) |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 17 | _switch_to_task: ; (page_directory, eip, ebp, esp) |
| 18 | add esp, 4 ; We don't care about the return address |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 19 | |
swissChili | 7be3274 | 2021-04-03 21:17:24 -0700 | [diff] [blame] | 20 | pop ecx ; Page directory |
| 21 | pop eax ; eip |
| 22 | pop ebp |
| 23 | pop ebx ; esp |
| 24 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 25 | mov esp, ebx ; Reset old stack |
| 26 | |
| 27 | mov cr3, ecx ; Set page directory |
| 28 | sti |
| 29 | jmp eax ; Jump back to code |
| 30 | |
| 31 | [extern _init_tasks] |
| 32 | [global init_tasks] |
| 33 | init_tasks: |
| 34 | lea eax, [esp + 4] ; Stack pointer before call |
| 35 | mov ebx, [esp] ; Return address |
| 36 | push ebx ; eip |
| 37 | push ebp ; ebp |
| 38 | push eax ; esp |
| 39 | call _init_tasks |
| 40 | add esp, 12 |
| 41 | ret |