This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is this correct ?


> > Using one ldr instruction should get to the value of prev_limit,
> > why does it take a sequence of two ldr instructions ? See below
> 
> >     80d4:       e59f3044        ldr     r3, [pc, #44]   ; 8120
> >     80dc:       e5933000        ldr     r3, [r3]
> 
> The reason is that 'prev_limit' is a static variable, not a local
> variable.  Therefore it will be stored in the .data section and not on
> the stack.  Since the compiler does not know where the .data section
> will be located in memory it cannot just use a pc-relative load to get
> the value.

Nearly, but not quite.

On the ARM, the pc-relative load is limited to a range of +/- 4Kbytes from 
the current address.  Since we cannot guarantee that the local variable 
will be in that range (in fact we can virtually guarantee that it won't -- 
most of that range will be code not data) we must use a pc-relative load 
to get the address of the variable and then load its value using that.

>  Instead the address of 'prev_limit' has to be stored in a
> word at the end of the get_request() function, and then two LDRs are
> used to load the value.  The first LDR loads the address of
> 'prev_limit' from the word at the end of the function.  The second LDR
> loads the contents of this address into R3.

R.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]