as: MIPS Small Data

1 
1 9.27.4 Controlling the use of small data accesses
1 -------------------------------------------------
1 
1 It often takes several instructions to load the address of a symbol.
1 For example, when 'addr' is a 32-bit symbol, the non-PIC expansion of
1 'dla $4,addr' is usually:
1 
1      lui     $4,%hi(addr)
1      daddiu  $4,$4,%lo(addr)
1 
11    The sequence is much longer when 'addr' is a 64-bit symbol.  ⇒
 Directives to override the size of symbols MIPS Symbol Sizes.
1 
1    In order to cut down on this overhead, most embedded MIPS systems set
1 aside a 64-kilobyte "small data" area and guarantee that all data of
1 size N and smaller will be placed in that area.  The limit N is passed
1 to both the assembler and the linker using the command-line option '-G
1 N', ⇒Assembler options MIPS Options.  Note that the same value of
1 N must be used when linking and when assembling all input files to the
1 link; any inconsistency could cause a relocation overflow error.
1 
1    The size of an object in the '.bss' section is set by the '.comm' or
1 '.lcomm' directive that defines it.  The size of an external object may
1 be set with the '.extern' directive.  For example, '.extern sym,4'
1 declares that the object at 'sym' is 4 bytes in length, while leaving
1 'sym' otherwise undefined.
1 
1    When no '-G' option is given, the default limit is 8 bytes.  The
1 option '-G 0' prevents any data from being automatically classified as
1 small.
1 
1    It is also possible to mark specific objects as small by putting them
1 in the special sections '.sdata' and '.sbss', which are "small"
1 counterparts of '.data' and '.bss' respectively.  The toolchain will
1 treat such data as small regardless of the '-G' setting.
1 
1    On startup, systems that support a small data area are expected to
1 initialize register '$28', also known as '$gp', in such a way that small
1 data can be accessed using a 16-bit offset from that register.  For
1 example, when 'addr' is small data, the 'dla $4,addr' instruction above
1 is equivalent to:
1 
1      daddiu  $4,$28,%gp_rel(addr)
1 
1    Small data is not supported for SVR4-style PIC.
1