12.07.2015 Views

The ARM-THUMB Procedure Call Standard

The ARM-THUMB Procedure Call Standard

The ARM-THUMB Procedure Call Standard

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>The</strong> <strong>ARM</strong>-<strong>THUMB</strong> <strong>Procedure</strong> <strong>Call</strong> <strong>Standard</strong>5.5 Shared librariesA shared library is a re-entrant program to which other programs may link at execution time. In general, both thelibrary and its client have read-write (RW) segments and the process of linking to a shared library creates a copyof the library’s RW segment for its client.Shared libraries are statically linked independently of one another and independently of their clients. As a result,different values of SB are needed to address the separately linked RW segments in a program that uses one ormore shared libraries. A new value of SB— or a local SB value— must be established when control passes from:oo<strong>The</strong> code of the client to the code of a library.<strong>The</strong> code of a library to the code of a different libraryOn returning, the value of SB must be as it was prior to the call.In the shared-library variant of the ATPCS, a new SB value is established after entry to a shared-library routinethat needs to use SB. <strong>The</strong> new value need not be established until it is needed and a routine that makes no use ofSB need not establish a new value. Formally:Pre: VAL(SB) = address of any static data segment{called routine}<strong>The</strong> post-condition VAL(SB) = PRE(SB) is guaranteed by the base standard.5.6 <strong>The</strong> shared-library data-addressing architecture<strong>The</strong> shared-library data addressing architecture extends the RWPI data addressing architecture (see section5.3.1, Position-independent data addressing):ooEach shared library has a unique identity represented by a small integer (the library index) bound into thelibrary code. A library index may be relocated when a library is loaded into RAM, or it may be bound statically.A library’s index is the same in every process threading it.Each (per-process) static data segment begins with a table of four pointers into a process data table. <strong>The</strong>ypoint to entries 0, 32, 64, and 96 of the process data table, respectively.o <strong>The</strong> N th entry in a process data table points to the start of the static data segment for library N.In <strong>ARM</strong>-state, a routine can locate its static data using the code sequence:LDR SB, [SB, #0]LDR SB, [SB, #my_index]; my_index may be relocated<strong>The</strong> base standard guarantees that SB is restored on exit from the subroutine.In Thumb-state, SB is a high register that cannot be used directly so a subroutine can locate its static data using:MOV LSB, SB ; LSB any low registerLDR LSB, [LSB, #my_segment] ; 0, 1, 2, or 3 ...LDR LSB, [LSB, #my_index ; ... and my_index may be relocatedA Thumb-state subroutine does not alter SB so it does not need to restore it.NoteNote<strong>The</strong>se code sequences do not need to be inline in their using routines. Each can be replaced by a call toa special (non-ATPCS-conforming) leaf routine, saving some space and reducing the number oflocations dependent on the library index, but costing some execution time.In <strong>ARM</strong>-state, every non-leaf routine and every static-data-using leaf routine bears the cost of SB’s fixedrole by losing a v-register (but non-static-data-using leaf routines may use v6). In Thumb-state, the localstatic base (LSB) is only needed in static-data-using routines where common sub-expression eliminationand register allocation can be applied to it together with user variables.SWS ESPC 0002 A-05 Page 18 of 37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!