0
    ; ---------- 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?

zx485
  • 28,498
  • 28
  • 50
  • 59
  • 6
    There are differences between BOCHS and QEMU in that QEMU is generally more permissive to improve speed. That being said you really need to give us a minimally complete verifiable example or this may difficult to trouble shoot. As an example because this isn't a [mcve] we don't know how you define `DESK_DATA_HIGH4` etc. You should supply a complete set of minimal code so that someone can try to reproduce the issue. This is almost certainly a bug in your code. – Michael Petch Jul 08 '23 at 10:19
  • Also, what do you mean by "quit unexpectedly" ? Does QEMU just exit with a 0 exit status? Does it crash? Does it hit an assertion failure? Is there an error message? – Peter Maydell Jul 10 '23 at 10:17
  • Oh, and qemu-i386 is the "run a single Linux binary" executable, so that command line can't work -- it will complain about syntax errors, I expect. You need qemu-system-i386 (or qemu-system-x86_64 for a 64-bit capable CPU). – Peter Maydell Jul 10 '23 at 10:19

0 Answers0