I set that the RPL value is 0 and DPL value is 1,I think the
RPL class s higher than DPL,the code segment can run,but when
I run the program,my PC always restart,why ?who could tell how
to correct?
Code: Select all
;JUMP Macro
jump macro selector,offsetv
db 0eah ;Opcode:JMP
dw offsetv
dw selector
endm
;segment descriptor
descriptor struc
limitl dw 0
basel dw 0
basem db 0
attributes dw 0
baseh db 0
descriptor ends
;
pdesc struc
limit dw 0
base dd 0
pdesc ends
;Constant
atce = 0B8h ;To DPL to 1
;
.386P
;--------------------------------------------------------
;GDT
dseg segment use16
gdt label byte
dummy descriptor <>
code descriptor <0ffffh,,,atce,>
code_sel =code-gdt ;Set RPL to 0
gdtlen =$-gdt
;
vgdtr pdesc <gdtlen-1,>
;
dseg ends
;-------------------------------------------------------------
cseg segment use16 ;
assume cs:cseg, ds:dseg
start:
mov ax,dseg
mov ds,ax
;set gdtr
mov bx,16
mul bx
add ax,offset gdt
adc dx,0
mov word ptr vgdtr.base,ax
mov word ptr vgdtr.base+2,dx
;
mov ax,cs
mul bx
mov code.basel,ax
mov code.basem,dl
mov code.baseh,dh
;Load GDTR
lgdt fword ptr vgdtr
;
cli
;
mov eax,cr0
or eax,1
mov cr0,eax
;
jump <code_sel>,<offset virtual>
;
virtual: ;P-Mode
mov ah,48h ;I write one instruct optionally
;
mov eax,cr0
and eax,0fffffffeh
mov cr0,eax
;
jump <seg real>,<offset real>
;
real: ;R-Mode
sti
mov ax,4c00h
int 21h
;
cseg ends
end start