objcopy -O binary only outputting 16 bit data

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
bradbobak
Member
Member
Posts: 26
Joined: Fri Apr 14, 2006 11:00 pm

objcopy -O binary only outputting 16 bit data

Post by bradbobak »

So, here is my c_test.c

Code: Select all

void entry()
{
  unsigned *p = (unsigned *)(0xb8000 + 160);

  p[0] = 0x0f42;
}
Now i compile and link

Code: Select all

gcc -nostdlib -m32 -c -o c_test.o c_test.c
ld -Ttext 0x8000 -melf_i386 -o boot.bin1 c_test.o
Doing an 'objdump -d boot.bin1' results in

Code: Select all

00008000 <entry>:
    8000:       55                      push   %ebp
    8001:       89 e5                   mov    %esp,%ebp
    8003:       83 ec 10                sub    $0x10,%esp
    8006:       c7 45 fc a0 80 0b 00    movl   $0xb80a0,-0x4(%ebp)
    800d:       8b 45 fc                mov    -0x4(%ebp),%eax
    8010:       c7 00 42 0f 00 00       movl   $0xf42,(%eax)
    8016:       c9                      leave  
    8017:       c3                      ret    
Note 8006: its using the 32-bit value 0xb80a0.

Next, I 'objcopy -O binary boot.bin1 boot.bin

Next, a 'ndisasm boot.bin' results in

Code: Select all

00000000  55                push bp
00000001  89E5              mov bp,sp
00000003  83EC10            sub sp,byte +0x10
00000006  C745FCA080        mov word [di-0x4],0x80a0
0000000B  0B00              or ax,[bx+si]
0000000D  8B45FC            mov ax,[di-0x4]
00000010  C700420F          mov word [bx+si],0xf42
00000014  0000              add [bx+si],al
00000016  C9                leave
00000017  C3                ret
Now, at offset 6, its only moving the 16-bit value 0x80a0, removing the 0x000b that should be in front of it.

Anyone have an idea why objcopy is using only a 16-bit value when transforming boot.bin1 to boot.bin?
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: objcopy -O binary only outputting 16 bit data

Post by xenos »

Seriously?

Code: Select all

00000006  C745FCA080        mov word [di-0x4],0x80a0
0000000B  0B00              or ax,[bx+si]
Everything is there, but your disassembler is obviously set to interpret the instructions as if they were executed in 16 bit mode.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
bradbobak
Member
Member
Posts: 26
Joined: Fri Apr 14, 2006 11:00 pm

Re: objcopy -O binary only outputting 16 bit data

Post by bradbobak »

Hmff.. Didn't even realize that. Thank you.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: objcopy -O binary only outputting 16 bit data

Post by alexfru »

See ndisasm's options, you want '-b 32'.
Post Reply