blob: 5c7eaa9e1db7355c289f65b1ac47cf5faa61aa07 [file] [log] [blame]
swissChili1e8b7562021-12-22 21:22:57 -08001 ;; 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)
swissChilicfd3c3c2021-04-03 15:04:24 -07006 add esp, 4 ; We don't care about the return address
swissChilicfd3c3c2021-04-03 15:04:24 -07007
swissChili7be32742021-04-03 21:17:24 -07008 pop ecx ; Page directory
9 pop eax ; eip
10 pop ebp
11 pop ebx ; esp
swissChilicfd3c3c2021-04-03 15:04:24 -070012
swissChili1e8b7562021-12-22 21:22:57 -080013 mov dx, 0x23 ; User mode data segment
14 mov ds, dx
15 mov es, dx
16 mov fs, dx
17 mov gs, dx
18
swissChilicfd3c3c2021-04-03 15:04:24 -070019 mov cr3, ecx ; Set page directory
swissChili1e8b7562021-12-22 21:22:57 -080020
21 push 0x23
22 push ebx ; esp
23
swissChilicfd3c3c2021-04-03 15:04:24 -070024 sti
25 jmp eax ; Jump back to code
swissChili1e8b7562021-12-22 21:22:57 -080026
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