不使用DPMI从DOS切换到保护模式 [英] Switching to protected mode from DOS not using DPMI

查看:146
本文介绍了不使用DPMI从DOS切换到保护模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习了x86-16组装,我想学习x86-32组装. 我做了一个简单的32位程序,但是此代码不起作用 当程序进行远程跳转时,控制台将显示"JMP非法描述符0" 我使用fasm和DOS 请告诉我我做的不好

I learned x86-16 assembly and i want to learn to x86-32 assembly. I maked a simple 32-bit program but this code not work When program makes a far jump console displays 'JMP illegal descriptor 0' I use fasm and DOS Please show me what i'm doing bad

这是我的代码

format MZ

push cs
pop ds
mov eax,cs
shl eax,4
mov [AdresSegmentuProgramu_32],eax ;Calculating real mode segment
add eax,gdt_table
mov [gdtr+2],eax
use32
lgdt [gdtr]


mov eax,[AdresSegmentuProgramu_32]
add eax,pmode_entry
mov [AdresSegmentu_PMODE_entry],eax

mov eax,cr0
or eax,1    ;Switch to PMODE
mov cr0,eax

mov eax,[AdresSegmentu_PMODE_entry] ;Far jump to reset CS and jump to simple code
mov [far_jump],eax


jmp far [ds:far_jump]

far_jump:
dd 0
dw 08h ; Selector 0x08

gdtr: dw 128
dd 0


AdresSegmentuProgramu_32 dd 0
AdresSegmentu_PMODE_entry dd 0

use32

gdt_table:
dq 0
code_descriptor:
dw 0ffffh
dw 0
db 0
db 09ah
db 11001111b
db 0
data_descriptor:
dw 0ffffh
dw 0
db 0
db 092h
db 11001111b
db 0

dq 0
dq 0

pmode_entry:

mov esi,0b8000h
mov byte [esi],'a'

推荐答案

设置PE(CR0的位0)后,处理器将以16位保护模式运行.跳到32位代码段是导致处理器开始以32位模式执行的步骤.因此,此代码中的远跳转指令以16位模式执行,并且默认情况下使用16位操作数.

After setting PE (bit 0 of CR0), the processor is running in 16-bit protected mode. The far jump to a 32-bit code segment is the step that causes the processor to start executing in 32-bit mode. Thus the far jump instruction in this code is executed in 16-bit mode, and uses a 16-bit operand by default.

按照迈克尔的建议,将fword属性应用于指令操作数会导致汇编器在远跳转指令上放置操作数大小前缀,从而将该指令的操作数大小更改为32位.

Applying the fword attribute to the instruction operand, as Michael advised, causes the assembler to put an operand size prefix on the far jump instruction, changing the operand size for that instruction to 32 bits.

另一种选择是将far_jump标签上的dd更改为dw并继续使用16位远跳转指令,但前提是您知道32位入口点位于第一个64k的内存.由于BIOS在7c00加载引导扇区,因此通常是这样.

Another alternative is to change the dd at the far_jump label to dw and continue to use a 16-bit far jump instruction, but only if you know that the 32-bit entry point is within the first 64k of memory. Since the BIOS loads the boot sector at 7c00, this is typically true.

这篇关于不使用DPMI从DOS切换到保护模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆