Switching to protected mode from DOS not using DPMI

一个人想着一个人 提交于 2019-12-11 05:19:40

问题


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

Here's my code

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'

回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/54679254/switching-to-protected-mode-from-dos-not-using-dpmi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!