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