This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
objcopy, ld and jumps
- From: Stefan Reinauer <stefan dot reinauer at coresystems dot de>
- To: binutils at sourceware dot org
- Date: Fri, 02 Feb 2007 09:37:00 +0100
- Subject: objcopy, ld and jumps
Dear binutils developers,
we're in the progress of building a new major version of LinuxBIOS, and
I want to take the chance to get rid of some bad habits in the code.
Well, the first thing that is required is the reset vector. It's 16
bytes at 0xfffffff0 (aliased to f000:fff0 in real mode). It jumps into
the real code which is placed at 0xffffe000 (0xe000 in the current segment).
--------- 8< reset.s --------------------------
SEGMENT_SIZE = 0x10000
RVECTOR = 0x00010
.code16
.globl _start
_start:
jmp SEGMENT_SIZE-(0x1f00 +0xf0 +RVECTOR)
.byte 0
.ascii "2007/02/01"
.word 0
----------------- 8< --------------------------
I build it with:
as reset.s -o reset.o
and link it:
ld -Ttext 0xfffffff0 reset.o -o reset.elf
objcopy -O binary -S reset.elf reset.bin
Now I disassemble it:
ndisasm -o 0xfffffff0 reset.bin | head -1
FFFFFFF0 E9FEDF jmp 0xdff1
Oops. It is obviously wrong. But why?
Alternatively I omit the objcopy step but I basically do the same (do I?):
ld -Ttext 0xfffffff0 -s --oformat binary reset.o -o reset.bin
ndisasm -o 0xfffffff0 reset.bin | head -1
FFFFFFF0 E90DE0 jmp 0xe000
Phew. It works here. But why? What's the difference?
We don't really want to use the second version, because the intermediate
elf binary is nice to dump a symbal table using nm -e reset.elf. People
are sometimes heavily relying on this:
0000000000000010 a RVECTOR
0000000000010000 a SEGMENT_SIZE
00000000fffffff0 T _start
Is this a binutils bug, or a problem between chair and keyboard?
Stefan
--
coresystems GmbH â Brahmsstr. 16 â D-79104 Freiburg i. Br.
Tel.: +49 761 7668825 â Fax: +49 761 7664613
Email: info@coresystems.de â http://www.coresystems.de/