From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12789 invoked by alias); 16 Aug 2007 00:20:27 -0000 Received: (qmail 12754 invoked by uid 22791); 16 Aug 2007 00:20:27 -0000 X-Spam-Check-By: sourceware.org Received: from wa-out-1112.google.com (HELO wa-out-1112.google.com) (209.85.146.177) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 16 Aug 2007 00:20:25 +0000 Received: by wa-out-1112.google.com with SMTP id l35so88534waf for ; Wed, 15 Aug 2007 17:20:23 -0700 (PDT) Received: by 10.114.14.1 with SMTP id 1mr1184656wan.1187223623257; Wed, 15 Aug 2007 17:20:23 -0700 (PDT) Received: by 10.115.18.10 with HTTP; Wed, 15 Aug 2007 17:20:23 -0700 (PDT) Message-ID: Date: Thu, 16 Aug 2007 00:20:00 -0000 From: "Marius Nita" To: gdb@sourceware.org Subject: a question MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2007-08/txt/msg00130.txt.bz2 Hi, I am trying to understand some endian-specific code in GDB (well, BFD for the purpose of this message). I would greatly appreciate any help. I have a rather specific question regarding the code below, which is in bfd/aout-arm.c line 420. This code seems to deal with bit-level endianness. E.g. a "char" address holding a bit pattern 00010000 represents 0x10 on one endianness and 0x08 on the other. The r_length left-shift below shifts data by 5 bits on big-endian and 1 bit on little-endian. The r_length data will end up occupying 2 bits in the natptr->r_type[0] byte. On big-endian, they'll be bits 6 and 7, and on little-endian, they are bits 2 and 3. My question is: why aren't the bits in r_length "reversed" to conform with bit-level endianness? For example, if the r_length bits are "10", this left-shift results in "0100 0000" on big-endian and "0000 0100" on little-endian. These bit strings are clearly not the reverse of each other. Any help would be much appreciated! Thank you! -m if (bfd_header_big_endian (abfd)) { natptr->r_index[0] = r_index >> 16; natptr->r_index[1] = r_index >> 8; natptr->r_index[2] = r_index; natptr->r_type[0] = ( (r_extern ? RELOC_STD_BITS_EXTERN_BIG: 0) | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG: 0) | (r_neg ? RELOC_ARM_BITS_NEG_BIG: 0) | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG)); } else { natptr->r_index[2] = r_index >> 16; natptr->r_index[1] = r_index >> 8; natptr->r_index[0] = r_index; natptr->r_type[0] = ( (r_extern ? RELOC_STD_BITS_EXTERN_LITTLE: 0) | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE: 0) | (r_neg ? RELOC_ARM_BITS_NEG_LITTLE: 0) | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE)); }