I am trying to write a bootloader by myself, but qemu-system-i386 CPU will reset probabilistically. But bochs does not have this problem. Why?
my code is mbr.s and loader.s:
# cat mbr.s
%include "boot.inc"
SECTION MBR vstart=0x7c00
...
call rd_disk_m_16 ; rd_disk_m_16 is ok
jmp LOADER_BASE_ADDR
...
db 0x55,0xaa
# cat loader.s
%include "boot.inc"
section loader vstart=LOADER_BASE_ADDR
LOADER_STACK_TOP equ LOADER_BASE_ADDR
jmp loader_start
...
loader_start:
cli
lgdt [gdt_ptr]
mov eax, cr0
or eax, 0x00000001
mov cr0, eax
jmp 0x08:p_mode_start
[bits 32]
p_mode_start:
jmp $
My step:
# bximage -func=create -hd=16M -imgmode="flat" -sectsize=512 -q hd.img
# nasm -I include/ -o mbr.bin mbr.s && dd if=mbr.bin of=./hd.img bs=512 count=1 conv=notrunc
# nasm -I include/ -o loader.bin loader.s && dd if=loader.bin of=./hd.img bs=512 count=4 seek=2 conv=notrunc
# qemu-system-i386 -hda hd.img -d cpu_reset,int -no-reboot