Xyris  0.5
flush.s
Go to the documentation of this file.
1 ; @brief This function is used to flush the GDT when we want to
2 ; enter into ring 3 (userspace) since we need to flush out all of
3 ; the kernel information and replace it with info safe for user
4 ; applications. The following function flushes the TSS and can
5 ; "flush" (invalidate) a page.
6 ;
7 section .text
8 align 4
9 
10 global gdt_flush
11 gdt_flush:
12  ; Load GDT
13  mov eax,[esp+4]
14  lgdt [eax]
15 
16  mov ax, 0x10
17  mov ds, ax
18  mov es, ax
19  mov fs, ax
20  mov ss, ax
21  mov gs, ax
22  ; Do a long jump back and return
23  jmp 0x08:.flush
24 .flush:
25  ret
26 
27 global tss_flush
28 tss_flush:
29  mov ax, 0x2B ; Load the index of our TSS structure - The index is
30  ; 0x28, as it is the 5th selector and each is 8 bytes
31  ; long, but we set the bottom two bits (making 0x2B)
32  ; so that it has an RPL of 3, not zero.
33  ltr ax ; Load 0x2B into the task state register.
34  ret