Home | History | Annotate | Line # | Download | only in doc
sframe-spec.texi revision 1.1.1.1
      1  1.1  christos \input texinfo       @c                    -*- Texinfo -*-
      2  1.1  christos @setfilename sframe-spec.info
      3  1.1  christos @settitle The SFrame Format
      4  1.1  christos 
      5  1.1  christos @copying
      6  1.1  christos Copyright @copyright{} 2021-2022 Free Software Foundation, Inc.
      7  1.1  christos 
      8  1.1  christos Permission is granted to copy, distribute and/or modify this document
      9  1.1  christos under the terms of the GNU General Public License, Version 3 or any
     10  1.1  christos later version published by the Free Software Foundation.  A copy of the
     11  1.1  christos license is included in the section entitled ``GNU General Public
     12  1.1  christos License''.
     13  1.1  christos 
     14  1.1  christos @end copying
     15  1.1  christos 
     16  1.1  christos @dircategory Software development
     17  1.1  christos @direntry
     18  1.1  christos * SFrame: (sframe-spec).         The Simple Frame format.
     19  1.1  christos @end direntry
     20  1.1  christos 
     21  1.1  christos @titlepage
     22  1.1  christos @title The SFrame Format
     23  1.1  christos @subtitle Version 1
     24  1.1  christos @author Indu Bhagat
     25  1.1  christos 
     26  1.1  christos @page
     27  1.1  christos @vskip 0pt plus 1filll
     28  1.1  christos @insertcopying
     29  1.1  christos @end titlepage
     30  1.1  christos @contents
     31  1.1  christos 
     32  1.1  christos @ifnottex
     33  1.1  christos @node Top
     34  1.1  christos @top The SFrame format
     35  1.1  christos 
     36  1.1  christos This manual describes version 1 of the SFrame file format.  SFrame stands for
     37  1.1  christos Simple Frame format.  SFrame format keeps track of the minimal necessary
     38  1.1  christos information needed for stack unwinding:
     39  1.1  christos 
     40  1.1  christos @itemize @minus
     41  1.1  christos @item
     42  1.1  christos Canonical Frame Address (CFA).
     43  1.1  christos @item
     44  1.1  christos Frame Pointer (FP).
     45  1.1  christos @item
     46  1.1  christos Return Address (RA).
     47  1.1  christos @end itemize
     48  1.1  christos 
     49  1.1  christos The reason for existence of the SFrame format is to support fast, online
     50  1.1  christos backtracing using a simple unwinder.
     51  1.1  christos 
     52  1.1  christos @menu
     53  1.1  christos * Overview::
     54  1.1  christos * SFrame section::
     55  1.1  christos * Index::
     56  1.1  christos @end menu
     57  1.1  christos 
     58  1.1  christos @end ifnottex
     59  1.1  christos 
     60  1.1  christos @node Overview
     61  1.1  christos @unnumbered Overview
     62  1.1  christos @cindex Overview
     63  1.1  christos @tindex PT_GNU_SFRAME
     64  1.1  christos 
     65  1.1  christos The SFrame unwind information is provided in a loaded section, known as the
     66  1.1  christos @code{.sframe} section.  When available, the @code{.sframe} section appears in
     67  1.1  christos a new segment of its own, PT_GNU_SFRAME.
     68  1.1  christos 
     69  1.1  christos The SFrame format is currently supported only for select ABIs, namely, AMD64
     70  1.1  christos and AAPCS64.
     71  1.1  christos 
     72  1.1  christos The contents of the SFrame section are stored in the target endianness, i.e.,
     73  1.1  christos in the endianness of the system on which the section is targetted to be used.
     74  1.1  christos An SFrame section reader may use the magic number in the SFrame header to
     75  1.1  christos identify the endianness of the SFrame section.
     76  1.1  christos 
     77  1.1  christos Addresses in this specification are expressed in bytes.
     78  1.1  christos 
     79  1.1  christos The associated API to decode, probe and encode the SFrame section, provided via
     80  1.1  christos @code{libsframe}, is not accompanied here at this time.  This will be added
     81  1.1  christos later.
     82  1.1  christos 
     83  1.1  christos This document is intended to be in sync with the C code in @file{sframe.h}.
     84  1.1  christos Please report descrepancies between the two, if any.
     85  1.1  christos 
     86  1.1  christos @node SFrame section
     87  1.1  christos @chapter SFrame section
     88  1.1  christos @cindex SFrame section
     89  1.1  christos 
     90  1.1  christos The SFrame section consists of an SFrame header, starting with a preamble, and
     91  1.1  christos two other sub-sections, namely the SFrame Function Descriptor Entry (SFrame
     92  1.1  christos FDE) sub-section, and the SFrame Frame Row Entry (SFrame FRE) sub-section.
     93  1.1  christos 
     94  1.1  christos @menu
     95  1.1  christos * SFrame Preamble::
     96  1.1  christos * SFrame Header::
     97  1.1  christos * SFrame Function Descriptor Entries::
     98  1.1  christos * SFrame Frame Row Entries::
     99  1.1  christos @end menu
    100  1.1  christos 
    101  1.1  christos @node SFrame Preamble
    102  1.1  christos @section SFrame Preamble
    103  1.1  christos @cindex SFrame preamble
    104  1.1  christos 
    105  1.1  christos The preamble is a 32-bit packed structure; the only part of the SFrame whose
    106  1.1  christos format cannot vary between versions.
    107  1.1  christos 
    108  1.1  christos @example
    109  1.1  christos typedef struct sframe_preamble
    110  1.1  christos @{
    111  1.1  christos   uint16_t sfp_magic;
    112  1.1  christos   uint8_t sfp_version;
    113  1.1  christos   uint8_t sfp_flags;
    114  1.1  christos @} ATTRIBUTE_PACKED sframe_preamble;
    115  1.1  christos @end example
    116  1.1  christos 
    117  1.1  christos All values are stored in the endianness of the target system for which the
    118  1.1  christos SFrame section is intended.  Further details:
    119  1.1  christos 
    120  1.1  christos @multitable {Offset} {@code{uint8_t sfp_version}} {The magic number for SFrame section: 0xdee2.  Defined}
    121  1.1  christos @headitem Offset @tab Name @tab Description
    122  1.1  christos @item 0x00
    123  1.1  christos @tab @code{uint16_t sfp_magic}
    124  1.1  christos @tab The magic number for SFrame section: 0xdee2.  Defined as a macro @code{SFRAME_MAGIC}.
    125  1.1  christos @tindex SFRAME_MAGIC
    126  1.1  christos 
    127  1.1  christos @item 0x02
    128  1.1  christos @tab @code{uint8_t sfp_version}
    129  1.1  christos @tab The version number of this SFrame section.  @xref{SFrame version}, for the
    130  1.1  christos set of valid values.  Current version is
    131  1.1  christos @code{SFRAME_VERSION_1}.
    132  1.1  christos 
    133  1.1  christos @item 0x03
    134  1.1  christos @tab @code{uint8_t sfp_flags}
    135  1.1  christos @tab Flags (section-wide) for this SFrame section.  @xref{SFrame flags}, for the
    136  1.1  christos set of valid values.
    137  1.1  christos @end multitable
    138  1.1  christos 
    139  1.1  christos @menu
    140  1.1  christos * SFrame endianness::
    141  1.1  christos * SFrame version::
    142  1.1  christos * SFrame flags::
    143  1.1  christos @end menu
    144  1.1  christos 
    145  1.1  christos @node SFrame endianness
    146  1.1  christos @subsection SFrame endianness
    147  1.1  christos 
    148  1.1  christos @cindex endianness
    149  1.1  christos SFrame sections are stored in the target endianness of the system that consumes
    150  1.1  christos them.  The SFrame library (@code{libsframe}) can, however, detect whether to
    151  1.1  christos endian-flip an SFrame section at decode time, by inspecting the
    152  1.1  christos @code{sfp_magic} field in the SFrame header (If it appears as 0xe2de,
    153  1.1  christos endian-flipping is needed).
    154  1.1  christos 
    155  1.1  christos @node SFrame version
    156  1.1  christos @subsection SFrame version
    157  1.1  christos 
    158  1.1  christos The version of the SFrame format can be determined by inspecting
    159  1.1  christos @code{sfp_version}.  The following versions are currently valid:
    160  1.1  christos 
    161  1.1  christos @tindex SFRAME_VERSION_1
    162  1.1  christos @cindex SFrame versions
    163  1.1  christos @multitable {SFRAME_VERSION_1} {Number} {First version, under development.}
    164  1.1  christos @headitem Version @tab Number @tab Description
    165  1.1  christos @item @code{SFRAME_VERSION_1}
    166  1.1  christos @tab 1 @tab First version, under development.
    167  1.1  christos @end multitable
    168  1.1  christos 
    169  1.1  christos This section documents @code{SFRAME_VERSION_1}.
    170  1.1  christos 
    171  1.1  christos @node SFrame flags
    172  1.1  christos @subsection SFrame flags
    173  1.1  christos @cindex SFrame flags
    174  1.1  christos @comment @vindex sfp_flags
    175  1.1  christos @comment @vindex SFrame section-wide flags
    176  1.1  christos @comment @subsection SFrame section-wide flags
    177  1.1  christos 
    178  1.1  christos The preamble contains bitflags in its @code{sfp_flags} field that
    179  1.1  christos describe various section-wide properties.
    180  1.1  christos 
    181  1.1  christos The following flags are currently defined.
    182  1.1  christos 
    183  1.1  christos @multitable {@code{SFRAME_F_FRAME_POINTER}} {Versions} {Value} {Function Descriptor Entries}
    184  1.1  christos @headitem Flag @tab Versions @tab Value @tab Meaning
    185  1.1  christos @tindex SFRAME_F_FDE_SORTED
    186  1.1  christos @item @code{SFRAME_F_FDE_SORTED} @tab All @tab 0x1 @tab Function Descriptor
    187  1.1  christos Entries are sorted on PC.
    188  1.1  christos @tindex SFRAME_F_FRAME_POINTER
    189  1.1  christos @item @code{SFRAME_F_FRAME_POINTER} @tab All @tab 0x2
    190  1.1  christos @tab Functions preserve frame-pointer.
    191  1.1  christos @end multitable
    192  1.1  christos 
    193  1.1  christos Further flags may be added in future.
    194  1.1  christos 
    195  1.1  christos @node SFrame Header
    196  1.1  christos @section SFrame Header
    197  1.1  christos @cindex SFrame header
    198  1.1  christos 
    199  1.1  christos The SFrame header is the first part of an SFrame section.  It begins with the
    200  1.1  christos SFrame preamble.  All parts of it other than the preamble
    201  1.1  christos (@pxref{SFrame Preamble}) can vary between SFrame file versions.  It contains
    202  1.1  christos things that apply to the section as a whole, and offsets to the various other
    203  1.1  christos sub-sections defined in the format.  As with the rest of the SFrame section,
    204  1.1  christos all values are stored in the endianness of the target system.
    205  1.1  christos 
    206  1.1  christos The two sub-sections tile the SFrame section: each section runs from the offset
    207  1.1  christos given until the start of the next section.  An explicit length is given for the
    208  1.1  christos last sub-section, the SFrame Frame Row Entry (SFrame FRE) sub-section.
    209  1.1  christos 
    210  1.1  christos @example
    211  1.1  christos typedef struct sframe_header
    212  1.1  christos @{
    213  1.1  christos   sframe_preamble sfh_preamble;
    214  1.1  christos   uint8_t sfh_abi_arch;
    215  1.1  christos   int8_t sfh_cfa_fixed_fp_offset;
    216  1.1  christos   int8_t sfh_cfa_fixed_ra_offset;
    217  1.1  christos   uint8_t sfh_auxhdr_len;
    218  1.1  christos   uint32_t sfh_num_fdes;
    219  1.1  christos   uint32_t sfh_num_fres;
    220  1.1  christos   uint32_t sfh_fre_len;
    221  1.1  christos   uint32_t sfh_fdeoff;
    222  1.1  christos   uint32_t sfh_freoff;
    223  1.1  christos @} ATTRIBUTE_PACKED sframe_header;
    224  1.1  christos @end example
    225  1.1  christos 
    226  1.1  christos The sub-section offsets, namely @code{sfh_fdeoff} and @code{sfh_freoff}, in the
    227  1.1  christos SFrame header are relative to the @emph{end} of the SFrame header; they are
    228  1.1  christos each an offset in bytes into the SFrame section where the SFrame FDE
    229  1.1  christos sub-section and the SFrame FRE sub-section respectively start.
    230  1.1  christos 
    231  1.1  christos SFrame header allows specifying explicitly the fixed offsets from CFA, if any,
    232  1.1  christos from which FP or RA may be recovered.  For example, in AMD64, the stack offset
    233  1.1  christos of the return address is @code{CFA - 8}.  Since this offset is in close
    234  1.1  christos vicinity with the CFA in most ABIs, @code{sfh_cfa_fixed_fp_offset} and
    235  1.1  christos @code{sfh_cfa_fixed_ra_offset} are limited to signed 8-bit integers.
    236  1.1  christos 
    237  1.1  christos SFrame format has provisioned for future ABIs/architectures that it may
    238  1.1  christos support.  The @code{sframe_header} structure provides an unsigned 8-bit
    239  1.1  christos integral field to denote the size of an auxilliary SFrame header.  The
    240  1.1  christos auxilliary SFrame header follows right after the @code{sframe_header}
    241  1.1  christos structure.  As for the offset calculations, the @emph{end} of SFrame header
    242  1.1  christos must be the end of the auxilliary SFrame header, if the latter is present.
    243  1.1  christos 
    244  1.1  christos Tieing it all together:
    245  1.1  christos 
    246  1.1  christos @multitable {Offset} {@code{int8_t sfh_cfa_fixed_fp_offset}} {The ABI/arch identifier. See above}
    247  1.1  christos @headitem Offset @tab Name @tab Description
    248  1.1  christos @item 0x00
    249  1.1  christos @tab @code{sframe_preamble sfh_preamble}
    250  1.1  christos @tab The SFrame preamble. @xref{SFrame Preamble}.
    251  1.1  christos 
    252  1.1  christos @item 0x04
    253  1.1  christos @tab @code{uint8_t sfh_abi_arch}
    254  1.1  christos @tab The ABI/arch identifier.  @xref{SFrame ABI/arch identifier}.
    255  1.1  christos 
    256  1.1  christos @item 0x05
    257  1.1  christos @tab @code{int8_t sfh_cfa_fixed_fp_offset}
    258  1.1  christos @tab The CFA fixed FP offset, if any.
    259  1.1  christos 
    260  1.1  christos @item 0x06
    261  1.1  christos @tab @code{int8_t sfh_cfa_fixed_ra_offset}
    262  1.1  christos @tab The CFA fixed RA offset, if any.
    263  1.1  christos 
    264  1.1  christos @item 0x07
    265  1.1  christos @tab @code{uint8_t sfh_auxhdr_len}
    266  1.1  christos @tab Size in bytes of the auxilliary header that follows the
    267  1.1  christos @code{sframe_header} structure.
    268  1.1  christos 
    269  1.1  christos @item 0x08
    270  1.1  christos @tab @code{uint32_t sfh_num_fdes}
    271  1.1  christos @tab The number of SFrame FDEs in the section.
    272  1.1  christos 
    273  1.1  christos @item 0xc
    274  1.1  christos @tab @code{uint32_t sfh_num_fres}
    275  1.1  christos @tab The number of SFrame FREs in the section.
    276  1.1  christos 
    277  1.1  christos @item 0x10
    278  1.1  christos @tab @code{uint32_t sfh_fre_len}
    279  1.1  christos @tab The length in bytes of the SFrame FRE sub-section.
    280  1.1  christos 
    281  1.1  christos @item 0x14
    282  1.1  christos @tab @code{uint32_t sfh_fdeoff}
    283  1.1  christos @tab The offset in bytes of the SFrame FDE sub-section.  This sub-section
    284  1.1  christos contains @code{sfh_num_fdes} number of fixed-length array elements.  The array
    285  1.1  christos element is of type SFrame function desciptor entry, each providing a
    286  1.1  christos high-level function description for backtracing.
    287  1.1  christos @xref{SFrame Function Descriptor Entries}.
    288  1.1  christos 
    289  1.1  christos @item 0x18
    290  1.1  christos @tab @code{uint32_t sfh_freoff}
    291  1.1  christos @tab The offset in bytes of the SFrame FRE sub-section, the core of the SFrame
    292  1.1  christos section, which describes the unwind information using variable-length array
    293  1.1  christos elements. @xref{SFrame Frame Row Entries}.
    294  1.1  christos 
    295  1.1  christos @end multitable
    296  1.1  christos 
    297  1.1  christos @menu
    298  1.1  christos * SFrame ABI/arch identifier::
    299  1.1  christos @end menu
    300  1.1  christos 
    301  1.1  christos @node SFrame ABI/arch identifier
    302  1.1  christos @subsection SFrame ABI/arch identifier
    303  1.1  christos @cindex SFrame ABI/arch identifier
    304  1.1  christos 
    305  1.1  christos SFrame header identifies the ABI/arch of the target system for which the
    306  1.1  christos executable and it's unwind information is intended.  There are currently three
    307  1.1  christos identifiable ABI/arch values in the format.
    308  1.1  christos 
    309  1.1  christos @multitable {SFRAME_ABI_AARCH64_ENDIAN_LITTLE} {Value} {@code{AARCH64 little-endian}}
    310  1.1  christos @headitem ABI/arch Identifier @tab Value @tab Description
    311  1.1  christos 
    312  1.1  christos @tindex SFRAME_ABI_AARCH64_ENDIAN_BIG
    313  1.1  christos @item @code{SFRAME_ABI_AARCH64_ENDIAN_BIG}
    314  1.1  christos @tab 1 @tab AARCH64 big-endian
    315  1.1  christos 
    316  1.1  christos @tindex SFRAME_ABI_AARCH64_ENDIAN_LITTLE
    317  1.1  christos @item @code{SFRAME_ABI_AARCH64_ENDIAN_LITTLE}
    318  1.1  christos @tab 2 @tab AARCH64 little-endian
    319  1.1  christos 
    320  1.1  christos @tindex SFRAME_ABI_AMD64_ENDIAN_LITTLE
    321  1.1  christos @item @code{SFRAME_ABI_AMD64_ENDIAN_LITTLE}
    322  1.1  christos @tab 3 @tab AMD64 little-endian
    323  1.1  christos 
    324  1.1  christos @end multitable
    325  1.1  christos 
    326  1.1  christos The presence of an explicit identification of ABI/arch in SFrame may allow
    327  1.1  christos unwinders to make certain ABI-specific decisions.
    328  1.1  christos 
    329  1.1  christos @node SFrame Function Descriptor Entries
    330  1.1  christos @section SFrame FDE
    331  1.1  christos @cindex SFrame FDE
    332  1.1  christos 
    333  1.1  christos The SFrame Function Descriptor Entry sub-section is a sorted array of
    334  1.1  christos fixed-length SFrame function descriptor entries (SFrame FDEs).  Each SFrame FDE
    335  1.1  christos is a packed structure which contains information to describe a function's unwind
    336  1.1  christos information at a high-level.
    337  1.1  christos 
    338  1.1  christos @example
    339  1.1  christos typedef struct sframe_func_desc_entry
    340  1.1  christos @{
    341  1.1  christos   int32_t sfde_func_start_address;
    342  1.1  christos   uint32_t sfde_func_size;
    343  1.1  christos   uint32_t sfde_func_start_fre_off;
    344  1.1  christos   uint32_t sfde_func_num_fres;
    345  1.1  christos   uint8_t sfde_func_info;
    346  1.1  christos @} ATTRIBUTE_PACKED sframe_func_desc_entry;
    347  1.1  christos @end example
    348  1.1  christos 
    349  1.1  christos @code{sfde_func_start_fre_off} is the offset to the first SFrame FRE for the
    350  1.1  christos function.  This offset is relative to the @emph{end of the SFrame FDE}
    351  1.1  christos sub-section (unlike the offsets in the SFrame header, which are relative to the
    352  1.1  christos @emph{end} of the SFrame header).
    353  1.1  christos 
    354  1.1  christos @code{sfde_func_info} is the "info word", containing information on the FRE
    355  1.1  christos type and the FDE type for the function @xref{The SFrame FDE info word}.
    356  1.1  christos 
    357  1.1  christos Following table describes each component of the SFrame FDE structure:
    358  1.1  christos 
    359  1.1  christos @multitable {Offset} {@code{uint32_t sfde_func_start_fre_off}} {The ABI/arch identifier. See above}
    360  1.1  christos @headitem Offset @tab Name @tab Description
    361  1.1  christos @item 0x00
    362  1.1  christos @tab @code{int32_t sfde_func_start_address}
    363  1.1  christos @tab Signed 32-bit integral field denoting the virtual memory address of the
    364  1.1  christos described function.
    365  1.1  christos 
    366  1.1  christos @item 0x04
    367  1.1  christos @tab @code{uint32_t sfde_func_size}
    368  1.1  christos @tab Unsigned 32-bit integral field specifying the size of the function in
    369  1.1  christos bytes.
    370  1.1  christos 
    371  1.1  christos @item 0x08
    372  1.1  christos @tab @code{uint32_t sfde_func_start_fre_off}
    373  1.1  christos @tab Unsigned 32-bit integral field specifying the offset in bytes of the
    374  1.1  christos function's first SFrame FRE in the SFrame section.
    375  1.1  christos 
    376  1.1  christos @item 0x0c
    377  1.1  christos @tab @code{uint32_t sfde_func_num_fres}
    378  1.1  christos @tab Unsigned 32-bit integral field specifying the total number of SFrame FREs
    379  1.1  christos used for the function.
    380  1.1  christos 
    381  1.1  christos @item 0x10
    382  1.1  christos @tab @code{uint8_t sfde_func_info}
    383  1.1  christos @tab The SFrame FDE info word. @xref{The SFrame FDE info word}.
    384  1.1  christos 
    385  1.1  christos @end multitable
    386  1.1  christos 
    387  1.1  christos @menu
    388  1.1  christos * The SFrame FDE info word::
    389  1.1  christos * The SFrame FDE types::
    390  1.1  christos * The SFrame FRE types::
    391  1.1  christos @end menu
    392  1.1  christos 
    393  1.1  christos @cindex The SFrame FDE info word
    394  1.1  christos @node The SFrame FDE info word
    395  1.1  christos @subsection The SFrame FDE info word
    396  1.1  christos 
    397  1.1  christos The info word is a bitfield split into three parts.  From MSB to LSB:
    398  1.1  christos 
    399  1.1  christos @multitable {Bit offset} {@code{isroot}} {Length of variable-length data for this type (some kinds only).}
    400  1.1  christos @headitem Bit offset @tab Name @tab Description
    401  1.1  christos @item 7--5
    402  1.1  christos @tab @code{unused}
    403  1.1  christos @tab Unused bits.
    404  1.1  christos 
    405  1.1  christos @item 4
    406  1.1  christos @tab @code{fdetype}
    407  1.1  christos @tab SFRAME_FDE_TYPE_PCMASK (1) or SFRAME_FDE_TYPE_PCINC (0). @xref{The SFrame FDE types}.
    408  1.1  christos 
    409  1.1  christos @item 0--3
    410  1.1  christos @tab @code{fretype}
    411  1.1  christos @tab Choice of three SFrame FRE types. @xref{The SFrame FRE types}.
    412  1.1  christos @end multitable
    413  1.1  christos 
    414  1.1  christos @node The SFrame FDE types
    415  1.1  christos @subsection The SFrame FDE types
    416  1.1  christos @tindex SFRAME_FDE_TYPE_PCMASK
    417  1.1  christos @tindex SFRAME_FDE_TYPE_PCINC
    418  1.1  christos 
    419  1.1  christos SFrame format defines two types of FDE entries.  The choice of which SFrame FDE
    420  1.1  christos type to use is made based on the instruction patterns in the relevant program
    421  1.1  christos stub.
    422  1.1  christos 
    423  1.1  christos An SFrame FDE of type @code{SFRAME_FDE_TYPE_PCINC} is an indication that the PCs in the
    424  1.1  christos FREs should be treated as increments in bytes.  This is used fo the the bulk of
    425  1.1  christos the executable code of a program, which contains instructions with no specific
    426  1.1  christos pattern.
    427  1.1  christos 
    428  1.1  christos In contrast, an SFrame FDE of type @code{SFRAME_FDE_TYPE_PCMASK} is an
    429  1.1  christos indication that the PCs in the FREs should be treated as masks.  This type is
    430  1.1  christos useful for the cases where a small pattern of instructions in a program stub is
    431  1.1  christos used repeatedly for a specific functionality.  Typical usecases are pltN
    432  1.1  christos entries and trampolines.
    433  1.1  christos 
    434  1.1  christos @multitable {Name of SFrame FDE type} {Value} {Unwinders perform a (PC >= FRE_START_ADDR)}
    435  1.1  christos @headitem Name of SFrame FDE type @tab Value @tab Description
    436  1.1  christos 
    437  1.1  christos @item SFRAME_FDE_TYPE_PCINC
    438  1.1  christos @tab 0 @tab Unwinders perform a (PC >= FRE_START_ADDR) to look up a matching FRE.
    439  1.1  christos 
    440  1.1  christos @item SFRAME_FDE_TYPE_PCMASK
    441  1.1  christos @tab 1 @tab  Unwinders perform a (PC & FRE_START_ADDR_AS_MASK >= FRE_START_ADDR_AS_MASK)
    442  1.1  christos to look up a matching FRE.
    443  1.1  christos 
    444  1.1  christos @end multitable
    445  1.1  christos 
    446  1.1  christos @node The SFrame FRE types
    447  1.1  christos @subsection The SFrame FRE types
    448  1.1  christos 
    449  1.1  christos A real world application can have functions of size big and small.  SFrame
    450  1.1  christos format defines three types of SFrame FRE entries to represent the unwind
    451  1.1  christos information for such a variety of function sizes.  These representations vary
    452  1.1  christos in the number of bits needed to encode the start address offset in the SFrame
    453  1.1  christos FRE.
    454  1.1  christos 
    455  1.1  christos The following constants are defined and used to identify the SFrame FRE types:
    456  1.1  christos 
    457  1.1  christos @multitable {SFRAME_FRE_TYPE_ADDR1} {@code{Value}} {The start address offset of FRE is an}
    458  1.1  christos @headitem Name @tab Value @tab Description
    459  1.1  christos 
    460  1.1  christos @tindex SFRAME_FRE_TYPE_ADDR1
    461  1.1  christos @item @code{SFRAME_FRE_TYPE_ADDR1}
    462  1.1  christos @tab 0
    463  1.1  christos @tab The start address offset (in bytes) of the SFrame FRE is an unsigned
    464  1.1  christos 8-bit value.
    465  1.1  christos 
    466  1.1  christos @tindex SFRAME_FRE_TYPE_ADDR2
    467  1.1  christos @item @code{SFRAME_FRE_TYPE_ADDR2}
    468  1.1  christos @tab 1
    469  1.1  christos @tab The start address offset (in bytes) of the SFrame FRE is an unsigned
    470  1.1  christos 16-bit value.
    471  1.1  christos 
    472  1.1  christos @tindex SFRAME_FRE_TYPE_ADDR4
    473  1.1  christos @item @code{SFRAME_FRE_TYPE_ADDR4}
    474  1.1  christos @tab 2
    475  1.1  christos @tab The start address offset (in bytes) of the SFrame FRE is an unsigned
    476  1.1  christos 32-bit value.
    477  1.1  christos @end multitable
    478  1.1  christos 
    479  1.1  christos A single function must use the same type of FRE throughout.  The choice of
    480  1.1  christos which SFrame FRE is used to encode the unwind information of a function, is
    481  1.1  christos stored in the @xref{The SFrame FDE info word}.
    482  1.1  christos 
    483  1.1  christos @node SFrame Frame Row Entries
    484  1.1  christos @section SFrame FRE
    485  1.1  christos @cindex SFrame FRE
    486  1.1  christos 
    487  1.1  christos The SFrame Frame Row Entry sub-section contains the core of the unwind
    488  1.1  christos information.
    489  1.1  christos 
    490  1.1  christos An SFrame Frame Row Entry is a self-sufficient record containing SFrame unwind
    491  1.1  christos info for a range of contiguous addresses, starting at the specified offset from
    492  1.1  christos the start of the function.  Each SFrame Frame Row Entry is followed by S*N
    493  1.1  christos bytes, where:
    494  1.1  christos 
    495  1.1  christos @itemize @minus
    496  1.1  christos @item
    497  1.1  christos @code{S} is the size of the stack frame offset for the FRE, and
    498  1.1  christos @item
    499  1.1  christos @code{N} is the number of stack frame offsets in the FRE
    500  1.1  christos @end itemize
    501  1.1  christos 
    502  1.1  christos The stack offsets, following the FRE, are interpreted in order as follows:
    503  1.1  christos 
    504  1.1  christos @itemize @minus
    505  1.1  christos @item
    506  1.1  christos The first offset is always used to locate the CFA, by interpreting it as:
    507  1.1  christos CFA = @code{BASE_REG} + offset1.
    508  1.1  christos @item
    509  1.1  christos If RA is being tracked, the second offset is always used to locate the RA, by
    510  1.1  christos interpreting it as: RA = CFA + offset2.  If RA is @emph{not} being tracked
    511  1.1  christos @emph{and} FP is being tracked, the second offset will be used to locate the
    512  1.1  christos FP, by interpreting it as: FP = CFA + offset2.
    513  1.1  christos @item
    514  1.1  christos If both RA and FP are being tracked, the third offset will be used to locate
    515  1.1  christos the FP, by interpreting it as FP = CFA + offset3.
    516  1.1  christos @end itemize
    517  1.1  christos 
    518  1.1  christos The entities @code{S}, @code{N} and @code{BASE_REG} are identified using the
    519  1.1  christos SFrame FRE info word, a.k.a. the @code{sframe_fre_info}
    520  1.1  christos @xref{The SFrame FRE info word}.
    521  1.1  christos 
    522  1.1  christos Following are the definitions of the allowed SFrame FRE:
    523  1.1  christos 
    524  1.1  christos @example
    525  1.1  christos typedef struct sframe_frame_row_entry_addr1
    526  1.1  christos @{
    527  1.1  christos   uint8_t sfre_start_address;
    528  1.1  christos   sframe_fre_info sfre_info;
    529  1.1  christos @} ATTRIBUTE_PACKED sframe_frame_row_entry_addr1;
    530  1.1  christos @end example
    531  1.1  christos 
    532  1.1  christos @example
    533  1.1  christos typedef struct sframe_frame_row_entry_addr2
    534  1.1  christos @{
    535  1.1  christos   uint16_t sfre_start_address;
    536  1.1  christos   sframe_fre_info sfre_info;
    537  1.1  christos @} ATTRIBUTE_PACKED sframe_frame_row_entry_addr2;
    538  1.1  christos @end example
    539  1.1  christos 
    540  1.1  christos @example
    541  1.1  christos typedef struct sframe_frame_row_entry_addr4
    542  1.1  christos @{
    543  1.1  christos   uint32_t sfre_start_address;
    544  1.1  christos   sframe_fre_info sfre_info;
    545  1.1  christos @} ATTRIBUTE_PACKED sframe_frame_row_entry_addr4;
    546  1.1  christos @end example
    547  1.1  christos 
    548  1.1  christos @code{sfre_start_address} is an unsigned 8-bit/16-bit/32-bit integral field
    549  1.1  christos identifies the start address of the range of program counters, for which the
    550  1.1  christos SFrame FRE applies.  The value encoded in the @code{sfre_start_address} field
    551  1.1  christos is the offset in bytes of the start address of the SFrame FRE, from the start
    552  1.1  christos address of the function.
    553  1.1  christos 
    554  1.1  christos Further FRE types may be added in future.
    555  1.1  christos 
    556  1.1  christos @menu
    557  1.1  christos * The SFrame FRE info word::
    558  1.1  christos @end menu
    559  1.1  christos 
    560  1.1  christos @cindex The SFrame FRE info word
    561  1.1  christos @node The SFrame FRE info word
    562  1.1  christos @subsection The SFrame FRE info word
    563  1.1  christos 
    564  1.1  christos The SFrame FRE info word is a bitfield split into four parts.  From MSB to LSB:
    565  1.1  christos 
    566  1.1  christos @multitable {Bit offset} {@code{fre_cfa_base_reg_id}} {Size of stack offsets in bytes.  Valid values}
    567  1.1  christos @headitem Bit offset @tab Name @tab Description
    568  1.1  christos @item 7
    569  1.1  christos @tab @code{fre_mangled_ra_p}
    570  1.1  christos @tab Indicate whether the return address is mangled with any authorization bits (signed RA).
    571  1.1  christos 
    572  1.1  christos @item 5-6
    573  1.1  christos @tab @code{fre_offset_size}
    574  1.1  christos @tab Size of stack offsets in bytes.  Valid values are SFRAME_FRE_OFFSET_1B,
    575  1.1  christos SFRAME_FRE_OFFSET_2B, and SFRAME_FRE_OFFSET_4B.
    576  1.1  christos 
    577  1.1  christos @item 1-4
    578  1.1  christos @tab @code{fre_offset_count}
    579  1.1  christos @tab A value of upto 3 is allowed to track all three of CFA, FP and RA.
    580  1.1  christos 
    581  1.1  christos @item 0
    582  1.1  christos @tab @code{fre_cfa_base_reg_id}
    583  1.1  christos @tab Distinguish between SP or FP based CFA recovery.
    584  1.1  christos 
    585  1.1  christos @end multitable
    586  1.1  christos 
    587  1.1  christos @multitable {SFRAME_FRE_OFFSET_4B} {@code{Value}} {All stack offsets following the fixed-length}
    588  1.1  christos @headitem Name @tab Value @tab Description
    589  1.1  christos 
    590  1.1  christos @tindex SFRAME_FRE_OFFSET_1B
    591  1.1  christos @item @code{SFRAME_FRE_OFFSET_1B}
    592  1.1  christos @tab 0
    593  1.1  christos @tab All stack offsets following the fixed-length FRE structure are 1 byte
    594  1.1  christos long.
    595  1.1  christos 
    596  1.1  christos @tindex SFRAME_FRE_OFFSET_2B
    597  1.1  christos @item @code{SFRAME_FRE_OFFSET_2B}
    598  1.1  christos @tab 1
    599  1.1  christos @tab All stack offsets following the fixed-length FRE structure are 2 bytes
    600  1.1  christos long.
    601  1.1  christos 
    602  1.1  christos @tindex SFRAME_FRE_OFFSET_4B
    603  1.1  christos @item @code{SFRAME_FRE_OFFSET_4B}
    604  1.1  christos @tab 2
    605  1.1  christos @tab All stack offsets following the fixed-length FRE structure are 4 bytes
    606  1.1  christos long.
    607  1.1  christos 
    608  1.1  christos @end multitable
    609  1.1  christos 
    610  1.1  christos @node Index
    611  1.1  christos @unnumbered Index
    612  1.1  christos 
    613  1.1  christos @syncodeindex tp cp
    614  1.1  christos @printindex cp
    615  1.1  christos 
    616  1.1  christos @bye
    617