Page 1 of 1

decode error, please help. Thanks.

Posted: Tue Jan 13, 2009 8:58 pm
by horryjing
I'm learning linux0.11, write some code followed book. Now my codes have enterd protect mode, jump to main() function correctly, but I met a problem when bochs decode instructions of main() .
Many thanks in advance!

For example:
Below is a objdump code
b8 00 00 00 00 mov $0x0,%eax
on bochs become below two instructions
[0x00007e09] 0000:0000000000007e09 (unk. ctxt): mov ax, 0x0000 ;b80000
[0x00007e0c] 0000:0000000000007e0c (unk. ctxt): add byte ptr ds:[bx+si], al; 0000
Why?

This is my main function:
void main(void)
{
unsigned int mem_size;
mem_size = 1<<20 + *((unsigned short*)0x6c00);
}

objdump result:
main.o: file format elf32-i386

Disassembly of section .text:

00000000 <main>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 08 sub $0x8,%esp
6: 83 e4 f0 and $0xfffffff0,%esp
9: b8 00 00 00 00 mov $0x0,%eax
e: 83 c0 0f add $0xf,%eax
11: 83 c0 0f add $0xf,%eax
14: c1 e8 04 shr $0x4,%eax
17: c1 e0 04 shl $0x4,%eax
1a: 29 c4 sub %eax,%esp
1c: 0f b7 05 00 6c 00 00 movzwl 0x6c00,%eax
23: 8d 48 14 lea 0x14(%eax),%ecx
26: b8 01 00 00 00 mov $0x1,%eax
2b: d3 e0 shl %cl,%eax
2d: 89 45 fc mov %eax,-0x4(%ebp)
30: c9 leave
31: c3 ret

on bochs:
[0x00007e00] 0000:0000000000007e00 (unk. ctxt): push bp ;55
[0x00007e01] 0000:0000000000007e01 (unk. ctxt): mov bp, sp ;89e5
[0x00007e03] 0000:0000000000007e03 (unk. ctxt): sub sp, 0x0008 ;83ec08
[0x00007e06] 0000:0000000000007e06 (unk. ctxt): and sp, 0xfff0 ;83e4f0
[0x00007e09] 0000:0000000000007e09 (unk. ctxt): mov ax, 0x0000 ;b80000
[0x00007e0c] 0000:0000000000007e0c (unk. ctxt): add byte ptr ds:[bx+si], al; 0000
[0x00007e0e] 0000:0000000000007e0e (unk. ctxt): add ax, 0x000f ;83c00f
[0x00007e11] 0000:0000000000007e11 (unk. ctxt): add ax, 0x000f ;83c00f
[0x00007e14] 0000:0000000000007e14 (unk. ctxt): shr ax, 0x04 ;c1e804
[0x00007e17] 0000:0000000000007e17 (unk. ctxt): shl ax, 0x04 ;c1e004
[0x00007e1a] 0000:0000000000007e1a (unk. ctxt): sub sp, ax ;29c4
[0x00007e1c] 0000:0000000000007e1c (unk. ctxt): mov ax, word ptr ds:[di] ;0fb705
[0x00007e1f] 0000:0000000000007e1f (unk. ctxt): add byte ptr ds:[si], ch ;006c00
[0x00007e22] 0000:0000000000007e22 (unk. ctxt): add byte ptr ds:[di+0x1448], cl ; 008d4814
[0x00007e26] 0000:0000000000007e26 (unk. ctxt): mov ax, 0x0001 ;b80100
[0x00007e29] 0000:0000000000007e29 (unk. ctxt): add byte ptr ds:[bx+si], al; 0000
[0x00007e2b] 0000:0000000000007e2b (unk. ctxt): shl ax, cl ;d3e0
[0x00007e2d] 0000:0000000000007e2d (unk. ctxt): mov word ptr ds:[di+0xfffc], ax ; 8945fc
[0x00007e30] 0000:0000000000007e30 (unk. ctxt): leave ;c9
[0x00007e31] 0000:0000000000007e31 (unk. ctxt): ret ;c3

Re: decode error, please help. Thanks.

Posted: Tue Jan 13, 2009 9:23 pm
by 01000101
try doing "disassemble size = 32" in the bochs debugger before debugging 32-bit code

Re: decode error, please help. Thanks.

Posted: Wed Jan 14, 2009 10:20 am
by stlw
Bochs disassembly defaults are according to current CPU execution mode. Your CPU is probably in 16-bit real mode and you trying to run 32-bit code.

Stanislav

Re: decode error, please help. Thanks.

Posted: Fri Jan 23, 2009 10:30 pm
by horryjing
Look like that is ok now.
I didn't set the CS when enter to protect mode.