I’m starting qemu-system-i386 with, for example, the MirBSD CD-ROM.
Then I attach gdb to qemu (started with -s -S), set a breakpoint at
the beginning of the bootsector, continue and disassemble.
(gdb) b *0x7c00
Breakpoint 1 at 0x7c00
(gdb) c
Continuing.
But it disassembles wrong:
(gdb) x/14i 0x7c00
=> 0x7c00: xor cx,cx
0x7c03: mov ss,ecx
0x7c05: mov esp,0x51667bfc
0x7c0a: popfw
0x7c0c: mov es,ecx
0x7c0e: mov edi,0xb1577c00
[…]
(gdb) x/14xb 0x7c00
0x7c00: 0x66 0x31 0xc9 0x8e 0xd1 0xbc 0xfc 0x7b
0x7c08: 0x66 0x51 0x66 0x9d 0x8e 0xc1
(gdb) show architecture
The target architecture is assumed to be i8086
The correct disassembly is:
66 31 C9 XOR ECX,ECX
8E D1 MOV SS,CX
BC FC 7B MOV SP,7BFCh
66 51 PUSH ECX
66 9D POPFD
8E C1 MOV ES,CX
Putting this code snippet into “objdump -d -Mintel,i8086” gets
it almost right (except for the popfd, which nasm also gets
wrong at least when assembling):
0: 66 31 c9 xor ecx,ecx
3: 8e d1 mov ss,cx
5: bc fc 7b mov sp,0x7bfc
8: 66 51 push ecx
a: 66 9d popf
c: 8e c1 mov es,cx
ndisasm *does* get it right:
00000000 6631C9 xor ecx,ecx
00000003 8ED1 mov ss,cx
00000005 BCFC7B mov sp,0x7bfc
00000008 6651 push ecx
0000000A 669D popfd
0000000C 8EC1 mov es,cx