swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame] | 1 | ;; This is very much the same as _switch_to_task, but we used iret |
| 2 | ;; and switch to ring3. |
| 3 | [global _switch_to_user_task] |
| 4 | ;; _switch_to_user_task(uint page_directory, uint eip, uint ebp, uint esp) |
| 5 | _switch_to_user_task: ; (page_directory, eip, ebp, esp) |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 6 | add esp, 4 ; We don't care about the return address |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 7 | |
swissChili | 7be3274 | 2021-04-03 21:17:24 -0700 | [diff] [blame] | 8 | pop ecx ; Page directory |
| 9 | pop eax ; eip |
| 10 | pop ebp |
| 11 | pop ebx ; esp |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 12 | |
swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame] | 13 | mov dx, 0x23 ; User mode data segment |
| 14 | mov ds, dx |
| 15 | mov es, dx |
| 16 | mov fs, dx |
| 17 | mov gs, dx |
| 18 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 19 | mov cr3, ecx ; Set page directory |
swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame] | 20 | |
| 21 | push 0x23 |
| 22 | push ebx ; esp |
| 23 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 24 | sti |
| 25 | jmp eax ; Jump back to code |
swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame] | 26 | |
| 27 | [global _switch_to_task] |
| 28 | _switch_to_task: ; (uint page_directory, struct |
| 29 | ; registers regs) |
| 30 | add esp, 4 ; We don't care about return address |
| 31 | pop eax |
| 32 | mov cr3, eax ; Change page directories |
| 33 | pop eax |
| 34 | mov ds, ax ; First is ds |
| 35 | popad ; Then the rest of the registers |
| 36 | add esp, 8 ; Then IRQ # and error # |
| 37 | iret ; And finally the saved state |