The RPL class is higher than DPL,but codes couldn't run well

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
leetow2003
Member
Member
Posts: 70
Joined: Fri Nov 19, 2010 6:54 pm

The RPL class is higher than DPL,but codes couldn't run well

Post by leetow2003 »

My pogram is very simple,there is only a code segment in GDT,
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
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: The RPL class is higher than DPL,but codes couldn't run

Post by egos »

"seg real" isn't 16-bit code selector. See Intel manuals to have known how to switch to real mode.
If you have seen bad English in my words, tell me what's wrong, please.
leetow2003
Member
Member
Posts: 70
Joined: Fri Nov 19, 2010 6:54 pm

Re: The RPL class is higher than DPL,but codes couldn't run

Post by leetow2003 »

egos wrote:"seg real" isn't 16-bit code selector. See Intel manuals to have known how to switch to real mode.
You mean it must be in p-mode between two segments
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: The RPL class is higher than DPL,but codes couldn't run

Post by egos »

I had wrong. It seemed to me that you use 32-bit code segment.

You cannot jump to code segment with DPL other than CPL directly. To decrease priveleges you should use "retf" instruction. To increase privileges you should use a gate. Some instructions as "mov cr0" can be executed successfully only with CPL=0.
If you have seen bad English in my words, tell me what's wrong, please.
Post Reply