how to switch CPL3 to CPL0

Viewed 115

I write a bootloader which i want to switch to ring0 from ring3 by sofaware interrupt. but it don't work.

org 0x7c00


mov dx,0x92
in al,dx
or al,2
out dx,al

mov eax,cr0
or eax,1
mov cr0,eax


lgdt [gdt_pointer]
mov ax,0x10
mov ds,ax
mov ss,ax
jmp 0x8:flush


[bits 32]
flush:

lidt [idt_pointer]


push (4<<3) | (3)  ;;SS 
push 0xffff        ;;ESP
push 0             ;;EFLAGS
push (3<<3) | (3)  ;;CS 
push ring3         ;;EIP
iret
jmp $

ring3:
mov ax,4<<3        ;;DS 
mov ds,ax

int 0
jmp $

idt_function:
    ;!!!!
    ;!!!! question:   why CPL keep 3 ????? 
    ;!!!! shouldn't dpl = 0?
    ;!!!! what should i do to switch to ring0???????
    ;!!!!

nop
jmp $


;;=================data==================
;;GDT
gdt_pointer:
dw 39
dd gdt_arrays

gdt_arrays:
dq 0
dq 0xCF9E000000FFFF ;DPL=0
dq 0xCF92000000FFFF ;DPL=0
dq 0xCFFE000000FFFF ;DPL=3
dq 0xCFF2000000FFFF ;DPL=3

;;IDT
idt_pointer:
dw 7
dd idt_arrays

idt_arrays:
;
dw idt_function
dw 1<<3 ;;
db 0
db 0xee ;;DPL=3,
dw 0


times 510-($-$$) db 0
db 0x55
db 0xaa
;;=================data==================

Doesn't the application(RING3) go to a higher privilege code space(RING0) via system interrupt, why do I still keep CPL=3 here? If the privilege is not enhanced (CPL=3), how can I use the stunt instructions (CPL=0), such as hlt, lgdt, etc.?

0 Answers
Related