qemu exit unexpectedly when I set PE and mov cr0, ax to enable the protected mode

91 Views Asked by At
    ; ---------- GDT ----------
GDT_BASE:
    dd 0x00000000
    dd 0x00000000
CODE_DESC:
    dd 0x0000ffff
    dd DESK_CODE_HIGH4
DATA_STACK_DECK:
    dd 0x0000ffff
    dd DESK_DATA_HIGH4
VIDEO_DESC:
    dd 0x80000007
    dd DESK_VIDEO_HIGH4
GDT_SIZE equ $ - GDT_BASE
GDT_LIMIT equ GDT_SIZE - 1

times 60 dq 0 ; 

; ---------- selector ----------
SELECTOR_CODE equ (0x0001 << 3) + TI_GDT + RPL0
SELECTOR_DATA equ (0x0002 << 3) + TI_GDT + RPL0 
SELECTOR_VIDEO equ (0x0003 << 3) + TI_GDT + RPL0

total_mem_bytes dd 0 ; 4

gdt_ptr: ; 6
    dw GDT_LIMIT
    dd GDT_BASE

; 4 + 6 + 232 + 2 + 12 = 256 bytes 
ards_buf times 232 db 0
ards_nr dw 0

loader_msg db "REAL LOADER."
msg_length equ $ - loader_msg
loader_start:


;   ------ open A20 ------
    in al, 0x92
    or al, 0x02 ; 0000_0010B
    out 0x92, al

 ; ------ load GDT ------
    lgdt [gdt_ptr]



    mov eax, cr0
    or eax, 0x1
    jmp $            ;        when I remove this, qemu will quit unexpectedly
    mov cr0, eax
    jmp $

image description

This code works perfectly in bochs,
but when I run it using qemu:

qemu-i386 -m 32 -drive file=../qemu/myimg.img,format=raw,index=0 -d int -no-reboot

it will quit unexpectedly.

This code works perfectly in bochs.
Is there any difference between bochs and qemu-system-i386?
Or do I do something wrong?

0

There are 0 best solutions below