+ -
当前位置:首页 → 问答吧 → 为什么在切换实模式和保护模式时会死机

为什么在切换实模式和保护模式时会死机

时间:2010-11-25

来源:互联网

jump16 macro selector,offsetv
  db 0eah ;jmp 
  dw offsetv ;2 bytes offset address
  dw selector  
  endm

jump32 macro selector,offsetv
  db 0eah  
  dd offsetv ;4 bytes offset address
  dw selector  
  endm

;
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

  .386P
;---------------------------------
dseg segment use16  
gdt label byte  
dummy descriptor <>  
code32_sel = 08h  
code32 descriptor <0ffffh,,,4098h,>
gdtlen = $-gdt
;
vgdtr pdesc <gdtlen-1,>  
dseg ends

;----------------------
;
cseg1 segment use16  
  assume cs:cseg1, ds:dseg
start:  
  mov ax,dseg
  mov ds,ax
  ;
  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,cseg2  
  mul bx
  mov code32.basel,ax  
  mov code32.basem,dl  
  mov code32.baseh,dh
  ;
  lgdt fword ptr vgdtr  
  ;
  cli  
  call ea20  
  ;
  mov eax,cr0
  or eax,1
  mov cr0,eax
  ;进入保护模式
  jump16 <code32_sel>,<offset spm32> 
  ;
toreal:  
  call da20  
  sti
  mov ah,4ch
  int 21h  
  ;
;
ea20 proc
  push ax
  in al,92h
  or al,2
  out 92h,al
  pop ax
  ret
ea20 endp
;
;
da20 proc
  push ax
  in al,92h
  and al,0fdh ;0fdh=not 20h
  out 92h,al
  pop ax
  ret
da20 endp
cseg1 ends
;---------------------------------
cseg2 segment use32  
  assume cs:cseg2
   
spm32:  
  mov eax,cr0
  and eax,0fffffffeh
  mov cr0,eax
  ;回到实模式
jump32 <seg toreal>,<offset toreal>
  ;

cseg2 ends
;--------------------------
  end start 
我的程序很简单,就是从实模式进入32位的保护模式,然后就返回到实模式,可是运行时会死机(我是用TASM编译的,
不知道为什么用masm5.1编译老是通不过),请问错在哪?如何改?

作者: leetow2003   发布时间: 2010-11-25

我也卡在这里很久啦,。。。唉。。。。

作者: masmaster   发布时间: 2010-11-25

也找不到资料,怎么解决呀

作者: leetow2003   发布时间: 2010-11-25