[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Relocation types in AVR GAS

From: Boyapati, Anitha
Subject: RE: [avr-gcc-list] Relocation types in AVR GAS
Date: Wed, 23 Mar 2011 14:08:50 +0800

>> I am trying to understand relocation types in AVR. To start with,
>> can someone illustrate how R_AVR_16 works in the following case?
>I can only guess.  Don't know whether there's someone with more

Yea...I was hoping if someone who ported binutils to AVR is also here. But I 
guess I am quite happy to continue the conversation. It would help me think 

>> As I see it, since the address is 16-bit, 'size' is 1. How do we arrive
>> at 'rightshift' and 'bitsize' entries?
>No idea what rightshift is doing, you might get an idea by comparing
>against other relocation types.

Actually the confusion started with the comparisions :-(

Hence I started with a simple relocation. Somewhere in the source code, it is 
commented that instruction relocation requires a right shift.

>bitsize should be clear: it's a 16-bit relocation.  My guess is that

Yeah. 16 bits need to be relocated in this case. Usually all lds/sts require 
this. [Similarly for R_AVR_7_PCREL and R_AVR_13_PCREL, 7 and 13 bits of the 
'16-bit' instruction need to be relocated. These are issued by branch and rjmp 

However, this is a little abstract to me. How exactly we are going to construct 
the final address? I'll start with R_AVR_16 type in the given example. 
Assembler stores 0x0 in all the lds/sts instructions (disassembly given in the 
end) and emits the corresponding relocation type. This forms the input to 

How linker is going to construct the final address of variable 'i'? I know some 
theory that we are going shift, add, .... such things. I believe 'HOWTO' comes 
into picture then, giving the linker a formula to construct the final address. 
It would be good to know how exactly this happens.

>> And how assembler knows to emit
>> R_AVR_16 type?
>Probably from the instruction it is connected with.  Obviously,
>R_AVR_16 only applies to instructions like STS/LDS etc.

Some generous person in gcc chat pointed out to me fix_new_exp(...) in 
avr_operand() of gas/tc-avr.c. I guess I have too many questions.


long i;

int main()
        return i++;


#Disassembly of section .text:

00000000 <main>:
   0:   df 93           push    r29
   2:   cf 93           push    r28
   4:   cd b7           in      r28, 0x3d       ; 61
   6:   de b7           in      r29, 0x3e       ; 62
   8:   80 91 00 00     lds     r24, 0x0000
   c:   90 91 00 00     lds     r25, 0x0000
  10:   a0 91 00 00     lds     r26, 0x0000
  14:   b0 91 00 00     lds     r27, 0x0000
  18:   9c 01           movw    r18, r24
  1a:   01 96           adiw    r24, 0x01       ; 1
  1c:   a1 1d           adc     r26, r1
  1e:   b1 1d           adc     r27, r1
  20:   80 93 00 00     sts     0x0000, r24
  24:   90 93 00 00     sts     0x0000, r25
  28:   a0 93 00 00     sts     0x0000, r26
  2c:   b0 93 00 00     sts     0x0000, r27
  30:   c9 01           movw    r24, r18
  32:   cf 91           pop     r28
  34:   df 91           pop     r29
  36:   08 95           ret


reply via email to

[Prev in Thread] Current Thread [Next in Thread]