ret value of bfd_get_sign_extend_vma

Dave Korn dk@artimi.com
Mon Jun 21 16:36:00 GMT 2004


> -----Original Message-----
> From: binutils-owner On Behalf Of Michael Mueller
> Sent: 21 June 2004 16:35

> Can someone explain to me what the return value of function 
> bfd_get_sign_extend_vma means? What the docu says is a mystery to me:
> 
> "Indicates if the target architecture "naturally" sign extends an 
> address. Some architectures implicitly sign extend address 
> values when 
> they are converted to types larger than the size of an address. For 
> instance, bfd_get_start_address() will return an address sign 
> extended 
> to fill a bfd_vma when this is the case."
> 
> How can an address have a sign? I think of an address as an unsigned 
> quantity.

  Some systems that have a 32-bit address space also have 16-bit addressing
modes.  For instance m68k: if you wanted to load data register d0 from
memory address 4, you can write

     move.l    d0,$4

which generates an instruction with a 32-bit address field containing the
value 4, or you can write.

     move.l    d0,$4.w

which generates an instruction with only 16-bits in the address field.

  Naturally enough, a 16-bit address field isn't sufficient to address the
entire 32-bit address range.  Effectively it allows you access to 64k of
locations.  The only question is, which 64k of locations.

  On some systems, the full 32-bit address is generated by sticking 16 zeros
on the front of the 16-bit field.  So you can address ranges 0x00000000 to
0x0000ffff by using 16-bit addresses 0x0000 to 0xffff.

  But on other systems, and m68k is one, the cpu duplicates the topmost bit
of the 16-bit field into the upper (missing from the instruction) 16 address
bits.  So on these systems, 16-bit addresses 0x0000 to 0x7fff address 32-bit
range 0x00000000 to 0x00007fff, and 16-bit addresses 0x8000 to 0xffff
address 32-bit range 0xffff8000 to 0xffffffff.

  That is to say, on some systems the reduced addressing mode allows you to
access the lowest 64kb block at the bottom of memory; on others it allows
you to access both the lowest 32kb and the highest 32kb of the 32-bit range.

  So yes, addresses are basically unsigned; but the behaviour here is the
same as takes place in sign extension, and it's a reasonable analogy if you
think of negative addresses as referring to the top end of the memory map.


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Binutils mailing list