回 帖 发 新 帖 刷新版面

主题:会保护模式的高手请进

S_DESC STRUC
Limit_L dw 0
BaseL dw 0
BaseM db 0
Attribute db 0
LimitH db 0
BaseH db 0
S_DESC ENDS

PDesc STRUC
Limit dw 0
Base dd 0
PDesc ENDS




;.386P
R_CODE SEGMENT USE16 'CODE'
 ASSUME CS:R_CODE,DS:R_CODE
 START:
 jmp begin
 GDT LABEL BYTE
 DUMMY S_DESC < >
 Code  S_DESC <0ffffh,,,98h,00h,>
 Video S_DESC <0ffffh,8000h,0bh,0f2h,00h,00h>
 CodeSel equ Code-GDT
 VideoSel equ Video-GDT
 GDTLen equ $-GDT
 VGDTR PDesc <GDTLen-1,>
 
  begin:
     xor eax,eax
     mov ax,cs
     mov ds,ax
     shl eax,4
     mov ecx,offset start
     add eax,ecx
     mov word ptr Code.BaseL,ax
     shr eax,16
     mov byte ptr Code.BaseM,al
     mov byte ptr Code.BaseH,ah
     xor eax,eax
     mov ax,ds
     shl eax,4
     mov ecx,offset GDT
     add eax,ecx
     mov dword ptr VGDTR.Base,eax
     lgdt  fword ptr ds:VGDTR
     in al,92h
     or al,02h
     out 92h,al
     mov eax,cr0
     or  eax,1
     mov cr0,eax
     db 0eah
     dw  offset prt
     dw 8
     prt:
     jmp $
     R_CODE ENDS
END START
为何在进入保护模式的时候总是不行?出错!!

回复列表 (共7个回复)

沙发

1:.386p不能去掉
2:你的代码只能在DOS下运行,建议你安装一个虚拟机,将你的代码放到DOS下运行。

板凳

我就是在虚拟机上运行的,装的ms-dos 7.1  ,总出现错误EMM:386 Untecoverable  privileged operation error#n9

3 楼

;----------------------------------------
; 说明:
; (1) 请编绎成.COM文件
; (2) 在DOS 7.1下运行通过
; (3) 该程序是在楼主基础上所作的修改(尽量少改动)
;----------------------------------------
.386P
R_CODE SEGMENT USE16
    org    100h
    ASSUME CS:R_CODE,DS:R_CODE

START:
      jmp begin


    S_DESC    STRUC
    Limit_L   dw 0
    BaseL     dw 0
    BaseM     db 0
    Attribute db 0
    LimitH    db 0
    BaseH     db 0
    S_DESC    ENDS

    PDesc     STRUC
    Limit     dw 0
    Base      dd 0
    PDesc     ENDS

    GDT      LABEL  BYTE
    DUMMY    S_DESC < >
    Code     S_DESC <0ffffh,,,98h,00h,>
    Video    S_DESC <0ffffh,8000h,0bh,0f2h,00h,00h>
    
    CodeSel  equ    Code-GDT
    VideoSel equ    Video-GDT
    GDTLen   equ    $-GDT

    VGDTR    PDesc  <GDTLen-1,>
 
begin:
     xor eax,eax
     mov ax,cs
     mov ds,ax

     shl eax,4
     mov ecx,offset R_CODE
     add eax,ecx
     mov word ptr Code.BaseL,ax
     shr eax,16
     mov byte ptr Code.BaseM,al
     mov byte ptr Code.BaseH,ah

     xor eax,eax
     mov ax,ds
     shl eax,4
     mov ecx,offset GDT
     add eax,ecx
     mov dword ptr VGDTR.Base,eax

     lgdt  fword ptr ds:VGDTR

     cli

     in al,92h
     or al,02h
     out 92h,al

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

     db 0eah
     dw prt
     dw CodeSel
prt:
     jmp $

R_CODE ENDS
    END START

4 楼

MSDOS7.1应该是在保护模式下了把~
去www.aogosoft.com论坛下个引导程序,搜索的关键词:"引导程序"(是在论坛帖子的附件,而不是下载专区).在这个引导程序的基础上添加你的代码,再不行的话在说--至少我看不出你的程序有什么问题。

5 楼

;----------------------------------------
; 上面3楼程序的一个例子:
;
; (1) 请编绎成.COM文件(EXE文件应该也没问题)
; (2) 在DOS下运行
; (3) 运行结果是在屏幕的左上角显示一个
;     红色的"P"和一个绿"M"
;----------------------------------------
.386P
R_CODE SEGMENT USE16
    org    100h
    ASSUME CS:R_CODE,DS:R_CODE

START:
      jmp begin


    S_DESC    STRUC
    Limit_L   dw 0
    BaseL     dw 0
    BaseM     db 0
    Attribute db 0
    LimitH    db 0
    BaseH     db 0
    S_DESC    ENDS

    PDesc     STRUC
    Limit     dw 0
    Base      dd 0
    PDesc     ENDS

    GDT       LABEL    BYTE
    DUMMY     S_DESC   < >
    Code      S_DESC   <PM_LEN-1,,,98h,0h,>
    Video     S_DESC   <0ffffh,8000h,0bh,92h,00h,00h>
    
    CodeSel   equ      Code-GDT
    VideoSel  equ      Video-GDT
    GDTLen    equ      $-GDT
 
    VGDTR     PDesc    <GDTLen-1,>
 
begin:
     xor eax,eax
     mov ax,cs
     mov ds,ax

     shl eax,4
     add eax,offset PM
     mov word ptr Code.BaseL,ax
     shr eax,16
     mov byte ptr Code.BaseM,al
     mov byte ptr Code.BaseH,ah

     xor eax,eax
     mov ax,ds
     shl eax,4
     add eax,offset GDT
     mov dword ptr VGDTR.Base,eax

     lgdt  qword ptr VGDTR

     cli

     in al,92h
     or al,02h
     out 92h,al

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

     db 0eah
     dw 0
     dw CodeSel
PM:

        mov    ax, VideoSel
        mov    gs, ax            
    
        mov    edi, 0
        mov    ah, 0Ch    
        mov    al, 'P'
        mov    gs:[edi], ax
        mov    ah, 02h
        mov    al, 'M'
        mov    gs:[edi+2], ax
     jmp $
PM_LEN    equ    $-PM
   
R_CODE ENDS
    END START

6 楼

谢谢大虾们的指教,以后还多关照啊,哈哈

7 楼

[quote]我就是在虚拟机上运行的,装的ms-dos 7.1  ,总出现错误EMM:386 Untecoverable  privileged operation error#n9
[/quote]
哈哈,这句话让我记忆犹新阿,连书上的代码,一字不差的打进去,都是这样,还好是VM虚拟机~~~



勿在浮沙筑高台

我来回复

您尚未登录,请登录后再回复。点此登录或注册